ReactOS 0.4.15-dev-7788-g1ad9096
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  _PROCESS_VALUES
 
struct  _DEFERRED_REVERSE_BARRIER
 
struct  _KI_SAMPLE_MAP
 
struct  _DPC_QUEUE_ENTRY
 
struct  _KNMI_HANDLER_CALLBACK
 

Macros

#define MAX_TIMER_DPCS   16
 
#define PRIORITY_MASK(Priority)   (1UL << (Priority))
 
#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_OBJECTPKPROFILE_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 _PROCESS_VALUES PROCESS_VALUES
 
typedef struct _PROCESS_VALUESPPROCESS_VALUES
 
typedef struct _DEFERRED_REVERSE_BARRIER DEFERRED_REVERSE_BARRIER
 
typedef struct _DEFERRED_REVERSE_BARRIERPDEFERRED_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_CALLBACKPKNMI_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 NTAPI KeStartAllProcessors (VOID)
 
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 KAFFINITY 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)
 
VOID NTAPI KeQueryValuesProcess (IN PKPROCESS Process, PPROCESS_VALUES Values)
 
BOOLEAN NTAPI KeInitSystem (VOID)
 
VOID NTAPI KeInitExceptions (VOID)
 
VOID NTAPI KeInitInterrupts (VOID)
 
VOID NTAPI KiInitializeBugCheck (VOID)
 
DECLSPEC_NORETURN 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)
 
 _IRQL_requires_min_ (DISPATCH_LEVEL) _Acquires_nonreentrant_lock_(*LockHandle -> Lock) _Acquires_exclusive_lock_(*LockHandle->Lock) VOID FASTCALL KeAcquireQueuedSpinLockAtDpcLevel(_Inout_ 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)
 
DECLSPEC_NORETURN VOID 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 []
 
KAFFINITY KiIdleSummary
 
ULONG KeTimeIncrement
 
ULONG KeTimeAdjustment
 
BOOLEAN KiTimeAdjustmentEnabled
 
LONG KiTickOffset
 
ULONG KiFreezeFlag
 
ULONG KiDPCTimeout
 
PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch
 
ULONGLONG BootCycles
 
ULONGLONG BootCyclesEnd
 
ULONG ProcessCount
 

Macro Definition Documentation

◆ MAX_TIMER_DPCS

#define MAX_TIMER_DPCS   16

Definition at line 69 of file ke.h.

◆ PRIORITY_MASK

#define PRIORITY_MASK (   Priority)    (1UL << (Priority))

Definition at line 158 of file ke.h.

◆ TIMER_OR_EVENT_TYPE

#define TIMER_OR_EVENT_TYPE   0x7L

Definition at line 161 of file ke.h.

◆ TIMER_WAIT_BLOCK

#define TIMER_WAIT_BLOCK   0x3L

Definition at line 164 of file ke.h.

Typedef Documentation

◆ CONNECT_TYPE

◆ DEFERRED_REVERSE_BARRIER

◆ DISPATCH_INFO

◆ DPC_QUEUE_ENTRY

◆ KI_SAMPLE_MAP

◆ KNMI_HANDLER_CALLBACK

◆ KPROFILE_SOURCE_OBJECT

◆ PCONNECT_TYPE

◆ PDEFERRED_REVERSE_BARRIER

◆ PDISPATCH_INFO

◆ PDPC_QUEUE_ENTRY

◆ PKE_BUGCHECK_UNICODE_TO_ANSI

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

Definition at line 86 of file ke.h.

◆ PKI_SAMPLE_MAP

◆ PKNMI_HANDLER_CALLBACK

◆ PKPROFILE_SOURCE_OBJECT

◆ PPROCESS_VALUES

◆ PROCESS_VALUES

◆ PWOW64_PROCESS

◆ WOW64_PROCESS

Enumeration Type Documentation

◆ _CONNECT_TYPE

Enumerator
NoConnect 
NormalConnect 
ChainConnect 
UnknownConnect 

Definition at line 25 of file ke.h.

26{
enum _CONNECT_TYPE * PCONNECT_TYPE
@ ChainConnect
Definition: ke.h:29
@ NoConnect
Definition: ke.h:27
@ NormalConnect
Definition: ke.h:28
@ UnknownConnect
Definition: ke.h:30
enum _CONNECT_TYPE CONNECT_TYPE

Function Documentation

◆ _IRQL_requires_min_()

Definition at line 121 of file spinlock.c.

127{
128#if defined(CONFIG_SMP) || DBG
129 /* Make sure we are at DPC or above! */
131 {
132 /* We aren't -- bugcheck */
133 KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
134 (ULONG_PTR)LockHandle->Lock,
136 0,
137 0);
138 }
139#endif
140
141 /* Do the inlined function */
142 KxReleaseSpinLock(LockHandle->Lock);
143}
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
uint32_t ULONG_PTR
Definition: typedefs.h:65
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:717

◆ DbgBreakPointNoBugCheck()

VOID NTAPI DbgBreakPointNoBugCheck ( VOID  )

◆ Ke386SetIOPL()

VOID NTAPI Ke386SetIOPL ( VOID  )

Definition at line 581 of file v86vdm.c.

582{
583
585 PKPROCESS Process = Thread->ApcState.Process;
586 PKTRAP_FRAME TrapFrame;
588
589 /* IOPL was enabled for this process/thread */
590 Process->Iopl = TRUE;
591 Thread->Iopl = TRUE;
592
593 /* Get the trap frame on exit */
594 TrapFrame = KeGetTrapFrame(Thread);
595
596 /* Convert to a context */
597 Context.ContextFlags = CONTEXT_CONTROL;
598 KeTrapFrameToContext(TrapFrame, NULL, &Context);
599
600 /* Set the IOPL flag */
601 Context.EFlags |= EFLAGS_IOPL;
602
603 /* Convert back to a trap frame */
605}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
#define KeGetCurrentThread
Definition: hal.h:55
#define UserMode
Definition: asm.h:35
#define EFLAGS_IOPL
Definition: ketypes.h:189
#define CONTEXT_CONTROL
Definition: nt_native.h:1369
#define KeGetTrapFrame(Thread)
Definition: ke.h:208
VOID NTAPI KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame, IN OUT PCONTEXT Context)
Definition: context.c:169
VOID NTAPI KeContextToTrapFrame(PCONTEXT Context, PKEXCEPTION_FRAME ExeptionFrame, PKTRAP_FRAME TrapFrame, ULONG ContextFlags, KPROCESSOR_MODE PreviousMode)

Referenced by NtSetInformationProcess().

◆ KeAlertResumeThread()

ULONG NTAPI KeAlertResumeThread ( IN PKTHREAD  Thread)

Definition at line 124 of file thrdobj.c.

125{
126 ULONG PreviousCount;
127 KLOCK_QUEUE_HANDLE ApcLock;
130
131 /* Lock the Dispatcher Database and the APC Queue */
134
135 /* Return if Thread is already alerted. */
136 if (!Thread->Alerted[KernelMode])
137 {
138 /* If it's Blocked, unblock if it we should */
139 if ((Thread->State == Waiting) && (Thread->Alertable))
140 {
141 /* Abort the wait */
143 }
144 else
145 {
146 /* If not, simply Alert it */
147 Thread->Alerted[KernelMode] = TRUE;
148 }
149 }
150
151 /* Save the old Suspend Count */
152 PreviousCount = Thread->SuspendCount;
153
154 /* If the thread is suspended, decrease one of the suspend counts */
155 if (PreviousCount)
156 {
157 /* Decrease count. If we are now zero, unwait it completely */
158 Thread->SuspendCount--;
159 if (!(Thread->SuspendCount) && !(Thread->FreezeCount))
160 {
161 /* Signal and satisfy */
162 Thread->SuspendSemaphore.Header.SignalState++;
163 KiWaitTest(&Thread->SuspendSemaphore.Header, IO_NO_INCREMENT);
164 }
165 }
166
167 /* Release Locks and return the Old State */
170 KiExitDispatcher(ApcLock.OldIrql);
171 return PreviousCount;
172}
FORCEINLINE VOID KiAcquireApcLockRaiseToSynch(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:607
FORCEINLINE VOID KiReleaseDispatcherLockFromSynchLevel(VOID)
Definition: ke_x.h:174
FORCEINLINE VOID KiAcquireDispatcherLockAtSynchLevel(VOID)
Definition: ke_x.h:165
FORCEINLINE VOID KiReleaseApcLockFromSynchLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
#define KernelMode
Definition: asm.h:34
@ Waiting
Definition: ketypes.h:393
#define THREAD_ALERT_INCREMENT
Definition: ketypes.h:126
#define ASSERT_THREAD(object)
Definition: ketypes.h:2076
VOID FASTCALL KiUnwaitThread(IN PKTHREAD Thread, IN LONG_PTR WaitStatus, IN KPRIORITY Increment)
Definition: wait.c:89
VOID FASTCALL KiWaitTest(PVOID Object, KPRIORITY Increment)
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
#define STATUS_ALERTED
Definition: ntstatus.h:80
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
uint32_t ULONG
Definition: typedefs.h:59
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by NtAlertResumeThread().

◆ KeAlertThread()

BOOLEAN NTAPI KeAlertThread ( IN PKTHREAD  Thread,
IN KPROCESSOR_MODE  AlertMode 
)

Definition at line 176 of file thrdobj.c.

178{
180 KLOCK_QUEUE_HANDLE ApcLock;
183
184 /* Lock the Dispatcher Database and the APC Queue */
187
188 /* Save the Previous State */
189 PreviousState = Thread->Alerted[AlertMode];
190
191 /* Check if it's already alerted */
192 if (!PreviousState)
193 {
194 /* Check if the thread is alertable, and blocked in the given mode */
195 if ((Thread->State == Waiting) &&
196 (Thread->Alertable) &&
197 (AlertMode <= Thread->WaitMode))
198 {
199 /* Abort the wait to alert the thread */
201 }
202 else
203 {
204 /* Otherwise, merely set the alerted state */
205 Thread->Alerted[AlertMode] = TRUE;
206 }
207 }
208
209 /* Release the Dispatcher Lock */
212 KiExitDispatcher(ApcLock.OldIrql);
213
214 /* Return the old state */
215 return PreviousState;
216}
unsigned char BOOLEAN
_In_ WDF_POWER_DEVICE_STATE PreviousState
Definition: wdfdevice.h:829

Referenced by NtAlertThread().

◆ KeBalanceSetManager()

VOID NTAPI KeBalanceSetManager ( IN PVOID  Context)

Definition at line 137 of file balmgr.c.

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 */
166 WaitObjects,
167 WaitAny,
168 Executive,
170 FALSE,
171 NULL,
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}
ULONG KiReadyScanLast
Definition: balmgr.c:18
VOID NTAPI KiScanReadyQueues(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: balmgr.c:24
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define FALSE
Definition: types.h:117
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
_Must_inspect_result_ _In_ WAIT_TYPE _In_opt_ PLARGE_INTEGER _In_opt_ PKWAIT_BLOCK WaitBlockArray
Definition: fsrtlfuncs.h:1153
Status
Definition: gdiplustypes.h:25
#define LOW_REALTIME_PRIORITY
@ WaitAny
@ SynchronizationTimer
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
#define STATUS_WAIT_0
Definition: ntstatus.h:237
#define STATUS_WAIT_1
Definition: ntstatus.h:71
Definition: ketypes.h:699
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1319
BOOLEAN NTAPI KeSetTimerEx(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN LONG Period, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:294
VOID NTAPI KeInitializeTimerEx(OUT PKTIMER Timer, IN TIMER_TYPE Type)
Definition: timerobj.c:244
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
@ Executive
Definition: ketypes.h:415

Referenced by MmInitBsmThread().

◆ KeBoostPriorityThread()

VOID NTAPI KeBoostPriorityThread ( IN PKTHREAD  Thread,
IN KPRIORITY  Increment 
)

Definition at line 220 of file thrdobj.c.

222{
226
227 /* Lock the Dispatcher Database */
229
230 /* Only threads in the dynamic range get boosts */
231 if (Thread->Priority < LOW_REALTIME_PRIORITY)
232 {
233 /* Lock the thread */
235
236 /* Check again, and make sure there's not already a boost */
237 if ((Thread->Priority < LOW_REALTIME_PRIORITY) &&
238 !(Thread->PriorityDecrement))
239 {
240 /* Compute the new priority and see if it's higher */
241 Priority = Thread->BasePriority + Increment;
242 if (Priority > Thread->Priority)
243 {
245 {
247 }
248
249 /* Reset the quantum */
250 Thread->Quantum = Thread->QuantumReset;
251
252 /* Set the new Priority */
254 }
255 }
256
257 /* Release thread lock */
259 }
260
261 /* Release the dispatcher lokc */
263}
LONG KPRIORITY
Definition: compat.h:803
UCHAR KIRQL
Definition: env_spec_w32.h:591
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:46
FORCEINLINE VOID KiReleaseDispatcherLock(IN KIRQL OldIrql)
Definition: ke_x.h:157
FORCEINLINE VOID KiAcquireThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:240
FORCEINLINE VOID KiReleaseThreadLock(IN PKTHREAD Thread)
Definition: ke_x.h:250
FORCEINLINE KIRQL KiAcquireDispatcherLock(VOID)
Definition: ke_x.h:149
VOID FASTCALL KiSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdschd.c:511
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:655
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by NtSetInformationProcess().

◆ KeBugCheckUnicodeToAnsi()

PCHAR NTAPI KeBugCheckUnicodeToAnsi ( IN PUNICODE_STRING  Unicode,
OUT PCHAR  Ansi,
IN ULONG  Length 
)

Definition at line 518 of file bug.c.

521{
522 PCHAR p;
523 PWCHAR pw;
524 ULONG i;
525
526 /* Set length and normalize it */
527 i = Unicode->Length / sizeof(WCHAR);
528 i = min(i, Length - 1);
529
530 /* Set source and destination, and copy */
531 pw = Unicode->Buffer;
532 p = Ansi;
533 while (i--) *p++ = (CHAR)*pw++;
534
535 /* Null terminate and return */
536 *p = ANSI_NULL;
537 return Ansi;
538}
#define CHAR(Char)
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define min(a, b)
Definition: monoChain.cc:55
#define ANSI_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
uint16_t * PWCHAR
Definition: typedefs.h:56
char * PCHAR
Definition: typedefs.h:51
__wchar_t WCHAR
Definition: xmlstorage.h:180

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

◆ KeBugCheckWithTf()

DECLSPEC_NORETURN VOID NTAPI KeBugCheckWithTf ( ULONG  BugCheckCode,
ULONG_PTR  BugCheckParameter1,
ULONG_PTR  BugCheckParameter2,
ULONG_PTR  BugCheckParameter3,
ULONG_PTR  BugCheckParameter4,
PKTRAP_FRAME  Tf 
)

◆ KeContextToTrapFrame()

VOID NTAPI KeContextToTrapFrame ( PCONTEXT  Context,
PKEXCEPTION_FRAME  ExeptionFrame,
PKTRAP_FRAME  TrapFrame,
ULONG  ContextFlags,
KPROCESSOR_MODE  PreviousMode 
)

◆ KeDisableThreadApcQueueing()

BOOLEAN NTAPI KeDisableThreadApcQueueing ( IN PKTHREAD  Thread)

◆ KeDumpStackFrames()

VOID NTAPI KeDumpStackFrames ( PULONG  Frame)

◆ KeFindNextRightSetAffinity()

UCHAR NTAPI KeFindNextRightSetAffinity ( IN UCHAR  Number,
IN KAFFINITY  Set 
)

Definition at line 22 of file thrdobj.c.

24{
25 KAFFINITY Bit;
27 ASSERT(Set != 0);
28
29 /* Calculate the mask */
30 Bit = (AFFINITY_MASK(Number) - 1) & Set;
31
32 /* If it's 0, use the one we got */
33 if (!Bit) Bit = Set;
34
35 /* Now find the right set and return it */
37 return (UCHAR)Result;
38}
ULONG_PTR KAFFINITY
Definition: compat.h:85
#define ASSERT(a)
Definition: mode.c:44
FORCEINLINE KAFFINITY AFFINITY_MASK(ULONG Index)
Definition: kefuncs.h:39
FORCEINLINE BOOLEAN BitScanReverseAffinity(PULONG Index, KAFFINITY Mask)
Definition: kefuncs.h:54
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:207
static BOOL Set
Definition: pageheap.c:10
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by KeInitializeProcess(), and KeStartThread().

◆ KeFlushCurrentTb()

VOID NTAPI KeFlushCurrentTb ( VOID  )

Definition at line 526 of file cpu.c.

527{
528 /* Flush the TLB by resetting CR3 */
530}
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1818
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1794

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

◆ KeFlushQueueApc()

PLIST_ENTRY NTAPI KeFlushQueueApc ( IN PKTHREAD  Thread,
IN KPROCESSOR_MODE  PreviousMode 
)

Definition at line 793 of file apc.c.

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 */
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 */
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 */
857FlushDone:
858 KiReleaseApcLock(&ApcLock);
859
860 /* Return the first entry */
861 return FirstEntry;
862}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
FORCEINLINE VOID KiReleaseApcLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:635
Definition: ketypes.h:547
BOOLEAN Inserted
Definition: ketypes.h:567
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103

Referenced by PspExitThread().

◆ KeForceResumeThread()

ULONG NTAPI KeForceResumeThread ( IN PKTHREAD  Thread)

Definition at line 267 of file thrdobj.c.

268{
269 KLOCK_QUEUE_HANDLE ApcLock;
270 ULONG PreviousCount;
273
274 /* Lock the APC Queue */
276
277 /* Save the old Suspend Count */
278 PreviousCount = Thread->SuspendCount + Thread->FreezeCount;
279
280 /* If the thread is suspended, wake it up!!! */
281 if (PreviousCount)
282 {
283 /* Unwait it completely */
284 Thread->SuspendCount = 0;
285 Thread->FreezeCount = 0;
286
287 /* Lock the dispatcher */
289
290 /* Signal and satisfy */
291 Thread->SuspendSemaphore.Header.SignalState++;
292 KiWaitTest(&Thread->SuspendSemaphore.Header, IO_NO_INCREMENT);
293
294 /* Release the dispatcher */
296 }
297
298 /* Release Lock and return the Old State */
300 KiExitDispatcher(ApcLock.OldIrql);
301 return PreviousCount;
302}

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

◆ KeFreezeAllThreads()

VOID NTAPI KeFreezeAllThreads ( VOID  )

Definition at line 306 of file thrdobj.c.

307{
309 PKTHREAD Current, CurrentThread = KeGetCurrentThread();
310 PKPROCESS Process = CurrentThread->ApcState.Process;
311 PLIST_ENTRY ListHead, NextEntry;
312 LONG OldCount;
314
315 /* Lock the process */
317
318 /* If someone is already trying to free us, try again */
319 while (CurrentThread->FreezeCount)
320 {
321 /* Release and re-acquire the process lock so the APC will go through */
324 }
325
326 /* Enter a critical region */
328
329 /* Loop the Process's Threads */
330 ListHead = &Process->ThreadListHead;
331 NextEntry = ListHead->Flink;
332 do
333 {
334 /* Get the current thread */
335 Current = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
336
337 /* Lock it */
338 KiAcquireApcLockAtSynchLevel(Current, &ApcLock);
339
340 /* Make sure it's not ours, and check if APCs are enabled */
341 if ((Current != CurrentThread) && (Current->ApcQueueable))
342 {
343 /* Sanity check */
344 OldCount = Current->SuspendCount;
345 ASSERT(OldCount != MAXIMUM_SUSPEND_COUNT);
346
347 /* Increase the freeze count */
348 Current->FreezeCount++;
349
350 /* Make sure it wasn't already suspended */
351 if (!(OldCount) && !(Current->SuspendCount))
352 {
353 /* Did we already insert it? */
354 if (!Current->SuspendApc.Inserted)
355 {
356 /* Insert the APC */
357 Current->SuspendApc.Inserted = TRUE;
358 KiInsertQueueApc(&Current->SuspendApc, IO_NO_INCREMENT);
359 }
360 else
361 {
362 /* Lock the dispatcher */
364
365 /* Unsignal the semaphore, the APC was already inserted */
366 Current->SuspendSemaphore.Header.SignalState--;
367
368 /* Release the dispatcher */
370 }
371 }
372 }
373
374 /* Release the APC lock */
376
377 /* Move to the next thread */
378 NextEntry = NextEntry->Flink;
379 } while (NextEntry != ListHead);
380
381 /* Release the process lock and exit the dispatcher */
384}
FORCEINLINE VOID KiReleaseProcessLockFromSynchLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:668
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
FORCEINLINE VOID KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:660
FORCEINLINE VOID KiAcquireApcLockAtSynchLevel(IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:616
FORCEINLINE VOID KiAcquireProcessLockRaiseToSynch(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:651
VOID FASTCALL KiInsertQueueApc(IN PKAPC Apc, IN KPRIORITY PriorityBoost)
Definition: apc.c:85
long LONG
Definition: pedump.c:60
ULONG FreezeCount
Definition: ketypes.h:1737
DISPATCHER_HEADER Header
Definition: ketypes.h:1661
CHAR SuspendCount
Definition: ketypes.h:1965
KAPC_STATE ApcState
Definition: ketypes.h:1778
ULONG ApcQueueable
Definition: ketypes.h:1711
#define MAXIMUM_SUSPEND_COUNT
Definition: winbase.h:405

Referenced by DbgkpSuspendProcess().

◆ KeFreezeExecution()

BOOLEAN NTAPI KeFreezeExecution ( IN PKTRAP_FRAME  TrapFrame,
IN PKEXCEPTION_FRAME  ExceptionFrame 
)

Definition at line 26 of file freeze.c.

28{
31
32#ifndef CONFIG_SMP
33 UNREFERENCED_PARAMETER(TrapFrame);
34 UNREFERENCED_PARAMETER(ExceptionFrame);
35#endif
36
37 /* Disable interrupts, get previous state and set the freeze flag */
39 KiFreezeFlag = 4;
40
41#ifndef CONFIG_SMP
42 /* Raise IRQL if we have to */
46#else
47 /* Raise IRQL to HIGH_LEVEL */
49#endif
50
51#ifdef CONFIG_SMP
52 // TODO: Add SMP support.
53#endif
54
55 /* Save the old IRQL to be restored on unfreeze */
57
58 /* Return whether interrupts were enabled */
59 return Enable;
60}
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment KeRaiseIrqlToDpcLevel
Definition: CrNtStubs.h:68
ULONG KiFreezeFlag
Definition: freeze.c:20
KIRQL KiOldIrql
Definition: freeze.c:19
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
FORCEINLINE BOOLEAN KeDisableInterrupts(VOID)
Definition: ke.h:239

Referenced by KdEnterDebugger().

◆ KeInitExceptions()

VOID NTAPI KeInitExceptions ( VOID  )

Definition at line 59 of file except.c.

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}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
__INTRIN_INLINE void __lidt(void *Source)
Definition: intrin_x86.h:2018
unsigned __int64 ULONG64
Definition: imports.h:198
#define KGDT64_R0_CODE
Definition: ketypes.h:133
#define KeGetPcr()
Definition: ketypes.h:81
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
KIDT_INIT KiInterruptInitTable[]
Definition: except.c:20
KIDTENTRY64 KiIdt[256]
Definition: except.c:50
KI_INTERRUPT_DISPATCH_ENTRY KiUnexpectedRange[256]
KDESCRIPTOR KiIdtDescriptor
Definition: except.c:51
USHORT Limit
Definition: ketypes.h:555
UCHAR Dpl
Definition: ke.h:96
UCHAR IstIndex
Definition: ke.h:97
ULONG OffsetHigh
Definition: ketypes.h:544
USHORT Reserved0
Definition: ketypes.h:539
USHORT IstIndex
Definition: ketypes.h:538
USHORT OffsetMiddle
Definition: ketypes.h:543
USHORT OffsetLow
Definition: ketypes.h:536
ULONG Reserved1
Definition: ketypes.h:545
USHORT Dpl
Definition: ketypes.h:541
USHORT Present
Definition: ketypes.h:542
USHORT Selector
Definition: ketypes.h:537
USHORT Type
Definition: ketypes.h:540
_In_ PKSERVICE_ROUTINE ServiceRoutine
Definition: iofuncs.h:800

Referenced by KiSystemStartup().

◆ KeInitializeEventPair()

VOID NTAPI KeInitializeEventPair ( PKEVENT_PAIR  EventPair)

Referenced by NtCreateEventPair().

◆ KeInitializeGate()

◆ KeInitializeProcess()

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

◆ KeInitializeProfile()

VOID NTAPI KeInitializeProfile ( struct _KPROFILE Profile,
struct _KPROCESS Process,
PVOID  ImageBase,
SIZE_T  ImageSize,
ULONG  BucketSize,
KPROFILE_SOURCE  ProfileSource,
KAFFINITY  Affinity 
)

Referenced by NtStartProfile().

◆ KeInitializeThread()

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 891 of file thrdobj.c.

899{
900 /* Initialize and start the thread on success */
902 KernelStack,
903 SystemRoutine,
905 StartContext,
906 Context,
907 Teb,
908 Process)))
909 {
910 /* Start it */
912 }
913}
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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:756
VOID NTAPI KeStartThread(IN OUT PKTHREAD Thread)
Definition: thrdobj.c:489
_In_ ULONG _In_opt_ POBJECT_ATTRIBUTES _In_opt_ HANDLE _Out_opt_ PCLIENT_ID _In_ PKSTART_ROUTINE StartRoutine
Definition: psfuncs.h:91

Referenced by KiInitializeHandBuiltThread(), and KiInitializeKernel().

◆ KeInitInterrupts()

VOID NTAPI KeInitInterrupts ( VOID  )

◆ KeInitSystem()

BOOLEAN NTAPI KeInitSystem ( VOID  )

Definition at line 296 of file krnlinit.c.

297{
298 /* Check if Threaded DPCs are enabled */
300 {
301 /* FIXME: TODO */
302 DPRINT1("Threaded DPCs not yet supported\n");
303 }
304
305 /* Initialize non-portable parts of the kernel */
307 return TRUE;
308}
BOOLEAN KeThreadDpcEnable
Definition: dpc.c:23
VOID NTAPI KiInitMachineDependent(VOID)
Definition: kiinit.c:48

Referenced by Phase1InitializationDiscard().

◆ KeInitThread()

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 756 of file thrdobj.c.

764{
765 BOOLEAN AllocatedStack = FALSE;
766 ULONG i;
767 PKWAIT_BLOCK TimerWaitBlock;
770
771 /* Initialize the Dispatcher Header */
772 Thread->Header.Type = ThreadObject;
773 Thread->Header.ThreadControlFlags = 0;
774 Thread->Header.DebugActive = FALSE;
775 Thread->Header.SignalState = 0;
776 InitializeListHead(&(Thread->Header.WaitListHead));
777
778 /* Initialize the Mutant List */
779 InitializeListHead(&Thread->MutantListHead);
780
781 /* Initialize the wait blocks */
782 for (i = 0; i< (THREAD_WAIT_OBJECTS + 1); i++)
783 {
784 /* Put our pointer */
785 Thread->WaitBlock[i].Thread = Thread;
786 }
787
788 /* Set swap settings */
789 Thread->EnableStackSwap = TRUE;
790 Thread->IdealProcessor = 1;
791 Thread->SwapBusy = FALSE;
792 Thread->KernelStackResident = TRUE;
793 Thread->AdjustReason = AdjustNone;
794
795 /* Initialize the lock */
797
798 /* Setup the Service Descriptor Table for Native Calls */
799 Thread->ServiceTable = KeServiceDescriptorTable;
800
801 /* Setup APC Fields */
802 InitializeListHead(&Thread->ApcState.ApcListHead[KernelMode]);
803 InitializeListHead(&Thread->ApcState.ApcListHead[UserMode]);
804 Thread->ApcState.Process = Process;
805 Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->ApcState;
806 Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->SavedApcState;
807 Thread->ApcStateIndex = OriginalApcEnvironment;
808 Thread->ApcQueueable = TRUE;
809 KeInitializeSpinLock(&Thread->ApcQueueLock);
810
811 /* Initialize the Suspend APC */
812 KeInitializeApc(&Thread->SuspendApc,
813 Thread,
819 NULL);
820
821 /* Initialize the Suspend Semaphore */
822 KeInitializeSemaphore(&Thread->SuspendSemaphore, 0, 2);
823
824 /* Setup the timer */
825 Timer = &Thread->Timer;
827 TimerWaitBlock = &Thread->WaitBlock[TIMER_WAIT_BLOCK];
828 TimerWaitBlock->Object = Timer;
829 TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
830 TimerWaitBlock->WaitType = WaitAny;
831 TimerWaitBlock->NextWaitBlock = NULL;
832
833 /* Link the two wait lists together */
834 TimerWaitBlock->WaitListEntry.Flink = &Timer->Header.WaitListHead;
835 TimerWaitBlock->WaitListEntry.Blink = &Timer->Header.WaitListHead;
836
837 /* Set the TEB and process */
838 Thread->Teb = Teb;
839 Thread->Process = Process;
840
841 /* Check if we have a kernel stack */
842 if (!KernelStack)
843 {
844 /* We don't, allocate one */
845 KernelStack = MmCreateKernelStack(FALSE, 0);
846 if (!KernelStack) return STATUS_INSUFFICIENT_RESOURCES;
847
848 /* Remember for later */
849 AllocatedStack = TRUE;
850 }
851
852 /* Set the Thread Stacks */
853 Thread->InitialStack = KernelStack;
854 Thread->StackBase = KernelStack;
855 Thread->StackLimit = (ULONG_PTR)KernelStack - KERNEL_STACK_SIZE;
856 Thread->KernelStackResident = TRUE;
857
858 /* Enter SEH to avoid crashes due to user mode */
861 {
862 /* Initialize the Thread Context */
864 SystemRoutine,
866 StartContext,
867 Context);
868 }
870 {
871 /* Set failure status */
873
874 /* Check if a stack was allocated */
875 if (AllocatedStack)
876 {
877 /* Delete the stack */
879 Thread->InitialStack = NULL;
880 }
881 }
882 _SEH2_END;
883
884 /* Set the Thread to initialized */
885 Thread->State = Initialized;
886 return Status;
887}
#define ULONG_PTR
Definition: config.h:101
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
@ ThreadObject
Definition: ketypes.h:412
@ Initialized
Definition: ketypes.h:388
@ AttachedApcEnvironment
Definition: ketypes.h:768
@ OriginalApcEnvironment
Definition: ketypes.h:767
@ AdjustNone
Definition: ketypes.h:439
VOID NTAPI KiInitializeContextThread(PKTHREAD Thread, PKSYSTEM_ROUTINE SystemRoutine, PKSTART_ROUTINE StartRoutine, PVOID StartContext, PCONTEXT Context)
#define TIMER_WAIT_BLOCK
Definition: ke.h:164
VOID NTAPI MmDeleteKernelStack(PVOID Stack, BOOLEAN GuiStack)
PVOID NTAPI MmCreateKernelStack(BOOLEAN GuiStack, UCHAR Node)
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_TIMEOUT
Definition: ntstatus.h:81
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]
Definition: procobj.c:23
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define KERNEL_STACK_SIZE
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
#define STATUS_SUCCESS
Definition: shellext.h:65
EX_PUSH_LOCK ThreadLock
Definition: pstypes.h:1160
PVOID Object
Definition: ketypes.h:468
LIST_ENTRY WaitListEntry
Definition: ketypes.h:456
UCHAR WaitType
Definition: ketypes.h:458
USHORT WaitKey
Definition: ketypes.h:460
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
VOID NTAPI KiSuspendNop(IN PKAPC Apc, IN PKNORMAL_ROUTINE *NormalRoutine, IN PVOID *NormalContext, IN PVOID *SystemArgument1, IN PVOID *SystemArgument2)
Definition: thrdobj.c:571
VOID NTAPI KiSuspendRundown(IN PKAPC Apc)
Definition: thrdobj.c:563
VOID NTAPI KiSuspendThread(IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: thrdobj.c:587
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define THREAD_WAIT_OBJECTS
Definition: ketypes.h:492

Referenced by KeInitializeThread(), and PspCreateThread().

◆ KeInvalidAccessAllowed()

BOOLEAN FASTCALL KeInvalidAccessAllowed ( IN PVOID TrapInformation  OPTIONAL)

Definition at line 756 of file exp.c.

757{
758 ULONG Eip;
759 PKTRAP_FRAME TrapFrame = TrapInformation;
761
762 /* Don't do anything if we didn't get a trap frame */
763 if (!TrapInformation) return FALSE;
764
765 /* Check where we came from */
766 switch (TrapFrame->SegCs)
767 {
768 /* Kernel mode */
769 case KGDT_R0_CODE:
770
771 /* Allow S-LIST Routine to fail */
773 break;
774
775 /* User code */
776 case KGDT_R3_CODE | RPL_MASK:
777
778 /* Allow S-LIST Routine to fail */
779 //Eip = (ULONG)KeUserPopEntrySListFault;
780 Eip = 0;
781 break;
782
783 default:
784
785 /* Anything else gets a bugcheck */
786 Eip = 0;
787 }
788
789 /* Return TRUE if we want to keep the system up */
790 return (TrapFrame->Eip == Eip) ? TRUE : FALSE;
791}
#define RPL_MASK
Definition: ketypes.h:130
#define KGDT_R3_CODE
Definition: ketypes.h:125
#define KGDT_R0_CODE
Definition: ketypes.h:123
VOID NTAPI ExpInterlockedPopEntrySListFault(VOID)
ULONG Eip
Definition: ketypes.h:321
USHORT SegCs
Definition: ketypes.h:450
#define NTAPI
Definition: typedefs.h:36

◆ KeInvalidateAllCaches()

BOOLEAN NTAPI KeInvalidateAllCaches ( VOID  )

Definition at line 663 of file cpu.c.

664{
665 /* Invalidate all caches */
666 __wbinvd();
667 return TRUE;
668}
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759

Referenced by MiMapLockedPagesInUserSpace(), and MmMapIoSpace().

◆ KeQueryBasePriorityThread()

LONG NTAPI KeQueryBasePriorityThread ( IN PKTHREAD  Thread)

Definition at line 52 of file thrdobj.c.

53{
54 LONG BaseIncrement;
59
60 /* Raise IRQL to synch level */
62
63 /* Lock the thread */
65
66 /* Get the Process */
67 Process = Thread->ApcStatePointer[0]->Process;
68
69 /* Calculate the base increment */
70 BaseIncrement = Thread->BasePriority - Process->BasePriority;
71
72 /* If saturation occured, return the saturation increment instead */
73 if (Thread->Saturation) BaseIncrement = (HIGH_PRIORITY + 1) / 2 *
74 Thread->Saturation;
75
76 /* Release thread lock */
78
79 /* Lower IRQl and return Increment */
81 return BaseIncrement;
82}
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
KIRQL NTAPI KeRaiseIrqlToSynchLevel(VOID)
Definition: pic.c:156
#define HIGH_PRIORITY

Referenced by NtQueryInformationThread().

◆ KeQueryIntervalProfile()

ULONG NTAPI KeQueryIntervalProfile ( KPROFILE_SOURCE  ProfileSource)

Referenced by NtQueryIntervalProfile().

◆ KeQueryRuntimeProcess()

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

Definition at line 860 of file procobj.c.

862{
863 ULONG TotalUser, TotalKernel;
864 KLOCK_QUEUE_HANDLE ProcessLock;
865 PLIST_ENTRY NextEntry, ListHead;
867
869
870 /* Initialize user and kernel times */
871 TotalUser = Process->UserTime;
872 TotalKernel = Process->KernelTime;
873
874 /* Lock the process */
876
877 /* Loop all child threads and sum up their times */
878 ListHead = &Process->ThreadListHead;
879 NextEntry = ListHead->Flink;
880 while (ListHead != NextEntry)
881 {
882 /* Get the thread */
883 Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
884
885 /* Sum up times */
886 TotalKernel += Thread->KernelTime;
887 TotalUser += Thread->UserTime;
888
889 /* Go to the next one */
890 NextEntry = NextEntry->Flink;
891 }
892
893 /* Release lock */
894 KiReleaseProcessLock(&ProcessLock);
895
896 /* Return the user time */
897 *UserTime = TotalUser;
898
899 /* Return the kernel time */
900 return TotalKernel;
901}
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2140
_Out_ PULONG UserTime
Definition: kefuncs.h:759

Referenced by NtQueryInformationProcess(), and QSI_DEF().

◆ KeQueryValuesProcess()

VOID NTAPI KeQueryValuesProcess ( IN PKPROCESS  Process,
PPROCESS_VALUES  Values 
)

Definition at line 525 of file procobj.c.

527{
528 PEPROCESS EProcess;
529 PLIST_ENTRY NextEntry;
530 ULONG TotalKernel, TotalUser;
531 KLOCK_QUEUE_HANDLE ProcessLock;
532
535
536 /* Lock the process */
538
539 /* Initialize user and kernel times */
540 TotalKernel = Process->KernelTime;
541 TotalUser = Process->UserTime;
542
543 /* Copy the IO_COUNTERS from the process */
544 EProcess = (PEPROCESS)Process;
551
552 /* Loop all child threads and sum up their times */
553 for (NextEntry = Process->ThreadListHead.Flink;
554 NextEntry != &Process->ThreadListHead;
555 NextEntry = NextEntry->Flink)
556 {
558
559 /* Get the thread */
560 Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
561
562 /* Sum up times */
563 TotalKernel += Thread->KernelTime;
564 TotalUser += Thread->UserTime;
565 }
566
567 /* Release the process lock */
568 KiReleaseProcessLock(&ProcessLock);
569
570 /* Compute total times */
571 Values->TotalKernelTime.QuadPart = TotalKernel * (LONGLONG)KeMaximumIncrement;
572 Values->TotalUserTime.QuadPart = TotalUser * (LONGLONG)KeMaximumIncrement;
573}
struct _EPROCESS * PEPROCESS
Definition: nt_native.h:30
ULONG KeMaximumIncrement
Definition: clock.c:20
LARGE_INTEGER WriteTransferCount
Definition: pstypes.h:1350
LARGE_INTEGER ReadTransferCount
Definition: pstypes.h:1349
LARGE_INTEGER ReadOperationCount
Definition: pstypes.h:1346
LARGE_INTEGER OtherTransferCount
Definition: pstypes.h:1351
LARGE_INTEGER WriteOperationCount
Definition: pstypes.h:1347
LARGE_INTEGER OtherOperationCount
Definition: pstypes.h:1348
ULONGLONG ReadOperationCount
Definition: pstypes.h:83
ULONGLONG WriteTransferCount
Definition: pstypes.h:87
ULONGLONG WriteOperationCount
Definition: pstypes.h:84
ULONGLONG ReadTransferCount
Definition: pstypes.h:86
ULONGLONG OtherOperationCount
Definition: pstypes.h:85
ULONGLONG OtherTransferCount
Definition: pstypes.h:88
LARGE_INTEGER TotalUserTime
Definition: ke.h:47
IO_COUNTERS IoInfo
Definition: ke.h:48
LARGE_INTEGER TotalKernelTime
Definition: ke.h:46
int64_t LONGLONG
Definition: typedefs.h:68
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by NtQueryInformationJobObject(), and NtQueryInformationProcess().

◆ KeReadStateThread()

BOOLEAN NTAPI KeReadStateThread ( IN PKTHREAD  Thread)

Definition at line 42 of file thrdobj.c.

43{
45
46 /* Return signal state */
47 return (BOOLEAN)Thread->Header.SignalState;
48}

Referenced by NtQueryInformationThread(), and PspExitThread().

◆ KeReadyThread()

VOID NTAPI KeReadyThread ( IN PKTHREAD  Thread)

Definition at line 106 of file thrdobj.c.

107{
111
112 /* Lock the Dispatcher Database */
114
115 /* Make the thread ready */
117
118 /* Unlock dispatcher database */
120}
VOID NTAPI KiReadyThread(IN PKTHREAD Thread)
Definition: thrdschd.c:429

Referenced by PspCreateThread().

◆ KeReleaseThread()

NTSTATUS NTAPI KeReleaseThread ( PKTHREAD  Thread)

◆ KeRemoveQueueApc()

BOOLEAN NTAPI KeRemoveQueueApc ( PKAPC  Apc)

◆ KeResumeThread()

ULONG NTAPI KeResumeThread ( IN PKTHREAD  Thread)

Definition at line 388 of file thrdobj.c.

389{
390 KLOCK_QUEUE_HANDLE ApcLock;
391 ULONG PreviousCount;
394
395 /* Lock the APC Queue */
397
398 /* Save the Old Count */
399 PreviousCount = Thread->SuspendCount;
400
401 /* Check if it existed */
402 if (PreviousCount)
403 {
404 /* Decrease the suspend count */
405 Thread->SuspendCount--;
406
407 /* Check if the thrad is still suspended or not */
408 if ((!Thread->SuspendCount) && (!Thread->FreezeCount))
409 {
410 /* Acquire the dispatcher lock */
412
413 /* Signal the Suspend Semaphore */
414 Thread->SuspendSemaphore.Header.SignalState++;
415 KiWaitTest(&Thread->SuspendSemaphore.Header, IO_NO_INCREMENT);
416
417 /* Release the dispatcher lock */
419 }
420 }
421
422 /* Release APC Queue lock and return the Old State */
424 KiExitDispatcher(ApcLock.OldIrql);
425 return PreviousCount;
426}

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

◆ KeRosDumpStackFrames()

VOID NTAPI KeRosDumpStackFrames ( PULONG_PTR  Frame,
ULONG  FrameCount 
)

◆ KeRundownThread()

VOID NTAPI KeRundownThread ( VOID  )

Definition at line 430 of file thrdobj.c.

431{
434 PLIST_ENTRY NextEntry, ListHead;
435 PKMUTANT Mutant;
437
438 /* Optimized path if nothing is on the list at the moment */
439 if (IsListEmpty(&Thread->MutantListHead)) return;
440
441 /* Lock the Dispatcher Database */
443
444 /* Get the List Pointers */
445 ListHead = &Thread->MutantListHead;
446 NextEntry = ListHead->Flink;
447 while (NextEntry != ListHead)
448 {
449 /* Get the Mutant */
450 Mutant = CONTAINING_RECORD(NextEntry, KMUTANT, MutantListEntry);
451 ASSERT_MUTANT(Mutant);
452
453 /* Make sure it's not terminating with APCs off */
454 if (Mutant->ApcDisable)
455 {
456 /* Bugcheck the system */
457 KeBugCheckEx(THREAD_TERMINATE_HELD_MUTEX,
459 (ULONG_PTR)Mutant,
460 0,
461 0);
462 }
463
464 /* Now we can remove it */
466
467 /* Unconditionally abandon it */
468 Mutant->Header.SignalState = 1;
469 Mutant->Abandoned = TRUE;
470 Mutant->OwnerThread = NULL;
471
472 /* Check if the Wait List isn't empty */
473 if (!IsListEmpty(&Mutant->Header.WaitListHead))
474 {
475 /* Wake the Mutant */
477 }
478
479 /* Move on */
480 NextEntry = Thread->MutantListHead.Flink;
481 }
482
483 /* Release the Lock */
485}
#define MUTANT_INCREMENT
Definition: extypes.h:84
LIST_ENTRY WaitListHead
Definition: ketypes.h:808
DISPATCHER_HEADER Header
Definition: ketypes.h:841
LIST_ENTRY MutantListEntry
Definition: ketypes.h:842
BOOLEAN Abandoned
Definition: ketypes.h:844
struct _KTHREAD *RESTRICTED_POINTER OwnerThread
Definition: ketypes.h:843
UCHAR ApcDisable
Definition: ketypes.h:845
#define ASSERT_MUTANT(Object)

Referenced by PspExitThread().

◆ KeSetAffinityProcess()

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

Definition at line 265 of file procobj.c.

267{
268
269 KLOCK_QUEUE_HANDLE ProcessLock;
270 PLIST_ENTRY NextEntry, ListHead;
271 KAFFINITY OldAffinity;
276
277 /* Lock the process */
279
280 /* Acquire the dispatcher lock */
282
283 /* Capture old affinity and update it */
284 OldAffinity = Process->Affinity;
285 Process->Affinity = Affinity;
286
287 /* Loop all child threads */
288 ListHead = &Process->ThreadListHead;
289 NextEntry = ListHead->Flink;
290 while (ListHead != NextEntry)
291 {
292 /* Get the thread */
293 Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
294
295 /* Set affinity on it */
297 NextEntry = NextEntry->Flink;
298 }
299
300 /* Release Dispatcher Database */
302
303 /* Release the process lock */
305 KiExitDispatcher(ProcessLock.OldIrql);
306
307 /* Return previous affinity */
308 return OldAffinity;
309}
KAFFINITY KeActiveProcessors
Definition: krnlinit.c:23
KAFFINITY FASTCALL KiSetAffinityThread(IN PKTHREAD Thread, IN KAFFINITY Affinity)
Definition: thrdschd.c:685
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:174

Referenced by NtSetInformationProcess().

◆ KeSetAutoAlignmentProcess()

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

Definition at line 313 of file procobj.c.

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

Referenced by NtSetInformationProcess().

◆ KeSetDisableBoostProcess()

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

Definition at line 331 of file procobj.c.

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

Referenced by NtSetInformationProcess().

◆ KeSetDisableBoostThread()

BOOLEAN NTAPI KeSetDisableBoostThread ( IN OUT PKTHREAD  Thread,
IN BOOLEAN  Disable 
)

Definition at line 86 of file thrdobj.c.

88{
90
91 /* Check if we're enabling or disabling */
92 if (Disable)
93 {
94 /* Set the bit */
95 return InterlockedBitTestAndSet(&Thread->ThreadFlags, 1);
96 }
97 else
98 {
99 /* Remove the bit */
100 return InterlockedBitTestAndReset(&Thread->ThreadFlags, 1);
101 }
102}

Referenced by NtSetInformationProcess(), and NtSetInformationThread().

◆ KeSetIntervalProfile()

VOID NTAPI KeSetIntervalProfile ( ULONG  Interval,
KPROFILE_SOURCE  ProfileSource 
)

Referenced by NtSetIntervalProfile().

◆ KeSetPriorityAndQuantumProcess()

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

Definition at line 349 of file procobj.c.

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

Referenced by NtSetInformationProcess(), and PsSetProcessPriorityByClass().

◆ KeSetProcess()

ULONG NTAPI KeSetProcess ( struct _KPROCESS Process,
KPRIORITY  Increment,
BOOLEAN  InWait 
)

Referenced by PspExitThread().

◆ KeSetQuantumProcess()

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

Definition at line 229 of file procobj.c.

231{
232 KLOCK_QUEUE_HANDLE ProcessLock;
233 PLIST_ENTRY NextEntry, ListHead;
237
238 /* Lock the process */
240
241 /* Set new quantum */
242 Process->QuantumReset = Quantum;
243
244 /* Loop all child threads */
245 ListHead = &Process->ThreadListHead;
246 NextEntry = ListHead->Flink;
247 while (ListHead != NextEntry)
248 {
249 /* Get the thread */
250 Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
251
252 /* Set quantum */
253 Thread->QuantumReset = Quantum;
254
255 /* Go to the next one */
256 NextEntry = NextEntry->Flink;
257 }
258
259 /* Release lock */
260 KiReleaseProcessLock(&ProcessLock);
261}

Referenced by PsChangeQuantumTable().

◆ KeSetSystemTime()

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.

32{
34 KIRQL OldIrql, OldIrql2;
35 LARGE_INTEGER DeltaTime;
36 PLIST_ENTRY ListHead, NextEntry;
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 */
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 */
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 */
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);
117 RemoveEntryList(&Timer->TimerListEntry);
118
119 /* Update the due time and handle */
120 Timer->DueTime.QuadPart -= DeltaTime.QuadPart;
121 Hand = KiComputeTimerTableIndex(Timer->DueTime.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 */
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}
BOOLEAN RtlTimeToTimeFields(IN PLARGE_INTEGER Time, IN PTIME_FIELDS TimeFields)
#define InsertTailList(ListHead, Entry)
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
FORCEINLINE VOID KiRemoveEntryTimer(IN PKTIMER Timer)
Definition: ke_x.h:892
FORCEINLINE VOID KiReleaseTimerLock(IN PKSPIN_LOCK_QUEUE LockQueue)
Definition: ke_x.h:297
FORCEINLINE ULONG KiComputeTimerTableIndex(IN ULONGLONG DueTime)
Definition: ke_x.h:881
FORCEINLINE PKSPIN_LOCK_QUEUE KiAcquireTimerLock(IN ULONG Hand)
Definition: ke_x.h:286
static PTIME_FIELDS TimeFields
Definition: time.c:104
BOOLEAN ExCmosClockIsSane
Definition: init.c:93
KTIMER_TABLE_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE]
Definition: timerobj.c:17
BOOLEAN FASTCALL KiInsertTimerTable(IN PKTIMER Timer, IN ULONG Hand)
Definition: timerobj.c:63
VOID FASTCALL KiTimerListExpire(IN PLIST_ENTRY ExpiredListHead, IN KIRQL OldIrql)
Definition: dpc.c:338
ULONGLONG KeBootTimeBias
Definition: clock.c:18
LARGE_INTEGER KeBootTime
Definition: clock.c:17
BOOLEAN NTAPI HalSetRealTimeClock(IN PTIME_FIELDS Time)
Definition: rtc.c:45
#define SharedUserData
LIST_ENTRY Entry
Definition: ketypes.h:778
VOID NTAPI KeSetSystemAffinityThread(IN KAFFINITY Affinity)
Definition: thrdobj.c:1107
VOID NTAPI KeRevertToUserAffinityThread(VOID)
Definition: thrdobj.c:1021
#define TIMER_TABLE_SIZE
Definition: ketypes.h:848

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

◆ KeSignalGateBoostPriority()

VOID FASTCALL KeSignalGateBoostPriority ( PKGATE  Gate)

◆ KeStartAllProcessors()

VOID NTAPI KeStartAllProcessors ( VOID  )

Definition at line 20 of file mproc.c.

21{
23}
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by Phase1InitializationDiscard().

◆ KeStartProfile()

BOOLEAN NTAPI KeStartProfile ( struct _KPROFILE Profile,
PVOID  Buffer 
)

Referenced by NtStartProfile().

◆ KeStartThread()

VOID NTAPI KeStartThread ( IN OUT PKTHREAD  Thread)

Definition at line 489 of file thrdobj.c.

490{
492#ifdef CONFIG_SMP
493 PKNODE Node;
494 PKPRCB NodePrcb;
496#endif
497 UCHAR IdealProcessor = 0;
498 PKPROCESS Process = Thread->ApcState.Process;
499
500 /* Setup static fields from parent */
501 Thread->DisableBoost = Process->DisableBoost;
502#if defined(_M_IX86)
503 Thread->Iopl = Process->Iopl;
504#endif
505 Thread->Quantum = Process->QuantumReset;
506 Thread->QuantumReset = Process->QuantumReset;
507 Thread->SystemAffinityActive = FALSE;
508
509 /* Lock the process */
511
512 /* Setup volatile data */
513 Thread->Priority = Process->BasePriority;
514 Thread->BasePriority = Process->BasePriority;
515 Thread->Affinity = Process->Affinity;
516 Thread->UserAffinity = Process->Affinity;
517
518#ifdef CONFIG_SMP
519 /* Get the KNODE and its PRCB */
520 Node = KeNodeBlock[Process->IdealNode];
521 NodePrcb = KiProcessorBlock[Process->ThreadSeed];
522
523 /* Calculate affinity mask */
524#ifdef _M_ARM
526 Set = 0;
527#else
528 Set = ~NodePrcb->MultiThreadProcessorSet;
529#endif
530 Mask = Node->ProcessorMask & Process->Affinity;
531 Set &= Mask;
532 if (Set) Mask = Set;
533
534 /* Get the new thread seed */
535 IdealProcessor = KeFindNextRightSetAffinity(Process->ThreadSeed, Mask);
536 Process->ThreadSeed = IdealProcessor;
537
538 /* Sanity check */
539 ASSERT((Thread->UserAffinity & AFFINITY_MASK(IdealProcessor)));
540#endif
541
542 /* Set the Ideal Processor */
543 Thread->IdealProcessor = IdealProcessor;
544 Thread->UserIdealProcessor = IdealProcessor;
545
546 /* Lock the Dispatcher Database */
548
549 /* Insert the thread into the process list */
550 InsertTailList(&Process->ThreadListHead, &Thread->ThreadListEntry);
551
552 /* Increase the stack count */
553 ASSERT(Process->StackCount != MAXULONG_PTR);
554 Process->StackCount++;
555
556 /* Release locks and return */
559}
#define MAXULONG_PTR
Definition: basetsd.h:103
union node Node
Definition: types.h:1255
unsigned int Mask
Definition: fpcontrol.c:82
NTSYSAPI void WINAPI DbgBreakPoint(void)
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
PKNODE KeNodeBlock[1]
Definition: krnlinit.c:39
LIST_ENTRY ThreadListEntry
Definition: pstypes.h:1158
UCHAR NTAPI KeFindNextRightSetAffinity(IN UCHAR Number, IN KAFFINITY Set)
Definition: thrdobj.c:22
Definition: dlist.c:348

Referenced by KeInitializeThread(), and PspCreateThread().

◆ KeStopProfile()

BOOLEAN NTAPI KeStopProfile ( struct _KPROFILE Profile)

Referenced by ExpDeleteProfile(), and NtStopProfile().

◆ KeSuspendThread()

ULONG NTAPI KeSuspendThread ( PKTHREAD  Thread)

Definition at line 601 of file thrdobj.c.

602{
603 KLOCK_QUEUE_HANDLE ApcLock;
604 ULONG PreviousCount;
607
608 /* Lock the APC Queue */
610
611 /* Save the Old Count */
612 PreviousCount = Thread->SuspendCount;
613
614 /* Handle the maximum */
615 if (PreviousCount == MAXIMUM_SUSPEND_COUNT)
616 {
617 /* Raise an exception */
618 KiReleaseApcLock(&ApcLock);
620 }
621
622 /* Should we bother to queue at all? */
623 if (Thread->ApcQueueable)
624 {
625 /* Increment the suspend count */
626 Thread->SuspendCount++;
627
628 /* Check if we should suspend it */
629 if (!(PreviousCount) && !(Thread->FreezeCount))
630 {
631 /* Is the APC already inserted? */
632 if (!Thread->SuspendApc.Inserted)
633 {
634 /* Not inserted, insert it */
635 Thread->SuspendApc.Inserted = TRUE;
637 }
638 else
639 {
640 /* Lock the dispatcher */
642
643 /* Unsignal the semaphore, the APC was already inserted */
644 Thread->SuspendSemaphore.Header.SignalState--;
645
646 /* Release the dispatcher */
648 }
649 }
650 }
651
652 /* Release Lock and return the Old State */
654 KiExitDispatcher(ApcLock.OldIrql);
655 return PreviousCount;
656}
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
#define STATUS_SUSPEND_COUNT_EXCEEDED
Definition: ntstatus.h:310

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

◆ KeSwitchKernelStack()

PVOID NTAPI KeSwitchKernelStack ( IN PVOID  StackBase,
IN PVOID  StackLimit 
)

Referenced by PsConvertToGuiThread().

◆ KeTestAlertThread()

BOOLEAN NTAPI KeTestAlertThread ( IN KPROCESSOR_MODE  AlertMode)

Definition at line 722 of file thrdobj.c.

723{
725 BOOLEAN OldState;
726 KLOCK_QUEUE_HANDLE ApcLock;
729
730 /* Lock the Dispatcher Database and the APC Queue */
732
733 /* Save the old State */
734 OldState = Thread->Alerted[AlertMode];
735
736 /* Check the Thread is alerted */
737 if (OldState)
738 {
739 /* Disable alert for this mode */
740 Thread->Alerted[AlertMode] = FALSE;
741 }
742 else if ((AlertMode != KernelMode) &&
743 (!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode])))
744 {
745 /* If the mode is User and the Queue isn't empty, set Pending */
746 Thread->ApcState.UserApcPending = TRUE;
747 }
748
749 /* Release Locks and return the Old State */
750 KiReleaseApcLock(&ApcLock);
751 return OldState;
752}

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

◆ KeThawAllThreads()

VOID NTAPI KeThawAllThreads ( VOID  )

Definition at line 660 of file thrdobj.c.

661{
663 PKTHREAD Current, CurrentThread = KeGetCurrentThread();
664 PKPROCESS Process = CurrentThread->ApcState.Process;
665 PLIST_ENTRY ListHead, NextEntry;
666 LONG OldCount;
668
669 /* Lock the process */
671
672 /* Loop the Process's Threads */
673 ListHead = &Process->ThreadListHead;
674 NextEntry = ListHead->Flink;
675 do
676 {
677 /* Get the current thread */
678 Current = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
679
680 /* Lock it */
681 KiAcquireApcLockAtSynchLevel(Current, &ApcLock);
682
683 /* Make sure we are frozen */
684 OldCount = Current->FreezeCount;
685 if (OldCount)
686 {
687 /* Decrease the freeze count */
688 Current->FreezeCount--;
689
690 /* Check if both counts are zero now */
691 if (!(Current->SuspendCount) && (!Current->FreezeCount))
692 {
693 /* Lock the dispatcher */
695
696 /* Signal the suspend semaphore and wake it */
697 Current->SuspendSemaphore.Header.SignalState++;
698 KiWaitTest(&Current->SuspendSemaphore, 0);
699
700 /* Unlock the dispatcher */
702 }
703 }
704
705 /* Release the APC lock */
707
708 /* Go to the next one */
709 NextEntry = NextEntry->Flink;
710 } while (NextEntry != ListHead);
711
712 /* Release the process lock and exit the dispatcher */
715
716 /* Leave the critical region */
718}
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119

Referenced by DbgkpResumeProcess().

◆ KeThawExecution()

VOID NTAPI KeThawExecution ( IN BOOLEAN  Enable)

Definition at line 64 of file freeze.c.

65{
66#ifdef CONFIG_SMP
67 // TODO: Add SMP support.
68#endif
69
70 /* Clear the freeze flag */
71 KiFreezeFlag = 0;
72
73 /* Cleanup CPU caches */
75
76 /* Restore the old IRQL */
77#ifndef CONFIG_SMP
79#endif
81
82 /* Re-enable interrupts */
84}
FORCEINLINE VOID KeRestoreInterrupts(BOOLEAN WereEnabled)
Definition: ke.h:254
VOID NTAPI KeFlushCurrentTb(VOID)
Definition: cpu.c:526

Referenced by KdExitDebugger().

◆ KeTrapFrameToContext()

VOID NTAPI KeTrapFrameToContext ( IN PKTRAP_FRAME  TrapFrame,
IN PKEXCEPTION_FRAME  ExceptionFrame,
IN OUT PCONTEXT  Context 
)

Definition at line 169 of file context.c.

172{
173 ULONG ContextFlags;
175
176 /* Do this at APC_LEVEL */
179
180 /* Make sure we have an amd64 context, then remove the flag */
181 ContextFlags = Context->ContextFlags;
182 ASSERT(ContextFlags & CONTEXT_AMD64);
183 ContextFlags &= ~CONTEXT_AMD64;
184
185 /* Handle integer registers */
186 if (ContextFlags & CONTEXT_INTEGER)
187 {
188 Context->Rax = TrapFrame->Rax;
189 Context->Rcx = TrapFrame->Rcx;
190 Context->Rdx = TrapFrame->Rdx;
191 Context->Rbp = TrapFrame->Rbp;
192 Context->R8 = TrapFrame->R8;
193 Context->R9 = TrapFrame->R9;
194 Context->R10 = TrapFrame->R10;
195 Context->R11 = TrapFrame->R11;
196
197 if (ExceptionFrame)
198 {
199 Context->Rbx = ExceptionFrame->Rbx;
200 Context->Rsi = ExceptionFrame->Rsi;
201 Context->Rdi = ExceptionFrame->Rdi;
202 Context->R12 = ExceptionFrame->R12;
203 Context->R13 = ExceptionFrame->R13;
204 Context->R14 = ExceptionFrame->R14;
205 Context->R15 = ExceptionFrame->R15;
206 }
207 }
208
209 /* Handle floating point registers */
210 if (ContextFlags & CONTEXT_FLOATING_POINT)
211 {
212 Context->MxCsr = TrapFrame->MxCsr;
213 Context->Xmm0 = TrapFrame->Xmm0;
214 Context->Xmm1 = TrapFrame->Xmm1;
215 Context->Xmm2 = TrapFrame->Xmm2;
216 Context->Xmm3 = TrapFrame->Xmm3;
217 Context->Xmm4 = TrapFrame->Xmm4;
218 Context->Xmm5 = TrapFrame->Xmm5;
219 if (ExceptionFrame)
220 {
221 Context->Xmm6 = ExceptionFrame->Xmm6;
222 Context->Xmm7 = ExceptionFrame->Xmm7;
223 Context->Xmm8 = ExceptionFrame->Xmm8;
224 Context->Xmm9 = ExceptionFrame->Xmm9;
225 Context->Xmm10 = ExceptionFrame->Xmm10;
226 Context->Xmm11 = ExceptionFrame->Xmm11;
227 Context->Xmm12 = ExceptionFrame->Xmm12;
228 Context->Xmm13 = ExceptionFrame->Xmm13;
229 Context->Xmm14 = ExceptionFrame->Xmm14;
230 Context->Xmm15 = ExceptionFrame->Xmm15;
231 }
232 }
233
234 /* Handle control registers */
235 if (ContextFlags & CONTEXT_CONTROL)
236 {
237 /* Check if this was a Kernel Trap */
238 if ((TrapFrame->SegCs & MODE_MASK) == KernelMode)
239 {
240 /* Set valid selectors */
241 Context->SegCs = KGDT64_R0_CODE;
242 Context->SegSs = KGDT64_R0_DATA;
243 }
244 else
245 {
246 /* Copy selectors */
247 Context->SegCs = TrapFrame->SegCs;
248 Context->SegSs = TrapFrame->SegSs;
249 }
250
251 /* Copy RIP, RSP, EFLAGS */
252 Context->Rip = TrapFrame->Rip;
253 Context->Rsp = TrapFrame->Rsp;
254 Context->EFlags = TrapFrame->EFlags;
255 }
256
257 /* Handle segment selectors */
258 if (ContextFlags & CONTEXT_SEGMENTS)
259 {
260 /* Check if this was a Kernel Trap */
261 if ((TrapFrame->SegCs & MODE_MASK) == KernelMode)
262 {
263 /* Set valid selectors */
268 }
269 else
270 {
271 /* Copy selectors */
272 Context->SegDs = TrapFrame->SegDs;
273 Context->SegEs = TrapFrame->SegEs;
274 Context->SegFs = TrapFrame->SegFs;
275 Context->SegGs = TrapFrame->SegGs;
276 }
277 }
278
279 /* Handle debug registers */
280 if (ContextFlags & CONTEXT_DEBUG_REGISTERS)
281 {
282 /* Copy the debug registers */
283 Context->Dr0 = TrapFrame->Dr0;
284 Context->Dr1 = TrapFrame->Dr1;
285 Context->Dr2 = TrapFrame->Dr2;
286 Context->Dr3 = TrapFrame->Dr3;
287 Context->Dr6 = TrapFrame->Dr6;
288 Context->Dr7 = TrapFrame->Dr7;
289 }
290
291 /* Restore IRQL */
293}
#define MODE_MASK
Definition: orders.h:326
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define KGDT64_R3_DATA
Definition: ketypes.h:136
#define KGDT64_R3_CMTEB
Definition: ketypes.h:139
#define KGDT64_R0_DATA
Definition: ketypes.h:134
#define CONTEXT_DEBUG_REGISTERS
Definition: nt_native.h:1373
#define CONTEXT_INTEGER
Definition: nt_native.h:1370
#define CONTEXT_FLOATING_POINT
Definition: nt_native.h:1372
#define CONTEXT_SEGMENTS
Definition: nt_native.h:1371
#define CONTEXT_AMD64

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

◆ KeUninitThread()

VOID NTAPI KeUninitThread ( IN PKTHREAD  Thread)

Definition at line 917 of file thrdobj.c.

918{
919 /* Delete the stack */
921 Thread->InitialStack = NULL;
922}

Referenced by PspCreateThread().

◆ KeUpdateRunTime()

VOID NTAPI KeUpdateRunTime ( PKTRAP_FRAME  TrapFrame,
KIRQL  Irql 
)

◆ KeV86Exception()

ULONG NTAPI KeV86Exception ( ULONG  ExceptionNr,
PKTRAP_FRAME  Tf,
ULONG  address 
)

◆ KeWaitForGate()

VOID FASTCALL KeWaitForGate ( PKGATE  Gate,
KWAIT_REASON  WaitReason,
KPROCESSOR_MODE  WaitMode 
)

◆ KeZeroPages()

VOID FASTCALL KeZeroPages ( IN PVOID  Address,
IN ULONG  Size 
)

Definition at line 56 of file cpu.c.

58{
59 /* Not using XMMI in this routine */
61}
static WCHAR Address[46]
Definition: ping.c:68
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

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

◆ KiAcquireFastMutex()

VOID FASTCALL KiAcquireFastMutex ( IN PFAST_MUTEX  FastMutex)

Definition at line 107 of file wait.c.

108{
109 /* Increase contention count */
110 FastMutex->Contention++;
111
112 /* Wait for the event */
113 KeWaitForSingleObject(&FastMutex->Event,
114 WrMutex,
116 FALSE,
117 NULL);
118}
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
@ WrMutex
Definition: ketypes.h:444

Referenced by _ExAcquireFastMutex(), and _ExAcquireFastMutexUnsafe().

◆ KiAcquireGuardedMutex()

VOID FASTCALL KiAcquireGuardedMutex ( IN OUT PKGUARDED_MUTEX  GuardedMutex)

Definition at line 122 of file wait.c.

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}
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define C_ASSERT(e)
Definition: intsafe.h:73
VOID FASTCALL KeWaitForGate(PKGATE Gate, KWAIT_REASON WaitReason, KPROCESSOR_MODE WaitMode)
@ WrGuardedMutex
Definition: ketypes.h:450
#define GM_LOCK_WAITER_WOKEN
#define GM_LOCK_BIT
#define GM_LOCK_WAITER_INC

Referenced by _KeAcquireGuardedMutex(), and _KeAcquireGuardedMutexUnsafe().

◆ KiActivateWaiterQueue()

VOID FASTCALL KiActivateWaiterQueue ( IN PKQUEUE  Queue)

Definition at line 24 of file queue.c.

25{
26 PLIST_ENTRY QueueEntry;
27 PLIST_ENTRY WaitEntry;
28 PKWAIT_BLOCK WaitBlock;
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;
61 }
62 }
63}
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
struct _KTHREAD * Thread
Definition: ketypes.h:465
_Must_inspect_result_ _In_ WDFDEVICE _In_ PIRP _In_ WDFQUEUE Queue
Definition: wdfdevice.h:2225
#define ASSERT_QUEUE(Q)
Definition: ketypes.h:1413

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

◆ KiAddProfileEvent()

VOID NTAPI KiAddProfileEvent ( KPROFILE_SOURCE  Source,
ULONG  Pc 
)

◆ KiAdjustQuantumThread()

VOID NTAPI KiAdjustQuantumThread ( IN PKTHREAD  Thread)

Definition at line 461 of file thrdschd.c.

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 PKTHREAD KiSelectReadyThread(IN KPRIORITY Priority, IN PKPRCB Prcb)
Definition: ke_x.h:1422
FORCEINLINE VOID KiReleasePrcbLock(IN PKPRCB Prcb)
Definition: ke_x.h:230
FORCEINLINE VOID KiAcquirePrcbLock(IN PKPRCB Prcb)
Definition: ke_x.h:220
FORCEINLINE SCHAR KiComputeNewPriority(IN PKTHREAD Thread, IN SCHAR Adjustment)
Definition: ke_x.h:1472
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1148
@ Standby
Definition: ketypes.h:391
struct _KTHREAD * NextThread
Definition: ketypes.h:637
volatile UCHAR State
Definition: ketypes.h:1789

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

◆ KiAttachProcess()

VOID NTAPI KiAttachProcess ( struct _KTHREAD Thread,
struct _KPROCESS Process,
PKLOCK_QUEUE_HANDLE  ApcLock,
struct _KAPC_STATE *  SavedApcState 
)

◆ KiCallbackReturn()

DECLSPEC_NORETURN VOID FASTCALL KiCallbackReturn ( IN PVOID  Stack,
IN NTSTATUS  Status 
)

Referenced by NtCallbackReturn().

◆ KiCallUserMode()

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

Definition at line 321 of file usercall.c.

324{
325 ASSERT(FALSE);
327}
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239

Referenced by KeUserModeCallback().

◆ KiChainedDispatch()

VOID FASTCALL KiChainedDispatch ( IN PKTRAP_FRAME  TrapFrame,
IN PKINTERRUPT  Interrupt 
)

Definition at line 231 of file irqobj.c.

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 */
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}
BOOLEAN NTAPI HalBeginSystemInterrupt(IN KIRQL Irql, IN ULONG Vector, OUT PKIRQL OldIrql)
Definition: pic.c:321
VOID FASTCALL KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
FORCEINLINE DECLSPEC_NORETURN VOID KiExitInterrupt(IN PKTRAP_FRAME TrapFrame, IN KIRQL OldIrql, IN BOOLEAN Spurious)
Definition: irqobj.c:135
@ LevelSensitive
Definition: miniport.h:80
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_INTERRUPT_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFINTERRUPT * Interrupt
Definition: wdfinterrupt.h:379
_In_ BOOLEAN Handled
Definition: ketypes.h:349

Referenced by KiGetVectorDispatch().

◆ KiCheckForKernelApcDelivery()

VOID NTAPI KiCheckForKernelApcDelivery ( VOID  )

Definition at line 36 of file apc.c.

37{
39
40 /* We should only deliver at passive */
42 {
43 /* Raise to APC and Deliver APCs, then lower back to Passive */
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 PASSIVE_LEVEL
Definition: env_spec_w32.h:693
VOID FASTCALL HalRequestSoftwareInterrupt(IN KIRQL Irql)
Definition: pic.c:271
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302

◆ KiCompleteTimer()

VOID FASTCALL KiCompleteTimer ( IN PKTIMER  Timer,
IN PKSPIN_LOCK_QUEUE  LockQueue 
)

Definition at line 167 of file timerobj.c.

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}
#define DPRINT
Definition: sndvol32.h:71
BOOLEAN FASTCALL KiSignalTimer(IN PKTIMER Timer)
Definition: timerobj.c:114

Referenced by KxInsertTimer().

◆ KiComputeReciprocal()

LARGE_INTEGER NTAPI KiComputeReciprocal ( IN LONG  Divisor,
OUT PUCHAR  Shift 
)

Definition at line 123 of file krnlinit.c.

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 */
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}
ULONG LowPart
Definition: typedefs.h:106
_In_ ULONG Shift
Definition: rtlfuncs.h:2681
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3044
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3045

Referenced by KiInitializeKernel().

◆ KiContinue()

NTSTATUS NTAPI KiContinue ( IN PCONTEXT  Context,
IN PKEXCEPTION_FRAME  ExceptionFrame,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 45 of file except.c.

48{
52
53 /* Raise to APC_LEVEL, only if needed */
55
56 /* Set up SEH to validate the context */
58 {
59 /* Check the previous mode */
61 {
62 /* Validate from user-mode */
64 ExceptionFrame,
65 TrapFrame);
66 }
67 else
68 {
69#ifdef _M_AMD64
71#else
72 /* Convert the context into Exception/Trap Frames */
74 ExceptionFrame,
75 TrapFrame,
76 Context->ContextFlags,
78#endif
79 }
80 }
82 {
83 /* Save the exception code */
85 }
87
88 /* Lower the IRQL if needed */
90
91 /* Return status */
92 return Status;
93}
#define KeGetPreviousMode()
Definition: ketypes.h:1115
VOID KiSetTrapContext(_Out_ PKTRAP_FRAME TrapFrame, _In_ PCONTEXT Context, _In_ KPROCESSOR_MODE RequestorMode)
VOID NTAPI KiContinuePreviousModeUser(IN PCONTEXT Context, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: except.c:20
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7

Referenced by NtContinue().

◆ KiDeferredReadyThread()

VOID FASTCALL KiDeferredReadyThread ( IN PKTHREAD  Thread)

Definition at line 79 of file thrdschd.c.

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;
281 if (OldPriority > NextThread->Priority)
282 {
283 /* Preempt it if it's already running */
284 if (NextThread->State == Running) NextThread->Preempted = TRUE;
285
286 /* Set the thread on standby and as the next thread */
287 Thread->State = Standby;
288 Prcb->NextThread = Thread;
289
290 /* Release the lock */
291 KiReleasePrcbLock(Prcb);
292
293 /* Check if we're running on another CPU */
294 if (KeGetCurrentProcessorNumber() != Thread->NextProcessor)
295 {
296 /* We are, send an IPI */
297 KiIpiSend(AFFINITY_MASK(Thread->NextProcessor), IPI_DPC);
298 }
299 return;
300 }
301 }
302
303 /* Sanity check */
304 ASSERT((OldPriority >= 0) && (OldPriority <= HIGH_PRIORITY));
305
306 /* Set this thread as ready */
307 Thread->State = Ready;
308 Thread->WaitTime = KeTickCount.LowPart;
309
310 /* Insert this thread in the appropriate order */
311 Preempted ? InsertHeadList(&Prcb->DispatcherReadyListHead[OldPriority],
312 &Thread->WaitListEntry) :
313 InsertTailList(&Prcb->DispatcherReadyListHead[OldPriority],
314 &Thread->WaitListEntry);
315
316 /* Update the ready summary */
317 Prcb->ReadySummary |= PRIORITY_MASK(OldPriority);
318
319 /* Sanity check */
320 ASSERT(OldPriority == Thread->Priority);
321
322 /* Release the lock */
323 KiReleasePrcbLock(Prcb);
324}
#define InsertHeadList(ListHead, Entry)
#define MEMORY_PRIORITY_FOREGROUND
Definition: pstypes.h:126
#define IPI_DPC
Definition: ketypes.h:298
@ Ready
Definition: ketypes.h:389
@ Running
Definition: ketypes.h:390
@ DeferredReady
Definition: ketypes.h:395
@ AdjustUnwait
Definition: ketypes.h:440
@ AdjustBoost
Definition: ketypes.h:441
NTKERNELAPI volatile KSYSTEM_TIME KeTickCount
Definition: clock.c:19
#define PRIORITY_MASK(Priority)
Definition: ke.h:158
VOID FASTCALL KiIpiSend(KAFFINITY TargetSet, ULONG IpiRequest)
#define STATUS_KERNEL_APC
Definition: ntstatus.h:79
ULONG PsPrioritySeparation
Definition: process.c:28
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:341
struct _KTHREAD * CurrentThread
Definition: ketypes.h:636
USHORT Number
Definition: ketypes.h:629
ULONG ReadySummary
Definition: ketypes.h:796
LIST_ENTRY DispatcherReadyListHead[32]
Definition: ketypes.h:801
ULONG LowPart
Definition: ketypes.h:929
SCHAR Priority
Definition: ketypes.h:1782
ULONG DeferredProcessor
Definition: ketypes.h:1906
UCHAR Preempted
Definition: ketypes.h:1927
KAFFINITY KiIdleSummary
Definition: thrdschd.c:25
VOID FASTCALL KiDeferredReadyThread(IN PKTHREAD Thread)
Definition: thrdschd.c:79
_In_ UCHAR Processor
Definition: kefuncs.h:670

Referenced by _Requires_lock_held_(), KiDeferredReadyThread(), KiInsertDeferredReadyList(), and KiProcessDeferredReadyList().

◆ KiDeliverUserApc()

BOOLEAN NTAPI KiDeliverUserApc ( PKTRAP_FRAME  TrapFrame)

◆ KiDispatchException()

VOID NTAPI KiDispatchException ( PEXCEPTION_RECORD  ExceptionRecord,
PKEXCEPTION_FRAME  ExceptionFrame,
PKTRAP_FRAME  Tf,
KPROCESSOR_MODE  PreviousMode,
BOOLEAN  SearchFrames 
)

◆ KiEndUnexpectedRange()

VOID NTAPI KiEndUnexpectedRange ( VOID  )

◆ KiExitDispatcher()

◆ KiExpireTimers()

VOID NTAPI KiExpireTimers ( PKDPC  Dpc,
PVOID  DeferredContext,
PVOID  SystemArgument1,
PVOID  SystemArgument2 
)

◆ KiHandleNmi()

BOOLEAN NTAPI KiHandleNmi ( VOID  )

Definition at line 1166 of file bug.c.

1167{
1169 PKNMI_HANDLER_CALLBACK NmiData;
1170
1171 /* Parse the list of callbacks */
1172 NmiData = KiNmiCallbackListHead;
1173 while (NmiData)
1174 {
1175 /* Save if this callback has handled it -- all it takes is one */
1176 Handled |= NmiData->Callback(NmiData->Context, Handled);
1177 NmiData = NmiData->Next;
1178 }
1179
1180 /* Has anyone handled this? */
1181 return Handled;
1182}
PKNMI_HANDLER_CALLBACK KiNmiCallbackListHead
Definition: bug.c:33
PNMI_CALLBACK Callback
Definition: ke.h:81
struct _KNMI_HANDLER_CALLBACK * Next
Definition: ke.h:80

Referenced by KiTrap02Handler().

◆ KiIdleLoop()

DECLSPEC_NORETURN VOID KiIdleLoop ( VOID  )

Definition at line 99 of file stubs.c.

100{
101 PKPRCB Prcb = KeGetCurrentPrcb();
102 PKTHREAD OldThread, NewThread;
103
104 /* Now loop forever */
105 while (TRUE)
106 {
107 /* Start of the idle loop: disable interrupts */
108 _enable();
111 _disable();
112
113 /* Check for pending timers, pending DPCs, or pending ready threads */
114 if ((Prcb->DpcData[0].DpcQueueDepth) ||
115 (Prcb->TimerRequest) ||
117 {
118 /* Quiesce the DPC software interrupt */
120
121 /* Handle it */
122 KiRetireDpcList(Prcb);
123 }
124
125 /* Check if a new thread is scheduled for execution */
126 if (Prcb->NextThread)
127 {
128 /* Enable interrupts */
129 _enable();
130
131 /* Capture current thread data */
132 OldThread = Prcb->CurrentThread;
133 NewThread = Prcb->NextThread;
134
135 /* Set new thread data */
136 Prcb->NextThread = NULL;
137 Prcb->CurrentThread = NewThread;
138
139 /* The thread is now running */
140 NewThread->State = Running;
141
142#ifdef CONFIG_SMP
143 /* Do the swap at SYNCH_LEVEL */
145#endif
146
147 /* Switch away from the idle thread */
148 KiSwapContext(APC_LEVEL, OldThread);
149
150#ifdef CONFIG_SMP
151 /* Go back to DISPATCH_LEVEL */
153#endif
154 }
155 else
156 {
157 /* Continue staying idle. Note the HAL returns with interrupts on */
158 Prcb->PowerState.IdleFunction(&Prcb->PowerState);
159 }
160 }
161}
#define SYNCH_LEVEL
Definition: env_spec_w32.h:704
VOID FASTCALL HalClearSoftwareInterrupt(IN KIRQL Irql)
Definition: pic.c:282
void __cdecl _disable(void)
Definition: intrin_arm.h:365
void __cdecl _enable(void)
Definition: intrin_arm.h:373
BOOLEAN FASTCALL KiSwapContext(IN KIRQL WaitIrql, IN PKTHREAD CurrentThread)
VOID FASTCALL KiRetireDpcList(IN PKPRCB Prcb)
Definition: dpc.c:562
#define YieldProcessor
Definition: ke.h:48
volatile ULONG DpcQueueDepth
Definition: ketypes.h:858
PROCESSOR_POWER_STATE PowerState
Definition: ketypes.h:865
KDPC_DATA DpcData[2]
Definition: ketypes.h:746
UINT64 TimerRequest
Definition: ketypes.h:761
SINGLE_LIST_ENTRY DeferredReadyListHead
Definition: ketypes.h:698
PPROCESSOR_IDLE_FUNCTION IdleFunction
Definition: potypes.h:68
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629

Referenced by KiInitializeSystem(), and KiSystemStartupBootStack().

◆ KiIdleSchedule()

PKTHREAD FASTCALL KiIdleSchedule ( IN PKPRCB  Prcb)

Definition at line 32 of file thrdschd.c.

33{
34 /* FIXME: TODO */
35 ASSERTMSG("SMP: Not yet implemented\n", FALSE);
36 return NULL;
37}
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431

◆ KiInitializeBugCheck()

VOID NTAPI KiInitializeBugCheck ( VOID  )

Definition at line 300 of file bug.c.

301{
303 LDR_RESOURCE_INFO ResourceInfo;
304 PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry;
306 PLDR_DATA_TABLE_ENTRY LdrEntry;
307
308 /* Get the kernel entry */
311 InLoadOrderLinks);
312
313 /* Cache the Bugcheck Message Strings. Prepare the Lookup Data */
314 ResourceInfo.Type = 11;
315 ResourceInfo.Name = 1;
316 ResourceInfo.Language = 9;
317
318 /* Do the lookup. */
319 Status = LdrFindResource_U(LdrEntry->DllBase,
320 &ResourceInfo,
322 &ResourceDataEntry);
323
324 /* Make sure it worked */
325 if (NT_SUCCESS(Status))
326 {
327 /* Now actually get a pointer to it */
328 Status = LdrAccessResource(LdrEntry->DllBase,
329 ResourceDataEntry,
331 NULL);
333 }
334}
static tBugCheckData BugCheckData
PMESSAGE_RESOURCE_DATA KiBugCodeMessages
Definition: bug.c:27
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
NTSTATUS NTAPI LdrAccessResource(_In_ PVOID BaseAddress, _In_ PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry, _Out_opt_ PVOID *Resource, _Out_opt_ PULONG Size)
NTSTATUS NTAPI LdrFindResource_U(_In_ PVOID BaseAddress, _In_ PLDR_RESOURCE_INFO ResourceInfo, _In_ ULONG Level, _Out_ PIMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry)
#define RESOURCE_DATA_LEVEL
Definition: ldrtypes.h:33
Definition: pedump.c:458
Definition: btrfs_drv.h:1876
PVOID DllBase
Definition: btrfs_drv.h:1880
ULONG_PTR Language
Definition: ldrtypes.h:183
ULONG_PTR Name
Definition: ldrtypes.h:182
ULONG_PTR Type
Definition: ldrtypes.h:181
LIST_ENTRY LoadOrderListHead
Definition: arc.h:540

Referenced by ExpInitializeExecutive().

◆ KiInitializeContextThread()

VOID NTAPI KiInitializeContextThread ( PKTHREAD  Thread,
PKSYSTEM_ROUTINE  SystemRoutine,
PKSTART_ROUTINE  StartRoutine,
PVOID  StartContext,
PCONTEXT  Context 
)

Referenced by KeInitThread().

◆ KiInitializeMachineType()

VOID NTAPI KiInitializeMachineType ( VOID  )

Definition at line 309 of file kiinit.c.

310{
311 /* Detect ARM version */
313
314 /* Set the number of TLB entries and ASIDs */
316 if (__ARMV6__)
317 {
318 /* 256 ASIDs on v6/v7 */
319 KeNumberProcessIds = 256;
320 }
321 else
322 {
323 /* The TLB is VIVT on v4/v5 */
325 }
326}
FORCEINLINE ARM_ID_CODE_REGISTER KeArmIdCodeRegisterGet(VOID)
Definition: intrin_i.h:31
BOOLEAN KeIsArmV6
Definition: kiinit.c:25
ULONG KeNumberTbEntries
Definition: kiinit.c:27
ULONG KeNumberProcessIds
Definition: kiinit.c:26
#define __ARMV6__
Definition: kiinit.c:30

Referenced by KiInitializeSystem(), and KiSystemStartup().

◆ KiInitializeUserApc()

VOID NTAPI KiInitializeUserApc ( IN PKEXCEPTION_FRAME  Reserved,
IN PKTRAP_FRAME  TrapFrame,
IN PKNORMAL_ROUTINE  NormalRoutine,
IN PVOID  NormalContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 266 of file usercall.c.

272{
273 CONTEXT Context = { 0 };
275 ULONG ContextLength;
276 DPRINT1("User APC: %p %p %p\n", NormalContext, SystemArgument1, SystemArgument2);
277
278 //
279 // Build the user mode context
280 //
281 Context.ContextFlags = CONTEXT_FULL;
282 KeTrapFrameToContext(TrapFrame, ExceptionFrame, &Context);
283
284 //
285 // Setup the context on the user stack
286 //
287 ContextLength = sizeof(CONTEXT);
288 Stack = (ULONG_PTR)(Context.Sp & ~7) - ContextLength;
289
290 //
291 // Make sure the stack is valid, and copy the context
292 //
293 ProbeForWrite((PVOID)Stack, ContextLength, sizeof(QUAD));
295
296 //
297 // Setup the trap frame when we return to user mode
298 //
299 TrapFrame->R0 = (ULONG)NormalContext;
300 TrapFrame->R1 = (ULONG)SystemArgument1;
301 TrapFrame->R2 = (ULONG)SystemArgument2;
302 TrapFrame->R3 = (ULONG)NormalRoutine;
303 TrapFrame->Sp = Stack;
304 TrapFrame->Lr = (ULONG)KeUserApcDispatcher;
305}
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
struct _CONTEXT CONTEXT
#define CONTEXT_FULL
Definition: nt_native.h:1375
PVOID KeUserApcDispatcher
Definition: ke.h:141
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:688
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:689

Referenced by KiDeliverApc(), and PspUserThreadStartup().

◆ KiInitMachineDependent()

VOID NTAPI KiInitMachineDependent ( VOID  )

Definition at line 48 of file kiinit.c.

49{
50 /* Check for large page support */
52 {
53 /* FIXME: Support this */
54 DPRINT("Large Page support detected but not yet taken advantage of!\n");
55 }
56
57 /* Check for global page support */
59 {
60 /* FIXME: Support this */
61 DPRINT("Global Page support detected but not yet taken advantage of!\n");
62 }
63
64 /* Check if we have MTRR */
66 {
67 /* FIXME: Support this */
68 DPRINT("MTRR support detected but not yet taken advantage of!\n");
69 }
70
71 /* Check for PAT and/or MTRR support */
73 {
74 /* FIXME: Support this */
75 DPRINT("PAT support detected but not yet taken advantage of!\n");
76 }
77
78// /* Allocate the IOPM save area */
79// Ki386IopmSaveArea = ExAllocatePoolWithTag(PagedPool,
80// IOPM_SIZE,
81// ' eK');
82// if (!Ki386IopmSaveArea)
83// {
84// /* Bugcheck. We need this for V86/VDM support. */
85// KeBugCheckEx(NO_PAGES_AVAILABLE, 2, IOPM_SIZE, 0, 0);
86// }
87
88}
#define KF_MTRR
Definition: ketypes.h:37
#define KF_LARGE_PAGE
Definition: ketypes.h:36
#define KF_PAT
Definition: ketypes.h:41
#define KF_GLOBAL_PAGE
Definition: ketypes.h:35
ULONG KeFeatureBits
Definition: krnlinit.c:22

Referenced by KeInitSystem().

◆ KiInitSpinLocks()

VOID NTAPI KiInitSpinLocks ( IN PKPRCB  Prcb,
IN CCHAR  Number 
)

Definition at line 187 of file krnlinit.c.

189{
190 ULONG i;
191
192 /* Initialize Dispatcher Fields */
193 Prcb->QueueIndex = 1;
194 Prcb->ReadySummary = 0;
195 Prcb->DeferredReadyListHead.Next = NULL;
196 for (i = 0; i < MAXIMUM_PRIORITY; i++)
197 {
198 /* Initialize the ready list */
199 InitializeListHead(&Prcb->DispatcherReadyListHead[i]);
200 }
201
202 /* Initialize DPC Fields */
203 InitializeListHead(&Prcb->DpcData[DPC_NORMAL].DpcListHead);
204 KeInitializeSpinLock(&Prcb->DpcData[DPC_NORMAL].DpcLock);
205 Prcb->DpcData[DPC_NORMAL].DpcQueueDepth = 0;
206 Prcb->DpcData[DPC_NORMAL].DpcCount = 0;
207 Prcb->DpcRoutineActive = FALSE;
208 Prcb->MaximumDpcQueueDepth = KiMaximumDpcQueueDepth;
209 Prcb->MinimumDpcRate = KiMinimumDpcRate;
210 Prcb->AdjustDpcThreshold = KiAdjustDpcThreshold;
211 KeInitializeDpc(&Prcb->CallDpc, NULL, NULL);
212 KeSetTargetProcessorDpc(&Prcb->CallDpc, Number);
213 KeSetImportanceDpc(&Prcb->CallDpc, HighImportance);
214
215 /* Initialize the Wait List Head */
216 InitializeListHead(&Prcb->WaitListHead);
217
218 /* Initialize Queued Spinlocks */
219 Prcb->LockQueue[LockQueueDispatcherLock].Next = NULL;
220 Prcb->LockQueue[LockQueueDispatcherLock].Lock = &KiDispatcherLock;
221 Prcb->LockQueue[LockQueueExpansionLock].Next = NULL;
222 Prcb->LockQueue[LockQueueExpansionLock].Lock = NULL;
223 Prcb->LockQueue[LockQueuePfnLock].Next = NULL;
224 Prcb->LockQueue[LockQueuePfnLock].Lock = &MmPfnLock;
225 Prcb->LockQueue[LockQueueSystemSpaceLock].Next = NULL;
226 Prcb->LockQueue[LockQueueSystemSpaceLock].Lock = &MmSystemSpaceLock;
227 Prcb->LockQueue[LockQueueBcbLock].Next = NULL;
228 Prcb->LockQueue[LockQueueBcbLock].Lock = &CcBcbSpinLock;
229 Prcb->LockQueue[LockQueueMasterLock].Next = NULL;
230 Prcb->LockQueue[LockQueueMasterLock].Lock = &CcMasterSpinLock;
231 Prcb->LockQueue[LockQueueVacbLock].Next = NULL;
232 Prcb->LockQueue[LockQueueVacbLock].Lock = &CcVacbSpinLock;
233 Prcb->LockQueue[LockQueueWorkQueueLock].Next = NULL;
234 Prcb->LockQueue[LockQueueWorkQueueLock].Lock = &CcWorkQueueSpinLock;
235 Prcb->LockQueue[LockQueueNonPagedPoolLock].Next = NULL;
236 Prcb->LockQueue[LockQueueNonPagedPoolLock].Lock = &NonPagedPoolLock;
237 Prcb->LockQueue[LockQueueMmNonPagedPoolLock].Next = NULL;
238 Prcb->LockQueue[LockQueueMmNonPagedPoolLock].Lock = &MmNonPagedPoolLock;
239 Prcb->LockQueue[LockQueueIoCancelLock].Next = NULL;
240 Prcb->LockQueue[LockQueueIoCancelLock].Lock = &IopCancelSpinLock;
241 Prcb->LockQueue[LockQueueIoVpbLock].Next = NULL;
242 Prcb->LockQueue[LockQueueIoVpbLock].Lock = &IopVpbSpinLock;
243 Prcb->LockQueue[LockQueueIoDatabaseLock].Next = NULL;
244 Prcb->LockQueue[LockQueueIoDatabaseLock].Lock = &IopDatabaseLock;
245 Prcb->LockQueue[LockQueueIoCompletionLock].Next = NULL;
246 Prcb->LockQueue[LockQueueIoCompletionLock].Lock = &IopCompletionLock;
247 Prcb->LockQueue[LockQueueNtfsStructLock].Next = NULL;
248 Prcb->LockQueue[LockQueueNtfsStructLock].Lock = &NtfsStructLock;
249 Prcb->LockQueue[LockQueueAfdWorkQueueLock].Next = NULL;
250 Prcb->LockQueue[LockQueueAfdWorkQueueLock].Lock = &AfdWorkQueueSpinLock;
251 Prcb->LockQueue[LockQueueUnusedSpare16].Next = NULL;
252 Prcb->LockQueue[LockQueueUnusedSpare16].Lock = NULL;
253
254 /* Loop timer locks (shared amongst all CPUs) */
255 for (i = 0; i < LOCK_QUEUE_TIMER_TABLE_LOCKS; i++)
256 {
257 /* Setup the Queued Spinlock (done only once by the boot CPU) */
258 if (!Number)
260
261 /* Initialize the lock */
262 Prcb->LockQueue[LockQueueTimerTableLock + i].Next = NULL;
263 Prcb->LockQueue[LockQueueTimerTableLock + i].Lock =
265 }
266
267 /* Initialize the PRCB lock */
268 KeInitializeSpinLock(&Prcb->PrcbLock);
269
270 /* Check if this is the boot CPU */
271 if (!Number)
272 {
273 /* Initialize the lock themselves */
290 }
291}
VOID NTAPI KeSetTargetProcessorDpc(IN PKDPC Dpc, IN CCHAR Number)
Definition: dpc.c:971
VOID NTAPI KeSetImportanceDpc(IN PKDPC Dpc, IN KDPC_IMPORTANCE Importance)
Definition: dpc.c:958
#define MAXIMUM_PRIORITY
KSPIN_LOCK IopCompletionLock
Definition: krnlinit.c:60
KSPIN_LOCK AfdWorkQueueSpinLock
Definition: krnlinit.c:62
KSPIN_LOCK MmPfnLock
Definition: krnlinit.c:49
KSPIN_LOCK CcMasterSpinLock
Definition: krnlinit.c:52
KSPIN_LOCK KiTimerTableLock[LOCK_QUEUE_TIMER_TABLE_LOCKS]
Definition: krnlinit.c:63
KSPIN_LOCK IopDatabaseLock
Definition: krnlinit.c:59
KSPIN_LOCK KiReverseStallIpiLock
Definition: krnlinit.c:64
KSPIN_LOCK NonPagedPoolLock
Definition: krnlinit.c:55
KSPIN_LOCK MmNonPagedPoolLock
Definition: krnlinit.c:56
KSPIN_LOCK CcVacbSpinLock
Definition: krnlinit.c:53
KSPIN_LOCK NtfsStructLock
Definition: krnlinit.c:61
KSPIN_LOCK KiDispatcherLock
Definition: krnlinit.c:48
KSPIN_LOCK IopVpbSpinLock
Definition: krnlinit.c:58
KSPIN_LOCK MmSystemSpaceLock
Definition: krnlinit.c:50
KSPIN_LOCK IopCancelSpinLock
Definition: krnlinit.c:57
KSPIN_LOCK CcWorkQueueSpinLock
Definition: krnlinit.c:54
KSPIN_LOCK CcBcbSpinLock
Definition: krnlinit.c:51
ULONG KiAdjustDpcThreshold
Definition: dpc.c:21
ULONG KiMaximumDpcQueueDepth
Definition: dpc.c:19
ULONG KiMinimumDpcRate
Definition: dpc.c:20
@ HighImportance
Definition: ketypes.h:695
#define DPC_NORMAL
#define LOCK_QUEUE_TIMER_TABLE_LOCKS
@ LockQueueNtfsStructLock
Definition: ketypes.h:670
@ LockQueueExpansionLock
Definition: ketypes.h:659
@ LockQueueTimerTableLock
Definition: ketypes.h:675
@ LockQueueWorkQueueLock
Definition: ketypes.h:666
@ LockQueueUnusedSpare16
Definition: ketypes.h:674
@ LockQueueNonPagedPoolLock
Definition: ketypes.h:664
@ LockQueueSystemSpaceLock
Definition: ketypes.h:661
@ LockQueueMasterLock
Definition: ketypes.h:663
@ LockQueueDispatcherLock
Definition: ketypes.h:658
@ LockQueueIoCancelLock
Definition: ketypes.h:665
@ LockQueuePfnLock
Definition: ketypes.h:660
@ LockQueueIoDatabaseLock
Definition: ketypes.h:668
@ LockQueueMmNonPagedPoolLock
Definition: ketypes.h:673
@ LockQueueBcbLock
Definition: ketypes.h:672
@ LockQueueIoVpbLock
Definition: ketypes.h:667
@ LockQueueIoCompletionLock
Definition: ketypes.h:669
@ LockQueueAfdWorkQueueLock
Definition: ketypes.h:671
@ LockQueueVacbLock
Definition: ketypes.h:662

Referenced by KiInitializeKernel(), and KiSystemStartupBootStack().

◆ KiInitSystem()

VOID NTAPI KiInitSystem ( VOID  )

Definition at line 71 of file krnlinit.c.

72{
73 ULONG i;
74
75 /* Initialize Bugcheck Callback data */
79
80 /* Initialize the Timer Expiration DPC */
83
84 /* Initialize Profiling data */
88
89 /* Loop the timer table */
90 for (i = 0; i < TIMER_TABLE_SIZE; i++)
91 {
92 /* Initialize the list and entries */
94 KiTimerTableListHead[i].Time.HighPart = 0xFFFFFFFF;
96 }
97
98 /* Initialize the Swap event and all swap lists */
103
104 /* Initialize the mutex for generic DPC calls */
106
107 /* Initialize the syscall table */
113
114 /* Copy the the current table into the shadow table for win32k */
118}
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
ULONG KiServiceLimit
Definition: krnlinit.c:26
@ SynchronizationEvent
LIST_ENTRY KeBugcheckCallbackListHead
Definition: bug.c:22
LIST_ENTRY KiProcessOutSwapListHead
Definition: ke.h:136
FAST_MUTEX KiGenericCallDpcMutex
Definition: dpc.c:24
KEVENT KiSwapEvent
Definition: procobj.c:21
KDPC KiTimerExpireDpc
Definition: dpc.c:25
KSPIN_LOCK BugCheckCallbackLock
Definition: bug.c:24
LIST_ENTRY KiProfileListHead
Definition: profobj.c:18
LIST_ENTRY KiProcessInSwapListHead
Definition: procobj.c:19
KSPIN_LOCK KiProfileLock
Definition: profobj.c:20
LIST_ENTRY KiStackInSwapListHead
Definition: procobj.c:20
LIST_ENTRY KeBugcheckReasonCallbackListHead
Definition: ke.h:128
LIST_ENTRY KiProfileSourceListHead
Definition: ke.h:133
VOID NTAPI KiTimerExpiration(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:79
ULONG_PTR MainSSDT[]
Definition: napi.h:9
UCHAR MainSSPT[]
Definition: napi.h:15
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES]
Definition: procobj.c:24
base of all file and directory entries
Definition: entries.h:83
ULARGE_INTEGER Time
Definition: ketypes.h:779
$ULONG LowPart
Definition: ntbasedef.h:569
$ULONG HighPart
Definition: ntbasedef.h:570
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274

Referenced by KiInitializeKernel().

◆ KiInsertQueue()

LONG NTAPI KiInsertQueue ( IN PKQUEUE  Queue,
IN PLIST_ENTRY  Entry,
BOOLEAN  Head 
)

Referenced by KeTerminateThread().

◆ KiInsertQueueApc()

VOID FASTCALL KiInsertQueueApc ( IN PKAPC  Apc,
IN KPRIORITY  PriorityBoost 
)

Definition at line 85 of file apc.c.

87{
88 PKTHREAD Thread = Apc->Thread;
90 KPROCESSOR_MODE ApcMode;
91 PLIST_ENTRY ListHead, NextEntry;
92 PKAPC QueuedApc;
93 PKGATE Gate;
95 BOOLEAN RequestInterrupt = FALSE;
96
97 /*
98 * Check if the caller wanted this APC to use the thread's environment at
99 * insertion time.
100 */
101 if (Apc->ApcStateIndex == InsertApcEnvironment)
102 {
103 /* Copy it over */
104 Apc->ApcStateIndex = Thread->ApcStateIndex;
105 }
106
107 /* Get the APC State for this Index, and the mode too */
108 ApcState = Thread->ApcStatePointer[(UCHAR)Apc->ApcStateIndex];
109 ApcMode = Apc->ApcMode;
110
111 /* The APC must be "inserted" already */
112 ASSERT(Apc->Inserted == TRUE);
113
114 /* Three scenarios:
115 * 1) Kernel APC with Normal Routine or User APC = Put it at the end of the List
116 * 2) User APC which is PsExitSpecialApc = Put it at the front of the List
117 * 3) Kernel APC without Normal Routine = Put it at the end of the No-Normal Routine Kernel APC list
118 */
119 if (Apc->NormalRoutine)
120 {
121 /* Normal APC; is it the Thread Termination APC? */
122 if ((ApcMode != KernelMode) &&
123 (Apc->KernelRoutine == PsExitSpecialApc))
124 {
125 /* Set User APC pending to true */
126 Thread->ApcState.UserApcPending = TRUE;
127
128 /* Insert it at the top of the list */
129 InsertHeadList(&ApcState->ApcListHead[ApcMode],
130 &Apc->ApcListEntry);
131 }
132 else
133 {
134 /* Regular user or kernel Normal APC */
135 InsertTailList(&ApcState->ApcListHead[ApcMode],
136 &Apc->ApcListEntry);
137 }
138 }
139 else
140 {
141 /* Special APC, find the last one in the list */
142 ListHead = &ApcState->ApcListHead[ApcMode];
143 NextEntry = ListHead->Blink;
144 while (NextEntry != ListHead)
145 {
146 /* Get the APC */
147 QueuedApc = CONTAINING_RECORD(NextEntry, KAPC, ApcListEntry);
148
149 /* Is this a No-Normal APC? If so, break */
150 if (!QueuedApc->NormalRoutine) break;
151
152 /* Move to the previous APC in the Queue */
153 NextEntry = NextEntry->Blink;
154 }
155
156 /* Insert us here */
157 InsertHeadList(NextEntry, &Apc->ApcListEntry);
158 }
159
160 /* Now check if the Apc State Indexes match */
161 if (Thread->ApcStateIndex == Apc->ApcStateIndex)
162 {
163 /* Check that the thread matches */
164 if (Thread == KeGetCurrentThread())
165 {
166 /* Sanity check */
167 ASSERT(Thread->State == Running);
168
169 /* Check if this is kernel mode */
170 if (ApcMode == KernelMode)
171 {
172 /* All valid, a Kernel APC is pending now */
173 Thread->ApcState.KernelApcPending = TRUE;
174
175 /* Check if Special APCs are disabled */
176 if (!Thread->SpecialApcDisable)
177 {
178 /* They're not, so request the interrupt */
180 }
181 }
182 }
183 else
184 {
185 /* Acquire the dispatcher lock */
187
188 /* Check if this is a kernel-mode APC */
189 if (ApcMode == KernelMode)
190 {
191 /* Kernel-mode APC, set us pending */
192 Thread->ApcState.KernelApcPending = TRUE;
193
194 /* Are we currently running? */
195 if (Thread->State == Running)
196 {
197 /* The thread is running, so remember to send a request */
198 RequestInterrupt = TRUE;
199 }
200 else if ((Thread->State == Waiting) &&
201 (Thread->WaitIrql == PASSIVE_LEVEL) &&
202 !(Thread->SpecialApcDisable) &&
203 (!(Apc->NormalRoutine) ||
204 (!(Thread->KernelApcDisable) &&
205 !(Thread->ApcState.KernelApcInProgress))))
206 {
207 /* We'll unwait with this status */
209
210 /* Wake up the thread */
212 }
213 else if (Thread->State == GateWait)
214 {
215 /* Lock the thread */
217
218 /* Essentially do the same check as above */
219 if ((Thread->State == GateWait) &&
220 (Thread->WaitIrql == PASSIVE_LEVEL) &&
221 !(Thread->SpecialApcDisable) &&
222 (!(Apc->NormalRoutine) ||
223 (!(Thread->KernelApcDisable) &&
224 !(Thread->ApcState.KernelApcInProgress))))
225 {
226 /* We were in a gate wait. Handle this. */
227 DPRINT1("A thread was in a gate wait\n");
228
229 /* Get the gate */
230 Gate = Thread->GateObject;
231
232 /* Lock the gate */
234
235 /* Remove it from the waiters list */
236 RemoveEntryList(&Thread->WaitBlock[0].WaitListEntry);
237
238 /* Unlock the gate */
240
241 /* Increase the queue counter if needed */
242 if (Thread->Queue) Thread->Queue->CurrentCount++;
243
244 /* Put into deferred ready list with this status */
245 Thread->WaitStatus = STATUS_KERNEL_APC;
247 }
248
249 /* Release the thread lock */
251 }
252 }
253 else if ((Thread->State == Waiting) &&
254 (Thread->WaitMode == UserMode) &&
255 ((Thread->Alertable) ||
256 (Thread->ApcState.UserApcPending)))
257 {
258 /* Set user-mode APC pending */
259 Thread->ApcState.UserApcPending = TRUE;
261
262 /* Wake up the thread */
264 }
265
266 /* Release dispatcher lock */
268
269 /* Check if an interrupt was requested */
270 KiRequestApcInterrupt(RequestInterrupt, Thread->NextProcessor);
271 }
272 }
273}
FORCEINLINE VOID KiRequestApcInterrupt(IN BOOLEAN NeedApc, IN UCHAR Processor)
Definition: ke_x.h:276
FORCEINLINE VOID KiReleaseDispatcherObject(IN DISPATCHER_HEADER *Object)
Definition: ke_x.h:142
FORCEINLINE VOID KiInsertDeferredReadyList(IN PKTHREAD Thread)
Definition: ke_x.h:185
FORCEINLINE VOID KiAcquireDispatcherObject(IN DISPATCHER_HEADER *Object)
Definition: ke_x.h:132
@ GateWait
Definition: ketypes.h:397
@ InsertApcEnvironment
Definition: ketypes.h:770
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1765
#define STATUS_USER_APC
Definition: ntstatus.h:78
VOID NTAPI PsExitSpecialApc(PKAPC Apc, PKNORMAL_ROUTINE *NormalRoutine, PVOID *NormalContext, PVOID *SystemArgument1, PVOID *SystemArgument2)
DISPATCHER_HEADER Header
Definition: ketypes.h:823
_In_ WDFREQUEST _In_ NTSTATUS _In_ CCHAR PriorityBoost
Definition: wdfrequest.h:1016
* PKAPC_STATE
Definition: ketypes.h:1409

Referenced by KeFreezeAllThreads(), KeInsertQueueApc(), and KeSuspendThread().

◆ KiInsertTimerTable()

BOOLEAN FASTCALL KiInsertTimerTable ( IN PKTIMER  Timer,
IN ULONG  Hand 
)

Definition at line 63 of file timerobj.c.

65{
66 LARGE_INTEGER InterruptTime;
67 LONGLONG DueTime = Timer->DueTime.QuadPart;
68 BOOLEAN Expired = FALSE;
69 PLIST_ENTRY ListHead, NextEntry;
70 PKTIMER CurrentTimer;
71 DPRINT("KiInsertTimerTable(): Timer %p, Hand: %lu\n", Timer, Hand);
72
73 /* Check if the period is zero */
74 if (!Timer->Period) Timer->Header.SignalState = FALSE;
75
76 /* Sanity check */
78
79 /* Loop the timer list backwards */
80 ListHead = &KiTimerTableListHead[Hand].Entry;
81 NextEntry = ListHead->Blink;
82 while (NextEntry != ListHead)
83 {
84 /* Get the timer */
85 CurrentTimer = CONTAINING_RECORD(NextEntry, KTIMER, TimerListEntry);
86
87 /* Now check if we can fit it before */
88 if ((ULONGLONG)DueTime >= CurrentTimer->DueTime.QuadPart) break;
89
90 /* Keep looping */
91 NextEntry = NextEntry->Blink;
92 }
93
94 /* Looped all the list, insert it here and get the interrupt time again */
95 InsertHeadList(NextEntry, &Timer->TimerListEntry);
96
97 /* Check if we didn't find it in the list */
98 if (NextEntry == ListHead)
99 {
100 /* Set the time */
102
103 /* Make sure it hasn't expired already */
104 InterruptTime.QuadPart = KeQueryInterruptTime();
105 if (DueTime <= InterruptTime.QuadPart) Expired = TRUE;
106 }
107
108 /* Return expired state */
109 return Expired;
110}
#define KeQueryInterruptTime()
Definition: ke.h:37
ULARGE_INTEGER DueTime
Definition: ketypes.h:853
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
KTIMER_TABLE_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE]
Definition: timerobj.c:17
uint64_t ULONGLONG
Definition: typedefs.h:67

Referenced by KeSetSystemTime(), KiInsertTreeTimer(), and KxInsertTimer().

◆ KiInsertTreeTimer()

BOOLEAN FASTCALL KiInsertTreeTimer ( IN PKTIMER  Timer,
IN LARGE_INTEGER  Interval 
)

Definition at line 26 of file timerobj.c.

28{
29 BOOLEAN Inserted = FALSE;
30 ULONG Hand = 0;
31 PKSPIN_LOCK_QUEUE LockQueue;
32 DPRINT("KiInsertTreeTimer(): Timer %p, Interval: %I64d\n", Timer, Interval.QuadPart);
33
34 /* Setup the timer's due time */
35 if (KiComputeDueTime(Timer, Interval, &Hand))
36 {
37 /* Acquire the lock */
38 LockQueue = KiAcquireTimerLock(Hand);
39
40 /* Insert the timer */
41 if (KiInsertTimerTable(Timer, Hand))
42 {
43 /* It was already there, remove it */
45 Timer->Header.Inserted = FALSE;
46 }
47 else
48 {
49 /* Otherwise, we're now inserted */
50 Inserted = TRUE;
51 }
52
53 /* Release the lock */
54 KiReleaseTimerLock(LockQueue);
55 }
56
57 /* Release the lock and return insert status */
58 return Inserted;
59}
FORCEINLINE BOOLEAN KiComputeDueTime(IN PKTIMER Timer, IN LARGE_INTEGER DueTime, OUT PULONG Hand)
Definition: ke_x.h:952
DWORD Interval
Definition: netstat.c:30
BOOLEAN FASTCALL KiInsertTimerTable(IN PKTIMER Timer, IN ULONG Hand)
Definition: timerobj.c:63

Referenced by KiSignalTimer(), KiTimerExpiration(), and KiTimerListExpire().

◆ KiInterruptDispatch()

VOID FASTCALL KiInterruptDispatch ( IN PKTRAP_FRAME  TrapFrame,
IN PKINTERRUPT  Interrupt 
)

Definition at line 197 of file irqobj.c.

199{
201
202 /* Increase interrupt count */
203 KeGetCurrentPrcb()->InterruptCount++;
204
205 /* Begin the interrupt, making sure it's not spurious */
206 if (HalBeginSystemInterrupt(Interrupt->SynchronizeIrql,
207 Interrupt->Vector,
208 &OldIrql))
209 {
210 /* Acquire interrupt lock */
211 KxAcquireSpinLock(Interrupt->ActualLock);
212
213 /* Call the ISR */
214 Interrupt->ServiceRoutine(Interrupt, Interrupt->ServiceContext);
215
216 /* Release interrupt lock */
217 KxReleaseSpinLock(Interrupt->ActualLock);
218
219 /* Now call the epilogue code */
220 KiExitInterrupt(TrapFrame, OldIrql, FALSE);
221 }
222 else
223 {
224 /* Now call the epilogue code */
225 KiExitInterrupt(TrapFrame, OldIrql, TRUE);
226 }
227}

◆ KiInterruptTemplate()

VOID __cdecl KiInterruptTemplate ( VOID  )

◆ KiIpiSend()

VOID FASTCALL KiIpiSend ( KAFFINITY  TargetSet,
ULONG  IpiRequest 
)

◆ KiIpiSendPacket()

VOID NTAPI KiIpiSendPacket ( IN KAFFINITY  TargetProcessors,
IN PKIPI_WORKER  WorkerFunction,
IN PKIPI_BROADCAST_WORKER  BroadcastFunction,
IN ULONG_PTR  Context,
IN PULONG  Count 
)

Definition at line 45 of file ipi.c.

50{
51 /* FIXME: TODO */
52 ASSERTMSG("Not yet implemented\n", FALSE);
53}

Referenced by KeFlushEntireTb(), and KeIpiGenericCall().

◆ KiIpiSignalPacketDone()

VOID FASTCALL KiIpiSignalPacketDone ( IN PKIPI_CONTEXT  PacketContext)

Definition at line 57 of file ipi.c.

58{
59 /* FIXME: TODO */
60 ASSERTMSG("Not yet implemented\n", FALSE);
61}

Referenced by KiFlushTargetEntireTb().

◆ KiIpiSignalPacketDoneAndStall()

VOID FASTCALL KiIpiSignalPacketDoneAndStall ( IN PKIPI_CONTEXT  PacketContext,
IN volatile PULONG  ReverseStall 
)

Definition at line 65 of file ipi.c.

67{
68 /* FIXME: TODO */
69 ASSERTMSG("Not yet implemented\n", FALSE);
70}

◆ KiMoveApcState()

VOID NTAPI KiMoveApcState ( PKAPC_STATE  OldState,
PKAPC_STATE  NewState 
)

Definition at line 538 of file apc.c.

540{
541 /* Restore backup of Original Environment */
542 RtlCopyMemory(NewState, OldState, KAPC_STATE_ACTUAL_LENGTH);
543
544 /* Repair Lists */
545 RepairList(OldState->ApcListHead, NewState->ApcListHead, KernelMode);
546 RepairList(OldState->ApcListHead, NewState->ApcListHead, UserMode);
547}
FORCEINLINE VOID RepairList(IN PLIST_ENTRY Original, IN PLIST_ENTRY Copy, IN KPROCESSOR_MODE Mode)
Definition: apc.c:516
#define KAPC_STATE_ACTUAL_LENGTH
Definition: ketypes.h:1411

Referenced by KeDetachProcess(), KeUnstackDetachProcess(), and KiAttachProcess().

◆ KiPcToFileHeader()

PVOID NTAPI KiPcToFileHeader ( IN PVOID  Eip,
OUT PLDR_DATA_TABLE_ENTRY LdrEntry,
IN BOOLEAN  DriversOnly,
OUT PBOOLEAN  InKernel 
)

Definition at line 44 of file bug.c.

48{
49 ULONG i = 0;
50 PVOID ImageBase, PcBase = NULL;
52 PLIST_ENTRY ListHead, NextEntry;
53
54 /* Check which list we should use */
57
58 /* Assume no */
59 *InKernel = FALSE;
60
61 /* Set list pointers and make sure it's valid */
62 NextEntry = ListHead->Flink;
63 if (NextEntry)
64 {
65 /* Start loop */
66 while (NextEntry != ListHead)
67 {
68 /* Increase entry */
69 i++;
70
71 /* Check if this is a kernel entry and we only want drivers */
72 if ((i <= 2) && (DriversOnly != FALSE))
73 {
74 /* Skip it */
75 NextEntry = NextEntry->Flink;
76 continue;
77 }
78
79 /* Get the loader entry */
80 Entry = CONTAINING_RECORD(NextEntry,
82 InLoadOrderLinks);
83
84 /* Move to the next entry */
85 NextEntry = NextEntry->Flink;
86 ImageBase = Entry->DllBase;
87
88 /* Check if this is the right one */
89 if (((ULONG_PTR)Pc >= (ULONG_PTR)Entry->DllBase) &&
90 ((ULONG_PTR)Pc < ((ULONG_PTR)Entry->DllBase + Entry->SizeOfImage)))
91 {
92 /* Return this entry */
93 *LdrEntry = Entry;
94 PcBase = ImageBase;
95
96 /* Check if this was a kernel or HAL entry */
97 if (i <= 2) *InKernel = TRUE;
98 break;
99 }
100 }
101 }
102
103 /* Return the base address */
104 return PcBase;
105}
if(dx< 0)
Definition: linetemp.h:194
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:21

Referenced by KeBugCheckWithTf(), KeRosDumpStackFrameArray(), KiDumpParameterImages(), and RtlPcToFileHeader().

◆ KiProcessDeferredReadyList()

VOID FASTCALL KiProcessDeferredReadyList ( IN PKPRCB  Prcb)

Definition at line 41 of file thrdschd.c.

42{
43 PSINGLE_LIST_ENTRY ListEntry;
45
46 /* Make sure there is something on the ready list */
47 ASSERT(Prcb->DeferredReadyListHead.Next != NULL);
48
49 /* Get the first entry and clear the list */
50 ListEntry = Prcb->DeferredReadyListHead.Next;
51 Prcb->DeferredReadyListHead.Next = NULL;
52
53 /* Start processing loop */
54 do
55 {
56 /* Get the thread and advance to the next entry */
57 Thread = CONTAINING_RECORD(ListEntry, KTHREAD, SwapListEntry);
58 ListEntry = ListEntry->Next;
59
60 /* Make the thread ready */
62 } while (ListEntry != NULL);
63
64 /* Make sure the ready list is still empty */
65 ASSERT(Prcb->DeferredReadyListHead.Next == NULL);
66}
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
Definition: ntbasedef.h:628

Referenced by KiRetireDpcList().

◆ KiQuantumEnd()

VOID NTAPI KiQuantumEnd ( VOID  )

◆ KiRaiseException()

NTSTATUS NTAPI KiRaiseException ( IN PEXCEPTION_RECORD  ExceptionRecord,
IN PCONTEXT  Context,
IN PKEXCEPTION_FRAME  ExceptionFrame,
IN PKTRAP_FRAME  TrapFrame,
IN BOOLEAN  SearchFrames 
)

Definition at line 97 of file except.c.

102{
104 CONTEXT LocalContext;
105 EXCEPTION_RECORD LocalExceptionRecord;
106 ULONG ParameterCount, Size;
107
108 /* Check if we need to probe */
110 {
111 /* Set up SEH */
113 {
114 /* Probe the context */
115 ProbeForRead(Context, sizeof(CONTEXT), sizeof(ULONG));
116
117 /* Probe the Exception Record */
118 ProbeForRead(ExceptionRecord,
119 FIELD_OFFSET(EXCEPTION_RECORD, NumberParameters) +
120 sizeof(ULONG),
121 sizeof(ULONG));
122
123 /* Validate the maximum parameters */
124 if ((ParameterCount = ExceptionRecord->NumberParameters) >
126 {
127 /* Too large */
129 }
130
131 /* Probe the entire parameters now*/
132 Size = (sizeof(EXCEPTION_RECORD) -
133 ((EXCEPTION_MAXIMUM_PARAMETERS - ParameterCount) * sizeof(ULONG)));
134 ProbeForRead(ExceptionRecord, Size, sizeof(ULONG));
135
136 /* Now make copies in the stack */
137 RtlCopyMemory(&LocalContext, Context, sizeof(CONTEXT));
138 RtlCopyMemory(&LocalExceptionRecord, ExceptionRecord, Size);
139 Context = &LocalContext;
140 ExceptionRecord = &LocalExceptionRecord;
141
142 /* Update the parameter count */
143 ExceptionRecord->NumberParameters = ParameterCount;
144 }
146 {
147 /* Don't fail silently */
148 DPRINT1("KiRaiseException: Failed to Probe\n");
149
150 /* Return the exception code */
152 }
153 _SEH2_END;
154 }
155
156 /* Convert the context record */
158 ExceptionFrame,
159 TrapFrame,
160 Context->ContextFlags,
162
163 /* Dispatch the exception */
164 ExceptionRecord->ExceptionCode &= ~KI_EXCEPTION_INTERNAL;
165 KiDispatchException(ExceptionRecord,
166 ExceptionFrame,
167 TrapFrame,
169 SearchFrames);
170
171 /* We are done */
172 return STATUS_SUCCESS;
173}
#define EXCEPTION_MAXIMUM_PARAMETERS
Definition: compat.h:206
struct _EXCEPTION_RECORD EXCEPTION_RECORD
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
VOID NTAPI KiDispatchException(PEXCEPTION_RECORD ExceptionRecord, PKEXCEPTION_FRAME ExceptionFrame, PKTRAP_FRAME Tf, KPROCESSOR_MODE PreviousMode, BOOLEAN SearchFrames)
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
DWORD NumberParameters
Definition: compat.h:212
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by NtRaiseException().

◆ KiReadyThread()

VOID NTAPI KiReadyThread ( IN PKTHREAD  Thread)

Definition at line 429 of file thrdschd.c.

430{
431 IN PKPROCESS Process = Thread->ApcState.Process;
432
433 /* Check if the process is paged out */
434 if (Process->State != ProcessInMemory)
435 {
436 /* We don't page out processes in ROS */
437 ASSERT(FALSE);
438 }
439 else if (!Thread->KernelStackResident)
440 {
441 /* Increase the stack count */
442 ASSERT(Process->StackCount != MAXULONG_PTR);
443 Process->StackCount++;
444
445 /* Set the thread to transition */
446 ASSERT(Thread->State != Transition);
447 Thread->State = Transition;
448
449 /* The stack is always resident in ROS */
450 ASSERT(FALSE);
451 }
452 else
453 {
454 /* Insert the thread on the deferred ready list */
456 }
457}
@ ProcessInMemory
Definition: ketypes.h:460
@ Transition
Definition: ketypes.h:394
#define IN
Definition: typedefs.h:39

Referenced by KeReadyThread(), KeSetEventBoostPriority(), KeSignalGateBoostPriority(), KiAttachProcess(), KiInsertQueue(), and KiUnwaitThread().

◆ KiRestoreProcessorControlState()

VOID NTAPI KiRestoreProcessorControlState ( IN PKPROCESSOR_STATE  ProcessorState)

◆ KiRetireDpcList()

VOID FASTCALL KiRetireDpcList ( IN PKPRCB  Prcb)

Definition at line 562 of file dpc.c.

563{
564 PKDPC_DATA DpcData;
565 PLIST_ENTRY ListHead, DpcEntry;
566 PKDPC Dpc;
567 PKDEFERRED_ROUTINE DeferredRoutine;
569 ULONG_PTR TimerHand;
570#ifdef CONFIG_SMP
572#endif
573
574 /* Get data and list variables before starting anything else */
575 DpcData = &Prcb->DpcData[DPC_NORMAL];
576 ListHead = &DpcData->DpcListHead;
577
578 /* Main outer loop */
579 do
580 {
581 /* Set us as active */
582 Prcb->DpcRoutineActive = TRUE;
583
584 /* Check if this is a timer expiration request */
585 if (Prcb->TimerRequest)
586 {
587 /* It is, get the timer hand and disable timer request */
588 TimerHand = Prcb->TimerHand;
589 Prcb->TimerRequest = 0;
590
591 /* Expire timers with interrupts enabled */
592 _enable();
593 KiTimerExpiration(NULL, NULL, (PVOID)TimerHand, NULL);
594 _disable();
595 }
596
597 /* Loop while we have entries in the queue */
598 while (DpcData->DpcQueueDepth != 0)
599 {
600 /* Lock the DPC data and get the DPC entry*/
602 DpcEntry = ListHead->Flink;
603
604 /* Make sure we have an entry */
605 if (DpcEntry != ListHead)
606 {
607 /* Remove the DPC from the list */
608 RemoveEntryList(DpcEntry);
609 Dpc = CONTAINING_RECORD(DpcEntry, KDPC, DpcListEntry);
610
611 /* Clear its DPC data and save its parameters */
612 Dpc->DpcData = NULL;
613 DeferredRoutine = Dpc->DeferredRoutine;
614 DeferredContext = Dpc->DeferredContext;
615 SystemArgument1 = Dpc->SystemArgument1;
616 SystemArgument2 = Dpc->SystemArgument2;
617
618 /* Decrease the queue depth */
619 DpcData->DpcQueueDepth--;
620
621#if DBG
622 /* Clear DPC Time */
623 Prcb->DebugDpcTime = 0;
624#endif
625
626 /* Release the lock */
628
629 /* Re-enable interrupts */
630 _enable();
631
632 /* Call the DPC */
633 DeferredRoutine(Dpc,
638
639 /* Disable interrupts and keep looping */
640 _disable();
641 }
642 else
643 {
644 /* The queue should be flushed now */
645 ASSERT(DpcData->DpcQueueDepth == 0);
646
647 /* Release DPC Lock */
649 }
650 }
651
652 /* Clear DPC Flags */
653 Prcb->DpcRoutineActive = FALSE;
654 Prcb->DpcInterruptRequested = FALSE;
655
656#ifdef CONFIG_SMP
657 /* Check if we have deferred threads */
658 if (Prcb->DeferredReadyListHead.Next)
659 {
660
661 /* Re-enable interrupts and raise to synch */
662 _enable();
664
665 /* Process deferred threads */
667
668 /* Lower IRQL back and disable interrupts */
670 _disable();
671 }
672#endif
673 } while (DpcData->DpcQueueDepth != 0);
674}
VOID NTAPI KiTimerExpiration(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:79
VOID FASTCALL KiProcessDeferredReadyList(IN PKPRCB Prcb)
Definition: thrdschd.c:41
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
ULONG_PTR DpcLock
Definition: ketypes.h:854
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:112
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:687
KDEFERRED_ROUTINE * PKDEFERRED_ROUTINE
Definition: ketypes.h:690

Referenced by KiDispatchInterrupt(), and KiIdleLoop().

◆ KiRosPcToUserFileHeader()

PVOID NTAPI KiRosPcToUserFileHeader ( IN PVOID  Eip,
OUT PLDR_DATA_TABLE_ENTRY LdrEntry 
)

Definition at line 109 of file bug.c.

111{
112 PVOID ImageBase, PcBase = NULL;
114 PLIST_ENTRY ListHead, NextEntry;
115
116 /*
117 * We know this is valid because we should only be called after a
118 * succesfull address from RtlWalkFrameChain for UserMode, which
119 * validates everything for us.
120 */
121 ListHead = &KeGetCurrentThread()->
122 Teb->ProcessEnvironmentBlock->Ldr->InLoadOrderModuleList;
123
124 /* Set list pointers and make sure it's valid */
125 NextEntry = ListHead->Flink;
126 if (NextEntry)
127 {
128 /* Start loop */
129 while (NextEntry != ListHead)
130 {
131 /* Get the loader entry */
132 Entry = CONTAINING_RECORD(NextEntry,
134 InLoadOrderLinks);
135
136 /* Move to the next entry */
137 NextEntry = NextEntry->Flink;
138 ImageBase = Entry->DllBase;
139
140 /* Check if this is the right one */
141 if (((ULONG_PTR)Pc >= (ULONG_PTR)Entry->DllBase) &&
142 ((ULONG_PTR)Pc < ((ULONG_PTR)Entry->DllBase + Entry->SizeOfImage)))
143 {
144 /* Return this entry */
145 *LdrEntry = Entry;
146 PcBase = ImageBase;
147 break;
148 }
149 }
150 }
151
152 /* Return the base address */
153 return PcBase;
154}

Referenced by KeRosDumpStackFrameArray().

◆ KiSaveProcessorControlState()

VOID NTAPI KiSaveProcessorControlState ( OUT PKPROCESSOR_STATE  ProcessorState)

Definition at line 576 of file cpu.c.

577{
578 /* Save the CR registers */
579 ProcessorState->SpecialRegisters.Cr0 = __readcr0();
580 ProcessorState->SpecialRegisters.Cr2 = __readcr2();
581 ProcessorState->SpecialRegisters.Cr3 = __readcr3();
582 ProcessorState->SpecialRegisters.Cr4 = __readcr4();
583 ProcessorState->SpecialRegisters.Cr8 = __readcr8();
584
585 /* Save the DR registers */
586 ProcessorState->SpecialRegisters.KernelDr0 = __readdr(0);
587 ProcessorState->SpecialRegisters.KernelDr1 = __readdr(1);
588 ProcessorState->SpecialRegisters.KernelDr2 = __readdr(2);
589 ProcessorState->SpecialRegisters.KernelDr3 = __readdr(3);
590 ProcessorState->SpecialRegisters.KernelDr6 = __readdr(6);
591 ProcessorState->SpecialRegisters.KernelDr7 = __readdr(7);
592
593 /* Save GDT, IDT, LDT and TSS */
594 __sgdt(&ProcessorState->SpecialRegisters.Gdtr.Limit);
595 __sldt(&ProcessorState->SpecialRegisters.Ldtr);
596 __str(&ProcessorState->SpecialRegisters.Tr);
597 __sidt(&ProcessorState->SpecialRegisters.Idtr.Limit);
598
599 ProcessorState->SpecialRegisters.MxCsr = _mm_getcsr();
600// ProcessorState->SpecialRegisters.DebugControl =
601// ProcessorState->SpecialRegisters.LastBranchToRip =
602// ProcessorState->SpecialRegisters.LastBranchFromRip =
603// ProcessorState->SpecialRegisters.LastExceptionToRip =
604// ProcessorState->SpecialRegisters.LastExceptionFromRip =
605
606 /* Save MSRs */
607 ProcessorState->SpecialRegisters.MsrGsBase = __readmsr(X86_MSR_GSBASE);
608 ProcessorState->SpecialRegisters.MsrGsSwap = __readmsr(X86_MSR_KERNEL_GSBASE);
609 ProcessorState->SpecialRegisters.MsrStar = __readmsr(X86_MSR_STAR);
610 ProcessorState->SpecialRegisters.MsrLStar = __readmsr(X86_MSR_LSTAR);
611 ProcessorState->SpecialRegisters.MsrCStar = __readmsr(X86_MSR_CSTAR);
612 ProcessorState->SpecialRegisters.MsrSyscallMask = __readmsr(X86_MSR_SFMASK);
613}
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
__INTRIN_INLINE unsigned int __readdr(unsigned int reg)
Definition: intrin_x86.h:1902
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1825
__INTRIN_INLINE unsigned long __readcr0(void)
Definition: intrin_x86.h:1804
__INTRIN_INLINE unsigned long __readcr2(void)
Definition: intrin_x86.h:1811
__INTRIN_INLINE void __sidt(void *Destination)
Definition: intrin_x86.h:2023
#define X86_MSR_CSTAR
Definition: ke.h:75
#define X86_MSR_GSBASE
Definition: ke.h:70
#define X86_MSR_LSTAR
Definition: ke.h:74
#define X86_MSR_SFMASK
Definition: ke.h:76
#define X86_MSR_KERNEL_GSBASE
Definition: ke.h:71
#define X86_MSR_STAR
Definition: ke.h:73
unsigned int _mm_getcsr(void)
Definition: xmmintrin.h:535

Referenced by KdpCommandString(), KdpReport(), KdpSymbol(), KeBugCheckWithTf(), KeSaveStateForHibernate(), KiInitializeKernel(), KiSaveProcessorState(), and KiSystemStartupBootStack().

◆ KiSaveProcessorState()

VOID NTAPI KiSaveProcessorState ( IN PKTRAP_FRAME  TrapFrame,
IN PKEXCEPTION_FRAME  ExceptionFrame 
)

Definition at line 1158 of file cpu.c.

1160{
1161 PKPRCB Prcb = KeGetCurrentPrcb();
1162
1163 //
1164 // Save full context
1165 //
1169
1170 //
1171 // Save control registers
1172 //
1174}
VOID NTAPI KiSaveProcessorControlState(OUT PKPROCESSOR_STATE ProcessorState)
Definition: cpu.c:980
ULONG ContextFlags
Definition: nt_native.h:1426
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:649
CONTEXT ContextFrame
Definition: ketypes.h:601

Referenced by KiTrap02Handler().

◆ KiSelectNextThread()

PKTHREAD FASTCALL KiSelectNextThread ( IN PKPRCB  Prcb)

Definition at line 328 of file thrdschd.c.

329{
331
332 /* Select a ready thread */
333 Thread = KiSelectReadyThread(0, Prcb);
334 if (!Thread)
335 {
336 /* Didn't find any, get the current idle thread */
337 Thread = Prcb->IdleThread;
338
339 /* Enable idle scheduling */
340 InterlockedOrSetMember(&KiIdleSummary, Prcb->SetMember);
341 Prcb->IdleSchedule = TRUE;
342
343 /* FIXME: SMT support */
344 ASSERTMSG("SMP: Not yet implemented\n", FALSE);
345 }
346
347 /* Sanity checks and return the thread */
348 ASSERT(Thread != NULL);
349 ASSERT((Thread->BasePriority == 0) || (Thread->Priority != 0));
350 return Thread;
351}
#define InterlockedOrSetMember(Destination, SetMember)
Definition: thrdschd.c:19

Referenced by KeRevertToUserAffinityThread(), and KeSetSystemAffinityThread().

◆ KiServiceExit()

DECLSPEC_NORETURN VOID FASTCALL KiServiceExit ( IN PKTRAP_FRAME  TrapFrame,
IN NTSTATUS  Status 
)

Definition at line 150 of file traphdlr.c.

152{
153 ASSERT((TrapFrame->EFlags & EFLAGS_V86_MASK) == 0);
154 ASSERT(!KiIsFrameEdited(TrapFrame));
155
156 /* Copy the status into EAX */
157 TrapFrame->Eax = Status;
158
159 /* Common trap exit code */
160 KiCommonExit(TrapFrame, FALSE);
161
162 /* Restore previous mode */
163 KeGetCurrentThread()->PreviousMode = (CCHAR)TrapFrame->PreviousPreviousMode;
164
165 /* Check for user mode exit */
166 if (KiUserTrap(TrapFrame))
167 {
168 /* Check if we were single stepping */
169 if (TrapFrame->EFlags & EFLAGS_TF)
170 {
171 /* Must use the IRET handler */
172 KiSystemCallTrapReturn(TrapFrame);
173 }
174 else
175 {
176 /* We can use the sysexit handler */
177 KiFastCallExitHandler(TrapFrame);
179 }
180 }
181
182 /* Exit to kernel mode */
183 KiSystemCallReturn(TrapFrame);
184}
#define EFLAGS_V86_MASK
Definition: ketypes.h:193
#define EFLAGS_TF
Definition: ketypes.h:186
#define UNREACHABLE
FORCEINLINE BOOLEAN KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:364
DECLSPEC_NORETURN VOID FASTCALL KiSystemCallTrapReturn(IN PKTRAP_FRAME TrapFrame)
DECLSPEC_NORETURN VOID FASTCALL KiSystemCallReturn(IN PKTRAP_FRAME TrapFrame)
FORCEINLINE BOOLEAN KiIsFrameEdited(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:87
PFAST_SYSTEM_CALL_EXIT KiFastCallExitHandler
Definition: traphdlr.c:56
FORCEINLINE VOID KiCommonExit(IN PKTRAP_FRAME TrapFrame, BOOLEAN SkipPreviousMode)
Definition: traphdlr.c:96
char CCHAR
Definition: typedefs.h:51

Referenced by KiCallbackReturnHandler(), KiSystemServiceHandler(), KiUserModeCallout(), NtContinue(), and NtRaiseException().

◆ KiServiceExit2()

DECLSPEC_NORETURN VOID FASTCALL KiServiceExit2 ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 189 of file traphdlr.c.

190{
191 /* Common trap exit code */
192 KiCommonExit(TrapFrame, FALSE);
193
194 /* Restore previous mode */
195 KeGetCurrentThread()->PreviousMode = (CCHAR)TrapFrame->PreviousPreviousMode;
196
197 /* Check if this was a V8086 trap */
198 if (TrapFrame->EFlags & EFLAGS_V86_MASK) KiTrapReturnNoSegments(TrapFrame);
199
200 /* Check for user mode exit */
201 if (KiUserTrap(TrapFrame)) KiTrapReturn(TrapFrame);
202
203 /* Check for edited frame */
204 if (KiIsFrameEdited(TrapFrame)) KiEditedTrapReturn(TrapFrame);
205
206 /* Check if we have single stepping enabled */
207 if (TrapFrame->EFlags & EFLAGS_TF) KiTrapReturnNoSegments(TrapFrame);
208
209 /* Exit the trap to kernel mode */
211}
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturnNoSegmentsRet8(IN PKTRAP_FRAME TrapFrame)
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturn(IN PKTRAP_FRAME TrapFrame)
DECLSPEC_NORETURN VOID FASTCALL KiEditedTrapReturn(IN PKTRAP_FRAME TrapFrame)
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturnNoSegments(IN PKTRAP_FRAME TrapFrame)

◆ KiSetAffinityThread()

KAFFINITY FASTCALL KiSetAffinityThread ( IN PKTHREAD  Thread,
IN KAFFINITY  Affinity 
)

Definition at line 685 of file thrdschd.c.

687{
688 KAFFINITY OldAffinity;
689
690 /* Get the current affinity */
691 OldAffinity = Thread->UserAffinity;
692
693 /* Make sure that the affinity is valid */
694 if (((Affinity & Thread->ApcState.Process->Affinity) != (Affinity)) ||
695 (!Affinity))
696 {
697 /* Bugcheck the system */
698 KeBugCheck(INVALID_AFFINITY_SET);
699 }
700
701 /* Update the new affinity */
702 Thread->UserAffinity = Affinity;
703
704 /* Check if system affinity is disabled */
705 if (!Thread->SystemAffinityActive)
706 {
707#ifdef CONFIG_SMP
708 /* FIXME: TODO */
709 DPRINT1("Affinity support disabled!\n");
710#endif
711 }
712
713 /* Return the old affinity */
714 return OldAffinity;
715}
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1431

Referenced by KeSetAffinityProcess(), and KeSetAffinityThread().

◆ KiSetPriorityThread()

VOID FASTCALL KiSetPriorityThread ( IN PKTHREAD  Thread,
IN KPRIORITY  Priority 
)

Definition at line 511 of file thrdschd.c.

513{
514 PKPRCB Prcb;
516 BOOLEAN RequestInterrupt = FALSE;
517 KPRIORITY OldPriority;
518 PKTHREAD NewThread;
519 ASSERT((Priority >= 0) && (Priority <= HIGH_PRIORITY));
520
521 /* Check if priority changed */
522 if (Thread->Priority != Priority)
523 {
524 /* Loop priority setting in case we need to start over */
525 for (;;)
526 {
527 /* Choose action based on thread's state */
528 if (Thread->State == Ready)
529 {
530 /* Make sure we're not on the ready queue */
531 if (!Thread->ProcessReadyQueue)
532 {
533 /* Get the PRCB for the thread and lock it */
534 Processor = Thread->NextProcessor;
536 KiAcquirePrcbLock(Prcb);
537
538 /* Make sure the thread is still ready and on this CPU */
539 if ((Thread->State == Ready) &&
540 (Thread->NextProcessor == Prcb->Number))
541 {
542 /* Sanity check */
543 ASSERT((Prcb->ReadySummary &
544 PRIORITY_MASK(Thread->Priority)));
545
546 /* Remove it from the current queue */
547 if (RemoveEntryList(&Thread->WaitListEntry))
548 {
549 /* Update the ready summary */
551 Priority);
552 }
553
554 /* Update priority */
555 Thread->Priority = (SCHAR)Priority;
556
557 /* Re-insert it at its current priority */
559
560 /* Release the PRCB Lock */
561 KiReleasePrcbLock(Prcb);
562 }
563 else
564 {
565 /* Release the lock and loop again */
566 KiReleasePrcbLock(Prcb);
567 continue;
568 }
569 }
570 else
571 {
572 /* It's already on the ready queue, just update priority */
573 Thread->Priority = (SCHAR)Priority;
574 }
575 }
576 else if (Thread->State == Standby)
577 {
578 /* Get the PRCB for the thread and lock it */
579 Processor = Thread->NextProcessor;
581 KiAcquirePrcbLock(Prcb);
582
583 /* Check if we're still the next thread to run */
584 if (Thread == Prcb->NextThread)
585 {
586 /* Get the old priority and update ours */
587 OldPriority = Thread->Priority;
588 Thread->Priority = (SCHAR)Priority;
589
590 /* Check if there was a change */
591 if (Priority < OldPriority)
592 {
593 /* Find a new thread */
594 NewThread = KiSelectReadyThread(Priority + 1, Prcb);
595 if (NewThread)
596 {
597 /* Found a new one, set it on standby */
598 NewThread->State = Standby;
599 Prcb->NextThread = NewThread;
600
601 /* Dispatch our thread */
603 }
604 }
605
606 /* Release the PRCB lock */
607 KiReleasePrcbLock(Prcb);
608 }
609 else
610 {
611 /* Release the lock and try again */
612 KiReleasePrcbLock(Prcb);
613 continue;
614 }
615 }
616 else if (Thread->State == Running)
617 {
618 /* Get the PRCB for the thread and lock it */
619 Processor = Thread->NextProcessor;
621 KiAcquirePrcbLock(Prcb);
622
623 /* Check if we're still the current thread running */
624 if (Thread == Prcb->CurrentThread)
625 {
626 /* Get the old priority and update ours */
627 OldPriority = Thread->Priority;
628 Thread->Priority = (SCHAR)Priority;
629
630 /* Check if there was a change and there's no new thread */
631 if ((Priority < OldPriority) && !(Prcb->NextThread))
632 {
633 /* Find a new thread */
634 NewThread = KiSelectReadyThread(Priority + 1, Prcb);
635 if (NewThread)
636 {
637 /* Found a new one, set it on standby */
638 NewThread->State = Standby;
639 Prcb->NextThread = NewThread;
640
641 /* Request an interrupt */
642 RequestInterrupt = TRUE;
643 }
644 }
645
646 /* Release the lock and check if we need an interrupt */
647 KiReleasePrcbLock(Prcb);
648 if (RequestInterrupt)
649 {
650 /* Check if we're running on another CPU */
652 {
653 /* We are, send an IPI */
655 }
656 }
657 }
658 else
659 {
660 /* Thread changed, release lock and restart */
661 KiReleasePrcbLock(Prcb);
662 continue;
663 }
664 }
665 else if (Thread->State == DeferredReady)
666 {
667 /* FIXME: TODO */
668 DPRINT1("Deferred state not yet supported\n");
669 ASSERT(FALSE);
670 }
671 else
672 {
673 /* Any other state, just change priority */
674 Thread->Priority = (SCHAR)Priority;
675 }
676
677 /* If we got here, then thread state was consistent, so bail out */
678 break;
679 }
680 }
681}

Referenced by ExpBoostOwnerThread(), KeBoostPriorityThread(), KeSetBasePriorityThread(), KeSetPriorityAndQuantumProcess(), and KeSetPriorityThread().

◆ KiSetupStackAndInitializeKernel()

VOID NTAPI KiSetupStackAndInitializeKernel ( IN PKPROCESS  InitProcess,
IN PKTHREAD  InitThread,
IN PVOID  IdleStack,
IN PKPRCB  Prcb,
IN CCHAR  Number,
IN PLOADER_PARAMETER_BLOCK  LoaderBlock 
)

◆ KiStartUnexpectedRange()

VOID NTAPI KiStartUnexpectedRange ( VOID  )

Referenced by KiGetVectorDispatch().

◆ KiSuspendNop()

VOID NTAPI KiSuspendNop ( IN PKAPC  Apc,
IN PKNORMAL_ROUTINE NormalRoutine,
IN PVOID NormalContext,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2 
)

Definition at line 571 of file thrdobj.c.

576{
577 /* Does nothing */
579 UNREFERENCED_PARAMETER(NormalRoutine);
580 UNREFERENCED_PARAMETER(NormalContext);
583}

Referenced by KeInitThread().

◆ KiSuspendRundown()

VOID NTAPI KiSuspendRundown ( IN PKAPC  Apc)

Definition at line 563 of file thrdobj.c.

564{
565 /* Does nothing */
567}

Referenced by KeInitThread().

◆ KiSuspendThread()

VOID NTAPI KiSuspendThread ( IN PVOID  NormalContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 587 of file thrdobj.c.

590{
591 /* Non-alertable kernel-mode suspended wait */
592 KeWaitForSingleObject(&KeGetCurrentThread()->SuspendSemaphore,
593 Suspended,
595 FALSE,
596 NULL);
597}
@ Suspended
Definition: ketypes.h:420

Referenced by KeInitThread().

◆ KiSwapContext()

◆ KiSwapProcess()

VOID NTAPI KiSwapProcess ( struct _KPROCESS NewProcess,
struct _KPROCESS OldProcess 
)

◆ KiSwapThread()

LONG_PTR FASTCALL KiSwapThread ( IN PKTHREAD  Thread,
IN PKPRCB  Prcb 
)

Definition at line 355 of file thrdschd.c.

357{
359 KIRQL WaitIrql;
360 LONG_PTR WaitStatus;
361 PKTHREAD NextThread;
363
364 /* Acquire the PRCB lock */
365 KiAcquirePrcbLock(Prcb);
366
367 /* Get the next thread */
368 NextThread = Prcb->NextThread;
369 if (NextThread)
370 {
371 /* Already got a thread, set it up */
372 Prcb->NextThread = NULL;
373 Prcb->CurrentThread = NextThread;
374 NextThread->State = Running;
375 }
376 else
377 {
378 /* Try to find a ready thread */
379 NextThread = KiSelectReadyThread(0, Prcb);
380 if (NextThread)
381 {
382 /* Switch to it */
383 Prcb->CurrentThread = NextThread;
384 NextThread->State = Running;
385 }
386 else
387 {
388 /* Set the idle summary */
389 InterlockedOrSetMember(&KiIdleSummary, Prcb->SetMember);
390
391 /* Schedule the idle thread */
392 NextThread = Prcb->IdleThread;
393 Prcb->CurrentThread = NextThread;
394 NextThread->State = Running;
395 }
396 }
397
398 /* Sanity check and release the PRCB */
399 ASSERT(CurrentThread != Prcb->IdleThread);
400 KiReleasePrcbLock(Prcb);
401
402 /* Save the wait IRQL */
403 WaitIrql = CurrentThread->WaitIrql;
404
405 /* Swap contexts */
406 ApcState = KiSwapContext(WaitIrql, CurrentThread);
407
408 /* Get the wait status */
409 WaitStatus = CurrentThread->WaitStatus;
410
411 /* Check if we need to deliver APCs */
412 if (ApcState)
413 {
414 /* Lower to APC_LEVEL */
416
417 /* Deliver APCs */
419 ASSERT(WaitIrql == 0);
420 }
421
422 /* Lower IRQL back to what it was and return the wait status */
423 KeLowerIrql(WaitIrql);
424 return WaitStatus;
425}

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

◆ KiSystemFatalException()

DECLSPEC_NORETURN VOID FASTCALL KiSystemFatalException ( IN ULONG  ExceptionCode,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 418 of file except.c.

420{
421 /* Bugcheck the system */
422 KeBugCheckWithTf(UNEXPECTED_KERNEL_MODE_TRAP,
424 0,
425 0,
426 0,
427 TrapFrame);
428}
_Inout_ PIRP _In_ NTSTATUS ExceptionCode
Definition: cdprocs.h:1774
DECLSPEC_NORETURN VOID NTAPI KeBugCheckWithTf(ULONG BugCheckCode, ULONG_PTR BugCheckParameter1, ULONG_PTR BugCheckParameter2, ULONG_PTR BugCheckParameter3, ULONG_PTR BugCheckParameter4, PKTRAP_FRAME Tf)

Referenced by KiTrap02Handler(), KiTrap05Handler(), KiTrap09Handler(), KiTrap0AHandler(), KiTrap0BHandler(), KiTrap0CHandler(), KiTrap0DHandler(), KiTrap0FHandler(), and KiTrap11Handler().

◆ KiSystemStartup()

DECLSPEC_NORETURN VOID NTAPI KiSystemStartup ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 476 of file kiinit.c.

477{
478 CCHAR Cpu;
479 PKTHREAD InitialThread;
480 ULONG64 InitialStack;
481 PKIPCR Pcr;
482
483 /* Boot cycles timestamp */
485
486 /* HACK */
487 FrLdrDbgPrint = LoaderBlock->u.I386.CommonDataArea;
488 //FrLdrDbgPrint("Hello from KiSystemStartup!!!\n");
489
490 /* Get the current CPU number */
491 Cpu = KeNumberProcessors++; // FIXME
492
493 /* LoaderBlock initialization for Cpu 0 */
494 if (Cpu == 0)
495 {
496 /* Save the loader block */
497 KeLoaderBlock = LoaderBlock;
498
499 /* Prepare LoaderBlock, PCR, TSS with the P0 boot data */
500 KiInitializeP0BootStructures(LoaderBlock);
501 }
502
503 /* Get Pcr from loader block */
504 Pcr = CONTAINING_RECORD(LoaderBlock->Prcb, KIPCR, Prcb);
505
506 /* Set the PRCB for this Processor */
507 KiProcessorBlock[Cpu] = &Pcr->Prcb;
508
509 /* Align stack to 16 bytes */
510 LoaderBlock->KernelStack &= ~(16 - 1);
511
512 /* Save the initial thread and stack */
513 InitialStack = LoaderBlock->KernelStack; // Checkme
514 InitialThread = (PKTHREAD)LoaderBlock->Thread;
515
516 /* Set us as the current process */
517 InitialThread->ApcState.Process = (PVOID)LoaderBlock->Process;
518
519 /* Initialize the CPU features */
520 KiInitializeCpu(Pcr);
521
522 /* Initial setup for the boot CPU */
523 if (Cpu == 0)
524 {
525 /* Initialize the module list (ntos, hal, kdcom) */
526 KiInitModuleList(LoaderBlock);
527
528 /* Setup the IDT */
530
531 /* Initialize debugging system */
533
534 /* Check for break-in */
536 }
537
538 DPRINT1("Pcr = %p, Gdt = %p, Idt = %p, Tss = %p\n",
539 Pcr, Pcr->GdtBase, Pcr->IdtBase, Pcr->TssBase);
540
541 /* Acquire lock */
542 while (InterlockedBitTestAndSet64((PLONG64)&KiFreezeExecutionLock, 0))
543 {
544 /* Loop until lock is free */
545 while ((*(volatile KSPIN_LOCK*)&KiFreezeExecutionLock) & 1);
546 }
547
548 /* Initialize the Processor with HAL */
550
551 /* Set processor as active */
552 KeActiveProcessors |= 1ULL << Cpu;
553
554 /* Release lock */
556
557 /* Raise to HIGH_LEVEL */
559
560 /* Machine specific kernel initialization */
561 if (Cpu == 0) KiInitializeKernelMachineDependent(&Pcr->Prcb, LoaderBlock);
562
563 /* Switch to new kernel stack and start kernel bootstrapping */
564 KiSwitchToBootStack(InitialStack & ~3);
565}
ULONG(* FrLdrDbgPrint)(const char *Format,...)
Definition: kiinit.c:23
static VOID KiInitializeP0BootStructures(_Inout_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kiinit.c:308
KSPIN_LOCK KiFreezeExecutionLock
Definition: kiinit.c:26
void KiInitModuleList(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kiinit.c:445
VOID NTAPI KiInitializeKernelMachineDependent(IN PKPRCB Prcb, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kiinit.c:345
VOID NTAPI KiInitializeCpu(PKIPCR Pcr)
Definition: kiinit.c:160
ULONGLONG BootCycles
Definition: kiinit.c:37
__int64 * PLONG64
Definition: basetsd.h:183
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
VOID NTAPI HalInitializeProcessor(IN ULONG ProcessorNumber, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: processor.c:48
#define InterlockedAnd64
Definition: interlocked.h:87
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
BOOLEAN NTAPI KdInitSystem(_In_ ULONG BootPhase, _In_opt_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kdinit.c:142
BOOLEAN NTAPI KdPollBreakIn(VOID)
Definition: kdlock.c:75
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
#define DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
struct _KTHREAD * PKTHREAD
Definition: nt_native.h:28
DECLSPEC_NORETURN VOID KiSwitchToBootStack(IN ULONG_PTR InitialStack)
Definition: ke.h:868
VOID NTAPI KeInitExceptions(VOID)
Definition: except.c:59
KPRCB Prcb
Definition: ketypes.h:962
union _KGDTENTRY64 * GdtBase
Definition: ketypes.h:933
struct _KTSS64 * TssBase
Definition: ketypes.h:934
union _KIDTENTRY64 * IdtBase
Definition: ketypes.h:942
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)

Referenced by KeStartAllProcessors(), and LoadAndBootWindowsCommon().

◆ KiTestAlert()

BOOLEAN NTAPI KiTestAlert ( VOID  )

◆ KiTimerExpiration()

VOID NTAPI KiTimerExpiration ( IN PKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 79 of file dpc.c.

83{
84 ULARGE_INTEGER SystemTime, InterruptTime;
86 LONG Limit, Index, i;
87 ULONG Timers, ActiveTimers, DpcCalls;
88 PLIST_ENTRY ListHead, NextEntry;
91 PKDPC TimerDpc;
94 PKSPIN_LOCK_QUEUE LockQueue;
95 PKPRCB Prcb = KeGetCurrentPrcb();
96
97 /* Disable interrupts */
98 _disable();
99
100 /* Query system and interrupt time */
101 KeQuerySystemTime((PLARGE_INTEGER)&SystemTime);
102 InterruptTime.QuadPart = KeQueryInterruptTime();
104
105 /* Bring interrupts back */
106 _enable();
107
108 /* Get the index of the timer and normalize it */
110 if ((Limit - Index) >= TIMER_TABLE_SIZE)
111 {
112 /* Normalize it */
114 }
115
116 /* Setup index and actual limit */
117 Index--;
118 Limit &= (TIMER_TABLE_SIZE - 1);
119
120 /* Setup accounting data */
121 DpcCalls = 0;
122 Timers = 24;
123 ActiveTimers = 4;
124
125 /* Lock the Database and Raise IRQL */
127
128 /* Start expiration loop */
129 do
130 {
131 /* Get the current index */
132 Index = (Index + 1) & (TIMER_TABLE_SIZE - 1);
133
134 /* Get list pointers and loop the list */
135 ListHead = &KiTimerTableListHead[Index].Entry;
136 while (ListHead != ListHead->Flink)
137 {
138 /* Lock the timer and go to the next entry */
139 LockQueue = KiAcquireTimerLock(Index);
140 NextEntry = ListHead->Flink;
141
142 /* Get the current timer and check its due time */
143 Timers--;
144 Timer = CONTAINING_RECORD(NextEntry, KTIMER, TimerListEntry);
145 if ((NextEntry != ListHead) &&
146 (Timer->DueTime.QuadPart <= InterruptTime.QuadPart))
147 {
148 /* It's expired, remove it */
149 ActiveTimers--;
151
152 /* Make it non-inserted, unlock it, and signal it */
153 Timer->Header.Inserted = FALSE;
154 KiReleaseTimerLock(LockQueue);
155 Timer->Header.SignalState = 1;
156
157 /* Get the DPC and period */
158 TimerDpc = Timer->Dpc;
159 Period = Timer->Period;
160
161 /* Check if there's any waiters */
162 if (!IsListEmpty(&Timer->Header.WaitListHead))
163 {
164 /* Check the type of event */
165 if (Timer->Header.Type == TimerNotificationObject)
166 {
167 /* Unwait the thread */
169 }
170 else
171 {
172 /* Otherwise unwait the thread and signal the timer */
174 }
175 }
176
177 /* Check if we have a period */
178 if (Period)
179 {
180 /* Calculate the interval and insert the timer */
181 Interval.QuadPart = Int32x32To64(Period, -10000);
183 }
184
185 /* Check if we have a DPC */
186 if (TimerDpc)
187 {
188#ifdef CONFIG_SMP
189 /*
190 * If the DPC is targeted to another processor,
191 * then insert it into that processor's DPC queue
192 * instead of delivering it now.
193 * If the DPC is a threaded DPC, and the current CPU
194 * has threaded DPCs enabled (KiExecuteDpc is actively parsing DPCs),
195 * then also insert it into the DPC queue for threaded delivery,
196 * instead of doing it here.
197 */
198 if (((TimerDpc->Number >= MAXIMUM_PROCESSORS) &&
199 ((TimerDpc->Number - MAXIMUM_PROCESSORS) != Prcb->Number)) ||
200 ((TimerDpc->Type == ThreadedDpcObject) && (Prcb->ThreadDpcEnable)))
201 {
202 /* Queue it */
203 KeInsertQueueDpc(TimerDpc,
204 UlongToPtr(SystemTime.LowPart),
205 UlongToPtr(SystemTime.HighPart));
206 }
207 else
208#endif
209 {
210 /* Setup the DPC Entry */
211 DpcEntry[DpcCalls].Dpc = TimerDpc;
212 DpcEntry[DpcCalls].Routine = TimerDpc->DeferredRoutine;
213 DpcEntry[DpcCalls].Context = TimerDpc->DeferredContext;
214 DpcCalls++;
215 ASSERT(DpcCalls < MAX_TIMER_DPCS);
216 }
217 }
218
219 /* Check if we're done processing */
220 if (!(ActiveTimers) || !(Timers))
221 {
222 /* Release the dispatcher while doing DPCs */
224
225 /* Start looping all DPC Entries */
226 for (i = 0; DpcCalls; DpcCalls--, i++)
227 {
228#if DBG
229 /* Clear DPC Time */
230 Prcb->DebugDpcTime = 0;
231#endif
232
233 /* Call the DPC */
234 DpcEntry[i].Routine(DpcEntry[i].Dpc,
235 DpcEntry[i].Context,
236 UlongToPtr(SystemTime.LowPart),
237 UlongToPtr(SystemTime.HighPart));
238 }
239
240 /* Reset accounting */
241 Timers = 24;
242 ActiveTimers = 4;
243
244 /* Lock the dispatcher database */
246 }
247 }
248 else
249 {
250 /* Check if the timer list is empty */
251 if (NextEntry != ListHead)
252 {
253 /* Sanity check */
255 Timer->DueTime.QuadPart);
256
257 /* Update the time */
258 _disable();
260 Timer->DueTime.QuadPart;
261 _enable();
262 }
263
264 /* Release the lock */
265 KiReleaseTimerLock(LockQueue);
266
267 /* Check if we've scanned all the timers we could */
268 if (!Timers)
269 {
270 /* Release the dispatcher while doing DPCs */
272
273 /* Start looping all DPC Entries */
274 for (i = 0; DpcCalls; DpcCalls--, i++)
275 {
276#if DBG
277 /* Clear DPC Time */
278 Prcb->DebugDpcTime = 0;
279#endif
280
281 /* Call the DPC */
282 DpcEntry[i].Routine(DpcEntry[i].Dpc,
283 DpcEntry[i].Context,
284 UlongToPtr(SystemTime.LowPart),
285 UlongToPtr(SystemTime.HighPart));
286 }
287
288 /* Reset accounting */
289 Timers = 24;
290 ActiveTimers = 4;
291
292 /* Lock the dispatcher database */
294 }
295
296 /* Done looping */
297 break;
298 }
299 }
300 } while (Index != Limit);
301
302 /* Verify the timer table, on debug builds */
303 if (KeNumberProcessors == 1) KiCheckTimerTable(InterruptTime);
304
305 /* Check if we still have DPC entries */
306 if (DpcCalls)
307 {
308 /* Release the dispatcher while doing DPCs */
310
311 /* Start looping all DPC Entries */
312 for (i = 0; DpcCalls; DpcCalls--, i++)
313 {
314#if DBG
315 /* Clear DPC Time */
316 Prcb->DebugDpcTime = 0;
317#endif
318
319 /* Call the DPC */
320 DpcEntry[i].Routine(DpcEntry[i].Dpc,
321 DpcEntry[i].Context,
322 UlongToPtr(SystemTime.LowPart),
323 UlongToPtr(SystemTime.HighPart));
324 }
325
326 /* Lower IRQL if we need to */
328 }
329 else
330 {
331 /* Unlock the dispatcher */
333 }
334}
#define PtrToLong(p)
Definition: basetsd.h:84
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
VOID NTAPI KiCheckTimerTable(IN ULARGE_INTEGER CurrentTime)
Definition: dpc.c:33
#define UlongToPtr(u)
Definition: config.h:106
#define MAXIMUM_PROCESSORS
Definition: rwlock.h:5
FORCEINLINE VOID KxUnwaitThread(IN DISPATCHER_HEADER *Object, IN KPRIORITY Increment)
Definition: ke_x.h:1259
FORCEINLINE VOID KxUnwaitThreadForEvent(IN PKEVENT Event, IN KPRIORITY Increment)
Definition: ke_x.h:1304
static PLARGE_INTEGER Time
Definition: time.c:105
@ TimerNotificationObject
Definition: ketypes.h:414
@ ThreadedDpcObject
Definition: ketypes.h:430
#define Int32x32To64(a, b)
BOOLEAN FASTCALL KiInsertTreeTimer(IN PKTIMER Timer, IN LARGE_INTEGER Interval)
Definition: timerobj.c:26
#define MAX_TIMER_DPCS
Definition: ke.h:69
Definition: ke.h:72
PVOID Context
Definition: ke.h:75
PKDEFERRED_ROUTINE Routine
Definition: ke.h:74
PKDPC Dpc
Definition: ke.h:73
UCHAR Type
Definition: ketypes.h:700
PKDEFERRED_ROUTINE DeferredRoutine
Definition: ketypes.h:704
volatile USHORT Number
Definition: ketypes.h:702
PVOID DeferredContext
Definition: ketypes.h:705
ULONG DebugDpcTime
Definition: ketypes.h:572
UCHAR ThreadDpcEnable
Definition: ketypes.h:765
static LIST_ENTRY Timers
Definition: clock.c:40
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1313
_In_ LONG _In_ LONG Limit
Definition: kefuncs.h:304

Referenced by KiInitializeKernel(), KiInitSystem(), and KiRetireDpcList().

◆ KiTimerListExpire()

VOID FASTCALL KiTimerListExpire ( IN PLIST_ENTRY  ExpiredListHead,
IN KIRQL  OldIrql 
)

Definition at line 338 of file dpc.c.

340{
341 ULARGE_INTEGER SystemTime;
343 LONG i;
344 ULONG DpcCalls = 0;
346 PKDPC TimerDpc;
349 PKPRCB Prcb = KeGetCurrentPrcb();
350
351 /* Query system */
352 KeQuerySystemTime((PLARGE_INTEGER)&SystemTime);
353
354 /* Loop expired list */
355 while (ExpiredListHead->Flink != ExpiredListHead)
356 {
357 /* Get the current timer */
358 Timer = CONTAINING_RECORD(ExpiredListHead->Flink, KTIMER, TimerListEntry);
359
360 /* Remove it */
361 RemoveEntryList(&Timer->TimerListEntry);
362
363 /* Not inserted */
364 Timer->Header.Inserted = FALSE;
365
366 /* Signal it */
367 Timer->Header.SignalState = 1;
368
369 /* Get the DPC and period */
370 TimerDpc = Timer->Dpc;
371 Period = Timer->Period;
372
373 /* Check if there's any waiters */
374 if (!IsListEmpty(&Timer->Header.WaitListHead))
375 {
376 /* Check the type of event */
377 if (Timer->Header.Type == TimerNotificationObject)
378 {
379 /* Unwait the thread */
381 }
382 else
383 {
384 /* Otherwise unwait the thread and signal the timer */
386 }
387 }
388
389 /* Check if we have a period */
390 if (Period)
391 {
392 /* Calculate the interval and insert the timer */
393 Interval.QuadPart = Int32x32To64(Period, -10000);
395 }
396
397 /* Check if we have a DPC */
398 if (TimerDpc)
399 {
400#ifdef CONFIG_SMP
401 /*
402 * If the DPC is targeted to another processor,
403 * then insert it into that processor's DPC queue
404 * instead of delivering it now.
405 * If the DPC is a threaded DPC, and the current CPU
406 * has threaded DPCs enabled (KiExecuteDpc is actively parsing DPCs),
407 * then also insert it into the DPC queue for threaded delivery,
408 * instead of doing it here.
409 */
410 if (((TimerDpc->Number >= MAXIMUM_PROCESSORS) &&
411 ((TimerDpc->Number - MAXIMUM_PROCESSORS) != Prcb->Number)) ||
412 ((TimerDpc->Type == ThreadedDpcObject) && (Prcb->ThreadDpcEnable)))
413 {
414 /* Queue it */
415 KeInsertQueueDpc(TimerDpc,
416 UlongToPtr(SystemTime.LowPart),
417 UlongToPtr(SystemTime.HighPart));
418 }
419 else
420#endif
421 {
422 /* Setup the DPC Entry */
423 DpcEntry[DpcCalls].Dpc = TimerDpc;
424 DpcEntry[DpcCalls].Routine = TimerDpc->DeferredRoutine;
425 DpcEntry[DpcCalls].Context = TimerDpc->DeferredContext;
426 DpcCalls++;
427 ASSERT(DpcCalls < MAX_TIMER_DPCS);
428 }
429 }
430 }
431
432 /* Check if we still have DPC entries */
433 if (DpcCalls)
434 {
435 /* Release the dispatcher while doing DPCs */
437
438 /* Start looping all DPC Entries */
439 for (i = 0; DpcCalls; DpcCalls--, i++)
440 {
441#if DBG
442 /* Clear DPC Time */
443 Prcb->DebugDpcTime = 0;
444#endif
445
446 /* Call the DPC */
447 DpcEntry[i].Routine(DpcEntry[i].Dpc,
448 DpcEntry[i].Context,
449 UlongToPtr(SystemTime.LowPart),
450 UlongToPtr(SystemTime.HighPart));
451 }
452
453 /* Lower IRQL */
455 }
456 else
457 {
458 /* Unlock the dispatcher */
460 }
461}

Referenced by KeSetSystemTime().

◆ KiUnlinkThread()

VOID FASTCALL KiUnlinkThread ( IN PKTHREAD  Thread,
IN LONG_PTR  WaitStatus 
)

Definition at line 55 of file wait.c.

57{
58 PKWAIT_BLOCK WaitBlock;
60
61 /* Update wait status */
62 Thread->WaitStatus |= WaitStatus;
63
64 /* Remove the Wait Blocks from the list */
65 WaitBlock = Thread->WaitBlockList;
66 do
67 {
68 /* Remove it */
69 RemoveEntryList(&WaitBlock->WaitListEntry);
70
71 /* Go to the next one */
72 WaitBlock = WaitBlock->NextWaitBlock;
73 } while (WaitBlock != Thread->WaitBlockList);
74
75 /* Remove the thread from the wait list! */
76 if (Thread->WaitListEntry.Flink) RemoveEntryList(&Thread->WaitListEntry);
77
78 /* Check if there's a Thread Timer */
79 Timer = &Thread->Timer;
80 if (Timer->Header.Inserted) KxRemoveTreeTimer(Timer);
81
82 /* Increment the Queue's active threads */
83 if (Thread->Queue) Thread->Queue->CurrentCount++;
84}
FORCEINLINE VOID KxRemoveTreeTimer(IN PKTIMER Timer)
Definition: ke_x.h:1004

Referenced by KeSetEventBoostPriority(), and KiUnwaitThread().

◆ KiUnwaitThread()

VOID FASTCALL KiUnwaitThread ( IN PKTHREAD  Thread,
IN LONG_PTR  WaitStatus,
IN KPRIORITY  Increment 
)

Definition at line 89 of file wait.c.

92{
93 /* Unlink the thread */
94 KiUnlinkThread(Thread, WaitStatus);
95
96 /* Tell the scheduler do to the increment when it readies the thread */
97 ASSERT(Increment >= 0);
98 Thread->AdjustIncrement = (SCHAR)Increment;
99 Thread->AdjustReason = AdjustUnwait;
100
101 /* Reschedule the Thread */
103}
VOID FASTCALL KiUnlinkThread(IN PKTHREAD Thread, IN LONG_PTR WaitStatus)
Definition: wait.c:55

Referenced by KeAlertResumeThread(), KeAlertThread(), KiActivateWaiterQueue(), KiInsertQueueApc(), KiWaitTest(), KxUnwaitThread(), and KxUnwaitThreadForEvent().

◆ KiWaitTest()

Variable Documentation

◆ BootCycles

ULONGLONG BootCycles
extern

Definition at line 37 of file kiinit.c.

Referenced by Ki386PerfEnd(), and KiSystemStartup().

◆ BootCyclesEnd

ULONGLONG BootCyclesEnd

Definition at line 152 of file ke.h.

Referenced by Ki386PerfEnd().

◆ BugCheckCallbackLock

KSPIN_LOCK BugCheckCallbackLock
extern

Definition at line 24 of file bug.c.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ ExCmosClockIsSane

BOOLEAN ExCmosClockIsSane
extern

Definition at line 93 of file init.c.

Referenced by KeSetSystemTime(), and Phase1InitializationDiscard().

◆ KeActiveProcessors

◆ KeBootTime

LARGE_INTEGER KeBootTime
extern

◆ KeBootTimeBias

ULONGLONG KeBootTimeBias
extern

Definition at line 18 of file clock.c.

Referenced by KeSetSystemTime(), and Phase1InitializationDiscard().

◆ KeBugcheckCallbackListHead

LIST_ENTRY KeBugcheckCallbackListHead
extern

◆ KeBugcheckReasonCallbackListHead

LIST_ENTRY KeBugcheckReasonCallbackListHead

Definition at line 128 of file ke.h.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ KeFeatureBits

◆ KeGdiFlushUserBatch

PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch
extern

Definition at line 20 of file win32.c.

Referenced by KeUserModeCallback(), KiSystemCallHandler(), and KiSystemServiceHandler().

◆ KeNodeBlock

PKNODE KeNodeBlock[1]
extern

◆ KeNumberNodes

UCHAR KeNumberNodes
extern

Definition at line 40 of file krnlinit.c.

Referenced by InitializePool(), KeInitializeProcess(), and QSI_DEF().

◆ KeProcessNodeSeed

UCHAR KeProcessNodeSeed
extern

Definition at line 41 of file krnlinit.c.

Referenced by KeInitializeProcess().

◆ KeProcessorArchitecture

USHORT KeProcessorArchitecture
extern

Definition at line 19 of file krnlinit.c.

Referenced by KiInitializeKernel(), KiInitializeKernelMachineDependent(), and QSI_DEF().

◆ KeProcessorLevel

◆ KeProcessorRevision

USHORT KeProcessorRevision
extern

Definition at line 21 of file krnlinit.c.

Referenced by KiInitializeKernel(), KiInitializeKernelMachineDependent(), and QSI_DEF().

◆ KeRaiseUserExceptionDispatcher

PVOID KeRaiseUserExceptionDispatcher
extern

Definition at line 144 of file ke.h.

Referenced by KeRaiseUserException().

◆ KernelAddressSpaceLock

EX_PUSH_LOCK KernelAddressSpaceLock
extern

◆ KeThreadDpcEnable

BOOLEAN KeThreadDpcEnable
extern

Definition at line 23 of file dpc.c.

Referenced by KeInitSystem().

◆ KeTimeAdjustment

ULONG KeTimeAdjustment
extern

Definition at line 18 of file time.c.

Referenced by KeSetTimeIncrement(), KeUpdateSystemTime(), QSI_DEF(), and SSI_DEF().

◆ KeTimeIncrement

ULONG KeTimeIncrement
extern

Definition at line 22 of file clock.c.

Referenced by ExSetTimerResolution(), KeSetTimeIncrement(), and NtQueryTimerResolution().

◆ KeUserApcDispatcher

PVOID KeUserApcDispatcher
extern

Definition at line 141 of file ke.h.

Referenced by KiInitializeUserApc().

◆ KeUserCallbackDispatcher

PVOID KeUserCallbackDispatcher
extern

Definition at line 142 of file ke.h.

Referenced by KdUpdateDataBlock(), and KiUserModeCallout().

◆ KeUserExceptionDispatcher

PVOID KeUserExceptionDispatcher
extern

Definition at line 143 of file ke.h.

Referenced by KiDispatchException(), and KiDispatchExceptionToUser().

◆ KiAdjustDpcThreshold

ULONG KiAdjustDpcThreshold
extern

Definition at line 21 of file dpc.c.

Referenced by KeUpdateRunTime(), KiInitializeKernel(), KiInitSpinLocks(), and QSI_DEF().

◆ KiDoubleFaultStack

ULONG_PTR KiDoubleFaultStack
extern

Definition at line 22 of file kiinit.c.

Referenced by Ki386InitializeTss(), and KiSystemStartup().

◆ KiDPCTimeout

ULONG KiDPCTimeout
extern

Definition at line 27 of file dpc.c.

Referenced by KeUpdateRunTime().

◆ KiFreezeFlag

ULONG KiFreezeFlag
extern

Definition at line 20 of file freeze.c.

Referenced by KdEnterDebugger(), KeFreezeExecution(), and KeThawExecution().

◆ KiGenericCallDpcMutex

FAST_MUTEX KiGenericCallDpcMutex
extern

Definition at line 24 of file dpc.c.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ KiIdealDpcRate

ULONG KiIdealDpcRate
extern

Definition at line 22 of file dpc.c.

Referenced by KeUpdateRunTime(), and QSI_DEF().

◆ KiIdleSummary

◆ KiInitialProcess

EPROCESS KiInitialProcess
extern

◆ KiInitialThread

ETHREAD KiInitialThread
extern

Definition at line 44 of file krnlinit.c.

Referenced by KiInitializeP0BootStructures(), and KiSystemStartup().

◆ KiInterruptTemplate2ndDispatch

PULONG KiInterruptTemplate2ndDispatch
extern

◆ KiInterruptTemplateDispatch

PULONG KiInterruptTemplateDispatch
extern

◆ KiInterruptTemplateObject

PULONG KiInterruptTemplateObject
extern

Referenced by KeInitializeInterrupt().

◆ KiMaximumDpcQueueDepth

ULONG KiMaximumDpcQueueDepth
extern

Definition at line 19 of file dpc.c.

Referenced by KeUpdateRunTime(), KiInitializeKernel(), KiInitSpinLocks(), and QSI_DEF().

◆ KiMinimumDpcRate

ULONG KiMinimumDpcRate
extern

Definition at line 20 of file dpc.c.

Referenced by KiInitializeKernel(), KiInitSpinLocks(), and QSI_DEF().

◆ KiNmiCallbackListHead

PKNMI_HANDLER_CALLBACK KiNmiCallbackListHead
extern

Definition at line 33 of file bug.c.

Referenced by KeDeregisterNmiCallback(), KeRegisterNmiCallback(), and KiHandleNmi().

◆ KiNmiCallbackListLock

KSPIN_LOCK KiNmiCallbackListLock
extern

Definition at line 34 of file bug.c.

Referenced by KiAcquireNmiListLock(), and KiReleaseNmiListLock().

◆ KiNode0

KNODE KiNode0
extern

Definition at line 38 of file krnlinit.c.

◆ KiProcessInSwapListHead

LIST_ENTRY KiProcessInSwapListHead
extern

Definition at line 19 of file procobj.c.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ KiProcessListHead

LIST_ENTRY KiProcessListHead
extern

Definition at line 18 of file procobj.c.

Referenced by KiInitializeKernel().

◆ KiProcessorBlock

◆ KiProcessOutSwapListHead

LIST_ENTRY KiProcessOutSwapListHead

Definition at line 136 of file ke.h.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ KiProfileListHead

LIST_ENTRY KiProfileListHead
extern

◆ KiProfileLock

KSPIN_LOCK KiProfileLock
extern

Definition at line 20 of file profobj.c.

Referenced by KeStartProfile(), KeStopProfile(), KiInitializeKernel(), and KiInitSystem().

◆ KiProfileSourceListHead

LIST_ENTRY KiProfileSourceListHead

Definition at line 133 of file ke.h.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ KiServiceLimit

ULONG KiServiceLimit
extern

Definition at line 26 of file krnlinit.c.

Referenced by ExpInitializeExecutive(), KiInitializeKernel(), and KiInitSystem().

◆ KiStackInSwapListHead

LIST_ENTRY KiStackInSwapListHead
extern

Definition at line 20 of file procobj.c.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ KiSwapEvent

KEVENT KiSwapEvent
extern

Definition at line 21 of file procobj.c.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ KiTickOffset

LONG KiTickOffset
extern

Definition at line 17 of file time.c.

Referenced by KeSetTimeIncrement(), and KeUpdateSystemTime().

◆ KiTimeAdjustmentEnabled

BOOLEAN KiTimeAdjustmentEnabled
extern

Definition at line 19 of file time.c.

Referenced by QSI_DEF(), and SSI_DEF().

◆ KiTimeIncrementReciprocal

LARGE_INTEGER KiTimeIncrementReciprocal
extern

Definition at line 18 of file timerobj.c.

Referenced by KiInitializeKernel().

◆ KiTimeIncrementShiftCount

UCHAR KiTimeIncrementShiftCount
extern

Definition at line 19 of file timerobj.c.

Referenced by KiInitializeKernel().

◆ KiTimeLimitIsrMicroseconds

ULONG KiTimeLimitIsrMicroseconds
extern

Definition at line 26 of file dpc.c.

Referenced by KiInitMachineDependent().

◆ KiTimerExpireDpc

KDPC KiTimerExpireDpc
extern

Definition at line 25 of file dpc.c.

Referenced by KiCheckTimerTable(), KiInitializeKernel(), and KiInitSystem().

◆ KiTimerTableListHead

◆ KiUnexpectedEntrySize

ULONG KiUnexpectedEntrySize
extern

Referenced by KiGetVectorDispatch().

◆ ProcessCount