fixed uninitialized variable warning
[reactos.git] / reactos / ntoskrnl / ke / usercall.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ke/usercall.c
5 * PURPOSE: User-Mode callbacks. Portable part.
6 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <internal/debug.h>
14
15 NTSTATUS
16 STDCALL
17 KiCallUserMode(
18 IN PVOID *OutputBuffer,
19 IN PULONG OutputLength
20 );
21
22 PULONG
23 STDCALL
24 KiGetUserModeStackAddress(
25 VOID
26 );
27
28 /* FUNCTIONS *****************************************************************/
29
30 /*
31 * @implemented
32 */
33 NTSTATUS
34 STDCALL
35 KeUserModeCallback(IN ULONG RoutineIndex,
36 IN PVOID Argument,
37 IN ULONG ArgumentLength,
38 OUT PVOID *Result,
39 OUT PULONG ResultLength)
40 {
41 ULONG_PTR NewStack, OldStack;
42 PULONG UserEsp;
43 NTSTATUS CallbackStatus = STATUS_SUCCESS;
44 PEXCEPTION_REGISTRATION_RECORD ExceptionList;
45 DPRINT("KeUserModeCallback(RoutineIndex %d, Argument %X, ArgumentLength %d)\n",
46 RoutineIndex, Argument, ArgumentLength);
47 ASSERT(KeGetCurrentThread()->ApcState.KernelApcInProgress == FALSE);
48 ASSERT(KeGetPreviousMode() == UserMode);
49
50 /* Get the current user-mode stack */
51 UserEsp = KiGetUserModeStackAddress();
52 OldStack = *UserEsp;
53
54 /* Enter a SEH Block */
55 _SEH_TRY
56 {
57 /* Calculate and align the stack size */
58 NewStack = (OldStack - ArgumentLength) & ~3;
59
60 /* Make sure it's writable */
61 ProbeForWrite((PVOID)(NewStack - 6 * sizeof(ULONG_PTR)),
62 ArgumentLength + 6 * sizeof(ULONG_PTR),
63 sizeof(CHAR));
64
65 /* Copy the buffer into the stack */
66 RtlCopyMemory((PVOID)NewStack, Argument, ArgumentLength);
67
68 /* Write the arguments */
69 NewStack -= 24;
70 *(PULONG)NewStack = 0;
71 *(PULONG)(NewStack + 4) = RoutineIndex;
72 *(PULONG)(NewStack + 8) = (NewStack + 24);
73 *(PULONG)(NewStack + 12) = ArgumentLength;
74
75 /* Save the exception list */
76 ExceptionList = KeGetCurrentThread()->Teb->Tib.ExceptionList;
77
78 /* Jump to user mode */
79 *UserEsp = NewStack;
80 CallbackStatus = KiCallUserMode(Result, ResultLength);
81
82 /* FIXME: Handle user-mode exception status */
83
84 /* Restore exception list */
85 KeGetCurrentThread()->Teb->Tib.ExceptionList = ExceptionList;
86 }
87 _SEH_HANDLE
88 {
89 CallbackStatus = _SEH_GetExceptionCode();
90 }
91 _SEH_END;
92
93 /* FIXME: Flush GDI Batch */
94
95 /* Restore stack and return */
96 *UserEsp = OldStack;
97 return CallbackStatus;
98 }
99
100 /* EOF */