Fixed prototype for MmSetAddressRangeModified().
[reactos.git] / 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 <ddk/ntddk.h>
33 #include <internal/ps.h>
34 #include <napi/win32.h>
35
36 /* TYPES *******************************************************************/
37
38 /* GLOBALS ******************************************************************/
39
40 static PW32_PROCESS_CALLBACK PspWin32ProcessCallback = NULL;
41 static PW32_THREAD_CALLBACK PspWin32ThreadCallback = NULL;
42 static ULONG PspWin32ProcessSize = 0;
43 static ULONG PspWin32ThreadSize = 0;
44
45 /* FUNCTIONS ***************************************************************/
46
47 PW32THREAD STDCALL
48 PsGetWin32Thread(VOID)
49 {
50   return(PsGetCurrentThread()->Win32Thread);
51 }
52
53 PW32PROCESS STDCALL
54 PsGetWin32Process(VOID)
55 {
56   return(PsGetCurrentProcess()->Win32Process);
57 }
58
59 NTSTATUS STDCALL
60 PsCreateWin32Process(PEPROCESS Process)
61 {
62   if (Process->Win32Process != NULL)
63     return(STATUS_SUCCESS);
64
65   Process->Win32Process = ExAllocatePool(NonPagedPool,
66                                          PspWin32ProcessSize);
67   if (Process->Win32Process == NULL)
68     return(STATUS_NO_MEMORY);
69
70   RtlZeroMemory(Process->Win32Process,
71                 PspWin32ProcessSize);
72
73   return(STATUS_SUCCESS);
74 }
75
76
77 /*
78  * @implemented
79  */
80 VOID STDCALL
81 PsEstablishWin32Callouts (PW32_PROCESS_CALLBACK W32ProcessCallback,
82                           PW32_THREAD_CALLBACK W32ThreadCallback,
83                           PVOID Param3,
84                           PVOID Param4,
85                           ULONG W32ThreadSize,
86                           ULONG W32ProcessSize)
87 {
88   PspWin32ProcessCallback = W32ProcessCallback;
89   PspWin32ThreadCallback = W32ThreadCallback;
90
91   PspWin32ProcessSize = W32ProcessSize;
92   PspWin32ThreadSize = W32ThreadSize;
93 }
94
95
96 NTSTATUS
97 PsInitWin32Thread (PETHREAD Thread)
98 {
99   PEPROCESS Process;
100
101   Process = Thread->ThreadsProcess;
102
103   if (Process->Win32Process == NULL)
104     {
105       Process->Win32Process = ExAllocatePool (NonPagedPool,
106                                               PspWin32ProcessSize);
107       if (Process->Win32Process == NULL)
108         return STATUS_NO_MEMORY;
109
110       RtlZeroMemory (Process->Win32Process,
111                      PspWin32ProcessSize);
112
113       if (PspWin32ProcessCallback != NULL)
114         {
115           PspWin32ProcessCallback (Process, TRUE);
116         }
117     }
118
119   if (Thread->Win32Thread == NULL)
120     {
121       Thread->Win32Thread = ExAllocatePool (NonPagedPool,
122                                             PspWin32ThreadSize);
123       if (Thread->Win32Thread == NULL)
124         return STATUS_NO_MEMORY;
125
126       RtlZeroMemory (Thread->Win32Thread,
127                      PspWin32ThreadSize);
128
129       if (PspWin32ThreadCallback != NULL)
130         {
131           PspWin32ThreadCallback (Thread, TRUE);
132         }
133     }
134
135   return(STATUS_SUCCESS);
136 }
137
138
139 VOID
140 PsTerminateWin32Process (PEPROCESS Process)
141 {
142   if (Process->Win32Process == NULL)
143     return;
144
145   if (PspWin32ProcessCallback != NULL)
146     {
147       PspWin32ProcessCallback (Process, FALSE);
148     }
149
150   ExFreePool (Process->Win32Process);
151 }
152
153
154 VOID
155 PsTerminateWin32Thread (PETHREAD Thread)
156 {
157   if (Thread->Win32Thread == NULL)
158     return;
159
160   if (PspWin32ThreadCallback != NULL)
161     {
162       PspWin32ThreadCallback (Thread, FALSE);
163     }
164
165   ExFreePool (Thread->Win32Thread);
166 }
167
168 /* EOF */