44c993a9126944e95bb02980efda7c1493075a19
[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 /* FUNCTION TYPES ************************************************************/
151
152 #ifdef NTOS_MODE_USER
153 typedef VOID
154 (NTAPI *PKNORMAL_ROUTINE)(
155 IN PVOID NormalContext,
156 IN PVOID SystemArgument1,
157 IN PVOID SystemArgument2);
158
159 typedef VOID
160 (NTAPI *PTIMER_APC_ROUTINE)(
161 IN PVOID TimerContext,
162 IN ULONG TimerLowValue,
163 IN LONG TimerHighValue);
164 #endif
165
166 /* TYPES *********************************************************************/
167
168 typedef LONG KPRIORITY;
169
170 #ifdef NTOS_MODE_USER
171 typedef CCHAR KPROCESSOR_MODE;
172
173 typedef struct _KSYSTEM_TIME
174 {
175 ULONG LowPart;
176 LONG High1Time;
177 LONG High2Time;
178 } KSYSTEM_TIME, *PKSYSTEM_TIME;
179
180 typedef struct _KUSER_SHARED_DATA
181 {
182 ULONG TickCountLowDeprecated;
183 ULONG TickCountMultiplier;
184 volatile KSYSTEM_TIME InterruptTime;
185 volatile KSYSTEM_TIME SystemTime;
186 volatile KSYSTEM_TIME TimeZoneBias;
187 USHORT ImageNumberLow;
188 USHORT ImageNumberHigh;
189 WCHAR NtSystemRoot[260];
190 ULONG MaxStackTraceDepth;
191 ULONG CryptoExponent;
192 ULONG TimeZoneId;
193 ULONG LargePageMinimum;
194 ULONG Reserved2[7];
195 NT_PRODUCT_TYPE NtProductType;
196 BOOLEAN ProductTypeIsValid;
197 ULONG NtMajorVersion;
198 ULONG NtMinorVersion;
199 BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
200 ULONG Reserved1;
201 ULONG Reserved3;
202 volatile ULONG TimeSlip;
203 ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
204 LARGE_INTEGER SystemExpirationDate;
205 ULONG SuiteMask;
206 BOOLEAN KdDebuggerEnabled;
207 volatile ULONG ActiveConsoleId;
208 volatile ULONG DismountCount;
209 ULONG ComPlusPackage;
210 ULONG LastSystemRITEventTickCount;
211 ULONG NumberOfPhysicalPages;
212 BOOLEAN SafeBootMode;
213 ULONG TraceLogging;
214 ULONGLONG Fill0;
215 ULONGLONG SystemCall[4];
216 union {
217 volatile KSYSTEM_TIME TickCount;
218 volatile ULONG64 TickCountQuad;
219 };
220 } KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
221 #endif
222
223 #ifndef NTOS_MODE_USER
224 typedef struct _CONFIGURATION_COMPONENT_DATA
225 {
226 struct _CONFIGURATION_COMPONENT_DATA *Parent;
227 struct _CONFIGURATION_COMPONENT_DATA *Child;
228 struct _CONFIGURATION_COMPONENT_DATA *Sibling;
229 CONFIGURATION_COMPONENT Component;
230 } CONFIGURATION_COMPONENT_DATA, *PCONFIGURATION_COMPONENT_DATA;
231
232 typedef enum _KAPC_ENVIRONMENT
233 {
234 OriginalApcEnvironment,
235 AttachedApcEnvironment,
236 CurrentApcEnvironment
237 } KAPC_ENVIRONMENT;
238
239 typedef struct _KNODE
240 {
241 SLIST_HEADER DeadStackList;
242 SLIST_HEADER PfnDereferenceSListHead;
243 ULONG ProcessorMask;
244 ULONG Color;
245 UCHAR Seed;
246 UCHAR NodeNumber;
247 ULONG Flags;
248 ULONG MmShiftedColor;
249 ULONG FreeCount[2];
250 struct _SINGLE_LIST_ENTRY *PfnDeferredList;
251 } KNODE, *PKNODE;
252
253 typedef struct _KPROFILE
254 {
255 CSHORT Type;
256 CSHORT Size;
257 LIST_ENTRY ListEntry;
258 PVOID RegionStart;
259 PVOID RegionEnd;
260 ULONG BucketShift;
261 PVOID Buffer;
262 KPROFILE_SOURCE Source;
263 ULONG Affinity;
264 BOOLEAN Active;
265 struct _KPROCESS *Process;
266 } KPROFILE, *PKPROFILE;
267
268 typedef struct _KINTERRUPT
269 {
270 CSHORT Type;
271 CSHORT Size;
272 LIST_ENTRY InterruptListEntry;
273 PKSERVICE_ROUTINE ServiceRoutine;
274 PVOID ServiceContext;
275 KSPIN_LOCK SpinLock;
276 ULONG TickCount;
277 PKSPIN_LOCK ActualLock;
278 PVOID DispatchAddress;
279 ULONG Vector;
280 KIRQL Irql;
281 KIRQL SynchronizeIrql;
282 BOOLEAN FloatingSave;
283 BOOLEAN Connected;
284 CHAR Number;
285 UCHAR ShareVector;
286 KINTERRUPT_MODE Mode;
287 ULONG ServiceCount;
288 ULONG DispatchCount;
289 ULONG DispatchCode[106];
290 } KINTERRUPT, *PKINTERRUPT;
291
292 typedef struct _KEVENT_PAIR
293 {
294 CSHORT Type;
295 CSHORT Size;
296 KEVENT LowEvent;
297 KEVENT HighEvent;
298 } KEVENT_PAIR, *PKEVENT_PAIR;
299
300 typedef struct _KEXECUTE_OPTIONS
301 {
302 UCHAR ExecuteDisable:1;
303 UCHAR ExecuteEnable:1;
304 UCHAR DisableThunkEmulation:1;
305 UCHAR Permanent:1;
306 UCHAR ExecuteDispatchEnable:1;
307 UCHAR ImageDispatchEnable:1;
308 UCHAR Spare:2;
309 } KEXECUTE_OPTIONS, *PKEXECUTE_OPTIONS;
310
311 typedef enum _KOBJECTS
312 {
313 EventNotificationObject = 0,
314 EventSynchronizationObject = 1,
315 MutantObject = 2,
316 ProcessObject = 3,
317 QueueObject = 4,
318 SemaphoreObject = 5,
319 ThreadObject = 6,
320 GateObject = 7,
321 TimerNotificationObject = 8,
322 TimerSynchronizationObject = 9,
323 Spare2Object = 10,
324 Spare3Object = 11,
325 Spare4Object = 12,
326 Spare5Object = 13,
327 Spare6Object = 14,
328 Spare7Object = 15,
329 Spare8Object = 16,
330 Spare9Object = 17,
331 ApcObject = 18,
332 DpcObject = 19,
333 DeviceQueueObject = 20,
334 EventPairObject = 21,
335 InterruptObject = 22,
336 ProfileObject = 23,
337 ThreadedDpcObject = 24,
338 MaximumKernelObject = 25
339 } KOBJECTS;
340
341 #include <pshpack1.h>
342
343 typedef struct _KTHREAD
344 {
345 DISPATCHER_HEADER DispatcherHeader; /* 00 */
346 LIST_ENTRY MutantListHead; /* 10 */
347 PVOID InitialStack; /* 18 */
348 ULONG_PTR StackLimit; /* 1C */
349 struct _TEB *Teb; /* 20 */
350 PVOID TlsArray; /* 24 */
351 PVOID KernelStack; /* 28 */
352 UCHAR DebugActive; /* 2C */
353 UCHAR State; /* 2D */
354 BOOLEAN Alerted[2]; /* 2E */
355 UCHAR Iopl; /* 30 */
356 UCHAR NpxState; /* 31 */
357 CHAR Saturation; /* 32 */
358 CHAR Priority; /* 33 */
359 KAPC_STATE ApcState; /* 34 */
360 ULONG ContextSwitches; /* 4C */
361 LONG WaitStatus; /* 50 */
362 KIRQL WaitIrql; /* 54 */
363 CHAR WaitMode; /* 55 */
364 UCHAR WaitNext; /* 56 */
365 UCHAR WaitReason; /* 57 */
366 union /* 58 */
367 {
368 PKWAIT_BLOCK WaitBlockList; /* 58 */
369 PKGATE GateObject; /* 58 */
370 }; /* 58 */
371 LIST_ENTRY WaitListEntry; /* 5C */
372 ULONG WaitTime; /* 64 */
373 CHAR BasePriority; /* 68 */
374 UCHAR DecrementCount; /* 69 */
375 UCHAR PriorityDecrement; /* 6A */
376 CHAR Quantum; /* 6B */
377 KWAIT_BLOCK WaitBlock[4]; /* 6C */
378 PVOID LegoData; /* CC */
379 union
380 {
381 struct
382 {
383 USHORT KernelApcDisable;
384 USHORT SpecialApcDisable;
385 };
386 ULONG CombinedApcDisable; /* D0 */
387 };
388 KAFFINITY UserAffinity; /* D4 */
389 UCHAR SystemAffinityActive;/* D8 */
390 UCHAR PowerState; /* D9 */
391 UCHAR NpxIrql; /* DA */
392 UCHAR Pad[1]; /* DB */
393 PVOID ServiceTable; /* DC */
394 struct _KQUEUE *Queue; /* E0 */
395 KSPIN_LOCK ApcQueueLock; /* E4 */
396 KTIMER Timer; /* E8 */
397 LIST_ENTRY QueueListEntry; /* 110 */
398 KAFFINITY Affinity; /* 118 */
399 UCHAR Preempted; /* 11C */
400 UCHAR ProcessReadyQueue; /* 11D */
401 UCHAR KernelStackResident; /* 11E */
402 UCHAR NextProcessor; /* 11F */
403 PVOID CallbackStack; /* 120 */
404 struct _W32THREAD *Win32Thread; /* 124 */
405 struct _KTRAP_FRAME *TrapFrame; /* 128 */
406 PKAPC_STATE ApcStatePointer[2]; /* 12C */
407 UCHAR EnableStackSwap; /* 134 */
408 UCHAR LargeStack; /* 135 */
409 UCHAR ResourceIndex; /* 136 */
410 UCHAR PreviousMode; /* 137 */
411 ULONG KernelTime; /* 138 */
412 ULONG UserTime; /* 13C */
413 KAPC_STATE SavedApcState; /* 140 */
414 UCHAR Alertable; /* 158 */
415 UCHAR ApcStateIndex; /* 159 */
416 UCHAR ApcQueueable; /* 15A */
417 UCHAR AutoAlignment; /* 15B */
418 PVOID StackBase; /* 15C */
419 KAPC SuspendApc; /* 160 */
420 KSEMAPHORE SuspendSemaphore; /* 190 */
421 LIST_ENTRY ThreadListEntry; /* 1A4 */
422 CHAR FreezeCount; /* 1AC */
423 UCHAR SuspendCount; /* 1AD */
424 UCHAR IdealProcessor; /* 1AE */
425 UCHAR DisableBoost; /* 1AF */
426 UCHAR QuantumReset; /* 1B0 */
427 } KTHREAD;
428
429 #include <poppack.h>
430
431 typedef struct _KPROCESS
432 {
433 DISPATCHER_HEADER Header; /* 000 */
434 LIST_ENTRY ProfileListHead; /* 010 */
435 PHYSICAL_ADDRESS DirectoryTableBase; /* 018 */
436 #if defined(_M_IX86)
437 KGDTENTRY LdtDescriptor; /* 020 */
438 KIDTENTRY Int21Descriptor; /* 028 */
439 USHORT IopmOffset; /* 030 */
440 UCHAR Iopl; /* 032 */
441 UCHAR Unused; /* 033 */
442 #endif
443 ULONG ActiveProcessors; /* 034 */
444 ULONG KernelTime; /* 038 */
445 ULONG UserTime; /* 03C */
446 LIST_ENTRY ReadyListHead; /* 040 */
447 LIST_ENTRY SwapListEntry; /* 048 */
448 PVOID VdmTrapcHandler; /* 04C */
449 LIST_ENTRY ThreadListHead; /* 050 */
450 KSPIN_LOCK ProcessLock; /* 058 */
451 KAFFINITY Affinity; /* 05C */
452 union
453 {
454 struct
455 {
456 ULONG AutoAlignment:1; /* 060.0 */
457 ULONG DisableBoost:1; /* 060.1 */
458 ULONG DisableQuantum:1; /* 060.2 */
459 ULONG ReservedFlags:29; /* 060.3 */
460 };
461 ULONG ProcessFlags; /* 060 */
462 };
463 CHAR BasePriority; /* 064 */
464 CHAR QuantumReset; /* 065 */
465 UCHAR State; /* 066 */
466 UCHAR ThreadSeed; /* 067 */
467 UCHAR PowerState; /* 068 */
468 UCHAR IdealNode; /* 069 */
469 UCHAR Visited; /* 06A */
470 KEXECUTE_OPTIONS Flags; /* 06B */
471 ULONG StackCount; /* 06C */
472 LIST_ENTRY ProcessListEntry; /* 070 */
473 } KPROCESS;
474
475 typedef struct _KSERVICE_TABLE_DESCRIPTOR
476 {
477 PULONG_PTR Base;
478 PULONG Count;
479 ULONG Limit;
480 #if defined(_IA64_)
481 LONG TableBaseGpOffset;
482 #endif
483 PUCHAR Number;
484 } KSERVICE_TABLE_DESCRIPTOR, *PKSERVICE_TABLE_DESCRIPTOR;
485 #endif /* !NTOS_MODE_USER */
486
487 /* EXPORTED DATA *************************************************************/
488 #ifndef NTOS_MODE_USER
489 extern CHAR NTSYSAPI KeNumberProcessors;
490 extern LOADER_PARAMETER_BLOCK NTSYSAPI KeLoaderBlock;
491 extern ULONG NTSYSAPI KeDcacheFlushCount;
492 extern ULONG NTSYSAPI KeIcacheFlushCount;
493 extern KAFFINITY NTSYSAPI KeActiveProcessors;
494 extern ULONG NTSYSAPI KiDmaIoCoherency; /* RISC Architectures only */
495 extern ULONG NTSYSAPI KeMaximumIncrement;
496 extern ULONG NTSYSAPI KeMinimumIncrement;
497 extern ULONG NTSYSAPI NtBuildNumber;
498 extern KSERVICE_TABLE_DESCRIPTOR NTSYSAPI KeServiceDescriptorTable[SSDT_MAX_ENTRIES];
499 extern KSERVICE_TABLE_DESCRIPTOR NTSYSAPI KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES];
500 #endif
501
502 #endif