From b85ab20f13c49450c8d7f7e82db9d3a32a0daf7c Mon Sep 17 00:00:00 2001 From: Sir Richard Date: Sun, 29 Aug 2010 19:27:58 +0000 Subject: [PATCH] [NTOS]: Missed a bunch of codepaths, protected pool "should" work now. svn path=/trunk/; revision=48650 --- reactos/ntoskrnl/include/internal/mm.h | 3 ++ reactos/ntoskrnl/mm/ARM3/pool.c | 42 ++++++++++++++++++++------ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/mm.h b/reactos/ntoskrnl/include/internal/mm.h index a7154de564d..346d9c08a54 100644 --- a/reactos/ntoskrnl/include/internal/mm.h +++ b/reactos/ntoskrnl/include/internal/mm.h @@ -435,6 +435,9 @@ typedef struct _MMFREE_POOL_ENTRY struct _MMFREE_POOL_ENTRY *Owner; } MMFREE_POOL_ENTRY, *PMMFREE_POOL_ENTRY; +/* Signature of a freed block */ +#define MM_FREE_POOL_SIGNATURE 'ARM3' + /* Paged pool information */ typedef struct _MM_PAGED_POOL_INFO { diff --git a/reactos/ntoskrnl/mm/ARM3/pool.c b/reactos/ntoskrnl/mm/ARM3/pool.c index ca3a4b3589b..2e089507234 100644 --- a/reactos/ntoskrnl/mm/ARM3/pool.c +++ b/reactos/ntoskrnl/mm/ARM3/pool.c @@ -615,6 +615,13 @@ MiAllocatePoolPages(IN POOL_TYPE PoolType, NextEntry = NextHead->Flink; while (NextEntry != NextHead) { + /* Is freed non paged pool enabled */ + if (MmProtectFreedNonPagedPool) + { + /* We need to be able to touch this page, unprotect it */ + MiUnProtectFreeNonPagedPool(NextEntry, 0); + } + // // Grab the entry and see if it can handle our allocation // @@ -632,23 +639,31 @@ MiAllocatePoolPages(IN POOL_TYPE PoolType, BaseVa = (PVOID)((ULONG_PTR)FreeEntry + (FreeEntry->Size << PAGE_SHIFT)); - // - // This is not a free page segment anymore - // - RemoveEntryList(&FreeEntry->List); + /* Remove the item from the list, depending if pool is protected */ + MmProtectFreedNonPagedPool ? + MiProtectedPoolRemoveEntryList(&FreeEntry->List) : + RemoveEntryList(&FreeEntry->List); // // However, check if its' still got space left // if (FreeEntry->Size != 0) { - // - // Insert it back into a different list, based on its pages - // + /* Check which list to insert this entry into */ i = FreeEntry->Size - 1; if (i >= MI_MAX_FREE_PAGE_LISTS) i = MI_MAX_FREE_PAGE_LISTS - 1; - InsertTailList (&MmNonPagedPoolFreeListHead[i], - &FreeEntry->List); + + /* Insert the entry into the free list head, check for prot. pool */ + MmProtectFreedNonPagedPool ? + MiProtectedPoolInsertList(&MmNonPagedPoolFreeListHead[i], &FreeEntry->List, TRUE) : + InsertTailList(&MmNonPagedPoolFreeListHead[i], &FreeEntry->List); + + /* Is freed non paged pool protected? */ + if (MmProtectFreedNonPagedPool) + { + /* Protect the freed pool! */ + MiProtectFreeNonPagedPool(FreeEntry, FreeEntry->Size); + } } // @@ -698,6 +713,13 @@ MiAllocatePoolPages(IN POOL_TYPE PoolType, // Try the next free page entry // NextEntry = FreeEntry->List.Flink; + + /* Is freed non paged pool protected? */ + if (MmProtectFreedNonPagedPool) + { + /* Protect the freed pool! */ + MiProtectFreeNonPagedPool(FreeEntry, FreeEntry->Size); + } } } while (++NextHead < LastHead); @@ -1095,7 +1117,7 @@ MiFreePoolPages(IN PVOID StartingVa) // // Link back to the parent free entry, and keep going // - NextEntry->Owner = FreeEntry; + NextEntry->Owner = FreeEntry; NextEntry = (PMMFREE_POOL_ENTRY)((ULONG_PTR)NextEntry + PAGE_SIZE); } while (NextEntry != LastEntry);