ReactOS 0.4.16-dev-106-g10b08aa
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)
 
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)
 
VOID NTAPI KxFreezeExecution (VOID)
 
VOID NTAPI KxThawExecution (VOID)
 
BOOLEAN NTAPI KeFreezeExecution (IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
 
VOID NTAPI KeThawExecution (IN BOOLEAN Enable)
 
KCONTINUE_STATUS NTAPI KxSwitchKdProcessor (_In_ ULONG ProcessorIndex)
 
 _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 NTAPI KiRestoreProcessorState (_Out_ PKTRAP_FRAME TrapFrame, _Out_ 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()

◆ 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 /* Architecture specific freeze code */
54#endif
55
56 /* Save the old IRQL to be restored on unfreeze */
58
59 /* Return whether interrupts were enabled */
60 return Enable;
61}
#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
VOID NTAPI KxFreezeExecution(VOID)
Definition: freeze.c:78

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:570
UCHAR Dpl
Definition: ke.h:96
UCHAR IstIndex
Definition: ke.h:97
ULONG OffsetHigh
Definition: ketypes.h:559
USHORT Reserved0
Definition: ketypes.h:554
USHORT IstIndex
Definition: ketypes.h:553
USHORT OffsetMiddle
Definition: ketypes.h:558
USHORT OffsetLow
Definition: ketypes.h:551
ULONG Reserved1
Definition: ketypes.h:560
USHORT Dpl
Definition: ketypes.h:556
USHORT Present
Definition: ketypes.h:557
USHORT Selector
Definition: ketypes.h:552
USHORT Type
Definition: ketypes.h:555
_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:33
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:66
#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:1161
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:465
#define NTAPI
Definition: typedefs.h:36

◆ KeInvalidateAllCaches()

BOOLEAN NTAPI KeInvalidateAllCaches ( VOID  )

Definition at line 698 of file cpu.c.

699{
700 /* Invalidate all caches */
701 __wbinvd();
702 return TRUE;
703}
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:1351
LARGE_INTEGER ReadTransferCount
Definition: pstypes.h:1350
LARGE_INTEGER ReadOperationCount
Definition: pstypes.h:1347
LARGE_INTEGER OtherTransferCount
Definition: pstypes.h:1352
LARGE_INTEGER WriteOperationCount
Definition: pstypes.h:1348
LARGE_INTEGER OtherOperationCount
Definition: pstypes.h:1349
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:268
#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:269

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:118

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:1159
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 65 of file freeze.c.

66{
67#ifdef CONFIG_SMP
68 /* Architecture specific thaw code */
70#endif
71
72 /* Clear the freeze flag */
73 KiFreezeFlag = 0;
74
75 /* Cleanup CPU caches */
77
78 /* Restore the old IRQL */
79#ifndef CONFIG_SMP
81#endif
83
84 /* Re-enable interrupts */
86}
FORCEINLINE VOID KeRestoreInterrupts(BOOLEAN WereEnabled)
Definition: ke.h:254
VOID NTAPI KeFlushCurrentTb(VOID)
Definition: cpu.c:526
VOID NTAPI KxThawExecution(VOID)
Definition: freeze.c:141

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:1161
@ Standby
Definition: ketypes.h:391
struct _KTHREAD * NextThread
Definition: ketypes.h:651
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:73
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:2695
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3058
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3059

Referenced by KiInitializeKernel().

◆ KiContinue()

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

Definition at line 42 of file except.c.

45{
49
50 /* Raise to APC_LEVEL, only if needed */
52
53 /* Set up SEH to validate the context */
55 {
56 /* Check the previous mode */
58 {
59 /* Validate from user-mode */
61 ExceptionFrame,
62 TrapFrame);
63 }
64 else
65 {
66 /* Convert the context into Exception/Trap Frames */
68 ExceptionFrame,
69 TrapFrame,
70 Context->ContextFlags,
72 }
73 }
75 {
76 /* Save the exception code */
78 }
80
81 /* Lower the IRQL if needed */
83
84 /* Return status */
85 return Status;
86}
#define KeGetPreviousMode()
Definition: ketypes.h:1115
VOID NTAPI KiContinuePreviousModeUser(_In_ PCONTEXT Context, _Out_ PKEXCEPTION_FRAME ExceptionFrame, _Out_ PKTRAP_FRAME TrapFrame)
Definition: except.c:20
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
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:127
#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
USHORT Number
Definition: ketypes.h:643
struct _KTHREAD * CurrentThread
Definition: ketypes.h:650
ULONG ReadySummary
Definition: ketypes.h:810
LIST_ENTRY DispatcherReadyListHead[32]
Definition: ketypes.h:815
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 1165 of file bug.c.

1166{
1168 PKNMI_HANDLER_CALLBACK NmiData;
1169
1170 /* Parse the list of callbacks */
1171 NmiData = KiNmiCallbackListHead;
1172 while (NmiData)
1173 {
1174 /* Save if this callback has handled it -- all it takes is one */
1175 Handled |= NmiData->Callback(NmiData->Context, Handled);
1176 NmiData = NmiData->Next;
1177 }
1178
1179 /* Has anyone handled this? */
1180 return Handled;
1181}
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 KiNmiInterruptHandler(), and 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
UINT64 TimerRequest
Definition: ketypes.h:775
PROCESSOR_POWER_STATE PowerState
Definition: ketypes.h:879
KDPC_DATA DpcData[2]
Definition: ketypes.h:760
SINGLE_LIST_ENTRY DeferredReadyListHead
Definition: ketypes.h:712
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