diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/orphanage.c | 7 | ||||
| -rw-r--r-- | src/tcb.c | 28 |
2 files changed, 24 insertions, 11 deletions
diff --git a/src/orphanage.c b/src/orphanage.c index 4760f73..9da6f8b 100644 --- a/src/orphanage.c +++ b/src/orphanage.c @@ -34,9 +34,14 @@ void unorphanize(struct tcb *t) t->pid = 1; t->eid = 1; + free_stack(t); + reset_rpc_stack(t); + t->proc = init->proc; - t->rpc_stack = RPC_STACK_BASE; use_vmem(t->proc.vmem); + alloc_stack(t); + + clear_bits(t->state, TCB_ORPHAN); catastrophic_assert(init->callback); set_args3(t, 0, SYS_USER_ORPHANED, t->tid); @@ -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 |
