move mesa32 over to new dir
[reactos.git] / reactos / dll / ntdll / main / dispatch.c
1 /* COPYRIGHT: See COPYING in the top level directory
2 * PROJECT: ReactOS NT Library
3 * FILE: lib/ntdll/main/dispatch.c
4 * PURPOSE: User-Mode NT Dispatchers
5 * PROGRAMERS: Alex Ionescu (alex@relsoft.net)
6 * David Welch <welch@cwcom.net>
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include <ntdll.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 typedef NTSTATUS (NTAPI *USER_CALL)(PVOID Argument, ULONG ArgumentLength);
16
17 EXCEPTION_DISPOSITION NTAPI
18 RtlpExecuteVectoredExceptionHandlers(IN PEXCEPTION_RECORD ExceptionRecord,
19 IN PCONTEXT Context);
20
21 /* FUNCTIONS ****************************************************************/
22
23 /*
24 * @implemented
25 */
26 VOID
27 NTAPI
28 KiUserExceptionDispatcher(PEXCEPTION_RECORD ExceptionRecord,
29 PCONTEXT Context)
30 {
31 EXCEPTION_RECORD NestedExceptionRecord;
32 NTSTATUS Status;
33
34 /* call the vectored exception handlers */
35 if(RtlpExecuteVectoredExceptionHandlers(ExceptionRecord,
36 Context) != ExceptionContinueExecution)
37 {
38 goto ContinueExecution;
39 }
40 else
41 {
42 /* Dispatch the exception and check the result */
43 if(RtlDispatchException(ExceptionRecord, Context))
44 {
45 ContinueExecution:
46 /* Continue executing */
47 Status = NtContinue(Context, FALSE);
48 }
49 else
50 {
51 /* Raise an exception */
52 Status = NtRaiseException(ExceptionRecord, Context, FALSE);
53 }
54 }
55
56 /* Setup the Exception record */
57 NestedExceptionRecord.ExceptionCode = Status;
58 NestedExceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE;
59 NestedExceptionRecord.ExceptionRecord = ExceptionRecord;
60 NestedExceptionRecord.NumberParameters = Status;
61
62 /* Raise the exception */
63 RtlRaiseException(&NestedExceptionRecord);
64 }
65
66 /*
67 * @implemented
68 */
69 VOID
70 NTAPI
71 KiRaiseUserExceptionDispatcher(VOID)
72 {
73 EXCEPTION_RECORD ExceptionRecord;
74
75 /* Setup the exception record */
76 ExceptionRecord.ExceptionCode = ((PTEB)NtCurrentTeb())->ExceptionCode;
77 ExceptionRecord.ExceptionFlags = 0;
78 ExceptionRecord.ExceptionRecord = NULL;
79 ExceptionRecord.NumberParameters = 0;
80
81 /* Raise the exception */
82 RtlRaiseException(&ExceptionRecord);
83 }
84
85 /*
86 * @implemented
87 */
88 VOID
89 NTAPI
90 KiUserCallbackDispatcher(ULONG Index,
91 PVOID Argument,
92 ULONG ArgumentLength)
93 {
94 /* Return with the result of the callback function */
95 ZwCallbackReturn(NULL,
96 0,
97 ((USER_CALL)(NtCurrentPeb()->KernelCallbackTable[Index]))
98 (Argument, ArgumentLength));
99 }