ReactOS  0.4.15-dev-1632-g4e289ce
ps.h
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Kernel
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: ntoskrnl/include/internal/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, fmt, ...) DPRINT(fmt, ##__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 {
83 
84 //
85 // Initialization Functions
86 //
87 VOID
88 NTAPI
90  VOID
91 );
92 
93 BOOLEAN
94 NTAPI
96  IN PLOADER_PARAMETER_BLOCK LoaderBlock
97 );
98 
99 //
100 // Utility Routines
101 //
102 PETHREAD
103 NTAPI
107 );
108 
109 PEPROCESS
110 NTAPI
112  IN PEPROCESS OldProcess OPTIONAL
113 );
114 
115 NTSTATUS
116 NTAPI
119  OUT PVOID *DllBase,
120  IN BOOLEAN UseLargePages
121 );
122 
123 NTSTATUS
124 NTAPI
126  VOID
127 );
128 
129 NTSTATUS
130 NTAPI
132  VOID
133 );
134 
135 VOID
136 NTAPI
138  IN BOOLEAN Immediate,
139  IN ULONG PrioritySeparation
140 );
141 
142 NTSTATUS
143 NTAPI
147 );
148 
149 //
150 // Process Routines
151 //
152 NTSTATUS
153 NTAPI
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 //
170 NTAPI
176 );
177 
178 NTSTATUS
179 NTAPI
183 );
184 
185 NTSTATUS
186 NTAPI
191 );
192 
193 NTSTATUS
194 NTAPI
198 );
199 
200 VOID
201 NTAPI
204 );
205 
206 VOID
207 NTAPI
210 );
211 
212 //
213 // Reaping and Deletion
214 //
215 VOID
216 NTAPI
218  PKAPC Apc,
219  PKNORMAL_ROUTINE *NormalRoutine,
220  PVOID *NormalContext,
223 );
224 
225 VOID
226 NTAPI
229 );
230 
231 VOID
232 NTAPI
235 );
236 
237 NTSTATUS
238 NTAPI
242  IN BOOLEAN bSelf
243 );
244 
245 VOID
246 NTAPI
250 );
251 
252 NTSTATUS
253 NTAPI
257 );
258 
259 VOID
260 NTAPI
262  IN PVOID ObjectBody
263 );
264 
265 VOID
266 NTAPI
268  IN PVOID ObjectBody
269 );
270 
271 //
272 // Thread/Process Startup
273 //
274 VOID
275 NTAPI
278  PVOID StartContext
279 );
280 
281 VOID
282 NTAPI
285 );
286 
287 //
288 // Quota Support
289 //
290 VOID
291 NTAPI
294  IN PEPROCESS ParentProcess
295 );
296 
297 VOID
298 NTAPI
301 );
302 
303 NTSTATUS
304 NTAPI
307  _In_ ULONG Unused,
308  _In_ PVOID QuotaLimits,
309  _In_ ULONG QuotaLimitsLength,
311 
312 #if defined(_X86_)
313 //
314 // VDM and LDT Support
315 //
316 VOID
317 NTAPI
320 );
321 
322 VOID
323 NTAPI
326 );
327 
328 NTSTATUS
329 NTAPI
332  IN PVOID ThreadInformation,
335 );
336 #endif
337 
338 //
339 // Job Routines
340 //
341 VOID
342 NTAPI
344  IN PEJOB Job,
346 );
347 
348 VOID
349 NTAPI
352  IN PEJOB Job
353 );
354 
355 VOID
356 NTAPI
358  VOID
359 );
360 
361 VOID
362 NTAPI
364  IN PVOID ObjectBody
365 );
366 
367 //
368 // State routines
369 //
370 NTSTATUS
371 NTAPI
374  OUT PULONG PreviousCount OPTIONAL
375 );
376 
377 NTSTATUS
378 NTAPI
381  OUT PULONG PreviousCount OPTIONAL
382 );
383 
384 VOID
385 NTAPI
387  IN PKAPC Apc,
388  IN OUT PKNORMAL_ROUTINE* NormalRoutine,
389  IN OUT PVOID* NormalContext,
392 );
393 
394 //
395 // Process Quotas
396 //
397 NTSTATUS
398 NTAPI
402 );
403 
404 NTSTATUS
405 NTAPI
409 );
410 
411 BOOLEAN
412 NTAPI
414 
415 //
416 // Apphelp functions
417 //
418 NTSTATUS
419 NTAPI
421 
422 VOID
423 NTAPI
425 
426 //
427 // Global data inside the Process Manager
428 //
429 extern ULONG PspTraceLevel;
434 extern BOOLEAN PspReaping;
435 extern PEPROCESS PsIdleProcess;
447 extern PKWIN32_PROCESS_CALLOUT PspW32ProcessCallout;
450 extern PVOID PspSystemDllBase;
458 extern POBJECT_TYPE PsJobType;
465 
466 //
467 // Inlined Functions
468 //
469 #include "ps_x.h"
VOID NTAPI PspSystemThreadStartup(PKSTART_ROUTINE StartRoutine, PVOID StartContext)
enum _SECURITY_IMPERSONATION_LEVEL * PSECURITY_IMPERSONATION_LEVEL
VOID NTAPI PspShutdownProcessManager(VOID)
Definition: kill.c:138
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define PSP_MAX_CREATE_PROCESS_NOTIFY
Definition: ps.h:66
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
_Must_inspect_result_ typedef _In_ PVOID Unused
Definition: iotypes.h:1166
#define IN
Definition: typedefs.h:39
VOID NTAPI PspInheritQuota(IN PEPROCESS Process, IN PEPROCESS ParentProcess)
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Amount
Definition: fsrtlfuncs.h:550
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
VOID NTAPI PspDeleteVdmObjects(PEPROCESS Process)
Definition: psldt.c:27
POBJECT_TYPE PsJobType
Definition: job.c:20
ULONG PspTraceLevel
Definition: query.c:18
PLEGO_NOTIFY_ROUTINE PspLegoNotifyRoutine
Definition: psnotify.c:24
VOID NTAPI PspDeleteThread(IN PVOID ObjectBody)
Definition: kill.c:390
_In_ ULONG _In_opt_ POBJECT_ATTRIBUTES _In_opt_ HANDLE _Out_opt_ PCLIENT_ID _In_ PKSTART_ROUTINE StartRoutine
Definition: psfuncs.h:87
BOOLEAN NTAPI PsInitSystem(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: psmgr.c:624
VOID NTAPI PsIdleThreadMain(IN PVOID Context)
enum _TOKEN_TYPE * PTOKEN_TYPE
NTSTATUS NTAPI PsOpenTokenOfProcess(IN HANDLE ProcessHandle, OUT PACCESS_TOKEN *Token)
Definition: security.c:471
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI PspInitializeJobStructures(VOID)
Definition: job.c:111
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE Token
VOID NTAPI PspReapRoutine(IN PVOID Context)
Definition: kill.c:170
ULONG PsRawPrioritySeparation
Definition: process.c:27
NTSTATUS NTAPI PsReturnProcessPageFileQuota(IN PEPROCESS Process, IN SIZE_T Amount)
Definition: quota.c:281
PKWIN32_PROCESS_CALLOUT PspW32ProcessCallout
Definition: win32.c:18
UNICODE_STRING PsNtDllPathName
Definition: psmgr.c:45
NTSTATUS(NTAPI * PKWIN32_THREAD_CALLOUT)(_In_ struct _ETHREAD *Thread, _In_ PSW32THREADCALLOUTTYPE Type)
Definition: pstypes.h:523
VOID NTAPI PspDeleteJob(IN PVOID ObjectBody)
DWORD LCID
Definition: nls.h:13
PHANDLE_TABLE PspCidTable
Definition: psmgr.c:48
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:728
PTOKEN PspBootAccessToken
Definition: security.c:17
LIST_ENTRY PsActiveProcessHead
Definition: process.c:22
NTSTATUS NTAPI PspMapSystemDll(IN PEPROCESS Process, OUT PVOID *DllBase, IN BOOLEAN UseLargePages)
VOID NTAPI PspExitThread(IN NTSTATUS ExitStatus)
Definition: kill.c:449
uint32_t ULONG_PTR
Definition: typedefs.h:65
NTSTATUS NTAPI PspQueryDescriptorThread(IN PETHREAD Thread, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: psldt.c:43
ERESOURCE PsLoadedModuleResource
Definition: sysldr.c:37
NTSTATUS NTAPI PspSetQuotaLimits(_In_ PEPROCESS Process, _In_ ULONG Unused, _In_ PVOID QuotaLimits, _In_ ULONG QuotaLimitsLength, _In_ KPROCESSOR_MODE PreviousMode)
Definition: quota.c:293
WORK_QUEUE_ITEM PspReaperWorkItem
Definition: kill.c:20
PEPROCESS PsIdleProcess
Definition: psmgr.c:51
NTSTATUS NTAPI ApphelpCacheInitialize(VOID)
Definition: apphelp.c:440
VOID NTAPI PspExitProcess(IN BOOLEAN LastThread, IN PEPROCESS Process)
Definition: kill.c:1074
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
KSPIN_LOCK PsLoadedModuleSpinLock
Definition: sysldr.c:36
KSTART_ROUTINE * PKSTART_ROUTINE
Definition: ketypes.h:487
NTSTATUS NTAPI PspCreateProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN HANDLE ParentProcess OPTIONAL, IN ULONG Flags, IN HANDLE SectionHandle OPTIONAL, IN HANDLE DebugPort OPTIONAL, IN HANDLE ExceptionPort OPTIONAL, IN BOOLEAN InJob)
Definition: process.c:347
PKWIN32_THREAD_CALLOUT PspW32ThreadCallout
Definition: win32.c:19
EPROCESS_QUOTA_BLOCK PspDefaultQuotaBlock
Definition: quota.c:17
ULONG_PTR PsNtosImageBase
Definition: sysldr.c:38
#define PSP_JOB_SCHEDULING_CLASSES
Definition: ps.h:71
EX_CALLBACK PspProcessNotifyRoutine[PSP_MAX_CREATE_PROCESS_NOTIFY]
Definition: psnotify.c:22
VOID NTAPI PspExitProcessFromJob(IN PEJOB Job, IN PEPROCESS Process)
Definition: job.c:146
CHAR PspJobSchedulingClasses[PSP_JOB_SCHEDULING_CLASSES]
Definition: job.c:27
NTSTATUS NTAPI PspSetPrimaryToken(IN PEPROCESS Process, IN HANDLE TokenHandle OPTIONAL, IN PACCESS_TOKEN Token OPTIONAL)
Definition: security.c:215
unsigned char BOOLEAN
VOID(NTAPI * PLEGO_NOTIFY_ROUTINE)(_In_ PKTHREAD Thread)
Definition: pstypes.h:609
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
Definition: psfuncs.h:715
VOID NTAPI PsChangeQuantumTable(IN BOOLEAN Immediate, IN ULONG PrioritySeparation)
Definition: process.c:235
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
#define PSP_MAX_CREATE_THREAD_NOTIFY
Definition: ps.h:64
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define PSP_MAX_LOAD_IMAGE_NOTIFY
Definition: ps.h:65
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSTATUS NTAPI PsSuspendThread(IN PETHREAD Thread, OUT PULONG PreviousCount OPTIONAL)
Definition: state.c:48
BOOLEAN PsImageNotifyEnabled
Definition: psnotify.c:18
ULONG PspProcessNotifyRoutineCount
Definition: psnotify.c:19
GENERIC_MAPPING PspJobMapping
Definition: job.c:41
NTSTATUS NTAPI PsTerminateProcess(IN PEPROCESS Process, IN NTSTATUS ExitStatus)
Definition: kill.c:129
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:34
KPROCESSOR_MODE Mode
Definition: ps.h:80
_Out_ PBOOLEAN _Out_ PBOOLEAN _Out_ PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: psfuncs.h:154
LCID PsDefaultSystemLocaleId
Definition: locale.c:20
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
PVOID PspSystemDllBase
Definition: psmgr.c:41
POBJECT_TYPE _PsProcessType
struct _GET_SET_CTX_CONTEXT * PGET_SET_CTX_CONTEXT
VOID NTAPI PspDeleteLdt(PEPROCESS Process)
Definition: psldt.c:19
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
BOOLEAN NTAPI PspIsProcessExiting(IN PEPROCESS Process)
Definition: kill.c:1067
* PFILE_OBJECT
Definition: iotypes.h:1995
EX_CALLBACK PspThreadNotifyRoutine[PSP_MAX_CREATE_THREAD_NOTIFY]
Definition: psnotify.c:21
PETHREAD NTAPI PsGetNextProcessThread(IN PEPROCESS Process, IN PETHREAD Thread OPTIONAL)
Definition: process.c:75
VOID NTAPI PspDeleteProcess(IN PVOID ObjectBody)
Definition: kill.c:256
char * PBOOLEAN
Definition: retypes.h:11
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
NTSTATUS NTAPI PsChargeProcessPageFileQuota(IN PEPROCESS Process, IN SIZE_T Amount)
Definition: quota.c:161
Definition: ketypes.h:535
PEPROCESS NTAPI PsGetNextProcess(IN PEPROCESS OldProcess OPTIONAL)
Definition: process.c:128
Definition: typedefs.h:119
PACCESS_TOKEN NTAPI PsReferenceEffectiveToken(IN PETHREAD Thread, OUT IN PTOKEN_TYPE TokenType, OUT PBOOLEAN EffectiveOnly, OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
Definition: security.c:739
VOID NTAPI PspDeleteProcessSecurity(IN PEPROCESS Process)
Definition: security.c:30
NTSTATUS NTAPI PsLocateSystemDll(VOID)
Definition: psmgr.c:279
PETHREAD LastThread
Definition: pinsup.c:109
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
VOID NTAPI PspDeleteThreadSecurity(IN PETHREAD Thread)
Definition: security.c:46
#define _In_
Definition: no_sal2.h:158
VOID NTAPI PspRemoveProcessFromJob(IN PEPROCESS Process, IN PEJOB Job)
Definition: job.c:138
ULONG_PTR SIZE_T
Definition: typedefs.h:80
VOID NTAPI PspDestroyQuotaBlock(IN PEPROCESS Process)
_In_ THREADINFOCLASS _In_ ULONG ThreadInformationLength
Definition: psfuncs.h:835
KEVENT Event
Definition: ps.h:79
ULONG PspThreadNotifyRoutineCount
Definition: psnotify.c:19
BOOLEAN PspUseJobSchedulingClasses
Definition: job.c:25
KGUARDED_MUTEX PspActiveProcessMutex
Definition: process.c:23
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:859
ULONG PsPrioritySeparation
Definition: process.c:28
unsigned int * PULONG
Definition: retypes.h:1
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
NTSTATUS NTAPI PsResumeThread(IN PETHREAD Thread, OUT PULONG PreviousCount OPTIONAL)
Definition: state.c:32
#define OUT
Definition: typedefs.h:40
PVOID PspSystemDllEntryPoint
Definition: psmgr.c:43
ULONG ERESOURCE
Definition: env_spec_w32.h:594
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI PspInitializeProcessSecurity(IN PEPROCESS Process, IN PEPROCESS Parent OPTIONAL)
Definition: security.c:71
LIST_ENTRY PspReaperListHead
Definition: kill.c:19
struct _GET_SET_CTX_CONTEXT GET_SET_CTX_CONTEXT
NTSTATUS NTAPI PspTerminateThreadByPointer(IN PETHREAD Thread, IN NTSTATUS ExitStatus, IN BOOLEAN bSelf)
Definition: kill.c:987
VOID(NTAPI * PKNORMAL_ROUTINE)(IN PVOID NormalContext OPTIONAL, IN PVOID SystemArgument1 OPTIONAL, IN PVOID SystemArgument2 OPTIONAL)
Definition: ketypes.h:674
VOID NTAPI PsExitSpecialApc(PKAPC Apc, PKNORMAL_ROUTINE *NormalRoutine, PVOID *NormalContext, PVOID *SystemArgument1, PVOID *SystemArgument2)
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ BOOLEAN EffectiveOnly
Definition: sefuncs.h:417
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
CONTEXT Context
Definition: ps.h:81
NTSTATUS NTAPI PspGetSystemDllEntryPoints(VOID)
ULONG ACCESS_MASK
Definition: nt_native.h:40
LARGE_INTEGER ShortPsLockDelay
Definition: ps.h:459
VOID NTAPI ApphelpCacheShutdown(VOID)
Definition: apphelp.c:466
POBJECT_TYPE _PsThreadType
NTSTATUS NTAPI PsReferenceProcessFilePointer(IN PEPROCESS Process, OUT PFILE_OBJECT *FileObject)
Definition: query.c:24
EX_CALLBACK PspLoadImageNotifyRoutine[PSP_MAX_LOAD_IMAGE_NOTIFY]
Definition: psnotify.c:23
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ BOOLEAN _In_ TOKEN_TYPE TokenType
Definition: sefuncs.h:417
LCID PsDefaultThreadLocaleId
Definition: locale.c:25
VOID NTAPI PspGetOrSetContextKernelRoutine(IN PKAPC Apc, IN OUT PKNORMAL_ROUTINE *NormalRoutine, IN OUT PVOID *NormalContext, IN OUT PVOID *SystemArgument1, IN OUT PVOID *SystemArgument2)
Definition: psctx.c:45
BOOLEAN PspReaping
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68