Fix race condition in page fault handler.
We enabled interrupts before getting the value of cr2 in the handler. If the handler was preempted, cr2 could have been overriden by a page fault in a separate thread or process.
This commit is contained in:
parent
3e1e37bf03
commit
bd32e85164
|
@ -43,6 +43,7 @@ InterruptDescriptor CreateDescriptor(void isr(void)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InterruptFrame {
|
struct InterruptFrame {
|
||||||
|
uint64_t cr2;
|
||||||
uint64_t rax;
|
uint64_t rax;
|
||||||
uint64_t rbx;
|
uint64_t rbx;
|
||||||
uint64_t rcx;
|
uint64_t rcx;
|
||||||
|
@ -90,14 +91,14 @@ extern "C" void interrupt_protection_fault(InterruptFrame* frame) {
|
||||||
|
|
||||||
extern "C" void isr_page_fault();
|
extern "C" void isr_page_fault();
|
||||||
extern "C" void interrupt_page_fault(InterruptFrame* frame) {
|
extern "C" void interrupt_page_fault(InterruptFrame* frame) {
|
||||||
uint64_t cr2;
|
uint64_t err = frame->error_code;
|
||||||
asm volatile("mov %%cr2, %0" : "=r"(cr2));
|
if ((err & 0x1) == 0) {
|
||||||
|
// Page not present error may be resolveable.
|
||||||
if (gScheduler->CurrentProcess().vmas()->HandlePageFault(cr2)) {
|
if (gScheduler->CurrentProcess().vmas()->HandlePageFault(frame->cr2)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
dbgln("Unhandled Page Fault:");
|
dbgln("Unhandled Page Fault:");
|
||||||
uint64_t err = frame->error_code;
|
|
||||||
if (err & 0x1) {
|
if (err & 0x1) {
|
||||||
dbgln("Page Protection");
|
dbgln("Page Protection");
|
||||||
} else {
|
} else {
|
||||||
|
@ -119,7 +120,7 @@ extern "C" void interrupt_page_fault(InterruptFrame* frame) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgln("rip: %m", frame->rip);
|
dbgln("rip: %m", frame->rip);
|
||||||
dbgln("addr: %m", cr2);
|
dbgln("addr: %m", frame->cr2);
|
||||||
panic("PF");
|
panic("PF");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,12 @@
|
||||||
push %rcx # (Return Address)
|
push %rcx # (Return Address)
|
||||||
push %rbx
|
push %rbx
|
||||||
push %rax
|
push %rax
|
||||||
|
mov %cr2, %rax
|
||||||
|
push %rax
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.macro interrupt_exit
|
.macro interrupt_exit
|
||||||
|
add $8, %rsp
|
||||||
pop %rax
|
pop %rax
|
||||||
pop %rbx
|
pop %rbx
|
||||||
pop %rcx
|
pop %rcx
|
||||||
|
@ -26,11 +29,11 @@
|
||||||
pop %r8
|
pop %r8
|
||||||
pop %r9
|
pop %r9
|
||||||
pop %r10
|
pop %r10
|
||||||
pop %r10
|
pop %r11
|
||||||
pop %r10
|
pop %r12
|
||||||
pop %r10
|
pop %r13
|
||||||
pop %r10
|
pop %r14
|
||||||
pop %r10
|
pop %r15
|
||||||
pop %rbp
|
pop %rbp
|
||||||
|
|
||||||
add $8, %rsp # Remove error code.
|
add $8, %rsp # Remove error code.
|
||||||
|
|
Loading…
Reference in New Issue