Jeremy Soller 6 роки тому
батько
коміт
31b781a287
4 змінених файлів з 38 додано та 1 видалено
  1. 4 1
      shim/Cargo.toml
  2. 9 0
      shim/src/config.rs
  3. 4 0
      shim/src/lib.rs
  4. 21 0
      shim/src/syscalls.rs

+ 4 - 1
shim/Cargo.toml

@@ -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"

+ 9 - 0
shim/src/config.rs

@@ -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.

+ 4 - 0
shim/src/lib.rs

@@ -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;

+ 21 - 0
shim/src/syscalls.rs

@@ -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())
+}