Commit 31b781a2 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Support Redox

parent b521bac2
......@@ -12,5 +12,8 @@ lto = true
debug-assertions = false
codegen-units = 1
[dependencies]
[target.'cfg(not(target_os = "redox"))'.dependencies]
sc = "0.2.1"
[target.'cfg(target_os = "redox")'.dependencies]
redox_syscall = "0.1"
......@@ -43,10 +43,19 @@ pub fn default_oom_handler() -> ! {
/// Write to the log.
///
/// This points to stderr, but could be changed arbitrarily.
#[cfg(not(target_os = "redox"))]
pub fn log(s: &str) -> usize {
unsafe { syscall!(WRITE, 2, s.as_ptr(), s.len()) }
}
/// Write to the log.
///
/// This points to stderr, but could be changed arbitrarily.
#[cfg(target_os = "redox")]
pub fn log(s: &str) -> usize {
::syscall::write(2, s.as_bytes()).unwrap_or(!0)
}
/// Canonicalize a fresh allocation.
///
/// The return value specifies how much _more_ space is requested to the fresh allocator.
......
......@@ -11,9 +11,13 @@
#![no_std]
#![warn(missing_docs)]
#[cfg(not(target_os = "redox"))]
#[macro_use]
extern crate sc;
#[cfg(target_os = "redox")]
extern crate syscall;
pub mod config;
pub mod thread_destructor;
pub mod debug;
......
......@@ -7,11 +7,32 @@
/// # Note
///
/// This is the `brk` **syscall**, not the library function.
#[cfg(not(target_os = "redox"))]
pub unsafe fn brk(ptr: *const u8) -> *const u8 {
syscall!(BRK, ptr) as *const u8
}
/// Voluntarily give a time slice to the scheduler.
#[cfg(not(target_os = "redox"))]
pub fn sched_yield() -> usize {
unsafe { syscall!(SCHED_YIELD) }
}
/// Change the data segment. See `man brk`.
///
/// On success, the new program break is returned. On failure, the old program break is returned.
///
/// # Note
///
/// This is the `brk` **syscall**, not the library function.
#[cfg(target_os = "redox")]
pub unsafe fn brk(ptr: *const u8) -> *const u8 {
let old = ::syscall::brk(0).unwrap_or(0);
::syscall::brk(ptr as usize).unwrap_or(old) as *const u8
}
/// Voluntarily give a time slice to the scheduler.
#[cfg(target_os = "redox")]
pub fn sched_yield() -> usize {
::syscall::Error::mux(::syscall::sched_yield())
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment