1 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_KE_H
2 #define __NTOSKRNL_INCLUDE_INTERNAL_KE_H
4 /* INCLUDES *****************************************************************/
8 /* INTERNAL KERNEL TYPES ****************************************************/
10 typedef struct _WOW64_PROCESS
13 } WOW64_PROCESS
, *PWOW64_PROCESS
;
15 typedef struct _KPROFILE_SOURCE_OBJECT
17 KPROFILE_SOURCE Source
;
19 } KPROFILE_SOURCE_OBJECT
, *PKPROFILE_SOURCE_OBJECT
;
21 typedef enum _CONNECT_TYPE
27 } CONNECT_TYPE
, *PCONNECT_TYPE
;
29 typedef struct _DISPATCH_INFO
32 PKINTERRUPT Interrupt
;
33 PKINTERRUPT_ROUTINE NoDispatch
;
34 PKINTERRUPT_ROUTINE InterruptDispatch
;
35 PKINTERRUPT_ROUTINE FloatingDispatch
;
36 PKINTERRUPT_ROUTINE ChainedDispatch
;
37 PKINTERRUPT_ROUTINE
*FlatDispatch
;
38 } DISPATCH_INFO
, *PDISPATCH_INFO
;
40 typedef struct _KI_SAMPLE_MAP
42 LARGE_INTEGER PerfStart
;
43 LARGE_INTEGER PerfEnd
;
45 LARGE_INTEGER PerfFreq
;
50 } KI_SAMPLE_MAP
, *PKI_SAMPLE_MAP
;
52 typedef struct _KTIMER_TABLE_ENTRY
56 } KTIMER_TABLE_ENTRY
, *PKTIMER_TABLE_ENTRY
;
58 #define MAX_TIMER_DPCS 16
60 typedef struct _DPC_QUEUE_ENTRY
63 PKDEFERRED_ROUTINE Routine
;
65 } DPC_QUEUE_ENTRY
, *PDPC_QUEUE_ENTRY
;
68 (NTAPI
*PKE_BUGCHECK_UNICODE_TO_ANSI
)(
69 IN PUNICODE_STRING Unicode
,
74 extern PVOID KeUserApcDispatcher
;
75 extern PVOID KeUserCallbackDispatcher
;
76 extern PVOID KeUserExceptionDispatcher
;
77 extern PVOID KeRaiseUserExceptionDispatcher
;
78 extern LARGE_INTEGER KeBootTime
;
79 extern ULONGLONG KeBootTimeBias
;
80 extern BOOLEAN ExCmosClockIsSane
;
81 extern ULONG KeProcessorArchitecture
;
82 extern ULONG KeProcessorLevel
;
83 extern ULONG KeProcessorRevision
;
84 extern ULONG KeFeatureBits
;
86 extern PKNODE KeNodeBlock
[1];
87 extern UCHAR KeNumberNodes
;
88 extern UCHAR KeProcessNodeSeed
;
89 extern ETHREAD KiInitialThread
;
90 extern EPROCESS KiInitialProcess
;
91 extern ULONG KiInterruptTemplate
[KINTERRUPT_DISPATCH_CODES
];
92 extern PULONG KiInterruptTemplateObject
;
93 extern PULONG KiInterruptTemplateDispatch
;
94 extern PULONG KiInterruptTemplate2ndDispatch
;
95 extern ULONG KiUnexpectedEntrySize
;
96 extern UCHAR P0BootStack
[];
97 extern UCHAR KiDoubleFaultStack
[];
98 extern EX_PUSH_LOCK KernelAddressSpaceLock
;
99 extern ULONG KiMaximumDpcQueueDepth
;
100 extern ULONG KiMinimumDpcRate
;
101 extern ULONG KiAdjustDpcThreshold
;
102 extern ULONG KiIdealDpcRate
;
103 extern BOOLEAN KeThreadDpcEnable
;
104 extern LARGE_INTEGER KiTimeIncrementReciprocal
;
105 extern UCHAR KiTimeIncrementShiftCount
;
106 extern ULONG KiTimeLimitIsrMicroseconds
;
107 extern ULONG KiServiceLimit
;
108 extern LIST_ENTRY KeBugcheckCallbackListHead
, KeBugcheckReasonCallbackListHead
;
109 extern KSPIN_LOCK BugCheckCallbackLock
;
110 extern KDPC KiTimerExpireDpc
;
111 extern KTIMER_TABLE_ENTRY KiTimerTableListHead
[TIMER_TABLE_SIZE
];
112 extern FAST_MUTEX KiGenericCallDpcMutex
;
113 extern LIST_ENTRY KiProfileListHead
, KiProfileSourceListHead
;
114 extern KSPIN_LOCK KiProfileLock
;
115 extern LIST_ENTRY KiProcessListHead
;
116 extern LIST_ENTRY KiProcessInSwapListHead
, KiProcessOutSwapListHead
;
117 extern LIST_ENTRY KiStackInSwapListHead
;
118 extern KEVENT KiSwapEvent
;
119 extern PKPRCB KiProcessorBlock
[];
120 extern ULONG KiMask32Array
[MAXIMUM_PRIORITY
];
121 extern ULONG KiIdleSummary
;
122 extern PVOID KeUserApcDispatcher
;
123 extern PVOID KeUserCallbackDispatcher
;
124 extern PVOID KeUserExceptionDispatcher
;
125 extern PVOID KeRaiseUserExceptionDispatcher
;
126 extern ULONG KeTimeIncrement
;
127 extern ULONG KeTimeAdjustment
;
128 extern ULONG_PTR KiBugCheckData
[5];
129 extern ULONG KiFreezeFlag
;
130 extern ULONG KiDPCTimeout
;
132 /* MACROS *************************************************************************/
134 #define AFFINITY_MASK(Id) KiMask32Array[Id]
135 #define PRIORITY_MASK(Id) KiMask32Array[Id]
137 /* The following macro initializes a dispatcher object's header */
138 #define KeInitializeDispatcherHeader(Header, t, s, State) \
140 (Header)->Type = t; \
141 (Header)->Absolute = 0; \
142 (Header)->Size = s; \
143 (Header)->Inserted = 0; \
144 (Header)->SignalState = State; \
145 InitializeListHead(&((Header)->WaitListHead)); \
148 /* Tells us if the Timer or Event is a Syncronization or Notification Object */
149 #define TIMER_OR_EVENT_TYPE 0x7L
151 /* One of the Reserved Wait Blocks, this one is for the Thread's Timer */
152 #define TIMER_WAIT_BLOCK 0x3L
154 #ifdef _M_ARM // FIXME: remove this once our headers are cleaned up
156 // A system call ID is formatted as such:
157 // .________________________________________________________________.
158 // | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
159 // |--------------|-------------------------------------------------|
160 // | TABLE NUMBER | TABLE OFFSET |
161 // \----------------------------------------------------------------/
164 // The table number is then used as an index into the service descriptor table.
165 #define TABLE_NUMBER_BITS 3
166 #define TABLE_OFFSET_BITS 12
169 // There are 2 tables (kernel and shadow, used by Win32K)
171 #define NUMBER_SERVICE_TABLES 2
172 #define NTOS_SERVICE_INDEX 0
173 #define WIN32K_SERVICE_INDEX 1
176 // NB. From assembly code, the table number must be computed as an offset into
177 // the service descriptor table.
179 // Each entry into the table is 16 bytes long on 32-bit architectures, and
180 // 32 bytes long on 64-bit architectures.
182 // Thus, Table Number 1 is offset 16 (0x10) on x86, and offset 32 (0x20) on
186 #define BITS_PER_ENTRY 5 // (1 << 5) = 32 bytes
188 #define BITS_PER_ENTRY 4 // (1 << 4) = 16 bytes
192 // We want the table number, but leave some extra bits to we can have the offset
193 // into the descriptor table.
195 #define SERVICE_TABLE_SHIFT (12 - BITS_PER_ENTRY)
198 // Now the table number (as an offset) is corrupted with part of the table offset
199 // This mask will remove the extra unwanted bits, and give us the offset into the
200 // descriptor table proper.
202 #define SERVICE_TABLE_MASK (((1 << TABLE_NUMBER_BITS) - 1) << BITS_PER_ENTRY)
205 // To get the table offset (ie: the service call number), just keep the 12 bits
207 #define SERVICE_NUMBER_MASK ((1 << TABLE_OFFSET_BITS) - 1)
210 // We'll often need to check if this is a graphics call. This is done by comparing
211 // the table number offset with the known Win32K table number offset.
212 // This is usually index 1, so table number offset 0x10 (x86) or 0x20 (x64)
214 #define SERVICE_TABLE_TEST (WIN32K_SERVICE_INDEX << BITS_PER_ENTRY)
218 /* INTERNAL KERNEL FUNCTIONS ************************************************/
224 OUT PULONG CpuInfoEax
,
225 OUT PULONG CpuInfoEbx
,
226 OUT PULONG CpuInfoEcx
,
227 OUT PULONG CpuInfoEdx
243 /* Finds a new thread to run */
259 KeSetDisableBoostThread(
260 IN OUT PKTHREAD Thread
,
266 KeBalanceSetManager(IN PVOID Context
);
270 KiReadyThread(IN PKTHREAD Thread
);
274 KeSuspendThread(PKTHREAD Thread
);
278 KeReadStateThread(IN PKTHREAD Thread
);
283 IN PKTHREAD CurrentThread
,
284 IN PKTHREAD NewThread
289 KiAdjustQuantumThread(IN PKTHREAD Thread
);
293 KiExitDispatcher(KIRQL OldIrql
);
297 KiDeferredReadyThread(IN PKTHREAD Thread
);
307 KiProcessDeferredReadyList(
315 IN KAFFINITY Affinity
334 IN PLIST_ENTRY ExpiredListHead
,
342 IN LARGE_INTEGER Interval
349 IN PKSPIN_LOCK_QUEUE LockQueue
352 /* gmutex.c ********************************************************************/
356 KiAcquireGuardedMutex(
357 IN OUT PKGUARDED_MUTEX GuardedMutex
363 IN PFAST_MUTEX FastMutex
366 /* gate.c **********************************************************************/
370 KeInitializeGate(PKGATE Gate
);
374 KeSignalGateBoostPriority(PKGATE Gate
);
380 KWAIT_REASON WaitReason
,
381 KPROCESSOR_MODE WaitMode
384 /* ipi.c ********************************************************************/
396 IN KAFFINITY TargetProcessors
,
397 IN PKIPI_WORKER WorkerFunction
,
398 IN PKIPI_BROADCAST_WORKER BroadcastFunction
,
399 IN ULONG_PTR Context
,
405 KiIpiSignalPacketDone(
406 IN PKIPI_CONTEXT PacketContext
411 KiIpiSignalPacketDoneAndStall(
412 IN PKIPI_CONTEXT PacketContext
,
413 IN
volatile PULONG ReverseStall
416 /* next file ***************************************************************/
420 KeFindNextRightSetAffinity(
427 DbgBreakPointNoBugCheck(VOID
);
432 struct _KPROFILE
* Profile
,
433 struct _KPROCESS
* Process
,
437 KPROFILE_SOURCE ProfileSource
,
444 struct _KPROFILE
* Profile
,
450 KeStopProfile(struct _KPROFILE
* Profile
);
454 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource
);
458 KeSetIntervalProfile(
459 KPROFILE_SOURCE ProfileSource
,
466 PKTRAP_FRAME TrapFrame
471 KeProfileInterruptWithSource(
472 IN PKTRAP_FRAME TrapFrame
,
473 IN KPROFILE_SOURCE Source
479 PKTRAP_FRAME TrapFrame
,
487 PVOID DeferredContext
,
488 PVOID SystemArgument1
,
489 PVOID SystemArgument2
495 IN PKPROCESS Process
,
496 IN OUT PKTHREAD Thread
,
497 IN PKSYSTEM_ROUTINE SystemRoutine
,
498 IN PKSTART_ROUTINE StartRoutine
,
499 IN PVOID StartContext
,
514 IN OUT PKTHREAD Thread
,
515 IN PVOID KernelStack
,
516 IN PKSYSTEM_ROUTINE SystemRoutine
,
517 IN PKSTART_ROUTINE StartRoutine
,
518 IN PVOID StartContext
,
526 KiInitializeContextThread(
528 PKSYSTEM_ROUTINE SystemRoutine
,
529 PKSTART_ROUTINE StartRoutine
,
537 IN OUT PKTHREAD Thread
544 IN KPROCESSOR_MODE AlertMode
568 KeRundownThread(VOID
);
572 KeReleaseThread(PKTHREAD Thread
);
584 IN PKNORMAL_ROUTINE
*NormalRoutine
,
585 IN PVOID
*NormalContext
,
586 IN PVOID
*SystemArgument1
,
587 IN PVOID
*SystemArgument2
593 IN PVOID NormalContext
,
594 IN PVOID SystemArgument1
,
595 IN PVOID SystemArgument2
600 KeQueryBasePriorityThread(IN PKTHREAD Thread
);
606 IN KPRIORITY Priority
613 IN NTSTATUS WaitStatus
618 KeDumpStackFrames(PULONG Frame
);
628 IN LONG_PTR WaitStatus
,
629 IN KPRIORITY Increment
635 struct _KPROCESS
*Process
,
638 PULONG DirectoryTableBase
,
645 IN PKPROCESS Process
,
651 KeSetPriorityAndQuantumProcess(
652 IN PKPROCESS Process
,
653 IN KPRIORITY Priority
,
654 IN UCHAR Quantum OPTIONAL
659 KeForceResumeThread(IN PKTHREAD Thread
);
675 KeDisableThreadApcQueueing(IN PKTHREAD Thread
);
686 KeContextToTrapFrame(
688 PKEXCEPTION_FRAME ExeptionFrame
,
689 PKTRAP_FRAME TrapFrame
,
691 KPROCESSOR_MODE PreviousMode
696 KiCheckForKernelApcDelivery(VOID
);
702 IN PLIST_ENTRY Entry
,
710 IN PVOID DeferredContext
,
711 IN PVOID SystemArgument1
,
712 IN PVOID SystemArgument2
717 KiComputeTimerTableIndex(
718 IN LONGLONG TimeValue
724 struct _KPROCESS
* Process
,
731 KeInitializeEventPair(PKEVENT_PAIR EventPair
);
736 IN PKEXCEPTION_FRAME Reserved
,
737 IN PKTRAP_FRAME TrapFrame
,
738 IN PKNORMAL_ROUTINE NormalRoutine
,
739 IN PVOID NormalContext
,
740 IN PVOID SystemArgument1
,
741 IN PVOID SystemArgument2
748 IN KPROCESSOR_MODE PreviousMode
754 struct _KTHREAD
*Thread
,
755 struct _KPROCESS
*Process
,
756 PKLOCK_QUEUE_HANDLE ApcLock
,
757 struct _KAPC_STATE
*SavedApcState
763 struct _KPROCESS
*NewProcess
,
764 struct _KPROCESS
*OldProcess
769 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode
);
773 KeRemoveQueueApc(PKAPC Apc
);
777 KiActivateWaiterQueue(IN PKQUEUE Queue
);
781 KeQueryRuntimeProcess(IN PKPROCESS Process
,
782 OUT PULONG UserTime
);
784 /* INITIALIZATION FUNCTIONS *************************************************/
792 KeInitExceptions(VOID
);
796 KeInitInterrupts(VOID
);
800 KiInitializeBugCheck(VOID
);
805 IN PLOADER_PARAMETER_BLOCK LoaderBlock
810 KiDeliverUserApc(PKTRAP_FRAME TrapFrame
);
815 PKAPC_STATE OldState
,
822 KPROFILE_SOURCE Source
,
829 PEXCEPTION_RECORD ExceptionRecord
,
830 PKEXCEPTION_FRAME ExceptionFrame
,
832 KPROCESSOR_MODE PreviousMode
,
838 KeTrapFrameToContext(
839 IN PKTRAP_FRAME TrapFrame
,
840 IN PKEXCEPTION_FRAME ExceptionFrame
,
841 IN OUT PCONTEXT Context
849 ULONG_PTR BugCheckParameter1
,
850 ULONG_PTR BugCheckParameter2
,
851 ULONG_PTR BugCheckParameter3
,
852 ULONG_PTR BugCheckParameter4
,
858 KeFlushCurrentTb(VOID
);
862 KeInvalidateAllCaches(VOID
);
866 KeZeroPages(IN PVOID Address
,
871 KeInvalidAccessAllowed(IN PVOID TrapInformation OPTIONAL
);
875 KeRosDumpStackFrames(
883 IN PLARGE_INTEGER NewSystemTime
,
884 OUT PLARGE_INTEGER OldSystemTime
,
885 IN BOOLEAN FixInterruptTime
,
886 IN PLARGE_INTEGER HalTime
899 KiStartUnexpectedRange(
905 KiEndUnexpectedRange(
923 KiInitializeMachineType(
929 KiSetupStackAndInitializeKernel(
930 IN PKPROCESS InitProcess
,
931 IN PKTHREAD InitThread
,
935 IN PLOADER_PARAMETER_BLOCK LoaderBlock
962 IN KPRIORITY PriorityBoost
968 IN PVOID
*OutputBuffer
,
969 IN PULONG OutputLength
974 KiGetUserModeStackAddress(
980 KiInitMachineDependent(VOID
);
984 KeFreezeExecution(IN PKTRAP_FRAME TrapFrame
,
985 IN PKEXCEPTION_FRAME ExceptionFrame
);
989 KeThawExecution(IN BOOLEAN Enable
);
999 KeAcquireQueuedSpinLockAtDpcLevel(
1000 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1005 KeReleaseQueuedSpinLockFromDpcLevel(
1006 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1011 KiRestoreProcessorControlState(
1012 IN PKPROCESSOR_STATE ProcessorState
1017 KiSaveProcessorControlState(
1018 OUT PKPROCESSOR_STATE ProcessorState
1036 IN PKTRAP_FRAME TrapFrame
,
1037 IN ULONG Instruction
1047 KiPcToFileHeader(IN PVOID Eip
,
1048 OUT PLDR_DATA_TABLE_ENTRY
*LdrEntry
,
1049 IN BOOLEAN DriversOnly
,
1050 OUT PBOOLEAN InKernel
);
1054 KiRosPcToUserFileHeader(IN PVOID Eip
,
1055 OUT PLDR_DATA_TABLE_ENTRY
*LdrEntry
);
1059 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */