2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntdll/dispatch/amd64/dispatch.S
5 * PURPOSE: Usermode dispatcher stubs
7 * PROGRAMMER: Timo kreuzer (timo.kreuzer@reactos.org)
10 /* INCLUDES ******************************************************************/
13 #include <ksamd64.inc>
15 EXTERN NtContinue:PROC
17 EXTERN ZwCallbackReturn:PROC
18 EXTERN RtlRaiseStatus:PROC
22 PUBLIC LdrInitializeThunk
23 .PROC LdrInitializeThunk
28 /* First parameter is the APC context */
34 PUBLIC KiUserApcDispatcher
35 .PROC KiUserApcDispatcher
37 /* We enter with a 16 byte aligned stack */
39 mov rcx, [rsp + CONTEXT_P1Home] /* NormalContext */
40 mov rdx, [rsp + CONTEXT_P2Home] /* SystemArgument1 */
41 mov r8, [rsp + CONTEXT_P3Home] /* SystemArgument2 */
42 lea r9, [rsp] /* Context */
43 call qword ptr [rsp + CONTEXT_P4Home] /* NormalRoutine */
45 /* NtContinue(Context, TRUE); */
55 PUBLIC KiRaiseUserExceptionDispatcher
56 .PROC KiRaiseUserExceptionDispatcher
62 PUBLIC KiUserCallbackDispatcher
63 .PROC KiUserCallbackDispatcher
65 /* The stack is set up with a UCALLOUT_FRAME */
66 /* The frame ends with a MACHINE_FRAME. */
69 /* This is for the Home space, Buffer, Length and ApiNumber */
74 /* We enter the function with a fully setup stack, so it must be aligned! */
81 /* Get the parameters from the callout frame */
82 mov rcx, [rsp + CkBuffer]
83 mov edx, [rsp + CkLength]
84 mov r8d, [rsp + CkApiNumber]
86 /* Get the callback table */
88 mov r9, [rax + PeKernelCallbackTable]
90 /* Call the routine */
91 call qword ptr [r9 + r8 * 8]
93 /* Return from callback */
99 /* Save callback return value */
113 RtlDispatchException(
114 _In_ PEXCEPTION_RECORD ExceptionRecord,
115 _In_ PCONTEXT ContextRecord);
117 EXTERN RtlDispatchException:PROC
123 _In_ PCONTEXT Context,
124 _In_ BOOLEAN TestAlert);
126 EXTERN ZwContinue:PROC
132 _In_ PEXCEPTION_RECORD ExceptionRecord,
133 _In_ PCONTEXT Context,
134 _In_ BOOLEAN SearchFrames);
136 EXTERN ZwRaiseException:PROC
142 _In_ PEXCEPTION_RECORD ExceptionRecord);
144 EXTERN RtlRaiseException:PROC
148 KiUserExceptionDispatcher(
149 CONTEXT ContextRecord<rcx>,
150 PEXCEPTION_RECORD ExceptionRecord<rdx>);
152 This function is called with the following stack layout:
153 CONTEXT ContextRecord <- RSP, RCX
154 EXCEPTION_RECORD ExceptionRecord <- RDX
156 MACHINE_FRAME MachineFrame
158 PUBLIC KiUserExceptionDispatcher
159 .PROC KiUserExceptionDispatcher
161 /* The stack is set up with a KUSER_EXCEPTION_STACK */
162 /* The frame ends with a MACHINE_FRAME. */
165 /* This is for the alignment, EXCEPTION_RECORD and CONTEXT */
166 .ALLOCSTACK 8 + EXCEPTION_RECORD_LENGTH + CONTEXT_FRAME_LENGTH
169 /* Clear direction flag */
172 /* Dispatch the exception */
173 call RtlDispatchException
175 /* Check for success */
179 /* We're fine, continue execution */
180 lea rcx, [rsp] /* ContextRecord */
181 mov dl, 0 /* TestAlert */
189 /* Raise the exception */
190 lea rcx, [rsp + CONTEXT_FRAME_LENGTH] /* ExceptionRecord */
191 lea rdx, [rsp] /* ContextRecord */
193 call ZwRaiseException
196 lea rcx, [rsp + CONTEXT_FRAME_LENGTH] /* ExceptionRecord */
198 call KiUserExceptionDispatcherNested
205 KiUserExceptionDispatcherNested(
206 _In_ ExceptionRecord<rcx>,
210 .PROC KiUserExceptionDispatcherNested
211 /* Allocate space for the nested exception record */
212 sub rsp, EXCEPTION_RECORD_LENGTH
213 .ALLOCSTACK EXCEPTION_RECORD_LENGTH
217 mov dword ptr [rsp + ErNumberParameters], 0
218 mov dword ptr [rsp + ErExceptionFlags], EXCEPTION_NONCONTINUABLE
219 mov [rsp + ErExceptionRecord], rcx
220 mov [rsp + ErExceptionCode], edx
222 /* Raise the exception */
224 call RtlRaiseException
226 /* Cleanup stack and return */
227 add rsp, EXCEPTION_RECORD_LENGTH