//
//#define K0IPCR ((ULONG_PTR)(KIP0PCRADDRESS))
//#define PCR ((volatile KPCR * const)K0IPCR)
-#define PCR 0 // HACK
+#define PCR ((volatile KPCR * const)__readgsqword(FIELD_OFFSET(KPCR, Self)))
//#if defined(CONFIG_SMP) || defined(NT_BUILD)
//#undef KeGetPcr
//#define KeGetPcr() ((volatile KPCR * const)__readfsdword(0x1C))
//
#define RPL_MASK 0x0003
#define MODE_MASK 0x0001
-#define KGDT_R0_CODE 0x8
-#define KGDT_R0_DATA 0x10
-#define KGDT_R3_CODE 0x18
-#define KGDT_R3_DATA 0x20
-#define KGDT_TSS 0x28
-#define KGDT_R0_PCR 0x30
-#define KGDT_R3_TEB 0x38
-#define KGDT_LDT 0x48
-#define KGDT_DF_TSS 0x50
-#define KGDT_NMI_TSS 0x58
+#define KGDT64_NULL 0x0000
+#define KGDT64_R0_CODE 0x0010
+#define KGDT64_R0_DATA 0x0018
+#define KGDT64_R3_CMCODE 0x0020
+#define KGDT64_R3_DATA 0x0028
+#define KGDT64_R3_CODE 0x0030
+#define KGDT64_SYS_TSS 0x0040
+#define KGDT64_R3_CMTEB 0x0050
+
//
// CR4
//
// HAL Variables
//
-#define INITIAL_STALL_COUNT 0x64
+#define INITIAL_STALL_COUNT 100
//
// IOPM Definitions
#ifndef CONFIG_SMP
#define SYNCH_LEVEL DISPATCH_LEVEL
#else
-#define SYNCH_LEVEL (IPI_LEVEL - 1)
+#define SYNCH_LEVEL (IPI_LEVEL - 2)
#endif
//
UINT64 R9;
UINT64 R10;
UINT64 R11;
- UINT64 GsBase;
- UINT64 GsSwap;
+ union
+ {
+ UINT64 GsBase;
+ UINT64 GsSwap;
+ };
M128A Xmm0;
M128A Xmm1;
M128A Xmm2;
M128A Xmm3;
M128A Xmm4;
M128A Xmm5;
- UINT64 FaultAddress;
- UINT64 ContextRecord;
- UINT64 TimeStampCKCL;
+ union
+ {
+ UINT64 FaultAddress;
+ UINT64 ContextRecord;
+ UINT64 TimeStampCKCL;
+ };
UINT64 Dr0;
UINT64 Dr1;
UINT64 Dr2;
UINT64 Dr3;
UINT64 Dr6;
UINT64 Dr7;
- UINT64 DebugControl;
- UINT64 LastBranchToRip;
- UINT64 LastBranchFromRip;
- UINT64 LastExceptionToRip;
- UINT64 LastExceptionFromRip;
- UINT64 LastBranchControl;
- ULONG LastBranchMSR;
+ union
+ {
+ struct
+ {
+ UINT64 DebugControl;
+ UINT64 LastBranchToRip;
+ UINT64 LastBranchFromRip;
+ UINT64 LastExceptionToRip;
+ UINT64 LastExceptionFromRip;
+ };
+ struct
+ {
+ UINT64 LastBranchControl;
+ ULONG LastBranchMSR;
+ };
+ };
USHORT SegDs;
USHORT SegEs;
USHORT SegFs;
UINT64 Rdi;
UINT64 Rsi;
UINT64 Rbp;
- UINT64 ErrorCode;
- UINT64 ExceptionFrame;
- UINT64 TimeStampKlog;
+ union
+ {
+ UINT64 ErrorCode;
+ UINT64 ExceptionFrame;
+ UINT64 TimeStampKlog;
+ };
UINT64 Rip;
USHORT SegCs;
UCHAR Fill0;
} KTRAP_FRAME, *PKTRAP_FRAME;
//
-// LDT Entry Definition
+// Defines the Callback Stack Layout for User Mode Callbacks
//
-#ifndef _LDT_ENTRY_DEFINED
-#define _LDT_ENTRY_DEFINED
-typedef struct _LDT_ENTRY
+typedef struct _KCALLOUT_FRAME
{
- USHORT LimitLow;
- USHORT BaseLow;
- union
- {
- struct
- {
- UCHAR BaseMid;
- UCHAR Flags1;
- UCHAR Flags2;
- UCHAR BaseHi;
- } Bytes;
- struct
- {
- ULONG BaseMid:8;
- ULONG Type:5;
- ULONG Dpl:2;
- ULONG Pres:1;
- ULONG LimitHi:4;
- ULONG Sys:1;
- ULONG Reserved_0:1;
- ULONG Default_Big:1;
- ULONG Granularity:1;
- ULONG BaseHi:8;
- } Bits;
- } HighWord;
-} LDT_ENTRY, *PLDT_ENTRY, *LPLDT_ENTRY;
-#endif
+ ULONG64 InitialStack;
+ ULONG64 TrapFrame;
+ ULONG64 CallbackStack;
+ ULONG64 Rdi;
+ ULONG64 Rsi;
+ ULONG64 Rbx;
+ ULONG64 Rbp;
+ ULONG64 ReturnAddress;
+ ULONG64 Result;
+ ULONG64 ResultLength;
+} KCALLOUT_FRAME, *PKCALLOUT_FRAME;
+
+//
+// Dummy LDT_ENTRY
+//
+typedef ULONG LDT_ENTRY;
//
// GDT Entry Definition
CONTEXT ContextFrame;
} KPROCESSOR_STATE, *PKPROCESSOR_STATE;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
typedef struct _GENERAL_LOOKASIDE_POOL
{
union
};
ULONG Future[2];
} GENERAL_LOOKASIDE_POOL, *PGENERAL_LOOKASIDE_POOL;
+#else
+#define GENERAL_LOOKASIDE_POOL PP_LOOKASIDE_LIST
+#endif
typedef struct _KREQUEST_PACKET
{
typedef struct _KPRCB
{
ULONG MxCsr;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
USHORT Number;
+#else
+ UCHAR Number;
+ UCHAR NestingLevel;
+#endif
UCHAR InterruptRequest;
UCHAR IdleHalt;
struct _KTHREAD *CurrentThread;
struct _KTHREAD *NextThread;
struct _KTHREAD *IdleThread;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
UCHAR NestingLevel;
UCHAR Group;
UCHAR PrcbPad00[6];
+#else
+ UINT64 UserRsp;
+#endif
UINT64 RspBase;
UINT64 PrcbLock;
UINT64 SetMember;
KPROCESSOR_STATE ProcessorState;
- UCHAR CpuType;
- UCHAR CpuID;
+ CHAR CpuType;
+ CHAR CpuID;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
+ union
+ {
+ USHORT CpuStep;
+ struct
+ {
+ UCHAR CpuStepping;
+ UCHAR CpuModel;
+ };
+ };
+#else
USHORT CpuStep;
- UCHAR CpuStepping;
- UCHAR CpuModel;
+#endif
ULONG MHz;
UINT64 HalReserved[8];
USHORT MinorVersion;
USHORT MajorVersion;
UCHAR BuildType;
UCHAR CpuVendor;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
UCHAR CoresPerPhysicalProcessor;
UCHAR LogicalProcessorsPerCore;
+#else
+ UCHAR InitialApicId;
+ UCHAR LogicalProcessorsPerPhysicalProcessor;
+#endif
ULONG ApicMask;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
ULONG CFlushSize;
+#else
+ UCHAR CFlushSize;
+ UCHAR PrcbPad0x[3];
+#endif
PVOID AcpiReserved;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
ULONG InitialApicId;
ULONG Stride;
UINT64 PrcbPad01[3];
- KSPIN_LOCK_QUEUE LockQueue[LockQueueMaximumLock];
+#else
+ UINT64 PrcbPad00[4];
+#endif
+ KSPIN_LOCK_QUEUE LockQueue[LockQueueMaximumLock]; // 2003: 33, vista:49
PP_LOOKASIDE_LIST PPLookasideList[16];
GENERAL_LOOKASIDE_POOL PPNPagedLookasideList[32];
GENERAL_LOOKASIDE_POOL PPPagedLookasideList[32];
LONG MmPageFaultCount;
LONG MmCopyOnWriteCount;
LONG MmTransitionCount;
+#if (NTDDI_VERSION < NTDDI_LONGHORN)
+ LONG MmCacheTransitionCount;
+#endif
LONG MmDemandZeroCount;
LONG MmPageReadCount;
LONG MmPageReadIoCount;
+#if (NTDDI_VERSION < NTDDI_LONGHORN)
+ LONG MmCacheReadCount;
+ LONG MmCacheIoCount;
+#endif
LONG MmDirtyPagesWriteCount;
LONG MmDirtyWriteIoCount;
LONG MmMappedPagesWriteCount;
LONG MmMappedWriteIoCount;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
ULONG KeSystemCalls;
ULONG KeContextSwitches;
ULONG CcFastReadNoWait;
ULONG CcCopyReadWait;
ULONG CcCopyReadNoWaitMiss;
LONG LookasideIrpFloat;
+#else
+ LONG LookasideIrpFloat;
+ ULONG KeSystemCalls;
+#endif
LONG IoReadOperationCount;
LONG IoWriteOperationCount;
LONG IoOtherOperationCount;
LARGE_INTEGER IoReadTransferCount;
LARGE_INTEGER IoWriteTransferCount;
LARGE_INTEGER IoOtherTransferCount;
+#if (NTDDI_VERSION < NTDDI_LONGHORN)
+ ULONG KeContextSwitches;
+ UCHAR PrcbPad2[12];
+#endif
UINT64 TargetSet;
ULONG IpiFrozen;
UCHAR PrcbPad3[116];
UCHAR PrcbPad4[120];
KDPC_DATA DpcData[2];
PVOID DpcStack;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
PVOID SparePtr0;
+#else
+ PVOID SavedRsp;
+#endif
LONG MaximumDpcQueueDepth;
ULONG DpcRequestRate;
ULONG MinimumDpcRate;
UCHAR PrcbPad50;
UCHAR IdleSchedule;
LONG DpcSetEventRequest;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
ULONG KeExceptionDispatchCount;
+#else
+ LONG PrcbPad40;
+ PVOID DpcThread;
+#endif
KEVENT DpcEvent;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
PVOID PrcbPad51;
+#endif
KDPC CallDpc;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
LONG ClockKeepAlive;
UCHAR ClockCheckSlot;
UCHAR ClockPollCycle;
LONG DpcWatchdogPeriod;
LONG DpcWatchdogCount;
UINT64 PrcbPad70[2];
+#else
+ UINT64 PrcbPad7[4];
+#endif
LIST_ENTRY WaitListHead;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
UINT64 WaitLock;
+#endif
ULONG ReadySummary;
ULONG QueueIndex;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
UINT64 PrcbPad71[12];
+#endif
LIST_ENTRY DispatcherReadyListHead[32];
ULONG InterruptCount;
ULONG KernelTime;
UCHAR SkipTick;
UCHAR DebuggerSavedIRQL;
UCHAR PollSlot;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
UCHAR PrcbPad80[5];
ULONG DpcTimeCount;
ULONG DpcTimeLimit;
ULONG PeriodicCount;
ULONG PeriodicBias;
UINT64 PrcbPad81[2];
+#else
+ UCHAR PrcbPad8[13];
+#endif
struct _KNODE *ParentNode;
UINT64 MultiThreadProcessorSet;
struct _KPRCB *MultiThreadSetMaster;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
UINT64 StartCycles;
LONG MmSpinLockOrdering;
ULONG PageColor;
ULONG NodeColor;
ULONG NodeShiftedColor;
ULONG SecondaryColorMask;
+#endif
LONG Sleeping;
+#if (NTDDI_VERSION >= NTDDI_LONGHORN)
UINT64 CycleTime;
ULONG CcFastMdlReadNoWait;
ULONG CcFastMdlReadWait;
UINT64 CacheProcessorMask[5];
UINT64 PackageProcessorSet;
UINT64 CoreProcessorSet;
+#else
+ ULONG PrcbPad90[1];
+ ULONG DebugDpcTime;
+ ULONG PageColor;
+ ULONG NodeColor;
+ ULONG NodeShiftedColor;
+ ULONG SecondaryColorMask;
+ UCHAR PrcbPad9[12];
+ ULONG CcFastReadNoWait;
+ ULONG CcFastReadWait;
+ ULONG CcFastReadNotPossible;
+ ULONG CcCopyReadNoWait;
+ ULONG CcCopyReadWait;
+ ULONG CcCopyReadNoWaitMiss;
+ ULONG KeAlignmentFixupCount;
+ ULONG KeDcacheFlushCount;
+ ULONG KeExceptionDispatchCount;
+ ULONG KeFirstLevelTbFills;
+ ULONG KeFloatingEmulationCount;
+ ULONG KeIcacheFlushCount;
+ ULONG KeSecondLevelTbFills;
+ UCHAR VendorString[13];
+ UCHAR PrcbPad10[2];
+ ULONG FeatureBits;
+ LARGE_INTEGER UpdateSignature;
+ PROCESSOR_POWER_STATE PowerState;
+ CACHE_DESCRIPTOR Cache[5];
+ ULONG CacheCount;
+#endif
}
KPRCB, *PKPRCB;
PVOID KdVersionBlock; // 0x108
PVOID Unused3;
ULONG PcrAlign1[24];
-
- ULONG Fill2; // 0x178
- KPRCB Prcb;
+ ULONG Fill2[2]; // 0x178
+ KPRCB Prcb; // 0x180
// hack:
ULONG ContextSwitches;
UCHAR IoMap[8196];
} KIIO_ACCESS_MAP;
-typedef struct _KTSS
+
+#pragma pack(push,4)
+typedef struct _KTSS64
{
- USHORT Backlink;
- USHORT Reserved0;
- ULONG Esp0;
- USHORT Ss0;
- USHORT Reserved1;
- ULONG NotUsed1[4];
- ULONG CR3;
- ULONG Eip;
- ULONG EFlags;
- ULONG Eax;
- ULONG Ecx;
- ULONG Edx;
- ULONG Ebx;
- ULONG Esp;
- ULONG Ebp;
- ULONG Esi;
- ULONG Edi;
- USHORT Es;
- USHORT Reserved2;
- USHORT Cs;
- USHORT Reserved3;
- USHORT Ss;
- USHORT Reserved4;
- USHORT Ds;
- USHORT Reserved5;
- USHORT Fs;
- USHORT Reserved6;
- USHORT Gs;
- USHORT Reserved7;
- USHORT LDT;
- USHORT Reserved8;
- USHORT Flags;
- USHORT IoMapBase;
- KIIO_ACCESS_MAP IoMaps[1];
- UCHAR IntDirectionMap[32];
-} KTSS, *PKTSS;
+ /* 000 */ ULONG Reserved0;
+ /* 004 */ UINT64 Rsp0;
+ /* 00c */ UINT64 Rsp1;
+ /* 014 */ UINT64 Rsp2;
+ /* 01c */ UINT64 Ist[8];
+ /* 05c */ UINT64 Reserved1;
+ /* 064 */ USHORT Reserved2;
+ /* 066 */ USHORT IoMapBase;
+} KTSS64, *PKTSS64;
+#pragma pack(pop)
+#define KTSS KTSS64
+#define PKTSS PKTSS64
//
// i386 CPUs don't have exception frames
typedef struct _KEXCEPTION_FRAME KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
//
-// Macro to get current KPRCB
+// Inline function to get current KPRCB
//
FORCEINLINE
struct _KPRCB *
KeGetCurrentPrcb(VOID)
{
- return (struct _KPRCB *)(ULONG_PTR)__readgsqword(FIELD_OFFSET(KIPCR, Prcb));
+ return (struct _KPRCB *)__readgsqword(FIELD_OFFSET(KIPCR, CurrentPrcb));
}
#endif