1 #ifndef __INCLUDE_DDK_KEFUNCS_H
2 #define __INCLUDE_DDK_KEFUNCS_H
4 /* KERNEL FUNCTIONS ********************************************************/
6 VOID
KeInitializeApc(PKAPC Apc
,
9 PKKERNEL_ROUTINE KernelRoutine
,
10 PKRUNDOWN_ROUTINE RundownRoutine
,
11 PKNORMAL_ROUTINE NormalRoutine
,
15 VOID
KeInsertQueueApc(PKAPC Apc
,
16 PVOID SystemArgument1
,
17 PVOID SystemArgument2
,
19 VOID
KeAttachProcess(struct _EPROCESS
* Process
);
20 VOID
KeDetachProcess(VOID
);
21 VOID
KeDrainApcQueue(VOID
);
22 PKPROCESS
KeGetCurrentProcess(VOID
);
25 * FUNCTION: Acquires a spinlock so the caller can synchronize access to
28 * SpinLock = Initialized spinlock
29 * OldIrql (OUT) = Set the previous irql on return
31 VOID
KeAcquireSpinLock(PKSPIN_LOCK SpinLock
, PKIRQL OldIrql
);
33 VOID
KeAcquireSpinLockAtDpcLevel(PKSPIN_LOCK SpinLock
);
34 BOOLEAN
KeCancelTimer(PKTIMER Timer
);
35 VOID
KeClearEvent(PKEVENT Event
);
36 NTSTATUS STDCALL
KeDelayExecutionThread (KPROCESSOR_MODE WaitMode
,
38 PLARGE_INTEGER Internal
);
39 BOOLEAN
KeDeregisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD
41 VOID
KeEnterCriticalRegion(VOID
);
42 VOID
KeFlushIoBuffers(PMDL Mdl
, BOOLEAN ReadOperation
, BOOLEAN DmaOperation
);
48 ULONG
KeGetCurrentProcessorNumber(VOID
);
49 ULONG
KeGetDcacheFillSize(VOID
);
50 PKTHREAD
KeGetCurrentThread(VOID
);
51 ULONG
KeGetPreviousMode(VOID
);
52 VOID
KeInitializeCallbackRecord(PKBUGCHECK_CALLBACK_RECORD CallbackRecord
);
53 VOID
KeInitializeDeviceQueue(PKDEVICE_QUEUE DeviceQueue
);
54 VOID
KeInitializeDpc(PKDPC Dpc
, PKDEFERRED_ROUTINE DeferredRoutine
,
55 PVOID DeferredContext
);
56 VOID
KeInitializeEvent(PKEVENT Event
, EVENT_TYPE Type
, BOOLEAN State
);
57 VOID
KeInitializeMutex(PKMUTEX Mutex
, ULONG Level
);
58 VOID
KeInitializeSemaphore(PKSEMAPHORE Semaphore
, LONG Count
, LONG Limit
);
59 VOID
KeInitializeTimer(PKTIMER Timer
);
60 VOID
KeInitializeTimerEx(PKTIMER Timer
, TIMER_TYPE Type
);
61 BOOLEAN
KeInsertByKeyDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
62 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
,
64 BOOLEAN
KeInsertDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
65 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
66 BOOLEAN
KeInsertQueueDpc(PKDPC Dpc
, PVOID SystemArgument1
,
67 PVOID SystemArgument2
);
68 VOID
KeLeaveCriticalRegion(VOID
);
74 LARGE_INTEGER
KeQueryPerformanceCounter(PLARGE_INTEGER PerformanceFrequency
);
75 VOID
KeQuerySystemTime(PLARGE_INTEGER CurrentTime
);
76 VOID
KeQueryTickCount(PLARGE_INTEGER TickCount
);
77 ULONG
KeQueryTimeIncrement(VOID
);
84 LONG
KeReadStateEvent(PKEVENT Event
);
85 LONG
KeReadStateMutex(PKMUTEX Mutex
);
86 LONG
KeReadStateSemaphore(PKSEMAPHORE Semaphore
);
87 BOOLEAN
KeReadStateTimer(PKTIMER Timer
);
88 BOOLEAN
KeRegisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord
,
89 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine
,
93 LONG
KeReleaseMutex(PKMUTEX Mutex
, BOOLEAN Wait
);
94 LONG
KeReleaseSemaphore(PKSEMAPHORE Semaphore
, KPRIORITY Increment
,
95 LONG Adjustment
, BOOLEAN Wait
);
96 VOID
KeReleaseSpinLock(PKSPIN_LOCK Spinlock
, KIRQL NewIrql
);
97 VOID
KeReleaseSpinLockFromDpcLevel(PKSPIN_LOCK Spinlock
);
98 PKDEVICE_QUEUE_ENTRY
KeRemoveByKeyDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
100 PKDEVICE_QUEUE_ENTRY
KeRemoveDeviceQueue(PKDEVICE_QUEUE DeviceQueue
);
101 BOOLEAN
KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
102 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
103 BOOLEAN
KeRemoveQueueDpc(PKDPC Dpc
);
104 LONG
KeResetEvent(PKEVENT Event
);
105 LONG
KeSetBasePriorityThread(PKTHREAD Thread
, LONG Increment
);
106 LONG
KeSetEvent(PKEVENT Event
, KPRIORITY Increment
, BOOLEAN Wait
);
107 KPRIORITY
KeSetPriorityThread(PKTHREAD Thread
, KPRIORITY Priority
);
108 BOOLEAN
KeSetTimer(PKTIMER Timer
, LARGE_INTEGER DueTime
, PKDPC Dpc
);
109 BOOLEAN
KeSetTimerEx(PKTIMER Timer
,
110 LARGE_INTEGER DueTime
,
113 VOID
KeStallExecutionProcessor(ULONG MicroSeconds
);
114 BOOLEAN
KeSynchronizeExecution(PKINTERRUPT Interrupt
,
115 PKSYNCHRONIZE_ROUTINE SynchronizeRoutine
,
116 PVOID SynchronizeContext
);
117 NTSTATUS
KeWaitForMultipleObjects(ULONG Count
,
120 KWAIT_REASON WaitReason
,
121 KPROCESSOR_MODE WaitMode
,
123 PLARGE_INTEGER Timeout
,
124 PKWAIT_BLOCK WaitBlockArray
);
125 NTSTATUS
KeWaitForMutexObject(PKMUTEX Mutex
,
126 KWAIT_REASON WaitReason
,
127 KPROCESSOR_MODE WaitMode
,
129 PLARGE_INTEGER Timeout
);
130 NTSTATUS
KeWaitForSingleObject(PVOID Object
,
131 KWAIT_REASON WaitReason
,
132 KPROCESSOR_MODE WaitMode
,
134 PLARGE_INTEGER Timeout
);
137 * FUNCTION: Initializes a spinlock
139 * SpinLock = Spinlock to initialize
141 VOID
KeInitializeSpinLock(PKSPIN_LOCK SpinLock
);
144 * FUNCTION: Sets the current irql without altering the current processor
147 * newlvl = IRQ level to set
148 * NOTE: This is for internal use only
150 VOID
KeSetCurrentIrql(KIRQL newlvl
);
154 * FUNCTION: Brings the system down in a controlled manner when an
155 * inconsistency that might otherwise cause corruption has been detected
157 * BugCheckCode = Specifies the reason for the bug check
158 * BugCheckParameter[1-4] = Additional information about bug
161 VOID
KeBugCheckEx(ULONG BugCheckCode
,
162 ULONG BugCheckParameter1
,
163 ULONG BugCheckParameter2
,
164 ULONG BugCheckParameter3
,
165 ULONG BugCheckParameter4
);
168 * FUNCTION: Brings the system down in a controlled manner when an
169 * inconsistency that might otherwise cause corruption has been detected
171 * BugCheckCode = Specifies the reason for the bug check
174 VOID
KeBugCheck(ULONG BugCheckCode
);
176 // io permission map has a 8k size
177 // Each bit in the IOPM corresponds to an io port byte address. The bitmap
178 // is initialized to allow IO at any port. [ all bits set ].
186 * FUNCTION: Provides the kernel with a new access map for a driver
188 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
189 * the kernel disables access to a particular port.
190 * IoPortMap = Caller supplies storage for the io permission map.
192 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
193 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
194 * the minium privilege level required to perform IO prior to checking the permission map.
196 VOID
Ke386SetIoAccessMap(ULONG NewMap
, PIOPM
*IoPermissionMap
);
199 * FUNCTION: Queries the io permission map.
201 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
202 * the kernel disables access to a particular port.
203 * IoPortMap = Caller supplies storage for the io permission map.
205 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
206 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
207 * the minium privilege level required to perform IO prior to checking the permission map.
209 VOID
Ke386QueryIoAccessMap(BOOLEAN NewMap
, PIOPM
*IoPermissionMap
);
212 * FUNCTION: Set the process IOPL
214 * Eprocess = Pointer to a executive process object
215 * EnableIo = Specify TRUE to enable IO and FALSE to disable
217 NTSTATUS
Ke386IoSetAccessProcess(PEPROCESS Eprocess
, BOOLEAN EnableIo
);
220 * FUNCTION: Releases a set of Global Descriptor Table Selectors
225 NTSTATUS
KeI386ReleaseGdtSelectors(OUT PULONG SelArray
,
226 IN ULONG NumOfSelectors
);
229 * FUNCTION: Allocates a set of Global Descriptor Table Selectors
234 NTSTATUS
KeI386AllocateGdtSelectors(OUT PULONG SelArray
,
235 IN ULONG NumOfSelectors
);
238 * FUNCTION: Raises a user mode exception
240 * ExceptionCode = Status code of the exception
242 VOID
KeRaiseUserException(NTSTATUS ExceptionCode
);
246 * FUNCTION: Enters the kernel debugger
252 KeEnterKernelDebugger (VOID
);
275 #endif /* __INCLUDE_DDK_KEFUNCS_H */