Thread/Process Termination/Repeaing Rewrite + Fixes
[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 /* threadsch.c ********************************************************************/
53
54 /* Thread Scheduler Functions */
55
56 /* Readies a Thread for Execution. */
57 VOID
58 STDCALL
59 KiDispatchThreadNoLock(ULONG NewThreadStatus);
60
61 /* Readies a Thread for Execution. */
62 VOID
63 STDCALL
64 KiDispatchThread(ULONG NewThreadStatus);
65
66 /* Puts a Thread into a block state. */
67 VOID
68 STDCALL
69 KiBlockThread(PNTSTATUS Status,
70 UCHAR Alertable,
71 ULONG WaitMode,
72 UCHAR WaitReason);
73
74 /* Removes a thread out of a block state. */
75 VOID
76 STDCALL
77 KiUnblockThread(PKTHREAD Thread,
78 PNTSTATUS WaitStatus,
79 KPRIORITY Increment);
80
81 /* ipi.c ********************************************************************/
82
83 BOOLEAN STDCALL
84 KiIpiServiceRoutine(IN PKTRAP_FRAME TrapFrame,
85 IN struct _KEXCEPTION_FRAME* ExceptionFrame);
86
87 VOID
88 KiIpiSendRequest(ULONG TargetSet,
89 ULONG IpiRequest);
90
91 VOID
92 KeIpiGenericCall(VOID (STDCALL *WorkerRoutine)(PVOID),
93 PVOID Argument);
94
95 /* next file ***************************************************************/
96
97 typedef struct _KPROFILE_SOURCE_OBJECT {
98 KPROFILE_SOURCE Source;
99 LIST_ENTRY ListEntry;
100 } KPROFILE_SOURCE_OBJECT, *PKPROFILE_SOURCE_OBJECT;
101
102 typedef struct _KPROFILE {
103 CSHORT Type;
104 CSHORT Size;
105 LIST_ENTRY ListEntry;
106 PVOID RegionStart;
107 PVOID RegionEnd;
108 ULONG BucketShift;
109 PVOID Buffer;
110 CSHORT Source;
111 ULONG Affinity;
112 BOOLEAN Active;
113 struct _KPROCESS *Process;
114 } KPROFILE, *PKPROFILE;
115
116 /* Cached modules from the loader block */
117 typedef enum _CACHED_MODULE_TYPE {
118 AnsiCodepage,
119 OemCodepage,
120 UnicodeCasemap,
121 SystemRegistry,
122 HardwareRegistry,
123 MaximumCachedModuleType,
124 } CACHED_MODULE_TYPE, *PCACHED_MODULE_TYPE;
125 extern PLOADER_MODULE CachedModules[MaximumCachedModuleType];
126
127 VOID STDCALL
128 DbgBreakPointNoBugCheck(VOID);
129
130 STDCALL
131 VOID
132 KeInitializeProfile(struct _KPROFILE* Profile,
133 struct _KPROCESS* Process,
134 PVOID ImageBase,
135 ULONG ImageSize,
136 ULONG BucketSize,
137 KPROFILE_SOURCE ProfileSource,
138 KAFFINITY Affinity);
139
140 STDCALL
141 VOID
142 KeStartProfile(struct _KPROFILE* Profile,
143 PVOID Buffer);
144
145 STDCALL
146 VOID
147 KeStopProfile(struct _KPROFILE* Profile);
148
149 STDCALL
150 ULONG
151 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource);
152
153 STDCALL
154 VOID
155 KeSetIntervalProfile(KPROFILE_SOURCE ProfileSource,
156 ULONG Interval);
157
158 VOID
159 STDCALL
160 KeProfileInterrupt(
161 PKTRAP_FRAME TrapFrame
162 );
163
164 VOID
165 STDCALL
166 KeProfileInterruptWithSource(
167 IN PKTRAP_FRAME TrapFrame,
168 IN KPROFILE_SOURCE Source
169 );
170
171
172 VOID STDCALL KeUpdateSystemTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);
173 VOID STDCALL KeUpdateRunTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);
174
175 VOID STDCALL KiExpireTimers(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2);
176
177 KIRQL inline FASTCALL KeAcquireDispatcherDatabaseLock(VOID);
178 VOID inline FASTCALL KeAcquireDispatcherDatabaseLockAtDpcLevel(VOID);
179 VOID inline FASTCALL KeReleaseDispatcherDatabaseLock(KIRQL Irql);
180 VOID inline FASTCALL KeReleaseDispatcherDatabaseLockFromDpcLevel(VOID);
181
182 VOID
183 STDCALL
184 KeInitializeThread(struct _KPROCESS* Process, PKTHREAD Thread, BOOLEAN First);
185
186 VOID
187 STDCALL
188 KeRundownThread(VOID);
189
190 NTSTATUS KeReleaseThread(PKTHREAD Thread);
191
192 VOID
193 STDCALL
194 KeStackAttachProcess (
195 IN struct _KPROCESS* Process,
196 OUT PKAPC_STATE ApcState
197 );
198
199 VOID
200 STDCALL
201 KeUnstackDetachProcess (
202 IN PKAPC_STATE ApcState
203 );
204
205 BOOLEAN KiDispatcherObjectWake(DISPATCHER_HEADER* hdr, KPRIORITY increment);
206 VOID STDCALL KeExpireTimers(PKDPC Apc,
207 PVOID Arg1,
208 PVOID Arg2,
209 PVOID Arg3);
210 VOID inline FASTCALL KeInitializeDispatcherHeader(DISPATCHER_HEADER* Header, ULONG Type,
211 ULONG Size, ULONG SignalState);
212 VOID KeDumpStackFrames(PULONG Frame);
213 BOOLEAN KiTestAlert(VOID);
214
215 VOID
216 FASTCALL
217 KiAbortWaitThread(PKTHREAD Thread,
218 NTSTATUS WaitStatus,
219 KPRIORITY Increment);
220
221 ULONG
222 STDCALL
223 KeForceResumeThread(IN PKTHREAD Thread);
224
225 BOOLEAN STDCALL KiInsertTimer(PKTIMER Timer, LARGE_INTEGER DueTime);
226
227 VOID inline FASTCALL KiSatisfyObjectWait(PDISPATCHER_HEADER Object, PKTHREAD Thread);
228
229 BOOLEAN inline FASTCALL KiIsObjectSignaled(PDISPATCHER_HEADER Object, PKTHREAD Thread);
230
231 VOID inline FASTCALL KiSatisifyMultipleObjectWaits(PKWAIT_BLOCK WaitBlock);
232
233 VOID FASTCALL KiWaitTest(PDISPATCHER_HEADER Object, KPRIORITY Increment);
234
235 PULONG KeGetStackTopThread(struct _ETHREAD* Thread);
236 VOID KeContextToTrapFrame(PCONTEXT Context, PKTRAP_FRAME TrapFrame);
237 VOID STDCALL KiDeliverApc(KPROCESSOR_MODE PreviousMode,
238 PVOID Reserved,
239 PKTRAP_FRAME TrapFrame);
240
241 LONG
242 STDCALL
243 KiInsertQueue(IN PKQUEUE Queue,
244 IN PLIST_ENTRY Entry,
245 BOOLEAN Head);
246
247 ULONG
248 STDCALL
249 KeSetProcess(struct _KPROCESS* Process,
250 KPRIORITY Increment);
251
252
253 VOID STDCALL KeInitializeEventPair(PKEVENT_PAIR EventPair);
254
255 VOID STDCALL KiInitializeUserApc(IN PVOID Reserved,
256 IN PKTRAP_FRAME TrapFrame,
257 IN PKNORMAL_ROUTINE NormalRoutine,
258 IN PVOID NormalContext,
259 IN PVOID SystemArgument1,
260 IN PVOID SystemArgument2);
261
262 VOID STDCALL KiAttachProcess(struct _KTHREAD *Thread, struct _KPROCESS *Process, KIRQL ApcLock, struct _KAPC_STATE *SavedApcState);
263
264 VOID STDCALL KiSwapProcess(struct _KPROCESS *NewProcess, struct _KPROCESS *OldProcess);
265
266 BOOLEAN
267 STDCALL
268 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode);
269
270 BOOLEAN STDCALL KeRemoveQueueApc (PKAPC Apc);
271 VOID FASTCALL KiWakeQueue(IN PKQUEUE Queue);
272 PLIST_ENTRY STDCALL KeRundownQueue(IN PKQUEUE Queue);
273
274 extern LARGE_INTEGER SystemBootTime;
275
276 /* INITIALIZATION FUNCTIONS *************************************************/
277
278 VOID KeInitExceptions(VOID);
279 VOID KeInitInterrupts(VOID);
280 VOID KeInitTimer(VOID);
281 VOID KeInitDpc(struct _KPRCB* Prcb);
282 VOID KeInitDispatcher(VOID);
283 VOID inline FASTCALL KeInitializeDispatcher(VOID);
284 VOID KiInitializeSystemClock(VOID);
285 VOID KiInitializeBugCheck(VOID);
286 VOID Phase1Initialization(PVOID Context);
287
288 VOID KeInit1(PCHAR CommandLine, PULONG LastKernelAddress);
289 VOID KeInit2(VOID);
290
291 BOOLEAN KiDeliverUserApc(PKTRAP_FRAME TrapFrame);
292
293 VOID
294 STDCALL
295 KiMoveApcState (PKAPC_STATE OldState,
296 PKAPC_STATE NewState);
297
298 VOID
299 KiAddProfileEvent(KPROFILE_SOURCE Source, ULONG Pc);
300 VOID
301 KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
302 PCONTEXT Context,
303 PKTRAP_FRAME Tf,
304 KPROCESSOR_MODE PreviousMode,
305 BOOLEAN SearchFrames);
306 VOID KeTrapFrameToContext(PKTRAP_FRAME TrapFrame,
307 PCONTEXT Context);
308 VOID
309 KeApplicationProcessorInit(VOID);
310 VOID
311 KePrepareForApplicationProcessorInit(ULONG id);
312 ULONG
313 KiUserTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2);
314 VOID STDCALL
315 KePushAndStackSwitchAndSysRet(ULONG Push, PVOID NewStack);
316 VOID STDCALL
317 KeStackSwitchAndRet(PVOID NewStack);
318 VOID STDCALL
319 KeBugCheckWithTf(ULONG BugCheckCode,
320 ULONG BugCheckParameter1,
321 ULONG BugCheckParameter2,
322 ULONG BugCheckParameter3,
323 ULONG BugCheckParameter4,
324 PKTRAP_FRAME Tf);
325 #define KEBUGCHECKWITHTF(a,b,c,d,e,f) DbgPrint("KeBugCheckWithTf at %s:%i\n",__FILE__,__LINE__), KeBugCheckWithTf(a,b,c,d,e,f)
326 VOID
327 KiDumpTrapFrame(PKTRAP_FRAME Tf, ULONG ExceptionNr, ULONG cr2);
328
329 VOID
330 STDCALL
331 KeFlushCurrentTb(VOID);
332
333 VOID
334 KiSetSystemTime(PLARGE_INTEGER NewSystemTime);
335
336 #endif /* not __ASM__ */
337
338 #define MAXIMUM_PROCESSORS 32
339
340 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */