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