4a3d1e7263ed4af4501df688ef6b25c790c06c68
[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 _KPRCB;
45 struct _KEXCEPTION_FRAME;
46
47 #define IPI_REQUEST_FUNCTIONCALL 0
48 #define IPI_REQUEST_APC 1
49 #define IPI_REQUEST_DPC 2
50 #define IPI_REQUEST_FREEZE 3
51
52 /* ipi.c ********************************************************************/
53
54 BOOLEAN STDCALL
55 KiIpiServiceRoutine(IN PKTRAP_FRAME TrapFrame,
56 IN struct _KEXCEPTION_FRAME* ExceptionFrame);
57
58 VOID
59 KiIpiSendRequest(ULONG TargetSet,
60 ULONG IpiRequest);
61
62 VOID
63 KeIpiGenericCall(VOID (STDCALL *WorkerRoutine)(PVOID),
64 PVOID Argument);
65
66 /* next file ***************************************************************/
67
68 typedef struct _KPROFILE_SOURCE_OBJECT {
69 KPROFILE_SOURCE Source;
70 LIST_ENTRY ListEntry;
71 } KPROFILE_SOURCE_OBJECT, *PKPROFILE_SOURCE_OBJECT;
72
73 typedef struct _KPROFILE {
74 CSHORT Type;
75 CSHORT Size;
76 LIST_ENTRY ListEntry;
77 PVOID RegionStart;
78 PVOID RegionEnd;
79 ULONG BucketShift;
80 PVOID Buffer;
81 CSHORT Source;
82 ULONG Affinity;
83 BOOLEAN Active;
84 struct _KPROCESS *Process;
85 } KPROFILE, *PKPROFILE;
86
87 /* Cached modules from the loader block */
88 typedef enum _CACHED_MODULE_TYPE {
89 AnsiCodepage,
90 OemCodepage,
91 UnicodeCasemap,
92 SystemRegistry,
93 HardwareRegistry,
94 MaximumCachedModuleType,
95 } CACHED_MODULE_TYPE, *PCACHED_MODULE_TYPE;
96 extern PLOADER_MODULE CachedModules[MaximumCachedModuleType];
97
98 VOID STDCALL
99 DbgBreakPointNoBugCheck(VOID);
100
101 STDCALL
102 VOID
103 KeInitializeProfile(struct _KPROFILE* Profile,
104 struct _KPROCESS* Process,
105 PVOID ImageBase,
106 ULONG ImageSize,
107 ULONG BucketSize,
108 KPROFILE_SOURCE ProfileSource,
109 KAFFINITY Affinity);
110
111 STDCALL
112 VOID
113 KeStartProfile(struct _KPROFILE* Profile,
114 PVOID Buffer);
115
116 STDCALL
117 VOID
118 KeStopProfile(struct _KPROFILE* Profile);
119
120 STDCALL
121 ULONG
122 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource);
123
124 STDCALL
125 VOID
126 KeSetIntervalProfile(KPROFILE_SOURCE ProfileSource,
127 ULONG Interval);
128
129 VOID
130 STDCALL
131 KeProfileInterrupt(
132 PKTRAP_FRAME TrapFrame
133 );
134
135 VOID
136 STDCALL
137 KeProfileInterruptWithSource(
138 IN PKTRAP_FRAME TrapFrame,
139 IN KPROFILE_SOURCE Source
140 );
141
142
143 VOID STDCALL KeUpdateSystemTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);
144 VOID STDCALL KeUpdateRunTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);
145
146 VOID STDCALL KiExpireTimers(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2);
147
148 KIRQL inline FASTCALL KeAcquireDispatcherDatabaseLock(VOID);
149 VOID inline FASTCALL KeAcquireDispatcherDatabaseLockAtDpcLevel(VOID);
150 VOID inline FASTCALL KeReleaseDispatcherDatabaseLock(KIRQL Irql);
151 VOID inline FASTCALL KeReleaseDispatcherDatabaseLockFromDpcLevel(VOID);
152
153 BOOLEAN KiDispatcherObjectWake(DISPATCHER_HEADER* hdr, KPRIORITY increment);
154 VOID STDCALL KeExpireTimers(PKDPC Apc,
155 PVOID Arg1,
156 PVOID Arg2,
157 PVOID Arg3);
158 VOID inline FASTCALL KeInitializeDispatcherHeader(DISPATCHER_HEADER* Header, ULONG Type,
159 ULONG Size, ULONG SignalState);
160 VOID KeDumpStackFrames(PULONG Frame);
161 BOOLEAN KiTestAlert(VOID);
162
163 VOID
164 FASTCALL
165 KiAbortWaitThread(PKTHREAD Thread,
166 NTSTATUS WaitStatus,
167 KPRIORITY Increment);
168
169 BOOLEAN STDCALL KiInsertTimer(PKTIMER Timer, LARGE_INTEGER DueTime);
170
171 VOID inline FASTCALL KiSatisfyObjectWait(PDISPATCHER_HEADER Object, PKTHREAD Thread);
172
173 BOOLEAN inline FASTCALL KiIsObjectSignaled(PDISPATCHER_HEADER Object, PKTHREAD Thread);
174
175 VOID inline FASTCALL KiSatisifyMultipleObjectWaits(PKWAIT_BLOCK WaitBlock);
176
177 VOID FASTCALL KiWaitTest(PDISPATCHER_HEADER Object, KPRIORITY Increment);
178
179 PULONG KeGetStackTopThread(struct _ETHREAD* Thread);
180 VOID KeContextToTrapFrame(PCONTEXT Context, PKTRAP_FRAME TrapFrame);
181 VOID STDCALL KiDeliverApc(KPROCESSOR_MODE PreviousMode,
182 PVOID Reserved,
183 PKTRAP_FRAME TrapFrame);
184
185 VOID STDCALL KeInitializeEventPair(PKEVENT_PAIR EventPair);
186
187 VOID STDCALL KiInitializeUserApc(IN PVOID Reserved,
188 IN PKTRAP_FRAME TrapFrame,
189 IN PKNORMAL_ROUTINE NormalRoutine,
190 IN PVOID NormalContext,
191 IN PVOID SystemArgument1,
192 IN PVOID SystemArgument2);
193
194 VOID STDCALL KiAttachProcess(struct _KTHREAD *Thread, struct _KPROCESS *Process, KIRQL ApcLock, struct _KAPC_STATE *SavedApcState);
195
196 VOID STDCALL KiSwapProcess(struct _KPROCESS *NewProcess, struct _KPROCESS *OldProcess);
197
198 BOOLEAN
199 STDCALL
200 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode);
201
202 BOOLEAN STDCALL KeRemoveQueueApc (PKAPC Apc);
203 VOID FASTCALL KiWakeQueue(IN PKQUEUE Queue);
204 PLIST_ENTRY STDCALL KeRundownQueue(IN PKQUEUE Queue);
205
206 extern LARGE_INTEGER SystemBootTime;
207
208 /* INITIALIZATION FUNCTIONS *************************************************/
209
210 VOID KeInitExceptions(VOID);
211 VOID KeInitInterrupts(VOID);
212 VOID KeInitTimer(VOID);
213 VOID KeInitDpc(struct _KPRCB* Prcb);
214 VOID KeInitDispatcher(VOID);
215 VOID inline FASTCALL KeInitializeDispatcher(VOID);
216 VOID KiInitializeSystemClock(VOID);
217 VOID KiInitializeBugCheck(VOID);
218 VOID Phase1Initialization(PVOID Context);
219
220 VOID KeInit1(PCHAR CommandLine, PULONG LastKernelAddress);
221 VOID KeInit2(VOID);
222
223 BOOLEAN KiDeliverUserApc(PKTRAP_FRAME TrapFrame);
224
225 VOID
226 STDCALL
227 KiMoveApcState (PKAPC_STATE OldState,
228 PKAPC_STATE NewState);
229
230 VOID
231 KiAddProfileEvent(KPROFILE_SOURCE Source, ULONG Pc);
232 VOID
233 KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
234 PCONTEXT Context,
235 PKTRAP_FRAME Tf,
236 KPROCESSOR_MODE PreviousMode,
237 BOOLEAN SearchFrames);
238 VOID KeTrapFrameToContext(PKTRAP_FRAME TrapFrame,
239 PCONTEXT Context);
240 VOID
241 KeApplicationProcessorInit(VOID);
242 VOID
243 KePrepareForApplicationProcessorInit(ULONG id);
244 ULONG
245 KiUserTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2);
246 VOID STDCALL
247 KePushAndStackSwitchAndSysRet(ULONG Push, PVOID NewStack);
248 VOID STDCALL
249 KeStackSwitchAndRet(PVOID NewStack);
250 VOID STDCALL
251 KeBugCheckWithTf(ULONG BugCheckCode,
252 ULONG BugCheckParameter1,
253 ULONG BugCheckParameter2,
254 ULONG BugCheckParameter3,
255 ULONG BugCheckParameter4,
256 PKTRAP_FRAME Tf);
257 #define KEBUGCHECKWITHTF(a,b,c,d,e,f) DbgPrint("KeBugCheckWithTf at %s:%i\n",__FILE__,__LINE__), KeBugCheckWithTf(a,b,c,d,e,f)
258 VOID
259 KiDumpTrapFrame(PKTRAP_FRAME Tf, ULONG ExceptionNr, ULONG cr2);
260
261 VOID
262 STDCALL
263 KeFlushCurrentTb(VOID);
264
265 VOID
266 KiSetSystemTime(PLARGE_INTEGER NewSystemTime);
267
268 #endif /* not __ASM__ */
269
270 #define MAXIMUM_PROCESSORS 32
271
272 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */