3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_KE_H
21 #define __NTOSKRNL_INCLUDE_INTERNAL_KE_H
23 /* INCLUDES *****************************************************************/
26 #include <ddk/ntifs.h>
28 #endif /* not __ASM__ */
32 /* INTERNAL KERNEL FUNCTIONS ************************************************/
35 struct _KPROCESS
* KeGetCurrentProcess(VOID
);
36 VOID
KeSetGdtSelector(ULONG Entry
, ULONG Value1
, ULONG Value2
);
42 struct _KIRQ_TRAPFRAME
;
44 struct _KEXCEPTION_FRAME
;
46 #define IPI_REQUEST_FUNCTIONCALL 0
47 #define IPI_REQUEST_APC 1
48 #define IPI_REQUEST_DPC 2
50 /* ipi.c ********************************************************************/
53 KiIpiServiceRoutine(IN PKTRAP_FRAME TrapFrame
,
54 IN
struct _KEXCEPTION_FRAME
* ExceptionFrame
);
57 KiIpiSendRequest(ULONG TargetSet
,
61 KeIpiGenericCall(VOID (STDCALL
*WorkerRoutine
)(PVOID
),
64 /* next file ***************************************************************/
66 typedef struct _KPROCESS_PROFILE
68 * List of the profile data structures associated with a process.
71 LIST_ENTRY ProfileListHead
;
74 } KPROCESS_PROFILE
, *PKPROCESS_PROFILE
;
76 typedef struct _KPROFILE
78 * Describes a contiguous region of process memory that is being profiled.
84 /* Entry in the list of profile data structures for this process. */
87 /* Base of the region being profiled. */
90 /* Size of the region being profiled. */
93 /* Shift of offsets from the region to buckets in the profiling buffer. */
96 /* MDL which described the buffer that receives profiling data. */
97 struct _MDL
*BufferMdl
;
99 /* System alias for the profiling buffer. */
102 /* Size of the buffer for profiling data. */
106 * Mask of processors for which profiling data should be collected.
111 /* TRUE if profiling has been started for this region. */
114 /* Pointer (and reference) to the process which is being profiled. */
115 struct _EPROCESS
*Process
;
116 } KPROFILE
, *PKPROFILE
;
119 DbgBreakPointNoBugCheck(VOID
);
124 PKTRAP_FRAME TrapFrame
129 KeProfileInterruptWithSource(
130 IN PKTRAP_FRAME TrapFrame
,
131 IN KPROFILE_SOURCE Source
134 VOID
KiAddProfileEventToProcess(PLIST_ENTRY ListHead
, PVOID Eip
);
135 VOID
KiAddProfileEvent(KPROFILE_SOURCE Source
, ULONG Eip
);
136 VOID
KiInsertProfileIntoProcess(PLIST_ENTRY ListHead
, PKPROFILE Profile
);
137 VOID
KiInsertProfile(PKPROFILE Profile
);
138 VOID
KiRemoveProfile(PKPROFILE Profile
);
139 VOID STDCALL
KiDeleteProfile(PVOID ObjectBody
);
142 VOID STDCALL
KeUpdateSystemTime(PKTRAP_FRAME TrapFrame
, KIRQL Irql
);
143 VOID STDCALL
KeUpdateRunTime(PKTRAP_FRAME TrapFrame
, KIRQL Irql
);
145 VOID STDCALL
KiExpireTimers(PKDPC Dpc
, PVOID DeferredContext
, PVOID SystemArgument1
, PVOID SystemArgument2
);
147 KIRQL
KeAcquireDispatcherDatabaseLock(VOID
);
148 VOID
KeAcquireDispatcherDatabaseLockAtDpcLevel(VOID
);
149 VOID
KeReleaseDispatcherDatabaseLock(KIRQL Irql
);
150 VOID
KeReleaseDispatcherDatabaseLockFromDpcLevel(VOID
);
152 BOOLEAN
KiDispatcherObjectWake(DISPATCHER_HEADER
* hdr
, KPRIORITY increment
);
153 VOID STDCALL
KeExpireTimers(PKDPC Apc
,
157 VOID
KeInitializeDispatcherHeader(DISPATCHER_HEADER
* Header
, ULONG Type
,
158 ULONG Size
, ULONG SignalState
);
159 VOID
KeDumpStackFrames(PULONG Frame
);
160 BOOLEAN
KiTestAlert(VOID
);
162 BOOLEAN
KiAbortWaitThread(struct _KTHREAD
* Thread
, NTSTATUS WaitStatus
);
164 PULONG
KeGetStackTopThread(struct _ETHREAD
* Thread
);
165 VOID
KeContextToTrapFrame(PCONTEXT Context
, PKTRAP_FRAME TrapFrame
);
166 VOID STDCALL
KiDeliverApc(KPROCESSOR_MODE PreviousMode
,
168 PKTRAP_FRAME TrapFrame
);
170 VOID
KiInitializeUserApc(IN PVOID Reserved
,
171 IN PKTRAP_FRAME TrapFrame
,
172 IN PKNORMAL_ROUTINE NormalRoutine
,
173 IN PVOID NormalContext
,
174 IN PVOID SystemArgument1
,
175 IN PVOID SystemArgument2
);
177 VOID STDCALL
KiAttachProcess(struct _KTHREAD
*Thread
, struct _KPROCESS
*Process
, KIRQL ApcLock
, struct _KAPC_STATE
*SavedApcState
);
179 VOID STDCALL
KiSwapProcess(struct _KPROCESS
*NewProcess
, struct _KPROCESS
*OldProcess
);
183 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode
);
185 BOOLEAN STDCALL
KeRemoveQueueApc (PKAPC Apc
);
186 PLIST_ENTRY STDCALL
KeRundownQueue(IN PKQUEUE Queue
);
188 extern LARGE_INTEGER SystemBootTime
;
190 /* INITIALIZATION FUNCTIONS *************************************************/
192 VOID
KeInitExceptions(VOID
);
193 VOID
KeInitInterrupts(VOID
);
194 VOID
KeInitTimer(VOID
);
195 VOID
KeInitDpc(struct _KPCR
* Pcr
);
196 VOID
KeInitDispatcher(VOID
);
197 VOID
KeInitializeDispatcher(VOID
);
198 VOID
KiInitializeSystemClock(VOID
);
199 VOID
KeInitializeBugCheck(VOID
);
200 VOID
Phase1Initialization(PVOID Context
);
202 VOID
KeInit1(PCHAR CommandLine
, PULONG LastKernelAddress
);
205 BOOLEAN
KiDeliverUserApc(PKTRAP_FRAME TrapFrame
);
209 KiMoveApcState (PKAPC_STATE OldState
,
210 PKAPC_STATE NewState
);
213 KiAddProfileEvent(KPROFILE_SOURCE Source
, ULONG Pc
);
215 KiDispatchException(PEXCEPTION_RECORD ExceptionRecord
,
218 KPROCESSOR_MODE PreviousMode
,
219 BOOLEAN SearchFrames
);
220 VOID
KeTrapFrameToContext(PKTRAP_FRAME TrapFrame
,
223 KeApplicationProcessorInit(VOID
);
225 KePrepareForApplicationProcessorInit(ULONG id
);
227 KiUserTrapHandler(PKTRAP_FRAME Tf
, ULONG ExceptionNr
, PVOID Cr2
);
229 KePushAndStackSwitchAndSysRet(ULONG Push
, PVOID NewStack
);
231 KeStackSwitchAndRet(PVOID NewStack
);
233 KeBugCheckWithTf(ULONG BugCheckCode
,
234 ULONG BugCheckParameter1
,
235 ULONG BugCheckParameter2
,
236 ULONG BugCheckParameter3
,
237 ULONG BugCheckParameter4
,
239 #define KEBUGCHECKWITHTF(a,b,c,d,e,f) DbgPrint("KeBugCheckWithTf at %s:%i\n",__FILE__,__LINE__), KeBugCheckWithTf(a,b,c,d,e,f)
241 KiDumpTrapFrame(PKTRAP_FRAME Tf
, ULONG ExceptionNr
, ULONG cr2
);
245 KeFlushCurrentTb(VOID
);
248 KiSetSystemTime(PLARGE_INTEGER NewSystemTime
);
250 #endif /* not __ASM__ */
252 #define MAXIMUM_PROCESSORS 32
254 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */