Compare commits

...

3 Commits

Author SHA1 Message Date
70739744ac fix: fault address always display 2025-02-07 11:30:12 +01:00
1e981755de fix: do not edit task if it's the current 2025-02-07 11:29:39 +01:00
3766464c47 add: zombify task 2025-02-07 11:28:22 +01:00
4 changed files with 26 additions and 16 deletions

View File

@ -36,6 +36,7 @@ i8 create_kernel_task(void);
void remove_task(struct task *task);
struct task *copy_task(const struct task *task);
void kfork(struct task *daddy);
void zombify_task(struct task *task);
// utils
void exec_fn(void (*fn)(void));

View File

@ -20,11 +20,9 @@ __attribute__((noreturn)) void kpanic(const char *format, ...)
kvprintf(format, &va);
va_end(va);
if (strcmp(format, faults[14]) == 0) {
u32 faulting_address;
__asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address));
kprintf("fault at address: %p\n", faulting_address);
}
u32 faulting_address;
__asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address));
kprintf("fault at address: %p\n", faulting_address);
/* for (int i = 16; i < 32; i++) */
/* kprintf("%p\n", page_table1[i]); */
/* show_valloc_mem(); */

View File

@ -12,8 +12,8 @@ struct task *current_task;
void scheduler(void)
{
// ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED
void (*func[])(struct task *) = {remove_task, NULL, NULL, NULL,
NULL, remove_task, kfork};
void (*func[])(struct task *) = {zombify_task, NULL, NULL, NULL,
NULL, remove_task, kfork};
if (!current_task) // || current_task->next == current_task)
return;

View File

@ -63,23 +63,34 @@ void exec_fn(void (*fn)(void))
new_task->eip = (u32 *)fn;
}
void zombify_task(struct task *task)
{
cli(); // Technically useless
free_pages(task->heap, 4096);
free_pages(task->esp0, STACK_SIZE);
task->esp0 = NULL;
task->heap = NULL;
toris();
}
void remove_task(struct task *task)
{
cli();
struct task *left = task->prev;
struct task *right = task->next;
if (task->child)
if (task->child) {
remove_task(task->child);
task->child = NULL;
}
if (task->heap)
free_pages(task->heap, 4096);
if (task->esp0)
free_pages(task->esp0, STACK_SIZE);
task->heap = NULL;
task->esp0 = NULL;
if (task->status != ZOMBIE) {
left->next = right;
right->prev = left;
vfree(task);
}
left->next = right;
right->prev = left;
vfree(task);
toris();
}
struct task *copy_task(const struct task *task)
@ -104,5 +115,5 @@ void exit_task(void)
current_task->status = STOPPED;
}
toris();
asm volatile("jmp scheduler");
scheduler();
}