[XDK]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Tue, 23 Mar 2010 20:18:51 +0000 (20:18 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Tue, 23 Mar 2010 20:18:51 +0000 (20:18 +0000)
- add x86/ke.h(mm.h and amd64/mm.h
- cleanup ntddk.template.h, moving stuff into approproate headers

svn path=/branches/header-work/; revision=46364

include/ddk/ntddk.h
include/ddk/wdm.h
include/xdk/amd64/ke.h
include/xdk/amd64/mm.h [new file with mode: 0644]
include/xdk/exfuncs.h
include/xdk/ia64/ke.h
include/xdk/ketypes.h
include/xdk/ntddk.template.h
include/xdk/x86/ke.h
include/xdk/x86/mm.h [new file with mode: 0644]

index 457b407..e67a9c6 100644 (file)
@@ -39,6 +39,7 @@
 #include <excpt.h>
 #include <ntdef.h>
 #include <ntstatus.h>
+#include <mce.h>
 
 /* FIXME
 #include <bugcodes.h>
@@ -92,200 +93,6 @@ typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS;
 
 #endif /* _NTIMAGE_ */
 
-#define PsGetCurrentProcess IoGetCurrentProcess
-
-#if (NTDDI_VERSION >= NTDDI_VISTA)
-extern NTSYSAPI volatile CCHAR KeNumberProcessors;
-#elif (NTDDI_VERSION >= NTDDI_WINXP)
-extern NTSYSAPI CCHAR KeNumberProcessors;
-#else
-extern PCCHAR KeNumberProcessors;
-#endif
-
-#include <mce.h>
-
-#ifdef _X86_
-
-#define KERNEL_STACK_SIZE                   12288
-#define KERNEL_LARGE_STACK_SIZE             61440
-#define KERNEL_LARGE_STACK_COMMIT           12288
-
-#define SIZE_OF_80387_REGISTERS   80
-
-#if !defined(RC_INVOKED)
-
-#define CONTEXT_i386               0x10000
-#define CONTEXT_i486               0x10000
-#define CONTEXT_CONTROL            (CONTEXT_i386|0x00000001L)
-#define CONTEXT_INTEGER            (CONTEXT_i386|0x00000002L)
-#define CONTEXT_SEGMENTS           (CONTEXT_i386|0x00000004L)
-#define CONTEXT_FLOATING_POINT     (CONTEXT_i386|0x00000008L)
-#define CONTEXT_DEBUG_REGISTERS    (CONTEXT_i386|0x00000010L)
-#define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386|0x00000020L)
-
-#define CONTEXT_FULL (CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS)
-#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS |  \
-                     CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS |      \
-                     CONTEXT_EXTENDED_REGISTERS)
-
-#define CONTEXT_XSTATE          (CONTEXT_i386 | 0x00000040L)
-
-#endif /* !defined(RC_INVOKED) */
-
-typedef struct _FLOATING_SAVE_AREA {
-  ULONG ControlWord;
-  ULONG StatusWord;
-  ULONG TagWord;
-  ULONG ErrorOffset;
-  ULONG ErrorSelector;
-  ULONG DataOffset;
-  ULONG DataSelector;
-  UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
-  ULONG Cr0NpxState;
-} FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
-
-#include "pshpack4.h"
-typedef struct _CONTEXT {
-  ULONG ContextFlags;
-  ULONG Dr0;
-  ULONG Dr1;
-  ULONG Dr2;
-  ULONG Dr3;
-  ULONG Dr6;
-  ULONG Dr7;
-  FLOATING_SAVE_AREA FloatSave;
-  ULONG SegGs;
-  ULONG SegFs;
-  ULONG SegEs;
-  ULONG SegDs;
-  ULONG Edi;
-  ULONG Esi;
-  ULONG Ebx;
-  ULONG Edx;
-  ULONG Ecx;
-  ULONG Eax;
-  ULONG Ebp;
-  ULONG Eip;
-  ULONG SegCs;
-  ULONG EFlags;
-  ULONG Esp;
-  ULONG SegSs;
-  UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
-} CONTEXT;
-#include "poppack.h"
-
-#endif /* _X86_ */
-
-#ifdef _AMD64_
-
-#define KERNEL_STACK_SIZE 0x6000
-#define KERNEL_LARGE_STACK_SIZE 0x12000
-#define KERNEL_LARGE_STACK_COMMIT KERNEL_STACK_SIZE
-
-#define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
-
-#define EXCEPTION_READ_FAULT    0
-#define EXCEPTION_WRITE_FAULT   1
-#define EXCEPTION_EXECUTE_FAULT 8
-
-#if !defined(RC_INVOKED)
-
-#define CONTEXT_AMD64 0x100000
-
-#define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
-#define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
-#define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
-#define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
-#define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
-
-#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
-#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
-
-#define CONTEXT_XSTATE (CONTEXT_AMD64 | 0x20L)
-
-#define CONTEXT_EXCEPTION_ACTIVE 0x8000000
-#define CONTEXT_SERVICE_ACTIVE 0x10000000
-#define CONTEXT_EXCEPTION_REQUEST 0x40000000
-#define CONTEXT_EXCEPTION_REPORTING 0x80000000
-
-#endif /* !defined(RC_INVOKED) */
-
-#define INITIAL_MXCSR                  0x1f80
-#define INITIAL_FPCSR                  0x027f
-
-typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
-  ULONG64 P1Home;
-  ULONG64 P2Home;
-  ULONG64 P3Home;
-  ULONG64 P4Home;
-  ULONG64 P5Home;
-  ULONG64 P6Home;
-  ULONG ContextFlags;
-  ULONG MxCsr;
-  USHORT SegCs;
-  USHORT SegDs;
-  USHORT SegEs;
-  USHORT SegFs;
-  USHORT SegGs;
-  USHORT SegSs;
-  ULONG EFlags;
-  ULONG64 Dr0;
-  ULONG64 Dr1;
-  ULONG64 Dr2;
-  ULONG64 Dr3;
-  ULONG64 Dr6;
-  ULONG64 Dr7;
-  ULONG64 Rax;
-  ULONG64 Rcx;
-  ULONG64 Rdx;
-  ULONG64 Rbx;
-  ULONG64 Rsp;
-  ULONG64 Rbp;
-  ULONG64 Rsi;
-  ULONG64 Rdi;
-  ULONG64 R8;
-  ULONG64 R9;
-  ULONG64 R10;
-  ULONG64 R11;
-  ULONG64 R12;
-  ULONG64 R13;
-  ULONG64 R14;
-  ULONG64 R15;
-  ULONG64 Rip;
-  union {
-    XMM_SAVE_AREA32 FltSave;
-    struct {
-      M128A Header[2];
-      M128A Legacy[8];
-      M128A Xmm0;
-      M128A Xmm1;
-      M128A Xmm2;
-      M128A Xmm3;
-      M128A Xmm4;
-      M128A Xmm5;
-      M128A Xmm6;
-      M128A Xmm7;
-      M128A Xmm8;
-      M128A Xmm9;
-      M128A Xmm10;
-      M128A Xmm11;
-      M128A Xmm12;
-      M128A Xmm13;
-      M128A Xmm14;
-      M128A Xmm15;
-    } DUMMYSTRUCTNAME;
-  } DUMMYUNIONNAME;
-  M128A VectorRegister[26];
-  ULONG64 VectorControl;
-  ULONG64 DebugControl;
-  ULONG64 LastBranchToRip;
-  ULONG64 LastBranchFromRip;
-  ULONG64 LastExceptionToRip;
-  ULONG64 LastExceptionFromRip;
-} CONTEXT;
-
-#endif /* _AMD64_ */
-
 /******************************************************************************
  *                            Executive Types                                 *
  ******************************************************************************/
@@ -2041,71 +1848,195 @@ typedef struct _XSTATE_CONFIGURATION {
   XSTATE_FEATURE Features[MAXIMUM_XSTATE_FEATURES];
 } XSTATE_CONFIGURATION, *PXSTATE_CONFIGURATION;
 
+#define MAX_WOW64_SHARED_ENTRIES 16
 
-/******************************************************************************
- *                          Kernel Debugger Types                             *
- ******************************************************************************/
-typedef struct _DEBUG_DEVICE_ADDRESS {
-  UCHAR Type;
-  BOOLEAN Valid;
-  UCHAR Reserved[2];
-  PUCHAR TranslatedAddress;
-  ULONG Length;
-} DEBUG_DEVICE_ADDRESS, *PDEBUG_DEVICE_ADDRESS;
-
-typedef struct _DEBUG_MEMORY_REQUIREMENTS {
-  PHYSICAL_ADDRESS Start;
-  PHYSICAL_ADDRESS MaxEnd;
-  PVOID VirtualAddress;
-  ULONG Length;
-  BOOLEAN Cached;
-  BOOLEAN Aligned;
-} DEBUG_MEMORY_REQUIREMENTS, *PDEBUG_MEMORY_REQUIREMENTS;
-
-typedef struct _DEBUG_DEVICE_DESCRIPTOR {
-  ULONG Bus;
-  ULONG Slot;
-  USHORT Segment;
-  USHORT VendorID;
-  USHORT DeviceID;
-  UCHAR BaseClass;
-  UCHAR SubClass;
-  UCHAR ProgIf;
-  BOOLEAN Initialized;
-  BOOLEAN Configured;
-  DEBUG_DEVICE_ADDRESS BaseAddress[6];
-  DEBUG_MEMORY_REQUIREMENTS Memory;
-} DEBUG_DEVICE_DESCRIPTOR, *PDEBUG_DEVICE_DESCRIPTOR;
-
-typedef NTSTATUS
-(NTAPI *pKdSetupPciDeviceForDebugging)(
-  IN PVOID LoaderBlock OPTIONAL,
-  IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice);
-
-typedef NTSTATUS
-(NTAPI *pKdReleasePciDeviceForDebugging)(
-  IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice);
-
-typedef PVOID
-(NTAPI *pKdGetAcpiTablePhase0)(
-  IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
-  IN ULONG Signature);
-
-typedef VOID
-(NTAPI *pKdCheckPowerButton)(
-  VOID);
-
-#if (NTDDI_VERSION >= NTDDI_VISTA)
-typedef PVOID
-(NTAPI *pKdMapPhysicalMemory64)(
-  IN PHYSICAL_ADDRESS PhysicalAddress,
-  IN ULONG NumberPages,
-  IN BOOLEAN FlushCurrentTLB);
-
-typedef VOID
-(NTAPI *pKdUnmapVirtualAddress)(
-  IN PVOID VirtualAddress,
-  IN ULONG NumberPages,
+typedef struct _KUSER_SHARED_DATA {
+  ULONG TickCountLowDeprecated;
+  ULONG TickCountMultiplier;
+  volatile KSYSTEM_TIME InterruptTime;
+  volatile KSYSTEM_TIME SystemTime;
+  volatile KSYSTEM_TIME TimeZoneBias;
+  USHORT ImageNumberLow;
+  USHORT ImageNumberHigh;
+  WCHAR NtSystemRoot[260];
+  ULONG MaxStackTraceDepth;
+  ULONG CryptoExponent;
+  ULONG TimeZoneId;
+  ULONG LargePageMinimum;
+  ULONG Reserved2[7];
+  NT_PRODUCT_TYPE NtProductType;
+  BOOLEAN ProductTypeIsValid;
+  ULONG NtMajorVersion;
+  ULONG NtMinorVersion;
+  BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
+  ULONG Reserved1;
+  ULONG Reserved3;
+  volatile ULONG TimeSlip;
+  ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
+  ULONG AltArchitecturePad[1];
+  LARGE_INTEGER SystemExpirationDate;
+  ULONG SuiteMask;
+  BOOLEAN KdDebuggerEnabled;
+#if (NTDDI_VERSION >= NTDDI_WINXPSP2)
+  UCHAR NXSupportPolicy;
+#endif
+  volatile ULONG ActiveConsoleId;
+  volatile ULONG DismountCount;
+  ULONG ComPlusPackage;
+  ULONG LastSystemRITEventTickCount;
+  ULONG NumberOfPhysicalPages;
+  BOOLEAN SafeBootMode;
+#if (NTDDI_VERSION >= NTDDI_WIN7)
+  union {
+    UCHAR TscQpcData;
+    struct {
+      UCHAR TscQpcEnabled:1;
+      UCHAR TscQpcSpareFlag:1;
+      UCHAR TscQpcShift:6;
+    } DUMMYSTRUCTNAME;
+  } DUMMYUNIONNAME;
+  UCHAR TscQpcPad[2];
+#endif
+#if (NTDDI_VERSION >= NTDDI_VISTA)
+  union {
+    ULONG SharedDataFlags;
+    struct {
+      ULONG DbgErrorPortPresent:1;
+      ULONG DbgElevationEnabled:1;
+      ULONG DbgVirtEnabled:1;
+      ULONG DbgInstallerDetectEnabled:1;
+      ULONG DbgSystemDllRelocated:1;
+      ULONG DbgDynProcessorEnabled:1;
+      ULONG DbgSEHValidationEnabled:1;
+      ULONG SpareBits:25;
+    } DUMMYSTRUCTNAME2;
+  } DUMMYUNIONNAME2;
+#else
+  ULONG TraceLogging;
+#endif
+  ULONG DataFlagsPad[1];
+  ULONGLONG TestRetInstruction;
+  ULONG SystemCall;
+  ULONG SystemCallReturn;
+  ULONGLONG SystemCallPad[3];
+  _ANONYMOUS_UNION union {
+    volatile KSYSTEM_TIME TickCount;
+    volatile ULONG64 TickCountQuad;
+    _ANONYMOUS_STRUCT struct {
+      ULONG ReservedTickCountOverlay[3];
+      ULONG TickCountPad[1];
+    } DUMMYSTRUCTNAME;
+  } DUMMYUNIONNAME3;
+  ULONG Cookie;
+  ULONG CookiePad[1];
+#if (NTDDI_VERSION >= NTDDI_WS03)
+  LONGLONG ConsoleSessionForegroundProcessId;
+  ULONG Wow64SharedInformation[MAX_WOW64_SHARED_ENTRIES];
+#endif
+#if (NTDDI_VERSION >= NTDDI_VISTA)
+#if (NTDDI_VERSION >= NTDDI_WIN7)
+  USHORT UserModeGlobalLogger[16];
+#else
+  USHORT UserModeGlobalLogger[8];
+  ULONG HeapTracingPid[2];
+  ULONG CritSecTracingPid[2];
+#endif
+  ULONG ImageFileExecutionOptions;
+#if (NTDDI_VERSION >= NTDDI_VISTASP1)
+  ULONG LangGenerationCount;
+#else
+  /* 4 bytes padding */
+#endif
+  ULONGLONG Reserved5;
+  volatile ULONG64 InterruptTimeBias;
+#endif
+#if (NTDDI_VERSION >= NTDDI_WIN7)
+  volatile ULONG64 TscQpcBias;
+  volatile ULONG ActiveProcessorCount;
+  volatile USHORT ActiveGroupCount;
+  USHORT Reserved4;
+  volatile ULONG AitSamplingValue;
+  volatile ULONG AppCompatFlag;
+  ULONGLONG SystemDllNativeRelocation;
+  ULONG SystemDllWowRelocation;
+  ULONG XStatePad[1];
+  XSTATE_CONFIGURATION XState;
+#endif
+} KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
+
+#if (NTDDI_VERSION >= NTDDI_VISTA)
+extern NTSYSAPI volatile CCHAR KeNumberProcessors;
+#elif (NTDDI_VERSION >= NTDDI_WINXP)
+extern NTSYSAPI CCHAR KeNumberProcessors;
+#else
+extern PCCHAR KeNumberProcessors;
+#endif
+
+
+/******************************************************************************
+ *                          Kernel Debugger Types                             *
+ ******************************************************************************/
+typedef struct _DEBUG_DEVICE_ADDRESS {
+  UCHAR Type;
+  BOOLEAN Valid;
+  UCHAR Reserved[2];
+  PUCHAR TranslatedAddress;
+  ULONG Length;
+} DEBUG_DEVICE_ADDRESS, *PDEBUG_DEVICE_ADDRESS;
+
+typedef struct _DEBUG_MEMORY_REQUIREMENTS {
+  PHYSICAL_ADDRESS Start;
+  PHYSICAL_ADDRESS MaxEnd;
+  PVOID VirtualAddress;
+  ULONG Length;
+  BOOLEAN Cached;
+  BOOLEAN Aligned;
+} DEBUG_MEMORY_REQUIREMENTS, *PDEBUG_MEMORY_REQUIREMENTS;
+
+typedef struct _DEBUG_DEVICE_DESCRIPTOR {
+  ULONG Bus;
+  ULONG Slot;
+  USHORT Segment;
+  USHORT VendorID;
+  USHORT DeviceID;
+  UCHAR BaseClass;
+  UCHAR SubClass;
+  UCHAR ProgIf;
+  BOOLEAN Initialized;
+  BOOLEAN Configured;
+  DEBUG_DEVICE_ADDRESS BaseAddress[6];
+  DEBUG_MEMORY_REQUIREMENTS Memory;
+} DEBUG_DEVICE_DESCRIPTOR, *PDEBUG_DEVICE_DESCRIPTOR;
+
+typedef NTSTATUS
+(NTAPI *pKdSetupPciDeviceForDebugging)(
+  IN PVOID LoaderBlock OPTIONAL,
+  IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice);
+
+typedef NTSTATUS
+(NTAPI *pKdReleasePciDeviceForDebugging)(
+  IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice);
+
+typedef PVOID
+(NTAPI *pKdGetAcpiTablePhase0)(
+  IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
+  IN ULONG Signature);
+
+typedef VOID
+(NTAPI *pKdCheckPowerButton)(
+  VOID);
+
+#if (NTDDI_VERSION >= NTDDI_VISTA)
+typedef PVOID
+(NTAPI *pKdMapPhysicalMemory64)(
+  IN PHYSICAL_ADDRESS PhysicalAddress,
+  IN ULONG NumberPages,
+  IN BOOLEAN FlushCurrentTLB);
+
+typedef VOID
+(NTAPI *pKdUnmapVirtualAddress)(
+  IN PVOID VirtualAddress,
+  IN ULONG NumberPages,
   IN BOOLEAN FlushCurrentTLB);
 #else
 typedef PVOID
@@ -2827,63 +2758,410 @@ typedef enum _WELL_KNOWN_SID_TYPE {
 
 
 
-/******************************************************************************
- *                          Executive Functions                               *
- ******************************************************************************/
-static __inline PVOID
-ExAllocateFromZone(
-  IN PZONE_HEADER Zone)
-{
-  if (Zone->FreeList.Next)
-    Zone->FreeList.Next = Zone->FreeList.Next->Next;
-  return (PVOID) Zone->FreeList.Next;
-}
+#if defined(_M_IX86)
 
-static __inline PVOID
-ExFreeToZone(
-  IN PZONE_HEADER Zone,
-  IN PVOID Block)
-{
-  ((PSINGLE_LIST_ENTRY) Block)->Next = Zone->FreeList.Next;
-  Zone->FreeList.Next = ((PSINGLE_LIST_ENTRY) Block);
-  return ((PSINGLE_LIST_ENTRY) Block)->Next;
-}
+#define KERNEL_STACK_SIZE                   12288
+#define KERNEL_LARGE_STACK_SIZE             61440
+#define KERNEL_LARGE_STACK_COMMIT           12288
 
-/*
- * PVOID
- * ExInterlockedAllocateFromZone(
- *   IN PZONE_HEADER  Zone,
- *   IN PKSPIN_LOCK  Lock)
- */
-#define ExInterlockedAllocateFromZone(Zone, Lock) \
-    ((PVOID) ExInterlockedPopEntryList(&Zone->FreeList, Lock))
+#define SIZE_OF_80387_REGISTERS   80
 
-/* PVOID
- * ExInterlockedFreeToZone(
- *  IN PZONE_HEADER  Zone,
- *  IN PVOID  Block,
- *  IN PKSPIN_LOCK  Lock);
- */
-#define ExInterlockedFreeToZone(Zone, Block, Lock) \
-    ExInterlockedPushEntryList(&(Zone)->FreeList, (PSINGLE_LIST_ENTRY)(Block), Lock)
+#if !defined(RC_INVOKED)
 
-/*
- * BOOLEAN
- * ExIsFullZone(
- *  IN PZONE_HEADER  Zone)
- */
-#define ExIsFullZone(Zone) \
-  ((Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY) NULL)
+#define CONTEXT_i386               0x10000
+#define CONTEXT_i486               0x10000
+#define CONTEXT_CONTROL            (CONTEXT_i386|0x00000001L)
+#define CONTEXT_INTEGER            (CONTEXT_i386|0x00000002L)
+#define CONTEXT_SEGMENTS           (CONTEXT_i386|0x00000004L)
+#define CONTEXT_FLOATING_POINT     (CONTEXT_i386|0x00000008L)
+#define CONTEXT_DEBUG_REGISTERS    (CONTEXT_i386|0x00000010L)
+#define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386|0x00000020L)
 
-/* BOOLEAN
- * ExIsObjectInFirstZoneSegment(
- *     IN PZONE_HEADER Zone,
- *     IN PVOID Object);
- */
-#define ExIsObjectInFirstZoneSegment(Zone,Object) \
-    ((BOOLEAN)( ((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
-                ((PUCHAR)(Object) <  (PUCHAR)(Zone)->SegmentList.Next + \
-                         (Zone)->TotalSegmentSize)) )
+#define CONTEXT_FULL (CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS)
+#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS |  \
+                     CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS |      \
+                     CONTEXT_EXTENDED_REGISTERS)
+
+#define CONTEXT_XSTATE          (CONTEXT_i386 | 0x00000040L)
+
+#endif /* !defined(RC_INVOKED) */
+
+typedef struct _FLOATING_SAVE_AREA {
+  ULONG ControlWord;
+  ULONG StatusWord;
+  ULONG TagWord;
+  ULONG ErrorOffset;
+  ULONG ErrorSelector;
+  ULONG DataOffset;
+  ULONG DataSelector;
+  UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
+  ULONG Cr0NpxState;
+} FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
+
+#include "pshpack4.h"
+typedef struct _CONTEXT {
+  ULONG ContextFlags;
+  ULONG Dr0;
+  ULONG Dr1;
+  ULONG Dr2;
+  ULONG Dr3;
+  ULONG Dr6;
+  ULONG Dr7;
+  FLOATING_SAVE_AREA FloatSave;
+  ULONG SegGs;
+  ULONG SegFs;
+  ULONG SegEs;
+  ULONG SegDs;
+  ULONG Edi;
+  ULONG Esi;
+  ULONG Ebx;
+  ULONG Edx;
+  ULONG Ecx;
+  ULONG Eax;
+  ULONG Ebp;
+  ULONG Eip;
+  ULONG SegCs;
+  ULONG EFlags;
+  ULONG Esp;
+  ULONG SegSs;
+  UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
+} CONTEXT;
+#include "poppack.h"
+
+#define KeGetPcr()                      PCR
+
+#define PCR_MINOR_VERSION 1
+#define PCR_MAJOR_VERSION 1
+
+typedef struct _KPCR {
+  union {
+    NT_TIB NtTib;
+    struct {
+      struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
+      PVOID Used_StackBase;
+      PVOID Spare2;
+      PVOID TssCopy;
+      ULONG ContextSwitches;
+      KAFFINITY SetMemberCopy;
+      PVOID Used_Self;
+    };
+  };
+  struct _KPCR *SelfPcr;
+  struct _KPRCB *Prcb;
+  KIRQL Irql;
+  ULONG IRR;
+  ULONG IrrActive;
+  ULONG IDR;
+  PVOID KdVersionBlock;
+  struct _KIDTENTRY *IDT;
+  struct _KGDTENTRY *GDT;
+  struct _KTSS *TSS;
+  USHORT MajorVersion;
+  USHORT MinorVersion;
+  KAFFINITY SetMember;
+  ULONG StallScaleFactor;
+  UCHAR SpareUnused;
+  UCHAR Number;
+  UCHAR Spare0;
+  UCHAR SecondLevelCacheAssociativity;
+  ULONG VdmAlert;
+  ULONG KernelReserved[14];
+  ULONG SecondLevelCacheSize;
+  ULONG HalReserved[16];
+} KPCR, *PKPCR;
+
+FORCEINLINE
+ULONG
+KeGetCurrentProcessorNumber(VOID)
+{
+    return (ULONG)__readfsbyte(FIELD_OFFSET(KPCR, Number));
+}
+
+
+
+
+
+
+extern NTKERNELAPI PVOID MmHighestUserAddress;
+extern NTKERNELAPI PVOID MmSystemRangeStart;
+extern NTKERNELAPI ULONG MmUserProbeAddress;
+
+#define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
+#define MM_SYSTEM_RANGE_START MmSystemRangeStart
+#if defined(_LOCAL_COPY_USER_PROBE_ADDRESS_)
+#define MM_USER_PROBE_ADDRESS _LOCAL_COPY_USER_PROBE_ADDRESS_
+extern ULONG _LOCAL_COPY_USER_PROBE_ADDRESS_;
+#else
+#define MM_USER_PROBE_ADDRESS MmUserProbeAddress
+#endif
+#define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
+#define MM_KSEG0_BASE       MM_SYSTEM_RANGE_START
+#define MM_SYSTEM_SPACE_END 0xFFFFFFFF
+#if !defined (_X86PAE_)
+#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
+#else
+#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
+#endif
+
+#elif defined(_M_AMD64)
+
+#define KERNEL_STACK_SIZE 0x6000
+#define KERNEL_LARGE_STACK_SIZE 0x12000
+#define KERNEL_LARGE_STACK_COMMIT KERNEL_STACK_SIZE
+
+#define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
+
+#define EXCEPTION_READ_FAULT    0
+#define EXCEPTION_WRITE_FAULT   1
+#define EXCEPTION_EXECUTE_FAULT 8
+
+#if !defined(RC_INVOKED)
+
+#define CONTEXT_AMD64 0x100000
+
+#define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
+#define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
+#define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
+#define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
+#define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
+
+#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
+#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
+
+#define CONTEXT_XSTATE (CONTEXT_AMD64 | 0x20L)
+
+#define CONTEXT_EXCEPTION_ACTIVE 0x8000000
+#define CONTEXT_SERVICE_ACTIVE 0x10000000
+#define CONTEXT_EXCEPTION_REQUEST 0x40000000
+#define CONTEXT_EXCEPTION_REPORTING 0x80000000
+
+#endif /* !defined(RC_INVOKED) */
+
+#define INITIAL_MXCSR                  0x1f80
+#define INITIAL_FPCSR                  0x027f
+
+typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
+  ULONG64 P1Home;
+  ULONG64 P2Home;
+  ULONG64 P3Home;
+  ULONG64 P4Home;
+  ULONG64 P5Home;
+  ULONG64 P6Home;
+  ULONG ContextFlags;
+  ULONG MxCsr;
+  USHORT SegCs;
+  USHORT SegDs;
+  USHORT SegEs;
+  USHORT SegFs;
+  USHORT SegGs;
+  USHORT SegSs;
+  ULONG EFlags;
+  ULONG64 Dr0;
+  ULONG64 Dr1;
+  ULONG64 Dr2;
+  ULONG64 Dr3;
+  ULONG64 Dr6;
+  ULONG64 Dr7;
+  ULONG64 Rax;
+  ULONG64 Rcx;
+  ULONG64 Rdx;
+  ULONG64 Rbx;
+  ULONG64 Rsp;
+  ULONG64 Rbp;
+  ULONG64 Rsi;
+  ULONG64 Rdi;
+  ULONG64 R8;
+  ULONG64 R9;
+  ULONG64 R10;
+  ULONG64 R11;
+  ULONG64 R12;
+  ULONG64 R13;
+  ULONG64 R14;
+  ULONG64 R15;
+  ULONG64 Rip;
+  union {
+    XMM_SAVE_AREA32 FltSave;
+    struct {
+      M128A Header[2];
+      M128A Legacy[8];
+      M128A Xmm0;
+      M128A Xmm1;
+      M128A Xmm2;
+      M128A Xmm3;
+      M128A Xmm4;
+      M128A Xmm5;
+      M128A Xmm6;
+      M128A Xmm7;
+      M128A Xmm8;
+      M128A Xmm9;
+      M128A Xmm10;
+      M128A Xmm11;
+      M128A Xmm12;
+      M128A Xmm13;
+      M128A Xmm14;
+      M128A Xmm15;
+    } DUMMYSTRUCTNAME;
+  } DUMMYUNIONNAME;
+  M128A VectorRegister[26];
+  ULONG64 VectorControl;
+  ULONG64 DebugControl;
+  ULONG64 LastBranchToRip;
+  ULONG64 LastBranchFromRip;
+  ULONG64 LastExceptionToRip;
+  ULONG64 LastExceptionFromRip;
+} CONTEXT;
+
+typedef struct _KPCR
+{
+    _ANONYMOUS_UNION union
+    {
+        NT_TIB NtTib;
+        _ANONYMOUS_STRUCT struct
+        {
+            union _KGDTENTRY64 *GdtBase;
+            struct _KTSS64 *TssBase;
+            ULONG64 UserRsp;
+            struct _KPCR *Self;
+            struct _KPRCB *CurrentPrcb;
+            PKSPIN_LOCK_QUEUE LockArray;
+            PVOID Used_Self;
+        };
+    };
+    union _KIDTENTRY64 *IdtBase;
+    ULONG64 Unused[2];
+    KIRQL Irql;
+    UCHAR SecondLevelCacheAssociativity;
+    UCHAR ObsoleteNumber;
+    UCHAR Fill0;
+    ULONG Unused0[3];
+    USHORT MajorVersion;
+    USHORT MinorVersion;
+    ULONG StallScaleFactor;
+    PVOID Unused1[3];
+    ULONG KernelReserved[15];
+    ULONG SecondLevelCacheSize;
+    ULONG HalReserved[16];
+    ULONG Unused2;
+    PVOID KdVersionBlock;
+    PVOID Unused3;
+    ULONG PcrAlign1[24];
+} KPCR, *PKPCR;
+
+FORCEINLINE
+PKPCR
+KeGetPcr(VOID)
+{
+    return (PKPCR)__readgsqword(FIELD_OFFSET(KPCR, Self));
+}
+
+FORCEINLINE
+ULONG
+KeGetCurrentProcessorNumber(VOID)
+{
+    return (ULONG)__readgsword(0x184);
+}
+
+
+#define PTI_SHIFT  12L
+#define PDI_SHIFT  21L
+#define PPI_SHIFT  30L
+#define PXI_SHIFT  39L
+#define PTE_PER_PAGE 512
+#define PDE_PER_PAGE 512
+#define PPE_PER_PAGE 512
+#define PXE_PER_PAGE 512
+#define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
+#define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
+#define PPI_MASK (PPE_PER_PAGE - 1)
+#define PXI_MASK (PXE_PER_PAGE - 1)
+
+#define PXE_BASE    0xFFFFF6FB7DBED000ULL
+#define PXE_SELFMAP 0xFFFFF6FB7DBEDF68ULL
+#define PPE_BASE    0xFFFFF6FB7DA00000ULL
+#define PDE_BASE    0xFFFFF6FB40000000ULL
+#define PTE_BASE    0xFFFFF68000000000ULL
+#define PXE_TOP     0xFFFFF6FB7DBEDFFFULL
+#define PPE_TOP     0xFFFFF6FB7DBFFFFFULL
+#define PDE_TOP     0xFFFFF6FB7FFFFFFFULL
+#define PTE_TOP     0xFFFFF6FFFFFFFFFFULL
+
+#define MM_HIGHEST_USER_ADDRESS           MmHighestUserAddress
+#define MM_SYSTEM_RANGE_START             MmSystemRangeStart
+#define MM_USER_PROBE_ADDRESS             MmUserProbeAddress
+#define MM_LOWEST_USER_ADDRESS   (PVOID)0x10000
+#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000ULL
+#define KI_USER_SHARED_DATA       0xFFFFF78000000000ULL
+
+
+#elif defined(_M_IA64)
+
+#elif defined(_M_PPC)
+
+
+#elif defined(_M_MIPS)
+
+#elif defined(_M_ARM)
+#else
+#error Unknown Architecture
+#endif
+
+/******************************************************************************
+ *                          Executive Functions                               *
+ ******************************************************************************/
+static __inline PVOID
+ExAllocateFromZone(
+  IN PZONE_HEADER Zone)
+{
+  if (Zone->FreeList.Next)
+    Zone->FreeList.Next = Zone->FreeList.Next->Next;
+  return (PVOID) Zone->FreeList.Next;
+}
+
+static __inline PVOID
+ExFreeToZone(
+  IN PZONE_HEADER Zone,
+  IN PVOID Block)
+{
+  ((PSINGLE_LIST_ENTRY) Block)->Next = Zone->FreeList.Next;
+  Zone->FreeList.Next = ((PSINGLE_LIST_ENTRY) Block);
+  return ((PSINGLE_LIST_ENTRY) Block)->Next;
+}
+
+/*
+ * PVOID
+ * ExInterlockedAllocateFromZone(
+ *   IN PZONE_HEADER  Zone,
+ *   IN PKSPIN_LOCK  Lock)
+ */
+#define ExInterlockedAllocateFromZone(Zone, Lock) \
+    ((PVOID) ExInterlockedPopEntryList(&Zone->FreeList, Lock))
+
+/* PVOID
+ * ExInterlockedFreeToZone(
+ *  IN PZONE_HEADER  Zone,
+ *  IN PVOID  Block,
+ *  IN PKSPIN_LOCK  Lock);
+ */
+#define ExInterlockedFreeToZone(Zone, Block, Lock) \
+    ExInterlockedPushEntryList(&(Zone)->FreeList, (PSINGLE_LIST_ENTRY)(Block), Lock)
+
+/*
+ * BOOLEAN
+ * ExIsFullZone(
+ *  IN PZONE_HEADER  Zone)
+ */
+#define ExIsFullZone(Zone) \
+  ((Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY) NULL)
+
+/* BOOLEAN
+ * ExIsObjectInFirstZoneSegment(
+ *     IN PZONE_HEADER Zone,
+ *     IN PVOID Object);
+ */
+#define ExIsObjectInFirstZoneSegment(Zone,Object) \
+    ((BOOLEAN)( ((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
+                ((PUCHAR)(Object) <  (PUCHAR)(Zone)->SegmentList.Next + \
+                         (Zone)->TotalSegmentSize)) )
 
 #define ExAcquireResourceExclusive ExAcquireResourceExclusiveLite
 #define ExAcquireResourceShared ExAcquireResourceSharedLite
@@ -2895,6 +3173,34 @@ ExFreeToZone(
 #define ExIsResourceAcquired ExIsResourceAcquiredSharedLite
 #define ExReleaseResourceForThread ExReleaseResourceForThreadLite
 
+typedef enum _INTERLOCKED_RESULT {
+  ResultNegative = RESULT_NEGATIVE,
+  ResultZero = RESULT_ZERO,
+  ResultPositive = RESULT_POSITIVE
+} INTERLOCKED_RESULT;
+
+#ifdef _X86_
+NTKERNELAPI
+INTERLOCKED_RESULT
+FASTCALL
+Exfi386InterlockedIncrementLong(
+  IN OUT LONG volatile *Addend);
+
+NTKERNELAPI
+INTERLOCKED_RESULT
+FASTCALL
+Exfi386InterlockedDecrementLong(
+  IN PLONG  Addend);
+
+NTKERNELAPI
+ULONG
+FASTCALL
+Exfi386InterlockedExchangeUlong(
+  IN PULONG  Target,
+  IN ULONG  Value);
+#endif
+
+
 
 #if (NTDDI_VERSION >= NTDDI_WIN2K)
 NTKERNELAPI
@@ -5375,196 +5681,80 @@ NtQueryInformationProcess(
 typedef enum _SYSTEM_FIRMWARE_TABLE_ACTION {
   SystemFirmwareTable_Enumerate,
   SystemFirmwareTable_Get
-} SYSTEM_FIRMWARE_TABLE_ACTION;
-
-typedef struct _SYSTEM_FIRMWARE_TABLE_INFORMATION {
-  ULONG ProviderSignature;
-  SYSTEM_FIRMWARE_TABLE_ACTION Action;
-  ULONG TableID;
-  ULONG TableBufferLength;
-  UCHAR TableBuffer[ANYSIZE_ARRAY];
-} SYSTEM_FIRMWARE_TABLE_INFORMATION, *PSYSTEM_FIRMWARE_TABLE_INFORMATION;
-
-typedef NTSTATUS
-(__cdecl *PFNFTH)(
-  IN OUT PSYSTEM_FIRMWARE_TABLE_INFORMATION SystemFirmwareTableInfo);
-
-typedef struct _SYSTEM_FIRMWARE_TABLE_HANDLER {
-  ULONG ProviderSignature;
-  BOOLEAN Register;
-  PFNFTH FirmwareTableHandler;
-  PVOID DriverObject;
-} SYSTEM_FIRMWARE_TABLE_HANDLER, *PSYSTEM_FIRMWARE_TABLE_HANDLER;
-
-typedef ULONG_PTR
-(NTAPI *PDRIVER_VERIFIER_THUNK_ROUTINE)(
-  IN PVOID Context);
-
-typedef struct _DRIVER_VERIFIER_THUNK_PAIRS {
-  PDRIVER_VERIFIER_THUNK_ROUTINE PristineRoutine;
-  PDRIVER_VERIFIER_THUNK_ROUTINE NewRoutine;
-} DRIVER_VERIFIER_THUNK_PAIRS, *PDRIVER_VERIFIER_THUNK_PAIRS;
-
-#define DRIVER_VERIFIER_SPECIAL_POOLING             0x0001
-#define DRIVER_VERIFIER_FORCE_IRQL_CHECKING         0x0002
-#define DRIVER_VERIFIER_INJECT_ALLOCATION_FAILURES  0x0004
-#define DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS      0x0008
-#define DRIVER_VERIFIER_IO_CHECKING                 0x0010
-
-#define MAX_WOW64_SHARED_ENTRIES 16
-
-#define NX_SUPPORT_POLICY_ALWAYSOFF 0
-#define NX_SUPPORT_POLICY_ALWAYSON 1
-#define NX_SUPPORT_POLICY_OPTIN 2
-#define NX_SUPPORT_POLICY_OPTOUT 3
-
-#define SHARED_GLOBAL_FLAGS_ERROR_PORT_V        0x0
-#define SHARED_GLOBAL_FLAGS_ERROR_PORT          (1UL << SHARED_GLOBAL_FLAGS_ERROR_PORT_V)
-
-#define SHARED_GLOBAL_FLAGS_ELEVATION_ENABLED_V 0x1
-#define SHARED_GLOBAL_FLAGS_ELEVATION_ENABLED   (1UL << SHARED_GLOBAL_FLAGS_ELEVATION_ENABLED_V)
-
-#define SHARED_GLOBAL_FLAGS_VIRT_ENABLED_V      0x2
-#define SHARED_GLOBAL_FLAGS_VIRT_ENABLED        (1UL << SHARED_GLOBAL_FLAGS_VIRT_ENABLED_V)
-
-#define SHARED_GLOBAL_FLAGS_INSTALLER_DETECT_ENABLED_V  0x3
-#define SHARED_GLOBAL_FLAGS_INSTALLER_DETECT_ENABLED    \
-    (1UL << SHARED_GLOBAL_FLAGS_INSTALLER_DETECT_ENABLED_V)
-
-#define SHARED_GLOBAL_FLAGS_SPARE_V                     0x4
-#define SHARED_GLOBAL_FLAGS_SPARE                       \
-    (1UL << SHARED_GLOBAL_FLAGS_SPARE_V)
-
-#define SHARED_GLOBAL_FLAGS_DYNAMIC_PROC_ENABLED_V      0x5
-#define SHARED_GLOBAL_FLAGS_DYNAMIC_PROC_ENABLED        \
-    (1UL << SHARED_GLOBAL_FLAGS_DYNAMIC_PROC_ENABLED_V)
-
-#define SHARED_GLOBAL_FLAGS_SEH_VALIDATION_ENABLED_V    0x6
-#define SHARED_GLOBAL_FLAGS_SEH_VALIDATION_ENABLED        \
-    (1UL << SHARED_GLOBAL_FLAGS_SEH_VALIDATION_ENABLED_V)
-
-#define EX_INIT_BITS(Flags, Bit) \
-    *((Flags)) |= (Bit)             // Safe to use before concurrently accessible
-
-#define EX_TEST_SET_BIT(Flags, Bit) \
-    InterlockedBitTestAndSet ((PLONG)(Flags), (Bit))
-
-#define EX_TEST_CLEAR_BIT(Flags, Bit) \
-    InterlockedBitTestAndReset ((PLONG)(Flags), (Bit))
-
-typedef struct _KUSER_SHARED_DATA {
-  ULONG TickCountLowDeprecated;
-  ULONG TickCountMultiplier;
-  volatile KSYSTEM_TIME InterruptTime;
-  volatile KSYSTEM_TIME SystemTime;
-  volatile KSYSTEM_TIME TimeZoneBias;
-  USHORT ImageNumberLow;
-  USHORT ImageNumberHigh;
-  WCHAR NtSystemRoot[260];
-  ULONG MaxStackTraceDepth;
-  ULONG CryptoExponent;
-  ULONG TimeZoneId;
-  ULONG LargePageMinimum;
-  ULONG Reserved2[7];
-  NT_PRODUCT_TYPE NtProductType;
-  BOOLEAN ProductTypeIsValid;
-  ULONG NtMajorVersion;
-  ULONG NtMinorVersion;
-  BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
-  ULONG Reserved1;
-  ULONG Reserved3;
-  volatile ULONG TimeSlip;
-  ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
-  ULONG AltArchitecturePad[1];
-  LARGE_INTEGER SystemExpirationDate;
-  ULONG SuiteMask;
-  BOOLEAN KdDebuggerEnabled;
-#if (NTDDI_VERSION >= NTDDI_WINXPSP2)
-  UCHAR NXSupportPolicy;
-#endif
-  volatile ULONG ActiveConsoleId;
-  volatile ULONG DismountCount;
-  ULONG ComPlusPackage;
-  ULONG LastSystemRITEventTickCount;
-  ULONG NumberOfPhysicalPages;
-  BOOLEAN SafeBootMode;
-#if (NTDDI_VERSION >= NTDDI_WIN7)
-  union {
-    UCHAR TscQpcData;
-    struct {
-      UCHAR TscQpcEnabled:1;
-      UCHAR TscQpcSpareFlag:1;
-      UCHAR TscQpcShift:6;
-    } DUMMYSTRUCTNAME;
-  } DUMMYUNIONNAME;
-  UCHAR TscQpcPad[2];
-#endif
-#if (NTDDI_VERSION >= NTDDI_VISTA)
-  union {
-    ULONG SharedDataFlags;
-    struct {
-      ULONG DbgErrorPortPresent:1;
-      ULONG DbgElevationEnabled:1;
-      ULONG DbgVirtEnabled:1;
-      ULONG DbgInstallerDetectEnabled:1;
-      ULONG DbgSystemDllRelocated:1;
-      ULONG DbgDynProcessorEnabled:1;
-      ULONG DbgSEHValidationEnabled:1;
-      ULONG SpareBits:25;
-    } DUMMYSTRUCTNAME2;
-  } DUMMYUNIONNAME2;
-#else
-  ULONG TraceLogging;
-#endif
-  ULONG DataFlagsPad[1];
-  ULONGLONG TestRetInstruction;
-  ULONG SystemCall;
-  ULONG SystemCallReturn;
-  ULONGLONG SystemCallPad[3];
-  _ANONYMOUS_UNION union {
-    volatile KSYSTEM_TIME TickCount;
-    volatile ULONG64 TickCountQuad;
-    _ANONYMOUS_STRUCT struct {
-      ULONG ReservedTickCountOverlay[3];
-      ULONG TickCountPad[1];
-    } DUMMYSTRUCTNAME;
-  } DUMMYUNIONNAME3;
-  ULONG Cookie;
-  ULONG CookiePad[1];
-#if (NTDDI_VERSION >= NTDDI_WS03)
-  LONGLONG ConsoleSessionForegroundProcessId;
-  ULONG Wow64SharedInformation[MAX_WOW64_SHARED_ENTRIES];
-#endif
-#if (NTDDI_VERSION >= NTDDI_VISTA)
-#if (NTDDI_VERSION >= NTDDI_WIN7)
-  USHORT UserModeGlobalLogger[16];
-#else
-  USHORT UserModeGlobalLogger[8];
-  ULONG HeapTracingPid[2];
-  ULONG CritSecTracingPid[2];
-#endif
-  ULONG ImageFileExecutionOptions;
-#if (NTDDI_VERSION >= NTDDI_VISTASP1)
-  ULONG LangGenerationCount;
-#else
-  /* 4 bytes padding */
-#endif
-  ULONGLONG Reserved5;
-  volatile ULONG64 InterruptTimeBias;
-#endif
-#if (NTDDI_VERSION >= NTDDI_WIN7)
-  volatile ULONG64 TscQpcBias;
-  volatile ULONG ActiveProcessorCount;
-  volatile USHORT ActiveGroupCount;
-  USHORT Reserved4;
-  volatile ULONG AitSamplingValue;
-  volatile ULONG AppCompatFlag;
-  ULONGLONG SystemDllNativeRelocation;
-  ULONG SystemDllWowRelocation;
-  ULONG XStatePad[1];
-  XSTATE_CONFIGURATION XState;
-#endif
-} KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
+} SYSTEM_FIRMWARE_TABLE_ACTION;
+
+typedef struct _SYSTEM_FIRMWARE_TABLE_INFORMATION {
+  ULONG ProviderSignature;
+  SYSTEM_FIRMWARE_TABLE_ACTION Action;
+  ULONG TableID;
+  ULONG TableBufferLength;
+  UCHAR TableBuffer[ANYSIZE_ARRAY];
+} SYSTEM_FIRMWARE_TABLE_INFORMATION, *PSYSTEM_FIRMWARE_TABLE_INFORMATION;
+
+typedef NTSTATUS
+(__cdecl *PFNFTH)(
+  IN OUT PSYSTEM_FIRMWARE_TABLE_INFORMATION SystemFirmwareTableInfo);
+
+typedef struct _SYSTEM_FIRMWARE_TABLE_HANDLER {
+  ULONG ProviderSignature;
+  BOOLEAN Register;
+  PFNFTH FirmwareTableHandler;
+  PVOID DriverObject;
+} SYSTEM_FIRMWARE_TABLE_HANDLER, *PSYSTEM_FIRMWARE_TABLE_HANDLER;
+
+typedef ULONG_PTR
+(NTAPI *PDRIVER_VERIFIER_THUNK_ROUTINE)(
+  IN PVOID Context);
+
+typedef struct _DRIVER_VERIFIER_THUNK_PAIRS {
+  PDRIVER_VERIFIER_THUNK_ROUTINE PristineRoutine;
+  PDRIVER_VERIFIER_THUNK_ROUTINE NewRoutine;
+} DRIVER_VERIFIER_THUNK_PAIRS, *PDRIVER_VERIFIER_THUNK_PAIRS;
+
+#define DRIVER_VERIFIER_SPECIAL_POOLING             0x0001
+#define DRIVER_VERIFIER_FORCE_IRQL_CHECKING         0x0002
+#define DRIVER_VERIFIER_INJECT_ALLOCATION_FAILURES  0x0004
+#define DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS      0x0008
+#define DRIVER_VERIFIER_IO_CHECKING                 0x0010
+
+#define NX_SUPPORT_POLICY_ALWAYSOFF 0
+#define NX_SUPPORT_POLICY_ALWAYSON 1
+#define NX_SUPPORT_POLICY_OPTIN 2
+#define NX_SUPPORT_POLICY_OPTOUT 3
+
+#define SHARED_GLOBAL_FLAGS_ERROR_PORT_V        0x0
+#define SHARED_GLOBAL_FLAGS_ERROR_PORT          (1UL << SHARED_GLOBAL_FLAGS_ERROR_PORT_V)
+
+#define SHARED_GLOBAL_FLAGS_ELEVATION_ENABLED_V 0x1
+#define SHARED_GLOBAL_FLAGS_ELEVATION_ENABLED   (1UL << SHARED_GLOBAL_FLAGS_ELEVATION_ENABLED_V)
+
+#define SHARED_GLOBAL_FLAGS_VIRT_ENABLED_V      0x2
+#define SHARED_GLOBAL_FLAGS_VIRT_ENABLED        (1UL << SHARED_GLOBAL_FLAGS_VIRT_ENABLED_V)
+
+#define SHARED_GLOBAL_FLAGS_INSTALLER_DETECT_ENABLED_V  0x3
+#define SHARED_GLOBAL_FLAGS_INSTALLER_DETECT_ENABLED    \
+    (1UL << SHARED_GLOBAL_FLAGS_INSTALLER_DETECT_ENABLED_V)
+
+#define SHARED_GLOBAL_FLAGS_SPARE_V                     0x4
+#define SHARED_GLOBAL_FLAGS_SPARE                       \
+    (1UL << SHARED_GLOBAL_FLAGS_SPARE_V)
+
+#define SHARED_GLOBAL_FLAGS_DYNAMIC_PROC_ENABLED_V      0x5
+#define SHARED_GLOBAL_FLAGS_DYNAMIC_PROC_ENABLED        \
+    (1UL << SHARED_GLOBAL_FLAGS_DYNAMIC_PROC_ENABLED_V)
+
+#define SHARED_GLOBAL_FLAGS_SEH_VALIDATION_ENABLED_V    0x6
+#define SHARED_GLOBAL_FLAGS_SEH_VALIDATION_ENABLED        \
+    (1UL << SHARED_GLOBAL_FLAGS_SEH_VALIDATION_ENABLED_V)
+
+#define EX_INIT_BITS(Flags, Bit) \
+    *((Flags)) |= (Bit)             // Safe to use before concurrently accessible
+
+#define EX_TEST_SET_BIT(Flags, Bit) \
+    InterlockedBitTestAndSet ((PLONG)(Flags), (Bit))
+
+#define EX_TEST_CLEAR_BIT(Flags, Bit) \
+    InterlockedBitTestAndReset ((PLONG)(Flags), (Bit))
 
 #define CmResourceTypeMaximum             8
 
@@ -5589,12 +5779,6 @@ typedef struct _CM_PCCARD_DEVICE_DATA {
 #define PCCARD_DUP_LEGACY_BASE         0x06
 #define PCCARD_NO_CONTROLLERS          0x07
 
-#if defined(_X86_) || defined(_AMD64_)
-#define PAUSE_PROCESSOR YieldProcessor();
-#elif defined(_IA64_)
-#define PAUSE_PROCESSOR __yield();
-#endif
-
 #define MAXIMUM_EXPANSION_SIZE (KERNEL_LARGE_STACK_SIZE - (PAGE_SIZE / 2))
 
 /* Filesystem runtime library routines */
@@ -5609,189 +5793,6 @@ FsRtlIsTotalDeviceFailure(
 
 /* FIXME : These definitions below doesn't belong to NTDDK */
 
-#ifdef _X86_
-
-extern NTKERNELAPI PVOID MmHighestUserAddress;
-extern NTKERNELAPI PVOID MmSystemRangeStart;
-extern NTKERNELAPI ULONG MmUserProbeAddress;
-
-#define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
-#define MM_SYSTEM_RANGE_START MmSystemRangeStart
-#if defined(_LOCAL_COPY_USER_PROBE_ADDRESS_)
-#define MM_USER_PROBE_ADDRESS _LOCAL_COPY_USER_PROBE_ADDRESS_
-extern ULONG _LOCAL_COPY_USER_PROBE_ADDRESS_;
-#else
-#define MM_USER_PROBE_ADDRESS MmUserProbeAddress
-#endif
-#define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
-#define MM_KSEG0_BASE       MM_SYSTEM_RANGE_START
-#define MM_SYSTEM_SPACE_END 0xFFFFFFFF
-#if !defined (_X86PAE_)
-#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
-#else
-#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
-#endif
-
-#define KeGetPcr()                      PCR
-
-#define PCR_MINOR_VERSION 1
-#define PCR_MAJOR_VERSION 1
-
-typedef struct _KPCR {
-  union {
-    NT_TIB NtTib;
-    struct {
-      struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
-      PVOID Used_StackBase;
-      PVOID Spare2;
-      PVOID TssCopy;
-      ULONG ContextSwitches;
-      KAFFINITY SetMemberCopy;
-      PVOID Used_Self;
-    };
-  };
-  struct _KPCR *SelfPcr;
-  struct _KPRCB *Prcb;
-  KIRQL Irql;
-  ULONG IRR;
-  ULONG IrrActive;
-  ULONG IDR;
-  PVOID KdVersionBlock;
-  struct _KIDTENTRY *IDT;
-  struct _KGDTENTRY *GDT;
-  struct _KTSS *TSS;
-  USHORT MajorVersion;
-  USHORT MinorVersion;
-  KAFFINITY SetMember;
-  ULONG StallScaleFactor;
-  UCHAR SpareUnused;
-  UCHAR Number;
-  UCHAR Spare0;
-  UCHAR SecondLevelCacheAssociativity;
-  ULONG VdmAlert;
-  ULONG KernelReserved[14];
-  ULONG SecondLevelCacheSize;
-  ULONG HalReserved[16];
-} KPCR, *PKPCR;
-
-FORCEINLINE
-ULONG
-KeGetCurrentProcessorNumber(VOID)
-{
-    return (ULONG)__readfsbyte(FIELD_OFFSET(KPCR, Number));
-}
-
-typedef enum _INTERLOCKED_RESULT {
-  ResultNegative = RESULT_NEGATIVE,
-  ResultZero = RESULT_ZERO,
-  ResultPositive = RESULT_POSITIVE
-} INTERLOCKED_RESULT;
-
-NTKERNELAPI
-INTERLOCKED_RESULT
-FASTCALL
-Exfi386InterlockedIncrementLong(
-  IN OUT LONG volatile *Addend);
-
-NTKERNELAPI
-INTERLOCKED_RESULT
-FASTCALL
-Exfi386InterlockedDecrementLong(
-  IN PLONG  Addend);
-
-NTKERNELAPI
-ULONG
-FASTCALL
-Exfi386InterlockedExchangeUlong(
-  IN PULONG  Target,
-  IN ULONG  Value);
-
-#endif /* _X86_ */
-
-#ifdef _AMD64_
-
-#define PTI_SHIFT  12L
-#define PDI_SHIFT  21L
-#define PPI_SHIFT  30L
-#define PXI_SHIFT  39L
-#define PTE_PER_PAGE 512
-#define PDE_PER_PAGE 512
-#define PPE_PER_PAGE 512
-#define PXE_PER_PAGE 512
-#define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
-#define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
-#define PPI_MASK (PPE_PER_PAGE - 1)
-#define PXI_MASK (PXE_PER_PAGE - 1)
-
-#define PXE_BASE    0xFFFFF6FB7DBED000ULL
-#define PXE_SELFMAP 0xFFFFF6FB7DBEDF68ULL
-#define PPE_BASE    0xFFFFF6FB7DA00000ULL
-#define PDE_BASE    0xFFFFF6FB40000000ULL
-#define PTE_BASE    0xFFFFF68000000000ULL
-#define PXE_TOP     0xFFFFF6FB7DBEDFFFULL
-#define PPE_TOP     0xFFFFF6FB7DBFFFFFULL
-#define PDE_TOP     0xFFFFF6FB7FFFFFFFULL
-#define PTE_TOP     0xFFFFF6FFFFFFFFFFULL
-
-#define MM_HIGHEST_USER_ADDRESS           MmHighestUserAddress
-#define MM_SYSTEM_RANGE_START             MmSystemRangeStart
-#define MM_USER_PROBE_ADDRESS             MmUserProbeAddress
-#define MM_LOWEST_USER_ADDRESS   (PVOID)0x10000
-#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000ULL
-#define KI_USER_SHARED_DATA       0xFFFFF78000000000ULL
-
-typedef struct _KPCR
-{
-    _ANONYMOUS_UNION union
-    {
-        NT_TIB NtTib;
-        _ANONYMOUS_STRUCT struct
-        {
-            union _KGDTENTRY64 *GdtBase;
-            struct _KTSS64 *TssBase;
-            ULONG64 UserRsp;
-            struct _KPCR *Self;
-            struct _KPRCB *CurrentPrcb;
-            PKSPIN_LOCK_QUEUE LockArray;
-            PVOID Used_Self;
-        };
-    };
-    union _KIDTENTRY64 *IdtBase;
-    ULONG64 Unused[2];
-    KIRQL Irql;
-    UCHAR SecondLevelCacheAssociativity;
-    UCHAR ObsoleteNumber;
-    UCHAR Fill0;
-    ULONG Unused0[3];
-    USHORT MajorVersion;
-    USHORT MinorVersion;
-    ULONG StallScaleFactor;
-    PVOID Unused1[3];
-    ULONG KernelReserved[15];
-    ULONG SecondLevelCacheSize;
-    ULONG HalReserved[16];
-    ULONG Unused2;
-    PVOID KdVersionBlock;
-    PVOID Unused3;
-    ULONG PcrAlign1[24];
-} KPCR, *PKPCR;
-
-FORCEINLINE
-PKPCR
-KeGetPcr(VOID)
-{
-    return (PKPCR)__readgsqword(FIELD_OFFSET(KPCR, Self));
-}
-
-FORCEINLINE
-ULONG
-KeGetCurrentProcessorNumber(VOID)
-{
-    return (ULONG)__readgsword(0x184);
-}
-
-#endif /* _AMD64_ */
-
 #ifdef __cplusplus
 }
 #endif
index 419cfa0..0aedafb 100644 (file)
@@ -552,7 +552,6 @@ typedef BOOLEAN
  *                              Kernel Types                                  *
  ******************************************************************************/
 
-
 typedef UCHAR KIRQL, *PKIRQL;
 typedef CCHAR KPROCESSOR_MODE;
 typedef LONG KPRIORITY;
@@ -7710,6 +7709,7 @@ typedef struct _KFLOATING_SAVE {
 extern NTKERNELAPI volatile KSYSTEM_TIME KeTickCount;
 
 #define YieldProcessor _mm_pause
+#define PAUSE_PROCESSOR YieldProcessor();
 
 FORCEINLINE
 VOID
@@ -7820,6 +7820,8 @@ _KeQueryTickCount(
 
 
 
+
+
 #elif defined(_M_AMD64)
 /** Kernel definitions for AMD64 **/
 
@@ -7861,6 +7863,7 @@ typedef XSAVE_FORMAT XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
 #define KeGetDcacheFillSize() 1L
 
 #define YieldProcessor _mm_pause
+#define PAUSE_PROCESSOR YieldProcessor();
 
 FORCEINLINE
 KIRQL
@@ -7935,6 +7938,8 @@ KeGetCurrentThread(VOID)
 #define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
 extern volatile LARGE_INTEGER KeTickCount;
 
+#define PAUSE_PROCESSOR __yield();
+
 FORCEINLINE
 VOID
 KeFlushWriteBuffer(VOID)
index 3a6b999..f4cfd97 100644 (file)
@@ -91,5 +91,166 @@ KeGetCurrentThread(VOID)
 
 /* x86 and x64 performs a 0x2C interrupt */
 #define DbgRaiseAssertionFailure __int2c
-$endif
 
+$endif /* _WDMDDK_ */
+$if (_NTDDK_)
+
+#define PAUSE_PROCESSOR YieldProcessor();
+
+#define KERNEL_STACK_SIZE 0x6000
+#define KERNEL_LARGE_STACK_SIZE 0x12000
+#define KERNEL_LARGE_STACK_COMMIT KERNEL_STACK_SIZE
+
+#define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
+
+#define EXCEPTION_READ_FAULT    0
+#define EXCEPTION_WRITE_FAULT   1
+#define EXCEPTION_EXECUTE_FAULT 8
+
+#if !defined(RC_INVOKED)
+
+#define CONTEXT_AMD64 0x100000
+
+#define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
+#define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
+#define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
+#define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
+#define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
+
+#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
+#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
+
+#define CONTEXT_XSTATE (CONTEXT_AMD64 | 0x20L)
+
+#define CONTEXT_EXCEPTION_ACTIVE 0x8000000
+#define CONTEXT_SERVICE_ACTIVE 0x10000000
+#define CONTEXT_EXCEPTION_REQUEST 0x40000000
+#define CONTEXT_EXCEPTION_REPORTING 0x80000000
+
+#endif /* !defined(RC_INVOKED) */
+
+#define INITIAL_MXCSR                  0x1f80
+#define INITIAL_FPCSR                  0x027f
+
+typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
+  ULONG64 P1Home;
+  ULONG64 P2Home;
+  ULONG64 P3Home;
+  ULONG64 P4Home;
+  ULONG64 P5Home;
+  ULONG64 P6Home;
+  ULONG ContextFlags;
+  ULONG MxCsr;
+  USHORT SegCs;
+  USHORT SegDs;
+  USHORT SegEs;
+  USHORT SegFs;
+  USHORT SegGs;
+  USHORT SegSs;
+  ULONG EFlags;
+  ULONG64 Dr0;
+  ULONG64 Dr1;
+  ULONG64 Dr2;
+  ULONG64 Dr3;
+  ULONG64 Dr6;
+  ULONG64 Dr7;
+  ULONG64 Rax;
+  ULONG64 Rcx;
+  ULONG64 Rdx;
+  ULONG64 Rbx;
+  ULONG64 Rsp;
+  ULONG64 Rbp;
+  ULONG64 Rsi;
+  ULONG64 Rdi;
+  ULONG64 R8;
+  ULONG64 R9;
+  ULONG64 R10;
+  ULONG64 R11;
+  ULONG64 R12;
+  ULONG64 R13;
+  ULONG64 R14;
+  ULONG64 R15;
+  ULONG64 Rip;
+  union {
+    XMM_SAVE_AREA32 FltSave;
+    struct {
+      M128A Header[2];
+      M128A Legacy[8];
+      M128A Xmm0;
+      M128A Xmm1;
+      M128A Xmm2;
+      M128A Xmm3;
+      M128A Xmm4;
+      M128A Xmm5;
+      M128A Xmm6;
+      M128A Xmm7;
+      M128A Xmm8;
+      M128A Xmm9;
+      M128A Xmm10;
+      M128A Xmm11;
+      M128A Xmm12;
+      M128A Xmm13;
+      M128A Xmm14;
+      M128A Xmm15;
+    } DUMMYSTRUCTNAME;
+  } DUMMYUNIONNAME;
+  M128A VectorRegister[26];
+  ULONG64 VectorControl;
+  ULONG64 DebugControl;
+  ULONG64 LastBranchToRip;
+  ULONG64 LastBranchFromRip;
+  ULONG64 LastExceptionToRip;
+  ULONG64 LastExceptionFromRip;
+} CONTEXT;
+
+typedef struct _KPCR
+{
+    _ANONYMOUS_UNION union
+    {
+        NT_TIB NtTib;
+        _ANONYMOUS_STRUCT struct
+        {
+            union _KGDTENTRY64 *GdtBase;
+            struct _KTSS64 *TssBase;
+            ULONG64 UserRsp;
+            struct _KPCR *Self;
+            struct _KPRCB *CurrentPrcb;
+            PKSPIN_LOCK_QUEUE LockArray;
+            PVOID Used_Self;
+        };
+    };
+    union _KIDTENTRY64 *IdtBase;
+    ULONG64 Unused[2];
+    KIRQL Irql;
+    UCHAR SecondLevelCacheAssociativity;
+    UCHAR ObsoleteNumber;
+    UCHAR Fill0;
+    ULONG Unused0[3];
+    USHORT MajorVersion;
+    USHORT MinorVersion;
+    ULONG StallScaleFactor;
+    PVOID Unused1[3];
+    ULONG KernelReserved[15];
+    ULONG SecondLevelCacheSize;
+    ULONG HalReserved[16];
+    ULONG Unused2;
+    PVOID KdVersionBlock;
+    PVOID Unused3;
+    ULONG PcrAlign1[24];
+} KPCR, *PKPCR;
+
+FORCEINLINE
+PKPCR
+KeGetPcr(VOID)
+{
+    return (PKPCR)__readgsqword(FIELD_OFFSET(KPCR, Self));
+}
+
+FORCEINLINE
+ULONG
+KeGetCurrentProcessorNumber(VOID)
+{
+    return (ULONG)__readgsword(0x184);
+}
+
+$endif /* _NTDDK_ */
diff --git a/include/xdk/amd64/mm.h b/include/xdk/amd64/mm.h
new file mode 100644 (file)
index 0000000..1170c35
--- /dev/null
@@ -0,0 +1,34 @@
+$if (_NTDDK_)
+
+#define PTI_SHIFT  12L
+#define PDI_SHIFT  21L
+#define PPI_SHIFT  30L
+#define PXI_SHIFT  39L
+#define PTE_PER_PAGE 512
+#define PDE_PER_PAGE 512
+#define PPE_PER_PAGE 512
+#define PXE_PER_PAGE 512
+#define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
+#define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
+#define PPI_MASK (PPE_PER_PAGE - 1)
+#define PXI_MASK (PXE_PER_PAGE - 1)
+
+#define PXE_BASE    0xFFFFF6FB7DBED000ULL
+#define PXE_SELFMAP 0xFFFFF6FB7DBEDF68ULL
+#define PPE_BASE    0xFFFFF6FB7DA00000ULL
+#define PDE_BASE    0xFFFFF6FB40000000ULL
+#define PTE_BASE    0xFFFFF68000000000ULL
+#define PXE_TOP     0xFFFFF6FB7DBEDFFFULL
+#define PPE_TOP     0xFFFFF6FB7DBFFFFFULL
+#define PDE_TOP     0xFFFFF6FB7FFFFFFFULL
+#define PTE_TOP     0xFFFFF6FFFFFFFFFFULL
+
+#define MM_HIGHEST_USER_ADDRESS           MmHighestUserAddress
+#define MM_SYSTEM_RANGE_START             MmSystemRangeStart
+#define MM_USER_PROBE_ADDRESS             MmUserProbeAddress
+#define MM_LOWEST_USER_ADDRESS   (PVOID)0x10000
+#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000ULL
+#define KI_USER_SHARED_DATA       0xFFFFF78000000000ULL
+
+$endif /* _NTDDK_ */
+
index 47aa03e..d9799f4 100644 (file)
@@ -66,6 +66,34 @@ ExFreeToZone(
 #define ExIsResourceAcquiredShared ExIsResourceAcquiredSharedLite
 #define ExIsResourceAcquired ExIsResourceAcquiredSharedLite
 #define ExReleaseResourceForThread ExReleaseResourceForThreadLite
+
+typedef enum _INTERLOCKED_RESULT {
+  ResultNegative = RESULT_NEGATIVE,
+  ResultZero = RESULT_ZERO,
+  ResultPositive = RESULT_POSITIVE
+} INTERLOCKED_RESULT;
+
+#ifdef _X86_
+NTKERNELAPI
+INTERLOCKED_RESULT
+FASTCALL
+Exfi386InterlockedIncrementLong(
+  IN OUT LONG volatile *Addend);
+
+NTKERNELAPI
+INTERLOCKED_RESULT
+FASTCALL
+Exfi386InterlockedDecrementLong(
+  IN PLONG  Addend);
+
+NTKERNELAPI
+ULONG
+FASTCALL
+Exfi386InterlockedExchangeUlong(
+  IN PULONG  Target,
+  IN ULONG  Value);
+#endif
+
 $endif
 
 $if (_WDMDDK_)
index d63eda7..2920636 100644 (file)
@@ -19,6 +19,8 @@ $if (_WDMDDK_)
 #define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
 extern volatile LARGE_INTEGER KeTickCount;
 
+#define PAUSE_PROCESSOR __yield();
+
 FORCEINLINE
 VOID
 KeFlushWriteBuffer(VOID)
index 2960497..4f29306 100644 (file)
@@ -1,60 +1,8 @@
 /******************************************************************************
  *                              Kernel Types                                  *
  ******************************************************************************/
-
-$if (_NTDDK_)
-typedef VOID
-(NTAPI *PEXPAND_STACK_CALLOUT)(
-  IN PVOID Parameter OPTIONAL);
-
-typedef VOID
-(NTAPI *PTIMER_APC_ROUTINE)(
-  IN PVOID TimerContext,
-  IN ULONG TimerLowValue,
-  IN LONG TimerHighValue);
-
-typedef enum _TIMER_SET_INFORMATION_CLASS {
-  TimerSetCoalescableTimer,
-  MaxTimerInfoClass 
-} TIMER_SET_INFORMATION_CLASS;
-
-#if (NTDDI_VERSION >= NTDDI_WIN7)
-typedef struct _TIMER_SET_COALESCABLE_TIMER_INFO {
-  IN LARGE_INTEGER DueTime;
-  IN PTIMER_APC_ROUTINE TimerApcRoutine OPTIONAL;
-  IN PVOID TimerContext OPTIONAL;
-  IN struct _COUNTED_REASON_CONTEXT *WakeContext OPTIONAL;
-  IN ULONG Period OPTIONAL;
-  IN ULONG TolerableDelay;
-  OUT PBOOLEAN PreviousState OPTIONAL;
-} TIMER_SET_COALESCABLE_TIMER_INFO, *PTIMER_SET_COALESCABLE_TIMER_INFO;
-#endif /* (NTDDI_VERSION >= NTDDI_WIN7) */
-
-#define XSTATE_LEGACY_FLOATING_POINT        0
-#define XSTATE_LEGACY_SSE                   1
-#define XSTATE_GSSE                         2
-
-#define XSTATE_MASK_LEGACY_FLOATING_POINT   (1i64 << (XSTATE_LEGACY_FLOATING_POINT))
-#define XSTATE_MASK_LEGACY_SSE              (1i64 << (XSTATE_LEGACY_SSE))
-#define XSTATE_MASK_LEGACY                  (XSTATE_MASK_LEGACY_FLOATING_POINT | XSTATE_MASK_LEGACY_SSE)
-#define XSTATE_MASK_GSSE                    (1i64 << (XSTATE_GSSE))
-
-#define MAXIMUM_XSTATE_FEATURES             64
-
-typedef struct _XSTATE_FEATURE {
-  ULONG Offset;
-  ULONG Size;
-} XSTATE_FEATURE, *PXSTATE_FEATURE;
-
-typedef struct _XSTATE_CONFIGURATION {
-  ULONG64 EnabledFeatures;
-  ULONG Size;
-  ULONG OptimizedSave:1;
-  XSTATE_FEATURE Features[MAXIMUM_XSTATE_FEATURES];
-} XSTATE_CONFIGURATION, *PXSTATE_CONFIGURATION;
-$endif
-
 $if (_WDMDDK_)
+
 typedef UCHAR KIRQL, *PKIRQL;
 typedef CCHAR KPROCESSOR_MODE;
 typedef LONG KPRIORITY;
@@ -1049,5 +997,182 @@ extern NTSYSAPI CCHAR KeNumberProcessors;
 extern PCCHAR KeNumberProcessors;
 #endif
 
-$endif
+$endif /* _WDMDDK_ */
+$if (_NTDDK_)
+
+typedef VOID
+(NTAPI *PEXPAND_STACK_CALLOUT)(
+  IN PVOID Parameter OPTIONAL);
+
+typedef VOID
+(NTAPI *PTIMER_APC_ROUTINE)(
+  IN PVOID TimerContext,
+  IN ULONG TimerLowValue,
+  IN LONG TimerHighValue);
+
+typedef enum _TIMER_SET_INFORMATION_CLASS {
+  TimerSetCoalescableTimer,
+  MaxTimerInfoClass 
+} TIMER_SET_INFORMATION_CLASS;
+
+#if (NTDDI_VERSION >= NTDDI_WIN7)
+typedef struct _TIMER_SET_COALESCABLE_TIMER_INFO {
+  IN LARGE_INTEGER DueTime;
+  IN PTIMER_APC_ROUTINE TimerApcRoutine OPTIONAL;
+  IN PVOID TimerContext OPTIONAL;
+  IN struct _COUNTED_REASON_CONTEXT *WakeContext OPTIONAL;
+  IN ULONG Period OPTIONAL;
+  IN ULONG TolerableDelay;
+  OUT PBOOLEAN PreviousState OPTIONAL;
+} TIMER_SET_COALESCABLE_TIMER_INFO, *PTIMER_SET_COALESCABLE_TIMER_INFO;
+#endif /* (NTDDI_VERSION >= NTDDI_WIN7) */
+
+#define XSTATE_LEGACY_FLOATING_POINT        0
+#define XSTATE_LEGACY_SSE                   1
+#define XSTATE_GSSE                         2
+
+#define XSTATE_MASK_LEGACY_FLOATING_POINT   (1i64 << (XSTATE_LEGACY_FLOATING_POINT))
+#define XSTATE_MASK_LEGACY_SSE              (1i64 << (XSTATE_LEGACY_SSE))
+#define XSTATE_MASK_LEGACY                  (XSTATE_MASK_LEGACY_FLOATING_POINT | XSTATE_MASK_LEGACY_SSE)
+#define XSTATE_MASK_GSSE                    (1i64 << (XSTATE_GSSE))
+
+#define MAXIMUM_XSTATE_FEATURES             64
+
+typedef struct _XSTATE_FEATURE {
+  ULONG Offset;
+  ULONG Size;
+} XSTATE_FEATURE, *PXSTATE_FEATURE;
+
+typedef struct _XSTATE_CONFIGURATION {
+  ULONG64 EnabledFeatures;
+  ULONG Size;
+  ULONG OptimizedSave:1;
+  XSTATE_FEATURE Features[MAXIMUM_XSTATE_FEATURES];
+} XSTATE_CONFIGURATION, *PXSTATE_CONFIGURATION;
+
+#define MAX_WOW64_SHARED_ENTRIES 16
+
+typedef struct _KUSER_SHARED_DATA {
+  ULONG TickCountLowDeprecated;
+  ULONG TickCountMultiplier;
+  volatile KSYSTEM_TIME InterruptTime;
+  volatile KSYSTEM_TIME SystemTime;
+  volatile KSYSTEM_TIME TimeZoneBias;
+  USHORT ImageNumberLow;
+  USHORT ImageNumberHigh;
+  WCHAR NtSystemRoot[260];
+  ULONG MaxStackTraceDepth;
+  ULONG CryptoExponent;
+  ULONG TimeZoneId;
+  ULONG LargePageMinimum;
+  ULONG Reserved2[7];
+  NT_PRODUCT_TYPE NtProductType;
+  BOOLEAN ProductTypeIsValid;
+  ULONG NtMajorVersion;
+  ULONG NtMinorVersion;
+  BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
+  ULONG Reserved1;
+  ULONG Reserved3;
+  volatile ULONG TimeSlip;
+  ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
+  ULONG AltArchitecturePad[1];
+  LARGE_INTEGER SystemExpirationDate;
+  ULONG SuiteMask;
+  BOOLEAN KdDebuggerEnabled;
+#if (NTDDI_VERSION >= NTDDI_WINXPSP2)
+  UCHAR NXSupportPolicy;
+#endif
+  volatile ULONG ActiveConsoleId;
+  volatile ULONG DismountCount;
+  ULONG ComPlusPackage;
+  ULONG LastSystemRITEventTickCount;
+  ULONG NumberOfPhysicalPages;
+  BOOLEAN SafeBootMode;
+#if (NTDDI_VERSION >= NTDDI_WIN7)
+  union {
+    UCHAR TscQpcData;
+    struct {
+      UCHAR TscQpcEnabled:1;
+      UCHAR TscQpcSpareFlag:1;
+      UCHAR TscQpcShift:6;
+    } DUMMYSTRUCTNAME;
+  } DUMMYUNIONNAME;
+  UCHAR TscQpcPad[2];
+#endif
+#if (NTDDI_VERSION >= NTDDI_VISTA)
+  union {
+    ULONG SharedDataFlags;
+    struct {
+      ULONG DbgErrorPortPresent:1;
+      ULONG DbgElevationEnabled:1;
+      ULONG DbgVirtEnabled:1;
+      ULONG DbgInstallerDetectEnabled:1;
+      ULONG DbgSystemDllRelocated:1;
+      ULONG DbgDynProcessorEnabled:1;
+      ULONG DbgSEHValidationEnabled:1;
+      ULONG SpareBits:25;
+    } DUMMYSTRUCTNAME2;
+  } DUMMYUNIONNAME2;
+#else
+  ULONG TraceLogging;
+#endif
+  ULONG DataFlagsPad[1];
+  ULONGLONG TestRetInstruction;
+  ULONG SystemCall;
+  ULONG SystemCallReturn;
+  ULONGLONG SystemCallPad[3];
+  _ANONYMOUS_UNION union {
+    volatile KSYSTEM_TIME TickCount;
+    volatile ULONG64 TickCountQuad;
+    _ANONYMOUS_STRUCT struct {
+      ULONG ReservedTickCountOverlay[3];
+      ULONG TickCountPad[1];
+    } DUMMYSTRUCTNAME;
+  } DUMMYUNIONNAME3;
+  ULONG Cookie;
+  ULONG CookiePad[1];
+#if (NTDDI_VERSION >= NTDDI_WS03)
+  LONGLONG ConsoleSessionForegroundProcessId;
+  ULONG Wow64SharedInformation[MAX_WOW64_SHARED_ENTRIES];
+#endif
+#if (NTDDI_VERSION >= NTDDI_VISTA)
+#if (NTDDI_VERSION >= NTDDI_WIN7)
+  USHORT UserModeGlobalLogger[16];
+#else
+  USHORT UserModeGlobalLogger[8];
+  ULONG HeapTracingPid[2];
+  ULONG CritSecTracingPid[2];
+#endif
+  ULONG ImageFileExecutionOptions;
+#if (NTDDI_VERSION >= NTDDI_VISTASP1)
+  ULONG LangGenerationCount;
+#else
+  /* 4 bytes padding */
+#endif
+  ULONGLONG Reserved5;
+  volatile ULONG64 InterruptTimeBias;
+#endif
+#if (NTDDI_VERSION >= NTDDI_WIN7)
+  volatile ULONG64 TscQpcBias;
+  volatile ULONG ActiveProcessorCount;
+  volatile USHORT ActiveGroupCount;
+  USHORT Reserved4;
+  volatile ULONG AitSamplingValue;
+  volatile ULONG AppCompatFlag;
+  ULONGLONG SystemDllNativeRelocation;
+  ULONG SystemDllWowRelocation;
+  ULONG XStatePad[1];
+  XSTATE_CONFIGURATION XState;
+#endif
+} KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
+
+#if (NTDDI_VERSION >= NTDDI_VISTA)
+extern NTSYSAPI volatile CCHAR KeNumberProcessors;
+#elif (NTDDI_VERSION >= NTDDI_WINXP)
+extern NTSYSAPI CCHAR KeNumberProcessors;
+#else
+extern PCCHAR KeNumberProcessors;
+#endif
+
+$endif /* _NTDDK_ */
 
index 35d5aea..bd4a1d2 100644 (file)
@@ -39,6 +39,7 @@
 #include <excpt.h>
 #include <ntdef.h>
 #include <ntstatus.h>
+#include <mce.h>
 
 /* FIXME
 #include <bugcodes.h>
@@ -92,200 +93,6 @@ typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS;
 
 #endif /* _NTIMAGE_ */
 
-#define PsGetCurrentProcess IoGetCurrentProcess
-
-#if (NTDDI_VERSION >= NTDDI_VISTA)
-extern NTSYSAPI volatile CCHAR KeNumberProcessors;
-#elif (NTDDI_VERSION >= NTDDI_WINXP)
-extern NTSYSAPI CCHAR KeNumberProcessors;
-#else
-extern PCCHAR KeNumberProcessors;
-#endif
-
-#include <mce.h>
-
-#ifdef _X86_
-
-#define KERNEL_STACK_SIZE                   12288
-#define KERNEL_LARGE_STACK_SIZE             61440
-#define KERNEL_LARGE_STACK_COMMIT           12288
-
-#define SIZE_OF_80387_REGISTERS   80
-
-#if !defined(RC_INVOKED)
-
-#define CONTEXT_i386               0x10000
-#define CONTEXT_i486               0x10000
-#define CONTEXT_CONTROL            (CONTEXT_i386|0x00000001L)
-#define CONTEXT_INTEGER            (CONTEXT_i386|0x00000002L)
-#define CONTEXT_SEGMENTS           (CONTEXT_i386|0x00000004L)
-#define CONTEXT_FLOATING_POINT     (CONTEXT_i386|0x00000008L)
-#define CONTEXT_DEBUG_REGISTERS    (CONTEXT_i386|0x00000010L)
-#define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386|0x00000020L)
-
-#define CONTEXT_FULL (CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS)
-#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS |  \
-                     CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS |      \
-                     CONTEXT_EXTENDED_REGISTERS)
-
-#define CONTEXT_XSTATE          (CONTEXT_i386 | 0x00000040L)
-
-#endif /* !defined(RC_INVOKED) */
-
-typedef struct _FLOATING_SAVE_AREA {
-  ULONG ControlWord;
-  ULONG StatusWord;
-  ULONG TagWord;
-  ULONG ErrorOffset;
-  ULONG ErrorSelector;
-  ULONG DataOffset;
-  ULONG DataSelector;
-  UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
-  ULONG Cr0NpxState;
-} FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
-
-#include "pshpack4.h"
-typedef struct _CONTEXT {
-  ULONG ContextFlags;
-  ULONG Dr0;
-  ULONG Dr1;
-  ULONG Dr2;
-  ULONG Dr3;
-  ULONG Dr6;
-  ULONG Dr7;
-  FLOATING_SAVE_AREA FloatSave;
-  ULONG SegGs;
-  ULONG SegFs;
-  ULONG SegEs;
-  ULONG SegDs;
-  ULONG Edi;
-  ULONG Esi;
-  ULONG Ebx;
-  ULONG Edx;
-  ULONG Ecx;
-  ULONG Eax;
-  ULONG Ebp;
-  ULONG Eip;
-  ULONG SegCs;
-  ULONG EFlags;
-  ULONG Esp;
-  ULONG SegSs;
-  UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
-} CONTEXT;
-#include "poppack.h"
-
-#endif /* _X86_ */
-
-#ifdef _AMD64_
-
-#define KERNEL_STACK_SIZE 0x6000
-#define KERNEL_LARGE_STACK_SIZE 0x12000
-#define KERNEL_LARGE_STACK_COMMIT KERNEL_STACK_SIZE
-
-#define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
-
-#define EXCEPTION_READ_FAULT    0
-#define EXCEPTION_WRITE_FAULT   1
-#define EXCEPTION_EXECUTE_FAULT 8
-
-#if !defined(RC_INVOKED)
-
-#define CONTEXT_AMD64 0x100000
-
-#define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
-#define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
-#define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
-#define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
-#define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
-
-#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
-#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
-
-#define CONTEXT_XSTATE (CONTEXT_AMD64 | 0x20L)
-
-#define CONTEXT_EXCEPTION_ACTIVE 0x8000000
-#define CONTEXT_SERVICE_ACTIVE 0x10000000
-#define CONTEXT_EXCEPTION_REQUEST 0x40000000
-#define CONTEXT_EXCEPTION_REPORTING 0x80000000
-
-#endif /* !defined(RC_INVOKED) */
-
-#define INITIAL_MXCSR                  0x1f80
-#define INITIAL_FPCSR                  0x027f
-
-typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
-  ULONG64 P1Home;
-  ULONG64 P2Home;
-  ULONG64 P3Home;
-  ULONG64 P4Home;
-  ULONG64 P5Home;
-  ULONG64 P6Home;
-  ULONG ContextFlags;
-  ULONG MxCsr;
-  USHORT SegCs;
-  USHORT SegDs;
-  USHORT SegEs;
-  USHORT SegFs;
-  USHORT SegGs;
-  USHORT SegSs;
-  ULONG EFlags;
-  ULONG64 Dr0;
-  ULONG64 Dr1;
-  ULONG64 Dr2;
-  ULONG64 Dr3;
-  ULONG64 Dr6;
-  ULONG64 Dr7;
-  ULONG64 Rax;
-  ULONG64 Rcx;
-  ULONG64 Rdx;
-  ULONG64 Rbx;
-  ULONG64 Rsp;
-  ULONG64 Rbp;
-  ULONG64 Rsi;
-  ULONG64 Rdi;
-  ULONG64 R8;
-  ULONG64 R9;
-  ULONG64 R10;
-  ULONG64 R11;
-  ULONG64 R12;
-  ULONG64 R13;
-  ULONG64 R14;
-  ULONG64 R15;
-  ULONG64 Rip;
-  union {
-    XMM_SAVE_AREA32 FltSave;
-    struct {
-      M128A Header[2];
-      M128A Legacy[8];
-      M128A Xmm0;
-      M128A Xmm1;
-      M128A Xmm2;
-      M128A Xmm3;
-      M128A Xmm4;
-      M128A Xmm5;
-      M128A Xmm6;
-      M128A Xmm7;
-      M128A Xmm8;
-      M128A Xmm9;
-      M128A Xmm10;
-      M128A Xmm11;
-      M128A Xmm12;
-      M128A Xmm13;
-      M128A Xmm14;
-      M128A Xmm15;
-    } DUMMYSTRUCTNAME;
-  } DUMMYUNIONNAME;
-  M128A VectorRegister[26];
-  ULONG64 VectorControl;
-  ULONG64 DebugControl;
-  ULONG64 LastBranchToRip;
-  ULONG64 LastBranchFromRip;
-  ULONG64 LastExceptionToRip;
-  ULONG64 LastExceptionFromRip;
-} CONTEXT;
-
-#endif /* _AMD64_ */
-
 $define (_NTDDK_)
 $include (extypes.h)
 $include (iotypes.h)
@@ -297,6 +104,24 @@ $include (pstypes.h)
 $include (rtltypes.h)
 $include (setypes.h)
 
+#if defined(_M_IX86)
+$include(x86/ke.h)
+$include(x86/mm.h)
+#elif defined(_M_AMD64)
+$include(amd64/ke.h)
+$include(amd64/mm.h)
+#elif defined(_M_IA64)
+$include(ia64/ke.h)
+#elif defined(_M_PPC)
+$include(ppc/ke.h)
+#elif defined(_M_MIPS)
+$include(mips/ke.h)
+#elif defined(_M_ARM)
+$include(arm/ke.h)
+#else
+#error Unknown Architecture
+#endif
+
 $include (exfuncs.h)
 $include (halfuncs.h)
 $include (iofuncs.h)
@@ -532,8 +357,6 @@ typedef struct _DRIVER_VERIFIER_THUNK_PAIRS {
 #define DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS      0x0008
 #define DRIVER_VERIFIER_IO_CHECKING                 0x0010
 
-#define MAX_WOW64_SHARED_ENTRIES 16
-
 #define NX_SUPPORT_POLICY_ALWAYSOFF 0
 #define NX_SUPPORT_POLICY_ALWAYSON 1
 #define NX_SUPPORT_POLICY_OPTIN 2
@@ -573,120 +396,6 @@ typedef struct _DRIVER_VERIFIER_THUNK_PAIRS {
 #define EX_TEST_CLEAR_BIT(Flags, Bit) \
     InterlockedBitTestAndReset ((PLONG)(Flags), (Bit))
 
-typedef struct _KUSER_SHARED_DATA {
-  ULONG TickCountLowDeprecated;
-  ULONG TickCountMultiplier;
-  volatile KSYSTEM_TIME InterruptTime;
-  volatile KSYSTEM_TIME SystemTime;
-  volatile KSYSTEM_TIME TimeZoneBias;
-  USHORT ImageNumberLow;
-  USHORT ImageNumberHigh;
-  WCHAR NtSystemRoot[260];
-  ULONG MaxStackTraceDepth;
-  ULONG CryptoExponent;
-  ULONG TimeZoneId;
-  ULONG LargePageMinimum;
-  ULONG Reserved2[7];
-  NT_PRODUCT_TYPE NtProductType;
-  BOOLEAN ProductTypeIsValid;
-  ULONG NtMajorVersion;
-  ULONG NtMinorVersion;
-  BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
-  ULONG Reserved1;
-  ULONG Reserved3;
-  volatile ULONG TimeSlip;
-  ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
-  ULONG AltArchitecturePad[1];
-  LARGE_INTEGER SystemExpirationDate;
-  ULONG SuiteMask;
-  BOOLEAN KdDebuggerEnabled;
-#if (NTDDI_VERSION >= NTDDI_WINXPSP2)
-  UCHAR NXSupportPolicy;
-#endif
-  volatile ULONG ActiveConsoleId;
-  volatile ULONG DismountCount;
-  ULONG ComPlusPackage;
-  ULONG LastSystemRITEventTickCount;
-  ULONG NumberOfPhysicalPages;
-  BOOLEAN SafeBootMode;
-#if (NTDDI_VERSION >= NTDDI_WIN7)
-  union {
-    UCHAR TscQpcData;
-    struct {
-      UCHAR TscQpcEnabled:1;
-      UCHAR TscQpcSpareFlag:1;
-      UCHAR TscQpcShift:6;
-    } DUMMYSTRUCTNAME;
-  } DUMMYUNIONNAME;
-  UCHAR TscQpcPad[2];
-#endif
-#if (NTDDI_VERSION >= NTDDI_VISTA)
-  union {
-    ULONG SharedDataFlags;
-    struct {
-      ULONG DbgErrorPortPresent:1;
-      ULONG DbgElevationEnabled:1;
-      ULONG DbgVirtEnabled:1;
-      ULONG DbgInstallerDetectEnabled:1;
-      ULONG DbgSystemDllRelocated:1;
-      ULONG DbgDynProcessorEnabled:1;
-      ULONG DbgSEHValidationEnabled:1;
-      ULONG SpareBits:25;
-    } DUMMYSTRUCTNAME2;
-  } DUMMYUNIONNAME2;
-#else
-  ULONG TraceLogging;
-#endif
-  ULONG DataFlagsPad[1];
-  ULONGLONG TestRetInstruction;
-  ULONG SystemCall;
-  ULONG SystemCallReturn;
-  ULONGLONG SystemCallPad[3];
-  _ANONYMOUS_UNION union {
-    volatile KSYSTEM_TIME TickCount;
-    volatile ULONG64 TickCountQuad;
-    _ANONYMOUS_STRUCT struct {
-      ULONG ReservedTickCountOverlay[3];
-      ULONG TickCountPad[1];
-    } DUMMYSTRUCTNAME;
-  } DUMMYUNIONNAME3;
-  ULONG Cookie;
-  ULONG CookiePad[1];
-#if (NTDDI_VERSION >= NTDDI_WS03)
-  LONGLONG ConsoleSessionForegroundProcessId;
-  ULONG Wow64SharedInformation[MAX_WOW64_SHARED_ENTRIES];
-#endif
-#if (NTDDI_VERSION >= NTDDI_VISTA)
-#if (NTDDI_VERSION >= NTDDI_WIN7)
-  USHORT UserModeGlobalLogger[16];
-#else
-  USHORT UserModeGlobalLogger[8];
-  ULONG HeapTracingPid[2];
-  ULONG CritSecTracingPid[2];
-#endif
-  ULONG ImageFileExecutionOptions;
-#if (NTDDI_VERSION >= NTDDI_VISTASP1)
-  ULONG LangGenerationCount;
-#else
-  /* 4 bytes padding */
-#endif
-  ULONGLONG Reserved5;
-  volatile ULONG64 InterruptTimeBias;
-#endif
-#if (NTDDI_VERSION >= NTDDI_WIN7)
-  volatile ULONG64 TscQpcBias;
-  volatile ULONG ActiveProcessorCount;
-  volatile USHORT ActiveGroupCount;
-  USHORT Reserved4;
-  volatile ULONG AitSamplingValue;
-  volatile ULONG AppCompatFlag;
-  ULONGLONG SystemDllNativeRelocation;
-  ULONG SystemDllWowRelocation;
-  ULONG XStatePad[1];
-  XSTATE_CONFIGURATION XState;
-#endif
-} KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
-
 #define CmResourceTypeMaximum             8
 
 typedef struct _CM_PCCARD_DEVICE_DATA {
@@ -710,12 +419,6 @@ typedef struct _CM_PCCARD_DEVICE_DATA {
 #define PCCARD_DUP_LEGACY_BASE         0x06
 #define PCCARD_NO_CONTROLLERS          0x07
 
-#if defined(_X86_) || defined(_AMD64_)
-#define PAUSE_PROCESSOR YieldProcessor();
-#elif defined(_IA64_)
-#define PAUSE_PROCESSOR __yield();
-#endif
-
 #define MAXIMUM_EXPANSION_SIZE (KERNEL_LARGE_STACK_SIZE - (PAGE_SIZE / 2))
 
 /* Filesystem runtime library routines */
@@ -730,189 +433,6 @@ FsRtlIsTotalDeviceFailure(
 
 /* FIXME : These definitions below doesn't belong to NTDDK */
 
-#ifdef _X86_
-
-extern NTKERNELAPI PVOID MmHighestUserAddress;
-extern NTKERNELAPI PVOID MmSystemRangeStart;
-extern NTKERNELAPI ULONG MmUserProbeAddress;
-
-#define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
-#define MM_SYSTEM_RANGE_START MmSystemRangeStart
-#if defined(_LOCAL_COPY_USER_PROBE_ADDRESS_)
-#define MM_USER_PROBE_ADDRESS _LOCAL_COPY_USER_PROBE_ADDRESS_
-extern ULONG _LOCAL_COPY_USER_PROBE_ADDRESS_;
-#else
-#define MM_USER_PROBE_ADDRESS MmUserProbeAddress
-#endif
-#define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
-#define MM_KSEG0_BASE       MM_SYSTEM_RANGE_START
-#define MM_SYSTEM_SPACE_END 0xFFFFFFFF
-#if !defined (_X86PAE_)
-#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
-#else
-#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
-#endif
-
-#define KeGetPcr()                      PCR
-
-#define PCR_MINOR_VERSION 1
-#define PCR_MAJOR_VERSION 1
-
-typedef struct _KPCR {
-  union {
-    NT_TIB NtTib;
-    struct {
-      struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
-      PVOID Used_StackBase;
-      PVOID Spare2;
-      PVOID TssCopy;
-      ULONG ContextSwitches;
-      KAFFINITY SetMemberCopy;
-      PVOID Used_Self;
-    };
-  };
-  struct _KPCR *SelfPcr;
-  struct _KPRCB *Prcb;
-  KIRQL Irql;
-  ULONG IRR;
-  ULONG IrrActive;
-  ULONG IDR;
-  PVOID KdVersionBlock;
-  struct _KIDTENTRY *IDT;
-  struct _KGDTENTRY *GDT;
-  struct _KTSS *TSS;
-  USHORT MajorVersion;
-  USHORT MinorVersion;
-  KAFFINITY SetMember;
-  ULONG StallScaleFactor;
-  UCHAR SpareUnused;
-  UCHAR Number;
-  UCHAR Spare0;
-  UCHAR SecondLevelCacheAssociativity;
-  ULONG VdmAlert;
-  ULONG KernelReserved[14];
-  ULONG SecondLevelCacheSize;
-  ULONG HalReserved[16];
-} KPCR, *PKPCR;
-
-FORCEINLINE
-ULONG
-KeGetCurrentProcessorNumber(VOID)
-{
-    return (ULONG)__readfsbyte(FIELD_OFFSET(KPCR, Number));
-}
-
-typedef enum _INTERLOCKED_RESULT {
-  ResultNegative = RESULT_NEGATIVE,
-  ResultZero = RESULT_ZERO,
-  ResultPositive = RESULT_POSITIVE
-} INTERLOCKED_RESULT;
-
-NTKERNELAPI
-INTERLOCKED_RESULT
-FASTCALL
-Exfi386InterlockedIncrementLong(
-  IN OUT LONG volatile *Addend);
-
-NTKERNELAPI
-INTERLOCKED_RESULT
-FASTCALL
-Exfi386InterlockedDecrementLong(
-  IN PLONG  Addend);
-
-NTKERNELAPI
-ULONG
-FASTCALL
-Exfi386InterlockedExchangeUlong(
-  IN PULONG  Target,
-  IN ULONG  Value);
-
-#endif /* _X86_ */
-
-#ifdef _AMD64_
-
-#define PTI_SHIFT  12L
-#define PDI_SHIFT  21L
-#define PPI_SHIFT  30L
-#define PXI_SHIFT  39L
-#define PTE_PER_PAGE 512
-#define PDE_PER_PAGE 512
-#define PPE_PER_PAGE 512
-#define PXE_PER_PAGE 512
-#define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
-#define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
-#define PPI_MASK (PPE_PER_PAGE - 1)
-#define PXI_MASK (PXE_PER_PAGE - 1)
-
-#define PXE_BASE    0xFFFFF6FB7DBED000ULL
-#define PXE_SELFMAP 0xFFFFF6FB7DBEDF68ULL
-#define PPE_BASE    0xFFFFF6FB7DA00000ULL
-#define PDE_BASE    0xFFFFF6FB40000000ULL
-#define PTE_BASE    0xFFFFF68000000000ULL
-#define PXE_TOP     0xFFFFF6FB7DBEDFFFULL
-#define PPE_TOP     0xFFFFF6FB7DBFFFFFULL
-#define PDE_TOP     0xFFFFF6FB7FFFFFFFULL
-#define PTE_TOP     0xFFFFF6FFFFFFFFFFULL
-
-#define MM_HIGHEST_USER_ADDRESS           MmHighestUserAddress
-#define MM_SYSTEM_RANGE_START             MmSystemRangeStart
-#define MM_USER_PROBE_ADDRESS             MmUserProbeAddress
-#define MM_LOWEST_USER_ADDRESS   (PVOID)0x10000
-#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000ULL
-#define KI_USER_SHARED_DATA       0xFFFFF78000000000ULL
-
-typedef struct _KPCR
-{
-    _ANONYMOUS_UNION union
-    {
-        NT_TIB NtTib;
-        _ANONYMOUS_STRUCT struct
-        {
-            union _KGDTENTRY64 *GdtBase;
-            struct _KTSS64 *TssBase;
-            ULONG64 UserRsp;
-            struct _KPCR *Self;
-            struct _KPRCB *CurrentPrcb;
-            PKSPIN_LOCK_QUEUE LockArray;
-            PVOID Used_Self;
-        };
-    };
-    union _KIDTENTRY64 *IdtBase;
-    ULONG64 Unused[2];
-    KIRQL Irql;
-    UCHAR SecondLevelCacheAssociativity;
-    UCHAR ObsoleteNumber;
-    UCHAR Fill0;
-    ULONG Unused0[3];
-    USHORT MajorVersion;
-    USHORT MinorVersion;
-    ULONG StallScaleFactor;
-    PVOID Unused1[3];
-    ULONG KernelReserved[15];
-    ULONG SecondLevelCacheSize;
-    ULONG HalReserved[16];
-    ULONG Unused2;
-    PVOID KdVersionBlock;
-    PVOID Unused3;
-    ULONG PcrAlign1[24];
-} KPCR, *PKPCR;
-
-FORCEINLINE
-PKPCR
-KeGetPcr(VOID)
-{
-    return (PKPCR)__readgsqword(FIELD_OFFSET(KPCR, Self));
-}
-
-FORCEINLINE
-ULONG
-KeGetCurrentProcessorNumber(VOID)
-{
-    return (ULONG)__readgsword(0x184);
-}
-
-#endif /* _AMD64_ */
-
 #ifdef __cplusplus
 }
 #endif
index ad34371..b210804 100644 (file)
@@ -154,6 +154,130 @@ _KeQueryTickCount(
 }
 #define KeQueryTickCount(CurrentCount) _KeQueryTickCount(CurrentCount)
 
-$endif
+$endif /* _WDMDDK_ */
+$if (_NTDDK_)
+
+#define PAUSE_PROCESSOR YieldProcessor();
+
+#define KERNEL_STACK_SIZE                   12288
+#define KERNEL_LARGE_STACK_SIZE             61440
+#define KERNEL_LARGE_STACK_COMMIT           12288
+
+#define SIZE_OF_80387_REGISTERS   80
+
+#if !defined(RC_INVOKED)
+
+#define CONTEXT_i386               0x10000
+#define CONTEXT_i486               0x10000
+#define CONTEXT_CONTROL            (CONTEXT_i386|0x00000001L)
+#define CONTEXT_INTEGER            (CONTEXT_i386|0x00000002L)
+#define CONTEXT_SEGMENTS           (CONTEXT_i386|0x00000004L)
+#define CONTEXT_FLOATING_POINT     (CONTEXT_i386|0x00000008L)
+#define CONTEXT_DEBUG_REGISTERS    (CONTEXT_i386|0x00000010L)
+#define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386|0x00000020L)
+
+#define CONTEXT_FULL (CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS)
+#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS |  \
+                     CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS |      \
+                     CONTEXT_EXTENDED_REGISTERS)
+
+#define CONTEXT_XSTATE          (CONTEXT_i386 | 0x00000040L)
+
+#endif /* !defined(RC_INVOKED) */
+
+typedef struct _FLOATING_SAVE_AREA {
+  ULONG ControlWord;
+  ULONG StatusWord;
+  ULONG TagWord;
+  ULONG ErrorOffset;
+  ULONG ErrorSelector;
+  ULONG DataOffset;
+  ULONG DataSelector;
+  UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
+  ULONG Cr0NpxState;
+} FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
+
+#include "pshpack4.h"
+typedef struct _CONTEXT {
+  ULONG ContextFlags;
+  ULONG Dr0;
+  ULONG Dr1;
+  ULONG Dr2;
+  ULONG Dr3;
+  ULONG Dr6;
+  ULONG Dr7;
+  FLOATING_SAVE_AREA FloatSave;
+  ULONG SegGs;
+  ULONG SegFs;
+  ULONG SegEs;
+  ULONG SegDs;
+  ULONG Edi;
+  ULONG Esi;
+  ULONG Ebx;
+  ULONG Edx;
+  ULONG Ecx;
+  ULONG Eax;
+  ULONG Ebp;
+  ULONG Eip;
+  ULONG SegCs;
+  ULONG EFlags;
+  ULONG Esp;
+  ULONG SegSs;
+  UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
+} CONTEXT;
+#include "poppack.h"
+
+#define KeGetPcr()                      PCR
+
+#define PCR_MINOR_VERSION 1
+#define PCR_MAJOR_VERSION 1
+
+typedef struct _KPCR {
+  union {
+    NT_TIB NtTib;
+    struct {
+      struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
+      PVOID Used_StackBase;
+      PVOID Spare2;
+      PVOID TssCopy;
+      ULONG ContextSwitches;
+      KAFFINITY SetMemberCopy;
+      PVOID Used_Self;
+    };
+  };
+  struct _KPCR *SelfPcr;
+  struct _KPRCB *Prcb;
+  KIRQL Irql;
+  ULONG IRR;
+  ULONG IrrActive;
+  ULONG IDR;
+  PVOID KdVersionBlock;
+  struct _KIDTENTRY *IDT;
+  struct _KGDTENTRY *GDT;
+  struct _KTSS *TSS;
+  USHORT MajorVersion;
+  USHORT MinorVersion;
+  KAFFINITY SetMember;
+  ULONG StallScaleFactor;
+  UCHAR SpareUnused;
+  UCHAR Number;
+  UCHAR Spare0;
+  UCHAR SecondLevelCacheAssociativity;
+  ULONG VdmAlert;
+  ULONG KernelReserved[14];
+  ULONG SecondLevelCacheSize;
+  ULONG HalReserved[16];
+} KPCR, *PKPCR;
+
+FORCEINLINE
+ULONG
+KeGetCurrentProcessorNumber(VOID)
+{
+    return (ULONG)__readfsbyte(FIELD_OFFSET(KPCR, Number));
+}
+
+$endif /* _NTDDK_ */
+
+
 
 
diff --git a/include/xdk/x86/mm.h b/include/xdk/x86/mm.h
new file mode 100644 (file)
index 0000000..d2cddd1
--- /dev/null
@@ -0,0 +1,24 @@
+$if (_NTDDK_)
+
+extern NTKERNELAPI PVOID MmHighestUserAddress;
+extern NTKERNELAPI PVOID MmSystemRangeStart;
+extern NTKERNELAPI ULONG MmUserProbeAddress;
+
+#define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
+#define MM_SYSTEM_RANGE_START MmSystemRangeStart
+#if defined(_LOCAL_COPY_USER_PROBE_ADDRESS_)
+#define MM_USER_PROBE_ADDRESS _LOCAL_COPY_USER_PROBE_ADDRESS_
+extern ULONG _LOCAL_COPY_USER_PROBE_ADDRESS_;
+#else
+#define MM_USER_PROBE_ADDRESS MmUserProbeAddress
+#endif
+#define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
+#define MM_KSEG0_BASE       MM_SYSTEM_RANGE_START
+#define MM_SYSTEM_SPACE_END 0xFFFFFFFF
+#if !defined (_X86PAE_)
+#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
+#else
+#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
+#endif
+
+$endif /* _NTDDK_ */