xref: /reactos/ntoskrnl/include/internal/ke.h (revision 4bc591c6)
1 #pragma once
2 
3 /* INCLUDES *****************************************************************/
4 
5 #include "arch/ke.h"
6 
7 #ifdef __cplusplus
8 extern "C"
9 {
10 #endif
11 
12 /* INTERNAL KERNEL TYPES ****************************************************/
13 
14 typedef struct _WOW64_PROCESS
15 {
16   PVOID Wow64;
17 } WOW64_PROCESS, *PWOW64_PROCESS;
18 
19 typedef struct _KPROFILE_SOURCE_OBJECT
20 {
21     KPROFILE_SOURCE Source;
22     LIST_ENTRY ListEntry;
23 } KPROFILE_SOURCE_OBJECT, *PKPROFILE_SOURCE_OBJECT;
24 
25 typedef enum _CONNECT_TYPE
26 {
27     NoConnect,
28     NormalConnect,
29     ChainConnect,
30     UnknownConnect
31 } CONNECT_TYPE, *PCONNECT_TYPE;
32 
33 typedef struct _DISPATCH_INFO
34 {
35     CONNECT_TYPE Type;
36     PKINTERRUPT Interrupt;
37     PKINTERRUPT_ROUTINE NoDispatch;
38     PKINTERRUPT_ROUTINE InterruptDispatch;
39     PKINTERRUPT_ROUTINE FloatingDispatch;
40     PKINTERRUPT_ROUTINE ChainedDispatch;
41     PKINTERRUPT_ROUTINE *FlatDispatch;
42 } DISPATCH_INFO, *PDISPATCH_INFO;
43 
44 typedef struct _PROCESS_VALUES
45 {
46     LARGE_INTEGER TotalKernelTime;
47     LARGE_INTEGER TotalUserTime;
48     IO_COUNTERS IoInfo;
49 } PROCESS_VALUES, *PPROCESS_VALUES;
50 
51 typedef struct _DEFERRED_REVERSE_BARRIER
52 {
53     ULONG Barrier;
54     ULONG TotalProcessors;
55 } DEFERRED_REVERSE_BARRIER, *PDEFERRED_REVERSE_BARRIER;
56 
57 typedef struct _KI_SAMPLE_MAP
58 {
59     LARGE_INTEGER PerfStart;
60     LARGE_INTEGER PerfEnd;
61     LONGLONG PerfDelta;
62     LARGE_INTEGER PerfFreq;
63     LONGLONG TSCStart;
64     LONGLONG TSCEnd;
65     LONGLONG TSCDelta;
66     ULONG MHz;
67 } KI_SAMPLE_MAP, *PKI_SAMPLE_MAP;
68 
69 #define MAX_TIMER_DPCS                      16
70 
71 typedef struct _DPC_QUEUE_ENTRY
72 {
73     PKDPC Dpc;
74     PKDEFERRED_ROUTINE Routine;
75     PVOID Context;
76 } DPC_QUEUE_ENTRY, *PDPC_QUEUE_ENTRY;
77 
78 typedef struct _KNMI_HANDLER_CALLBACK
79 {
80     struct _KNMI_HANDLER_CALLBACK* Next;
81     PNMI_CALLBACK Callback;
82     PVOID Context;
83     PVOID Handle;
84 } KNMI_HANDLER_CALLBACK, *PKNMI_HANDLER_CALLBACK;
85 
86 typedef PCHAR
87 (NTAPI *PKE_BUGCHECK_UNICODE_TO_ANSI)(
88     IN PUNICODE_STRING Unicode,
89     IN PCHAR Ansi,
90     IN ULONG Length
91 );
92 
93 extern KAFFINITY KeActiveProcessors;
94 extern PKNMI_HANDLER_CALLBACK KiNmiCallbackListHead;
95 extern KSPIN_LOCK KiNmiCallbackListLock;
96 extern PVOID KeUserApcDispatcher;
97 extern PVOID KeUserCallbackDispatcher;
98 extern PVOID KeUserExceptionDispatcher;
99 extern PVOID KeRaiseUserExceptionDispatcher;
100 extern LARGE_INTEGER KeBootTime;
101 extern ULONGLONG KeBootTimeBias;
102 extern BOOLEAN ExCmosClockIsSane;
103 extern USHORT KeProcessorArchitecture;
104 extern USHORT KeProcessorLevel;
105 extern USHORT KeProcessorRevision;
106 extern ULONG KeFeatureBits;
107 extern KNODE KiNode0;
108 extern PKNODE KeNodeBlock[1];
109 extern UCHAR KeNumberNodes;
110 extern UCHAR KeProcessNodeSeed;
111 extern ETHREAD KiInitialThread;
112 extern EPROCESS KiInitialProcess;
113 extern PULONG KiInterruptTemplateObject;
114 extern PULONG KiInterruptTemplateDispatch;
115 extern PULONG KiInterruptTemplate2ndDispatch;
116 extern ULONG KiUnexpectedEntrySize;
117 extern ULONG_PTR KiDoubleFaultStack;
118 extern EX_PUSH_LOCK KernelAddressSpaceLock;
119 extern ULONG KiMaximumDpcQueueDepth;
120 extern ULONG KiMinimumDpcRate;
121 extern ULONG KiAdjustDpcThreshold;
122 extern ULONG KiIdealDpcRate;
123 extern BOOLEAN KeThreadDpcEnable;
124 extern LARGE_INTEGER KiTimeIncrementReciprocal;
125 extern UCHAR KiTimeIncrementShiftCount;
126 extern ULONG KiTimeLimitIsrMicroseconds;
127 extern ULONG KiServiceLimit;
128 extern LIST_ENTRY KeBugcheckCallbackListHead, KeBugcheckReasonCallbackListHead;
129 extern KSPIN_LOCK BugCheckCallbackLock;
130 extern KDPC KiTimerExpireDpc;
131 extern KTIMER_TABLE_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE];
132 extern FAST_MUTEX KiGenericCallDpcMutex;
133 extern LIST_ENTRY KiProfileListHead, KiProfileSourceListHead;
134 extern KSPIN_LOCK KiProfileLock;
135 extern LIST_ENTRY KiProcessListHead;
136 extern LIST_ENTRY KiProcessInSwapListHead, KiProcessOutSwapListHead;
137 extern LIST_ENTRY KiStackInSwapListHead;
138 extern KEVENT KiSwapEvent;
139 extern PKPRCB KiProcessorBlock[];
140 extern KAFFINITY KiIdleSummary;
141 extern PVOID KeUserApcDispatcher;
142 extern PVOID KeUserCallbackDispatcher;
143 extern PVOID KeUserExceptionDispatcher;
144 extern PVOID KeRaiseUserExceptionDispatcher;
145 extern ULONG KeTimeIncrement;
146 extern ULONG KeTimeAdjustment;
147 extern BOOLEAN KiTimeAdjustmentEnabled;
148 extern LONG KiTickOffset;
149 extern ULONG KiFreezeFlag;
150 extern ULONG KiDPCTimeout;
151 extern PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch;
152 extern ULONGLONG BootCycles, BootCyclesEnd;
153 extern ULONG ProcessCount;
154 extern VOID __cdecl KiInterruptTemplate(VOID);
155 
156 /* MACROS *************************************************************************/
157 
158 #define PRIORITY_MASK(Priority) (1UL << (Priority))
159 
160 /* Tells us if the Timer or Event is a Syncronization or Notification Object */
161 #define TIMER_OR_EVENT_TYPE 0x7L
162 
163 /* One of the Reserved Wait Blocks, this one is for the Thread's Timer */
164 #define TIMER_WAIT_BLOCK 0x3L
165 
166 /* INTERNAL KERNEL FUNCTIONS ************************************************/
167 
168 /* Finds a new thread to run */
169 LONG_PTR
170 FASTCALL
171 KiSwapThread(
172     IN PKTHREAD Thread,
173     IN PKPRCB Prcb
174 );
175 
176 VOID
177 NTAPI
178 KeReadyThread(
179     IN PKTHREAD Thread
180 );
181 
182 BOOLEAN
183 NTAPI
184 KeSetDisableBoostThread(
185     IN OUT PKTHREAD Thread,
186     IN BOOLEAN Disable
187 );
188 
189 BOOLEAN
190 NTAPI
191 KeSetDisableBoostProcess(
192     IN PKPROCESS Process,
193     IN BOOLEAN Disable
194 );
195 
196 BOOLEAN
197 NTAPI
198 KeSetAutoAlignmentProcess(
199     IN PKPROCESS Process,
200     IN BOOLEAN Enable
201 );
202 
203 KAFFINITY
204 NTAPI
205 KeSetAffinityProcess(
206     IN PKPROCESS Process,
207     IN KAFFINITY Affinity
208 );
209 
210 VOID
211 NTAPI
212 KeBoostPriorityThread(
213     IN PKTHREAD Thread,
214     IN KPRIORITY Increment
215 );
216 
217 VOID
218 NTAPI
219 KeBalanceSetManager(IN PVOID Context);
220 
221 VOID
222 NTAPI
223 KiReadyThread(IN PKTHREAD Thread);
224 
225 ULONG
226 NTAPI
227 KeSuspendThread(PKTHREAD Thread);
228 
229 BOOLEAN
230 NTAPI
231 KeReadStateThread(IN PKTHREAD Thread);
232 
233 BOOLEAN
234 FASTCALL
235 KiSwapContext(
236     IN KIRQL WaitIrql,
237     IN PKTHREAD CurrentThread
238 );
239 
240 VOID
241 NTAPI
242 KiAdjustQuantumThread(IN PKTHREAD Thread);
243 
244 VOID
245 FASTCALL
246 KiExitDispatcher(KIRQL OldIrql);
247 
248 VOID
249 FASTCALL
250 KiDeferredReadyThread(IN PKTHREAD Thread);
251 
252 PKTHREAD
253 FASTCALL
254 KiIdleSchedule(
255     IN PKPRCB Prcb
256 );
257 
258 VOID
259 FASTCALL
260 KiProcessDeferredReadyList(
261     IN PKPRCB Prcb
262 );
263 
264 KAFFINITY
265 FASTCALL
266 KiSetAffinityThread(
267     IN PKTHREAD Thread,
268     IN KAFFINITY Affinity
269 );
270 
271 PKTHREAD
272 FASTCALL
273 KiSelectNextThread(
274     IN PKPRCB Prcb
275 );
276 
277 BOOLEAN
278 FASTCALL
279 KiInsertTimerTable(
280     IN PKTIMER Timer,
281     IN ULONG Hand
282 );
283 
284 VOID
285 FASTCALL
286 KiTimerListExpire(
287     IN PLIST_ENTRY ExpiredListHead,
288     IN KIRQL OldIrql
289 );
290 
291 BOOLEAN
292 FASTCALL
293 KiInsertTreeTimer(
294     IN PKTIMER Timer,
295     IN LARGE_INTEGER Interval
296 );
297 
298 VOID
299 FASTCALL
300 KiCompleteTimer(
301     IN PKTIMER Timer,
302     IN PKSPIN_LOCK_QUEUE LockQueue
303 );
304 
305 CODE_SEG("INIT")
306 VOID
307 NTAPI
308 KeStartAllProcessors(
309     VOID
310 );
311 
312 /* gmutex.c ********************************************************************/
313 
314 VOID
315 FASTCALL
316 KiAcquireGuardedMutex(
317     IN OUT PKGUARDED_MUTEX GuardedMutex
318 );
319 
320 VOID
321 FASTCALL
322 KiAcquireFastMutex(
323     IN PFAST_MUTEX FastMutex
324 );
325 
326 /* gate.c **********************************************************************/
327 
328 VOID
329 FASTCALL
330 KeInitializeGate(PKGATE Gate);
331 
332 VOID
333 FASTCALL
334 KeSignalGateBoostPriority(PKGATE Gate);
335 
336 VOID
337 FASTCALL
338 KeWaitForGate(
339     PKGATE Gate,
340     KWAIT_REASON WaitReason,
341     KPROCESSOR_MODE WaitMode
342 );
343 
344 /* ipi.c ********************************************************************/
345 
346 VOID
347 FASTCALL
348 KiIpiSend(
349     KAFFINITY TargetSet,
350     ULONG IpiRequest
351 );
352 
353 VOID
354 NTAPI
355 KiIpiSendPacket(
356     IN KAFFINITY TargetProcessors,
357     IN PKIPI_WORKER WorkerFunction,
358     IN PKIPI_BROADCAST_WORKER BroadcastFunction,
359     IN ULONG_PTR Context,
360     IN PULONG Count
361 );
362 
363 VOID
364 FASTCALL
365 KiIpiSignalPacketDone(
366     IN PKIPI_CONTEXT PacketContext
367 );
368 
369 VOID
370 FASTCALL
371 KiIpiSignalPacketDoneAndStall(
372     IN PKIPI_CONTEXT PacketContext,
373     IN volatile PULONG ReverseStall
374 );
375 
376 /* next file ***************************************************************/
377 
378 UCHAR
379 NTAPI
380 KeFindNextRightSetAffinity(
381     IN UCHAR Number,
382     IN KAFFINITY Set
383 );
384 
385 VOID
386 NTAPI
387 DbgBreakPointNoBugCheck(VOID);
388 
389 VOID
390 NTAPI
391 KeInitializeProfile(
392     struct _KPROFILE* Profile,
393     struct _KPROCESS* Process,
394     PVOID ImageBase,
395     SIZE_T ImageSize,
396     ULONG BucketSize,
397     KPROFILE_SOURCE ProfileSource,
398     KAFFINITY Affinity
399 );
400 
401 BOOLEAN
402 NTAPI
403 KeStartProfile(
404     struct _KPROFILE* Profile,
405     PVOID Buffer
406 );
407 
408 BOOLEAN
409 NTAPI
410 KeStopProfile(struct _KPROFILE* Profile);
411 
412 ULONG
413 NTAPI
414 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource);
415 
416 VOID
417 NTAPI
418 KeSetIntervalProfile(
419     ULONG Interval,
420     KPROFILE_SOURCE ProfileSource
421 );
422 
423 VOID
424 NTAPI
425 KeUpdateRunTime(
426     PKTRAP_FRAME TrapFrame,
427     KIRQL Irql
428 );
429 
430 VOID
431 NTAPI
432 KiExpireTimers(
433     PKDPC Dpc,
434     PVOID DeferredContext,
435     PVOID SystemArgument1,
436     PVOID SystemArgument2
437 );
438 
439 VOID
440 NTAPI
441 KeInitializeThread(
442     IN PKPROCESS Process,
443     IN OUT PKTHREAD Thread,
444     IN PKSYSTEM_ROUTINE SystemRoutine,
445     IN PKSTART_ROUTINE StartRoutine,
446     IN PVOID StartContext,
447     IN PCONTEXT Context,
448     IN PVOID Teb,
449     IN PVOID KernelStack
450 );
451 
452 VOID
453 NTAPI
454 KeUninitThread(
455     IN PKTHREAD Thread
456 );
457 
458 NTSTATUS
459 NTAPI
460 KeInitThread(
461     IN OUT PKTHREAD Thread,
462     IN PVOID KernelStack,
463     IN PKSYSTEM_ROUTINE SystemRoutine,
464     IN PKSTART_ROUTINE StartRoutine,
465     IN PVOID StartContext,
466     IN PCONTEXT Context,
467     IN PVOID Teb,
468     IN PKPROCESS Process
469 );
470 
471 VOID
472 NTAPI
473 KiInitializeContextThread(
474     PKTHREAD Thread,
475     PKSYSTEM_ROUTINE SystemRoutine,
476     PKSTART_ROUTINE StartRoutine,
477     PVOID StartContext,
478     PCONTEXT Context
479 );
480 
481 VOID
482 NTAPI
483 KeStartThread(
484     IN OUT PKTHREAD Thread
485 );
486 
487 BOOLEAN
488 NTAPI
489 KeAlertThread(
490     IN PKTHREAD Thread,
491     IN KPROCESSOR_MODE AlertMode
492 );
493 
494 ULONG
495 NTAPI
496 KeAlertResumeThread(
497     IN PKTHREAD Thread
498 );
499 
500 ULONG
501 NTAPI
502 KeResumeThread(
503     IN PKTHREAD Thread
504 );
505 
506 PVOID
507 NTAPI
508 KeSwitchKernelStack(
509     IN PVOID StackBase,
510     IN PVOID StackLimit
511 );
512 
513 VOID
514 NTAPI
515 KeRundownThread(VOID);
516 
517 NTSTATUS
518 NTAPI
519 KeReleaseThread(PKTHREAD Thread);
520 
521 VOID
522 NTAPI
523 KiSuspendRundown(
524     IN PKAPC Apc
525 );
526 
527 VOID
528 NTAPI
529 KiSuspendNop(
530     IN PKAPC Apc,
531     IN PKNORMAL_ROUTINE *NormalRoutine,
532     IN PVOID *NormalContext,
533     IN PVOID *SystemArgument1,
534     IN PVOID *SystemArgument2
535 );
536 
537 VOID
538 NTAPI
539 KiSuspendThread(
540     IN PVOID NormalContext,
541     IN PVOID SystemArgument1,
542     IN PVOID SystemArgument2
543 );
544 
545 LONG
546 NTAPI
547 KeQueryBasePriorityThread(IN PKTHREAD Thread);
548 
549 VOID
550 FASTCALL
551 KiSetPriorityThread(
552     IN PKTHREAD Thread,
553     IN KPRIORITY Priority
554 );
555 
556 VOID
557 FASTCALL
558 KiUnlinkThread(
559     IN PKTHREAD Thread,
560     IN LONG_PTR WaitStatus
561 );
562 
563 VOID
564 NTAPI
565 KeDumpStackFrames(PULONG Frame);
566 
567 BOOLEAN
568 NTAPI
569 KiTestAlert(VOID);
570 
571 VOID
572 FASTCALL
573 KiUnwaitThread(
574     IN PKTHREAD Thread,
575     IN LONG_PTR WaitStatus,
576     IN KPRIORITY Increment
577 );
578 
579 VOID
580 NTAPI
581 KeInitializeProcess(
582     struct _KPROCESS *Process,
583     KPRIORITY Priority,
584     KAFFINITY Affinity,
585     PULONG_PTR DirectoryTableBase,
586     IN BOOLEAN Enable
587 );
588 
589 VOID
590 NTAPI
591 KeSetQuantumProcess(
592     IN PKPROCESS Process,
593     IN UCHAR Quantum
594 );
595 
596 KPRIORITY
597 NTAPI
598 KeSetPriorityAndQuantumProcess(
599     IN PKPROCESS Process,
600     IN KPRIORITY Priority,
601     IN UCHAR Quantum OPTIONAL
602 );
603 
604 ULONG
605 NTAPI
606 KeForceResumeThread(IN PKTHREAD Thread);
607 
608 VOID
609 NTAPI
610 KeThawAllThreads(
611     VOID
612 );
613 
614 VOID
615 NTAPI
616 KeFreezeAllThreads(
617     VOID
618 );
619 
620 BOOLEAN
621 NTAPI
622 KeDisableThreadApcQueueing(IN PKTHREAD Thread);
623 
624 VOID
625 FASTCALL
626 KiWaitTest(
627     PVOID Object,
628     KPRIORITY Increment
629 );
630 
631 VOID
632 NTAPI
633 KeContextToTrapFrame(
634     PCONTEXT Context,
635     PKEXCEPTION_FRAME ExeptionFrame,
636     PKTRAP_FRAME TrapFrame,
637     ULONG ContextFlags,
638     KPROCESSOR_MODE PreviousMode
639 );
640 
641 VOID
642 NTAPI
643 Ke386SetIOPL(VOID);
644 
645 VOID
646 NTAPI
647 KiCheckForKernelApcDelivery(VOID);
648 
649 LONG
650 NTAPI
651 KiInsertQueue(
652     IN PKQUEUE Queue,
653     IN PLIST_ENTRY Entry,
654     BOOLEAN Head
655 );
656 
657 VOID
658 NTAPI
659 KiTimerExpiration(
660     IN PKDPC Dpc,
661     IN PVOID DeferredContext,
662     IN PVOID SystemArgument1,
663     IN PVOID SystemArgument2
664 );
665 
666 ULONG
667 NTAPI
668 KeSetProcess(
669     struct _KPROCESS* Process,
670     KPRIORITY Increment,
671     BOOLEAN InWait
672 );
673 
674 VOID
675 NTAPI
676 KeInitializeEventPair(PKEVENT_PAIR EventPair);
677 
678 VOID
679 NTAPI
680 KiInitializeUserApc(
681     IN PKEXCEPTION_FRAME Reserved,
682     IN PKTRAP_FRAME TrapFrame,
683     IN PKNORMAL_ROUTINE NormalRoutine,
684     IN PVOID NormalContext,
685     IN PVOID SystemArgument1,
686     IN PVOID SystemArgument2
687 );
688 
689 PLIST_ENTRY
690 NTAPI
691 KeFlushQueueApc(
692     IN PKTHREAD Thread,
693     IN KPROCESSOR_MODE PreviousMode
694 );
695 
696 VOID
697 NTAPI
698 KiAttachProcess(
699     struct _KTHREAD *Thread,
700     struct _KPROCESS *Process,
701     PKLOCK_QUEUE_HANDLE ApcLock,
702     struct _KAPC_STATE *SavedApcState
703 );
704 
705 VOID
706 NTAPI
707 KiSwapProcess(
708     struct _KPROCESS *NewProcess,
709     struct _KPROCESS *OldProcess
710 );
711 
712 BOOLEAN
713 NTAPI
714 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode);
715 
716 BOOLEAN
717 NTAPI
718 KeRemoveQueueApc(PKAPC Apc);
719 
720 VOID
721 FASTCALL
722 KiActivateWaiterQueue(IN PKQUEUE Queue);
723 
724 ULONG
725 NTAPI
726 KeQueryRuntimeProcess(IN PKPROCESS Process,
727                       OUT PULONG UserTime);
728 
729 VOID
730 NTAPI
731 KeQueryValuesProcess(IN PKPROCESS Process,
732                      PPROCESS_VALUES Values);
733 
734 /* INITIALIZATION FUNCTIONS *************************************************/
735 
736 CODE_SEG("INIT")
737 BOOLEAN
738 NTAPI
739 KeInitSystem(VOID);
740 
741 CODE_SEG("INIT")
742 VOID
743 NTAPI
744 KeInitExceptions(VOID);
745 
746 VOID
747 NTAPI
748 KeInitInterrupts(VOID);
749 
750 CODE_SEG("INIT")
751 VOID
752 NTAPI
753 KiInitializeBugCheck(VOID);
754 
755 DECLSPEC_NORETURN
756 CODE_SEG("INIT")
757 VOID
758 NTAPI
759 KiSystemStartup(
760     IN PLOADER_PARAMETER_BLOCK LoaderBlock
761 );
762 
763 BOOLEAN
764 NTAPI
765 KiDeliverUserApc(PKTRAP_FRAME TrapFrame);
766 
767 VOID
768 NTAPI
769 KiMoveApcState(
770     PKAPC_STATE OldState,
771     PKAPC_STATE NewState
772 );
773 
774 VOID
775 NTAPI
776 KiAddProfileEvent(
777     KPROFILE_SOURCE Source,
778     ULONG Pc
779 );
780 
781 VOID
782 NTAPI
783 KiDispatchException(
784     PEXCEPTION_RECORD ExceptionRecord,
785     PKEXCEPTION_FRAME ExceptionFrame,
786     PKTRAP_FRAME Tf,
787     KPROCESSOR_MODE PreviousMode,
788     BOOLEAN SearchFrames
789 );
790 
791 VOID
792 NTAPI
793 KeTrapFrameToContext(
794     IN PKTRAP_FRAME TrapFrame,
795     IN PKEXCEPTION_FRAME ExceptionFrame,
796     IN OUT PCONTEXT Context
797 );
798 
799 DECLSPEC_NORETURN
800 VOID
801 NTAPI
802 KeBugCheckWithTf(
803     ULONG BugCheckCode,
804     ULONG_PTR BugCheckParameter1,
805     ULONG_PTR BugCheckParameter2,
806     ULONG_PTR BugCheckParameter3,
807     ULONG_PTR BugCheckParameter4,
808     PKTRAP_FRAME Tf
809 );
810 
811 BOOLEAN
812 NTAPI
813 KiHandleNmi(VOID);
814 
815 VOID
816 NTAPI
817 KeFlushCurrentTb(VOID);
818 
819 BOOLEAN
820 NTAPI
821 KeInvalidateAllCaches(VOID);
822 
823 VOID
824 FASTCALL
825 KeZeroPages(IN PVOID Address,
826             IN ULONG Size);
827 
828 BOOLEAN
829 FASTCALL
830 KeInvalidAccessAllowed(IN PVOID TrapInformation OPTIONAL);
831 
832 VOID
833 NTAPI
834 KeRosDumpStackFrames(
835     PULONG_PTR Frame,
836     ULONG FrameCount
837 );
838 
839 VOID
840 NTAPI
841 KeSetSystemTime(
842     IN PLARGE_INTEGER NewSystemTime,
843     OUT PLARGE_INTEGER OldSystemTime,
844     IN BOOLEAN FixInterruptTime,
845     IN PLARGE_INTEGER HalTime
846 );
847 
848 ULONG
849 NTAPI
850 KeV86Exception(
851     ULONG ExceptionNr,
852     PKTRAP_FRAME Tf,
853     ULONG address
854 );
855 
856 VOID
857 NTAPI
858 KiStartUnexpectedRange(
859     VOID
860 );
861 
862 VOID
863 NTAPI
864 KiEndUnexpectedRange(
865     VOID
866 );
867 
868 NTSTATUS
869 NTAPI
870 KiRaiseException(
871     IN PEXCEPTION_RECORD ExceptionRecord,
872     IN PCONTEXT Context,
873     IN PKEXCEPTION_FRAME ExceptionFrame,
874     IN PKTRAP_FRAME TrapFrame,
875     IN BOOLEAN SearchFrames
876 );
877 
878 NTSTATUS
879 NTAPI
880 KiContinue(
881     IN PCONTEXT Context,
882     IN PKEXCEPTION_FRAME ExceptionFrame,
883     IN PKTRAP_FRAME TrapFrame
884 );
885 
886 #ifndef _M_AMD64
887 VOID
888 FASTCALL
889 KiInterruptDispatch(
890     IN PKTRAP_FRAME TrapFrame,
891     IN PKINTERRUPT Interrupt
892 );
893 #endif
894 
895 VOID
896 FASTCALL
897 KiChainedDispatch(
898     IN PKTRAP_FRAME TrapFrame,
899     IN PKINTERRUPT Interrupt
900 );
901 
902 CODE_SEG("INIT")
903 VOID
904 NTAPI
905 KiInitializeMachineType(
906     VOID
907 );
908 
909 VOID
910 NTAPI
911 KiSetupStackAndInitializeKernel(
912     IN PKPROCESS InitProcess,
913     IN PKTHREAD InitThread,
914     IN PVOID IdleStack,
915     IN PKPRCB Prcb,
916     IN CCHAR Number,
917     IN PLOADER_PARAMETER_BLOCK LoaderBlock
918 );
919 
920 CODE_SEG("INIT")
921 VOID
922 NTAPI
923 KiInitSpinLocks(
924     IN PKPRCB Prcb,
925     IN CCHAR Number
926 );
927 
928 CODE_SEG("INIT")
929 LARGE_INTEGER
930 NTAPI
931 KiComputeReciprocal(
932     IN LONG Divisor,
933     OUT PUCHAR Shift
934 );
935 
936 CODE_SEG("INIT")
937 VOID
938 NTAPI
939 KiInitSystem(
940     VOID
941 );
942 
943 VOID
944 FASTCALL
945 KiInsertQueueApc(
946     IN PKAPC Apc,
947     IN KPRIORITY PriorityBoost
948 );
949 
950 NTSTATUS
951 NTAPI
952 KiCallUserMode(
953     IN PVOID *OutputBuffer,
954     IN PULONG OutputLength
955 );
956 
957 DECLSPEC_NORETURN
958 VOID
959 FASTCALL
960 KiCallbackReturn(
961     IN PVOID Stack,
962     IN NTSTATUS Status
963 );
964 
965 CODE_SEG("INIT")
966 VOID
967 NTAPI
968 KiInitMachineDependent(VOID);
969 
970 VOID
971 NTAPI
972 KxFreezeExecution(
973     VOID);
974 
975 VOID
976 NTAPI
977 KxThawExecution(
978     VOID);
979 
980 BOOLEAN
981 NTAPI
982 KeFreezeExecution(IN PKTRAP_FRAME TrapFrame,
983                   IN PKEXCEPTION_FRAME ExceptionFrame);
984 
985 VOID
986 NTAPI
987 KeThawExecution(IN BOOLEAN Enable);
988 
989 KCONTINUE_STATUS
990 NTAPI
991 KxSwitchKdProcessor(
992     _In_ ULONG ProcessorIndex);
993 
994 _IRQL_requires_min_(DISPATCH_LEVEL)
995 _Acquires_nonreentrant_lock_(*LockHandle->Lock)
996 _Acquires_exclusive_lock_(*LockHandle->Lock)
997 VOID
998 FASTCALL
999 KeAcquireQueuedSpinLockAtDpcLevel(
1000     _Inout_ PKSPIN_LOCK_QUEUE LockQueue
1001 );
1002 
1003 _IRQL_requires_min_(DISPATCH_LEVEL)
1004 _Releases_nonreentrant_lock_(*LockHandle->Lock)
1005 _Releases_exclusive_lock_(*LockHandle->Lock)
1006 VOID
1007 FASTCALL
1008 KeReleaseQueuedSpinLockFromDpcLevel(
1009     _Inout_ PKSPIN_LOCK_QUEUE LockQueue
1010 );
1011 
1012 VOID
1013 NTAPI
1014 KiRestoreProcessorControlState(
1015     IN PKPROCESSOR_STATE ProcessorState
1016 );
1017 
1018 VOID
1019 NTAPI
1020 KiSaveProcessorControlState(
1021     OUT PKPROCESSOR_STATE ProcessorState
1022 );
1023 
1024 VOID
1025 NTAPI
1026 KiSaveProcessorState(
1027     _In_ PKTRAP_FRAME TrapFrame,
1028     _In_ PKEXCEPTION_FRAME ExceptionFrame);
1029 
1030 VOID
1031 NTAPI
1032 KiRestoreProcessorState(
1033     _Out_ PKTRAP_FRAME TrapFrame,
1034     _Out_ PKEXCEPTION_FRAME ExceptionFrame);
1035 
1036 VOID
1037 FASTCALL
1038 KiRetireDpcList(
1039     IN PKPRCB Prcb
1040 );
1041 
1042 VOID
1043 NTAPI
1044 KiQuantumEnd(
1045     VOID
1046 );
1047 
1048 DECLSPEC_NORETURN
1049 VOID
1050 KiIdleLoop(
1051     VOID
1052 );
1053 
1054 DECLSPEC_NORETURN
1055 VOID
1056 FASTCALL
1057 KiSystemFatalException(
1058     IN ULONG ExceptionCode,
1059     IN PKTRAP_FRAME TrapFrame
1060 );
1061 
1062 PVOID
1063 NTAPI
1064 KiPcToFileHeader(IN PVOID Eip,
1065                  OUT PLDR_DATA_TABLE_ENTRY *LdrEntry,
1066                  IN BOOLEAN DriversOnly,
1067                  OUT PBOOLEAN InKernel);
1068 
1069 PVOID
1070 NTAPI
1071 KiRosPcToUserFileHeader(IN PVOID Eip,
1072                         OUT PLDR_DATA_TABLE_ENTRY *LdrEntry);
1073 
1074 PCHAR
1075 NTAPI
1076 KeBugCheckUnicodeToAnsi(
1077     IN PUNICODE_STRING Unicode,
1078     OUT PCHAR Ansi,
1079     IN ULONG Length
1080 );
1081 
1082 #ifdef __cplusplus
1083 } // extern "C"
1084 
1085 namespace ntoskrnl
1086 {
1087 
1088 /* Like std::lock_guard, but for a Queued Spinlock */
1089 template <KSPIN_LOCK_QUEUE_NUMBER n>
1090 class KiQueuedSpinLockGuard
1091 {
1092 private:
1093     KIRQL m_OldIrql;
1094 public:
1095 
_Requires_lock_not_held_(n)1096     _Requires_lock_not_held_(n)
1097     _Acquires_lock_(n)
1098     _IRQL_raises_(DISPATCH_LEVEL)
1099     explicit KiQueuedSpinLockGuard()
1100     {
1101         m_OldIrql = KeAcquireQueuedSpinLock(n);
1102     }
1103 
1104     _Requires_lock_held_(n)
_Releases_lock_(n)1105     _Releases_lock_(n)
1106     ~KiQueuedSpinLockGuard()
1107     {
1108         KeReleaseQueuedSpinLock(n, m_OldIrql);
1109     }
1110 
1111 private:
1112     KiQueuedSpinLockGuard(KiQueuedSpinLockGuard const&) = delete;
1113     KiQueuedSpinLockGuard& operator=(KiQueuedSpinLockGuard const&) = delete;
1114 };
1115 
1116 }
1117 
1118 #endif
1119 
1120 #include "ke_x.h"
1121