2 #ifndef __INCLUDE_DDK_KEFUNCS_H
3 #define __INCLUDE_DDK_KEFUNCS_H
5 #define KEBUGCHECK(a) DbgPrint("KeBugCheck at %s:%i\n",__FILE__,__LINE__), KeBugCheck(a)
7 /* KERNEL FUNCTIONS ********************************************************/
11 KeRestoreFloatingPointState(
12 IN PKFLOATING_SAVE FloatSave
);
16 KeSaveFloatingPointState(
17 OUT PKFLOATING_SAVE FloatSave
);
19 #ifndef KeFlushIoBuffers
20 #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
23 VOID STDCALL
KeAttachProcess(struct _KPROCESS
*Process
);
25 VOID FASTCALL
KiAcquireSpinLock(PKSPIN_LOCK SpinLock
);
27 VOID FASTCALL
KiReleaseSpinLock(PKSPIN_LOCK SpinLock
);
29 VOID
KeDrainApcQueue(VOID
);
31 struct _KPROCESS
* KeGetCurrentProcess(VOID
);
34 * FUNCTION: Acquires a spinlock so the caller can synchronize access to
37 * SpinLock = Initialized spinlock
38 * OldIrql (OUT) = Set the previous irql on return
40 VOID STDCALL
KeAcquireSpinLock (PKSPIN_LOCK SpinLock
,
50 volatile LONG Barrier
;
51 __asm__
__volatile__ ("xchg %%eax, %0" : : "m" (Barrier
) : "%eax");
54 VOID STDCALL
KeAcquireSpinLockAtDpcLevel (IN PKSPIN_LOCK SpinLock
);
56 #define KefAcquireSpinLockAtDpcLevel KeAcquireSpinLockAtDpcLevel
60 KeReleaseSpinLockFromDpcLevel(
61 IN PKSPIN_LOCK SpinLock
);
66 * FUNCTION: Brings the system down in a controlled manner when an
67 * inconsistency that might otherwise cause corruption has been detected
69 * BugCheckCode = Specifies the reason for the bug check
72 * NOTES - please use the macro KEBUGCHECK with the same argument so the end-user
73 * knows what file/line number where the bug check occured
75 VOID STDCALL
KeBugCheck (ULONG BugCheckCode
);
78 * FUNCTION: Brings the system down in a controlled manner when an
79 * inconsistency that might otherwise cause corruption has been detected
81 * BugCheckCode = Specifies the reason for the bug check
82 * BugCheckParameter[1-4] = Additional information about bug
85 * NOTES - please use the macro KEBUGCHECKEX with the same arguments so the end-user
86 * knows what file/line number where the bug check occured
88 VOID STDCALL
KeBugCheckEx (ULONG BugCheckCode
,
89 ULONG BugCheckParameter1
,
90 ULONG BugCheckParameter2
,
91 ULONG BugCheckParameter3
,
92 ULONG BugCheckParameter4
);
94 BOOLEAN STDCALL
KeCancelTimer (PKTIMER Timer
);
96 VOID STDCALL
KeClearEvent (PKEVENT Event
);
98 BOOLEAN STDCALL
KeConnectInterrupt(PKINTERRUPT InterruptObject
);
100 NTSTATUS STDCALL
KeDelayExecutionThread (KPROCESSOR_MODE WaitMode
,
102 PLARGE_INTEGER Internal
);
104 BOOLEAN STDCALL
KeDeregisterBugCheckCallback (
105 PKBUGCHECK_CALLBACK_RECORD CallbackRecord
);
107 VOID STDCALL
KeDetachProcess (VOID
);
109 VOID STDCALL
KeDisconnectInterrupt(PKINTERRUPT InterruptObject
);
111 VOID STDCALL
KeEnterCriticalRegion (VOID
);
114 * FUNCTION: Enters the kernel debugger
118 VOID STDCALL
KeEnterKernelDebugger (VOID
);
120 KIRQL STDCALL
KeGetCurrentIrql (VOID
);
123 #define KeGetCurrentProcessorNumber() (KeGetCurrentKPCR()->ProcessorNumber)
124 ULONG
KeGetDcacheFillSize(VOID
);
125 KPROCESSOR_MODE STDCALL
KeGetPreviousMode (VOID
);
128 struct _KTHREAD
* STDCALL
KeGetCurrentThread (VOID
);
130 VOID STDCALL
KeInitializeApc (IN PKAPC Apc
,
132 IN KAPC_ENVIRONMENT TargetEnvironment
,
133 IN PKKERNEL_ROUTINE KernelRoutine
,
134 IN PKRUNDOWN_ROUTINE RundownRoutine
,
135 IN PKNORMAL_ROUTINE NormalRoutine
,
136 IN KPROCESSOR_MODE Mode
,
142 * KeInitializeCallbackRecord (
143 * PKBUGCHECK_CALLBACK_RECORD CallbackRecord
146 #ifndef KeInitializeCallbackRecord
147 #define KeInitializeCallbackRecord(CallbackRecord) \
148 (CallbackRecord)->State = BufferEmpty
151 VOID STDCALL
KeInitializeDeviceQueue (PKDEVICE_QUEUE DeviceQueue
);
153 VOID STDCALL
KeInitializeDpc (PKDPC Dpc
,
154 PKDEFERRED_ROUTINE DeferredRoutine
,
155 PVOID DeferredContext
);
157 VOID STDCALL
KeInitializeEvent (PKEVENT Event
,
161 VOID STDCALL
KeInitializeInterrupt(PKINTERRUPT InterruptObject
,
162 PKSERVICE_ROUTINE ServiceRoutine
,
163 PVOID ServiceContext
,
164 PKSPIN_LOCK SpinLock
,
167 KIRQL SynchronizeIrql
,
168 KINTERRUPT_MODE InterruptMode
,
170 CHAR ProcessorNumber
,
171 BOOLEAN FloatingSave
);
173 VOID STDCALL
KeInitializeMutant(IN PKMUTANT Mutant
,
174 IN BOOLEAN InitialOwner
);
176 VOID STDCALL
KeInitializeMutex (PKMUTEX Mutex
,
180 KeInitializeQueue(IN PKQUEUE Queue
,
184 KeRundownQueue(IN PKQUEUE Queue
);
186 VOID STDCALL
KeInitializeSemaphore (PKSEMAPHORE Semaphore
,
191 * FUNCTION: Initializes a spinlock
193 * SpinLock = Spinlock to initialize
195 VOID STDCALL
KeInitializeSpinLock (PKSPIN_LOCK SpinLock
);
197 VOID STDCALL
KeInitializeTimer (PKTIMER Timer
);
199 VOID STDCALL
KeInitializeTimerEx (PKTIMER Timer
,
202 BOOLEAN STDCALL
KeInsertByKeyDeviceQueue (PKDEVICE_QUEUE DeviceQueue
,
203 PKDEVICE_QUEUE_ENTRY QueueEntry
,
206 BOOLEAN STDCALL
KeInsertDeviceQueue (PKDEVICE_QUEUE DeviceQueue
,
207 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
210 KeInsertHeadQueue(IN PKQUEUE Queue
,
211 IN PLIST_ENTRY Entry
);
214 KeInsertQueue(IN PKQUEUE Queue
,
215 IN PLIST_ENTRY Entry
);
217 BOOLEAN STDCALL
KeInsertQueueApc (PKAPC Apc
,
218 PVOID SystemArgument1
,
219 PVOID SystemArgument2
,
220 KPRIORITY PriorityBoost
);
222 BOOLEAN STDCALL
KeInsertQueueDpc (PKDPC Dpc
,
223 PVOID SystemArgument1
,
224 PVOID SystemArgument2
);
226 VOID STDCALL
KeLeaveCriticalRegion (VOID
);
228 VOID STDCALL
KeLowerIrql (KIRQL NewIrql
);
230 LONG STDCALL
KePulseEvent (PKEVENT Event
,
236 KeQueryPerformanceCounter (
237 PLARGE_INTEGER PerformanceFrequency
243 PLARGE_INTEGER CurrentTime
249 PLARGE_INTEGER TickCount
254 KeQueryTimeIncrement (
260 KeQueryInterruptTime(
273 KeRaiseIrqlToDpcLevel (
284 KeReadStateMutant(IN PKMUTANT Mutant
);
287 KeReadStateMutex(IN PKMUTEX Mutex
);
290 KeReadStateQueue(IN PKQUEUE Queue
);
293 KeReadStateSemaphore(IN PKSEMAPHORE Semaphore
);
296 KeReadStateTimer(IN PKTIMER Timer
);
300 KeRegisterBugCheckCallback (
301 PKBUGCHECK_CALLBACK_RECORD CallbackRecord
,
302 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine
,
312 IN KPRIORITY Increment
,
327 PKSEMAPHORE Semaphore
,
336 PKSPIN_LOCK Spinlock
,
343 KeReleaseSpinLockFromDpcLevel (
350 KeRemoveByKeyDeviceQueue (
351 PKDEVICE_QUEUE DeviceQueue
,
357 KeRemoveDeviceQueue (
358 PKDEVICE_QUEUE DeviceQueue
362 KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
363 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
366 KeRemoveQueue(IN PKQUEUE Queue
,
367 IN KPROCESSOR_MODE WaitMode
,
368 IN PLARGE_INTEGER Timeout OPTIONAL
);
371 KeRemoveQueueDpc(IN PKDPC Dpc
);
374 KeResetEvent(IN PKEVENT Event
);
377 KeRosDumpStackFrames ( PULONG Frame
, ULONG FrameCount
);
380 KeRosGetStackFrames ( PULONG Frames
, ULONG FrameCount
);
383 KeRosPrintAddress(PVOID address
);
386 KeSetAffinityThread(PKTHREAD Thread
,
390 KeSetBasePriorityThread(struct _KTHREAD
* Thread
,
401 KPRIORITY STDCALL
KeSetPriorityThread (struct _KTHREAD
* Thread
,
404 BOOLEAN STDCALL
KeSetTimer (PKTIMER Timer
,
405 LARGE_INTEGER DueTime
,
408 BOOLEAN STDCALL
KeSetTimerEx (PKTIMER Timer
,
409 LARGE_INTEGER DueTime
,
413 VOID STDCALL
KeStallExecutionProcessor (ULONG MicroSeconds
);
415 BOOLEAN STDCALL
KeSynchronizeExecution (PKINTERRUPT Interrupt
,
416 PKSYNCHRONIZE_ROUTINE SynchronizeRoutine
,
417 PVOID SynchronizeContext
);
419 NTSTATUS STDCALL
KeWaitForMultipleObjects (ULONG Count
,
422 KWAIT_REASON WaitReason
,
423 KPROCESSOR_MODE WaitMode
,
425 PLARGE_INTEGER Timeout
,
426 PKWAIT_BLOCK WaitBlockArray
);
430 KeWaitForMutexObject (
432 KWAIT_REASON WaitReason
,
433 KPROCESSOR_MODE WaitMode
,
435 PLARGE_INTEGER Timeout
440 KeWaitForSingleObject (
442 KWAIT_REASON WaitReason
,
443 KPROCESSOR_MODE WaitMode
,
445 PLARGE_INTEGER Timeout
450 /* io permission map has a 8k size
451 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
452 * is initialized to allow IO at any port. [ all bits set ].
460 * FUNCTION: Provides the kernel with a new access map for a driver
462 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
463 * the kernel disables access to a particular port.
464 * IoPortMap = Caller supplies storage for the io permission map.
466 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
467 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
468 * the minium privilege level required to perform IO prior to checking the permission map.
471 Ke386SetIoAccessMap(ULONG NewMap
, PULONG IoPermissionMap
);
474 * FUNCTION: Queries the io permission map.
476 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
477 * the kernel disables access to a particular port.
478 * IoPortMap = Caller supplies storage for the io permission map.
480 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
481 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
482 * the minium privilege level required to perform IO prior to checking the permission map.
485 Ke386QueryIoAccessMap(ULONG NewMap
, PULONG IoPermissionMap
);
488 * FUNCTION: Set the process IOPL
490 * Eprocess = Pointer to a executive process object
491 * EnableIo = Specify TRUE to enable IO and FALSE to disable
494 Ke386IoSetAccessProcess(struct _EPROCESS
* Eprocess
, BOOL EnableIo
);
497 * FUNCTION: Sets the contents of a gdt descriptor.
499 * Entry = The selector to set.
500 * Value1 = The value of the low dword of the descriptor.
501 * Value2 = The value of the high dword of the descriptor.
511 * FUNCTION: Releases a set of Global Descriptor Table Selectors
517 KeI386ReleaseGdtSelectors(
519 IN ULONG NumOfSelectors
523 * FUNCTION: Allocates a set of Global Descriptor Table Selectors
529 KeI386AllocateGdtSelectors(
531 IN ULONG NumOfSelectors
538 IN PKSPIN_LOCK SpinLock
557 IN PKSPIN_LOCK SpinLock
,
562 VOID STDCALL
KiDispatchInterrupt(VOID
);
564 /* Stubs Start here */
568 KeReleaseInterruptSpinLock(
569 IN PKINTERRUPT Interrupt
,
587 KeGetRecommendedSharedDataAlignment(
593 KeQueryRuntimeThread(
600 KeSetKernelStackSwapEnable(
606 KeDeregisterBugCheckReasonCallback(
607 IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
612 KeRegisterBugCheckReasonCallback(
613 IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
,
614 IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine
,
615 IN KBUGCHECK_CALLBACK_REASON Reason
,
622 IN KPRIORITY Increment
633 KeSetEventBoostPriority(
635 IN PKTHREAD
*Thread OPTIONAL
640 KeFindConfigurationEntry(
643 IN CONFIGURATION_TYPE Type
,
649 KeFindConfigurationNextEntry(
652 IN CONFIGURATION_TYPE Type
,
661 IN BOOLEAN CurrentCpuOnly
666 KeRevertToUserAffinityThread(
678 KiUnexpectedInterrupt(
696 KeSetSystemAffinityThread(
697 IN KAFFINITY Affinity
704 IN PVOID InputBuffer
,
705 IN ULONG InputLength
,
706 OUT PVOID
*OutputBuffer
,
707 OUT PULONG OutputLength
713 IN ULONG MaxIncrement
,
714 IN ULONG MinIncrement
719 KeCapturePersistentThreadState(
720 IN PVOID CurrentThread
,
731 KeRemoveSystemServiceTable(
736 KeI386FlatToGdtSelector(
744 KeSetIdealProcessorThread (
751 (FASTCALL
*PTIME_UPDATE_NOTIFY_ROUTINE
)(
753 IN KPROCESSOR_MODE Mode
758 KeSetTimeUpdateNotifyRoutine(
759 IN PTIME_UPDATE_NOTIFY_ROUTINE NotifyRoutine
764 KeRemoveByKeyDeviceQueueIfBusy (
765 IN PKDEVICE_QUEUE DeviceQueue
,
771 KeQueryActiveProcessors (
777 KeAcquireInStackQueuedSpinLockAtDpcLevel(
778 IN PKSPIN_LOCK SpinLock
,
779 IN PKLOCK_QUEUE_HANDLE LockHandle
784 KeReleaseInStackQueuedSpinLockFromDpcLevel(
785 IN PKLOCK_QUEUE_HANDLE LockHandle
790 KeQueryPriorityThread (
796 KeAcquireInterruptSpinLock(
797 IN PKINTERRUPT Interrupt
802 KeSaveStateForHibernate(
808 KeRaiseUserException(
809 IN NTSTATUS ExceptionCode
812 #endif /* __INCLUDE_DDK_KEFUNCS_H */