1 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_KE_H
2 #define __NTOSKRNL_INCLUDE_INTERNAL_KE_H
4 /* INCLUDES *****************************************************************/
8 /* INTERNAL KERNEL TYPES ****************************************************/
10 typedef struct _WOW64_PROCESS
13 } WOW64_PROCESS
, *PWOW64_PROCESS
;
15 typedef struct _KPROFILE_SOURCE_OBJECT
17 KPROFILE_SOURCE Source
;
19 } KPROFILE_SOURCE_OBJECT
, *PKPROFILE_SOURCE_OBJECT
;
21 /* Cached modules from the loader block */
22 typedef enum _CACHED_MODULE_TYPE
29 MaximumCachedModuleType
,
30 } CACHED_MODULE_TYPE
, *PCACHED_MODULE_TYPE
;
31 extern PLOADER_MODULE CachedModules
[MaximumCachedModuleType
];
33 struct _KIRQ_TRAPFRAME
;
36 struct _KEXCEPTION_FRAME
;
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 extern ULONG KeI386NpxPresent
;
45 extern ULONG KeI386XMMIPresent
;
46 extern ULONG KeI386FxsrPresent
;
48 /* MACROS *************************************************************************/
51 * On UP machines, we don't actually have a spinlock, we merely raise
55 #define KeInitializeDispatcher() KeInitializeSpinLock(&DispatcherDatabaseLock);
56 #define KeAcquireDispatcherDatabaseLock() KfAcquireSpinLock(&DispatcherDatabaseLock);
57 #define KeAcquireDispatcherDatabaseLockAtDpcLevel() \
58 KeAcquireSpinLockAtDpcLevel (&DispatcherDatabaseLock);
59 #define KeReleaseDispatcherDatabaseLockFromDpcLevel() \
60 KeReleaseSpinLockFromDpcLevel(&DispatcherDatabaseLock);
61 #define KeReleaseDispatcherDatabaseLock(OldIrql) \
62 KiExitDispatcher(OldIrql);
64 #define KeInitializeDispatcher()
65 #define KeAcquireDispatcherDatabaseLock() KeRaiseIrqlToDpcLevel();
66 #define KeReleaseDispatcherDatabaseLock(OldIrql) KiExitDispatcher(OldIrql);
67 #define KeAcquireDispatcherDatabaseLockAtDpcLevel()
68 #define KeReleaseDispatcherDatabaseLockFromDpcLevel()
71 /* The following macro initializes a dispatcher object's header */
72 #define KeInitializeDispatcherHeader(Header, t, s, State) \
75 (Header)->Absolute = 0; \
76 (Header)->Inserted = 0; \
78 (Header)->SignalState = State; \
79 InitializeListHead(&((Header)->WaitListHead)); \
82 /* The following macro satisfies the wait of any dispatcher object */
83 #define KiSatisfyObjectWait(Object, Thread) \
85 /* Special case for Mutants */ \
86 if ((Object)->Header.Type == MutantObject) \
88 /* Decrease the Signal State */ \
89 (Object)->Header.SignalState--; \
91 /* Check if it's now non-signaled */ \
92 if (!(Object)->Header.SignalState) \
94 /* Set the Owner Thread */ \
95 (Object)->OwnerThread = Thread; \
97 /* Disable APCs if needed */ \
98 Thread->KernelApcDisable -= (Object)->ApcDisable; \
100 /* Check if it's abandoned */ \
101 if ((Object)->Abandoned) \
104 (Object)->Abandoned = FALSE; \
106 /* Return Status */ \
107 Thread->WaitStatus = STATUS_ABANDONED; \
110 /* Insert it into the Mutant List */ \
111 InsertHeadList(&Thread->MutantListHead, \
112 &(Object)->MutantListEntry); \
115 else if (((Object)->Header.Type & TIMER_OR_EVENT_TYPE) == \
116 EventSynchronizationObject) \
118 /* Synchronization Timers and Events just get un-signaled */ \
119 (Object)->Header.SignalState = 0; \
121 else if ((Object)->Header.Type == SemaphoreObject) \
123 /* These ones can have multiple states, so we only decrease it */ \
124 (Object)->Header.SignalState--; \
128 /* The following macro satisfies the wait of a mutant dispatcher object */
129 #define KiSatisfyMutantWait(Object, Thread) \
131 /* Decrease the Signal State */ \
132 (Object)->Header.SignalState--; \
134 /* Check if it's now non-signaled */ \
135 if (!(Object)->Header.SignalState) \
137 /* Set the Owner Thread */ \
138 (Object)->OwnerThread = Thread; \
140 /* Disable APCs if needed */ \
141 Thread->KernelApcDisable -= (Object)->ApcDisable; \
143 /* Check if it's abandoned */ \
144 if ((Object)->Abandoned) \
147 (Object)->Abandoned = FALSE; \
149 /* Return Status */ \
150 Thread->WaitStatus = STATUS_ABANDONED; \
153 /* Insert it into the Mutant List */ \
154 InsertHeadList(&Thread->MutantListHead, \
155 &(Object)->MutantListEntry); \
159 /* The following macro satisfies the wait of any nonmutant dispatcher object */
160 #define KiSatisfyNonMutantWait(Object, Thread) \
162 if (((Object)->Header.Type & TIMER_OR_EVENT_TYPE) == \
163 EventSynchronizationObject) \
165 /* Synchronization Timers and Events just get un-signaled */ \
166 (Object)->Header.SignalState = 0; \
168 else if ((Object)->Header.Type == SemaphoreObject) \
170 /* These ones can have multiple states, so we only decrease it */ \
171 (Object)->Header.SignalState--; \
175 extern KSPIN_LOCK DispatcherDatabaseLock
;
177 #define KeEnterCriticalRegion() \
179 PKTHREAD _Thread = KeGetCurrentThread(); \
180 if (_Thread) _Thread->KernelApcDisable--; \
183 #define KeLeaveCriticalRegion() \
185 PKTHREAD _Thread = KeGetCurrentThread(); \
186 if((_Thread) && (++_Thread->KernelApcDisable == 0)) \
188 if (!IsListEmpty(&_Thread->ApcState.ApcListHead[KernelMode]) && \
189 (_Thread->SpecialApcDisable == 0)) \
191 KiCheckForKernelApcDelivery(); \
196 #define KEBUGCHECKWITHTF(a,b,c,d,e,f) \
197 DbgPrint("KeBugCheckWithTf at %s:%i\n",__FILE__,__LINE__), \
198 KeBugCheckWithTf(a,b,c,d,e,f)
200 /* Tells us if the Timer or Event is a Syncronization or Notification Object */
201 #define TIMER_OR_EVENT_TYPE 0x7L
203 /* One of the Reserved Wait Blocks, this one is for the Thread's Timer */
204 #define TIMER_WAIT_BLOCK 0x3L
206 /* INTERNAL KERNEL FUNCTIONS ************************************************/
208 /* threadsch.c ********************************************************************/
210 /* Thread Scheduler Functions */
212 /* Readies a Thread for Execution. */
215 KiDispatchThreadNoLock(ULONG NewThreadStatus
);
217 /* Readies a Thread for Execution. */
220 KiDispatchThread(ULONG NewThreadStatus
);
222 /* Finds a new thread to run */
229 /* Removes a thread out of a block state. */
234 PNTSTATUS WaitStatus
,
240 KeSuspendThread(PKTHREAD Thread
);
244 KiSwapContext(PKTHREAD NewThread
);
248 KiAdjustQuantumThread(IN PKTHREAD Thread
);
252 KiExitDispatcher(KIRQL OldIrql
);
254 /* gmutex.c ********************************************************************/
258 KiAcquireGuardedMutexContented(PKGUARDED_MUTEX GuardedMutex
);
260 /* gate.c **********************************************************************/
264 KeInitializeGate(PKGATE Gate
);
268 KeSignalGateBoostPriority(PKGATE Gate
);
274 KWAIT_REASON WaitReason
,
275 KPROCESSOR_MODE WaitMode
278 /* ipi.c ********************************************************************/
287 /* next file ***************************************************************/
291 DbgBreakPointNoBugCheck(VOID
);
296 struct _KPROFILE
* Profile
,
297 struct _KPROCESS
* Process
,
301 KPROFILE_SOURCE ProfileSource
,
308 struct _KPROFILE
* Profile
,
314 KeStopProfile(struct _KPROFILE
* Profile
);
318 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource
);
322 KeSetIntervalProfile(
323 KPROFILE_SOURCE ProfileSource
,
330 PKTRAP_FRAME TrapFrame
335 KeProfileInterruptWithSource(
336 IN PKTRAP_FRAME TrapFrame
,
337 IN KPROFILE_SOURCE Source
342 KiRosPrintAddress(PVOID Address
);
347 PKTRAP_FRAME TrapFrame
,
354 PKTRAP_FRAME TrapFrame
,
362 PVOID DeferredContext
,
363 PVOID SystemArgument1
,
364 PVOID SystemArgument2
370 struct _KPROCESS
* Process
,
372 PKSYSTEM_ROUTINE SystemRoutine
,
373 PKSTART_ROUTINE StartRoutine
,
382 KeRundownThread(VOID
);
386 KeReleaseThread(PKTHREAD Thread
);
390 KeQueryBasePriorityThread(IN PKTHREAD Thread
);
402 KiDispatcherObjectWake(
403 DISPATCHER_HEADER
* hdr
,
418 KeDumpStackFrames(PULONG Frame
);
435 struct _KPROCESS
*Process
,
438 LARGE_INTEGER DirectoryTableBase
443 KeForceResumeThread(IN PKTHREAD Thread
);
447 KeDisableThreadApcQueueing(IN PKTHREAD Thread
);
453 LARGE_INTEGER DueTime
465 KeGetStackTopThread(struct _ETHREAD
* Thread
);
469 KeContextToTrapFrame(
471 PKEXCEPTION_FRAME ExeptionFrame
,
472 PKTRAP_FRAME TrapFrame
,
474 KPROCESSOR_MODE PreviousMode
480 KPROCESSOR_MODE PreviousMode
,
482 PKTRAP_FRAME TrapFrame
487 KiCheckForKernelApcDelivery(VOID
);
493 IN PLIST_ENTRY Entry
,
500 struct _KPROCESS
* Process
,
506 KeInitializeEventPair(PKEVENT_PAIR EventPair
);
511 IN PKEXCEPTION_FRAME Reserved
,
512 IN PKTRAP_FRAME TrapFrame
,
513 IN PKNORMAL_ROUTINE NormalRoutine
,
514 IN PVOID NormalContext
,
515 IN PVOID SystemArgument1
,
516 IN PVOID SystemArgument2
523 IN KPROCESSOR_MODE PreviousMode
529 struct _KTHREAD
*Thread
,
530 struct _KPROCESS
*Process
,
532 struct _KAPC_STATE
*SavedApcState
538 struct _KPROCESS
*NewProcess
,
539 struct _KPROCESS
*OldProcess
544 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode
);
548 KeRemoveQueueApc(PKAPC Apc
);
552 KiWakeQueue(IN PKQUEUE Queue
);
554 /* INITIALIZATION FUNCTIONS *************************************************/
558 KeInitExceptions(VOID
);
562 KeInitInterrupts(VOID
);
570 KeInitDpc(struct _KPRCB
* Prcb
);
574 KeInitDispatcher(VOID
);
578 KiInitializeSystemClock(VOID
);
582 KiInitializeBugCheck(VOID
);
586 Phase1Initialization(PVOID Context
);
592 PULONG LastKernelAddress
601 KiDeliverUserApc(PKTRAP_FRAME TrapFrame
);
606 PKAPC_STATE OldState
,
613 KPROFILE_SOURCE Source
,
620 PEXCEPTION_RECORD ExceptionRecord
,
621 PKEXCEPTION_FRAME ExceptionFrame
,
623 KPROCESSOR_MODE PreviousMode
,
629 KeTrapFrameToContext(
630 IN PKTRAP_FRAME TrapFrame
,
631 IN PKEXCEPTION_FRAME ExceptionFrame
,
632 IN OUT PCONTEXT Context
637 KeApplicationProcessorInit(VOID
);
641 KePrepareForApplicationProcessorInit(ULONG id
);
653 KePushAndStackSwitchAndSysRet(
660 KeStackSwitchAndRet(PVOID NewStack
);
666 ULONG BugCheckParameter1
,
667 ULONG BugCheckParameter2
,
668 ULONG BugCheckParameter3
,
669 ULONG BugCheckParameter4
,
683 KeFlushCurrentTb(VOID
);
687 KeRosDumpStackFrames(
701 KiSetSystemTime(PLARGE_INTEGER NewSystemTime
);
711 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */