aboutsummaryrefslogtreecommitdiff
path: root/src/tcb.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-05 19:38:11 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-05 19:38:11 +0300
commite09edb5d54e39bd9509a1dc450df5ab320759f97 (patch)
tree78e050b0db87df3a3ddfbb6570d44513ac34e02a /src/tcb.c
parent98f21e694a6b0964d6d08196cb6bfbc1c2ae2ff4 (diff)
downloadkmi-e09edb5d54e39bd9509a1dc450df5ab320759f97.tar.gz
kmi-e09edb5d54e39bd9509a1dc450df5ab320759f97.zip
allow booting with Qemu's -kernel flag directly
+ Took some fairly significant changes, for one the kernel is no longer relocated at the start of a boot, instead it sits wherever the user decides the kernel should sit. Similarly, the initial kernel stack and page table are stored within the binary, slightly bloating the size but making it much safer to boot since there's really no chance of us overwriting the fdt or initrd in memory.
Diffstat (limited to 'src/tcb.c')
-rw-r--r--src/tcb.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/tcb.c b/src/tcb.c
index 1287cef..ba134c6 100644
--- a/src/tcb.c
+++ b/src/tcb.c
@@ -74,7 +74,7 @@ static id_t __alloc_tid(struct tcb *t)
if (i == stop_tid)
return ERR_NF;
- if (get_tcb(i) || i == 0)
+ if (tcbs[i & (num_tids - 1)] || i == 0)
continue;
tcbs[i & (num_tids - 1)] = t;
@@ -210,6 +210,11 @@ static stat_t __destroy_thread_data(struct tcb *t)
destroy_vmem(t->rpc.vmem);
/* remove ourselves from the thread pool */
+ /** @todo this should be at the top of the function, and be wrapped in
+ * some kind of lock that checks that nobody reads the value while we're
+ * setting it to zero. get_tcb() should accordingly increment the
+ * reference count atomically. Also, an unget_tcb() is needed to
+ * decrement the reference count I guess? */
tcbs[t->tid] = 0;
/* forcefully free last struggling bits of memory */
@@ -228,6 +233,7 @@ stat_t destroy_thread(struct tcb *t)
hard_assert(!is_proc(t), ERR_INVAL);
/* mark us as zombies */
+ set_bits(t->state, TCB_ZOMBIE);
t->rid = 0;
/* remove reference to root process */