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
,
45 VOID STDCALL
KeAcquireSpinLockAtDpcLevel (IN PKSPIN_LOCK SpinLock
);
47 #define KefAcquireSpinLockAtDpcLevel KeAcquireSpinLockAtDpcLevel
51 KeReleaseSpinLockFromDpcLevel(
52 IN PKSPIN_LOCK SpinLock
);
57 * FUNCTION: Brings the system down in a controlled manner when an
58 * inconsistency that might otherwise cause corruption has been detected
60 * BugCheckCode = Specifies the reason for the bug check
63 * NOTES - please use the macro KEBUGCHECK with the same argument so the end-user
64 * knows what file/line number where the bug check occured
66 VOID STDCALL
KeBugCheck (ULONG BugCheckCode
);
69 * FUNCTION: Brings the system down in a controlled manner when an
70 * inconsistency that might otherwise cause corruption has been detected
72 * BugCheckCode = Specifies the reason for the bug check
73 * BugCheckParameter[1-4] = Additional information about bug
76 * NOTES - please use the macro KEBUGCHECKEX with the same arguments so the end-user
77 * knows what file/line number where the bug check occured
79 VOID STDCALL
KeBugCheckEx (ULONG BugCheckCode
,
80 ULONG BugCheckParameter1
,
81 ULONG BugCheckParameter2
,
82 ULONG BugCheckParameter3
,
83 ULONG BugCheckParameter4
);
85 BOOLEAN STDCALL
KeCancelTimer (PKTIMER Timer
);
87 VOID STDCALL
KeClearEvent (PKEVENT Event
);
89 BOOLEAN STDCALL
KeConnectInterrupt(PKINTERRUPT InterruptObject
);
91 NTSTATUS STDCALL
KeDelayExecutionThread (KPROCESSOR_MODE WaitMode
,
93 PLARGE_INTEGER Internal
);
95 BOOLEAN STDCALL
KeDeregisterBugCheckCallback (
96 PKBUGCHECK_CALLBACK_RECORD CallbackRecord
);
98 VOID STDCALL
KeDetachProcess (VOID
);
100 VOID STDCALL
KeDisconnectInterrupt(PKINTERRUPT InterruptObject
);
102 VOID STDCALL
KeEnterCriticalRegion (VOID
);
105 * FUNCTION: Enters the kernel debugger
109 VOID STDCALL
KeEnterKernelDebugger (VOID
);
111 KIRQL STDCALL
KeGetCurrentIrql (VOID
);
114 #define KeGetCurrentProcessorNumber() (KeGetCurrentKPCR()->ProcessorNumber)
115 ULONG
KeGetDcacheFillSize(VOID
);
116 ULONG STDCALL
KeGetPreviousMode (VOID
);
119 struct _KTHREAD
* STDCALL
KeGetCurrentThread (VOID
);
121 VOID STDCALL
KeInitializeApc (IN PKAPC Apc
,
123 IN KAPC_ENVIRONMENT TargetEnvironment
,
124 IN PKKERNEL_ROUTINE KernelRoutine
,
125 IN PKRUNDOWN_ROUTINE RundownRoutine
,
126 IN PKNORMAL_ROUTINE NormalRoutine
,
127 IN KPROCESSOR_MODE Mode
,
133 * KeInitializeCallbackRecord (
134 * PKBUGCHECK_CALLBACK_RECORD CallbackRecord
137 #ifndef KeInitializeCallbackRecord
138 #define KeInitializeCallbackRecord(CallbackRecord) \
139 (CallbackRecord)->State = BufferEmpty
142 VOID STDCALL
KeInitializeDeviceQueue (PKDEVICE_QUEUE DeviceQueue
);
144 VOID STDCALL
KeInitializeDpc (PKDPC Dpc
,
145 PKDEFERRED_ROUTINE DeferredRoutine
,
146 PVOID DeferredContext
);
148 VOID STDCALL
KeInitializeEvent (PKEVENT Event
,
152 NTSTATUS STDCALL
KeInitializeInterrupt(PKINTERRUPT InterruptObject
,
153 PKSERVICE_ROUTINE ServiceRoutine
,
154 PVOID ServiceContext
,
155 PKSPIN_LOCK SpinLock
,
158 KIRQL SynchronizeIrql
,
159 KINTERRUPT_MODE InterruptMode
,
161 KAFFINITY ProcessorEnableMask
,
162 BOOLEAN FloatingSave
);
164 VOID STDCALL
KeInitializeMutant(IN PKMUTANT Mutant
,
165 IN BOOLEAN InitialOwner
);
167 VOID STDCALL
KeInitializeMutex (PKMUTEX Mutex
,
171 KeInitializeQueue(IN PKQUEUE Queue
,
175 KeRundownQueue(IN PKQUEUE Queue
);
177 VOID STDCALL
KeInitializeSemaphore (PKSEMAPHORE Semaphore
,
182 * FUNCTION: Initializes a spinlock
184 * SpinLock = Spinlock to initialize
186 VOID STDCALL
KeInitializeSpinLock (PKSPIN_LOCK SpinLock
);
188 VOID STDCALL
KeInitializeTimer (PKTIMER Timer
);
190 VOID STDCALL
KeInitializeTimerEx (PKTIMER Timer
,
193 BOOLEAN STDCALL
KeInsertByKeyDeviceQueue (PKDEVICE_QUEUE DeviceQueue
,
194 PKDEVICE_QUEUE_ENTRY QueueEntry
,
197 BOOLEAN STDCALL
KeInsertDeviceQueue (PKDEVICE_QUEUE DeviceQueue
,
198 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
201 KeInsertHeadQueue(IN PKQUEUE Queue
,
202 IN PLIST_ENTRY Entry
);
205 KeInsertQueue(IN PKQUEUE Queue
,
206 IN PLIST_ENTRY Entry
);
208 BOOLEAN STDCALL
KeInsertQueueApc (PKAPC Apc
,
209 PVOID SystemArgument1
,
210 PVOID SystemArgument2
,
211 KPRIORITY PriorityBoost
);
213 BOOLEAN STDCALL
KeInsertQueueDpc (PKDPC Dpc
,
214 PVOID SystemArgument1
,
215 PVOID SystemArgument2
);
217 VOID STDCALL
KeLeaveCriticalRegion (VOID
);
219 VOID STDCALL
KeLowerIrql (KIRQL NewIrql
);
221 NTSTATUS STDCALL
KePulseEvent (PKEVENT Event
,
227 KeQueryPerformanceCounter (
228 PLARGE_INTEGER PerformanceFrequency
234 PLARGE_INTEGER CurrentTime
240 PLARGE_INTEGER TickCount
245 KeQueryTimeIncrement (
258 KeRaiseIrqlToDpcLevel (
269 KeReadStateMutant(IN PKMUTANT Mutant
);
272 KeReadStateMutex(IN PKMUTEX Mutex
);
275 KeReadStateQueue(IN PKQUEUE Queue
);
278 KeReadStateSemaphore(IN PKSEMAPHORE Semaphore
);
281 KeReadStateTimer(IN PKTIMER Timer
);
285 KeRegisterBugCheckCallback (
286 PKBUGCHECK_CALLBACK_RECORD CallbackRecord
,
287 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine
,
297 IN KPRIORITY Increment
,
312 PKSEMAPHORE Semaphore
,
321 PKSPIN_LOCK Spinlock
,
328 KeReleaseSpinLockFromDpcLevel (
335 KeRemoveByKeyDeviceQueue (
336 PKDEVICE_QUEUE DeviceQueue
,
342 KeRemoveDeviceQueue (
343 PKDEVICE_QUEUE DeviceQueue
347 KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
348 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
351 KeRemoveQueue(IN PKQUEUE Queue
,
352 IN KPROCESSOR_MODE WaitMode
,
353 IN PLARGE_INTEGER Timeout OPTIONAL
);
356 KeRemoveQueueDpc(IN PKDPC Dpc
);
359 KeResetEvent(IN PKEVENT Event
);
362 KeRosDumpStackFrames ( PULONG Frame
, ULONG FrameCount
);
365 KeRosGetStackFrames ( PULONG Frames
, ULONG FrameCount
);
368 KeRosPrintAddress(PVOID address
);
371 KeSetBasePriorityThread(struct _KTHREAD
* Thread
,
382 KPRIORITY STDCALL
KeSetPriorityThread (struct _KTHREAD
* Thread
,
385 BOOLEAN STDCALL
KeSetTimer (PKTIMER Timer
,
386 LARGE_INTEGER DueTime
,
389 BOOLEAN STDCALL
KeSetTimerEx (PKTIMER Timer
,
390 LARGE_INTEGER DueTime
,
394 VOID STDCALL
KeStallExecutionProcessor (ULONG MicroSeconds
);
396 BOOLEAN STDCALL
KeSynchronizeExecution (PKINTERRUPT Interrupt
,
397 PKSYNCHRONIZE_ROUTINE SynchronizeRoutine
,
398 PVOID SynchronizeContext
);
400 NTSTATUS STDCALL
KeWaitForMultipleObjects (ULONG Count
,
403 KWAIT_REASON WaitReason
,
404 KPROCESSOR_MODE WaitMode
,
406 PLARGE_INTEGER Timeout
,
407 PKWAIT_BLOCK WaitBlockArray
);
411 KeWaitForMutexObject (
413 KWAIT_REASON WaitReason
,
414 KPROCESSOR_MODE WaitMode
,
416 PLARGE_INTEGER Timeout
421 KeWaitForSingleObject (
423 KWAIT_REASON WaitReason
,
424 KPROCESSOR_MODE WaitMode
,
426 PLARGE_INTEGER Timeout
431 /* io permission map has a 8k size
432 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
433 * is initialized to allow IO at any port. [ all bits set ].
441 * FUNCTION: Provides the kernel with a new access map for a driver
443 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
444 * the kernel disables access to a particular port.
445 * IoPortMap = Caller supplies storage for the io permission map.
447 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
448 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
449 * the minium privilege level required to perform IO prior to checking the permission map.
452 Ke386SetIoAccessMap(ULONG NewMap
, PULONG IoPermissionMap
);
455 * FUNCTION: Queries the io permission map.
457 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
458 * the kernel disables access to a particular port.
459 * IoPortMap = Caller supplies storage for the io permission map.
461 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
462 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
463 * the minium privilege level required to perform IO prior to checking the permission map.
466 Ke386QueryIoAccessMap(ULONG NewMap
, PULONG IoPermissionMap
);
469 * FUNCTION: Set the process IOPL
471 * Eprocess = Pointer to a executive process object
472 * EnableIo = Specify TRUE to enable IO and FALSE to disable
475 Ke386IoSetAccessProcess(struct _EPROCESS
* Eprocess
, BOOL EnableIo
);
478 * FUNCTION: Sets the contents of a gdt descriptor.
480 * Entry = The selector to set.
481 * Value1 = The value of the low dword of the descriptor.
482 * Value2 = The value of the high dword of the descriptor.
492 * FUNCTION: Releases a set of Global Descriptor Table Selectors
498 KeI386ReleaseGdtSelectors(
500 IN ULONG NumOfSelectors
504 * FUNCTION: Allocates a set of Global Descriptor Table Selectors
510 KeI386AllocateGdtSelectors(
512 IN ULONG NumOfSelectors
519 IN PKSPIN_LOCK SpinLock
538 IN PKSPIN_LOCK SpinLock
,
543 VOID STDCALL
KiDispatchInterrupt(VOID
);
545 /* Stubs Start here */
549 KeReleaseInterruptSpinLock(
550 IN PKINTERRUPT Interrupt
,
568 KeGetRecommendedSharedDataAlignment(
574 KeQueryRuntimeThread(
581 KeSetKernelStackSwapEnable(
587 KeDeregisterBugCheckReasonCallback(
588 IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
593 KeRegisterBugCheckReasonCallback(
594 IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
,
595 IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine
,
596 IN KBUGCHECK_CALLBACK_REASON Reason
,
603 IN KPRIORITY Increment
614 KeSetEventBoostPriority(
616 IN PKTHREAD
*Thread OPTIONAL
621 KeFindConfigurationEntry(
624 IN CONFIGURATION_TYPE Type
,
630 KeFindConfigurationNextEntry(
633 IN CONFIGURATION_TYPE Type
,
642 IN BOOLEAN CurrentCpuOnly
647 KeRevertToUserAffinityThread(
659 KiUnexpectedInterrupt(
677 KeSetSystemAffinityThread(
678 IN KAFFINITY Affinity
685 IN PVOID InputBuffer
,
686 IN ULONG InputLength
,
687 OUT PVOID
*OutputBuffer
,
688 OUT PULONG OutputLength
694 IN ULONG MaxIncrement
,
695 IN ULONG MinIncrement
700 KeCapturePersistentThreadState(
701 IN PVOID CurrentThread
,
712 KeRemoveSystemServiceTable(
717 KeI386FlatToGdtSelector(
725 KeSetIdealProcessorThread (
732 (FASTCALL
*PTIME_UPDATE_NOTIFY_ROUTINE
)(
734 IN KPROCESSOR_MODE Mode
739 KeSetTimeUpdateNotifyRoutine(
740 IN PTIME_UPDATE_NOTIFY_ROUTINE NotifyRoutine
745 KeRemoveByKeyDeviceQueueIfBusy (
746 IN PKDEVICE_QUEUE DeviceQueue
,
752 KeQueryActiveProcessors (
758 KeAcquireInStackQueuedSpinLockAtDpcLevel(
759 IN PKSPIN_LOCK SpinLock
,
760 IN PKLOCK_QUEUE_HANDLE LockHandle
765 KeReleaseInStackQueuedSpinLockFromDpcLevel(
766 IN PKLOCK_QUEUE_HANDLE LockHandle
771 KeQueryPriorityThread (
777 KeAcquireInterruptSpinLock(
778 IN PKINTERRUPT Interrupt
783 KeSaveStateForHibernate(
789 KeRaiseUserException(
790 IN NTSTATUS ExceptionCode
793 #endif /* __INCLUDE_DDK_KEFUNCS_H */