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
;
144 /* MACROS *************************************************************************/
146 #define AFFINITY_MASK(Id) KiMask32Array[Id]
147 #define PRIORITY_MASK(Id) KiMask32Array[Id]
149 /* The following macro initializes a dispatcher object's header */
150 #define KeInitializeDispatcherHeader(Header, t, s, State) \
152 (Header)->Type = t; \
153 (Header)->Absolute = 0; \
154 (Header)->Size = s; \
155 (Header)->Inserted = 0; \
156 (Header)->SignalState = State; \
157 InitializeListHead(&((Header)->WaitListHead)); \
160 /* Tells us if the Timer or Event is a Syncronization or Notification Object */
161 #define TIMER_OR_EVENT_TYPE 0x7L
163 /* One of the Reserved Wait Blocks, this one is for the Thread's Timer */
164 #define TIMER_WAIT_BLOCK 0x3L
166 #ifdef _M_ARM // FIXME: remove this once our headers are cleaned up
168 // A system call ID is formatted as such:
169 // .________________________________________________________________.
170 // | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
171 // |--------------|-------------------------------------------------|
172 // | TABLE NUMBER | TABLE OFFSET |
173 // \----------------------------------------------------------------/
176 // The table number is then used as an index into the service descriptor table.
177 #define TABLE_NUMBER_BITS 3
178 #define TABLE_OFFSET_BITS 12
181 // There are 2 tables (kernel and shadow, used by Win32K)
183 #define NUMBER_SERVICE_TABLES 2
184 #define NTOS_SERVICE_INDEX 0
185 #define WIN32K_SERVICE_INDEX 1
188 // NB. From assembly code, the table number must be computed as an offset into
189 // the service descriptor table.
191 // Each entry into the table is 16 bytes long on 32-bit architectures, and
192 // 32 bytes long on 64-bit architectures.
194 // Thus, Table Number 1 is offset 16 (0x10) on x86, and offset 32 (0x20) on
198 #define BITS_PER_ENTRY 5 // (1 << 5) = 32 bytes
200 #define BITS_PER_ENTRY 4 // (1 << 4) = 16 bytes
204 // We want the table number, but leave some extra bits to we can have the offset
205 // into the descriptor table.
207 #define SERVICE_TABLE_SHIFT (12 - BITS_PER_ENTRY)
210 // Now the table number (as an offset) is corrupted with part of the table offset
211 // This mask will remove the extra unwanted bits, and give us the offset into the
212 // descriptor table proper.
214 #define SERVICE_TABLE_MASK (((1 << TABLE_NUMBER_BITS) - 1) << BITS_PER_ENTRY)
217 // To get the table offset (ie: the service call number), just keep the 12 bits
219 #define SERVICE_NUMBER_MASK ((1 << TABLE_OFFSET_BITS) - 1)
222 // We'll often need to check if this is a graphics call. This is done by comparing
223 // the table number offset with the known Win32K table number offset.
224 // This is usually index 1, so table number offset 0x10 (x86) or 0x20 (x64)
226 #define SERVICE_TABLE_TEST (WIN32K_SERVICE_INDEX << BITS_PER_ENTRY)
230 #define KTS_SYSCALL_BIT (((KTRAP_STATE_BITS) { { .SystemCall = TRUE } }).Bits)
231 #define KTS_PM_BIT (((KTRAP_STATE_BITS) { { .PreviousMode = TRUE } }).Bits)
232 #define KTS_SEG_BIT (((KTRAP_STATE_BITS) { { .Segments = TRUE } }).Bits)
233 #define KTS_VOL_BIT (((KTRAP_STATE_BITS) { { .Volatiles = TRUE } }).Bits)
234 #define KTS_FULL_BIT (((KTRAP_STATE_BITS) { { .Full = TRUE } }).Bits)
236 /* INTERNAL KERNEL FUNCTIONS ************************************************/
242 OUT PULONG CpuInfoEax
,
243 OUT PULONG CpuInfoEbx
,
244 OUT PULONG CpuInfoEcx
,
245 OUT PULONG CpuInfoEdx
261 /* Finds a new thread to run */
277 KeSetDisableBoostThread(
278 IN OUT PKTHREAD Thread
,
284 KeBalanceSetManager(IN PVOID Context
);
288 KiReadyThread(IN PKTHREAD Thread
);
292 KeSuspendThread(PKTHREAD Thread
);
296 KeReadStateThread(IN PKTHREAD Thread
);
301 IN PKTHREAD CurrentThread
,
302 IN PKTHREAD NewThread
307 KiAdjustQuantumThread(IN PKTHREAD Thread
);
311 KiExitDispatcher(KIRQL OldIrql
);
315 KiDeferredReadyThread(IN PKTHREAD Thread
);
325 KiProcessDeferredReadyList(
333 IN KAFFINITY Affinity
352 IN PLIST_ENTRY ExpiredListHead
,
360 IN LARGE_INTEGER Interval
367 IN PKSPIN_LOCK_QUEUE LockQueue
370 /* gmutex.c ********************************************************************/
374 KiAcquireGuardedMutex(
375 IN OUT PKGUARDED_MUTEX GuardedMutex
381 IN PFAST_MUTEX FastMutex
384 /* gate.c **********************************************************************/
388 KeInitializeGate(PKGATE Gate
);
392 KeSignalGateBoostPriority(PKGATE Gate
);
398 KWAIT_REASON WaitReason
,
399 KPROCESSOR_MODE WaitMode
402 /* ipi.c ********************************************************************/
414 IN KAFFINITY TargetProcessors
,
415 IN PKIPI_WORKER WorkerFunction
,
416 IN PKIPI_BROADCAST_WORKER BroadcastFunction
,
417 IN ULONG_PTR Context
,
423 KiIpiSignalPacketDone(
424 IN PKIPI_CONTEXT PacketContext
429 KiIpiSignalPacketDoneAndStall(
430 IN PKIPI_CONTEXT PacketContext
,
431 IN
volatile PULONG ReverseStall
434 /* next file ***************************************************************/
438 KeFindNextRightSetAffinity(
445 DbgBreakPointNoBugCheck(VOID
);
450 struct _KPROFILE
* Profile
,
451 struct _KPROCESS
* Process
,
455 KPROFILE_SOURCE ProfileSource
,
462 struct _KPROFILE
* Profile
,
468 KeStopProfile(struct _KPROFILE
* Profile
);
472 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource
);
476 KeSetIntervalProfile(
477 KPROFILE_SOURCE ProfileSource
,
484 PKTRAP_FRAME TrapFrame
489 KeProfileInterruptWithSource(
490 IN PKTRAP_FRAME TrapFrame
,
491 IN KPROFILE_SOURCE Source
497 PKTRAP_FRAME TrapFrame
,
505 PVOID DeferredContext
,
506 PVOID SystemArgument1
,
507 PVOID SystemArgument2
513 IN PKPROCESS Process
,
514 IN OUT PKTHREAD Thread
,
515 IN PKSYSTEM_ROUTINE SystemRoutine
,
516 IN PKSTART_ROUTINE StartRoutine
,
517 IN PVOID StartContext
,
532 IN OUT PKTHREAD Thread
,
533 IN PVOID KernelStack
,
534 IN PKSYSTEM_ROUTINE SystemRoutine
,
535 IN PKSTART_ROUTINE StartRoutine
,
536 IN PVOID StartContext
,
544 KiInitializeContextThread(
546 PKSYSTEM_ROUTINE SystemRoutine
,
547 PKSTART_ROUTINE StartRoutine
,
555 IN OUT PKTHREAD Thread
562 IN KPROCESSOR_MODE AlertMode
586 KeRundownThread(VOID
);
590 KeReleaseThread(PKTHREAD Thread
);
602 IN PKNORMAL_ROUTINE
*NormalRoutine
,
603 IN PVOID
*NormalContext
,
604 IN PVOID
*SystemArgument1
,
605 IN PVOID
*SystemArgument2
611 IN PVOID NormalContext
,
612 IN PVOID SystemArgument1
,
613 IN PVOID SystemArgument2
618 KeQueryBasePriorityThread(IN PKTHREAD Thread
);
624 IN KPRIORITY Priority
631 IN NTSTATUS WaitStatus
636 KeDumpStackFrames(PULONG Frame
);
646 IN LONG_PTR WaitStatus
,
647 IN KPRIORITY Increment
653 struct _KPROCESS
*Process
,
656 PULONG DirectoryTableBase
,
663 IN PKPROCESS Process
,
669 KeSetPriorityAndQuantumProcess(
670 IN PKPROCESS Process
,
671 IN KPRIORITY Priority
,
672 IN UCHAR Quantum OPTIONAL
677 KeForceResumeThread(IN PKTHREAD Thread
);
693 KeDisableThreadApcQueueing(IN PKTHREAD Thread
);
704 KeContextToTrapFrame(
706 PKEXCEPTION_FRAME ExeptionFrame
,
707 PKTRAP_FRAME TrapFrame
,
709 KPROCESSOR_MODE PreviousMode
714 KiCheckForKernelApcDelivery(VOID
);
720 IN PLIST_ENTRY Entry
,
728 IN PVOID DeferredContext
,
729 IN PVOID SystemArgument1
,
730 IN PVOID SystemArgument2
736 struct _KPROCESS
* Process
,
743 KeInitializeEventPair(PKEVENT_PAIR EventPair
);
748 IN PKEXCEPTION_FRAME Reserved
,
749 IN PKTRAP_FRAME TrapFrame
,
750 IN PKNORMAL_ROUTINE NormalRoutine
,
751 IN PVOID NormalContext
,
752 IN PVOID SystemArgument1
,
753 IN PVOID SystemArgument2
760 IN KPROCESSOR_MODE PreviousMode
766 struct _KTHREAD
*Thread
,
767 struct _KPROCESS
*Process
,
768 PKLOCK_QUEUE_HANDLE ApcLock
,
769 struct _KAPC_STATE
*SavedApcState
775 struct _KPROCESS
*NewProcess
,
776 struct _KPROCESS
*OldProcess
781 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode
);
785 KeRemoveQueueApc(PKAPC Apc
);
789 KiActivateWaiterQueue(IN PKQUEUE Queue
);
793 KeQueryRuntimeProcess(IN PKPROCESS Process
,
794 OUT PULONG UserTime
);
796 /* INITIALIZATION FUNCTIONS *************************************************/
804 KeInitExceptions(VOID
);
808 KeInitInterrupts(VOID
);
812 KiInitializeBugCheck(VOID
);
817 IN PLOADER_PARAMETER_BLOCK LoaderBlock
822 KiDeliverUserApc(PKTRAP_FRAME TrapFrame
);
827 PKAPC_STATE OldState
,
834 KPROFILE_SOURCE Source
,
841 PEXCEPTION_RECORD ExceptionRecord
,
842 PKEXCEPTION_FRAME ExceptionFrame
,
844 KPROCESSOR_MODE PreviousMode
,
850 KeTrapFrameToContext(
851 IN PKTRAP_FRAME TrapFrame
,
852 IN PKEXCEPTION_FRAME ExceptionFrame
,
853 IN OUT PCONTEXT Context
861 ULONG_PTR BugCheckParameter1
,
862 ULONG_PTR BugCheckParameter2
,
863 ULONG_PTR BugCheckParameter3
,
864 ULONG_PTR BugCheckParameter4
,
874 KeFlushCurrentTb(VOID
);
878 KeInvalidateAllCaches(VOID
);
882 KeZeroPages(IN PVOID Address
,
887 KeInvalidAccessAllowed(IN PVOID TrapInformation OPTIONAL
);
891 KeRosDumpStackFrames(
899 IN PLARGE_INTEGER NewSystemTime
,
900 OUT PLARGE_INTEGER OldSystemTime
,
901 IN BOOLEAN FixInterruptTime
,
902 IN PLARGE_INTEGER HalTime
915 KiStartUnexpectedRange(
921 KiEndUnexpectedRange(
928 IN PEXCEPTION_RECORD ExceptionRecord
,
930 IN PKEXCEPTION_FRAME ExceptionFrame
,
931 IN PKTRAP_FRAME TrapFrame
,
932 IN BOOLEAN SearchFrames
939 IN PKEXCEPTION_FRAME ExceptionFrame
,
940 IN PKTRAP_FRAME TrapFrame
946 IN PKTRAP_FRAME TrapFrame
,
953 IN PKTRAP_FRAME TrapFrame
959 IN PKTRAP_FRAME TrapFrame
,
960 IN PKINTERRUPT Interrupt
966 IN PKTRAP_FRAME TrapFrame
,
967 IN PKINTERRUPT Interrupt
972 KiInitializeMachineType(
978 KiSetupStackAndInitializeKernel(
979 IN PKPROCESS InitProcess
,
980 IN PKTHREAD InitThread
,
984 IN PLOADER_PARAMETER_BLOCK LoaderBlock
1011 IN KPRIORITY PriorityBoost
1017 IN PVOID
*OutputBuffer
,
1018 IN PULONG OutputLength
1023 KiGetUserModeStackAddress(
1029 KiInitMachineDependent(VOID
);
1033 KeFreezeExecution(IN PKTRAP_FRAME TrapFrame
,
1034 IN PKEXCEPTION_FRAME ExceptionFrame
);
1038 KeThawExecution(IN BOOLEAN Enable
);
1042 KeDisableInterrupts(
1048 KeAcquireQueuedSpinLockAtDpcLevel(
1049 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1054 KeReleaseQueuedSpinLockFromDpcLevel(
1055 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1060 KiRestoreProcessorControlState(
1061 IN PKPROCESSOR_STATE ProcessorState
1066 KiSaveProcessorControlState(
1067 OUT PKPROCESSOR_STATE ProcessorState
1072 KiSaveProcessorState(
1073 IN PKTRAP_FRAME TrapFrame
,
1074 IN PKEXCEPTION_FRAME ExceptionFrame
1098 KiSystemFatalException(
1099 IN ULONG ExceptionCode
,
1100 IN PKTRAP_FRAME TrapFrame
1105 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */