3 Copyright (c) Alex Ionescu. All rights reserved.
11 Type definitions for the Loader.
15 Alex Ionescu (alexi@tinykrnl.org) - Updated - 27-Feb-2006
26 #ifndef NTOS_MODE_USER
33 // Context Record Flags
35 #define CONTEXT_DEBUGGER (CONTEXT_FULL | CONTEXT_FLOATING_POINT)
38 // Maximum System Descriptor Table Entries
40 #define SSDT_MAX_ENTRIES 2
43 // Dispatcher Priority increments
45 #define THREAD_ALERT_INCREMENT 2
48 // User Shared Data in Kernel-Mode
50 #define KI_USER_SHARED_DATA 0xffdf0000
53 // Physical memory offset of KUSER_SHARED_DATA
55 #define KI_USER_SHARED_DATA_PHYSICAL 0x41000
58 // Kernel Feature Bits
60 #define KF_RDTSC 0x00000002
63 // KPCR Access for non-IA64 builds
65 #define K0IPCR ((ULONG_PTR)(KIP0PCRADDRESS))
66 #define PCR ((volatile KPCR * const)K0IPCR)
67 #define KeGetPcr() PCR
70 // Number of dispatch codes supported by KINTERRUPT
72 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
73 #define KINTERRUPT_DISPATCH_CODES 135
75 #define KINTERRUPT_DISPATCH_CODES 106
81 // KPROCESSOR_MODE Type
83 typedef CCHAR KPROCESSOR_MODE
;
86 // Dereferencable pointer to KUSER_SHARED_DATA in User-Mode
88 #define SharedUserData ((KUSER_SHARED_DATA *CONST)USER_SHARED_DATA)
91 // Maximum WOW64 Entries in KUSER_SHARED_DATA
93 #define MAX_WOW64_SHARED_ENTRIES 16
96 // Maximum Processor Features supported in KUSER_SHARED_DATA
98 #define PROCESSOR_FEATURE_MAX 64
103 typedef enum _EVENT_TYPE
112 typedef enum _TIMER_TYPE
121 typedef enum _WAIT_TYPE
128 // Processor Execution Modes
140 typedef enum _KWAIT_REASON
182 typedef enum _KPROFILE_SOURCE
185 ProfileAlignmentFixup
,
188 ProfileLoadInstructions
,
189 ProfilePipelineFrozen
,
190 ProfileBranchInstructions
,
191 ProfileTotalNonissues
,
195 ProfileBranchMispredictions
,
196 ProfileStoreInstructions
,
197 ProfileFpInstructions
,
198 ProfileIntegerInstructions
,
202 ProfileSpecialInstructions
,
205 ProfileDcacheAccesses
,
206 ProfileMemoryBarrierCycles
,
207 ProfileLoadLinkedIssues
,
212 // NT Product and Architecture Types
214 typedef enum _NT_PRODUCT_TYPE
219 } NT_PRODUCT_TYPE
, *PNT_PRODUCT_TYPE
;
221 typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE
226 } ALTERNATIVE_ARCHITECTURE_TYPE
;
233 typedef enum _KTHREAD_STATE
243 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
246 } KTHREAD_STATE
, *PKTHREAD_STATE
;
251 typedef enum _KPROCESS_STATE
258 } KPROCESS_STATE
, *PKPROCESS_STATE
;
261 // NtVdmControl Classes
263 typedef enum _VDMSERVICECLASS
265 VdmStartExecution
= 0,
266 VdmQueueInterrupt
= 1,
267 VdmDelayInterrupt
= 2,
270 VdmSetInt21Handler
= 5,
272 VdmPrinterDirectIoOpen
= 7,
273 VdmPrinterDirectIoClose
= 8,
274 VdmPrinterInitialize
= 9,
275 VdmSetLdtEntries
= 10,
276 VdmSetProcessLdtInfo
= 11,
277 VdmAdlibEmulation
= 12,
278 VdmPMCliControl
= 13,
279 VdmQueryVdmProcess
= 14,
282 #ifdef NTOS_MODE_USER
285 // APC Normal Routine
288 (NTAPI
*PKNORMAL_ROUTINE
)(
289 IN PVOID NormalContext
,
290 IN PVOID SystemArgument1
,
291 IN PVOID SystemArgument2
298 (NTAPI
*PTIMER_APC_ROUTINE
)(
299 IN PVOID TimerContext
,
300 IN ULONG TimerLowValue
,
301 IN LONG TimerHighValue
305 // System Time Structure
307 typedef struct _KSYSTEM_TIME
312 } KSYSTEM_TIME
, *PKSYSTEM_TIME
;
315 // Shared Kernel User Data
317 typedef struct _KUSER_SHARED_DATA
319 ULONG TickCountLowDeprecated
;
320 ULONG TickCountMultiplier
;
321 volatile KSYSTEM_TIME InterruptTime
;
322 volatile KSYSTEM_TIME SystemTime
;
323 volatile KSYSTEM_TIME TimeZoneBias
;
324 USHORT ImageNumberLow
;
325 USHORT ImageNumberHigh
;
326 WCHAR NtSystemRoot
[260];
327 ULONG MaxStackTraceDepth
;
328 ULONG CryptoExponent
;
330 ULONG LargePageMinimum
;
332 NT_PRODUCT_TYPE NtProductType
;
333 BOOLEAN ProductTypeIsValid
;
334 ULONG NtMajorVersion
;
335 ULONG NtMinorVersion
;
336 BOOLEAN ProcessorFeatures
[PROCESSOR_FEATURE_MAX
];
339 volatile ULONG TimeSlip
;
340 ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture
;
341 LARGE_INTEGER SystemExpirationDate
;
343 BOOLEAN KdDebuggerEnabled
;
344 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
345 UCHAR NXSupportPolicy
;
347 volatile ULONG ActiveConsoleId
;
348 volatile ULONG DismountCount
;
349 ULONG ComPlusPackage
;
350 ULONG LastSystemRITEventTickCount
;
351 ULONG NumberOfPhysicalPages
;
352 BOOLEAN SafeBootMode
;
355 ULONGLONG TestRetInstruction
;
357 ULONG SystemCallReturn
;
358 ULONGLONG SystemCallPad
[3];
360 volatile KSYSTEM_TIME TickCount
;
361 volatile ULONG64 TickCountQuad
;
364 #if (NTDDI_VERSION >= NTDDI_WS03)
365 LONGLONG ConsoleSessionForegroundProcessId
;
366 ULONG Wow64SharedInformation
[MAX_WOW64_SHARED_ENTRIES
];
368 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
369 USHORT UserModeGlobalLogger
[8];
370 ULONG HeapTracingPid
[2];
371 ULONG CritSecTracingPid
[2];
374 ULONG SharedDataFlags
;
377 ULONG DbgErrorPortPresent
:1;
378 ULONG DbgElevationEnabled
:1;
379 ULONG DbgVirtEnabled
:1;
380 ULONG DbgInstallerDetectEnabled
:1;
384 ULONG ImageFileExecutionOptions
;
385 KAFFINITY ActiveProcessorAffinity
;
387 } KUSER_SHARED_DATA
, *PKUSER_SHARED_DATA
;
392 #include "pshpack1.h"
393 typedef struct _VdmVirtualIca
406 } VDMVIRTUALICA
, *PVDMVIRTUALICA
;
409 typedef struct _VdmIcaUserData
412 PVDMVIRTUALICA pIcaMaster
;
413 PVDMVIRTUALICA pIcaSlave
;
418 PULONG pAddrIretBopTable
;
419 PHANDLE phWowIdleEvent
;
420 PLARGE_INTEGER pIcaTimeout
;
421 PHANDLE phMainThreadSuspended
;
422 } VDMICAUSERDATA
, *PVDMICAUSERDATA
;
424 typedef struct _VDM_INITIALIZE_DATA
427 PVDMICAUSERDATA IcaUserData
;
428 } VDM_INITIALIZE_DATA
, *PVDM_INITIALIZE_DATA
;
433 // System Thread Start Routine
437 (NTAPI
*PKSYSTEM_ROUTINE
)(
438 PKSTART_ROUTINE StartRoutine
,
443 // APC Environment Types
445 typedef enum _KAPC_ENVIRONMENT
447 OriginalApcEnvironment
,
448 AttachedApcEnvironment
,
449 CurrentApcEnvironment
455 typedef enum _PROCESSOR_CACHE_TYPE
461 } PROCESSOR_CACHE_TYPE
;
466 typedef struct _KDPC_DATA
468 LIST_ENTRY DpcListHead
;
472 } KDPC_DATA
, *PKDPC_DATA
;
475 // Per-Processor Lookaside List
477 typedef struct _PP_LOOKASIDE_LIST
479 struct _GENERAL_LOOKASIDE
*P
;
480 struct _GENERAL_LOOKASIDE
*L
;
481 } PP_LOOKASIDE_LIST
, *PPP_LOOKASIDE_LIST
;
484 // CPU Cache Descriptor
486 typedef struct _CACHE_DESCRIPTOR
492 PROCESSOR_CACHE_TYPE Type
;
493 } CACHE_DESCRIPTOR
, *PCACHE_DESCRIPTOR
;
496 // Architectural Types
498 #include <arch/ketypes.h>
501 // Kernel Memory Node
503 #include <pshpack1.h>
504 typedef struct _KNODE
506 SLIST_HEADER DeadStackList
;
507 SLIST_HEADER PfnDereferenceSListHead
;
508 KAFFINITY ProcessorMask
;
513 ULONG MmShiftedColor
;
515 struct _SINGLE_LIST_ENTRY
*PfnDeferredList
;
520 // Kernel Profile Object
522 typedef struct _KPROFILE
526 LIST_ENTRY ProfileListEntry
;
527 struct _KPROCESS
*Process
;
534 KPROFILE_SOURCE Source
;
536 } KPROFILE
, *PKPROFILE
;
539 // Kernel Interrupt Object
541 typedef struct _KINTERRUPT
545 LIST_ENTRY InterruptListEntry
;
546 PKSERVICE_ROUTINE ServiceRoutine
;
547 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
548 PKSERVICE_ROUTINE MessageServiceRoutine
;
551 PVOID ServiceContext
;
554 PKSPIN_LOCK ActualLock
;
555 PVOID DispatchAddress
;
558 KIRQL SynchronizeIrql
;
559 BOOLEAN FloatingSave
;
563 KINTERRUPT_MODE Mode
;
564 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
565 KINTERRUPT_POLARITY Polarity
;
569 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
572 ULONG DispatchCode
[KINTERRUPT_DISPATCH_CODES
];
573 } KINTERRUPT
, *PKINTERRUPT
;
576 // Kernel Event Pair Object
578 typedef struct _KEVENT_PAIR
584 } KEVENT_PAIR
, *PKEVENT_PAIR
;
587 // Kernel No Execute Options
589 typedef struct _KEXECUTE_OPTIONS
591 UCHAR ExecuteDisable
:1;
592 UCHAR ExecuteEnable
:1;
593 UCHAR DisableThunkEmulation
:1;
595 UCHAR ExecuteDispatchEnable
:1;
596 UCHAR ImageDispatchEnable
:1;
598 } KEXECUTE_OPTIONS
, *PKEXECUTE_OPTIONS
;
601 // Kernel Object Types
603 typedef enum _KOBJECTS
605 EventNotificationObject
= 0,
606 EventSynchronizationObject
= 1,
613 TimerNotificationObject
= 8,
614 TimerSynchronizationObject
= 9,
625 DeviceQueueObject
= 20,
626 EventPairObject
= 21,
627 InterruptObject
= 22,
629 ThreadedDpcObject
= 24,
630 MaximumKernelObject
= 25
634 // Kernel Thread (KTHREAD)
636 #include <pshpack1.h>
637 typedef struct _KTHREAD
639 DISPATCHER_HEADER DispatcherHeader
;
640 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
644 LIST_ENTRY MutantListHead
;
647 ULONG_PTR StackLimit
;
649 KSPIN_LOCK ThreadLock
;
655 UCHAR ApcStateFill
[23];
660 UCHAR DeferredProcessor
;
662 UCHAR AdjustIncrement
;
663 KSPIN_LOCK ApcQueueLock
;
664 ULONG ContextSwitches
;
672 PKWAIT_BLOCK WaitBlockList
;
679 UCHAR EnableStackSwap
;
684 LIST_ENTRY WaitListEntry
;
685 SINGLE_LIST_ENTRY SwapListEntry
;
693 USHORT KernelApcDisable
;
694 USHORT SpecialApcDisable
;
696 ULONG CombinedApcDisable
;
708 LONG AutoAlignment
:1;
710 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
711 LONG EtwStackTrace1ApcInserted
:1;
712 LONG EtwStackTrace2ApcInserted
:1;
713 LONG CycleChargePending
:1;
714 LONG ReservedFlags
:27;
716 LONG ReservedFlags
:30;
724 KWAIT_BLOCK WaitBlock
[4];
729 UCHAR WaitBlockFill0
[23];
730 UCHAR SystemAffinityActive
;
734 UCHAR WaitBlockFill1
[47];
739 UCHAR WaitBlockFill2
[71];
744 UCHAR WaitBlockFill3
[95];
749 LIST_ENTRY QueueListEntry
;
750 PKTRAP_FRAME TrapFrame
;
751 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
757 UCHAR IdealProcessor
;
759 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
762 UCHAR ProcessReadyQueue
;
764 UCHAR KernelStackResident
;
766 CHAR PriorityDecrement
;
768 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
769 ULONG SystemCallNumber
;
775 ULONG ReadyTransition
:1;
776 ULONG ProcessReadyQueue
:1;
783 KAFFINITY UserAffinity
;
784 struct _KPROCESS
*Process
;
786 PKAPC_STATE ApcStatePointer
[2];
789 KAPC_STATE SavedApcState
;
792 UCHAR SavedApcStateFill
[23];
797 UCHAR UserIdealProcessor
;
798 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
803 UCHAR ReservedBits0
:1;
804 UCHAR SegmentsPresent
:1;
805 UCHAR Reservedbits1
:1;
807 UCHAR NestedStateFlags
;
820 UCHAR SuspendApcFill0
[1];
825 UCHAR SuspendApcFill1
[3];
830 UCHAR SuspendApcFill2
[4];
835 UCHAR SuspendApcFill3
[36];
836 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
844 UCHAR SuspendApcFill4
[40];
849 UCHAR SuspendApcFill5
[47];
856 KSEMAPHORE SuspendSemaphore
;
857 UCHAR SuspendSemaphorefill
[20];
859 ULONG SListFaultCount
;
860 LIST_ENTRY ThreadListEntry
;
861 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
862 LIST_ENTRY MutantListHead
;
864 PVOID SListFaultAddress
;
865 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
866 PVOID MdlForLockedteb
;
872 // Kernel Process (KPROCESS)
874 typedef struct _KPROCESS
876 DISPATCHER_HEADER Header
;
877 LIST_ENTRY ProfileListHead
;
878 PHYSICAL_ADDRESS DirectoryTableBase
;
880 KGDTENTRY LdtDescriptor
;
881 KIDTENTRY Int21Descriptor
;
886 ULONG ActiveProcessors
;
889 LIST_ENTRY ReadyListHead
;
890 SINGLE_LIST_ENTRY SwapListEntry
;
891 PVOID VdmTrapcHandler
;
892 LIST_ENTRY ThreadListHead
;
893 KSPIN_LOCK ProcessLock
;
899 ULONG AutoAlignment
:1;
900 ULONG DisableBoost
:1;
901 ULONG DisableQuantum
:1;
902 ULONG ReservedFlags
:29;
915 KEXECUTE_OPTIONS Flags
;
916 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
917 UCHAR ExecuteOptions
;
921 LIST_ENTRY ProcessListEntry
;
922 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
925 } KPROCESS
, *PKPROCESS
;
928 // System Service Table Descriptor
930 typedef struct _KSERVICE_TABLE_DESCRIPTOR
936 LONG TableBaseGpOffset
;
939 } KSERVICE_TABLE_DESCRIPTOR
, *PKSERVICE_TABLE_DESCRIPTOR
;
942 // Exported Loader Parameter Block
945 extern struct _LOADER_PARAMETER_BLOCK NTSYSAPI
*KeLoaderBlock
;
947 extern struct _ROS_LOADER_PARAMETER_BLOCK NTSYSAPI KeLoaderBlock
;
951 // Exported Hardware Data
953 extern KAFFINITY NTSYSAPI KeActiveProcessors
;
954 extern CHAR NTSYSAPI KeNumberProcessors
;
955 extern ULONG NTSYSAPI KiDmaIoCoherency
;
956 extern ULONG NTSYSAPI KeMaximumIncrement
;
957 extern ULONG NTSYSAPI KeMinimumIncrement
;
958 extern ULONG NTSYSAPI KeDcacheFlushCount
;
959 extern ULONG NTSYSAPI KeIcacheFlushCount
;
962 // Exported System Service Descriptor Tables
964 extern KSERVICE_TABLE_DESCRIPTOR NTSYSAPI KeServiceDescriptorTable
[SSDT_MAX_ENTRIES
];
965 extern KSERVICE_TABLE_DESCRIPTOR NTSYSAPI KeServiceDescriptorTableShadow
[SSDT_MAX_ENTRIES
];
967 #endif // !NTOS_MODE_USER