cleanup/reformat syscall code, save return value as soon as possible so that eax...
[reactos.git] / reactos / ntoskrnl / ke / i386 / usercall.c
1 /* $Id: usercall.c,v 1.27 2004/07/01 01:52:37 royce Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/hal/x86/usercall.c
6 * PURPOSE: 2E interrupt handler
7 * PROGRAMMER: David Welch (david.welch@seh.ox.ac.uk)
8 * UPDATE HISTORY:
9 * ???
10 */
11
12 /* INCLUDES ******************************************************************/
13
14 #define NTOS_MODE_KERNEL
15 #include <ntos.h>
16 #include <internal/ntoskrnl.h>
17 #include <internal/ke.h>
18 #include <internal/ps.h>
19 #include <internal/i386/segment.h>
20 #include <internal/i386/mm.h>
21
22 #define NDEBUG
23 #include <internal/debug.h>
24
25 #include <internal/ps.h>
26
27 /* FUNCTIONS *****************************************************************/
28
29 VOID
30 KiSystemCallHook(ULONG Nr, ...)
31 {
32 #if 0
33 va_list ap;
34 ULONG i;
35
36 va_start(ap, Nr);
37
38 DbgPrint("%x/%d ", KeServiceDescriptorTable[0].SSDT[Nr].SysCallPtr, Nr);
39 DbgPrint("%x (", KeServiceDescriptorTable[0].SSPT[Nr].ParamBytes);
40 for (i = 0; i < KeServiceDescriptorTable[0].SSPT[Nr].ParamBytes / 4; i++)
41 {
42 DbgPrint("%x, ", va_arg(ap, ULONG));
43 }
44 DbgPrint(")\n");
45 assert_irql(PASSIVE_LEVEL);
46 va_end(ap);
47 #endif
48 }
49
50 VOID
51 KiAfterSystemCallHook(PKTRAP_FRAME TrapFrame)
52 {
53 if (KeGetCurrentThread()->Alerted[1] != 0 && TrapFrame->Cs != KERNEL_CS)
54 {
55 KiDeliverNormalApc();
56 }
57 if (KeGetCurrentThread()->Alerted[0] != 0 && TrapFrame->Cs != KERNEL_CS)
58 {
59 KiDeliverUserApc(TrapFrame);
60 }
61 }
62
63
64 VOID
65 KiServiceCheck (ULONG Nr)
66 {
67 PETHREAD Thread;
68
69 Thread = PsGetCurrentThread();
70
71 #if 0
72 DbgPrint ("KiServiceCheck(%p) called\n", Thread);
73 DbgPrint ("Service %d (%p)\n", Nr, KeServiceDescriptorTableShadow[1].SSDT[Nr].SysCallPtr);
74 #endif
75
76 if (Thread->Tcb.ServiceTable != KeServiceDescriptorTableShadow)
77 {
78 #if 0
79 DbgPrint ("Initialize Win32 thread\n");
80 #endif
81
82 PsInitWin32Thread (Thread);
83
84 Thread->Tcb.ServiceTable = KeServiceDescriptorTableShadow;
85 }
86 }
87
88 // This function should be used by win32k.sys to add its own user32/gdi32 services
89 // TableIndex is 0 based
90 // ServiceCountTable its not used at the moment
91 /*
92 * @implemented
93 */
94 BOOLEAN STDCALL
95 KeAddSystemServiceTable (
96 PSSDT SSDT,
97 PULONG ServiceCounterTable,
98 ULONG NumberOfServices,
99 PSSPT SSPT,
100 ULONG TableIndex
101 )
102 {
103 if (TableIndex > SSDT_MAX_ENTRIES - 1)
104 return FALSE;
105
106 /* check if descriptor table entry is free */
107 if ((KeServiceDescriptorTable[TableIndex].SSDT != NULL) ||
108 (KeServiceDescriptorTableShadow[TableIndex].SSDT != NULL))
109 return FALSE;
110
111 /* initialize the shadow service descriptor table */
112 KeServiceDescriptorTableShadow[TableIndex].SSDT = SSDT;
113 KeServiceDescriptorTableShadow[TableIndex].SSPT = SSPT;
114 KeServiceDescriptorTableShadow[TableIndex].NumberOfServices = NumberOfServices;
115 KeServiceDescriptorTableShadow[TableIndex].ServiceCounterTable = ServiceCounterTable;
116
117 /* initialize the service descriptor table (not for win32k services) */
118 if (TableIndex != 1)
119 {
120 KeServiceDescriptorTable[TableIndex].SSDT = SSDT;
121 KeServiceDescriptorTable[TableIndex].SSPT = SSPT;
122 KeServiceDescriptorTable[TableIndex].NumberOfServices = NumberOfServices;
123 KeServiceDescriptorTable[TableIndex].ServiceCounterTable = ServiceCounterTable;
124 }
125
126 return TRUE;
127 }
128
129 /*
130 * @unimplemented
131 */
132 STDCALL
133 BOOLEAN
134 KeRemoveSystemServiceTable(
135 IN PUCHAR Number
136 )
137 {
138 UNIMPLEMENTED;
139 return FALSE;
140 }
141
142 /*
143 * @unimplemented
144 */
145 STDCALL
146 NTSTATUS
147 KeUserModeCallback(
148 IN ULONG FunctionID,
149 IN PVOID InputBuffer,
150 IN ULONG InputLength,
151 OUT PVOID *OutputBuffer,
152 OUT PULONG OutputLength
153 )
154 {
155 UNIMPLEMENTED;
156 return 0;
157 }
158
159 /* EOF */