From e980bd998f118c072adbb5d25b223bc909ca5552 Mon Sep 17 00:00:00 2001 From: ReactOS Portable Systems Group Date: Mon, 22 Jun 2009 08:22:41 +0000 Subject: [PATCH] - Initialize the ARM pool (MiInitializeArmPool): - Do some additional accounting to keep track of initial nonpaged pool range and size. - Create and initialize the free page lists, and free page entries. - Validate that the initial nonpaged pool address space was properly mapped. - Validate that the expansion nonpaged pool address space is unmapped, and prepare to map it. svn path=/trunk/; revision=41527 --- reactos/ntoskrnl/mm/ARM3/init.c | 5 + reactos/ntoskrnl/mm/ARM3/miarm.h | 12 +++ reactos/ntoskrnl/mm/ARM3/pool.c | 125 +++++++++++++++++++++++ reactos/ntoskrnl/ntoskrnl-generic.rbuild | 1 + 4 files changed, 143 insertions(+) create mode 100644 reactos/ntoskrnl/mm/ARM3/pool.c diff --git a/reactos/ntoskrnl/mm/ARM3/init.c b/reactos/ntoskrnl/mm/ARM3/init.c index b113b5d7e7d..0c7e2175903 100644 --- a/reactos/ntoskrnl/mm/ARM3/init.c +++ b/reactos/ntoskrnl/mm/ARM3/init.c @@ -362,6 +362,11 @@ MmArmInitSystem(IN ULONG Phase, 0, BoundaryAddressMultiple); ASSERT(Status == STATUS_SUCCESS); + + // + // Now go ahead and initialize the ARM pool + // + MiInitializeArmPool(); } // diff --git a/reactos/ntoskrnl/mm/ARM3/miarm.h b/reactos/ntoskrnl/mm/ARM3/miarm.h index 7011adfee2e..cdc2881ef3b 100644 --- a/reactos/ntoskrnl/mm/ARM3/miarm.h +++ b/reactos/ntoskrnl/mm/ARM3/miarm.h @@ -9,7 +9,19 @@ #define MI_MIN_PAGES_FOR_NONPAGED_POOL_TUNING ((255*1024*1024) >> PAGE_SHIFT) #define MI_MAX_INIT_NONPAGED_POOL_SIZE (128 * 1024 * 1024) #define MI_MAX_NONPAGED_POOL_SIZE (128 * 1024 * 1024) +#define MI_MAX_FREE_PAGE_LISTS 4 extern MMPTE HyperTemplatePte; +extern ULONG MmSizeOfNonPagedPoolInBytes; +extern ULONG MmMaximumNonPagedPoolInBytes; +extern PVOID MmNonPagedPoolStart; +extern PVOID MmNonPagedPoolExpansionStart; + +VOID +NTAPI +MiInitializeArmPool( + VOID +); + /* EOF */ diff --git a/reactos/ntoskrnl/mm/ARM3/pool.c b/reactos/ntoskrnl/mm/ARM3/pool.c new file mode 100644 index 00000000000..63e0b536359 --- /dev/null +++ b/reactos/ntoskrnl/mm/ARM3/pool.c @@ -0,0 +1,125 @@ +/* + * PROJECT: ReactOS Kernel + * LICENSE: BSD - See COPYING.ARM in the top level directory + * FILE: ntoskrnl/mm/ARM3/pool.c + * PURPOSE: ARM Memory Manager Pool Allocator + * PROGRAMMERS: ReactOS Portable Systems Group + */ + +/* INCLUDES *******************************************************************/ + +#include +#define NDEBUG +#include + +#line 15 "ARM³::POOL" +#define MODULE_INVOLVED_IN_ARM3 +#include "../ARM3/miarm.h" + +/* GLOBALS ********************************************************************/ + +LIST_ENTRY MmNonPagedPoolFreeListHead[MI_MAX_FREE_PAGE_LISTS]; +PFN_NUMBER MmNumberOfFreeNonPagedPool, MiExpansionPoolPagesInitialCharge; +PVOID MmNonPagedPoolEnd0; +PFN_NUMBER MiStartOfInitialPoolFrame, MiEndOfInitialPoolFrame; + +/* PRIVATE FUNCTIONS **********************************************************/ + +VOID +NTAPI +MiInitializeArmPool(VOID) +{ + ULONG i; + PFN_NUMBER PoolPages; + PMMFREE_POOL_ENTRY FreeEntry, FirstEntry; + PMMPTE PointerPte; + PAGED_CODE(); + + // + // We keep 4 lists of free pages (4 lists help avoid contention) + // + for (i = 0; i < MI_MAX_FREE_PAGE_LISTS; i++) + { + // + // Initialize each of them + // + InitializeListHead(&MmNonPagedPoolFreeListHead[i]); + } + + // + // Calculate how many pages the initial nonpaged pool has + // + PoolPages = BYTES_TO_PAGES(MmSizeOfNonPagedPoolInBytes); + MmNumberOfFreeNonPagedPool = PoolPages; + + // + // Initialize the first free entry + // + FreeEntry = MmNonPagedPoolStart; + FirstEntry = FreeEntry; + FreeEntry->Size = PoolPages; + FreeEntry->Owner = FirstEntry; + + // + // Insert it into the last list + // + InsertHeadList(&MmNonPagedPoolFreeListHead[MI_MAX_FREE_PAGE_LISTS - 1], + &FreeEntry->List); + + // + // Now create free entries for every single other page + // + while (PoolPages-- > 1) + { + // + // Link them all back to the original entry + // + FreeEntry = (PMMFREE_POOL_ENTRY)((ULONG_PTR)FreeEntry + PAGE_SIZE); + FreeEntry->Owner = FirstEntry; + } + + // + // Validate and remember first allocated pool page + // + PointerPte = MiAddressToPte(MmNonPagedPoolStart); + ASSERT(PointerPte->u.Hard.Valid == 1); + MiStartOfInitialPoolFrame = PFN_FROM_PTE(PointerPte); + + // + // Keep track of where initial nonpaged pool ends + // + MmNonPagedPoolEnd0 = (PVOID)((ULONG_PTR)MmNonPagedPoolStart + + MmSizeOfNonPagedPoolInBytes); + + // + // Validate and remember last allocated pool page + // + PointerPte = MiAddressToPte((PVOID)((ULONG_PTR)MmNonPagedPoolEnd0 - 1)); + ASSERT(PointerPte->u.Hard.Valid == 1); + MiEndOfInitialPoolFrame = PFN_FROM_PTE(PointerPte); + + // + // Validate the first nonpaged pool expansion page (which is a guard page) + // + PointerPte = MiAddressToPte(MmNonPagedPoolExpansionStart); + ASSERT(PointerPte->u.Hard.Valid == 0); + + // + // Calculate the size of the expansion region alone + // + MiExpansionPoolPagesInitialCharge = + BYTES_TO_PAGES(MmMaximumNonPagedPoolInBytes - MmSizeOfNonPagedPoolInBytes); + + // + // Remove 2 pages, since there's a guard page on top and on the bottom + // + MiExpansionPoolPagesInitialCharge -= 2; + + // + // Now initialize the nonpaged pool expansion PTE space. Remember there's a + // guard page on top so make sure to skip it. The bottom guard page will be + // guaranteed by the fact our size is off by one. + // +} + +/* EOF */ diff --git a/reactos/ntoskrnl/ntoskrnl-generic.rbuild b/reactos/ntoskrnl/ntoskrnl-generic.rbuild index 78d6e5dd15b..5240db23593 100644 --- a/reactos/ntoskrnl/ntoskrnl-generic.rbuild +++ b/reactos/ntoskrnl/ntoskrnl-generic.rbuild @@ -361,6 +361,7 @@ init.c + pool.c anonmem.c balance.c