From 130121dd61a9adf70d1800ceb03007275bfb589d Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 7 May 2020 14:29:28 +0200 Subject: Added wait syscall --- src/kernel/syscall/actions/sys_wait.c | 24 ++++++++++++++++++++++++ src/kernel/syscall/syscall.c | 1 + src/kernel/syscall/syscall.h | 2 ++ src/kernel/tasks/process.c | 4 ++-- src/kernel/tasks/process.h | 4 ++-- 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 src/kernel/syscall/actions/sys_wait.c (limited to 'src/kernel') diff --git a/src/kernel/syscall/actions/sys_wait.c b/src/kernel/syscall/actions/sys_wait.c new file mode 100644 index 0000000..7cea24f --- /dev/null +++ b/src/kernel/syscall/actions/sys_wait.c @@ -0,0 +1,24 @@ +#include + +u32 sys_wait(u32 pid, u32 *status, u32 options) +{ + u32 ret; + + if (pid < 0) { // Wait for any process in gid to die + ret = process_wait_gid(pid * -1, status); + } + + if (pid == -1) { // Wait for any child to be killed + ret = process_wait_gid(current_proc->pid, status); + } + + if (pid == 0) { // Wait for siblings of this process to die + ret = process_wait_gid(current_proc->gid, status); + } + + if (pid > 0) { // Wait for pid to die + ret = process_wait_pid(pid, status); + } + + return ret; +} \ No newline at end of file diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c index 958428a..f1ee003 100644 --- a/src/kernel/syscall/syscall.c +++ b/src/kernel/syscall/syscall.c @@ -15,6 +15,7 @@ u32 (*syscalls[])() = { [SYS_HALT] = (u32(*)())halt_loop, // DEBUG! [SYS_READ] = sys_read, [SYS_WRITE] = sys_write, [SYS_EXEC] = sys_exec, + [SYS_WAIT] = sys_wait, [SYS_GET_PID] = sys_get_pid, [SYS_MALLOC] = sys_malloc, [SYS_FREE] = sys_free, diff --git a/src/kernel/syscall/syscall.h b/src/kernel/syscall/syscall.h index bc52e74..c5167a4 100644 --- a/src/kernel/syscall/syscall.h +++ b/src/kernel/syscall/syscall.h @@ -18,6 +18,8 @@ u32 sys_write(char *path, u32 offset, u32 count, u8 *buf); u32 sys_exec(char *path); +u32 sys_wait(u32 pid, u32 *status, u32 options); + u32 sys_get_pid(); u32 sys_malloc(u32 count); diff --git a/src/kernel/tasks/process.c b/src/kernel/tasks/process.c index efacc1f..d2a75fd 100644 --- a/src/kernel/tasks/process.c +++ b/src/kernel/tasks/process.c @@ -84,7 +84,7 @@ u32 process_spawn(struct process *process) return process->pid; } -int process_wait_gid(u32 gid, int *status) +u32 process_wait_gid(u32 gid, u32 *status) { struct process *i = root; @@ -101,7 +101,7 @@ int process_wait_gid(u32 gid, int *status) return WAIT_OKAY; } -int process_wait_pid(u32 pid, int *status) +u32 process_wait_pid(u32 pid, u32 *status) { struct process *i = current_proc->next; diff --git a/src/kernel/tasks/process.h b/src/kernel/tasks/process.h index bd6a6e7..9aae9bc 100644 --- a/src/kernel/tasks/process.h +++ b/src/kernel/tasks/process.h @@ -45,8 +45,8 @@ void process_wake(u32 pid); u32 process_child(struct process *process, u32 pid); u32 process_fork(u32 pid); -int process_wait_gid(u32 gid, int *status); -int process_wait_pid(u32 pid, int *status); +u32 process_wait_gid(u32 gid, u32 *status); +u32 process_wait_pid(u32 pid, u32 *status); struct process *process_from_pid(u32 pid); -- cgit v1.2.3