* The Shell.. for a long time we dreamed of having a compatible, properly working...
[reactos.git] / reactos / include / ndk / ketypes.h
1 /*++ NDK Version: 0098
2
3 Copyright (c) Alex Ionescu. All rights reserved.
4
5 Header Name:
6
7 lpctypes.h
8
9 Abstract:
10
11 Type definitions for the Loader.
12
13 Author:
14
15 Alex Ionescu (alexi@tinykrnl.org) - Updated - 27-Feb-2006
16
17 --*/
18
19 #ifndef _KETYPES_H
20 #define _KETYPES_H
21
22 //
23 // Dependencies
24 //
25 #include <umtypes.h>
26 #ifndef NTOS_MODE_USER
27 #include <haltypes.h>
28 #include <potypes.h>
29 #include <ifssupp.h>
30 #endif
31
32 //
33 // Context Record Flags
34 //
35 #define CONTEXT_DEBUGGER (CONTEXT_FULL | CONTEXT_FLOATING_POINT)
36
37 //
38 // Maximum System Descriptor Table Entries
39 //
40 #define SSDT_MAX_ENTRIES 2
41
42 //
43 // Processor Architectures
44 //
45 #define PROCESSOR_ARCHITECTURE_INTEL 0
46 #define PROCESSOR_ARCHITECTURE_MIPS 1
47 #define PROCESSOR_ARCHITECTURE_ALPHA 2
48 #define PROCESSOR_ARCHITECTURE_PPC 3
49 #define PROCESSOR_ARCHITECTURE_SHX 4
50 #define PROCESSOR_ARCHITECTURE_ARM 5
51 #define PROCESSOR_ARCHITECTURE_IA64 6
52 #define PROCESSOR_ARCHITECTURE_ALPHA64 7
53 #define PROCESSOR_ARCHITECTURE_MSIL 8
54 #define PROCESSOR_ARCHITECTURE_AMD64 9
55 #define PROCESSOR_ARCHITECTURE_UNKNOWN 0xFFFF
56
57 //
58 // Object Type Mask for Kernel Dispatcher Objects
59 //
60 #define KOBJECT_TYPE_MASK 0x7F
61 #define KOBJECT_LOCK_BIT 0x80
62
63 //
64 // Dispatcher Priority increments
65 //
66 #define THREAD_ALERT_INCREMENT 2
67
68 //
69 // Physical memory offset of KUSER_SHARED_DATA
70 //
71 #define KI_USER_SHARED_DATA_PHYSICAL 0x41000
72
73 //
74 // Quantum values and decrements
75 //
76 #define MAX_QUANTUM 0x7F
77 #define WAIT_QUANTUM_DECREMENT 1
78 #define CLOCK_QUANTUM_DECREMENT 3
79
80 //
81 // Kernel Feature Bits
82 //
83 #define KF_V86_VIS 0x00000001
84 #define KF_RDTSC 0x00000002
85 #define KF_CR4 0x00000004
86 #define KF_CMOV 0x00000008
87 #define KF_GLOBAL_PAGE 0x00000010
88 #define KF_LARGE_PAGE 0x00000020
89 #define KF_MTRR 0x00000040
90 #define KF_CMPXCHG8B 0x00000080
91 #define KF_MMX 0x00000100
92 #define KF_WORKING_PTE 0x00000200
93 #define KF_PAT 0x00000400
94 #define KF_FXSR 0x00000800
95 #define KF_FAST_SYSCALL 0x00001000
96 #define KF_XMMI 0x00002000
97 #define KF_3DNOW 0x00004000
98 #define KF_AMDK6MTRR 0x00008000
99 #define KF_XMMI64 0x00010000
100 #define KF_DTS 0x00020000
101 #define KF_NX_BIT 0x20000000
102 #define KF_NX_DISABLED 0x40000000
103 #define KF_NX_ENABLED 0x80000000
104
105 //
106 // Internal Exception Codes
107 //
108 #define KI_EXCEPTION_INTERNAL 0x10000000
109 #define KI_EXCEPTION_ACCESS_VIOLATION (KI_EXCEPTION_INTERNAL | 0x04)
110
111 #ifndef NTOS_MODE_USER
112 //
113 // Number of dispatch codes supported by KINTERRUPT
114 //
115 #ifdef _M_AMD64
116 #define DISPATCH_LENGTH 4
117 #elif (NTDDI_VERSION >= NTDDI_LONGHORN)
118 #define DISPATCH_LENGTH 135
119 #else
120 #define DISPATCH_LENGTH 106
121 #endif
122
123 #else
124
125 //
126 // KPROCESSOR_MODE Type
127 //
128 typedef CCHAR KPROCESSOR_MODE;
129
130 //
131 // Dereferencable pointer to KUSER_SHARED_DATA in User-Mode
132 //
133 #define SharedUserData ((KUSER_SHARED_DATA *)USER_SHARED_DATA)
134
135 //
136 // Maximum WOW64 Entries in KUSER_SHARED_DATA
137 //
138 #define MAX_WOW64_SHARED_ENTRIES 16
139
140 //
141 // Maximum Processor Features supported in KUSER_SHARED_DATA
142 //
143 #define PROCESSOR_FEATURE_MAX 64
144
145 //
146 // Event Types
147 //
148 typedef enum _EVENT_TYPE
149 {
150 NotificationEvent,
151 SynchronizationEvent
152 } EVENT_TYPE;
153
154 //
155 // Timer Types
156 //
157 typedef enum _TIMER_TYPE
158 {
159 NotificationTimer,
160 SynchronizationTimer
161 } TIMER_TYPE;
162
163 //
164 // Wait Types
165 //
166 typedef enum _WAIT_TYPE
167 {
168 WaitAll,
169 WaitAny
170 } WAIT_TYPE;
171
172 //
173 // Processor Execution Modes
174 //
175 typedef enum _MODE
176 {
177 KernelMode,
178 UserMode,
179 MaximumMode
180 } MODE;
181
182 //
183 // Wait Reasons
184 //
185 typedef enum _KWAIT_REASON
186 {
187 Executive,
188 FreePage,
189 PageIn,
190 PoolAllocation,
191 DelayExecution,
192 Suspended,
193 UserRequest,
194 WrExecutive,
195 WrFreePage,
196 WrPageIn,
197 WrPoolAllocation,
198 WrDelayExecution,
199 WrSuspended,
200 WrUserRequest,
201 WrEventPair,
202 WrQueue,
203 WrLpcReceive,
204 WrLpcReply,
205 WrVirtualMemory,
206 WrPageOut,
207 WrRendezvous,
208 Spare2,
209 WrGuardedMutex,
210 Spare4,
211 Spare5,
212 Spare6,
213 WrKernel,
214 WrResource,
215 WrPushLock,
216 WrMutex,
217 WrQuantumEnd,
218 WrDispatchInt,
219 WrPreempted,
220 WrYieldExecution,
221 MaximumWaitReason
222 } KWAIT_REASON;
223
224 //
225 // Profiling Sources
226 //
227 typedef enum _KPROFILE_SOURCE
228 {
229 ProfileTime,
230 ProfileAlignmentFixup,
231 ProfileTotalIssues,
232 ProfilePipelineDry,
233 ProfileLoadInstructions,
234 ProfilePipelineFrozen,
235 ProfileBranchInstructions,
236 ProfileTotalNonissues,
237 ProfileDcacheMisses,
238 ProfileIcacheMisses,
239 ProfileCacheMisses,
240 ProfileBranchMispredictions,
241 ProfileStoreInstructions,
242 ProfileFpInstructions,
243 ProfileIntegerInstructions,
244 Profile2Issue,
245 Profile3Issue,
246 Profile4Issue,
247 ProfileSpecialInstructions,
248 ProfileTotalCycles,
249 ProfileIcacheIssues,
250 ProfileDcacheAccesses,
251 ProfileMemoryBarrierCycles,
252 ProfileLoadLinkedIssues,
253 ProfileMaximum
254 } KPROFILE_SOURCE;
255
256 //
257 // NT Product and Architecture Types
258 //
259 typedef enum _NT_PRODUCT_TYPE
260 {
261 NtProductWinNt = 1,
262 NtProductLanManNt,
263 NtProductServer
264 } NT_PRODUCT_TYPE, *PNT_PRODUCT_TYPE;
265
266 typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE
267 {
268 StandardDesign,
269 NEC98x86,
270 EndAlternatives
271 } ALTERNATIVE_ARCHITECTURE_TYPE;
272
273 #endif
274
275 //
276 // Thread States
277 //
278 typedef enum _KTHREAD_STATE
279 {
280 Initialized,
281 Ready,
282 Running,
283 Standby,
284 Terminated,
285 Waiting,
286 Transition,
287 DeferredReady,
288 #if (NTDDI_VERSION >= NTDDI_WS03)
289 GateWait
290 #endif
291 } KTHREAD_STATE, *PKTHREAD_STATE;
292
293 //
294 // Kernel Object Types
295 //
296 typedef enum _KOBJECTS
297 {
298 EventNotificationObject = 0,
299 EventSynchronizationObject = 1,
300 MutantObject = 2,
301 ProcessObject = 3,
302 QueueObject = 4,
303 SemaphoreObject = 5,
304 ThreadObject = 6,
305 GateObject = 7,
306 TimerNotificationObject = 8,
307 TimerSynchronizationObject = 9,
308 Spare2Object = 10,
309 Spare3Object = 11,
310 Spare4Object = 12,
311 Spare5Object = 13,
312 Spare6Object = 14,
313 Spare7Object = 15,
314 Spare8Object = 16,
315 Spare9Object = 17,
316 ApcObject = 18,
317 DpcObject = 19,
318 DeviceQueueObject = 20,
319 EventPairObject = 21,
320 InterruptObject = 22,
321 ProfileObject = 23,
322 ThreadedDpcObject = 24,
323 MaximumKernelObject = 25
324 } KOBJECTS;
325
326 //
327 // Adjust reasons
328 //
329 typedef enum _ADJUST_REASON
330 {
331 AdjustNone = 0,
332 AdjustUnwait = 1,
333 AdjustBoost = 2
334 } ADJUST_REASON;
335
336 //
337 // Continue Status
338 //
339 typedef enum _KCONTINUE_STATUS
340 {
341 ContinueError = 0,
342 ContinueSuccess,
343 ContinueProcessorReselected,
344 ContinueNextProcessor
345 } KCONTINUE_STATUS;
346
347 //
348 // Process States
349 //
350 typedef enum _KPROCESS_STATE
351 {
352 ProcessInMemory,
353 ProcessOutOfMemory,
354 ProcessInTransition,
355 ProcessInSwap,
356 ProcessOutSwap,
357 } KPROCESS_STATE, *PKPROCESS_STATE;
358
359 //
360 // NtVdmControl Classes
361 //
362 typedef enum _VDMSERVICECLASS
363 {
364 VdmStartExecution = 0,
365 VdmQueueInterrupt = 1,
366 VdmDelayInterrupt = 2,
367 VdmInitialize = 3,
368 VdmFeatures = 4,
369 VdmSetInt21Handler = 5,
370 VdmQueryDir = 6,
371 VdmPrinterDirectIoOpen = 7,
372 VdmPrinterDirectIoClose = 8,
373 VdmPrinterInitialize = 9,
374 VdmSetLdtEntries = 10,
375 VdmSetProcessLdtInfo = 11,
376 VdmAdlibEmulation = 12,
377 VdmPMCliControl = 13,
378 VdmQueryVdmProcess = 14,
379 } VDMSERVICECLASS;
380
381 #ifdef NTOS_MODE_USER
382
383 //
384 // APC Normal Routine
385 //
386 typedef VOID
387 (NTAPI *PKNORMAL_ROUTINE)(
388 _In_ PVOID NormalContext,
389 _In_ PVOID SystemArgument1,
390 _In_ PVOID SystemArgument2
391 );
392
393 //
394 // Timer Routine
395 //
396 typedef VOID
397 (NTAPI *PTIMER_APC_ROUTINE)(
398 _In_ PVOID TimerContext,
399 _In_ ULONG TimerLowValue,
400 _In_ LONG TimerHighValue
401 );
402
403 //
404 // System Time Structure
405 //
406 typedef struct _KSYSTEM_TIME
407 {
408 ULONG LowPart;
409 LONG High1Time;
410 LONG High2Time;
411 } KSYSTEM_TIME, *PKSYSTEM_TIME;
412
413 //
414 // Shared Kernel User Data
415 //
416 typedef struct _KUSER_SHARED_DATA
417 {
418 ULONG TickCountLowDeprecated;
419 ULONG TickCountMultiplier;
420 volatile KSYSTEM_TIME InterruptTime;
421 volatile KSYSTEM_TIME SystemTime;
422 volatile KSYSTEM_TIME TimeZoneBias;
423 USHORT ImageNumberLow;
424 USHORT ImageNumberHigh;
425 WCHAR NtSystemRoot[260];
426 ULONG MaxStackTraceDepth;
427 ULONG CryptoExponent;
428 ULONG TimeZoneId;
429 ULONG LargePageMinimum;
430 ULONG Reserved2[7];
431 NT_PRODUCT_TYPE NtProductType;
432 BOOLEAN ProductTypeIsValid;
433 ULONG NtMajorVersion;
434 ULONG NtMinorVersion;
435 BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
436 ULONG Reserved1;
437 ULONG Reserved3;
438 volatile ULONG TimeSlip;
439 ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
440 LARGE_INTEGER SystemExpirationDate;
441 ULONG SuiteMask;
442 BOOLEAN KdDebuggerEnabled;
443 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
444 UCHAR NXSupportPolicy;
445 #endif
446 volatile ULONG ActiveConsoleId;
447 volatile ULONG DismountCount;
448 ULONG ComPlusPackage;
449 ULONG LastSystemRITEventTickCount;
450 ULONG NumberOfPhysicalPages;
451 BOOLEAN SafeBootMode;
452 ULONG TraceLogging;
453 ULONG Fill0;
454 ULONGLONG TestRetInstruction;
455 ULONG SystemCall;
456 ULONG SystemCallReturn;
457 ULONGLONG SystemCallPad[3];
458 union {
459 volatile KSYSTEM_TIME TickCount;
460 volatile ULONG64 TickCountQuad;
461 };
462 ULONG Cookie;
463 #if (NTDDI_VERSION >= NTDDI_WS03)
464 LONGLONG ConsoleSessionForegroundProcessId;
465 ULONG Wow64SharedInformation[MAX_WOW64_SHARED_ENTRIES];
466 #endif
467 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
468 USHORT UserModeGlobalLogger[8];
469 ULONG HeapTracingPid[2];
470 ULONG CritSecTracingPid[2];
471 union
472 {
473 ULONG SharedDataFlags;
474 struct
475 {
476 ULONG DbgErrorPortPresent:1;
477 ULONG DbgElevationEnabled:1;
478 ULONG DbgVirtEnabled:1;
479 ULONG DbgInstallerDetectEnabled:1;
480 ULONG SpareBits:28;
481 };
482 };
483 ULONG ImageFileExecutionOptions;
484 KAFFINITY ActiveProcessorAffinity;
485 #endif
486 } KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
487
488 //
489 // VDM Structures
490 //
491 #include "pshpack1.h"
492 typedef struct _VdmVirtualIca
493 {
494 LONG ica_count[8];
495 LONG ica_int_line;
496 LONG ica_cpu_int;
497 USHORT ica_base;
498 USHORT ica_hipiri;
499 USHORT ica_mode;
500 UCHAR ica_master;
501 UCHAR ica_irr;
502 UCHAR ica_isr;
503 UCHAR ica_imr;
504 UCHAR ica_ssr;
505 } VDMVIRTUALICA, *PVDMVIRTUALICA;
506 #include "poppack.h"
507
508 typedef struct _VdmIcaUserData
509 {
510 PVOID pIcaLock;
511 PVDMVIRTUALICA pIcaMaster;
512 PVDMVIRTUALICA pIcaSlave;
513 PULONG pDelayIrq;
514 PULONG pUndelayIrq;
515 PULONG pDelayIret;
516 PULONG pIretHooked;
517 PULONG pAddrIretBopTable;
518 PHANDLE phWowIdleEvent;
519 PLARGE_INTEGER pIcaTimeout;
520 PHANDLE phMainThreadSuspended;
521 } VDMICAUSERDATA, *PVDMICAUSERDATA;
522
523 typedef struct _VDM_INITIALIZE_DATA
524 {
525 PVOID TrapcHandler;
526 PVDMICAUSERDATA IcaUserData;
527 } VDM_INITIALIZE_DATA, *PVDM_INITIALIZE_DATA;
528
529 #else
530
531 //
532 // System Thread Start Routine
533 //
534 typedef
535 VOID
536 (NTAPI *PKSYSTEM_ROUTINE)(
537 PKSTART_ROUTINE StartRoutine,
538 PVOID StartContext
539 );
540
541 //
542 // APC Environment Types
543 //
544 typedef enum _KAPC_ENVIRONMENT
545 {
546 OriginalApcEnvironment,
547 AttachedApcEnvironment,
548 CurrentApcEnvironment,
549 InsertApcEnvironment
550 } KAPC_ENVIRONMENT;
551
552 //
553 // PRCB DPC Data
554 //
555 typedef struct _KDPC_DATA
556 {
557 LIST_ENTRY DpcListHead;
558 ULONG_PTR DpcLock;
559 #ifdef _M_AMD64
560 volatile LONG DpcQueueDepth;
561 #else
562 volatile ULONG DpcQueueDepth;
563 #endif
564 ULONG DpcCount;
565 } KDPC_DATA, *PKDPC_DATA;
566
567 //
568 // Per-Processor Lookaside List
569 //
570 typedef struct _PP_LOOKASIDE_LIST
571 {
572 struct _GENERAL_LOOKASIDE *P;
573 struct _GENERAL_LOOKASIDE *L;
574 } PP_LOOKASIDE_LIST, *PPP_LOOKASIDE_LIST;
575
576 //
577 // Architectural Types
578 //
579 #include <arch/ketypes.h>
580
581 //
582 // Kernel Memory Node
583 //
584 #include <pshpack1.h>
585 typedef struct _KNODE
586 {
587 SLIST_HEADER DeadStackList;
588 SLIST_HEADER PfnDereferenceSListHead;
589 KAFFINITY ProcessorMask;
590 ULONG Color;
591 UCHAR Seed;
592 UCHAR NodeNumber;
593 ULONG Flags;
594 ULONG MmShiftedColor;
595 ULONG FreeCount[2];
596 struct _SINGLE_LIST_ENTRY *PfnDeferredList;
597 } KNODE, *PKNODE;
598 #include <poppack.h>
599
600 //
601 // Kernel Profile Object
602 //
603 typedef struct _KPROFILE
604 {
605 CSHORT Type;
606 CSHORT Size;
607 LIST_ENTRY ProfileListEntry;
608 struct _KPROCESS *Process;
609 PVOID RangeBase;
610 PVOID RangeLimit;
611 ULONG BucketShift;
612 PVOID Buffer;
613 ULONG_PTR Segment;
614 KAFFINITY Affinity;
615 KPROFILE_SOURCE Source;
616 BOOLEAN Started;
617 } KPROFILE, *PKPROFILE;
618
619 //
620 // Kernel Interrupt Object
621 //
622 typedef struct _KINTERRUPT
623 {
624 CSHORT Type;
625 CSHORT Size;
626 LIST_ENTRY InterruptListEntry;
627 PKSERVICE_ROUTINE ServiceRoutine;
628 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
629 PKSERVICE_ROUTINE MessageServiceRoutine;
630 ULONG MessageIndex;
631 #endif
632 PVOID ServiceContext;
633 KSPIN_LOCK SpinLock;
634 ULONG TickCount;
635 PKSPIN_LOCK ActualLock;
636 PKINTERRUPT_ROUTINE DispatchAddress;
637 ULONG Vector;
638 KIRQL Irql;
639 KIRQL SynchronizeIrql;
640 BOOLEAN FloatingSave;
641 BOOLEAN Connected;
642 CCHAR Number;
643 BOOLEAN ShareVector;
644 KINTERRUPT_MODE Mode;
645 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
646 KINTERRUPT_POLARITY Polarity;
647 #endif
648 ULONG ServiceCount;
649 ULONG DispatchCount;
650 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
651 ULONGLONG Rsvd1;
652 #endif
653 #ifdef _M_AMD64
654 PKTRAP_FRAME TrapFrame;
655 PVOID Reserved;
656 #endif
657 ULONG DispatchCode[DISPATCH_LENGTH];
658 } KINTERRUPT;
659
660 //
661 // Kernel Event Pair Object
662 //
663 typedef struct _KEVENT_PAIR
664 {
665 CSHORT Type;
666 CSHORT Size;
667 KEVENT LowEvent;
668 KEVENT HighEvent;
669 } KEVENT_PAIR, *PKEVENT_PAIR;
670
671 //
672 // Kernel No Execute Options
673 //
674 typedef struct _KEXECUTE_OPTIONS
675 {
676 UCHAR ExecuteDisable:1;
677 UCHAR ExecuteEnable:1;
678 UCHAR DisableThunkEmulation:1;
679 UCHAR Permanent:1;
680 UCHAR ExecuteDispatchEnable:1;
681 UCHAR ImageDispatchEnable:1;
682 UCHAR Spare:2;
683 } KEXECUTE_OPTIONS, *PKEXECUTE_OPTIONS;
684
685 #if (NTDDI_VERSION >= NTDDI_WIN7)
686 typedef union _KWAIT_STATUS_REGISTER
687 {
688 UCHAR Flags;
689 struct
690 {
691 UCHAR State:2;
692 UCHAR Affinity:1;
693 UCHAR Priority:1;
694 UCHAR Apc:1;
695 UCHAR UserApc:1;
696 UCHAR Alert:1;
697 UCHAR Unused:1;
698 };
699 } KWAIT_STATUS_REGISTER, *PKWAIT_STATUS_REGISTER;
700
701 typedef struct _COUNTER_READING
702 {
703 enum _HARDWARE_COUNTER_TYPE Type;
704 ULONG Index;
705 ULONG64 Start;
706 ULONG64 Total;
707 }COUNTER_READING, *PCOUNTER_READING;
708
709 typedef struct _KTHREAD_COUNTERS
710 {
711 ULONG64 WaitReasonBitMap;
712 struct _THREAD_PERFORMANCE_DATA* UserData;
713 ULONG Flags;
714 ULONG ContextSwitches;
715 ULONG64 CycleTimeBias;
716 ULONG64 HardwareCounters;
717 COUNTER_READING HwCounter[16];
718 }KTHREAD_COUNTERS, *PKTHREAD_COUNTERS;
719 #endif
720
721 //
722 // Kernel Thread (KTHREAD)
723 //
724 typedef struct _KTHREAD
725 {
726 DISPATCHER_HEADER Header;
727 #if (NTDDI_VERSION >= NTDDI_LONGHORN) // [
728 ULONGLONG CycleTime;
729 #ifndef _WIN64 // [
730 ULONG HighCycleTime;
731 #endif // ]
732 ULONGLONG QuantumTarget;
733 #else // ][
734 LIST_ENTRY MutantListHead;
735 #endif // ]
736 PVOID InitialStack;
737 ULONG_PTR StackLimit; // FIXME: PVOID
738 PVOID KernelStack;
739 KSPIN_LOCK ThreadLock;
740 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
741 KWAIT_STATUS_REGISTER WaitRegister;
742 BOOLEAN Running;
743 BOOLEAN Alerted[2];
744 union
745 {
746 struct
747 {
748 ULONG KernelStackResident:1;
749 ULONG ReadyTransition:1;
750 ULONG ProcessReadyQueue:1;
751 ULONG WaitNext:1;
752 ULONG SystemAffinityActive:1;
753 ULONG Alertable:1;
754 ULONG GdiFlushActive:1;
755 ULONG UserStackWalkActive:1;
756 ULONG ApcInterruptRequest:1;
757 ULONG ForceDeferSchedule:1;
758 ULONG QuantumEndMigrate:1;
759 ULONG UmsDirectedSwitchEnable:1;
760 ULONG TimerActive:1;
761 ULONG Reserved:19;
762 };
763 LONG MiscFlags;
764 };
765 #endif // ]
766 union
767 {
768 KAPC_STATE ApcState;
769 struct
770 {
771 UCHAR ApcStateFill[FIELD_OFFSET(KAPC_STATE, UserApcPending) + 1];
772 #if (NTDDI_VERSION >= NTDDI_LONGHORN) // [
773 SCHAR Priority;
774 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
775 /* On x86, the following members "fall out" of the union */
776 volatile ULONG NextProcessor;
777 volatile ULONG DeferredProcessor;
778 #else // ][
779 /* On x86, the following members "fall out" of the union */
780 volatile USHORT NextProcessor;
781 volatile USHORT DeferredProcessor;
782 #endif // ]
783 #else // ][
784 UCHAR ApcQueueable;
785 /* On x86, the following members "fall out" of the union */
786 volatile UCHAR NextProcessor;
787 volatile UCHAR DeferredProcessor;
788 UCHAR AdjustReason;
789 SCHAR AdjustIncrement;
790 #endif // ]
791 };
792 };
793 KSPIN_LOCK ApcQueueLock;
794 #ifndef _M_AMD64 // [
795 ULONG ContextSwitches;
796 volatile UCHAR State;
797 UCHAR NpxState;
798 KIRQL WaitIrql;
799 KPROCESSOR_MODE WaitMode;
800 #endif // ]
801 LONG_PTR WaitStatus;
802 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
803 PKWAIT_BLOCK WaitBlockList;
804 #else // ][
805 union
806 {
807 PKWAIT_BLOCK WaitBlockList;
808 PKGATE GateObject;
809 };
810 #if (NTDDI_VERSION >= NTDDI_LONGHORN) // [
811 union
812 {
813 struct
814 {
815 ULONG KernelStackResident:1;
816 ULONG ReadyTransition:1;
817 ULONG ProcessReadyQueue:1;
818 ULONG WaitNext:1;
819 ULONG SystemAffinityActive:1;
820 ULONG Alertable:1;
821 ULONG GdiFlushActive:1;
822 ULONG Reserved:25;
823 };
824 LONG MiscFlags;
825 };
826 #else // ][
827 BOOLEAN Alertable;
828 BOOLEAN WaitNext;
829 #endif // ]
830 UCHAR WaitReason;
831 #if (NTDDI_VERSION < NTDDI_LONGHORN)
832 SCHAR Priority;
833 BOOLEAN EnableStackSwap;
834 #endif // ]
835 volatile UCHAR SwapBusy;
836 BOOLEAN Alerted[MaximumMode];
837 #endif // ]
838 union
839 {
840 LIST_ENTRY WaitListEntry;
841 SINGLE_LIST_ENTRY SwapListEntry;
842 };
843 PKQUEUE Queue;
844 #ifndef _M_AMD64 // [
845 ULONG WaitTime;
846 union
847 {
848 struct
849 {
850 SHORT KernelApcDisable;
851 SHORT SpecialApcDisable;
852 };
853 ULONG CombinedApcDisable;
854 };
855 #endif // ]
856 struct _TEB *Teb;
857
858 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
859 KTIMER Timer;
860 #else // ][
861 union
862 {
863 KTIMER Timer;
864 struct
865 {
866 UCHAR TimerFill[FIELD_OFFSET(KTIMER, Period) + sizeof(LONG)];
867 #if !defined(_WIN64) // [
868 };
869 };
870 #endif // ]
871 #endif // ]
872 union
873 {
874 struct
875 {
876 ULONG AutoAlignment:1;
877 ULONG DisableBoost:1;
878 #if (NTDDI_VERSION >= NTDDI_LONGHORN) // [
879 ULONG EtwStackTraceApc1Inserted:1;
880 ULONG EtwStackTraceApc2Inserted:1;
881 ULONG CycleChargePending:1;
882 ULONG CalloutActive:1;
883 ULONG ApcQueueable:1;
884 ULONG EnableStackSwap:1;
885 ULONG GuiThread:1;
886 ULONG ReservedFlags:23;
887 #else // ][
888 LONG ReservedFlags:30;
889 #endif // ]
890 };
891 LONG ThreadFlags;
892 };
893 #if defined(_WIN64) && (NTDDI_VERSION < NTDDI_WIN7) // [
894 };
895 };
896 #endif // ]
897 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
898 #if defined(_WIN64) // [
899 ULONG Spare0;
900 #else // ][
901 PVOID ServiceTable;
902 #endif // ]
903 #endif // ]
904 union
905 {
906 DECLSPEC_ALIGN(8) KWAIT_BLOCK WaitBlock[THREAD_WAIT_OBJECTS + 1];
907 #if (NTDDI_VERSION < NTDDI_WIN7) // [
908 struct
909 {
910 UCHAR WaitBlockFill0[FIELD_OFFSET(KWAIT_BLOCK, SpareByte)]; // 32bit = 23, 64bit = 43
911 #if (NTDDI_VERSION >= NTDDI_LONGHORN) // [
912 UCHAR IdealProcessor;
913 #else // ][
914 BOOLEAN SystemAffinityActive;
915 #endif // ]
916 };
917 struct
918 {
919 UCHAR WaitBlockFill1[1 * sizeof(KWAIT_BLOCK) + FIELD_OFFSET(KWAIT_BLOCK, SpareByte)]; // 47 / 91
920 CCHAR PreviousMode;
921 };
922 struct
923 {
924 UCHAR WaitBlockFill2[2 * sizeof(KWAIT_BLOCK) + FIELD_OFFSET(KWAIT_BLOCK, SpareByte)]; // 71 / 139
925 UCHAR ResourceIndex;
926 };
927 struct
928 {
929 UCHAR WaitBlockFill3[3 * sizeof(KWAIT_BLOCK) + FIELD_OFFSET(KWAIT_BLOCK, SpareByte)]; // 95 / 187
930 UCHAR LargeStack;
931 };
932 #endif // ]
933 #ifdef _M_AMD64 // [
934 struct
935 {
936 UCHAR WaitBlockFill4[FIELD_OFFSET(KWAIT_BLOCK, SpareLong)];
937 ULONG ContextSwitches;
938 };
939 struct
940 {
941 UCHAR WaitBlockFill5[1 * sizeof(KWAIT_BLOCK) + FIELD_OFFSET(KWAIT_BLOCK, SpareLong)];
942 UCHAR State;
943 UCHAR NpxState;
944 UCHAR WaitIrql;
945 CHAR WaitMode;
946 };
947 struct
948 {
949 UCHAR WaitBlockFill6[2 * sizeof(KWAIT_BLOCK) + FIELD_OFFSET(KWAIT_BLOCK, SpareLong)];
950 ULONG WaitTime;
951 };
952 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
953 struct
954 {
955 UCHAR WaitBlockFill7[168];
956 PVOID TebMappedLowVa;
957 struct _UMS_CONTROL_BLOCK* Ucb;
958 };
959 #endif // ]
960 struct
961 {
962 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
963 UCHAR WaitBlockFill8[188];
964 #else // ][
965 UCHAR WaitBlockFill7[3 * sizeof(KWAIT_BLOCK) + FIELD_OFFSET(KWAIT_BLOCK, SpareLong)];
966 #endif // ]
967 union
968 {
969 struct
970 {
971 SHORT KernelApcDisable;
972 SHORT SpecialApcDisable;
973 };
974 ULONG CombinedApcDisable;
975 };
976 };
977 #endif // ]
978 };
979 LIST_ENTRY QueueListEntry;
980 PKTRAP_FRAME TrapFrame;
981 #if (NTDDI_VERSION >= NTDDI_LONGHORN) // [
982 PVOID FirstArgument;
983 union // 2 elements, 0x8 bytes (sizeof)
984 {
985 PVOID CallbackStack;
986 ULONG_PTR CallbackDepth;
987 };
988 #else // ][
989 PVOID CallbackStack;
990 #endif // ]
991 #if (NTDDI_VERSION < NTDDI_LONGHORN) || ((NTDDI_VERSION < NTDDI_WIN7) && !defined(_WIN64)) // [
992 PVOID ServiceTable;
993 #endif // ]
994 #if (NTDDI_VERSION < NTDDI_LONGHORN) && defined(_WIN64) // [
995 ULONG KernelLimit;
996 #endif // ]
997 UCHAR ApcStateIndex;
998 #if (NTDDI_VERSION < NTDDI_LONGHORN) // [
999 UCHAR IdealProcessor;
1000 BOOLEAN Preempted;
1001 BOOLEAN ProcessReadyQueue;
1002 #ifdef _WIN64 // [
1003 PVOID Win32kTable;
1004 ULONG Win32kLimit;
1005 #endif // ]
1006 BOOLEAN KernelStackResident;
1007 #endif // ]
1008 SCHAR BasePriority;
1009 SCHAR PriorityDecrement;
1010 #if (NTDDI_VERSION >= NTDDI_LONGHORN) // [
1011 BOOLEAN Preempted;
1012 UCHAR AdjustReason;
1013 CHAR AdjustIncrement;
1014 #if (NTDDI_VERSION >= NTDDI_WIN7)
1015 UCHAR PreviousMode;
1016 #else
1017 UCHAR Spare01;
1018 #endif
1019 #endif // ]
1020 CHAR Saturation;
1021 #if (NTDDI_VERSION >= NTDDI_LONGHORN) // [
1022 ULONG SystemCallNumber;
1023 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
1024 ULONG FreezeCount;
1025 #else // ][
1026 ULONG Spare02;
1027 #endif // ]
1028 #endif // ]
1029 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
1030 GROUP_AFFINITY UserAffinity;
1031 struct _KPROCESS *Process;
1032 GROUP_AFFINITY Affinity;
1033 ULONG IdealProcessor;
1034 ULONG UserIdealProcessor;
1035 #else // ][
1036 KAFFINITY UserAffinity;
1037 struct _KPROCESS *Process;
1038 KAFFINITY Affinity;
1039 #endif // ]
1040 PKAPC_STATE ApcStatePointer[2];
1041 union
1042 {
1043 KAPC_STATE SavedApcState;
1044 struct
1045 {
1046 UCHAR SavedApcStateFill[FIELD_OFFSET(KAPC_STATE, UserApcPending) + 1];
1047 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
1048 UCHAR WaitReason;
1049 #else // ][
1050 CCHAR FreezeCount;
1051 #endif // ]
1052 #ifndef _WIN64 // [
1053 };
1054 };
1055 #endif // ]
1056 CCHAR SuspendCount;
1057 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
1058 CCHAR Spare1;
1059 #else // ][
1060 UCHAR UserIdealProcessor;
1061 #endif // ]
1062 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
1063 #elif (NTDDI_VERSION >= NTDDI_LONGHORN) // ][
1064 UCHAR Spare03;
1065 #else // ][
1066 UCHAR CalloutActive;
1067 #endif // ]
1068 #ifdef _WIN64 // [
1069 UCHAR CodePatchInProgress;
1070 };
1071 };
1072 #endif // ]
1073 #if defined(_M_IX86) // [
1074 #if (NTDDI_VERSION >= NTDDI_LONGHORN) // [
1075 UCHAR OtherPlatformFill;
1076 #else // ][
1077 UCHAR Iopl;
1078 #endif // ]
1079 #endif // ]
1080 PVOID Win32Thread;
1081 PVOID StackBase;
1082 union
1083 {
1084 KAPC SuspendApc;
1085 struct
1086 {
1087 UCHAR SuspendApcFill0[1];
1088 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
1089 UCHAR ResourceIndex;
1090 #elif (NTDDI_VERSION >= NTDDI_LONGHORN) // ][
1091 CHAR Spare04;
1092 #else // ][
1093 SCHAR Quantum;
1094 #endif // ]
1095 };
1096 struct
1097 {
1098 UCHAR SuspendApcFill1[3];
1099 UCHAR QuantumReset;
1100 };
1101 struct
1102 {
1103 UCHAR SuspendApcFill2[4];
1104 ULONG KernelTime;
1105 };
1106 struct
1107 {
1108 UCHAR SuspendApcFill3[FIELD_OFFSET(KAPC, SystemArgument1)];
1109 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1110 PKPRCB WaitPrcb;
1111 #else
1112 PVOID TlsArray;
1113 #endif
1114 };
1115 struct
1116 {
1117 UCHAR SuspendApcFill4[FIELD_OFFSET(KAPC, SystemArgument2)]; // 40 / 72
1118 PVOID LegoData;
1119 };
1120 struct
1121 {
1122 UCHAR SuspendApcFill5[FIELD_OFFSET(KAPC, Inserted) + 1]; // 47 / 83
1123 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
1124 UCHAR LargeStack;
1125 #else // ][
1126 UCHAR PowerState;
1127 #endif // ]
1128 #ifdef _WIN64 // [
1129 ULONG UserTime;
1130 #endif // ]
1131 };
1132 };
1133 #ifndef _WIN64 // [
1134 ULONG UserTime;
1135 #endif // ]
1136 union
1137 {
1138 KSEMAPHORE SuspendSemaphore;
1139 struct
1140 {
1141 UCHAR SuspendSemaphorefill[FIELD_OFFSET(KSEMAPHORE, Limit) + 4]; // 20 / 28
1142 #ifdef _WIN64 // [
1143 ULONG SListFaultCount;
1144 #endif // ]
1145 };
1146 };
1147 #ifndef _WIN64 // [
1148 ULONG SListFaultCount;
1149 #endif // ]
1150 LIST_ENTRY ThreadListEntry;
1151 #if (NTDDI_VERSION >= NTDDI_LONGHORN) // [
1152 LIST_ENTRY MutantListHead;
1153 #endif // ]
1154 PVOID SListFaultAddress;
1155 #ifdef _M_AMD64 // [
1156 LONG64 ReadOperationCount;
1157 LONG64 WriteOperationCount;
1158 LONG64 OtherOperationCount;
1159 LONG64 ReadTransferCount;
1160 LONG64 WriteTransferCount;
1161 LONG64 OtherTransferCount;
1162 #endif // ]
1163 #if (NTDDI_VERSION >= NTDDI_WIN7) // [
1164 PKTHREAD_COUNTERS ThreadCounters;
1165 PXSTATE_SAVE XStateSave;
1166 #elif (NTDDI_VERSION >= NTDDI_LONGHORN) // ][
1167 PVOID MdlForLockedTeb;
1168 #endif // ]
1169 } KTHREAD;
1170
1171 #define ASSERT_THREAD(object) \
1172 ASSERT((((object)->Header.Type & KOBJECT_TYPE_MASK) == ThreadObject))
1173
1174 //
1175 // Kernel Process (KPROCESS)
1176 //
1177 typedef struct _KPROCESS
1178 {
1179 DISPATCHER_HEADER Header;
1180 LIST_ENTRY ProfileListHead;
1181 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1182 ULONG_PTR DirectoryTableBase;
1183 ULONG Unused0;
1184 #else
1185 ULONG_PTR DirectoryTableBase[2];
1186 #endif
1187 #if defined(_M_IX86)
1188 KGDTENTRY LdtDescriptor;
1189 KIDTENTRY Int21Descriptor;
1190 #endif
1191 USHORT IopmOffset;
1192 #if defined(_M_IX86)
1193 UCHAR Iopl;
1194 UCHAR Unused;
1195 #endif
1196 volatile ULONG ActiveProcessors;
1197 ULONG KernelTime;
1198 ULONG UserTime;
1199 LIST_ENTRY ReadyListHead;
1200 SINGLE_LIST_ENTRY SwapListEntry;
1201 PVOID VdmTrapcHandler;
1202 LIST_ENTRY ThreadListHead;
1203 KSPIN_LOCK ProcessLock;
1204 KAFFINITY Affinity;
1205 union
1206 {
1207 struct
1208 {
1209 LONG AutoAlignment:1;
1210 LONG DisableBoost:1;
1211 LONG DisableQuantum:1;
1212 LONG ReservedFlags:29;
1213 };
1214 LONG ProcessFlags;
1215 };
1216 SCHAR BasePriority;
1217 SCHAR QuantumReset;
1218 UCHAR State;
1219 UCHAR ThreadSeed;
1220 UCHAR PowerState;
1221 UCHAR IdealNode;
1222 UCHAR Visited;
1223 union
1224 {
1225 KEXECUTE_OPTIONS Flags;
1226 UCHAR ExecuteOptions;
1227 };
1228 ULONG StackCount;
1229 LIST_ENTRY ProcessListEntry;
1230 #if (NTDDI_VERSION >= NTDDI_LONGHORN) // [
1231 ULONGLONG CycleTime;
1232 #endif // ]
1233 } KPROCESS;
1234
1235 #define ASSERT_PROCESS(object) \
1236 ASSERT((((object)->Header.Type & KOBJECT_TYPE_MASK) == ProcessObject))
1237
1238 //
1239 // System Service Table Descriptor
1240 //
1241 typedef struct _KSERVICE_TABLE_DESCRIPTOR
1242 {
1243 PULONG_PTR Base;
1244 PULONG Count;
1245 ULONG Limit;
1246 #if defined(_IA64_)
1247 LONG TableBaseGpOffset;
1248 #endif
1249 PUCHAR Number;
1250 } KSERVICE_TABLE_DESCRIPTOR, *PKSERVICE_TABLE_DESCRIPTOR;
1251
1252 //
1253 // Exported Loader Parameter Block
1254 //
1255 extern struct _LOADER_PARAMETER_BLOCK NTSYSAPI *KeLoaderBlock;
1256
1257 //
1258 // Exported Hardware Data
1259 //
1260 extern KAFFINITY NTSYSAPI KeActiveProcessors;
1261 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1262 extern volatile CCHAR NTSYSAPI KeNumberProcessors;
1263 #else
1264 #if (NTDDI_VERSION >= NTDDI_WINXP)
1265 extern CCHAR NTSYSAPI KeNumberProcessors;
1266 #else
1267 //extern PCCHAR KeNumberProcessors;
1268 extern NTSYSAPI CCHAR KeNumberProcessors; //FIXME: Note to Alex: I won't fix this atm, since I prefer to discuss this with you first.
1269 #endif
1270 #endif
1271 extern ULONG NTSYSAPI KiDmaIoCoherency;
1272 extern ULONG NTSYSAPI KeMaximumIncrement;
1273 extern ULONG NTSYSAPI KeMinimumIncrement;
1274 extern ULONG NTSYSAPI KeDcacheFlushCount;
1275 extern ULONG NTSYSAPI KeIcacheFlushCount;
1276 extern ULONG_PTR NTSYSAPI KiBugCheckData[];
1277 extern BOOLEAN NTSYSAPI KiEnableTimerWatchdog;
1278
1279 //
1280 // Exported System Service Descriptor Tables
1281 //
1282 extern KSERVICE_TABLE_DESCRIPTOR NTSYSAPI KeServiceDescriptorTable[SSDT_MAX_ENTRIES];
1283 extern KSERVICE_TABLE_DESCRIPTOR NTSYSAPI KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES];
1284
1285 #endif // !NTOS_MODE_USER
1286
1287 #endif // _KETYPES_H