Skip to content

Commit 1b4baae

Browse files
committed
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.
1 parent e3b9f78 commit 1b4baae

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Kernel/Arch/x86_64/Interrupts.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,16 @@ void page_fault_handler(TrapFrame* trap)
177177
{
178178
clac();
179179

180-
// NOTE: Once we've extracted the faulting address from CR2,
181-
// we can re-enable interrupts.
182180
auto fault_address = read_cr2();
183-
sti();
184181

185182
auto& regs = *trap->regs;
186183

184+
// NOTE: Once we've extracted the faulting address from CR2, we can re-enable interrupts.
185+
// However, we only do this *if* they were enabled when the page fault occurred.
186+
if (regs.flags() & 0x200) {
187+
sti();
188+
}
189+
187190
if constexpr (PAGE_FAULT_DEBUG) {
188191
u32 fault_page_directory = read_cr3();
189192
dbgln("CPU #{} ring {} {} page fault in PD={:#x}, {}{} {}",

0 commit comments

Comments
 (0)