diff --git a/src/api/thread.c b/src/api/thread.c index 41e3514..4ae29ba 100644 --- a/src/api/thread.c +++ b/src/api/thread.c @@ -212,9 +212,6 @@ int arch_setup_new_thread(struct ktcb *new, struct ktcb *orig, /* Skip lr_svc since it's not going to be used */ new->context.pc = orig->syscall_regs->lr_usr; - /* Copy other relevant fields from original ktcb */ - new->pagerid = orig->pagerid; - /* Distribute original thread's ticks into two threads */ new->ticks_left = orig->ticks_left / 2; orig->ticks_left /= 2; @@ -229,9 +226,6 @@ int arch_setup_new_thread(struct ktcb *new, struct ktcb *orig, int thread_setup_new_ids(struct task_ids *ids, unsigned int flags, struct ktcb *new, struct ktcb *orig) { - /* Allocate a new id */ - ids->tid = id_new(thread_id_pool); - /* * If thread space is new or copied, * thread gets same group id as its thread id @@ -324,6 +318,16 @@ int thread_create(struct task_ids *ids, unsigned int flags) } } + /* + * Setup container-generic fields from current task + * + * NOTE: If a new container is created, this needs + * to assign the new pager and container + */ + new->pagerid = current->pagerid; + new->pager = current->pager; + new->container = current->container; + /* Set up new thread context by using parent ids and flags */ thread_setup_new_ids(ids, flags, new, parent); arch_setup_new_thread(new, parent, flags); diff --git a/src/generic/container.c b/src/generic/container.c index 8027dab..6303ad3 100644 --- a/src/generic/container.c +++ b/src/generic/container.c @@ -278,7 +278,6 @@ int init_first_pager(struct pager *pager, pager->tcb = task; task->pager = pager; task->container = cont; - link_init(&task->cap_list.caps); /* TODO: Do this in tcb_alloc_init */ task->cap_list_ptr = &pager->cap_list; /* Map the task's space */ @@ -326,7 +325,6 @@ int init_pager(struct pager *pager, struct container *cont) pager->tcb = task; task->pager = pager; task->container = cont; - link_init(&task->cap_list.caps); /* TODO: Do this in tcb_alloc_init */ task->cap_list_ptr = &pager->cap_list; add_mapping_pgd(pager->start_lma, pager->start_vma, diff --git a/src/generic/space.c b/src/generic/space.c index 892ff98..ed81dff 100644 --- a/src/generic/space.c +++ b/src/generic/space.c @@ -83,7 +83,7 @@ void address_space_delete(struct address_space *space) delete_page_tables(space); /* Return the space id */ - id_del(space_id_pool, space->spid); + id_del(&kernel_container.space_ids, space->spid); /* Deallocate the space structure */ free_space(space); diff --git a/src/generic/tcb.c b/src/generic/tcb.c index 1cc6258..9f76a80 100644 --- a/src/generic/tcb.c +++ b/src/generic/tcb.c @@ -16,11 +16,6 @@ #include INC_SUBARCH(mm.h) #include INC_GLUE(memory.h) -/* ID pools for threads and spaces. */ -struct id_pool *thread_id_pool; -struct id_pool *space_id_pool; - - void init_ktcb_list(struct ktcb_list *ktcb_list) { memset(ktcb_list, 0, sizeof(*ktcb_list)); @@ -36,6 +31,8 @@ void tcb_init(struct ktcb *new) link_init(&new->task_list); mutex_init(&new->thread_control_lock); + link_init(&new->cap_list.caps); + /* Initialise task's scheduling state and parameters. */ sched_init_task(new, TASK_PRIO_NORMAL); @@ -92,7 +89,7 @@ void tcb_delete(struct ktcb *tcb) address_space_reference_unlock(); /* Deallocate tcb ids */ - id_del(thread_id_pool, tcb->tid); + id_del(&kernel_container.ktcb_ids, tcb->tid); /* Free the tcb */ free_ktcb(tcb);