342a644050001c8175a46746b4659eec51494c02
[reactos.git] / reactos / include / ndk / ketypes.h
1 /*
2 * PROJECT: ReactOS Native Headers
3 * FILE: include/ndk/ketypes.h
4 * PURPOSE: Definitions for Kernel Types not defined in DDK/IFS
5 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
6 * UPDATE HISTORY:
7 * Created 06/10/04
8 */
9 #ifndef _KETYPES_H
10 #define _KETYPES_H
11
12 /* DEPENDENCIES **************************************************************/
13 #ifndef NTOS_MODE_USER
14 #include <arc/arc.h>
15 #include "arch/ketypes.h"
16 #endif
17
18 /* CONSTANTS *****************************************************************/
19 #define SSDT_MAX_ENTRIES 4
20 #define PROCESSOR_FEATURE_MAX 64
21 #define CONTEXT_DEBUGGER (CONTEXT_FULL | CONTEXT_FLOATING_POINT)
22
23 #ifdef NTOS_MODE_USER
24 #define SharedUserData ((KUSER_SHARED_DATA * CONST) USER_SHARED_DATA)
25 #endif
26
27 /* ENUMERATIONS **************************************************************/
28
29 #ifdef NTOS_MODE_USER
30 typedef enum _EVENT_TYPE
31 {
32 NotificationEvent,
33 SynchronizationEvent
34 } EVENT_TYPE;
35
36 typedef enum _TIMER_TYPE
37 {
38 NotificationTimer,
39 SynchronizationTimer
40 } TIMER_TYPE;
41
42 typedef enum _WAIT_TYPE
43 {
44 WaitAll,
45 WaitAny
46 } WAIT_TYPE;
47
48 typedef enum _MODE
49 {
50 KernelMode,
51 UserMode,
52 MaximumMode
53 } MODE;
54
55 typedef enum _KWAIT_REASON
56 {
57 Executive,
58 FreePage,
59 PageIn,
60 PoolAllocation,
61 DelayExecution,
62 Suspended,
63 UserRequest,
64 WrExecutive,
65 WrFreePage,
66 WrPageIn,
67 WrPoolAllocation,
68 WrDelayExecution,
69 WrSuspended,
70 WrUserRequest,
71 WrEventPair,
72 WrQueue,
73 WrLpcReceive,
74 WrLpcReply,
75 WrVirtualMemory,
76 WrPageOut,
77 WrRendezvous,
78 Spare2,
79 WrGuardedMutex,
80 Spare4,
81 Spare5,
82 Spare6,
83 WrKernel,
84 WrResource,
85 WrPushLock,
86 WrMutex,
87 WrQuantumEnd,
88 WrDispatchInt,
89 WrPreempted,
90 WrYieldExecution,
91 MaximumWaitReason
92 } KWAIT_REASON;
93
94 typedef enum _KPROFILE_SOURCE
95 {
96 ProfileTime,
97 ProfileAlignmentFixup,
98 ProfileTotalIssues,
99 ProfilePipelineDry,
100 ProfileLoadInstructions,
101 ProfilePipelineFrozen,
102 ProfileBranchInstructions,
103 ProfileTotalNonissues,
104 ProfileDcacheMisses,
105 ProfileIcacheMisses,
106 ProfileCacheMisses,
107 ProfileBranchMispredictions,
108 ProfileStoreInstructions,
109 ProfileFpInstructions,
110 ProfileIntegerInstructions,
111 Profile2Issue,
112 Profile3Issue,
113 Profile4Issue,
114 ProfileSpecialInstructions,
115 ProfileTotalCycles,
116 ProfileIcacheIssues,
117 ProfileDcacheAccesses,
118 ProfileMemoryBarrierCycles,
119 ProfileLoadLinkedIssues,
120 ProfileMaximum
121 } KPROFILE_SOURCE;
122
123 typedef enum _NT_PRODUCT_TYPE
124 {
125 NtProductWinNt = 1,
126 NtProductLanManNt,
127 NtProductServer
128 } NT_PRODUCT_TYPE, *PNT_PRODUCT_TYPE;
129
130 typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE
131 {
132 StandardDesign,
133 NEC98x86,
134 EndAlternatives
135 } ALTERNATIVE_ARCHITECTURE_TYPE;
136 #endif
137
138 typedef enum _KTHREAD_STATE
139 {
140 Initialized,
141 Ready,
142 Running,
143 Standby,
144 Terminated,
145 Waiting,
146 Transition,
147 DeferredReady,
148 } KTHREAD_STATE, *PKTHREAD_STATE;
149
150 typedef enum _KPROCESS_STATE
151 {
152 ProcessInMemory,
153 ProcessOutOfMemory,
154 ProcessInTransition,
155 } KPROCESS_STATE, *PKPROCESS_STATE;
156
157 /* FUNCTION TYPES ************************************************************/
158
159 #ifdef NTOS_MODE_USER
160 typedef VOID
161 (NTAPI *PKNORMAL_ROUTINE)(
162 IN PVOID NormalContext,
163 IN PVOID SystemArgument1,
164 IN PVOID SystemArgument2);
165
166 typedef VOID
167 (NTAPI *PTIMER_APC_ROUTINE)(
168 IN PVOID TimerContext,
169 IN ULONG TimerLowValue,
170 IN LONG TimerHighValue);
171 #endif
172
173 /* TYPES *********************************************************************/
174
175 #ifdef NTOS_MODE_USER
176 typedef CCHAR KPROCESSOR_MODE;
177
178 typedef struct _KSYSTEM_TIME
179 {
180 ULONG LowPart;
181 LONG High1Time;
182 LONG High2Time;
183 } KSYSTEM_TIME, *PKSYSTEM_TIME;
184
185 typedef struct _KUSER_SHARED_DATA
186 {
187 ULONG TickCountLowDeprecated;
188 ULONG TickCountMultiplier;
189 volatile KSYSTEM_TIME InterruptTime;
190 volatile KSYSTEM_TIME SystemTime;
191 volatile KSYSTEM_TIME TimeZoneBias;
192 USHORT ImageNumberLow;
193 USHORT ImageNumberHigh;
194 WCHAR NtSystemRoot[260];
195 ULONG MaxStackTraceDepth;
196 ULONG CryptoExponent;
197 ULONG TimeZoneId;
198 ULONG LargePageMinimum;
199 ULONG Reserved2[7];
200 NT_PRODUCT_TYPE NtProductType;
201 BOOLEAN ProductTypeIsValid;
202 ULONG NtMajorVersion;
203 ULONG NtMinorVersion;
204 BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
205 ULONG Reserved1;
206 ULONG Reserved3;
207 volatile ULONG TimeSlip;
208 ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
209 LARGE_INTEGER SystemExpirationDate;
210 ULONG SuiteMask;
211 BOOLEAN KdDebuggerEnabled;
212 volatile ULONG ActiveConsoleId;
213 volatile ULONG DismountCount;
214 ULONG ComPlusPackage;
215 ULONG LastSystemRITEventTickCount;
216 ULONG NumberOfPhysicalPages;
217 BOOLEAN SafeBootMode;
218 ULONG TraceLogging;
219 ULONGLONG Fill0;
220 ULONGLONG SystemCall[4];
221 union {
222 volatile KSYSTEM_TIME TickCount;
223 volatile ULONG64 TickCountQuad;
224 };
225 } KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
226 #endif
227
228 #ifndef NTOS_MODE_USER
229 typedef struct _CONFIGURATION_COMPONENT_DATA
230 {
231 struct _CONFIGURATION_COMPONENT_DATA *Parent;
232 struct _CONFIGURATION_COMPONENT_DATA *Child;
233 struct _CONFIGURATION_COMPONENT_DATA *Sibling;
234 CONFIGURATION_COMPONENT Component;
235 } CONFIGURATION_COMPONENT_DATA, *PCONFIGURATION_COMPONENT_DATA;
236
237 typedef enum _KAPC_ENVIRONMENT
238 {
239 OriginalApcEnvironment,
240 AttachedApcEnvironment,
241 CurrentApcEnvironment
242 } KAPC_ENVIRONMENT;
243
244 typedef struct _KNODE
245 {
246 SLIST_HEADER DeadStackList;
247 SLIST_HEADER PfnDereferenceSListHead;
248 ULONG ProcessorMask;
249 ULONG Color;
250 UCHAR Seed;
251 UCHAR NodeNumber;
252 ULONG Flags;
253 ULONG MmShiftedColor;
254 ULONG FreeCount[2];
255 struct _SINGLE_LIST_ENTRY *PfnDeferredList;
256 } KNODE, *PKNODE;
257
258 typedef struct _KPROFILE
259 {
260 CSHORT Type;
261 CSHORT Size;
262 LIST_ENTRY ListEntry;
263 PVOID RegionStart;
264 PVOID RegionEnd;
265 ULONG BucketShift;
266 PVOID Buffer;
267 KPROFILE_SOURCE Source;
268 ULONG Affinity;
269 BOOLEAN Active;
270 struct _KPROCESS *Process;
271 } KPROFILE, *PKPROFILE;
272
273 typedef struct _KINTERRUPT
274 {
275 CSHORT Type;
276 CSHORT Size;
277 LIST_ENTRY InterruptListEntry;
278 PKSERVICE_ROUTINE ServiceRoutine;
279 PVOID ServiceContext;
280 KSPIN_LOCK SpinLock;
281 ULONG TickCount;
282 PKSPIN_LOCK ActualLock;
283 PVOID DispatchAddress;
284 ULONG Vector;
285 KIRQL Irql;
286 KIRQL SynchronizeIrql;
287 BOOLEAN FloatingSave;
288 BOOLEAN Connected;
289 CHAR Number;
290 UCHAR ShareVector;
291 KINTERRUPT_MODE Mode;
292 ULONG ServiceCount;
293 ULONG DispatchCount;
294 ULONG DispatchCode[106];
295 } KINTERRUPT, *PKINTERRUPT;
296
297 typedef struct _KEVENT_PAIR
298 {
299 CSHORT Type;
300 CSHORT Size;
301 KEVENT LowEvent;
302 KEVENT HighEvent;
303 } KEVENT_PAIR, *PKEVENT_PAIR;
304
305 typedef struct _KEXECUTE_OPTIONS
306 {
307 UCHAR ExecuteDisable:1;
308 UCHAR ExecuteEnable:1;
309 UCHAR DisableThunkEmulation:1;
310 UCHAR Permanent:1;
311 UCHAR ExecuteDispatchEnable:1;
312 UCHAR ImageDispatchEnable:1;
313 UCHAR Spare:2;
314 } KEXECUTE_OPTIONS, *PKEXECUTE_OPTIONS;
315
316 typedef enum _KOBJECTS
317 {
318 EventNotificationObject = 0,
319 EventSynchronizationObject = 1,
320 MutantObject = 2,
321 ProcessObject = 3,
322 QueueObject = 4,
323 SemaphoreObject = 5,
324 ThreadObject = 6,
325 GateObject = 7,
326 TimerNotificationObject = 8,
327 TimerSynchronizationObject = 9,
328 Spare2Object = 10,
329 Spare3Object = 11,
330 Spare4Object = 12,
331 Spare5Object = 13,
332 Spare6Object = 14,
333 Spare7Object = 15,
334 Spare8Object = 16,
335 Spare9Object = 17,
336 ApcObject = 18,
337 DpcObject = 19,
338 DeviceQueueObject = 20,
339 EventPairObject = 21,
340 InterruptObject = 22,
341 ProfileObject = 23,
342 ThreadedDpcObject = 24,
343 MaximumKernelObject = 25
344 } KOBJECTS;
345
346 #include <pshpack1.h>
347
348 typedef struct _KTHREAD
349 {
350 DISPATCHER_HEADER DispatcherHeader; /* 00 */
351 LIST_ENTRY MutantListHead; /* 10 */
352 PVOID InitialStack; /* 18 */
353 ULONG_PTR StackLimit; /* 1C */
354 struct _TEB *Teb; /* 20 */
355 PVOID TlsArray; /* 24 */
356 PVOID KernelStack; /* 28 */
357 UCHAR DebugActive; /* 2C */
358 UCHAR State; /* 2D */
359 BOOLEAN Alerted[2]; /* 2E */
360 UCHAR Iopl; /* 30 */
361 UCHAR NpxState; /* 31 */
362 CHAR Saturation; /* 32 */
363 CHAR Priority; /* 33 */
364 KAPC_STATE ApcState; /* 34 */
365 ULONG ContextSwitches; /* 4C */
366 LONG WaitStatus; /* 50 */
367 KIRQL WaitIrql; /* 54 */
368 CHAR WaitMode; /* 55 */
369 UCHAR WaitNext; /* 56 */
370 UCHAR WaitReason; /* 57 */
371 union /* 58 */
372 {
373 PKWAIT_BLOCK WaitBlockList; /* 58 */
374 PKGATE GateObject; /* 58 */
375 }; /* 58 */
376 LIST_ENTRY WaitListEntry; /* 5C */
377 ULONG WaitTime; /* 64 */
378 CHAR BasePriority; /* 68 */
379 UCHAR DecrementCount; /* 69 */
380 UCHAR PriorityDecrement; /* 6A */
381 CHAR Quantum; /* 6B */
382 KWAIT_BLOCK WaitBlock[4]; /* 6C */
383 PVOID LegoData; /* CC */
384 union
385 {
386 struct
387 {
388 USHORT KernelApcDisable;
389 USHORT SpecialApcDisable;
390 };
391 ULONG CombinedApcDisable; /* D0 */
392 };
393 KAFFINITY UserAffinity; /* D4 */
394 UCHAR SystemAffinityActive;/* D8 */
395 UCHAR PowerState; /* D9 */
396 UCHAR NpxIrql; /* DA */
397 UCHAR Pad[1]; /* DB */
398 PVOID ServiceTable; /* DC */
399 struct _KQUEUE *Queue; /* E0 */
400 KSPIN_LOCK ApcQueueLock; /* E4 */
401 KTIMER Timer; /* E8 */
402 LIST_ENTRY QueueListEntry; /* 110 */
403 KAFFINITY Affinity; /* 118 */
404 UCHAR Preempted; /* 11C */
405 UCHAR ProcessReadyQueue; /* 11D */
406 UCHAR KernelStackResident; /* 11E */
407 UCHAR NextProcessor; /* 11F */
408 PVOID CallbackStack; /* 120 */
409 struct _W32THREAD *Win32Thread; /* 124 */
410 struct _KTRAP_FRAME *TrapFrame; /* 128 */
411 PKAPC_STATE ApcStatePointer[2]; /* 12C */
412 UCHAR EnableStackSwap; /* 134 */
413 UCHAR LargeStack; /* 135 */
414 UCHAR ResourceIndex; /* 136 */
415 UCHAR PreviousMode; /* 137 */
416 ULONG KernelTime; /* 138 */
417 ULONG UserTime; /* 13C */
418 KAPC_STATE SavedApcState; /* 140 */
419 UCHAR Alertable; /* 158 */
420 UCHAR ApcStateIndex; /* 159 */
421 UCHAR ApcQueueable; /* 15A */
422 UCHAR AutoAlignment; /* 15B */
423 PVOID StackBase; /* 15C */
424 KAPC SuspendApc; /* 160 */
425 KSEMAPHORE SuspendSemaphore; /* 190 */
426 LIST_ENTRY ThreadListEntry; /* 1A4 */
427 CHAR FreezeCount; /* 1AC */
428 UCHAR SuspendCount; /* 1AD */
429 UCHAR IdealProcessor; /* 1AE */
430 UCHAR DisableBoost; /* 1AF */
431 UCHAR QuantumReset; /* 1B0 */
432 } KTHREAD;
433
434 #include <poppack.h>
435
436 typedef struct _KPROCESS
437 {
438 DISPATCHER_HEADER Header; /* 000 */
439 LIST_ENTRY ProfileListHead; /* 010 */
440 PHYSICAL_ADDRESS DirectoryTableBase; /* 018 */
441 #if defined(_M_IX86)
442 KGDTENTRY LdtDescriptor; /* 020 */
443 KIDTENTRY Int21Descriptor; /* 028 */
444 USHORT IopmOffset; /* 030 */
445 UCHAR Iopl; /* 032 */
446 UCHAR Unused; /* 033 */
447 #endif
448 ULONG ActiveProcessors; /* 034 */
449 ULONG KernelTime; /* 038 */
450 ULONG UserTime; /* 03C */
451 LIST_ENTRY ReadyListHead; /* 040 */
452 LIST_ENTRY SwapListEntry; /* 048 */
453 PVOID VdmTrapcHandler; /* 04C */
454 LIST_ENTRY ThreadListHead; /* 050 */
455 KSPIN_LOCK ProcessLock; /* 058 */
456 KAFFINITY Affinity; /* 05C */
457 union
458 {
459 struct
460 {
461 ULONG AutoAlignment:1; /* 060.0 */
462 ULONG DisableBoost:1; /* 060.1 */
463 ULONG DisableQuantum:1; /* 060.2 */
464 ULONG ReservedFlags:29; /* 060.3 */
465 };
466 ULONG ProcessFlags; /* 060 */
467 };
468 CHAR BasePriority; /* 064 */
469 CHAR QuantumReset; /* 065 */
470 UCHAR State; /* 066 */
471 UCHAR ThreadSeed; /* 067 */
472 UCHAR PowerState; /* 068 */
473 UCHAR IdealNode; /* 069 */
474 UCHAR Visited; /* 06A */
475 KEXECUTE_OPTIONS Flags; /* 06B */
476 ULONG StackCount; /* 06C */
477 LIST_ENTRY ProcessListEntry; /* 070 */
478 } KPROCESS;
479
480 typedef struct _KSERVICE_TABLE_DESCRIPTOR
481 {
482 PULONG_PTR Base;
483 PULONG Count;
484 ULONG Limit;
485 #if defined(_IA64_)
486 LONG TableBaseGpOffset;
487 #endif
488 PUCHAR Number;
489 } KSERVICE_TABLE_DESCRIPTOR, *PKSERVICE_TABLE_DESCRIPTOR;
490 #endif /* !NTOS_MODE_USER */
491
492 /* EXPORTED DATA *************************************************************/
493 #ifndef NTOS_MODE_USER
494 extern CHAR NTSYSAPI KeNumberProcessors;
495 extern LOADER_PARAMETER_BLOCK NTSYSAPI KeLoaderBlock;
496 extern ULONG NTSYSAPI KeDcacheFlushCount;
497 extern ULONG NTSYSAPI KeIcacheFlushCount;
498 extern KAFFINITY NTSYSAPI KeActiveProcessors;
499 extern ULONG NTSYSAPI KiDmaIoCoherency; /* RISC Architectures only */
500 extern ULONG NTSYSAPI KeMaximumIncrement;
501 extern ULONG NTSYSAPI KeMinimumIncrement;
502 extern ULONG NTSYSAPI NtBuildNumber;
503 extern KSERVICE_TABLE_DESCRIPTOR NTSYSAPI KeServiceDescriptorTable[SSDT_MAX_ENTRIES];
504 extern KSERVICE_TABLE_DESCRIPTOR NTSYSAPI KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES];
505 #endif
506
507 #endif