From dddd87c2c38f984242e3d71423ecc959c7a9d98c Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 28 Jun 2017 22:05:01 -0700 Subject: [PATCH] Implement getppid system call --- src/syscall/mod.rs | 1 + src/syscall/process.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/syscall/mod.rs b/src/syscall/mod.rs index 1d9cea6..5e9d59a 100644 --- a/src/syscall/mod.rs +++ b/src/syscall/mod.rs @@ -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), diff --git a/src/syscall/process.rs b/src/syscall/process.rs index 8a86ba0..d32adec 100644 --- a/src/syscall/process.rs +++ b/src/syscall/process.rs @@ -925,6 +925,13 @@ pub fn getpid() -> Result { Ok(context.id) } +pub fn getppid() -> Result { + 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 { let (ruid, euid) = { let contexts = context::contexts();