diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index 7059ad05ca497d8fd48505055eead37d598a11b5..491025ac51f415445ecbd3ceb728b08344433f6d 100644 --- a/src/header/stdio/mod.rs +++ b/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` diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 100c9e6c8081ddd41d80b0b2c022469b3b2f2e31..564033201ee79a8c486706dd331cf6a6d10bb512 100644 --- a/src/header/unistd/mod.rs +++ b/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] diff --git a/src/ld_so/mod.rs b/src/ld_so/mod.rs index 2eaf9061ebe10c4e4497b07b5d7262432b596d75..cbc27567bc503bffb8645fd90e8d9b23cb72ceba 100644 --- a/src/ld_so/mod.rs +++ b/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), }; diff --git a/src/ld_so/start.rs b/src/ld_so/start.rs index a05e67185c83441be326175055c4870d34fb0353..a5ae510dcec2cf51f9a78fae01b66dd4c841b74b 100644 --- a/src/ld_so/start.rs +++ b/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 { diff --git a/src/macros.rs b/src/macros.rs index f870522b9c46b3ec4453c5a1b372d8c093d9a8a7..132d784186e16994125fed666518ae6d0e682a81 100644 --- a/src/macros.rs +++ b/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] diff --git a/src/mutex.rs b/src/mutex.rs index 3e3d5df226fabc32f73b1952cfb44ffa49150cda..34ff1ed44dd34027aea088e10b101dd03f3f533c 100644 --- a/src/mutex.rs +++ b/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); } diff --git a/src/start.rs b/src/start.rs index a918e6dd7368afc07e2d6e20d1cff880ba97c395..e3c02fbb6359a14f49e47e8aad308ca52e8537c8 100644 --- a/src/start.rs +++ b/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 {