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 ULONG KiInterruptTemplate
[KINTERRUPT_DISPATCH_CODES
];
102 extern PULONG KiInterruptTemplateObject
;
103 extern PULONG KiInterruptTemplateDispatch
;
104 extern PULONG KiInterruptTemplate2ndDispatch
;
105 extern ULONG KiUnexpectedEntrySize
;
106 extern UCHAR P0BootStack
[];
107 extern UCHAR KiDoubleFaultStack
[];
108 extern EX_PUSH_LOCK KernelAddressSpaceLock
;
109 extern ULONG KiMaximumDpcQueueDepth
;
110 extern ULONG KiMinimumDpcRate
;
111 extern ULONG KiAdjustDpcThreshold
;
112 extern ULONG KiIdealDpcRate
;
113 extern BOOLEAN KeThreadDpcEnable
;
114 extern LARGE_INTEGER KiTimeIncrementReciprocal
;
115 extern UCHAR KiTimeIncrementShiftCount
;
116 extern ULONG KiTimeLimitIsrMicroseconds
;
117 extern ULONG KiServiceLimit
;
118 extern LIST_ENTRY KeBugcheckCallbackListHead
, KeBugcheckReasonCallbackListHead
;
119 extern KSPIN_LOCK BugCheckCallbackLock
;
120 extern KDPC KiTimerExpireDpc
;
121 extern KTIMER_TABLE_ENTRY KiTimerTableListHead
[TIMER_TABLE_SIZE
];
122 extern FAST_MUTEX KiGenericCallDpcMutex
;
123 extern LIST_ENTRY KiProfileListHead
, KiProfileSourceListHead
;
124 extern KSPIN_LOCK KiProfileLock
;
125 extern LIST_ENTRY KiProcessListHead
;
126 extern LIST_ENTRY KiProcessInSwapListHead
, KiProcessOutSwapListHead
;
127 extern LIST_ENTRY KiStackInSwapListHead
;
128 extern KEVENT KiSwapEvent
;
129 extern PKPRCB KiProcessorBlock
[];
130 extern ULONG KiMask32Array
[MAXIMUM_PRIORITY
];
131 extern ULONG KiIdleSummary
;
132 extern PVOID KeUserApcDispatcher
;
133 extern PVOID KeUserCallbackDispatcher
;
134 extern PVOID KeUserExceptionDispatcher
;
135 extern PVOID KeRaiseUserExceptionDispatcher
;
136 extern ULONG KeTimeIncrement
;
137 extern ULONG KeTimeAdjustment
;
138 extern ULONG_PTR KiBugCheckData
[5];
139 extern ULONG KiFreezeFlag
;
140 extern ULONG KiDPCTimeout
;
142 /* MACROS *************************************************************************/
144 #define AFFINITY_MASK(Id) KiMask32Array[Id]
145 #define PRIORITY_MASK(Id) KiMask32Array[Id]
147 /* The following macro initializes a dispatcher object's header */
148 #define KeInitializeDispatcherHeader(Header, t, s, State) \
150 (Header)->Type = t; \
151 (Header)->Absolute = 0; \
152 (Header)->Size = s; \
153 (Header)->Inserted = 0; \
154 (Header)->SignalState = State; \
155 InitializeListHead(&((Header)->WaitListHead)); \
158 /* Tells us if the Timer or Event is a Syncronization or Notification Object */
159 #define TIMER_OR_EVENT_TYPE 0x7L
161 /* One of the Reserved Wait Blocks, this one is for the Thread's Timer */
162 #define TIMER_WAIT_BLOCK 0x3L
164 #ifdef _M_ARM // FIXME: remove this once our headers are cleaned up
166 // A system call ID is formatted as such:
167 // .________________________________________________________________.
168 // | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
169 // |--------------|-------------------------------------------------|
170 // | TABLE NUMBER | TABLE OFFSET |
171 // \----------------------------------------------------------------/
174 // The table number is then used as an index into the service descriptor table.
175 #define TABLE_NUMBER_BITS 3
176 #define TABLE_OFFSET_BITS 12
179 // There are 2 tables (kernel and shadow, used by Win32K)
181 #define NUMBER_SERVICE_TABLES 2
182 #define NTOS_SERVICE_INDEX 0
183 #define WIN32K_SERVICE_INDEX 1
186 // NB. From assembly code, the table number must be computed as an offset into
187 // the service descriptor table.
189 // Each entry into the table is 16 bytes long on 32-bit architectures, and
190 // 32 bytes long on 64-bit architectures.
192 // Thus, Table Number 1 is offset 16 (0x10) on x86, and offset 32 (0x20) on
196 #define BITS_PER_ENTRY 5 // (1 << 5) = 32 bytes
198 #define BITS_PER_ENTRY 4 // (1 << 4) = 16 bytes
202 // We want the table number, but leave some extra bits to we can have the offset
203 // into the descriptor table.
205 #define SERVICE_TABLE_SHIFT (12 - BITS_PER_ENTRY)
208 // Now the table number (as an offset) is corrupted with part of the table offset
209 // This mask will remove the extra unwanted bits, and give us the offset into the
210 // descriptor table proper.
212 #define SERVICE_TABLE_MASK (((1 << TABLE_NUMBER_BITS) - 1) << BITS_PER_ENTRY)
215 // To get the table offset (ie: the service call number), just keep the 12 bits
217 #define SERVICE_NUMBER_MASK ((1 << TABLE_OFFSET_BITS) - 1)
220 // We'll often need to check if this is a graphics call. This is done by comparing
221 // the table number offset with the known Win32K table number offset.
222 // This is usually index 1, so table number offset 0x10 (x86) or 0x20 (x64)
224 #define SERVICE_TABLE_TEST (WIN32K_SERVICE_INDEX << BITS_PER_ENTRY)
228 #define KTS_SYSCALL_BIT (((KTRAP_STATE_BITS) { { .SystemCall = TRUE } }).Bits)
229 #define KTS_PM_BIT (((KTRAP_STATE_BITS) { { .PreviousMode = TRUE } }).Bits)
230 #define KTS_SEG_BIT (((KTRAP_STATE_BITS) { { .Segments = TRUE } }).Bits)
231 #define KTS_VOL_BIT (((KTRAP_STATE_BITS) { { .Volatiles = TRUE } }).Bits)
232 #define KTS_FULL_BIT (((KTRAP_STATE_BITS) { { .Full = TRUE } }).Bits)
234 /* INTERNAL KERNEL FUNCTIONS ************************************************/
240 OUT PULONG CpuInfoEax
,
241 OUT PULONG CpuInfoEbx
,
242 OUT PULONG CpuInfoEcx
,
243 OUT PULONG CpuInfoEdx
259 /* Finds a new thread to run */
275 KeSetDisableBoostThread(
276 IN OUT PKTHREAD Thread
,
282 KeBalanceSetManager(IN PVOID Context
);
286 KiReadyThread(IN PKTHREAD Thread
);
290 KeSuspendThread(PKTHREAD Thread
);
294 KeReadStateThread(IN PKTHREAD Thread
);
299 IN PKTHREAD CurrentThread
,
300 IN PKTHREAD NewThread
305 KiAdjustQuantumThread(IN PKTHREAD Thread
);
309 KiExitDispatcher(KIRQL OldIrql
);
313 KiDeferredReadyThread(IN PKTHREAD Thread
);
323 KiProcessDeferredReadyList(
331 IN KAFFINITY Affinity
350 IN PLIST_ENTRY ExpiredListHead
,
358 IN LARGE_INTEGER Interval
365 IN PKSPIN_LOCK_QUEUE LockQueue
368 /* gmutex.c ********************************************************************/
372 KiAcquireGuardedMutex(
373 IN OUT PKGUARDED_MUTEX GuardedMutex
379 IN PFAST_MUTEX FastMutex
382 /* gate.c **********************************************************************/
386 KeInitializeGate(PKGATE Gate
);
390 KeSignalGateBoostPriority(PKGATE Gate
);
396 KWAIT_REASON WaitReason
,
397 KPROCESSOR_MODE WaitMode
400 /* ipi.c ********************************************************************/
412 IN KAFFINITY TargetProcessors
,
413 IN PKIPI_WORKER WorkerFunction
,
414 IN PKIPI_BROADCAST_WORKER BroadcastFunction
,
415 IN ULONG_PTR Context
,
421 KiIpiSignalPacketDone(
422 IN PKIPI_CONTEXT PacketContext
427 KiIpiSignalPacketDoneAndStall(
428 IN PKIPI_CONTEXT PacketContext
,
429 IN
volatile PULONG ReverseStall
432 /* next file ***************************************************************/
436 KeFindNextRightSetAffinity(
443 DbgBreakPointNoBugCheck(VOID
);
448 struct _KPROFILE
* Profile
,
449 struct _KPROCESS
* Process
,
453 KPROFILE_SOURCE ProfileSource
,
460 struct _KPROFILE
* Profile
,
466 KeStopProfile(struct _KPROFILE
* Profile
);
470 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource
);
474 KeSetIntervalProfile(
475 KPROFILE_SOURCE ProfileSource
,
482 PKTRAP_FRAME TrapFrame
487 KeProfileInterruptWithSource(
488 IN PKTRAP_FRAME TrapFrame
,
489 IN KPROFILE_SOURCE Source
495 PKTRAP_FRAME TrapFrame
,
503 PVOID DeferredContext
,
504 PVOID SystemArgument1
,
505 PVOID SystemArgument2
511 IN PKPROCESS Process
,
512 IN OUT PKTHREAD Thread
,
513 IN PKSYSTEM_ROUTINE SystemRoutine
,
514 IN PKSTART_ROUTINE StartRoutine
,
515 IN PVOID StartContext
,
530 IN OUT PKTHREAD Thread
,
531 IN PVOID KernelStack
,
532 IN PKSYSTEM_ROUTINE SystemRoutine
,
533 IN PKSTART_ROUTINE StartRoutine
,
534 IN PVOID StartContext
,
542 KiInitializeContextThread(
544 PKSYSTEM_ROUTINE SystemRoutine
,
545 PKSTART_ROUTINE StartRoutine
,
553 IN OUT PKTHREAD Thread
560 IN KPROCESSOR_MODE AlertMode
584 KeRundownThread(VOID
);
588 KeReleaseThread(PKTHREAD Thread
);
600 IN PKNORMAL_ROUTINE
*NormalRoutine
,
601 IN PVOID
*NormalContext
,
602 IN PVOID
*SystemArgument1
,
603 IN PVOID
*SystemArgument2
609 IN PVOID NormalContext
,
610 IN PVOID SystemArgument1
,
611 IN PVOID SystemArgument2
616 KeQueryBasePriorityThread(IN PKTHREAD Thread
);
622 IN KPRIORITY Priority
629 IN NTSTATUS WaitStatus
634 KeDumpStackFrames(PULONG Frame
);
644 IN LONG_PTR WaitStatus
,
645 IN KPRIORITY Increment
651 struct _KPROCESS
*Process
,
654 PULONG DirectoryTableBase
,
661 IN PKPROCESS Process
,
667 KeSetPriorityAndQuantumProcess(
668 IN PKPROCESS Process
,
669 IN KPRIORITY Priority
,
670 IN UCHAR Quantum OPTIONAL
675 KeForceResumeThread(IN PKTHREAD Thread
);
691 KeDisableThreadApcQueueing(IN PKTHREAD Thread
);
702 KeContextToTrapFrame(
704 PKEXCEPTION_FRAME ExeptionFrame
,
705 PKTRAP_FRAME TrapFrame
,
707 KPROCESSOR_MODE PreviousMode
712 KiCheckForKernelApcDelivery(VOID
);
718 IN PLIST_ENTRY Entry
,
726 IN PVOID DeferredContext
,
727 IN PVOID SystemArgument1
,
728 IN PVOID SystemArgument2
734 struct _KPROCESS
* Process
,
741 KeInitializeEventPair(PKEVENT_PAIR EventPair
);
746 IN PKEXCEPTION_FRAME Reserved
,
747 IN PKTRAP_FRAME TrapFrame
,
748 IN PKNORMAL_ROUTINE NormalRoutine
,
749 IN PVOID NormalContext
,
750 IN PVOID SystemArgument1
,
751 IN PVOID SystemArgument2
758 IN KPROCESSOR_MODE PreviousMode
764 struct _KTHREAD
*Thread
,
765 struct _KPROCESS
*Process
,
766 PKLOCK_QUEUE_HANDLE ApcLock
,
767 struct _KAPC_STATE
*SavedApcState
773 struct _KPROCESS
*NewProcess
,
774 struct _KPROCESS
*OldProcess
779 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode
);
783 KeRemoveQueueApc(PKAPC Apc
);
787 KiActivateWaiterQueue(IN PKQUEUE Queue
);
791 KeQueryRuntimeProcess(IN PKPROCESS Process
,
792 OUT PULONG UserTime
);
794 /* INITIALIZATION FUNCTIONS *************************************************/
802 KeInitExceptions(VOID
);
806 KeInitInterrupts(VOID
);
810 KiInitializeBugCheck(VOID
);
815 IN PLOADER_PARAMETER_BLOCK LoaderBlock
820 KiDeliverUserApc(PKTRAP_FRAME TrapFrame
);
825 PKAPC_STATE OldState
,
832 KPROFILE_SOURCE Source
,
839 PEXCEPTION_RECORD ExceptionRecord
,
840 PKEXCEPTION_FRAME ExceptionFrame
,
842 KPROCESSOR_MODE PreviousMode
,
848 KeTrapFrameToContext(
849 IN PKTRAP_FRAME TrapFrame
,
850 IN PKEXCEPTION_FRAME ExceptionFrame
,
851 IN OUT PCONTEXT Context
859 ULONG_PTR BugCheckParameter1
,
860 ULONG_PTR BugCheckParameter2
,
861 ULONG_PTR BugCheckParameter3
,
862 ULONG_PTR BugCheckParameter4
,
868 KiDispatchExceptionFromTrapFrame(
870 IN ULONG_PTR Address
,
871 IN ULONG ParameterCount
,
872 IN ULONG_PTR Parameter1
,
873 IN ULONG_PTR Parameter2
,
874 IN ULONG_PTR Parameter3
,
875 IN PKTRAP_FRAME TrapFrame
884 KeFlushCurrentTb(VOID
);
888 KeInvalidateAllCaches(VOID
);
892 KeZeroPages(IN PVOID Address
,
897 KeInvalidAccessAllowed(IN PVOID TrapInformation OPTIONAL
);
901 KeRosDumpStackFrames(
909 IN PLARGE_INTEGER NewSystemTime
,
910 OUT PLARGE_INTEGER OldSystemTime
,
911 IN BOOLEAN FixInterruptTime
,
912 IN PLARGE_INTEGER HalTime
925 KiStartUnexpectedRange(
931 KiEndUnexpectedRange(
938 IN PEXCEPTION_RECORD ExceptionRecord
,
940 IN PKEXCEPTION_FRAME ExceptionFrame
,
941 IN PKTRAP_FRAME TrapFrame
,
942 IN BOOLEAN SearchFrames
949 IN PKEXCEPTION_FRAME ExceptionFrame
,
950 IN PKTRAP_FRAME TrapFrame
956 IN PKTRAP_FRAME TrapFrame
962 IN PKTRAP_FRAME TrapFrame
965 #ifndef HAL_INTERRUPT_SUPPORT_IN_C
981 IN PKTRAP_FRAME TrapFrame
,
982 IN PKINTERRUPT Interrupt
988 IN PKTRAP_FRAME TrapFrame
,
989 IN PKINTERRUPT Interrupt
995 KiInitializeMachineType(
1001 KiSetupStackAndInitializeKernel(
1002 IN PKPROCESS InitProcess
,
1003 IN PKTHREAD InitThread
,
1007 IN PLOADER_PARAMETER_BLOCK LoaderBlock
1019 KiComputeReciprocal(
1034 IN KPRIORITY PriorityBoost
1040 IN PVOID
*OutputBuffer
,
1041 IN PULONG OutputLength
1046 KiGetUserModeStackAddress(
1052 KiInitMachineDependent(VOID
);
1056 KeFreezeExecution(IN PKTRAP_FRAME TrapFrame
,
1057 IN PKEXCEPTION_FRAME ExceptionFrame
);
1061 KeThawExecution(IN BOOLEAN Enable
);
1065 KeDisableInterrupts(
1071 KeAcquireQueuedSpinLockAtDpcLevel(
1072 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1077 KeReleaseQueuedSpinLockFromDpcLevel(
1078 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1083 KiRestoreProcessorControlState(
1084 IN PKPROCESSOR_STATE ProcessorState
1089 KiSaveProcessorControlState(
1090 OUT PKPROCESSOR_STATE ProcessorState
1095 KiSaveProcessorState(
1096 IN PKTRAP_FRAME TrapFrame
,
1097 IN PKEXCEPTION_FRAME ExceptionFrame
1115 IN PKTRAP_FRAME TrapFrame
,
1116 IN ULONG Instruction
1126 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */