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