ReactOS  0.4.14-dev-49-gfb4591c
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 INIT_FUNCTION
94 BOOLEAN
95 NTAPI
97  IN PLOADER_PARAMETER_BLOCK LoaderBlock
98 );
99 
100 //
101 // Utility Routines
102 //
103 PETHREAD
104 NTAPI
108 );
109 
110 PEPROCESS
111 NTAPI
113  IN PEPROCESS OldProcess OPTIONAL
114 );
115 
116 NTSTATUS
117 NTAPI
120  OUT PVOID *DllBase,
121  IN BOOLEAN UseLargePages
122 );
123 
124 INIT_FUNCTION
125 NTSTATUS
126 NTAPI
128  VOID
129 );
130 
131 NTSTATUS
132 NTAPI
134  VOID
135 );
136 
137 VOID
138 NTAPI
140  IN BOOLEAN Immediate,
141  IN ULONG PrioritySeparation
142 );
143 
144 NTSTATUS
145 NTAPI
149 );
150 
151 //
152 // Process Routines
153 //
154 NTSTATUS
155 NTAPI
160  IN HANDLE ParentProcess OPTIONAL,
161  IN ULONG Flags,
162  IN HANDLE SectionHandle OPTIONAL,
163  IN HANDLE DebugPort OPTIONAL,
164  IN HANDLE ExceptionPort OPTIONAL,
165  IN BOOLEAN InJob
166 );
167 
168 //
169 // Security Routines
170 //
172 NTAPI
178 );
179 
180 NTSTATUS
181 NTAPI
185 );
186 
187 NTSTATUS
188 NTAPI
193 );
194 
195 NTSTATUS
196 NTAPI
200 );
201 
202 VOID
203 NTAPI
206 );
207 
208 VOID
209 NTAPI
212 );
213 
214 //
215 // Reaping and Deletion
216 //
217 VOID
218 NTAPI
220  PKAPC Apc,
221  PKNORMAL_ROUTINE *NormalRoutine,
222  PVOID *NormalContext,
225 );
226 
227 VOID
228 NTAPI
231 );
232 
233 VOID
234 NTAPI
237 );
238 
239 NTSTATUS
240 NTAPI
244  IN BOOLEAN bSelf
245 );
246 
247 VOID
248 NTAPI
252 );
253 
254 NTSTATUS
255 NTAPI
259 );
260 
261 VOID
262 NTAPI
264  IN PVOID ObjectBody
265 );
266 
267 VOID
268 NTAPI
270  IN PVOID ObjectBody
271 );
272 
273 //
274 // Thread/Process Startup
275 //
276 VOID
277 NTAPI
280  PVOID StartContext
281 );
282 
283 VOID
284 NTAPI
287 );
288 
289 //
290 // Quota Support
291 //
292 VOID
293 NTAPI
296  IN PEPROCESS ParentProcess
297 );
298 
299 VOID
300 NTAPI
303 );
304 
305 NTSTATUS
306 NTAPI
309  _In_ ULONG Unused,
310  _In_ PVOID QuotaLimits,
311  _In_ ULONG QuotaLimitsLength,
313 
314 #if defined(_X86_)
315 //
316 // VDM and LDT Support
317 //
318 VOID
319 NTAPI
322 );
323 
324 VOID
325 NTAPI
328 );
329 
330 NTSTATUS
331 NTAPI
334  IN PVOID ThreadInformation,
337 );
338 #endif
339 
340 //
341 // Job Routines
342 //
343 VOID
344 NTAPI
346  IN PEJOB Job,
348 );
349 
350 VOID
351 NTAPI
354  IN PEJOB Job
355 );
356 
357 INIT_FUNCTION
358 VOID
359 NTAPI
361  VOID
362 );
363 
364 VOID
365 NTAPI
367  IN PVOID ObjectBody
368 );
369 
370 //
371 // State routines
372 //
373 NTSTATUS
374 NTAPI
377  OUT PULONG PreviousCount OPTIONAL
378 );
379 
380 NTSTATUS
381 NTAPI
384  OUT PULONG PreviousCount OPTIONAL
385 );
386 
387 VOID
388 NTAPI
390  IN PKAPC Apc,
391  IN OUT PKNORMAL_ROUTINE* NormalRoutine,
392  IN OUT PVOID* NormalContext,
395 );
396 
397 //
398 // Process Quotas
399 //
400 NTSTATUS
401 NTAPI
405 );
406 
407 NTSTATUS
408 NTAPI
412 );
413 
414 BOOLEAN
415 NTAPI
417 
418 //
419 // Apphelp functions
420 //
421 INIT_FUNCTION
422 NTSTATUS
423 NTAPI
425 
426 VOID
427 NTAPI
429 
430 //
431 // Global data inside the Process Manager
432 //
433 extern ULONG PspTraceLevel;
438 extern BOOLEAN PspReaping;
439 extern PEPROCESS PsIdleProcess;
451 extern PKWIN32_PROCESS_CALLOUT PspW32ProcessCallout;
454 extern PVOID PspSystemDllBase;
462 extern POBJECT_TYPE PsJobType;
469 
470 //
471 // Inlined Functions
472 //
473 #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:1129
#define IN
Definition: typedefs.h:38
VOID NTAPI PspInheritQuota(IN PEPROCESS Process, IN PEPROCESS ParentProcess)
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Amount
Definition: fsrtlfuncs.h:550
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
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
_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:515
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:722
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)
INIT_FUNCTION NTSTATUS NTAPI PsLocateSystemDll(VOID)
Definition: psmgr.c:279
VOID NTAPI PspExitThread(IN NTSTATUS ExitStatus)
Definition: kill.c:449
uint32_t ULONG_PTR
Definition: typedefs.h:63
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
INIT_FUNCTION NTSTATUS NTAPI ApphelpCacheInitialize(VOID)
Definition: apphelp.c:440
WORK_QUEUE_ITEM PspReaperWorkItem
Definition: kill.c:20
PEPROCESS PsIdleProcess
Definition: psmgr.c:51
VOID NTAPI PspExitProcess(IN BOOLEAN LastThread, IN PEPROCESS Process)
Definition: kill.c:1074
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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:601
_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
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#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
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
INIT_FUNCTION BOOLEAN NTAPI PsInitSystem(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: psmgr.c:624
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
BOOLEAN NTAPI PspIsProcessExiting(IN PEPROCESS Process)
Definition: kill.c:1067
* PFILE_OBJECT
Definition: iotypes.h:1955
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:414
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:117
PACCESS_TOKEN NTAPI PsReferenceEffectiveToken(IN PETHREAD Thread, OUT IN PTOKEN_TYPE TokenType, OUT PBOOLEAN EffectiveOnly, OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
Definition: security.c:713
VOID NTAPI PspDeleteProcessSecurity(IN PEPROCESS Process)
Definition: security.c:30
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:204
VOID NTAPI PspRemoveProcessFromJob(IN PEPROCESS Process, IN PEJOB Job)
Definition: job.c:138
ULONG_PTR SIZE_T
Definition: typedefs.h:78
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
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
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:39
PVOID PspSystemDllEntryPoint
Definition: psmgr.c:43
ULONG ERESOURCE
Definition: env_spec_w32.h:594
unsigned int ULONG
Definition: retypes.h:1
INIT_FUNCTION VOID NTAPI PspInitializeJobStructures(VOID)
Definition: job.c:111
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:632
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:463
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