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