1 /*++ NDK Version: 0098 2 3 Copyright (c) Alex Ionescu. All rights reserved. 4 5 Header Name: 6 7 kefuncs.h 8 9 Abstract: 10 11 Functions definitions for the Kernel services. 12 13 Author: 14 15 Alex Ionescu (alexi@tinykrnl.org) - Updated - 27-Feb-2006 16 17 --*/ 18 19 #ifndef _KEFUNCS_H 20 #define _KEFUNCS_H 21 22 // 23 // Dependencies 24 // 25 #include <umtypes.h> 26 #include <ketypes.h> 27 #include <section_attribs.h> 28 29 #ifdef __cplusplus 30 extern "C" 31 { 32 #endif 33 34 #ifndef NTOS_MODE_USER 35 36 // 37 // APC Functions 38 // 39 VOID 40 NTAPI 41 KeInitializeApc( 42 _In_ PKAPC Apc, 43 _In_ PKTHREAD Thread, 44 _In_ KAPC_ENVIRONMENT TargetEnvironment, 45 _In_ PKKERNEL_ROUTINE KernelRoutine, 46 _In_opt_ PKRUNDOWN_ROUTINE RundownRoutine, 47 _In_ PKNORMAL_ROUTINE NormalRoutine, 48 _In_ KPROCESSOR_MODE Mode, 49 _In_ PVOID Context 50 ); 51 52 BOOLEAN 53 NTAPI 54 KeInsertQueueApc( 55 _In_ PKAPC Apc, 56 _In_ PVOID SystemArgument1, 57 _In_ PVOID SystemArgument2, 58 _In_ KPRIORITY PriorityBoost 59 ); 60 61 VOID 62 NTAPI 63 KiDeliverApc( 64 _In_ KPROCESSOR_MODE PreviousMode, 65 #ifdef _M_AMD64 66 _In_ PKEXCEPTION_FRAME ExceptionFrame, 67 #else 68 _Reserved_ PKEXCEPTION_FRAME ExceptionFrame, 69 #endif 70 _In_ PKTRAP_FRAME TrapFrame 71 ); 72 73 // 74 // Process/Thread Functions 75 // 76 VOID 77 NTAPI 78 KeTerminateThread( 79 _In_ KPRIORITY Increment 80 ); 81 82 BOOLEAN 83 NTAPI 84 KeIsAttachedProcess( 85 VOID 86 ); 87 88 VOID 89 NTAPI 90 KeSetEventBoostPriority( 91 _In_ PKEVENT Event, 92 _In_opt_ PKTHREAD *Thread 93 ); 94 95 KAFFINITY 96 NTAPI 97 KeSetAffinityThread( 98 _Inout_ PKTHREAD Thread, 99 _In_ KAFFINITY Affinity 100 ); 101 102 PKPROCESS 103 NTAPI 104 KeGetCurrentProcess( 105 VOID 106 ); 107 108 BOOLEAN 109 NTAPI 110 KeAddSystemServiceTable( 111 _In_ PULONG_PTR Base, 112 _In_opt_ PULONG Count, 113 _In_ ULONG Limit, 114 _In_ PUCHAR Number, 115 _In_ ULONG Index 116 ); 117 118 // 119 // Spinlock Functions 120 // 121 VOID 122 FASTCALL 123 KiAcquireSpinLock( 124 _Inout_ PKSPIN_LOCK SpinLock 125 ); 126 127 VOID 128 FASTCALL 129 KiReleaseSpinLock( 130 _Inout_ PKSPIN_LOCK SpinLock 131 ); 132 133 KIRQL 134 FASTCALL 135 KeAcquireQueuedSpinLockRaiseToSynch( 136 _In_ KSPIN_LOCK_QUEUE_NUMBER LockNumber 137 ); 138 139 BOOLEAN 140 FASTCALL 141 KeTryToAcquireQueuedSpinLockRaiseToSynch( 142 _In_ KSPIN_LOCK_QUEUE_NUMBER LockNumber, 143 _In_ PKIRQL OldIrql 144 ); 145 146 VOID 147 FASTCALL 148 KeAcquireInStackQueuedSpinLockRaiseToSynch( 149 _In_ PKSPIN_LOCK SpinLock, 150 _In_ PKLOCK_QUEUE_HANDLE LockHandle 151 ); 152 153 154 // 155 // Interrupt Functions 156 // 157 VOID 158 NTAPI 159 KeInitializeInterrupt( 160 _Out_ PKINTERRUPT InterruptObject, 161 _In_ PKSERVICE_ROUTINE ServiceRoutine, 162 _In_ PVOID ServiceContext, 163 _In_ PKSPIN_LOCK SpinLock, 164 _In_ ULONG Vector, 165 _In_ KIRQL Irql, 166 _In_ KIRQL SynchronizeIrql, 167 _In_ KINTERRUPT_MODE InterruptMode, 168 _In_ BOOLEAN ShareVector, 169 _In_ CHAR ProcessorNumber, 170 _In_ BOOLEAN FloatingSave 171 ); 172 173 BOOLEAN 174 NTAPI 175 KeConnectInterrupt( 176 _Inout_ PKINTERRUPT InterruptObject 177 ); 178 179 BOOLEAN 180 NTAPI 181 KeDisconnectInterrupt( 182 _Inout_ PKINTERRUPT InterruptObject 183 ); 184 185 VOID 186 NTAPI 187 KiDispatchInterrupt( 188 VOID 189 ); 190 191 VOID 192 NTAPI 193 KiCoprocessorError( 194 VOID 195 ); 196 197 DECLSPEC_NORETURN 198 VOID 199 __cdecl 200 KiUnexpectedInterrupt( 201 VOID 202 ); 203 204 VOID 205 NTAPI 206 KeEnterKernelDebugger( 207 VOID 208 ); 209 210 BOOLEAN 211 NTAPI 212 KeIsExecutingDpc( 213 VOID 214 ); 215 216 BOOLEAN 217 NTAPI 218 KiIpiServiceRoutine( 219 _In_ PKTRAP_FRAME TrapFrame, 220 #ifdef _M_AMD64 221 _In_ PKEXCEPTION_FRAME ExceptionFrame 222 #else 223 _Reserved_ PKEXCEPTION_FRAME ExceptionFrame 224 #endif 225 ); 226 227 // 228 // Generic DPC Routines 229 // 230 VOID 231 NTAPI 232 KeGenericCallDpc( 233 _In_ PKDEFERRED_ROUTINE Routine, 234 _In_ PVOID Context 235 ); 236 237 VOID 238 NTAPI 239 KeSignalCallDpcDone( 240 _In_ PVOID SystemArgument1 241 ); 242 243 BOOLEAN 244 NTAPI 245 KeSignalCallDpcSynchronize( 246 _In_ PVOID SystemArgument2 247 ); 248 249 // 250 // ARC Configuration Functions. Only enabled if you have ARC Support 251 // 252 #ifdef _ARC_ 253 PCONFIGURATION_COMPONENT_DATA 254 NTAPI 255 KeFindConfigurationNextEntry( 256 _In_ PCONFIGURATION_COMPONENT_DATA Child, 257 _In_ CONFIGURATION_CLASS Class, 258 _In_ CONFIGURATION_TYPE Type, 259 _In_opt_ PULONG ComponentKey, 260 _In_ PCONFIGURATION_COMPONENT_DATA *NextLink 261 ); 262 263 PCONFIGURATION_COMPONENT_DATA 264 NTAPI 265 KeFindConfigurationEntry( 266 _In_ PCONFIGURATION_COMPONENT_DATA Child, 267 _In_ CONFIGURATION_CLASS Class, 268 _In_ CONFIGURATION_TYPE Type, 269 _In_opt_ PULONG ComponentKey 270 ); 271 #endif 272 273 // 274 // Low-level Hardware/CPU Control Functions 275 // 276 VOID 277 NTAPI 278 KeFlushEntireTb( 279 _In_ BOOLEAN Invalid, 280 _In_ BOOLEAN AllProcessors 281 ); 282 283 VOID 284 NTAPI 285 KeSetDmaIoCoherency( 286 _In_ ULONG Coherency 287 ); 288 289 VOID 290 KeSetGdtSelector( 291 _In_ ULONG Entry, 292 _In_ ULONG Value1, 293 _In_ ULONG Value2 294 ); 295 296 VOID 297 NTAPI 298 KeProfileInterrupt( 299 _In_ PKTRAP_FRAME TrapFrame 300 ); 301 302 VOID 303 NTAPI 304 KeProfileInterruptWithSource( 305 _In_ PKTRAP_FRAME TrapFrame, 306 _In_ KPROFILE_SOURCE Source 307 ); 308 309 VOID 310 NTAPI 311 KeSetProfileIrql( 312 _In_ KIRQL ProfileIrql 313 ); 314 315 VOID 316 NTAPI 317 KeSetTimeIncrement( 318 _In_ ULONG MaxIncrement, 319 _In_ ULONG MinIncrement 320 ); 321 322 NTSTATUS 323 NTAPI 324 Ke386CallBios( 325 _In_ ULONG BiosCommand, 326 _Inout_ PCONTEXT BiosArguments 327 ); 328 329 // 330 // Misc. Functions 331 // 332 NTSTATUS 333 NTAPI 334 KeUserModeCallback( 335 _In_ ULONG FunctionID, 336 _In_reads_opt_(InputLength) PVOID InputBuffer, 337 _In_ ULONG InputLength, 338 _Outptr_result_buffer_(*OutputLength) PVOID *OutputBuffer, 339 _Out_ PULONG OutputLength 340 ); 341 342 NTSTATUS 343 NTAPI 344 KeRaiseUserException( 345 _In_ NTSTATUS ExceptionCode 346 ); 347 348 #endif 349 350 // 351 // Native Calls 352 // 353 NTSYSCALLAPI 354 NTSTATUS 355 NTAPI 356 NtContinue( 357 _In_ PCONTEXT Context, 358 _In_ BOOLEAN TestAlert 359 ); 360 361 NTSYSCALLAPI 362 NTSTATUS 363 NTAPI 364 NtCallbackReturn( 365 _In_ PVOID Result, 366 _In_ ULONG ResultLength, 367 _In_ NTSTATUS Status 368 ); 369 370 NTSYSCALLAPI 371 NTSTATUS 372 NTAPI 373 NtCreateProfile( 374 _Out_ PHANDLE ProfileHandle, 375 _In_ HANDLE ProcessHandle, 376 _In_ PVOID ImageBase, 377 _In_ SIZE_T ImageSize, 378 _In_ ULONG Granularity, 379 _Out_ PVOID Buffer, 380 _In_ ULONG ProfilingSize, 381 _In_ KPROFILE_SOURCE Source, 382 _In_ KAFFINITY ProcessorMask 383 ); 384 385 NTSYSCALLAPI 386 NTSTATUS 387 NTAPI 388 NtCreateProfileEx( 389 _Out_ PHANDLE ProfileHandle, 390 _In_ HANDLE ProcessHandle, 391 _In_ PVOID ImageBase, 392 _In_ SIZE_T ImageSize, 393 _In_ ULONG Granularity, 394 _Out_ PVOID Buffer, 395 _In_ ULONG ProfilingSize, 396 _In_ KPROFILE_SOURCE Source, 397 _In_ USHORT GroupCount, 398 _In_reads_(GroupCount) PGROUP_AFFINITY Affinity 399 ); 400 401 NTSYSCALLAPI 402 NTSTATUS 403 NTAPI 404 NtDelayExecution( 405 _In_ BOOLEAN Alertable, 406 _In_ LARGE_INTEGER *Interval 407 ); 408 409 ULONG 410 NTAPI 411 NtGetCurrentProcessorNumber( 412 VOID 413 ); 414 415 NTSYSCALLAPI 416 NTSTATUS 417 NTAPI 418 NtGetContextThread( 419 _In_ HANDLE ThreadHandle, 420 _Out_ PCONTEXT Context 421 ); 422 423 NTSYSCALLAPI 424 ULONG 425 NTAPI 426 NtGetTickCount( 427 VOID 428 ); 429 430 NTSYSCALLAPI 431 NTSTATUS 432 NTAPI 433 NtQueryIntervalProfile( 434 _In_ KPROFILE_SOURCE ProfileSource, 435 _Out_ PULONG Interval 436 ); 437 438 NTSYSCALLAPI 439 NTSTATUS 440 NTAPI 441 NtQueryPerformanceCounter( 442 _Out_ PLARGE_INTEGER Counter, 443 _Out_opt_ PLARGE_INTEGER Frequency 444 ); 445 446 NTSYSCALLAPI 447 NTSTATUS 448 NTAPI 449 NtQuerySystemTime( 450 _Out_ PLARGE_INTEGER CurrentTime 451 ); 452 453 NTSYSCALLAPI 454 NTSTATUS 455 NTAPI 456 NtQueryTimerResolution( 457 _Out_ PULONG MinimumResolution, 458 _Out_ PULONG MaximumResolution, 459 _Out_ PULONG ActualResolution 460 ); 461 462 NTSYSCALLAPI 463 NTSTATUS 464 NTAPI 465 NtQueueApcThread( 466 _In_ HANDLE ThreadHandle, 467 _In_ PKNORMAL_ROUTINE ApcRoutine, 468 _In_opt_ PVOID NormalContext, 469 _In_opt_ PVOID SystemArgument1, 470 _In_opt_ PVOID SystemArgument2 471 ); 472 473 NTSYSCALLAPI 474 NTSTATUS 475 NTAPI 476 NtQueueApcThreadEx( 477 _In_ HANDLE ThreadHandle, 478 _In_opt_ HANDLE UserApcReserveHandle, 479 _In_ PKNORMAL_ROUTINE ApcRoutine, 480 _In_opt_ PVOID NormalContext, 481 _In_opt_ PVOID SystemArgument1, 482 _In_opt_ PVOID SystemArgument2 483 ); 484 485 NTSYSCALLAPI 486 NTSTATUS 487 NTAPI 488 NtRaiseException( 489 _In_ PEXCEPTION_RECORD ExceptionRecord, 490 _In_ PCONTEXT Context, 491 _In_ BOOLEAN SearchFrames 492 ); 493 494 NTSYSCALLAPI 495 NTSTATUS 496 NTAPI 497 NtSetContextThread( 498 _In_ HANDLE ThreadHandle, 499 _In_ PCONTEXT Context 500 ); 501 502 NTSYSCALLAPI 503 NTSTATUS 504 NTAPI 505 NtSetIntervalProfile( 506 _In_ ULONG Interval, 507 _In_ KPROFILE_SOURCE ClockSource 508 ); 509 510 NTSYSCALLAPI 511 NTSTATUS 512 NTAPI 513 NtSetLdtEntries( 514 _In_ ULONG Selector1, 515 _In_ LDT_ENTRY LdtEntry1, 516 _In_ ULONG Selector2, 517 _In_ LDT_ENTRY LdtEntry2 518 ); 519 520 NTSYSCALLAPI 521 NTSTATUS 522 NTAPI 523 NtSetSystemTime( 524 _In_ PLARGE_INTEGER SystemTime, 525 _In_opt_ PLARGE_INTEGER NewSystemTime 526 ); 527 528 NTSYSCALLAPI 529 NTSTATUS 530 NTAPI 531 NtSetTimerResolution( 532 _In_ ULONG RequestedResolution, 533 _In_ BOOLEAN SetOrUnset, 534 _Out_ PULONG ActualResolution 535 ); 536 537 NTSYSCALLAPI 538 NTSTATUS 539 NTAPI 540 NtStartProfile( 541 _In_ HANDLE ProfileHandle 542 ); 543 544 NTSYSCALLAPI 545 NTSTATUS 546 NTAPI 547 NtStopProfile( 548 _In_ HANDLE ProfileHandle 549 ); 550 551 NTSYSCALLAPI 552 NTSTATUS 553 NTAPI 554 NtTestAlert( 555 VOID 556 ); 557 558 NTSYSCALLAPI 559 NTSTATUS 560 NTAPI 561 NtVdmControl( 562 _In_ ULONG ControlCode, 563 _In_ PVOID ControlData 564 ); 565 566 NTSYSCALLAPI 567 NTSTATUS 568 NTAPI 569 NtW32Call( 570 _In_ ULONG RoutineIndex, 571 _In_ PVOID Argument, 572 _In_ ULONG ArgumentLength, 573 _Out_opt_ PVOID* Result, 574 _Out_opt_ PULONG ResultLength 575 ); 576 577 NTSYSCALLAPI 578 NTSTATUS 579 NTAPI 580 NtYieldExecution( 581 VOID 582 ); 583 584 NTSYSAPI 585 NTSTATUS 586 NTAPI 587 ZwContinue( 588 _In_ PCONTEXT Context, 589 _In_ BOOLEAN TestAlert 590 ); 591 592 NTSYSAPI 593 NTSTATUS 594 NTAPI 595 ZwCallbackReturn( 596 _In_ PVOID Result, 597 _In_ ULONG ResultLength, 598 _In_ NTSTATUS Status 599 ); 600 601 NTSYSAPI 602 NTSTATUS 603 NTAPI 604 ZwCreateProfile( 605 _Out_ PHANDLE ProfileHandle, 606 _In_ HANDLE ProcessHandle, 607 _In_ PVOID ImageBase, 608 _In_ ULONG ImageSize, 609 _In_ ULONG Granularity, 610 _Out_ PVOID Buffer, 611 _In_ ULONG ProfilingSize, 612 _In_ KPROFILE_SOURCE Source, 613 _In_ KAFFINITY ProcessorMask 614 ); 615 616 NTSYSAPI 617 NTSTATUS 618 NTAPI 619 ZwDelayExecution( 620 _In_ BOOLEAN Alertable, 621 _In_ LARGE_INTEGER *Interval 622 ); 623 624 NTSYSAPI 625 NTSTATUS 626 NTAPI 627 ZwFlushInstructionCache( 628 _In_ HANDLE ProcessHandle, 629 _In_ PVOID BaseAddress, 630 _In_ ULONG NumberOfBytesToFlush 631 ); 632 633 NTSYSAPI 634 NTSTATUS 635 NTAPI 636 ZwGetContextThread( 637 _In_ HANDLE ThreadHandle, 638 _Out_ PCONTEXT Context 639 ); 640 641 NTSYSAPI 642 ULONG 643 NTAPI 644 ZwGetTickCount( 645 VOID 646 ); 647 648 NTSYSAPI 649 NTSTATUS 650 NTAPI 651 ZwQueryIntervalProfile( 652 _In_ KPROFILE_SOURCE ProfileSource, 653 _Out_ PULONG Interval 654 ); 655 656 NTSYSAPI 657 NTSTATUS 658 NTAPI 659 ZwQueryPerformanceCounter( 660 _Out_ PLARGE_INTEGER Counter, 661 _Out_opt_ PLARGE_INTEGER Frequency 662 ); 663 664 NTSYSAPI 665 NTSTATUS 666 NTAPI 667 ZwQuerySystemTime( 668 _Out_ PLARGE_INTEGER CurrentTime 669 ); 670 671 NTSYSAPI 672 NTSTATUS 673 NTAPI 674 ZwQueryTimerResolution( 675 _Out_ PULONG MinimumResolution, 676 _Out_ PULONG MaximumResolution, 677 _Out_ PULONG ActualResolution 678 ); 679 680 NTSYSAPI 681 NTSTATUS 682 NTAPI 683 ZwQueueApcThread( 684 _In_ HANDLE ThreadHandle, 685 _In_ PKNORMAL_ROUTINE ApcRoutine, 686 _In_opt_ PVOID NormalContext, 687 _In_opt_ PVOID SystemArgument1, 688 _In_opt_ PVOID SystemArgument2 689 ); 690 691 NTSYSAPI 692 NTSTATUS 693 NTAPI 694 ZwRaiseException( 695 _In_ PEXCEPTION_RECORD ExceptionRecord, 696 _In_ PCONTEXT Context, 697 _In_ BOOLEAN SearchFrames 698 ); 699 700 NTSYSAPI 701 NTSTATUS 702 NTAPI 703 ZwSetContextThread( 704 _In_ HANDLE ThreadHandle, 705 _In_ PCONTEXT Context 706 ); 707 708 NTSYSAPI 709 NTSTATUS 710 NTAPI 711 ZwSetIntervalProfile( 712 _In_ ULONG Interval, 713 _In_ KPROFILE_SOURCE ClockSource 714 ); 715 716 NTSYSAPI 717 NTSTATUS 718 NTAPI 719 ZwSetLdtEntries( 720 _In_ ULONG Selector1, 721 _In_ LDT_ENTRY LdtEntry1, 722 _In_ ULONG Selector2, 723 _In_ LDT_ENTRY LdtEntry2 724 ); 725 726 NTSYSAPI 727 NTSTATUS 728 NTAPI 729 ZwSetSystemTime( 730 _In_ PLARGE_INTEGER SystemTime, 731 _In_opt_ PLARGE_INTEGER NewSystemTime 732 ); 733 734 NTSYSAPI 735 NTSTATUS 736 NTAPI 737 ZwSetTimerResolution( 738 _In_ ULONG RequestedResolution, 739 _In_ BOOLEAN SetOrUnset, 740 _Out_ PULONG ActualResolution 741 ); 742 743 NTSYSAPI 744 NTSTATUS 745 NTAPI 746 ZwStartProfile( 747 _In_ HANDLE ProfileHandle 748 ); 749 750 NTSYSAPI 751 NTSTATUS 752 NTAPI 753 ZwStopProfile( 754 _In_ HANDLE ProfileHandle 755 ); 756 757 NTSYSAPI 758 NTSTATUS 759 NTAPI 760 ZwTestAlert( 761 VOID 762 ); 763 764 NTSYSAPI 765 NTSTATUS 766 NTAPI 767 ZwVdmControl( 768 _In_ ULONG ControlCode, 769 _In_ PVOID ControlData 770 ); 771 772 NTSYSAPI 773 NTSTATUS 774 NTAPI 775 ZwW32Call( 776 _In_ ULONG RoutineIndex, 777 _In_ PVOID Argument, 778 _In_ ULONG ArgumentLength, 779 _Out_opt_ PVOID* Result, 780 _Out_opt_ PULONG ResultLength 781 ); 782 783 NTSYSAPI 784 NTSTATUS 785 NTAPI 786 ZwYieldExecution( 787 VOID 788 ); 789 #endif 790 791 #ifdef __cplusplus 792 } // extern "C" 793 #endif 794