xref: /reactos/ntoskrnl/include/internal/ps.h (revision 29fa274d)
1 /*
2  * PROJECT:         ReactOS Kernel
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            ntoskrnl/include/ps.h
5  * PURPOSE:         Internal header for the Process Manager
6  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
7  */
8 
9 //
10 // Define this if you want debugging support
11 //
12 #define _PS_DEBUG_                                      0x00
13 
14 //
15 // These define the Debug Masks Supported
16 //
17 #define PS_THREAD_DEBUG                                 0x01
18 #define PS_PROCESS_DEBUG                                0x02
19 #define PS_SECURITY_DEBUG                               0x04
20 #define PS_JOB_DEBUG                                    0x08
21 #define PS_NOTIFICATIONS_DEBUG                          0x10
22 #define PS_WIN32K_DEBUG                                 0x20
23 #define PS_STATE_DEBUG                                  0x40
24 #define PS_QUOTA_DEBUG                                  0x80
25 #define PS_KILL_DEBUG                                   0x100
26 #define PS_REF_DEBUG                                    0x200
27 
28 //
29 // Debug/Tracing support
30 //
31 #if _PS_DEBUG_
32 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented
33 #define PSTRACE(x, ...)                                     \
34     {                                                       \
35         DbgPrintEx("%s [%.16s] - ",                         \
36                    __FUNCTION__,                            \
37                    PsGetCurrentProcess()->ImageFileName);   \
38         DbgPrintEx(__VA_ARGS__);                            \
39     }
40 #else
41 #define PSTRACE(x, ...)                                     \
42     if (x & PspTraceLevel)                                  \
43     {                                                       \
44         DbgPrint("%s [%.16s] - ",                           \
45                  __FUNCTION__,                              \
46                  PsGetCurrentProcess()->ImageFileName);     \
47         DbgPrint(__VA_ARGS__);                              \
48     }
49 #endif
50 #define PSREFTRACE(x)                                       \
51     PSTRACE(PS_REF_DEBUG,                                   \
52             "Pointer Count [%p] @%d: %lx\n",                \
53             x,                                              \
54             __LINE__,                                       \
55             OBJECT_TO_OBJECT_HEADER(x)->PointerCount)
56 #else
57 #define PSTRACE(x, ...) DPRINT(__VA_ARGS__)
58 #define PSREFTRACE(x)
59 #endif
60 
61 //
62 // Maximum Count of Notification Routines
63 //
64 #define PSP_MAX_CREATE_THREAD_NOTIFY            8
65 #define PSP_MAX_LOAD_IMAGE_NOTIFY               8
66 #define PSP_MAX_CREATE_PROCESS_NOTIFY           8
67 
68 //
69 // Maximum Job Scheduling Classes
70 //
71 #define PSP_JOB_SCHEDULING_CLASSES              10
72 
73 //
74 // Thread "Set/Get Context" Context Structure
75 //
76 typedef struct _GET_SET_CTX_CONTEXT
77 {
78     KAPC Apc;
79     KEVENT Event;
80     KPROCESSOR_MODE Mode;
81     CONTEXT Context;
82 } GET_SET_CTX_CONTEXT, *PGET_SET_CTX_CONTEXT;
83 
84 //
85 // Initialization Functions
86 //
87 VOID
88 NTAPI
89 PspShutdownProcessManager(
90     VOID
91 );
92 
93 BOOLEAN
94 NTAPI
95 PsInitSystem(
96     IN PLOADER_PARAMETER_BLOCK LoaderBlock
97 );
98 
99 //
100 // Utility Routines
101 //
102 PETHREAD
103 NTAPI
104 PsGetNextProcessThread(
105     IN PEPROCESS Process,
106     IN PETHREAD Thread OPTIONAL
107 );
108 
109 PEPROCESS
110 NTAPI
111 PsGetNextProcess(
112     IN PEPROCESS OldProcess OPTIONAL
113 );
114 
115 NTSTATUS
116 NTAPI
117 PspMapSystemDll(
118     IN PEPROCESS Process,
119     OUT PVOID *DllBase,
120     IN BOOLEAN UseLargePages
121 );
122 
123 NTSTATUS
124 NTAPI
125 PsLocateSystemDll(
126     VOID
127 );
128 
129 NTSTATUS
130 NTAPI
131 PspGetSystemDllEntryPoints(
132     VOID
133 );
134 
135 VOID
136 NTAPI
137 PsChangeQuantumTable(
138     IN BOOLEAN Immediate,
139     IN ULONG PrioritySeparation
140 );
141 
142 NTSTATUS
143 NTAPI
144 PsReferenceProcessFilePointer(
145     IN PEPROCESS Process,
146     OUT PFILE_OBJECT *FileObject
147 );
148 
149 //
150 // Process Routines
151 //
152 NTSTATUS
153 NTAPI
154 PspCreateProcess(
155     OUT PHANDLE ProcessHandle,
156     IN ACCESS_MASK DesiredAccess,
157     IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
158     IN HANDLE ParentProcess OPTIONAL,
159     IN ULONG Flags,
160     IN HANDLE SectionHandle OPTIONAL,
161     IN HANDLE DebugPort OPTIONAL,
162     IN HANDLE ExceptionPort OPTIONAL,
163     IN BOOLEAN InJob
164 );
165 
166 //
167 // Security Routines
168 //
169 PACCESS_TOKEN
170 NTAPI
171 PsReferenceEffectiveToken(
172     IN PETHREAD Thread,
173     OUT PTOKEN_TYPE TokenType,
174     OUT PUCHAR b,
175     OUT PSECURITY_IMPERSONATION_LEVEL Level
176 );
177 
178 NTSTATUS
179 NTAPI
180 PsOpenTokenOfProcess(
181     IN HANDLE ProcessHandle,
182     OUT PACCESS_TOKEN* Token
183 );
184 
185 NTSTATUS
186 NTAPI
187 PspSetPrimaryToken(
188     IN PEPROCESS Process,
189     IN HANDLE TokenHandle OPTIONAL,
190     IN PACCESS_TOKEN Token OPTIONAL
191 );
192 
193 NTSTATUS
194 NTAPI
195 PspInitializeProcessSecurity(
196     IN PEPROCESS Process,
197     IN PEPROCESS Parent OPTIONAL
198 );
199 
200 VOID
201 NTAPI
202 PspDeleteProcessSecurity(
203     IN PEPROCESS Process
204 );
205 
206 VOID
207 NTAPI
208 PspDeleteThreadSecurity(
209     IN PETHREAD Thread
210 );
211 
212 //
213 // Reaping and Deletion
214 //
215 VOID
216 NTAPI
217 PsExitSpecialApc(
218     PKAPC Apc,
219     PKNORMAL_ROUTINE *NormalRoutine,
220     PVOID *NormalContext,
221     PVOID *SystemArgument1,
222     PVOID *SystemArgument2
223 );
224 
225 VOID
226 NTAPI
227 PspReapRoutine(
228     IN PVOID Context
229 );
230 
231 VOID
232 NTAPI
233 PspExitThread(
234     IN NTSTATUS ExitStatus
235 );
236 
237 NTSTATUS
238 NTAPI
239 PspTerminateThreadByPointer(
240     IN PETHREAD Thread,
241     IN NTSTATUS ExitStatus,
242     IN BOOLEAN bSelf
243 );
244 
245 VOID
246 NTAPI
247 PspExitProcess(
248     IN BOOLEAN LastThread,
249     IN PEPROCESS Process
250 );
251 
252 NTSTATUS
253 NTAPI
254 PsTerminateProcess(
255     IN PEPROCESS Process,
256     IN NTSTATUS ExitStatus
257 );
258 
259 VOID
260 NTAPI
261 PspDeleteProcess(
262     IN PVOID ObjectBody
263 );
264 
265 VOID
266 NTAPI
267 PspDeleteThread(
268     IN PVOID ObjectBody
269 );
270 
271 //
272 // Thread/Process Startup
273 //
274 VOID
275 NTAPI
276 PspSystemThreadStartup(
277     PKSTART_ROUTINE StartRoutine,
278     PVOID StartContext
279 );
280 
281 VOID
282 NTAPI
283 PsIdleThreadMain(
284     IN PVOID Context
285 );
286 
287 //
288 // Quota Support
289 //
290 VOID
291 NTAPI
292 PspInheritQuota(
293     IN PEPROCESS Process,
294     IN PEPROCESS ParentProcess
295 );
296 
297 VOID
298 NTAPI
299 PspDestroyQuotaBlock(
300     IN PEPROCESS Process
301 );
302 
303 #if defined(_X86_)
304 //
305 // VDM and LDT Support
306 //
307 NTSTATUS
308 NTAPI
309 PspDeleteLdt(
310     IN PEPROCESS Process
311 );
312 
313 NTSTATUS
314 NTAPI
315 PspDeleteVdmObjects(
316     IN PEPROCESS Process
317 );
318 
319 NTSTATUS
320 NTAPI
321 PspQueryDescriptorThread(
322     IN PETHREAD Thread,
323     IN PVOID ThreadInformation,
324     IN ULONG ThreadInformationLength,
325     OUT PULONG ReturnLength OPTIONAL
326 );
327 #endif
328 
329 //
330 // Job Routines
331 //
332 VOID
333 NTAPI
334 PspExitProcessFromJob(
335     IN PEJOB Job,
336     IN PEPROCESS Process
337 );
338 
339 VOID
340 NTAPI
341 PspRemoveProcessFromJob(
342     IN PEPROCESS Process,
343     IN PEJOB Job
344 );
345 
346 VOID
347 NTAPI
348 PspInitializeJobStructures(
349     VOID
350 );
351 
352 VOID
353 NTAPI
354 PspDeleteJob(
355     IN PVOID ObjectBody
356 );
357 
358 //
359 // State routines
360 //
361 NTSTATUS
362 NTAPI
363 PsResumeThread(
364     IN PETHREAD Thread,
365     OUT PULONG PreviousCount OPTIONAL
366 );
367 
368 NTSTATUS
369 NTAPI
370 PsSuspendThread(
371     IN PETHREAD Thread,
372     OUT PULONG PreviousCount OPTIONAL
373 );
374 
375 VOID
376 NTAPI
377 PspGetOrSetContextKernelRoutine(
378     IN PKAPC Apc,
379     IN OUT PKNORMAL_ROUTINE* NormalRoutine,
380     IN OUT PVOID* NormalContext,
381     IN OUT PVOID* SystemArgument1,
382     IN OUT PVOID* SystemArgument2
383 );
384 
385 //
386 // Process Quotas
387 //
388 NTSTATUS
389 NTAPI
390 PsReturnProcessPageFileQuota(
391     IN PEPROCESS Process,
392     IN SIZE_T Amount
393 );
394 
395 NTSTATUS
396 NTAPI
397 PsChargeProcessPageFileQuota(
398     IN PEPROCESS Process,
399     IN SIZE_T Amount
400 );
401 
402 //
403 // Global data inside the Process Manager
404 //
405 extern ULONG PspTraceLevel;
406 extern LCID PsDefaultThreadLocaleId;
407 extern LCID PsDefaultSystemLocaleId;
408 extern LIST_ENTRY PspReaperListHead;
409 extern WORK_QUEUE_ITEM PspReaperWorkItem;
410 extern BOOLEAN PspReaping;
411 extern PEPROCESS PsIdleProcess;
412 extern LIST_ENTRY PsActiveProcessHead;
413 extern KGUARDED_MUTEX PspActiveProcessMutex;
414 extern LARGE_INTEGER ShortPsLockDelay;
415 extern EPROCESS_QUOTA_BLOCK PspDefaultQuotaBlock;
416 extern PHANDLE_TABLE PspCidTable;
417 extern EX_CALLBACK PspThreadNotifyRoutine[PSP_MAX_CREATE_THREAD_NOTIFY];
418 extern EX_CALLBACK PspProcessNotifyRoutine[PSP_MAX_CREATE_PROCESS_NOTIFY];
419 extern EX_CALLBACK PspLoadImageNotifyRoutine[PSP_MAX_LOAD_IMAGE_NOTIFY];
420 extern PLEGO_NOTIFY_ROUTINE PspLegoNotifyRoutine;
421 extern ULONG PspThreadNotifyRoutineCount, PspProcessNotifyRoutineCount;
422 extern BOOLEAN PsImageNotifyEnabled;
423 extern PKWIN32_PROCESS_CALLOUT PspW32ProcessCallout;
424 extern PKWIN32_THREAD_CALLOUT PspW32ThreadCallout;
425 extern PVOID PspSystemDllEntryPoint;
426 extern PVOID PspSystemDllBase;
427 extern BOOLEAN PspUseJobSchedulingClasses;
428 extern CHAR PspJobSchedulingClasses[PSP_JOB_SCHEDULING_CLASSES];
429 extern ULONG PsRawPrioritySeparation;
430 extern POBJECT_TYPE _PsThreadType, _PsProcessType;
431 extern PTOKEN PspBootAccessToken;
432 extern GENERIC_MAPPING PspJobMapping;
433 extern POBJECT_TYPE PsJobType;
434 extern LARGE_INTEGER ShortPsLockDelay;
435 extern UNICODE_STRING PsNtDllPathName;
436 extern LIST_ENTRY PsLoadedModuleList;
437 extern KSPIN_LOCK PsLoadedModuleSpinLock;
438 extern ERESOURCE PsLoadedModuleResource;
439 extern ULONG_PTR PsNtosImageBase;
440 
441 //
442 // Inlined Functions
443 //
444 #include "ps_x.h"
445