aboutsummaryrefslogtreecommitdiff
path: root/src/uapi
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-08-26 18:51:10 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-08-26 18:51:10 +0300
commitb25156373cd89792b1c457b77699bb7f9beb430d (patch)
tree56816903fcedc9fe35786b9baf43499d4ec3d19f /src/uapi
parent260fc4c790ca25ee1ffab4edd9c6488d3bcb441c (diff)
downloadkmi-b25156373cd89792b1c457b77699bb7f9beb430d.tar.gz
kmi-b25156373cd89792b1c457b77699bb7f9beb430d.zip
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.
Diffstat (limited to 'src/uapi')
-rw-r--r--src/uapi/dispatch.c1
-rw-r--r--src/uapi/ipc.c3
-rw-r--r--src/uapi/proc.c41
3 files changed, 9 insertions, 36 deletions
diff --git a/src/uapi/dispatch.c b/src/uapi/dispatch.c
index 859543a..2eef5bc 100644
--- a/src/uapi/dispatch.c
+++ b/src/uapi/dispatch.c
@@ -71,7 +71,6 @@ void handle_syscall(sys_arg_t syscall, sys_arg_t a, sys_arg_t b,
case SYS_FORK: sys_fork(t, a, b, c, d, e); break;
case SYS_EXEC: sys_exec(t, a, b, c, d, e); break;
case SYS_SPAWN: sys_spawn(t, a, b, c, d, e); break;
- case SYS_KILL: sys_kill(t, a, b, c, d, e); break;
case SYS_SWAP: sys_swap(t, a, b, c, d, e); break;
case SYS_SET_CONF: sys_set_conf(t, a, b, c, d, e); break;
case SYS_GET_CONF: sys_get_conf(t, a, b, c, d, e); break;
diff --git a/src/uapi/ipc.c b/src/uapi/ipc.c
index 850178c..0fba899 100644
--- a/src/uapi/ipc.c
+++ b/src/uapi/ipc.c
@@ -71,7 +71,7 @@ static inline void finalize_rpc(struct tcb *t, struct tcb *r, vm_t s)
{
clone_uvmem(r->proc.vmem, t->rpc.vmem);
set_return(t, r->callback);
- reference_proc(r);
+ reference_thread(r);
t->pid = r->rid;
/* make sure updates are visible when swapping to the new virtual memory */
@@ -446,6 +446,7 @@ SYSCALL_DEFINE4(ipc_resp)(struct tcb *t, sys_arg_t d0, sys_arg_t d1,
/* inform requester who answered (pid) in the case of the request being
* kicked forward */
enable_irqs();
+ unreference_thread(get_cproc(t));
leave_rpc(t, SYS_RET6(OK, t->pid, d0, d1, d2, d3));
}
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
@@ -175,29 +175,6 @@ SYSCALL_DEFINE2(spawn)(struct tcb *t, sys_arg_t bin, sys_arg_t interp)
}
/**
- * 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
* currently running.
@@ -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);
}