wip: fork and wait are almost working (missing child's stack)

This commit is contained in:
2025-01-28 15:44:09 +01:00
parent e60969b37a
commit 1ca8c68cf5
5 changed files with 23 additions and 12 deletions

View File

@ -20,6 +20,7 @@ struct task *create_task(u8 uid)
new_task->next = current_task->next;
new_task->prev = current_task;
current_task->next = new_task;
new_task->status = RUN;
new_task->uid = uid;
new_task->esp0 = alloc_pages(STACK_SIZE, NULL);
if (!new_task->esp0) {
@ -58,7 +59,6 @@ void exec_fn(void (*fn)(void))
struct task *new_task = create_task(OWNER_KERNEL);
if (!new_task)
kpanic("failed to create new task");
new_task->status = RUN;
new_task->eip = (u32 *)fn;
}
@ -69,9 +69,9 @@ void remove_task(struct task *task)
if (task->child)
remove_task(task->child);
if (task->heap)
vfree(task->heap);
free_pages(task->heap, 4096);
if (task->esp0)
vfree(task->esp0);
free_pages(task->esp0, STACK_SIZE);
task->heap = NULL;
task->esp0 = NULL;
if (task->status != ZOMBIE) {
@ -86,8 +86,11 @@ void exit_task(void)
cli();
if (current_task->daddy && current_task->daddy->status != WAIT)
current_task->status = ZOMBIE;
else
else {
if (current_task->daddy->status == WAIT)
current_task->daddy->status = RUN;
current_task->status = STOPPED;
}
toris();
asm volatile("jmp scheduler");
}