summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2021-07-13 11:44:30 -0600
committerAndreas Kling <kling@serenityos.org>2021-07-13 20:23:10 +0200
commitb919789db24cbeb323a694989ca784c43fff9acc (patch)
tree5a2f4071b31f71b763e8b2a8ad7c6a8d1e25a9d3 /Kernel
parentfa8fe40266f2cd631b97e8155bdad2486c31f437 (diff)
downloadserenity-b919789db24cbeb323a694989ca784c43fff9acc.zip
Kernel: Kill user mode threads that are marked to die
Threads that don't make syscalls still need to be killed, and we can do that at any time we want so long the thread is in user mode and not somehow blocked (e.g. page fault).
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Scheduler.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp
index da69b27cd7..ef3e702aca 100644
--- a/Kernel/Scheduler.cpp
+++ b/Kernel/Scheduler.cpp
@@ -443,6 +443,16 @@ void Scheduler::timer_tick(const RegisterState& regs)
return; // TODO: This prevents scheduling on other CPUs!
#endif
+ if (current_thread->previous_mode() == Thread::PreviousMode::UserMode && current_thread->should_die() && !current_thread->is_blocked()) {
+ dbgln_if(SCHEDULER_DEBUG, "Scheduler[{}]: Terminating user mode thread {}", Processor::id(), *current_thread);
+ {
+ ScopedSpinLock scheduler_lock(g_scheduler_lock);
+ current_thread->set_state(Thread::Dying);
+ }
+ VERIFY(!Processor::current().in_critical());
+ Processor::current().invoke_scheduler_async();
+ return;
+ }
if (current_thread->tick())
return;