[NTDLL][KERNEL32] Implement FLS callbacks.
[reactos.git] / 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
14 #define NDEBUG
15 #include <debug.h>
16
17 typedef NTSTATUS (NTAPI *USER_CALL)(PVOID Argument, ULONG ArgumentLength);
18
19 /* FUNCTIONS ****************************************************************/
20
21 /*
22 * @implemented
23 */
24 VOID
25 NTAPI
26 KiUserExceptionDispatcher(PEXCEPTION_RECORD ExceptionRecord,
27 PCONTEXT Context)
28 {
29 EXCEPTION_RECORD NestedExceptionRecord;
30 NTSTATUS Status;
31
32 /* Dispatch the exception and check the result */
33 if (RtlDispatchException(ExceptionRecord, Context))
34 {
35 /* Continue executing */
36 Status = NtContinue(Context, FALSE);
37 }
38 else
39 {
40 /* Raise an exception */
41 Status = NtRaiseException(ExceptionRecord, Context, FALSE);
42 }
43
44 /* Setup the Exception record */
45 NestedExceptionRecord.ExceptionCode = Status;
46 NestedExceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE;
47 NestedExceptionRecord.ExceptionRecord = ExceptionRecord;
48 NestedExceptionRecord.NumberParameters = Status;
49
50 /* Raise the exception */
51 RtlRaiseException(&NestedExceptionRecord);
52 }
53
54 /*
55 * @implemented
56 */
57 VOID
58 NTAPI
59 KiRaiseUserExceptionDispatcher(VOID)
60 {
61 EXCEPTION_RECORD ExceptionRecord;
62
63 /* Setup the exception record */
64 ExceptionRecord.ExceptionCode = ((PTEB)NtCurrentTeb())->ExceptionCode;
65 ExceptionRecord.ExceptionFlags = 0;
66 ExceptionRecord.ExceptionRecord = NULL;
67 ExceptionRecord.NumberParameters = 0;
68
69 /* Raise the exception */
70 RtlRaiseException(&ExceptionRecord);
71 }
72
73 /*
74 * @implemented
75 */
76 VOID
77 NTAPI
78 KiUserCallbackDispatcher(ULONG Index,
79 PVOID Argument,
80 ULONG ArgumentLength)
81 {
82 /* Return with the result of the callback function */
83 USER_CALL *KernelCallbackTable = NtCurrentPeb()->KernelCallbackTable;
84 ZwCallbackReturn(NULL,
85 0,
86 KernelCallbackTable[Index](Argument, ArgumentLength));
87 }