From 5eae93bbb00d34fa2e3b0ee5f33ad8cf5cccd1b7 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 30 Oct 2022 20:51:32 +0100 Subject: [PATCH] Bugfix: do not crash if we are blocking for no reason --- kernel/src/thread/Scheduler.cpp | 5 +++++ kernel/src/thread/Task.cpp | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index a52ba639..8248095d 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -99,6 +99,7 @@ void Scheduler::init() idle_task.regs.rflags = (1 << 21) | (1 << 9); idle_task.task_sleep = 1000; idle_task.user_task = false; + idle_task.block_reason = BlockReason::None; idle_task.state = idle_task.Idle; strlcpy(idle_task.name, "[cpu-idle]", sizeof(idle_task.name)); @@ -129,6 +130,7 @@ void Scheduler::add_kernel_task(const char* taskname, void (*task)(void)) new_task->cpu_time = 0; strlcpy(new_task->name, taskname, sizeof(new_task->name)); append_task(new_task); + new_task->block_reason = BlockReason::None; new_task->state = new_task->Running; task_num++; kinfoln("Adding kernel task: %s, starts at %lx, PID %ld, stack at %lx, total tasks: %ld", new_task->name, @@ -146,6 +148,7 @@ Task* Scheduler::create_user_task() new_task->task_sleep = 0; new_task->task_time = 0; new_task->cpu_time = 0; + new_task->block_reason = BlockReason::None; append_task(new_task); task_num++; return new_task; @@ -214,6 +217,7 @@ long Scheduler::load_user_task(const char* filename) new_task->cpu_time = 0; strlcpy(new_task->name, filename, sizeof(new_task->name)); append_task(new_task); + new_task->block_reason = BlockReason::None; new_task->state = new_task->Running; task_num++; kinfoln("Adding user task: %s, loaded at %lx, PID %ld, stack at %lx, total tasks: %ld", new_task->name, @@ -236,6 +240,7 @@ void Scheduler::reset_task(Task* task, ELFImage* new_image) task->regs.rflags = (1 << 21) | (1 << 9); // enable interrupts task->task_sleep = 0; task->cpu_time = 0; + task->block_reason = BlockReason::None; kinfoln("Resetting task: %s, loaded at %lx, PID %ld, stack at %lx, total tasks: %ld", task->name, task->regs.rip, task->id, task->regs.rsp, task_num); } diff --git a/kernel/src/thread/Task.cpp b/kernel/src/thread/Task.cpp index 8f6bd230..89c4f772 100644 --- a/kernel/src/thread/Task.cpp +++ b/kernel/src/thread/Task.cpp @@ -89,7 +89,7 @@ void Task::resume() VMM::switch_to_previous_user_address_space(); switch (block_reason) { - case BlockReason::None: ASSERT(false); + case BlockReason::None: return; case BlockReason::Reading: resume_read(); break; case BlockReason::Waiting: resume_wait(); break; @@ -104,11 +104,11 @@ bool Task::is_still_blocking() { switch (block_reason) { - case BlockReason::None: ASSERT(false); + case BlockReason::None: return true; case BlockReason::Reading: return is_read_still_blocking(); case BlockReason::Waiting: return is_wait_still_blocking(); - default: ASSERT(false); + default: return true; } }