diff options
author | dzwdz | 2023-08-29 23:35:03 +0200 |
---|---|---|
committer | dzwdz | 2023-08-29 23:35:03 +0200 |
commit | f71af249cfb9ca9eb0832cc46437b2c5cb7bb217 (patch) | |
tree | dcc5403d304547da397644b9d43e2bf8c67a0b3e /src | |
parent | dd385a413c92d53a1f792011e1029d7d68e19c6c (diff) |
kernel: remove _sys_await, emulate it in libc
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/init/driver/termcook.c | 1 | ||||
-rw-r--r-- | src/cmd/init/init.c | 1 | ||||
-rw-r--r-- | src/cmd/netdog/nd.c | 1 | ||||
-rw-r--r-- | src/cmd/netstack/netstack.c | 1 | ||||
-rw-r--r-- | src/cmd/shell/shell.c | 1 | ||||
-rw-r--r-- | src/cmd/tests/kernel/fdlimit.c | 1 | ||||
-rw-r--r-- | src/cmd/tests/kernel/misc.c | 1 | ||||
-rw-r--r-- | src/cmd/tests/kernel/miscsyscall.c | 1 | ||||
-rw-r--r-- | src/cmd/tests/kernel/threads.c | 1 | ||||
-rw-r--r-- | src/cmd/tests/libc/esemaphore.c | 1 | ||||
-rw-r--r-- | src/cmd/tests/stress.c | 1 | ||||
-rw-r--r-- | src/kernel/proc.c | 18 | ||||
-rw-r--r-- | src/kernel/proc.h | 1 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 26 | ||||
-rw-r--r-- | src/libc/compat.c | 9 | ||||
-rw-r--r-- | src/libc/include/camellia/compat.h | 2 | ||||
-rw-r--r-- | src/libc/syscall.c | 4 | ||||
-rw-r--r-- | src/libk/include/camellia/syscalls.h | 7 |
18 files changed, 29 insertions, 49 deletions
diff --git a/src/cmd/init/driver/termcook.c b/src/cmd/init/driver/termcook.c index 68b5746..a0da8c3 100644 --- a/src/cmd/init/driver/termcook.c +++ b/src/cmd/init/driver/termcook.c @@ -1,4 +1,5 @@ #include "driver.h" +#include <camellia/compat.h> #include <camellia/syscalls.h> #include <err.h> #include <errno.h> diff --git a/src/cmd/init/init.c b/src/cmd/init/init.c index d221a7f..72b5c5a 100644 --- a/src/cmd/init/init.c +++ b/src/cmd/init/init.c @@ -1,4 +1,5 @@ #include "driver/driver.h" +#include <camellia/compat.h> #include <camellia/flags.h> #include <camellia/syscalls.h> #include <stdint.h> diff --git a/src/cmd/netdog/nd.c b/src/cmd/netdog/nd.c index af5c264..2caaab9 100644 --- a/src/cmd/netdog/nd.c +++ b/src/cmd/netdog/nd.c @@ -1,4 +1,5 @@ #include <camellia.h> +#include <camellia/compat.h> #include <camellia/syscalls.h> #include <stdio.h> #include <string.h> diff --git a/src/cmd/netstack/netstack.c b/src/cmd/netstack/netstack.c index 2636429..4cdf409 100644 --- a/src/cmd/netstack/netstack.c +++ b/src/cmd/netstack/netstack.c @@ -1,6 +1,7 @@ #include "proto.h" #include "util.h" #include <camellia.h> +#include <camellia/compat.h> #include <camellia/syscalls.h> #include <stdbool.h> #include <stddef.h> diff --git a/src/cmd/shell/shell.c b/src/cmd/shell/shell.c index 185aa7e..df239eb 100644 --- a/src/cmd/shell/shell.c +++ b/src/cmd/shell/shell.c @@ -1,5 +1,6 @@ #include "builtins.h" #include "shell.h" +#include <camellia/compat.h> #include <camellia/flags.h> #include <camellia/syscalls.h> #include <err.h> diff --git a/src/cmd/tests/kernel/fdlimit.c b/src/cmd/tests/kernel/fdlimit.c index f332357..9e1f9dc 100644 --- a/src/cmd/tests/kernel/fdlimit.c +++ b/src/cmd/tests/kernel/fdlimit.c @@ -1,4 +1,5 @@ #include "../tests.h" +#include <camellia/compat.h> #include <camellia/flags.h> #include <errno.h> #include <unistd.h> diff --git a/src/cmd/tests/kernel/misc.c b/src/cmd/tests/kernel/misc.c index 5d6b531..7fc0866 100644 --- a/src/cmd/tests/kernel/misc.c +++ b/src/cmd/tests/kernel/misc.c @@ -1,4 +1,5 @@ #include "../tests.h" +#include <camellia/compat.h> #include <camellia/errno.h> #include <camellia/flags.h> #include <camellia/syscalls.h> diff --git a/src/cmd/tests/kernel/miscsyscall.c b/src/cmd/tests/kernel/miscsyscall.c index 90da0e4..0518654 100644 --- a/src/cmd/tests/kernel/miscsyscall.c +++ b/src/cmd/tests/kernel/miscsyscall.c @@ -1,4 +1,5 @@ #include "../tests.h" +#include <camellia/compat.h> #include <camellia/errno.h> #include <camellia/execbuf.h> #include <camellia/flags.h> diff --git a/src/cmd/tests/kernel/threads.c b/src/cmd/tests/kernel/threads.c index b3c1c06..9b0a687 100644 --- a/src/cmd/tests/kernel/threads.c +++ b/src/cmd/tests/kernel/threads.c @@ -1,4 +1,5 @@ #include "../tests.h" +#include <camellia/compat.h> #include <camellia/flags.h> #include <camellia/syscalls.h> #include <string.h> diff --git a/src/cmd/tests/libc/esemaphore.c b/src/cmd/tests/libc/esemaphore.c index f089f4f..27bf108 100644 --- a/src/cmd/tests/libc/esemaphore.c +++ b/src/cmd/tests/libc/esemaphore.c @@ -1,4 +1,5 @@ #include "../tests.h" +#include <camellia/compat.h> #include <camellia/flags.h> #include <camellia/syscalls.h> #include <stdio.h> diff --git a/src/cmd/tests/stress.c b/src/cmd/tests/stress.c index 1ef018c..8e0186e 100644 --- a/src/cmd/tests/stress.c +++ b/src/cmd/tests/stress.c @@ -1,4 +1,5 @@ #include "tests.h" +#include <camellia/compat.h> #include <camellia/flags.h> #include <camellia/syscalls.h> #include <stdlib.h> diff --git a/src/kernel/proc.c b/src/kernel/proc.c index cd9db9b..bbf939c 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -353,17 +353,13 @@ void proc_tryreap(Proc *dead) { if (parent->awaited_death.pid && parent->awaited_death.pid != pid) { return; /* we're not The One */ } - if (parent->awaited_death.legacy) { - regs_savereturn(&parent->regs, dead->death_msg); - } else { - regs_savereturn(&parent->regs, pid); - if (parent->awaited_death.out) { - struct sys_wait2 __user *out = parent->awaited_death.out; - struct sys_wait2 data; - memset(&data, 0, sizeof data); - data.status = dead->death_msg; - pcpy_to(parent, out, &data, sizeof data); - } + regs_savereturn(&parent->regs, pid); + if (parent->awaited_death.out) { + struct sys_wait2 __user *out = parent->awaited_death.out; + struct sys_wait2 data; + memset(&data, 0, sizeof data); + data.status = dead->death_msg; + pcpy_to(parent, out, &data, sizeof data); } proc_setstate(parent, PS_RUNNING); } diff --git a/src/kernel/proc.h b/src/kernel/proc.h index afa4439..0dffe08 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -45,7 +45,6 @@ struct Proc { union { /* saved value, meaning depends on .state */ int death_msg; // PS_DEAD struct { - bool legacy; /* false = wait2, true = await */ uint32_t pid; /* valid if nonzero */ struct sys_wait2 __user *out; } awaited_death; diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index a8b47ae..0dda320 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -22,30 +22,6 @@ _Noreturn void _sys_exit(long ret) { proc_switch_any(); } -long _sys_await(void) { - bool has_children = false; - proc_setstate(proc_cur, PS_WAITS4CHILDDEATH); - proc_cur->awaited_death.legacy = true; - proc_cur->awaited_death.pid = 0; - - for (Proc *iter = proc_cur->child; - iter; iter = iter->sibling) - { - if (iter->noreap) continue; - has_children = true; - if (iter->state == PS_TOREAP) { - proc_tryreap(iter); - return 0; // dummy - } - } - - if (!has_children) { - proc_setstate(proc_cur, PS_RUNNING); - SYSCALL_RETURN(~0); // TODO errno - } - return 0; // dummy -} - long _sys_fork(int flags, hid_t __user *fs_front) { Proc *child; @@ -410,7 +386,6 @@ int _sys_wait2(int pid, int flags, struct sys_wait2 __user *out) { bool has_children = false; proc_setstate(proc_cur, PS_WAITS4CHILDDEATH); - proc_cur->awaited_death.legacy = false; proc_cur->awaited_death.out = out; proc_cur->awaited_death.pid = (0 < pid) ? pid : 0; @@ -463,7 +438,6 @@ long _syscall(long num, long a, long b, long c, long d, long e) { * see execbuf */ switch (num) { break; case _SYS_EXIT: _sys_exit(a); - break; case _SYS_AWAIT: _sys_await(); break; case _SYS_FORK: _sys_fork(a, (userptr_t)b); break; case _SYS_OPEN: _sys_open((userptr_t)a, b, c); break; case _SYS_MOUNT: _sys_mount(a, (userptr_t)b, c); diff --git a/src/libc/compat.c b/src/libc/compat.c index 3ec47f9..fdf24bb 100644 --- a/src/libc/compat.c +++ b/src/libc/compat.c @@ -18,3 +18,12 @@ long c0_fs_respond(void *buf, long ret, int flags) { h = -1; return ret; } + +/* old syscall */ +long _sys_await(void) { + struct sys_wait2 res; + if (_sys_wait2(-1, 0, &res) < 0) { + return ~0; + } + return res.status; +} diff --git a/src/libc/include/camellia/compat.h b/src/libc/include/camellia/compat.h index a7c6f1f..8b2efa1 100644 --- a/src/libc/include/camellia/compat.h +++ b/src/libc/include/camellia/compat.h @@ -4,3 +4,5 @@ /* c0 - fs_wait returning a handle */ long c0_fs_wait(char *buf, long len, struct ufs_request *res); long c0_fs_respond(void *buf, long ret, int flags); + +long _sys_await(void); diff --git a/src/libc/syscall.c b/src/libc/syscall.c index 5196683..b920e14 100644 --- a/src/libc/syscall.c +++ b/src/libc/syscall.c @@ -10,10 +10,6 @@ _Noreturn void _sys_exit(long ret) { __builtin_unreachable(); } -long _sys_await(void) { - return _syscall(_SYS_AWAIT, 0, 0, 0, 0, 0); -} - long _sys_fork(int flags, hid_t __user *fs_front) { return _syscall(_SYS_FORK, (long)flags, (long)fs_front, 0, 0, 0); } diff --git a/src/libk/include/camellia/syscalls.h b/src/libk/include/camellia/syscalls.h index 9a8fa94..b7e60a0 100644 --- a/src/libk/include/camellia/syscalls.h +++ b/src/libk/include/camellia/syscalls.h @@ -1,7 +1,6 @@ #pragma once #define _SYS_EXIT 0 -#define _SYS_AWAIT 1 #define _SYS_FORK 2 #define _SYS_OPEN 3 #define _SYS_MOUNT 4 @@ -36,11 +35,6 @@ long _syscall(long, long, long, long, long, long); */ _Noreturn void _sys_exit(long ret); -/** Waits for a child to exit. - * @return the value the child passed to exit() - */ -long _sys_await(void); - /** Creates a copy of the current process, and executes it. * All user memory pages get copied too. * @@ -85,7 +79,6 @@ void _sys_intr_set(void __user *ip); uint32_t _sys_getpid(void); uint32_t _sys_getppid(void); -// TODO deprecate await int _sys_wait2(int pid, int flags, struct sys_wait2 __user *out); /* see shared/execbuf.h */ |