update for HEAD-2003091401
[reactos.git] / ntoskrnl / ke / i386 / usercall.c
1 /* $Id$
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 KiSystemCallHook(ULONG Nr, ...)
30 {
31 #if 0
32    va_list ap;
33    ULONG i;
34
35    va_start(ap, Nr);
36
37    DbgPrint("%x/%d ", KeServiceDescriptorTable[0].SSDT[Nr].SysCallPtr, Nr);
38    DbgPrint("%x (", KeServiceDescriptorTable[0].SSPT[Nr].ParamBytes);
39    for (i = 0; i < KeServiceDescriptorTable[0].SSPT[Nr].ParamBytes / 4; i++)
40      {
41         DbgPrint("%x, ", va_arg(ap, ULONG));
42      }
43    DbgPrint(")\n");
44    assert_irql(PASSIVE_LEVEL);
45    va_end(ap);
46 #endif
47 }
48
49 ULONG KiAfterSystemCallHook(ULONG NtStatus, PKTRAP_FRAME TrapFrame)
50 {
51   if (KeGetCurrentThread()->Alerted[1] != 0 && TrapFrame->Cs != KERNEL_CS)
52     {
53       KiDeliverNormalApc();
54     }
55   if (KeGetCurrentThread()->Alerted[0] != 0 && TrapFrame->Cs != KERNEL_CS)
56     {
57       KiDeliverUserApc(TrapFrame);
58     }
59   return(NtStatus);
60 }
61
62
63 VOID KiServiceCheck (ULONG Nr)
64 {
65   PETHREAD Thread;
66
67   Thread = PsGetCurrentThread();
68
69 #if 0
70   DbgPrint ("KiServiceCheck(%p) called\n", Thread);
71   DbgPrint ("Service %d (%p)\n", Nr, KeServiceDescriptorTableShadow[1].SSDT[Nr].SysCallPtr);
72 #endif
73
74   if (Thread->Tcb.ServiceTable != KeServiceDescriptorTableShadow)
75     {
76 #if 0
77       DbgPrint ("Initialize Win32 thread\n");
78 #endif
79
80       PsInitWin32Thread (Thread);
81
82       Thread->Tcb.ServiceTable = KeServiceDescriptorTableShadow;
83     }
84 }
85
86 // This function should be used by win32k.sys to add its own user32/gdi32 services
87 // TableIndex is 0 based
88 // ServiceCountTable its not used at the moment
89 /*
90  * @implemented
91  */
92 BOOLEAN STDCALL
93 KeAddSystemServiceTable (
94         PSSDT   SSDT,
95         PULONG  ServiceCounterTable,
96         ULONG   NumberOfServices,
97         PSSPT   SSPT,
98         ULONG   TableIndex
99         )
100 {
101     if (TableIndex > SSDT_MAX_ENTRIES - 1)
102         return FALSE;
103
104     /* check if descriptor table entry is free */
105     if ((KeServiceDescriptorTable[TableIndex].SSDT != NULL) ||
106         (KeServiceDescriptorTableShadow[TableIndex].SSDT != NULL))
107         return FALSE;
108
109     /* initialize the shadow service descriptor table */
110     KeServiceDescriptorTableShadow[TableIndex].SSDT = SSDT;
111     KeServiceDescriptorTableShadow[TableIndex].SSPT = SSPT;
112     KeServiceDescriptorTableShadow[TableIndex].NumberOfServices = NumberOfServices;
113     KeServiceDescriptorTableShadow[TableIndex].ServiceCounterTable = ServiceCounterTable;
114
115     /* initialize the service descriptor table (not for win32k services) */
116     if (TableIndex != 1)
117     {
118         KeServiceDescriptorTable[TableIndex].SSDT = SSDT;
119         KeServiceDescriptorTable[TableIndex].SSPT = SSPT;
120         KeServiceDescriptorTable[TableIndex].NumberOfServices = NumberOfServices;
121         KeServiceDescriptorTable[TableIndex].ServiceCounterTable = ServiceCounterTable;
122     }
123
124     return TRUE;
125 }
126
127 /* EOF */