Alex Ionescu <ionucu@videotron.ca>
[reactos.git] / reactos / ntoskrnl / ps / win32.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ps/win32.c
6 * PURPOSE: win32k support
7 *
8 * PROGRAMMERS: Eric Kohl (ekohl@rz-online.de)
9 */
10
11 /* INCLUDES ****************************************************************/
12
13 #include <ntoskrnl.h>
14
15 /* TYPES *******************************************************************/
16
17 /* GLOBALS ******************************************************************/
18
19 static PW32_PROCESS_CALLBACK PspWin32ProcessCallback = NULL;
20 static PW32_THREAD_CALLBACK PspWin32ThreadCallback = NULL;
21 static ULONG PspWin32ProcessSize = 0;
22 static ULONG PspWin32ThreadSize = 0;
23
24 extern OBJECT_CREATE_ROUTINE ExpWindowStationObjectCreate;
25 extern OBJECT_PARSE_ROUTINE ExpWindowStationObjectParse;
26 extern OBJECT_DELETE_ROUTINE ExpWindowStationObjectDelete;
27 extern OBJECT_FIND_ROUTINE ExpWindowStationObjectFind;
28 extern OBJECT_CREATE_ROUTINE ExpDesktopObjectCreate;
29 extern OBJECT_DELETE_ROUTINE ExpDesktopObjectDelete;
30
31 /* FUNCTIONS ***************************************************************/
32
33 PW32THREAD STDCALL
34 PsGetWin32Thread(VOID)
35 {
36 return(PsGetCurrentThread()->Tcb.Win32Thread);
37 }
38
39 PW32PROCESS STDCALL
40 PsGetWin32Process(VOID)
41 {
42 return(PsGetCurrentProcess()->Win32Process);
43 }
44
45 NTSTATUS STDCALL
46 PsCreateWin32Process(PEPROCESS Process)
47 {
48 if (Process->Win32Process != NULL)
49 return(STATUS_SUCCESS);
50
51 Process->Win32Process = ExAllocatePool(NonPagedPool,
52 PspWin32ProcessSize);
53 if (Process->Win32Process == NULL)
54 return(STATUS_NO_MEMORY);
55
56 RtlZeroMemory(Process->Win32Process,
57 PspWin32ProcessSize);
58
59 return(STATUS_SUCCESS);
60 }
61
62
63 /*
64 * @implemented
65 */
66 VOID STDCALL
67 PsEstablishWin32Callouts (PW32_PROCESS_CALLBACK W32ProcessCallback,
68 PW32_THREAD_CALLBACK W32ThreadCallback,
69 PW32_OBJECT_CALLBACK W32ObjectCallback,
70 PVOID Param4,
71 ULONG W32ThreadSize,
72 ULONG W32ProcessSize)
73 {
74 PspWin32ProcessCallback = W32ProcessCallback;
75 PspWin32ThreadCallback = W32ThreadCallback;
76
77 PspWin32ProcessSize = W32ProcessSize;
78 PspWin32ThreadSize = W32ThreadSize;
79
80 ExpWindowStationObjectCreate = W32ObjectCallback->WinStaCreate;
81 ExpWindowStationObjectParse = W32ObjectCallback->WinStaParse;
82 ExpWindowStationObjectDelete = W32ObjectCallback->WinStaDelete;
83 ExpWindowStationObjectFind = W32ObjectCallback->WinStaFind;
84 ExpDesktopObjectCreate = W32ObjectCallback->DesktopCreate;
85 ExpDesktopObjectDelete = W32ObjectCallback->DesktopDelete;
86 }
87
88 NTSTATUS
89 PsInitWin32Thread (PETHREAD Thread)
90 {
91 PEPROCESS Process;
92
93 Process = Thread->ThreadsProcess;
94
95 if (Process->Win32Process == NULL)
96 {
97 /* FIXME - lock the process */
98 Process->Win32Process = ExAllocatePool (NonPagedPool,
99 PspWin32ProcessSize);
100
101 if (Process->Win32Process == NULL)
102 return STATUS_NO_MEMORY;
103
104 RtlZeroMemory (Process->Win32Process,
105 PspWin32ProcessSize);
106 /* FIXME - unlock the process */
107
108 if (PspWin32ProcessCallback != NULL)
109 {
110 PspWin32ProcessCallback (Process, TRUE);
111 }
112 }
113
114 if (Thread->Tcb.Win32Thread == NULL)
115 {
116 Thread->Tcb.Win32Thread = ExAllocatePool (NonPagedPool,
117 PspWin32ThreadSize);
118 if (Thread->Tcb.Win32Thread == NULL)
119 return STATUS_NO_MEMORY;
120
121 RtlZeroMemory (Thread->Tcb.Win32Thread,
122 PspWin32ThreadSize);
123
124 if (PspWin32ThreadCallback != NULL)
125 {
126 PspWin32ThreadCallback (Thread, TRUE);
127 }
128 }
129
130 return(STATUS_SUCCESS);
131 }
132
133
134 VOID
135 PsTerminateWin32Process (PEPROCESS Process)
136 {
137 if (Process->Win32Process == NULL)
138 return;
139
140 if (PspWin32ProcessCallback != NULL)
141 {
142 PspWin32ProcessCallback (Process, FALSE);
143 }
144
145 /* don't delete the W32PROCESS structure at this point, wait until the
146 EPROCESS structure is being freed */
147 }
148
149
150 VOID
151 PsTerminateWin32Thread (PETHREAD Thread)
152 {
153 if (Thread->Tcb.Win32Thread != NULL)
154 {
155 if (PspWin32ThreadCallback != NULL)
156 {
157 PspWin32ThreadCallback (Thread, FALSE);
158 }
159
160 /* don't delete the W32THREAD structure at this point, wait until the
161 ETHREAD structure is being freed */
162 }
163 }
164
165 /* EOF */