ReactOS  0.4.14-dev-55-g2da92ac
process.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for process.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PETHREAD NTAPI PsGetNextProcessThread (IN PEPROCESS Process, IN PETHREAD Thread OPTIONAL)
 
PEPROCESS NTAPI PsGetNextProcess (IN PEPROCESS OldProcess)
 
KPRIORITY NTAPI PspComputeQuantumAndPriority (IN PEPROCESS Process, IN PSPROCESSPRIORITYMODE Mode, OUT PUCHAR Quantum)
 
VOID NTAPI PsChangeQuantumTable (IN BOOLEAN Immediate, IN ULONG PrioritySeparation)
 
NTSTATUS NTAPI PspCreateProcess (OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN HANDLE ParentProcess OPTIONAL, IN ULONG Flags, IN HANDLE SectionHandle OPTIONAL, IN HANDLE DebugPort OPTIONAL, IN HANDLE ExceptionPort OPTIONAL, IN BOOLEAN InJob)
 
NTSTATUS NTAPI PsCreateSystemProcess (OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
 
NTSTATUS NTAPI PsLookupProcessByProcessId (IN HANDLE ProcessId, OUT PEPROCESS *Process)
 
NTSTATUS NTAPI PsLookupProcessThreadByCid (IN PCLIENT_ID Cid, OUT PEPROCESS *Process OPTIONAL, OUT PETHREAD *Thread)
 
LARGE_INTEGER NTAPI PsGetProcessExitTime (VOID)
 
LONGLONG NTAPI PsGetProcessCreateTimeQuadPart (PEPROCESS Process)
 
PVOID NTAPI PsGetProcessDebugPort (PEPROCESS Process)
 
BOOLEAN NTAPI PsGetProcessExitProcessCalled (PEPROCESS Process)
 
NTSTATUS NTAPI PsGetProcessExitStatus (PEPROCESS Process)
 
HANDLE NTAPI PsGetProcessId (PEPROCESS Process)
 
LPSTR NTAPI PsGetProcessImageFileName (PEPROCESS Process)
 
HANDLE NTAPI PsGetProcessInheritedFromUniqueProcessId (PEPROCESS Process)
 
PEJOB NTAPI PsGetProcessJob (PEPROCESS Process)
 
PPEB NTAPI PsGetProcessPeb (PEPROCESS Process)
 
ULONG NTAPI PsGetProcessPriorityClass (PEPROCESS Process)
 
HANDLE NTAPI PsGetCurrentProcessId (VOID)
 
ULONG NTAPI PsGetCurrentProcessSessionId (VOID)
 
PVOID NTAPI PsGetProcessSectionBaseAddress (PEPROCESS Process)
 
PVOID NTAPI PsGetProcessSecurityPort (PEPROCESS Process)
 
ULONG NTAPI PsGetProcessSessionId (IN PEPROCESS Process)
 
ULONG NTAPI PsGetProcessSessionIdEx (IN PEPROCESS Process)
 
PVOID NTAPI PsGetCurrentProcessWin32Process (VOID)
 
PVOID NTAPI PsGetProcessWin32Process (PEPROCESS Process)
 
PVOID NTAPI PsGetProcessWin32WindowStation (PEPROCESS Process)
 
BOOLEAN NTAPI PsIsProcessBeingDebugged (PEPROCESS Process)
 
BOOLEAN NTAPI PsIsSystemProcess (IN PEPROCESS Process)
 
VOID NTAPI PsSetProcessPriorityClass (PEPROCESS Process, ULONG PriorityClass)
 
NTSTATUS NTAPI PsSetProcessSecurityPort (PEPROCESS Process, PVOID SecurityPort)
 
NTSTATUS NTAPI PsSetProcessWin32Process (_Inout_ PEPROCESS Process, _In_opt_ PVOID Win32Process, _In_opt_ PVOID OldWin32Process)
 
VOID NTAPI PsSetProcessWindowStation (PEPROCESS Process, PVOID WindowStation)
 
VOID NTAPI PsSetProcessPriorityByClass (IN PEPROCESS Process, IN PSPROCESSPRIORITYMODE Type)
 
NTSTATUS NTAPI NtCreateProcessEx (OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN HANDLE ParentProcess, IN ULONG Flags, IN HANDLE SectionHandle OPTIONAL, IN HANDLE DebugPort OPTIONAL, IN HANDLE ExceptionPort OPTIONAL, IN BOOLEAN InJob)
 
NTSTATUS NTAPI NtCreateProcess (OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN HANDLE ParentProcess, IN BOOLEAN InheritObjectTable, IN HANDLE SectionHandle OPTIONAL, IN HANDLE DebugPort OPTIONAL, IN HANDLE ExceptionPort OPTIONAL)
 
NTSTATUS NTAPI NtOpenProcess (OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId)
 

Variables

ULONG PsMinimumWorkingSet
 
ULONG PsMaximumWorkingSet
 
POBJECT_TYPE PsProcessType = NULL
 
LIST_ENTRY PsActiveProcessHead
 
KGUARDED_MUTEX PspActiveProcessMutex
 
LARGE_INTEGER ShortPsLockDelay
 
ULONG PsRawPrioritySeparation
 
ULONG PsPrioritySeparation
 
CHAR PspForegroundQuantum [3]
 
CHAR PspFixedQuantums [6]
 
CHAR PspVariableQuantums [6]
 
KPRIORITY PspPriorityTable [PROCESS_PRIORITY_CLASS_ABOVE_NORMAL+1]
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file process.c.

Function Documentation

◆ NtCreateProcess()

NTSTATUS NTAPI NtCreateProcess ( OUT PHANDLE  ProcessHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
IN HANDLE  ParentProcess,
IN BOOLEAN  InheritObjectTable,
IN HANDLE SectionHandle  OPTIONAL,
IN HANDLE DebugPort  OPTIONAL,
IN HANDLE ExceptionPort  OPTIONAL 
)

Definition at line 1405 of file process.c.

1413 {
1414  ULONG Flags = 0;
1416  "Parent: %p Attributes: %p\n", ParentProcess, ObjectAttributes);
1417 
1418  /* Set new-style flags */
1419  if ((ULONG_PTR)SectionHandle & 1) Flags |= PROCESS_CREATE_FLAGS_BREAKAWAY;
1420  if ((ULONG_PTR)DebugPort & 1) Flags |= PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT;
1421  if (InheritObjectTable) Flags |= PROCESS_CREATE_FLAGS_INHERIT_HANDLES;
1422 
1423  /* Call the new API */
1425  DesiredAccess,
1427  ParentProcess,
1428  Flags,
1429  SectionHandle,
1430  DebugPort,
1431  ExceptionPort,
1432  FALSE);
1433 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
uint32_t ULONG_PTR
Definition: typedefs.h:63
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define PROCESS_CREATE_FLAGS_INHERIT_HANDLES
Definition: pstypes.h:93
#define PS_PROCESS_DEBUG
Definition: ps.h:18
#define PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT
Definition: pstypes.h:92
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define PROCESS_CREATE_FLAGS_BREAKAWAY
Definition: pstypes.h:91
unsigned int ULONG
Definition: retypes.h:1
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
NTSTATUS NTAPI NtCreateProcessEx(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN HANDLE ParentProcess, IN ULONG Flags, IN HANDLE SectionHandle OPTIONAL, IN HANDLE DebugPort OPTIONAL, IN HANDLE ExceptionPort OPTIONAL, IN BOOLEAN InJob)
Definition: process.c:1344

◆ NtCreateProcessEx()

NTSTATUS NTAPI NtCreateProcessEx ( OUT PHANDLE  ProcessHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
IN HANDLE  ParentProcess,
IN ULONG  Flags,
IN HANDLE SectionHandle  OPTIONAL,
IN HANDLE DebugPort  OPTIONAL,
IN HANDLE ExceptionPort  OPTIONAL,
IN BOOLEAN  InJob 
)

Definition at line 1344 of file process.c.

1353 {
1355  NTSTATUS Status;
1356  PAGED_CODE();
1358  "ParentProcess: %p Flags: %lx\n", ParentProcess, Flags);
1359 
1360  /* Check if we came from user mode */
1361  if (PreviousMode != KernelMode)
1362  {
1363  _SEH2_TRY
1364  {
1365  /* Probe process handle */
1367  }
1369  {
1370  /* Return the exception code */
1372  }
1373  _SEH2_END;
1374  }
1375 
1376  /* Make sure there's a parent process */
1377  if (!ParentProcess)
1378  {
1379  /* Can't create System Processes like this */
1381  }
1382  else
1383  {
1384  /* Create a user Process */
1386  DesiredAccess,
1388  ParentProcess,
1389  Flags,
1390  SectionHandle,
1391  DebugPort,
1392  ExceptionPort,
1393  InJob);
1394  }
1395 
1396  /* Return Status */
1397  return Status;
1398 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI PspCreateProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN HANDLE ParentProcess OPTIONAL, IN ULONG Flags, IN HANDLE SectionHandle OPTIONAL, IN HANDLE DebugPort OPTIONAL, IN HANDLE ExceptionPort OPTIONAL, IN BOOLEAN InJob)
Definition: process.c:347
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define PS_PROCESS_DEBUG
Definition: ps.h:18
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

Referenced by CreateProcessInternalW(), and NtCreateProcess().

◆ NtOpenProcess()

NTSTATUS NTAPI NtOpenProcess ( OUT PHANDLE  ProcessHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES  ObjectAttributes,
IN PCLIENT_ID  ClientId 
)

Definition at line 1440 of file process.c.

1444 {
1446  CLIENT_ID SafeClientId;
1447  ULONG Attributes = 0;
1448  HANDLE hProcess;
1449  BOOLEAN HasObjectName = FALSE;
1450  PETHREAD Thread = NULL;
1452  NTSTATUS Status;
1454  AUX_ACCESS_DATA AuxData;
1455  PAGED_CODE();
1457  "ClientId: %p Attributes: %p\n", ClientId, ObjectAttributes);
1458 
1459  /* Check if we were called from user mode */
1460  if (PreviousMode != KernelMode)
1461  {
1462  /* Enter SEH for probing */
1463  _SEH2_TRY
1464  {
1465  /* Probe the thread handle */
1467 
1468  /* Check for a CID structure */
1469  if (ClientId)
1470  {
1471  /* Probe and capture it */
1472  ProbeForRead(ClientId, sizeof(CLIENT_ID), sizeof(ULONG));
1473  SafeClientId = *ClientId;
1474  ClientId = &SafeClientId;
1475  }
1476 
1477  /*
1478  * Just probe the object attributes structure, don't capture it
1479  * completely. This is done later if necessary
1480  */
1482  sizeof(OBJECT_ATTRIBUTES),
1483  sizeof(ULONG));
1484  HasObjectName = (ObjectAttributes->ObjectName != NULL);
1485 
1486  /* Validate user attributes */
1488  }
1490  {
1491  /* Return the exception code */
1493  }
1494  _SEH2_END;
1495  }
1496  else
1497  {
1498  /* Otherwise just get the data directly */
1499  HasObjectName = (ObjectAttributes->ObjectName != NULL);
1500 
1501  /* Still have to sanitize attributes */
1503  }
1504 
1505  /* Can't pass both, fail */
1506  if ((HasObjectName) && (ClientId)) return STATUS_INVALID_PARAMETER_MIX;
1507 
1508  /* Create an access state */
1510  &AuxData,
1511  DesiredAccess,
1513  if (!NT_SUCCESS(Status)) return Status;
1514 
1515  /* Check if this is a debugger */
1517  {
1518  /* Did he want full access? */
1519  if (AccessState.RemainingDesiredAccess & MAXIMUM_ALLOWED)
1520  {
1521  /* Give it to him */
1522  AccessState.PreviouslyGrantedAccess |= PROCESS_ALL_ACCESS;
1523  }
1524  else
1525  {
1526  /* Otherwise just give every other access he could want */
1527  AccessState.PreviouslyGrantedAccess |=
1528  AccessState.RemainingDesiredAccess;
1529  }
1530 
1531  /* The caller desires nothing else now */
1532  AccessState.RemainingDesiredAccess = 0;
1533  }
1534 
1535  /* Open by name if one was given */
1536  if (HasObjectName)
1537  {
1538  /* Open it */
1540  PsProcessType,
1541  PreviousMode,
1542  &AccessState,
1543  0,
1544  NULL,
1545  &hProcess);
1546 
1547  /* Get rid of the access state */
1549  }
1550  else if (ClientId)
1551  {
1552  /* Open by Thread ID */
1553  if (ClientId->UniqueThread)
1554  {
1555  /* Get the Process */
1557  }
1558  else
1559  {
1560  /* Get the Process */
1562  &Process);
1563  }
1564 
1565  /* Check if we didn't find anything */
1566  if (!NT_SUCCESS(Status))
1567  {
1568  /* Get rid of the access state and return */
1570  return Status;
1571  }
1572 
1573  /* Open the Process Object */
1575  Attributes,
1576  &AccessState,
1577  0,
1578  PsProcessType,
1579  PreviousMode,
1580  &hProcess);
1581 
1582  /* Delete the access state */
1584 
1585  /* Dereference the thread if we used it */
1587 
1588  /* Dereference the Process */
1590  }
1591  else
1592  {
1593  /* neither an object name nor a client id was passed */
1595  }
1596 
1597  /* Check for success */
1598  if (NT_SUCCESS(Status))
1599  {
1600  /* Use SEH for write back */
1601  _SEH2_TRY
1602  {
1603  /* Write back the handle */
1605  }
1607  {
1608  /* Get the exception code */
1610  }
1611  _SEH2_END;
1612  }
1613 
1614  /* Return status */
1615  return Status;
1616 }
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2529
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSTATUS NTAPI SeCreateAccessState(IN OUT PACCESS_STATE AccessState, IN PAUX_ACCESS_DATA AuxData, IN ACCESS_MASK Access, IN PGENERIC_MAPPING GenericMapping)
Definition: access.c:439
#define PROCESS_ALL_ACCESS
Definition: nt_native.h:1324
const LUID SeDebugPrivilege
Definition: priv.c:41
#define KeGetPreviousMode()
Definition: ketypes.h:1107
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define STATUS_INVALID_PARAMETER_MIX
Definition: ntstatus.h:271
HANDLE UniqueProcess
Definition: compat.h:474
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2739
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
HANDLE UniqueThread
Definition: compat.h:475
NTSTATUS NTAPI PsLookupProcessThreadByCid(IN PCLIENT_ID Cid, OUT PEPROCESS *Process OPTIONAL, OUT PETHREAD *Thread)
Definition: process.c:961
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:414
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
#define PS_PROCESS_DEBUG
Definition: ps.h:18
Status
Definition: gdiplustypes.h:24
FORCEINLINE ULONG ObpValidateAttributes(IN ULONG Attributes, IN KPROCESSOR_MODE PreviousMode)
Definition: ob_x.h:22
_Must_inspect_result_ _In_ USHORT _In_ PHIDP_PREPARSED_DATA _Out_writes_to_ LengthAttributes PHIDP_EXTENDED_ATTRIBUTES Attributes
Definition: hidpi.h:348
_SEH2_END
Definition: create.c:4424
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
VOID NTAPI SeDeleteAccessState(IN PACCESS_STATE AccessState)
Definition: access.c:460
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
POBJECT_TYPE PsProcessType
Definition: process.c:20

Referenced by CSR_API(), LsapCheckLogonProcess(), LsapEnumLogonSessions(), LsapGetLogonSessionData(), Main(), OpenProcess(), PrintProcess(), ProcessIdToHandle(), ProcessIdToSessionId(), RtlQueryProcessDebugInformation(), SmpExecPgm(), SmpHandleConnectionRequest(), and UserpFormatMessages().

◆ PsChangeQuantumTable()

VOID NTAPI PsChangeQuantumTable ( IN BOOLEAN  Immediate,
IN ULONG  PrioritySeparation 
)

Definition at line 235 of file process.c.

237 {
239  ULONG i;
240  UCHAR Quantum;
241  PCHAR QuantumTable;
242  PAGED_CODE();
244  "%lx PrioritySeparation: %lx\n", Immediate, PrioritySeparation);
245 
246  /* Write the current priority separation */
248 
249  /* Normalize it if it was too high */
251 
252  /* Get the quantum table to use */
253  if (PspQuantumTypeFromMask(PrioritySeparation) == PSP_VARIABLE_QUANTUMS)
254  {
255  /* Use a variable table */
256  QuantumTable = PspVariableQuantums;
257  }
258  else if (PspQuantumTypeFromMask(PrioritySeparation) == PSP_FIXED_QUANTUMS)
259  {
260  /* Use fixed table */
261  QuantumTable = PspFixedQuantums;
262  }
263  else
264  {
265  /* Use default for the type of system we're on */
267  }
268 
269  /* Now check if we should use long or short */
270  if (PspQuantumLengthFromMask(PrioritySeparation) == PSP_LONG_QUANTUMS)
271  {
272  /* Use long quantums */
273  QuantumTable += 3;
274  }
275  else if (PspQuantumLengthFromMask(PrioritySeparation) == PSP_SHORT_QUANTUMS)
276  {
277  /* Keep existing table */
278  NOTHING;
279  }
280  else
281  {
282  /* Use default for the type of system we're on */
283  QuantumTable += MmIsThisAnNtAsSystem() ? 3 : 0;
284  }
285 
286  /* Check if we're using long fixed quantums */
287  if (QuantumTable == &PspFixedQuantums[3])
288  {
289  /* Use Job scheduling classes */
291  }
292  else
293  {
294  /* Otherwise, we don't */
296  }
297 
298  /* Copy the selected table into the Foreground Quantum table */
300  QuantumTable,
301  sizeof(PspForegroundQuantum));
302 
303  /* Check if we should apply these changes real-time */
304  if (Immediate)
305  {
306  /* We are...loop every process */
308  while (Process)
309  {
310  /* Use the priority separation if this is a foreground process */
311  i = (Process->Vm.Flags.MemoryPriority ==
314 
315  /* Make sure that the process isn't idle */
316  if (Process->PriorityClass != PROCESS_PRIORITY_CLASS_IDLE)
317  {
318  /* Does the process have a job? */
319  if ((Process->Job) && (PspUseJobSchedulingClasses))
320  {
321  /* Use job quantum */
322  Quantum = PspJobSchedulingClasses[Process->Job->SchedulingClass];
323  }
324  else
325  {
326  /* Use calculated quantum */
327  Quantum = PspForegroundQuantum[i];
328  }
329  }
330  else
331  {
332  /* Process is idle, use default quantum */
333  Quantum = 6;
334  }
335 
336  /* Now set the quantum */
337  KeSetQuantumProcess(&Process->Pcb, Quantum);
338 
339  /* Get the next process */
341  }
342  }
343 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
CHAR PspForegroundQuantum[3]
Definition: process.c:29
CHAR PspFixedQuantums[6]
Definition: process.c:32
#define PSP_VARIABLE_QUANTUMS
Definition: pstypes.h:132
#define PAGED_CODE()
Definition: video.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG PsPrioritySeparation
Definition: process.c:28
CHAR PspJobSchedulingClasses[PSP_JOB_SCHEDULING_CLASSES]
Definition: job.c:27
smooth NULL
Definition: ftsmooth.c:416
#define PSP_LONG_QUANTUMS
Definition: pstypes.h:134
BOOLEAN NTAPI MmIsThisAnNtAsSystem(VOID)
Definition: mmsup.c:246
#define MEMORY_PRIORITY_BACKGROUND
Definition: pstypes.h:124
unsigned char UCHAR
Definition: xmlstorage.h:181
#define PspQuantumLengthFromMask(Mask)
Definition: ps_x.h:19
#define PspPrioritySeparationFromMask(Mask)
Definition: ps_x.h:13
#define PSP_FIXED_QUANTUMS
Definition: pstypes.h:133
#define NOTHING
Definition: env_spec_w32.h:461
#define PS_PROCESS_DEBUG
Definition: ps.h:18
#define PSP_SHORT_QUANTUMS
Definition: pstypes.h:135
CHAR PspVariableQuantums[6]
Definition: process.c:46
PEPROCESS NTAPI PsGetNextProcess(IN PEPROCESS OldProcess)
Definition: process.c:128
BOOLEAN PspUseJobSchedulingClasses
Definition: job.c:25
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
VOID NTAPI KeSetQuantumProcess(IN PKPROCESS Process, IN UCHAR Quantum)
Definition: procobj.c:229
#define PROCESS_PRIORITY_CLASS_IDLE
Definition: pstypes.h:107
#define PspQuantumTypeFromMask(Mask)
Definition: ps_x.h:16

Referenced by PspInitPhase0(), and SSI_DEF().

◆ PsCreateSystemProcess()

NTSTATUS NTAPI PsCreateSystemProcess ( OUT PHANDLE  ProcessHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES  ObjectAttributes 
)

Definition at line 898 of file process.c.

901 {
902  /* Call the internal API */
906  NULL,
907  0,
908  NULL,
909  NULL,
910  NULL,
911  FALSE);
912 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSTATUS NTAPI PspCreateProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN HANDLE ParentProcess OPTIONAL, IN ULONG Flags, IN HANDLE SectionHandle OPTIONAL, IN HANDLE DebugPort OPTIONAL, IN HANDLE ExceptionPort OPTIONAL, IN BOOLEAN InJob)
Definition: process.c:347
smooth NULL
Definition: ftsmooth.c:416
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

◆ PsGetCurrentProcessId()

◆ PsGetCurrentProcessSessionId()

ULONG NTAPI PsGetCurrentProcessSessionId ( VOID  )

Definition at line 1133 of file process.c.

1134 {
1136 }
#define PsGetCurrentProcess
Definition: psfuncs.h:17
ULONG NTAPI MmGetSessionId(IN PEPROCESS Process)
Definition: session.c:180

Referenced by ExpWin32SessionCallout(), IntCreateDesktop(), IntDestroyMenuObject(), NtSetInformationObject(), NtUserSwitchDesktop(), ObpLookupObjectName(), and VideoPortUseDeviceInSession().

◆ PsGetCurrentProcessWin32Process()

PVOID NTAPI PsGetCurrentProcessWin32Process ( VOID  )

Definition at line 1183 of file process.c.

1184 {
1185  return PsGetCurrentProcess()->Win32Process;
1186 }
#define PsGetCurrentProcess
Definition: psfuncs.h:17

Referenced by _Function_class_(), CheckWinstaAttributeAccess(), co_IntGraphicsCheck(), co_IntSetParent(), co_IntSetWindowLongPtr(), co_IntUserManualGuiCheck(), co_UserDestroyWindow(), DC_bAllocDcAttr(), DC_vFreeDcAttr(), DecrementCurrentProcessGdiHandleCount(), DesktopHeapAddressToUser(), DesktopHeapGetUserDelta(), GDI_CleanupForProcess(), GetBrushAttrPool(), GetControlColor(), GetFontFamilyInfoForSubstitutes(), GetW32ProcessInfo(), handle_internal_message(), IdlePing(), IdlePong(), IncrementCurrentProcessGdiHandleCount(), IntAllowSetForegroundWindow(), IntGdiAddFontMemResource(), IntGdiCleanupPrivateFontsForProcess(), IntGdiLoadFontsFromMemory(), IntGdiRemoveFontMemResource(), IntGdiSetRegionOwner(), IntGetFontFamilyInfo(), IntLoadHookModule(), IntLoadSystenIcons(), IntLockSetForegroundWindow(), IntMapDesktopView(), IntUnmapDesktopView(), IntWinStaOkToClose(), NtUserCallHwndParam(), NtUserCallOneParam(), NtUserDestroyCursor(), NtUserFindExistingCursorIcon(), NtUserGetComboBoxInfo(), NtUserGetListBoxInfo(), NtUserSetSystemCursor(), NtUserSetWindowFNID(), REGION_bAllocRgnAttr(), REGION_vCleanup(), TextIntRealizeFont(), UserDbgAssertThreadInfo(), UserGetDCEx(), UserGetProcessWindowStation(), UserHeapAddressToUser(), UserSetProcessWindowStation(), UserSystemParametersInfo(), and UserUnregisterUserApiHook().

◆ PsGetNextProcess()

PEPROCESS NTAPI PsGetNextProcess ( IN PEPROCESS OldProcess  )

Definition at line 128 of file process.c.

129 {
131  PEPROCESS FoundProcess = NULL;
132  PAGED_CODE();
133  PSTRACE(PS_PROCESS_DEBUG, "Process: %p\n", OldProcess);
134 
135  /* Acquire the Active Process Lock */
137 
138  /* Check if we're already starting somewhere */
139  if (OldProcess)
140  {
141  /* Start where we left off */
142  Entry = OldProcess->ActiveProcessLinks.Flink;
143  }
144  else
145  {
146  /* Start at the beginning */
148  }
149 
150  /* Loop the process list */
151  while (Entry != &PsActiveProcessHead)
152  {
153  /* Get the process */
154  FoundProcess = CONTAINING_RECORD(Entry, EPROCESS, ActiveProcessLinks);
155 
156  /* Reference the process */
157  if (ObReferenceObjectSafe(FoundProcess)) break;
158 
159  /* Nothing found, keep trying */
160  FoundProcess = NULL;
161  Entry = Entry->Flink;
162  }
163 
164  /* Release the lock */
166 
167  /* Dereference the Process we had referenced earlier */
168  if (OldProcess) ObDereferenceObject(OldProcess);
169  return FoundProcess;
170 }
struct _Entry Entry
Definition: kefuncs.h:640
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PAGED_CODE()
Definition: video.h:57
BOOLEAN FASTCALL ObReferenceObjectSafe(IN PVOID Object)
Definition: obref.c:24
LIST_ENTRY PsActiveProcessHead
Definition: process.c:22
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
#define PS_PROCESS_DEBUG
Definition: ps.h:18
KGUARDED_MUTEX PspActiveProcessMutex
Definition: process.c:23
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
base of all file and directory entries
Definition: entries.h:82

Referenced by DbgkpCloseObject(), ExpDebuggerWorker(), PopGracefulShutdown(), PsChangeQuantumTable(), PspShutdownProcessManager(), and QSI_DEF().

◆ PsGetNextProcessThread()

PETHREAD NTAPI PsGetNextProcessThread ( IN PEPROCESS  Process,
IN PETHREAD Thread  OPTIONAL 
)

Definition at line 75 of file process.c.

77 {
78  PETHREAD FoundThread = NULL;
79  PLIST_ENTRY ListHead, Entry;
80  PAGED_CODE();
82  "Process: %p Thread: %p\n", Process, Thread);
83 
84  /* Lock the process */
86  ExAcquirePushLockShared(&Process->ProcessLock);
87 
88  /* Check if we're already starting somewhere */
89  if (Thread)
90  {
91  /* Start where we left off */
93  }
94  else
95  {
96  /* Start at the beginning */
97  Entry = Process->ThreadListHead.Flink;
98  }
99 
100  /* Set the list head and start looping */
101  ListHead = &Process->ThreadListHead;
102  while (ListHead != Entry)
103  {
104  /* Get the Thread */
105  FoundThread = CONTAINING_RECORD(Entry, ETHREAD, ThreadListEntry);
106 
107  /* Safe reference the thread */
108  if (ObReferenceObjectSafe(FoundThread)) break;
109 
110  /* Nothing found, keep looping */
111  FoundThread = NULL;
112  Entry = Entry->Flink;
113  }
114 
115  /* Unlock the process */
116  ExReleasePushLockShared(&Process->ProcessLock);
118 
119  /* Check if we had a starting thread, and dereference it */
121 
122  /* Return what we found */
123  return FoundThread;
124 }
LIST_ENTRY ThreadListEntry
Definition: pstypes.h:1089
struct _Entry Entry
Definition: kefuncs.h:640
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PAGED_CODE()
Definition: video.h:57
BOOLEAN FASTCALL ObReferenceObjectSafe(IN PVOID Object)
Definition: obref.c:24
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
Definition: typedefs.h:117
#define PS_PROCESS_DEBUG
Definition: ps.h:18
FORCEINLINE VOID ExAcquirePushLockShared(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1091
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
FORCEINLINE VOID ExReleasePushLockShared(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1199
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
base of all file and directory entries
Definition: entries.h:82

Referenced by DbgkpPostFakeThreadMessages(), DbgkpSetProcessDebugObject(), ExSwapinWorkerThreads(), NtSetInformationThread(), NtTerminateProcess(), PspTerminateProcess(), PsResumeProcess(), and PsSuspendProcess().

◆ PsGetProcessCreateTimeQuadPart()

LONGLONG NTAPI PsGetProcessCreateTimeQuadPart ( PEPROCESS  Process)

Definition at line 1023 of file process.c.

1024 {
1025  return Process->CreateTime.QuadPart;
1026 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by KsecGetKeyData().

◆ PsGetProcessDebugPort()

PVOID NTAPI PsGetProcessDebugPort ( PEPROCESS  Process)

Definition at line 1033 of file process.c.

1034 {
1035  return Process->DebugPort;
1036 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ PsGetProcessExitProcessCalled()

BOOLEAN NTAPI PsGetProcessExitProcessCalled ( PEPROCESS  Process)

Definition at line 1043 of file process.c.

1044 {
1045  return (BOOLEAN)Process->ProcessExiting;
1046 }
unsigned char BOOLEAN
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by NtUserWaitForInputIdle().

◆ PsGetProcessExitStatus()

NTSTATUS NTAPI PsGetProcessExitStatus ( PEPROCESS  Process)

Definition at line 1053 of file process.c.

1054 {
1055  return Process->ExitStatus;
1056 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by ExitThreadCallback().

◆ PsGetProcessExitTime()

LARGE_INTEGER NTAPI PsGetProcessExitTime ( VOID  )

Definition at line 1013 of file process.c.

1014 {
1015  return PsGetCurrentProcess()->ExitTime;
1016 }
#define PsGetCurrentProcess
Definition: psfuncs.h:17

◆ PsGetProcessId()

HANDLE NTAPI PsGetProcessId ( PEPROCESS  Process)

Definition at line 1063 of file process.c.

1064 {
1065  return (HANDLE)Process->UniqueProcessId;
1066 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by IntHookModuleUnloaded(), IntLoadHookModule(), UserProcessCreate(), UserRegisterUserApiHook(), and UserUnregisterUserApiHook().

◆ PsGetProcessImageFileName()

LPSTR NTAPI PsGetProcessImageFileName ( PEPROCESS  Process)

Definition at line 1073 of file process.c.

1074 {
1075  return (LPSTR)Process->ImageFileName;
1076 }
char * LPSTR
Definition: xmlstorage.h:182
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ PsGetProcessInheritedFromUniqueProcessId()

HANDLE NTAPI PsGetProcessInheritedFromUniqueProcessId ( PEPROCESS  Process)

Definition at line 1083 of file process.c.

1084 {
1085  return Process->InheritedFromUniqueProcessId;
1086 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ PsGetProcessJob()

PEJOB NTAPI PsGetProcessJob ( PEPROCESS  Process)

Definition at line 1093 of file process.c.

1094 {
1095  return Process->Job;
1096 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ PsGetProcessPeb()

PPEB NTAPI PsGetProcessPeb ( PEPROCESS  Process)

Definition at line 1103 of file process.c.

1104 {
1105  return Process->Peb;
1106 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ PsGetProcessPriorityClass()

ULONG NTAPI PsGetProcessPriorityClass ( PEPROCESS  Process)

Definition at line 1113 of file process.c.

1114 {
1115  return Process->PriorityClass;
1116 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ PsGetProcessSectionBaseAddress()

PVOID NTAPI PsGetProcessSectionBaseAddress ( PEPROCESS  Process)

Definition at line 1143 of file process.c.

1144 {
1145  return Process->SectionBaseAddress;
1146 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ PsGetProcessSecurityPort()

PVOID NTAPI PsGetProcessSecurityPort ( PEPROCESS  Process)

Definition at line 1153 of file process.c.

1154 {
1155  return Process->SecurityPort;
1156 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ PsGetProcessSessionId()

ULONG NTAPI PsGetProcessSessionId ( IN PEPROCESS  Process)

Definition at line 1163 of file process.c.

1164 {
1165  return MmGetSessionId(Process);
1166 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG NTAPI MmGetSessionId(IN PEPROCESS Process)
Definition: session.c:180

Referenced by NtAssignProcessToJobObject(), NtCreateJobObject(), NtQueryInformationProcess(), and NtSetInformationProcess().

◆ PsGetProcessSessionIdEx()

ULONG NTAPI PsGetProcessSessionIdEx ( IN PEPROCESS  Process)

Definition at line 1173 of file process.c.

1174 {
1175  return MmGetSessionIdEx(Process);
1176 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG NTAPI MmGetSessionIdEx(IN PEPROCESS Process)
Definition: session.c:195

◆ PsGetProcessWin32Process()

◆ PsGetProcessWin32WindowStation()

PVOID NTAPI PsGetProcessWin32WindowStation ( PEPROCESS  Process)

Definition at line 1203 of file process.c.

1204 {
1205  return Process->Win32WindowStation;
1206 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by UserSetProcessWindowStation().

◆ PsIsProcessBeingDebugged()

BOOLEAN NTAPI PsIsProcessBeingDebugged ( PEPROCESS  Process)

Definition at line 1213 of file process.c.

1214 {
1215  return Process->DebugPort != NULL;
1216 }
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ PsIsSystemProcess()

BOOLEAN NTAPI PsIsSystemProcess ( IN PEPROCESS  Process)

Definition at line 1223 of file process.c.

1224 {
1225  /* Return if this is the System Process */
1226  return Process == PsInitialSystemProcess;
1227 }
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by IntHookModuleUnloaded(), and UserRegisterUserApiHook().

◆ PsLookupProcessByProcessId()

NTSTATUS NTAPI PsLookupProcessByProcessId ( IN HANDLE  ProcessId,
OUT PEPROCESS Process 
)

Definition at line 919 of file process.c.

921 {
922  PHANDLE_TABLE_ENTRY CidEntry;
923  PEPROCESS FoundProcess;
925  PAGED_CODE();
926  PSTRACE(PS_PROCESS_DEBUG, "ProcessId: %p\n", ProcessId);
928 
929  /* Get the CID Handle Entry */
931  if (CidEntry)
932  {
933  /* Get the Process */
934  FoundProcess = CidEntry->Object;
935 
936  /* Make sure it's really a process */
937  if (FoundProcess->Pcb.Header.Type == ProcessObject)
938  {
939  /* Safe Reference and return it */
940  if (ObReferenceObjectSafe(FoundProcess))
941  {
942  *Process = FoundProcess;
944  }
945  }
946 
947  /* Unlock the Entry */
949  }
950 
951  /* Return to caller */
953  return Status;
954 }
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2697
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PHANDLE_TABLE_ENTRY NTAPI ExMapHandleToPointer(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle)
Definition: handle.c:1010
LONG NTSTATUS
Definition: precomp.h:26
PHANDLE_TABLE PspCidTable
Definition: psmgr.c:48
VOID NTAPI ExUnlockHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:887
#define PAGED_CODE()
Definition: video.h:57
BOOLEAN FASTCALL ObReferenceObjectSafe(IN PVOID Object)
Definition: obref.c:24
Definition: extypes.h:595
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
KPROCESS Pcb
Definition: pstypes.h:1193
#define PS_PROCESS_DEBUG
Definition: ps.h:18
Status
Definition: gdiplustypes.h:24
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
PVOID Object
Definition: extypes.h:599
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
return STATUS_SUCCESS
Definition: btrfs.c:2966
DISPATCHER_HEADER Header
Definition: ketypes.h:1974

Referenced by co_IntRegisterLogonProcess(), DecrementGdiHandleCount(), IncrementGdiHandleCount(), IntAllowSetForegroundWindow(), KdbpAttachToProcess(), KdbpCmdProc(), KdbpCmdThread(), and NtOpenProcess().

◆ PsLookupProcessThreadByCid()

NTSTATUS NTAPI PsLookupProcessThreadByCid ( IN PCLIENT_ID  Cid,
OUT PEPROCESS *Process  OPTIONAL,
OUT PETHREAD Thread 
)

Definition at line 961 of file process.c.

964 {
965  PHANDLE_TABLE_ENTRY CidEntry;
966  PETHREAD FoundThread;
968  PAGED_CODE();
969  PSTRACE(PS_PROCESS_DEBUG, "Cid: %p\n", Cid);
971 
972  /* Get the CID Handle Entry */
973  CidEntry = ExMapHandleToPointer(PspCidTable, Cid->UniqueThread);
974  if (CidEntry)
975  {
976  /* Get the Process */
977  FoundThread = CidEntry->Object;
978 
979  /* Make sure it's really a thread and this process' */
980  if ((FoundThread->Tcb.Header.Type == ThreadObject) &&
981  (FoundThread->Cid.UniqueProcess == Cid->UniqueProcess))
982  {
983  /* Safe Reference and return it */
984  if (ObReferenceObjectSafe(FoundThread))
985  {
986  *Thread = FoundThread;
988 
989  /* Check if we should return the Process too */
990  if (Process)
991  {
992  /* Return it and reference it */
993  *Process = FoundThread->ThreadsProcess;
995  }
996  }
997  }
998 
999  /* Unlock the Entry */
1001  }
1002 
1003  /* Return to caller */
1005  return Status;
1006 }
PHANDLE_TABLE_ENTRY NTAPI ExMapHandleToPointer(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle)
Definition: handle.c:1010
LONG NTSTATUS
Definition: precomp.h:26
KTHREAD Tcb
Definition: pstypes.h:1034
PHANDLE_TABLE PspCidTable
Definition: psmgr.c:48
HANDLE UniqueProcess
Definition: compat.h:474
VOID NTAPI ExUnlockHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:887
#define PAGED_CODE()
Definition: video.h:57
BOOLEAN FASTCALL ObReferenceObjectSafe(IN PVOID Object)
Definition: obref.c:24
#define STATUS_INVALID_CID
Definition: ntstatus.h:234
Definition: extypes.h:595
CLIENT_ID Cid
Definition: pstypes.h:1059
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define PS_PROCESS_DEBUG
Definition: ps.h:18
Status
Definition: gdiplustypes.h:24
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
DISPATCHER_HEADER Header
Definition: ketypes.h:1551
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ObReferenceObject
Definition: obfuncs.h:204
PVOID Object
Definition: extypes.h:599
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by LpcpCopyRequestData(), NtAcceptConnectPort(), NtImpersonateClientOfPort(), NtOpenProcess(), NtOpenThread(), NtReplyPort(), and NtReplyWaitReceivePortEx().

◆ PspComputeQuantumAndPriority()

KPRIORITY NTAPI PspComputeQuantumAndPriority ( IN PEPROCESS  Process,
IN PSPROCESSPRIORITYMODE  Mode,
OUT PUCHAR  Quantum 
)

Definition at line 174 of file process.c.

177 {
178  ULONG i;
179  UCHAR LocalQuantum, MemoryPriority;
180  PAGED_CODE();
181  PSTRACE(PS_PROCESS_DEBUG, "Process: %p Mode: %lx\n", Process, Mode);
182 
183  /* Check if this is a foreground process */
185  {
186  /* Set the memory priority and use priority separation */
187  MemoryPriority = MEMORY_PRIORITY_FOREGROUND;
189  }
190  else
191  {
192  /* Set the background memory priority and no separation */
193  MemoryPriority = MEMORY_PRIORITY_BACKGROUND;
194  i = 0;
195  }
196 
197  /* Make sure that the process mode isn't spinning */
199  {
200  /* Set the priority */
201  MmSetMemoryPriorityProcess(Process, MemoryPriority);
202  }
203 
204  /* Make sure that the process isn't idle */
205  if (Process->PriorityClass != PROCESS_PRIORITY_CLASS_IDLE)
206  {
207  /* Does the process have a job? */
208  if ((Process->Job) && (PspUseJobSchedulingClasses))
209  {
210  /* Use job quantum */
211  LocalQuantum = PspJobSchedulingClasses[Process->Job->
212  SchedulingClass];
213  }
214  else
215  {
216  /* Use calculated quantum */
217  LocalQuantum = PspForegroundQuantum[i];
218  }
219  }
220  else
221  {
222  /* Process is idle, use default quantum */
223  LocalQuantum = 6;
224  }
225 
226  /* Return quantum to caller */
227  *Quantum = LocalQuantum;
228 
229  /* Return priority */
230  return PspPriorityTable[Process->PriorityClass];
231 }
_In_ ULONG Mode
Definition: hubbusif.h:303
CHAR PspForegroundQuantum[3]
Definition: process.c:29
#define PAGED_CODE()
Definition: video.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG PsPrioritySeparation
Definition: process.c:28
CHAR PspJobSchedulingClasses[PSP_JOB_SCHEDULING_CLASSES]
Definition: job.c:27
KPRIORITY PspPriorityTable[PROCESS_PRIORITY_CLASS_ABOVE_NORMAL+1]
Definition: process.c:60
#define MEMORY_PRIORITY_BACKGROUND
Definition: pstypes.h:124
unsigned char UCHAR
Definition: xmlstorage.h:181
#define PS_PROCESS_DEBUG
Definition: ps.h:18
#define MEMORY_PRIORITY_FOREGROUND
Definition: pstypes.h:126
BOOLEAN PspUseJobSchedulingClasses
Definition: job.c:25
NTSTATUS NTAPI MmSetMemoryPriorityProcess(IN PEPROCESS Process, IN UCHAR MemoryPriority)
Definition: procsup.c:469
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
#define PROCESS_PRIORITY_CLASS_IDLE
Definition: pstypes.h:107

Referenced by PspCreateProcess(), and PsSetProcessPriorityByClass().

◆ PspCreateProcess()

NTSTATUS NTAPI PspCreateProcess ( OUT PHANDLE  ProcessHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
IN HANDLE ParentProcess  OPTIONAL,
IN ULONG  Flags,
IN HANDLE SectionHandle  OPTIONAL,
IN HANDLE DebugPort  OPTIONAL,
IN HANDLE ExceptionPort  OPTIONAL,
IN BOOLEAN  InJob 
)

Definition at line 347 of file process.c.

356 {
359  PVOID ExceptionPortObject;
360  PDEBUG_OBJECT DebugObject;
363  ULONG_PTR DirectoryTableBase[2] = {0,0};
365  HANDLE_TABLE_ENTRY CidEntry;
366  PETHREAD CurrentThread = PsGetCurrentThread();
369  ULONG MinWs, MaxWs;
370  ACCESS_STATE LocalAccessState;
371  PACCESS_STATE AccessState = &LocalAccessState;
372  AUX_ACCESS_DATA AuxData;
373  UCHAR Quantum;
374  BOOLEAN Result, SdAllocated;
377  BOOLEAN NeedsPeb = FALSE;
378  INITIAL_PEB InitialPeb;
379  PAGED_CODE();
381  "ProcessHandle: %p Parent: %p\n", ProcessHandle, ParentProcess);
382 
383  /* Validate flags */
385 
386  /* Check for parent */
387  if (ParentProcess)
388  {
389  /* Reference it */
390  Status = ObReferenceObjectByHandle(ParentProcess,
393  PreviousMode,
394  (PVOID*)&Parent,
395  NULL);
396  if (!NT_SUCCESS(Status)) return Status;
397 
398  /* If this process should be in a job but the parent isn't */
399  if ((InJob) && (!Parent->Job))
400  {
401  /* This is illegal. Dereference the parent and fail */
404  }
405 
406  /* Inherit Parent process's Affinity. */
407  Affinity = Parent->Pcb.Affinity;
408  }
409  else
410  {
411  /* We have no parent */
412  Parent = NULL;
414  }
415 
416  /* Save working set data */
417  MinWs = PsMinimumWorkingSet;
418  MaxWs = PsMaximumWorkingSet;
419 
420  /* Create the Object */
424  PreviousMode,
425  NULL,
426  sizeof(EPROCESS),
427  0,
428  0,
429  (PVOID*)&Process);
430  if (!NT_SUCCESS(Status)) goto Cleanup;
431 
432  /* Clean up the Object */
433  RtlZeroMemory(Process, sizeof(EPROCESS));
434 
435  /* Initialize pushlock and rundown protection */
436  ExInitializeRundownProtection(&Process->RundownProtect);
437  Process->ProcessLock.Value = 0;
438 
439  /* Setup the Thread List Head */
440  InitializeListHead(&Process->ThreadListHead);
441 
442  /* Set up the Quota Block from the Parent */
444 
445  /* Set up Dos Device Map from the Parent */
447 
448  /* Check if we have a parent */
449  if (Parent)
450  {
451  /* Inherit PID and hard-error processing */
452  Process->InheritedFromUniqueProcessId = Parent->UniqueProcessId;
453  Process->DefaultHardErrorProcessing = Parent->DefaultHardErrorProcessing;
454  }
455  else
456  {
457  /* Use default hard-error processing */
458  Process->DefaultHardErrorProcessing = SEM_FAILCRITICALERRORS;
459  }
460 
461  /* Check for a section handle */
462  if (SectionHandle)
463  {
464  /* Get a pointer to it */
465  Status = ObReferenceObjectByHandle(SectionHandle,
468  PreviousMode,
469  (PVOID*)&SectionObject,
470  NULL);
471  if (!NT_SUCCESS(Status)) goto CleanupWithRef;
472  }
473  else
474  {
475  /* Assume no section object */
477 
478  /* Is the parent the initial process?
479  * Check for NULL also, as at initialization PsInitialSystemProcess is NULL */
480  if (Parent != PsInitialSystemProcess && (Parent != NULL))
481  {
482  /* It's not, so acquire the process rundown */
483  if (ExAcquireRundownProtection(&Parent->RundownProtect))
484  {
485  /* If the parent has a section, use it */
486  SectionObject = Parent->SectionObject;
488 
489  /* Release process rundown */
490  ExReleaseRundownProtection(&Parent->RundownProtect);
491  }
492 
493  /* If we don't have a section object */
494  if (!SectionObject)
495  {
496  /* Then the process is in termination, so fail */
498  goto CleanupWithRef;
499  }
500  }
501  }
502 
503  /* Save the pointer to the section object */
504  Process->SectionObject = SectionObject;
505 
506  /* Check for the debug port */
507  if (DebugPort)
508  {
509  /* Reference it */
510  Status = ObReferenceObjectByHandle(DebugPort,
513  PreviousMode,
514  (PVOID*)&DebugObject,
515  NULL);
516  if (!NT_SUCCESS(Status)) goto CleanupWithRef;
517 
518  /* Save the debug object */
519  Process->DebugPort = DebugObject;
520 
521  /* Check if the caller doesn't want the debug stuff inherited */
523  {
524  /* Set the process flag */
526  }
527  }
528  else
529  {
530  /* Do we have a parent? Copy his debug port */
532  }
533 
534  /* Now check for an exception port */
535  if (ExceptionPort)
536  {
537  /* Reference it */
538  Status = ObReferenceObjectByHandle(ExceptionPort,
541  PreviousMode,
542  (PVOID*)&ExceptionPortObject,
543  NULL);
544  if (!NT_SUCCESS(Status)) goto CleanupWithRef;
545 
546  /* Save the exception port */
547  Process->ExceptionPort = ExceptionPortObject;
548  }
549 
550  /* Save the pointer to the section object */
551  Process->SectionObject = SectionObject;
552 
553  /* Set default exit code */
554  Process->ExitStatus = STATUS_PENDING;
555 
556  /* Check if this is the initial process being built */
557  if (Parent)
558  {
559  /* Create the address space for the child */
560  if (!MmCreateProcessAddressSpace(MinWs,
561  Process,
562  DirectoryTableBase))
563  {
564  /* Failed */
566  goto CleanupWithRef;
567  }
568  }
569  else
570  {
571  /* Otherwise, we are the boot process, we're already semi-initialized */
572  Process->ObjectTable = CurrentProcess->ObjectTable;
573  Status = MmInitializeHandBuiltProcess(Process, DirectoryTableBase);
574  if (!NT_SUCCESS(Status)) goto CleanupWithRef;
575  }
576 
577  /* We now have an address space */
579 
580  /* Set the maximum WS */
581  Process->Vm.MaximumWorkingSetSize = MaxWs;
582 
583  /* Now initialize the Kernel Process */
586  Affinity,
587  DirectoryTableBase,
588  BooleanFlagOn(Process->DefaultHardErrorProcessing,
590 
591  /* Duplicate Parent Token */
593  if (!NT_SUCCESS(Status)) goto CleanupWithRef;
594 
595  /* Set default priority class */
596  Process->PriorityClass = PROCESS_PRIORITY_CLASS_NORMAL;
597 
598  /* Check if we have a parent */
599  if (Parent)
600  {
601  /* Check our priority class */
602  if (Parent->PriorityClass == PROCESS_PRIORITY_CLASS_IDLE ||
604  {
605  /* Normalize it */
606  Process->PriorityClass = Parent->PriorityClass;
607  }
608 
609  /* Initialize object manager for the process */
611  Parent : NULL,
612  Process);
613  if (!NT_SUCCESS(Status)) goto CleanupWithRef;
614  }
615  else
616  {
617  /* Do the second part of the boot process memory setup */
619  if (!NT_SUCCESS(Status)) goto CleanupWithRef;
620  }
621 
622  /* Set success for now */
624 
625  /* Check if this is a real user-mode process */
626  if (SectionHandle)
627  {
628  /* Initialize the address space */
630  NULL,
632  &Flags,
633  &Process->
634  SeAuditProcessCreationInfo.
635  ImageFileName);
636  if (!NT_SUCCESS(Status)) goto CleanupWithRef;
637 
638  //
639  // We need a PEB
640  //
641  NeedsPeb = TRUE;
642  }
643  else if (Parent)
644  {
645  /* Check if this is a child of the system process */
647  {
648  //
649  // We need a PEB
650  //
651  NeedsPeb = TRUE;
652 
653  /* This is a clone! */
654  ASSERTMSG("No support for cloning yet\n", FALSE);
655  }
656  else
657  {
658  /* This is the initial system process */
661  NULL,
662  NULL,
663  &Flags,
664  NULL);
665  if (!NT_SUCCESS(Status)) goto CleanupWithRef;
666 
667  /* Create a dummy image file name */
668  Process->SeAuditProcessCreationInfo.ImageFileName =
670  sizeof(OBJECT_NAME_INFORMATION),
671  TAG_SEPA);
672  if (!Process->SeAuditProcessCreationInfo.ImageFileName)
673  {
674  /* Fail */
676  goto CleanupWithRef;
677  }
678 
679  /* Zero it out */
680  RtlZeroMemory(Process->SeAuditProcessCreationInfo.ImageFileName,
681  sizeof(OBJECT_NAME_INFORMATION));
682  }
683  }
684 
685 #if MI_TRACE_PFNS
686  /* Copy the process name now that we have it */
687  memcpy(MiGetPfnEntry(Process->Pcb.DirectoryTableBase[0] >> PAGE_SHIFT)->ProcessName, Process->ImageFileName, 16);
688  if (Process->Pcb.DirectoryTableBase[1]) memcpy(MiGetPfnEntry(Process->Pcb.DirectoryTableBase[1] >> PAGE_SHIFT)->ProcessName, Process->ImageFileName, 16);
689  if (Process->WorkingSetPage) memcpy(MiGetPfnEntry(Process->WorkingSetPage)->ProcessName, Process->ImageFileName, 16);
690 #endif
691 
692  /* Check if we have a section object and map the system DLL */
694 
695  /* Create a handle for the Process */
696  CidEntry.Object = Process;
697  CidEntry.GrantedAccess = 0;
698  Process->UniqueProcessId = ExCreateHandle(PspCidTable, &CidEntry);
699  if (!Process->UniqueProcessId)
700  {
701  /* Fail */
703  goto CleanupWithRef;
704  }
705 
706  /* Set the handle table PID */
707  Process->ObjectTable->UniqueProcessId = Process->UniqueProcessId;
708 
709  /* Check if we need to audit */
711 
712  /* Check if the parent had a job */
713  if ((Parent) && (Parent->Job))
714  {
715  /* FIXME: We need to insert this process */
716  DPRINT1("Jobs not yet supported\n");
717  }
718 
719  /* Create PEB only for User-Mode Processes */
720  if ((Parent) && (NeedsPeb))
721  {
722  //
723  // Set up the initial PEB
724  //
725  RtlZeroMemory(&InitialPeb, sizeof(INITIAL_PEB));
726  InitialPeb.Mutant = (HANDLE)-1;
727  InitialPeb.ImageUsesLargePages = 0; // FIXME: Not yet supported
728 
729  //
730  // Create it only if we have an image section
731  //
732  if (SectionHandle)
733  {
734  //
735  // Create it
736  //
737  Status = MmCreatePeb(Process, &InitialPeb, &Process->Peb);
738  if (!NT_SUCCESS(Status)) goto CleanupWithRef;
739  }
740  else
741  {
742  //
743  // We have to clone it
744  //
745  ASSERTMSG("No support for cloning yet\n", FALSE);
746  }
747 
748  }
749 
750  /* The process can now be activated */
752  InsertTailList(&PsActiveProcessHead, &Process->ActiveProcessLinks);
754 
755  /* Create an access state */
756  Status = SeCreateAccessStateEx(CurrentThread,
757  ((Parent) &&
760  &LocalAccessState,
761  &AuxData,
764  if (!NT_SUCCESS(Status)) goto CleanupWithRef;
765 
766  /* Insert the Process into the Object Directory */
768  AccessState,
770  1,
771  NULL,
772  &hProcess);
773 
774  /* Free the access state */
776 
777  /* Cleanup on failure */
778  if (!NT_SUCCESS(Status)) goto Cleanup;
779 
780  /* Compute Quantum and Priority */
781  ASSERT(IsListEmpty(&Process->ThreadListHead) == TRUE);
782  Process->Pcb.BasePriority =
785  &Quantum);
786  Process->Pcb.QuantumReset = Quantum;
787 
788  /* Check if we have a parent other then the initial system process */
789  Process->GrantedAccess = PROCESS_TERMINATE;
790  if ((Parent) && (Parent != PsInitialSystemProcess))
791  {
792  /* Get the process's SD */
795  &SdAllocated);
796  if (!NT_SUCCESS(Status))
797  {
798  /* We failed, close the handle and clean up */
800  goto CleanupWithRef;
801  }
802 
803  /* Create the subject context */
804  SubjectContext.ProcessAuditId = Process;
806  SubjectContext.ClientToken = NULL;
807 
808  /* Do the access check */
811  FALSE,
813  0,
814  NULL,
816  PreviousMode,
817  &Process->GrantedAccess,
818  &AccessStatus);
819 
820  /* Dereference the token and let go the SD */
822  SubjectContext.PrimaryToken);
824 
825  /* Remove access if it failed */
826  if (!Result) Process->GrantedAccess = 0;
827 
828  /* Give the process some basic access */
829  Process->GrantedAccess |= (PROCESS_VM_OPERATION |
840  }
841  else
842  {
843  /* Set full granted access */
844  Process->GrantedAccess = PROCESS_ALL_ACCESS;
845  }
846 
847  /* Set the Creation Time */
848  KeQuerySystemTime(&Process->CreateTime);
849 
850  /* Protect against bad user-mode pointer */
851  _SEH2_TRY
852  {
853  /* Hacky way of returning the PEB to the user-mode creator */
854  if ((Process->Peb) && (CurrentThread->Tcb.Teb))
855  {
856  CurrentThread->Tcb.Teb->NtTib.ArbitraryUserPointer = Process->Peb;
857  }
858 
859  /* Save the process handle */
861  }
863  {
864  /* Get the exception code */
866  }
867  _SEH2_END;
868 
869  /* Run the Notification Routines */
871 
872  /* If 12 processes have been created, enough of user-mode is ready */
873  if (++ProcessCount == 12) Ki386PerfEnd();
874 
875 CleanupWithRef:
876  /*
877  * Dereference the process. For failures, kills the process and does
878  * cleanup present in PspDeleteProcess. For success, kills the extra
879  * reference added by ObInsertObject.
880  */
882 
883 Cleanup:
884  /* Dereference the parent */
886 
887  /* Return status to caller */
888  return Status;
889 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
BOOLEAN NTAPI SeAccessCheck(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext, IN BOOLEAN SubjectContextLocked, IN ACCESS_MASK DesiredAccess, IN ACCESS_MASK PreviouslyGrantedAccess, OUT PPRIVILEGE_SET *Privileges, IN PGENERIC_MAPPING GenericMapping, IN KPROCESSOR_MODE AccessMode, OUT PACCESS_MASK GrantedAccess, OUT PNTSTATUS AccessStatus)
Definition: accesschk.c:340
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
VOID NTAPI PspInheritQuota(IN PEPROCESS Process, IN PEPROCESS ParentProcess)
#define PROCESS_CREATE_FLAGS_LEGAL_MASK
Definition: pstypes.h:97
_Inout_ PLIST_ENTRY _In_ PVOID _In_ PSTRING _In_ BOOLEAN _In_ BOOLEAN _In_ ULONG _In_ PFLT_CALLBACK_DATA _In_opt_ PCHECK_FOR_TRAVERSE_ACCESS _In_opt_ PSECURITY_SUBJECT_CONTEXT SubjectContext
Definition: fltkernel.h:2239
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PROCESS_ALL_ACCESS
Definition: nt_native.h:1324
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:158
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
#define SEM_NOALIGNMENTFAULTEXCEPT
Definition: rtltypes.h:71
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK _Out_ PNTSTATUS AccessStatus
Definition: sefuncs.h:13
NTKERNELAPI VOID FASTCALL ExReleaseRundownProtection(_Inout_ PEX_RUNDOWN_REF RunRef)
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:182
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
INIT_FUNCTION NTSTATUS NTAPI MmInitializeHandBuiltProcess(IN PEPROCESS Process, IN PULONG_PTR DirectoryTableBase)
Definition: procsup.c:1033
LONG NTSTATUS
Definition: precomp.h:26
KTHREAD Tcb
Definition: pstypes.h:1034
#define ExAcquireRundownProtection
Definition: ex.h:130
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PHANDLE_TABLE PspCidTable
Definition: psmgr.c:48
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:722
#define PROCESS_CREATE_FLAGS_LARGE_PAGES
Definition: pstypes.h:95
#define InsertTailList(ListHead, Entry)
NTSTATUS NTAPI PspMapSystemDll(IN PEPROCESS Process, OUT PVOID *DllBase, IN BOOLEAN UseLargePages)
ULONG PsMinimumWorkingSet
Definition: psmgr.c:54
NTKERNELAPI VOID FASTCALL ExInitializeRundownProtection(_Out_ PEX_RUNDOWN_REF RunRef)
VOID NTAPI KeInitializeProcess(struct _KPROCESS *Process, KPRIORITY Priority, KAFFINITY Affinity, PULONG_PTR DirectoryTableBase, IN BOOLEAN Enable)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define PAGED_CODE()
Definition: video.h:57
ULONG ProcessCount
Definition: perfdata.c:37
#define PROCESS_CREATE_THREAD
Definition: pstypes.h:150
_SEH2_TRY
Definition: create.c:4250
LIST_ENTRY PsActiveProcessHead
Definition: process.c:22
uint32_t ULONG_PTR
Definition: typedefs.h:63
HANDLE NTAPI ExCreateHandle(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:791
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
KPRIORITY NTAPI PspComputeQuantumAndPriority(IN PEPROCESS Process, IN PSPROCESSPRIORITYMODE Mode, OUT PUCHAR Quantum)
Definition: process.c:174
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define PROCESS_DUP_HANDLE
#define PROCESS_PRIORITY_NORMAL
Definition: pstypes.h:118
#define PsGetCurrentProcess
Definition: psfuncs.h:17
Definition: extypes.h:595
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
VOID NTAPI ObReleaseObjectSecurity(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN BOOLEAN MemoryAllocated)
Definition: obsecure.c:709
unsigned char BOOLEAN
BOOLEAN ImageUsesLargePages
Definition: pstypes.h:655
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
FORCEINLINE VOID Ki386PerfEnd(VOID)
Definition: ke.h:893
#define PROCESS_PRIORITY_CLASS_NORMAL
Definition: pstypes.h:108
#define PROCESS_SET_QUOTA
Definition: pstypes.h:156
#define PSF_HAS_ADDRESS_SPACE_BIT
Definition: pstypes.h:274
NTSTATUS NTAPI ObGetObjectSecurity(IN PVOID Object, OUT PSECURITY_DESCRIPTOR *SecurityDescriptor, OUT PBOOLEAN MemoryAllocated)
Definition: obsecure.c:611
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
POBJECT_TYPE LpcPortObjectType
Definition: port.c:17
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
INIT_FUNCTION NTSTATUS NTAPI MmInitializeHandBuiltProcess2(IN PEPROCESS Process)
Definition: procsup.c:1058
ULONG CurrentProcess
Definition: shell.c:125
#define PROCESS_CREATE_FLAGS_INHERIT_HANDLES
Definition: pstypes.h:93
#define PROCESS_VM_WRITE
Definition: pstypes.h:154
VOID NTAPI DbgkCopyProcessDebugPort(IN PEPROCESS Process, IN PEPROCESS Parent)
Definition: dbgkobj.c:276
NTSTATUS NTAPI MmCreatePeb(IN PEPROCESS Process, IN PINITIAL_PEB InitialPeb, OUT PPEB *BasePeb)
Definition: procsup.c:500
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define PSF_NO_DEBUG_INHERIT_BIT
Definition: pstypes.h:258
NTSTATUS NTAPI MmInitializeProcessAddressSpace(IN PEPROCESS Process, IN PEPROCESS Clone OPTIONAL, IN PVOID Section OPTIONAL, IN OUT PULONG Flags, IN POBJECT_NAME_INFORMATION *AuditName OPTIONAL)
#define STATUS_PROCESS_IS_TERMINATING
Definition: ntstatus.h:488
ULONG GrantedAccess
Definition: extypes.h:606
FORCEINLINE VOID PspRunCreateProcessNotifyRoutines(IN PEPROCESS CurrentProcess, IN BOOLEAN Create)
Definition: ps_x.h:62
signed char SCHAR
Definition: sqltypes.h:14
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:170
#define PROCESS_CREATE_PROCESS
Definition: pstypes.h:155
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
static HANDLE(WINAPI *pCreateJobObjectW)(LPSECURITY_ATTRIBUTES sa
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:414
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
VOID NTAPI SeAuditProcessCreate(IN PEPROCESS Process)
Definition: audit.c:33
#define InterlockedOr
Definition: interlocked.h:224
PACCESS_TOKEN NTAPI PsReferencePrimaryToken(PEPROCESS Process)
Definition: security.c:440
static const WCHAR Cleanup[]
Definition: register.c:80
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
#define PS_PROCESS_DEBUG
Definition: ps.h:18
#define PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT
Definition: pstypes.h:92
KAFFINITY KeActiveProcessors
Definition: krnlinit.c:23
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:940
BOOLEAN NTAPI MmCreateProcessAddressSpace(IN ULONG MinWs, IN PEPROCESS Dest, IN PULONG_PTR DirectoryTableBase)
Status
Definition: gdiplustypes.h:24
#define DbgkDebugObjectType
Definition: ObTypes.c:125
HANDLE Mutant
Definition: pstypes.h:668
_SEH2_END
Definition: create.c:4424
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2932
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
#define PROCESS_TERMINATE
Definition: pstypes.h:149
ULONG_PTR KAFFINITY
Definition: compat.h:75
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
VOID NTAPI SeDeleteAccessState(IN PACCESS_STATE AccessState)
Definition: access.c:460
KGUARDED_MUTEX PspActiveProcessMutex
Definition: process.c:23
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
ULONG PsMaximumWorkingSet
Definition: psmgr.c:54
PVOID Teb
Definition: ketypes.h:1697
#define DPRINT1
Definition: precomp.h:8
#define PROCESS_VM_READ
Definition: pstypes.h:153
VOID FASTCALL ObFastDereferenceObject(IN PEX_FAST_REF FastRef, IN PVOID Object)
Definition: obref.c:169
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define PORT_ALL_ACCESS
Definition: lpctypes.h:47
#define DEBUG_OBJECT_ADD_REMOVE_PROCESS
Definition: dbgktypes.h:32
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned int ULONG
Definition: retypes.h:1
#define SECTION_MAP_EXECUTE
Definition: nt_native.h:1290
NTSTATUS NTAPI ObInitProcess(IN PEPROCESS Parent OPTIONAL, IN PEPROCESS Process)
Definition: obhandle.c:2087
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
PVOID Object
Definition: extypes.h:599
#define PROCESS_VM_OPERATION
Definition: pstypes.h:152
NTSTATUS NTAPI PspInitializeProcessSecurity(IN PEPROCESS Process, IN PEPROCESS Parent OPTIONAL)
Definition: security.c:71
#define PROCESS_SET_INFORMATION
Definition: pstypes.h:157
#define PROCESS_PRIORITY_CLASS_BELOW_NORMAL
Definition: pstypes.h:111
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define TAG_SEPA
Definition: tag.h:189
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
NTSTATUS NTAPI SeCreateAccessStateEx(IN PETHREAD Thread, IN PEPROCESS Process, IN OUT PACCESS_STATE AccessState, IN PAUX_ACCESS_DATA AuxData, IN ACCESS_MASK Access, IN PGENERIC_MAPPING GenericMapping)
Definition: access.c:378
BOOLEAN NTAPI SeDetailedAuditingWithToken(IN PTOKEN Token)
Definition: audit.c:25
#define PROCESS_PRIORITY_CLASS_IDLE
Definition: pstypes.h:107
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:2966
signed int * PLONG
Definition: retypes.h:5
POBJECT_TYPE PsProcessType
Definition: process.c:20
VOID NTAPI ObInheritDeviceMap(IN PEPROCESS Parent, IN PEPROCESS Process)
Definition: devicemap.c:511

Referenced by NtCreateProcessEx(), PsCreateSystemProcess(), and PspInitPhase0().

◆ PsSetProcessPriorityByClass()

VOID NTAPI PsSetProcessPriorityByClass ( IN PEPROCESS  Process,
IN PSPROCESSPRIORITYMODE  Type 
)

Definition at line 1325 of file process.c.

1327 {
1328  UCHAR Quantum;
1329  ULONG Priority;
1330  PSTRACE(PS_PROCESS_DEBUG, "Process: %p Type: %lx\n", Process, Type);
1331 
1332  /* Compute quantum and priority */
1334 
1335  /* Set them */
1337 }
Type
Definition: Type.h:6
_In_ KPRIORITY Priority
Definition: kefuncs.h:516
KPRIORITY NTAPI PspComputeQuantumAndPriority(IN PEPROCESS Process, IN PSPROCESSPRIORITYMODE Mode, OUT PUCHAR Quantum)
Definition: process.c:174
unsigned char UCHAR
Definition: xmlstorage.h:181
KPRIORITY NTAPI KeSetPriorityAndQuantumProcess(IN PKPROCESS Process, IN KPRIORITY Priority, IN UCHAR Quantum OPTIONAL)
Definition: procobj.c:349
#define PS_PROCESS_DEBUG
Definition: ps.h:18
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define PSTRACE(x, fmt,...)
Definition: ps.h:57

Referenced by NtSetInformationProcess().

◆ PsSetProcessPriorityClass()

VOID NTAPI PsSetProcessPriorityClass ( PEPROCESS  Process,
ULONG  PriorityClass 
)

Definition at line 1234 of file process.c.

1236 {
1237  Process->PriorityClass = (UCHAR)PriorityClass;
1238 }
unsigned char UCHAR
Definition: xmlstorage.h:181
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ PsSetProcessSecurityPort()

NTSTATUS NTAPI PsSetProcessSecurityPort ( PEPROCESS  Process,
PVOID  SecurityPort 
)

Definition at line 1245 of file process.c.

1247 {
1248  Process->SecurityPort = SecurityPort;
1249  return STATUS_SUCCESS;
1250 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ PsSetProcessWin32Process()

NTSTATUS NTAPI PsSetProcessWin32Process ( _Inout_ PEPROCESS  Process,
_In_opt_ PVOID  Win32Process,
_In_opt_ PVOID  OldWin32Process 
)

Definition at line 1257 of file process.c.

1261 {
1262  NTSTATUS Status;
1263 
1264  /* Assume success */
1266 
1267  /* Lock the process */
1269  ExAcquirePushLockExclusive(&Process->ProcessLock);
1270 
1271  /* Check if we set a new win32 process */
1272  if (Win32Process != NULL)
1273  {
1274  /* Check if the process is in the right state */
1275  if (((Process->Flags & PSF_PROCESS_DELETE_BIT) == 0) &&
1276  (Process->Win32Process == NULL))
1277  {
1278  /* Set the new win32 process */
1279  Process->Win32Process = Win32Process;
1280  }
1281  else
1282  {
1283  /* Otherwise fail */
1285  }
1286  }
1287  else
1288  {
1289  /* Reset the win32 process, did the caller specify the correct old value? */
1290  if (Process->Win32Process == OldWin32Process)
1291  {
1292  /* Yes, so reset the win32 process to NULL */
1293  Process->Win32Process = NULL;
1294  }
1295  else
1296  {
1297  /* Otherwise fail */
1299  }
1300  }
1301 
1302  /* Unlock the process */
1303  ExReleasePushLockExclusive(&Process->ProcessLock);
1305 
1306  return Status;
1307 }
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1022
LONG NTSTATUS
Definition: precomp.h:26
FORCEINLINE VOID ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1238
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_PROCESS_IS_TERMINATING
Definition: ntstatus.h:488
#define PSF_PROCESS_DELETE_BIT
Definition: pstypes.h:260
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
Status
Definition: gdiplustypes.h:24
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AllocW32Process(), and ExitProcessCallback().

◆ PsSetProcessWindowStation()

VOID NTAPI PsSetProcessWindowStation ( PEPROCESS  Process,
PVOID  WindowStation 
)

Definition at line 1314 of file process.c.

1316 {
1317  Process->Win32WindowStation = WindowStation;
1318 }
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by UserSetProcessWindowStation().

Variable Documentation

◆ PsActiveProcessHead

LIST_ENTRY PsActiveProcessHead

Definition at line 22 of file process.c.

Referenced by GspQuery(), KdbpCmdProc(), PsGetNextProcess(), PspCreateProcess(), and PspInitPhase0().

◆ PsMaximumWorkingSet

ULONG PsMaximumWorkingSet

Definition at line 54 of file psmgr.c.

Referenced by PspCreateProcess(), and PspInitPhase0().

◆ PsMinimumWorkingSet

ULONG PsMinimumWorkingSet

Definition at line 54 of file psmgr.c.

Referenced by PspCreateProcess(), and PspInitPhase0().

◆ PspActiveProcessMutex

KGUARDED_MUTEX PspActiveProcessMutex

Definition at line 23 of file process.c.

Referenced by PsGetNextProcess(), PspCreateProcess(), PspDeleteProcess(), and PspInitPhase0().

◆ PspFixedQuantums

CHAR PspFixedQuantums[6]
Initial value:
=
{
3 * 6,
3 * 6,
3 * 6,
6 * 6,
6 * 6,
6 * 6
}

Definition at line 32 of file process.c.

Referenced by PsChangeQuantumTable().

◆ PspForegroundQuantum

CHAR PspForegroundQuantum[3]

Definition at line 29 of file process.c.

Referenced by PsChangeQuantumTable(), and PspComputeQuantumAndPriority().

◆ PspPriorityTable

Initial value:
=
{
8,
4,
8,
13,
24,
6,
10
}

Definition at line 60 of file process.c.

Referenced by PspComputeQuantumAndPriority().

◆ PsPrioritySeparation

ULONG PsPrioritySeparation

◆ PsProcessType

◆ PspVariableQuantums

CHAR PspVariableQuantums[6]
Initial value:
=
{
1 * 6,
2 * 6,
3 * 6,
2 * 6,
4 * 6,
6 * 6
}

Definition at line 46 of file process.c.

Referenced by PsChangeQuantumTable().

◆ PsRawPrioritySeparation

ULONG PsRawPrioritySeparation

Definition at line 27 of file process.c.

Referenced by PspInitPhase0().

◆ ShortPsLockDelay

LARGE_INTEGER ShortPsLockDelay

Definition at line 25 of file process.c.