Kernel/x86_64: *Restore* interrupt flag in page fault handler

If a page fault occurs while interrupts are disabled, we were wrongly
enabling interrupts right away in the page fault handler.

Instead, we should only do this if interrupts were enabled when the
page fault occurred.
This commit is contained in:
Andreas Kling 2022-12-30 23:14:28 +01:00
parent e3b9f78eb9
commit 1b4baaed56

View file

@ -177,13 +177,16 @@ void page_fault_handler(TrapFrame* trap)
{
clac();
// NOTE: Once we've extracted the faulting address from CR2,
// we can re-enable interrupts.
auto fault_address = read_cr2();
sti();
auto& regs = *trap->regs;
// NOTE: Once we've extracted the faulting address from CR2, we can re-enable interrupts.
// However, we only do this *if* they were enabled when the page fault occurred.
if (regs.flags() & 0x200) {
sti();
}
if constexpr (PAGE_FAULT_DEBUG) {
u32 fault_page_directory = read_cr3();
dbgln("CPU #{} ring {} {} page fault in PD={:#x}, {}{} {}",