Thread/Process Termination/Repeaing Rewrite + Fixes
[reactos.git] / reactos / ntoskrnl / include / internal / ps.h
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * FILE: ntoskrnl/ke/kthread.c
22 * PURPOSE: Process manager definitions
23 * PROGRAMMER: David Welch (welch@cwcom.net)
24 * UPDATE HISTORY:
25 * Created 22/05/98
26 */
27
28 #ifndef __INCLUDE_INTERNAL_PS_H
29 #define __INCLUDE_INTERNAL_PS_H
30
31 #ifndef __ASM__
32
33 /* Forward declarations. */
34 struct _KTHREAD;
35 struct _KTRAPFRAME;
36 struct _EJOB;
37
38 #endif /* __ASM__ */
39
40 #include <internal/arch/ps.h>
41
42 #ifndef __ASM__
43
44 #include <internal/mm.h>
45 #include <napi/teb.h>
46
47 #ifndef KeGetCurrentProcessorNumber
48 #define KeGetCurrentProcessorNumber() (KeGetCurrentKPCR()->ProcessorNumber)
49 #endif
50
51 extern LCID PsDefaultThreadLocaleId;
52 extern LCID PsDefaultSystemLocaleId;
53
54 #include <pshpack1.h>
55
56 typedef struct _KTHREAD
57 {
58 /* For waiting on thread exit */
59 DISPATCHER_HEADER DispatcherHeader; /* 00 */
60
61 /* List of mutants owned by the thread */
62 LIST_ENTRY MutantListHead; /* 10 */
63 PVOID InitialStack; /* 18 */
64 ULONG_PTR StackLimit; /* 1C */
65
66 /* Pointer to the thread's environment block in user memory */
67 PTEB Teb; /* 20 */
68
69 /* Pointer to the thread's TLS array */
70 PVOID TlsArray; /* 24 */
71 PVOID KernelStack; /* 28 */
72 UCHAR DebugActive; /* 2C */
73
74 /* Thread state (one of THREAD_STATE_xxx constants below) */
75 UCHAR State; /* 2D */
76 BOOLEAN Alerted[2]; /* 2E */
77 UCHAR Iopl; /* 30 */
78 UCHAR NpxState; /* 31 */
79 CHAR Saturation; /* 32 */
80 CHAR Priority; /* 33 */
81 KAPC_STATE ApcState; /* 34 */
82 ULONG ContextSwitches; /* 4C */
83 LONG WaitStatus; /* 50 */
84 KIRQL WaitIrql; /* 54 */
85 CHAR WaitMode; /* 55 */
86 UCHAR WaitNext; /* 56 */
87 UCHAR WaitReason; /* 57 */
88 PKWAIT_BLOCK WaitBlockList; /* 58 */
89 LIST_ENTRY WaitListEntry; /* 5C */
90 ULONG WaitTime; /* 64 */
91 CHAR BasePriority; /* 68 */
92 UCHAR DecrementCount; /* 69 */
93 UCHAR PriorityDecrement; /* 6A */
94 CHAR Quantum; /* 6B */
95 KWAIT_BLOCK WaitBlock[4]; /* 6C */
96 PVOID LegoData; /* CC */
97 ULONG KernelApcDisable; /* D0 */
98 KAFFINITY UserAffinity; /* D4 */
99 UCHAR SystemAffinityActive;/* D8 */
100 UCHAR PowerState; /* D9 */
101 UCHAR NpxIrql; /* DA */
102 UCHAR Pad[1]; /* DB */
103 SSDT_ENTRY *ServiceTable; /* DC */
104 PKQUEUE Queue; /* E0 */
105 KSPIN_LOCK ApcQueueLock; /* E4 */
106 KTIMER Timer; /* E8 */
107 LIST_ENTRY QueueListEntry; /* 110 */
108 KAFFINITY Affinity; /* 118 */
109 UCHAR Preempted; /* 11C */
110 UCHAR ProcessReadyQueue; /* 11D */
111 UCHAR KernelStackResident; /* 11E */
112 UCHAR NextProcessor; /* 11F */
113 PVOID CallbackStack; /* 120 */
114 struct _W32THREAD *Win32Thread; /* 124 */
115 struct _KTRAP_FRAME *TrapFrame; /* 128 */
116 PKAPC_STATE ApcStatePointer[2]; /* 12C */
117 UCHAR EnableStackSwap; /* 134 */
118 UCHAR LargeStack; /* 135 */
119 UCHAR ResourceIndex; /* 136 */
120 UCHAR PreviousMode; /* 137 */
121 ULONG KernelTime; /* 138 */
122 ULONG UserTime; /* 13C */
123 KAPC_STATE SavedApcState; /* 140 */
124 UCHAR Alertable; /* 158 */
125 UCHAR ApcStateIndex; /* 159 */
126 UCHAR ApcQueueable; /* 15A */
127 UCHAR AutoAlignment; /* 15B */
128 PVOID StackBase; /* 15C */
129 KAPC SuspendApc; /* 160 */
130 KSEMAPHORE SuspendSemaphore; /* 190 */
131 LIST_ENTRY ThreadListEntry; /* 1A4 */
132 CHAR FreezeCount; /* 1AC */
133 UCHAR SuspendCount; /* 1AD */
134 UCHAR IdealProcessor; /* 1AE */
135 UCHAR DisableBoost; /* 1AF */
136 } KTHREAD;
137
138 #include <poppack.h>
139
140 /* Top level irp definitions. */
141 #define FSRTL_FSP_TOP_LEVEL_IRP (0x01)
142 #define FSRTL_CACHE_TOP_LEVEL_IRP (0x02)
143 #define FSRTL_MOD_WRITE_TOP_LEVEL_IRP (0x03)
144 #define FSRTL_FAST_IO_TOP_LEVEL_IRP (0x04)
145 #define FSRTL_MAX_TOP_LEVEL_IRP_FLAG (0x04)
146
147 #ifndef __USE_W32API
148 typedef struct
149 {
150 PACCESS_TOKEN Token;
151 BOOLEAN CopyOnOpen;
152 BOOLEAN EffectiveOnly;
153 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
154 } PS_IMPERSONATION_INFORMATION, *PPS_IMPERSONATION_INFORMATION;
155 #endif
156
157 #include <pshpack1.h>
158
159 typedef struct _ETHREAD
160 {
161 KTHREAD Tcb;
162 union {
163 LARGE_INTEGER CreateTime;
164 UCHAR NestedFaultCount:2;
165 UCHAR ApcNeeded:1;
166 };
167 LARGE_INTEGER ExitTime;
168 LIST_ENTRY LpcReplyChain;
169 NTSTATUS ExitStatus;
170 PVOID OfsChain;
171 LIST_ENTRY PostBlockList;
172 LIST_ENTRY TerminationPortList;
173 KSPIN_LOCK ActiveTimerListLock;
174 LIST_ENTRY ActiveTimerListHead;
175 CLIENT_ID Cid;
176 KSEMAPHORE LpcReplySemaphore;
177 PVOID LpcReplyMessage;
178 ULONG LpcReplyMessageId;
179 ULONG PerformanceCountLow;
180 PPS_IMPERSONATION_INFORMATION ImpersonationInfo;
181 LIST_ENTRY IrpList;
182 PIRP TopLevelIrp;
183 PDEVICE_OBJECT DeviceToVerify;
184 ULONG ReadClusterSize;
185 UCHAR ForwardClusterOnly;
186 UCHAR DisablePageFaultClustering;
187 UCHAR DeadThread;
188 UCHAR HideFromDebugger;
189 ULONG HasTerminated;
190 #ifdef _ENABLE_THRDEVTPAIR
191 PVOID EventPair;
192 #endif /* _ENABLE_THRDEVTPAIR */
193 ACCESS_MASK GrantedAccess;
194 struct _EPROCESS *ThreadsProcess;
195 PKSTART_ROUTINE StartAddress;
196 LPTHREAD_START_ROUTINE Win32StartAddress;
197 ULONG LpcReceivedMessageId;
198 UCHAR LpcExitThreadCalled;
199 UCHAR HardErrorsAreDisabled;
200 UCHAR LpcReceivedMsgIdValid;
201 UCHAR ActiveImpersonationInfo;
202 ULONG PerformanceCountHigh;
203 LIST_ENTRY ThreadListEntry;
204 BOOLEAN SystemThread;
205 } ETHREAD;
206
207 #include <poppack.h>
208
209
210 #ifndef __USE_W32API
211
212 typedef struct _ETHREAD *PETHREAD;
213
214 #endif /* __USE_W32API */
215
216
217 typedef struct _KPROCESS
218 {
219 /* So it's possible to wait for the process to terminate */
220 DISPATCHER_HEADER DispatcherHeader; /* 000 */
221 /*
222 * Presumably a list of profile objects associated with this process,
223 * currently unused.
224 */
225 LIST_ENTRY ProfileListHead; /* 010 */
226 /*
227 * We use the first member of this array to hold the physical address of
228 * the page directory for this process.
229 */
230 PHYSICAL_ADDRESS DirectoryTableBase; /* 018 */
231 /*
232 * Presumably a descriptor for the process's LDT, currently unused.
233 */
234 ULONG LdtDescriptor[2]; /* 020 */
235 /*
236 * Virtual Dos Machine flag.
237 */
238 ULONG NtVdmFlag; /* 028 */
239 ULONG VdmUnused; /* 02C */
240 /* Is the i/o permission map enabled for the process. */
241 USHORT IopmOffset; /* 030 */
242 /*
243 * Presumably I/O privilege level to be used for this process, currently
244 * unused.
245 */
246 UCHAR Iopl; /* 032 */
247 /* Set if this process is a virtual dos machine? */
248 UCHAR VdmFlag; /* 033 */
249 /* Bitmask of the processors being used by this process's threads? */
250 ULONG ActiveProcessors; /* 034 */
251 /* Aggregate of the time this process's threads have spent in kernel mode? */
252 ULONG KernelTime; /* 038 */
253 /* Aggregate of the time this process's threads have spent in user mode? */
254 ULONG UserTime; /* 03C */
255 /* List of this process's threads that are ready for execution? */
256 LIST_ENTRY ReadyListHead; /* 040 */
257 /* List of this process's threads that have their stacks swapped out? */
258 LIST_ENTRY SwapListEntry; /* 048 */
259 /* List of this process's threads? */
260 LIST_ENTRY ThreadListHead; /* 050 */
261 /* Maybe a lock for this data structure, the type is assumed. */
262 KSPIN_LOCK ProcessLock; /* 058 */
263 /* Default affinity mask for this process's threads? */
264 ULONG Affinity; /* 05C */
265 /* Count of the stacks allocated for this process's threads? */
266 USHORT StackCount; /* 060 */
267 /* Base priority for this process's threads? */
268 KPRIORITY BasePriority; /* 062 */
269 /* Default quantum for this process's threads */
270 UCHAR ThreadQuantum; /* 063 */
271 /* Unknown. */
272 UCHAR AutoAlignment; /* 064 */
273 /* Process execution state, currently either active or terminated. */
274 UCHAR State; /* 065 */
275 /* Seed for generating thread ids for this process's threads? */
276 UCHAR ThreadSeed; /* 066 */
277 /* Disable priority boosts? */
278 UCHAR DisableBoost; /* 067 */
279 } KPROCESS;
280
281 #ifndef __USE_W32API
282
283 typedef struct _KPROCESS *PKPROCESS;
284
285 typedef struct _HARDWARE_PTE_X86 {
286 ULONG Valid : 1;
287 ULONG Write : 1;
288 ULONG Owner : 1;
289 ULONG WriteThrough : 1;
290 ULONG CacheDisable : 1;
291 ULONG Accessed : 1;
292 ULONG Dirty : 1;
293 ULONG LargePage : 1;
294 ULONG Global : 1;
295 ULONG CopyOnWrite : 1;
296 ULONG Prototype : 1;
297 ULONG reserved : 1;
298 ULONG PageFrameNumber : 20;
299 } HARDWARE_PTE_X86, *PHARDWARE_PTE_X86;
300
301 typedef struct _WOW64_PROCESS
302 {
303 PVOID Wow64;
304 } WOW64_PROCESS, *PWOW64_PROCESS;
305
306 #endif /* __USE_W32API */
307
308 struct _EPROCESS
309 {
310 /* Microkernel specific process state. */
311 KPROCESS Pcb; /* 000 */
312 /* Exit status of the process. */
313 NTSTATUS ExitStatus; /* 068 */
314 /* Unknown. */
315 KEVENT LockEvent; /* 06C */
316 /* Unknown. */
317 ULONG LockCount; /* 07C */
318
319 /* Time of process creation. */
320 LARGE_INTEGER CreateTime; /* 080 */
321
322 /* Time of process exit. */
323 LARGE_INTEGER ExitTime; /* 088 */
324 /* Unknown. */
325 PKTHREAD LockOwner; /* 090 */
326 /* Process id. */
327 HANDLE UniqueProcessId; /* 094 */
328 /* Unknown. */
329 LIST_ENTRY ActiveProcessLinks; /* 098 */
330 /* Unknown. */
331 ULONG QuotaPeakPoolUsage[2]; /* 0A0 */
332 /* Unknown. */
333 ULONG QuotaPoolUsage[2]; /* 0A8 */
334 /* Unknown. */
335 ULONG PagefileUsage; /* 0B0 */
336 /* Unknown. */
337 ULONG CommitCharge; /* 0B4 */
338 /* Unknown. */
339 ULONG PeakPagefileUsage; /* 0B8 */
340 /* Unknown. */
341 ULONG PeakVirtualSize; /* 0BC */
342 /* Unknown. */
343 LARGE_INTEGER VirtualSize; /* 0C0 */
344
345 MMSUPPORT Vm;
346 LIST_ENTRY SessionProcessLinks;
347 struct _EPORT *DebugPort;
348 struct _EPORT *ExceptionPort;
349 PHANDLE_TABLE ObjectTable;
350 PVOID Token;
351 FAST_MUTEX WorkingSetLock;
352 ULONG WorkingSetPage;
353 UCHAR ProcessOutswapEnabled;
354 UCHAR ProcessOutswapped;
355 UCHAR AddressSpaceInitialized;
356 UCHAR AddressSpaceDeleted;
357 FAST_MUTEX AddressCreationLock;
358 KSPIN_LOCK HyperSpaceLock;
359 PETHREAD ForkInProgress;
360 USHORT VmOperation;
361 UCHAR ForkWasSuccessful;
362 UCHAR MmAgressiveWsTrimMask;
363 PKEVENT VmOperationEvent;
364 PVOID PaeTop;
365 ULONG LastFaultCount;
366 ULONG ModifiedPageCount;
367 PVOID VadRoot;
368 PVOID VadHint;
369 PVOID CloneRoot;
370 ULONG NumberOfPrivatePages;
371 ULONG NumberOfLockedPages;
372 USHORT NextPageColor;
373 UCHAR ExitProcessCalled;
374 UCHAR CreateProcessReported;
375 HANDLE SectionHandle;
376 PPEB Peb;
377 PVOID SectionBaseAddress;
378 PEPROCESS_QUOTA_BLOCK QuotaBlock;
379 NTSTATUS LastThreadExitStatus;
380 PPAGEFAULT_HISTORY WorkingSetWatch;
381 HANDLE Win32WindowStation;
382 HANDLE InheritedFromUniqueProcessId;
383 ULONG GrantedAccess;
384 ULONG DefaultHardErrorProcessing;
385 PVOID LdtInformation;
386 PVOID VadFreeHint;
387 PVOID VdmObjects;
388 PVOID DeviceObjects;
389 ULONG SessionId;
390 LIST_ENTRY PhysicalVadList;
391 HARDWARE_PTE_X86 PageDirectoryPte;
392 ULONGLONG Filler;
393 ULONG PaePageDirectoryPage;
394 CHAR ImageFileName[16];
395 ULONG VmTrimFaultValue;
396 UCHAR SetTimerResolution;
397 UCHAR PriorityClass;
398 UCHAR SubSystemMinorVersion;
399 UCHAR SubSystemMajorVersion;
400 USHORT SubSystemVersion;
401 struct _W32PROCESS *Win32Process;
402 struct _EJOB *Job;
403 ULONG JobStatus;
404 LIST_ENTRY JobLinks;
405 PVOID LockedPagesList;
406 struct _EPORT *SecurityPort;
407 PWOW64_PROCESS Wow64;
408 LARGE_INTEGER ReadOperationCount;
409 LARGE_INTEGER WriteOperationCount;
410 LARGE_INTEGER OtherOperationCount;
411 LARGE_INTEGER ReadTransferCount;
412 LARGE_INTEGER WriteTransferCount;
413 LARGE_INTEGER OtherTransferCount;
414 ULONG CommitChargeLimit;
415 ULONG CommitChargePeak;
416 LIST_ENTRY ThreadListHead;
417 PRTL_BITMAP VadPhysicalPagesBitMap;
418 ULONG VadPhysicalPages;
419 KSPIN_LOCK AweLock;
420 ULONG Cookie;
421
422 /*
423 * FIXME - ReactOS specified - remove the following fields ASAP!!!
424 */
425 MADDRESS_SPACE AddressSpace;
426 LIST_ENTRY ProcessListEntry;
427 FAST_MUTEX TebLock;
428 PVOID TebBlock;
429 PVOID TebLastAllocated;
430 };
431
432 #define PROCESS_STATE_TERMINATED (1)
433 #define PROCESS_STATE_ACTIVE (2)
434
435 VOID PiInitDefaultLocale(VOID);
436 VOID PiInitProcessManager(VOID);
437 VOID PiShutdownProcessManager(VOID);
438 VOID PsInitThreadManagment(VOID);
439 VOID PsInitProcessManagment(VOID);
440 VOID PsInitIdleThread(VOID);
441 VOID PiTerminateProcessThreads(PEPROCESS Process, NTSTATUS ExitStatus);
442 VOID PsTerminateCurrentThread(NTSTATUS ExitStatus);
443 VOID PsTerminateOtherThread(PETHREAD Thread, NTSTATUS ExitStatus);
444 VOID PsReleaseThread(PETHREAD Thread);
445 VOID PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext);
446 VOID PsBeginThreadWithContextInternal(VOID);
447 VOID PiKillMostProcesses(VOID);
448 NTSTATUS STDCALL PiTerminateProcess(PEPROCESS Process, NTSTATUS ExitStatus);
449 VOID PiInitApcManagement(VOID);
450 VOID STDCALL PiDeleteThread(PVOID ObjectBody);
451 VOID PsReapThreads(VOID);
452 VOID PsInitializeThreadReaper(VOID);
453 VOID PsQueueThreadReap(PETHREAD Thread);
454 NTSTATUS
455 PsInitializeThread(PEPROCESS Process,
456 PETHREAD* ThreadPtr,
457 POBJECT_ATTRIBUTES ObjectAttributes,
458 KPROCESSOR_MODE AccessMode,
459 BOOLEAN First);
460
461 PACCESS_TOKEN STDCALL PsReferenceEffectiveToken(PETHREAD Thread,
462 PTOKEN_TYPE TokenType,
463 PUCHAR b,
464 PSECURITY_IMPERSONATION_LEVEL Level);
465
466 NTSTATUS STDCALL PsOpenTokenOfProcess(HANDLE ProcessHandle,
467 PACCESS_TOKEN* Token);
468 VOID
469 STDCALL
470 PspTerminateProcessThreads(PEPROCESS Process,
471 NTSTATUS ExitStatus);
472 NTSTATUS PsSuspendThread(PETHREAD Thread, PULONG PreviousCount);
473 NTSTATUS PsResumeThread(PETHREAD Thread, PULONG PreviousCount);
474 NTSTATUS
475 STDCALL
476 PspAssignPrimaryToken(PEPROCESS Process,
477 HANDLE TokenHandle);
478 VOID STDCALL PsExitSpecialApc(PKAPC Apc,
479 PKNORMAL_ROUTINE *NormalRoutine,
480 PVOID *NormalContext,
481 PVOID *SystemArgument1,
482 PVOID *SystemArgument2);
483
484 #define THREAD_STATE_INITIALIZED (0)
485 #define THREAD_STATE_READY (1)
486 #define THREAD_STATE_RUNNING (2)
487 #define THREAD_STATE_SUSPENDED (3)
488 #define THREAD_STATE_FROZEN (4)
489 #define THREAD_STATE_TERMINATED_1 (5)
490 #define THREAD_STATE_TERMINATED_2 (6)
491 #define THREAD_STATE_BLOCKED (7)
492 #define THREAD_STATE_MAX (8)
493
494
495 /*
496 * Internal thread priorities, added by Phillip Susi
497 * TODO: rebalence these to make use of all priorities... the ones above 16
498 * can not all be used right now
499 */
500 #define PROCESS_PRIO_IDLE 3
501 #define PROCESS_PRIO_NORMAL 8
502 #define PROCESS_PRIO_HIGH 13
503 #define PROCESS_PRIO_RT 18
504
505
506 VOID STDCALL PiDeleteProcess(PVOID ObjectBody);
507
508 VOID
509 STDCALL
510 PspReapRoutine(PVOID Context);
511
512 VOID
513 STDCALL
514 PspExitThread(NTSTATUS ExitStatus);
515
516 extern LIST_ENTRY PspReaperListHead;
517 extern WORK_QUEUE_ITEM PspReaperWorkItem;
518 extern BOOLEAN PspReaping;
519
520 VOID
521 STDCALL
522 PspTerminateThreadByPointer(PETHREAD Thread,
523 NTSTATUS ExitStatus);
524
525 VOID PsUnfreezeOtherThread(PETHREAD Thread);
526 VOID PsFreezeOtherThread(PETHREAD Thread);
527 VOID PsFreezeProcessThreads(PEPROCESS Process);
528 VOID PsUnfreezeProcessThreads(PEPROCESS Process);
529 ULONG PsEnumThreadsByProcess(PEPROCESS Process);
530 PEPROCESS PsGetNextProcess(PEPROCESS OldProcess);
531 VOID
532 PsApplicationProcessorInit(VOID);
533 VOID
534 PsPrepareForApplicationProcessorInit(ULONG Id);
535 VOID STDCALL
536 PsIdleThreadMain(PVOID Context);
537
538 VOID STDCALL
539 PiSuspendThreadRundownRoutine(PKAPC Apc);
540 VOID STDCALL
541 PiSuspendThreadKernelRoutine(PKAPC Apc,
542 PKNORMAL_ROUTINE* NormalRoutine,
543 PVOID* NormalContext,
544 PVOID* SystemArgument1,
545 PVOID* SystemArguemnt2);
546 VOID STDCALL
547 PiSuspendThreadNormalRoutine(PVOID NormalContext,
548 PVOID SystemArgument1,
549 PVOID SystemArgument2);
550 VOID
551 PsInitialiseSuspendImplementation(VOID);
552 NTSTATUS
553 STDCALL
554 PspExitProcess(PEPROCESS Process);
555
556 VOID
557 STDCALL
558 PspDeleteProcess(PVOID ObjectBody);
559
560 VOID
561 STDCALL
562 PspDeleteThread(PVOID ObjectBody);
563
564 extern LONG PiNrThreadsAwaitingReaping;
565
566 NTSTATUS
567 PsInitWin32Thread (PETHREAD Thread);
568
569 VOID
570 PsTerminateWin32Process (PEPROCESS Process);
571
572 VOID
573 PsTerminateWin32Thread (PETHREAD Thread);
574
575 VOID
576 PsInitialiseW32Call(VOID);
577
578 VOID
579 STDCALL
580 PspRunCreateThreadNotifyRoutines(PETHREAD, BOOLEAN);
581
582 VOID
583 STDCALL
584 PspRunCreateProcessNotifyRoutines(PEPROCESS, BOOLEAN);
585
586 #include <pshpack1.h>
587 typedef struct _PS_JOB_TOKEN_FILTER
588 {
589 UINT CapturedSidCount;
590 PSID_AND_ATTRIBUTES CapturedSids;
591 UINT CapturedSidsLength;
592 UINT CapturedGroupCount;
593 PSID_AND_ATTRIBUTES CapturedGroups;
594 UINT CapturedGroupsLength;
595 UINT CapturedPrivilegeCount;
596 PLUID_AND_ATTRIBUTES CapturedPrivileges;
597 UINT CapturedPrivilegesLength;
598 } PS_JOB_TOKEN_FILTER, *PPS_JOB_TOKEN_FILTER;
599 #include <poppack.h>
600
601 #include <pshpack1.h>
602 typedef struct _EJOB
603 {
604 KEVENT Event;
605 LIST_ENTRY JobLinks;
606 LIST_ENTRY ProcessListHead;
607 ERESOURCE JobLock;
608 LARGE_INTEGER TotalUserTime;
609 LARGE_INTEGER TotalKernelTime;
610 LARGE_INTEGER ThisPeriodTotalUserTime;
611 LARGE_INTEGER ThisPeriodTotalKernelTime;
612 UINT TotalPageFaultCount;
613 UINT TotalProcesses;
614 UINT ActiveProcesses;
615 UINT TotalTerminatedProcesses;
616 LARGE_INTEGER PerProcessUserTimeLimit;
617 LARGE_INTEGER PerJobUserTimeLimit;
618 UINT LimitFlags;
619 UINT MinimumWorkingSetSize;
620 UINT MaximumWorkingSetSize;
621 UINT ActiveProcessLimit;
622 UINT Affinity;
623 BYTE PriorityClass;
624 UINT UIRestrictionsClass;
625 UINT SecurityLimitFlags;
626 PVOID Token;
627 PPS_JOB_TOKEN_FILTER Filter;
628 UINT EndOfJobTimeAction;
629 PVOID CompletionPort;
630 PVOID CompletionKey;
631 UINT SessionId;
632 UINT SchedulingClass;
633 ULONGLONG ReadOperationCount;
634 ULONGLONG WriteOperationCount;
635 ULONGLONG OtherOperationCount;
636 ULONGLONG ReadTransferCount;
637 ULONGLONG WriteTransferCount;
638 ULONGLONG OtherTransferCount;
639 IO_COUNTERS IoInfo;
640 UINT ProcessMemoryLimit;
641 UINT JobMemoryLimit;
642 UINT PeakProcessMemoryUsed;
643 UINT PeakJobMemoryUsed;
644 UINT CurrentJobMemoryUsed;
645 FAST_MUTEX MemoryLimitsLock;
646 } EJOB;
647 #include <poppack.h>
648
649 VOID INIT_FUNCTION PsInitJobManagment(VOID);
650
651 /* CLIENT ID */
652
653 NTSTATUS PsCreateCidHandle(PVOID Object, POBJECT_TYPE ObjectType, PHANDLE Handle);
654 NTSTATUS PsDeleteCidHandle(HANDLE CidHandle, POBJECT_TYPE ObjectType);
655 PHANDLE_TABLE_ENTRY PsLookupCidHandle(HANDLE CidHandle, POBJECT_TYPE ObjectType, PVOID *Object);
656 VOID PsUnlockCidHandle(PHANDLE_TABLE_ENTRY CidEntry);
657 NTSTATUS PsLockProcess(PEPROCESS Process, BOOL Timeout);
658 VOID PsUnlockProcess(PEPROCESS Process);
659
660 #define ETHREAD_TO_KTHREAD(pEThread) (&(pEThread)->Tcb)
661 #define KTHREAD_TO_ETHREAD(pKThread) (CONTAINING_RECORD((pKThread), ETHREAD, Tcb))
662 #define EPROCESS_TO_KPROCESS(pEProcess) (&(pEProcess)->Pcb)
663 #define KPROCESS_TO_EPROCESS(pKProcess) (CONTAINING_RECORD((pKProcess), EPROCESS, Pcb))
664
665 #endif /* ASSEMBLER */
666
667 #endif /* __INCLUDE_INTERNAL_PS_H */