Jeremy Soller 8 rokov pred
rodič
commit
6149ff3090
3 zmenil súbory, kde vykonal 19 pridanie a 16 odobranie
  1. 7 3
      shim/src/lib.rs
  2. 7 7
      shim/src/redox.rs
  3. 5 6
      shim/src/unix.rs

+ 7 - 3
shim/src/lib.rs

@@ -7,9 +7,13 @@
 #![warn(missing_docs)]
 
 #[cfg(redox)]
-mod redox as imp;
+mod redox;
+
+#[cfg(redox)]
+pub use redox::*;
 
 #[cfg(not(redox))]
-mod unix as imp;
+mod unix;
 
-pub use imp::*;
+#[cfg(not(redox))]
+pub use unix::*;

+ 7 - 7
shim/src/redox.rs

@@ -1,10 +1,10 @@
-extern crate system;
+extern crate syscall;
 
-use system::syscall::unix::{sys_brk, sys_write, sys_yield};
+use self::syscall;
 
 /// Cooperatively gives up a timeslice to the OS scheduler.
 pub extern "C" fn sched_yield() -> isize {
-    match sys_yield() {
+    match syscall::sched_yield() {
         Ok(_) => 0,
         Err(_) => -1
     }
@@ -18,7 +18,7 @@ pub extern "C" fn sched_yield() -> isize {
 /// This is unsafe for multiple reasons. Most importantly, it can create an inconsistent state,
 /// because it is not atomic. Thus, it can be used to create Undefined Behavior.
 pub extern "C" fn sbrk(n: isize) -> *mut u8 {
-    let orig_seg_end = match unsafe { sys_brk(0) } {
+    let orig_seg_end = match unsafe { syscall::brk(0) } {
         Ok(end) => end,
         Err(_) => return !0 as *mut u8
     };
@@ -32,14 +32,14 @@ pub extern "C" fn sbrk(n: isize) -> *mut u8 {
         None => return !0 as *mut u8
     };
 
-    let new_seg_end = match unsafe { sys_brk(expected_end) } {
+    let new_seg_end = match unsafe { syscall::brk(expected_end) } {
         Ok(end) => end,
         Err(_) => return !0 as *mut u8
     };
 
     if new_seg_end != expected_end {
         // Reset the break.
-        let _ = unsafe { sys_brk(orig_seg_end) };
+        let _ = unsafe { syscall::brk(orig_seg_end) };
 
         !0 as *mut u8
     } else {
@@ -51,7 +51,7 @@ pub extern "C" fn sbrk(n: isize) -> *mut u8 {
 ///
 /// This points to stderr, but could be changed arbitrarily.
 pub fn log(s: &str) -> isize {
-    sys_write(2, s.as_bytes()).map(|count| count as isize).unwrap_or(-1)
+    syscall::write(2, s.as_bytes()).map(|count| count as isize).unwrap_or(-1)
 }
 
 pub mod thread_destructor {

+ 5 - 6
shim/src/unix.rs

@@ -1,7 +1,6 @@
-
 extern crate libc;
 
-pub use libc::sched_yield;
+pub use self::libc::sched_yield;
 
 extern {
     /// Change the data segment. See `man sbrk`.
@@ -20,7 +19,7 @@ pub fn log(s: &str) -> libc::ssize_t {
 /// Thread destructors for Linux.
 #[cfg(target_os = "linux")]
 pub mod thread_destructor {
-    use libc;
+    use super::libc;
 
     extern {
         #[linkage = "extern_weak"]
@@ -34,7 +33,7 @@ pub mod thread_destructor {
     /// This will return true, if and only if `__cxa_thread_atexit_impl` is non-null.
     #[inline]
     pub fn is_supported() -> bool {
-        !__cxa_thread_atexit_impl.is_null()
+        unsafe { !__cxa_thread_atexit_impl.is_null() }
     }
 
     /// Register a thread destructor.
@@ -60,7 +59,7 @@ pub mod thread_destructor {
 /// Thread destructors for Mac OS.
 #[cfg(target_os = "macos")]
 pub mod thread_destructor {
-    use libc;
+    use super::libc;
 
     /// Does this platform support thread destructors?
     ///
@@ -86,7 +85,7 @@ pub mod thread_destructor {
 
 /// Debugging.
 pub mod debug {
-    use libc;
+    use super::libc;
 
     extern {
         /// Valgrind symbol to declare memory undefined.