diff options
author | dzwdz | 2023-06-10 16:26:46 +0200 |
---|---|---|
committer | dzwdz | 2023-06-10 16:26:46 +0200 |
commit | b09263bd64b3408cbd109dacc4b7618d22b02248 (patch) | |
tree | e461c86fdf229670451f657ef83dd1e2ac802bba /src/kernel | |
parent | 112eafe13c3628cad6e692179c064dbbc3be2d8b (diff) |
kernel: implement getpid, getppid
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/proc.h | 1 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/kernel/proc.h b/src/kernel/proc.h index dce99fb..bf5db69 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -69,6 +69,7 @@ struct Proc { Handle *procfs; } specialh; + // TODO pids should be 64bit. also typedef pid_t uint32_t globalid; /* only for internal use, don't expose to userland */ uint32_t refcount; /* non-owning. should always be 0 on kill */ bool noreap; diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 589098b..03d9ef1 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -388,6 +388,20 @@ void _sys_intr_set(void __user *ip) { proc_cur->intr_fn = ip; } +uint32_t _sys_getpid(void) { + SYSCALL_RETURN(proc_ns_id(proc_cur->pns, proc_cur)); +} + +uint32_t _sys_getppid(void) { + if (proc_cur->pns == proc_cur) { + SYSCALL_RETURN(0); + } else { + assert(proc_cur->parent); + assert(proc_cur->parent->pns == proc_cur->pns); + SYSCALL_RETURN(proc_ns_id(proc_cur->pns, proc_cur->parent)); + } +} + long _sys_execbuf(void __user *ubuf, size_t len) { if (len == 0) SYSCALL_RETURN(0); if (len > EXECBUF_MAX_LEN) @@ -440,6 +454,8 @@ long _syscall(long num, long a, long b, long c, long d, long e) { break; case _SYS_FILICIDE: _sys_filicide(); break; case _SYS_INTR: _sys_intr(); break; case _SYS_INTR_SET: _sys_intr_set((userptr_t)a); + break; case _SYS_GETPID: _sys_getpid(); + break; case _SYS_GETPPID: _sys_getppid(); break; case _SYS_EXECBUF: _sys_execbuf((userptr_t)a, b); break; case _SYS_DEBUG_KLOG: _sys_debug_klog((userptr_t)a, b); break; |