c4f48eadd91af2e30e4cf0c959f2738cd7f9964d
[reactos.git] / reactos / ntoskrnl / include / internal / ke.h
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_KE_H
21 #define __NTOSKRNL_INCLUDE_INTERNAL_KE_H
22
23 /* INCLUDES *****************************************************************/
24
25 #ifndef __ASM__
26 #include <ddk/ntifs.h>
27 #include <stdarg.h>
28 #endif /* not __ASM__ */
29
30 #include "arch/ke.h"
31
32 /* INTERNAL KERNEL FUNCTIONS ************************************************/
33
34 #ifdef __USE_W32API
35 struct _KPROCESS* KeGetCurrentProcess(VOID);
36 VOID KeSetGdtSelector(ULONG Entry, ULONG Value1, ULONG Value2);
37 #endif
38
39 #ifndef __ASM__
40
41 struct _KTHREAD;
42 struct _KIRQ_TRAPFRAME;
43 struct _KPCR;
44 struct _KEXCEPTION_FRAME;
45
46 #define IPI_REQUEST_FUNCTIONCALL 0
47 #define IPI_REQUEST_APC 1
48 #define IPI_REQUEST_DPC 2
49
50 /* ipi.c ********************************************************************/
51
52 BOOLEAN STDCALL
53 KiIpiServiceRoutine(IN PKTRAP_FRAME TrapFrame,
54 IN struct _KEXCEPTION_FRAME* ExceptionFrame);
55
56 VOID
57 KiIpiSendRequest(ULONG TargetSet,
58 ULONG IpiRequest);
59
60 VOID
61 KeIpiGenericCall(VOID (STDCALL *WorkerRoutine)(PVOID),
62 PVOID Argument);
63
64 /* next file ***************************************************************/
65
66 typedef struct _KPROCESS_PROFILE
67 /*
68 * List of the profile data structures associated with a process.
69 */
70 {
71 LIST_ENTRY ProfileListHead;
72 LIST_ENTRY ListEntry;
73 HANDLE Pid;
74 } KPROCESS_PROFILE, *PKPROCESS_PROFILE;
75
76 typedef struct _KPROFILE
77 /*
78 * Describes a contiguous region of process memory that is being profiled.
79 */
80 {
81 CSHORT Type;
82 CSHORT Name;
83
84 /* Entry in the list of profile data structures for this process. */
85 LIST_ENTRY ListEntry;
86
87 /* Base of the region being profiled. */
88 PVOID Base;
89
90 /* Size of the region being profiled. */
91 ULONG Size;
92
93 /* Shift of offsets from the region to buckets in the profiling buffer. */
94 ULONG BucketShift;
95
96 /* MDL which described the buffer that receives profiling data. */
97 struct _MDL *BufferMdl;
98
99 /* System alias for the profiling buffer. */
100 PULONG Buffer;
101
102 /* Size of the buffer for profiling data. */
103 ULONG BufferSize;
104
105 /*
106 * Mask of processors for which profiling data should be collected.
107 * Currently unused.
108 */
109 ULONG ProcessorMask;
110
111 /* TRUE if profiling has been started for this region. */
112 BOOLEAN Started;
113
114 /* Pointer (and reference) to the process which is being profiled. */
115 struct _EPROCESS *Process;
116 } KPROFILE, *PKPROFILE;
117
118 /* Cached modules from the loader block */
119 typedef enum _CACHED_MODULE_TYPE {
120 AnsiCodepage,
121 OemCodepage,
122 UnicodeCasemap,
123 SystemRegistry,
124 HardwareRegistry,
125 MaximumCachedModuleType,
126 } CACHED_MODULE_TYPE, *PCACHED_MODULE_TYPE;
127 extern PLOADER_MODULE CachedModules[MaximumCachedModuleType];
128
129 VOID STDCALL
130 DbgBreakPointNoBugCheck(VOID);
131
132 VOID
133 STDCALL
134 KeProfileInterrupt(
135 PKTRAP_FRAME TrapFrame
136 );
137
138 VOID
139 STDCALL
140 KeProfileInterruptWithSource(
141 IN PKTRAP_FRAME TrapFrame,
142 IN KPROFILE_SOURCE Source
143 );
144
145 VOID KiAddProfileEventToProcess(PLIST_ENTRY ListHead, PVOID Eip);
146 VOID KiAddProfileEvent(KPROFILE_SOURCE Source, ULONG Eip);
147 VOID KiInsertProfileIntoProcess(PLIST_ENTRY ListHead, PKPROFILE Profile);
148 VOID KiInsertProfile(PKPROFILE Profile);
149 VOID KiRemoveProfile(PKPROFILE Profile);
150 VOID STDCALL KiDeleteProfile(PVOID ObjectBody);
151
152
153 VOID STDCALL KeUpdateSystemTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);
154 VOID STDCALL KeUpdateRunTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);
155
156 VOID STDCALL KiExpireTimers(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2);
157
158 KIRQL inline FASTCALL KeAcquireDispatcherDatabaseLock(VOID);
159 VOID inline FASTCALL KeAcquireDispatcherDatabaseLockAtDpcLevel(VOID);
160 VOID inline FASTCALL KeReleaseDispatcherDatabaseLock(KIRQL Irql);
161 VOID inline FASTCALL KeReleaseDispatcherDatabaseLockFromDpcLevel(VOID);
162
163 BOOLEAN KiDispatcherObjectWake(DISPATCHER_HEADER* hdr, KPRIORITY increment);
164 VOID STDCALL KeExpireTimers(PKDPC Apc,
165 PVOID Arg1,
166 PVOID Arg2,
167 PVOID Arg3);
168 VOID inline FASTCALL KeInitializeDispatcherHeader(DISPATCHER_HEADER* Header, ULONG Type,
169 ULONG Size, ULONG SignalState);
170 VOID KeDumpStackFrames(PULONG Frame);
171 BOOLEAN KiTestAlert(VOID);
172
173 VOID FASTCALL KiAbortWaitThread(struct _KTHREAD* Thread, NTSTATUS WaitStatus);
174
175 BOOLEAN STDCALL KiInsertTimer(PKTIMER Timer, LARGE_INTEGER DueTime);
176
177 VOID inline FASTCALL KiSatisfyObjectWait(PDISPATCHER_HEADER Object, PKTHREAD Thread);
178
179 BOOLEAN inline FASTCALL KiIsObjectSignaled(PDISPATCHER_HEADER Object, PKTHREAD Thread);
180
181 VOID inline FASTCALL KiSatisifyMultipleObjectWaits(PKWAIT_BLOCK WaitBlock);
182
183 VOID FASTCALL KiWaitTest(PDISPATCHER_HEADER Object, KPRIORITY Increment);
184
185 PULONG KeGetStackTopThread(struct _ETHREAD* Thread);
186 VOID KeContextToTrapFrame(PCONTEXT Context, PKTRAP_FRAME TrapFrame);
187 VOID STDCALL KiDeliverApc(KPROCESSOR_MODE PreviousMode,
188 PVOID Reserved,
189 PKTRAP_FRAME TrapFrame);
190
191 VOID STDCALL KeInitializeEventPair(PKEVENT_PAIR EventPair);
192
193 VOID STDCALL KiInitializeUserApc(IN PVOID Reserved,
194 IN PKTRAP_FRAME TrapFrame,
195 IN PKNORMAL_ROUTINE NormalRoutine,
196 IN PVOID NormalContext,
197 IN PVOID SystemArgument1,
198 IN PVOID SystemArgument2);
199
200 VOID STDCALL KiAttachProcess(struct _KTHREAD *Thread, struct _KPROCESS *Process, KIRQL ApcLock, struct _KAPC_STATE *SavedApcState);
201
202 VOID STDCALL KiSwapProcess(struct _KPROCESS *NewProcess, struct _KPROCESS *OldProcess);
203
204 BOOLEAN
205 STDCALL
206 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode);
207
208 BOOLEAN STDCALL KeRemoveQueueApc (PKAPC Apc);
209 VOID FASTCALL KiWakeQueue(IN PKQUEUE Queue);
210 PLIST_ENTRY STDCALL KeRundownQueue(IN PKQUEUE Queue);
211
212 extern LARGE_INTEGER SystemBootTime;
213
214 /* INITIALIZATION FUNCTIONS *************************************************/
215
216 VOID KeInitExceptions(VOID);
217 VOID KeInitInterrupts(VOID);
218 VOID KeInitTimer(VOID);
219 VOID KeInitDpc(struct _KPCR* Pcr);
220 VOID KeInitDispatcher(VOID);
221 VOID inline FASTCALL KeInitializeDispatcher(VOID);
222 VOID KiInitializeSystemClock(VOID);
223 VOID KeInitializeBugCheck(VOID);
224 VOID Phase1Initialization(PVOID Context);
225
226 VOID KeInit1(PCHAR CommandLine, PULONG LastKernelAddress);
227 VOID KeInit2(VOID);
228
229 BOOLEAN KiDeliverUserApc(PKTRAP_FRAME TrapFrame);
230
231 VOID
232 STDCALL
233 KiMoveApcState (PKAPC_STATE OldState,
234 PKAPC_STATE NewState);
235
236 VOID
237 KiAddProfileEvent(KPROFILE_SOURCE Source, ULONG Pc);
238 VOID
239 KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
240 PCONTEXT Context,
241 PKTRAP_FRAME Tf,
242 KPROCESSOR_MODE PreviousMode,
243 BOOLEAN SearchFrames);
244 VOID KeTrapFrameToContext(PKTRAP_FRAME TrapFrame,
245 PCONTEXT Context);
246 VOID
247 KeApplicationProcessorInit(VOID);
248 VOID
249 KePrepareForApplicationProcessorInit(ULONG id);
250 ULONG
251 KiUserTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2);
252 VOID STDCALL
253 KePushAndStackSwitchAndSysRet(ULONG Push, PVOID NewStack);
254 VOID STDCALL
255 KeStackSwitchAndRet(PVOID NewStack);
256 VOID STDCALL
257 KeBugCheckWithTf(ULONG BugCheckCode,
258 ULONG BugCheckParameter1,
259 ULONG BugCheckParameter2,
260 ULONG BugCheckParameter3,
261 ULONG BugCheckParameter4,
262 PKTRAP_FRAME Tf);
263 #define KEBUGCHECKWITHTF(a,b,c,d,e,f) DbgPrint("KeBugCheckWithTf at %s:%i\n",__FILE__,__LINE__), KeBugCheckWithTf(a,b,c,d,e,f)
264 VOID
265 KiDumpTrapFrame(PKTRAP_FRAME Tf, ULONG ExceptionNr, ULONG cr2);
266
267 VOID
268 STDCALL
269 KeFlushCurrentTb(VOID);
270
271 VOID
272 KiSetSystemTime(PLARGE_INTEGER NewSystemTime);
273
274 #endif /* not __ASM__ */
275
276 #define MAXIMUM_PROCESSORS 32
277
278 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */