Skip to content

Commit 9ab8761

Browse files
committed
[NTDLL] Improve x64 KiUserExceptionDispatcher
Add Wow64PrepareForException handler, which is well documented as a hook for KiUserExceptionDispatcher (see e.g. https://github.com/brew02/KiUserExceptionDispatcherHook) and used by ntdll_winetest. This also reloads rcx and rdx for the call to RtlDispatchException from the stack instead of relying on the registers to be set up by the kernel, which again is a feature used by ntdll_winetest, which calls this function from a hook with zeroed registers.
1 parent 9f78833 commit 9ab8761

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

dll/ntdll/dispatch/amd64/dispatch.S

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ EXTERN LdrpInit:PROC
1717
EXTERN ZwCallbackReturn:PROC
1818
EXTERN RtlRaiseStatus:PROC
1919

20+
.data
21+
22+
Wow64PrepareForException:
23+
.quad 0
24+
2025
.code
2126

2227
PUBLIC LdrInitializeThunk
@@ -195,7 +200,21 @@ PUBLIC KiUserExceptionDispatcher
195200
/* Clear direction flag */
196201
cld
197202

203+
/* Check the WOW64 callback */
204+
mov rax, qword ptr Wow64PrepareForException[rip]
205+
test rax, rax
206+
jz .NoWow64
207+
208+
/* Prepare for WOW64 exception dispatching */
209+
lea rcx, [rsp + CONTEXT_FRAME_LENGTH] /* ExceptionRecord */
210+
lea rdx, [rsp] /* ContextRecord */
211+
call rax
212+
213+
.NoWow64:
214+
198215
/* Dispatch the exception */
216+
lea rcx, [rsp + CONTEXT_FRAME_LENGTH] /* ExceptionRecord */
217+
lea rdx, [rsp] /* ContextRecord */
199218
call RtlDispatchException
200219

201220
/* Check for success */

0 commit comments

Comments
 (0)