From b61c07af798557eff4333716c917c99a4f0c13c6 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 13 Oct 2025 16:14:02 -0400 Subject: kern: proc: Add initial waitpid() syscall Signed-off-by: Ian Moffett --- src/sys/include/compat/unix/syscall.h | 3 ++- src/sys/include/sys/proc.h | 5 +++++ src/sys/include/sys/syscall.h | 1 + src/sys/os/os_proc.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) (limited to 'src/sys') diff --git a/src/sys/include/compat/unix/syscall.h b/src/sys/include/compat/unix/syscall.h index 7a612c3..13bd617 100644 --- a/src/sys/include/compat/unix/syscall.h +++ b/src/sys/include/compat/unix/syscall.h @@ -74,7 +74,8 @@ scret_t(*g_unix_sctab[])(struct syscall_args *) = { [SYS_open] = sys_open, [SYS_muxtap] = sys_muxtap, [SYS_getargv] = sys_getargv, - [SYS_reboot] = sys_reboot + [SYS_reboot] = sys_reboot, + [SYS_waitpid] = sys_waitpid }; #endif /* !_NEED_UNIX_SCTAB */ diff --git a/src/sys/include/sys/proc.h b/src/sys/include/sys/proc.h index bb34066..618ddf3 100644 --- a/src/sys/include/sys/proc.h +++ b/src/sys/include/sys/proc.h @@ -263,5 +263,10 @@ scret_t sys_spawn(struct syscall_args *scargs); */ scret_t sys_getargv(struct syscall_args *scargs); +/* + * Wait for a child to complete + */ +scret_t sys_waitpid(struct syscall_args *scargs); + #endif /* !_KERNEL */ #endif /* !_SYS_PROC_H_ */ diff --git a/src/sys/include/sys/syscall.h b/src/sys/include/sys/syscall.h index 9616aed..ac03055 100644 --- a/src/sys/include/sys/syscall.h +++ b/src/sys/include/sys/syscall.h @@ -54,6 +54,7 @@ #define SYS_muxtap 0x09 /* mux an I/O tap */ #define SYS_getargv 0x0A /* get process argv */ #define SYS_reboot 0x0B /* reboot the system */ +#define SYS_waitpid 0x0C /* wait for child to exit */ typedef __ssize_t scret_t; typedef __ssize_t scarg_t; diff --git a/src/sys/os/os_proc.c b/src/sys/os/os_proc.c index 4ee4fd8..764b3f2 100644 --- a/src/sys/os/os_proc.c +++ b/src/sys/os/os_proc.c @@ -439,3 +439,35 @@ sys_getargv(struct syscall_args *scargs) arg = envblk->argv[argno]; return copyoutstr(arg, u_buf, maxlen); } + +/* + * Wait for a child to complete + * + * ARG0: PID + * ARG1: Status + * ARG2: Options + */ +scret_t +sys_waitpid(struct syscall_args *scargs) +{ + int pid = SCARG(scargs, int, 0); + int *u_status = SCARG(scargs, int *, 1); + int status = 0; + int error = 0; + struct proc *proc, *self; + + if ((proc = proc_lookup(pid)) == NULL) { + return -ESRCH; + } + + if (u_status != NULL) { + error = copyout(&status, u_status, sizeof(*u_status)); + } + if (error < 0) { + return error; + } + + self = proc_self(); + proc_sleep(self); + return 0; +} -- cgit v1.2.3