3976c9826871612748dcad2c255adaacfd64a695
[reactos.git] / reactos / ntoskrnl / include / internal / ke.h
1 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_KE_H
2 #define __NTOSKRNL_INCLUDE_INTERNAL_KE_H
3
4 /* INCLUDES *****************************************************************/
5
6 #include "arch/ke.h"
7
8 /* INTERNAL KERNEL TYPES ****************************************************/
9
10 typedef struct _WOW64_PROCESS
11 {
12 PVOID Wow64;
13 } WOW64_PROCESS, *PWOW64_PROCESS;
14
15 typedef struct _KPROFILE_SOURCE_OBJECT
16 {
17 KPROFILE_SOURCE Source;
18 LIST_ENTRY ListEntry;
19 } KPROFILE_SOURCE_OBJECT, *PKPROFILE_SOURCE_OBJECT;
20
21 /* Cached modules from the loader block */
22 typedef enum _CACHED_MODULE_TYPE
23 {
24 AnsiCodepage,
25 OemCodepage,
26 UnicodeCasemap,
27 SystemRegistry,
28 HardwareRegistry,
29 MaximumCachedModuleType,
30 } CACHED_MODULE_TYPE, *PCACHED_MODULE_TYPE;
31 extern PLOADER_MODULE CachedModules[MaximumCachedModuleType];
32
33 struct _KIRQ_TRAPFRAME;
34 struct _KPCR;
35 struct _KPRCB;
36 struct _KEXCEPTION_FRAME;
37
38 extern PVOID KeUserApcDispatcher;
39 extern PVOID KeUserCallbackDispatcher;
40 extern PVOID KeUserExceptionDispatcher;
41 extern PVOID KeRaiseUserExceptionDispatcher;
42 extern LARGE_INTEGER SystemBootTime;
43 extern ULONG_PTR KERNEL_BASE;
44
45 /* MACROS *************************************************************************/
46
47 #define KeEnterCriticalRegion() \
48 { \
49 PKTHREAD _Thread = KeGetCurrentThread(); \
50 if (_Thread) _Thread->KernelApcDisable--; \
51 }
52
53 #define KeLeaveCriticalRegion() \
54 { \
55 PKTHREAD _Thread = KeGetCurrentThread(); \
56 if((_Thread) && (++_Thread->KernelApcDisable == 0)) \
57 { \
58 if (!IsListEmpty(&_Thread->ApcState.ApcListHead[KernelMode]) && \
59 (_Thread->SpecialApcDisable == 0)) \
60 { \
61 KiCheckForKernelApcDelivery(); \
62 } \
63 } \
64 }
65
66 #define KEBUGCHECKWITHTF(a,b,c,d,e,f) \
67 DbgPrint("KeBugCheckWithTf at %s:%i\n",__FILE__,__LINE__), KeBugCheckWithTf(a,b,c,d,e,f)
68
69 #define MAXIMUM_PROCESSORS 32
70
71
72 /* INTERNAL KERNEL FUNCTIONS ************************************************/
73
74 /* threadsch.c ********************************************************************/
75
76 /* Thread Scheduler Functions */
77
78 /* Readies a Thread for Execution. */
79 VOID
80 STDCALL
81 KiDispatchThreadNoLock(ULONG NewThreadStatus);
82
83 /* Readies a Thread for Execution. */
84 VOID
85 STDCALL
86 KiDispatchThread(ULONG NewThreadStatus);
87
88 /* Puts a Thread into a block state. */
89 VOID
90 STDCALL
91 KiBlockThread(
92 PNTSTATUS Status,
93 UCHAR Alertable,
94 ULONG WaitMode,
95 UCHAR WaitReason
96 );
97
98 /* Removes a thread out of a block state. */
99 VOID
100 STDCALL
101 KiUnblockThread(
102 PKTHREAD Thread,
103 PNTSTATUS WaitStatus,
104 KPRIORITY Increment
105 );
106
107 NTSTATUS
108 STDCALL
109 KeSuspendThread(PKTHREAD Thread);
110
111 NTSTATUS
112 FASTCALL
113 KiSwapContext(PKTHREAD NewThread);
114
115 VOID
116 STDCALL
117 KiAdjustQuantumThread(IN PKTHREAD Thread);
118
119 /* gmutex.c ********************************************************************/
120
121 VOID
122 FASTCALL
123 KiAcquireGuardedMutexContented(PKGUARDED_MUTEX GuardedMutex);
124
125 /* gate.c **********************************************************************/
126
127 VOID
128 FASTCALL
129 KeInitializeGate(PKGATE Gate);
130
131 VOID
132 FASTCALL
133 KeSignalGateBoostPriority(PKGATE Gate);
134
135 VOID
136 FASTCALL
137 KeWaitForGate(
138 PKGATE Gate,
139 KWAIT_REASON WaitReason,
140 KPROCESSOR_MODE WaitMode
141 );
142
143 /* ipi.c ********************************************************************/
144
145 BOOLEAN
146 STDCALL
147 KiIpiServiceRoutine(
148 IN PKTRAP_FRAME TrapFrame,
149 IN struct _KEXCEPTION_FRAME* ExceptionFrame
150 );
151
152 VOID
153 NTAPI
154 KiIpiSendRequest(
155 KAFFINITY TargetSet,
156 ULONG IpiRequest
157 );
158
159 VOID
160 NTAPI
161 KeIpiGenericCall(
162 VOID (STDCALL *WorkerRoutine)(PVOID),
163 PVOID Argument
164 );
165
166 /* next file ***************************************************************/
167
168 VOID
169 STDCALL
170 DbgBreakPointNoBugCheck(VOID);
171
172 VOID
173 STDCALL
174 KeInitializeProfile(
175 struct _KPROFILE* Profile,
176 struct _KPROCESS* Process,
177 PVOID ImageBase,
178 ULONG ImageSize,
179 ULONG BucketSize,
180 KPROFILE_SOURCE ProfileSource,
181 KAFFINITY Affinity
182 );
183
184 VOID
185 STDCALL
186 KeStartProfile(
187 struct _KPROFILE* Profile,
188 PVOID Buffer
189 );
190
191 VOID
192 STDCALL
193 KeStopProfile(struct _KPROFILE* Profile);
194
195 ULONG
196 STDCALL
197 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource);
198
199 VOID
200 STDCALL
201 KeSetIntervalProfile(
202 KPROFILE_SOURCE ProfileSource,
203 ULONG Interval
204 );
205
206 VOID
207 STDCALL
208 KeProfileInterrupt(
209 PKTRAP_FRAME TrapFrame
210 );
211
212 VOID
213 STDCALL
214 KeProfileInterruptWithSource(
215 IN PKTRAP_FRAME TrapFrame,
216 IN KPROFILE_SOURCE Source
217 );
218
219 BOOLEAN
220 STDCALL
221 KiRosPrintAddress(PVOID Address);
222
223 VOID
224 STDCALL
225 KeUpdateSystemTime(
226 PKTRAP_FRAME TrapFrame,
227 KIRQL Irql
228 );
229
230 VOID
231 STDCALL
232 KeUpdateRunTime(
233 PKTRAP_FRAME TrapFrame,
234 KIRQL Irql
235 );
236
237 VOID
238 STDCALL
239 KiExpireTimers(
240 PKDPC Dpc,
241 PVOID DeferredContext,
242 PVOID SystemArgument1,
243 PVOID SystemArgument2
244 );
245
246 KIRQL
247 __inline
248 FASTCALL
249 KeAcquireDispatcherDatabaseLock(VOID);
250
251 VOID
252 __inline
253 FASTCALL
254 KeAcquireDispatcherDatabaseLockAtDpcLevel(VOID);
255
256 VOID
257 __inline
258 FASTCALL
259 KeReleaseDispatcherDatabaseLock(KIRQL Irql);
260
261 VOID
262 __inline
263 FASTCALL
264 KeReleaseDispatcherDatabaseLockFromDpcLevel(VOID);
265
266 VOID
267 STDCALL
268 KeInitializeThread(
269 struct _KPROCESS* Process,
270 PKTHREAD Thread,
271 PKSYSTEM_ROUTINE SystemRoutine,
272 PKSTART_ROUTINE StartRoutine,
273 PVOID StartContext,
274 PCONTEXT Context,
275 PVOID Teb,
276 PVOID KernelStack
277 );
278
279 VOID
280 STDCALL
281 KeRundownThread(VOID);
282
283 NTSTATUS
284 NTAPI
285 KeReleaseThread(PKTHREAD Thread);
286
287 LONG
288 STDCALL
289 KeQueryBasePriorityThread(IN PKTHREAD Thread);
290
291 VOID
292 STDCALL
293 KiSetPriorityThread(
294 PKTHREAD Thread,
295 KPRIORITY Priority,
296 PBOOLEAN Released
297 );
298
299 BOOLEAN
300 NTAPI
301 KiDispatcherObjectWake(
302 DISPATCHER_HEADER* hdr,
303 KPRIORITY increment
304 );
305
306 VOID
307 STDCALL
308 KeExpireTimers(
309 PKDPC Apc,
310 PVOID Arg1,
311 PVOID Arg2,
312 PVOID Arg3
313 );
314
315 VOID
316 __inline
317 FASTCALL
318 KeInitializeDispatcherHeader(
319 DISPATCHER_HEADER* Header,
320 ULONG Type,
321 ULONG Size,
322 ULONG SignalState
323 );
324
325 VOID
326 NTAPI
327 KeDumpStackFrames(PULONG Frame);
328
329 BOOLEAN
330 NTAPI
331 KiTestAlert(VOID);
332
333 VOID
334 FASTCALL
335 KiAbortWaitThread(
336 PKTHREAD Thread,
337 NTSTATUS WaitStatus,
338 KPRIORITY Increment
339 );
340
341 VOID
342 STDCALL
343 KeInitializeProcess(
344 struct _KPROCESS *Process,
345 KPRIORITY Priority,
346 KAFFINITY Affinity,
347 LARGE_INTEGER DirectoryTableBase
348 );
349
350 ULONG
351 STDCALL
352 KeForceResumeThread(IN PKTHREAD Thread);
353
354 BOOLEAN
355 STDCALL
356 KeDisableThreadApcQueueing(IN PKTHREAD Thread);
357
358 BOOLEAN
359 STDCALL
360 KiInsertTimer(
361 PKTIMER Timer,
362 LARGE_INTEGER DueTime
363 );
364
365 VOID
366 __inline
367 FASTCALL
368 KiSatisfyObjectWait(
369 PDISPATCHER_HEADER Object,
370 PKTHREAD Thread
371 );
372
373 BOOLEAN
374 __inline
375 FASTCALL
376 KiIsObjectSignaled(
377 PDISPATCHER_HEADER Object,
378 PKTHREAD Thread
379 );
380
381 VOID
382 __inline
383 FASTCALL
384 KiSatisifyMultipleObjectWaits(PKWAIT_BLOCK WaitBlock);
385
386 VOID
387 FASTCALL
388 KiWaitTest(
389 PDISPATCHER_HEADER Object,
390 KPRIORITY Increment
391 );
392
393 PULONG
394 NTAPI
395 KeGetStackTopThread(struct _ETHREAD* Thread);
396
397 BOOLEAN
398 STDCALL
399 KeContextToTrapFrame(
400 PCONTEXT Context,
401 PKEXCEPTION_FRAME ExeptionFrame,
402 PKTRAP_FRAME TrapFrame,
403 KPROCESSOR_MODE PreviousMode
404 );
405
406 VOID
407 STDCALL
408 KiDeliverApc(
409 KPROCESSOR_MODE PreviousMode,
410 PVOID Reserved,
411 PKTRAP_FRAME TrapFrame
412 );
413
414 VOID
415 STDCALL
416 KiCheckForKernelApcDelivery(VOID);
417
418 LONG
419 STDCALL
420 KiInsertQueue(
421 IN PKQUEUE Queue,
422 IN PLIST_ENTRY Entry,
423 BOOLEAN Head
424 );
425
426 ULONG
427 STDCALL
428 KeSetProcess(
429 struct _KPROCESS* Process,
430 KPRIORITY Increment
431 );
432
433 VOID
434 STDCALL
435 KeInitializeEventPair(PKEVENT_PAIR EventPair);
436
437 VOID
438 STDCALL
439 KiInitializeUserApc(
440 IN PKEXCEPTION_FRAME Reserved,
441 IN PKTRAP_FRAME TrapFrame,
442 IN PKNORMAL_ROUTINE NormalRoutine,
443 IN PVOID NormalContext,
444 IN PVOID SystemArgument1,
445 IN PVOID SystemArgument2
446 );
447
448 PLIST_ENTRY
449 STDCALL
450 KeFlushQueueApc(
451 IN PKTHREAD Thread,
452 IN KPROCESSOR_MODE PreviousMode
453 );
454
455 VOID
456 STDCALL
457 KiAttachProcess(
458 struct _KTHREAD *Thread,
459 struct _KPROCESS *Process,
460 KIRQL ApcLock,
461 struct _KAPC_STATE *SavedApcState
462 );
463
464 VOID
465 STDCALL
466 KiSwapProcess(
467 struct _KPROCESS *NewProcess,
468 struct _KPROCESS *OldProcess
469 );
470
471 BOOLEAN
472 STDCALL
473 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode);
474
475 BOOLEAN
476 STDCALL
477 KeRemoveQueueApc(PKAPC Apc);
478
479 VOID
480 FASTCALL
481 KiWakeQueue(IN PKQUEUE Queue);
482
483 PLIST_ENTRY
484 STDCALL
485 KeRundownQueue(IN PKQUEUE Queue);
486
487 /* INITIALIZATION FUNCTIONS *************************************************/
488
489 VOID
490 NTAPI
491 KeInitExceptions(VOID);
492
493 VOID
494 NTAPI
495 KeInitInterrupts(VOID);
496
497 VOID
498 NTAPI
499 KeInitTimer(VOID);
500
501 VOID
502 NTAPI
503 KeInitDpc(struct _KPRCB* Prcb);
504
505 VOID
506 NTAPI
507 KeInitDispatcher(VOID);
508
509 VOID
510 __inline
511 FASTCALL
512 KeInitializeDispatcher(VOID);
513
514 VOID
515 NTAPI
516 KiInitializeSystemClock(VOID);
517
518 VOID
519 NTAPI
520 KiInitializeBugCheck(VOID);
521
522 VOID
523 NTAPI
524 Phase1Initialization(PVOID Context);
525
526 VOID
527 NTAPI
528 KeInit1(
529 PCHAR CommandLine,
530 PULONG LastKernelAddress
531 );
532
533 VOID
534 NTAPI
535 KeInit2(VOID);
536
537 BOOLEAN
538 NTAPI
539 KiDeliverUserApc(PKTRAP_FRAME TrapFrame);
540
541 VOID
542 STDCALL
543 KiMoveApcState(
544 PKAPC_STATE OldState,
545 PKAPC_STATE NewState
546 );
547
548 VOID
549 NTAPI
550 KiAddProfileEvent(
551 KPROFILE_SOURCE Source,
552 ULONG Pc
553 );
554
555 VOID
556 NTAPI
557 KiDispatchException(
558 PEXCEPTION_RECORD ExceptionRecord,
559 PKEXCEPTION_FRAME ExceptionFrame,
560 PKTRAP_FRAME Tf,
561 KPROCESSOR_MODE PreviousMode,
562 BOOLEAN SearchFrames
563 );
564
565 VOID
566 NTAPI
567 KeTrapFrameToContext(
568 IN PKTRAP_FRAME TrapFrame,
569 IN PKEXCEPTION_FRAME ExceptionFrame,
570 IN OUT PCONTEXT Context
571 );
572
573 VOID
574 NTAPI
575 KeApplicationProcessorInit(VOID);
576
577 VOID
578 NTAPI
579 KePrepareForApplicationProcessorInit(ULONG id);
580
581 ULONG
582 NTAPI
583 KiUserTrapHandler(
584 PKTRAP_FRAME Tf,
585 ULONG ExceptionNr,
586 PVOID Cr2
587 );
588
589 VOID
590 STDCALL
591 KePushAndStackSwitchAndSysRet(
592 ULONG Push,
593 PVOID NewStack
594 );
595
596 VOID
597 STDCALL
598 KeStackSwitchAndRet(PVOID NewStack);
599
600 VOID
601 STDCALL
602 KeBugCheckWithTf(
603 ULONG BugCheckCode,
604 ULONG BugCheckParameter1,
605 ULONG BugCheckParameter2,
606 ULONG BugCheckParameter3,
607 ULONG BugCheckParameter4,
608 PKTRAP_FRAME Tf
609 );
610
611 VOID
612 STDCALL
613 KiDumpTrapFrame(
614 PKTRAP_FRAME Tf,
615 ULONG ExceptionNr,
616 ULONG cr2
617 );
618
619 VOID
620 STDCALL
621 KeFlushCurrentTb(VOID);
622
623 VOID
624 STDCALL
625 KeRosDumpStackFrames(
626 PULONG Frame,
627 ULONG FrameCount
628 );
629
630 ULONG
631 STDCALL
632 KeRosGetStackFrames(
633 PULONG Frames,
634 ULONG FrameCount
635 );
636
637 VOID
638 NTAPI
639 KiSetSystemTime(PLARGE_INTEGER NewSystemTime);
640
641 NTSTATUS
642 STDCALL
643 Ke386CallBios(
644 UCHAR Int,
645 PKV86M_REGISTERS Regs
646 );
647
648 ULONG
649 NTAPI
650 KeV86Exception(
651 ULONG ExceptionNr,
652 PKTRAP_FRAME Tf,
653 ULONG address
654 );
655
656 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */