diff --git a/src/arch/arm.rs b/src/arch/arm.rs index 9e4dd082bd..e640f7ed37 100644 --- a/src/arch/arm.rs +++ b/src/arch/arm.rs @@ -1,4 +1,4 @@ -use error::{Error, Result}; +use super::error::{Error, Result}; pub unsafe fn syscall0(mut a: usize) -> Result { asm!("swi $$0" @@ -61,7 +61,8 @@ pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Error::demux(a) } -pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result { +pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) + -> Result { asm!("swi $$0" : "={r0}"(a) : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d), "{r3}"(e), "{r4}"(f) diff --git a/src/arch/x86.rs b/src/arch/x86.rs index 3196189cf2..0cd6409bb0 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -1,4 +1,4 @@ -use error::{Error, Result}; +use super::error::{Error, Result}; pub unsafe fn syscall0(mut a: usize) -> Result { asm!("int 0x80" @@ -61,7 +61,8 @@ pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Error::demux(a) } -pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result { +pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) + -> Result { asm!("int 0x80" : "={eax}"(a) : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d), "{esi}"(e), "{edi}"(f) diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index 84d5769176..52ad01bd4a 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -1,4 +1,4 @@ -use error::{Error, Result}; +use super::error::{Error, Result}; pub unsafe fn syscall0(mut a: usize) -> Result { asm!("int 0x80" @@ -25,7 +25,8 @@ pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result { asm!("int 0x80" : "={rax}"(a) : "{rax}"(a), "{rbx}"(b) - : "memory", "rbx", "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" + : "memory", "rbx", "rcx", "rdx", "rsi", "rdi", "r8", + "r9", "r10", "r11", "r12", "r13", "r14", "r15" : "intel", "volatile"); Error::demux(a) @@ -61,7 +62,8 @@ pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Error::demux(a) } -pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result { +pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) + -> Result { asm!("int 0x80" : "={rax}"(a) : "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d), "{rsi}"(e), "{rdi}"(f) diff --git a/src/call.rs b/src/call.rs index 212338ad73..9dd081a776 100644 --- a/src/call.rs +++ b/src/call.rs @@ -36,7 +36,7 @@ pub unsafe fn brk(addr: usize) -> Result { /// /// * `EACCES` - permission is denied for one of the components of `path`, or `path` /// * `EFAULT` - `path` does not point to the process's addressible memory -/// * `EIO` - an I/O error occured +/// * `EIO` - an I/O error occurred /// * `ENOENT` - `path` does not exit /// * `ENOTDIR` - `path` is not a directory pub fn chdir>(path: T) -> Result { @@ -74,7 +74,8 @@ pub fn dup2(fd: usize, newfd: usize, buf: &[u8]) -> Result { /// Replace the current process with a new executable pub fn execve>(path: T, args: &[[usize; 2]]) -> Result { - unsafe { syscall4(SYS_EXECVE, path.as_ref().as_ptr() as usize, path.as_ref().len(), args.as_ptr() as usize, args.len()) } + unsafe { syscall4(SYS_EXECVE, path.as_ref().as_ptr() as usize, + path.as_ref().len(), args.as_ptr() as usize, args.len()) } } /// Exit the current process @@ -132,8 +133,9 @@ pub fn futimens(fd: usize, times: &[TimeSpec]) -> Result { unsafe { syscall3(SYS_FUTIMENS, fd, times.as_ptr() as usize, times.len() * mem::size_of::()) } } -/// Fast userspace mutex - TODO: Document -pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32) -> Result { +/// Fast userspace mutex +pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32) + -> Result { syscall5(SYS_FUTEX, addr as usize, op, (val as isize) as usize, val2, addr2 as usize) } @@ -214,7 +216,8 @@ pub fn mkns(schemes: &[[usize; 2]]) -> Result { /// Sleep for the time specified in `req` pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result { - unsafe { syscall2(SYS_NANOSLEEP, req as *const TimeSpec as usize, rem as *mut TimeSpec as usize) } + unsafe { syscall2(SYS_NANOSLEEP, req as *const TimeSpec as usize, + rem as *mut TimeSpec as usize) } } /// Open a file @@ -316,7 +319,7 @@ pub fn waitpid(pid: usize, status: &mut usize, options: usize) -> Result /// * `EAGAIN` - the file descriptor was opened with `O_NONBLOCK` and writing would block /// * `EBADF` - the file descriptor is not valid or is not open for writing /// * `EFAULT` - `buf` does not point to the process's addressible memory -/// * `EIO` - an I/O error occured +/// * `EIO` - an I/O error occurred /// * `ENOSPC` - the device containing the file descriptor has no room for data /// * `EPIPE` - the file descriptor refers to a pipe or socket whose reading end is closed pub fn write(fd: usize, buf: &[u8]) -> Result { diff --git a/src/data.rs b/src/data.rs index 74ad159949..8e0cff43f2 100644 --- a/src/data.rs +++ b/src/data.rs @@ -97,7 +97,8 @@ impl Deref for Stat { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const Stat as *const u8, mem::size_of::()) as &[u8] + slice::from_raw_parts(self as *const Stat as *const u8, + mem::size_of::()) as &[u8] } } } @@ -105,7 +106,8 @@ impl Deref for Stat { impl DerefMut for Stat { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut Stat as *mut u8, mem::size_of::()) as &mut [u8] + slice::from_raw_parts_mut(self as *mut Stat as *mut u8, + mem::size_of::()) as &mut [u8] } } } @@ -117,14 +119,14 @@ pub struct StatVfs { pub f_blocks: u64, pub f_bfree: u64, pub f_bavail: u64, - //TODO: More fields https://linux.die.net/man/2/statvfs } impl Deref for StatVfs { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const StatVfs as *const u8, mem::size_of::()) as &[u8] + slice::from_raw_parts(self as *const StatVfs as *const u8, + mem::size_of::()) as &[u8] } } } @@ -132,7 +134,8 @@ impl Deref for StatVfs { impl DerefMut for StatVfs { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut StatVfs as *mut u8, mem::size_of::()) as &mut [u8] + slice::from_raw_parts_mut(self as *mut StatVfs as *mut u8, + mem::size_of::()) as &mut [u8] } } } diff --git a/src/flag.rs b/src/flag.rs index b8e41a914b..6cb22bc65e 100644 --- a/src/flag.rs +++ b/src/flag.rs @@ -3,6 +3,7 @@ pub const CLONE_FS: usize = 0x200; pub const CLONE_FILES: usize = 0x400; pub const CLONE_SIGHAND: usize = 0x800; pub const CLONE_VFORK: usize = 0x4000; +pub const CLONE_THREAD: usize = 0x10000; pub const CLOCK_REALTIME: usize = 1; pub const CLOCK_MONOTONIC: usize = 4; diff --git a/src/number.rs b/src/number.rs index e240c7af41..bf0ca5720c 100644 --- a/src/number.rs +++ b/src/number.rs @@ -18,7 +18,7 @@ pub const SYS_UNLINK: usize = SYS_CLASS_PATH | 10; pub const SYS_CLOSE: usize = SYS_CLASS_FILE | 6; pub const SYS_DUP: usize = SYS_CLASS_FILE | SYS_RET_FILE | 41; -pub const SYS_DUP2: usize = SYS_CLASS_FILE | SYS_RET_FILE | 63; +pub const SYS_DUP2: usize = SYS_CLASS_FILE | SYS_RET_FILE | 63; pub const SYS_READ: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 3; pub const SYS_WRITE: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 4; pub const SYS_LSEEK: usize = SYS_CLASS_FILE | 19;