From 8d2dfa6f62254c069888cf131b397a938c7df3bd Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Wed, 4 Mar 2026 22:44:45 +0100 Subject: [PATCH] Set up owner pointers for all pages during pool initialization --- sdk/xtdk/mmtypes.h | 1 + xtoskrnl/mm/alloc.cc | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sdk/xtdk/mmtypes.h b/sdk/xtdk/mmtypes.h index 22dac32..2cf29d7 100644 --- a/sdk/xtdk/mmtypes.h +++ b/sdk/xtdk/mmtypes.h @@ -102,6 +102,7 @@ typedef struct _MMFREE_POOL_ENTRY { LIST_ENTRY List; PFN_COUNT Size; + PMMFREE_POOL_ENTRY Owner; } MMFREE_POOL_ENTRY, *PMMFREE_POOL_ENTRY; /* Memory layout structure definition */ diff --git a/xtoskrnl/mm/alloc.cc b/xtoskrnl/mm/alloc.cc index e60a18c..3e98973 100644 --- a/xtoskrnl/mm/alloc.cc +++ b/xtoskrnl/mm/alloc.cc @@ -265,8 +265,8 @@ XTAPI VOID MM::Allocator::InitializeNonPagedPool(VOID) { + PMMFREE_POOL_ENTRY FreeEntry, SetupEntry; PMMMEMORY_LAYOUT MemoryLayout; - PMMFREE_POOL_ENTRY FreeEntry; ULONG Index; /* Retrieve memory layout */ @@ -282,8 +282,9 @@ MM::Allocator::InitializeNonPagedPool(VOID) RTL::LinkedList::InitializeListHead(&NonPagedPoolFreeList[Index]); } - /* Take the first free page from the pool */ + /* Take the first free entry from the pool and set its size */ FreeEntry = (PMMFREE_POOL_ENTRY)MemoryLayout->NonPagedPoolStart; + FreeEntry->Size = MemoryLayout->NonPagedPoolSize; /* Take number of pages in the pool */ Index = (ULONG)(MemoryLayout->NonPagedPoolSize - 1); @@ -293,9 +294,17 @@ MM::Allocator::InitializeNonPagedPool(VOID) Index = MM_MAX_FREE_PAGE_LIST_HEADS - 1; } - /* Insert the first free page into the free page list and set its size */ + /* Insert the first free entry into the free page list */ RTL::LinkedList::InsertHeadList(&NonPagedPoolFreeList[Index], &FreeEntry->List); - FreeEntry->Size = MemoryLayout->NonPagedPoolSize; + + /* Create a free entry for each page in the pool */ + SetupEntry = FreeEntry; + for(Index = 0; Index < MemoryLayout->NonPagedPoolSize; Index++) + { + /* Initialize the owner for each entry */ + SetupEntry->Owner = FreeEntry; + SetupEntry = (PMMFREE_POOL_ENTRY)((ULONG_PTR)SetupEntry + MM_PAGE_SIZE); + } } /**