1 #ifndef __INCLUDE_DDK_KEFUNCS_H
2 #define __INCLUDE_DDK_KEFUNCS_H
5 /* KERNEL FUNCTIONS ********************************************************/
7 #ifndef KeFlushIoBuffers
8 #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
11 VOID STDCALL
KeAttachProcess (struct _EPROCESS
* Process
);
13 VOID
KeDrainApcQueue(VOID
);
14 struct _KPROCESS
* KeGetCurrentProcess(VOID
);
17 * FUNCTION: Acquires a spinlock so the caller can synchronize access to
20 * SpinLock = Initialized spinlock
21 * OldIrql (OUT) = Set the previous irql on return
23 VOID STDCALL
KeAcquireSpinLock (PKSPIN_LOCK SpinLock
,
28 VOID STDCALL
KeAcquireSpinLockAtDpcLevel (IN PKSPIN_LOCK SpinLock
);
35 //KefAcquireSpinLockAtDpcLevel(
36 // IN PKSPIN_LOCK SpinLock);
38 #define KefAcquireSpinLockAtDpcLevel KeAcquireSpinLockAtDpcLevel
45 KeReleaseSpinLockFromDpcLevel(
46 IN PKSPIN_LOCK SpinLock
);
51 * FUNCTION: Brings the system down in a controlled manner when an
52 * inconsistency that might otherwise cause corruption has been detected
54 * BugCheckCode = Specifies the reason for the bug check
57 * NOTES - please use the macro KEBUGCHECK with the same argument so the end-user
58 * knows what file/line number where the bug check occured
60 VOID STDCALL
KeBugCheck (ULONG BugCheckCode
);
61 #define KEBUGCHECK(a) DbgPrint("KeBugCheck at %s:%i\n",__FILE__,__LINE__), KeBugCheck(a)
64 * FUNCTION: Brings the system down in a controlled manner when an
65 * inconsistency that might otherwise cause corruption has been detected
67 * BugCheckCode = Specifies the reason for the bug check
68 * BugCheckParameter[1-4] = Additional information about bug
71 * NOTES - please use the macro KEBUGCHECKEX with the same arguments so the end-user
72 * knows what file/line number where the bug check occured
74 VOID STDCALL
KeBugCheckEx (ULONG BugCheckCode
,
75 ULONG BugCheckParameter1
,
76 ULONG BugCheckParameter2
,
77 ULONG BugCheckParameter3
,
78 ULONG BugCheckParameter4
);
79 #define KEBUGCHECKEX(a,b,c,d,e) DbgPrint("KeBugCheckEx at %s:%i\n",__FILE__,__LINE__), KeBugCheckEx(a,b,c,d,e)
81 BOOLEAN STDCALL
KeCancelTimer (PKTIMER Timer
);
83 VOID STDCALL
KeClearEvent (PKEVENT Event
);
85 NTSTATUS STDCALL
KeConnectInterrupt(PKINTERRUPT InterruptObject
);
87 NTSTATUS STDCALL
KeDelayExecutionThread (KPROCESSOR_MODE WaitMode
,
89 PLARGE_INTEGER Internal
);
91 BOOLEAN STDCALL
KeDeregisterBugCheckCallback (
92 PKBUGCHECK_CALLBACK_RECORD CallbackRecord
);
94 VOID STDCALL
KeDetachProcess (VOID
);
96 VOID STDCALL
KeDisconnectInterrupt(PKINTERRUPT InterruptObject
);
98 VOID STDCALL
KeEnterCriticalRegion (VOID
);
101 * FUNCTION: Enters the kernel debugger
105 VOID STDCALL
KeEnterKernelDebugger (VOID
);
107 VOID STDCALL
KeFlushWriteBuffer (VOID
);
109 KIRQL STDCALL
KeGetCurrentIrql (VOID
);
112 ULONG
KeGetCurrentProcessorNumber(VOID
);
113 ULONG
KeGetDcacheFillSize(VOID
);
114 ULONG STDCALL
KeGetPreviousMode (VOID
);
117 struct _KTHREAD
* STDCALL
KeGetCurrentThread (VOID
);
119 VOID STDCALL
KeInitializeApc (IN PKAPC Apc
,
122 IN PKKERNEL_ROUTINE KernelRoutine
,
123 IN PKRUNDOWN_ROUTINE RundownRoutine
,
124 IN PKNORMAL_ROUTINE NormalRoutine
,
131 * KeInitializeCallbackRecord (
132 * PKBUGCHECK_CALLBACK_RECORD CallbackRecord
135 #ifndef KeInitializeCallbackRecord
136 #define KeInitializeCallbackRecord(CallbackRecord) \
137 (CallbackRecord)->State = BufferEmpty
140 VOID STDCALL
KeInitializeDeviceQueue (PKDEVICE_QUEUE DeviceQueue
);
142 VOID STDCALL
KeInitializeDpc (PKDPC Dpc
,
143 PKDEFERRED_ROUTINE DeferredRoutine
,
144 PVOID DeferredContext
);
146 VOID STDCALL
KeInitializeEvent (PKEVENT Event
,
150 NTSTATUS STDCALL
KeInitializeInterrupt(PKINTERRUPT InterruptObject
,
151 PKSERVICE_ROUTINE ServiceRoutine
,
152 PVOID ServiceContext
,
153 PKSPIN_LOCK SpinLock
,
156 KIRQL SynchronizeIrql
,
157 KINTERRUPT_MODE InterruptMode
,
159 KAFFINITY ProcessorEnableMask
,
160 BOOLEAN FloatingSave
);
162 VOID STDCALL
KeInitializeMutant(IN PKMUTANT Mutant
,
163 IN BOOLEAN InitialOwner
);
165 VOID STDCALL
KeInitializeMutex (PKMUTEX Mutex
,
169 KeInitializeQueue(IN PKQUEUE Queue
,
173 KeRundownQueue(IN PKQUEUE Queue
);
175 VOID STDCALL
KeInitializeSemaphore (PKSEMAPHORE Semaphore
,
180 * FUNCTION: Initializes a spinlock
182 * SpinLock = Spinlock to initialize
184 VOID STDCALL
KeInitializeSpinLock (PKSPIN_LOCK SpinLock
);
186 VOID STDCALL
KeInitializeTimer (PKTIMER Timer
);
188 VOID STDCALL
KeInitializeTimerEx (PKTIMER Timer
,
191 BOOLEAN STDCALL
KeInsertByKeyDeviceQueue (PKDEVICE_QUEUE DeviceQueue
,
192 PKDEVICE_QUEUE_ENTRY QueueEntry
,
195 BOOLEAN STDCALL
KeInsertDeviceQueue (PKDEVICE_QUEUE DeviceQueue
,
196 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
199 KeInsertHeadQueue(IN PKQUEUE Queue
,
200 IN PLIST_ENTRY Entry
);
203 KeInsertQueue(IN PKQUEUE Queue
,
204 IN PLIST_ENTRY Entry
);
206 BOOLEAN STDCALL
KeInsertQueueApc (PKAPC Apc
,
207 PVOID SystemArgument1
,
208 PVOID SystemArgument2
,
209 KPRIORITY PriorityBoost
);
211 BOOLEAN STDCALL
KeInsertQueueDpc (PKDPC Dpc
,
212 PVOID SystemArgument1
,
213 PVOID SystemArgument2
);
215 VOID STDCALL
KeLeaveCriticalRegion (VOID
);
217 VOID STDCALL
KeLowerIrql (KIRQL NewIrql
);
219 NTSTATUS STDCALL
KePulseEvent (PKEVENT Event
,
225 KeQueryPerformanceCounter (
226 PLARGE_INTEGER PerformanceFrequency
232 PLARGE_INTEGER CurrentTime
238 PLARGE_INTEGER TickCount
243 KeQueryTimeIncrement (
256 KeRaiseIrqlToDpcLevel (
261 * FUNCTION: Raises a user mode exception
263 * ExceptionCode = Status code of the exception
267 KeRaiseUserException (
268 IN NTSTATUS ExceptionCode
278 KeReadStateMutant(IN PKMUTANT Mutant
);
281 KeReadStateMutex(IN PKMUTEX Mutex
);
284 KeReadStateQueue(IN PKQUEUE Queue
);
287 KeReadStateSemaphore(IN PKSEMAPHORE Semaphore
);
290 KeReadStateTimer(IN PKTIMER Timer
);
294 KeRegisterBugCheckCallback (
295 PKBUGCHECK_CALLBACK_RECORD CallbackRecord
,
296 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine
,
306 IN KPRIORITY Increment
,
321 PKSEMAPHORE Semaphore
,
330 PKSPIN_LOCK Spinlock
,
337 KeReleaseSpinLockFromDpcLevel (
344 KeRemoveByKeyDeviceQueue (
345 PKDEVICE_QUEUE DeviceQueue
,
351 KeRemoveDeviceQueue (
352 PKDEVICE_QUEUE DeviceQueue
356 KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
357 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
360 KeRemoveQueue(IN PKQUEUE Queue
,
361 IN KPROCESSOR_MODE WaitMode
,
362 IN PLARGE_INTEGER Timeout OPTIONAL
);
365 KeRemoveQueueDpc(IN PKDPC Dpc
);
368 KeResetEvent(IN PKEVENT Event
);
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.
451 VOID
Ke386SetIoAccessMap(ULONG NewMap
, PIOPM
*IoPermissionMap
);
454 * FUNCTION: Queries the io permission map.
456 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
457 * the kernel disables access to a particular port.
458 * IoPortMap = Caller supplies storage for the io permission map.
460 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
461 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
462 * the minium privilege level required to perform IO prior to checking the permission map.
464 VOID
Ke386QueryIoAccessMap(BOOLEAN NewMap
, PIOPM
*IoPermissionMap
);
467 * FUNCTION: Set the process IOPL
469 * Eprocess = Pointer to a executive process object
470 * EnableIo = Specify TRUE to enable IO and FALSE to disable
472 NTSTATUS
Ke386IoSetAccessProcess(struct _EPROCESS
* Eprocess
, BOOLEAN EnableIo
);
475 * FUNCTION: Releases a set of Global Descriptor Table Selectors
480 NTSTATUS
KeI386ReleaseGdtSelectors(OUT PULONG SelArray
,
481 IN ULONG NumOfSelectors
);
484 * FUNCTION: Allocates a set of Global Descriptor Table Selectors
489 NTSTATUS
KeI386AllocateGdtSelectors(OUT PULONG SelArray
,
490 IN ULONG NumOfSelectors
);
496 IN PKSPIN_LOCK SpinLock
515 IN PKSPIN_LOCK SpinLock
,
520 VOID STDCALL
KiDeliverApc(ULONG Unknown1
,
524 VOID STDCALL
KiDispatchInterrupt(VOID
);
526 #endif /* __INCLUDE_DDK_KEFUNCS_H */