2
0
Jeremy Soller 5 жил өмнө
parent
commit
05f71567ab

+ 5 - 1
src/header/stdio/mod.rs

@@ -419,7 +419,11 @@ pub unsafe extern "C" fn fputs(s: *const c_char, stream: *mut FILE) -> c_int {
     let mut stream = (*stream).lock();
     let buf = slice::from_raw_parts(s as *mut u8, strlen(s));
 
-    if stream.write_all(&buf).is_ok() { 0 } else { -1 }
+    if stream.write_all(&buf).is_ok() {
+        0
+    } else {
+        -1
+    }
 }
 
 /// Read `nitems` of size `size` into `ptr` from `stream`

+ 5 - 4
src/header/unistd/mod.rs

@@ -12,9 +12,9 @@ use header::sys_ioctl;
 use header::sys_time;
 use header::termios;
 use header::time::timespec;
+use platform;
 use platform::types::*;
 use platform::{Pal, Sys};
-use platform;
 
 pub use self::brk::*;
 pub use self::getopt::*;
@@ -50,9 +50,10 @@ pub static mut fork_hooks_static: Option<[LinkedList<extern "C" fn()>; 3]> = Non
 unsafe fn init_fork_hooks<'a>() -> &'a mut [LinkedList<extern "C" fn()>; 3] {
     // Transmute the lifetime so we can return here. Should be safe as
     // long as one does not access the original fork_hooks.
-    mem::transmute(fork_hooks_static.get_or_insert_with(|| {
-        [LinkedList::new(), LinkedList::new(), LinkedList::new()]
-    }))
+    mem::transmute(
+        fork_hooks_static
+            .get_or_insert_with(|| [LinkedList::new(), LinkedList::new(), LinkedList::new()]),
+    )
 }
 
 #[no_mangle]

+ 7 - 7
src/ld_so/mod.rs

@@ -1,7 +1,7 @@
 use goblin::elf::program_header::{self, program_header32, program_header64, ProgramHeader};
 
+use self::tcb::{Master, Tcb};
 use crate::start::Stack;
-use self::tcb::{Tcb, Master};
 
 pub const PAGE_SIZE: usize = 4096;
 
@@ -22,10 +22,10 @@ pub fn static_init(sp: &'static Stack) {
         }
 
         match kind {
-           3 => phdr_opt = Some(value),
-           4 => phent_opt = Some(value),
-           5 => phnum_opt = Some(value),
-           _ => (),
+            3 => phdr_opt = Some(value),
+            4 => phent_opt = Some(value),
+            5 => phnum_opt = Some(value),
+            _ => (),
         }
 
         auxv = unsafe { auxv.add(1) };
@@ -40,10 +40,10 @@ pub fn static_init(sp: &'static Stack) {
         let ph: ProgramHeader = match phent {
             program_header32::SIZEOF_PHDR => {
                 unsafe { *(ph_addr as *const program_header32::ProgramHeader) }.into()
-            },
+            }
             program_header64::SIZEOF_PHDR => {
                 unsafe { *(ph_addr as *const program_header64::ProgramHeader) }.into()
-            },
+            }
             _ => panic!("unknown AT_PHENT size {}", phent),
         };
 

+ 1 - 1
src/ld_so/start.rs

@@ -4,8 +4,8 @@ use c_str::CStr;
 use header::unistd;
 use platform::types::c_char;
 
-use crate::start::Stack;
 use super::linker::Linker;
+use crate::start::Stack;
 
 #[no_mangle]
 pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize {

+ 8 - 3
src/macros.rs

@@ -53,12 +53,17 @@ macro_rules! dbg {
         // of temporaries - https://stackoverflow.com/a/48732525/1063961
         match $val {
             tmp => {
-                eprintln!("[{}:{}] {} = {:#?}",
-                    file!(), line!(), stringify!($val), &tmp);
+                eprintln!(
+                    "[{}:{}] {} = {:#?}",
+                    file!(),
+                    line!(),
+                    stringify!($val),
+                    &tmp
+                );
                 tmp
             }
         }
-    }
+    };
 }
 
 #[macro_export]

+ 10 - 3
src/mutex.rs

@@ -1,8 +1,8 @@
 use core::cell::UnsafeCell;
 use core::ops::{Deref, DerefMut};
+use core::sync::atomic;
 use core::sync::atomic::AtomicI32 as AtomicInt;
 use core::sync::atomic::Ordering::SeqCst;
-use core::sync::atomic;
 use platform::types::*;
 use platform::{Pal, Sys};
 
@@ -45,7 +45,8 @@ impl<T> Mutex<T> {
     /// on failure. You should probably not worry about this, it's used for
     /// internal optimizations.
     pub unsafe fn manual_try_lock(&self) -> Result<&mut T, c_int> {
-        self.atomic().compare_exchange(0, 1, SeqCst, SeqCst)
+        self.atomic()
+            .compare_exchange(0, 1, SeqCst, SeqCst)
             .map(|_| &mut *self.content.get())
     }
     /// Lock the mutex, returning the inner content. After doing this, it's
@@ -70,7 +71,13 @@ impl<T> Mutex<T> {
             //
             // - Skip the atomic operation if the last value was 2, since it most likely hasn't changed.
             // - Skip the futex wait if the atomic operation says the mutex is unlocked.
-            if last == 2 || self.atomic().compare_exchange(1, 2, SeqCst, SeqCst).unwrap_or_else(|err| err) != 0 {
+            if last == 2
+                || self
+                    .atomic()
+                    .compare_exchange(1, 2, SeqCst, SeqCst)
+                    .unwrap_or_else(|err| err)
+                    != 0
+            {
                 Sys::futex(self.atomic().get_mut(), FUTEX_WAIT, 2);
             }
 

+ 1 - 1
src/start.rs

@@ -2,10 +2,10 @@ use alloc::vec::Vec;
 use core::{intrinsics, ptr};
 
 use header::{stdio, stdlib};
+use ld_so;
 use platform;
 use platform::types::*;
 use platform::{Pal, Sys};
-use ld_so;
 
 #[repr(C)]
 pub struct Stack {