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 ********************************************************************/
283 IN PKTRAP_FRAME TrapFrame
,
284 IN
struct _KEXCEPTION_FRAME
* ExceptionFrame
297 VOID (STDCALL
*WorkerRoutine
)(PVOID
),
301 /* next file ***************************************************************/
305 DbgBreakPointNoBugCheck(VOID
);
310 struct _KPROFILE
* Profile
,
311 struct _KPROCESS
* Process
,
315 KPROFILE_SOURCE ProfileSource
,
322 struct _KPROFILE
* Profile
,
328 KeStopProfile(struct _KPROFILE
* Profile
);
332 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource
);
336 KeSetIntervalProfile(
337 KPROFILE_SOURCE ProfileSource
,
344 PKTRAP_FRAME TrapFrame
349 KeProfileInterruptWithSource(
350 IN PKTRAP_FRAME TrapFrame
,
351 IN KPROFILE_SOURCE Source
356 KiRosPrintAddress(PVOID Address
);
361 PKTRAP_FRAME TrapFrame
,
368 PKTRAP_FRAME TrapFrame
,
376 PVOID DeferredContext
,
377 PVOID SystemArgument1
,
378 PVOID SystemArgument2
384 struct _KPROCESS
* Process
,
386 PKSYSTEM_ROUTINE SystemRoutine
,
387 PKSTART_ROUTINE StartRoutine
,
396 KeRundownThread(VOID
);
400 KeReleaseThread(PKTHREAD Thread
);
404 KeQueryBasePriorityThread(IN PKTHREAD Thread
);
416 KiDispatcherObjectWake(
417 DISPATCHER_HEADER
* hdr
,
432 KeDumpStackFrames(PULONG Frame
);
449 struct _KPROCESS
*Process
,
452 LARGE_INTEGER DirectoryTableBase
457 KeForceResumeThread(IN PKTHREAD Thread
);
461 KeDisableThreadApcQueueing(IN PKTHREAD Thread
);
467 LARGE_INTEGER DueTime
479 KeGetStackTopThread(struct _ETHREAD
* Thread
);
483 KeContextToTrapFrame(
485 PKEXCEPTION_FRAME ExeptionFrame
,
486 PKTRAP_FRAME TrapFrame
,
488 KPROCESSOR_MODE PreviousMode
494 KPROCESSOR_MODE PreviousMode
,
496 PKTRAP_FRAME TrapFrame
501 KiCheckForKernelApcDelivery(VOID
);
507 IN PLIST_ENTRY Entry
,
514 struct _KPROCESS
* Process
,
520 KeInitializeEventPair(PKEVENT_PAIR EventPair
);
525 IN PKEXCEPTION_FRAME Reserved
,
526 IN PKTRAP_FRAME TrapFrame
,
527 IN PKNORMAL_ROUTINE NormalRoutine
,
528 IN PVOID NormalContext
,
529 IN PVOID SystemArgument1
,
530 IN PVOID SystemArgument2
537 IN KPROCESSOR_MODE PreviousMode
543 struct _KTHREAD
*Thread
,
544 struct _KPROCESS
*Process
,
546 struct _KAPC_STATE
*SavedApcState
552 struct _KPROCESS
*NewProcess
,
553 struct _KPROCESS
*OldProcess
558 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode
);
562 KeRemoveQueueApc(PKAPC Apc
);
566 KiWakeQueue(IN PKQUEUE Queue
);
568 /* INITIALIZATION FUNCTIONS *************************************************/
572 KeInitExceptions(VOID
);
576 KeInitInterrupts(VOID
);
584 KeInitDpc(struct _KPRCB
* Prcb
);
588 KeInitDispatcher(VOID
);
592 KiInitializeSystemClock(VOID
);
596 KiInitializeBugCheck(VOID
);
600 Phase1Initialization(PVOID Context
);
606 PULONG LastKernelAddress
615 KiDeliverUserApc(PKTRAP_FRAME TrapFrame
);
620 PKAPC_STATE OldState
,
627 KPROFILE_SOURCE Source
,
634 PEXCEPTION_RECORD ExceptionRecord
,
635 PKEXCEPTION_FRAME ExceptionFrame
,
637 KPROCESSOR_MODE PreviousMode
,
643 KeTrapFrameToContext(
644 IN PKTRAP_FRAME TrapFrame
,
645 IN PKEXCEPTION_FRAME ExceptionFrame
,
646 IN OUT PCONTEXT Context
651 KeApplicationProcessorInit(VOID
);
655 KePrepareForApplicationProcessorInit(ULONG id
);
667 KePushAndStackSwitchAndSysRet(
674 KeStackSwitchAndRet(PVOID NewStack
);
680 ULONG BugCheckParameter1
,
681 ULONG BugCheckParameter2
,
682 ULONG BugCheckParameter3
,
683 ULONG BugCheckParameter4
,
697 KeFlushCurrentTb(VOID
);
701 KeRosDumpStackFrames(
715 KiSetSystemTime(PLARGE_INTEGER NewSystemTime
);
721 PKV86M_REGISTERS Regs
732 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */