migrate substitution keywords to SVN
[reactos.git] / reactos / ntoskrnl / ps / win32.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: ntoskrnl/ps/win32.c
24 * PURPOSE: win32k support
25 * PROGRAMMER: Eric Kohl (ekohl@rz-online.de)
26 * REVISION HISTORY:
27 * 04/01/2002: Created
28 */
29
30 /* INCLUDES ****************************************************************/
31
32 #include <ntoskrnl.h>
33
34 /* TYPES *******************************************************************/
35
36 /* GLOBALS ******************************************************************/
37
38 static PW32_PROCESS_CALLBACK PspWin32ProcessCallback = NULL;
39 static PW32_THREAD_CALLBACK PspWin32ThreadCallback = NULL;
40 static ULONG PspWin32ProcessSize = 0;
41 static ULONG PspWin32ThreadSize = 0;
42
43 /* FUNCTIONS ***************************************************************/
44
45 PW32THREAD STDCALL
46 PsGetWin32Thread(VOID)
47 {
48 return(PsGetCurrentThread()->Tcb.Win32Thread);
49 }
50
51 PW32PROCESS STDCALL
52 PsGetWin32Process(VOID)
53 {
54 return(PsGetCurrentProcess()->Win32Process);
55 }
56
57 NTSTATUS STDCALL
58 PsCreateWin32Process(PEPROCESS Process)
59 {
60 if (Process->Win32Process != NULL)
61 return(STATUS_SUCCESS);
62
63 Process->Win32Process = ExAllocatePool(NonPagedPool,
64 PspWin32ProcessSize);
65 if (Process->Win32Process == NULL)
66 return(STATUS_NO_MEMORY);
67
68 RtlZeroMemory(Process->Win32Process,
69 PspWin32ProcessSize);
70
71 return(STATUS_SUCCESS);
72 }
73
74
75 /*
76 * @implemented
77 */
78 VOID STDCALL
79 PsEstablishWin32Callouts (PW32_PROCESS_CALLBACK W32ProcessCallback,
80 PW32_THREAD_CALLBACK W32ThreadCallback,
81 PVOID Param3,
82 PVOID Param4,
83 ULONG W32ThreadSize,
84 ULONG W32ProcessSize)
85 {
86 PspWin32ProcessCallback = W32ProcessCallback;
87 PspWin32ThreadCallback = W32ThreadCallback;
88
89 PspWin32ProcessSize = W32ProcessSize;
90 PspWin32ThreadSize = W32ThreadSize;
91 }
92
93
94 NTSTATUS
95 PsInitWin32Thread (PETHREAD Thread)
96 {
97 PEPROCESS Process;
98
99 Process = Thread->ThreadsProcess;
100
101 if (Process->Win32Process == NULL)
102 {
103 /* FIXME - lock the process */
104 Process->Win32Process = ExAllocatePool (NonPagedPool,
105 PspWin32ProcessSize);
106
107 if (Process->Win32Process == NULL)
108 return STATUS_NO_MEMORY;
109
110 RtlZeroMemory (Process->Win32Process,
111 PspWin32ProcessSize);
112 /* FIXME - unlock the process */
113
114 if (PspWin32ProcessCallback != NULL)
115 {
116 PspWin32ProcessCallback (Process, TRUE);
117 }
118 }
119
120 if (Thread->Tcb.Win32Thread == NULL)
121 {
122 Thread->Tcb.Win32Thread = ExAllocatePool (NonPagedPool,
123 PspWin32ThreadSize);
124 if (Thread->Tcb.Win32Thread == NULL)
125 return STATUS_NO_MEMORY;
126
127 RtlZeroMemory (Thread->Tcb.Win32Thread,
128 PspWin32ThreadSize);
129
130 if (PspWin32ThreadCallback != NULL)
131 {
132 PspWin32ThreadCallback (Thread, TRUE);
133 }
134 }
135
136 return(STATUS_SUCCESS);
137 }
138
139
140 VOID
141 PsTerminateWin32Process (PEPROCESS Process)
142 {
143 if (Process->Win32Process == NULL)
144 return;
145
146 if (PspWin32ProcessCallback != NULL)
147 {
148 PspWin32ProcessCallback (Process, FALSE);
149 }
150
151 /* don't delete the W32PROCESS structure at this point, wait until the
152 EPROCESS structure is being freed */
153 }
154
155
156 VOID
157 PsTerminateWin32Thread (PETHREAD Thread)
158 {
159 if (Thread->Tcb.Win32Thread != NULL)
160 {
161 if (PspWin32ThreadCallback != NULL)
162 {
163 PspWin32ThreadCallback (Thread, FALSE);
164 }
165
166 /* don't delete the W32THREAD structure at this point, wait until the
167 ETHREAD structure is being freed */
168 }
169 }
170
171 /* EOF */