ReactOS  0.4.11-dev-433-g473ca91
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 AFFINITY_MASK(Id)   KiMask32Array[Id]
 
#define PRIORITY_MASK(Id)   KiMask32Array[Id]
 
#define TIMER_OR_EVENT_TYPE   0x7L
 
#define TIMER_WAIT_BLOCK   0x3L
 

Typedefs

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

Enumerations

enum  _CONNECT_TYPE { NoConnect, NormalConnect, ChainConnect, UnknownConnect }
 

Functions

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

Variables

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

Macro Definition Documentation

#define MAX_TIMER_DPCS   16

Definition at line 64 of file ke.h.

Referenced by KiTimerExpiration(), and KiTimerListExpire().

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

Definition at line 159 of file ke.h.

#define TIMER_WAIT_BLOCK   0x3L

Typedef Documentation

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

Definition at line 82 of file ke.h.

Enumeration Type Documentation

Enumerator
NoConnect 
NormalConnect 
ChainConnect 
UnknownConnect 

Definition at line 20 of file ke.h.

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

Function Documentation

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

Definition at line 578 of file v86vdm.c.

Referenced by NtSetInformationProcess().

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

Definition at line 133 of file thrdobj.c.

Referenced by NtAlertResumeThread().

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

Definition at line 185 of file thrdobj.c.

Referenced by NtAlertThread().

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

Definition at line 137 of file balmgr.c.

Referenced by MmInitBsmThread().

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

Definition at line 229 of file thrdobj.c.

Referenced by NtSetInformationProcess().

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

Definition at line 552 of file bug.c.

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

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

Definition at line 92 of file stubs.c.

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

Definition at line 32 of file thrdobj.c.

Referenced by KeInitializeProcess(), and KeStartThread().

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

Definition at line 322 of file cpu.c.

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

323 {
324  /* Flush the TLB by resetting CR3 */
326 }
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1711
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1680
PLIST_ENTRY NTAPI KeFlushQueueApc ( IN PKTHREAD  Thread,
IN KPROCESSOR_MODE  PreviousMode 
)

Definition at line 793 of file apc.c.

Referenced by PspExitThread().

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

Definition at line 276 of file thrdobj.c.

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

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

Definition at line 315 of file thrdobj.c.

Referenced by DbgkpSuspendProcess().

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

Definition at line 26 of file freeze.c.

Referenced by KdEnterDebugger().

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

Definition at line 59 of file except.c.

Referenced by KiSystemStartup().

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

Referenced by NtCreateEventPair().

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

Referenced by NtStartProfile().

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

Definition at line 900 of file thrdobj.c.

Referenced by KiInitializeHandBuiltThread(), and KiInitializeKernel().

908 {
909  /* Initialize and start the thread on success */
911  KernelStack,
912  SystemRoutine,
913  StartRoutine,
914  StartContext,
915  Context,
916  Teb,
917  Process)))
918  {
919  /* Start it */
921  }
922 }
VOID NTAPI KeStartThread(IN OUT PKTHREAD Thread)
Definition: thrdobj.c:498
_In_ ULONG _In_opt_ POBJECT_ATTRIBUTES _In_opt_ HANDLE _Out_opt_ PCLIENT_ID _In_ PKSTART_ROUTINE StartRoutine
Definition: psfuncs.h:87
NTSTATUS NTAPI KeInitThread(IN OUT PKTHREAD Thread, IN PVOID KernelStack, IN PKSYSTEM_ROUTINE SystemRoutine, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext, IN PCONTEXT Context, IN PVOID Teb, IN PKPROCESS Process)
Definition: thrdobj.c:765
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
_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:219
VOID NTAPI KeInitInterrupts ( VOID  )

Definition at line 151 of file ppc_irq.c.

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

Definition at line 293 of file krnlinit.c.

Referenced by Phase1InitializationDiscard().

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

Definition at line 765 of file thrdobj.c.

Referenced by KeInitializeThread(), and PspCreateThread().

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

Definition at line 801 of file exp.c.

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

Definition at line 459 of file cpu.c.

Referenced by MiMapLockedPagesInUserSpace(), and MmMapIoSpace().

460 {
461  /* Invalidate all caches */
462  __wbinvd();
463  return TRUE;
464 }
#define TRUE
Definition: types.h:120
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
LONG NTAPI KeQueryBasePriorityThread ( IN PKTHREAD  Thread)

Definition at line 61 of file thrdobj.c.

Referenced by NtQueryInformationThread().

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

Referenced by NtQueryIntervalProfile().

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

Definition at line 857 of file procobj.c.

Referenced by NtQueryInformationProcess(), and QSI_DEF().

859 {
860  ULONG TotalUser, TotalKernel;
861  KLOCK_QUEUE_HANDLE ProcessLock;
862  PLIST_ENTRY NextEntry, ListHead;
864 
866 
867  /* Initialize user and kernel times */
868  TotalUser = Process->UserTime;
869  TotalKernel = Process->KernelTime;
870 
871  /* Lock the process */
872  KiAcquireProcessLock(Process, &ProcessLock);
873 
874  /* Loop all child threads and sum up their times */
875  ListHead = &Process->ThreadListHead;
876  NextEntry = ListHead->Flink;
877  while (ListHead != NextEntry)
878  {
879  /* Get the thread */
880  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
881 
882  /* Sum up times */
883  TotalKernel += Thread->KernelTime;
884  TotalUser += Thread->UserTime;
885 
886  /* Go to the next one */
887  NextEntry = NextEntry->Flink;
888  }
889 
890  /* Release lock */
891  KiReleaseProcessLock(&ProcessLock);
892 
893  /* Return the user time */
894  *UserTime = TotalUser;
895 
896  /* Return the kernel time */
897  return TotalKernel;
898 }
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_Out_ PULONG UserTime
Definition: kefuncs.h:784
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
ULONG KernelTime
Definition: ketypes.h:1877
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
FORCEINLINE VOID KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:652
FORCEINLINE VOID KiAcquireProcessLock(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
Definition: typedefs.h:117
ULONG UserTime
Definition: ketypes.h:1893
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2030
VOID NTAPI KeQueryValuesProcess ( IN PKPROCESS  Process,
PPROCESS_VALUES  Values 
)

Definition at line 522 of file procobj.c.

Referenced by NtQueryInformationJobObject(), and NtQueryInformationProcess().

524 {
525  PEPROCESS EProcess;
526  PLIST_ENTRY NextEntry;
527  ULONG TotalKernel, TotalUser;
528  KLOCK_QUEUE_HANDLE ProcessLock;
529 
532 
533  /* Lock the process */
534  KiAcquireProcessLock(Process, &ProcessLock);
535 
536  /* Initialize user and kernel times */
537  TotalKernel = Process->KernelTime;
538  TotalUser = Process->UserTime;
539 
540  /* Copy the IO_COUNTERS from the process */
541  EProcess = (PEPROCESS)Process;
548 
549  /* Loop all child threads and sum up their times */
550  for (NextEntry = Process->ThreadListHead.Flink;
551  NextEntry != &Process->ThreadListHead;
552  NextEntry = NextEntry->Flink)
553  {
555 
556  /* Get the thread */
557  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
558 
559  /* Sum up times */
560  TotalKernel += Thread->KernelTime;
561  TotalUser += Thread->UserTime;
562  }
563 
564  /* Release the process lock */
565  KiReleaseProcessLock(&ProcessLock);
566 
567  /* Compute total times */
568  Values->TotalKernelTime.QuadPart = TotalKernel * (LONGLONG)KeMaximumIncrement;
569  Values->TotalUserTime.QuadPart = TotalUser * (LONGLONG)KeMaximumIncrement;
570 }
LARGE_INTEGER WriteOperationCount
Definition: pstypes.h:1278
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
ULONG KeMaximumIncrement
Definition: clock.c:20
ULONGLONG OtherOperationCount
Definition: pstypes.h:85
LARGE_INTEGER ReadOperationCount
Definition: pstypes.h:1277
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
struct _EPROCESS * PEPROCESS
Definition: nt_native.h:30
ULONGLONG WriteOperationCount
Definition: pstypes.h:84
IO_COUNTERS IoInfo
Definition: ke.h:43
LARGE_INTEGER OtherTransferCount
Definition: pstypes.h:1282
ULONGLONG WriteTransferCount
Definition: pstypes.h:87
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
int64_t LONGLONG
Definition: typedefs.h:66
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
ULONG KernelTime
Definition: ketypes.h:1877
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
LARGE_INTEGER WriteTransferCount
Definition: pstypes.h:1281
FORCEINLINE VOID KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:652
ULONGLONG ReadTransferCount
Definition: pstypes.h:86
FORCEINLINE VOID KiAcquireProcessLock(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
Definition: typedefs.h:117
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
LARGE_INTEGER TotalKernelTime
Definition: ke.h:41
ULONG UserTime
Definition: ketypes.h:1893
LARGE_INTEGER OtherOperationCount
Definition: pstypes.h:1279
LARGE_INTEGER ReadTransferCount
Definition: pstypes.h:1280
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
LARGE_INTEGER TotalUserTime
Definition: ke.h:42
ULONGLONG OtherTransferCount
Definition: pstypes.h:88
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2030
LONGLONG QuadPart
Definition: typedefs.h:112
ULONGLONG ReadOperationCount
Definition: pstypes.h:83
BOOLEAN NTAPI KeReadStateThread ( IN PKTHREAD  Thread)

Definition at line 51 of file thrdobj.c.

Referenced by NtQueryInformationThread(), and PspExitThread().

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

Definition at line 115 of file thrdobj.c.

Referenced by PspCreateThread().

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

Definition at line 397 of file thrdobj.c.

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

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

Definition at line 439 of file thrdobj.c.

Referenced by PspExitThread().

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

Definition at line 265 of file procobj.c.

Referenced by NtSetInformationProcess().

267 {
268 
269  KLOCK_QUEUE_HANDLE ProcessLock;
270  PLIST_ENTRY NextEntry, ListHead;
271  KAFFINITY OldAffinity;
276 
277  /* Lock the process */
278  KiAcquireProcessLock(Process, &ProcessLock);
279 
280  /* Acquire the dispatcher lock */
282 
283  /* Capture old affinity and update it */
284  OldAffinity = Process->Affinity;
285  Process->Affinity = Affinity;
286 
287  /* Loop all child threads */
288  ListHead = &Process->ThreadListHead;
289  NextEntry = ListHead->Flink;
290  while (ListHead != NextEntry)
291  {
292  /* Get the thread */
293  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
294 
295  /* Set affinity on it */
296  KiSetAffinityThread(Thread, Affinity);
297  NextEntry = NextEntry->Flink;
298  }
299 
300  /* Release Dispatcher Database */
302 
303  /* Release the process lock */
304  KiReleaseProcessLockFromDpcLevel(&ProcessLock);
305  KiExitDispatcher(ProcessLock.OldIrql);
306 
307  /* Return previous affinity */
308  return OldAffinity;
309 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
KAFFINITY FASTCALL KiSetAffinityThread(IN PKTHREAD Thread, IN KAFFINITY Affinity)
Definition: thrdschd.c:685
FORCEINLINE VOID KiReleaseProcessLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:660
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
VOID FASTCALL KiExitDispatcher(KIRQL OldIrql)
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:170
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
FORCEINLINE VOID KiAcquireProcessLock(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
Definition: typedefs.h:117
KAFFINITY KeActiveProcessors
Definition: krnlinit.c:23
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
ULONG_PTR KAFFINITY
Definition: compat.h:75
FORCEINLINE VOID KiReleaseDispatcherLockFromDpcLevel(VOID)
Definition: ke_x.h:168
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2030
FORCEINLINE VOID KiAcquireDispatcherLockAtDpcLevel(VOID)
Definition: ke_x.h:160
BOOLEAN NTAPI KeSetAutoAlignmentProcess ( IN PKPROCESS  Process,
IN BOOLEAN  Enable 
)

Definition at line 313 of file procobj.c.

Referenced by NtSetInformationProcess().

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

Definition at line 331 of file procobj.c.

Referenced by NtSetInformationProcess().

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

Definition at line 95 of file thrdobj.c.

Referenced by NtSetInformationProcess(), and NtSetInformationThread().

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

Referenced by NtSetIntervalProfile().

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

Definition at line 349 of file procobj.c.

Referenced by NtSetInformationProcess(), and PsSetProcessPriorityByClass().

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

Referenced by PspExitThread().

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

Definition at line 229 of file procobj.c.

Referenced by PsChangeQuantumTable().

231 {
232  KLOCK_QUEUE_HANDLE ProcessLock;
233  PLIST_ENTRY NextEntry, ListHead;
237 
238  /* Lock the process */
239  KiAcquireProcessLock(Process, &ProcessLock);
240 
241  /* Set new quantum */
242  Process->QuantumReset = Quantum;
243 
244  /* Loop all child threads */
245  ListHead = &Process->ThreadListHead;
246  NextEntry = ListHead->Flink;
247  while (ListHead != NextEntry)
248  {
249  /* Get the thread */
250  Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
251 
252  /* Set quantum */
253  Thread->QuantumReset = Quantum;
254 
255  /* Go to the next one */
256  NextEntry = NextEntry->Flink;
257  }
258 
259  /* Release lock */
260  KiReleaseProcessLock(&ProcessLock);
261 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
FORCEINLINE VOID KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:652
FORCEINLINE VOID KiAcquireProcessLock(IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
Definition: ke_x.h:643
Definition: typedefs.h:117
UCHAR QuantumReset
Definition: ketypes.h:1872
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ASSERT_PROCESS(object)
Definition: ketypes.h:2030
VOID NTAPI KeSetSystemTime ( IN PLARGE_INTEGER  NewSystemTime,
OUT PLARGE_INTEGER  OldSystemTime,
IN BOOLEAN  FixInterruptTime,
IN PLARGE_INTEGER  HalTime 
)

Definition at line 28 of file clock.c.

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

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

Referenced by NtStartProfile().

VOID NTAPI KeStartThread ( IN OUT PKTHREAD  Thread)

Definition at line 498 of file thrdobj.c.

Referenced by KeInitializeThread(), and PspCreateThread().

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

Referenced by ExpDeleteProfile(), and NtStopProfile().

ULONG NTAPI KeSuspendThread ( PKTHREAD  Thread)

Definition at line 610 of file thrdobj.c.

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

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

Referenced by PsConvertToGuiThread().

BOOLEAN NTAPI KeTestAlertThread ( IN KPROCESSOR_MODE  AlertMode)

Definition at line 731 of file thrdobj.c.

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

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

Definition at line 669 of file thrdobj.c.

Referenced by DbgkpResumeProcess().

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

Definition at line 46 of file freeze.c.

Referenced by KdExitDebugger().

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

Definition at line 147 of file context.c.

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

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

Definition at line 926 of file thrdobj.c.

Referenced by PspCreateThread().

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

Definition at line 82 of file stubs.c.

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

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

Definition at line 107 of file wait.c.

Referenced by _ExAcquireFastMutex(), and _ExAcquireFastMutexUnsafe().

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

Definition at line 122 of file wait.c.

Referenced by _KeAcquireGuardedMutex(), and _KeAcquireGuardedMutexUnsafe().

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

Definition at line 24 of file queue.c.

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

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

Definition at line 461 of file thrdschd.c.

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

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

Referenced by NtCallbackReturn().

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

Definition at line 439 of file stubs.c.

Referenced by KeUserModeCallback().

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

Definition at line 231 of file irqobj.c.

Referenced by KiGetVectorDispatch().

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

Definition at line 36 of file apc.c.

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

Definition at line 167 of file timerobj.c.

Referenced by KxInsertTimer().

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

Definition at line 123 of file krnlinit.c.

Referenced by KiInitializeKernel().

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

Definition at line 41 of file except.c.

Referenced by NtContinue().

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

Definition at line 79 of file thrdschd.c.

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

80 {
81  PKPRCB Prcb;
82  BOOLEAN Preempted;
83  ULONG Processor = 0;
84  KPRIORITY OldPriority;
85  PKTHREAD NextThread;
86 
87  /* Sanity checks */
88  ASSERT(Thread->State == DeferredReady);
89  ASSERT((Thread->Priority >= 0) && (Thread->Priority <= HIGH_PRIORITY));
90 
91  /* Check if we have any adjusts to do */
92  if (Thread->AdjustReason == AdjustBoost)
93  {
94  /* Lock the thread */
96 
97  /* Check if the priority is low enough to qualify for boosting */
98  if ((Thread->Priority <= Thread->AdjustIncrement) &&
99  (Thread->Priority < (LOW_REALTIME_PRIORITY - 3)) &&
100  !(Thread->DisableBoost))
101  {
102  /* Calculate the new priority based on the adjust increment */
103  OldPriority = min(Thread->AdjustIncrement + 1,
105 
106  /* Make sure we're not decreasing outside of the priority range */
107  ASSERT((Thread->PriorityDecrement >= 0) &&
108  (