From 946f17e93d48b62821cd0a9ddb48b82a9ed4844e Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Wed, 7 Dec 2022 20:50:34 +0200 Subject: [PATCH] [NTOS] Fix x64 definition of MMPFN Adjust the definition of COLORED_LIST_HEAD to always match the new MI_PTE_FRAME_BITS define. --- ntoskrnl/include/internal/mm.h | 11 ++++++++++- ntoskrnl/mm/ARM3/miarm.h | 14 ++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ntoskrnl/include/internal/mm.h b/ntoskrnl/include/internal/mm.h index 8f541fc2648..7ee98a4c77f 100644 --- a/ntoskrnl/include/internal/mm.h +++ b/ntoskrnl/include/internal/mm.h @@ -380,6 +380,12 @@ typedef struct _MMPFNENTRY USHORT ParityError:1; } MMPFNENTRY; +#ifdef _WIN64 +#define MI_PTE_FRAME_BITS 57 +#else +#define MI_PTE_FRAME_BITS 25 +#endif + // Mm internal typedef struct _MMPFN { @@ -413,6 +419,9 @@ typedef struct _MMPFN USHORT ShortFlags; } e2; } u3; +#ifdef _WIN64 + ULONG UsedPageTableEntries; +#endif union { MMPTE OriginalPte; @@ -426,7 +435,7 @@ typedef struct _MMPFN ULONG_PTR EntireFrame; struct { - ULONG_PTR PteFrame:25; + ULONG_PTR PteFrame : MI_PTE_FRAME_BITS; ULONG_PTR InPageError:1; ULONG_PTR VerifierAllocation:1; ULONG_PTR AweAllocation:1; diff --git a/ntoskrnl/mm/ARM3/miarm.h b/ntoskrnl/mm/ARM3/miarm.h index 45abbea577c..60a99c90dc9 100644 --- a/ntoskrnl/mm/ARM3/miarm.h +++ b/ntoskrnl/mm/ARM3/miarm.h @@ -220,24 +220,14 @@ extern const ULONG MmProtectToValue[32]; // #define MI_INITIAL_SESSION_IDS 64 -#if defined(_M_IX86) || defined(_M_ARM) -// -// PFN List Sentinel -// -#define LIST_HEAD 0xFFFFFFFF +#define LIST_HEAD ULONG_PTR_MAX // // Because GCC cannot automatically downcast 0xFFFFFFFF to lesser-width bits, // we need a manual definition suited to the number of bits in the PteFrame. // This is used as a LIST_HEAD for the colored list // -#define COLORED_LIST_HEAD ((1 << 25) - 1) // 0x1FFFFFF -#elif defined(_M_AMD64) -#define LIST_HEAD 0xFFFFFFFFFFFFFFFFLL -#define COLORED_LIST_HEAD ((1ULL << 57) - 1) // 0x1FFFFFFFFFFFFFFLL -#else -#error Define these please! -#endif +#define COLORED_LIST_HEAD (((ULONG_PTR)1 << MI_PTE_FRAME_BITS) - 1) // // Returns the color of a page