[NDK][NTOS] Add global definition of INIT_FUNCTION/INIT_SECTION (#779)
[reactos.git] / ntoskrnl / include / internal / ps.h
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 {
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 INIT_FUNCTION
94 BOOLEAN
95 NTAPI
96 PsInitSystem(
97 IN PLOADER_PARAMETER_BLOCK LoaderBlock
98 );
99
100 //
101 // Utility Routines
102 //
103 PETHREAD
104 NTAPI
105 PsGetNextProcessThread(
106 IN PEPROCESS Process,
107 IN PETHREAD Thread OPTIONAL
108 );
109
110 PEPROCESS
111 NTAPI
112 PsGetNextProcess(
113 IN PEPROCESS OldProcess OPTIONAL
114 );
115
116 NTSTATUS
117 NTAPI
118 PspMapSystemDll(
119 IN PEPROCESS Process,
120 OUT PVOID *DllBase,
121 IN BOOLEAN UseLargePages
122 );
123
124 INIT_FUNCTION
125 NTSTATUS
126 NTAPI
127 PsLocateSystemDll(
128 VOID
129 );
130
131 NTSTATUS
132 NTAPI
133 PspGetSystemDllEntryPoints(
134 VOID
135 );
136
137 VOID
138 NTAPI
139 PsChangeQuantumTable(
140 IN BOOLEAN Immediate,
141 IN ULONG PrioritySeparation
142 );
143
144 NTSTATUS
145 NTAPI
146 PsReferenceProcessFilePointer(
147 IN PEPROCESS Process,
148 OUT PFILE_OBJECT *FileObject
149 );
150
151 //
152 // Process Routines
153 //
154 NTSTATUS
155 NTAPI
156 PspCreateProcess(
157 OUT PHANDLE ProcessHandle,
158 IN ACCESS_MASK DesiredAccess,
159 IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
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 //
171 PACCESS_TOKEN
172 NTAPI
173 PsReferenceEffectiveToken(
174 IN PETHREAD Thread,
175 OUT IN PTOKEN_TYPE TokenType,
176 OUT PBOOLEAN EffectiveOnly,
177 OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
178 );
179
180 NTSTATUS
181 NTAPI
182 PsOpenTokenOfProcess(
183 IN HANDLE ProcessHandle,
184 OUT PACCESS_TOKEN* Token
185 );
186
187 NTSTATUS
188 NTAPI
189 PspSetPrimaryToken(
190 IN PEPROCESS Process,
191 IN HANDLE TokenHandle OPTIONAL,
192 IN PACCESS_TOKEN Token OPTIONAL
193 );
194
195 NTSTATUS
196 NTAPI
197 PspInitializeProcessSecurity(
198 IN PEPROCESS Process,
199 IN PEPROCESS Parent OPTIONAL
200 );
201
202 VOID
203 NTAPI
204 PspDeleteProcessSecurity(
205 IN PEPROCESS Process
206 );
207
208 VOID
209 NTAPI
210 PspDeleteThreadSecurity(
211 IN PETHREAD Thread
212 );
213
214 //
215 // Reaping and Deletion
216 //
217 VOID
218 NTAPI
219 PsExitSpecialApc(
220 PKAPC Apc,
221 PKNORMAL_ROUTINE *NormalRoutine,
222 PVOID *NormalContext,
223 PVOID *SystemArgument1,
224 PVOID *SystemArgument2
225 );
226
227 VOID
228 NTAPI
229 PspReapRoutine(
230 IN PVOID Context
231 );
232
233 VOID
234 NTAPI
235 PspExitThread(
236 IN NTSTATUS ExitStatus
237 );
238
239 NTSTATUS
240 NTAPI
241 PspTerminateThreadByPointer(
242 IN PETHREAD Thread,
243 IN NTSTATUS ExitStatus,
244 IN BOOLEAN bSelf
245 );
246
247 VOID
248 NTAPI
249 PspExitProcess(
250 IN BOOLEAN LastThread,
251 IN PEPROCESS Process
252 );
253
254 NTSTATUS
255 NTAPI
256 PsTerminateProcess(
257 IN PEPROCESS Process,
258 IN NTSTATUS ExitStatus
259 );
260
261 VOID
262 NTAPI
263 PspDeleteProcess(
264 IN PVOID ObjectBody
265 );
266
267 VOID
268 NTAPI
269 PspDeleteThread(
270 IN PVOID ObjectBody
271 );
272
273 //
274 // Thread/Process Startup
275 //
276 VOID
277 NTAPI
278 PspSystemThreadStartup(
279 PKSTART_ROUTINE StartRoutine,
280 PVOID StartContext
281 );
282
283 VOID
284 NTAPI
285 PsIdleThreadMain(
286 IN PVOID Context
287 );
288
289 //
290 // Quota Support
291 //
292 VOID
293 NTAPI
294 PspInheritQuota(
295 IN PEPROCESS Process,
296 IN PEPROCESS ParentProcess
297 );
298
299 VOID
300 NTAPI
301 PspDestroyQuotaBlock(
302 IN PEPROCESS Process
303 );
304
305 NTSTATUS
306 NTAPI
307 PspSetQuotaLimits(
308 _In_ PEPROCESS Process,
309 _In_ ULONG Unused,
310 _In_ PVOID QuotaLimits,
311 _In_ ULONG QuotaLimitsLength,
312 _In_ KPROCESSOR_MODE PreviousMode);
313
314 #if defined(_X86_)
315 //
316 // VDM and LDT Support
317 //
318 VOID
319 NTAPI
320 PspDeleteLdt(
321 IN PEPROCESS Process
322 );
323
324 VOID
325 NTAPI
326 PspDeleteVdmObjects(
327 IN PEPROCESS Process
328 );
329
330 NTSTATUS
331 NTAPI
332 PspQueryDescriptorThread(
333 IN PETHREAD Thread,
334 IN PVOID ThreadInformation,
335 IN ULONG ThreadInformationLength,
336 OUT PULONG ReturnLength OPTIONAL
337 );
338 #endif
339
340 //
341 // Job Routines
342 //
343 VOID
344 NTAPI
345 PspExitProcessFromJob(
346 IN PEJOB Job,
347 IN PEPROCESS Process
348 );
349
350 VOID
351 NTAPI
352 PspRemoveProcessFromJob(
353 IN PEPROCESS Process,
354 IN PEJOB Job
355 );
356
357 INIT_FUNCTION
358 VOID
359 NTAPI
360 PspInitializeJobStructures(
361 VOID
362 );
363
364 VOID
365 NTAPI
366 PspDeleteJob(
367 IN PVOID ObjectBody
368 );
369
370 //
371 // State routines
372 //
373 NTSTATUS
374 NTAPI
375 PsResumeThread(
376 IN PETHREAD Thread,
377 OUT PULONG PreviousCount OPTIONAL
378 );
379
380 NTSTATUS
381 NTAPI
382 PsSuspendThread(
383 IN PETHREAD Thread,
384 OUT PULONG PreviousCount OPTIONAL
385 );
386
387 VOID
388 NTAPI
389 PspGetOrSetContextKernelRoutine(
390 IN PKAPC Apc,
391 IN OUT PKNORMAL_ROUTINE* NormalRoutine,
392 IN OUT PVOID* NormalContext,
393 IN OUT PVOID* SystemArgument1,
394 IN OUT PVOID* SystemArgument2
395 );
396
397 //
398 // Process Quotas
399 //
400 NTSTATUS
401 NTAPI
402 PsReturnProcessPageFileQuota(
403 IN PEPROCESS Process,
404 IN SIZE_T Amount
405 );
406
407 NTSTATUS
408 NTAPI
409 PsChargeProcessPageFileQuota(
410 IN PEPROCESS Process,
411 IN SIZE_T Amount
412 );
413
414 BOOLEAN
415 NTAPI
416 PspIsProcessExiting(IN PEPROCESS Process);
417
418 //
419 // Apphelp functions
420 //
421 INIT_FUNCTION
422 NTSTATUS
423 NTAPI
424 ApphelpCacheInitialize(VOID);
425
426 VOID
427 NTAPI
428 ApphelpCacheShutdown(VOID);
429
430 //
431 // Global data inside the Process Manager
432 //
433 extern ULONG PspTraceLevel;
434 extern LCID PsDefaultThreadLocaleId;
435 extern LCID PsDefaultSystemLocaleId;
436 extern LIST_ENTRY PspReaperListHead;
437 extern WORK_QUEUE_ITEM PspReaperWorkItem;
438 extern BOOLEAN PspReaping;
439 extern PEPROCESS PsIdleProcess;
440 extern LIST_ENTRY PsActiveProcessHead;
441 extern KGUARDED_MUTEX PspActiveProcessMutex;
442 extern LARGE_INTEGER ShortPsLockDelay;
443 extern EPROCESS_QUOTA_BLOCK PspDefaultQuotaBlock;
444 extern PHANDLE_TABLE PspCidTable;
445 extern EX_CALLBACK PspThreadNotifyRoutine[PSP_MAX_CREATE_THREAD_NOTIFY];
446 extern EX_CALLBACK PspProcessNotifyRoutine[PSP_MAX_CREATE_PROCESS_NOTIFY];
447 extern EX_CALLBACK PspLoadImageNotifyRoutine[PSP_MAX_LOAD_IMAGE_NOTIFY];
448 extern PLEGO_NOTIFY_ROUTINE PspLegoNotifyRoutine;
449 extern ULONG PspThreadNotifyRoutineCount, PspProcessNotifyRoutineCount;
450 extern BOOLEAN PsImageNotifyEnabled;
451 extern PKWIN32_PROCESS_CALLOUT PspW32ProcessCallout;
452 extern PKWIN32_THREAD_CALLOUT PspW32ThreadCallout;
453 extern PVOID PspSystemDllEntryPoint;
454 extern PVOID PspSystemDllBase;
455 extern BOOLEAN PspUseJobSchedulingClasses;
456 extern CHAR PspJobSchedulingClasses[PSP_JOB_SCHEDULING_CLASSES];
457 extern ULONG PsRawPrioritySeparation;
458 extern ULONG PsPrioritySeparation;
459 extern POBJECT_TYPE _PsThreadType, _PsProcessType;
460 extern PTOKEN PspBootAccessToken;
461 extern GENERIC_MAPPING PspJobMapping;
462 extern POBJECT_TYPE PsJobType;
463 extern LARGE_INTEGER ShortPsLockDelay;
464 extern UNICODE_STRING PsNtDllPathName;
465 extern LIST_ENTRY PsLoadedModuleList;
466 extern KSPIN_LOCK PsLoadedModuleSpinLock;
467 extern ERESOURCE PsLoadedModuleResource;
468 extern ULONG_PTR PsNtosImageBase;
469
470 //
471 // Inlined Functions
472 //
473 #include "ps_x.h"