Skip to content

Commit 6909e6c

Browse files
committed
Kernel: Only dispatch signals to running threads
1 parent 9df5cc4 commit 6909e6c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Kernel/Arch/Processor.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,12 @@ void ProcessorBase::exit_trap(TrapFrame& trap, TrapType trap_type)
290290
self->smp_process_pending_messages();
291291
#endif
292292

293-
if (current_thread)
294-
current_thread->check_dispatch_pending_signal(YieldBehavior::FlagYield);
293+
{
294+
// Take the scheduler lock to avoid TOCTOU issues with the thread's state.
295+
SpinlockLocker lock(g_scheduler_lock);
296+
if (current_thread && current_thread->state() == Thread::State::Running)
297+
current_thread->check_dispatch_pending_signal(YieldBehavior::FlagYield);
298+
}
295299

296300
// Process the deferred call queue. Among other things, this ensures
297301
// that any pending thread unblocks happen before we enter the scheduler.

0 commit comments

Comments
 (0)