summaryrefslogtreecommitdiff
path: root/src/kernel/syscalls.c
diff options
context:
space:
mode:
authordzwdz2021-09-21 17:48:52 +0200
committerdzwdz2021-09-21 17:48:52 +0200
commit2373680d99372b9e7cdecf1c8d4b0a7366eb3cfb (patch)
tree93069f4e46428d6bb1055d1c999c527e87f49a35 /src/kernel/syscalls.c
parentd34bd9a45440be2ef65d24619af5505b8c05c229 (diff)
refactor `await_finish` into `process_try2collect`
the new name is terrible, but at least the function now has a clear purpose
Diffstat (limited to 'src/kernel/syscalls.c')
-rw-r--r--src/kernel/syscalls.c31
1 files changed, 6 insertions, 25 deletions
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index ac21cdb..16238e7 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -8,33 +8,11 @@
#include <shared/syscalls.h>
#include <stdint.h>
-_Noreturn static void await_finish(struct process *dead, struct process *listener) {
- int len;
- bool res;
-
- assert(dead->state == PS_DEAD);
- assert(listener->state == PS_WAITS4CHILDDEATH);
- dead->state = PS_DEADER;
- listener->state = PS_RUNNING;
-
- len = listener->death_msg.len < dead->death_msg.len
- ? listener->death_msg.len : dead->death_msg.len;
- res = virt_cpy(
- listener->pages, listener->death_msg.buf,
- dead->pages, dead->death_msg.buf, len);
- regs_savereturn(&listener->regs, res ? len : -1);
- process_switch(listener);
-}
-
-
_Noreturn void _syscall_exit(const char __user *msg, size_t len) {
process_current->state = PS_DEAD;
process_current->death_msg.buf = (userptr_t) msg; // discarding const
process_current->death_msg.len = len;
-
- if (process_current->parent->state == PS_WAITS4CHILDDEATH)
- await_finish(process_current, process_current->parent);
-
+ process_try2collect(process_current);
process_switch_any();
}
@@ -47,8 +25,11 @@ int _syscall_await(char __user *buf, int len) {
// find any already dead children
for (struct process *iter = process_current->child;
iter; iter = iter->sibling) {
- if (iter->state == PS_DEAD)
- await_finish(iter, process_current); // doesn't return
+ if (iter->state == PS_DEAD) {
+ int ret = process_try2collect(iter);
+ assert(ret >= 0);
+ return ret;
+ }
if (iter->state != PS_DEADER)
has_children = true;
}