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:
Drew Galbraith 2023-06-07 22:24:50 -07:00
parent 3e1e37bf03
commit bd32e85164
2 changed files with 16 additions and 12 deletions

View file

@ -14,9 +14,12 @@
push %rcx # (Return Address)
push %rbx
push %rax
mov %cr2, %rax
push %rax
.endm
.macro interrupt_exit
add $8, %rsp
pop %rax
pop %rbx
pop %rcx
@ -26,11 +29,11 @@
pop %r8
pop %r9
pop %r10
pop %r10
pop %r10
pop %r10
pop %r10
pop %r10
pop %r11
pop %r12
pop %r13
pop %r14
pop %r15
pop %rbp
add $8, %rsp # Remove error code.