update for HEAD-2003050101
[reactos.git] / include / ddk / kefuncs.h
1 #ifndef __INCLUDE_DDK_KEFUNCS_H
2 #define __INCLUDE_DDK_KEFUNCS_H
3
4
5 /* KERNEL FUNCTIONS ********************************************************/
6
7 #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
8
9 VOID STDCALL KeAttachProcess (struct _EPROCESS* Process);
10
11 VOID KeDrainApcQueue(VOID);
12 struct _KPROCESS* KeGetCurrentProcess(VOID);
13
14 /*
15  * FUNCTION: Acquires a spinlock so the caller can synchronize access to 
16  * data
17  * ARGUMENTS:
18  *         SpinLock = Initialized spinlock
19  *         OldIrql (OUT) = Set the previous irql on return 
20  */
21 VOID STDCALL KeAcquireSpinLock (PKSPIN_LOCK     SpinLock,
22                                 PKIRQL          OldIrql);
23
24 VOID STDCALL KeAcquireSpinLockAtDpcLevel (PKSPIN_LOCK   SpinLock);
25
26 /*
27  * FUNCTION: Brings the system down in a controlled manner when an 
28  * inconsistency that might otherwise cause corruption has been detected
29  * ARGUMENTS:
30  *           BugCheckCode = Specifies the reason for the bug check
31  * RETURNS: Doesn't
32  */
33 VOID STDCALL KeBugCheck (ULONG  BugCheckCode);
34
35
36 /*
37  * FUNCTION: Brings the system down in a controlled manner when an 
38  * inconsistency that might otherwise cause corruption has been detected
39  * ARGUMENTS:
40  *           BugCheckCode = Specifies the reason for the bug check
41  *           BugCheckParameter[1-4] = Additional information about bug
42  * RETURNS: Doesn't
43  */
44 VOID STDCALL KeBugCheckEx (ULONG        BugCheckCode,
45                            ULONG        BugCheckParameter1,
46                            ULONG        BugCheckParameter2,
47                            ULONG        BugCheckParameter3,
48                            ULONG        BugCheckParameter4);
49
50 BOOLEAN STDCALL KeCancelTimer (PKTIMER  Timer);
51
52 VOID STDCALL KeClearEvent (PKEVENT      Event);
53
54 NTSTATUS STDCALL KeConnectInterrupt(PKINTERRUPT InterruptObject);
55
56 NTSTATUS STDCALL KeDelayExecutionThread (KPROCESSOR_MODE        WaitMode,
57                                          BOOLEAN                Alertable,
58                                          PLARGE_INTEGER Internal);
59
60 BOOLEAN STDCALL KeDeregisterBugCheckCallback (
61                        PKBUGCHECK_CALLBACK_RECORD       CallbackRecord);
62
63 VOID STDCALL KeDetachProcess (VOID);
64
65 VOID STDCALL KeDisconnectInterrupt(PKINTERRUPT InterruptObject);
66
67 VOID STDCALL KeEnterCriticalRegion (VOID);
68
69 /*
70  * FUNCTION: Enters the kernel debugger
71  * ARGUMENTS:
72  *      None
73  */
74 VOID STDCALL KeEnterKernelDebugger (VOID);
75
76 VOID STDCALL KeFlushWriteBuffer (VOID);
77
78 KIRQL STDCALL KeGetCurrentIrql (VOID);
79
80 ULONG KeGetCurrentProcessorNumber(VOID);
81
82 struct _KTHREAD* STDCALL KeGetCurrentThread (VOID);
83
84 ULONG KeGetDcacheFillSize(VOID);
85
86 ULONG STDCALL KeGetPreviousMode (VOID);
87
88 VOID STDCALL KeInitializeApc (PKAPC                     Apc,
89                               struct _KTHREAD*          Thread,
90                               UCHAR                     StateIndex,
91                               PKKERNEL_ROUTINE  KernelRoutine,
92                               PKRUNDOWN_ROUTINE RundownRoutine,
93                               PKNORMAL_ROUTINE  NormalRoutine,
94                               UCHAR                     Mode,
95                               PVOID                     Context);
96
97 /*
98  * VOID
99  * KeInitializeCallbackRecord (
100  *      PKBUGCHECK_CALLBACK_RECORD CallbackRecord
101  *      );
102  */
103 #define KeInitializeCallbackRecord(CallbackRecord) \
104         (CallbackRecord)->State = BufferEmpty
105
106 VOID STDCALL KeInitializeDeviceQueue (PKDEVICE_QUEUE    DeviceQueue);
107
108 VOID STDCALL KeInitializeDpc (PKDPC                     Dpc,
109                               PKDEFERRED_ROUTINE        DeferredRoutine,
110                               PVOID                     DeferredContext);
111
112 VOID STDCALL KeInitializeEvent (PKEVENT         Event,
113                                 EVENT_TYPE      Type,
114                                 BOOLEAN         State);
115
116 NTSTATUS STDCALL KeInitializeInterrupt(PKINTERRUPT InterruptObject,
117                                        PKSERVICE_ROUTINE ServiceRoutine,
118                                        PVOID ServiceContext,
119                                        PKSPIN_LOCK SpinLock,
120                                        ULONG Vector,
121                                        KIRQL Irql,
122                                        KIRQL SynchronizeIrql,
123                                        KINTERRUPT_MODE InterruptMode,
124                                        BOOLEAN ShareVector,
125                                        KAFFINITY ProcessorEnableMask,
126                                        BOOLEAN FloatingSave);
127
128 VOID STDCALL KeInitializeMutant(IN PKMUTANT Mutant,
129                                 IN BOOLEAN InitialOwner);
130
131 VOID STDCALL KeInitializeMutex (PKMUTEX Mutex,
132                                 ULONG   Level);
133
134 VOID STDCALL
135 KeInitializeQueue(IN PKQUEUE Queue,
136                   IN ULONG Count);
137
138 PLIST_ENTRY STDCALL
139 KeRundownQueue(IN PKQUEUE Queue);
140
141 VOID STDCALL KeInitializeSemaphore (PKSEMAPHORE Semaphore,
142                                     LONG                Count,
143                                     LONG                Limit);
144
145 /*
146  * FUNCTION: Initializes a spinlock
147  * ARGUMENTS:
148  *        SpinLock = Spinlock to initialize
149  */
150 VOID STDCALL KeInitializeSpinLock (PKSPIN_LOCK  SpinLock);
151
152 VOID STDCALL KeInitializeTimer (PKTIMER Timer);
153
154 VOID STDCALL KeInitializeTimerEx (PKTIMER               Timer,
155                                   TIMER_TYPE    Type);
156
157 BOOLEAN STDCALL KeInsertByKeyDeviceQueue (PKDEVICE_QUEUE DeviceQueue,
158                                           PKDEVICE_QUEUE_ENTRY  QueueEntry,
159                                           ULONG                 SortKey);
160
161 BOOLEAN STDCALL KeInsertDeviceQueue (PKDEVICE_QUEUE             DeviceQueue,
162                                      PKDEVICE_QUEUE_ENTRY DeviceQueueEntry);
163
164 LONG STDCALL
165 KeInsertHeadQueue(IN PKQUEUE Queue,
166                   IN PLIST_ENTRY Entry);
167
168 LONG STDCALL
169 KeInsertQueue(IN PKQUEUE Queue,
170               IN PLIST_ENTRY Entry);
171
172 VOID STDCALL KeInsertQueueApc (PKAPC    Apc,
173                                PVOID    SystemArgument1,
174                                PVOID    SystemArgument2,
175                                UCHAR    Mode);
176
177 BOOLEAN STDCALL KeInsertQueueDpc (PKDPC Dpc,
178                                   PVOID SystemArgument1,
179                                   PVOID SystemArgument2);
180
181 VOID STDCALL KeLeaveCriticalRegion (VOID);
182
183 VOID STDCALL KeLowerIrql (KIRQL NewIrql);
184
185 NTSTATUS STDCALL KePulseEvent (PKEVENT          Event,
186                                KPRIORITY        Increment,
187                                BOOLEAN          Wait);
188
189 LARGE_INTEGER
190 STDCALL
191 KeQueryPerformanceCounter (
192         PLARGE_INTEGER  PerformanceFrequency
193         );
194
195 VOID
196 STDCALL
197 KeQuerySystemTime (
198         PLARGE_INTEGER  CurrentTime
199         );
200
201 VOID
202 STDCALL
203 KeQueryTickCount (
204         PLARGE_INTEGER  TickCount
205         );
206
207 ULONG
208 STDCALL
209 KeQueryTimeIncrement (
210         VOID
211         );
212
213 VOID
214 STDCALL
215 KeRaiseIrql (
216         KIRQL   NewIrql,
217         PKIRQL  OldIrql
218         );
219
220 KIRQL
221 STDCALL
222 KeRaiseIrqlToDpcLevel (
223         VOID
224         );
225
226 KIRQL
227 STDCALL
228 KeRaiseIrqlToSynchLevel (
229         VOID
230         );
231
232 /*
233  * FUNCTION: Raises a user mode exception
234  * ARGUMENTS:
235  *      ExceptionCode = Status code of the exception
236  */
237 VOID
238 STDCALL
239 KeRaiseUserException (
240         IN      NTSTATUS        ExceptionCode
241         );
242
243 LONG
244 STDCALL
245 KeReadStateEvent (
246         PKEVENT Event
247         );
248
249 LONG STDCALL
250 KeReadStateMutant(IN PKMUTANT Mutant);
251
252 LONG STDCALL
253 KeReadStateMutex(IN PKMUTEX Mutex);
254
255 LONG STDCALL
256 KeReadStateQueue(IN PKQUEUE Queue);
257
258 LONG STDCALL
259 KeReadStateSemaphore(IN PKSEMAPHORE Semaphore);
260
261 BOOLEAN STDCALL
262 KeReadStateTimer(IN PKTIMER Timer);
263
264 BOOLEAN
265 STDCALL
266 KeRegisterBugCheckCallback (
267         PKBUGCHECK_CALLBACK_RECORD      CallbackRecord,
268         PKBUGCHECK_CALLBACK_ROUTINE     CallbackRoutine,
269         PVOID                           Buffer,
270         ULONG                           Length,
271         PUCHAR                          Component
272         );
273
274 LONG
275 STDCALL
276 KeReleaseMutant(
277         IN PKMUTANT Mutant,
278         IN KPRIORITY Increment,
279         IN BOOLEAN Abandon,
280         IN BOOLEAN Wait
281         );
282
283 LONG
284 STDCALL
285 KeReleaseMutex (
286         PKMUTEX Mutex,
287         BOOLEAN Wait
288         );
289
290 LONG
291 STDCALL
292 KeReleaseSemaphore (
293         PKSEMAPHORE     Semaphore,
294         KPRIORITY       Increment,
295         LONG            Adjustment,
296         BOOLEAN         Wait
297         );
298
299 VOID
300 STDCALL
301 KeReleaseSpinLock (
302         PKSPIN_LOCK     Spinlock,
303         KIRQL           NewIrql
304         );
305
306 VOID
307 STDCALL
308 KeReleaseSpinLockFromDpcLevel (
309         PKSPIN_LOCK     Spinlock
310         );
311
312 PKDEVICE_QUEUE_ENTRY
313 STDCALL
314 KeRemoveByKeyDeviceQueue (
315         PKDEVICE_QUEUE  DeviceQueue,
316         ULONG           SortKey
317         );
318
319 PKDEVICE_QUEUE_ENTRY
320 STDCALL
321 KeRemoveDeviceQueue (
322         PKDEVICE_QUEUE  DeviceQueue
323         );
324
325 BOOLEAN STDCALL
326 KeRemoveEntryDeviceQueue(PKDEVICE_QUEUE DeviceQueue,
327                          PKDEVICE_QUEUE_ENTRY DeviceQueueEntry);
328
329 PLIST_ENTRY STDCALL
330 KeRemoveQueue(IN PKQUEUE Queue,
331               IN KPROCESSOR_MODE WaitMode,
332               IN PLARGE_INTEGER Timeout OPTIONAL);
333
334 BOOLEAN STDCALL
335 KeRemoveQueueDpc(IN PKDPC Dpc);
336
337 LONG STDCALL
338 KeResetEvent(IN PKEVENT Event);
339
340 LONG STDCALL
341 KeSetBasePriorityThread(struct _KTHREAD* Thread,
342                         LONG Increment);
343
344 LONG
345 STDCALL
346 KeSetEvent (
347         PKEVENT         Event,
348         KPRIORITY       Increment,
349         BOOLEAN         Wait
350         );
351
352 KPRIORITY STDCALL KeSetPriorityThread (struct _KTHREAD* Thread,
353                                        KPRIORITY        Priority);
354
355 BOOLEAN STDCALL KeSetTimer (PKTIMER             Timer,
356                             LARGE_INTEGER       DueTime,
357                             PKDPC               Dpc);
358
359 BOOLEAN STDCALL KeSetTimerEx (PKTIMER           Timer,
360                               LARGE_INTEGER     DueTime,
361                               LONG              Period,
362                               PKDPC             Dpc);
363
364 VOID STDCALL KeStallExecutionProcessor (ULONG   MicroSeconds);
365
366 BOOLEAN STDCALL KeSynchronizeExecution (PKINTERRUPT             Interrupt,
367                                         PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
368                                         PVOID SynchronizeContext);
369
370 NTSTATUS STDCALL KeWaitForMultipleObjects (ULONG                Count,
371                                            PVOID                Object[],
372                                            WAIT_TYPE    WaitType,
373                                            KWAIT_REASON WaitReason,
374                                            KPROCESSOR_MODE      WaitMode,
375                                            BOOLEAN              Alertable,
376                                            PLARGE_INTEGER       Timeout,
377                                            PKWAIT_BLOCK WaitBlockArray);
378
379 NTSTATUS
380 STDCALL
381 KeWaitForMutexObject (
382         PKMUTEX         Mutex,
383         KWAIT_REASON    WaitReason,
384         KPROCESSOR_MODE WaitMode,
385         BOOLEAN         Alertable,
386         PLARGE_INTEGER  Timeout
387         );
388
389 NTSTATUS
390 STDCALL
391 KeWaitForSingleObject (
392         PVOID           Object,
393         KWAIT_REASON    WaitReason,
394         KPROCESSOR_MODE WaitMode,
395         BOOLEAN         Alertable,
396         PLARGE_INTEGER  Timeout
397         );
398
399
400
401 // io permission map has a 8k size
402 // Each bit in the IOPM corresponds to an io port byte address. The bitmap
403 // is initialized to allow IO at any port. [ all bits set ]. 
404
405 typedef struct _IOPM
406 {
407         UCHAR Bitmap[8192];
408 } IOPM, *PIOPM;
409
410 /*
411  * FUNCTION: Provides the kernel with a new access map for a driver
412  * ARGUMENTS:
413  *      NewMap: =  If FALSE the kernel's map is set to all disabled. If TRUE
414  *                      the kernel disables access to a particular port.
415  *      IoPortMap = Caller supplies storage for the io permission map.
416  * REMARKS
417  *      Each bit in the IOPM corresponds to an io port byte address. The bitmap
418  *      is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
419  *      the minium privilege level required to perform IO prior to checking the permission map.
420  */
421 VOID Ke386SetIoAccessMap(ULONG NewMap, PIOPM *IoPermissionMap);
422
423 /*
424  * FUNCTION: Queries the io permission  map.
425  * ARGUMENTS:
426  *      NewMap: =  If FALSE the kernel's map is set to all disabled. If TRUE
427  *                      the kernel disables access to a particular port.
428  *      IoPortMap = Caller supplies storage for the io permission map.
429  * REMARKS
430  *      Each bit in the IOPM corresponds to an io port byte address. The bitmap
431  *      is initialized to allow IO at any port. [ all bits set ]. The IOPL determines
432  *      the minium privilege level required to perform IO prior to checking the permission map.
433  */
434 VOID Ke386QueryIoAccessMap(BOOLEAN NewMap, PIOPM *IoPermissionMap);
435
436 /*
437  * FUNCTION: Set the process IOPL
438  * ARGUMENTS:
439  *      Eprocess = Pointer to a executive process object
440  *      EnableIo = Specify TRUE to enable IO and FALSE to disable 
441  */
442 NTSTATUS Ke386IoSetAccessProcess(struct _EPROCESS* Eprocess, BOOLEAN EnableIo);
443
444 /*
445  * FUNCTION: Releases a set of Global Descriptor Table Selectors
446  * ARGUMENTS:
447  *      SelArray = 
448  *      NumOfSelectors = 
449  */
450 NTSTATUS KeI386ReleaseGdtSelectors(OUT PULONG SelArray,
451                                    IN ULONG NumOfSelectors);
452
453 /*
454  * FUNCTION: Allocates a set of Global Descriptor Table Selectors
455  * ARGUMENTS:
456  *      SelArray = 
457  *      NumOfSelectors = 
458  */
459 NTSTATUS KeI386AllocateGdtSelectors(OUT PULONG SelArray,
460                                     IN ULONG NumOfSelectors);
461
462
463 KIRQL
464 FASTCALL
465 KfAcquireSpinLock (
466         IN      PKSPIN_LOCK     SpinLock
467         );
468
469 VOID
470 FASTCALL
471 KfLowerIrql (
472         IN      KIRQL   NewIrql
473         );
474
475
476 KIRQL
477 FASTCALL
478 KfRaiseIrql (
479         IN      KIRQL   NewIrql
480         );
481
482 VOID
483 FASTCALL
484 KfReleaseSpinLock (
485         IN      PKSPIN_LOCK     SpinLock,
486         IN      KIRQL           NewIrql
487         );
488
489
490 VOID STDCALL KiDeliverApc(ULONG Unknown1,
491                           ULONG Unknown2,
492                           ULONG Unknown3);
493
494 VOID STDCALL KiDispatchInterrupt(VOID);
495
496 #endif /* __INCLUDE_DDK_KEFUNCS_H */