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