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
;
67 typedef struct _KNMI_HANDLER_CALLBACK
69 struct _KNMI_HANDLER_CALLBACK
* Next
;
70 PNMI_CALLBACK Callback
;
73 } KNMI_HANDLER_CALLBACK
, *PKNMI_HANDLER_CALLBACK
;
76 (NTAPI
*PKE_BUGCHECK_UNICODE_TO_ANSI
)(
77 IN PUNICODE_STRING Unicode
,
82 extern PKNMI_HANDLER_CALLBACK KiNmiCallbackListHead
;
83 extern KSPIN_LOCK KiNmiCallbackListLock
;
84 extern PVOID KeUserApcDispatcher
;
85 extern PVOID KeUserCallbackDispatcher
;
86 extern PVOID KeUserExceptionDispatcher
;
87 extern PVOID KeRaiseUserExceptionDispatcher
;
88 extern LARGE_INTEGER KeBootTime
;
89 extern ULONGLONG KeBootTimeBias
;
90 extern BOOLEAN ExCmosClockIsSane
;
91 extern ULONG KeProcessorArchitecture
;
92 extern ULONG KeProcessorLevel
;
93 extern ULONG KeProcessorRevision
;
94 extern ULONG KeFeatureBits
;
96 extern PKNODE KeNodeBlock
[1];
97 extern UCHAR KeNumberNodes
;
98 extern UCHAR KeProcessNodeSeed
;
99 extern ETHREAD KiInitialThread
;
100 extern EPROCESS KiInitialProcess
;
101 extern PULONG KiInterruptTemplateObject
;
102 extern PULONG KiInterruptTemplateDispatch
;
103 extern PULONG KiInterruptTemplate2ndDispatch
;
104 extern ULONG KiUnexpectedEntrySize
;
105 extern ULONG_PTR KiDoubleFaultStack
;
106 extern EX_PUSH_LOCK KernelAddressSpaceLock
;
107 extern ULONG KiMaximumDpcQueueDepth
;
108 extern ULONG KiMinimumDpcRate
;
109 extern ULONG KiAdjustDpcThreshold
;
110 extern ULONG KiIdealDpcRate
;
111 extern BOOLEAN KeThreadDpcEnable
;
112 extern LARGE_INTEGER KiTimeIncrementReciprocal
;
113 extern UCHAR KiTimeIncrementShiftCount
;
114 extern ULONG KiTimeLimitIsrMicroseconds
;
115 extern ULONG KiServiceLimit
;
116 extern LIST_ENTRY KeBugcheckCallbackListHead
, KeBugcheckReasonCallbackListHead
;
117 extern KSPIN_LOCK BugCheckCallbackLock
;
118 extern KDPC KiTimerExpireDpc
;
119 extern KTIMER_TABLE_ENTRY KiTimerTableListHead
[TIMER_TABLE_SIZE
];
120 extern FAST_MUTEX KiGenericCallDpcMutex
;
121 extern LIST_ENTRY KiProfileListHead
, KiProfileSourceListHead
;
122 extern KSPIN_LOCK KiProfileLock
;
123 extern LIST_ENTRY KiProcessListHead
;
124 extern LIST_ENTRY KiProcessInSwapListHead
, KiProcessOutSwapListHead
;
125 extern LIST_ENTRY KiStackInSwapListHead
;
126 extern KEVENT KiSwapEvent
;
127 extern PKPRCB KiProcessorBlock
[];
128 extern ULONG KiMask32Array
[MAXIMUM_PRIORITY
];
129 extern ULONG KiIdleSummary
;
130 extern PVOID KeUserApcDispatcher
;
131 extern PVOID KeUserCallbackDispatcher
;
132 extern PVOID KeUserExceptionDispatcher
;
133 extern PVOID KeRaiseUserExceptionDispatcher
;
134 extern ULONG KeTimeIncrement
;
135 extern ULONG KeTimeAdjustment
;
136 extern LONG KiTickOffset
;
137 extern ULONG_PTR KiBugCheckData
[5];
138 extern ULONG KiFreezeFlag
;
139 extern ULONG KiDPCTimeout
;
140 extern PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch
;
141 extern ULONGLONG BootCycles
, BootCyclesEnd
;
142 extern ULONG ProcessCount
;
143 extern VOID __cdecl
KiInterruptTemplate(VOID
);
145 /* MACROS *************************************************************************/
147 #define AFFINITY_MASK(Id) KiMask32Array[Id]
148 #define PRIORITY_MASK(Id) KiMask32Array[Id]
150 /* The following macro initializes a dispatcher object's header */
151 #define KeInitializeDispatcherHeader(Header, t, s, State) \
153 (Header)->Type = t; \
154 (Header)->Absolute = 0; \
155 (Header)->Size = s; \
156 (Header)->Inserted = 0; \
157 (Header)->SignalState = State; \
158 InitializeListHead(&((Header)->WaitListHead)); \
161 /* Tells us if the Timer or Event is a Syncronization or Notification Object */
162 #define TIMER_OR_EVENT_TYPE 0x7L
164 /* One of the Reserved Wait Blocks, this one is for the Thread's Timer */
165 #define TIMER_WAIT_BLOCK 0x3L
167 #ifdef _M_ARM // FIXME: remove this once our headers are cleaned up
169 // A system call ID is formatted as such:
170 // .________________________________________________________________.
171 // | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
172 // |--------------|-------------------------------------------------|
173 // | TABLE NUMBER | TABLE OFFSET |
174 // \----------------------------------------------------------------/
177 // The table number is then used as an index into the service descriptor table.
178 #define TABLE_NUMBER_BITS 3
179 #define TABLE_OFFSET_BITS 12
182 // There are 2 tables (kernel and shadow, used by Win32K)
184 #define NUMBER_SERVICE_TABLES 2
185 #define NTOS_SERVICE_INDEX 0
186 #define WIN32K_SERVICE_INDEX 1
189 // NB. From assembly code, the table number must be computed as an offset into
190 // the service descriptor table.
192 // Each entry into the table is 16 bytes long on 32-bit architectures, and
193 // 32 bytes long on 64-bit architectures.
195 // Thus, Table Number 1 is offset 16 (0x10) on x86, and offset 32 (0x20) on
199 #define BITS_PER_ENTRY 5 // (1 << 5) = 32 bytes
201 #define BITS_PER_ENTRY 4 // (1 << 4) = 16 bytes
205 // We want the table number, but leave some extra bits to we can have the offset
206 // into the descriptor table.
208 #define SERVICE_TABLE_SHIFT (12 - BITS_PER_ENTRY)
211 // Now the table number (as an offset) is corrupted with part of the table offset
212 // This mask will remove the extra unwanted bits, and give us the offset into the
213 // descriptor table proper.
215 #define SERVICE_TABLE_MASK (((1 << TABLE_NUMBER_BITS) - 1) << BITS_PER_ENTRY)
218 // To get the table offset (ie: the service call number), just keep the 12 bits
220 #define SERVICE_NUMBER_MASK ((1 << TABLE_OFFSET_BITS) - 1)
223 // We'll often need to check if this is a graphics call. This is done by comparing
224 // the table number offset with the known Win32K table number offset.
225 // This is usually index 1, so table number offset 0x10 (x86) or 0x20 (x64)
227 #define SERVICE_TABLE_TEST (WIN32K_SERVICE_INDEX << BITS_PER_ENTRY)
231 #define KTS_SYSCALL_BIT (((KTRAP_STATE_BITS) { { .SystemCall = TRUE } }).Bits)
232 #define KTS_PM_BIT (((KTRAP_STATE_BITS) { { .PreviousMode = TRUE } }).Bits)
233 #define KTS_SEG_BIT (((KTRAP_STATE_BITS) { { .Segments = TRUE } }).Bits)
234 #define KTS_VOL_BIT (((KTRAP_STATE_BITS) { { .Volatiles = TRUE } }).Bits)
235 #define KTS_FULL_BIT (((KTRAP_STATE_BITS) { { .Full = TRUE } }).Bits)
237 /* INTERNAL KERNEL FUNCTIONS ************************************************/
243 OUT PULONG CpuInfoEax
,
244 OUT PULONG CpuInfoEbx
,
245 OUT PULONG CpuInfoEcx
,
246 OUT PULONG CpuInfoEdx
262 /* Finds a new thread to run */
278 KeSetDisableBoostThread(
279 IN OUT PKTHREAD Thread
,
285 KeBalanceSetManager(IN PVOID Context
);
289 KiReadyThread(IN PKTHREAD Thread
);
293 KeSuspendThread(PKTHREAD Thread
);
297 KeReadStateThread(IN PKTHREAD Thread
);
302 IN PKTHREAD CurrentThread
,
303 IN PKTHREAD NewThread
308 KiAdjustQuantumThread(IN PKTHREAD Thread
);
312 KiExitDispatcher(KIRQL OldIrql
);
316 KiDeferredReadyThread(IN PKTHREAD Thread
);
326 KiProcessDeferredReadyList(
334 IN KAFFINITY Affinity
353 IN PLIST_ENTRY ExpiredListHead
,
361 IN LARGE_INTEGER Interval
368 IN PKSPIN_LOCK_QUEUE LockQueue
371 /* gmutex.c ********************************************************************/
375 KiAcquireGuardedMutex(
376 IN OUT PKGUARDED_MUTEX GuardedMutex
382 IN PFAST_MUTEX FastMutex
385 /* gate.c **********************************************************************/
389 KeInitializeGate(PKGATE Gate
);
393 KeSignalGateBoostPriority(PKGATE Gate
);
399 KWAIT_REASON WaitReason
,
400 KPROCESSOR_MODE WaitMode
403 /* ipi.c ********************************************************************/
415 IN KAFFINITY TargetProcessors
,
416 IN PKIPI_WORKER WorkerFunction
,
417 IN PKIPI_BROADCAST_WORKER BroadcastFunction
,
418 IN ULONG_PTR Context
,
424 KiIpiSignalPacketDone(
425 IN PKIPI_CONTEXT PacketContext
430 KiIpiSignalPacketDoneAndStall(
431 IN PKIPI_CONTEXT PacketContext
,
432 IN
volatile PULONG ReverseStall
435 /* next file ***************************************************************/
439 KeFindNextRightSetAffinity(
446 DbgBreakPointNoBugCheck(VOID
);
451 struct _KPROFILE
* Profile
,
452 struct _KPROCESS
* Process
,
456 KPROFILE_SOURCE ProfileSource
,
463 struct _KPROFILE
* Profile
,
469 KeStopProfile(struct _KPROFILE
* Profile
);
473 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource
);
477 KeSetIntervalProfile(
478 KPROFILE_SOURCE ProfileSource
,
485 PKTRAP_FRAME TrapFrame
490 KeProfileInterruptWithSource(
491 IN PKTRAP_FRAME TrapFrame
,
492 IN KPROFILE_SOURCE Source
498 PKTRAP_FRAME TrapFrame
,
506 PVOID DeferredContext
,
507 PVOID SystemArgument1
,
508 PVOID SystemArgument2
514 IN PKPROCESS Process
,
515 IN OUT PKTHREAD Thread
,
516 IN PKSYSTEM_ROUTINE SystemRoutine
,
517 IN PKSTART_ROUTINE StartRoutine
,
518 IN PVOID StartContext
,
533 IN OUT PKTHREAD Thread
,
534 IN PVOID KernelStack
,
535 IN PKSYSTEM_ROUTINE SystemRoutine
,
536 IN PKSTART_ROUTINE StartRoutine
,
537 IN PVOID StartContext
,
545 KiInitializeContextThread(
547 PKSYSTEM_ROUTINE SystemRoutine
,
548 PKSTART_ROUTINE StartRoutine
,
556 IN OUT PKTHREAD Thread
563 IN KPROCESSOR_MODE AlertMode
587 KeRundownThread(VOID
);
591 KeReleaseThread(PKTHREAD Thread
);
603 IN PKNORMAL_ROUTINE
*NormalRoutine
,
604 IN PVOID
*NormalContext
,
605 IN PVOID
*SystemArgument1
,
606 IN PVOID
*SystemArgument2
612 IN PVOID NormalContext
,
613 IN PVOID SystemArgument1
,
614 IN PVOID SystemArgument2
619 KeQueryBasePriorityThread(IN PKTHREAD Thread
);
625 IN KPRIORITY Priority
632 IN NTSTATUS WaitStatus
637 KeDumpStackFrames(PULONG Frame
);
647 IN LONG_PTR WaitStatus
,
648 IN KPRIORITY Increment
654 struct _KPROCESS
*Process
,
657 PULONG DirectoryTableBase
,
664 IN PKPROCESS Process
,
670 KeSetPriorityAndQuantumProcess(
671 IN PKPROCESS Process
,
672 IN KPRIORITY Priority
,
673 IN UCHAR Quantum OPTIONAL
678 KeForceResumeThread(IN PKTHREAD Thread
);
694 KeDisableThreadApcQueueing(IN PKTHREAD Thread
);
705 KeContextToTrapFrame(
707 PKEXCEPTION_FRAME ExeptionFrame
,
708 PKTRAP_FRAME TrapFrame
,
710 KPROCESSOR_MODE PreviousMode
715 KiCheckForKernelApcDelivery(VOID
);
721 IN PLIST_ENTRY Entry
,
729 IN PVOID DeferredContext
,
730 IN PVOID SystemArgument1
,
731 IN PVOID SystemArgument2
737 struct _KPROCESS
* Process
,
744 KeInitializeEventPair(PKEVENT_PAIR EventPair
);
749 IN PKEXCEPTION_FRAME Reserved
,
750 IN PKTRAP_FRAME TrapFrame
,
751 IN PKNORMAL_ROUTINE NormalRoutine
,
752 IN PVOID NormalContext
,
753 IN PVOID SystemArgument1
,
754 IN PVOID SystemArgument2
761 IN KPROCESSOR_MODE PreviousMode
767 struct _KTHREAD
*Thread
,
768 struct _KPROCESS
*Process
,
769 PKLOCK_QUEUE_HANDLE ApcLock
,
770 struct _KAPC_STATE
*SavedApcState
776 struct _KPROCESS
*NewProcess
,
777 struct _KPROCESS
*OldProcess
782 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode
);
786 KeRemoveQueueApc(PKAPC Apc
);
790 KiActivateWaiterQueue(IN PKQUEUE Queue
);
794 KeQueryRuntimeProcess(IN PKPROCESS Process
,
795 OUT PULONG UserTime
);
797 /* INITIALIZATION FUNCTIONS *************************************************/
805 KeInitExceptions(VOID
);
809 KeInitInterrupts(VOID
);
813 KiInitializeBugCheck(VOID
);
818 IN PLOADER_PARAMETER_BLOCK LoaderBlock
823 KiDeliverUserApc(PKTRAP_FRAME TrapFrame
);
828 PKAPC_STATE OldState
,
835 KPROFILE_SOURCE Source
,
842 PEXCEPTION_RECORD ExceptionRecord
,
843 PKEXCEPTION_FRAME ExceptionFrame
,
845 KPROCESSOR_MODE PreviousMode
,
851 KeTrapFrameToContext(
852 IN PKTRAP_FRAME TrapFrame
,
853 IN PKEXCEPTION_FRAME ExceptionFrame
,
854 IN OUT PCONTEXT Context
862 ULONG_PTR BugCheckParameter1
,
863 ULONG_PTR BugCheckParameter2
,
864 ULONG_PTR BugCheckParameter3
,
865 ULONG_PTR BugCheckParameter4
,
875 KeFlushCurrentTb(VOID
);
879 KeInvalidateAllCaches(VOID
);
883 KeZeroPages(IN PVOID Address
,
888 KeInvalidAccessAllowed(IN PVOID TrapInformation OPTIONAL
);
892 KeRosDumpStackFrames(
900 IN PLARGE_INTEGER NewSystemTime
,
901 OUT PLARGE_INTEGER OldSystemTime
,
902 IN BOOLEAN FixInterruptTime
,
903 IN PLARGE_INTEGER HalTime
916 KiStartUnexpectedRange(
922 KiEndUnexpectedRange(
929 IN PEXCEPTION_RECORD ExceptionRecord
,
931 IN PKEXCEPTION_FRAME ExceptionFrame
,
932 IN PKTRAP_FRAME TrapFrame
,
933 IN BOOLEAN SearchFrames
940 IN PKEXCEPTION_FRAME ExceptionFrame
,
941 IN PKTRAP_FRAME TrapFrame
947 IN PKTRAP_FRAME TrapFrame
,
954 IN PKTRAP_FRAME TrapFrame
960 IN PKTRAP_FRAME TrapFrame
,
961 IN PKINTERRUPT Interrupt
967 IN PKTRAP_FRAME TrapFrame
,
968 IN PKINTERRUPT Interrupt
973 KiInitializeMachineType(
979 KiSetupStackAndInitializeKernel(
980 IN PKPROCESS InitProcess
,
981 IN PKTHREAD InitThread
,
985 IN PLOADER_PARAMETER_BLOCK LoaderBlock
1012 IN KPRIORITY PriorityBoost
1018 IN PVOID
*OutputBuffer
,
1019 IN PULONG OutputLength
1024 KiGetUserModeStackAddress(
1030 KiInitMachineDependent(VOID
);
1034 KeFreezeExecution(IN PKTRAP_FRAME TrapFrame
,
1035 IN PKEXCEPTION_FRAME ExceptionFrame
);
1039 KeThawExecution(IN BOOLEAN Enable
);
1043 KeDisableInterrupts(
1049 KeAcquireQueuedSpinLockAtDpcLevel(
1050 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1055 KeReleaseQueuedSpinLockFromDpcLevel(
1056 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1061 KiRestoreProcessorControlState(
1062 IN PKPROCESSOR_STATE ProcessorState
1067 KiSaveProcessorControlState(
1068 OUT PKPROCESSOR_STATE ProcessorState
1073 KiSaveProcessorState(
1074 IN PKTRAP_FRAME TrapFrame
,
1075 IN PKEXCEPTION_FRAME ExceptionFrame
1099 KiSystemFatalException(
1100 IN ULONG ExceptionCode
,
1101 IN PKTRAP_FRAME TrapFrame
1106 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */