aboutsummaryrefslogtreecommitdiff
path: root/src/uapi/proc.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-04 22:52:47 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-04 22:52:47 +0300
commitfdbc5adf83741d7e3af0c3f0ffdb59bdf42493b6 (patch)
tree2eb538b9ecc2898d1f94305fe56d0625060834de /src/uapi/proc.c
parentb82479a69cd6110c9099031e133fda62f8e11222 (diff)
downloadkmi-fdbc5adf83741d7e3af0c3f0ffdb59bdf42493b6.tar.gz
kmi-fdbc5adf83741d7e3af0c3f0ffdb59bdf42493b6.zip
generalize orphants
+ Allow threads to make themselves become orphants
Diffstat (limited to 'src/uapi/proc.c')
-rw-r--r--src/uapi/proc.c29
1 files changed, 29 insertions, 0 deletions
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
@@ -235,6 +235,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.
*
* \todo Implement.