1 #ifndef __INCLUDE_DDK_KEFUNCS_H
2 #define __INCLUDE_DDK_KEFUNCS_H
4 /* KERNEL FUNCTIONS ********************************************************/
12 PKKERNEL_ROUTINE KernelRoutine
,
13 PKRUNDOWN_ROUTINE RundownRoutine
,
14 PKNORMAL_ROUTINE NormalRoutine
,
19 void KeInsertQueueApc(struct _KAPC
*Apc
, PVOID SystemArgument1
,
20 PVOID SystemArgument2
, UCHAR Mode
);
21 void KeAttachProcess(struct _EPROCESS
* Process
);
22 void KeDetachProcess(VOID
);
23 VOID
KeDrainApcQueue(VOID
);
24 PKPROCESS
KeGetCurrentProcess(VOID
);
27 * FUNCTION: Acquires a spinlock so the caller can synchronize access to
30 * SpinLock = Initialized spinlock
31 * OldIrql (OUT) = Set the previous irql on return
33 VOID
KeAcquireSpinLock(PKSPIN_LOCK SpinLock
, PKIRQL OldIrql
);
35 VOID
KeAcquireSpinLockAtDpcLevel(PKSPIN_LOCK SpinLock
);
36 BOOLEAN
KeCancelTimer(PKTIMER Timer
);
37 VOID
KeClearEvent(PKEVENT Event
);
38 NTSTATUS
KeDelayExecutionThread(KPROCESSOR_MODE WaitMode
,
40 PLARGE_INTEGER Internal
);
41 BOOLEAN
KeDeregisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD
43 VOID
KeEnterCriticalRegion(VOID
);
44 VOID
KeFlushIoBuffers(PMDL Mdl
, BOOLEAN ReadOperation
, BOOLEAN DmaOperation
);
45 KIRQL
KeGetCurrentIrql(VOID
);
46 ULONG
KeGetCurrentProcessorNumber(VOID
);
47 ULONG
KeGetDcacheFillSize(VOID
);
48 PKTHREAD
KeGetCurrentThread(VOID
);
49 VOID
KeInitializeCallbackRecord(PKBUGCHECK_CALLBACK_RECORD CallbackRecord
);
50 VOID
KeInitializeDeviceQueue(PKDEVICE_QUEUE DeviceQueue
);
51 VOID
KeInitializeDpc(PKDPC Dpc
, PKDEFERRED_ROUTINE DeferredRoutine
,
52 PVOID DeferredContext
);
53 VOID
KeInitializeEvent(PKEVENT Event
, EVENT_TYPE Type
, BOOLEAN State
);
54 VOID
KeInitializeMutex(PKMUTEX Mutex
, ULONG Level
);
55 VOID
KeInitializeSemaphore(PKSEMAPHORE Semaphore
, LONG Count
, LONG Limit
);
56 VOID
KeInitializeTimer(PKTIMER Timer
);
57 VOID
KeInitializeTimerEx(PKTIMER Timer
, TIMER_TYPE Type
);
58 BOOLEAN
KeInsertByKeyDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
59 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
,
61 BOOLEAN
KeInsertDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
62 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
63 BOOLEAN
KeInsertQueueDpc(PKDPC Dpc
, PVOID SystemArgument1
,
64 PVOID SystemArgument2
);
65 VOID
KeLeaveCriticalRegion(VOID
);
66 VOID
KeLowerIrql(KIRQL NewIrql
);
67 LARGE_INTEGER
KeQueryPerformanceCounter(PLARGE_INTEGER PerformanceFrequency
);
68 VOID
KeQuerySystemTime(PLARGE_INTEGER CurrentTime
);
69 VOID
KeQueryTickCount(PLARGE_INTEGER TickCount
);
70 ULONG
KeQueryTimeIncrement(VOID
);
71 VOID
KeRaiseIrql(KIRQL NewIrql
, PKIRQL OldIrql
);
72 LONG
KeReadStateEvent(PKEVENT Event
);
73 LONG
KeReadStateMutex(PKMUTEX Mutex
);
74 LONG
KeReadStateSemaphore(PKSEMAPHORE Semaphore
);
75 BOOLEAN
KeReadStateTimer(PKTIMER Timer
);
76 BOOLEAN
KeRegisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord
,
77 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine
,
81 LONG
KeReleaseMutex(PKMUTEX Mutex
, BOOLEAN Wait
);
82 LONG
KeReleaseSemaphore(PKSEMAPHORE Semaphore
, KPRIORITY Increment
,
83 LONG Adjustment
, BOOLEAN Wait
);
84 VOID
KeReleaseSpinLock(PKSPIN_LOCK Spinlock
, KIRQL NewIrql
);
85 VOID
KeReleaseSpinLockFromDpcLevel(PKSPIN_LOCK Spinlock
);
86 PKDEVICE_QUEUE_ENTRY
KeRemoveByKeyDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
88 PKDEVICE_QUEUE_ENTRY
KeRemoveDeviceQueue(PKDEVICE_QUEUE DeviceQueue
);
89 BOOLEAN
KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue
,
90 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
91 BOOLEAN
KeRemoveQueueDpc(PKDPC Dpc
);
92 LONG
KeResetEvent(PKEVENT Event
);
93 LONG
KeSetBasePriorityThread(PKTHREAD Thread
, LONG Increment
);
94 LONG
KeSetEvent(PKEVENT Event
, KPRIORITY Increment
, BOOLEAN Wait
);
95 KPRIORITY
KeSetPriorityThread(PKTHREAD Thread
, KPRIORITY Priority
);
96 BOOLEAN
KeSetTimer(PKTIMER Timer
, LARGE_INTEGER DueTime
, PKDPC Dpc
);
97 BOOLEAN
KeSetTimerEx(PKTIMER Timer
, LARGE_INTEGER DueTime
, LONG Period
,
99 VOID
KeStallExecutionProcessor(ULONG MicroSeconds
);
100 BOOLEAN
KeSynchronizeExecution(PKINTERRUPT Interrupt
,
101 PKSYNCHRONIZE_ROUTINE SynchronizeRoutine
,
102 PVOID SynchronizeContext
);
103 NTSTATUS
KeWaitForMultipleObjects(ULONG Count
,
106 KWAIT_REASON WaitReason
,
107 KPROCESSOR_MODE WaitMode
,
109 PLARGE_INTEGER Timeout
,
110 PKWAIT_BLOCK WaitBlockArray
);
111 NTSTATUS
KeWaitForMutexObject(PKMUTEX Mutex
, KWAIT_REASON WaitReason
,
112 KPROCESSOR_MODE WaitMode
, BOOLEAN Alertable
,
113 PLARGE_INTEGER Timeout
);
114 NTSTATUS
KeWaitForSingleObject(PVOID Object
, KWAIT_REASON WaitReason
,
115 KPROCESSOR_MODE WaitMode
,
116 BOOLEAN Alertable
, PLARGE_INTEGER Timeout
);
119 * FUNCTION: Initializes a spinlock
121 * SpinLock = Spinlock to initialize
123 VOID
KeInitializeSpinLock(PKSPIN_LOCK SpinLock
);
126 * FUNCTION: Sets the current irql without altering the current processor
129 * newlvl = IRQ level to set
130 * NOTE: This is for internal use only
132 VOID
KeSetCurrentIrql(KIRQL newlvl
);
136 * FUNCTION: Brings the system down in a controlled manner when an
137 * inconsistency that might otherwise cause corruption has been detected
139 * BugCheckCode = Specifies the reason for the bug check
140 * BugCheckParameter[1-4] = Additional information about bug
143 VOID
KeBugCheckEx(ULONG BugCheckCode
,
144 ULONG BugCheckParameter1
,
145 ULONG BugCheckParameter2
,
146 ULONG BugCheckParameter3
,
147 ULONG BugCheckParameter4
);
150 * FUNCTION: Brings the system down in a controlled manner when an
151 * inconsistency that might otherwise cause corruption has been detected
153 * BugCheckCode = Specifies the reason for the bug check
156 VOID
KeBugCheck(ULONG BugCheckCode
);
158 // kmutant definition slightly modified from nt5 ddk
160 typedef struct _KMUTANT
162 DISPATCHER_HEADER Header
;
163 LIST_ENTRY MutantListEntry
;
164 struct _KTHREAD
* OwnerThread
;
167 } KMUTANT
, *PKMUTANT
;
169 // io permission map has a 8k size
170 // Each bit in the IOPM corresponds to an io port byte address. The bitmap
171 // is initialized to allow IO at any port. [ all bits set ].
179 * FUNCTION: Provides the kernel with a new access map for a driver
181 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
182 * the kernel disables access to a particular port.
183 * IoPortMap = Caller supplies storage for the io permission map.
185 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
186 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
187 * the minium privilege level required to perform IO prior to checking the permission map.
189 void Ke386SetIoAccessMap(int NewMap
, PIOPM
*IoPermissionMap
);
192 * FUNCTION: Queries the io permission map.
194 * NewMap: = If FALSE the kernel's map is set to all disabled. If TRUE
195 * the kernel disables access to a particular port.
196 * IoPortMap = Caller supplies storage for the io permission map.
198 * Each bit in the IOPM corresponds to an io port byte address. The bitmap
199 * is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
200 * the minium privilege level required to perform IO prior to checking the permission map.
202 void Ke386QueryIoAccessMap(BOOLEAN NewMap
, PIOPM
*IoPermissionMap
);
205 * FUNCTION: Set the process IOPL
207 * Eprocess = Pointer to a executive process object
208 * EnableIo = Specify TRUE to enable IO and FALSE to disable
210 NTSTATUS
Ke386IoSetAccessProcess(PEPROCESS Eprocess
, BOOLEAN EnableIo
);
213 * FUNCTION: Releases a set of Global Descriptor Table Selectors
218 NTSTATUS
KeI386ReleaseGdtSelectors(
220 IN ULONG NumOfSelectors
224 * FUNCTION: Allocates a set of Global Descriptor Table Selectors
229 NTSTATUS
KeI386AllocateGdtSelectors(
231 IN ULONG NumOfSelectors
235 * FUNCTION: Raises a user mode exception
237 * ExceptionCode = Status code of the exception
239 void KeRaiseUserException(NTSTATUS ExceptionCode
);
242 #endif /* __INCLUDE_DDK_KEFUNCS_H */