ReactOS  0.4.15-dev-2972-gda2a567
procobj.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for procobj.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI KiAttachProcess (IN PKTHREAD Thread, IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE ApcLock, IN PRKAPC_STATE SavedApcState)
 
VOID NTAPI KeInitializeProcess (IN OUT PKPROCESS Process, IN KPRIORITY Priority, IN KAFFINITY Affinity, IN PULONG_PTR DirectoryTableBase, IN BOOLEAN Enable)
 
ULONG NTAPI KeSetProcess (IN PKPROCESS Process, IN KPRIORITY Increment, IN BOOLEAN InWait)
 
VOID NTAPI KeSetQuantumProcess (IN PKPROCESS Process, IN UCHAR Quantum)
 
KAFFINITY NTAPI KeSetAffinityProcess (IN PKPROCESS Process, IN KAFFINITY Affinity)
 
BOOLEAN NTAPI KeSetAutoAlignmentProcess (IN PKPROCESS Process, IN BOOLEAN Enable)
 
BOOLEAN NTAPI KeSetDisableBoostProcess (IN PKPROCESS Process, IN BOOLEAN Disable)
 
KPRIORITY NTAPI KeSetPriorityAndQuantumProcess (IN PKPROCESS Process, IN KPRIORITY Priority, IN UCHAR Quantum OPTIONAL)
 
VOID NTAPI KeQueryValuesProcess (IN PKPROCESS Process, PPROCESS_VALUES Values)
 
VOID NTAPI KeAttachProcess (IN PKPROCESS Process)
 
VOID NTAPI KeDetachProcess (VOID)
 
BOOLEAN NTAPI KeIsAttachedProcess (VOID)
 
VOID NTAPI KeStackAttachProcess (IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
 
VOID NTAPI KeUnstackDetachProcess (IN PRKAPC_STATE ApcState)
 
ULONG NTAPI KeQueryRuntimeProcess (IN PKPROCESS Process, OUT PULONG UserTime)
 
BOOLEAN NTAPI KeAddSystemServiceTable (IN PULONG_PTR Base, IN PULONG Count OPTIONAL, IN ULONG Limit, IN PUCHAR Number, IN ULONG Index)
 
BOOLEAN NTAPI KeRemoveSystemServiceTable (IN ULONG Index)
 

Variables

LIST_ENTRY KiProcessListHead
 
LIST_ENTRY KiProcessInSwapListHead
 
LIST_ENTRY KiProcessOutSwapListHead
 
LIST_ENTRY KiStackInSwapListHead
 
KEVENT KiSwapEvent
 
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable [SSDT_MAX_ENTRIES]
 
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow [SSDT_MAX_ENTRIES]
 
PVOID KeUserApcDispatcher
 
PVOID KeUserCallbackDispatcher
 
PVOID KeUserExceptionDispatcher
 
PVOID KeRaiseUserExceptionDispatcher
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file procobj.c.

Function Documentation

◆ KeAddSystemServiceTable()

BOOLEAN NTAPI KeAddSystemServiceTable ( IN PULONG_PTR  Base,
IN PULONG Count  OPTIONAL,
IN ULONG  Limit,
IN PUCHAR  Number,
IN ULONG  Index 
)

Definition at line 908 of file procobj.c.

913 {
914  PAGED_CODE();
915 
916  /* Check if descriptor table entry is free */
917  if ((Index > SSDT_MAX_ENTRIES - 1) ||
920  {
921  /* It's not, fail */
922  return FALSE;
923  }
924 
925  /* Initialize the shadow service descriptor table */
930  return TRUE;
931 }
#define TRUE
Definition: types.h:120
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2386
#define SSDT_MAX_ENTRIES
Definition: ketypes.h:100
#define FALSE
Definition: types.h:117
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES]
Definition: procobj.c:24
int Count
Definition: noreturn.cpp:7
_In_ WDFCOLLECTION _In_ ULONG Index
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]
Definition: procobj.c:23
_In_ LONG _In_ LONG Limit
Definition: kefuncs.h:315
#define PAGED_CODE()

Referenced by DriverEntry().

◆ KeAttachProcess()

VOID NTAPI KeAttachProcess ( IN PKPROCESS  Process)

Definition at line 582 of file procobj.c.

583 {
584  KLOCK_QUEUE_HANDLE ApcLock;
588 
589  /* Check if we're already in that process */
590  if (Thread->ApcState.Process == Process) return;
591 
592  /* Check if a DPC is executing or if we're already attached */
593  if ((Thread->ApcStateIndex != OriginalApcEnvironment) ||
594  (KeIsExecutingDpc()))
595  {
596  /* Invalid attempt */
597  KeBugCheckEx(INVALID_PROCESS_ATTACH_ATTEMPT,
599  (ULONG_PTR)Thread->ApcState.Process,
600  Thread->ApcStateIndex,
601  KeIsExecutingDpc());
602  }
603  else
604  {
605  /* Acquire APC Lock */
607 
608  /* Acquire the dispatcher lock */
610 
611  /* Legit attach attempt: do it! */
612  KiAttachProcess(Thread, Process, &ApcLock, &Thread->SavedApcState);
613  }
614 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
VOID NTAPI KiAttachProcess(IN PKTHREAD Thread, IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE ApcLock, IN PRKAPC_STATE SavedApcState)
Definition: procobj.c:35
BOOLEAN NTAPI KeIsExecutingDpc(VOID)
Definition: dpc.c:947
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
FORCEINLINE VOID KiAcquireApcLockRaiseToSynch(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:607
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define KeGetCurrentThread
Definition: hal.h:55
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2072
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
FORCEINLINE VOID KiAcquireDispatcherLockAtSynchLevel(VOID)
Definition: ke_x.h:165

Referenced by MmCreatePeb(), MmCreateTeb(), MmDeletePageTable(), MmDeleteTeb(), MmFreeMemoryArea(), MmFreePageTable(), MmInitializeProcessAddressSpace(), MmPageOutPhysicalAddress(), MmWorkingSetManager(), NtSetInformationProcess(), NtUserGetComboBoxInfo(), NtUserGetListBoxInfo(), NtUserGetThreadDesktop(), and VideoPortWin32kCallout().

◆ KeDetachProcess()

VOID NTAPI KeDetachProcess ( VOID  )

Definition at line 621 of file procobj.c.

622 {
624  KLOCK_QUEUE_HANDLE ApcLock;
627 
628  /* Check if it's attached */
629  if (Thread->ApcStateIndex == OriginalApcEnvironment) return;
630 
631  /* Acquire APC Lock */
633 
634  /* Check for invalid attach attempts */
635  if ((Thread->ApcState.KernelApcInProgress) ||
636  !(IsListEmpty(&Thread->ApcState.ApcListHead[KernelMode])) ||
637  !(IsListEmpty(&Thread->ApcState.ApcListHead[UserMode])))
638  {
639  /* Crash the system */
640  KeBugCheck(INVALID_PROCESS_DETACH_ATTEMPT);
641  }
642 
643  /* Get the process */
644  Process = Thread->ApcState.Process;
645 
646  /* Acquire dispatcher lock */
648 
649  /* Decrease the stack count */
650  ASSERT(Process->StackCount != 0);
651  ASSERT(Process->State == ProcessInMemory);
652  Process->StackCount--;
653 
654  /* Check if we can swap the process out */
655  if (!Process->StackCount)
656  {
657  /* FIXME: Swap the process out */
658  }
659 
660  /* Release dispatcher lock */
662 
663  /* Restore the APC State */
664  KiMoveApcState(&Thread->SavedApcState, &Thread->ApcState);
665  Thread->SavedApcState.Process = NULL;
666  Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->ApcState;
667  Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->SavedApcState;
668  Thread->ApcStateIndex = OriginalApcEnvironment;
669 
670  /* Release lock */
672 
673  /* Swap Processes */
674  KiSwapProcess(Thread->ApcState.Process, Process);
675 
676  /* Exit the dispatcher */
677  KiExitDispatcher(ApcLock.OldIrql);
678 
679  /* Check if we have pending APCs */
680  if (!(IsListEmpty(&Thread->ApcState.ApcListHead[KernelMode])))
681  {
682  /* What do you know, we do! Request them to be delivered */
683  Thread->ApcState.KernelApcPending = TRUE;
685  }
686 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
#define TRUE
Definition: types.h:120
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
#define ASSERT(a)
Definition: mode.c:44
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
FORCEINLINE VOID KiReleaseDispatcherLockFromSynchLevel(VOID)
Definition: ke_x.h:174
FORCEINLINE VOID KiAcquireApcLockRaiseToSynch(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:607
VOID NTAPI KiSwapProcess(struct _KPROCESS *NewProcess, struct _KPROCESS *OldProcess)
Definition: stubs.c:139
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID FASTCALL HalRequestSoftwareInterrupt(IN KIRQL Irql)
Definition: pic.c:271
FORCEINLINE VOID KiReleaseApcLockFromSynchLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
VOID NTAPI KiMoveApcState(PKAPC_STATE OldState, PKAPC_STATE NewState)
Definition: apc.c:538
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define KeGetCurrentThread
Definition: hal.h:55
#define APC_LEVEL
Definition: env_spec_w32.h:695
FORCEINLINE VOID KiAcquireDispatcherLockAtSynchLevel(VOID)
Definition: ke_x.h:165

Referenced by KdbpOverwriteInstruction(), MmCreatePeb(), MmCreateTeb(), MmDeletePageTable(), MmDeleteTeb(), MmFreeMemoryArea(), MmFreePageTable(), MmInitializeProcessAddressSpace(), MmPageOutPhysicalAddress(), MmWorkingSetManager(), NtSetInformationProcess(), NtUserGetComboBoxInfo(), NtUserGetListBoxInfo(), NtUserGetThreadDesktop(), and VideoPortWin32kCallout().

◆ KeInitializeProcess()

VOID NTAPI KeInitializeProcess ( IN OUT PKPROCESS  Process,
IN KPRIORITY  Priority,
IN KAFFINITY  Affinity,
IN PULONG_PTR  DirectoryTableBase,
IN BOOLEAN  Enable 
)

Definition at line 115 of file procobj.c.

120 {
121 #ifdef CONFIG_SMP
122  ULONG i = 0;
123  UCHAR IdealNode = 0;
124  PKNODE Node;
125 #endif
126 
127  /* Initialize the Dispatcher Header */
128  Process->Header.Type = ProcessObject;
129  Process->Header.Size = sizeof(KPROCESS) / sizeof(ULONG);
130  Process->Header.SignalState = 0;
131  InitializeListHead(&(Process->Header.WaitListHead));
132 
133  /* Initialize Scheduler Data, Alignment Faults and Set the PDE */
134  Process->Affinity = Affinity;
135  Process->BasePriority = (CHAR)Priority;
136  Process->QuantumReset = 6;
137  Process->DirectoryTableBase[0] = DirectoryTableBase[0];
138  Process->DirectoryTableBase[1] = DirectoryTableBase[1];
139  Process->AutoAlignment = Enable;
140 #if defined(_M_IX86)
142 #endif
143 
144  /* Initialize the lists */
145  InitializeListHead(&Process->ThreadListHead);
146  InitializeListHead(&Process->ProfileListHead);
147  InitializeListHead(&Process->ReadyListHead);
148 
149  /* Initialize the current State */
150  Process->State = ProcessInMemory;
151 
152  /* Check how many Nodes there are on the system */
153 #ifdef CONFIG_SMP
154  if (KeNumberNodes > 1)
155  {
156  /* Set the new seed */
158  IdealNode = KeProcessNodeSeed;
159 
160  /* Loop every node */
161  do
162  {
163  /* Check if the affinity matches */
164  if (KeNodeBlock[IdealNode]->ProcessorMask != Affinity) break;
165 
166  /* No match, try next Ideal Node and increase node loop index */
167  IdealNode++;
168  i++;
169 
170  /* Check if the Ideal Node is beyond the total number of nodes */
171  if (IdealNode >= KeNumberNodes)
172  {
173  /* Normalize the Ideal Node */
174  IdealNode -= KeNumberNodes;
175  }
176  } while (i < KeNumberNodes);
177  }
178 
179  /* Set the ideal node and get the ideal node block */
180  Process->IdealNode = IdealNode;
181  Node = KeNodeBlock[IdealNode];
182  ASSERT(Node->ProcessorMask & Affinity);
183 
184  /* Find the matching affinity set to calculate the thread seed */
185  Affinity &= Node->ProcessorMask;
186  Process->ThreadSeed = KeFindNextRightSetAffinity(Node->Seed,
187  (ULONG)Affinity);
188  Node->Seed = Process->ThreadSeed;
189 #endif
190 }
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
UCHAR NTAPI KeFindNextRightSetAffinity(IN UCHAR Number, IN ULONG Set)
Definition: thrdobj.c:32
union node Node
Definition: types.h:1255
UCHAR KeProcessNodeSeed
Definition: krnlinit.c:41
#define IO_ACCESS_MAP_NONE
Definition: ketypes.h:267
struct _KPROCESS KPROCESS
#define ASSERT(a)
Definition: mode.c:44
PKNODE KeNodeBlock[1]
Definition: krnlinit.c:39
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:170
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:651
unsigned char UCHAR
Definition: xmlstorage.h:181
UCHAR KeNumberNodes
Definition: krnlinit.c:40
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 KiComputeIopmOffset(MapNumber)
Definition: ketypes.h:269
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_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 CHAR(Char)
Definition: dlist.c:348

◆ KeIsAttachedProcess()

BOOLEAN NTAPI KeIsAttachedProcess ( VOID  )

Definition at line 693 of file procobj.c.

694 {
695  /* Return the APC State */
696  return KeGetCurrentThread()->ApcStateIndex;
697 }
#define KeGetCurrentThread
Definition: hal.h:55

Referenced by MiAccessCheck(), MiCheckForUserStackOverflow(), MmWorkingSetManager(), ObpCloseHandle(), PspExitThread(), and RtlWalkFrameChain().

◆ KeQueryRuntimeProcess()

ULONG NTAPI KeQueryRuntimeProcess ( IN PKPROCESS  Process,
OUT PULONG  UserTime 
)

Definition at line 860 of file procobj.c.

862 {
863  ULONG TotalUser, TotalKernel;
864  KLOCK_QUEUE_HANDLE ProcessLock;
865  PLIST_ENTRY NextEntry, ListHead;
867 
869 
870  /* Initialize user and kernel times */
871  TotalUser = Process->UserTime;
872  TotalKernel = Process->KernelTime;
873 
874  /* Lock the process */
876 
877  /* Loop all child threads and sum up their times */
878  ListHead = &Process->ThreadListHead;
879  NextEntry = ListHead->Flink;
880  while (ListHead != NextEntry)
881  {
882  /* Get the thread */
883  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
884 
885  /* Sum up times */
886  TotalKernel += Thread->KernelTime;
887  TotalUser += Thread->UserTime;
888 
889  /* Go to the next one */
890  NextEntry = NextEntry->Flink;
891  }
892 
893  /* Release lock */
894  KiReleaseProcessLock(&ProcessLock);
895 
896  /* Return the user time */
897  *UserTime = TotalUser;
898 
899  /* Return the kernel time */
900  return TotalKernel;
901 }
FORCEINLINE VOID KiAcquireProcessLockRaiseToSynch(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:651
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
_Out_ PULONG UserTime
Definition: kefuncs.h:771
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
FORCEINLINE VOID KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:660
Definition: typedefs.h:119
_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 ASSERT_PROCESS(object)
Definition: ketypes.h:2072

Referenced by NtQueryInformationProcess(), and QSI_DEF().

◆ KeQueryValuesProcess()

VOID NTAPI KeQueryValuesProcess ( IN PKPROCESS  Process,
PPROCESS_VALUES  Values 
)

Definition at line 525 of file procobj.c.

527 {
528  PEPROCESS EProcess;
529  PLIST_ENTRY NextEntry;
530  ULONG TotalKernel, TotalUser;
531  KLOCK_QUEUE_HANDLE ProcessLock;
532 
535 
536  /* Lock the process */
538 
539  /* Initialize user and kernel times */
540  TotalKernel = Process->KernelTime;
541  TotalUser = Process->UserTime;
542 
543  /* Copy the IO_COUNTERS from the process */
544  EProcess = (PEPROCESS)Process;
551 
552  /* Loop all child threads and sum up their times */
553  for (NextEntry = Process->ThreadListHead.Flink;
554  NextEntry != &Process->ThreadListHead;
555  NextEntry = NextEntry->Flink)
556  {
558 
559  /* Get the thread */
560  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
561 
562  /* Sum up times */
563  TotalKernel += Thread->KernelTime;
564  TotalUser += Thread->UserTime;
565  }
566 
567  /* Release the process lock */
568  KiReleaseProcessLock(&ProcessLock);
569 
570  /* Compute total times */
571  Values->TotalKernelTime.QuadPart = TotalKernel * (LONGLONG)KeMaximumIncrement;
572  Values->TotalUserTime.QuadPart = TotalUser * (LONGLONG)KeMaximumIncrement;
573 }
LARGE_INTEGER WriteOperationCount
Definition: pstypes.h:1347
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
ULONG KeMaximumIncrement
Definition: clock.c:20
ULONGLONG OtherOperationCount
Definition: pstypes.h:85
LARGE_INTEGER ReadOperationCount
Definition: pstypes.h:1346
FORCEINLINE VOID KiAcquireProcessLockRaiseToSynch(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:651
struct _EPROCESS * PEPROCESS
Definition: nt_native.h:30
ULONGLONG WriteOperationCount
Definition: pstypes.h:84
IO_COUNTERS IoInfo
Definition: ke.h:48
LARGE_INTEGER OtherTransferCount
Definition: pstypes.h:1351
ULONGLONG WriteTransferCount
Definition: pstypes.h:87
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
int64_t LONGLONG
Definition: typedefs.h:68
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:44
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
LARGE_INTEGER WriteTransferCount
Definition: pstypes.h:1350
FORCEINLINE VOID KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:660
ULONGLONG ReadTransferCount
Definition: pstypes.h:86
Definition: typedefs.h:119
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
LARGE_INTEGER TotalKernelTime
Definition: ke.h:46
LARGE_INTEGER OtherOperationCount
Definition: pstypes.h:1348
LARGE_INTEGER ReadTransferCount
Definition: pstypes.h:1349
_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
LARGE_INTEGER TotalUserTime
Definition: ke.h:47
ULONGLONG OtherTransferCount
Definition: pstypes.h:88
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2072
LONGLONG QuadPart
Definition: typedefs.h:114
ULONGLONG ReadOperationCount
Definition: pstypes.h:83

Referenced by NtQueryInformationJobObject(), and NtQueryInformationProcess().

◆ KeRemoveSystemServiceTable()

BOOLEAN NTAPI KeRemoveSystemServiceTable ( IN ULONG  Index)

Definition at line 938 of file procobj.c.

939 {
940  PAGED_CODE();
941 
942  /* Make sure the Index is valid */
943  if (Index > (SSDT_MAX_ENTRIES - 1)) return FALSE;
944 
945  /* Is there a Normal Descriptor Table? */
947  {
948  /* Not with the index, is there a shadow at least? */
950  }
951 
952  /* Now clear from the Shadow Table. */
957 
958  /* Check if we should clean from the Master one too */
959  if (Index == 1)
960  {
965  }
966 
967  /* Return success */
968  return TRUE;
969 }
#define TRUE
Definition: types.h:120
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2386
#define SSDT_MAX_ENTRIES
Definition: ketypes.h:100
#define FALSE
Definition: types.h:117
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES]
Definition: procobj.c:24
_In_ WDFCOLLECTION _In_ ULONG Index
#define NULL
Definition: types.h:112
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]
Definition: procobj.c:23
#define PAGED_CODE()

◆ KeSetAffinityProcess()

KAFFINITY NTAPI KeSetAffinityProcess ( IN PKPROCESS  Process,
IN KAFFINITY  Affinity 
)

Definition at line 265 of file procobj.c.

267 {
268 
269  KLOCK_QUEUE_HANDLE ProcessLock;
270  PLIST_ENTRY NextEntry, ListHead;
271  KAFFINITY OldAffinity;
276 
277  /* Lock the process */
279 
280  /* Acquire the dispatcher lock */
282 
283  /* Capture old affinity and update it */
284  OldAffinity = Process->Affinity;
285  Process->Affinity = Affinity;
286 
287  /* Loop all child threads */
288  ListHead = &Process->ThreadListHead;
289  NextEntry = ListHead->Flink;
290  while (ListHead != NextEntry)
291  {
292  /* Get the thread */
293  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
294 
295  /* Set affinity on it */
297  NextEntry = NextEntry->Flink;
298  }
299 
300  /* Release Dispatcher Database */
302 
303  /* Release the process lock */
305  KiExitDispatcher(ProcessLock.OldIrql);
306 
307  /* Return previous affinity */
308  return OldAffinity;
309 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
KAFFINITY FASTCALL KiSetAffinityThread(IN PKTHREAD Thread, IN KAFFINITY Affinity)
Definition: thrdschd.c:685
FORCEINLINE VOID KiAcquireProcessLockRaiseToSynch(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:651
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
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:44
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:170
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
FORCEINLINE VOID KiReleaseDispatcherLockFromSynchLevel(VOID)
Definition: ke_x.h:174
Definition: typedefs.h:119
KAFFINITY KeActiveProcessors
Definition: krnlinit.c:23
FORCEINLINE VOID KiReleaseProcessLockFromSynchLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:668
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
ULONG_PTR KAFFINITY
Definition: compat.h:85
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2072
FORCEINLINE VOID KiAcquireDispatcherLockAtSynchLevel(VOID)
Definition: ke_x.h:165

Referenced by NtSetInformationProcess().

◆ KeSetAutoAlignmentProcess()

BOOLEAN NTAPI KeSetAutoAlignmentProcess ( IN PKPROCESS  Process,
IN BOOLEAN  Enable 
)

Definition at line 313 of file procobj.c.

315 {
316  /* Set or reset the bit depending on what the enable flag says */
317  if (Enable)
318  {
319  return InterlockedBitTestAndSet(&Process->ProcessFlags,
321  }
322  else
323  {
324  return InterlockedBitTestAndReset(&Process->ProcessFlags,
326  }
327 }
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
#define InterlockedBitTestAndReset
Definition: interlocked.h:35
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
#define KPSF_AUTO_ALIGNMENT_BIT
Definition: pstypes.h:267
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by NtSetInformationProcess().

◆ KeSetDisableBoostProcess()

BOOLEAN NTAPI KeSetDisableBoostProcess ( IN PKPROCESS  Process,
IN BOOLEAN  Disable 
)

Definition at line 331 of file procobj.c.

333 {
334  /* Set or reset the bit depending on what the disable flag says */
335  if (Disable)
336  {
337  return InterlockedBitTestAndSet(&Process->ProcessFlags,
339  }
340  else
341  {
342  return InterlockedBitTestAndReset(&Process->ProcessFlags,
344  }
345 }
#define KPSF_DISABLE_BOOST_BIT
Definition: pstypes.h:268
#define InterlockedBitTestAndReset
Definition: interlocked.h:35
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by NtSetInformationProcess().

◆ KeSetPriorityAndQuantumProcess()

KPRIORITY NTAPI KeSetPriorityAndQuantumProcess ( IN PKPROCESS  Process,
IN KPRIORITY  Priority,
IN UCHAR Quantum  OPTIONAL 
)

Definition at line 349 of file procobj.c.

352 {
353  KLOCK_QUEUE_HANDLE ProcessLock;
355  PLIST_ENTRY NextEntry, ListHead;
356  KPRIORITY NewPriority, OldPriority;
360 
361  /* Check if the process already has this priority */
362  if (Process->BasePriority == Priority) return Process->BasePriority;
363 
364  /* If the caller gave priority 0, normalize to 1 */
365  if (!Priority) Priority = LOW_PRIORITY + 1;
366 
367  /* Lock the process */
369 
370  /* Acquire the dispatcher lock */
372 
373  /* Check if we are modifying the quantum too */
374  if (Quantum) Process->QuantumReset = Quantum;
375 
376  /* Save the current base priority and update it */
377  OldPriority = Process->BasePriority;
378  Process->BasePriority = (SCHAR)Priority;
379 
380  /* Calculate the priority delta */
381  Delta = Priority - OldPriority;
382 
383  /* Set the list head and list entry */
384  ListHead = &Process->ThreadListHead;
385  NextEntry = ListHead->Flink;
386 
387  /* Check if this is a real-time priority */
389  {
390  /* Loop the thread list */
391  while (NextEntry != ListHead)
392  {
393  /* Get the thread */
394  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
395 
396  /* Update the quantum if we had one */
397  if (Quantum) Thread->QuantumReset = Quantum;
398 
399  /* Acquire the thread lock */
401 
402  /* Calculate the new priority */
403  NewPriority = Thread->BasePriority + Delta;
404  if (NewPriority < LOW_REALTIME_PRIORITY)
405  {
406  /* We're in real-time range, don't let it go below */
407  NewPriority = LOW_REALTIME_PRIORITY;
408  }
409  else if (NewPriority > HIGH_PRIORITY)
410  {
411  /* We're going beyond the maximum priority, normalize */
412  NewPriority = HIGH_PRIORITY;
413  }
414 
415  /*
416  * If priority saturation occured or the old priority was still in
417  * the real-time range, don't do anything.
418  */
419  if (!(Thread->Saturation) || (OldPriority < LOW_REALTIME_PRIORITY))
420  {
421  /* Check if we had priority saturation */
422  if (Thread->Saturation > 0)
423  {
424  /* Boost priority to maximum */
425  NewPriority = HIGH_PRIORITY;
426  }
427  else if (Thread->Saturation < 0)
428  {
429  /* If we had negative saturation, set minimum priority */
430  NewPriority = LOW_REALTIME_PRIORITY;
431  }
432 
433  /* Update priority and quantum */
434  Thread->BasePriority = (SCHAR)NewPriority;
435  Thread->Quantum = Thread->QuantumReset;
436 
437  /* Disable decrements and update priority */
438  Thread->PriorityDecrement = 0;
439  KiSetPriorityThread(Thread, NewPriority);
440  }
441 
442  /* Release the thread lock */
444 
445  /* Go to the next thread */
446  NextEntry = NextEntry->Flink;
447  }
448  }
449  else
450  {
451  /* Loop the thread list */
452  while (NextEntry != ListHead)
453  {
454  /* Get the thread */
455  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
456 
457  /* Update the quantum if we had one */
458  if (Quantum) Thread->QuantumReset = Quantum;
459 
460  /* Lock the thread */
462 
463  /* Calculate the new priority */
464  NewPriority = Thread->BasePriority + Delta;
465  if (NewPriority >= LOW_REALTIME_PRIORITY)
466  {
467  /* We're not real-time range, don't let it enter RT range */
468  NewPriority = LOW_REALTIME_PRIORITY - 1;
469  }
470  else if (NewPriority <= LOW_PRIORITY)
471  {
472  /* We're going below the minimum priority, normalize */
473  NewPriority = 1;
474  }
475 
476  /*
477  * If priority saturation occured or the old priority was still in
478  * the real-time range, don't do anything.
479  */
480  if (!(Thread->Saturation) ||
481  (OldPriority >= LOW_REALTIME_PRIORITY))
482  {
483  /* Check if we had priority saturation */
484  if (Thread->Saturation > 0)
485  {
486  /* Boost priority to maximum */
487  NewPriority = LOW_REALTIME_PRIORITY - 1;
488  }
489  else if (Thread->Saturation < 0)
490  {
491  /* If we had negative saturation, set minimum priority */
492  NewPriority = 1;
493  }
494 
495  /* Update priority and quantum */
496  Thread->BasePriority = (SCHAR)NewPriority;
497  Thread->Quantum = Thread->QuantumReset;
498 
499  /* Disable decrements and update priority */
500  Thread->PriorityDecrement = 0;
501  KiSetPriorityThread(Thread, NewPriority);
502  }
503 
504  /* Release the thread lock */
506 
507  /* Go to the next thread */
508  NextEntry = NextEntry->Flink;
509  }
510  }
511 
512  /* Release Dispatcher Database */
514 
515  /* Release the process lock */
517  KiExitDispatcher(ProcessLock.OldIrql);
518 
519  /* Return previous priority */
520  return OldPriority;
521 }
FORCEINLINE VOID KiReleaseThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:250
#define LOW_PRIORITY
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
FORCEINLINE VOID KiAcquireProcessLockRaiseToSynch(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:651
#define LOW_REALTIME_PRIORITY
LONG KPRIORITY
Definition: compat.h:662
VOID FASTCALL KiSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdschd.c:511
#define HIGH_PRIORITY
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
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
FORCEINLINE VOID KiAcquireThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:240
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
signed char SCHAR
Definition: sqltypes.h:14
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:651
FORCEINLINE VOID KiReleaseDispatcherLockFromSynchLevel(VOID)
Definition: ke_x.h:174
Definition: typedefs.h:119
FORCEINLINE VOID KiReleaseProcessLockFromSynchLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:668
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
static ULONG Delta
Definition: xboxvideo.c:33
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2072
FORCEINLINE VOID KiAcquireDispatcherLockAtSynchLevel(VOID)
Definition: ke_x.h:165

Referenced by NtSetInformationProcess(), and PsSetProcessPriorityByClass().

◆ KeSetProcess()

ULONG NTAPI KeSetProcess ( IN PKPROCESS  Process,
IN KPRIORITY  Increment,
IN BOOLEAN  InWait 
)

Definition at line 194 of file procobj.c.

197 {
198  KIRQL OldIrql;
199  ULONG OldState;
202 
203  /* Lock Dispatcher */
205 
206  /* Get Old State */
207  OldState = Process->Header.SignalState;
208 
209  /* Signal the Process */
210  Process->Header.SignalState = TRUE;
211 
212  /* Check if was unsignaled and has waiters */
213  if (!(OldState) &&
214  !(IsListEmpty(&Process->Header.WaitListHead)))
215  {
216  /* Unwait the threads */
217  KxUnwaitThread(&Process->Header, Increment);
218  }
219 
220  /* Release Dispatcher Database */
222 
223  /* Return the previous State */
224  return OldState;
225 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
#define TRUE
Definition: types.h:120
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
KIRQL OldIrql
Definition: mm.h:1502
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE VOID KiReleaseDispatcherLock(IN KIRQL OldIrql)
Definition: ke_x.h:157
FORCEINLINE KIRQL KiAcquireDispatcherLock(VOID)
Definition: ke_x.h:149
_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
FORCEINLINE VOID KxUnwaitThread(IN DISPATCHER_HEADER *Object, IN KPRIORITY Increment)
Definition: ke_x.h:1259
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2072

◆ KeSetQuantumProcess()

VOID NTAPI KeSetQuantumProcess ( IN PKPROCESS  Process,
IN UCHAR  Quantum 
)

Definition at line 229 of file procobj.c.

231 {
232  KLOCK_QUEUE_HANDLE ProcessLock;
233  PLIST_ENTRY NextEntry, ListHead;
237 
238  /* Lock the process */
240 
241  /* Set new quantum */
242  Process->QuantumReset = Quantum;
243 
244  /* Loop all child threads */
245  ListHead = &Process->ThreadListHead;
246  NextEntry = ListHead->Flink;
247  while (ListHead != NextEntry)
248  {
249  /* Get the thread */
250  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
251 
252  /* Set quantum */
253  Thread->QuantumReset = Quantum;
254 
255  /* Go to the next one */
256  NextEntry = NextEntry->Flink;
257  }
258 
259  /* Release lock */
260  KiReleaseProcessLock(&ProcessLock);
261 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
FORCEINLINE VOID KiAcquireProcessLockRaiseToSynch(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:651
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:121
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
FORCEINLINE VOID KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:660
Definition: typedefs.h:119
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2072

Referenced by PsChangeQuantumTable().

◆ KeStackAttachProcess()

VOID NTAPI KeStackAttachProcess ( IN PKPROCESS  Process,
OUT PRKAPC_STATE  ApcState 
)

Definition at line 704 of file procobj.c.

706 {
707  KLOCK_QUEUE_HANDLE ApcLock;
711 
712  /* Crash system if DPC is being executed! */
713  if (KeIsExecutingDpc())
714  {
715  /* Executing a DPC, crash! */
716  KeBugCheckEx(INVALID_PROCESS_ATTACH_ATTEMPT,
718  (ULONG_PTR)Thread->ApcState.Process,
719  Thread->ApcStateIndex,
720  KeIsExecutingDpc());
721  }
722 
723  /* Check if we are already in the target process */
724  if (Thread->ApcState.Process == Process)
725  {
726  /* Set magic value so we don't crash later when detaching */
727  ApcState->Process = (PKPROCESS)1;
728  return;
729  }
730 
731  /* Acquire APC Lock */
733 
734  /* Acquire dispatcher lock */
736 
737  /* Check if the Current Thread is already attached */
738  if (Thread->ApcStateIndex != OriginalApcEnvironment)
739  {
740  /* We're already attached, so save the APC State into what we got */
741  KiAttachProcess(Thread, Process, &ApcLock, ApcState);
742  }
743  else
744  {
745  /* We're not attached, so save the APC State into SavedApcState */
746  KiAttachProcess(Thread, Process, &ApcLock, &Thread->SavedApcState);
747  ApcState->Process = NULL;
748  }
749 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
VOID NTAPI KiAttachProcess(IN PKTHREAD Thread, IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE ApcLock, IN PRKAPC_STATE SavedApcState)
Definition: procobj.c:35
BOOLEAN NTAPI KeIsExecutingDpc(VOID)
Definition: dpc.c:947
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
FORCEINLINE VOID KiAcquireApcLockRaiseToSynch(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:607
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
struct _KPROCESS * PKPROCESS
Definition: wdm.template.h:206
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1679
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define KeGetCurrentThread
Definition: hal.h:55
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2072
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
FORCEINLINE VOID KiAcquireDispatcherLockAtSynchLevel(VOID)
Definition: ke_x.h:165

Referenced by DbgkpMarkProcessPeb(), DbgkpPostFakeProcessCreateMessages(), ExpDebuggerWorker(), IntAttachToCSRSS(), IntRemoveHook(), KdbCommand_Gdi_dumpht(), KdbCommand_Gdi_entry(), KdbCommand_Gdi_handle(), KdbpAttachToThread(), KdbpOverwriteInstruction(), MiDoMappedCopy(), MiDoPoolCopy(), MiLoadImageSection(), MiQueryMemoryBasicInformation(), MiUnmapViewOfSection(), MmCheckSystemImage(), MmMapViewOfArm3Section(), MmTrimUserMemory(), NtAllocateVirtualMemory(), NtFlushInstructionCache(), NtFreeVirtualMemory(), NtLockVirtualMemory(), NtProtectVirtualMemory(), NtSetInformationObject(), NtUnlockVirtualMemory(), NtUserSetWindowsHookEx(), NtUserWaitForInputIdle(), ObClearProcessHandleTable(), ObDuplicateObject(), ObpCloseHandle(), ObpCreateHandle(), ObpCreateUnnamedHandle(), ObSetHandleAttributes(), PspDeleteProcess(), PspSetQuotaLimits(), PspWriteTebImpersonationInfo(), and SepCleanupLUIDDeviceMapDirectory().

◆ KeUnstackDetachProcess()

VOID NTAPI KeUnstackDetachProcess ( IN PRKAPC_STATE  ApcState)

Definition at line 756 of file procobj.c.

757 {
758  KLOCK_QUEUE_HANDLE ApcLock;
762 
763  /* Check for magic value meaning we were already in the same process */
764  if (ApcState->Process == (PKPROCESS)1) return;
765 
766  /* Loop to make sure no APCs are pending */
767  for (;;)
768  {
769  /* Acquire APC Lock */
771 
772  /* Check if a kernel APC is pending */
773  if (Thread->ApcState.KernelApcPending)
774  {
775  /* Check if kernel APC should be delivered */
776  if (!(Thread->KernelApcDisable) && (ApcLock.OldIrql <= APC_LEVEL))
777  {
778  /* Release the APC lock so that the APC can be delivered */
779  KiReleaseApcLock(&ApcLock);
780  continue;
781  }
782  }
783 
784  /* Otherwise, break out */
785  break;
786  }
787 
788  /*
789  * Check if the process isn't attacked, or has a Kernel APC in progress
790  * or has pending APC of any kind.
791  */
792  if ((Thread->ApcStateIndex == OriginalApcEnvironment) ||
793  (Thread->ApcState.KernelApcInProgress) ||
794  (!IsListEmpty(&Thread->ApcState.ApcListHead[KernelMode])) ||
795  (!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode])))
796  {
797  /* Bugcheck the system */
798  KeBugCheck(INVALID_PROCESS_DETACH_ATTEMPT);
799  }
800 
801  /* Get the process */
802  Process = Thread->ApcState.Process;
803 
804  /* Acquire dispatcher lock */
806 
807  /* Decrease the stack count */
808  ASSERT(Process->StackCount != 0);
809  ASSERT(Process->State == ProcessInMemory);
810  Process->StackCount--;
811 
812  /* Check if we can swap the process out */
813  if (!Process->StackCount)
814  {
815  /* FIXME: Swap the process out */
816  }
817 
818  /* Release dispatcher lock */
820 
821  /* Check if there's an APC state to restore */
822  if (ApcState->Process)
823  {
824  /* Restore the APC State */
825  KiMoveApcState(ApcState, &Thread->ApcState);
826  }
827  else
828  {
829  /* The ApcState parameter is useless, so use the saved data and reset it */
830  KiMoveApcState(&Thread->SavedApcState, &Thread->ApcState);
831  Thread->SavedApcState.Process = NULL;
832  Thread->ApcStateIndex = OriginalApcEnvironment;
833  Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->ApcState;
834  Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->SavedApcState;
835  }
836 
837  /* Release lock */
839 
840  /* Swap Processes */
841  KiSwapProcess(Thread->ApcState.Process, Process);
842 
843  /* Exit the dispatcher */
844  KiExitDispatcher(ApcLock.OldIrql);
845 
846  /* Check if we have pending APCs */
847  if (!(IsListEmpty(&Thread->ApcState.ApcListHead[KernelMode])))
848  {
849  /* What do you know, we do! Request them to be delivered */
850  Thread->ApcState.KernelApcPending = TRUE;
852  }
853 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
#define TRUE
Definition: types.h:120
FORCEINLINE VOID KiReleaseApcLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:635
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
#define ASSERT(a)
Definition: mode.c:44
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
FORCEINLINE VOID KiReleaseDispatcherLockFromSynchLevel(VOID)
Definition: ke_x.h:174
FORCEINLINE VOID KiAcquireApcLockRaiseToSynch(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:607
VOID NTAPI KiSwapProcess(struct _KPROCESS *NewProcess, struct _KPROCESS *OldProcess)
Definition: stubs.c:139
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID FASTCALL HalRequestSoftwareInterrupt(IN KIRQL Irql)
Definition: pic.c:271
FORCEINLINE VOID KiReleaseApcLockFromSynchLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
VOID NTAPI KiMoveApcState(PKAPC_STATE OldState, PKAPC_STATE NewState)
Definition: apc.c:538
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1679
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define KeGetCurrentThread
Definition: hal.h:55
#define APC_LEVEL
Definition: env_spec_w32.h:695
FORCEINLINE VOID KiAcquireDispatcherLockAtSynchLevel(VOID)
Definition: ke_x.h:165

Referenced by DbgkpMarkProcessPeb(), DbgkpPostFakeProcessCreateMessages(), ExpDebuggerWorker(), IntDetachFromCSRSS(), IntRemoveHook(), KdbCommand_Gdi_dumpht(), KdbCommand_Gdi_entry(), KdbCommand_Gdi_handle(), KdbEnterDebuggerException(), KdbpAttachToThread(), KdbpOverwriteInstruction(), MiDoMappedCopy(), MiDoPoolCopy(), MiLoadImageSection(), MiQueryMemoryBasicInformation(), MiUnmapViewOfSection(), MmCheckSystemImage(), MmMapViewOfArm3Section(), MmTrimUserMemory(), NtAllocateVirtualMemory(), NtFlushInstructionCache(), NtFreeVirtualMemory(), NtLockVirtualMemory(), NtProtectVirtualMemory(), NtSetInformationObject(), NtUnlockVirtualMemory(), NtUserSetWindowsHookEx(), NtUserWaitForInputIdle(), ObClearProcessHandleTable(), ObDuplicateObject(), ObpCloseHandle(), ObpCreateHandle(), ObpCreateUnnamedHandle(), ObSetHandleAttributes(), PspDeleteProcess(), PspSetQuotaLimits(), PspWriteTebImpersonationInfo(), and SepCleanupLUIDDeviceMapDirectory().

◆ KiAttachProcess()

VOID NTAPI KiAttachProcess ( IN PKTHREAD  Thread,
IN PKPROCESS  Process,
IN PKLOCK_QUEUE_HANDLE  ApcLock,
IN PRKAPC_STATE  SavedApcState 
)

Definition at line 35 of file procobj.c.

39 {
40 #if 0
41  PLIST_ENTRY ListHead, NextEntry;
42  PKTHREAD CurrentThread;
43 #endif
44  ASSERT(Process != Thread->ApcState.Process);
45 
46  /* Increase Stack Count */
47  ASSERT(Process->StackCount != MAXULONG_PTR);
48  Process->StackCount++;
49 
50  /* Swap the APC Environment */
51  KiMoveApcState(&Thread->ApcState, SavedApcState);
52 
53  /* Reinitialize Apc State */
54  InitializeListHead(&Thread->ApcState.ApcListHead[KernelMode]);
55  InitializeListHead(&Thread->ApcState.ApcListHead[UserMode]);
56  Thread->ApcState.Process = Process;
57  Thread->ApcState.KernelApcInProgress = FALSE;
58  Thread->ApcState.KernelApcPending = FALSE;
59  Thread->ApcState.UserApcPending = FALSE;
60 
61  /* Update Environment Pointers if needed*/
62  if (SavedApcState == &Thread->SavedApcState)
63  {
64  Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->
65  SavedApcState;
66  Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->ApcState;
67  Thread->ApcStateIndex = AttachedApcEnvironment;
68  }
69 
70  /* Check if the process is paged in */
71  if (Process->State == ProcessInMemory)
72  {
73  /* Scan the ready list */
74 #if 0
75  ListHead = &Process->ReadyListHead;
76  NextEntry = ListHead->Flink;
77  while (NextEntry != ListHead)
78  {
79  /* Get the thread */
80  CurrentThread = CONTAINING_RECORD(NextEntry, KTHREAD, WaitListEntry);
81 
82  /* Remove it */
83  RemoveEntryList(NextEntry);
84  CurrentThread->ProcessReadyQueue = FALSE;
85 
86  /* Mark it ready */
87  KiReadyThread(CurrentThread);
88 
89  /* Go to the next one */
90  NextEntry = ListHead->Flink;
91  }
92 #endif
93 
94  /* Release dispatcher lock */
96 
97  /* Release lock */
99 
100  /* Swap Processes */
101  KiSwapProcess(Process, SavedApcState->Process);
102 
103  /* Exit the dispatcher */
104  KiExitDispatcher(ApcLock->OldIrql);
105  }
106  else
107  {
108  DPRINT1("Errr. ReactOS doesn't support paging out processes yet...\n");
109  ASSERT(FALSE);
110  }
111 }
#define MAXULONG_PTR
Definition: basetsd.h:103
ULONG ProcessReadyQueue
Definition: ketypes.h:1627
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define FALSE
Definition: types.h:117
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
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
VOID NTAPI KiReadyThread(IN PKTHREAD Thread)
Definition: thrdschd.c:429
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:44
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
FORCEINLINE VOID KiReleaseDispatcherLockFromSynchLevel(VOID)
Definition: ke_x.h:174
Definition: typedefs.h:119
VOID NTAPI KiSwapProcess(struct _KPROCESS *NewProcess, struct _KPROCESS *OldProcess)
Definition: stubs.c:139
FORCEINLINE VOID KiReleaseApcLockFromSynchLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
VOID NTAPI KiMoveApcState(PKAPC_STATE OldState, PKAPC_STATE NewState)
Definition: apc.c:538
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by KeAttachProcess(), and KeStackAttachProcess().

Variable Documentation

◆ KeRaiseUserExceptionDispatcher

PVOID KeRaiseUserExceptionDispatcher

Definition at line 29 of file procobj.c.

Referenced by KeRaiseUserException(), and PspLookupKernelUserEntryPoints().

◆ KeServiceDescriptorTable

◆ KeServiceDescriptorTableShadow

◆ KeUserApcDispatcher

PVOID KeUserApcDispatcher

Definition at line 26 of file procobj.c.

Referenced by KiInitializeUserApc(), and PspLookupKernelUserEntryPoints().

◆ KeUserCallbackDispatcher

PVOID KeUserCallbackDispatcher

Definition at line 27 of file procobj.c.

Referenced by KdUpdateDataBlock(), KiUserModeCallout(), and PspLookupKernelUserEntryPoints().

◆ KeUserExceptionDispatcher

PVOID KeUserExceptionDispatcher

◆ KiProcessInSwapListHead

LIST_ENTRY KiProcessInSwapListHead

Definition at line 19 of file procobj.c.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ KiProcessListHead

LIST_ENTRY KiProcessListHead

Definition at line 18 of file procobj.c.

Referenced by KiInitializeKernel().

◆ KiProcessOutSwapListHead

LIST_ENTRY KiProcessOutSwapListHead

Definition at line 19 of file procobj.c.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ KiStackInSwapListHead

LIST_ENTRY KiStackInSwapListHead

Definition at line 20 of file procobj.c.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ KiSwapEvent

KEVENT KiSwapEvent

Definition at line 21 of file procobj.c.

Referenced by KiInitializeKernel(), and KiInitSystem().