99// except according to those terms.
1010
1111use super :: arch:: * ;
12- use super :: data:: { Stat , StatVfs , TimeSpec } ;
12+ use super :: data:: { SigAction , Stat , StatVfs , TimeSpec } ;
1313use super :: error:: Result ;
1414use super :: number:: * ;
1515
16- use core:: mem;
16+ use core:: { mem, ptr} ;
17+
18+ // Signal restorer
19+ extern "C" fn restorer ( ) -> ! {
20+ sigreturn ( ) . unwrap ( ) ;
21+ unreachable ! ( ) ;
22+ }
1723
1824/// Set the end of the process's heap
1925///
@@ -43,12 +49,12 @@ pub unsafe fn brk(addr: usize) -> Result<usize> {
4349/// * `EIO` - an I/O error occurred
4450/// * `ENOENT` - `path` does not exit
4551/// * `ENOTDIR` - `path` is not a directory
46- pub fn chdir ( path : & str ) -> Result < usize > {
47- unsafe { syscall2 ( SYS_CHDIR , path. as_ptr ( ) as usize , path. len ( ) ) }
52+ pub fn chdir < T : AsRef < [ u8 ] > > ( path : T ) -> Result < usize > {
53+ unsafe { syscall2 ( SYS_CHDIR , path. as_ref ( ) . as_ptr ( ) as usize , path. as_ref ( ) . len ( ) ) }
4854}
4955
50- pub fn chmod ( path : & str , mode : usize ) -> Result < usize > {
51- unsafe { syscall3 ( SYS_CHMOD , path. as_ptr ( ) as usize , path. len ( ) , mode) }
56+ pub fn chmod < T : AsRef < [ u8 ] > > ( path : T , mode : usize ) -> Result < usize > {
57+ unsafe { syscall3 ( SYS_CHMOD , path. as_ref ( ) . as_ptr ( ) as usize , path. as_ref ( ) . len ( ) , mode) }
5258}
5359
5460/// Produce a fork of the current process, or a new process thread
@@ -132,6 +138,12 @@ pub fn ftruncate(fd: usize, len: usize) -> Result<usize> {
132138 unsafe { syscall2 ( SYS_FTRUNCATE , fd, len) }
133139}
134140
141+ // Change modify and/or access times
142+ pub fn futimens ( fd : usize , times : & [ TimeSpec ] ) -> Result < usize > {
143+ unsafe { syscall3 ( SYS_FUTIMENS , fd, times. as_ptr ( ) as usize ,
144+ times. len ( ) * mem:: size_of :: < TimeSpec > ( ) ) }
145+ }
146+
135147/// Fast userspace mutex
136148pub unsafe fn futex ( addr : * mut i32 , op : usize , val : i32 , val2 : usize , addr2 : * mut i32 )
137149 -> Result < usize > {
@@ -173,6 +185,16 @@ pub fn getpid() -> Result<usize> {
173185 unsafe { syscall0 ( SYS_GETPID ) }
174186}
175187
188+ /// Get the process group ID
189+ pub fn getpgid ( pid : usize ) -> Result < usize > {
190+ unsafe { syscall1 ( SYS_GETPGID , pid) }
191+ }
192+
193+ /// Get the parent process ID
194+ pub fn getppid ( ) -> Result < usize > {
195+ unsafe { syscall0 ( SYS_GETPPID ) }
196+ }
197+
176198/// Get the current user ID
177199pub fn getuid ( ) -> Result < usize > {
178200 unsafe { syscall0 ( SYS_GETUID ) }
@@ -210,8 +232,8 @@ pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result<usize> {
210232}
211233
212234/// Open a file
213- pub fn open ( path : & str , flags : usize ) -> Result < usize > {
214- unsafe { syscall3 ( SYS_OPEN , path. as_ptr ( ) as usize , path. len ( ) , flags) }
235+ pub fn open < T : AsRef < [ u8 ] > > ( path : T , flags : usize ) -> Result < usize > {
236+ unsafe { syscall3 ( SYS_OPEN , path. as_ref ( ) . as_ptr ( ) as usize , path. as_ref ( ) . len ( ) , flags) }
215237}
216238
217239/// Allocate pages, linearly in physical memory
@@ -245,8 +267,13 @@ pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
245267}
246268
247269/// Remove a directory
248- pub fn rmdir ( path : & str ) -> Result < usize > {
249- unsafe { syscall2 ( SYS_RMDIR , path. as_ptr ( ) as usize , path. len ( ) ) }
270+ pub fn rmdir < T : AsRef < [ u8 ] > > ( path : T ) -> Result < usize > {
271+ unsafe { syscall2 ( SYS_RMDIR , path. as_ref ( ) . as_ptr ( ) as usize , path. as_ref ( ) . len ( ) ) }
272+ }
273+
274+ /// Set the process group ID
275+ pub fn setpgid ( pid : usize , pgid : usize ) -> Result < usize > {
276+ unsafe { syscall2 ( SYS_SETPGID , pid, pgid) }
250277}
251278
252279/// Set the current process group IDs
@@ -264,9 +291,23 @@ pub fn setreuid(ruid: usize, euid: usize) -> Result<usize> {
264291 unsafe { syscall2 ( SYS_SETREUID , ruid, euid) }
265292}
266293
294+ /// Set up a signal handler
295+ pub fn sigaction ( sig : usize , act : Option < & SigAction > , oldact : Option < & mut SigAction > )
296+ -> Result < usize > {
297+ unsafe { syscall4 ( SYS_SIGACTION , sig,
298+ act. map ( |x| x as * const _ ) . unwrap_or_else ( ptr:: null) as usize ,
299+ oldact. map ( |x| x as * mut _ ) . unwrap_or_else ( ptr:: null_mut) as usize ,
300+ restorer as usize ) }
301+ }
302+
303+ // Return from signal handler
304+ pub fn sigreturn ( ) -> Result < usize > {
305+ unsafe { syscall0 ( SYS_SIGRETURN ) }
306+ }
307+
267308/// Remove a file
268- pub fn unlink ( path : & str ) -> Result < usize > {
269- unsafe { syscall2 ( SYS_UNLINK , path. as_ptr ( ) as usize , path. len ( ) ) }
309+ pub fn unlink < T : AsRef < [ u8 ] > > ( path : T ) -> Result < usize > {
310+ unsafe { syscall2 ( SYS_UNLINK , path. as_ref ( ) . as_ptr ( ) as usize , path. as_ref ( ) . len ( ) ) }
270311}
271312
272313/// Convert a virtual address to a physical one
0 commit comments