feature: fork added and exit_task is almost working

This commit is contained in:
2025-01-28 13:38:39 +01:00
parent d7626df19c
commit dbdf851dd2
9 changed files with 80 additions and 19 deletions

View File

@ -1,6 +1,7 @@
#include "task.h"
#include "alloc.h"
#include "debug.h"
#include "interrupts.h"
#include "kpanic.h"
#include "kprintf.h"
#include "memory.h"
@ -9,7 +10,7 @@
u32 esp_backup;
static struct task *create_task(u8 owner_id)
struct task *create_task(u8 uid)
{
static u32 pid = 1;
struct task *new_task = vmalloc(sizeof(struct task));
@ -18,7 +19,7 @@ static struct task *create_task(u8 owner_id)
new_task->next = current_task->next;
new_task->prev = current_task;
current_task->next = new_task;
new_task->uid = owner_id;
new_task->uid = uid;
new_task->esp0 = alloc_pages(STACK_SIZE, NULL);
if (!new_task->esp0) {
vfree(new_task);
@ -60,9 +61,31 @@ void exec_fn(void (*fn)(void))
new_task->eip = (u32 *)fn;
}
/*
* Create task
* Allocate new pd => kmalloc(4096)
* Add pd address to the struct task
*
*/
void remove_task(struct task *task)
{
struct task *left = task->prev;
struct task *right = task->next;
if (task->child)
remove_task(task->child);
if (task->heap)
vfree(task->heap);
if (task->esp0)
vfree(task->esp0);
task->heap = NULL;
task->esp0 = NULL;
if (task->status != ZOMBIE) {
left->next = right;
right->prev = left;
vfree(task);
}
}
void exit_task(void)
{
cli();
if (current_task->daddy && current_task->daddy->status != WAIT)
current_task->status = ZOMBIE;
else
current_task->status = STOPPED;
toris();
}