Skip to content

Commit

Permalink
UefiCpuPkg/CpuExceptionHandlerLib: Setup single step in #PF handler
Browse files Browse the repository at this point in the history
Once the #PF handler has set the page to be 'present', there should
be a way to reset it to 'not-present'. 'TF' bit in EFLAGS can be used
for this purpose. 'TF' bit will be set in interrupted function context
so that it can be triggered once the cpu control returns back to the
instruction causing #PF and re-execute it.

This is an necessary step to implement non-stop mode for Heap Guard
and NULL Pointer Detection feature.

Cc: Eric Dong <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Cc: Ruiyu Ni <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <[email protected]>
Reviewed-by: Eric Dong <[email protected]>
Acked-by: Laszlo Ersek <[email protected]>
  • Loading branch information
Jian J Wang committed Aug 29, 2018
1 parent 8f26136 commit 16b918b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ ErrorCodeAndVectorOnStack:
pop dword [ebp - 4]
mov esp, ebp
pop ebp

; Enable TF bit after page fault handler runs
cmp dword [esp], 14 ; #PF?
jne .5
bts dword [esp + 16], 8 ; EFLAGS

.5:
add esp, 8
cmp dword [esp - 16], 0 ; check EXCEPTION_HANDLER_CONTEXT.OldIdtHandler
jz DoReturn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,8 @@ o16 mov [ecx + IA32_TSS._SS], ax
movzx ebx, word [ecx + IA32_TSS._CS]
mov [eax - 0x8], ebx ; create CS in old stack
mov ebx, dword [ecx + IA32_TSS.EFLAGS]
bts ebx, 8
bts ebx, 8 ; Set TF
mov [eax - 0x4], ebx ; create eflags in old stack
mov dword [ecx + IA32_TSS.EFLAGS], ebx ; update eflags in old TSS
mov eax, dword [ecx + IA32_TSS._ESP] ; Get old stack pointer
sub eax, 0xc ; minus 12 byte
mov dword [ecx + IA32_TSS._ESP], eax ; Set new stack pointer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ HasErrorCode:
pop r15

mov rsp, rbp
cmp qword [rbp + 8], 14 ; #PF?
jne .1
bts qword [rsp + 40], 8 ; RFLAGS.TF
.1:
pop rbp
add rsp, 16
cmp qword [rsp - 32], 0 ; check EXCEPTION_HANDLER_CONTEXT.OldIdtHandler
Expand Down

0 comments on commit 16b918b

Please sign in to comment.