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
;
45 /* MACROS *************************************************************************/
48 * On UP machines, we don't actually have a spinlock, we merely raise
52 #define KeInitializeDispatcher() KeInitializeSpinLock(&DispatcherDatabaseLock);
53 #define KeAcquireDispatcherDatabaseLock() KfAcquireSpinLock(&DispatcherDatabaseLock);
54 #define KeAcquireDispatcherDatabaseLockAtDpcLevel() \
55 KeAcquireSpinLockAtDpcLevel (&DispatcherDatabaseLock);
56 #define KeReleaseDispatcherDatabaseLockFromDpcLevel() \
57 KeReleaseSpinLockFromDpcLevel(&DispatcherDatabaseLock);
58 #define KeReleaseDispatcherDatabaseLock(OldIrql) \
59 KiExitDispatcher(OldIrql);
61 #define KeInitializeDispatcher()
62 #define KeAcquireDispatcherDatabaseLock() KeRaiseIrqlToDpcLevel();
63 #define KeReleaseDispatcherDatabaseLock(OldIrql) KiExitDispatcher(OldIrql);
64 #define KeAcquireDispatcherDatabaseLockAtDpcLevel()
65 #define KeReleaseDispatcherDatabaseLockFromDpcLevel()
68 /* The following macro initializes a dispatcher object's header */
69 #define KeInitializeDispatcherHeader(Header, t, s, State) \
72 (Header)->Absolute = 0; \
73 (Header)->Inserted = 0; \
75 (Header)->SignalState = State; \
76 InitializeListHead(&((Header)->WaitListHead)); \
79 /* The following macro satisfies the wait of any dispatcher object */
80 #define KiSatisfyObjectWait(Object, Thread) \
82 /* Special case for Mutants */ \
83 if ((Object)->Header.Type == MutantObject) \
85 /* Decrease the Signal State */ \
86 (Object)->Header.SignalState--; \
88 /* Check if it's now non-signaled */ \
89 if (!(Object)->Header.SignalState) \
91 /* Set the Owner Thread */ \
92 (Object)->OwnerThread = Thread; \
94 /* Disable APCs if needed */ \
95 Thread->KernelApcDisable -= (Object)->ApcDisable; \
97 /* Check if it's abandoned */ \
98 if ((Object)->Abandoned) \
101 (Object)->Abandoned = FALSE; \
103 /* Return Status */ \
104 Thread->WaitStatus = STATUS_ABANDONED; \
107 /* Insert it into the Mutant List */ \
108 InsertHeadList(&Thread->MutantListHead, \
109 &(Object)->MutantListEntry); \
112 else if (((Object)->Header.Type & TIMER_OR_EVENT_TYPE) == \
113 EventSynchronizationObject) \
115 /* Synchronization Timers and Events just get un-signaled */ \
116 (Object)->Header.SignalState = 0; \
118 else if ((Object)->Header.Type == SemaphoreObject) \
120 /* These ones can have multiple states, so we only decrease it */ \
121 (Object)->Header.SignalState--; \
125 /* The following macro satisfies the wait of a mutant dispatcher object */
126 #define KiSatisfyMutantWait(Object, Thread) \
128 /* Decrease the Signal State */ \
129 (Object)->Header.SignalState--; \
131 /* Check if it's now non-signaled */ \
132 if (!(Object)->Header.SignalState) \
134 /* Set the Owner Thread */ \
135 (Object)->OwnerThread = Thread; \
137 /* Disable APCs if needed */ \
138 Thread->KernelApcDisable -= (Object)->ApcDisable; \
140 /* Check if it's abandoned */ \
141 if ((Object)->Abandoned) \
144 (Object)->Abandoned = FALSE; \
146 /* Return Status */ \
147 Thread->WaitStatus = STATUS_ABANDONED; \
150 /* Insert it into the Mutant List */ \
151 InsertHeadList(&Thread->MutantListHead, \
152 &(Object)->MutantListEntry); \
156 /* The following macro satisfies the wait of any nonmutant dispatcher object */
157 #define KiSatisfyNonMutantWait(Object, Thread) \
159 if (((Object)->Header.Type & TIMER_OR_EVENT_TYPE) == \
160 EventSynchronizationObject) \
162 /* Synchronization Timers and Events just get un-signaled */ \
163 (Object)->Header.SignalState = 0; \
165 else if ((Object)->Header.Type == SemaphoreObject) \
167 /* These ones can have multiple states, so we only decrease it */ \
168 (Object)->Header.SignalState--; \
172 extern KSPIN_LOCK DispatcherDatabaseLock
;
174 #define KeEnterCriticalRegion() \
176 PKTHREAD _Thread = KeGetCurrentThread(); \
177 if (_Thread) _Thread->KernelApcDisable--; \
180 #define KeLeaveCriticalRegion() \
182 PKTHREAD _Thread = KeGetCurrentThread(); \
183 if((_Thread) && (++_Thread->KernelApcDisable == 0)) \
185 if (!IsListEmpty(&_Thread->ApcState.ApcListHead[KernelMode]) && \
186 (_Thread->SpecialApcDisable == 0)) \
188 KiCheckForKernelApcDelivery(); \
193 #define KEBUGCHECKWITHTF(a,b,c,d,e,f) \
194 DbgPrint("KeBugCheckWithTf at %s:%i\n",__FILE__,__LINE__), \
195 KeBugCheckWithTf(a,b,c,d,e,f)
197 /* Tells us if the Timer or Event is a Syncronization or Notification Object */
198 #define TIMER_OR_EVENT_TYPE 0x7L
200 /* One of the Reserved Wait Blocks, this one is for the Thread's Timer */
201 #define TIMER_WAIT_BLOCK 0x3L
203 /* INTERNAL KERNEL FUNCTIONS ************************************************/
205 /* threadsch.c ********************************************************************/
207 /* Thread Scheduler Functions */
209 /* Readies a Thread for Execution. */
212 KiDispatchThreadNoLock(ULONG NewThreadStatus
);
214 /* Readies a Thread for Execution. */
217 KiDispatchThread(ULONG NewThreadStatus
);
219 /* Finds a new thread to run */
226 /* Removes a thread out of a block state. */
231 PNTSTATUS WaitStatus
,
237 KeSuspendThread(PKTHREAD Thread
);
241 KiSwapContext(PKTHREAD NewThread
);
245 KiAdjustQuantumThread(IN PKTHREAD Thread
);
249 KiExitDispatcher(KIRQL OldIrql
);
251 /* gmutex.c ********************************************************************/
255 KiAcquireGuardedMutexContented(PKGUARDED_MUTEX GuardedMutex
);
257 /* gate.c **********************************************************************/
261 KeInitializeGate(PKGATE Gate
);
265 KeSignalGateBoostPriority(PKGATE Gate
);
271 KWAIT_REASON WaitReason
,
272 KPROCESSOR_MODE WaitMode
275 /* ipi.c ********************************************************************/
280 IN PKTRAP_FRAME TrapFrame
,
281 IN
struct _KEXCEPTION_FRAME
* ExceptionFrame
294 VOID (STDCALL
*WorkerRoutine
)(PVOID
),
298 /* next file ***************************************************************/
302 DbgBreakPointNoBugCheck(VOID
);
307 struct _KPROFILE
* Profile
,
308 struct _KPROCESS
* Process
,
312 KPROFILE_SOURCE ProfileSource
,
319 struct _KPROFILE
* Profile
,
325 KeStopProfile(struct _KPROFILE
* Profile
);
329 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource
);
333 KeSetIntervalProfile(
334 KPROFILE_SOURCE ProfileSource
,
341 PKTRAP_FRAME TrapFrame
346 KeProfileInterruptWithSource(
347 IN PKTRAP_FRAME TrapFrame
,
348 IN KPROFILE_SOURCE Source
353 KiRosPrintAddress(PVOID Address
);
358 PKTRAP_FRAME TrapFrame
,
365 PKTRAP_FRAME TrapFrame
,
373 PVOID DeferredContext
,
374 PVOID SystemArgument1
,
375 PVOID SystemArgument2
381 struct _KPROCESS
* Process
,
383 PKSYSTEM_ROUTINE SystemRoutine
,
384 PKSTART_ROUTINE StartRoutine
,
393 KeRundownThread(VOID
);
397 KeReleaseThread(PKTHREAD Thread
);
401 KeQueryBasePriorityThread(IN PKTHREAD Thread
);
413 KiDispatcherObjectWake(
414 DISPATCHER_HEADER
* hdr
,
429 KeDumpStackFrames(PULONG Frame
);
446 struct _KPROCESS
*Process
,
449 LARGE_INTEGER DirectoryTableBase
454 KeForceResumeThread(IN PKTHREAD Thread
);
458 KeDisableThreadApcQueueing(IN PKTHREAD Thread
);
464 LARGE_INTEGER DueTime
476 KeGetStackTopThread(struct _ETHREAD
* Thread
);
480 KeContextToTrapFrame(
482 PKEXCEPTION_FRAME ExeptionFrame
,
483 PKTRAP_FRAME TrapFrame
,
484 KPROCESSOR_MODE PreviousMode
490 KPROCESSOR_MODE PreviousMode
,
492 PKTRAP_FRAME TrapFrame
497 KiCheckForKernelApcDelivery(VOID
);
503 IN PLIST_ENTRY Entry
,
510 struct _KPROCESS
* Process
,
516 KeInitializeEventPair(PKEVENT_PAIR EventPair
);
521 IN PKEXCEPTION_FRAME Reserved
,
522 IN PKTRAP_FRAME TrapFrame
,
523 IN PKNORMAL_ROUTINE NormalRoutine
,
524 IN PVOID NormalContext
,
525 IN PVOID SystemArgument1
,
526 IN PVOID SystemArgument2
533 IN KPROCESSOR_MODE PreviousMode
539 struct _KTHREAD
*Thread
,
540 struct _KPROCESS
*Process
,
542 struct _KAPC_STATE
*SavedApcState
548 struct _KPROCESS
*NewProcess
,
549 struct _KPROCESS
*OldProcess
554 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode
);
558 KeRemoveQueueApc(PKAPC Apc
);
562 KiWakeQueue(IN PKQUEUE Queue
);
564 /* INITIALIZATION FUNCTIONS *************************************************/
568 KeInitExceptions(VOID
);
572 KeInitInterrupts(VOID
);
580 KeInitDpc(struct _KPRCB
* Prcb
);
584 KeInitDispatcher(VOID
);
588 KiInitializeSystemClock(VOID
);
592 KiInitializeBugCheck(VOID
);
596 Phase1Initialization(PVOID Context
);
602 PULONG LastKernelAddress
611 KiDeliverUserApc(PKTRAP_FRAME TrapFrame
);
616 PKAPC_STATE OldState
,
623 KPROFILE_SOURCE Source
,
630 PEXCEPTION_RECORD ExceptionRecord
,
631 PKEXCEPTION_FRAME ExceptionFrame
,
633 KPROCESSOR_MODE PreviousMode
,
639 KeTrapFrameToContext(
640 IN PKTRAP_FRAME TrapFrame
,
641 IN PKEXCEPTION_FRAME ExceptionFrame
,
642 IN OUT PCONTEXT Context
647 KeApplicationProcessorInit(VOID
);
651 KePrepareForApplicationProcessorInit(ULONG id
);
663 KePushAndStackSwitchAndSysRet(
670 KeStackSwitchAndRet(PVOID NewStack
);
676 ULONG BugCheckParameter1
,
677 ULONG BugCheckParameter2
,
678 ULONG BugCheckParameter3
,
679 ULONG BugCheckParameter4
,
693 KeFlushCurrentTb(VOID
);
697 KeRosDumpStackFrames(
711 KiSetSystemTime(PLARGE_INTEGER NewSystemTime
);
717 PKV86M_REGISTERS Regs
728 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */