aboutsummaryrefslogtreecommitdiff
path: root/src/tcb.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-06 20:50:36 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-06 20:50:36 +0300
commit9c0f26d26366ff7def20d5be6aff5e0f93976ad6 (patch)
tree3872c5a1018a232e51da3f774ca54ae2e9967427 /src/tcb.c
parente9da1d29939a74e186afc39f2fce8e085764fea0 (diff)
downloadkmi-9c0f26d26366ff7def20d5be6aff5e0f93976ad6.tar.gz
kmi-9c0f26d26366ff7def20d5be6aff5e0f93976ad6.zip
adjust stack handling
Diffstat (limited to 'src/tcb.c')
-rw-r--r--src/tcb.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/tcb.c b/src/tcb.c
index 51aa939..45c31ce 100644
--- a/src/tcb.c
+++ b/src/tcb.c
@@ -107,11 +107,17 @@ stat_t alloc_stack(struct tcb *t)
return ERR_OOMEM;
/** \todo this only allows for a global stack size, what if a user wants
- * per thread stack sizes? */
- t->thread_stack_top = t->thread_stack + __thread_stack_size;
+ * per thread stack sizes? I guess allocate them yourself in userspace
+ * or something? */
+ t->thread_stack_size = __thread_stack_size;
return OK;
}
+void free_stack(struct tcb *t)
+{
+ free_uvmem(t, t->thread_stack);
+}
+
struct tcb *create_thread(struct tcb *p)
{
hard_assert(tcbs, 0);
@@ -171,7 +177,7 @@ static stat_t __copy_proc(struct tcb *p, struct tcb *n)
n->exec = p->exec;
n->callback = p->callback;
n->thread_stack = p->thread_stack;
- n->thread_stack_top = p->thread_stack_top;
+ n->thread_stack_size = p->thread_stack_size;
copy_regs(n, p);
copy_caps(n->caps, p->caps);
@@ -188,7 +194,7 @@ struct tcb *create_proc(struct tcb *p)
return 0;
if (p)
- __copy_proc(p, n); /* we have a parent thread */
+ __copy_proc(p, n); /* we have a parent process i.e. fork */
return n;
}
@@ -203,12 +209,6 @@ static stat_t __destroy_thread_data(struct tcb *t)
{
catastrophic_assert(t->refcount == 0);
- /* free memory backing rpc stack */
- destroy_rpc_stack(t);
-
- /* free rpc vmem */
- 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
@@ -241,6 +241,14 @@ stat_t destroy_thread(struct tcb *t)
/* remove reference to root process */
unreference_proc(get_rproc(t));
+ free_stack(t);
+
+ /* free memory backing rpc stack */
+ destroy_rpc_stack(t);
+
+ /* free rpc vmem */
+ destroy_vmem(t->rpc.vmem);
+
unqueue_ipi(t);
/** @todo timers, irqs? theoretically we could allow them to stay and