xref: /reactos/sdk/include/ndk/kefuncs.h (revision 5c7ce447)
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 CODE_SEG("INIT")
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 CODE_SEG("INIT")
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 NtQueueApcThreadEx(
474     _In_ HANDLE ThreadHandle,
475     _In_opt_ HANDLE UserApcReserveHandle,
476     _In_ PKNORMAL_ROUTINE ApcRoutine,
477     _In_opt_ PVOID NormalContext,
478     _In_opt_ PVOID SystemArgument1,
479     _In_opt_ PVOID SystemArgument2
480 );
481 
482 NTSYSCALLAPI
483 NTSTATUS
484 NTAPI
485 NtRaiseException(
486     _In_ PEXCEPTION_RECORD ExceptionRecord,
487     _In_ PCONTEXT Context,
488     _In_ BOOLEAN SearchFrames
489 );
490 
491 NTSYSCALLAPI
492 NTSTATUS
493 NTAPI
494 NtSetContextThread(
495     _In_ HANDLE ThreadHandle,
496     _In_ PCONTEXT Context
497 );
498 
499 NTSYSCALLAPI
500 NTSTATUS
501 NTAPI
502 NtSetIntervalProfile(
503     _In_ ULONG Interval,
504     _In_ KPROFILE_SOURCE ClockSource
505 );
506 
507 NTSYSCALLAPI
508 NTSTATUS
509 NTAPI
510 NtSetLdtEntries(
511     _In_ ULONG Selector1,
512     _In_ LDT_ENTRY LdtEntry1,
513     _In_ ULONG Selector2,
514     _In_ LDT_ENTRY LdtEntry2
515 );
516 
517 NTSYSCALLAPI
518 NTSTATUS
519 NTAPI
520 NtSetSystemTime(
521     _In_ PLARGE_INTEGER SystemTime,
522     _In_opt_ PLARGE_INTEGER NewSystemTime
523 );
524 
525 NTSYSCALLAPI
526 NTSTATUS
527 NTAPI
528 NtSetTimerResolution(
529     _In_ ULONG RequestedResolution,
530     _In_ BOOLEAN SetOrUnset,
531     _Out_ PULONG ActualResolution
532 );
533 
534 NTSYSCALLAPI
535 NTSTATUS
536 NTAPI
537 NtStartProfile(
538     _In_ HANDLE ProfileHandle
539 );
540 
541 NTSYSCALLAPI
542 NTSTATUS
543 NTAPI
544 NtStopProfile(
545     _In_ HANDLE ProfileHandle
546 );
547 
548 NTSYSCALLAPI
549 NTSTATUS
550 NTAPI
551 NtTestAlert(
552     VOID
553 );
554 
555 NTSYSCALLAPI
556 NTSTATUS
557 NTAPI
558 NtVdmControl(
559     _In_ ULONG ControlCode,
560     _In_ PVOID ControlData
561 );
562 
563 NTSYSCALLAPI
564 NTSTATUS
565 NTAPI
566 NtW32Call(
567     _In_ ULONG RoutineIndex,
568     _In_ PVOID Argument,
569     _In_ ULONG ArgumentLength,
570     _Out_opt_ PVOID* Result,
571     _Out_opt_ PULONG ResultLength
572 );
573 
574 NTSYSCALLAPI
575 NTSTATUS
576 NTAPI
577 NtYieldExecution(
578     VOID
579 );
580 
581 NTSYSAPI
582 NTSTATUS
583 NTAPI
584 ZwContinue(
585     _In_ PCONTEXT Context,
586     _In_ BOOLEAN TestAlert
587 );
588 
589 NTSYSAPI
590 NTSTATUS
591 NTAPI
592 ZwCallbackReturn(
593     _In_ PVOID Result,
594     _In_ ULONG ResultLength,
595     _In_ NTSTATUS Status
596 );
597 
598 NTSYSAPI
599 NTSTATUS
600 NTAPI
601 ZwCreateProfile(
602     _Out_ PHANDLE ProfileHandle,
603     _In_ HANDLE ProcessHandle,
604     _In_ PVOID ImageBase,
605     _In_ ULONG ImageSize,
606     _In_ ULONG Granularity,
607     _Out_ PVOID Buffer,
608     _In_ ULONG ProfilingSize,
609     _In_ KPROFILE_SOURCE Source,
610     _In_ KAFFINITY ProcessorMask
611 );
612 
613 NTSYSAPI
614 NTSTATUS
615 NTAPI
616 ZwDelayExecution(
617     _In_ BOOLEAN Alertable,
618     _In_ LARGE_INTEGER *Interval
619 );
620 
621 NTSYSAPI
622 NTSTATUS
623 NTAPI
624 ZwFlushInstructionCache(
625     _In_ HANDLE ProcessHandle,
626     _In_ PVOID BaseAddress,
627     _In_ ULONG NumberOfBytesToFlush
628 );
629 
630 NTSYSAPI
631 NTSTATUS
632 NTAPI
633 ZwGetContextThread(
634     _In_ HANDLE ThreadHandle,
635     _Out_ PCONTEXT Context
636 );
637 
638 NTSYSAPI
639 ULONG
640 NTAPI
641 ZwGetTickCount(
642     VOID
643 );
644 
645 NTSYSAPI
646 NTSTATUS
647 NTAPI
648 ZwQueryIntervalProfile(
649     _In_  KPROFILE_SOURCE ProfileSource,
650     _Out_ PULONG Interval
651 );
652 
653 NTSYSAPI
654 NTSTATUS
655 NTAPI
656 ZwQueryPerformanceCounter(
657     _Out_ PLARGE_INTEGER Counter,
658     _Out_opt_ PLARGE_INTEGER Frequency
659 );
660 
661 NTSYSAPI
662 NTSTATUS
663 NTAPI
664 ZwQuerySystemTime(
665     _Out_ PLARGE_INTEGER CurrentTime
666 );
667 
668 NTSYSAPI
669 NTSTATUS
670 NTAPI
671 ZwQueryTimerResolution(
672     _Out_ PULONG MinimumResolution,
673     _Out_ PULONG MaximumResolution,
674     _Out_ PULONG ActualResolution
675 );
676 
677 NTSYSAPI
678 NTSTATUS
679 NTAPI
680 ZwQueueApcThread(
681     _In_ HANDLE ThreadHandle,
682     _In_ PKNORMAL_ROUTINE ApcRoutine,
683     _In_opt_ PVOID NormalContext,
684     _In_opt_ PVOID SystemArgument1,
685     _In_opt_ PVOID SystemArgument2
686 );
687 
688 NTSYSAPI
689 NTSTATUS
690 NTAPI
691 ZwRaiseException(
692     _In_ PEXCEPTION_RECORD ExceptionRecord,
693     _In_ PCONTEXT Context,
694     _In_ BOOLEAN SearchFrames
695 );
696 
697 NTSYSAPI
698 NTSTATUS
699 NTAPI
700 ZwSetContextThread(
701     _In_ HANDLE ThreadHandle,
702     _In_ PCONTEXT Context
703 );
704 
705 NTSYSAPI
706 NTSTATUS
707 NTAPI
708 ZwSetIntervalProfile(
709     _In_ ULONG Interval,
710     _In_ KPROFILE_SOURCE ClockSource
711 );
712 
713 NTSYSAPI
714 NTSTATUS
715 NTAPI
716 ZwSetLdtEntries(
717     _In_ ULONG Selector1,
718     _In_ LDT_ENTRY LdtEntry1,
719     _In_ ULONG Selector2,
720     _In_ LDT_ENTRY LdtEntry2
721 );
722 
723 NTSYSAPI
724 NTSTATUS
725 NTAPI
726 ZwSetSystemTime(
727     _In_ PLARGE_INTEGER SystemTime,
728     _In_opt_ PLARGE_INTEGER NewSystemTime
729 );
730 
731 NTSYSAPI
732 NTSTATUS
733 NTAPI
734 ZwSetTimerResolution(
735     _In_ ULONG RequestedResolution,
736     _In_ BOOLEAN SetOrUnset,
737     _Out_ PULONG ActualResolution
738 );
739 
740 NTSYSAPI
741 NTSTATUS
742 NTAPI
743 ZwStartProfile(
744     _In_ HANDLE ProfileHandle
745 );
746 
747 NTSYSAPI
748 NTSTATUS
749 NTAPI
750 ZwStopProfile(
751     _In_ HANDLE ProfileHandle
752 );
753 
754 NTSYSAPI
755 NTSTATUS
756 NTAPI
757 ZwTestAlert(
758     VOID
759 );
760 
761 NTSYSAPI
762 NTSTATUS
763 NTAPI
764 ZwVdmControl(
765     _In_ ULONG ControlCode,
766     _In_ PVOID ControlData
767 );
768 
769 NTSYSAPI
770 NTSTATUS
771 NTAPI
772 ZwW32Call(
773     _In_ ULONG RoutineIndex,
774     _In_ PVOID Argument,
775     _In_ ULONG ArgumentLength,
776     _Out_opt_ PVOID* Result,
777     _Out_opt_ PULONG ResultLength
778 );
779 
780 NTSYSAPI
781 NTSTATUS
782 NTAPI
783 ZwYieldExecution(
784     VOID
785 );
786 #endif
787