3 /* INCLUDES *****************************************************************/
7 /* INTERNAL KERNEL TYPES ****************************************************/
9 typedef struct _WOW64_PROCESS
12 } WOW64_PROCESS
, *PWOW64_PROCESS
;
14 typedef struct _KPROFILE_SOURCE_OBJECT
16 KPROFILE_SOURCE Source
;
18 } KPROFILE_SOURCE_OBJECT
, *PKPROFILE_SOURCE_OBJECT
;
20 typedef enum _CONNECT_TYPE
26 } CONNECT_TYPE
, *PCONNECT_TYPE
;
28 typedef struct _DISPATCH_INFO
31 PKINTERRUPT Interrupt
;
32 PKINTERRUPT_ROUTINE NoDispatch
;
33 PKINTERRUPT_ROUTINE InterruptDispatch
;
34 PKINTERRUPT_ROUTINE FloatingDispatch
;
35 PKINTERRUPT_ROUTINE ChainedDispatch
;
36 PKINTERRUPT_ROUTINE
*FlatDispatch
;
37 } DISPATCH_INFO
, *PDISPATCH_INFO
;
39 typedef struct _KI_SAMPLE_MAP
41 LARGE_INTEGER PerfStart
;
42 LARGE_INTEGER PerfEnd
;
44 LARGE_INTEGER PerfFreq
;
49 } KI_SAMPLE_MAP
, *PKI_SAMPLE_MAP
;
51 typedef struct _KTIMER_TABLE_ENTRY
55 } KTIMER_TABLE_ENTRY
, *PKTIMER_TABLE_ENTRY
;
57 #define MAX_TIMER_DPCS 16
59 typedef struct _DPC_QUEUE_ENTRY
62 PKDEFERRED_ROUTINE Routine
;
64 } DPC_QUEUE_ENTRY
, *PDPC_QUEUE_ENTRY
;
66 typedef struct _KNMI_HANDLER_CALLBACK
68 struct _KNMI_HANDLER_CALLBACK
* Next
;
69 PNMI_CALLBACK Callback
;
72 } KNMI_HANDLER_CALLBACK
, *PKNMI_HANDLER_CALLBACK
;
75 (NTAPI
*PKE_BUGCHECK_UNICODE_TO_ANSI
)(
76 IN PUNICODE_STRING Unicode
,
81 extern PKNMI_HANDLER_CALLBACK KiNmiCallbackListHead
;
82 extern KSPIN_LOCK KiNmiCallbackListLock
;
83 extern PVOID KeUserApcDispatcher
;
84 extern PVOID KeUserCallbackDispatcher
;
85 extern PVOID KeUserExceptionDispatcher
;
86 extern PVOID KeRaiseUserExceptionDispatcher
;
87 extern LARGE_INTEGER KeBootTime
;
88 extern ULONGLONG KeBootTimeBias
;
89 extern BOOLEAN ExCmosClockIsSane
;
90 extern USHORT KeProcessorArchitecture
;
91 extern USHORT KeProcessorLevel
;
92 extern USHORT KeProcessorRevision
;
93 extern ULONG KeFeatureBits
;
95 extern PKNODE KeNodeBlock
[1];
96 extern UCHAR KeNumberNodes
;
97 extern UCHAR KeProcessNodeSeed
;
98 extern ETHREAD KiInitialThread
;
99 extern EPROCESS KiInitialProcess
;
100 extern PULONG KiInterruptTemplateObject
;
101 extern PULONG KiInterruptTemplateDispatch
;
102 extern PULONG KiInterruptTemplate2ndDispatch
;
103 extern ULONG KiUnexpectedEntrySize
;
104 extern ULONG_PTR KiDoubleFaultStack
;
105 extern EX_PUSH_LOCK KernelAddressSpaceLock
;
106 extern ULONG KiMaximumDpcQueueDepth
;
107 extern ULONG KiMinimumDpcRate
;
108 extern ULONG KiAdjustDpcThreshold
;
109 extern ULONG KiIdealDpcRate
;
110 extern BOOLEAN KeThreadDpcEnable
;
111 extern LARGE_INTEGER KiTimeIncrementReciprocal
;
112 extern UCHAR KiTimeIncrementShiftCount
;
113 extern ULONG KiTimeLimitIsrMicroseconds
;
114 extern ULONG KiServiceLimit
;
115 extern LIST_ENTRY KeBugcheckCallbackListHead
, KeBugcheckReasonCallbackListHead
;
116 extern KSPIN_LOCK BugCheckCallbackLock
;
117 extern KDPC KiTimerExpireDpc
;
118 extern KTIMER_TABLE_ENTRY KiTimerTableListHead
[TIMER_TABLE_SIZE
];
119 extern FAST_MUTEX KiGenericCallDpcMutex
;
120 extern LIST_ENTRY KiProfileListHead
, KiProfileSourceListHead
;
121 extern KSPIN_LOCK KiProfileLock
;
122 extern LIST_ENTRY KiProcessListHead
;
123 extern LIST_ENTRY KiProcessInSwapListHead
, KiProcessOutSwapListHead
;
124 extern LIST_ENTRY KiStackInSwapListHead
;
125 extern KEVENT KiSwapEvent
;
126 extern PKPRCB KiProcessorBlock
[];
127 extern ULONG KiMask32Array
[MAXIMUM_PRIORITY
];
128 extern ULONG_PTR KiIdleSummary
;
129 extern PVOID KeUserApcDispatcher
;
130 extern PVOID KeUserCallbackDispatcher
;
131 extern PVOID KeUserExceptionDispatcher
;
132 extern PVOID KeRaiseUserExceptionDispatcher
;
133 extern ULONG KeTimeIncrement
;
134 extern ULONG KeTimeAdjustment
;
135 extern BOOLEAN KiTimeAdjustmentEnabled
;
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 /* Tells us if the Timer or Event is a Syncronization or Notification Object */
151 #define TIMER_OR_EVENT_TYPE 0x7L
153 /* One of the Reserved Wait Blocks, this one is for the Thread's Timer */
154 #define TIMER_WAIT_BLOCK 0x3L
156 #ifdef _M_ARM // FIXME: remove this once our headers are cleaned up
158 // A system call ID is formatted as such:
159 // .________________________________________________________________.
160 // | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
161 // |--------------|-------------------------------------------------|
162 // | TABLE NUMBER | TABLE OFFSET |
163 // \----------------------------------------------------------------/
166 // The table number is then used as an index into the service descriptor table.
167 #define TABLE_NUMBER_BITS 3
168 #define TABLE_OFFSET_BITS 12
171 // There are 2 tables (kernel and shadow, used by Win32K)
173 #define NUMBER_SERVICE_TABLES 2
174 #define NTOS_SERVICE_INDEX 0
175 #define WIN32K_SERVICE_INDEX 1
178 // NB. From assembly code, the table number must be computed as an offset into
179 // the service descriptor table.
181 // Each entry into the table is 16 bytes long on 32-bit architectures, and
182 // 32 bytes long on 64-bit architectures.
184 // Thus, Table Number 1 is offset 16 (0x10) on x86, and offset 32 (0x20) on
188 #define BITS_PER_ENTRY 5 // (1 << 5) = 32 bytes
190 #define BITS_PER_ENTRY 4 // (1 << 4) = 16 bytes
194 // We want the table number, but leave some extra bits to we can have the offset
195 // into the descriptor table.
197 #define SERVICE_TABLE_SHIFT (12 - BITS_PER_ENTRY)
200 // Now the table number (as an offset) is corrupted with part of the table offset
201 // This mask will remove the extra unwanted bits, and give us the offset into the
202 // descriptor table proper.
204 #define SERVICE_TABLE_MASK (((1 << TABLE_NUMBER_BITS) - 1) << BITS_PER_ENTRY)
207 // To get the table offset (ie: the service call number), just keep the 12 bits
209 #define SERVICE_NUMBER_MASK ((1 << TABLE_OFFSET_BITS) - 1)
212 // We'll often need to check if this is a graphics call. This is done by comparing
213 // the table number offset with the known Win32K table number offset.
214 // This is usually index 1, so table number offset 0x10 (x86) or 0x20 (x64)
216 #define SERVICE_TABLE_TEST (WIN32K_SERVICE_INDEX << BITS_PER_ENTRY)
220 #define KTS_SYSCALL_BIT (((KTRAP_STATE_BITS) { { .SystemCall = TRUE } }).Bits)
221 #define KTS_PM_BIT (((KTRAP_STATE_BITS) { { .PreviousMode = TRUE } }).Bits)
222 #define KTS_SEG_BIT (((KTRAP_STATE_BITS) { { .Segments = TRUE } }).Bits)
223 #define KTS_VOL_BIT (((KTRAP_STATE_BITS) { { .Volatiles = TRUE } }).Bits)
224 #define KTS_FULL_BIT (((KTRAP_STATE_BITS) { { .Full = TRUE } }).Bits)
226 /* INTERNAL KERNEL FUNCTIONS ************************************************/
232 OUT PULONG CpuInfoEax
,
233 OUT PULONG CpuInfoEbx
,
234 OUT PULONG CpuInfoEcx
,
235 OUT PULONG CpuInfoEdx
251 /* Finds a new thread to run */
267 KeSetDisableBoostThread(
268 IN OUT PKTHREAD Thread
,
274 KeSetDisableBoostProcess(
275 IN PKPROCESS Process
,
281 KeSetAutoAlignmentProcess(
282 IN PKPROCESS Process
,
288 KeSetAffinityProcess(
289 IN PKPROCESS Process
,
290 IN KAFFINITY Affinity
295 KeBoostPriorityThread(
297 IN KPRIORITY Increment
302 KeBalanceSetManager(IN PVOID Context
);
306 KiReadyThread(IN PKTHREAD Thread
);
310 KeSuspendThread(PKTHREAD Thread
);
314 KeReadStateThread(IN PKTHREAD Thread
);
320 IN PKTHREAD CurrentThread
325 KiAdjustQuantumThread(IN PKTHREAD Thread
);
329 KiExitDispatcher(KIRQL OldIrql
);
333 KiDeferredReadyThread(IN PKTHREAD Thread
);
343 KiProcessDeferredReadyList(
351 IN KAFFINITY Affinity
370 IN PLIST_ENTRY ExpiredListHead
,
378 IN LARGE_INTEGER Interval
385 IN PKSPIN_LOCK_QUEUE LockQueue
388 /* gmutex.c ********************************************************************/
392 KiAcquireGuardedMutex(
393 IN OUT PKGUARDED_MUTEX GuardedMutex
399 IN PFAST_MUTEX FastMutex
402 /* gate.c **********************************************************************/
406 KeInitializeGate(PKGATE Gate
);
410 KeSignalGateBoostPriority(PKGATE Gate
);
416 KWAIT_REASON WaitReason
,
417 KPROCESSOR_MODE WaitMode
420 /* ipi.c ********************************************************************/
432 IN KAFFINITY TargetProcessors
,
433 IN PKIPI_WORKER WorkerFunction
,
434 IN PKIPI_BROADCAST_WORKER BroadcastFunction
,
435 IN ULONG_PTR Context
,
441 KiIpiSignalPacketDone(
442 IN PKIPI_CONTEXT PacketContext
447 KiIpiSignalPacketDoneAndStall(
448 IN PKIPI_CONTEXT PacketContext
,
449 IN
volatile PULONG ReverseStall
452 /* next file ***************************************************************/
456 KeFindNextRightSetAffinity(
463 DbgBreakPointNoBugCheck(VOID
);
468 struct _KPROFILE
* Profile
,
469 struct _KPROCESS
* Process
,
473 KPROFILE_SOURCE ProfileSource
,
480 struct _KPROFILE
* Profile
,
486 KeStopProfile(struct _KPROFILE
* Profile
);
490 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource
);
494 KeSetIntervalProfile(
495 KPROFILE_SOURCE ProfileSource
,
502 PKTRAP_FRAME TrapFrame
507 KeProfileInterruptWithSource(
508 IN PKTRAP_FRAME TrapFrame
,
509 IN KPROFILE_SOURCE Source
515 PKTRAP_FRAME TrapFrame
,
523 PVOID DeferredContext
,
524 PVOID SystemArgument1
,
525 PVOID SystemArgument2
531 IN PKPROCESS Process
,
532 IN OUT PKTHREAD Thread
,
533 IN PKSYSTEM_ROUTINE SystemRoutine
,
534 IN PKSTART_ROUTINE StartRoutine
,
535 IN PVOID StartContext
,
550 IN OUT PKTHREAD Thread
,
551 IN PVOID KernelStack
,
552 IN PKSYSTEM_ROUTINE SystemRoutine
,
553 IN PKSTART_ROUTINE StartRoutine
,
554 IN PVOID StartContext
,
562 KiInitializeContextThread(
564 PKSYSTEM_ROUTINE SystemRoutine
,
565 PKSTART_ROUTINE StartRoutine
,
573 IN OUT PKTHREAD Thread
580 IN KPROCESSOR_MODE AlertMode
604 KeRundownThread(VOID
);
608 KeReleaseThread(PKTHREAD Thread
);
620 IN PKNORMAL_ROUTINE
*NormalRoutine
,
621 IN PVOID
*NormalContext
,
622 IN PVOID
*SystemArgument1
,
623 IN PVOID
*SystemArgument2
629 IN PVOID NormalContext
,
630 IN PVOID SystemArgument1
,
631 IN PVOID SystemArgument2
636 KeQueryBasePriorityThread(IN PKTHREAD Thread
);
642 IN KPRIORITY Priority
649 IN LONG_PTR WaitStatus
654 KeDumpStackFrames(PULONG Frame
);
664 IN LONG_PTR WaitStatus
,
665 IN KPRIORITY Increment
671 struct _KPROCESS
*Process
,
674 PULONG_PTR DirectoryTableBase
,
681 IN PKPROCESS Process
,
687 KeSetPriorityAndQuantumProcess(
688 IN PKPROCESS Process
,
689 IN KPRIORITY Priority
,
690 IN UCHAR Quantum OPTIONAL
695 KeForceResumeThread(IN PKTHREAD Thread
);
711 KeDisableThreadApcQueueing(IN PKTHREAD Thread
);
722 KeContextToTrapFrame(
724 PKEXCEPTION_FRAME ExeptionFrame
,
725 PKTRAP_FRAME TrapFrame
,
727 KPROCESSOR_MODE PreviousMode
732 KiCheckForKernelApcDelivery(VOID
);
738 IN PLIST_ENTRY Entry
,
746 IN PVOID DeferredContext
,
747 IN PVOID SystemArgument1
,
748 IN PVOID SystemArgument2
754 struct _KPROCESS
* Process
,
761 KeInitializeEventPair(PKEVENT_PAIR EventPair
);
766 IN PKEXCEPTION_FRAME Reserved
,
767 IN PKTRAP_FRAME TrapFrame
,
768 IN PKNORMAL_ROUTINE NormalRoutine
,
769 IN PVOID NormalContext
,
770 IN PVOID SystemArgument1
,
771 IN PVOID SystemArgument2
778 IN KPROCESSOR_MODE PreviousMode
784 struct _KTHREAD
*Thread
,
785 struct _KPROCESS
*Process
,
786 PKLOCK_QUEUE_HANDLE ApcLock
,
787 struct _KAPC_STATE
*SavedApcState
793 struct _KPROCESS
*NewProcess
,
794 struct _KPROCESS
*OldProcess
799 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode
);
803 KeRemoveQueueApc(PKAPC Apc
);
807 KiActivateWaiterQueue(IN PKQUEUE Queue
);
811 KeQueryRuntimeProcess(IN PKPROCESS Process
,
812 OUT PULONG UserTime
);
814 /* INITIALIZATION FUNCTIONS *************************************************/
822 KeInitExceptions(VOID
);
826 KeInitInterrupts(VOID
);
830 KiInitializeBugCheck(VOID
);
835 IN PLOADER_PARAMETER_BLOCK LoaderBlock
840 KiDeliverUserApc(PKTRAP_FRAME TrapFrame
);
845 PKAPC_STATE OldState
,
852 KPROFILE_SOURCE Source
,
859 PEXCEPTION_RECORD ExceptionRecord
,
860 PKEXCEPTION_FRAME ExceptionFrame
,
862 KPROCESSOR_MODE PreviousMode
,
868 KeTrapFrameToContext(
869 IN PKTRAP_FRAME TrapFrame
,
870 IN PKEXCEPTION_FRAME ExceptionFrame
,
871 IN OUT PCONTEXT Context
879 ULONG_PTR BugCheckParameter1
,
880 ULONG_PTR BugCheckParameter2
,
881 ULONG_PTR BugCheckParameter3
,
882 ULONG_PTR BugCheckParameter4
,
892 KeFlushCurrentTb(VOID
);
896 KeInvalidateAllCaches(VOID
);
900 KeZeroPages(IN PVOID Address
,
905 KeInvalidAccessAllowed(IN PVOID TrapInformation OPTIONAL
);
909 KeRosDumpStackFrames(
917 IN PLARGE_INTEGER NewSystemTime
,
918 OUT PLARGE_INTEGER OldSystemTime
,
919 IN BOOLEAN FixInterruptTime
,
920 IN PLARGE_INTEGER HalTime
933 KiStartUnexpectedRange(
939 KiEndUnexpectedRange(
946 IN PEXCEPTION_RECORD ExceptionRecord
,
948 IN PKEXCEPTION_FRAME ExceptionFrame
,
949 IN PKTRAP_FRAME TrapFrame
,
950 IN BOOLEAN SearchFrames
957 IN PKEXCEPTION_FRAME ExceptionFrame
,
958 IN PKTRAP_FRAME TrapFrame
965 IN PKTRAP_FRAME TrapFrame
,
973 IN PKTRAP_FRAME TrapFrame
979 IN PKTRAP_FRAME TrapFrame
,
980 IN PKINTERRUPT Interrupt
986 IN PKTRAP_FRAME TrapFrame
,
987 IN PKINTERRUPT Interrupt
992 KiInitializeMachineType(
998 KiSetupStackAndInitializeKernel(
999 IN PKPROCESS InitProcess
,
1000 IN PKTHREAD InitThread
,
1004 IN PLOADER_PARAMETER_BLOCK LoaderBlock
1016 KiComputeReciprocal(
1031 IN KPRIORITY PriorityBoost
1037 IN PVOID
*OutputBuffer
,
1038 IN PULONG OutputLength
1043 KiInitMachineDependent(VOID
);
1047 KeFreezeExecution(IN PKTRAP_FRAME TrapFrame
,
1048 IN PKEXCEPTION_FRAME ExceptionFrame
);
1052 KeThawExecution(IN BOOLEAN Enable
);
1056 KeAcquireQueuedSpinLockAtDpcLevel(
1057 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1062 KeReleaseQueuedSpinLockFromDpcLevel(
1063 IN OUT PKSPIN_LOCK_QUEUE LockQueue
1068 KiRestoreProcessorControlState(
1069 IN PKPROCESSOR_STATE ProcessorState
1074 KiSaveProcessorControlState(
1075 OUT PKPROCESSOR_STATE ProcessorState
1080 KiSaveProcessorState(
1081 IN PKTRAP_FRAME TrapFrame
,
1082 IN PKEXCEPTION_FRAME ExceptionFrame
1106 KiSystemFatalException(
1107 IN ULONG ExceptionCode
,
1108 IN PKTRAP_FRAME TrapFrame
1113 KiPcToFileHeader(IN PVOID Eip
,
1114 OUT PLDR_DATA_TABLE_ENTRY
*LdrEntry
,
1115 IN BOOLEAN DriversOnly
,
1116 OUT PBOOLEAN InKernel
);
1120 KiRosPcToUserFileHeader(IN PVOID Eip
,
1121 OUT PLDR_DATA_TABLE_ENTRY
*LdrEntry
);