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 <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
pop dword [ebp - 4]\r
mov esp, ebp\r
pop ebp\r
+\r
+; Enable TF bit after page fault handler runs\r
+ cmp dword [esp], 14 ; #PF?\r
+ jne .5\r
+ bts dword [esp + 16], 8 ; EFLAGS\r
+\r
+.5:\r
add esp, 8\r
cmp dword [esp - 16], 0 ; check EXCEPTION_HANDLER_CONTEXT.OldIdtHandler\r
jz DoReturn\r
movzx ebx, word [ecx + IA32_TSS._CS]\r
mov [eax - 0x8], ebx ; create CS in old stack\r
mov ebx, dword [ecx + IA32_TSS.EFLAGS]\r
- bts ebx, 8\r
+ bts ebx, 8 ; Set TF\r
mov [eax - 0x4], ebx ; create eflags in old stack\r
- mov dword [ecx + IA32_TSS.EFLAGS], ebx ; update eflags in old TSS\r
- mov eax, dword [ecx + IA32_TSS._ESP] ; Get old stack pointer\r
sub eax, 0xc ; minus 12 byte\r
mov dword [ecx + IA32_TSS._ESP], eax ; Set new stack pointer\r
\r
pop r15\r
\r
mov rsp, rbp\r
+ cmp qword [rbp + 8], 14 ; #PF?\r
+ jne .1\r
+ bts qword [rsp + 40], 8 ; RFLAGS.TF\r
+.1:\r
pop rbp\r
add rsp, 16\r
cmp qword [rsp - 32], 0 ; check EXCEPTION_HANDLER_CONTEXT.OldIdtHandler\r