Kernel: Fix possible context switch within first context switch of a thread

We were enabling interrupts too early, before the first context switch to
a thread was complete. This could then trigger another context switch
within the context switch, which lead to a crash.
This commit is contained in:
Tom 2021-01-25 13:17:43 -07:00 committed by Andreas Kling
parent bd73102513
commit b580c005f1
Notes: sideshowbarker 2024-07-18 22:51:14 +09:00

View File

@ -1366,8 +1366,10 @@ extern "C" void context_first_init([[maybe_unused]] Thread* from_thread, [[maybe
// Since we got here and don't have Scheduler::context_switch in the
// call stack (because this is the first time we switched into this
// context), we need to notify the scheduler so that it can release
// the scheduler lock.
Scheduler::leave_on_first_switch(trap->regs->eflags);
// the scheduler lock. We don't want to enable interrupts at this point
// as we're still in the middle of a context switch. Doing so could
// trigger a context switch within a context switch, leading to a crash.
Scheduler::leave_on_first_switch(trap->regs->eflags & ~0x200);
}
extern "C" void thread_context_first_enter(void);