ReactOS  r74622
ke.h File Reference
#include "arch/ke.h"
#include "ke_x.h"
Include dependency graph for ke.h:

Go to the source code of this file.

Classes

struct  _WOW64_PROCESS
 
struct  _KPROFILE_SOURCE_OBJECT
 
struct  _DISPATCH_INFO
 
struct  _DEFERRED_REVERSE_BARRIER
 
struct  _KI_SAMPLE_MAP
 
struct  _DPC_QUEUE_ENTRY
 
struct  _KNMI_HANDLER_CALLBACK
 

Macros

#define MAX_TIMER_DPCS   16
 
#define AFFINITY_MASK(Id)   KiMask32Array[Id]
 
#define PRIORITY_MASK(Id)   KiMask32Array[Id]
 
#define TIMER_OR_EVENT_TYPE   0x7L
 
#define TIMER_WAIT_BLOCK   0x3L
 

Typedefs

typedef struct _WOW64_PROCESS WOW64_PROCESS
 
typedef struct _WOW64_PROCESSPWOW64_PROCESS
 
typedef struct
_KPROFILE_SOURCE_OBJECT 
KPROFILE_SOURCE_OBJECT
 
typedef struct
_KPROFILE_SOURCE_OBJECT
PKPROFILE_SOURCE_OBJECT
 
typedef enum _CONNECT_TYPE CONNECT_TYPE
 
typedef enum _CONNECT_TYPEPCONNECT_TYPE
 
typedef struct _DISPATCH_INFO DISPATCH_INFO
 
typedef struct _DISPATCH_INFOPDISPATCH_INFO
 
typedef struct
_DEFERRED_REVERSE_BARRIER 
DEFERRED_REVERSE_BARRIER
 
typedef struct
_DEFERRED_REVERSE_BARRIER
PDEFERRED_REVERSE_BARRIER
 
typedef struct _KI_SAMPLE_MAP KI_SAMPLE_MAP
 
typedef struct _KI_SAMPLE_MAPPKI_SAMPLE_MAP
 
typedef struct _DPC_QUEUE_ENTRY DPC_QUEUE_ENTRY
 
typedef struct _DPC_QUEUE_ENTRYPDPC_QUEUE_ENTRY
 
typedef struct
_KNMI_HANDLER_CALLBACK 
KNMI_HANDLER_CALLBACK
 
typedef struct
_KNMI_HANDLER_CALLBACK
PKNMI_HANDLER_CALLBACK
 
typedef PCHAR(NTAPIPKE_BUGCHECK_UNICODE_TO_ANSI )(IN PUNICODE_STRING Unicode, IN PCHAR Ansi, IN ULONG Length)
 

Enumerations

enum  _CONNECT_TYPE { NoConnect, NormalConnect, ChainConnect, UnknownConnect }
 

Functions

VOID __cdecl KiInterruptTemplate (VOID)
 
LONG_PTR FASTCALL KiSwapThread (IN PKTHREAD Thread, IN PKPRCB Prcb)
 
VOID NTAPI KeReadyThread (IN PKTHREAD Thread)
 
BOOLEAN NTAPI KeSetDisableBoostThread (IN OUT PKTHREAD Thread, IN BOOLEAN Disable)
 
BOOLEAN NTAPI KeSetDisableBoostProcess (IN PKPROCESS Process, IN BOOLEAN Disable)
 
BOOLEAN NTAPI KeSetAutoAlignmentProcess (IN PKPROCESS Process, IN BOOLEAN Enable)
 
KAFFINITY NTAPI KeSetAffinityProcess (IN PKPROCESS Process, IN KAFFINITY Affinity)
 
VOID NTAPI KeBoostPriorityThread (IN PKTHREAD Thread, IN KPRIORITY Increment)
 
VOID NTAPI KeBalanceSetManager (IN PVOID Context)
 
VOID NTAPI KiReadyThread (IN PKTHREAD Thread)
 
ULONG NTAPI KeSuspendThread (PKTHREAD Thread)
 
BOOLEAN NTAPI KeReadStateThread (IN PKTHREAD Thread)
 
BOOLEAN FASTCALL KiSwapContext (IN KIRQL WaitIrql, IN PKTHREAD CurrentThread)
 
VOID NTAPI KiAdjustQuantumThread (IN PKTHREAD Thread)
 
VOID FASTCALL KiExitDispatcher (KIRQL OldIrql)
 
VOID FASTCALL KiDeferredReadyThread (IN PKTHREAD Thread)
 
PKTHREAD FASTCALL KiIdleSchedule (IN PKPRCB Prcb)
 
VOID FASTCALL KiProcessDeferredReadyList (IN PKPRCB Prcb)
 
KAFFINITY FASTCALL KiSetAffinityThread (IN PKTHREAD Thread, IN KAFFINITY Affinity)
 
PKTHREAD FASTCALL KiSelectNextThread (IN PKPRCB Prcb)
 
BOOLEAN FASTCALL KiInsertTimerTable (IN PKTIMER Timer, IN ULONG Hand)
 
VOID FASTCALL KiTimerListExpire (IN PLIST_ENTRY ExpiredListHead, IN KIRQL OldIrql)
 
BOOLEAN FASTCALL KiInsertTreeTimer (IN PKTIMER Timer, IN LARGE_INTEGER Interval)
 
VOID FASTCALL KiCompleteTimer (IN PKTIMER Timer, IN PKSPIN_LOCK_QUEUE LockQueue)
 
VOID FASTCALL KiAcquireGuardedMutex (IN OUT PKGUARDED_MUTEX GuardedMutex)
 
VOID FASTCALL KiAcquireFastMutex (IN PFAST_MUTEX FastMutex)
 
VOID FASTCALL KeInitializeGate (PKGATE Gate)
 
VOID FASTCALL KeSignalGateBoostPriority (PKGATE Gate)
 
VOID FASTCALL KeWaitForGate (PKGATE Gate, KWAIT_REASON WaitReason, KPROCESSOR_MODE WaitMode)
 
VOID FASTCALL KiIpiSend (KAFFINITY TargetSet, ULONG IpiRequest)
 
VOID NTAPI KiIpiSendPacket (IN KAFFINITY TargetProcessors, IN PKIPI_WORKER WorkerFunction, IN PKIPI_BROADCAST_WORKER BroadcastFunction, IN ULONG_PTR Context, IN PULONG Count)
 
VOID FASTCALL KiIpiSignalPacketDone (IN PKIPI_CONTEXT PacketContext)
 
VOID FASTCALL KiIpiSignalPacketDoneAndStall (IN PKIPI_CONTEXT PacketContext, IN volatile PULONG ReverseStall)
 
UCHAR NTAPI KeFindNextRightSetAffinity (IN UCHAR Number, IN ULONG Set)
 
VOID NTAPI DbgBreakPointNoBugCheck (VOID)
 
VOID NTAPI KeInitializeProfile (struct _KPROFILE *Profile, struct _KPROCESS *Process, PVOID ImageBase, SIZE_T ImageSize, ULONG BucketSize, KPROFILE_SOURCE ProfileSource, KAFFINITY Affinity)
 
BOOLEAN NTAPI KeStartProfile (struct _KPROFILE *Profile, PVOID Buffer)
 
BOOLEAN NTAPI KeStopProfile (struct _KPROFILE *Profile)
 
ULONG NTAPI KeQueryIntervalProfile (KPROFILE_SOURCE ProfileSource)
 
VOID NTAPI KeSetIntervalProfile (ULONG Interval, KPROFILE_SOURCE ProfileSource)
 
VOID NTAPI KeUpdateRunTime (PKTRAP_FRAME TrapFrame, KIRQL Irql)
 
VOID NTAPI KiExpireTimers (PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
 
VOID NTAPI KeInitializeThread (IN PKPROCESS Process, IN OUT PKTHREAD Thread, IN PKSYSTEM_ROUTINE SystemRoutine, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext, IN PCONTEXT Context, IN PVOID Teb, IN PVOID KernelStack)
 
VOID NTAPI KeUninitThread (IN PKTHREAD Thread)
 
NTSTATUS NTAPI KeInitThread (IN OUT PKTHREAD Thread, IN PVOID KernelStack, IN PKSYSTEM_ROUTINE SystemRoutine, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext, IN PCONTEXT Context, IN PVOID Teb, IN PKPROCESS Process)
 
VOID NTAPI KiInitializeContextThread (PKTHREAD Thread, PKSYSTEM_ROUTINE SystemRoutine, PKSTART_ROUTINE StartRoutine, PVOID StartContext, PCONTEXT Context)
 
VOID NTAPI KeStartThread (IN OUT PKTHREAD Thread)
 
BOOLEAN NTAPI KeAlertThread (IN PKTHREAD Thread, IN KPROCESSOR_MODE AlertMode)
 
ULONG NTAPI KeAlertResumeThread (IN PKTHREAD Thread)
 
ULONG NTAPI KeResumeThread (IN PKTHREAD Thread)
 
PVOID NTAPI KeSwitchKernelStack (IN PVOID StackBase, IN PVOID StackLimit)
 
VOID NTAPI KeRundownThread (VOID)
 
NTSTATUS NTAPI KeReleaseThread (PKTHREAD Thread)
 
VOID NTAPI KiSuspendRundown (IN PKAPC Apc)
 
VOID NTAPI KiSuspendNop (IN PKAPC Apc, IN PKNORMAL_ROUTINE *NormalRoutine, IN PVOID *NormalContext, IN PVOID *SystemArgument1, IN PVOID *SystemArgument2)
 
VOID NTAPI KiSuspendThread (IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
LONG NTAPI KeQueryBasePriorityThread (IN PKTHREAD Thread)
 
VOID FASTCALL KiSetPriorityThread (IN PKTHREAD Thread, IN KPRIORITY Priority)
 
VOID FASTCALL KiUnlinkThread (IN PKTHREAD Thread, IN LONG_PTR WaitStatus)
 
VOID NTAPI KeDumpStackFrames (PULONG Frame)
 
BOOLEAN NTAPI KiTestAlert (VOID)
 
VOID FASTCALL KiUnwaitThread (IN PKTHREAD Thread, IN LONG_PTR WaitStatus, IN KPRIORITY Increment)
 
VOID NTAPI KeInitializeProcess (struct _KPROCESS *Process, KPRIORITY Priority, KAFFINITY Affinity, PULONG_PTR DirectoryTableBase, IN BOOLEAN Enable)
 
VOID NTAPI KeSetQuantumProcess (IN PKPROCESS Process, IN UCHAR Quantum)
 
KPRIORITY NTAPI KeSetPriorityAndQuantumProcess (IN PKPROCESS Process, IN KPRIORITY Priority, IN UCHAR Quantum OPTIONAL)
 
ULONG NTAPI KeForceResumeThread (IN PKTHREAD Thread)
 
VOID NTAPI KeThawAllThreads (VOID)
 
VOID NTAPI KeFreezeAllThreads (VOID)
 
BOOLEAN NTAPI KeDisableThreadApcQueueing (IN PKTHREAD Thread)
 
VOID FASTCALL KiWaitTest (PVOID Object, KPRIORITY Increment)
 
VOID NTAPI KeContextToTrapFrame (PCONTEXT Context, PKEXCEPTION_FRAME ExeptionFrame, PKTRAP_FRAME TrapFrame, ULONG ContextFlags, KPROCESSOR_MODE PreviousMode)
 
VOID NTAPI Ke386SetIOPL (VOID)
 
VOID NTAPI KiCheckForKernelApcDelivery (VOID)
 
LONG NTAPI KiInsertQueue (IN PKQUEUE Queue, IN PLIST_ENTRY Entry, BOOLEAN Head)
 
VOID NTAPI KiTimerExpiration (IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
ULONG NTAPI KeSetProcess (struct _KPROCESS *Process, KPRIORITY Increment, BOOLEAN InWait)
 
VOID NTAPI KeInitializeEventPair (PKEVENT_PAIR EventPair)
 
VOID NTAPI KiInitializeUserApc (IN PKEXCEPTION_FRAME Reserved, IN PKTRAP_FRAME TrapFrame, IN PKNORMAL_ROUTINE NormalRoutine, IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
PLIST_ENTRY NTAPI KeFlushQueueApc (IN PKTHREAD Thread, IN KPROCESSOR_MODE PreviousMode)
 
VOID NTAPI KiAttachProcess (struct _KTHREAD *Thread, struct _KPROCESS *Process, PKLOCK_QUEUE_HANDLE ApcLock, struct _KAPC_STATE *SavedApcState)
 
VOID NTAPI KiSwapProcess (struct _KPROCESS *NewProcess, struct _KPROCESS *OldProcess)
 
BOOLEAN NTAPI KeTestAlertThread (IN KPROCESSOR_MODE AlertMode)
 
BOOLEAN NTAPI KeRemoveQueueApc (PKAPC Apc)
 
VOID FASTCALL KiActivateWaiterQueue (IN PKQUEUE Queue)
 
ULONG NTAPI KeQueryRuntimeProcess (IN PKPROCESS Process, OUT PULONG UserTime)
 
BOOLEAN NTAPI KeInitSystem (VOID)
 
VOID NTAPI KeInitExceptions (VOID)
 
VOID NTAPI KeInitInterrupts (VOID)
 
VOID NTAPI KiInitializeBugCheck (VOID)
 
VOID NTAPI KiSystemStartup (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
BOOLEAN NTAPI KiDeliverUserApc (PKTRAP_FRAME TrapFrame)
 
VOID NTAPI KiMoveApcState (PKAPC_STATE OldState, PKAPC_STATE NewState)
 
VOID NTAPI KiAddProfileEvent (KPROFILE_SOURCE Source, ULONG Pc)
 
VOID NTAPI KiDispatchException (PEXCEPTION_RECORD ExceptionRecord, PKEXCEPTION_FRAME ExceptionFrame, PKTRAP_FRAME Tf, KPROCESSOR_MODE PreviousMode, BOOLEAN SearchFrames)
 
VOID NTAPI KeTrapFrameToContext (IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame, IN OUT PCONTEXT Context)
 
DECLSPEC_NORETURN VOID NTAPI KeBugCheckWithTf (ULONG BugCheckCode, ULONG_PTR BugCheckParameter1, ULONG_PTR BugCheckParameter2, ULONG_PTR BugCheckParameter3, ULONG_PTR BugCheckParameter4, PKTRAP_FRAME Tf)
 
BOOLEAN NTAPI KiHandleNmi (VOID)
 
VOID NTAPI KeFlushCurrentTb (VOID)
 
BOOLEAN NTAPI KeInvalidateAllCaches (VOID)
 
VOID FASTCALL KeZeroPages (IN PVOID Address, IN ULONG Size)
 
BOOLEAN FASTCALL KeInvalidAccessAllowed (IN PVOID TrapInformation OPTIONAL)
 
VOID NTAPI KeRosDumpStackFrames (PULONG_PTR Frame, ULONG FrameCount)
 
VOID NTAPI KeSetSystemTime (IN PLARGE_INTEGER NewSystemTime, OUT PLARGE_INTEGER OldSystemTime, IN BOOLEAN FixInterruptTime, IN PLARGE_INTEGER HalTime)
 
ULONG NTAPI KeV86Exception (ULONG ExceptionNr, PKTRAP_FRAME Tf, ULONG address)
 
VOID NTAPI KiStartUnexpectedRange (VOID)
 
VOID NTAPI KiEndUnexpectedRange (VOID)
 
NTSTATUS NTAPI KiRaiseException (IN PEXCEPTION_RECORD ExceptionRecord, IN PCONTEXT Context, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame, IN BOOLEAN SearchFrames)
 
NTSTATUS NTAPI KiContinue (IN PCONTEXT Context, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
 
DECLSPEC_NORETURN VOID FASTCALL KiServiceExit (IN PKTRAP_FRAME TrapFrame, IN NTSTATUS Status)
 
DECLSPEC_NORETURN VOID FASTCALL KiServiceExit2 (IN PKTRAP_FRAME TrapFrame)
 
VOID FASTCALL KiInterruptDispatch (IN PKTRAP_FRAME TrapFrame, IN PKINTERRUPT Interrupt)
 
VOID FASTCALL KiChainedDispatch (IN PKTRAP_FRAME TrapFrame, IN PKINTERRUPT Interrupt)
 
VOID NTAPI KiInitializeMachineType (VOID)
 
VOID NTAPI KiSetupStackAndInitializeKernel (IN PKPROCESS InitProcess, IN PKTHREAD InitThread, IN PVOID IdleStack, IN PKPRCB Prcb, IN CCHAR Number, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID NTAPI KiInitSpinLocks (IN PKPRCB Prcb, IN CCHAR Number)
 
LARGE_INTEGER NTAPI KiComputeReciprocal (IN LONG Divisor, OUT PUCHAR Shift)
 
VOID NTAPI KiInitSystem (VOID)
 
VOID FASTCALL KiInsertQueueApc (IN PKAPC Apc, IN KPRIORITY PriorityBoost)
 
NTSTATUS NTAPI KiCallUserMode (IN PVOID *OutputBuffer, IN PULONG OutputLength)
 
DECLSPEC_NORETURN VOID FASTCALL KiCallbackReturn (IN PVOID Stack, IN NTSTATUS Status)
 
VOID NTAPI KiInitMachineDependent (VOID)
 
BOOLEAN NTAPI KeFreezeExecution (IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
 
VOID NTAPI KeThawExecution (IN BOOLEAN Enable)
 
VOID FASTCALL KeAcquireQueuedSpinLockAtDpcLevel (IN OUT PKSPIN_LOCK_QUEUE LockQueue)
 
VOID FASTCALL KeReleaseQueuedSpinLockFromDpcLevel (IN OUT PKSPIN_LOCK_QUEUE LockQueue)
 
VOID NTAPI KiRestoreProcessorControlState (IN PKPROCESSOR_STATE ProcessorState)
 
VOID NTAPI KiSaveProcessorControlState (OUT PKPROCESSOR_STATE ProcessorState)
 
VOID NTAPI KiSaveProcessorState (IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
 
VOID FASTCALL KiRetireDpcList (IN PKPRCB Prcb)
 
VOID NTAPI KiQuantumEnd (VOID)
 
VOID FASTCALL KiIdleLoop (VOID)
 
DECLSPEC_NORETURN VOID FASTCALL KiSystemFatalException (IN ULONG ExceptionCode, IN PKTRAP_FRAME TrapFrame)
 
PVOID NTAPI KiPcToFileHeader (IN PVOID Eip, OUT PLDR_DATA_TABLE_ENTRY *LdrEntry, IN BOOLEAN DriversOnly, OUT PBOOLEAN InKernel)
 
PVOID NTAPI KiRosPcToUserFileHeader (IN PVOID Eip, OUT PLDR_DATA_TABLE_ENTRY *LdrEntry)
 
PCHAR NTAPI KeBugCheckUnicodeToAnsi (IN PUNICODE_STRING Unicode, OUT PCHAR Ansi, IN ULONG Length)
 

Variables

KAFFINITY KeActiveProcessors
 
PKNMI_HANDLER_CALLBACK KiNmiCallbackListHead
 
KSPIN_LOCK KiNmiCallbackListLock
 
PVOID KeUserApcDispatcher
 
PVOID KeUserCallbackDispatcher
 
PVOID KeUserExceptionDispatcher
 
PVOID KeRaiseUserExceptionDispatcher
 
LARGE_INTEGER KeBootTime
 
ULONGLONG KeBootTimeBias
 
BOOLEAN ExCmosClockIsSane
 
USHORT KeProcessorArchitecture
 
USHORT KeProcessorLevel
 
USHORT KeProcessorRevision
 
ULONG KeFeatureBits
 
KNODE KiNode0
 
PKNODE KeNodeBlock [1]
 
UCHAR KeNumberNodes
 
UCHAR KeProcessNodeSeed
 
ETHREAD KiInitialThread
 
EPROCESS KiInitialProcess
 
PULONG KiInterruptTemplateObject
 
PULONG KiInterruptTemplateDispatch
 
PULONG KiInterruptTemplate2ndDispatch
 
ULONG KiUnexpectedEntrySize
 
ULONG_PTR KiDoubleFaultStack
 
EX_PUSH_LOCK KernelAddressSpaceLock
 
ULONG KiMaximumDpcQueueDepth
 
ULONG KiMinimumDpcRate
 
ULONG KiAdjustDpcThreshold
 
ULONG KiIdealDpcRate
 
BOOLEAN KeThreadDpcEnable
 
LARGE_INTEGER KiTimeIncrementReciprocal
 
UCHAR KiTimeIncrementShiftCount
 
ULONG KiTimeLimitIsrMicroseconds
 
ULONG KiServiceLimit
 
LIST_ENTRY KeBugcheckCallbackListHead
 
LIST_ENTRY KeBugcheckReasonCallbackListHead
 
KSPIN_LOCK BugCheckCallbackLock
 
KDPC KiTimerExpireDpc
 
KTIMER_TABLE_ENTRY KiTimerTableListHead [TIMER_TABLE_SIZE]
 
FAST_MUTEX KiGenericCallDpcMutex
 
LIST_ENTRY KiProfileListHead
 
LIST_ENTRY KiProfileSourceListHead
 
KSPIN_LOCK KiProfileLock
 
LIST_ENTRY KiProcessListHead
 
LIST_ENTRY KiProcessInSwapListHead
 
LIST_ENTRY KiProcessOutSwapListHead
 
LIST_ENTRY KiStackInSwapListHead
 
KEVENT KiSwapEvent
 
PKPRCB KiProcessorBlock []
 
ULONG KiMask32Array [MAXIMUM_PRIORITY]
 
ULONG_PTR KiIdleSummary
 
ULONG KeTimeIncrement
 
ULONG KeTimeAdjustment
 
BOOLEAN KiTimeAdjustmentEnabled
 
LONG KiTickOffset
 
ULONG_PTR KiBugCheckData [5]
 
ULONG KiFreezeFlag
 
ULONG KiDPCTimeout
 
PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch
 
ULONGLONG BootCycles
 
ULONGLONG BootCyclesEnd
 
ULONG ProcessCount
 

Macro Definition Documentation

#define MAX_TIMER_DPCS   16

Definition at line 57 of file ke.h.

Referenced by KiTimerExpiration(), and KiTimerListExpire().

#define PRIORITY_MASK (   Id)    KiMask32Array[Id]
#define TIMER_OR_EVENT_TYPE   0x7L

Definition at line 152 of file ke.h.

#define TIMER_WAIT_BLOCK   0x3L

Typedef Documentation

typedef PCHAR(NTAPI * PKE_BUGCHECK_UNICODE_TO_ANSI)(IN PUNICODE_STRING Unicode, IN PCHAR Ansi, IN ULONG Length)

Definition at line 75 of file ke.h.

Enumeration Type Documentation

Enumerator
NoConnect 
NormalConnect 
ChainConnect 
UnknownConnect 

Definition at line 20 of file ke.h.

21 {
22  NoConnect,
enum _CONNECT_TYPE CONNECT_TYPE
Definition: ke.h:22
enum _CONNECT_TYPE * PCONNECT_TYPE

Function Documentation

VOID NTAPI DbgBreakPointNoBugCheck ( VOID  )
VOID NTAPI Ke386SetIOPL ( VOID  )

Definition at line 578 of file v86vdm.c.

Referenced by NtSetInformationProcess().

579 {
580 
582  PKPROCESS Process = Thread->ApcState.Process;
583  PKTRAP_FRAME TrapFrame;
585 
586  /* IOPL was enabled for this process/thread */
587  Process->Iopl = TRUE;
588  Thread->Iopl = TRUE;
589 
590  /* Get the trap frame on exit */
591  TrapFrame = KeGetTrapFrame(Thread);
592 
593  /* Convert to a context */
594  Context.ContextFlags = CONTEXT_CONTROL;
595  KeTrapFrameToContext(TrapFrame, NULL, &Context);
596 
597  /* Set the IOPL flag */
598  Context.EFlags |= EFLAGS_IOPL;
599 
600  /* Convert back to a trap frame */
601  KeContextToTrapFrame(&Context, NULL, TrapFrame, CONTEXT_CONTROL, UserMode);
602 }
VOID NTAPI KeContextToTrapFrame(PCONTEXT Context, PKEXCEPTION_FRAME ExeptionFrame, PKTRAP_FRAME TrapFrame, ULONG ContextFlags, KPROCESSOR_MODE PreviousMode)
#define TRUE
Definition: numbers.c:17
KAPC_STATE ApcState
Definition: ketypes.h:969
smooth NULL
Definition: ftsmooth.c:464
ULONG EFlags
Definition: nt_native.h:1478
VOID NTAPI KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame, IN OUT PCONTEXT Context)
Definition: context.c:146
ULONG ContextFlags
Definition: compat.h:331
#define CONTEXT_CONTROL
Definition: compat.h:265
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define EFLAGS_IOPL
Definition: cpu.c:17
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
struct tagContext Context
Definition: acpixf.h:1013
#define KeGetCurrentThread
Definition: hal.h:44
#define KeGetTrapFrame(Thread)
Definition: ke.h:121
VOID FASTCALL KeAcquireQueuedSpinLockAtDpcLevel ( IN OUT PKSPIN_LOCK_QUEUE  LockQueue)

Referenced by MiAllocatePoolPages().

ULONG NTAPI KeAlertResumeThread ( IN PKTHREAD  Thread)

Definition at line 133 of file thrdobj.c.

Referenced by NtAlertResumeThread().

134 {
135  ULONG PreviousCount;
136  KLOCK_QUEUE_HANDLE ApcLock;
139 
140  /* Lock the Dispatcher Database and the APC Queue */
141  KiAcquireApcLock(Thread, &ApcLock);
143 
144  /* Return if Thread is already alerted. */
145  if (!Thread->Alerted[KernelMode])
146  {
147  /* If it's Blocked, unblock if it we should */
148  if ((Thread->State == Waiting) && (Thread->Alertable))
149  {
150  /* Abort the wait */
152  }
153  else
154  {
155  /* If not, simply Alert it */
156  Thread->Alerted[KernelMode] = TRUE;
157  }
158  }
159 
160  /* Save the old Suspend Count */
161  PreviousCount = Thread->SuspendCount;
162 
163  /* If the thread is suspended, decrease one of the suspend counts */
164  if (PreviousCount)
165  {
166  /* Decrease count. If we are now zero, unwait it completely */
167  Thread->SuspendCount--;
168  if (!(Thread->SuspendCount) && !(Thread->FreezeCount))
169  {
170  /* Signal and satisfy */
171  Thread->SuspendSemaphore.Header.SignalState++;
172  KiWaitTest(&Thread->SuspendSemaphore.Header, IO_NO_INCREMENT);
173  }
174  }
175 
176  /* Release Locks and return the Old State */
179  KiExitDispatcher(ApcLock.OldIrql);
180  return PreviousCount;
181 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
VOID FASTCALL KiUnwaitThread(IN PKTHREAD Thread, IN LONG_PTR WaitStatus, IN KPRIORITY Increment)
Definition: wait.c:89
#define TRUE
Definition: numbers.c:17
FORCEINLINE VOID KiAcquireApcLock(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:600
VOID FASTCALL KiWaitTest(PVOID Object, KPRIORITY Increment)
#define STATUS_ALERTED
Definition: ntstatus.h:80
#define ASSERT_THREAD(object)
Definition: ketypes.h:1372
FORCEINLINE VOID KiReleaseApcLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:635
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define THREAD_ALERT_INCREMENT
Definition: ketypes.h:126
FORCEINLINE VOID KiAcquireDispatcherLockAtDpcLevel(VOID)
Definition: ke_x.h:160
BOOLEAN NTAPI KeAlertThread ( IN PKTHREAD  Thread,
IN KPROCESSOR_MODE  AlertMode 
)

Definition at line 185 of file thrdobj.c.

Referenced by NtAlertThread().

187 {
189  KLOCK_QUEUE_HANDLE ApcLock;
192 
193  /* Lock the Dispatcher Database and the APC Queue */
194  KiAcquireApcLock(Thread, &ApcLock);
196 
197  /* Save the Previous State */
198  PreviousState = Thread->Alerted[AlertMode];
199 
200  /* Check if it's already alerted */
201  if (!PreviousState)
202  {
203  /* Check if the thread is alertable, and blocked in the given mode */
204  if ((Thread->State == Waiting) &&
205  (Thread->Alertable) &&
206  (AlertMode <= Thread->WaitMode))
207  {
208  /* Abort the wait to alert the thread */
210  }
211  else
212  {
213  /* Otherwise, merely set the alerted state */
214  Thread->Alerted[AlertMode] = TRUE;
215  }
216  }
217 
218  /* Release the Dispatcher Lock */
221  KiExitDispatcher(ApcLock.OldIrql);
222 
223  /* Return the old state */
224  return PreviousState;
225 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
VOID FASTCALL KiUnwaitThread(IN PKTHREAD Thread, IN LONG_PTR WaitStatus, IN KPRIORITY Increment)
Definition: wait.c:89
#define TRUE
Definition: numbers.c:17
FORCEINLINE VOID KiAcquireApcLock(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:600
#define STATUS_ALERTED
Definition: ntstatus.h:80
#define ASSERT_THREAD(object)
Definition: ketypes.h:1372
FORCEINLINE VOID KiReleaseApcLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:635
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
unsigned char BOOLEAN
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_In_ PLARGE_INTEGER _In_opt_ PTIMER_APC_ROUTINE _In_opt_ PVOID _In_ BOOLEAN _In_opt_ LONG _Out_opt_ PBOOLEAN PreviousState
Definition: zwfuncs.h:428
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
#define THREAD_ALERT_INCREMENT
Definition: ketypes.h:126
FORCEINLINE VOID KiAcquireDispatcherLockAtDpcLevel(VOID)
Definition: ke_x.h:160
VOID NTAPI KeBalanceSetManager ( IN PVOID  Context)

Definition at line 137 of file balmgr.c.

Referenced by MmInitBsmThread().

138 {
139  KDPC ScanDpc;
140  KTIMER PeriodTimer;
143  PVOID WaitObjects[1];
145 
146  /* Set us at a low real-time priority level */
148 
149  /* Setup the timer and scanner DPC */
152 
153  /* Setup the periodic timer */
154  DueTime.QuadPart = -1 * 10 * 1000 * 1000;
155  KeSetTimerEx(&PeriodTimer, DueTime, 1000, &ScanDpc);
156 
157  /* Setup the wait objects */
158  WaitObjects[0] = &PeriodTimer;
159  //WaitObjects[1] = MmWorkingSetManagerEvent; // NO WS Management Yet!
160 
161  /* Start wait loop */
162  do
163  {
164  /* Wait on our objects */
165  Status = KeWaitForMultipleObjects(1,
166  WaitObjects,
167  WaitAny,
168  Executive,
169  KernelMode,
170  FALSE,
171  NULL,
172  WaitBlockArray);
173  switch (Status)
174  {
175  /* Check if our timer expired */
176  case STATUS_WAIT_0:
177 
178  /* Adjust lookaside lists */
179  //ExAdjustLookasideDepth();
180 
181  /* Call the working set manager */
182  //MmWorkingSetManager();
183 
184  /* FIXME: Outswap stacks */
185 
186  /* Done */
187  break;
188 
189  /* Check if the working set manager notified us */
190  case STATUS_WAIT_1:
191 
192  /* Call the working set manager */
193  //MmWorkingSetManager();
194  break;
195 
196  /* Anything else */
197  default:
198  DPRINT1("BALMGR: Illegal wait status, %lx =\n", Status);
199  break;
200  }
201  } while (TRUE);
202 }
DWORD *typedef PVOID
Definition: winlogon.h:52
ULONG KiReadyScanLast
Definition: balmgr.c:18
_In_ LARGE_INTEGER DueTime
Definition: kefuncs.h:524
#define TRUE
Definition: numbers.c:17
BOOLEAN NTAPI KeSetTimerEx(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN LONG Period, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:294
#define LOW_REALTIME_PRIORITY
#define STATUS_WAIT_1
Definition: ntstatus.h:71
#define STATUS_WAIT_0
Definition: ntstatus.h:223
smooth NULL
Definition: ftsmooth.c:464
VOID NTAPI KiScanReadyQueues(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: balmgr.c:24
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586
Definition: ketypes.h:672
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1327
#define DPRINT1
Definition: precomp.h:8
#define FALSE
Definition: numbers.c:16
_Must_inspect_result_ _In_ WAIT_TYPE _In_opt_ PLARGE_INTEGER _In_opt_ PKWAIT_BLOCK WaitBlockArray
Definition: fsrtlfuncs.h:1151
#define KeGetCurrentThread
Definition: hal.h:44
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
VOID NTAPI KeInitializeTimerEx(OUT PKTIMER Timer, IN TIMER_TYPE Type)
Definition: timerobj.c:244
LONGLONG QuadPart
Definition: typedefs.h:113
VOID NTAPI KeBoostPriorityThread ( IN PKTHREAD  Thread,
IN KPRIORITY  Increment 
)

Definition at line 229 of file thrdobj.c.

Referenced by NtSetInformationProcess().

231 {
232  KIRQL OldIrql;
235 
236  /* Lock the Dispatcher Database */
237  OldIrql = KiAcquireDispatcherLock();
238 
239  /* Only threads in the dynamic range get boosts */
240  if (Thread->Priority < LOW_REALTIME_PRIORITY)
241  {
242  /* Lock the thread */
244 
245  /* Check again, and make sure there's not already a boost */
246  if ((Thread->Priority < LOW_REALTIME_PRIORITY) &&
247  !(Thread->PriorityDecrement))
248  {
249  /* Compute the new priority and see if it's higher */
250  Priority = Thread->BasePriority + Increment;
251  if (Priority > Thread->Priority)
252  {
253  if (Priority >= LOW_REALTIME_PRIORITY)
254  {
255  Priority = LOW_REALTIME_PRIORITY - 1;
256  }
257 
258  /* Reset the quantum */
259  Thread->Quantum = Thread->QuantumReset;
260 
261  /* Set the new Priority */
262  KiSetPriorityThread(Thread, Priority);
263  }
264  }
265 
266  /* Release thread lock */
268  }
269 
270  /* Release the dispatcher lokc */
271  KiReleaseDispatcherLock(OldIrql);
272 }
FORCEINLINE VOID KiReleaseThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:244
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
_In_ KPRIORITY Priority
Definition: kefuncs.h:516
#define LOW_REALTIME_PRIORITY
LONG KPRIORITY
Definition: compat.h:454
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID FASTCALL KiSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdschd.c:511
FORCEINLINE VOID KiAcquireThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:234
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE VOID KiReleaseDispatcherLock(IN KIRQL OldIrql)
Definition: ke_x.h:152
FORCEINLINE KIRQL KiAcquireDispatcherLock(VOID)
Definition: ke_x.h:144
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42
PCHAR NTAPI KeBugCheckUnicodeToAnsi ( IN PUNICODE_STRING  Unicode,
OUT PCHAR  Ansi,
IN ULONG  Length 
)

Definition at line 552 of file bug.c.

Referenced by KeBugCheckWithTf(), KeRosDumpStackFrameArray(), and KiDisplayBlueScreen().

555 {
556  PCHAR p;
557  PWCHAR pw;
558  ULONG i;
559 
560  /* Set length and normalize it */
561  i = Unicode->Length / sizeof(WCHAR);
562  i = min(i, Length - 1);
563 
564  /* Set source and destination, and copy */
565  pw = Unicode->Buffer;
566  p = Ansi;
567  while (i--) *p++ = (CHAR)*pw++;
568 
569  /* Null terminate and return */
570  *p = ANSI_NULL;
571  return Ansi;
572 }
uint16_t * PWCHAR
Definition: typedefs.h:55
#define WCHAR
Definition: msvc.h:43
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define ANSI_NULL
VOID UINTN Length
Definition: acefiex.h:718
#define min(a, b)
Definition: monoChain.cc:55
signed char * PCHAR
Definition: retypes.h:7
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
#define CHAR(Char)
DECLSPEC_NORETURN VOID NTAPI KeBugCheckWithTf ( ULONG  BugCheckCode,
ULONG_PTR  BugCheckParameter1,
ULONG_PTR  BugCheckParameter2,
ULONG_PTR  BugCheckParameter3,
ULONG_PTR  BugCheckParameter4,
PKTRAP_FRAME  Tf 
)
BOOLEAN NTAPI KeDisableThreadApcQueueing ( IN PKTHREAD  Thread)
VOID NTAPI KeDumpStackFrames ( PULONG  Frame)

Definition at line 92 of file stubs.c.

93 {
94 }
UCHAR NTAPI KeFindNextRightSetAffinity ( IN UCHAR  Number,
IN ULONG  Set 
)

Definition at line 32 of file thrdobj.c.

Referenced by KeInitializeProcess(), and KeStartThread().

34 {
35  ULONG Bit, Result;
36  ASSERT(Set != 0);
37 
38  /* Calculate the mask */
39  Bit = (AFFINITY_MASK(Number) - 1) & Set;
40 
41  /* If it's 0, use the one we got */
42  if (!Bit) Bit = Set;
43 
44  /* Now find the right set and return it */
45  BitScanReverse(&Result, Bit);
46  return (UCHAR)Result;
47 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define AFFINITY_MASK(Id)
Definition: ke.h:148
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
unsigned char UCHAR
Definition: xmlstorage.h:181
#define BitScanReverse
Definition: interlocked.h:6
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
void Set(const char *const tok1, const char *const tok2)
Definition: pref.c:430
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KeFlushCurrentTb ( VOID  )

Definition at line 332 of file cpu.c.

Referenced by KeFlushEntireTb(), KeThawExecution(), KiFlushTargetEntireTb(), MiDeletePte(), MiFlushTbAndCapture(), MiFlushTlbIpiRoutine(), MiInitializePageTable(), MiInitMachineDependent(), MiProcessValidPteList(), MiRemoveMappedPtes(), and MmFreeLoaderBlock().

333 {
334  /* Flush the TLB by resetting CR3 */
336 }
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1601
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1572
PLIST_ENTRY NTAPI KeFlushQueueApc ( IN PKTHREAD  Thread,
IN KPROCESSOR_MODE  PreviousMode 
)

Definition at line 793 of file apc.c.

Referenced by PspExitThread().

795 {
796  PKAPC Apc;
797  PLIST_ENTRY FirstEntry, CurrentEntry;
798  KLOCK_QUEUE_HANDLE ApcLock;
800 
801  /* Check if this was user mode */
802  if (PreviousMode == UserMode)
803  {
804  /* Get the APC lock */
805  KiAcquireApcLock(Thread, &ApcLock);
806 
807  /* Select user list and check if it's empty */
808  if (IsListEmpty(&Thread->ApcState.ApcListHead[UserMode]))
809  {
810  /* Don't return anything */
811  FirstEntry = NULL;
812  goto FlushDone;
813  }
814  }
815  else
816  {
817  /* Select kernel list and check if it's empty */
818  if (IsListEmpty( &Thread->ApcState.ApcListHead[KernelMode]))
819  {
820  /* Don't return anything */
821  return NULL;
822  }
823 
824  /* Otherwise, acquire the APC lock */
825  KiAcquireApcLock(Thread, &ApcLock);
826  }
827 
828  /* Get the first entry and check if the list is empty now */
829  FirstEntry = Thread->ApcState.ApcListHead[PreviousMode].Flink;
830  if (FirstEntry == &Thread->ApcState.ApcListHead[PreviousMode])
831  {
832  /* It is, clear the returned entry */
833  FirstEntry = NULL;
834  }
835  else
836  {
837  /* It's not, remove the first entry */
838  RemoveEntryList(&Thread->ApcState.ApcListHead[PreviousMode]);
839 
840  /* Loop all the entries */
841  CurrentEntry = FirstEntry;
842  do
843  {
844  /* Get the APC and make it un-inserted */
845  Apc = CONTAINING_RECORD(CurrentEntry, KAPC, ApcListEntry);
846  Apc->Inserted = FALSE;
847 
848  /* Get the next entry */
849  CurrentEntry = CurrentEntry->Flink;
850  } while (CurrentEntry != FirstEntry);
851 
852  /* Re-initialize the list */
853  InitializeListHead(&Thread->ApcState.ApcListHead[PreviousMode]);
854  }
855 
856  /* Release the lock */
857 FlushDone:
858  KiReleaseApcLock(&ApcLock);
859 
860  /* Return the first entry */
861  return FirstEntry;
862 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
FORCEINLINE VOID KiAcquireApcLock(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:600
FORCEINLINE VOID KiReleaseApcLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:627
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
smooth NULL
Definition: ftsmooth.c:464
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
Definition: ketypes.h:520
Definition: typedefs.h:118
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define FALSE
Definition: numbers.c:16
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
BOOLEAN Inserted
Definition: ketypes.h:540
ULONG NTAPI KeForceResumeThread ( IN PKTHREAD  Thread)

Definition at line 276 of file thrdobj.c.

Referenced by PspCreateThread(), PspExitThread(), PspTerminateThreadByPointer(), and PsSuspendThread().

277 {
278  KLOCK_QUEUE_HANDLE ApcLock;
279  ULONG PreviousCount;
282 
283  /* Lock the APC Queue */
284  KiAcquireApcLock(Thread, &ApcLock);
285 
286  /* Save the old Suspend Count */
287  PreviousCount = Thread->SuspendCount + Thread->FreezeCount;
288 
289  /* If the thread is suspended, wake it up!!! */
290  if (PreviousCount)
291  {
292  /* Unwait it completely */
293  Thread->SuspendCount = 0;
294  Thread->FreezeCount = 0;
295 
296  /* Lock the dispatcher */
298 
299  /* Signal and satisfy */
300  Thread->SuspendSemaphore.Header.SignalState++;
301  KiWaitTest(&Thread->SuspendSemaphore.Header, IO_NO_INCREMENT);
302 
303  /* Release the dispatcher */
305  }
306 
307  /* Release Lock and return the Old State */
309  KiExitDispatcher(ApcLock.OldIrql);
310  return PreviousCount;
311 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
FORCEINLINE VOID KiAcquireApcLock(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:600
VOID FASTCALL KiWaitTest(PVOID Object, KPRIORITY Increment)
#define ASSERT_THREAD(object)
Definition: ketypes.h:1372
FORCEINLINE VOID KiReleaseApcLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:635
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
FORCEINLINE VOID KiAcquireDispatcherLockAtDpcLevel(VOID)
Definition: ke_x.h:160
VOID NTAPI KeFreezeAllThreads ( VOID  )

Definition at line 315 of file thrdobj.c.

Referenced by DbgkpSuspendProcess().

316 {
318  PKTHREAD Current, CurrentThread = KeGetCurrentThread();
319  PKPROCESS Process = CurrentThread->ApcState.Process;
320  PLIST_ENTRY ListHead, NextEntry;
321  LONG OldCount;
323 
324  /* Lock the process */
325  KiAcquireProcessLock(Process, &LockHandle);
326 
327  /* If someone is already trying to free us, try again */
328  while (CurrentThread->FreezeCount)
329  {
330  /* Release and re-acquire the process lock so the APC will go through */
331  KiReleaseProcessLock(&LockHandle);
332  KiAcquireProcessLock(Process, &LockHandle);
333  }
334 
335  /* Enter a critical region */
337 
338  /* Loop the Process's Threads */
339  ListHead = &Process->ThreadListHead;
340  NextEntry = ListHead->Flink;
341  do
342  {
343  /* Get the current thread */
344  Current = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
345 
346  /* Lock it */
347  KiAcquireApcLockAtDpcLevel(Current, &ApcLock);
348 
349  /* Make sure it's not ours, and check if APCs are enabled */
350  if ((Current != CurrentThread) && (Current->ApcQueueable))
351  {
352  /* Sanity check */
353  OldCount = Current->SuspendCount;
354  ASSERT(OldCount != MAXIMUM_SUSPEND_COUNT);
355 
356  /* Increase the freeze count */
357  Current->FreezeCount++;
358 
359  /* Make sure it wasn't already suspended */
360  if (!(OldCount) && !(Current->SuspendCount))
361  {
362  /* Did we already insert it? */
363  if (!Current->SuspendApc.Inserted)
364  {
365  /* Insert the APC */
366  Current->SuspendApc.Inserted = TRUE;
368  }
369  else
370  {
371  /* Lock the dispatcher */
373 
374  /* Unsignal the semaphore, the APC was already inserted */
376 
377  /* Release the dispatcher */
379  }
380  }
381  }
382 
383  /* Release the APC lock */
385 
386  /* Move to the next thread */
387  NextEntry = NextEntry->Flink;
388  } while (NextEntry != ListHead);
389 
390  /* Release the process lock and exit the dispatcher */
392  KiExitDispatcher(LockHandle.OldIrql);
393 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
ULONG FreezeCount
Definition: ketypes.h:1225
FORCEINLINE VOID KiReleaseProcessLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:660
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define TRUE
Definition: numbers.c:17
VOID FASTCALL KiInsertQueueApc(IN PKAPC Apc, IN KPRIORITY PriorityBoost)
Definition: apc.c:85
FORCEINLINE VOID KiAcquireApcLockAtDpcLevel(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:609
KSEMAPHORE SuspendSemaphore
Definition: ketypes.h:1339
long LONG
Definition: pedump.c:60
KAPC_STATE ApcState
Definition: ketypes.h:969
FORCEINLINE VOID KiReleaseApcLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:635
LIST_ENTRY ThreadListHead
Definition: ketypes.h:1403
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
CCHAR SuspendCount
Definition: ketypes.h:1257
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
FORCEINLINE VOID KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:652
#define MAXIMUM_SUSPEND_COUNT
Definition: winbase.h:377
FORCEINLINE VOID KiAcquireProcessLock(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
Definition: typedefs.h:118
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
DISPATCHER_HEADER Header
Definition: ketypes.h:789
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
BOOLEAN Inserted
Definition: ketypes.h:540
PKTHREAD NTAPI KeGetCurrentThread(VOID)
Definition: thrdobj.c:957
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:742
ULONG ApcQueueable
Definition: ketypes.h:1084
KAPC SuspendApc
Definition: ketypes.h:1285
FORCEINLINE VOID KiAcquireDispatcherLockAtDpcLevel(VOID)
Definition: ke_x.h:160
BOOLEAN NTAPI KeFreezeExecution ( IN PKTRAP_FRAME  TrapFrame,
IN PKEXCEPTION_FRAME  ExceptionFrame 
)

Definition at line 26 of file freeze.c.

Referenced by KdEnterDebugger().

28 {
30 
31  /* Disable interrupts and get previous state */
32  Enable = KeDisableInterrupts();
33 
34  /* Save freeze flag */
35  KiFreezeFlag = 4;
36 
37  /* Save the old IRQL */
39 
40  /* Return whether interrupts were enabled */
41  return Enable;
42 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
BOOLEAN Enable
Definition: acefiex.h:245
FORCEINLINE BOOLEAN KeDisableInterrupts(VOID)
Definition: ke.h:152
unsigned char BOOLEAN
KIRQL KiOldIrql
Definition: freeze.c:19
ULONG KiFreezeFlag
Definition: freeze.c:20
VOID NTAPI KeInitExceptions ( VOID  )

Definition at line 59 of file except.c.

Referenced by KiSystemStartup().

60 {
61  int i, j;
62 
63  /* Initialize the Idt */
64  for (j = i = 0; i < 256; i++)
65  {
67 
68  if (KiInterruptInitTable[j].InterruptId == i)
69  {
73  j++;
74  }
75  else
76  {
77  Offset = (ULONG64)&KiUnexpectedRange[i]._Op_push;
78  KiIdt[i].Dpl = 0;
79  KiIdt[i].IstIndex = 0;
80  }
81  KiIdt[i].OffsetLow = Offset & 0xffff;
83  KiIdt[i].Type = 0x0e;
84  KiIdt[i].Reserved0 = 0;
85  KiIdt[i].Present = 1;
86  KiIdt[i].OffsetMiddle = (Offset >> 16) & 0xffff;
87  KiIdt[i].OffsetHigh = (Offset >> 32);
88  KiIdt[i].Reserved1 = 0;
89  }
90 
91  KeGetPcr()->IdtBase = KiIdt;
93 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
UCHAR IstIndex
Definition: ke.h:69
KIDTENTRY64 KiIdt[256]
Definition: except.c:50
__INTRIN_INLINE void __lidt(void *Source)
Definition: intrin_x86.h:1808
UCHAR Dpl
Definition: ke.h:68
#define KeGetPcr()
Definition: ke.h:25
USHORT Selector
Definition: ketypes.h:467
USHORT Limit
Definition: ketypes.h:485
GLenum GLclampf GLint i
Definition: glfuncs.h:14
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
uint64_t ULONG64
Definition: typedefs.h:66
USHORT OffsetLow
Definition: ketypes.h:466
USHORT Reserved0
Definition: ketypes.h:469
USHORT Type
Definition: ketypes.h:470
USHORT Present
Definition: ketypes.h:472
USHORT OffsetMiddle
Definition: ketypes.h:473
#define KGDT64_R0_CODE
Definition: ketypes.h:72
USHORT IstIndex
Definition: ketypes.h:468
USHORT Dpl
Definition: ketypes.h:471
ULONG Reserved1
Definition: ketypes.h:475
KI_INTERRUPT_DISPATCH_ENTRY KiUnexpectedRange[256]
KIDT_INIT KiInterruptInitTable[]
Definition: except.c:20
KDESCRIPTOR KiIdtDescriptor
Definition: except.c:51
ULONG OffsetHigh
Definition: ketypes.h:474
_In_ PKSERVICE_ROUTINE ServiceRoutine
Definition: iofuncs.h:798
VOID NTAPI KeInitializeEventPair ( PKEVENT_PAIR  EventPair)

Referenced by NtCreateEventPair().

VOID NTAPI KeInitializeProcess ( struct _KPROCESS Process,
KPRIORITY  Priority,
KAFFINITY  Affinity,
PULONG_PTR  DirectoryTableBase,
IN BOOLEAN  Enable 
)
VOID NTAPI KeInitializeProfile ( struct _KPROFILE Profile,
struct _KPROCESS Process,
PVOID  ImageBase,
SIZE_T  ImageSize,
ULONG  BucketSize,
KPROFILE_SOURCE  ProfileSource,
KAFFINITY  Affinity 
)

Referenced by NtStartProfile().

VOID NTAPI KeInitializeThread ( IN PKPROCESS  Process,
IN OUT PKTHREAD  Thread,
IN PKSYSTEM_ROUTINE  SystemRoutine,
IN PKSTART_ROUTINE  StartRoutine,
IN PVOID  StartContext,
IN PCONTEXT  Context,
IN PVOID  Teb,
IN PVOID  KernelStack 
)

Definition at line 900 of file thrdobj.c.

Referenced by KiInitializeHandBuiltThread(), and KiInitializeKernel().

908 {
909  /* Initialize and start the thread on success */
911  KernelStack,
912  SystemRoutine,
913  StartRoutine,
914  StartContext,
915  Context,
916  Teb,
917  Process)))
918  {
919  /* Start it */
921  }
922 }
VOID NTAPI KeStartThread(IN OUT PKTHREAD Thread)
Definition: thrdobj.c:498
_In_ ULONG _In_opt_ POBJECT_ATTRIBUTES _In_opt_ HANDLE _Out_opt_ PCLIENT_ID _In_ PKSTART_ROUTINE StartRoutine
Definition: psfuncs.h:87
NTSTATUS NTAPI KeInitThread(IN OUT PKTHREAD Thread, IN PVOID KernelStack, IN PKSYSTEM_ROUTINE SystemRoutine, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext, IN PCONTEXT Context, IN PVOID Teb, IN PKPROCESS Process)
Definition: thrdobj.c:765
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
VOID NTAPI KeInitInterrupts ( VOID  )

Definition at line 151 of file ppc_irq.c.

152 {
153  int i, j;
154 
155  /*
156  * Setup the IDT entries to point to the interrupt handlers
157  */
158  for (i=0;i<NR_TRAPS;i++)
159  {
160 #ifdef CONFIG_SMP
161  for (j = 0; j < MAXIMUM_PROCESSORS; j++)
162 #else
163  j = 0;
164 #endif
165  {
166  InitializeListHead(&IsrTable[i][j].ListHead);
168  IsrTable[i][j].Count = 0;
169  }
170  }
171 }
#define MAXIMUM_PROCESSORS
Definition: rwlock.h:5
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
GLenum GLclampf GLint i
Definition: glfuncs.h:14
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
ULONG Count
Definition: ppc_irq.c:134
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static ISR_TABLE IsrTable[NR_TRAPS][1]
Definition: ppc_irq.c:141
#define NR_TRAPS
Definition: ppc_irq.c:41
BOOLEAN NTAPI KeInitSystem ( VOID  )

Definition at line 293 of file krnlinit.c.

Referenced by Phase1InitializationDiscard().

294 {
295  /* Check if Threaded DPCs are enabled */
296  if (KeThreadDpcEnable)
297  {
298  /* FIXME: TODO */
299  DPRINT1("Threaded DPCs not yet supported\n");
300  }
301 
302  /* Initialize non-portable parts of the kernel */
304  return TRUE;
305 }
VOID NTAPI KiInitMachineDependent(VOID)
Definition: kiinit.c:47
#define TRUE
Definition: numbers.c:17
BOOLEAN KeThreadDpcEnable
Definition: dpc.c:23
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI KeInitThread ( IN OUT PKTHREAD  Thread,
IN PVOID  KernelStack,
IN PKSYSTEM_ROUTINE  SystemRoutine,
IN PKSTART_ROUTINE  StartRoutine,
IN PVOID  StartContext,
IN PCONTEXT  Context,
IN PVOID  Teb,
IN PKPROCESS  Process 
)

Definition at line 765 of file thrdobj.c.

Referenced by KeInitializeThread(), and PspCreateThread().

773 {
774  BOOLEAN AllocatedStack = FALSE;
775  ULONG i;
776  PKWAIT_BLOCK TimerWaitBlock;
777  PKTIMER Timer;
779 
780  /* Initialize the Dispatcher Header */
781  Thread->Header.Type = ThreadObject;
782  Thread->Header.ThreadControlFlags = 0;
783  Thread->Header.DebugActive = FALSE;
784  Thread->Header.SignalState = 0;
785  InitializeListHead(&(Thread->Header.WaitListHead));
786 
787  /* Initialize the Mutant List */
788  InitializeListHead(&Thread->MutantListHead);
789 
790  /* Initialize the wait blocks */
791  for (i = 0; i< (THREAD_WAIT_OBJECTS + 1); i++)
792  {
793  /* Put our pointer */
794  Thread->WaitBlock[i].Thread = Thread;
795  }
796 
797  /* Set swap settings */
798  Thread->EnableStackSwap = TRUE;
799  Thread->IdealProcessor = 1;
800  Thread->SwapBusy = FALSE;
801  Thread->KernelStackResident = TRUE;
802  Thread->AdjustReason = AdjustNone;
803 
804  /* Initialize the lock */
806 
807  /* Setup the Service Descriptor Table for Native Calls */
808  Thread->ServiceTable = KeServiceDescriptorTable;
809 
810  /* Setup APC Fields */
811  InitializeListHead(&Thread->ApcState.ApcListHead[KernelMode]);
812  InitializeListHead(&Thread->ApcState.ApcListHead[UserMode]);
813  Thread->ApcState.Process = Process;
814  Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->ApcState;
815  Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->SavedApcState;
816  Thread->ApcStateIndex = OriginalApcEnvironment;
817  Thread->ApcQueueable = TRUE;
818  KeInitializeSpinLock(&Thread->ApcQueueLock);
819 
820  /* Initialize the Suspend APC */
821  KeInitializeApc(&Thread->SuspendApc,
822  Thread,
824  KiSuspendNop,
827  KernelMode,
828  NULL);
829 
830  /* Initialize the Suspend Semaphore */
831  KeInitializeSemaphore(&Thread->SuspendSemaphore, 0, 2);
832 
833  /* Setup the timer */
834  Timer = &Thread->Timer;
835  KeInitializeTimer(Timer);
836  TimerWaitBlock = &Thread->WaitBlock[TIMER_WAIT_BLOCK];
837  TimerWaitBlock->Object = Timer;
838  TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
839  TimerWaitBlock->WaitType = WaitAny;
840  TimerWaitBlock->NextWaitBlock = NULL;
841 
842  /* Link the two wait lists together */
843  TimerWaitBlock->WaitListEntry.Flink = &Timer->Header.WaitListHead;
844  TimerWaitBlock->WaitListEntry.Blink = &Timer->Header.WaitListHead;
845 
846  /* Set the TEB and process */
847  Thread->Teb = Teb;
848  Thread->Process = Process;
849 
850  /* Check if we have a kernel stack */
851  if (!KernelStack)
852  {
853  /* We don't, allocate one */
854  KernelStack = MmCreateKernelStack(FALSE, 0);
855  if (!KernelStack) return STATUS_INSUFFICIENT_RESOURCES;
856 
857  /* Remember for later */
858  AllocatedStack = TRUE;
859  }
860 
861  /* Set the Thread Stacks */
862  Thread->InitialStack = KernelStack;
863  Thread->StackBase = KernelStack;
864  Thread->StackLimit = (ULONG_PTR)KernelStack - KERNEL_STACK_SIZE;
865  Thread->KernelStackResident = TRUE;
866 
867  /* Enter SEH to avoid crashes due to user mode */
868  Status = STATUS_SUCCESS;
869  _SEH2_TRY
870  {
871  /* Initialize the Thread Context */
873  SystemRoutine,
874  StartRoutine,
875  StartContext,
876  Context);
877  }
879  {
880  /* Set failure status */
881  Status = STATUS_UNSUCCESSFUL;
882 
883  /* Check if a stack was allocated */
884  if (AllocatedStack)
885  {
886  /* Delete the stack */
887  MmDeleteKernelStack((PVOID)Thread->StackBase, FALSE);
888  Thread->InitialStack = NULL;
889  }
890  }
891  _SEH2_END;
892 
893  /* Set the Thread to initialized */
894  Thread->State = Initialized;
895  return Status;
896 }
DWORD *typedef PVOID
Definition: winlogon.h:52
VOID NTAPI KeInitializeApc(IN PKAPC Apc, IN PKTHREAD Thread, IN KAPC_ENVIRONMENT TargetEnvironment, IN PKKERNEL_ROUTINE KernelRoutine, IN PKRUNDOWN_ROUTINE RundownRoutine OPTIONAL, IN PKNORMAL_ROUTINE NormalRoutine, IN KPROCESSOR_MODE Mode, IN PVOID Context)
Definition: apc.c:651
#define STATUS_SUCCESS
Definition: contextmenu.cpp:55
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LIST_ENTRY WaitListEntry
Definition: ketypes.h:444
_In_ ULONG _In_opt_ POBJECT_ATTRIBUTES _In_opt_ HANDLE _Out_opt_ PCLIENT_ID _In_ PKSTART_ROUTINE StartRoutine
Definition: psfuncs.h:87
struct _LIST_ENTRY * Blink
Definition: typedefs.h:121
VOID NTAPI MmDeleteKernelStack(PVOID Stack, BOOLEAN GuiStack)
#define TRUE
Definition: numbers.c:17
#define TIMER_WAIT_BLOCK
Definition: ke.h:155
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
VOID NTAPI KiInitializeContextThread(PKTHREAD Thread, PKSYSTEM_ROUTINE SystemRoutine, PKSTART_ROUTINE StartRoutine, PVOID StartContext, PCONTEXT Context)
GLenum GLclampf GLint i
Definition: glfuncs.h:14
DISPATCHER_HEADER Header
Definition: ketypes.h:825
VOID NTAPI KiSuspendThread(IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: thrdobj.c:596
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
smooth NULL
Definition: ftsmooth.c:464
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
unsigned char BOOLEAN
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
UCHAR WaitType
Definition: ketypes.h:449
USHORT WaitKey
Definition: ketypes.h:448
PVOID Object
Definition: ketypes.h:446
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define KERNEL_STACK_SIZE
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
UINT Timer
Definition: capclock.c:11
LONG NTSTATUS
Definition: DriverTester.h:11
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define _SEH2_TRY
Definition: pseh2_64.h:5
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]
Definition: procobj.c:23
#define FALSE
Definition: numbers.c:16
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
VOID NTAPI KiSuspendRundown(IN PKAPC Apc)
Definition: thrdobj.c:572
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
LIST_ENTRY WaitListHead
Definition: ketypes.h:781
PVOID NTAPI MmCreateKernelStack(BOOLEAN GuiStack, UCHAR Node)
EX_PUSH_LOCK ThreadLock
Definition: pstypes.h:1092
VOID NTAPI KiSuspendNop(IN PKAPC Apc, IN PKNORMAL_ROUTINE *NormalRoutine, IN PVOID *NormalContext, IN PVOID *SystemArgument1, IN PVOID *SystemArgument2)
Definition: thrdobj.c:580
#define THREAD_WAIT_OBJECTS
Definition: ketypes.h:465
struct _KWAIT_BLOCK * NextWaitBlock
Definition: ketypes.h:447
BOOLEAN FASTCALL KeInvalidAccessAllowed ( IN PVOID TrapInformation  OPTIONAL)

Definition at line 801 of file exp.c.

802 {
803  ULONG Eip;
804  PKTRAP_FRAME TrapFrame = TrapInformation;
806 
807  /* Don't do anything if we didn't get a trap frame */
808  if (!TrapInformation) return FALSE;
809 
810  /* Check where we came from */
811  switch (TrapFrame->SegCs)
812  {
813  /* Kernel mode */
814  case KGDT_R0_CODE:
815 
816  /* Allow S-LIST Routine to fail */
818  break;
819 
820  /* User code */
821  case KGDT_R3_CODE | RPL_MASK:
822 
823  /* Allow S-LIST Routine to fail */
824  //Eip = (ULONG)KeUserPopEntrySListFault;
825  Eip = 0;
826  break;
827 
828  default:
829 
830  /* Anything else gets a bugcheck */
831  Eip = 0;
832  }
833 
834  /* Return TRUE if we want to keep the system up */
835  return (TrapFrame->Eip == Eip) ? TRUE : FALSE;
836 }
#define TRUE
Definition: numbers.c:17
#define KGDT_R0_CODE
Definition: ketypes.h:74
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define RPL_MASK
Definition: ketypes.h:69
USHORT SegCs
Definition: ketypes.h:380
VOID NTAPI ExpInterlockedPopEntrySListFault(VOID)
ULONG Eip
Definition: ketypes.h:265
#define KGDT_R3_CODE
Definition: ketypes.h:76
#define FALSE
Definition: numbers.c:16
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN NTAPI KeInvalidateAllCaches ( VOID  )

Definition at line 469 of file cpu.c.

Referenced by MmMapIoSpace().

470 {
471  /* Invalidate all caches */
472  __wbinvd();
473  return TRUE;
474 }
#define TRUE
Definition: numbers.c:17
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
LONG NTAPI KeQueryBasePriorityThread ( IN PKTHREAD  Thread)

Definition at line 61 of file thrdobj.c.

Referenced by NtQueryInformationThread().

62 {
63  LONG BaseIncrement;
64  KIRQL OldIrql;
68 
69  /* Raise IRQL to synch level */
70  OldIrql = KeRaiseIrqlToSynchLevel();
71 
72  /* Lock the thread */
74 
75  /* Get the Process */
76  Process = Thread->ApcStatePointer[0]->Process;
77 
78  /* Calculate the base increment */
79  BaseIncrement = Thread->BasePriority - Process->BasePriority;
80 
81  /* If saturation occured, return the saturation increment instead */
82  if (Thread->Saturation) BaseIncrement = (HIGH_PRIORITY + 1) / 2 *
83  Thread->Saturation;
84 
85  /* Release thread lock */
87 
88  /* Lower IRQl and return Increment */
89  KeLowerIrql(OldIrql);
90  return BaseIncrement;
91 }
FORCEINLINE VOID KiReleaseThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:244
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
SCHAR BasePriority
Definition: ketypes.h:1417
#define ASSERT_THREAD(object)
Definition: ketypes.h:1372
UCHAR KIRQL
Definition: env_spec_w32.h:591
long LONG
Definition: pedump.c:60
FORCEINLINE VOID KiAcquireThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:234
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#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 HIGH_PRIORITY
KIRQL NTAPI KeRaiseIrqlToSynchLevel(VOID)
Definition: pic.c:156
ULONG NTAPI KeQueryIntervalProfile ( KPROFILE_SOURCE  ProfileSource)

Referenced by NtQueryIntervalProfile().

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

Definition at line 805 of file procobj.c.

Referenced by NtQueryInformationProcess(), and QSI_DEF().

807 {
808  ULONG TotalUser, TotalKernel;
809  KLOCK_QUEUE_HANDLE ProcessLock;
810  PLIST_ENTRY NextEntry, ListHead;
812 
814 
815  /* Initialize user and kernel times */
816  TotalUser = Process->UserTime;
817  TotalKernel = Process->KernelTime;
818 
819  /* Lock the process */
820  KiAcquireProcessLock(Process, &ProcessLock);
821 
822  /* Loop all child threads and sum up their times */
823  ListHead = &Process->ThreadListHead;
824  NextEntry = ListHead->Flink;
825  while (ListHead != NextEntry)
826  {
827  /* Get the thread */
828  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
829 
830  /* Sum up times */
831  TotalKernel += Thread->KernelTime;
832  TotalUser += Thread->UserTime;
833 
834  /* Go to the next one */
835  NextEntry = NextEntry->Flink;
836  }
837 
838  /* Release lock */
839  KiReleaseProcessLock(&ProcessLock);
840 
841  /* Return the user time */
842  *UserTime = TotalUser;
843 
844  /* Return the kernel time */
845  return TotalKernel;
846 }
_Out_ PULONG UserTime
Definition: kefuncs.h:784
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
ULONG KernelTime
Definition: ketypes.h:1305
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
FORCEINLINE VOID KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:652
FORCEINLINE VOID KiAcquireProcessLock(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
Definition: typedefs.h:118
ULONG UserTime
Definition: ketypes.h:1335
_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 CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define ASSERT_PROCESS(object)
Definition: ketypes.h:1436
BOOLEAN NTAPI KeReadStateThread ( IN PKTHREAD  Thread)

Definition at line 51 of file thrdobj.c.

Referenced by NtQueryInformationThread(), and PspExitThread().

52 {
54 
55  /* Return signal state */
56  return (BOOLEAN)Thread->Header.SignalState;
57 }
#define ASSERT_THREAD(object)
Definition: ketypes.h:1372
unsigned char BOOLEAN
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
VOID NTAPI KeReadyThread ( IN PKTHREAD  Thread)

Definition at line 115 of file thrdobj.c.

Referenced by PspCreateThread().

116 {
117  KIRQL OldIrql;
120 
121  /* Lock the Dispatcher Database */
122  OldIrql = KiAcquireDispatcherLock();
123 
124  /* Make the thread ready */
126 
127  /* Unlock dispatcher database */
128  KiReleaseDispatcherLock(OldIrql);
129 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
#define ASSERT_THREAD(object)
Definition: ketypes.h:1372
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID NTAPI KiReadyThread(IN PKTHREAD Thread)
Definition: thrdschd.c:429
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE VOID KiReleaseDispatcherLock(IN KIRQL OldIrql)
Definition: ke_x.h:152
FORCEINLINE KIRQL KiAcquireDispatcherLock(VOID)
Definition: ke_x.h:144
VOID FASTCALL KeReleaseQueuedSpinLockFromDpcLevel ( IN OUT PKSPIN_LOCK_QUEUE  LockQueue)

Referenced by MiAllocatePoolPages().

NTSTATUS NTAPI KeReleaseThread ( PKTHREAD  Thread)
BOOLEAN NTAPI KeRemoveQueueApc ( PKAPC  Apc)
ULONG NTAPI KeResumeThread ( IN PKTHREAD  Thread)

Definition at line 397 of file thrdobj.c.

Referenced by PspCreateThread(), PsResumeProcess(), and PsResumeThread().

398 {
399  KLOCK_QUEUE_HANDLE ApcLock;
400  ULONG PreviousCount;
403 
404  /* Lock the APC Queue */
405  KiAcquireApcLock(Thread, &ApcLock);
406 
407  /* Save the Old Count */
408  PreviousCount = Thread->SuspendCount;
409 
410  /* Check if it existed */
411  if (PreviousCount)
412  {
413  /* Decrease the suspend count */
414  Thread->SuspendCount--;
415 
416  /* Check if the thrad is still suspended or not */
417  if ((!Thread->SuspendCount) && (!Thread->FreezeCount))
418  {
419  /* Acquire the dispatcher lock */
421 
422  /* Signal the Suspend Semaphore */
423  Thread->SuspendSemaphore.Header.SignalState++;
424  KiWaitTest(&Thread->SuspendSemaphore.Header, IO_NO_INCREMENT);
425 
426  /* Release the dispatcher lock */
428  }
429  }
430 
431  /* Release APC Queue lock and return the Old State */
433  KiExitDispatcher(ApcLock.OldIrql);
434  return PreviousCount;
435 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
FORCEINLINE VOID KiAcquireApcLock(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:600
VOID FASTCALL KiWaitTest(PVOID Object, KPRIORITY Increment)
#define ASSERT_THREAD(object)
Definition: ketypes.h:1372
FORCEINLINE VOID KiReleaseApcLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:635
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
FORCEINLINE VOID KiAcquireDispatcherLockAtDpcLevel(VOID)
Definition: ke_x.h:160
VOID NTAPI KeRosDumpStackFrames ( PULONG_PTR  Frame,
ULONG  FrameCount 
)
VOID NTAPI KeRundownThread ( VOID  )

Definition at line 439 of file thrdobj.c.

Referenced by PspExitThread().

440 {
441  KIRQL OldIrql;
443  PLIST_ENTRY NextEntry, ListHead;
444  PKMUTANT Mutant;
446 
447  /* Optimized path if nothing is on the list at the moment */
448  if (IsListEmpty(&Thread->MutantListHead)) return;
449 
450  /* Lock the Dispatcher Database */
451  OldIrql = KiAcquireDispatcherLock();
452 
453  /* Get the List Pointers */
454  ListHead = &Thread->MutantListHead;
455  NextEntry = ListHead->Flink;
456  while (NextEntry != ListHead)
457  {
458  /* Get the Mutant */
459  Mutant = CONTAINING_RECORD(NextEntry, KMUTANT, MutantListEntry);
460  ASSERT_MUTANT(Mutant);
461 
462  /* Make sure it's not terminating with APCs off */
463  if (Mutant->ApcDisable)
464  {
465  /* Bugcheck the system */
466  KeBugCheckEx(THREAD_TERMINATE_HELD_MUTEX,
467  (ULONG_PTR)Thread,
468  (ULONG_PTR)Mutant,
469  0,
470  0);
471  }
472 
473  /* Now we can remove it */
475 
476  /* Unconditionally abandon it */
477  Mutant->Header.SignalState = 1;
478  Mutant->Abandoned = TRUE;
479  Mutant->OwnerThread = NULL;
480 
481  /* Check if the Wait List isn't empty */
482  if (!IsListEmpty(&Mutant->Header.WaitListHead))
483  {
484  /* Wake the Mutant */
486  }
487 
488  /* Move on */
489  NextEntry = Thread->MutantListHead.Flink;
490  }
491 
492  /* Release the Lock */
493  KiReleaseDispatcherLock(OldIrql);
494 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
#define TRUE
Definition: numbers.c:17
VOID FASTCALL KiWaitTest(PVOID Object, KPRIORITY Increment)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:64
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
LIST_ENTRY MutantListEntry
Definition: ketypes.h:815
smooth NULL
Definition: ftsmooth.c:464
DISPATCHER_HEADER Header
Definition: ketypes.h:814
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define MUTANT_INCREMENT
Definition: extypes.h:84
#define ASSERT_MUTANT(Object)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:118
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE VOID KiReleaseDispatcherLock(IN KIRQL OldIrql)
Definition: ke_x.h:152
FORCEINLINE KIRQL KiAcquireDispatcherLock(VOID)
Definition: ke_x.h:144
UCHAR ApcDisable
Definition: ketypes.h:818
BOOLEAN Abandoned
Definition: ketypes.h:817
struct _KTHREAD *RESTRICTED_POINTER OwnerThread
Definition: ketypes.h:816
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
PKTHREAD NTAPI KeGetCurrentThread(VOID)
Definition: thrdobj.c:957
LIST_ENTRY WaitListHead
Definition: ketypes.h:781
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:90
LIST_ENTRY MutantListHead
Definition: ketypes.h:1353
KAFFINITY NTAPI KeSetAffinityProcess ( IN PKPROCESS  Process,
IN KAFFINITY  Affinity 
)

Definition at line 265 of file procobj.c.

Referenced by NtSetInformationProcess().

267 {
268 
269  KLOCK_QUEUE_HANDLE ProcessLock;
270  PLIST_ENTRY NextEntry, ListHead;
271  KAFFINITY OldAffinity;
276 
277  /* Lock the process */
278  KiAcquireProcessLock(Process, &ProcessLock);
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 */
296  KiSetAffinityThread(Thread, Affinity);
297  NextEntry = NextEntry->Flink;
298  }
299 
300  /* Release Dispatcher Database */
302 
303  /* Release the process lock */
304  KiReleaseProcessLockFromDpcLevel(&ProcessLock);
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 KiReleaseProcessLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:660
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
_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:2653
FORCEINLINE VOID KiAcquireProcessLock(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
Definition: typedefs.h:118
KAFFINITY KeActiveProcessors
Definition: krnlinit.c:23
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
ULONG_PTR KAFFINITY
Definition: compat.h:75
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define ASSERT_PROCESS(object)
Definition: ketypes.h:1436
FORCEINLINE VOID KiAcquireDispatcherLockAtDpcLevel(VOID)
Definition: ke_x.h:160
BOOLEAN NTAPI KeSetAutoAlignmentProcess ( IN PKPROCESS  Process,
IN BOOLEAN  Enable 
)

Definition at line 313 of file procobj.c.

Referenced by NtSetInformationProcess().

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 }
BOOLEAN Enable
Definition: acefiex.h:245
#define InterlockedBitTestAndReset
Definition: interlocked.h:35
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
#define KPSF_AUTO_ALIGNMENT_BIT
Definition: pstypes.h:252
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
BOOLEAN NTAPI KeSetDisableBoostProcess ( IN PKPROCESS  Process,
IN BOOLEAN  Disable 
)

Definition at line 331 of file procobj.c.

Referenced by NtSetInformationProcess().

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 InterlockedBitTestAndReset
Definition: interlocked.h:35
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
#define KPSF_DISABLE_BOOST_BIT
Definition: pstypes.h:253
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
BOOLEAN NTAPI KeSetDisableBoostThread ( IN OUT PKTHREAD  Thread,
IN BOOLEAN  Disable 
)

Definition at line 95 of file thrdobj.c.

Referenced by NtSetInformationProcess(), and NtSetInformationThread().

97 {
99 
100  /* Check if we're enabling or disabling */
101  if (Disable)
102  {
103  /* Set the bit */
104  return InterlockedBitTestAndSet(&Thread->ThreadFlags, 1);
105  }
106  else
107  {
108  /* Remove the bit */
109  return InterlockedBitTestAndReset(&Thread->ThreadFlags, 1);
110  }
111 }
#define ASSERT_THREAD(object)
Definition: ketypes.h:1372
#define InterlockedBitTestAndReset
Definition: interlocked.h:35
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
VOID NTAPI KeSetIntervalProfile ( ULONG  Interval,
KPROFILE_SOURCE  ProfileSource 
)

Referenced by NtSetIntervalProfile().

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

Definition at line 349 of file procobj.c.

Referenced by NtSetInformationProcess(), and PsSetProcessPriorityByClass().

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 */
368  KiAcquireProcessLock(Process, &ProcessLock);
369 
370  /* Check if we are modifying the quantum too */
371  if (Quantum) Process->QuantumReset = Quantum;
372 
373  /* Save the current base priority and update it */
374  OldPriority = Process->BasePriority;
375  Process->BasePriority = (SCHAR)Priority;
376 
377  /* Calculate the priority delta */
378  Delta = Priority - OldPriority;
379 
380  /* Set the list head and list entry */
381  ListHead = &Process->ThreadListHead;
382  NextEntry = ListHead->Flink;
383 
384  /* Check if this is a real-time priority */
386  {
387  /* Loop the thread list */
388  while (NextEntry != ListHead)
389  {
390  /* Get the thread */
391  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
392 
393  /* Update the quantum if we had one */
394  if (Quantum) Thread->QuantumReset = Quantum;
395 
396  /* Acquire the thread lock */
397  KiAcquireThreadLock(Thread);
398 
399  /* Calculate the new priority */
400  NewPriority = Thread->BasePriority + Delta;
401  if (NewPriority < LOW_REALTIME_PRIORITY)
402  {
403  /* We're in real-time range, don't let it go below */
404  NewPriority = LOW_REALTIME_PRIORITY;
405  }
406  else if (NewPriority > HIGH_PRIORITY)
407  {
408  /* We're going beyond the maximum priority, normalize */
409  NewPriority = HIGH_PRIORITY;
410  }
411 
412  /*
413  * If priority saturation occured or the old priority was still in
414  * the real-time range, don't do anything.
415  */
416  if (!(Thread->Saturation) || (OldPriority < LOW_REALTIME_PRIORITY))
417  {
418  /* Check if we had priority saturation */
419  if (Thread->Saturation > 0)
420  {
421  /* Boost priority to maximum */
422  NewPriority = HIGH_PRIORITY;
423  }
424  else if (Thread->Saturation < 0)
425  {
426  /* If we had negative saturation, set minimum priority */
427  NewPriority = LOW_REALTIME_PRIORITY;
428  }
429 
430  /* Update priority and quantum */
431  Thread->BasePriority = (SCHAR)NewPriority;
432  Thread->Quantum = Thread->QuantumReset;
433 
434  /* Disable decrements and update priority */
435  Thread->PriorityDecrement = 0;
436  KiSetPriorityThread(Thread, NewPriority);
437  }
438 
439  /* Release the thread lock */
440  KiReleaseThreadLock(Thread);
441 
442  /* Go to the next thread */
443  NextEntry = NextEntry->Flink;
444  }
445  }
446  else
447  {
448  /* Loop the thread list */
449  while (NextEntry != ListHead)
450  {
451  /* Get the thread */
452  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
453 
454  /* Update the quantum if we had one */
455  if (Quantum) Thread->QuantumReset = Quantum;
456 
457  /* Lock the thread */
458  KiAcquireThreadLock(Thread);
459 
460  /* Calculate the new priority */
461  NewPriority = Thread->BasePriority + Delta;
462  if (NewPriority >= LOW_REALTIME_PRIORITY)
463  {
464  /* We're not real-time range, don't let it enter RT range */
465  NewPriority = LOW_REALTIME_PRIORITY - 1;
466  }
467  else if (NewPriority <= LOW_PRIORITY)
468  {
469  /* We're going below the minimum priority, normalize */
470  NewPriority = 1;
471  }
472 
473  /*
474  * If priority saturation occured or the old priority was still in
475  * the real-time range, don't do anything.
476  */
477  if (!(Thread->Saturation) ||
478  (OldPriority >= LOW_REALTIME_PRIORITY))
479  {
480  /* Check if we had priority saturation */
481  if (Thread->Saturation > 0)
482  {
483  /* Boost priority to maximum */
484  NewPriority = LOW_REALTIME_PRIORITY - 1;
485  }
486  else if (Thread->Saturation < 0)
487  {
488  /* If we had negative saturation, set minimum priority */
489  NewPriority = 1;
490  }
491 
492  /* Update priority and quantum */
493  Thread->BasePriority = (SCHAR)NewPriority;
494  Thread->Quantum = Thread->QuantumReset;
495 
496  /* Disable decrements and update priority */
497  Thread->PriorityDecrement = 0;
498  KiSetPriorityThread(Thread, NewPriority);
499  }
500 
501  /* Release the thread lock */
502  KiReleaseThreadLock(Thread);
503 
504  /* Go to the next thread */
505  NextEntry = NextEntry->Flink;
506  }
507  }
508 
509  /* Release Dispatcher Database */
511 
512  /* Release the process lock */
513  KiReleaseProcessLockFromDpcLevel(&ProcessLock);
514  KiExitDispatcher(ProcessLock.OldIrql);
515 
516  /* Return previous priority */
517  return OldPriority;
518 }
FORCEINLINE VOID KiReleaseThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:244
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
SCHAR PriorityDecrement
Definition: ketypes.h:1210
FORCEINLINE VOID KiReleaseProcessLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:660
_In_ KPRIORITY Priority
Definition: kefuncs.h:516
CHAR Saturation
Definition: ketypes.h:1221
#define LOW_REALTIME_PRIORITY
LONG KPRIORITY
Definition: compat.h:454
VOID FASTCALL KiSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdschd.c:511
#define LOW_PRIORITY
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
FORCEINLINE VOID KiAcquireThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:234
SCHAR BasePriority
Definition: ketypes.h:1209
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
signed char SCHAR
Definition: sqltypes.h:14
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
FORCEINLINE VOID KiAcquireProcessLock(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
Definition: typedefs.h:118
UCHAR QuantumReset
Definition: ketypes.h:1300
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
static ULONG Delta
Definition: xboxvideo.c:28
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define HIGH_PRIORITY
#define ASSERT_PROCESS(object)
Definition: ketypes.h:1436
ULONG NTAPI KeSetProcess ( struct _KPROCESS Process,
KPRIORITY  Increment,
BOOLEAN  InWait 
)

Referenced by PspExitThread().

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

Definition at line 229 of file procobj.c.

Referenced by PsChangeQuantumTable().

231 {
232  KLOCK_QUEUE_HANDLE ProcessLock;
233  PLIST_ENTRY NextEntry, ListHead;
237 
238  /* Lock the process */
239  KiAcquireProcessLock(Process, &ProcessLock);
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:250
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
FORCEINLINE VOID KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:652
FORCEINLINE VOID KiAcquireProcessLock(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
Definition: typedefs.h:118
UCHAR QuantumReset
Definition: ketypes.h:1300
#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 CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define ASSERT_PROCESS(object)
Definition: ketypes.h:1436
VOID NTAPI KeSetSystemTime ( IN PLARGE_INTEGER  NewSystemTime,
OUT PLARGE_INTEGER  OldSystemTime,
IN BOOLEAN  FixInterruptTime,
IN PLARGE_INTEGER  HalTime 
)

Definition at line 28 of file clock.c.

Referenced by ExpSetTimeZoneInformation(), NtSetSystemTime(), and Phase1InitializationDiscard().

32 {
34  KIRQL OldIrql, OldIrql2;
35  LARGE_INTEGER DeltaTime;
36  PLIST_ENTRY ListHead, NextEntry;
37  PKTIMER Timer;
38  PKSPIN_LOCK_QUEUE LockQueue;
39  LIST_ENTRY TempList, TempList2;
40  ULONG Hand, i;
41 
42  /* Sanity checks */
43  ASSERT((NewTime->HighPart & 0xF0000000) == 0);
45 
46  /* Check if this is for the HAL */
47  if (HalTime) RtlTimeToTimeFields(HalTime, &TimeFields);
48 
49  /* Set affinity to this CPU, lock the dispatcher, and raise IRQL */
51  OldIrql = KiAcquireDispatcherLock();
52  KeRaiseIrql(HIGH_LEVEL, &OldIrql2);
53 
54  /* Query the system time now */
55  KeQuerySystemTime(OldTime);
56 
57  /* Set the new system time (ordering of these operations is critical) */
58  SharedUserData->SystemTime.High2Time = NewTime->HighPart;
59  SharedUserData->SystemTime.LowPart = NewTime->LowPart;
60  SharedUserData->SystemTime.High1Time = NewTime->HighPart;
61 
62  /* Check if this was for the HAL and set the RTC time */
63  if (HalTime) ExCmosClockIsSane = HalSetRealTimeClock(&TimeFields);
64 
65  /* Calculate the difference between the new and the old time */
66  DeltaTime.QuadPart = NewTime->QuadPart - OldTime->QuadPart;
67 
68  /* Update system boot time */
69  KeBootTime.QuadPart += DeltaTime.QuadPart;
71 
72  /* Lower IRQL back */
73  KeLowerIrql(OldIrql2);
74 
75  /* Check if we need to adjust interrupt time */
76  if (FixInterruptTime) ASSERT(FALSE);
77 
78  /* Setup a temporary list of absolute timers */
79  InitializeListHead(&TempList);
80 
81  /* Loop current timers */
82  for (i = 0; i < TIMER_TABLE_SIZE; i++)
83  {
84  /* Loop the entries in this table and lock the timers */
85  ListHead = &KiTimerTableListHead[i].Entry;
86  LockQueue = KiAcquireTimerLock(i);
87  NextEntry = ListHead->Flink;
88  while (NextEntry != ListHead)
89  {
90  /* Get the timer */
91  Timer = CONTAINING_RECORD(NextEntry, KTIMER, TimerListEntry);
92  NextEntry = NextEntry->Flink;
93 
94  /* Is it absolute? */
95  if (Timer->Header.Absolute)
96  {
97  /* Remove it from the timer list */
98  KiRemoveEntryTimer(Timer);
99 
100  /* Insert it into our temporary list */
101  InsertTailList(&TempList, &Timer->TimerListEntry);
102  }
103  }
104 
105  /* Release the lock */
106  KiReleaseTimerLock(LockQueue);
107  }
108 
109  /* Setup a temporary list of expired timers */
110  InitializeListHead(&TempList2);
111 
112  /* Loop absolute timers */
113  while (TempList.Flink != &TempList)
114  {
115  /* Get the timer */
116  Timer = CONTAINING_RECORD(TempList.Flink, KTIMER, TimerListEntry);
118 
119  /* Update the due time and handle */
120  Timer->DueTime.QuadPart -= DeltaTime.QuadPart;
122  Timer->Header.Hand = (UCHAR)Hand;
123 
124  /* Lock the timer and re-insert it */
125  LockQueue = KiAcquireTimerLock(Hand);
126  if (KiInsertTimerTable(Timer, Hand))
127  {
128  /* Remove it from the timer list */
129  KiRemoveEntryTimer(Timer);
130 
131  /* Insert it into our temporary list */
132  InsertTailList(&TempList2, &Timer->TimerListEntry);
133  }
134 
135  /* Release the lock */
136  KiReleaseTimerLock(LockQueue);
137  }
138 
139  /* Process expired timers. This releases the dispatcher lock. */
140  KiTimerListExpire(&TempList2, OldIrql);
141 
142  /* Revert affinity */
144 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
VOID NTAPI KeRevertToUserAffinityThread(VOID)
Definition: thrdobj.c:1030
FORCEINLINE PKSPIN_LOCK_QUEUE KiAcquireTimerLock(IN ULONG Hand)
Definition: ke_x.h:280
ULONGLONG KeBootTimeBias
Definition: clock.c:18
LIST_ENTRY TimerListEntry
Definition: ketypes.h:827
VOID FASTCALL KiTimerListExpire(IN PLIST_ENTRY ExpiredListHead, IN KIRQL OldIrql)
Definition: dpc.c:338
#define InsertTailList(ListHead, Entry)
VOID NTAPI KeSetSystemAffinityThread(IN KAFFINITY Affinity)
Definition: thrdobj.c:1116
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
GLenum GLclampf GLint i
Definition: glfuncs.h:14
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
LARGE_INTEGER KeBootTime
Definition: clock.c:17
VOID NTAPI KeQuerySystemTime(OUT PLARGE_INTEGER CurrentTime)
Definition: clock.c:184
DISPATCHER_HEADER Header
Definition: ketypes.h:825
BOOLEAN ExCmosClockIsSane
Definition: init.c:89
BOOLEAN FASTCALL KiInsertTimerTable(IN PKTIMER Timer, IN ULONG Hand)
Definition: timerobj.c:63
BOOLEAN RtlTimeToTimeFields(IN PLARGE_INTEGER Time, IN PTIME_FIELDS TimeFields)
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
#define TIMER_TABLE_SIZE
Definition: ketypes.h:821
LIST_ENTRY Entry
Definition: ketypes.h:666
ULARGE_INTEGER DueTime
Definition: ketypes.h:826
KTIMER_TABLE_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE]
Definition: timerobj.c:17
#define SharedUserData
unsigned char UCHAR
Definition: xmlstorage.h:181
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:118
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
UINT Timer
Definition: capclock.c:11
FORCEINLINE KIRQL KiAcquireDispatcherLock(VOID)
Definition: ke_x.h:144
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
FORCEINLINE VOID KiRemoveEntryTimer(IN PKTIMER Timer)
Definition: ke_x.h:884
#define FALSE
Definition: numbers.c:16
unsigned int ULONG
Definition: retypes.h:1
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static PTIME_FIELDS TimeFields
Definition: time.c:27
FORCEINLINE ULONG KiComputeTimerTableIndex(IN ULONGLONG DueTime)
Definition: ke_x.h:873
FORCEINLINE VOID KiReleaseTimerLock(IN PKSPIN_LOCK_QUEUE LockQueue)
Definition: ke_x.h:291
BOOLEAN NTAPI HalSetRealTimeClock(IN PTIME_FIELDS Time)
Definition: rtc.c:45
LONGLONG QuadPart
Definition: typedefs.h:113
VOID FASTCALL KeSignalGateBoostPriority ( PKGATE  Gate)
BOOLEAN NTAPI KeStartProfile ( struct _KPROFILE Profile,
PVOID  Buffer 
)

Referenced by NtStartProfile().

VOID NTAPI KeStartThread ( IN OUT PKTHREAD  Thread)

Definition at line 498 of file thrdobj.c.

Referenced by KeInitializeThread(), and PspCreateThread().

499 {
501 #ifdef CONFIG_SMP
502  PKNODE Node;
503  PKPRCB NodePrcb;
504  ULONG Set, Mask;
505 #endif
506  UCHAR IdealProcessor = 0;
507  PKPROCESS Process = Thread->ApcState.Process;
508 
509  /* Setup static fields from parent */
510  Thread->DisableBoost = Process->DisableBoost;
511 #if defined(_M_IX86)
512  Thread->Iopl = Process->Iopl;
513 #endif
514  Thread->Quantum = Process->QuantumReset;
515  Thread->QuantumReset = Process->QuantumReset;
516  Thread->SystemAffinityActive = FALSE;
517 
518  /* Lock the process */
519  KiAcquireProcessLock(Process, &LockHandle);
520 
521  /* Setup volatile data */
522  Thread->Priority = Process->BasePriority;
523  Thread->BasePriority = Process->BasePriority;
524  Thread->Affinity = Process->Affinity;
525  Thread->UserAffinity = Process->Affinity;
526 
527 #ifdef CONFIG_SMP
528  /* Get the KNODE and its PRCB */
529  Node = KeNodeBlock[Process->IdealNode];
530  NodePrcb = KiProcessorBlock[Process->ThreadSeed];
531 
532  /* Calculate affinity mask */
533 #ifdef _M_ARM
534  DbgBreakPoint();
535  Set = 0;
536 #else
537  Set = ~NodePrcb->MultiThreadProcessorSet;
538 #endif
539  Mask = (ULONG)(Node->ProcessorMask & Process->Affinity);
540  Set &= Mask;
541  if (Set) Mask = Set;
542 
543  /* Get the new thread seed */
544  IdealProcessor = KeFindNextRightSetAffinity(Process->ThreadSeed, Mask);
545  Process->ThreadSeed = IdealProcessor;
546 
547  /* Sanity check */
548  ASSERT((Thread->UserAffinity & AFFINITY_MASK(IdealProcessor)));
549 #endif
550 
551  /* Set the Ideal Processor */
552  Thread->IdealProcessor = IdealProcessor;
553  Thread->UserIdealProcessor = IdealProcessor;
554 
555  /* Lock the Dispatcher Database */
557 
558  /* Insert the thread into the process list */
560 
561  /* Increase the stack count */
562  ASSERT(Process->StackCount != MAXULONG_PTR);
563  Process->StackCount++;
564 
565  /* Release locks and return */
567  KiReleaseProcessLock(&LockHandle);
568 }
SCHAR QuantumReset
Definition: ketypes.h:1418
LIST_ENTRY ThreadListEntry
Definition: pstypes.h:1090
LONG DisableBoost
Definition: ketypes.h:1411
UCHAR NTAPI KeFindNextRightSetAffinity(IN UCHAR Number, IN ULONG Set)
Definition: thrdobj.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
SCHAR BasePriority
Definition: ketypes.h:1417
#define MAXULONG_PTR
Definition: basetsd.h:102
#define AFFINITY_MASK(Id)
Definition: ke.h:148
#define InsertTailList(ListHead, Entry)
void DbgBreakPoint()
Definition: mach.c:558
ULONG StackCount
Definition: ketypes.h:1429
LIST_ENTRY ThreadListHead
Definition: ketypes.h:1403
KAFFINITY Affinity
Definition: ketypes.h:1405
PKNODE KeNodeBlock[1]
Definition: krnlinit.c:39
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
FORCEINLINE VOID KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:652
unsigned char UCHAR
Definition: xmlstorage.h:181
UCHAR ThreadSeed
Definition: ketypes.h:1420
UCHAR IdealNode
Definition: ketypes.h:1422
FORCEINLINE VOID KiAcquireProcessLock(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
void Set(const char *const tok1, const char *const tok2)
Definition: pref.c:430
UINT64 MultiThreadProcessorSet
Definition: ketypes.h:752
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define FALSE
Definition: numbers.c:16
unsigned int ULONG
Definition: retypes.h:1
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:742
KAFFINITY ProcessorMask
Definition: ketypes.h:776
union gl_dlist_node Node
Definition: dlist.c:302
FORCEINLINE VOID KiAcquireDispatcherLockAtDpcLevel(VOID)
Definition: ke_x.h:160
BOOLEAN NTAPI KeStopProfile ( struct _KPROFILE Profile)

Referenced by ExpDeleteProfile(), and NtStopProfile().

ULONG NTAPI KeSuspendThread ( PKTHREAD  Thread)

Definition at line 610 of file thrdobj.c.

Referenced by NtSetSystemPowerState(), PspCreateThread(), and PsSuspendThread().

611 {
612  KLOCK_QUEUE_HANDLE ApcLock;
613  ULONG PreviousCount;
614  ASSERT_THREAD(Thread);
616 
617  /* Lock the APC Queue */
618  KiAcquireApcLock(Thread, &ApcLock);
619 
620  /* Save the Old Count */
621  PreviousCount = Thread->SuspendCount;
622 
623  /* Handle the maximum */
624  if (PreviousCount == MAXIMUM_SUSPEND_COUNT)
625  {
626  /* Raise an exception */
627  KiReleaseApcLock(&ApcLock);
629  }
630 
631  /* Should we bother to queue at all? */
632  if (Thread->ApcQueueable)
633  {
634  /* Increment the suspend count */
635  Thread->SuspendCount++;
636 
637  /* Check if we should suspend it */
638  if (!(PreviousCount) && !(Thread->FreezeCount))
639  {
640  /* Is the APC already inserted? */
641  if (!Thread->SuspendApc.Inserted)
642  {
643  /* Not inserted, insert it */
644  Thread->SuspendApc.Inserted = TRUE;
646  }
647  else
648  {
649  /* Lock the dispatcher */
651 
652  /* Unsignal the semaphore, the APC was already inserted */
654 
655  /* Release the dispatcher */
657  }
658  }
659  }
660 
661  /* Release Lock and return the Old State */
663  KiExitDispatcher(ApcLock.OldIrql);
664  return PreviousCount;
665 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
ULONG FreezeCount
Definition: ketypes.h:1225
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
#define TRUE
Definition: numbers.c:17
FORCEINLINE VOID KiAcquireApcLock(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:600
VOID FASTCALL KiInsertQueueApc(IN PKAPC Apc, IN KPRIORITY PriorityBoost)
Definition: apc.c:85
FORCEINLINE VOID KiReleaseApcLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:627
#define ASSERT_THREAD(object)
Definition: ketypes.h:1372
KSEMAPHORE SuspendSemaphore
Definition: ketypes.h:1339
FORCEINLINE VOID KiReleaseApcLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:635
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
CCHAR SuspendCount
Definition: ketypes.h:1257
#define MAXIMUM_SUSPEND_COUNT
Definition: winbase.h:377
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
DISPATCHER_HEADER Header
Definition: ketypes.h:789
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
BOOLEAN Inserted
Definition: ketypes.h:540
ULONG ApcQueueable
Definition: ketypes.h:1084
#define STATUS_SUSPEND_COUNT_EXCEEDED
Definition: ntstatus.h:296
KAPC SuspendApc
Definition: ketypes.h:1285
FORCEINLINE VOID KiAcquireDispatcherLockAtDpcLevel(VOID)
Definition: ke_x.h:160
PVOID NTAPI KeSwitchKernelStack ( IN PVOID  StackBase,
IN PVOID  StackLimit 
)

Referenced by PsConvertToGuiThread().

BOOLEAN NTAPI KeTestAlertThread ( IN KPROCESSOR_MODE  AlertMode)

Definition at line 731 of file thrdobj.c.

Referenced by KiDeliverApc(), NtContinue(), and NtTestAlert().

732 {
734  BOOLEAN OldState;
735  KLOCK_QUEUE_HANDLE ApcLock;
736  ASSERT_THREAD(Thread);
738 
739  /* Lock the Dispatcher Database and the APC Queue */
740  KiAcquireApcLock(Thread, &ApcLock);
741 
742  /* Save the old State */
743  OldState = Thread->Alerted[AlertMode];
744 
745  /* Check the Thread is alerted */
746  if (OldState)
747  {
748  /* Disable alert for this mode */
749  Thread->Alerted[AlertMode] = FALSE;
750  }
751  else if ((AlertMode != KernelMode) &&
752  (!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode])))
753  {
754  /* If the mode is User and the Queue isn't empty, set Pending */
755  Thread->ApcState.UserApcPending = TRUE;
756  }
757 
758  /* Release Locks and return the Old State */
759  KiReleaseApcLock(&ApcLock);
760  return OldState;
761 }
BOOLEAN Alerted[2]
Definition: ketypes.h:944
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
#define TRUE
Definition: numbers.c:17
FORCEINLINE VOID KiAcquireApcLock(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:600
FORCEINLINE VOID KiReleaseApcLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:627
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define ASSERT_THREAD(object)
Definition: ketypes.h:1372
KAPC_STATE ApcState
Definition: ketypes.h:969
unsigned char BOOLEAN
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define FALSE
Definition: numbers.c:16
PKTHREAD NTAPI KeGetCurrentThread(VOID)
Definition: thrdobj.c:957
VOID NTAPI KeThawAllThreads ( VOID  )

Definition at line 669 of file thrdobj.c.

Referenced by DbgkpResumeProcess().

670 {
672  PKTHREAD Current, CurrentThread = KeGetCurrentThread();
673  PKPROCESS Process = CurrentThread->ApcState.Process;
674  PLIST_ENTRY ListHead, NextEntry;
675  LONG OldCount;
677 
678  /* Lock the process */
679  KiAcquireProcessLock(Process, &LockHandle);
680 
681  /* Loop the Process's Threads */
682  ListHead = &Process->ThreadListHead;
683  NextEntry = ListHead->Flink;
684  do
685  {
686  /* Get the current thread */
687  Current = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
688 
689  /* Lock it */
690  KiAcquireApcLockAtDpcLevel(Current, &ApcLock);
691 
692  /* Make sure we are frozen */
693  OldCount = Current->FreezeCount;
694  if (OldCount)
695  {
696  /* Decrease the freeze count */
697  Current->FreezeCount--;
698 
699  /* Check if both counts are zero now */
700  if (!(Current->SuspendCount) && (!Current->FreezeCount))
701  {
702  /* Lock the dispatcher */
704 
705  /* Signal the suspend semaphore and wake it */
707  KiWaitTest(&Current->SuspendSemaphore, 0);
708 
709  /* Unlock the dispatcher */
711  }
712  }
713 
714  /* Release the APC lock */
716 
717  /* Go to the next one */
718  NextEntry = NextEntry->Flink;
719  } while (NextEntry != ListHead);
720 
721  /* Release the process lock and exit the dispatcher */
723  KiExitDispatcher(LockHandle.OldIrql);
724 
725  /* Leave the critical region */
727 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:250
ULONG FreezeCount
Definition: ketypes.h:1225
FORCEINLINE VOID KiReleaseProcessLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:660
VOID FASTCALL KiWaitTest(PVOID Object, KPRIORITY Increment)
FORCEINLINE VOID KiAcquireApcLockAtDpcLevel(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:609
KSEMAPHORE SuspendSemaphore
Definition: ketypes.h:1339
long LONG
Definition: pedump.c:60
KAPC_STATE ApcState
Definition: ketypes.h:969
FORCEINLINE VOID KiReleaseApcLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:635
LIST_ENTRY ThreadListHead
Definition: ketypes.h:1403
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
CCHAR SuspendCount
Definition: ketypes.h:1257
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
FORCEINLINE VOID KiAcquireProcessLock(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
Definition: typedefs.h:118
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
DISPATCHER_HEADER Header
Definition: ketypes.h:789
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
PKTHREAD NTAPI KeGetCurrentThread(VOID)
Definition: thrdobj.c:957
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:742
FORCEINLINE VOID KiAcquireDispatcherLockAtDpcLevel(VOID)
Definition: ke_x.h:160
VOID NTAPI KeThawExecution ( IN BOOLEAN  Enable)

Definition at line 46 of file freeze.c.

Referenced by KdExitDebugger().

47 {
48  /* Cleanup CPU caches */
50 
51  /* Re-enable interrupts */
52  if (Enable) _enable();
53 }
BOOLEAN Enable
Definition: acefiex.h:245
void __cdecl _enable(void)
Definition: intrin_arm.h:373
VOID NTAPI KeFlushCurrentTb(VOID)
Definition: cpu.c:332
VOID NTAPI KeTrapFrameToContext ( IN PKTRAP_FRAME  TrapFrame,
IN PKEXCEPTION_FRAME  ExceptionFrame,
IN OUT PCONTEXT  Context 
)

Definition at line 146 of file context.c.

Referenced by GspBreakIn(), Ke386SetIOPL(), KiDispatchException(), KiInitializeUserApc(), KiSaveProcessorState(), and PspGetContext().

149 {
150  KIRQL OldIrql;
151 
152  /* Do this at APC_LEVEL */
153  OldIrql = KeGetCurrentIrql();
154  if (OldIrql < APC_LEVEL) KeRaiseIrql(APC_LEVEL, &OldIrql);
155 
156  /* Handle integer registers */
157  if ((Context->ContextFlags & CONTEXT_INTEGER) == CONTEXT_INTEGER)
158  {
159  Context->Rax = TrapFrame->Rax;
160  Context->Rbx = TrapFrame->Rbx;
161  Context->Rcx = TrapFrame->Rcx;
162  Context->Rdx = TrapFrame->Rdx;
163  Context->Rsi = TrapFrame->Rsi;
164  Context->Rdi = TrapFrame->Rdi;
165  Context->Rbp = TrapFrame->Rbp;
166  Context->R8 = TrapFrame->R8;
167  Context->R9 = TrapFrame->R9;
168  Context->R10 = TrapFrame->R10;
169  Context->R11 = TrapFrame->R11;
170 
171  if (ExceptionFrame)
172  {
173  Context->R12 = ExceptionFrame->R12;
174  Context->R13 = ExceptionFrame->R13;
175  Context->R14 = ExceptionFrame->R14;
176  Context->R15 = ExceptionFrame->R15;
177  }
178  }
179 
180  /* Handle floating point registers */
181  if (((Context->ContextFlags & CONTEXT_FLOATING_POINT) ==
182  CONTEXT_FLOATING_POINT) && (TrapFrame->SegCs & MODE_MASK))
183  {
184  Context->Xmm0 = TrapFrame->Xmm0;
185  Context->Xmm1 = TrapFrame->Xmm1;
186  Context->Xmm2 = TrapFrame->Xmm2;
187  Context->Xmm3 = TrapFrame->Xmm3;
188  Context->Xmm4 = TrapFrame->Xmm4;
189  Context->Xmm5 = TrapFrame->Xmm5;
190  if (ExceptionFrame)
191  {
192  Context->Xmm6 = ExceptionFrame->Xmm6;
193  Context->Xmm7 = ExceptionFrame->Xmm7;
194  Context->Xmm8 = ExceptionFrame->Xmm8;
195  Context->Xmm9 = ExceptionFrame->Xmm9;
196  Context->Xmm10 = ExceptionFrame->Xmm10;
197  Context->Xmm11 = ExceptionFrame->Xmm11;
198  Context->Xmm12 = ExceptionFrame->Xmm12;
199  Context->Xmm13 = ExceptionFrame->Xmm13;
200  Context->Xmm14 = ExceptionFrame->Xmm14;
201  Context->Xmm15 = ExceptionFrame->Xmm15;
202  }
203  }
204 
205  /* Handle control registers */
206  if ((Context->ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL)
207  {
208  /* Check if this was a Kernel Trap */
209  if (TrapFrame->SegCs == KGDT64_R0_CODE)
210  {
211  /* Set valid selectors */
212  Context->SegCs = KGDT64_R0_CODE;
213  Context->SegSs = KGDT64_R0_DATA;
214  }
215  else
216  {
217  /* Copy selectors */
218  Context->SegCs = TrapFrame->SegCs;
219  Context->SegSs = TrapFrame->SegSs;
220  }
221 
222  /* Copy RIP, RSP, EFLAGS */
223  Context->Rip = TrapFrame->Rip;
224  Context->Rsp = TrapFrame->Rsp;
225  Context->EFlags = TrapFrame->EFlags;
226  }
227 
228  /* Handle segment selectors */
229  if ((Context->ContextFlags & CONTEXT_SEGMENTS) == CONTEXT_SEGMENTS)
230  {
231  /* Check if this was a Kernel Trap */
232  if (TrapFrame->SegCs == KGDT64_R0_CODE)
233  {
234  /* Set valid selectors */
235  Context->SegDs = KGDT64_R3_DATA | RPL_MASK;
236  Context->SegEs = KGDT64_R3_DATA | RPL_MASK;
237  Context->SegFs = KGDT64_R3_CMTEB | RPL_MASK;
238  Context->SegGs = KGDT64_R3_DATA | RPL_MASK;
239  }
240  else
241  {
242  /* Copy selectors */
243  Context->SegDs = TrapFrame->SegDs;
244  Context->SegEs = TrapFrame->SegEs;
245  Context->SegFs = TrapFrame->SegFs;
246  Context->SegGs = TrapFrame->SegGs;
247  }
248  }
249 
250  /* Handle debug registers */
251  if ((Context->ContextFlags & CONTEXT_DEBUG_REGISTERS) ==
253  {
254  /* Copy the debug registers */
255  Context->Dr0 = TrapFrame->Dr0;
256  Context->Dr1 = TrapFrame->Dr1;
257  Context->Dr2 = TrapFrame->Dr2;
258  Context->Dr3 = TrapFrame->Dr3;
259  Context->Dr6 = TrapFrame->Dr6;
260  Context->Dr7 = TrapFrame->Dr7;
261  }
262 
263  /* Restore IRQL */
264  if (OldIrql < APC_LEVEL) KeLowerIrql(OldIrql);
265 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define MODE_MASK
Definition: orders.h:326
#define KGDT64_R3_CMTEB
Definition: ketypes.h:78
#define CONTEXT_SEGMENTS
Definition: nt_native.h:1371
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KGDT64_R3_DATA
Definition: ketypes.h:75
#define RPL_MASK
Definition: ketypes.h:69
#define CONTEXT_CONTROL
Definition: compat.h:265
#define KGDT64_R0_CODE
Definition: ketypes.h:72
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define CONTEXT_FLOATING_POINT
Definition: compat.h:267
#define KGDT64_R0_DATA
Definition: ketypes.h:73
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define CONTEXT_INTEGER
Definition: compat.h:266
#define CONTEXT_DEBUG_REGISTERS
Definition: compat.h:268
VOID NTAPI KeUninitThread ( IN PKTHREAD  Thread)

Definition at line 926 of file thrdobj.c.

Referenced by PspCreateThread().

927 {
928  /* Delete the stack */
929  MmDeleteKernelStack((PVOID)Thread->StackBase, FALSE);
930  Thread->InitialStack = NULL;
931 }
DWORD *typedef PVOID
Definition: winlogon.h:52
VOID NTAPI MmDeleteKernelStack(PVOID Stack, BOOLEAN GuiStack)
smooth NULL
Definition: ftsmooth.c:464
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define FALSE
Definition: numbers.c:16
VOID NTAPI KeUpdateRunTime ( PKTRAP_FRAME  TrapFrame,
KIRQL  Irql 
)
ULONG NTAPI KeV86Exception ( ULONG  ExceptionNr,
PKTRAP_FRAME  Tf,
ULONG  address 
)
VOID FASTCALL KeWaitForGate ( PKGATE  Gate,
KWAIT_REASON  WaitReason,
KPROCESSOR_MODE  WaitMode 
)
VOID FASTCALL KeZeroPages ( IN PVOID  Address,
IN ULONG  Size 
)

Definition at line 82 of file stubs.c.

Referenced by MiSessionInitializeWorkingSetList(), MiZeroPfn(), and MiZeroPhysicalPage().

84 {
85  /* Not using XMMI in this routine */
87 }
PVOID ULONG Address
Definition: oprghdlr.h:14
UINTN Size
Definition: acefiex.h:550
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
VOID FASTCALL KiAcquireFastMutex ( IN PFAST_MUTEX  FastMutex)

Definition at line 107 of file wait.c.

Referenced by _ExAcquireFastMutex(), and _ExAcquireFastMutexUnsafe().

108 {
109  /* Increase contention count */
110  FastMutex->Contention++;
111 
112  /* Wait for the event */
113  KeWaitForSingleObject(&FastMutex->Event,
114  WrMutex,
115  KernelMode,
116  FALSE,
117  NULL);
118 }
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
smooth NULL
Definition: ftsmooth.c:464
#define FALSE
Definition: numbers.c:16
VOID FASTCALL KiAcquireGuardedMutex ( IN OUT PKGUARDED_MUTEX  GuardedMutex)

Definition at line 122 of file wait.c.

Referenced by _KeAcquireGuardedMutex(), and _KeAcquireGuardedMutexUnsafe().

123 {
124  ULONG BitsToRemove, BitsToAdd;
125  LONG OldValue, NewValue;
126 
127  /* We depend on these bits being just right */
129 
130  /* Increase the contention count */
131  GuardedMutex->Contention++;
132 
133  /* Start by unlocking the Guarded Mutex */
134  BitsToRemove = GM_LOCK_BIT;
135  BitsToAdd = GM_LOCK_WAITER_INC;
136 
137  /* Start change loop */
138  for (;;)
139  {
140  /* Loop sanity checks */
141  ASSERT((BitsToRemove == GM_LOCK_BIT) ||
142  (BitsToRemove == (GM_LOCK_BIT | GM_LOCK_WAITER_WOKEN)));
143  ASSERT((BitsToAdd == GM_LOCK_WAITER_INC) ||
144  (BitsToAdd == GM_LOCK_WAITER_WOKEN));
145 
146  /* Get the Count Bits */
147  OldValue = GuardedMutex->Count;
148 
149  /* Start internal bit change loop */
150  for (;;)
151  {
152  /* Check if the Guarded Mutex is locked */
153  if (OldValue & GM_LOCK_BIT)
154  {
155  /* Sanity check */
156  ASSERT((BitsToRemove == GM_LOCK_BIT) ||
157  ((OldValue & GM_LOCK_WAITER_WOKEN) != 0));
158 
159  /* Unlock it by removing the Lock Bit */
160  NewValue = OldValue ^ BitsToRemove;
161  NewValue = InterlockedCompareExchange(&GuardedMutex->Count,
162  NewValue,
163  OldValue);
164  if (NewValue == OldValue) return;
165  }
166  else
167  {
168  /* The Guarded Mutex isn't locked, so simply set the bits */
169  NewValue = OldValue + BitsToAdd;
170  NewValue = InterlockedCompareExchange(&GuardedMutex->Count,
171  NewValue,
172  OldValue);
173  if (NewValue == OldValue) break;
174  }
175 
176  /* Old value changed, loop again */
177  OldValue = NewValue;
178  }
179 
180  /* Now we have to wait for it */
181  KeWaitForGate(&GuardedMutex->Gate, WrGuardedMutex, KernelMode);
182  ASSERT((GuardedMutex->Count & GM_LOCK_WAITER_WOKEN) != 0);
183 
184  /* Ok, the wait is done, so set the new bits */
185  BitsToRemove = GM_LOCK_BIT | GM_LOCK_WAITER_WOKEN;
186  BitsToAdd = GM_LOCK_WAITER_WOKEN;
187  }
188 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define GM_LOCK_BIT
long LONG
Definition: pedump.c:60
#define GM_LOCK_WAITER_INC
#define C_ASSERT(e)
Definition: ntstrsafe.h:22
VOID FASTCALL KeWaitForGate(PKGATE Gate, KWAIT_REASON WaitReason, KPROCESSOR_MODE WaitMode)
unsigned int ULONG
Definition: retypes.h:1
#define GM_LOCK_WAITER_WOKEN
VOID FASTCALL KiActivateWaiterQueue ( IN PKQUEUE  Queue)

Definition at line 24 of file queue.c.

Referenced by KeDelayExecutionThread(), KeRemoveQueue(), KeTerminateThread(), KeWaitForGate(), KeWaitForMultipleObjects(), and KeWaitForSingleObject().

25 {
26  PLIST_ENTRY QueueEntry;
27  PLIST_ENTRY WaitEntry;
28  PKWAIT_BLOCK WaitBlock;
30  ASSERT_QUEUE(Queue);
31 
32  /* Decrement the number of active threads */
33  Queue->CurrentCount--;
34 
35  /* Make sure the counts are OK */
36  if (Queue->CurrentCount < Queue->MaximumCount)
37  {
38  /* Get the Queue Entry */
39  QueueEntry = Queue->EntryListHead.Flink;
40 
41  /* Get the Wait Entry */
42  WaitEntry = Queue->Header.WaitListHead.Blink;
43 
44  /* Make sure that the Queue entries are not part of empty lists */
45  if ((WaitEntry != &Queue->Header.WaitListHead) &&
46  (QueueEntry != &Queue->EntryListHead))
47  {
48  /* Remove this entry */
49  RemoveEntryList(QueueEntry);
50  QueueEntry->Flink = NULL;
51 
52  /* Decrease the Signal State */
53  Queue->Header.SignalState--;
54 
55  /* Unwait the Thread */
56  WaitBlock = CONTAINING_RECORD(WaitEntry,
58  WaitListEntry);
59  Thread = WaitBlock->Thread;
60  KiUnwaitThread(Thread, (LONG_PTR)QueueEntry, IO_NO_INCREMENT);
61  }
62  }
63 }
VOID FASTCALL KiUnwaitThread(IN PKTHREAD Thread, IN LONG_PTR WaitStatus, IN KPRIORITY Increment)
Definition: wait.c:89
struct _LIST_ENTRY * Blink
Definition: typedefs.h:121
struct _KTHREAD * Thread
Definition: ketypes.h:445
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
smooth NULL
Definition: ftsmooth.c:464
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
Definition: typedefs.h:118
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define ASSERT_QUEUE(Q)
Definition: ketypes.h:1262
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
VOID NTAPI KiAddProfileEvent ( KPROFILE_SOURCE  Source,
ULONG  Pc 
)
VOID NTAPI KiAdjustQuantumThread ( IN PKTHREAD  Thread)

Definition at line 461 of file thrdschd.c.

Referenced by KeDelayExecutionThread(), KeWaitForMultipleObjects(), and KeWaitForSingleObject().

462 {
463  PKPRCB Prcb = KeGetCurrentPrcb();
464  PKTHREAD NextThread;
465 
466  /* Acquire thread and PRCB lock */
468  KiAcquirePrcbLock(Prcb);
469 
470  /* Don't adjust for RT threads */
471  if ((Thread->Priority < LOW_REALTIME_PRIORITY) &&
472  (Thread->BasePriority < (LOW_REALTIME_PRIORITY - 2)))
473  {
474  /* Decrease Quantum by one and see if we've ran out */
475  if (--Thread->Quantum <= 0)
476  {
477  /* Return quantum */
478  Thread->Quantum = Thread->QuantumReset;
479 
480  /* Calculate new Priority */
481  Thread->Priority = KiComputeNewPriority(Thread, 1);
482 
483  /* Check if there's no next thread scheduled */
484  if (!Prcb->NextThread)
485  {
486  /* Select a ready thread and check if we found one */
487  NextThread = KiSelectReadyThread(Thread->Priority, Prcb);
488  if (NextThread)
489  {
490  /* Set it on standby and switch to it */
491  NextThread->State = Standby;
492  Prcb->NextThread = NextThread;
493  }
494  }
495  else
496  {
497  /* This thread can be preempted again */
498  Thread->Preempted = FALSE;
499  }
500  }
501  }
502 
503  /* Release locks */
504  KiReleasePrcbLock(Prcb);
506  KiExitDispatcher(Thread->WaitIrql);
507 }
FORCEINLINE VOID KiReleaseThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:244
FORCEINLINE VOID KiReleasePrcbLock(IN PKPRCB Prcb)
Definition: ke_x.h:224
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1054
#define LOW_REALTIME_PRIORITY
struct _KTHREAD * NextThread
Definition: ketypes.h:567
FORCEINLINE SCHAR KiComputeNewPriority(IN PKTHREAD Thread, IN SCHAR Adjustment)
Definition: ke_x.h:1458
FORCEINLINE VOID KiAcquirePrcbLock(IN PKPRCB Prcb)
Definition: ke_x.h:214
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
FORCEINLINE VOID KiAcquireThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:234
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
FORCEINLINE PKTHREAD KiSelectReadyThread(IN KPRIORITY Priority, IN PKPRCB Prcb)
Definition: ke_x.h:1408
#define FALSE
Definition: numbers.c:16
volatile UCHAR State
Definition: ketypes.h:997
VOID NTAPI KiAttachProcess ( struct _KTHREAD Thread,
struct _KPROCESS Process,
PKLOCK_QUEUE_HANDLE  ApcLock,
struct _KAPC_STATE *  SavedApcState 
)
DECLSPEC_NORETURN VOID FASTCALL KiCallbackReturn ( IN PVOID  Stack,
IN NTSTATUS  Status 
)

Referenced by NtCallbackReturn().

NTSTATUS NTAPI KiCallUserMode ( IN PVOID OutputBuffer,
IN PULONG  OutputLength 
)

Definition at line 441 of file stubs.c.

Referenced by KeUserModeCallback().

444 {
446  __debugbreak();
447  return STATUS_UNSUCCESSFUL;
448 }
#define UNIMPLEMENTED
Definition: stubs.c:20
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
VOID FASTCALL KiChainedDispatch ( IN PKTRAP_FRAME  TrapFrame,
IN PKINTERRUPT  Interrupt 
)

Definition at line 231 of file irqobj.c.

Referenced by KiGetVectorDispatch().

233 {
234  KIRQL OldIrql, OldInterruptIrql = 0;
236  PLIST_ENTRY NextEntry, ListHead;
237 
238  /* Increase interrupt count */
239  KeGetCurrentPrcb()->InterruptCount++;
240 
241  /* Begin the interrupt, making sure it's not spurious */
242  if (HalBeginSystemInterrupt(Interrupt->Irql,
243  Interrupt->Vector,
244  &OldIrql))
245  {
246  /* Get list pointers */
247  ListHead = &Interrupt->InterruptListEntry;
248  NextEntry = ListHead; /* The head is an entry! */
249  while (TRUE)
250  {
251  /* Check if this interrupt's IRQL is higher than the current one */
252  if (Interrupt->SynchronizeIrql > Interrupt->Irql)
253  {
254  /* Raise to higher IRQL */
255  OldInterruptIrql = KfRaiseIrql(Interrupt->SynchronizeIrql);
256  }
257 
258  /* Acquire interrupt lock */
259  KxAcquireSpinLock(Interrupt->ActualLock);
260 
261  /* Call the ISR */
262  Handled = Interrupt->ServiceRoutine(Interrupt,
263  Interrupt->ServiceContext);
264 
265  /* Release interrupt lock */
266  KxReleaseSpinLock(Interrupt->ActualLock);
267 
268  /* Check if this interrupt's IRQL is higher than the current one */
269  if (Interrupt->SynchronizeIrql > Interrupt->Irql)
270  {
271  /* Lower the IRQL back */
272  ASSERT(OldInterruptIrql == Interrupt->Irql);
273  KfLowerIrql(OldInterruptIrql);
274  }
275 
276  /* Check if the interrupt got handled and it's level */
277  if ((Handled) && (Interrupt->Mode == LevelSensitive)) break;
278 
279  /* What's next? */
280  NextEntry = NextEntry->Flink;
281 
282  /* Is this the last one? */
283  if (NextEntry == ListHead)
284  {
285  /* Level should not have gotten here */
286  if (Interrupt->Mode == LevelSensitive) break;
287 
288  /* As for edge, we can only exit once nobody can handle the interrupt */
289  if (!Handled) break;
290  }
291 
292  /* Get the interrupt object for the next pass */
293  Interrupt = CONTAINING_RECORD(NextEntry, KINTERRUPT, InterruptListEntry);
294  }
295 
296  /* Now call the epilogue code */
297  KiExitInterrupt(TrapFrame, OldIrql, FALSE);
298  }
299  else
300  {
301  /* Now call the epilogue code */
302  KiExitInterrupt(TrapFrame, OldIrql, TRUE);
303  }
304 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
FORCEINLINE VOID KxReleaseSpinLock(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.h:35
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1054
#define TRUE
Definition: numbers.c:17
BOOLEAN NTAPI HalBeginSystemInterrupt(IN KIRQL Irql, IN ULONG Vector, OUT PKIRQL OldIrql)
Definition: pic.c:321
UCHAR KIRQL
Definition: env_spec_w32.h:591
FORCEINLINE VOID KxAcquireSpinLock(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.h:20
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
unsigned char BOOLEAN
_In_ BOOLEAN Handled
Definition: ketypes.h:337
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
FORCEINLINE DECLSPEC_NORETURN VOID KiExitInterrupt(IN PKTRAP_FRAME TrapFrame, IN KIRQL OldIrql, IN BOOLEAN Spurious)
Definition: irqobj.c:135
Definition: typedefs.h:118
VOID FASTCALL KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
#define FALSE
Definition: numbers.c:16
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
VOID NTAPI KiCheckForKernelApcDelivery ( VOID  )

Definition at line 36 of file apc.c.

37 {
38  KIRQL OldIrql;
39 
40  /* We should only deliver at passive */
42  {
43  /* Raise to APC and Deliver APCs, then lower back to Passive */
44  KeRaiseIrql(APC_LEVEL, &OldIrql);
45  KiDeliverApc(KernelMode, 0, 0);
47  }
48  else
49  {
50  /*
51  * If we're not at passive level it means someone raised IRQL
52  * to APC level before the critical or guarded section was entered
53  * (e.g) by a fast mutex). This implies that the APCs shouldn't
54  * be delivered now, but after the IRQL is lowered to passive
55  * level again.
56  */
57  KeGetCurrentThread()->ApcState.KernelApcPending = TRUE;
59  }
60 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define TRUE
Definition: numbers.c:17
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
VOID FASTCALL HalRequestSoftwareInterrupt(IN KIRQL Irql)
Definition: pic.c:271
#define KeGetCurrentThread
Definition: hal.h:44
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
#define APC_LEVEL
Definition: env_spec_w32.h:695
VOID FASTCALL KiCompleteTimer ( IN PKTIMER  Timer,
IN PKSPIN_LOCK_QUEUE  LockQueue 
)

Definition at line 167 of file timerobj.c.

Referenced by KxInsertTimer().

169 {
170  LIST_ENTRY ListHead;
171  BOOLEAN RequestInterrupt = FALSE;
172  DPRINT("KiCompleteTimer(): Timer %p, LockQueue: %p\n", Timer, LockQueue);
173 
174  /* Remove it from the timer list */
176 
177  /* Link the timer list to our stack */
178  ListHead.Flink = &Timer->TimerListEntry;
179  ListHead.Blink = &Timer->TimerListEntry;
180  Timer->TimerListEntry.Flink = &ListHead;
181  Timer->TimerListEntry.Blink = &ListHead;
182 
183  /* Release the timer lock */
184  KiReleaseTimerLock(LockQueue);
185 
186  /* Acquire dispatcher lock */
188 
189  /* Signal the timer if it's still on our list */
190  if (!IsListEmpty(&ListHead)) RequestInterrupt = KiSignalTimer(Timer);
191 
192  /* Release the dispatcher lock */
194 
195  /* Request a DPC if needed */
196  if (RequestInterrupt) HalRequestSoftwareInterrupt(DISPATCH_LEVEL);
197 }
struct _LIST_ENTRY * Blink
Definition: typedefs.h:121
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
void DPRINT(...)
Definition: polytest.cpp:61
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
unsigned char BOOLEAN
BOOLEAN FASTCALL KiSignalTimer(IN PKTIMER Timer)
Definition: timerobj.c:114
Definition: typedefs.h:118
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID FASTCALL HalRequestSoftwareInterrupt(IN KIRQL Irql)
Definition: pic.c:271
FORCEINLINE VOID KiRemoveEntryTimer(IN PKTIMER Timer)
Definition: ke_x.h:884
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
#define FALSE
Definition: numbers.c:16
FORCEINLINE VOID KiReleaseTimerLock(IN PKSPIN_LOCK_QUEUE LockQueue)
Definition: ke_x.h:291
FORCEINLINE VOID KiAcquireDispatcherLockAtDpcLevel(VOID)
Definition: ke_x.h:160
LARGE_INTEGER NTAPI KiComputeReciprocal ( IN LONG  Divisor,
OUT PUCHAR  Shift 
)

Definition at line 123 of file krnlinit.c.

Referenced by KiInitializeKernel().

125 {
126  LARGE_INTEGER Reciprocal = {{0, 0}};
127  LONG BitCount = 0, Remainder = 1;
128 
129  /* Start by calculating the remainder */
130  while (Reciprocal.HighPart >= 0)
131  {
132  /* Increase the loop (bit) count */
133  BitCount++;
134 
135  /* Calculate the current fraction */
136  Reciprocal.HighPart = (Reciprocal.HighPart << 1) |
137  (Reciprocal.LowPart >> 31);
138  Reciprocal.LowPart <<= 1;
139 
140  /* Double the remainder and see if we went past the divisor */
141  Remainder <<= 1;
142  if (Remainder >= Divisor)
143  {
144  /* Set the low-bit and calculate the new remainder */
145  Remainder -= Divisor;
146  Reciprocal.LowPart |= 1;
147  }
148  }
149 
150  /* Check if we have a remainder */
151  if (Remainder)
152  {
153  /* Check if the current fraction value is too large */
154  if ((Reciprocal.LowPart == 0xFFFFFFFF) &&
155  (Reciprocal.HighPart == (LONG)0xFFFFFFFF))
156  {
157  /* Set the high bit and reduce the bit count */
158  Reciprocal.LowPart = 0;
159  Reciprocal.HighPart = 0x80000000;
160  BitCount--;
161  }
162  else
163  {
164  /* Check if only the lowest bits got too large */
165  if (Reciprocal.LowPart == 0xFFFFFFFF)
166  {
167  /* Reset them and increase the high bits instead */
168  Reciprocal.LowPart = 0;
169  Reciprocal.HighPart++;
170  }
171  else
172  {
173  /* All is well, increase the low bits */
174  Reciprocal.LowPart++;
175  }
176  }
177  }
178 
179  /* Now calculate the actual shift and return the reciprocal */
180  *Shift = (UCHAR)BitCount - 64;
181  return Reciprocal;
182 }
long LONG
Definition: pedump.c:60
#define LONG
Definition: msvc.h:36
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG LowPart
Definition: typedefs.h:105
_In_ ULONG Shift
Definition: rtlfuncs.h:2683
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3046
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3046
NTSTATUS NTAPI KiContinue ( IN PCONTEXT  Context,
IN PKEXCEPTION_FRAME  ExceptionFrame,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 41 of file except.c.

Referenced by NtContinue().

44 {
48 
49  /* Raise to APC_LEVEL, only if needed */
50  if (KeGetCurrentIrql() < APC_LEVEL) KeRaiseIrql(APC_LEVEL, &OldIrql);
51 
52  /* Set up SEH to validate the context */
53  _SEH2_TRY
54  {
55  /* Check the previous mode */
56  if (PreviousMode != KernelMode)
57  {
58  /* Validate from user-mode */
60  ExceptionFrame,
61  TrapFrame);
62  }
63  else
64  {
65  /* Convert the context into Exception/Trap Frames */
67  ExceptionFrame,
68  TrapFrame,
69  Context->ContextFlags,
70  KernelMode);
71  }
72  }
74  {
75  /* Save the exception code */
76  Status = _SEH2_GetExceptionCode();
77  }
78  _SEH2_END;
79 
80  /* Lower the IRQL if needed */
81  if (OldIrql < APC_LEVEL) KeLowerIrql(OldIrql);
82 
83  /* Return status */
84  return Status;
85 }
VOID NTAPI KeContextToTrapFrame(PCONTEXT Context, PKEXCEPTION_FRAME ExeptionFrame, PKTRAP_FRAME TrapFrame, ULONG ContextFlags, KPROCESSOR_MODE PreviousMode)
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define STATUS_SUCCESS
Definition: contextmenu.cpp:55
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define KeGetPreviousMode()
Definition: ketypes.h:1081
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
VOID NTAPI KiContinuePreviousModeUser(IN PCONTEXT Context, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: except.c:20
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#define _SEH2_TRY
Definition: pseh2_64.h:5
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define APC_LEVEL
Definition: env_spec_w32.h:695
VOID FASTCALL KiDeferredReadyThread ( IN PKTHREAD  Thread)

Definition at line 79 of file thrdschd.c.

Referenced by KiInsertDeferredReadyList(), KiProcessDeferredReadyList(), and KxQueueReadyThread().

80 {
81  PKPRCB Prcb;
82  BOOLEAN Preempted;
83  ULONG Processor = 0;
84  KPRIORITY OldPriority;
85  PKTHREAD NextThread;
86 
87  /* Sanity checks */
88  ASSERT(Thread->State == DeferredReady);
89  ASSERT((Thread->Priority >= 0) && (Thread->Priority <= HIGH_PRIORITY));
90 
91  /* Check if we have any adjusts to do */
92  if (Thread->AdjustReason == AdjustBoost)
93  {
94  /* Lock the thread */
96 
97  /* Check if the priority is low enough to qualify for boosting */
98  if ((Thread->Priority <= Thread->AdjustIncrement) &&
99  (Thread->Priority < (LOW_REALTIME_PRIORITY - 3)) &&
100  !(Thread->DisableBoost))
101  {
102  /* Calculate the new priority based on the adjust increment */
103  OldPriority = min(Thread->AdjustIncrement + 1,
105 
106  /* Make sure we're not decreasing outside of the priority range */
107  ASSERT((Thread->PriorityDecrement >= 0) &&
108  (Thread->PriorityDecrement <= Thread->Priority));
109 
110  /* Calculate the new priority decrement based on the boost */
111  Thread->PriorityDecrement += ((SCHAR)OldPriority - Thread->Priority);
112 
113  /* Again verify that this decrement is valid */
114  ASSERT((Thread->PriorityDecrement >= 0) &&
115  (Thread->PriorityDecrement <= OldPriority));
116 
117  /* Set the new priority */
118  Thread->Priority = (SCHAR)OldPriority;
119  }
120 
121  /* We need 4 quanta, make sure we have them, then decrease by one */
122  if (Thread->Quantum < 4) Thread->Quantum = 4;
123  Thread->Quantum--;
124 
125  /* Make sure the priority is still valid */
126  ASSERT((Thread->Priority >= 0) && (Thread->Priority <= HIGH_PRIORITY));
127 
128  /* Release the lock and clear the adjust reason */
130  Thread->AdjustReason = AdjustNone;
131  }
132  else if (Thread->AdjustReason == AdjustUnwait)
133  {
134  /* Acquire the thread lock and check if this is a real-time thread */
136  if (Thread->Priority < LOW_REALTIME_PRIORITY)
137  {
138  /* It's not real time, but is it time critical? */
139  if (Thread->BasePriority >= (LOW_REALTIME_PRIORITY - 2))
140  {
141  /* It is, so simply reset its quantum */
142  Thread->Quantum = Thread->QuantumReset;
143  }
144  else
145  {
146  /* Has the priority been adjusted previously? */
147  if (!(Thread->PriorityDecrement) && (Thread->AdjustIncrement))
148  {
149  /* Yes, reset its quantum */
150  Thread->Quantum = Thread->QuantumReset;
151  }
152 
153  /* Wait code already handles quantum adjustment during APCs */
154  if (Thread->WaitStatus != STATUS_KERNEL_APC)
155  {
156  /* Decrease the quantum by one and check if we're out */
157  if (--Thread->Quantum <= 0)
158  {
159  /* We are, reset the quantum and get a new priority */
160  Thread->Quantum = Thread->QuantumReset;
161  Thread->Priority = KiComputeNewPriority(Thread, 1);
162  }
163  }
164  }
165 
166  /* Now check if we have no decrement and boosts are enabled */
167  if (!(Thread->PriorityDecrement) && !(Thread->DisableBoost))
168  {
169  /* Make sure we have an increment */
170  ASSERT(Thread->AdjustIncrement >= 0);
171 
172  /* Calculate the new priority after the increment */
173  OldPriority = Thread->BasePriority + Thread->AdjustIncrement;
174 
175  /* Check if this is a foreground process */
176  if (CONTAINING_RECORD(Thread->ApcState.Process, EPROCESS, Pcb)->
177  Vm.Flags.MemoryPriority == MEMORY_PRIORITY_FOREGROUND)
178  {
179  /* Apply the foreground boost */
180  OldPriority += PsPrioritySeparation;
181  }
182 
183  /* Check if this new priority is higher */
184  if (OldPriority > Thread->Priority)
185  {
186  /* Make sure we don't go into the real time range */
187  if (OldPriority >= LOW_REALTIME_PRIORITY)
188  {
189  /* Normalize it back down one notch */
190  OldPriority = LOW_REALTIME_PRIORITY - 1;
191  }
192 
193  /* Check if the priority is higher then the boosted base */
194  if (OldPriority > (Thread->BasePriority +
195  Thread->AdjustIncrement))
196  {
197  /* Setup a priority decrement to nullify the boost */
198  Thread->PriorityDecrement = ((SCHAR)OldPriority -
199  Thread->BasePriority -
200  Thread->AdjustIncrement);
201  }
202 
203  /* Make sure that the priority decrement is valid */
204  ASSERT((Thread->PriorityDecrement >= 0) &&
205  (Thread->PriorityDecrement <= OldPriority));
206 
207  /* Set this new priority */
208  Thread->Priority = (SCHAR)OldPriority;
209  }
210  }
211  }
212  else
213  {
214  /* It's a real-time thread, so just reset its quantum */
215  Thread->Quantum = Thread->QuantumReset;
216  }
217 
218  /* Make sure the priority makes sense */
219  ASSERT((Thread->Priority >= 0) && (Thread->Priority <= HIGH_PRIORITY));
220 
221  /* Release the thread lock and reset the adjust reason */
223  Thread->AdjustReason = AdjustNone;
224  }
225 
226  /* Clear thread preemption status and save current values */
227  Preempted = Thread->Preempted;
228  OldPriority = Thread->Priority;
229  Thread->Preempted = FALSE;
230 
231  /* Queue the thread on CPU 0 and get the PRCB and lock it */
232  Thread->NextProcessor = 0;
233  Prcb = KiProcessorBlock[0];
234  KiAcquirePrcbLock(Prcb);
235 
236  /* Check if we have an idle summary */
237  if (KiIdleSummary)
238  {
239  /* Clear it and set this thread as the next one */
240  KiIdleSummary = 0;
241  Thread->State = Standby;
242  Prcb->NextThread = Thread;
243 
244  /* Unlock the PRCB and return */
245  KiReleasePrcbLock(Prcb);
246  return;
247  }
248 
249  /* Set the CPU number */
250  Thread->NextProcessor = (UCHAR)Processor;
251 
252  /* Get the next scheduled thread */
253  NextThread = Prcb->NextThread;
254  if (NextThread)
255  {
256  /* Sanity check */
257  ASSERT(NextThread->State == Standby);
258 
259  /* Check if priority changed */
260  if (OldPriority > NextThread->Priority)
261  {
262  /* Preempt the thread */
263  NextThread->Preempted = TRUE;
264 
265  /* Put this one as the next one */
266  Thread->State = Standby;
267  Prcb->NextThread = Thread;
268 
269  /* Set it in deferred ready mode */
270  NextThread->State = DeferredReady;
271  NextThread->DeferredProcessor = Prcb->Number;
272  KiReleasePrcbLock(Prcb);
273  KiDeferredReadyThread(NextThread);
274  return;
275  }
276  }
277  else
278  {
279  /* Set the next thread as the current thread */
280  NextThread = Prcb->CurrentThread;