diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-04 19:25:12 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-04 19:25:12 +0300 |
| commit | 07c2376702fb3d508d6ffad6b0ce93b83972ad6e (patch) | |
| tree | 9ce46b000f8411fa86118645063b4df05d018dbf /src/orphanage.c | |
| parent | 66e7f184a925247bac51aae02d01483faa5454fc (diff) | |
| download | kmi-07c2376702fb3d508d6ffad6b0ce93b83972ad6e.tar.gz kmi-07c2376702fb3d508d6ffad6b0ce93b83972ad6e.zip | |
add zombie and orphan threads
+ Should write this down somewhere but the idea is that when a process
gets killed, it frees all the memory it can, making all threads within
that process orphans. Orphaned threads are assigned to the init
process, which will generally call exit() on each one. Zombie threads
are threads that own some bit of shared data, and whose reference
count is above zero. They may not be swapped to or called, even though
they take up space in thread map and reserve their thread ID.
Diffstat (limited to 'src/orphanage.c')
| -rw-r--r-- | src/orphanage.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/orphanage.c b/src/orphanage.c new file mode 100644 index 0000000..7415e8b --- /dev/null +++ b/src/orphanage.c @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: copyleft-next-0.3.1 */ +/* Copyright 2024, Kim Kuparinen < kimi.h.kuparinen@gmail.com > */ + +#include <kmi/assert.h> +#include <kmi/orphanage.h> + +#include <arch/proc.h> + +/** + * @file orphanage.c + * + * Stuff related to orphaned threads implementation. + */ + +bool orphan(struct tcb *t) +{ + struct tcb *r = get_rproc(t); + return !r || r->dead; +} + +void orphanize(struct tcb *t) +{ + catastrophic_assert(!is_rpc(t)); + + struct tcb *r = get_tcb(t->rid); + if (r) + unreference_proc(r); + + /* attach to init process */ + struct tcb *init = get_tcb(1); + reference_proc(init); + + t->rid = 1; + t->pid = 1; + t->eid = 1; + + t->proc = init->proc; + use_vmem(t->proc.vmem); + + catastrophic_assert(init->callback); + set_args3(t, 0, SYS_USER_ORPHANED, t->tid); + set_return(t, init->callback); + t->callback = init->callback; + + /** @todo release irqs, here or later? */ + + ret_userspace_fast(); + unreachable(); +} |
