* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/*
+/* $Id$
+ *
* FILE: ntoskrnl/ke/kthread.c
* PURPOSE: Process manager definitions
* PROGRAMMER: David Welch (welch@cwcom.net)
#ifndef __INCLUDE_INTERNAL_PS_H
#define __INCLUDE_INTERNAL_PS_H
-/*
- * Defines for accessing KPCR and KTHREAD structure members
- */
-#define KTHREAD_KERNEL_STACK 0x28
-#define KTHREAD_PREVIOUS_MODE 0x137
-#define KTHREAD_TRAP_FRAME 0x128
+#ifndef __ASM__
+
+/* Forward declarations. */
+struct _KTHREAD;
+struct _KTRAPFRAME;
+struct _EJOB;
-#define KPCR_BASE 0xFFDFF000
+#endif /* __ASM__ */
-#define KPCR_EXCEPTION_LIST 0x0
-#define KPCR_CURRENT_THREAD 0x124
+#include <internal/arch/ps.h>
#ifndef __ASM__
-#include <internal/hal.h>
#include <internal/mm.h>
+#include <napi/teb.h>
-struct _KTHREAD;
-struct _KTRAPFRAME;
+#ifndef KeGetCurrentProcessorNumber
+#define KeGetCurrentProcessorNumber() (KeGetCurrentKPCR()->ProcessorNumber)
+#endif
-/*
- * Processor Control Region
- */
-typedef struct _KPCR
-{
- PVOID ExceptionList; /* 00 */
- PVOID StackBase; /* 04 */
- PVOID StackLimit; /* 08 */
- PVOID SubSystemTib; /* 0C */
- PVOID Reserved1; /* 10 */
- PVOID ArbitraryUserPointer; /* 14 */
- struct _KPCR* Self; /* 18 */
- UCHAR Reserved2[0x108]; /* 1C */
- struct _KTHREAD* CurrentThread; /* 124 */
-} KPCR, *PKPCR;
-
-#define CURRENT_KPCR ((PKPCR)KPCR_BASE)
-
-extern HANDLE SystemProcessHandle;
-
-typedef struct _KAPC_STATE
-{
- LIST_ENTRY ApcListHead[2];
- struct _KPROCESS* Process;
- UCHAR KernelApcInProgress;
- UCHAR KernelApcPending;
- USHORT UserApcPending;
-} __attribute__((packed)) KAPC_STATE, *PKAPC_STATE;
+extern LCID PsDefaultThreadLocaleId;
+extern LCID PsDefaultSystemLocaleId;
+
+#include <pshpack1.h>
typedef struct _KTHREAD
{
+ /* For waiting on thread exit */
DISPATCHER_HEADER DispatcherHeader; /* 00 */
+
+ /* List of mutants owned by the thread */
LIST_ENTRY MutantListHead; /* 10 */
PVOID InitialStack; /* 18 */
- ULONG StackLimit; /* 1C */
- NT_TEB* Teb; /* 20 */
+ ULONG_PTR StackLimit; /* 1C */
+
+ /* Pointer to the thread's environment block in user memory */
+ PTEB Teb; /* 20 */
+
+ /* Pointer to the thread's TLS array */
PVOID TlsArray; /* 24 */
PVOID KernelStack; /* 28 */
UCHAR DebugActive; /* 2C */
+
+ /* Thread state (one of THREAD_STATE_xxx constants below) */
UCHAR State; /* 2D */
- UCHAR Alerted[2]; /* 2E */
+ BOOLEAN Alerted[2]; /* 2E */
UCHAR Iopl; /* 30 */
UCHAR NpxState; /* 31 */
- UCHAR Saturation; /* 32 */
+ CHAR Saturation; /* 32 */
CHAR Priority; /* 33 */
KAPC_STATE ApcState; /* 34 */
ULONG ContextSwitches; /* 4C */
- ULONG WaitStatus; /* 50 */
+ LONG WaitStatus; /* 50 */
KIRQL WaitIrql; /* 54 */
- UCHAR WaitMode; /* 55 */
+ CHAR WaitMode; /* 55 */
UCHAR WaitNext; /* 56 */
UCHAR WaitReason; /* 57 */
PKWAIT_BLOCK WaitBlockList; /* 58 */
CHAR BasePriority; /* 68 */
UCHAR DecrementCount; /* 69 */
UCHAR PriorityDecrement; /* 6A */
- UCHAR Quantum; /* 6B */
+ CHAR Quantum; /* 6B */
KWAIT_BLOCK WaitBlock[4]; /* 6C */
PVOID LegoData; /* CC */
- LONG KernelApcDisable; /* D0 */
+ ULONG KernelApcDisable; /* D0 */
KAFFINITY UserAffinity; /* D4 */
UCHAR SystemAffinityActive;/* D8 */
- UCHAR Pad[7]; /* D9 */
+ UCHAR PowerState; /* D9 */
+ UCHAR NpxIrql; /* DA */
+ UCHAR Pad[1]; /* DB */
+ SSDT_ENTRY *ServiceTable; /* DC */
PKQUEUE Queue; /* E0 */
KSPIN_LOCK ApcQueueLock; /* E4 */
KTIMER Timer; /* E8 */
UCHAR KernelStackResident; /* 11E */
UCHAR NextProcessor; /* 11F */
PVOID CallbackStack; /* 120 */
- BOOL Win32Thread; /* 124 */
- struct _KTRAP_FRAME* TrapFrame; /* 128 */
- PVOID ApcStatePointer[2]; /* 12C */
+ struct _W32THREAD *Win32Thread; /* 124 */
+ struct _KTRAP_FRAME *TrapFrame; /* 128 */
+ PKAPC_STATE ApcStatePointer[2]; /* 12C */
UCHAR EnableStackSwap; /* 134 */
UCHAR LargeStack; /* 135 */
UCHAR ResourceIndex; /* 136 */
UCHAR PreviousMode; /* 137 */
- TIME KernelTime; /* 138 */
- TIME UserTime; /* 13C */
+ ULONG KernelTime; /* 138 */
+ ULONG UserTime; /* 13C */
KAPC_STATE SavedApcState; /* 140 */
UCHAR Alertable; /* 158 */
UCHAR ApcStateIndex; /* 159 */
UCHAR SuspendCount; /* 1AD */
UCHAR IdealProcessor; /* 1AE */
UCHAR DisableBoost; /* 1AF */
-
- /*
- * Below here are thread structure members that are specific to ReactOS
- */
-
- /* Added by Phillip Susi for list of threads in a process */
- LIST_ENTRY ProcessThreadListEntry;
-
- /* Provisionally added by David Welch */
- hal_thread_state Context;
- /* Added by Phillip Susi for internal KeAddThreadTimeout() implementation */
- KDPC TimerDpc;
-} __attribute__((packed)) KTHREAD, *PKTHREAD;
-
-// According to documentation the stack should have a commited [ 1 page ] and
-// a reserved part [ 1 M ] but can be specified otherwise in the image file.
-
+} KTHREAD;
+#include <poppack.h>
+/* Top level irp definitions. */
+#define FSRTL_FSP_TOP_LEVEL_IRP (0x01)
+#define FSRTL_CACHE_TOP_LEVEL_IRP (0x02)
+#define FSRTL_MOD_WRITE_TOP_LEVEL_IRP (0x03)
+#define FSRTL_FAST_IO_TOP_LEVEL_IRP (0x04)
+#define FSRTL_MAX_TOP_LEVEL_IRP_FLAG (0x04)
-
-
-
-// TopLevelIrp can be one of the following values:
-// FIXME I belong somewhere else
-
-#define FSRTL_FSP_TOP_LEVEL_IRP (0x01)
-#define FSRTL_CACHE_TOP_LEVEL_IRP (0x02)
-#define FSRTL_MOD_WRITE_TOP_LEVEL_IRP (0x03)
-#define FSRTL_FAST_IO_TOP_LEVEL_IRP (0x04)
-#define FSRTL_MAX_TOP_LEVEL_IRP_FLAG (0x04)
-
-typedef struct _TOP_LEVEL_IRP
-{
- PIRP TopLevelIrp;
- ULONG TopLevelIrpConst;
-} TOP_LEVEL_IRP;
-
+#ifndef __USE_W32API
typedef struct
{
- PACCESS_TOKEN Token; // 0x0
- UCHAR Unknown1; // 0x4
- UCHAR Unknown2; // 0x5
- UCHAR Pad[2]; // 0x6
- SECURITY_IMPERSONATION_LEVEL Level; // 0x8
-} PS_IMPERSONATION_INFO, *PPS_IMPERSONATION_INFO;
+ PACCESS_TOKEN Token;
+ BOOLEAN CopyOnOpen;
+ BOOLEAN EffectiveOnly;
+ SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
+} PS_IMPERSONATION_INFORMATION, *PPS_IMPERSONATION_INFORMATION;
+#endif
-struct _WIN32THREADDATA;
+#include <pshpack1.h>
-typedef struct _ETHREAD
+/* This needs to be fixed ASAP! */
+typedef struct _ETHREAD
{
- KTHREAD Tcb;
- TIME CreateTime;
- TIME ExitTime;
- NTSTATUS ExitStatus;
- LIST_ENTRY PostBlockList;
- LIST_ENTRY TerminationPortList;
- KSPIN_LOCK ActiveTimerListLock;
- PVOID ActiveTimerListHead;
- CLIENT_ID Cid;
- PLARGE_INTEGER LpcReplySemaphore;
- PVOID LpcReplyMessage;
- PLARGE_INTEGER LpcReplyMessageId;
- PPS_IMPERSONATION_INFO ImpersonationInfo;
- LIST_ENTRY IrpList;
- TOP_LEVEL_IRP TopLevelIrp;
- ULONG ReadClusterSize;
- UCHAR ForwardClusterOnly;
- UCHAR DisablePageFaultClustering;
- UCHAR DeadThread;
- UCHAR HasTerminated;
- ACCESS_MASK GrantedAccess;
- struct _EPROCESS* ThreadsProcess;
- PKSTART_ROUTINE StartAddress;
- LPTHREAD_START_ROUTINE Win32StartAddress;
- UCHAR LpcExitThreadCalled;
- UCHAR HardErrorsAreDisabled;
- UCHAR LpcReceivedMsgIdValid;
- UCHAR ActiveImpersonationInfo;
- ULONG PerformanceCountHigh;
-
- /*
- * Added by David Welch (welch@cwcom.net)
- */
- struct _EPROCESS* OldProcess;
- struct _WIN32THREADDATA *Win32ThreadData; // Pointer to win32 private thread data
-
-} ETHREAD, *PETHREAD;
+ KTHREAD Tcb;
+ union {
+ LARGE_INTEGER CreateTime;
+ UCHAR NestedFaultCount:2;
+ UCHAR ApcNeeded:1;
+ };
+ LARGE_INTEGER ExitTime;
+ LIST_ENTRY LpcReplyChain;
+ NTSTATUS ExitStatus;
+ PVOID OfsChain;
+ LIST_ENTRY PostBlockList;
+ union {
+ struct _TERMINATION_PORT *TerminationPort;
+ struct _ETHREAD* ReaperLink;
+ };
+ KSPIN_LOCK ActiveTimerListLock;
+ LIST_ENTRY ActiveTimerListHead;
+ CLIENT_ID Cid;
+ KSEMAPHORE LpcReplySemaphore;
+ PVOID LpcReplyMessage;
+ ULONG LpcReplyMessageId;
+ ULONG PerformanceCountLow;
+ PPS_IMPERSONATION_INFORMATION ImpersonationInfo;
+ LIST_ENTRY IrpList;
+ PIRP TopLevelIrp;
+ PDEVICE_OBJECT DeviceToVerify;
+ ULONG ReadClusterSize;
+ UCHAR ForwardClusterOnly;
+ UCHAR DisablePageFaultClustering;
+ UCHAR DeadThread;
+ UCHAR HideFromDebugger;
+ ULONG HasTerminated;
+#ifdef _ENABLE_THRDEVTPAIR
+ PVOID EventPair;
+#endif /* _ENABLE_THRDEVTPAIR */
+ ACCESS_MASK GrantedAccess;
+ struct _EPROCESS *ThreadsProcess;
+ PKSTART_ROUTINE StartAddress;
+ LPTHREAD_START_ROUTINE Win32StartAddress;
+ ULONG LpcReceivedMessageId;
+ UCHAR LpcExitThreadCalled;
+ UCHAR HardErrorsAreDisabled;
+ UCHAR LpcReceivedMsgIdValid;
+ UCHAR ActiveImpersonationInfo;
+ ULONG PerformanceCountHigh;
+ LIST_ENTRY ThreadListEntry;
+ BOOLEAN SystemThread;
+} ETHREAD;
+
+#include <poppack.h>
+
+
+#ifndef __USE_W32API
+
+typedef struct _ETHREAD *PETHREAD;
+
+#endif /* __USE_W32API */
typedef struct _KPROCESS
{
- DISPATCHER_HEADER DispatcherHeader;
- PVOID PageTableDirectory; // FIXME: I should point to a PTD
- TIME ElapsedTime;
- TIME KernelTime;
- TIME UserTime;
- LIST_ENTRY InMemoryList;
- LIST_ENTRY SwappedOutList;
- KSPIN_LOCK SpinLock;
- KAFFINITY Affinity;
- ULONG StackCount;
- KPRIORITY BasePriority;
- ULONG DefaultThreadQuantum;
- UCHAR ProcessState;
- ULONG ThreadSeed;
- UCHAR DisableBoost;
-} KPROCESS, *PKPROCESS;
-
-struct _WIN32PROCESSDATA;
-
-typedef struct _EPROCESS
+ /* So it's possible to wait for the process to terminate */
+ DISPATCHER_HEADER DispatcherHeader; /* 000 */
+ /*
+ * Presumably a list of profile objects associated with this process,
+ * currently unused.
+ */
+ LIST_ENTRY ProfileListHead; /* 010 */
+ /*
+ * We use the first member of this array to hold the physical address of
+ * the page directory for this process.
+ */
+ PHYSICAL_ADDRESS DirectoryTableBase; /* 018 */
+ /*
+ * Presumably a descriptor for the process's LDT, currently unused.
+ */
+ ULONG LdtDescriptor[2]; /* 020 */
+ /*
+ * Virtual Dos Machine flag.
+ */
+ ULONG NtVdmFlag; /* 028 */
+ ULONG VdmUnused; /* 02C */
+ /* Is the i/o permission map enabled for the process. */
+ USHORT IopmOffset; /* 030 */
+ /*
+ * Presumably I/O privilege level to be used for this process, currently
+ * unused.
+ */
+ UCHAR Iopl; /* 032 */
+ /* Set if this process is a virtual dos machine? */
+ UCHAR VdmFlag; /* 033 */
+ /* Bitmask of the processors being used by this process's threads? */
+ ULONG ActiveProcessors; /* 034 */
+ /* Aggregate of the time this process's threads have spent in kernel mode? */
+ ULONG KernelTime; /* 038 */
+ /* Aggregate of the time this process's threads have spent in user mode? */
+ ULONG UserTime; /* 03C */
+ /* List of this process's threads that are ready for execution? */
+ LIST_ENTRY ReadyListHead; /* 040 */
+ /* List of this process's threads that have their stacks swapped out? */
+ LIST_ENTRY SwapListEntry; /* 048 */
+ /* List of this process's threads? */
+ LIST_ENTRY ThreadListHead; /* 050 */
+ /* Maybe a lock for this data structure, the type is assumed. */
+ KSPIN_LOCK ProcessLock; /* 058 */
+ /* Default affinity mask for this process's threads? */
+ ULONG Affinity; /* 05C */
+ /* Count of the stacks allocated for this process's threads? */
+ USHORT StackCount; /* 060 */
+ /* Base priority for this process's threads? */
+ KPRIORITY BasePriority; /* 062 */
+ /* Default quantum for this process's threads */
+ UCHAR ThreadQuantum; /* 063 */
+ /* Unknown. */
+ UCHAR AutoAlignment; /* 064 */
+ /* Process execution state, currently either active or terminated. */
+ UCHAR State; /* 065 */
+ /* Seed for generating thread ids for this process's threads? */
+ UCHAR ThreadSeed; /* 066 */
+ /* Disable priority boosts? */
+ UCHAR DisableBoost; /* 067 */
+} KPROCESS;
+
+#ifndef __USE_W32API
+
+typedef struct _KPROCESS *PKPROCESS;
+
+typedef struct _HARDWARE_PTE_X86 {
+ ULONG Valid : 1;
+ ULONG Write : 1;
+ ULONG Owner : 1;
+ ULONG WriteThrough : 1;
+ ULONG CacheDisable : 1;
+ ULONG Accessed : 1;
+ ULONG Dirty : 1;
+ ULONG LargePage : 1;
+ ULONG Global : 1;
+ ULONG CopyOnWrite : 1;
+ ULONG Prototype : 1;
+ ULONG reserved : 1;
+ ULONG PageFrameNumber : 20;
+} HARDWARE_PTE_X86, *PHARDWARE_PTE_X86;
+
+typedef struct _WOW64_PROCESS
{
- KPROCESS Pcb;
- NTSTATUS ExitStatus;
- KEVENT LockEvent;
- ULONG LockCount;
- TIME CreateTime;
- TIME ExitTime;
- PVOID LockOwner;
- ULONG UniqueProcessId;
- LIST_ENTRY ActiveProcessLinks;
- ULONG QuotaPeakPoolUsage[2];
- ULONG QuotaPoolUsage[2];
- ULONG PagefileUsage;
- ULONG CommitCharge;
- ULONG PeakPagefileUsage;
- ULONG PeakVirtualUsage;
- LARGE_INTEGER VirtualSize;
- PVOID Vm; // Actually 48 bytes
- PVOID LastProtoPteFault;
- struct _EPORT* DebugPort;
- struct _EPORT* ExceptionPort;
- PVOID ObjectTable;
- PVOID Token;
- KMUTEX WorkingSetLock;
- PVOID WorkingSetPage;
- UCHAR ProcessOutswapEnabled;
- UCHAR ProcessOutswapped;
- UCHAR AddressSpaceInitialized;
- UCHAR AddressSpaceDeleted;
- KMUTEX AddressCreationLock;
- PVOID ForkInProgress;
- PVOID VmOperation;
- PKEVENT VmOperationEvent;
- PVOID PageDirectoryPte;
- LARGE_INTEGER LastFaultCount;
- PVOID VadRoot;
- PVOID VadHint;
- PVOID CloneRoot;
- ULONG NumberOfPrivatePages;
- ULONG NumberOfLockedPages;
- UCHAR ForkWasSuccessFul;
- UCHAR ExitProcessCalled;
- UCHAR CreateProcessReported;
- HANDLE SectionHandle;
- PPEB Peb;
- PVOID SectionBaseAddress;
- PVOID QuotaBlock;
- NTSTATUS LastThreadExitStatus;
- LARGE_INTEGER WorkingSetWatch; //
- ULONG InheritedFromUniqueProcessId;
- ACCESS_MASK GrantedAccess;
- ULONG DefaultHardErrorProcessing;
- PVOID LdtInformation;
- ULONG VadFreeHint;
- PVOID VdmObjects;
- KMUTANT ProcessMutant;
- CHAR ImageFileName[16];
- LARGE_INTEGER VmTrimFaultValue;
- struct _WIN32PROCESSDATA *Win32Process;
-
- /*
- * Added by David Welch (welch@mcmail.com)
- */
- MADDRESS_SPACE AddressSpace;
- HANDLE_TABLE HandleTable;
- LIST_ENTRY ProcessListEntry;
-
- /*
- * Added by Philip Susi for list of threads in process
- */
- LIST_ENTRY ThreadListHead;
-} EPROCESS, *PEPROCESS;
+ PVOID Wow64;
+} WOW64_PROCESS, *PWOW64_PROCESS;
+
+#endif /* __USE_W32API */
+
+struct _EPROCESS
+{
+ /* Microkernel specific process state. */
+ KPROCESS Pcb; /* 000 */
+ /* Exit status of the process. */
+ NTSTATUS ExitStatus; /* 068 */
+ /* Unknown. */
+ KEVENT LockEvent; /* 06C */
+ /* Unknown. */
+ ULONG LockCount; /* 07C */
+
+ /* Time of process creation. */
+ LARGE_INTEGER CreateTime; /* 080 */
+
+ /* Time of process exit. */
+ LARGE_INTEGER ExitTime; /* 088 */
+ /* Unknown. */
+ PKTHREAD LockOwner; /* 090 */
+ /* Process id. */
+ HANDLE UniqueProcessId; /* 094 */
+ /* Unknown. */
+ LIST_ENTRY ActiveProcessLinks; /* 098 */
+ /* Unknown. */
+ ULONG QuotaPeakPoolUsage[2]; /* 0A0 */
+ /* Unknown. */
+ ULONG QuotaPoolUsage[2]; /* 0A8 */
+ /* Unknown. */
+ ULONG PagefileUsage; /* 0B0 */
+ /* Unknown. */
+ ULONG CommitCharge; /* 0B4 */
+ /* Unknown. */
+ ULONG PeakPagefileUsage; /* 0B8 */
+ /* Unknown. */
+ ULONG PeakVirtualSize; /* 0BC */
+ /* Unknown. */
+ LARGE_INTEGER VirtualSize; /* 0C0 */
+
+ MMSUPPORT Vm;
+ LIST_ENTRY SessionProcessLinks;
+ struct _EPORT *DebugPort;
+ struct _EPORT *ExceptionPort;
+ PHANDLE_TABLE ObjectTable;
+ PVOID Token;
+ FAST_MUTEX WorkingSetLock;
+ ULONG WorkingSetPage;
+ UCHAR ProcessOutswapEnabled;
+ UCHAR ProcessOutswapped;
+ UCHAR AddressSpaceInitialized;
+ UCHAR AddressSpaceDeleted;
+ FAST_MUTEX AddressCreationLock;
+ KSPIN_LOCK HyperSpaceLock;
+ PETHREAD ForkInProgress;
+ USHORT VmOperation;
+ UCHAR ForkWasSuccessful;
+ UCHAR MmAgressiveWsTrimMask;
+ PKEVENT VmOperationEvent;
+ PVOID PaeTop;
+ ULONG LastFaultCount;
+ ULONG ModifiedPageCount;
+ PVOID VadRoot;
+ PVOID VadHint;
+ PVOID CloneRoot;
+ ULONG NumberOfPrivatePages;
+ ULONG NumberOfLockedPages;
+ USHORT NextPageColor;
+ UCHAR ExitProcessCalled;
+ UCHAR CreateProcessReported;
+ HANDLE SectionHandle;
+ PPEB Peb;
+ PVOID SectionBaseAddress;
+ PEPROCESS_QUOTA_BLOCK QuotaBlock;
+ NTSTATUS LastThreadExitStatus;
+ PPAGEFAULT_HISTORY WorkingSetWatch;
+ HANDLE Win32WindowStation;
+ HANDLE InheritedFromUniqueProcessId;
+ ULONG GrantedAccess;
+ ULONG DefaultHardErrorProcessing;
+ PVOID LdtInformation;
+ PVOID VadFreeHint;
+ PVOID VdmObjects;
+ PVOID DeviceObjects;
+ ULONG SessionId;
+ LIST_ENTRY PhysicalVadList;
+ HARDWARE_PTE_X86 PageDirectoryPte;
+ ULONGLONG Filler;
+ ULONG PaePageDirectoryPage;
+ CHAR ImageFileName[16];
+ ULONG VmTrimFaultValue;
+ UCHAR SetTimerResolution;
+ UCHAR PriorityClass;
+ UCHAR SubSystemMinorVersion;
+ UCHAR SubSystemMajorVersion;
+ USHORT SubSystemVersion;
+ struct _W32PROCESS *Win32Process;
+ struct _EJOB *Job;
+ ULONG JobStatus;
+ LIST_ENTRY JobLinks;
+ PVOID LockedPagesList;
+ struct _EPORT *SecurityPort;
+ PWOW64_PROCESS Wow64;
+ LARGE_INTEGER ReadOperationCount;
+ LARGE_INTEGER WriteOperationCount;
+ LARGE_INTEGER OtherOperationCount;
+ LARGE_INTEGER ReadTransferCount;
+ LARGE_INTEGER WriteTransferCount;
+ LARGE_INTEGER OtherTransferCount;
+ ULONG CommitChargeLimit;
+ ULONG CommitChargePeak;
+ LIST_ENTRY ThreadListHead;
+ PRTL_BITMAP VadPhysicalPagesBitMap;
+ ULONG VadPhysicalPages;
+ KSPIN_LOCK AweLock;
+ ULONG Cookie;
+
+ /*
+ * FIXME - ReactOS specified - remove the following fields ASAP!!!
+ */
+ MADDRESS_SPACE AddressSpace;
+ LIST_ENTRY ProcessListEntry;
+ PVOID TebBlock;
+ PVOID TebLastAllocated;
+};
#define PROCESS_STATE_TERMINATED (1)
#define PROCESS_STATE_ACTIVE (2)
+VOID PiInitDefaultLocale(VOID);
VOID PiInitProcessManager(VOID);
VOID PiShutdownProcessManager(VOID);
VOID PsInitThreadManagment(VOID);
VOID PsInitProcessManagment(VOID);
VOID PsInitIdleThread(VOID);
-VOID PsDispatchThread(ULONG NewThreadStatus);
-VOID PsDispatchThreadNoLock(ULONG NewThreadStatus);
VOID PiTerminateProcessThreads(PEPROCESS Process, NTSTATUS ExitStatus);
+VOID PsTerminateCurrentThread(NTSTATUS ExitStatus);
VOID PsTerminateOtherThread(PETHREAD Thread, NTSTATUS ExitStatus);
VOID PsReleaseThread(PETHREAD Thread);
VOID PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext);
VOID PsBeginThreadWithContextInternal(VOID);
VOID PiKillMostProcesses(VOID);
NTSTATUS STDCALL PiTerminateProcess(PEPROCESS Process, NTSTATUS ExitStatus);
-ULONG PsUnfreezeThread(PETHREAD Thread, PNTSTATUS WaitStatus);
-ULONG PsFreezeThread(PETHREAD Thread, PNTSTATUS WaitStatus,
- UCHAR Alertable, ULONG WaitMode);
VOID PiInitApcManagement(VOID);
-VOID PiDeleteThread(PVOID ObjectBody);
-VOID PiCloseThread(PVOID ObjectBody, ULONG HandleCount);
+VOID STDCALL PiDeleteThread(PVOID ObjectBody);
VOID PsReapThreads(VOID);
-NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
- PETHREAD* ThreadPtr,
- PHANDLE ThreadHandle,
- ACCESS_MASK DesiredAccess,
- POBJECT_ATTRIBUTES ObjectAttributes);
-
-PACCESS_TOKEN PsReferenceEffectiveToken(PETHREAD Thread,
+VOID PsInitializeThreadReaper(VOID);
+VOID PsQueueThreadReap(PETHREAD Thread);
+NTSTATUS
+PsInitializeThread(PEPROCESS Process,
+ PETHREAD* ThreadPtr,
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ KPROCESSOR_MODE AccessMode,
+ BOOLEAN First);
+
+PACCESS_TOKEN STDCALL PsReferenceEffectiveToken(PETHREAD Thread,
PTOKEN_TYPE TokenType,
PUCHAR b,
PSECURITY_IMPERSONATION_LEVEL Level);
-NTSTATUS PsOpenTokenOfProcess(HANDLE ProcessHandle,
+NTSTATUS STDCALL PsOpenTokenOfProcess(HANDLE ProcessHandle,
PACCESS_TOKEN* Token);
-
-ULONG PsSuspendThread(PETHREAD Thread,
- PNTSTATUS WaitStatus,
- UCHAR Alertable,
- ULONG WaitMode);
-ULONG PsResumeThread(PETHREAD Thread,
- PNTSTATUS WaitStatus);
-
-
-#define THREAD_STATE_INVALID (0)
-#define THREAD_STATE_RUNNABLE (1)
+VOID
+STDCALL
+PspTerminateProcessThreads(PEPROCESS Process,
+ NTSTATUS ExitStatus);
+NTSTATUS PsSuspendThread(PETHREAD Thread, PULONG PreviousCount);
+NTSTATUS PsResumeThread(PETHREAD Thread, PULONG PreviousCount);
+NTSTATUS
+STDCALL
+PspAssignPrimaryToken(PEPROCESS Process,
+ HANDLE TokenHandle);
+VOID STDCALL PsExitSpecialApc(PKAPC Apc,
+ PKNORMAL_ROUTINE *NormalRoutine,
+ PVOID *NormalContext,
+ PVOID *SystemArgument1,
+ PVOID *SystemArgument2);
+
+#define THREAD_STATE_INITIALIZED (0)
+#define THREAD_STATE_READY (1)
#define THREAD_STATE_RUNNING (2)
#define THREAD_STATE_SUSPENDED (3)
#define THREAD_STATE_FROZEN (4)
#define THREAD_STATE_TERMINATED_1 (5)
#define THREAD_STATE_TERMINATED_2 (6)
-#define THREAD_STATE_MAX (7)
+#define THREAD_STATE_BLOCKED (7)
+#define THREAD_STATE_MAX (8)
/*
* Internal thread priorities, added by Phillip Susi
- * TODO: rebalence these to make use of all priorities... the ones above 16 can not all be used right now
+ * TODO: rebalence these to make use of all priorities... the ones above 16
+ * can not all be used right now
*/
-
#define PROCESS_PRIO_IDLE 3
#define PROCESS_PRIO_NORMAL 8
#define PROCESS_PRIO_HIGH 13
#define PROCESS_PRIO_RT 18
-/*
- * Functions the HAL must provide
- */
+
+VOID STDCALL PiDeleteProcess(PVOID ObjectBody);
VOID
-KeInitializeThread(PKPROCESS Process, PKTHREAD Thread);
-
-void HalInitFirstTask(PETHREAD thread);
-NTSTATUS HalInitTask(PETHREAD thread, PKSTART_ROUTINE fn, PVOID StartContext);
-void HalTaskSwitch(PKTHREAD thread);
-NTSTATUS HalInitTaskWithContext(PETHREAD Thread, PCONTEXT Context);
-NTSTATUS HalReleaseTask(PETHREAD Thread);
-VOID PiDeleteProcess(PVOID ObjectBody);
-VOID PsReapThreads(VOID);
+STDCALL
+PspReapRoutine(PVOID Context);
+
+VOID
+STDCALL
+PspExitThread(NTSTATUS ExitStatus);
+
+extern LIST_ENTRY PspReaperListHead;
+extern WORK_QUEUE_ITEM PspReaperWorkItem;
+extern BOOLEAN PspReaping;
+
+VOID
+STDCALL
+PspTerminateThreadByPointer(PETHREAD Thread,
+ NTSTATUS ExitStatus);
+
VOID PsUnfreezeOtherThread(PETHREAD Thread);
VOID PsFreezeOtherThread(PETHREAD Thread);
VOID PsFreezeProcessThreads(PEPROCESS Process);
VOID PsUnfreezeProcessThreads(PEPROCESS Process);
+ULONG PsEnumThreadsByProcess(PEPROCESS Process);
PEPROCESS PsGetNextProcess(PEPROCESS OldProcess);
+VOID
+PsApplicationProcessorInit(VOID);
+VOID
+PsPrepareForApplicationProcessorInit(ULONG Id);
+VOID STDCALL
+PsIdleThreadMain(PVOID Context);
+
+VOID STDCALL
+PiSuspendThreadRundownRoutine(PKAPC Apc);
+VOID STDCALL
+PiSuspendThreadKernelRoutine(PKAPC Apc,
+ PKNORMAL_ROUTINE* NormalRoutine,
+ PVOID* NormalContext,
+ PVOID* SystemArgument1,
+ PVOID* SystemArguemnt2);
+VOID STDCALL
+PiSuspendThreadNormalRoutine(PVOID NormalContext,
+ PVOID SystemArgument1,
+ PVOID SystemArgument2);
+VOID
+PsInitialiseSuspendImplementation(VOID);
+NTSTATUS
+STDCALL
+PspExitProcess(PEPROCESS Process);
+
+VOID
+STDCALL
+PspDeleteProcess(PVOID ObjectBody);
+
+VOID
+STDCALL
+PspDeleteThread(PVOID ObjectBody);
+
+extern LONG PiNrThreadsAwaitingReaping;
+
+NTSTATUS
+PsInitWin32Thread (PETHREAD Thread);
+
+VOID
+PsTerminateWin32Process (PEPROCESS Process);
+
+VOID
+PsTerminateWin32Thread (PETHREAD Thread);
+
+VOID
+PsInitialiseW32Call(VOID);
+
+VOID
+STDCALL
+PspRunCreateThreadNotifyRoutines(PETHREAD, BOOLEAN);
+
+VOID
+STDCALL
+PspRunCreateProcessNotifyRoutines(PEPROCESS, BOOLEAN);
+
+#include <pshpack1.h>
+typedef struct _PS_JOB_TOKEN_FILTER
+{
+ UINT CapturedSidCount;
+ PSID_AND_ATTRIBUTES CapturedSids;
+ UINT CapturedSidsLength;
+ UINT CapturedGroupCount;
+ PSID_AND_ATTRIBUTES CapturedGroups;
+ UINT CapturedGroupsLength;
+ UINT CapturedPrivilegeCount;
+ PLUID_AND_ATTRIBUTES CapturedPrivileges;
+ UINT CapturedPrivilegesLength;
+} PS_JOB_TOKEN_FILTER, *PPS_JOB_TOKEN_FILTER;
+#include <poppack.h>
+
+#include <pshpack1.h>
+typedef struct _EJOB
+{
+ KEVENT Event;
+ LIST_ENTRY JobLinks;
+ LIST_ENTRY ProcessListHead;
+ ERESOURCE JobLock;
+ LARGE_INTEGER TotalUserTime;
+ LARGE_INTEGER TotalKernelTime;
+ LARGE_INTEGER ThisPeriodTotalUserTime;
+ LARGE_INTEGER ThisPeriodTotalKernelTime;
+ UINT TotalPageFaultCount;
+ UINT TotalProcesses;
+ UINT ActiveProcesses;
+ UINT TotalTerminatedProcesses;
+ LARGE_INTEGER PerProcessUserTimeLimit;
+ LARGE_INTEGER PerJobUserTimeLimit;
+ UINT LimitFlags;
+ UINT MinimumWorkingSetSize;
+ UINT MaximumWorkingSetSize;
+ UINT ActiveProcessLimit;
+ UINT Affinity;
+ BYTE PriorityClass;
+ UINT UIRestrictionsClass;
+ UINT SecurityLimitFlags;
+ PVOID Token;
+ PPS_JOB_TOKEN_FILTER Filter;
+ UINT EndOfJobTimeAction;
+ PVOID CompletionPort;
+ PVOID CompletionKey;
+ UINT SessionId;
+ UINT SchedulingClass;
+ ULONGLONG ReadOperationCount;
+ ULONGLONG WriteOperationCount;
+ ULONGLONG OtherOperationCount;
+ ULONGLONG ReadTransferCount;
+ ULONGLONG WriteTransferCount;
+ ULONGLONG OtherTransferCount;
+ IO_COUNTERS IoInfo;
+ UINT ProcessMemoryLimit;
+ UINT JobMemoryLimit;
+ UINT PeakProcessMemoryUsed;
+ UINT PeakJobMemoryUsed;
+ UINT CurrentJobMemoryUsed;
+ FAST_MUTEX MemoryLimitsLock;
+} EJOB;
+#include <poppack.h>
+
+VOID INIT_FUNCTION PsInitJobManagment(VOID);
+
+/* CLIENT ID */
+
+NTSTATUS PsCreateCidHandle(PVOID Object, POBJECT_TYPE ObjectType, PHANDLE Handle);
+NTSTATUS PsDeleteCidHandle(HANDLE CidHandle, POBJECT_TYPE ObjectType);
+PHANDLE_TABLE_ENTRY PsLookupCidHandle(HANDLE CidHandle, POBJECT_TYPE ObjectType, PVOID *Object);
+VOID PsUnlockCidHandle(PHANDLE_TABLE_ENTRY CidEntry);
+NTSTATUS PsLockProcess(PEPROCESS Process, BOOLEAN Timeout);
+VOID PsUnlockProcess(PEPROCESS Process);
+
+#define ETHREAD_TO_KTHREAD(pEThread) (&(pEThread)->Tcb)
+#define KTHREAD_TO_ETHREAD(pKThread) (CONTAINING_RECORD((pKThread), ETHREAD, Tcb))
+#define EPROCESS_TO_KPROCESS(pEProcess) (&(pEProcess)->Pcb)
+#define KPROCESS_TO_EPROCESS(pKProcess) (CONTAINING_RECORD((pKProcess), EPROCESS, Pcb))
#endif /* ASSEMBLER */