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 /* INTERNAL KERNEL FUNCTIONS ************************************************/
234 OUT PULONG CpuInfoEax
,
235 OUT PULONG CpuInfoEbx
,
236 OUT PULONG CpuInfoEcx
,
237 OUT PULONG CpuInfoEdx
253 /* Finds a new thread to run */
269 KeSetDisableBoostThread(
270 IN OUT PKTHREAD Thread
,
276 KeBalanceSetManager(IN PVOID Context
);
280 KiReadyThread(IN PKTHREAD Thread
);
284 KeSuspendThread(PKTHREAD Thread
);
288 KeReadStateThread(IN PKTHREAD Thread
);
293 IN PKTHREAD CurrentThread
,
294 IN PKTHREAD NewThread
299 KiAdjustQuantumThread(IN PKTHREAD Thread
);
303 KiExitDispatcher(KIRQL OldIrql
);
307 KiDeferredReadyThread(IN PKTHREAD Thread
);
317 KiProcessDeferredReadyList(
325 IN KAFFINITY Affinity
344 IN PLIST_ENTRY ExpiredListHead
,
352 IN LARGE_INTEGER Interval
359 IN PKSPIN_LOCK_QUEUE LockQueue
362 /* gmutex.c ********************************************************************/
366 KiAcquireGuardedMutex(
367 IN OUT PKGUARDED_MUTEX GuardedMutex
373 IN PFAST_MUTEX FastMutex
376 /* gate.c **********************************************************************/
380 KeInitializeGate(PKGATE Gate
);
384 KeSignalGateBoostPriority(PKGATE Gate
);
390 KWAIT_REASON WaitReason
,
391 KPROCESSOR_MODE WaitMode
394 /* ipi.c ********************************************************************/
406 IN KAFFINITY TargetProcessors
,
407 IN PKIPI_WORKER WorkerFunction
,
408 IN PKIPI_BROADCAST_WORKER BroadcastFunction
,
409 IN ULONG_PTR Context
,
415 KiIpiSignalPacketDone(
416 IN PKIPI_CONTEXT PacketContext
421 KiIpiSignalPacketDoneAndStall(
422 IN PKIPI_CONTEXT PacketContext
,
423 IN
volatile PULONG ReverseStall
426 /* next file ***************************************************************/
430 KeFindNextRightSetAffinity(
437 DbgBreakPointNoBugCheck(VOID
);
442 struct _KPROFILE
* Profile
,
443 struct _KPROCESS
* Process
,
447 KPROFILE_SOURCE ProfileSource
,
454 struct _KPROFILE
* Profile
,
460 KeStopProfile(struct _KPROFILE
* Profile
);
464 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource
);
468 KeSetIntervalProfile(
469 KPROFILE_SOURCE ProfileSource
,
476 PKTRAP_FRAME TrapFrame
481 KeProfileInterruptWithSource(
482 IN PKTRAP_FRAME TrapFrame
,
483 IN KPROFILE_SOURCE Source
489 PKTRAP_FRAME TrapFrame
,
497 PVOID DeferredContext
,
498 PVOID SystemArgument1
,
499 PVOID SystemArgument2
505 IN PKPROCESS Process
,
506 IN OUT PKTHREAD Thread
,
507 IN PKSYSTEM_ROUTINE SystemRoutine
,
508 IN PKSTART_ROUTINE StartRoutine
,
509 IN PVOID StartContext
,
524 IN OUT PKTHREAD Thread
,
525 IN PVOID KernelStack
,
526 IN PKSYSTEM_ROUTINE SystemRoutine
,
527 IN PKSTART_ROUTINE StartRoutine
,
528 IN PVOID StartContext
,
536 KiInitializeContextThread(
538 PKSYSTEM_ROUTINE SystemRoutine
,
539 PKSTART_ROUTINE StartRoutine
,
547 IN OUT PKTHREAD Thread
554 IN KPROCESSOR_MODE AlertMode
578 KeRundownThread(VOID
);
582 KeReleaseThread(PKTHREAD Thread
);
594 IN PKNORMAL_ROUTINE
*NormalRoutine
,
595 IN PVOID
*NormalContext
,
596 IN PVOID
*SystemArgument1
,
597 IN PVOID
*SystemArgument2
603 IN PVOID NormalContext
,
604 IN PVOID SystemArgument1
,
605 IN PVOID SystemArgument2
610 KeQueryBasePriorityThread(IN PKTHREAD Thread
);
616 IN KPRIORITY Priority
623 IN NTSTATUS WaitStatus
628 KeDumpStackFrames(PULONG Frame
);
638 IN NTSTATUS WaitStatus
,
639 IN KPRIORITY Increment
645 struct _KPROCESS
*Process
,
648 PULONG DirectoryTableBase
,
655 IN PKPROCESS Process
,
661 KeSetPriorityAndQuantumProcess(
662 IN PKPROCESS Process
,
663 IN KPRIORITY Priority
,
664 IN UCHAR Quantum OPTIONAL
669 KeForceResumeThread(IN PKTHREAD Thread
);
685 KeDisableThreadApcQueueing(IN PKTHREAD Thread
);
696 KeContextToTrapFrame(
698 PKEXCEPTION_FRAME ExeptionFrame
,
699 PKTRAP_FRAME TrapFrame
,
701 KPROCESSOR_MODE PreviousMode
706 KiCheckForKernelApcDelivery(VOID
);
712 IN PLIST_ENTRY Entry
,
720 IN PVOID DeferredContext
,
721 IN PVOID SystemArgument1
,
722 IN PVOID SystemArgument2
727 KiComputeTimerTableIndex(
728 IN LONGLONG TimeValue
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
,
872 KeFlushCurrentTb(VOID
);
876 KeInvalidateAllCaches(VOID
);
880 KeZeroPages(IN PVOID Address
,
885 KeInvalidAccessAllowed(IN PVOID TrapInformation OPTIONAL
);
889 KeRosDumpStackFrames(
897 IN PLARGE_INTEGER NewSystemTime
,
898 OUT PLARGE_INTEGER OldSystemTime
,
899 IN BOOLEAN FixInterruptTime
,
900 IN PLARGE_INTEGER HalTime
913 KiStartUnexpectedRange(
919 KiEndUnexpectedRange(
937 KiInitializeMachineType(
943 KiSetupStackAndInitializeKernel(
944 IN PKPROCESS InitProcess
,
945 IN PKTHREAD InitThread
,
949 IN PLOADER_PARAMETER_BLOCK LoaderBlock
976 IN KPRIORITY PriorityBoost
982 IN PVOID
*OutputBuffer
,
983 IN PULONG OutputLength
988 KiGetUserModeStackAddress(
994 KiInitMachineDependent(VOID
);
998 KeFreezeExecution(IN PKTRAP_FRAME TrapFrame
,
999 IN PKEXCEPTION_FRAME ExceptionFrame
);
1003 KeThawExecution(IN BOOLEAN Enable
);
1007 KeDisableInterrupts(
1013 KeAcquireQueuedSpinLockAtDpcLevel(
1014 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1019 KeReleaseQueuedSpinLockFromDpcLevel(
1020 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1025 KiRestoreProcessorControlState(
1026 IN PKPROCESSOR_STATE ProcessorState
1031 KiSaveProcessorControlState(
1032 OUT PKPROCESSOR_STATE ProcessorState
1050 IN PKTRAP_FRAME TrapFrame
,
1051 IN ULONG Instruction
1061 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */