1 #ifndef __INCLUDE_DDK_KEFUNCS_H
2 #define __INCLUDE_DDK_KEFUNCS_H
5 /* KERNEL FUNCTIONS ********************************************************/
7 #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
9 VOID STDCALL
KeAttachProcess (struct _EPROCESS
* Process
);
11 VOID
KeDrainApcQueue(VOID
);
12 struct _KPROCESS
* KeGetCurrentProcess(VOID
);
15 * FUNCTION: Acquires a spinlock so the caller can synchronize access to
18 * SpinLock = Initialized spinlock
19 * OldIrql (OUT) = Set the previous irql on return
21 VOID STDCALL
KeAcquireSpinLock (PKSPIN_LOCK SpinLock
,
24 VOID STDCALL
KeAcquireSpinLockAtDpcLevel (PKSPIN_LOCK SpinLock
);
27 * FUNCTION: Brings the system down in a controlled manner when an
28 * inconsistency that might otherwise cause corruption has been detected
30 * BugCheckCode = Specifies the reason for the bug check
33 VOID STDCALL
KeBugCheck (ULONG BugCheckCode
);
37 * FUNCTION: Brings the system down in a controlled manner when an
38 * inconsistency that might otherwise cause corruption has been detected
40 * BugCheckCode = Specifies the reason for the bug check
41 * BugCheckParameter[1-4] = Additional information about bug
44 VOID STDCALL
KeBugCheckEx (ULONG BugCheckCode
,
45 ULONG BugCheckParameter1
,
46 ULONG BugCheckParameter2
,
47 ULONG BugCheckParameter3
,
48 ULONG BugCheckParameter4
);
50 BOOLEAN STDCALL
KeCancelTimer (PKTIMER Timer
);
52 VOID STDCALL
KeClearEvent (PKEVENT Event
);
54 NTSTATUS STDCALL
KeConnectInterrupt(PKINTERRUPT InterruptObject
);
56 NTSTATUS STDCALL
KeDelayExecutionThread (KPROCESSOR_MODE WaitMode
,
58 PLARGE_INTEGER Internal
);
60 BOOLEAN STDCALL
KeDeregisterBugCheckCallback (
61 PKBUGCHECK_CALLBACK_RECORD CallbackRecord
);
63 VOID STDCALL
KeDetachProcess (VOID
);
65 VOID STDCALL
KeDisconnectInterrupt(PKINTERRUPT InterruptObject
);
67 VOID STDCALL
KeEnterCriticalRegion (VOID
);
70 * FUNCTION: Enters the kernel debugger
74 VOID STDCALL
KeEnterKernelDebugger (VOID
);
76 VOID STDCALL
KeFlushWriteBuffer (VOID
);
78 KIRQL STDCALL
KeGetCurrentIrql (VOID
);
80 ULONG
KeGetCurrentProcessorNumber(VOID
);
82 struct _KTHREAD
* STDCALL
KeGetCurrentThread (VOID
);
84 ULONG
KeGetDcacheFillSize(VOID
);
86 ULONG STDCALL
KeGetPreviousMode (VOID
);
88 VOID STDCALL
KeInitializeApc (IN PKAPC Apc
,
91 IN PKKERNEL_ROUTINE KernelRoutine
,
92 IN PKRUNDOWN_ROUTINE RundownRoutine
,
93 IN PKNORMAL_ROUTINE NormalRoutine
,
100 * KeInitializeCallbackRecord (
101 * PKBUGCHECK_CALLBACK_RECORD CallbackRecord
104 #define KeInitializeCallbackRecord(CallbackRecord) \
105 (CallbackRecord)->State = BufferEmpty
107 VOID STDCALL
KeInitializeDeviceQueue (PKDEVICE_QUEUE DeviceQueue
);
109 VOID STDCALL
KeInitializeDpc (PKDPC Dpc
,
110 PKDEFERRED_ROUTINE DeferredRoutine
,
111 PVOID DeferredContext
);
113 VOID STDCALL
KeInitializeEvent (PKEVENT Event
,
117 NTSTATUS STDCALL
KeInitializeInterrupt(PKINTERRUPT InterruptObject
,
118 PKSERVICE_ROUTINE ServiceRoutine
,
119 PVOID ServiceContext
,
120 PKSPIN_LOCK SpinLock
,
123 KIRQL SynchronizeIrql
,
124 KINTERRUPT_MODE InterruptMode
,
126 KAFFINITY ProcessorEnableMask
,
127 BOOLEAN FloatingSave
);
129 VOID STDCALL
KeInitializeMutant(IN PKMUTANT Mutant
,
130 IN BOOLEAN InitialOwner
);
132 VOID STDCALL
KeInitializeMutex (PKMUTEX Mutex
,
136 KeInitializeQueue(IN PKQUEUE Queue
,
140 KeRundownQueue(IN PKQUEUE Queue
);
142 VOID STDCALL
KeInitializeSemaphore (PKSEMAPHORE Semaphore
,
147 * FUNCTION: Initializes a spinlock
149 * SpinLock = Spinlock to initialize
151 VOID STDCALL
KeInitializeSpinLock (PKSPIN_LOCK SpinLock
);
153 VOID STDCALL
KeInitializeTimer (PKTIMER Timer
);
155 VOID STDCALL
KeInitializeTimerEx (PKTIMER Timer
,
158 BOOLEAN STDCALL
KeInsertByKeyDeviceQueue (PKDEVICE_QUEUE DeviceQueue
,
159 PKDEVICE_QUEUE_ENTRY QueueEntry
,
162 BOOLEAN STDCALL
KeInsertDeviceQueue (PKDEVICE_QUEUE DeviceQueue
,
163 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
166 KeInsertHeadQueue(IN PKQUEUE Queue
,
167 IN PLIST_ENTRY Entry
);
170 KeInsertQueue(IN PKQUEUE Queue
,
171 IN PLIST_ENTRY Entry
);
173 BOOLEAN STDCALL
KeInsertQueueApc (PKAPC Apc
,
174 PVOID SystemArgument1
,
175 PVOID SystemArgument2
,
176 KPRIORITY PriorityBoost
);
178 BOOLEAN STDCALL
KeInsertQueueDpc (PKDPC Dpc
,
179 PVOID SystemArgument1
,
180 PVOID SystemArgument2
);
182 VOID STDCALL
KeLeaveCriticalRegion (VOID
);
184 VOID STDCALL
KeLowerIrql (KIRQL NewIrql
);
186 NTSTATUS STDCALL
KePulseEvent (PKEVENT Event
,
192 KeQueryPerformanceCounter (
193 PLARGE_INTEGER PerformanceFrequency
199 PLARGE_INTEGER CurrentTime
205 PLARGE_INTEGER TickCount
210 KeQueryTimeIncrement (
223 KeRaiseIrqlToDpcLevel (
228 * FUNCTION: Raises a user mode exception
230 * ExceptionCode = Status code of the exception
234 KeRaiseUserException (
235 IN NTSTATUS ExceptionCode
245 KeReadStateMutant(IN PKMUTANT Mutant
);
248 KeReadStateMutex(IN PKMUTEX Mutex
);
251 KeReadStateQueue(IN PKQUEUE Queue
);
254 KeReadStateSemaphore(IN PKSEMAPHORE Semaphore
);
257 KeReadStateTimer(IN PKTIMER Timer
);
261 KeRegisterBugCheckCallback (
262 PKBUGCHECK_CALLBACK_RECORD CallbackRecord
,
263 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine
,
273 IN KPRIORITY Increment
,
288 PKSEMAPHORE Semaphore
,
297 PKSPIN_LOCK Spinlock
,
303 KeReleaseSpinLockFromDpcLevel (
309 KeRemoveByKeyDeviceQueue (
310 PKDEVICE_QUEUE DeviceQueue
,
316 KeRemoveDeviceQueue (
317 PKDEVICE_QUEUE DeviceQueue
321 KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
322 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
325 KeRemoveQueue(IN PKQUEUE Queue
,
326 IN KPROCESSOR_MODE WaitMode
,
327 IN PLARGE_INTEGER Timeout OPTIONAL
);
330 KeRemoveQueueDpc(IN PKDPC Dpc
);
333 KeResetEvent(IN PKEVENT Event
);
336 KeSetBasePriorityThread(struct _KTHREAD
* Thread
,
347 KPRIORITY STDCALL
KeSetPriorityThread (struct _KTHREAD
* Thread
,
350 BOOLEAN STDCALL
KeSetTimer (PKTIMER Timer
,
351 LARGE_INTEGER DueTime
,
354 BOOLEAN STDCALL
KeSetTimerEx (PKTIMER Timer
,
355 LARGE_INTEGER DueTime
,
359 VOID STDCALL
KeStallExecutionProcessor (ULONG MicroSeconds
);
361 BOOLEAN STDCALL
KeSynchronizeExecution (PKINTERRUPT Interrupt
,
362 PKSYNCHRONIZE_ROUTINE SynchronizeRoutine
,
363 PVOID SynchronizeContext
);
365 NTSTATUS STDCALL
KeWaitForMultipleObjects (ULONG Count
,
368 KWAIT_REASON WaitReason
,
369 KPROCESSOR_MODE WaitMode
,
371 PLARGE_INTEGER Timeout
,
372 PKWAIT_BLOCK WaitBlockArray
);
376 KeWaitForMutexObject (
378 KWAIT_REASON WaitReason
,
379 KPROCESSOR_MODE WaitMode
,
381 PLARGE_INTEGER Timeout
386 KeWaitForSingleObject (
388 KWAIT_REASON WaitReason
,
389 KPROCESSOR_MODE WaitMode
,
391 PLARGE_INTEGER Timeout
396 // io permission map has a 8k size
397 // Each bit in the IOPM corresponds to an io port byte address. The bitmap
398 // is initialized to allow IO at any port. [ all bits set ].
406 * FUNCTION: Provides the kernel with a new access map for a driver
408 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
409 * the kernel disables access to a particular port.
410 * IoPortMap = Caller supplies storage for the io permission map.
412 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
413 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
414 * the minium privilege level required to perform IO prior to checking the permission map.
416 VOID
Ke386SetIoAccessMap(ULONG NewMap
, PIOPM
*IoPermissionMap
);
419 * FUNCTION: Queries the io permission map.
421 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
422 * the kernel disables access to a particular port.
423 * IoPortMap = Caller supplies storage for the io permission map.
425 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
426 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
427 * the minium privilege level required to perform IO prior to checking the permission map.
429 VOID
Ke386QueryIoAccessMap(BOOLEAN NewMap
, PIOPM
*IoPermissionMap
);
432 * FUNCTION: Set the process IOPL
434 * Eprocess = Pointer to a executive process object
435 * EnableIo = Specify TRUE to enable IO and FALSE to disable
437 NTSTATUS
Ke386IoSetAccessProcess(struct _EPROCESS
* Eprocess
, BOOLEAN EnableIo
);
440 * FUNCTION: Releases a set of Global Descriptor Table Selectors
445 NTSTATUS
KeI386ReleaseGdtSelectors(OUT PULONG SelArray
,
446 IN ULONG NumOfSelectors
);
449 * FUNCTION: Allocates a set of Global Descriptor Table Selectors
454 NTSTATUS
KeI386AllocateGdtSelectors(OUT PULONG SelArray
,
455 IN ULONG NumOfSelectors
);
461 IN PKSPIN_LOCK SpinLock
480 IN PKSPIN_LOCK SpinLock
,
485 VOID STDCALL
KiDeliverApc(ULONG Unknown1
,
489 VOID STDCALL
KiDispatchInterrupt(VOID
);
491 #endif /* __INCLUDE_DDK_KEFUNCS_H */