Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2095 lines
43 KiB

  1. /*++ BUILD Version: 0009 // Increment this if a change has global effects
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ps.h
  5. Abstract:
  6. This module contains the process structure public data structures and
  7. procedure prototypes to be used within the NT system.
  8. Author:
  9. Mark Lucovsky 16-Feb-1989
  10. Revision History:
  11. --*/
  12. #ifndef _PS_
  13. #define _PS_
  14. //
  15. // Process Object
  16. //
  17. //
  18. // Process object body. A pointer to this structure is returned when a handle
  19. // to a process object is referenced. This structure contains a process control
  20. // block (PCB) which is the kernel's representation of a process.
  21. //
  22. #define MEMORY_PRIORITY_BACKGROUND 0
  23. #define MEMORY_PRIORITY_WASFOREGROUND 1
  24. #define MEMORY_PRIORITY_FOREGROUND 2
  25. typedef struct _MMSUPPORT_FLAGS {
  26. unsigned SessionSpace : 1;
  27. unsigned BeingTrimmed : 1;
  28. unsigned SessionLeader : 1;
  29. unsigned TrimHard : 1;
  30. unsigned WorkingSetHard : 1;
  31. unsigned AddressSpaceBeingDeleted : 1;
  32. unsigned Available : 10;
  33. unsigned AllowWorkingSetAdjustment : 8;
  34. unsigned MemoryPriority : 8;
  35. } MMSUPPORT_FLAGS;
  36. typedef ULONG WSLE_NUMBER, *PWSLE_NUMBER;
  37. typedef struct _MMSUPPORT {
  38. LARGE_INTEGER LastTrimTime;
  39. MMSUPPORT_FLAGS Flags;
  40. ULONG PageFaultCount;
  41. WSLE_NUMBER PeakWorkingSetSize;
  42. WSLE_NUMBER WorkingSetSize;
  43. WSLE_NUMBER MinimumWorkingSetSize;
  44. WSLE_NUMBER MaximumWorkingSetSize;
  45. struct _MMWSL *VmWorkingSetList;
  46. LIST_ENTRY WorkingSetExpansionLinks;
  47. WSLE_NUMBER Claim;
  48. WSLE_NUMBER NextEstimationSlot;
  49. WSLE_NUMBER NextAgingSlot;
  50. WSLE_NUMBER EstimatedAvailable;
  51. WSLE_NUMBER GrowthSinceLastEstimate;
  52. } MMSUPPORT;
  53. typedef MMSUPPORT *PMMSUPPORT;
  54. //
  55. // Client impersonation information.
  56. //
  57. typedef struct _PS_IMPERSONATION_INFORMATION {
  58. PACCESS_TOKEN Token;
  59. BOOLEAN CopyOnOpen;
  60. BOOLEAN EffectiveOnly;
  61. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  62. } PS_IMPERSONATION_INFORMATION, *PPS_IMPERSONATION_INFORMATION;
  63. //
  64. // Audit Information structure: this is a member of the EPROCESS structure
  65. // and currently contains only the name of the exec'ed image file.
  66. //
  67. typedef struct _SE_AUDIT_PROCESS_CREATION_INFO {
  68. POBJECT_NAME_INFORMATION ImageFileName;
  69. } SE_AUDIT_PROCESS_CREATION_INFO, *PSE_AUDIT_PROCESS_CREATION_INFO;
  70. typedef enum _PS_QUOTA_TYPE {
  71. PsNonPagedPool = 0,
  72. PsPagedPool = 1,
  73. PsPageFile = 2,
  74. PsQuotaTypes = 3
  75. } PS_QUOTA_TYPE, *PPS_QUOTA_TYPE;
  76. typedef struct _EPROCESS_QUOTA_ENTRY {
  77. SIZE_T Usage; // Current usage count
  78. SIZE_T Limit; // Unhidered progress may be made to this point
  79. SIZE_T Peak; // Peak quota usage
  80. SIZE_T Return; // Quota value to return to the pool once its big enough
  81. } EPROCESS_QUOTA_ENTRY, *PEPROCESS_QUOTA_ENTRY;
  82. //#define PS_TRACK_QUOTA 1
  83. #define EPROCESS_QUOTA_TRACK_MAX 10000
  84. typedef struct _EPROCESS_QUOTA_TRACK {
  85. SIZE_T Charge;
  86. PVOID Caller;
  87. PVOID FreeCaller;
  88. PVOID Process;
  89. } EPROCESS_QUOTA_TRACK, *PEPROCESS_QUOTA_TRACK;
  90. typedef struct _EPROCESS_QUOTA_BLOCK {
  91. EPROCESS_QUOTA_ENTRY QuotaEntry[PsQuotaTypes];
  92. LIST_ENTRY QuotaList; // All additional quota blocks are chained through here
  93. ULONG ReferenceCount;
  94. ULONG ProcessCount; // Total number of processes still referencing this block
  95. #if defined (PS_TRACK_QUOTA)
  96. EPROCESS_QUOTA_TRACK Tracker[2][EPROCESS_QUOTA_TRACK_MAX];
  97. #endif
  98. } EPROCESS_QUOTA_BLOCK, *PEPROCESS_QUOTA_BLOCK;
  99. //
  100. // Pagefault monitoring.
  101. //
  102. typedef struct _PAGEFAULT_HISTORY {
  103. ULONG CurrentIndex;
  104. ULONG MaxIndex;
  105. KSPIN_LOCK SpinLock;
  106. PVOID Reserved;
  107. PROCESS_WS_WATCH_INFORMATION WatchInfo[1];
  108. } PAGEFAULT_HISTORY, *PPAGEFAULT_HISTORY;
  109. #define PS_WS_TRIM_FROM_EXE_HEADER 1
  110. #define PS_WS_TRIM_BACKGROUND_ONLY_APP 2
  111. //
  112. // Wow64 process stucture.
  113. //
  114. typedef struct _WOW64_PROCESS {
  115. PVOID Wow64;
  116. #if defined(_IA64_)
  117. FAST_MUTEX AlternateTableLock;
  118. PULONG AltPermBitmap;
  119. UCHAR AlternateTableAcquiredUnsafe;
  120. #endif
  121. } WOW64_PROCESS, *PWOW64_PROCESS;
  122. #if defined (_WIN64)
  123. #define PS_GET_WOW64_PROCESS(Process) ((Process)->Wow64Process)
  124. #else
  125. #define PS_GET_WOW64_PROCESS(Process) ((Process), ((PWOW64_PROCESS)NULL))
  126. #endif
  127. #define PS_SET_BITS(Flags, Flag) \
  128. RtlInterlockedSetBitsDiscardReturn (Flags, Flag)
  129. #define PS_TEST_SET_BITS(Flags, Flag) \
  130. RtlInterlockedSetBits (Flags, Flag)
  131. #define PS_CLEAR_BITS(Flags, Flag) \
  132. RtlInterlockedClearBitsDiscardReturn (Flags, Flag)
  133. #define PS_TEST_CLEAR_BITS(Flags, Flag) \
  134. RtlInterlockedClearBits (Flags, Flag)
  135. #define PS_SET_CLEAR_BITS(Flags, sFlag, cFlag) \
  136. RtlInterlockedSetClearBits (Flags, sFlag, cFlag)
  137. #define PS_TEST_ALL_BITS_SET(Flags, Bits) \
  138. ((Flags&(Bits)) == (Bits))
  139. // Process structure.
  140. //
  141. // If you remove a field from this structure, please also
  142. // remove the reference to it from within the kernel debugger
  143. // (nt\private\sdktools\ntsd\ntkext.c)
  144. //
  145. typedef struct _EPROCESS {
  146. KPROCESS Pcb;
  147. //
  148. // Lock used to protect:
  149. // The list of threads in the process.
  150. // Process token.
  151. // Win32 process field.
  152. // Process and thread affinity setting.
  153. //
  154. EX_PUSH_LOCK ProcessLock;
  155. LARGE_INTEGER CreateTime;
  156. LARGE_INTEGER ExitTime;
  157. //
  158. // Structure to allow lock free cross process access to the process
  159. // handle table, process section and address space. Acquire rundown
  160. // protection with this if you do cross process handle table, process
  161. // section or address space references.
  162. //
  163. EX_RUNDOWN_REF RundownProtect;
  164. HANDLE UniqueProcessId;
  165. //
  166. // Global list of all processes in the system. Processes are removed
  167. // from this list in the object deletion routine. References to
  168. // processes in this list must be done with ObReferenceObjectSafe
  169. // because of this.
  170. //
  171. LIST_ENTRY ActiveProcessLinks;
  172. //
  173. // Quota Fields.
  174. //
  175. SIZE_T QuotaUsage[PsQuotaTypes];
  176. SIZE_T QuotaPeak[PsQuotaTypes];
  177. SIZE_T CommitCharge;
  178. //
  179. // VmCounters.
  180. //
  181. SIZE_T PeakVirtualSize;
  182. SIZE_T VirtualSize;
  183. LIST_ENTRY SessionProcessLinks;
  184. PVOID DebugPort;
  185. PVOID ExceptionPort;
  186. PHANDLE_TABLE ObjectTable;
  187. //
  188. // Security.
  189. //
  190. EX_FAST_REF Token;
  191. FAST_MUTEX WorkingSetLock;
  192. PFN_NUMBER WorkingSetPage;
  193. FAST_MUTEX AddressCreationLock;
  194. KSPIN_LOCK HyperSpaceLock;
  195. struct _ETHREAD *ForkInProgress;
  196. ULONG_PTR HardwareTrigger;
  197. PVOID VadRoot;
  198. PVOID VadHint;
  199. PVOID CloneRoot;
  200. PFN_NUMBER NumberOfPrivatePages;
  201. PFN_NUMBER NumberOfLockedPages;
  202. PVOID Win32Process;
  203. struct _EJOB *Job;
  204. PVOID SectionObject;
  205. PVOID SectionBaseAddress;
  206. PEPROCESS_QUOTA_BLOCK QuotaBlock;
  207. PPAGEFAULT_HISTORY WorkingSetWatch;
  208. HANDLE Win32WindowStation;
  209. HANDLE InheritedFromUniqueProcessId;
  210. PVOID LdtInformation;
  211. PVOID VadFreeHint;
  212. PVOID VdmObjects;
  213. PVOID DeviceMap;
  214. LIST_ENTRY PhysicalVadList;
  215. union {
  216. HARDWARE_PTE PageDirectoryPte;
  217. ULONGLONG Filler;
  218. };
  219. PVOID Session;
  220. UCHAR ImageFileName[ 16 ];
  221. LIST_ENTRY JobLinks;
  222. PVOID LockedPagesList;
  223. LIST_ENTRY ThreadListHead;
  224. //
  225. // Used by rdr/security for authentication.
  226. //
  227. PVOID SecurityPort;
  228. #ifdef _WIN64
  229. PWOW64_PROCESS Wow64Process;
  230. #else
  231. PVOID PaeTop;
  232. #endif
  233. ULONG ActiveThreads;
  234. ACCESS_MASK GrantedAccess;
  235. ULONG DefaultHardErrorProcessing;
  236. NTSTATUS LastThreadExitStatus;
  237. //
  238. // Peb
  239. //
  240. PPEB Peb;
  241. //
  242. // Pointer to the prefetches trace block.
  243. //
  244. EX_FAST_REF PrefetchTrace;
  245. LARGE_INTEGER ReadOperationCount;
  246. LARGE_INTEGER WriteOperationCount;
  247. LARGE_INTEGER OtherOperationCount;
  248. LARGE_INTEGER ReadTransferCount;
  249. LARGE_INTEGER WriteTransferCount;
  250. LARGE_INTEGER OtherTransferCount;
  251. SIZE_T CommitChargeLimit;
  252. SIZE_T CommitChargePeak;
  253. PVOID AweInfo;
  254. //
  255. // This is used for SeAuditProcessCreation.
  256. // It contains the full path to the image file.
  257. //
  258. SE_AUDIT_PROCESS_CREATION_INFO SeAuditProcessCreationInfo;
  259. MMSUPPORT Vm;
  260. ULONG LastFaultCount;
  261. ULONG ModifiedPageCount;
  262. ULONG NumberOfVads;
  263. #define PS_JOB_STATUS_NOT_REALLY_ACTIVE 0x00000001UL
  264. #define PS_JOB_STATUS_ACCOUNTING_FOLDED 0x00000002UL
  265. #define PS_JOB_STATUS_NEW_PROCESS_REPORTED 0x00000004UL
  266. #define PS_JOB_STATUS_EXIT_PROCESS_REPORTED 0x00000008UL
  267. #define PS_JOB_STATUS_REPORT_COMMIT_CHANGES 0x00000010UL
  268. #define PS_JOB_STATUS_LAST_REPORT_MEMORY 0x00000020UL
  269. ULONG JobStatus;
  270. //
  271. // Process flags. Use interlocked operations with PS_SET_BITS, etc
  272. // to modify these.
  273. //
  274. #define PS_PROCESS_FLAGS_CREATE_REPORTED 0x00000001UL // Create process debug call has occurred
  275. #define PS_PROCESS_FLAGS_NO_DEBUG_INHERIT 0x00000002UL // Don't inherit debug port
  276. #define PS_PROCESS_FLAGS_PROCESS_EXITING 0x00000004UL // PspExitProcess entered
  277. #define PS_PROCESS_FLAGS_PROCESS_DELETE 0x00000008UL // Delete process has been issued
  278. #define PS_PROCESS_FLAGS_WOW64_SPLIT_PAGES 0x00000010UL // Wow64 split pages
  279. #define PS_PROCESS_FLAGS_VM_DELETED 0x00000020UL // VM is deleted
  280. #define PS_PROCESS_FLAGS_OUTSWAP_ENABLED 0x00000040UL // Outswap enabled
  281. #define PS_PROCESS_FLAGS_OUTSWAPPED 0x00000080UL // Outswapped
  282. #define PS_PROCESS_FLAGS_FORK_FAILED 0x00000100UL // Fork status
  283. #define PS_PROCESS_FLAGS_HAS_PHYSICAL_VAD 0x00000200UL // Has physical VAD
  284. #define PS_PROCESS_FLAGS_ADDRESS_SPACE1 0x00000400UL // Addr space state1
  285. #define PS_PROCESS_FLAGS_ADDRESS_SPACE2 0x00000800UL // Addr space state2
  286. #define PS_PROCESS_FLAGS_SET_TIMER_RESOLUTION 0x00001000UL // SetTimerResolution has been called
  287. #define PS_PROCESS_FLAGS_BREAK_ON_TERMINATION 0x00002000UL // Break on process termination
  288. #define PS_PROCESS_FLAGS_CREATING_SESSION 0x00004000UL // Process is creating a session
  289. #define PS_PROCESS_FLAGS_USING_WRITE_WATCH 0x00008000UL // Process is using the write watch APIs
  290. #define PS_PROCESS_FLAGS_IN_SESSION 0x00010000UL // Process is in a session
  291. #define PS_PROCESS_FLAGS_OVERRIDE_ADDRESS_SPACE 0x00020000UL // Process must use native address space (Win64 only)
  292. #define PS_PROCESS_FLAGS_HAS_ADDRESS_SPACE 0x00040000UL // This process has an address space
  293. #define PS_PROCESS_FLAGS_LAUNCH_PREFETCHED 0x00080000UL // Process launch was prefetched
  294. #define PS_PROCESS_INJECT_INPAGE_ERRORS 0x00100000UL // Process should be given inpage errors - hardcoded in trap.asm too
  295. union {
  296. ULONG Flags;
  297. //
  298. // Fields can only be set by the PS_SET_BITS and other interlocked
  299. // macros. Reading fields is best done via the bit definitions so
  300. // references are easy to locate.
  301. //
  302. struct {
  303. ULONG CreateReported : 1;
  304. ULONG NoDebugInherit : 1;
  305. ULONG ProcessExiting : 1;
  306. ULONG ProcessDelete : 1;
  307. ULONG Wow64SplitPages : 1;
  308. ULONG VmDeleted : 1;
  309. ULONG OutswapEnabled : 1;
  310. ULONG Outswapped : 1;
  311. ULONG ForkFailed : 1;
  312. ULONG HasPhysicalVad : 1;
  313. ULONG AddressSpaceInitialized : 2;
  314. ULONG SetTimerResolution : 1;
  315. ULONG BreakOnTermination : 1;
  316. ULONG SessionCreationUnderway : 1;
  317. ULONG WriteWatch : 1;
  318. ULONG ProcessInSession : 1;
  319. ULONG OverrideAddressSpace : 1;
  320. ULONG HasAddressSpace : 1;
  321. ULONG LaunchPrefetched : 1;
  322. ULONG InjectInpageErrors : 1;
  323. ULONG Unused :11;
  324. };
  325. };
  326. NTSTATUS ExitStatus;
  327. USHORT NextPageColor;
  328. union {
  329. struct {
  330. UCHAR SubSystemMinorVersion;
  331. UCHAR SubSystemMajorVersion;
  332. };
  333. USHORT SubSystemVersion;
  334. };
  335. UCHAR PriorityClass;
  336. UCHAR WorkingSetAcquiredUnsafe;
  337. } EPROCESS;
  338. typedef EPROCESS *PEPROCESS;
  339. //
  340. // Thread termination port
  341. //
  342. typedef struct _TERMINATION_PORT {
  343. struct _TERMINATION_PORT *Next;
  344. PVOID Port;
  345. } TERMINATION_PORT, *PTERMINATION_PORT;
  346. // Thread Object
  347. //
  348. // Thread object body. A pointer to this structure is returned when a handle
  349. // to a thread object is referenced. This structure contains a thread control
  350. // block (TCB) which is the kernel's representation of a thread.
  351. //
  352. //
  353. // The upper 4 bits of the CreateTime should be zero on initialization so
  354. // that the shift doesn't destroy anything.
  355. //
  356. #define PS_GET_THREAD_CREATE_TIME(Thread) ((Thread)->CreateTime.QuadPart >> 3)
  357. #define PS_SET_THREAD_CREATE_TIME(Thread, InputCreateTime) \
  358. ((Thread)->CreateTime.QuadPart = (InputCreateTime.QuadPart << 3))
  359. //
  360. // Macro to return TRUE if the specified thread is impersonating.
  361. //
  362. #define PS_IS_THREAD_IMPERSONATING(Thread) (((Thread)->CrossThreadFlags&PS_CROSS_THREAD_FLAGS_IMPERSONATING) != 0)
  363. typedef struct _ETHREAD {
  364. KTHREAD Tcb;
  365. union {
  366. //
  367. // The fact that this is a union means that all accesses to CreateTime
  368. // must be sanitized using the two macros above.
  369. //
  370. LARGE_INTEGER CreateTime;
  371. //
  372. // These fields are accessed only by the owning thread, but can be
  373. // accessed from within a special kernel APC so IRQL protection must
  374. // be applied.
  375. //
  376. struct {
  377. unsigned NestedFaultCount : 2;
  378. unsigned ApcNeeded : 1;
  379. };
  380. };
  381. union {
  382. LARGE_INTEGER ExitTime;
  383. LIST_ENTRY LpcReplyChain;
  384. LIST_ENTRY KeyedWaitChain;
  385. };
  386. union {
  387. NTSTATUS ExitStatus;
  388. PVOID OfsChain;
  389. };
  390. //
  391. // Registry
  392. //
  393. LIST_ENTRY PostBlockList;
  394. //
  395. // Single linked list of termination blocks
  396. //
  397. union {
  398. //
  399. // List of termination ports
  400. //
  401. PTERMINATION_PORT TerminationPort;
  402. //
  403. // List of threads to be reaped. Only used at thread exit
  404. //
  405. struct _ETHREAD *ReaperLink;
  406. //
  407. // Keyvalue being waited for
  408. //
  409. PVOID KeyedWaitValue;
  410. };
  411. KSPIN_LOCK ActiveTimerListLock;
  412. LIST_ENTRY ActiveTimerListHead;
  413. CLIENT_ID Cid;
  414. //
  415. // Lpc
  416. //
  417. union {
  418. KSEMAPHORE LpcReplySemaphore;
  419. KSEMAPHORE KeyedWaitSemaphore;
  420. };
  421. union {
  422. PVOID LpcReplyMessage; // -> Message that contains the reply
  423. PVOID LpcWaitingOnPort;
  424. };
  425. //
  426. // Security
  427. //
  428. //
  429. // Client - If non null, indicates the thread is impersonating
  430. // a client.
  431. //
  432. PPS_IMPERSONATION_INFORMATION ImpersonationInfo;
  433. //
  434. // Io
  435. //
  436. LIST_ENTRY IrpList;
  437. //
  438. // File Systems
  439. //
  440. ULONG_PTR TopLevelIrp; // either NULL, an Irp or a flag defined in FsRtl.h
  441. struct _DEVICE_OBJECT *DeviceToVerify;
  442. PEPROCESS ThreadsProcess;
  443. PVOID StartAddress;
  444. union {
  445. PVOID Win32StartAddress;
  446. ULONG LpcReceivedMessageId;
  447. };
  448. //
  449. // Ps
  450. //
  451. LIST_ENTRY ThreadListEntry;
  452. //
  453. // Rundown protection structure. Acquire this to do cross thread
  454. // TEB, TEB32 or stack references.
  455. //
  456. EX_RUNDOWN_REF RundownProtect;
  457. //
  458. // Lock to protect thread impersonation information
  459. //
  460. EX_PUSH_LOCK ThreadLock;
  461. ULONG LpcReplyMessageId; // MessageId this thread is waiting for reply to
  462. ULONG ReadClusterSize;
  463. //
  464. // Client/server
  465. //
  466. ACCESS_MASK GrantedAccess;
  467. //
  468. // Flags for cross thread access. Use interlocked operations
  469. // via PS_SET_BITS etc.
  470. //
  471. //
  472. // Used to signify that the delete APC has been queued or the
  473. // thread has called PspExitThread itself.
  474. //
  475. #define PS_CROSS_THREAD_FLAGS_TERMINATED 0x00000001UL
  476. //
  477. // Thread create failed
  478. //
  479. #define PS_CROSS_THREAD_FLAGS_DEADTHREAD 0x00000002UL
  480. //
  481. // Debugger isn't shown this thread
  482. //
  483. #define PS_CROSS_THREAD_FLAGS_HIDEFROMDBG 0x00000004UL
  484. //
  485. // Thread is impersonating
  486. //
  487. #define PS_CROSS_THREAD_FLAGS_IMPERSONATING 0x00000008UL
  488. //
  489. // This is a system thread
  490. //
  491. #define PS_CROSS_THREAD_FLAGS_SYSTEM 0x00000010UL
  492. //
  493. // Hard errors are disabled for this thread
  494. //
  495. #define PS_CROSS_THREAD_FLAGS_HARD_ERRORS_DISABLED 0x00000020UL
  496. //
  497. // We should break in when this thread is terminated
  498. //
  499. #define PS_CROSS_THREAD_FLAGS_BREAK_ON_TERMINATION 0x00000040UL
  500. //
  501. // This thread should skip sending its create thread message
  502. //
  503. #define PS_CROSS_THREAD_FLAGS_SKIP_CREATION_MSG 0x00000080UL
  504. //
  505. // This thread should skip sending its final thread termination message
  506. //
  507. #define PS_CROSS_THREAD_FLAGS_SKIP_TERMINATION_MSG 0x00000100UL
  508. union {
  509. ULONG CrossThreadFlags;
  510. //
  511. // The following fields are for the debugger only. Do not use.
  512. // Use the bit definitions instead.
  513. //
  514. struct {
  515. ULONG Terminated : 1;
  516. ULONG DeadThread : 1;
  517. ULONG HideFromDebugger : 1;
  518. ULONG ActiveImpersonationInfo : 1;
  519. ULONG SystemThread : 1;
  520. ULONG HardErrorsAreDisabled : 1;
  521. ULONG BreakOnTermination : 1;
  522. ULONG SkipCreationMsg : 1;
  523. ULONG SkipTerminationMsg : 1;
  524. };
  525. };
  526. //
  527. // Flags to be accessed in this thread's context only at PASSIVE
  528. // level -- no need to use interlocked operations.
  529. //
  530. union {
  531. ULONG SameThreadPassiveFlags;
  532. struct {
  533. //
  534. // This thread is an active Ex worker thread; it should
  535. // not terminate.
  536. //
  537. ULONG ActiveExWorker : 1;
  538. ULONG ExWorkerCanWaitUser : 1;
  539. ULONG MemoryMaker : 1;
  540. };
  541. };
  542. //
  543. // Flags to be accessed in this thread's context only at APC_LEVEL.
  544. // No need to use interlocked operations.
  545. //
  546. union {
  547. ULONG SameThreadApcFlags;
  548. struct {
  549. //
  550. // The stored thread's MSGID is valid. This is only accessed
  551. // while the LPC mutex is held so it's an APC_LEVEL flag.
  552. //
  553. BOOLEAN LpcReceivedMsgIdValid : 1;
  554. BOOLEAN LpcExitThreadCalled : 1;
  555. BOOLEAN AddressSpaceOwner : 1;
  556. };
  557. };
  558. BOOLEAN ForwardClusterOnly;
  559. BOOLEAN DisablePageFaultClustering;
  560. #if defined (PERF_DATA)
  561. ULONG PerformanceCountLow;
  562. LONG PerformanceCountHigh;
  563. #endif
  564. } ETHREAD;
  565. typedef ETHREAD *PETHREAD;
  566. //
  567. // The following two inline functions allow a thread or process object to
  568. // be converted into a kernel thread or process, respectively, without
  569. // having to expose the ETHREAD and EPROCESS definitions to the world.
  570. //
  571. // These functions take advantage of the fact that the kernel structures
  572. // appear as the first element in the respective object structures.
  573. //
  574. // The C_ASSERTs that follow ensure that this is the case.
  575. //
  576. // begin_ntosp
  577. PKTHREAD
  578. FORCEINLINE
  579. PsGetKernelThread(
  580. IN PETHREAD ThreadObject
  581. )
  582. {
  583. return (PKTHREAD)ThreadObject;
  584. }
  585. PKPROCESS
  586. FORCEINLINE
  587. PsGetKernelProcess(
  588. IN PEPROCESS ProcessObject
  589. )
  590. {
  591. return (PKPROCESS)ProcessObject;
  592. }
  593. NTSTATUS
  594. PsGetContextThread(
  595. IN PETHREAD Thread,
  596. IN OUT PCONTEXT ThreadContext,
  597. IN KPROCESSOR_MODE Mode
  598. );
  599. NTSTATUS
  600. PsSetContextThread(
  601. IN PETHREAD Thread,
  602. IN PCONTEXT ThreadContext,
  603. IN KPROCESSOR_MODE Mode
  604. );
  605. // end_ntosp
  606. C_ASSERT( FIELD_OFFSET(ETHREAD,Tcb) == 0 );
  607. C_ASSERT( FIELD_OFFSET(EPROCESS,Pcb) == 0 );
  608. //
  609. // Initial PEB
  610. //
  611. typedef struct _INITIAL_PEB {
  612. BOOLEAN InheritedAddressSpace; // These four fields cannot change unless the
  613. BOOLEAN ReadImageFileExecOptions; //
  614. BOOLEAN BeingDebugged; //
  615. BOOLEAN SpareBool; //
  616. HANDLE Mutant; // PEB structure is also updated.
  617. } INITIAL_PEB, *PINITIAL_PEB;
  618. typedef struct _PS_JOB_TOKEN_FILTER {
  619. ULONG CapturedSidCount ;
  620. PSID_AND_ATTRIBUTES CapturedSids ;
  621. ULONG CapturedSidsLength ;
  622. ULONG CapturedGroupCount ;
  623. PSID_AND_ATTRIBUTES CapturedGroups ;
  624. ULONG CapturedGroupsLength ;
  625. ULONG CapturedPrivilegeCount ;
  626. PLUID_AND_ATTRIBUTES CapturedPrivileges ;
  627. ULONG CapturedPrivilegesLength ;
  628. } PS_JOB_TOKEN_FILTER, * PPS_JOB_TOKEN_FILTER ;
  629. //
  630. // Job Object
  631. //
  632. typedef struct _EJOB {
  633. KEVENT Event;
  634. //
  635. // All jobs are chained together via this list.
  636. // Protected by the global lock PspJobListLock
  637. //
  638. LIST_ENTRY JobLinks;
  639. //
  640. // All processes within this job. Processes are removed from this
  641. // list at last dereference. Safe object referencing needs to be done.
  642. // Protected by the joblock.
  643. //
  644. LIST_ENTRY ProcessListHead;
  645. ERESOURCE JobLock;
  646. //
  647. // Accounting Info
  648. //
  649. LARGE_INTEGER TotalUserTime;
  650. LARGE_INTEGER TotalKernelTime;
  651. LARGE_INTEGER ThisPeriodTotalUserTime;
  652. LARGE_INTEGER ThisPeriodTotalKernelTime;
  653. ULONG TotalPageFaultCount;
  654. ULONG TotalProcesses;
  655. ULONG ActiveProcesses;
  656. ULONG TotalTerminatedProcesses;
  657. //
  658. // Limitable Attributes
  659. //
  660. LARGE_INTEGER PerProcessUserTimeLimit;
  661. LARGE_INTEGER PerJobUserTimeLimit;
  662. ULONG LimitFlags;
  663. SIZE_T MinimumWorkingSetSize;
  664. SIZE_T MaximumWorkingSetSize;
  665. ULONG ActiveProcessLimit;
  666. KAFFINITY Affinity;
  667. UCHAR PriorityClass;
  668. //
  669. // UI restrictions
  670. //
  671. ULONG UIRestrictionsClass;
  672. //
  673. // Security Limitations: write once, read always
  674. //
  675. ULONG SecurityLimitFlags;
  676. PACCESS_TOKEN Token;
  677. PPS_JOB_TOKEN_FILTER Filter;
  678. //
  679. // End Of Job Time Limit
  680. //
  681. ULONG EndOfJobTimeAction;
  682. PVOID CompletionPort;
  683. PVOID CompletionKey;
  684. ULONG SessionId;
  685. ULONG SchedulingClass;
  686. ULONGLONG ReadOperationCount;
  687. ULONGLONG WriteOperationCount;
  688. ULONGLONG OtherOperationCount;
  689. ULONGLONG ReadTransferCount;
  690. ULONGLONG WriteTransferCount;
  691. ULONGLONG OtherTransferCount;
  692. //
  693. // Extended Limits
  694. //
  695. IO_COUNTERS IoInfo; // not used yet
  696. SIZE_T ProcessMemoryLimit;
  697. SIZE_T JobMemoryLimit;
  698. SIZE_T PeakProcessMemoryUsed;
  699. SIZE_T PeakJobMemoryUsed;
  700. SIZE_T CurrentJobMemoryUsed;
  701. FAST_MUTEX MemoryLimitsLock;
  702. //
  703. // List of jobs in a job set. Processes within a job in a job set
  704. // can create processes in the same or higher members of the jobset.
  705. // Protected by the global lock PspJobListLock
  706. //
  707. LIST_ENTRY JobSetLinks;
  708. //
  709. // Member level for this job in the jobset.
  710. //
  711. ULONG MemberLevel;
  712. //
  713. // This job has had its last handle closed.
  714. //
  715. #define PS_JOB_FLAGS_CLOSE_DONE 0x1UL
  716. ULONG JobFlags;
  717. } EJOB;
  718. typedef EJOB *PEJOB;
  719. //
  720. // Global Variables
  721. //
  722. extern ULONG PsPrioritySeperation;
  723. extern ULONG PsRawPrioritySeparation;
  724. extern LIST_ENTRY PsActiveProcessHead;
  725. extern const UNICODE_STRING PsNtDllPathName;
  726. extern PVOID PsSystemDllBase;
  727. extern FAST_MUTEX PsProcessSecurityLock;
  728. extern PEPROCESS PsInitialSystemProcess;
  729. extern PVOID PsNtosImageBase;
  730. extern PVOID PsHalImageBase;
  731. #if defined(_AMD64_) || defined(_IA64_)
  732. extern INVERTED_FUNCTION_TABLE PsInvertedFunctionTable;
  733. #endif
  734. extern LIST_ENTRY PsLoadedModuleList;
  735. extern ERESOURCE PsLoadedModuleResource;
  736. extern KSPIN_LOCK PsLoadedModuleSpinLock;
  737. extern LCID PsDefaultSystemLocaleId;
  738. extern LCID PsDefaultThreadLocaleId;
  739. extern LANGID PsDefaultUILanguageId;
  740. extern LANGID PsInstallUILanguageId;
  741. extern PEPROCESS PsIdleProcess;
  742. extern BOOLEAN PsReaperActive;
  743. extern PETHREAD PsReaperList;
  744. extern WORK_QUEUE_ITEM PsReaperWorkItem;
  745. #define PS_EMBEDDED_NO_USERMODE 1 // no user mode code will run on the system
  746. extern ULONG PsEmbeddedNTMask;
  747. BOOLEAN
  748. PsChangeJobMemoryUsage(
  749. SSIZE_T Amount
  750. );
  751. VOID
  752. PsReportProcessMemoryLimitViolation(
  753. VOID
  754. );
  755. #define THREAD_HIT_SLOTS 750
  756. extern ULONG PsThreadHits[THREAD_HIT_SLOTS];
  757. VOID
  758. PsThreadHit(
  759. IN PETHREAD Thread
  760. );
  761. VOID
  762. PsEnforceExecutionTimeLimits(
  763. VOID
  764. );
  765. BOOLEAN
  766. PsInitSystem (
  767. IN ULONG Phase,
  768. IN PLOADER_PARAMETER_BLOCK LoaderBlock
  769. );
  770. VOID
  771. PsInitializeQuotaSystem (
  772. VOID
  773. );
  774. LOGICAL
  775. PsShutdownSystem (
  776. VOID
  777. );
  778. BOOLEAN
  779. PsWaitForAllProcesses (
  780. VOID);
  781. NTSTATUS
  782. PsLocateSystemDll (
  783. VOID
  784. );
  785. VOID
  786. PsChangeQuantumTable(
  787. BOOLEAN ModifyActiveProcesses,
  788. ULONG PrioritySeparation
  789. );
  790. //
  791. // Get Gurrent Prototypes
  792. //
  793. #define THREAD_TO_PROCESS(Thread) ((Thread)->ThreadsProcess)
  794. #define IS_SYSTEM_THREAD(Thread) (((Thread)->CrossThreadFlags&PS_CROSS_THREAD_FLAGS_SYSTEM) != 0)
  795. #define _PsGetCurrentProcess() (CONTAINING_RECORD(((KeGetCurrentThread())->ApcState.Process),EPROCESS,Pcb))
  796. #define PsGetCurrentProcessByThread(xCurrentThread) (CONTAINING_RECORD(((xCurrentThread)->Tcb.ApcState.Process),EPROCESS,Pcb))
  797. #define _PsGetCurrentThread() (CONTAINING_RECORD((KeGetCurrentThread()),ETHREAD,Tcb))
  798. #if defined(_NTOSP_)
  799. // begin_ntosp
  800. NTKERNELAPI
  801. PEPROCESS
  802. PsGetCurrentProcess(
  803. VOID
  804. );
  805. NTKERNELAPI
  806. PETHREAD
  807. PsGetCurrentThread(
  808. VOID
  809. );
  810. // end_ntosp
  811. #else
  812. #define PsGetCurrentProcess() _PsGetCurrentProcess()
  813. #define PsGetCurrentThread() _PsGetCurrentThread()
  814. #endif
  815. //
  816. // Exit kernel mode APC routine.
  817. //
  818. VOID
  819. PsExitSpecialApc(
  820. IN PKAPC Apc,
  821. IN PKNORMAL_ROUTINE *NormalRoutine,
  822. IN PVOID *NormalContext,
  823. IN PVOID *SystemArgument1,
  824. IN PVOID *SystemArgument2
  825. );
  826. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntosp
  827. //
  828. // System Thread and Process Creation and Termination
  829. //
  830. NTKERNELAPI
  831. NTSTATUS
  832. PsCreateSystemThread(
  833. OUT PHANDLE ThreadHandle,
  834. IN ULONG DesiredAccess,
  835. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  836. IN HANDLE ProcessHandle OPTIONAL,
  837. OUT PCLIENT_ID ClientId OPTIONAL,
  838. IN PKSTART_ROUTINE StartRoutine,
  839. IN PVOID StartContext
  840. );
  841. NTKERNELAPI
  842. NTSTATUS
  843. PsTerminateSystemThread(
  844. IN NTSTATUS ExitStatus
  845. );
  846. // end_ntddk end_wdm end_nthal end_ntifs end_ntosp
  847. NTSTATUS
  848. PsCreateSystemProcess(
  849. OUT PHANDLE ProcessHandle,
  850. IN ULONG DesiredAccess,
  851. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL
  852. );
  853. typedef
  854. VOID (*PLEGO_NOTIFY_ROUTINE)(
  855. PKTHREAD Thread
  856. );
  857. ULONG
  858. PsSetLegoNotifyRoutine(
  859. PLEGO_NOTIFY_ROUTINE LegoNotifyRoutine
  860. );
  861. // begin_ntifs begin_ntddk
  862. typedef
  863. VOID
  864. (*PCREATE_PROCESS_NOTIFY_ROUTINE)(
  865. IN HANDLE ParentId,
  866. IN HANDLE ProcessId,
  867. IN BOOLEAN Create
  868. );
  869. NTSTATUS
  870. PsSetCreateProcessNotifyRoutine(
  871. IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
  872. IN BOOLEAN Remove
  873. );
  874. typedef
  875. VOID
  876. (*PCREATE_THREAD_NOTIFY_ROUTINE)(
  877. IN HANDLE ProcessId,
  878. IN HANDLE ThreadId,
  879. IN BOOLEAN Create
  880. );
  881. NTSTATUS
  882. PsSetCreateThreadNotifyRoutine(
  883. IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
  884. );
  885. NTSTATUS
  886. PsRemoveCreateThreadNotifyRoutine (
  887. IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
  888. );
  889. //
  890. // Structures for Load Image Notify
  891. //
  892. typedef struct _IMAGE_INFO {
  893. union {
  894. ULONG Properties;
  895. struct {
  896. ULONG ImageAddressingMode : 8; // code addressing mode
  897. ULONG SystemModeImage : 1; // system mode image
  898. ULONG ImageMappedToAllPids : 1; // image mapped into all processes
  899. ULONG Reserved : 22;
  900. };
  901. };
  902. PVOID ImageBase;
  903. ULONG ImageSelector;
  904. SIZE_T ImageSize;
  905. ULONG ImageSectionNumber;
  906. } IMAGE_INFO, *PIMAGE_INFO;
  907. #define IMAGE_ADDRESSING_MODE_32BIT 3
  908. typedef
  909. VOID
  910. (*PLOAD_IMAGE_NOTIFY_ROUTINE)(
  911. IN PUNICODE_STRING FullImageName,
  912. IN HANDLE ProcessId, // pid into which image is being mapped
  913. IN PIMAGE_INFO ImageInfo
  914. );
  915. NTSTATUS
  916. PsSetLoadImageNotifyRoutine(
  917. IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
  918. );
  919. NTSTATUS
  920. PsRemoveLoadImageNotifyRoutine(
  921. IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
  922. );
  923. // end_ntddk
  924. //
  925. // Security Support
  926. //
  927. NTSTATUS
  928. PsAssignImpersonationToken(
  929. IN PETHREAD Thread,
  930. IN HANDLE Token
  931. );
  932. // begin_ntosp
  933. NTKERNELAPI
  934. PACCESS_TOKEN
  935. PsReferencePrimaryToken(
  936. IN PEPROCESS Process
  937. );
  938. VOID
  939. PsDereferencePrimaryToken(
  940. IN PACCESS_TOKEN PrimaryToken
  941. );
  942. VOID
  943. PsDereferenceImpersonationToken(
  944. IN PACCESS_TOKEN ImpersonationToken
  945. );
  946. // end_ntifs
  947. // end_ntosp
  948. #define PsDereferencePrimaryTokenEx(P,T) (ObFastDereferenceObject (&P->Token,(T)))
  949. #define PsDereferencePrimaryToken(T) (ObDereferenceObject((T)))
  950. #define PsDereferenceImpersonationToken(T) \
  951. {if (ARGUMENT_PRESENT((T))) { \
  952. (ObDereferenceObject((T))); \
  953. } else { \
  954. ; \
  955. } \
  956. }
  957. #define PsProcessAuditId(Process) ((Process)->UniqueProcessId)
  958. // begin_ntosp
  959. // begin_ntifs
  960. NTKERNELAPI
  961. PACCESS_TOKEN
  962. PsReferenceImpersonationToken(
  963. IN PETHREAD Thread,
  964. OUT PBOOLEAN CopyOnOpen,
  965. OUT PBOOLEAN EffectiveOnly,
  966. OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  967. );
  968. // end_ntifs
  969. PACCESS_TOKEN
  970. PsReferenceEffectiveToken(
  971. IN PETHREAD Thread,
  972. OUT PTOKEN_TYPE TokenType,
  973. OUT PBOOLEAN EffectiveOnly,
  974. OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  975. );
  976. // begin_ntifs
  977. LARGE_INTEGER
  978. PsGetProcessExitTime(
  979. VOID
  980. );
  981. // end_ntifs
  982. // end_ntosp
  983. #if defined(_NTDDK_) || defined(_NTIFS_)
  984. // begin_ntifs begin_ntosp
  985. BOOLEAN
  986. PsIsThreadTerminating(
  987. IN PETHREAD Thread
  988. );
  989. // end_ntifs end_ntosp
  990. #else
  991. //
  992. // BOOLEAN
  993. // PsIsThreadTerminating(
  994. // IN PETHREAD Thread
  995. // )
  996. //
  997. // Returns TRUE if thread is in the process of terminating.
  998. //
  999. #define PsIsThreadTerminating(T) \
  1000. (((T)->CrossThreadFlags&PS_CROSS_THREAD_FLAGS_TERMINATED) != 0)
  1001. #endif
  1002. extern BOOLEAN PsImageNotifyEnabled;
  1003. VOID
  1004. PsCallImageNotifyRoutines(
  1005. IN PUNICODE_STRING FullImageName,
  1006. IN HANDLE ProcessId, // pid into which image is being mapped
  1007. IN PIMAGE_INFO ImageInfo
  1008. );
  1009. // begin_ntifs
  1010. // begin_ntosp
  1011. NTSTATUS
  1012. PsImpersonateClient(
  1013. IN PETHREAD Thread,
  1014. IN PACCESS_TOKEN Token,
  1015. IN BOOLEAN CopyOnOpen,
  1016. IN BOOLEAN EffectiveOnly,
  1017. IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  1018. );
  1019. // end_ntosp
  1020. BOOLEAN
  1021. PsDisableImpersonation(
  1022. IN PETHREAD Thread,
  1023. IN PSE_IMPERSONATION_STATE ImpersonationState
  1024. );
  1025. VOID
  1026. PsRestoreImpersonation(
  1027. IN PETHREAD Thread,
  1028. IN PSE_IMPERSONATION_STATE ImpersonationState
  1029. );
  1030. // end_ntifs
  1031. // begin_ntosp
  1032. NTKERNELAPI
  1033. VOID
  1034. PsRevertToSelf(
  1035. VOID
  1036. );
  1037. NTKERNELAPI
  1038. VOID
  1039. PsRevertThreadToSelf(
  1040. PETHREAD Thread
  1041. );
  1042. // end_ntosp
  1043. NTSTATUS
  1044. PsOpenTokenOfThread(
  1045. IN HANDLE ThreadHandle,
  1046. IN BOOLEAN OpenAsSelf,
  1047. OUT PACCESS_TOKEN *Token,
  1048. OUT PBOOLEAN CopyOnOpen,
  1049. OUT PBOOLEAN EffectiveOnly,
  1050. OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  1051. );
  1052. NTSTATUS
  1053. PsOpenTokenOfProcess(
  1054. IN HANDLE ProcessHandle,
  1055. OUT PACCESS_TOKEN *Token
  1056. );
  1057. NTSTATUS
  1058. PsOpenTokenOfJob(
  1059. IN HANDLE JobHandle,
  1060. OUT PACCESS_TOKEN * Token
  1061. );
  1062. //
  1063. // Cid
  1064. //
  1065. NTSTATUS
  1066. PsLookupProcessThreadByCid(
  1067. IN PCLIENT_ID Cid,
  1068. OUT PEPROCESS *Process OPTIONAL,
  1069. OUT PETHREAD *Thread
  1070. );
  1071. // begin_ntosp
  1072. NTKERNELAPI
  1073. NTSTATUS
  1074. PsLookupProcessByProcessId(
  1075. IN HANDLE ProcessId,
  1076. OUT PEPROCESS *Process
  1077. );
  1078. NTKERNELAPI
  1079. NTSTATUS
  1080. PsLookupThreadByThreadId(
  1081. IN HANDLE ThreadId,
  1082. OUT PETHREAD *Thread
  1083. );
  1084. // begin_ntifs
  1085. //
  1086. // Quota Operations
  1087. //
  1088. VOID
  1089. PsChargePoolQuota(
  1090. IN PEPROCESS Process,
  1091. IN POOL_TYPE PoolType,
  1092. IN ULONG_PTR Amount
  1093. );
  1094. NTSTATUS
  1095. PsChargeProcessPoolQuota(
  1096. IN PEPROCESS Process,
  1097. IN POOL_TYPE PoolType,
  1098. IN ULONG_PTR Amount
  1099. );
  1100. VOID
  1101. PsReturnPoolQuota(
  1102. IN PEPROCESS Process,
  1103. IN POOL_TYPE PoolType,
  1104. IN ULONG_PTR Amount
  1105. );
  1106. // end_ntifs
  1107. // end_ntosp
  1108. NTSTATUS
  1109. PsChargeProcessQuota (
  1110. IN PEPROCESS Process,
  1111. IN PS_QUOTA_TYPE QuotaType,
  1112. IN SIZE_T Amount
  1113. );
  1114. VOID
  1115. PsReturnProcessQuota (
  1116. IN PEPROCESS Process,
  1117. IN PS_QUOTA_TYPE QuotaType,
  1118. IN SIZE_T Amount
  1119. );
  1120. NTSTATUS
  1121. PsChargeProcessNonPagedPoolQuota(
  1122. IN PEPROCESS Process,
  1123. IN SIZE_T Amount
  1124. );
  1125. VOID
  1126. PsReturnProcessNonPagedPoolQuota(
  1127. IN PEPROCESS Process,
  1128. IN SIZE_T Amount
  1129. );
  1130. NTSTATUS
  1131. PsChargeProcessPagedPoolQuota(
  1132. IN PEPROCESS Process,
  1133. IN SIZE_T Amount
  1134. );
  1135. VOID
  1136. PsReturnProcessPagedPoolQuota(
  1137. IN PEPROCESS Process,
  1138. IN SIZE_T Amount
  1139. );
  1140. NTSTATUS
  1141. PsChargeProcessPageFileQuota(
  1142. IN PEPROCESS Process,
  1143. IN SIZE_T Amount
  1144. );
  1145. VOID
  1146. PsReturnProcessPageFileQuota(
  1147. IN PEPROCESS Process,
  1148. IN SIZE_T Amount
  1149. );
  1150. //
  1151. // Context Management
  1152. //
  1153. VOID
  1154. PspContextToKframes(
  1155. OUT PKTRAP_FRAME TrapFrame,
  1156. OUT PKEXCEPTION_FRAME ExceptionFrame,
  1157. IN PCONTEXT Context
  1158. );
  1159. VOID
  1160. PspContextFromKframes(
  1161. OUT PKTRAP_FRAME TrapFrame,
  1162. OUT PKEXCEPTION_FRAME ExceptionFrame,
  1163. IN PCONTEXT Context
  1164. );
  1165. VOID
  1166. PsReturnSharedPoolQuota(
  1167. IN PEPROCESS_QUOTA_BLOCK QuotaBlock,
  1168. IN ULONG_PTR PagedAmount,
  1169. IN ULONG_PTR NonPagedAmount
  1170. );
  1171. PEPROCESS_QUOTA_BLOCK
  1172. PsChargeSharedPoolQuota(
  1173. IN PEPROCESS Process,
  1174. IN ULONG_PTR PagedAmount,
  1175. IN ULONG_PTR NonPagedAmount
  1176. );
  1177. //
  1178. // Exception Handling
  1179. //
  1180. BOOLEAN
  1181. PsForwardException (
  1182. IN PEXCEPTION_RECORD ExceptionRecord,
  1183. IN BOOLEAN DebugException,
  1184. IN BOOLEAN SecondChance
  1185. );
  1186. // begin_ntosp
  1187. typedef
  1188. NTSTATUS
  1189. (*PKWIN32_PROCESS_CALLOUT) (
  1190. IN PEPROCESS Process,
  1191. IN BOOLEAN Initialize
  1192. );
  1193. typedef enum _PSW32JOBCALLOUTTYPE {
  1194. PsW32JobCalloutSetInformation,
  1195. PsW32JobCalloutAddProcess,
  1196. PsW32JobCalloutTerminate
  1197. } PSW32JOBCALLOUTTYPE;
  1198. typedef struct _WIN32_JOBCALLOUT_PARAMETERS {
  1199. PVOID Job;
  1200. PSW32JOBCALLOUTTYPE CalloutType;
  1201. IN PVOID Data;
  1202. } WIN32_JOBCALLOUT_PARAMETERS, *PKWIN32_JOBCALLOUT_PARAMETERS;
  1203. typedef
  1204. NTSTATUS
  1205. (*PKWIN32_JOB_CALLOUT) (
  1206. IN PKWIN32_JOBCALLOUT_PARAMETERS Parm
  1207. );
  1208. typedef enum _PSW32THREADCALLOUTTYPE {
  1209. PsW32ThreadCalloutInitialize,
  1210. PsW32ThreadCalloutExit
  1211. } PSW32THREADCALLOUTTYPE;
  1212. typedef
  1213. NTSTATUS
  1214. (*PKWIN32_THREAD_CALLOUT) (
  1215. IN PETHREAD Thread,
  1216. IN PSW32THREADCALLOUTTYPE CalloutType
  1217. );
  1218. typedef enum _PSPOWEREVENTTYPE {
  1219. PsW32FullWake,
  1220. PsW32EventCode,
  1221. PsW32PowerPolicyChanged,
  1222. PsW32SystemPowerState,
  1223. PsW32SystemTime,
  1224. PsW32DisplayState,
  1225. PsW32CapabilitiesChanged,
  1226. PsW32SetStateFailed,
  1227. PsW32GdiOff,
  1228. PsW32GdiOn
  1229. } PSPOWEREVENTTYPE;
  1230. typedef struct _WIN32_POWEREVENT_PARAMETERS {
  1231. PSPOWEREVENTTYPE EventNumber;
  1232. ULONG_PTR Code;
  1233. } WIN32_POWEREVENT_PARAMETERS, *PKWIN32_POWEREVENT_PARAMETERS;
  1234. typedef enum _POWERSTATETASK {
  1235. PowerState_BlockSessionSwitch,
  1236. PowerState_Init,
  1237. PowerState_QueryApps,
  1238. PowerState_QueryFailed,
  1239. PowerState_SuspendApps,
  1240. PowerState_ShowUI,
  1241. PowerState_NotifyWL,
  1242. PowerState_ResumeApps,
  1243. PowerState_UnBlockSessionSwitch
  1244. } POWERSTATETASK;
  1245. typedef struct _WIN32_POWERSTATE_PARAMETERS {
  1246. BOOLEAN Promotion;
  1247. POWER_ACTION SystemAction;
  1248. SYSTEM_POWER_STATE MinSystemState;
  1249. ULONG Flags;
  1250. BOOLEAN fQueryDenied;
  1251. POWERSTATETASK PowerStateTask;
  1252. } WIN32_POWERSTATE_PARAMETERS, *PKWIN32_POWERSTATE_PARAMETERS;
  1253. typedef
  1254. NTSTATUS
  1255. (*PKWIN32_POWEREVENT_CALLOUT) (
  1256. IN PKWIN32_POWEREVENT_PARAMETERS Parm
  1257. );
  1258. typedef
  1259. NTSTATUS
  1260. (*PKWIN32_POWERSTATE_CALLOUT) (
  1261. IN PKWIN32_POWERSTATE_PARAMETERS Parm
  1262. );
  1263. typedef
  1264. NTSTATUS
  1265. (*PKWIN32_OBJECT_CALLOUT) (
  1266. IN PVOID Parm
  1267. );
  1268. typedef struct _WIN32_CALLOUTS_FPNS {
  1269. PKWIN32_PROCESS_CALLOUT ProcessCallout;
  1270. PKWIN32_THREAD_CALLOUT ThreadCallout;
  1271. PKWIN32_GLOBALATOMTABLE_CALLOUT GlobalAtomTableCallout;
  1272. PKWIN32_POWEREVENT_CALLOUT PowerEventCallout;
  1273. PKWIN32_POWERSTATE_CALLOUT PowerStateCallout;
  1274. PKWIN32_JOB_CALLOUT JobCallout;
  1275. PVOID BatchFlushRoutine;
  1276. PKWIN32_OBJECT_CALLOUT DesktopOpenProcedure;
  1277. PKWIN32_OBJECT_CALLOUT DesktopOkToCloseProcedure;
  1278. PKWIN32_OBJECT_CALLOUT DesktopCloseProcedure;
  1279. PKWIN32_OBJECT_CALLOUT DesktopDeleteProcedure;
  1280. PKWIN32_OBJECT_CALLOUT WindowStationOkToCloseProcedure;
  1281. PKWIN32_OBJECT_CALLOUT WindowStationCloseProcedure;
  1282. PKWIN32_OBJECT_CALLOUT WindowStationDeleteProcedure;
  1283. PKWIN32_OBJECT_CALLOUT WindowStationParseProcedure;
  1284. PKWIN32_OBJECT_CALLOUT WindowStationOpenProcedure;
  1285. } WIN32_CALLOUTS_FPNS, *PKWIN32_CALLOUTS_FPNS;
  1286. NTKERNELAPI
  1287. VOID
  1288. PsEstablishWin32Callouts(
  1289. IN PKWIN32_CALLOUTS_FPNS pWin32Callouts
  1290. );
  1291. typedef enum _PSPROCESSPRIORITYMODE {
  1292. PsProcessPriorityBackground,
  1293. PsProcessPriorityForeground,
  1294. PsProcessPrioritySpinning
  1295. } PSPROCESSPRIORITYMODE;
  1296. NTKERNELAPI
  1297. VOID
  1298. PsSetProcessPriorityByClass(
  1299. IN PEPROCESS Process,
  1300. IN PSPROCESSPRIORITYMODE PriorityMode
  1301. );
  1302. // end_ntosp
  1303. VOID
  1304. PsWatchWorkingSet(
  1305. IN NTSTATUS Status,
  1306. IN PVOID PcValue,
  1307. IN PVOID Va
  1308. );
  1309. // begin_ntddk begin_nthal begin_ntifs begin_ntosp
  1310. HANDLE
  1311. PsGetCurrentProcessId( VOID );
  1312. HANDLE
  1313. PsGetCurrentThreadId( VOID );
  1314. // end_ntosp
  1315. BOOLEAN
  1316. PsGetVersion(
  1317. PULONG MajorVersion OPTIONAL,
  1318. PULONG MinorVersion OPTIONAL,
  1319. PULONG BuildNumber OPTIONAL,
  1320. PUNICODE_STRING CSDVersion OPTIONAL
  1321. );
  1322. // end_ntddk end_nthal end_ntifs
  1323. // begin_ntosp
  1324. NTKERNELAPI
  1325. ULONG
  1326. PsGetCurrentProcessSessionId(
  1327. VOID
  1328. );
  1329. NTKERNELAPI
  1330. PVOID
  1331. PsGetCurrentThreadStackLimit(
  1332. VOID
  1333. );
  1334. NTKERNELAPI
  1335. PVOID
  1336. PsGetCurrentThreadStackBase(
  1337. VOID
  1338. );
  1339. NTKERNELAPI
  1340. CCHAR
  1341. PsGetCurrentThreadPreviousMode(
  1342. VOID
  1343. );
  1344. NTKERNELAPI
  1345. PERESOURCE
  1346. PsGetJobLock(
  1347. PEJOB Job
  1348. );
  1349. NTKERNELAPI
  1350. ULONG
  1351. PsGetJobSessionId(
  1352. PEJOB Job
  1353. );
  1354. NTKERNELAPI
  1355. ULONG
  1356. PsGetJobUIRestrictionsClass(
  1357. PEJOB Job
  1358. );
  1359. NTKERNELAPI
  1360. LONGLONG
  1361. PsGetProcessCreateTimeQuadPart(
  1362. PEPROCESS Process
  1363. );
  1364. NTKERNELAPI
  1365. PVOID
  1366. PsGetProcessDebugPort(
  1367. PEPROCESS Process
  1368. );
  1369. BOOLEAN
  1370. PsIsProcessBeingDebugged(
  1371. PEPROCESS Process
  1372. );
  1373. NTKERNELAPI
  1374. BOOLEAN
  1375. PsGetProcessExitProcessCalled(
  1376. PEPROCESS Process
  1377. );
  1378. NTKERNELAPI
  1379. NTSTATUS
  1380. PsGetProcessExitStatus(
  1381. PEPROCESS Process
  1382. );
  1383. NTKERNELAPI
  1384. HANDLE
  1385. PsGetProcessId(
  1386. PEPROCESS Process
  1387. );
  1388. NTKERNELAPI
  1389. UCHAR *
  1390. PsGetProcessImageFileName(
  1391. PEPROCESS Process
  1392. );
  1393. #define PsGetCurrentProcessImageFileName() PsGetProcessImageFileName(PsGetCurrentProcess())
  1394. NTKERNELAPI
  1395. HANDLE
  1396. PsGetProcessInheritedFromUniqueProcessId(
  1397. PEPROCESS Process
  1398. );
  1399. NTKERNELAPI
  1400. PEJOB
  1401. PsGetProcessJob(
  1402. PEPROCESS Process
  1403. );
  1404. NTKERNELAPI
  1405. ULONG
  1406. PsGetProcessSessionId(
  1407. PEPROCESS Process
  1408. );
  1409. NTKERNELAPI
  1410. PVOID
  1411. PsGetProcessSectionBaseAddress(
  1412. PEPROCESS Process
  1413. );
  1414. #define PsGetProcessPcb(Process) ((PKPROCESS)(Process))
  1415. NTKERNELAPI
  1416. PPEB
  1417. PsGetProcessPeb(
  1418. PEPROCESS Process
  1419. );
  1420. NTKERNELAPI
  1421. UCHAR
  1422. PsGetProcessPriorityClass(
  1423. PEPROCESS Process
  1424. );
  1425. NTKERNELAPI
  1426. HANDLE
  1427. PsGetProcessWin32WindowStation(
  1428. PEPROCESS Process
  1429. );
  1430. #define PsGetCurrentProcessWin32WindowStation() PsGetProcessWin32WindowStation(PsGetCurrentProcess())
  1431. NTKERNELAPI
  1432. PVOID
  1433. PsGetProcessWin32Process(
  1434. PEPROCESS Process
  1435. );
  1436. #define PsGetCurrentProcessWin32Process() PsGetProcessWin32Process(PsGetCurrentProcess())
  1437. #if defined(_WIN64)
  1438. NTKERNELAPI
  1439. PVOID
  1440. PsGetProcessWow64Process(
  1441. PEPROCESS Process
  1442. );
  1443. #endif
  1444. NTKERNELAPI
  1445. HANDLE
  1446. PsGetThreadId(
  1447. PETHREAD Thread
  1448. );
  1449. NTKERNELAPI
  1450. CCHAR
  1451. PsGetThreadFreezeCount(
  1452. PETHREAD Thread
  1453. );
  1454. NTKERNELAPI
  1455. BOOLEAN
  1456. PsGetThreadHardErrorsAreDisabled(
  1457. PETHREAD Thread);
  1458. NTKERNELAPI
  1459. PEPROCESS
  1460. PsGetThreadProcess(
  1461. PETHREAD Thread
  1462. );
  1463. #define PsGetCurrentThreadProcess() PsGetThreadProcess(PsGetCurrentThread())
  1464. NTKERNELAPI
  1465. HANDLE
  1466. PsGetThreadProcessId(
  1467. PETHREAD Thread
  1468. );
  1469. #define PsGetCurrentThreadProcessId() PsGetThreadProcessId(PsGetCurrentThread())
  1470. NTKERNELAPI
  1471. ULONG
  1472. PsGetThreadSessionId(
  1473. PETHREAD Thread
  1474. );
  1475. #define PsGetThreadTcb(Thread) ((PKTHREAD)(Thread))
  1476. NTKERNELAPI
  1477. PVOID
  1478. PsGetThreadTeb(
  1479. PETHREAD Thread
  1480. );
  1481. #define PsGetCurrentThreadTeb() PsGetThreadTeb(PsGetCurrentThread())
  1482. NTKERNELAPI
  1483. PVOID
  1484. PsGetThreadWin32Thread(
  1485. PETHREAD Thread
  1486. );
  1487. #define PsGetCurrentThreadWin32Thread() PsGetThreadWin32Thread(PsGetCurrentThread())
  1488. NTKERNELAPI //ntifs
  1489. BOOLEAN //ntifs
  1490. PsIsSystemThread( //ntifs
  1491. PETHREAD Thread //ntifs
  1492. ); //ntifs
  1493. NTKERNELAPI
  1494. BOOLEAN
  1495. PsIsThreadImpersonating (
  1496. IN PETHREAD Thread
  1497. );
  1498. NTSTATUS
  1499. PsReferenceProcessFilePointer (
  1500. IN PEPROCESS Process,
  1501. OUT PVOID *pFilePointer
  1502. );
  1503. NTKERNELAPI
  1504. VOID
  1505. PsSetJobUIRestrictionsClass(
  1506. PEJOB Job,
  1507. ULONG UIRestrictionsClass
  1508. );
  1509. NTKERNELAPI
  1510. VOID
  1511. PsSetProcessPriorityClass(
  1512. PEPROCESS Process,
  1513. UCHAR PriorityClass
  1514. );
  1515. NTKERNELAPI
  1516. NTSTATUS
  1517. PsSetProcessWin32Process(
  1518. PEPROCESS Process,
  1519. PVOID Win32Process,
  1520. PVOID PrevWin32Proces
  1521. );
  1522. NTKERNELAPI
  1523. VOID
  1524. PsSetProcessWindowStation(
  1525. PEPROCESS Process,
  1526. HANDLE Win32WindowStation
  1527. );
  1528. NTKERNELAPI
  1529. VOID
  1530. PsSetThreadHardErrorsAreDisabled(
  1531. PETHREAD Thread,
  1532. BOOLEAN HardErrorsAreDisabled
  1533. );
  1534. NTKERNELAPI
  1535. VOID
  1536. PsSetThreadWin32Thread(
  1537. PETHREAD Thread,
  1538. PVOID Win32Thread,
  1539. PVOID PrevWin32Thread
  1540. );
  1541. NTKERNELAPI
  1542. PVOID
  1543. PsGetProcessSecurityPort(
  1544. PEPROCESS Process
  1545. );
  1546. NTKERNELAPI
  1547. NTSTATUS
  1548. PsSetProcessSecurityPort(
  1549. PEPROCESS Process,
  1550. PVOID Port
  1551. );
  1552. typedef
  1553. NTSTATUS
  1554. (*PROCESS_ENUM_ROUTINE)(
  1555. IN PEPROCESS Process,
  1556. IN PVOID Context
  1557. );
  1558. typedef
  1559. NTSTATUS
  1560. (*THREAD_ENUM_ROUTINE)(
  1561. IN PEPROCESS Process,
  1562. IN PETHREAD Thread,
  1563. IN PVOID Context
  1564. );
  1565. NTSTATUS
  1566. PsEnumProcesses (
  1567. IN PROCESS_ENUM_ROUTINE CallBack,
  1568. IN PVOID Context
  1569. );
  1570. NTSTATUS
  1571. PsEnumProcessThreads (
  1572. IN PEPROCESS Process,
  1573. IN THREAD_ENUM_ROUTINE CallBack,
  1574. IN PVOID Context
  1575. );
  1576. PEPROCESS
  1577. PsGetNextProcess (
  1578. IN PEPROCESS Process
  1579. );
  1580. PETHREAD
  1581. PsGetNextProcessThread (
  1582. IN PEPROCESS Process,
  1583. IN PETHREAD Thread
  1584. );
  1585. VOID
  1586. PsQuitNextProcess (
  1587. IN PEPROCESS Process
  1588. );
  1589. VOID
  1590. PsQuitNextProcessThread (
  1591. IN PETHREAD Thread
  1592. );
  1593. PEJOB
  1594. PsGetNextJob (
  1595. IN PEJOB Job
  1596. );
  1597. PEPROCESS
  1598. PsGetNextJobProcess (
  1599. IN PEJOB Job,
  1600. IN PEPROCESS Process
  1601. );
  1602. VOID
  1603. PsQuitNextJob (
  1604. IN PEJOB Job
  1605. );
  1606. VOID
  1607. PsQuitNextJobProcess (
  1608. IN PEPROCESS Process
  1609. );
  1610. NTSTATUS
  1611. PsSuspendProcess (
  1612. IN PEPROCESS Process
  1613. );
  1614. NTSTATUS
  1615. PsResumeProcess (
  1616. IN PEPROCESS Process
  1617. );
  1618. NTSTATUS
  1619. PsTerminateProcess(
  1620. IN PEPROCESS Process,
  1621. IN NTSTATUS Status
  1622. );
  1623. NTSTATUS
  1624. PsSuspendThread (
  1625. IN PETHREAD Thread,
  1626. OUT PULONG PreviousSuspendCount OPTIONAL
  1627. );
  1628. NTSTATUS
  1629. PsResumeThread (
  1630. IN PETHREAD Thread,
  1631. OUT PULONG PreviousSuspendCount OPTIONAL
  1632. );
  1633. // end_ntosp
  1634. #endif // _PS_P