diff --git a/src/libstd/sys/redox/net/netc.rs b/src/libstd/sys/redox/net/netc.rs index 03e1c9fffa4d0..d443a4d68a170 100644 --- a/src/libstd/sys/redox/net/netc.rs +++ b/src/libstd/sys/redox/net/netc.rs @@ -14,8 +14,8 @@ pub type in_port_t = u16; pub type socklen_t = u32; pub type sa_family_t = u16; -pub const AF_INET: sa_family_t = 1; -pub const AF_INET6: sa_family_t = 2; +pub const AF_INET: sa_family_t = 2; +pub const AF_INET6: sa_family_t = 23; #[derive(Copy, Clone)] #[repr(C)] diff --git a/src/libstd/sys/redox/syscall/call.rs b/src/libstd/sys/redox/syscall/call.rs index 9fc809eb821d8..7770a2f3f1b5a 100644 --- a/src/libstd/sys/redox/syscall/call.rs +++ b/src/libstd/sys/redox/syscall/call.rs @@ -9,11 +9,17 @@ // except according to those terms. use super::arch::*; -use super::data::{Stat, StatVfs, TimeSpec}; +use super::data::{SigAction, Stat, StatVfs, TimeSpec}; use super::error::Result; use super::number::*; -use core::mem; +use core::{mem, ptr}; + +// Signal restorer +extern "C" fn restorer() -> ! { + sigreturn().unwrap(); + unreachable!(); +} /// Set the end of the process's heap /// @@ -43,12 +49,12 @@ pub unsafe fn brk(addr: usize) -> Result { /// * `EIO` - an I/O error occurred /// * `ENOENT` - `path` does not exit /// * `ENOTDIR` - `path` is not a directory -pub fn chdir(path: &str) -> Result { - unsafe { syscall2(SYS_CHDIR, path.as_ptr() as usize, path.len()) } +pub fn chdir>(path: T) -> Result { + unsafe { syscall2(SYS_CHDIR, path.as_ref().as_ptr() as usize, path.as_ref().len()) } } -pub fn chmod(path: &str, mode: usize) -> Result { - unsafe { syscall3(SYS_CHMOD, path.as_ptr() as usize, path.len(), mode) } +pub fn chmod>(path: T, mode: usize) -> Result { + unsafe { syscall3(SYS_CHMOD, path.as_ref().as_ptr() as usize, path.as_ref().len(), mode) } } /// Produce a fork of the current process, or a new process thread @@ -132,6 +138,12 @@ pub fn ftruncate(fd: usize, len: usize) -> Result { unsafe { syscall2(SYS_FTRUNCATE, fd, len) } } +// Change modify and/or access times +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 pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32) -> Result { @@ -173,6 +185,16 @@ pub fn getpid() -> Result { unsafe { syscall0(SYS_GETPID) } } +/// Get the process group ID +pub fn getpgid(pid: usize) -> Result { + unsafe { syscall1(SYS_GETPGID, pid) } +} + +/// Get the parent process ID +pub fn getppid() -> Result { + unsafe { syscall0(SYS_GETPPID) } +} + /// Get the current user ID pub fn getuid() -> Result { unsafe { syscall0(SYS_GETUID) } @@ -210,8 +232,8 @@ pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result { } /// Open a file -pub fn open(path: &str, flags: usize) -> Result { - unsafe { syscall3(SYS_OPEN, path.as_ptr() as usize, path.len(), flags) } +pub fn open>(path: T, flags: usize) -> Result { + unsafe { syscall3(SYS_OPEN, path.as_ref().as_ptr() as usize, path.as_ref().len(), flags) } } /// Allocate pages, linearly in physical memory @@ -245,8 +267,13 @@ pub fn read(fd: usize, buf: &mut [u8]) -> Result { } /// Remove a directory -pub fn rmdir(path: &str) -> Result { - unsafe { syscall2(SYS_RMDIR, path.as_ptr() as usize, path.len()) } +pub fn rmdir>(path: T) -> Result { + unsafe { syscall2(SYS_RMDIR, path.as_ref().as_ptr() as usize, path.as_ref().len()) } +} + +/// Set the process group ID +pub fn setpgid(pid: usize, pgid: usize) -> Result { + unsafe { syscall2(SYS_SETPGID, pid, pgid) } } /// Set the current process group IDs @@ -264,9 +291,23 @@ pub fn setreuid(ruid: usize, euid: usize) -> Result { unsafe { syscall2(SYS_SETREUID, ruid, euid) } } +/// Set up a signal handler +pub fn sigaction(sig: usize, act: Option<&SigAction>, oldact: Option<&mut SigAction>) +-> Result { + unsafe { syscall4(SYS_SIGACTION, sig, + act.map(|x| x as *const _).unwrap_or_else(ptr::null) as usize, + oldact.map(|x| x as *mut _).unwrap_or_else(ptr::null_mut) as usize, + restorer as usize) } +} + +// Return from signal handler +pub fn sigreturn() -> Result { + unsafe { syscall0(SYS_SIGRETURN) } +} + /// Remove a file -pub fn unlink(path: &str) -> Result { - unsafe { syscall2(SYS_UNLINK, path.as_ptr() as usize, path.len()) } +pub fn unlink>(path: T) -> Result { + unsafe { syscall2(SYS_UNLINK, path.as_ref().as_ptr() as usize, path.as_ref().len()) } } /// Convert a virtual address to a physical one diff --git a/src/libstd/sys/redox/syscall/data.rs b/src/libstd/sys/redox/syscall/data.rs index 0beb173477d90..2e784ebc8a5c5 100644 --- a/src/libstd/sys/redox/syscall/data.rs +++ b/src/libstd/sys/redox/syscall/data.rs @@ -11,6 +11,90 @@ use core::ops::{Deref, DerefMut}; use core::{mem, slice}; +#[derive(Copy, Clone, Debug, Default)] +pub struct Event { + pub id: usize, + pub flags: usize, + pub data: usize +} + +impl Deref for Event { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts( + self as *const Event as *const u8, + mem::size_of::() + ) as &[u8] + } + } +} + +impl DerefMut for Event { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut( + self as *mut Event as *mut u8, + mem::size_of::() + ) as &mut [u8] + } + } +} + +#[derive(Copy, Clone, Debug, Default)] +#[repr(C)] +pub struct Packet { + pub id: u64, + pub pid: usize, + pub uid: u32, + pub gid: u32, + pub a: usize, + pub b: usize, + pub c: usize, + pub d: usize +} + +impl Deref for Packet { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts( + self as *const Packet as *const u8, + mem::size_of::() + ) as &[u8] + } + } +} + +impl DerefMut for Packet { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut( + self as *mut Packet as *mut u8, + mem::size_of::() + ) as &mut [u8] + } + } +} + +#[derive(Copy, Clone, Debug)] +#[repr(C)] +pub struct SigAction { + pub sa_handler: extern "C" fn(usize), + pub sa_mask: [u64; 2], + pub sa_flags: usize, +} + +impl Default for SigAction { + fn default() -> Self { + Self { + sa_handler: unsafe { mem::transmute(0usize) }, + sa_mask: [0; 2], + sa_flags: 0, + } + } +} + #[derive(Copy, Clone, Debug, Default)] #[repr(C)] pub struct Stat { @@ -35,8 +119,10 @@ 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] } } } @@ -44,8 +130,10 @@ 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] } } } @@ -63,8 +151,10 @@ 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] } } } @@ -72,8 +162,10 @@ 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] } } } @@ -89,8 +181,10 @@ impl Deref for TimeSpec { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const TimeSpec as *const u8, - mem::size_of::()) as &[u8] + slice::from_raw_parts( + self as *const TimeSpec as *const u8, + mem::size_of::() + ) as &[u8] } } } @@ -98,8 +192,10 @@ impl Deref for TimeSpec { impl DerefMut for TimeSpec { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut TimeSpec as *mut u8, - mem::size_of::()) as &mut [u8] + slice::from_raw_parts_mut( + self as *mut TimeSpec as *mut u8, + mem::size_of::() + ) as &mut [u8] } } } diff --git a/src/libstd/sys/redox/syscall/flag.rs b/src/libstd/sys/redox/syscall/flag.rs index 892007df2b7c6..0f61b9fa77b52 100644 --- a/src/libstd/sys/redox/syscall/flag.rs +++ b/src/libstd/sys/redox/syscall/flag.rs @@ -11,7 +11,9 @@ pub const CLONE_VM: usize = 0x100; 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; @@ -20,6 +22,7 @@ pub const EVENT_NONE: usize = 0; pub const EVENT_READ: usize = 1; pub const EVENT_WRITE: usize = 2; +pub const F_DUPFD: usize = 0; pub const F_GETFD: usize = 1; pub const F_SETFD: usize = 2; pub const F_GETFL: usize = 3; @@ -36,6 +39,8 @@ pub const MODE_TYPE: u16 = 0xF000; pub const MODE_DIR: u16 = 0x4000; pub const MODE_FILE: u16 = 0x8000; pub const MODE_SYMLINK: u16 = 0xA000; +pub const MODE_FIFO: u16 = 0x1000; +pub const MODE_CHR: u16 = 0x2000; pub const MODE_PERM: u16 = 0x0FFF; pub const MODE_SETUID: u16 = 0o4000; @@ -96,4 +101,16 @@ pub const SIGIO: usize = 29; pub const SIGPWR: usize = 30; pub const SIGSYS: usize = 31; +pub const SIG_DFL: usize = 0; +pub const SIG_IGN: usize = 1; + +pub const SA_NOCLDSTOP: usize = 0x00000001; +pub const SA_NOCLDWAIT: usize = 0x00000002; +pub const SA_SIGINFO: usize = 0x00000004; +pub const SA_RESTORER: usize = 0x04000000; +pub const SA_ONSTACK: usize = 0x08000000; +pub const SA_RESTART: usize = 0x10000000; +pub const SA_NODEFER: usize = 0x40000000; +pub const SA_RESETHAND: usize = 0x80000000; + pub const WNOHANG: usize = 1; diff --git a/src/libstd/sys/redox/syscall/number.rs b/src/libstd/sys/redox/syscall/number.rs index 98f8b73e4e1bb..07db91647ff68 100644 --- a/src/libstd/sys/redox/syscall/number.rs +++ b/src/libstd/sys/redox/syscall/number.rs @@ -41,6 +41,7 @@ pub const SYS_FSTAT: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 28; pub const SYS_FSTATVFS: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 100; pub const SYS_FSYNC: usize = SYS_CLASS_FILE | 118; pub const SYS_FTRUNCATE: usize =SYS_CLASS_FILE | 93; +pub const SYS_FUTIMENS: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 320; pub const SYS_BRK: usize = 45; pub const SYS_CHDIR: usize = 12; @@ -56,6 +57,8 @@ pub const SYS_GETEUID: usize = 201; pub const SYS_GETGID: usize = 200; pub const SYS_GETNS: usize = 950; pub const SYS_GETPID: usize = 20; +pub const SYS_GETPGID: usize = 132; +pub const SYS_GETPPID: usize = 64; pub const SYS_GETUID: usize = 199; pub const SYS_IOPL: usize = 110; pub const SYS_KILL: usize = 37; @@ -67,8 +70,11 @@ pub const SYS_PHYSMAP: usize = 947; pub const SYS_PHYSUNMAP: usize =948; pub const SYS_VIRTTOPHYS: usize=949; pub const SYS_PIPE2: usize = 331; +pub const SYS_SETPGID: usize = 57; pub const SYS_SETREGID: usize = 204; pub const SYS_SETRENS: usize = 952; pub const SYS_SETREUID: usize = 203; +pub const SYS_SIGACTION: usize =67; +pub const SYS_SIGRETURN: usize =119; pub const SYS_WAITPID: usize = 7; pub const SYS_YIELD: usize = 158;