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 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 IN PTOKEN_TYPE TokenType, 174 OUT PBOOLEAN EffectiveOnly, 175 OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel 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 NTSTATUS 304 NTAPI 305 PspSetQuotaLimits( 306 _In_ PEPROCESS Process, 307 _In_ ULONG Unused, 308 _In_ PVOID QuotaLimits, 309 _In_ ULONG QuotaLimitsLength, 310 _In_ KPROCESSOR_MODE PreviousMode); 311 312 #if defined(_X86_) 313 // 314 // VDM and LDT Support 315 // 316 VOID 317 NTAPI 318 PspDeleteLdt( 319 IN PEPROCESS Process 320 ); 321 322 VOID 323 NTAPI 324 PspDeleteVdmObjects( 325 IN PEPROCESS Process 326 ); 327 328 NTSTATUS 329 NTAPI 330 PspQueryDescriptorThread( 331 IN PETHREAD Thread, 332 IN PVOID ThreadInformation, 333 IN ULONG ThreadInformationLength, 334 OUT PULONG ReturnLength OPTIONAL 335 ); 336 #endif 337 338 // 339 // Job Routines 340 // 341 VOID 342 NTAPI 343 PspExitProcessFromJob( 344 IN PEJOB Job, 345 IN PEPROCESS Process 346 ); 347 348 VOID 349 NTAPI 350 PspRemoveProcessFromJob( 351 IN PEPROCESS Process, 352 IN PEJOB Job 353 ); 354 355 VOID 356 NTAPI 357 PspInitializeJobStructures( 358 VOID 359 ); 360 361 VOID 362 NTAPI 363 PspDeleteJob( 364 IN PVOID ObjectBody 365 ); 366 367 // 368 // State routines 369 // 370 NTSTATUS 371 NTAPI 372 PsResumeThread( 373 IN PETHREAD Thread, 374 OUT PULONG PreviousCount OPTIONAL 375 ); 376 377 NTSTATUS 378 NTAPI 379 PsSuspendThread( 380 IN PETHREAD Thread, 381 OUT PULONG PreviousCount OPTIONAL 382 ); 383 384 VOID 385 NTAPI 386 PspGetOrSetContextKernelRoutine( 387 IN PKAPC Apc, 388 IN OUT PKNORMAL_ROUTINE* NormalRoutine, 389 IN OUT PVOID* NormalContext, 390 IN OUT PVOID* SystemArgument1, 391 IN OUT PVOID* SystemArgument2 392 ); 393 394 // 395 // Process Quotas 396 // 397 NTSTATUS 398 NTAPI 399 PsReturnProcessPageFileQuota( 400 IN PEPROCESS Process, 401 IN SIZE_T Amount 402 ); 403 404 NTSTATUS 405 NTAPI 406 PsChargeProcessPageFileQuota( 407 IN PEPROCESS Process, 408 IN SIZE_T Amount 409 ); 410 411 BOOLEAN 412 NTAPI 413 PspIsProcessExiting(IN PEPROCESS Process); 414 415 // 416 // Apphelp functions 417 // 418 NTSTATUS 419 NTAPI 420 ApphelpCacheInitialize(VOID); 421 422 VOID 423 NTAPI 424 ApphelpCacheShutdown(VOID); 425 426 // 427 // Global data inside the Process Manager 428 // 429 extern ULONG PspTraceLevel; 430 extern LCID PsDefaultThreadLocaleId; 431 extern LCID PsDefaultSystemLocaleId; 432 extern LIST_ENTRY PspReaperListHead; 433 extern WORK_QUEUE_ITEM PspReaperWorkItem; 434 extern BOOLEAN PspReaping; 435 extern PEPROCESS PsIdleProcess; 436 extern LIST_ENTRY PsActiveProcessHead; 437 extern KGUARDED_MUTEX PspActiveProcessMutex; 438 extern LARGE_INTEGER ShortPsLockDelay; 439 extern EPROCESS_QUOTA_BLOCK PspDefaultQuotaBlock; 440 extern PHANDLE_TABLE PspCidTable; 441 extern EX_CALLBACK PspThreadNotifyRoutine[PSP_MAX_CREATE_THREAD_NOTIFY]; 442 extern EX_CALLBACK PspProcessNotifyRoutine[PSP_MAX_CREATE_PROCESS_NOTIFY]; 443 extern EX_CALLBACK PspLoadImageNotifyRoutine[PSP_MAX_LOAD_IMAGE_NOTIFY]; 444 extern PLEGO_NOTIFY_ROUTINE PspLegoNotifyRoutine; 445 extern ULONG PspThreadNotifyRoutineCount, PspProcessNotifyRoutineCount; 446 extern BOOLEAN PsImageNotifyEnabled; 447 extern PKWIN32_PROCESS_CALLOUT PspW32ProcessCallout; 448 extern PKWIN32_THREAD_CALLOUT PspW32ThreadCallout; 449 extern PVOID PspSystemDllEntryPoint; 450 extern PVOID PspSystemDllBase; 451 extern BOOLEAN PspUseJobSchedulingClasses; 452 extern CHAR PspJobSchedulingClasses[PSP_JOB_SCHEDULING_CLASSES]; 453 extern ULONG PsRawPrioritySeparation; 454 extern ULONG PsPrioritySeparation; 455 extern POBJECT_TYPE _PsThreadType, _PsProcessType; 456 extern PTOKEN PspBootAccessToken; 457 extern GENERIC_MAPPING PspJobMapping; 458 extern POBJECT_TYPE PsJobType; 459 extern LARGE_INTEGER ShortPsLockDelay; 460 extern UNICODE_STRING PsNtDllPathName; 461 extern LIST_ENTRY PsLoadedModuleList; 462 extern KSPIN_LOCK PsLoadedModuleSpinLock; 463 extern ERESOURCE PsLoadedModuleResource; 464 extern ULONG_PTR PsNtosImageBase; 465 466 // 467 // Inlined Functions 468 // 469 #include "ps_x.h" 470