From b25156373cd89792b1c457b77699bb7f9beb430d Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 26 Aug 2024 18:51:10 +0300 Subject: improve killing processes/threads, test + Remove sys_kill() as we should be using a two-stage process where a thread is first orphaned by sys_detach(), and then the thread itself calls sys_exit() after it has done all necessary cleanup in init. --- src/uapi/proc.c | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) (limited to 'src/uapi/proc.c') diff --git a/src/uapi/proc.c b/src/uapi/proc.c index c0fe5f0..b90433f 100644 --- a/src/uapi/proc.c +++ b/src/uapi/proc.c @@ -174,29 +174,6 @@ SYSCALL_DEFINE2(spawn)(struct tcb *t, sys_arg_t bin, sys_arg_t interp) return_args1(t, n->pid); } -/** - * Kill syscall handler. - * - * @param t Current tcb. - * @param pid Process to kill. - * \todo Implement. - * - * @return ERR_PERM if not capable to kill, otherwise OK. - */ -SYSCALL_DEFINE1(kill)(struct tcb *t, sys_arg_t pid) -{ - struct tcb *c = get_cproc(t); - if (!(has_cap(c->caps, CAP_PROC))) - return_args1(t, ERR_PERM); - - struct tcb *r = get_tcb(pid); - if (is_proc(r)) - return_args1(t, ERR_INVAL); - - destroy_proc(r); - return_args1(t, OK); -} - /** * Actual worker of swapping between threads. * Assumes that both \p t and \p s exist and that \p s isn't a zombie or @@ -215,7 +192,7 @@ static void swap(struct tcb *t, struct tcb *s) enable_irqs(); if (!is_rpc(s) && orphan(s)) { - orphanize(s); + unorphanize(s); return; } @@ -242,6 +219,12 @@ static void swap(struct tcb *t, struct tcb *s) */ SYSCALL_DEFINE1(exit)(struct tcb *t, sys_arg_t tid) { + /* init thread is not allowed to exit */ + /** @todo what about other possible threads start at init, are they + * allowed to exit? I guess? */ + if (t->tid == 1) + return_args1(t, ERR_INVAL); + if (tid != 0) { struct tcb *s = get_tcb(tid); if (!s) @@ -284,17 +267,7 @@ SYSCALL_DEFINE1(detach)(struct tcb *t, sys_arg_t tid) if (!o || orphan(o)) return_args1(t, ERR_INVAL); - struct tcb *r = get_tcb(o->rid); - if (r) - unreference_proc(r); - orphanize(o); - - /* generally the thread shouldn't do anything with this information, but - * it fits really nicely into the notification framework so just do it - */ - notify(o, NOTIFY_ORPHANED); - return_args1(t, OK); } -- cgit v1.3