Implement getppid system call

This commit is contained in:
Ian Douglas Scott
2017-06-28 22:05:01 -07:00
parent 12d487ec9c
commit dddd87c2c3
2 changed files with 8 additions and 0 deletions

View File

@@ -75,6 +75,7 @@ pub extern fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize
SYS_FUTEX => futex(validate_slice_mut(b as *mut i32, 1).map(|uaddr| &mut uaddr[0])?, c, d as i32, e, f as *mut i32),
SYS_BRK => brk(b),
SYS_GETPID => getpid().map(ContextId::into),
SYS_GETPPID => getppid().map(ContextId::into),
SYS_CLONE => clone(b, stack).map(ContextId::into),
SYS_EXIT => exit((b & 0xFF) << 8),
SYS_KILL => kill(ContextId::from(b), c),

View File

@@ -925,6 +925,13 @@ pub fn getpid() -> Result<ContextId> {
Ok(context.id)
}
pub fn getppid() -> Result<ContextId> {
let contexts = context::contexts();
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
let context = context_lock.read();
Ok(context.ppid)
}
pub fn kill(pid: ContextId, sig: usize) -> Result<usize> {
let (ruid, euid) = {
let contexts = context::contexts();