From 03db57bbf9dd3428d0f532569a5c800c9970b169 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 1 Oct 2022 12:32:09 +0200 Subject: [PATCH] Sanity checks --- kernel/src/thread/Scheduler.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index f7e3b71f..59e6c127 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -64,7 +64,7 @@ void Scheduler::add_kernel_task(void (*task)(void)) new_task->regs.rip = (uint64_t)task; new_task->allocated_stack = (uint64_t)MemoryManager::get_pages(TASK_PAGES_IN_STACK); // 16 KB is enough for everyone, right? - new_task->regs.rsp = new_task->allocated_stack + (4096 * 4) - sizeof(uintptr_t); + new_task->regs.rsp = new_task->allocated_stack + (4096 * TASK_PAGES_IN_STACK) - sizeof(uintptr_t); new_task->regs.cs = 0x08; new_task->regs.ss = 0x10; new_task->regs.ds = 0x10; @@ -92,7 +92,7 @@ void Scheduler::add_user_task(void* task) new_task->regs.rip = (uint64_t)task; new_task->allocated_stack = (uint64_t)MemoryManager::get_pages( TASK_PAGES_IN_STACK, MAP_READ_WRITE | MAP_USER); // 16 KB is enough for everyone, right? - new_task->regs.rsp = new_task->allocated_stack + (4096 * 4) - sizeof(uintptr_t); + new_task->regs.rsp = new_task->allocated_stack + (4096 * TASK_PAGES_IN_STACK) - sizeof(uintptr_t); new_task->regs.cs = 0x18 | 0x03; new_task->regs.ss = 0x20 | 0x03; new_task->regs.ds = 0x20 | 0x03; @@ -126,7 +126,7 @@ void Scheduler::load_user_task(const char* filename) } new_task->allocated_stack = (uint64_t)MemoryManager::get_pages( TASK_PAGES_IN_STACK, MAP_READ_WRITE | MAP_USER); // 16 KB is enough for everyone, right? - new_task->regs.rsp = new_task->allocated_stack + (4096 * 4) - sizeof(uintptr_t); + new_task->regs.rsp = new_task->allocated_stack + (4096 * TASK_PAGES_IN_STACK) - sizeof(uintptr_t); new_task->regs.cs = 0x18 | 0x03; new_task->regs.ss = 0x20 | 0x03; new_task->regs.ds = 0x20 | 0x03; @@ -150,6 +150,7 @@ void Scheduler::reap_task(Task* task) ASSERT(!Interrupts::is_in_handler()); task_num--; Task* exiting_task = task; + ASSERT(task->id != 0); // WHY IN THE WORLD WOULD WE BE REAPING THE IDLE TASK? kinfoln("reaping task %ld", exiting_task->id); if (exiting_task->allocated_stack) MemoryManager::release_pages((void*)exiting_task->allocated_stack, TASK_PAGES_IN_STACK);