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 _EPROCESS
* Process
);
25 VOID FASTCALL
KiAcquireSpinLock(PKSPIN_LOCK SpinLock
);
27 VOID FASTCALL
KiReleaseSpinLock(PKSPIN_LOCK SpinLock
);
29 VOID
KeDrainApcQueue(VOID
);
30 struct _KPROCESS
* KeGetCurrentProcess(VOID
);
33 * FUNCTION: Acquires a spinlock so the caller can synchronize access to
36 * SpinLock = Initialized spinlock
37 * OldIrql (OUT) = Set the previous irql on return
39 VOID STDCALL
KeAcquireSpinLock (PKSPIN_LOCK SpinLock
,
44 VOID STDCALL
KeAcquireSpinLockAtDpcLevel (IN PKSPIN_LOCK SpinLock
);
46 #define KefAcquireSpinLockAtDpcLevel KeAcquireSpinLockAtDpcLevel
50 KeReleaseSpinLockFromDpcLevel(
51 IN PKSPIN_LOCK SpinLock
);
56 * FUNCTION: Brings the system down in a controlled manner when an
57 * inconsistency that might otherwise cause corruption has been detected
59 * BugCheckCode = Specifies the reason for the bug check
62 * NOTES - please use the macro KEBUGCHECK with the same argument so the end-user
63 * knows what file/line number where the bug check occured
65 VOID STDCALL
KeBugCheck (ULONG BugCheckCode
);
68 * FUNCTION: Brings the system down in a controlled manner when an
69 * inconsistency that might otherwise cause corruption has been detected
71 * BugCheckCode = Specifies the reason for the bug check
72 * BugCheckParameter[1-4] = Additional information about bug
75 * NOTES - please use the macro KEBUGCHECKEX with the same arguments so the end-user
76 * knows what file/line number where the bug check occured
78 VOID STDCALL
KeBugCheckEx (ULONG BugCheckCode
,
79 ULONG BugCheckParameter1
,
80 ULONG BugCheckParameter2
,
81 ULONG BugCheckParameter3
,
82 ULONG BugCheckParameter4
);
84 BOOLEAN STDCALL
KeCancelTimer (PKTIMER Timer
);
86 VOID STDCALL
KeClearEvent (PKEVENT Event
);
88 BOOLEAN STDCALL
KeConnectInterrupt(PKINTERRUPT InterruptObject
);
90 NTSTATUS STDCALL
KeDelayExecutionThread (KPROCESSOR_MODE WaitMode
,
92 PLARGE_INTEGER Internal
);
94 BOOLEAN STDCALL
KeDeregisterBugCheckCallback (
95 PKBUGCHECK_CALLBACK_RECORD CallbackRecord
);
97 VOID STDCALL
KeDetachProcess (VOID
);
99 VOID STDCALL
KeDisconnectInterrupt(PKINTERRUPT InterruptObject
);
101 VOID STDCALL
KeEnterCriticalRegion (VOID
);
104 * FUNCTION: Enters the kernel debugger
108 VOID STDCALL
KeEnterKernelDebugger (VOID
);
110 KIRQL STDCALL
KeGetCurrentIrql (VOID
);
113 ULONG
KeGetCurrentProcessorNumber(VOID
);
114 ULONG
KeGetDcacheFillSize(VOID
);
115 ULONG STDCALL
KeGetPreviousMode (VOID
);
118 struct _KTHREAD
* STDCALL
KeGetCurrentThread (VOID
);
120 VOID STDCALL
KeInitializeApc (IN PKAPC Apc
,
122 IN KAPC_ENVIRONMENT TargetEnvironment
,
123 IN PKKERNEL_ROUTINE KernelRoutine
,
124 IN PKRUNDOWN_ROUTINE RundownRoutine
,
125 IN PKNORMAL_ROUTINE NormalRoutine
,
126 IN KPROCESSOR_MODE Mode
,
132 * KeInitializeCallbackRecord (
133 * PKBUGCHECK_CALLBACK_RECORD CallbackRecord
136 #ifndef KeInitializeCallbackRecord
137 #define KeInitializeCallbackRecord(CallbackRecord) \
138 (CallbackRecord)->State = BufferEmpty
141 VOID STDCALL
KeInitializeDeviceQueue (PKDEVICE_QUEUE DeviceQueue
);
143 VOID STDCALL
KeInitializeDpc (PKDPC Dpc
,
144 PKDEFERRED_ROUTINE DeferredRoutine
,
145 PVOID DeferredContext
);
147 VOID STDCALL
KeInitializeEvent (PKEVENT Event
,
151 NTSTATUS STDCALL
KeInitializeInterrupt(PKINTERRUPT InterruptObject
,
152 PKSERVICE_ROUTINE ServiceRoutine
,
153 PVOID ServiceContext
,
154 PKSPIN_LOCK SpinLock
,
157 KIRQL SynchronizeIrql
,
158 KINTERRUPT_MODE InterruptMode
,
160 KAFFINITY ProcessorEnableMask
,
161 BOOLEAN FloatingSave
);
163 VOID STDCALL
KeInitializeMutant(IN PKMUTANT Mutant
,
164 IN BOOLEAN InitialOwner
);
166 VOID STDCALL
KeInitializeMutex (PKMUTEX Mutex
,
170 KeInitializeQueue(IN PKQUEUE Queue
,
174 KeRundownQueue(IN PKQUEUE Queue
);
176 VOID STDCALL
KeInitializeSemaphore (PKSEMAPHORE Semaphore
,
181 * FUNCTION: Initializes a spinlock
183 * SpinLock = Spinlock to initialize
185 VOID STDCALL
KeInitializeSpinLock (PKSPIN_LOCK SpinLock
);
187 VOID STDCALL
KeInitializeTimer (PKTIMER Timer
);
189 VOID STDCALL
KeInitializeTimerEx (PKTIMER Timer
,
192 BOOLEAN STDCALL
KeInsertByKeyDeviceQueue (PKDEVICE_QUEUE DeviceQueue
,
193 PKDEVICE_QUEUE_ENTRY QueueEntry
,
196 BOOLEAN STDCALL
KeInsertDeviceQueue (PKDEVICE_QUEUE DeviceQueue
,
197 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
200 KeInsertHeadQueue(IN PKQUEUE Queue
,
201 IN PLIST_ENTRY Entry
);
204 KeInsertQueue(IN PKQUEUE Queue
,
205 IN PLIST_ENTRY Entry
);
207 BOOLEAN STDCALL
KeInsertQueueApc (PKAPC Apc
,
208 PVOID SystemArgument1
,
209 PVOID SystemArgument2
,
210 KPRIORITY PriorityBoost
);
212 BOOLEAN STDCALL
KeInsertQueueDpc (PKDPC Dpc
,
213 PVOID SystemArgument1
,
214 PVOID SystemArgument2
);
216 VOID STDCALL
KeLeaveCriticalRegion (VOID
);
218 VOID STDCALL
KeLowerIrql (KIRQL NewIrql
);
220 NTSTATUS STDCALL
KePulseEvent (PKEVENT Event
,
226 KeQueryPerformanceCounter (
227 PLARGE_INTEGER PerformanceFrequency
233 PLARGE_INTEGER CurrentTime
239 PLARGE_INTEGER TickCount
244 KeQueryTimeIncrement (
257 KeRaiseIrqlToDpcLevel (
268 KeReadStateMutant(IN PKMUTANT Mutant
);
271 KeReadStateMutex(IN PKMUTEX Mutex
);
274 KeReadStateQueue(IN PKQUEUE Queue
);
277 KeReadStateSemaphore(IN PKSEMAPHORE Semaphore
);
280 KeReadStateTimer(IN PKTIMER Timer
);
284 KeRegisterBugCheckCallback (
285 PKBUGCHECK_CALLBACK_RECORD CallbackRecord
,
286 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine
,
296 IN KPRIORITY Increment
,
311 PKSEMAPHORE Semaphore
,
320 PKSPIN_LOCK Spinlock
,
327 KeReleaseSpinLockFromDpcLevel (
334 KeRemoveByKeyDeviceQueue (
335 PKDEVICE_QUEUE DeviceQueue
,
341 KeRemoveDeviceQueue (
342 PKDEVICE_QUEUE DeviceQueue
346 KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
347 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
350 KeRemoveQueue(IN PKQUEUE Queue
,
351 IN KPROCESSOR_MODE WaitMode
,
352 IN PLARGE_INTEGER Timeout OPTIONAL
);
355 KeRemoveQueueDpc(IN PKDPC Dpc
);
358 KeResetEvent(IN PKEVENT Event
);
361 KeSetBasePriorityThread(struct _KTHREAD
* Thread
,
372 KPRIORITY STDCALL
KeSetPriorityThread (struct _KTHREAD
* Thread
,
375 BOOLEAN STDCALL
KeSetTimer (PKTIMER Timer
,
376 LARGE_INTEGER DueTime
,
379 BOOLEAN STDCALL
KeSetTimerEx (PKTIMER Timer
,
380 LARGE_INTEGER DueTime
,
384 VOID STDCALL
KeStallExecutionProcessor (ULONG MicroSeconds
);
386 BOOLEAN STDCALL
KeSynchronizeExecution (PKINTERRUPT Interrupt
,
387 PKSYNCHRONIZE_ROUTINE SynchronizeRoutine
,
388 PVOID SynchronizeContext
);
390 NTSTATUS STDCALL
KeWaitForMultipleObjects (ULONG Count
,
393 KWAIT_REASON WaitReason
,
394 KPROCESSOR_MODE WaitMode
,
396 PLARGE_INTEGER Timeout
,
397 PKWAIT_BLOCK WaitBlockArray
);
401 KeWaitForMutexObject (
403 KWAIT_REASON WaitReason
,
404 KPROCESSOR_MODE WaitMode
,
406 PLARGE_INTEGER Timeout
411 KeWaitForSingleObject (
413 KWAIT_REASON WaitReason
,
414 KPROCESSOR_MODE WaitMode
,
416 PLARGE_INTEGER Timeout
421 /* io permission map has a 8k size
422 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
423 * is initialized to allow IO at any port. [ all bits set ].
431 * FUNCTION: Provides the kernel with a new access map for a driver
433 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
434 * the kernel disables access to a particular port.
435 * IoPortMap = Caller supplies storage for the io permission map.
437 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
438 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
439 * the minium privilege level required to perform IO prior to checking the permission map.
442 Ke386SetIoAccessMap(ULONG NewMap
, PULONG IoPermissionMap
);
445 * FUNCTION: Queries the io permission map.
447 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
448 * the kernel disables access to a particular port.
449 * IoPortMap = Caller supplies storage for the io permission map.
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 ]. The IOPL determines
453 * the minium privilege level required to perform IO prior to checking the permission map.
456 Ke386QueryIoAccessMap(ULONG NewMap
, PULONG IoPermissionMap
);
459 * FUNCTION: Set the process IOPL
461 * Eprocess = Pointer to a executive process object
462 * EnableIo = Specify TRUE to enable IO and FALSE to disable
465 Ke386IoSetAccessProcess(struct _EPROCESS
* Eprocess
, BOOL EnableIo
);
468 * FUNCTION: Sets the contents of a gdt descriptor.
470 * Entry = The selector to set.
471 * Value1 = The value of the low dword of the descriptor.
472 * Value2 = The value of the high dword of the descriptor.
482 * FUNCTION: Releases a set of Global Descriptor Table Selectors
488 KeI386ReleaseGdtSelectors(
490 IN ULONG NumOfSelectors
494 * FUNCTION: Allocates a set of Global Descriptor Table Selectors
500 KeI386AllocateGdtSelectors(
502 IN ULONG NumOfSelectors
509 IN PKSPIN_LOCK SpinLock
528 IN PKSPIN_LOCK SpinLock
,
533 VOID STDCALL
KiDeliverApc(ULONG Unknown1
,
537 VOID STDCALL
KiDispatchInterrupt(VOID
);
539 /* Stubs Start here */
543 KeReleaseInterruptSpinLock(
544 IN PKINTERRUPT Interrupt
,
562 KeGetRecommendedSharedDataAlignment(
568 KeQueryRuntimeThread(
575 KeSetKernelStackSwapEnable(
581 KeDeregisterBugCheckReasonCallback(
582 IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
587 KeRegisterBugCheckReasonCallback(
588 IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
,
589 IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine
,
590 IN KBUGCHECK_CALLBACK_REASON Reason
,
597 IN KPRIORITY Increment
608 KeSetEventBoostPriority(
610 IN PKTHREAD
*Thread OPTIONAL
615 KeFindConfigurationEntry(
618 IN CONFIGURATION_TYPE Type
,
624 KeFindConfigurationNextEntry(
627 IN CONFIGURATION_TYPE Type
,
636 IN BOOLEAN CurrentCpuOnly
641 KeRevertToUserAffinityThread(
653 KiUnexpectedInterrupt(
671 KeSetSystemAffinityThread(
672 IN KAFFINITY Affinity
679 IN PVOID InputBuffer
,
680 IN ULONG InputLength
,
681 OUT PVOID
*OutputBuffer
,
682 OUT PULONG OutputLength
688 IN ULONG MaxIncrement
,
689 IN ULONG MinIncrement
694 KeCapturePersistentThreadState(
695 IN PVOID CurrentThread
,
706 KeRemoveSystemServiceTable(
711 KeI386FlatToGdtSelector(
719 KeSetIdealProcessorThread (
726 (FASTCALL
*PTIME_UPDATE_NOTIFY_ROUTINE
)(
728 IN KPROCESSOR_MODE Mode
733 KeSetTimeUpdateNotifyRoutine(
734 IN PTIME_UPDATE_NOTIFY_ROUTINE NotifyRoutine
739 KeRemoveByKeyDeviceQueueIfBusy (
740 IN PKDEVICE_QUEUE DeviceQueue
,
746 KeQueryActiveProcessors (
752 KeAcquireInStackQueuedSpinLockAtDpcLevel(
753 IN PKSPIN_LOCK SpinLock
,
754 IN PKLOCK_QUEUE_HANDLE LockHandle
759 KeReleaseInStackQueuedSpinLockFromDpcLevel(
760 IN PKLOCK_QUEUE_HANDLE LockHandle
765 KeQueryPriorityThread (
771 KeAcquireInterruptSpinLock(
772 IN PKINTERRUPT Interrupt
777 KeSaveStateForHibernate(
783 KeRaiseUserException(
784 IN NTSTATUS ExceptionCode
787 #endif /* __INCLUDE_DDK_KEFUNCS_H */