Support thread.

This commit is contained in:
TXuian
2024-05-19 11:48:43 +08:00
parent 736ba18769
commit 4803239498
17 changed files with 175 additions and 56 deletions
+12 -9
View File
@@ -204,28 +204,31 @@ static struct Thread* _new_task_cb(struct MemSpace* pmemspace)
if (!task) {
return NULL;
}
// init vm
if (pmemspace != NULL) {
task->memspace = pmemspace;
task->thread_context.user_stack_idx = -1;
doubleListNodeInit(&task->memspace_list_node);
doubleListAddOnBack(&task->memspace_list_node, &pmemspace->thread_list_guard);
} else {
task->memspace = NULL;
}
/* init basic task member */
doubleListNodeInit(&task->cli_sess_listhead);
doubleListNodeInit(&task->svr_sess_listhead);
/* when creating a new task, memspace will be freed outside during memory shortage */
task->memspace = NULL;
/* init main thread of task */
task->thread_context.task = task;
// alloc stack page for task
if ((void*)(task->thread_context.kern_stack_addr = (uintptr_t)kalloc(USER_STACK_SIZE)) == NULL) {
/* here inside, will no free memspace */
_dealloc_task_cb(task);
return NULL;
}
/* from now on, _new_task_cb() will not generate error */
/* init vm */
assert(pmemspace != NULL);
task->memspace = pmemspace;
task->thread_context.user_stack_idx = -1;
doubleListNodeInit(&task->memspace_list_node);
doubleListAddOnBack(&task->memspace_list_node, &pmemspace->thread_list_guard);
/* set context of main thread stack */
/// stack bottom
memset((void*)task->thread_context.kern_stack_addr, 0x00, USER_STACK_SIZE);