ReactOS 0.4.17-dev-691-gfdddc52
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)
 
 _IRQL_requires_max_ (PASSIVE_LEVEL)
 

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

◆ _IRQL_requires_max_()

_IRQL_requires_max_ ( PASSIVE_LEVEL  )

Definition at line 1648 of file process.c.

1653{
1654 ULONG64 CurrentCycleTime, TotalCycleTime;
1655 KIRQL OldIrql;
1656
1657 /* Raise IRQL, so we stay on the same processor */
1659
1660#ifdef CONFIG_SMP
1661 // FIXME should send an IPI to all processors running this process to update
1662 // their cycle times.
1663#endif
1664
1665 /* Get the current cycle time */
1666 CurrentCycleTime = KxQueryProcessorCycleTime();
1667
1668 /* Get the process' cycle time */
1669 TotalCycleTime = Process->CycleTime;
1670
1671 /* Check if this is the current process */
1673 {
1674 /* Add the additional cycle time from the current thread */
1675 TotalCycleTime += CurrentCycleTime - KeGetCurrentPrcb()->StartCycles;
1676 }
1677
1678 /* Lower IRQL */
1680
1681 /* Return the current cycle time as the time stamp */
1682 if (CycleTimeStamp)
1683 {
1684 *CycleTimeStamp = CurrentCycleTime;
1685 }
1686
1687 /* Return the total cycle time */
1688 return TotalCycleTime;
1689}
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment KeRaiseIrqlToDpcLevel
Definition: CrNtStubs.h:68
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
unsigned __int64 ULONG64
Definition: imports.h:198
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1197
FORCEINLINE ULONG64 KxQueryProcessorCycleTime(VOID)
Definition: ke.h:209
_Out_ PULONG64 CycleTimeStamp
Definition: ke.h:1091
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
#define PsGetCurrentProcess
Definition: psfuncs.h:17

◆ 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 1435 of file process.c.

1443{
1444 ULONG Flags = 0;
1446 "Parent: %p Attributes: %p\n", ParentProcess, ObjectAttributes);
1447
1448 /* Set new-style flags */
1449 if ((ULONG_PTR)SectionHandle & 1) Flags |= PROCESS_CREATE_FLAGS_BREAKAWAY;
1451 if (InheritObjectTable) Flags |= PROCESS_CREATE_FLAGS_INHERIT_HANDLES;
1452
1453 /* Call the new API */
1457 ParentProcess,
1458 Flags,
1459 SectionHandle,
1460 DebugPort,
1461 ExceptionPort,
1462 FALSE);
1463}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define FALSE
Definition: types.h:117
#define PROCESS_CREATE_FLAGS_BREAKAWAY
Definition: pstypes.h:87
#define PROCESS_CREATE_FLAGS_INHERIT_HANDLES
Definition: pstypes.h:89
#define PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT
Definition: pstypes.h:88
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:407
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:1374
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
#define PS_PROCESS_DEBUG
Definition: ps.h:18
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2664
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

◆ 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 1374 of file process.c.

1383{
1386 PAGED_CODE();
1388 "ParentProcess: %p Flags: %lx\n", ParentProcess, Flags);
1389
1390 /* Check if we came from user mode */
1391 if (PreviousMode != KernelMode)
1392 {
1393 _SEH2_TRY
1394 {
1395 /* Probe process handle */
1397 }
1399 {
1400 /* Return the exception code */
1402 }
1403 _SEH2_END;
1404 }
1405
1406 /* Make sure there's a parent process */
1407 if (!ParentProcess)
1408 {
1409 /* Can't create System Processes like this */
1411 }
1412 else
1413 {
1414 /* Create a user Process */
1418 ParentProcess,
1419 Flags,
1420 SectionHandle,
1421 DebugPort,
1422 ExceptionPort,
1423 InJob);
1424 }
1425
1426 /* Return Status */
1427 return Status;
1428}
#define PAGED_CODE()
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG _In_ KPROCESSOR_MODE PreviousMode
LONG NTSTATUS
Definition: precomp.h:26
#define ExGetPreviousMode
Definition: ex.h:143
Status
Definition: gdiplustypes.h:24
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define KernelMode
Definition: asm.h:38
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
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:204
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:207
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7

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 1470 of file process.c.

1474{
1476 CLIENT_ID SafeClientId;
1477 ULONG Attributes = 0;
1479 BOOLEAN HasObjectName = FALSE;
1484 AUX_ACCESS_DATA AuxData;
1485 PAGED_CODE();
1487 "ClientId: %p Attributes: %p\n", ClientId, ObjectAttributes);
1488
1489 /* Check if we were called from user mode */
1490 if (PreviousMode != KernelMode)
1491 {
1492 /* Enter SEH for probing */
1493 _SEH2_TRY
1494 {
1495 /* Probe the thread handle */
1497
1498 /* Check for a CID structure */
1499 if (ClientId)
1500 {
1501 /* Probe and capture it */
1502 ProbeForRead(ClientId, sizeof(CLIENT_ID), sizeof(ULONG));
1503 SafeClientId = *ClientId;
1504 ClientId = &SafeClientId;
1505 }
1506
1507 /*
1508 * Just probe the object attributes structure, don't capture it
1509 * completely. This is done later if necessary
1510 */
1512 sizeof(OBJECT_ATTRIBUTES),
1513 sizeof(ULONG));
1514 HasObjectName = (ObjectAttributes->ObjectName != NULL);
1515
1516 /* Validate user attributes */
1518 }
1520 {
1521 /* Return the exception code */
1523 }
1524 _SEH2_END;
1525 }
1526 else
1527 {
1528 /* Otherwise just get the data directly */
1529 HasObjectName = (ObjectAttributes->ObjectName != NULL);
1530
1531 /* Still have to sanitize attributes */
1533 }
1534
1535 /* Can't pass both, fail */
1536 if ((HasObjectName) && (ClientId)) return STATUS_INVALID_PARAMETER_MIX;
1537
1538 /* Create an access state */
1540 &AuxData,
1543 if (!NT_SUCCESS(Status)) return Status;
1544
1545 /* Check if this is a debugger */
1547 {
1548 /* Did he want full access? */
1549 if (AccessState.RemainingDesiredAccess & MAXIMUM_ALLOWED)
1550 {
1551 /* Give it to him */
1552 AccessState.PreviouslyGrantedAccess |= PROCESS_ALL_ACCESS;
1553 }
1554 else
1555 {
1556 /* Otherwise just give every other access he could want */
1557 AccessState.PreviouslyGrantedAccess |=
1558 AccessState.RemainingDesiredAccess;
1559 }
1560
1561 /* The caller desires nothing else now */
1562 AccessState.RemainingDesiredAccess = 0;
1563 }
1564
1565 /* Open by name if one was given */
1566 if (HasObjectName)
1567 {
1568 /* Open it */
1572 &AccessState,
1573 0,
1574 NULL,
1575 &hProcess);
1576
1577 /* Get rid of the access state */
1579 }
1580 else if (ClientId)
1581 {
1582 /* Open by Thread ID */
1584 {
1585 /* Get the Process */
1587 }
1588 else
1589 {
1590 /* Get the Process */
1592 &Process);
1593 }
1594
1595 /* Check if we didn't find anything */
1596 if (!NT_SUCCESS(Status))
1597 {
1598 /* Get rid of the access state and return */
1600 return Status;
1601 }
1602
1603 /* Open the Process Object */
1605 Attributes,
1606 &AccessState,
1607 0,
1610 &hProcess);
1611
1612 /* Delete the access state */
1614
1615 /* Dereference the thread if we used it */
1617
1618 /* Dereference the Process */
1620 }
1621 else
1622 {
1623 /* neither an object name nor a client id was passed */
1625 }
1626
1627 /* Check for success */
1628 if (NT_SUCCESS(Status))
1629 {
1630 /* Use SEH for write back */
1631 _SEH2_TRY
1632 {
1633 /* Write back the handle */
1635 }
1637 {
1638 /* Get the exception code */
1640 }
1641 _SEH2_END;
1642 }
1643
1644 /* Return status */
1645 return Status;
1646}
unsigned char BOOLEAN
Definition: actypes.h:127
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
#define KeGetPreviousMode()
Definition: ketypes.h:1115
#define PROCESS_ALL_ACCESS
Definition: nt_native.h:1327
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
const LUID SeDebugPrivilege
Definition: priv.c:39
POBJECT_TYPE PsProcessType
Definition: process.c:20
NTSTATUS NTAPI PsLookupProcessThreadByCid(IN PCLIENT_ID Cid, OUT PEPROCESS *Process OPTIONAL, OUT PETHREAD *Thread)
Definition: process.c:991
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:949
VOID NTAPI SeDeleteAccessState(_In_ PACCESS_STATE AccessState)
Deletes an allocated access state from the memory.
Definition: access.c:150
NTSTATUS NTAPI SeCreateAccessState(_Out_ PACCESS_STATE AccessState, _Out_ __drv_aliasesMem PAUX_ACCESS_DATA AuxData, _In_ ACCESS_MASK Access, _In_ PGENERIC_MAPPING GenericMapping)
Creates an access state.
Definition: access.c:121
BOOLEAN NTAPI SeSinglePrivilegeCheck(_In_ LUID PrivilegeValue, _In_ KPROCESSOR_MODE PreviousMode)
Checks if a single privilege is present in the context of the calling thread.
Definition: priv.c:744
#define STATUS_INVALID_PARAMETER_MIX
Definition: ntstatus.h:378
FORCEINLINE ULONG ObpValidateAttributes(IN ULONG Attributes, IN KPROCESSOR_MODE PreviousMode)
Definition: ob_x.h:22
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:2764
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:2554
HANDLE UniqueThread
Definition: compat.h:826
HANDLE UniqueProcess
Definition: compat.h:825
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:379
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:411
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1151
#define ObDereferenceObject
Definition: obfuncs.h:203
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:417

Referenced by CSR_API(), LsapAddNotification(), LsapCheckLogonProcess(), LsapEnumLogonSessions(), LsapGetLogonSessionData(), Main(), OpenProcess(), PrintProcess(), ProcessIdToHandle(), ProcessIdToSessionId(), RtlQueryProcessDebugInformation(), SmpExecPgm(), SmpHandleConnectionRequest(), test_query_process(), 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}
#define TRUE
Definition: types.h:120
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
#define PROCESS_PRIORITY_CLASS_IDLE
Definition: pstypes.h:103
#define PSP_VARIABLE_QUANTUMS
Definition: pstypes.h:128
#define PSP_LONG_QUANTUMS
Definition: pstypes.h:130
#define PSP_FIXED_QUANTUMS
Definition: pstypes.h:129
#define MEMORY_PRIORITY_BACKGROUND
Definition: pstypes.h:120
#define PSP_SHORT_QUANTUMS
Definition: pstypes.h:131
#define NOTHING
Definition: input_list.c:10
BOOLEAN NTAPI MmIsThisAnNtAsSystem(VOID)
Definition: mmsup.c:246
VOID NTAPI KeSetQuantumProcess(IN PKPROCESS Process, IN UCHAR Quantum)
Definition: procobj.c:229
PEPROCESS NTAPI PsGetNextProcess(IN PEPROCESS OldProcess)
Definition: process.c:128
CHAR PspForegroundQuantum[3]
Definition: process.c:29
ULONG PsPrioritySeparation
Definition: process.c:28
CHAR PspFixedQuantums[6]
Definition: process.c:32
CHAR PspVariableQuantums[6]
Definition: process.c:46
BOOLEAN PspUseJobSchedulingClasses
Definition: job.c:28
CHAR PspJobSchedulingClasses[PSP_JOB_SCHEDULING_CLASSES]
Definition: job.c:30
#define PspPrioritySeparationFromMask(Mask)
Definition: ps_x.h:13
#define PspQuantumTypeFromMask(Mask)
Definition: ps_x.h:16
#define PspQuantumLengthFromMask(Mask)
Definition: ps_x.h:19
unsigned char UCHAR
Definition: typedefs.h:53
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
char * PCHAR
Definition: typedefs.h:51

Referenced by PspInitPhase0(), and SSI_DEF().

◆ PsCreateSystemProcess()

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

Definition at line 928 of file process.c.

931{
932 /* Call the internal API */
936 NULL,
937 0,
938 NULL,
939 NULL,
940 NULL,
941 FALSE);
942}

◆ PsGetCurrentProcessId()

◆ PsGetCurrentProcessSessionId()

◆ PsGetCurrentProcessWin32Process()

PVOID NTAPI PsGetCurrentProcessWin32Process ( VOID  )

◆ PsGetNextProcess()

PEPROCESS NTAPI PsGetNextProcess ( IN PEPROCESS OldProcess  OPTIONAL)

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}
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
LIST_ENTRY PsActiveProcessHead
Definition: process.c:22
KGUARDED_MUTEX PspActiveProcessMutex
Definition: process.c:23
BOOLEAN FASTCALL ObReferenceObjectSafe(IN PVOID Object)
Definition: obref.c:22
Entry
Definition: section.c:5216
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

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

◆ 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}
FORCEINLINE VOID ExAcquirePushLockShared(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1108
FORCEINLINE VOID ExReleasePushLockShared(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1216
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
LIST_ENTRY ThreadListEntry
Definition: pstypes.h:1268

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

◆ PsGetProcessCreateTimeQuadPart()

LONGLONG NTAPI PsGetProcessCreateTimeQuadPart ( PEPROCESS  Process)

Definition at line 1053 of file process.c.

1054{
1055 return Process->CreateTime.QuadPart;
1056}
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by KsecGetKeyData().

◆ PsGetProcessDebugPort()

PVOID NTAPI PsGetProcessDebugPort ( PEPROCESS  Process)

Definition at line 1063 of file process.c.

1064{
1065 return Process->DebugPort;
1066}

◆ PsGetProcessExitProcessCalled()

BOOLEAN NTAPI PsGetProcessExitProcessCalled ( PEPROCESS  Process)

Definition at line 1073 of file process.c.

1074{
1075 return (BOOLEAN)Process->ProcessExiting;
1076}

Referenced by NtUserWaitForInputIdle().

◆ PsGetProcessExitStatus()

NTSTATUS NTAPI PsGetProcessExitStatus ( PEPROCESS  Process)

Definition at line 1083 of file process.c.

1084{
1085 return Process->ExitStatus;
1086}

Referenced by ExitThreadCallback().

◆ PsGetProcessExitTime()

LARGE_INTEGER NTAPI PsGetProcessExitTime ( VOID  )

Definition at line 1043 of file process.c.

1044{
1045 return PsGetCurrentProcess()->ExitTime;
1046}

◆ PsGetProcessId()

HANDLE NTAPI PsGetProcessId ( PEPROCESS  Process)

Definition at line 1093 of file process.c.

1094{
1095 return (HANDLE)Process->UniqueProcessId;
1096}

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

◆ PsGetProcessImageFileName()

LPSTR NTAPI PsGetProcessImageFileName ( PEPROCESS  Process)

Definition at line 1103 of file process.c.

1104{
1105 return (LPSTR)Process->ImageFileName;
1106}
char * LPSTR
Definition: typedefs.h:51

◆ PsGetProcessInheritedFromUniqueProcessId()

HANDLE NTAPI PsGetProcessInheritedFromUniqueProcessId ( PEPROCESS  Process)

Definition at line 1113 of file process.c.

1114{
1115 return Process->InheritedFromUniqueProcessId;
1116}

◆ PsGetProcessJob()

PEJOB NTAPI PsGetProcessJob ( PEPROCESS  Process)

Definition at line 1123 of file process.c.

1124{
1125 return Process->Job;
1126}

◆ PsGetProcessPeb()

PPEB NTAPI PsGetProcessPeb ( PEPROCESS  Process)

Definition at line 1133 of file process.c.

1134{
1135 return Process->Peb;
1136}

◆ PsGetProcessPriorityClass()

ULONG NTAPI PsGetProcessPriorityClass ( PEPROCESS  Process)

Definition at line 1143 of file process.c.

1144{
1145 return Process->PriorityClass;
1146}

◆ PsGetProcessSectionBaseAddress()

PVOID NTAPI PsGetProcessSectionBaseAddress ( PEPROCESS  Process)

Definition at line 1173 of file process.c.

1174{
1175 return Process->SectionBaseAddress;
1176}

◆ PsGetProcessSecurityPort()

PVOID NTAPI PsGetProcessSecurityPort ( PEPROCESS  Process)

Definition at line 1183 of file process.c.

1184{
1185 return Process->SecurityPort;
1186}

◆ PsGetProcessSessionId()

ULONG NTAPI PsGetProcessSessionId ( IN PEPROCESS  Process)

◆ PsGetProcessSessionIdEx()

ULONG NTAPI PsGetProcessSessionIdEx ( IN PEPROCESS  Process)

Definition at line 1203 of file process.c.

1204{
1205 return MmGetSessionIdEx(Process);
1206}
ULONG NTAPI MmGetSessionIdEx(IN PEPROCESS Process)
Definition: session.c:194

◆ PsGetProcessWin32Process()

◆ PsGetProcessWin32WindowStation()

PVOID NTAPI PsGetProcessWin32WindowStation ( PEPROCESS  Process)

Definition at line 1233 of file process.c.

1234{
1235 return Process->Win32WindowStation;
1236}

Referenced by UserSetProcessWindowStation().

◆ PsIsProcessBeingDebugged()

BOOLEAN NTAPI PsIsProcessBeingDebugged ( PEPROCESS  Process)

Definition at line 1243 of file process.c.

1244{
1245 return Process->DebugPort != NULL;
1246}

◆ PsIsSystemProcess()

BOOLEAN NTAPI PsIsSystemProcess ( IN PEPROCESS  Process)

Definition at line 1253 of file process.c.

1254{
1255 /* Return if this is the System Process */
1257}
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50

Referenced by IntHookModuleUnloaded(), and UserRegisterUserApiHook().

◆ PsLookupProcessByProcessId()

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

Definition at line 949 of file process.c.

951{
952 PHANDLE_TABLE_ENTRY CidEntry;
953 PEPROCESS FoundProcess;
955 PAGED_CODE();
956 PSTRACE(PS_PROCESS_DEBUG, "ProcessId: %p\n", ProcessId);
958
959 /* Get the CID Handle Entry */
961 if (CidEntry)
962 {
963 /* Get the Process */
964 FoundProcess = CidEntry->Object;
965
966 /* Make sure it's really a process */
967 if (FoundProcess->Pcb.Header.Type == ProcessObject)
968 {
969 /* Safe Reference and return it */
970 if (ObReferenceObjectSafe(FoundProcess))
971 {
972 *Process = FoundProcess;
974 }
975 }
976
977 /* Unlock the Entry */
979 }
980
981 /* Return to caller */
983 return Status;
984}
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2712
@ ProcessObject
Definition: ketypes.h:428
PHANDLE_TABLE_ENTRY NTAPI ExMapHandleToPointer(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle)
Definition: handle.c:1046
VOID NTAPI ExUnlockHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:923
PHANDLE_TABLE PspCidTable
Definition: psmgr.c:48
#define STATUS_SUCCESS
Definition: shellext.h:65
KPROCESS Pcb
Definition: pstypes.h:1384
Definition: extypes.h:767
PVOID Object
Definition: extypes.h:770
DISPATCHER_HEADER Header
Definition: ketypes.h:2231

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 991 of file process.c.

994{
995 PHANDLE_TABLE_ENTRY CidEntry;
996 PETHREAD FoundThread;
998 PAGED_CODE();
999 PSTRACE(PS_PROCESS_DEBUG, "Cid: %p\n", Cid);
1001
1002 /* Get the CID Handle Entry */
1003 CidEntry = ExMapHandleToPointer(PspCidTable, Cid->UniqueThread);
1004 if (CidEntry)
1005 {
1006 /* Get the Process */
1007 FoundThread = CidEntry->Object;
1008
1009 /* Make sure it's really a thread and this process' */
1010 if ((FoundThread->Tcb.Header.Type == ThreadObject) &&
1011 (FoundThread->Cid.UniqueProcess == Cid->UniqueProcess))
1012 {
1013 /* Safe Reference and return it */
1014 if (ObReferenceObjectSafe(FoundThread))
1015 {
1016 *Thread = FoundThread;
1018
1019 /* Check if we should return the Process too */
1020 if (Process)
1021 {
1022 /* Return it and reference it */
1023 *Process = FoundThread->ThreadsProcess;
1025 }
1026 }
1027 }
1028
1029 /* Unlock the Entry */
1031 }
1032
1033 /* Return to caller */
1035 return Status;
1036}
@ ThreadObject
Definition: ketypes.h:431
#define STATUS_INVALID_CID
Definition: ntstatus.h:341
KTHREAD Tcb
Definition: pstypes.h:1213
CLIENT_ID Cid
Definition: pstypes.h:1238
DISPATCHER_HEADER Header
Definition: ketypes.h:1808
#define ObReferenceObject
Definition: obfuncs.h:204

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
@ PsProcessPrioritySpinning
Definition: pstypes.h:472
@ PsProcessPriorityForeground
Definition: pstypes.h:470
#define MEMORY_PRIORITY_FOREGROUND
Definition: pstypes.h:122
NTSTATUS NTAPI MmSetMemoryPriorityProcess(IN PEPROCESS Process, IN UCHAR MemoryPriority)
Definition: procsup.c:543
KPRIORITY PspPriorityTable[PROCESS_PRIORITY_CLASS_ABOVE_NORMAL+1]
Definition: process.c:60

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();
368 PEPROCESS CurrentProcess = PsGetCurrentProcess();
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
380 PAGED_CODE();
381
383 "ProcessHandle: %p Parent: %p\n", ProcessHandle, ParentProcess);
384
385 /* Validate flags */
387
388 /* Check for parent */
389 if (ParentProcess)
390 {
391 /* Reference it */
392 Status = ObReferenceObjectByHandle(ParentProcess,
396 (PVOID*)&Parent,
397 NULL);
398 if (!NT_SUCCESS(Status)) return Status;
399
400 /* If this process should be in a job but the parent isn't */
401 if ((InJob) && (!Parent->Job))
402 {
403 /* This is illegal. Dereference the parent and fail */
406 }
407
408 /* Inherit Parent process's Affinity. */
409 Affinity = Parent->Pcb.Affinity;
410 }
411 else
412 {
413 /* We have no parent */
414 Parent = NULL;
416 }
417
418 /* Save working set data */
419 MinWs = PsMinimumWorkingSet;
420 MaxWs = PsMaximumWorkingSet;
421
422 /* Create the Object */
427 NULL,
428 sizeof(EPROCESS),
429 0,
430 0,
431 (PVOID*)&Process);
432 if (!NT_SUCCESS(Status)) goto Cleanup;
433
434 /* Clean up the Object */
436
437 /* Initialize pushlock and rundown protection */
438 ExInitializeRundownProtection(&Process->RundownProtect);
439 Process->ProcessLock.Value = 0;
440
441 /* Setup the Thread List Head */
442 InitializeListHead(&Process->ThreadListHead);
443
444 /* Initialize the job process list entry */
445 InitializeListHead(&Process->JobLinks);
446
447 /* Set up the Quota Block from the Parent */
449
450 /* Set up Dos Device Map from the Parent */
452
453 /* Check if we have a parent */
454 if (Parent)
455 {
456 /* Inherit PID and hard-error processing */
457 Process->InheritedFromUniqueProcessId = Parent->UniqueProcessId;
458 Process->DefaultHardErrorProcessing = Parent->DefaultHardErrorProcessing;
459 }
460 else
461 {
462 /* Use default hard-error processing */
463 Process->DefaultHardErrorProcessing = SEM_FAILCRITICALERRORS;
464 }
465
466 /* Check for a section handle */
467 if (SectionHandle)
468 {
469 /* Get a pointer to it */
470 Status = ObReferenceObjectByHandle(SectionHandle,
475 NULL);
476 if (!NT_SUCCESS(Status)) goto CleanupWithRef;
477 }
478 else
479 {
480 /* Assume no section object */
482
483 /* Is the parent the initial process?
484 * Check for NULL also, as at initialization PsInitialSystemProcess is NULL */
486 {
487 /* It's not, so acquire the process rundown */
488 if (ExAcquireRundownProtection(&Parent->RundownProtect))
489 {
490 /* If the parent has a section, use it */
491 SectionObject = Parent->SectionObject;
493
494 /* Release process rundown */
495 ExReleaseRundownProtection(&Parent->RundownProtect);
496 }
497
498 /* If we don't have a section object */
499 if (!SectionObject)
500 {
501 /* Then the process is in termination, so fail */
503 goto CleanupWithRef;
504 }
505 }
506 }
507
508 /* Save the pointer to the section object */
509 Process->SectionObject = SectionObject;
510
511 /* Check for the debug port */
512 if (DebugPort)
513 {
514 /* Reference it */
519 (PVOID*)&DebugObject,
520 NULL);
521 if (!NT_SUCCESS(Status)) goto CleanupWithRef;
522
523 /* Save the debug object */
524 Process->DebugPort = DebugObject;
525
526 /* Check if the caller doesn't want the debug stuff inherited */
528 {
529 /* Set the process flag */
531 }
532 }
533 else
534 {
535 /* Do we have a parent? Copy his debug port */
537 }
538
539 /* Now check for an exception port */
540 if (ExceptionPort)
541 {
542 /* Reference it */
543 Status = ObReferenceObjectByHandle(ExceptionPort,
547 (PVOID*)&ExceptionPortObject,
548 NULL);
549 if (!NT_SUCCESS(Status)) goto CleanupWithRef;
550
551 /* Save the exception port */
552 Process->ExceptionPort = ExceptionPortObject;
553 }
554
555 /* Save the pointer to the section object */
556 Process->SectionObject = SectionObject;
557
558 /* Set default exit code */
559 Process->ExitStatus = STATUS_PENDING;
560
561 /* Check if this is the initial process being built */
562 if (Parent)
563 {
564 /* Create the address space for the child */
566 Process,
567 DirectoryTableBase))
568 {
569 /* Failed */
571 goto CleanupWithRef;
572 }
573 }
574 else
575 {
576 /* Otherwise, we are the boot process, we're already semi-initialized */
577 Process->ObjectTable = CurrentProcess->ObjectTable;
578 Status = MmInitializeHandBuiltProcess(Process, DirectoryTableBase);
579 if (!NT_SUCCESS(Status)) goto CleanupWithRef;
580 }
581
582 /* We now have an address space */
584
585 /* Set the maximum WS */
586 Process->Vm.MaximumWorkingSetSize = MaxWs;
587
588 /* Now initialize the Kernel Process */
591 Affinity,
592 DirectoryTableBase,
593 BooleanFlagOn(Process->DefaultHardErrorProcessing,
595
596 /* Duplicate Parent Token */
598 if (!NT_SUCCESS(Status)) goto CleanupWithRef;
599
600 /* Set default priority class */
601 Process->PriorityClass = PROCESS_PRIORITY_CLASS_NORMAL;
602
603 /* Check if we have a parent */
604 if (Parent)
605 {
606 /* Check our priority class */
607 if (Parent->PriorityClass == PROCESS_PRIORITY_CLASS_IDLE ||
609 {
610 /* Normalize it */
611 Process->PriorityClass = Parent->PriorityClass;
612 }
613
614 /* Initialize object manager for the process */
616 Parent : NULL,
617 Process);
618 if (!NT_SUCCESS(Status)) goto CleanupWithRef;
619 }
620 else
621 {
622 /* Do the second part of the boot process memory setup */
624 if (!NT_SUCCESS(Status)) goto CleanupWithRef;
625 }
626
627 /* Set success for now */
629
630 /* Check if this is a real user-mode process */
631 if (SectionHandle)
632 {
633 /* Initialize the address space */
635 NULL,
637 &Flags,
638 &Process->
639 SeAuditProcessCreationInfo.
640 ImageFileName);
641 if (!NT_SUCCESS(Status)) goto CleanupWithRef;
642
643 //
644 // We need a PEB
645 //
646 NeedsPeb = TRUE;
647 }
648 else if (Parent)
649 {
650 /* Check if this is a child of the system process */
652 {
653 //
654 // We need a PEB
655 //
656 NeedsPeb = TRUE;
657
658 /* This is a clone! */
659 ASSERTMSG("No support for cloning yet\n", FALSE);
660 }
661 else
662 {
663 /* This is the initial system process */
664 Flags &= ~PROCESS_CREATE_FLAGS_LARGE_PAGES;
666 NULL,
667 NULL,
668 &Flags,
669 NULL);
670 if (!NT_SUCCESS(Status)) goto CleanupWithRef;
671
672 /* Create a dummy image file name */
673 Process->SeAuditProcessCreationInfo.ImageFileName =
676 TAG_SEPA);
677 if (!Process->SeAuditProcessCreationInfo.ImageFileName)
678 {
679 /* Fail */
681 goto CleanupWithRef;
682 }
683
684 /* Zero it out */
685 RtlZeroMemory(Process->SeAuditProcessCreationInfo.ImageFileName,
687 }
688 }
689
690#if MI_TRACE_PFNS
691 /* Copy the process name now that we have it */
692 memcpy(MiGetPfnEntry(Process->Pcb.DirectoryTableBase[0] >> PAGE_SHIFT)->ProcessName, Process->ImageFileName, 16);
693 if (Process->Pcb.DirectoryTableBase[1]) memcpy(MiGetPfnEntry(Process->Pcb.DirectoryTableBase[1] >> PAGE_SHIFT)->ProcessName, Process->ImageFileName, 16);
694 if (Process->WorkingSetPage) memcpy(MiGetPfnEntry(Process->WorkingSetPage)->ProcessName, Process->ImageFileName, 16);
695#endif
696
697 /* Check if we have a section object and map the system DLL */
699
700 /* Create a handle for the Process */
701 CidEntry.Object = Process;
702 CidEntry.GrantedAccess = 0;
703 Process->UniqueProcessId = ExCreateHandle(PspCidTable, &CidEntry);
704 if (!Process->UniqueProcessId)
705 {
706 /* Fail */
708 goto CleanupWithRef;
709 }
710
711 /* Set the handle table PID */
712 Process->ObjectTable->UniqueProcessId = Process->UniqueProcessId;
713
714 /* Check if we need to audit */
716
717 /*
718 * Attach the process to parent's job if:
719 * a) parent exists,
720 * b) parent has a job,
721 * c) parent's job does NOT allow silent breakaway.
722 */
723 if (Parent && Parent->Job &&
725 {
726 PEJOB ParentJob = Parent->Job;
727
728 /* If caller explicitly requested breakaway from the job */
730 {
731 /* Deny if the job forbids breakaway */
733 {
735 goto CleanupWithRef;
736 }
737 }
738 else
739 {
740 /* Under normal conditions, child should join a parent's job */
742 if (!NT_SUCCESS(Status))
743 {
744 goto CleanupWithRef;
745 }
746 }
747 }
748
749 /* Create PEB only for User-Mode Processes */
750 if ((Parent) && (NeedsPeb))
751 {
752 //
753 // Set up the initial PEB
754 //
755 RtlZeroMemory(&InitialPeb, sizeof(INITIAL_PEB));
756 InitialPeb.Mutant = (HANDLE)-1;
757 InitialPeb.ImageUsesLargePages = 0; // FIXME: Not yet supported
758
759 //
760 // Create it only if we have an image section
761 //
762 if (SectionHandle)
763 {
764 //
765 // Create it
766 //
767 Status = MmCreatePeb(Process, &InitialPeb, &Process->Peb);
768 if (!NT_SUCCESS(Status)) goto CleanupWithRef;
769 }
770 else
771 {
772 //
773 // We have to clone it
774 //
775 ASSERTMSG("No support for cloning yet\n", FALSE);
776 }
777
778 }
779
780 /* The process can now be activated */
782 InsertTailList(&PsActiveProcessHead, &Process->ActiveProcessLinks);
784
785 /* Create an access state */
786 Status = SeCreateAccessStateEx(CurrentThread,
787 ((Parent) &&
789 Parent : CurrentProcess,
790 &LocalAccessState,
791 &AuxData,
794 if (!NT_SUCCESS(Status)) goto CleanupWithRef;
795
796 /* Insert the Process into the Object Directory */
800 1,
801 NULL,
802 &hProcess);
803
804 /* Free the access state */
806
807 /* Cleanup on failure */
808 if (!NT_SUCCESS(Status)) goto Cleanup;
809
810 /* Compute Quantum and Priority */
811 ASSERT(IsListEmpty(&Process->ThreadListHead) == TRUE);
812 Process->Pcb.BasePriority =
815 &Quantum);
816 Process->Pcb.QuantumReset = Quantum;
817
818 /* Check if we have a parent other then the initial system process */
819 Process->GrantedAccess = PROCESS_TERMINATE;
821 {
822 /* Get the process's SD */
825 &SdAllocated);
826 if (!NT_SUCCESS(Status))
827 {
828 /* We failed, close the handle and clean up */
830 goto CleanupWithRef;
831 }
832
833 /* Create the subject context */
834 SubjectContext.ProcessAuditId = Process;
836 SubjectContext.ClientToken = NULL;
837
838 /* Do the access check */
841 FALSE,
843 0,
844 NULL,
847 &Process->GrantedAccess,
848 &AccessStatus);
849
850 /* Dereference the token and let go the SD */
852 SubjectContext.PrimaryToken);
854
855 /* Remove access if it failed */
856 if (!Result) Process->GrantedAccess = 0;
857
858 /* Give the process some basic access */
859 Process->GrantedAccess |= (PROCESS_VM_OPERATION |
870 }
871 else
872 {
873 /* Set full granted access */
874 Process->GrantedAccess = PROCESS_ALL_ACCESS;
875 }
876
877 /* Set the Creation Time */
878 KeQuerySystemTime(&Process->CreateTime);
879
880 /* Protect against bad user-mode pointer */
882 {
883 /* Hacky way of returning the PEB to the user-mode creator */
884 if ((Process->Peb) && (CurrentThread->Tcb.Teb))
885 {
886 CurrentThread->Tcb.Teb->NtTib.ArbitraryUserPointer = Process->Peb;
887 }
888
889 /* Save the process handle */
891 }
893 {
894 /* Get the exception code */
896 }
897 _SEH2_END;
898
899 /* Run the Notification Routines */
901
902 /* If 12 processes have been created, enough of user-mode is ready */
903 if (++ProcessCount == 12) Ki386PerfEnd();
904
905CleanupWithRef:
906 /*
907 * Dereference the process. For failures, kills the process and does
908 * cleanup present in PspDeleteProcess. For success, kills the extra
909 * reference added by ObInsertObject.
910 */
912
913Cleanup:
914 /* Dereference the parent */
916
917 /* Return status to caller */
918 return Status;
919}
#define DbgkDebugObjectType
Definition: ObTypes.cpp:172
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)
Determines whether security access rights can be given to an object depending on the security descrip...
Definition: accesschk.c:1994
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx 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:732
VOID NTAPI DbgkCopyProcessDebugPort(IN PEPROCESS Process, IN PEPROCESS Parent)
Definition: dbgkobj.c:276
#define DEBUG_OBJECT_ADD_REMOVE_PROCESS
Definition: dbgktypes.h:32
ULONG_PTR KAFFINITY
Definition: compat.h:85
static const WCHAR Cleanup[]
Definition: register.c:80
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define PagedPool
Definition: env_spec_w32.h:308
#define ExReleaseRundownProtection
Definition: ex.h:139
#define ExInitializeRundownProtection
Definition: ex.h:140
#define ExAcquireRundownProtection
Definition: ex.h:138
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
_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:2246
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
#define PROCESS_TERMINATE
Definition: pstypes.h:153
#define PROCESS_VM_READ
Definition: pstypes.h:157
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:162
#define PROCESS_VM_WRITE
Definition: pstypes.h:158
#define JOB_OBJECT_LIMIT_BREAKAWAY_OK
Definition: pstypes.h:219
#define PROCESS_CREATE_THREAD
Definition: pstypes.h:154
#define PROCESS_PRIORITY_CLASS_NORMAL
Definition: pstypes.h:104
#define PSF_NO_DEBUG_INHERIT_BIT
Definition: pstypes.h:285
#define PROCESS_VM_OPERATION
Definition: pstypes.h:156
@ PsProcessPriorityBackground
Definition: pstypes.h:471
#define PROCESS_PRIORITY_CLASS_BELOW_NORMAL
Definition: pstypes.h:107
#define PROCESS_SET_INFORMATION
Definition: pstypes.h:161
#define PROCESS_PRIORITY_NORMAL
Definition: pstypes.h:114
#define PROCESS_CREATE_PROCESS
Definition: pstypes.h:159
#define PSF_HAS_ADDRESS_SPACE_BIT
Definition: pstypes.h:301
#define PROCESS_CREATE_FLAGS_LEGAL_MASK
Definition: pstypes.h:93
#define JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK
Definition: pstypes.h:220
#define PROCESS_SET_QUOTA
Definition: pstypes.h:160
#define PROCESS_DUP_HANDLE
#define InterlockedOr
Definition: interlocked.h:239
POBJECT_TYPE LpcPortObjectType
Definition: port.c:17
#define PORT_ALL_ACCESS
Definition: lpctypes.h:51
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ASSERT(a)
Definition: mode.c:44
#define SEM_NOALIGNMENTFAULTEXCEPT
Definition: rtltypes.h:71
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
#define SECTION_MAP_EXECUTE
Definition: nt_native.h:1293
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
HANDLE NTAPI ExCreateHandle(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:827
#define Ki386PerfEnd()
Definition: ke.h:174
KAFFINITY KeActiveProcessors
Definition: processor.c:16
VOID NTAPI KeInitializeProcess(struct _KPROCESS *Process, KPRIORITY Priority, KAFFINITY Affinity, PULONG_PTR DirectoryTableBase, IN BOOLEAN Enable)
NTSTATUS NTAPI MmInitializeHandBuiltProcess2(IN PEPROCESS Process)
Definition: procsup.c:1209
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:1046
NTSTATUS NTAPI MmInitializeProcessAddressSpace(IN PEPROCESS Process, IN PEPROCESS Clone OPTIONAL, IN PVOID Section OPTIONAL, IN OUT PULONG Flags, IN POBJECT_NAME_INFORMATION *AuditName OPTIONAL)
NTSTATUS NTAPI MmCreatePeb(IN PEPROCESS Process, IN PINITIAL_PEB InitialPeb, OUT PPEB *BasePeb)
Definition: procsup.c:574
NTSTATUS NTAPI MmInitializeHandBuiltProcess(IN PEPROCESS Process, IN PULONG_PTR DirectoryTableBase)
Definition: procsup.c:1183
BOOLEAN NTAPI MmCreateProcessAddressSpace(IN ULONG MinWs, IN PEPROCESS Dest, IN PULONG_PTR DirectoryTableBase)
Definition: page.c:136
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)
BOOLEAN NTAPI SeDetailedAuditingWithToken(_In_ PTOKEN Token)
Peforms a detailed security auditing with an access token.
Definition: audit.c:34
VOID NTAPI SeAuditProcessCreate(_In_ PEPROCESS Process)
Peforms a security auditing against a process that is about to be created.
Definition: audit.c:56
KPRIORITY NTAPI PspComputeQuantumAndPriority(IN PEPROCESS Process, IN PSPROCESSPRIORITYMODE Mode, OUT PUCHAR Quantum)
Definition: process.c:174
ULONG PsMaximumWorkingSet
Definition: process.c:18
ULONG PsMinimumWorkingSet
Definition: psmgr.c:54
PACCESS_TOKEN NTAPI PsReferencePrimaryToken(PEPROCESS Process)
Definition: security.c:440
#define STATUS_PROCESS_IS_TERMINATING
Definition: ntstatus.h:596
VOID NTAPI ObInheritDeviceMap(IN PEPROCESS Parent, IN PEPROCESS Process)
Definition: devicemap.c:511
VOID FASTCALL ObFastDereferenceObject(IN PEX_FAST_REF FastRef, IN PVOID Object)
Definition: obref.c:167
NTSTATUS NTAPI ObInitProcess(IN PEPROCESS Parent OPTIONAL, IN PEPROCESS Process)
Definition: obhandle.c:2112
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3406
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:2957
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:1040
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:493
NTSTATUS NTAPI ObGetObjectSecurity(IN PVOID Object, OUT PSECURITY_DESCRIPTOR *SecurityDescriptor, OUT PBOOLEAN MemoryAllocated)
Definition: obsecure.c:612
VOID NTAPI ObReleaseObjectSecurity(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN BOOLEAN MemoryAllocated)
Definition: obsecure.c:712
ULONG ProcessCount
Definition: perfdata.c:22
NTSTATUS NTAPI PspAssignProcessToJob(_In_ PEPROCESS Process, _In_ PEJOB Job)
Definition: job.c:432
NTSTATUS NTAPI PspInitializeProcessSecurity(IN PEPROCESS Process, IN PEPROCESS Parent OPTIONAL)
Definition: security.c:71
NTSTATUS NTAPI PspMapSystemDll(IN PEPROCESS Process, OUT PVOID *DllBase, IN BOOLEAN UseLargePages)
VOID NTAPI PspInheritQuota(_In_ PEPROCESS Process, _In_ PEPROCESS ParentProcess)
FORCEINLINE VOID PspRunCreateProcessNotifyRoutines(IN PEPROCESS CurrentProcess, IN BOOLEAN Create)
Definition: ps_x.h:62
POBJECT_TYPE MmSectionObjectType
Definition: section.c:196
signed char SCHAR
Definition: sqltypes.h:14
ULONG LimitFlags
Definition: pstypes.h:1618
PHANDLE_TABLE ObjectTable
Definition: pstypes.h:1408
ULONG GrantedAccess
Definition: extypes.h:777
BOOLEAN ImageUsesLargePages
Definition: pstypes.h:719
HANDLE Mutant
Definition: pstypes.h:732
PVOID Teb
Definition: ketypes.h:1954
#define TAG_SEPA
Definition: tag.h:158
#define STATUS_PENDING
Definition: telnetd.h:14
PVOID HANDLE
Definition: typedefs.h:73
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
int32_t * PLONG
Definition: typedefs.h:58
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_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:191
_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:409
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:174
_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:21

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

◆ PsSetProcessPriorityByClass()

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

Definition at line 1355 of file process.c.

1357{
1358 UCHAR Quantum;
1360 PSTRACE(PS_PROCESS_DEBUG, "Process: %p Type: %lx\n", Process, Type);
1361
1362 /* Compute quantum and priority */
1364
1365 /* Set them */
1367}
Type
Definition: Type.h:7
KPRIORITY NTAPI KeSetPriorityAndQuantumProcess(IN PKPROCESS Process, IN KPRIORITY Priority, IN UCHAR Quantum OPTIONAL)
Definition: procobj.c:349
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:655

Referenced by NtSetInformationProcess().

◆ PsSetProcessPriorityClass()

VOID NTAPI PsSetProcessPriorityClass ( PEPROCESS  Process,
ULONG  PriorityClass 
)

Definition at line 1264 of file process.c.

1266{
1267 Process->PriorityClass = (UCHAR)PriorityClass;
1268}

◆ PsSetProcessSecurityPort()

NTSTATUS NTAPI PsSetProcessSecurityPort ( PEPROCESS  Process,
PVOID  SecurityPort 
)

Definition at line 1275 of file process.c.

1277{
1278 Process->SecurityPort = SecurityPort;
1279 return STATUS_SUCCESS;
1280}

◆ PsSetProcessWin32Process()

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

Definition at line 1287 of file process.c.

1291{
1293
1294 /* Assume success */
1296
1297 /* Lock the process */
1299 ExAcquirePushLockExclusive(&Process->ProcessLock);
1300
1301 /* Check if we set a new win32 process */
1302 if (Win32Process != NULL)
1303 {
1304 /* Check if the process is in the right state */
1305 if (((Process->Flags & PSF_PROCESS_DELETE_BIT) == 0) &&
1306 (Process->Win32Process == NULL))
1307 {
1308 /* Set the new win32 process */
1309 Process->Win32Process = Win32Process;
1310 }
1311 else
1312 {
1313 /* Otherwise fail */
1315 }
1316 }
1317 else
1318 {
1319 /* Reset the win32 process, did the caller specify the correct old value? */
1320 if (Process->Win32Process == OldWin32Process)
1321 {
1322 /* Yes, so reset the win32 process to NULL */
1323 Process->Win32Process = NULL;
1324 }
1325 else
1326 {
1327 /* Otherwise fail */
1329 }
1330 }
1331
1332 /* Unlock the process */
1333 ExReleasePushLockExclusive(&Process->ProcessLock);
1335
1336 return Status;
1337}
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1039
FORCEINLINE VOID ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1255
#define PSF_PROCESS_DELETE_BIT
Definition: pstypes.h:287
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by AllocW32Process(), and ExitProcessCallback().

◆ PsSetProcessWindowStation()

VOID NTAPI PsSetProcessWindowStation ( PEPROCESS  Process,
PVOID  WindowStation 
)

Definition at line 1344 of file process.c.

1346{
1347 Process->Win32WindowStation = WindowStation;
1348}

Referenced by UserSetProcessWindowStation().

Variable Documentation

◆ PsActiveProcessHead

LIST_ENTRY PsActiveProcessHead

Definition at line 22 of file process.c.

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

◆ PsMaximumWorkingSet

ULONG PsMaximumWorkingSet

Definition at line 18 of file process.c.

Referenced by PspCreateProcess().

◆ PsMinimumWorkingSet

ULONG PsMinimumWorkingSet
extern

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.