From fdbc5adf83741d7e3af0c3f0ffdb59bdf42493b6 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 4 Jul 2024 22:52:47 +0300 Subject: generalize orphants + Allow threads to make themselves become orphants --- src/uapi/proc.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/uapi/proc.c') diff --git a/src/uapi/proc.c b/src/uapi/proc.c index 3ce808f..231cc32 100644 --- a/src/uapi/proc.c +++ b/src/uapi/proc.c @@ -234,6 +234,35 @@ SYSCALL_DEFINE1(exit)(struct tcb *t, sys_arg_t tid) } } +/** + * Syscall handler for orphanizing a thread. + * + * @param t Thread that wants to make itself an orphant. + * @return \ref OK on success, + * \ref ERR_PERM if current process missing \ref CAP_PROC, + * \ref ERR_INVAL if already an orphant. + */ +SYSCALL_DEFINE0(detach)(struct tcb *t) +{ + struct tcb *c = get_cproc(t); + if (!(has_cap(c->caps, CAP_PROC))) + return_args1(t, ERR_PERM); + + if (orphan(t)) + return_args1(t, ERR_INVAL); + + struct tcb *r = get_tcb(t->rid); + if (r) + unreference_proc(r); + + orphanize(t); + + if (!is_rpc(t)) + unorphanize(t); + + return_args1(t, OK); +} + /** * Swap syscall handler. * -- cgit v1.3