Skip to content

Commit b580c00

Browse files
tomutaawesomekling
authored andcommitted
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.
1 parent bd73102 commit b580c00

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Kernel/Arch/i386/CPU.cpp

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

13731375
extern "C" void thread_context_first_enter(void);

0 commit comments

Comments
 (0)