[NTOS]: Read almost all the Memory Management variables into the system configuration...
authorSir Richard <sir_richard@svn.reactos.org>
Tue, 20 Apr 2010 22:47:51 +0000 (22:47 +0000)
committerSir Richard <sir_richard@svn.reactos.org>
Tue, 20 Apr 2010 22:47:51 +0000 (22:47 +0000)
[NTOS]: Minimal stubbed support for some large page functionality in case it gets implemented later and these things would've been ignored. One critical change is that now the MmProcessList is initialized, and the system process is added to it. Other processes should be added later.
[NTOS]: Add stubbed support for parsing the registry list of drivers that should have large pages enabled.
[NTOS]: Initialize the loaded module list before working set work.
[NTOS]: Reload the boot drivers much earlier, as part of ARM3 initialization.
[NTOS]: Start doing some minor MmResidentAvailablePages accounting during bootup.
[NTOS]: Start doing the math required for computing the appropriate MmSystemCacheWsMinimum on the booting system (based on RAM).
[NTOS]: Now that we use the HAL heap, add the code to scan it for I/O mappings. These are dangerous because we need to sync up caching attributes (not yet used in ReactOS, so not a problem for now).
[NTOS]: Add more header definitions, and helper definitions such as PDE_MAPPED_VA instead of doing the math by hand.
[NTOS]: Move MmPageEntireDriver and MmResetDriverPaging to sysldr.c since drvmgmt.c is more for Driver Verifier-style functionality.

svn path=/trunk/; revision=46971

14 files changed:
reactos/ntoskrnl/config/cmdata.c
reactos/ntoskrnl/mm/ARM3/drvmgmt.c
reactos/ntoskrnl/mm/ARM3/largepag.c [new file with mode: 0644]
reactos/ntoskrnl/mm/ARM3/mdlsup.c
reactos/ntoskrnl/mm/ARM3/miarm.h
reactos/ntoskrnl/mm/ARM3/mminit.c
reactos/ntoskrnl/mm/ARM3/pfnlist.c
reactos/ntoskrnl/mm/ARM3/pool.c
reactos/ntoskrnl/mm/freelist.c
reactos/ntoskrnl/mm/mminit.c
reactos/ntoskrnl/mm/pagefile.c
reactos/ntoskrnl/mm/section.c
reactos/ntoskrnl/mm/sysldr.c
reactos/ntoskrnl/ntoskrnl-generic.rbuild

index b3df10c..6dbf2a0 100644 (file)
@@ -11,7 +11,8 @@
 #include "ntoskrnl.h"
 #define NDEBUG
 #include "debug.h"
+#include "./../mm/ARM3/miarm.h"
+
 /* GLOBALS *******************************************************************/
 
 ULONG DummyData;
@@ -252,7 +253,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"DynamicMemory",
-        &DummyData,
+        &MmDynamicPfn,
         NULL,
         NULL
     },
@@ -260,7 +261,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"Mirroring",
-        &DummyData,
+        &MmMirroring,
         NULL,
         NULL
     },
@@ -273,14 +274,6 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
         NULL
     },
 
-    {
-        L"Session Manager\\Memory Management",
-        L"SessionViewSize",
-        &DummyData,
-        NULL,
-        NULL
-    },
-
     {
         L"Session Manager\\Memory Management",
         L"SessionImageSize",
@@ -300,7 +293,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"PoolUsageMaximum",
-        &DummyData,
+        &MmConsumedPoolPercentage,
         NULL,
         NULL
     },
@@ -308,7 +301,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"MapAllocationFragment",
-        &DummyData,
+        &MmAllocationFragment,
         NULL,
         NULL
     },
@@ -316,7 +309,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"PagedPoolSize",
-        &DummyData,
+        &MmSizeOfPagedPoolInBytes,
         NULL,
         NULL
     },
@@ -324,7 +317,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"NonPagedPoolSize",
-        &DummyData,
+        &MmSizeOfNonPagedPoolInBytes,
         NULL,
         NULL
     },
@@ -340,7 +333,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"LargeSystemCache",
-        &DummyData,
+        &MmLargeSystemCache,
         NULL,
         NULL
     },
@@ -356,7 +349,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"SystemPages",
-        &DummyData,
+        &MmNumberOfSystemPtes,
         NULL,
         NULL
     },
@@ -364,7 +357,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"LowMemoryThreshold",
-        &DummyData,
+        &MmLowMemoryThreshold,
         NULL,
         NULL
     },
@@ -372,7 +365,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"HighMemoryThreshold",
-        &DummyData,
+        &MmHighMemoryThreshold,
         NULL,
         NULL
     },
@@ -396,7 +389,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"SecondLevelDataCache",
-        &DummyData,
+        &MmSecondaryColors,
         NULL,
         NULL
     },
@@ -404,7 +397,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"ClearPageFileAtShutdown",
-        &DummyData,
+        &MmZeroPageFile,
         NULL,
         NULL
     },
@@ -452,7 +445,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"ProtectNonPagedPool",
-        &DummyData,
+        &MmProtectFreedNonPagedPool,
         NULL,
         NULL
     },
@@ -460,7 +453,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"TrackLockedPages",
-        &DummyData,
+        &MmTrackLockedPages,
         NULL,
         NULL
     },
@@ -468,7 +461,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"TrackPtes",
-        &DummyData,
+        &MmTrackPtes,
         NULL,
         NULL
     },
@@ -476,15 +469,15 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"VerifyDrivers",
-        &DummyData,
-        &DummyData,
-        &DummyData
+        MmVerifyDriverBuffer,
+        &MmVerifyDriverBufferLength,
+        &MmVerifyDriverBufferType
     },
 
     {
         L"Session Manager\\Memory Management",
         L"VerifyDriverLevel",
-        &DummyData,
+        &MmVerifyDriverLevel,
         NULL,
         NULL
     },
@@ -508,7 +501,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"EnforceWriteProtection",
-        &DummyData,
+        &MmEnforceWriteProtection,
         NULL,
         NULL
     },
@@ -516,7 +509,7 @@ CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
     {
         L"Session Manager\\Memory Management",
         L"MakeLowMemory",
-        &DummyData,
+        &MmMakeLowMemory,
         NULL,
         NULL
     },
index 4811a44..ad85c47 100644 (file)
 MM_DRIVER_VERIFIER_DATA MmVerifierData;
 LIST_ENTRY MiVerifierDriverAddedThunkListHead;
 ULONG MiActiveVerifierThunks;
-
-/* PRIVATE FUNCTIONS *********************************************************/
-
-PLDR_DATA_TABLE_ENTRY
-NTAPI
-MiLookupDataTableEntry(IN PVOID Address)
-{
-    PLDR_DATA_TABLE_ENTRY LdrEntry, FoundEntry = NULL;
-    PLIST_ENTRY NextEntry;
-    PAGED_CODE();
-    
-    //
-    // Loop entries
-    //
-    NextEntry = PsLoadedModuleList.Flink;
-    do
-    {
-        //
-        // Get the loader entry
-        //
-        LdrEntry =  CONTAINING_RECORD(NextEntry,
-                                      LDR_DATA_TABLE_ENTRY,
-                                      InLoadOrderLinks);
-        
-        //
-        // Check if the address matches
-        //
-        if ((Address >= LdrEntry->DllBase) &&
-            (Address < (PVOID)((ULONG_PTR)LdrEntry->DllBase +
-                               LdrEntry->SizeOfImage)))
-        {
-            //
-            // Found a match
-            //
-            FoundEntry = LdrEntry;
-            break;
-        }
-        
-        //
-        // Move on
-        //
-        NextEntry = NextEntry->Flink;
-    } while(NextEntry != &PsLoadedModuleList);
-    
-    //
-    // Return the entry
-    //
-    return FoundEntry;
-}
+WCHAR MmVerifyDriverBuffer[512] = {0};
+ULONG MmVerifyDriverBufferLength = sizeof(MmVerifyDriverBuffer);
+ULONG MmVerifyDriverBufferType = REG_NONE;
+ULONG MmVerifyDriverLevel = -1;
+PVOID MmTriageActionTaken;
+PVOID KernelVerifier;
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
@@ -107,68 +64,6 @@ MmLockPageableDataSection(IN PVOID AddressWithinSection)
     return AddressWithinSection;
 }
 
-/*
- * @unimplemented
- */
-PVOID
-NTAPI
-MmPageEntireDriver(IN PVOID AddressWithinSection)
-{
-    //PMMPTE StartPte, EndPte;
-    PLDR_DATA_TABLE_ENTRY LdrEntry;
-    PAGED_CODE();
-
-    //
-    // Get the loader entry
-    //
-    LdrEntry = MiLookupDataTableEntry(AddressWithinSection);
-    if (!LdrEntry) return NULL;
-
-    //
-    // Check if paging of kernel mode is disabled or if the driver is mapped as
-    // an image
-    //
-    if ((MmDisablePagingExecutive & 0x1) || (LdrEntry->SectionPointer))
-    {
-        //
-        // Don't do anything, just return the base address
-        //
-        return LdrEntry->DllBase;
-    }
-
-    //
-    // Wait for active DPCs to finish before we page out the driver
-    //
-    KeFlushQueuedDpcs();
-
-    //
-    // Get the PTE range for the whole driver image
-    //
-    //StartPte = MiGetPteAddress(LdrEntry->DllBase);
-    //EndPte = MiGetPteAddress(LdrEntry->DllBase +
-    //                         LdrEntry->SizeOfImage);
-
-    //
-    // Enable paging for the PTE range
-    //
-    //MiSetPagingOfDriver(StartPte, EndPte);
-
-    //
-    // Return the base address
-    //
-    return LdrEntry->DllBase;
-}
-
-/*
- * @unimplemented
- */
-VOID
-NTAPI
-MmResetDriverPaging(IN PVOID AddressWithinSection)
-{
-    UNIMPLEMENTED;
-}
-
 /*
  * @unimplemented
  */
diff --git a/reactos/ntoskrnl/mm/ARM3/largepag.c b/reactos/ntoskrnl/mm/ARM3/largepag.c
new file mode 100644 (file)
index 0000000..0cd1e50
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * PROJECT:         ReactOS Kernel
+ * LICENSE:         BSD - See COPYING.ARM in the top level directory
+ * FILE:            ntoskrnl/mm/ARM3/largepag.c
+ * PURPOSE:         ARM Memory Manager Large Page Support
+ * PROGRAMMERS:     ReactOS Portable Systems Group
+ */
+
+/* INCLUDES *******************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <debug.h>
+
+#line 15 "ARMĀ³::LARGEPAGE"
+#define MODULE_INVOLVED_IN_ARM3
+#include "../ARM3/miarm.h"
+
+/* GLOBALS ********************************************************************/
+
+LIST_ENTRY MmProcessList;
+PMMPTE MiLargePageHyperPte;
+ULONG MiLargePageRangeIndex;
+MI_LARGE_PAGE_RANGES MiLargePageRanges[64];
+WCHAR MmLargePageDriverBuffer[512] = {0};
+ULONG MmLargePageDriverBufferLength = -1;
+LIST_ENTRY MiLargePageDriverList;
+BOOLEAN MiLargePageAllDrivers;
+
+/* FUNCTIONS ******************************************************************/
+
+VOID
+NTAPI
+MiInitializeLargePageSupport(VOID)
+{
+#if _MI_PAGING_LEVELS > 2
+#error "PAE/x64 Not Implemented"
+#else
+    /* Initialize the large-page hyperspace PTE used for initial mapping */
+    MiLargePageHyperPte = MiReserveSystemPtes(1, SystemPteSpace);
+    ASSERT(MiLargePageHyperPte);
+    MiLargePageHyperPte->u.Long = 0;
+
+    /* Initialize the process tracking list, and insert the system process */
+    InitializeListHead(&MmProcessList);
+    InsertTailList(&MmProcessList, &PsGetCurrentProcess()->MmProcessLinks);
+#endif    
+}
+
+VOID
+NTAPI
+MiSyncCachedRanges(VOID)
+{
+    ULONG i;
+
+    /* Scan every range */
+    for (i = 0; i < MiLargePageRangeIndex; i++)
+    {
+        DPRINT1("No support for large pages\n");
+        while (TRUE);
+    }
+}
+
+VOID
+NTAPI
+MiInitializeDriverLargePageList(VOID)
+{
+    PWCHAR p, pp;
+
+    /* Initialize the list */
+    InitializeListHead(&MiLargePageDriverList);
+
+    /* Bail out if there's nothing */
+    if (MmLargePageDriverBufferLength == 0xFFFFFFFF) return;
+
+    /* Loop from start to finish */
+    p = MmLargePageDriverBuffer;
+    pp = MmLargePageDriverBuffer + (MmLargePageDriverBufferLength / sizeof(WCHAR));
+    while (p < pp)
+    {
+        /* Skip whitespaces */
+        if ((*p == L' ') || (*p == L'\n') || (*p == L'\r') || (*p == L'\t'))
+        {
+            /* Skip the character */
+            p++;
+            continue;
+        }
+        
+        /* A star means everything */
+        if (*p == L'*')
+        {
+            /* No need to keep going */
+            MiLargePageAllDrivers = TRUE;
+            break;
+        }
+        
+        DPRINT1("Large page drivers not supported\n");
+        ASSERT(FALSE);
+    }
+}
+
+/* EOF */
index 0100040..1b95448 100644 (file)
@@ -16,6 +16,9 @@
 #define MODULE_INVOLVED_IN_ARM3
 #include "../ARM3/miarm.h"
 
+BOOLEAN MmTrackPtes;
+BOOLEAN MmTrackLockedPages;
+
 /* PUBLIC FUNCTIONS ***********************************************************/
 
 /*
index 1ced65d..11d4189 100644 (file)
@@ -42,6 +42,9 @@
 #define _1KB (1024)
 #define _1MB (1024 * _1KB)
 
+/* Are mapped by a PDE */
+#define PDE_MAPPED_VA   (PTE_COUNT * PAGE_SIZE)
+
 /* Size of a PDE directory, and size of a page table */
 #define PDE_SIZE (PDE_COUNT * sizeof(MMPDE))
 #define PT_SIZE  (PTE_COUNT * sizeof(MMPTE))
 #error Define these please!
 #endif
 
+#ifdef _M_IX86
+#define IMAGE_FILE_MACHINE_NATIVE   IMAGE_FILE_MACHINE_I386
+#elif _M_ARM
+#define IMAGE_FILE_MACHINE_NATIVE   IMAGE_FILE_MACHINE_ARM
+#elif _M_AMD64
+#define IMAGE_FILE_MACHINE_NATIVE   IMAGE_FILE_MACHINE_AMD64
+#else
+#error Define these please!
+#endif
+
+//
+// Protection Bits part of the internal memory manager Protection Mask
+// Taken from http://www.reactos.org/wiki/Techwiki:Memory_management_in_the_Windows_XP_kernel
+// and public assertions.
+//
+#define MM_ZERO_ACCESS         0
+#define MM_READONLY            1 
+#define MM_EXECUTE             2 
+#define MM_EXECUTE_READ        3 
+#define MM_READWRITE           4
+#define MM_WRITECOPY           5 
+#define MM_EXECUTE_READWRITE   6 
+#define MM_EXECUTE_WRITECOPY   7 
+#define MM_NOCACHE             8 
+#define MM_DECOMMIT            0x10 
+#define MM_NOACCESS            (MM_DECOMMIT | MM_NOCACHE)
+
+//
+// Special values for LoadedImports
+//
+#define MM_SYSLDR_NO_IMPORTS   (PVOID)0xFFFFFFFE
+#define MM_SYSLDR_BOOT_LOADED  (PVOID)0xFFFFFFFF
+#define MM_SYSLDR_SINGLE_ENTRY 0x1
+
 //
 // PFN List Sentinel
 //
@@ -168,10 +205,34 @@ typedef struct _MMCOLOR_TABLES
     PFN_NUMBER Count;
 } MMCOLOR_TABLES, *PMMCOLOR_TABLES;
 
+typedef struct _MI_LARGE_PAGE_RANGES
+{
+    PFN_NUMBER StartFrame;
+    PFN_NUMBER LastFrame;
+} MI_LARGE_PAGE_RANGES, *PMI_LARGE_PAGE_RANGES;
+
 extern MMPTE HyperTemplatePte;
 extern MMPTE ValidKernelPde;
 extern MMPTE ValidKernelPte;
-
+extern BOOLEAN MmLargeSystemCache;
+extern BOOLEAN MmZeroPageFile;
+extern BOOLEAN MmProtectFreedNonPagedPool;
+extern BOOLEAN MmTrackLockedPages;
+extern BOOLEAN MmTrackPtes;
+extern BOOLEAN MmDynamicPfn;
+extern BOOLEAN MmMirroring;
+extern BOOLEAN MmMakeLowMemory;
+extern BOOLEAN MmEnforceWriteProtection;
+extern ULONG MmAllocationFragment;
+extern ULONG MmConsumedPoolPercentage;
+extern ULONG MmVerifyDriverBufferType;
+extern ULONG MmVerifyDriverLevel;
+extern WCHAR MmVerifyDriverBuffer[512];
+extern WCHAR MmLargePageDriverBuffer[512];
+extern LIST_ENTRY MiLargePageDriverList;
+extern BOOLEAN MiLargePageAllDrivers;
+extern ULONG MmVerifyDriverBufferLength;
+extern ULONG MmLargePageDriverBufferLength;
 extern ULONG MmSizeOfNonPagedPoolInBytes;
 extern ULONG MmMaximumNonPagedPoolInBytes;
 extern PFN_NUMBER MmMaximumNonPagedPoolInPages;
@@ -243,11 +304,32 @@ extern PFN_NUMBER MmMinimumFreePages;
 extern PFN_NUMBER MmPlentyFreePages;
 extern PFN_NUMBER MiExpansionPoolPagesInitialCharge;
 extern PFN_NUMBER MmResidentAvailablePages;
-extern PFN_NUMBER MmResidentAvailablePagesAtInit;
+extern PFN_NUMBER MmResidentAvailableAtInit;
+extern ULONG MmTotalFreeSystemPtes[MaximumPtePoolTypes];
+extern PFN_NUMBER MmTotalSystemDriverPages;
+extern PVOID MiSessionImageStart;
+extern PVOID MiSessionImageEnd;
 
 #define MI_PFN_TO_PFNENTRY(x)     (&MmPfnDatabase[1][x])
 #define MI_PFNENTRY_TO_PFN(x)     (x - MmPfnDatabase[1])
 
+#define MI_IS_SESSION_IMAGE_ADDRESS(Address) \
+    (((Address) >= MiSessionImageStart) && ((Address) < MiSessionImageEnd))
+
+#define MI_IS_SESSION_ADDRESS(Address) \
+    (((Address) >= MmSessionBase) && ((Address) < MiSessionSpaceEnd))
+        
+FORCEINLINE
+BOOLEAN
+MI_IS_PHYSICAL_ADDRESS(IN PVOID Address)
+{
+    PMMPDE PointerPde;
+    
+    /* Large pages are never paged out, always physically resident */
+    PointerPde = MiAddressToPde(Address);
+    return ((PointerPde->u.Hard.LargePage) && (PointerPde->u.Hard.Valid));
+}
+
 NTSTATUS
 NTAPI
 MmArmInitSystem(
@@ -457,4 +539,28 @@ MiInsertPageInFreeList(
     IN PFN_NUMBER PageFrameIndex
 );
 
+PLDR_DATA_TABLE_ENTRY
+NTAPI
+MiLookupDataTableEntry(
+    IN PVOID Address
+);
+
+VOID
+NTAPI
+MiInitializeDriverLargePageList(
+    VOID
+);
+
+VOID
+NTAPI
+MiInitializeLargePageSupport(
+    VOID
+);
+
+VOID
+NTAPI
+MiSyncCachedRanges(
+    VOID
+);
+
 /* EOF */
index 89d082e..d21adc0 100644 (file)
@@ -301,6 +301,20 @@ PFN_NUMBER MmPlentyFreePages = 400;
 ULONG MmProductType;
 MM_SYSTEMSIZE MmSystemSize;
 
+/*
+ * These values store the cache working set minimums and maximums, in pages
+ *
+ * The minimum value is boosted on systems with more than 24MB of RAM, and cut
+ * down to only 32 pages on embedded (<24MB RAM) systems.
+ *
+ * An extra boost of 2MB is given on systems with more than 33MB of RAM.
+ */
+PFN_NUMBER MmSystemCacheWsMinimum = 288;
+PFN_NUMBER MmSystemCacheWsMaximum = 350;
+
+/* FIXME: Move to cache/working set code later */
+BOOLEAN MmLargeSystemCache;
+
 /* PRIVATE FUNCTIONS **********************************************************/
 
 //
@@ -742,7 +756,7 @@ MiBuildPfnDatabaseFromPages(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
         else
         {
             /* Next PDE mapped address */
-            BaseAddress += PTE_COUNT * PAGE_SIZE;
+            BaseAddress += PDE_MAPPED_VA;
         }
         
         /* Next PTE */
@@ -1159,6 +1173,61 @@ MiInitializeMemoryEvents(VOID)
     return TRUE;
 }
 
+VOID
+NTAPI
+MiAddHalIoMappings(VOID)
+{
+    PVOID BaseAddress;
+    PMMPTE PointerPde;
+    PMMPTE PointerPte;
+    ULONG i, j, PdeCount;
+    PFN_NUMBER PageFrameIndex;
+
+    /* HAL Heap address -- should be on a PDE boundary */
+    BaseAddress = (PVOID)0xFFC00000;
+    ASSERT(MiAddressToPteOffset(BaseAddress) == 0);
+
+    /* Check how many PDEs the heap has */
+    PointerPde = MiAddressToPde(BaseAddress);
+    PdeCount = PDE_COUNT - ADDR_TO_PDE_OFFSET(BaseAddress);
+    for (i = 0; i < PdeCount; i++)
+    {
+        /* Does the HAL own this mapping? */
+        if ((PointerPde->u.Hard.Valid == 1) &&
+            (PointerPde->u.Hard.LargePage == 0))
+        {
+            /* Get the PTE for it and scan each page */
+            PointerPte = MiAddressToPte(BaseAddress);
+            for (j = 0 ; j < PTE_COUNT; j++)
+            {
+                /* Does the HAL own this page? */
+                if (PointerPte->u.Hard.Valid == 1)
+                {
+                    /* Is the HAL using it for device or I/O mapped memory? */
+                    PageFrameIndex = PFN_FROM_PTE(PointerPte);
+                    if (!MiGetPfnEntry(PageFrameIndex))
+                    {
+                        /* FIXME: For PAT, we need to track I/O cache attributes for coherency */
+                        DPRINT1("HAL I/O Mapping at %p is unsafe\n", BaseAddress);
+                    }
+                }
+
+                /* Move to the next page */
+                BaseAddress = (PVOID)((ULONG_PTR)BaseAddress + PAGE_SIZE);
+                PointerPte++;
+            }
+        }
+        else
+        {
+            /* Move to the next address */
+            BaseAddress = (PVOID)((ULONG_PTR)BaseAddress + PDE_MAPPED_VA);
+        }
+
+        /* Move to the next PDE */
+        PointerPde++;
+    }
+}
+
 VOID
 NTAPI
 MmDumpArmPfnDatabase(VOID)
@@ -1813,11 +1882,26 @@ MmArmInitSystem(IN ULONG Phase,
             }
         }
         
-        //
-        // Size up paged pool and build the shadow system page directory
-        //
-        MiBuildPagedPool();
-        
+        /* Look for large page cache entries that need caching */
+        MiSyncCachedRanges();
+
+        /* Loop for HAL Heap I/O device mappings that need coherency tracking */
+        MiAddHalIoMappings();
+
+        /* Set the initial resident page count */
+        MmResidentAvailablePages = MmAvailablePages - 32;
+
+        /* Initialize large page structures on PAE/x64, and MmProcessList on x86 */
+        MiInitializeLargePageSupport();
+
+        /* Check if the registry says any drivers should be loaded with large pages */
+        MiInitializeDriverLargePageList();
+
+        /* Relocate the boot drivers into system PTE space and fixup their PFNs */
+        MiReloadBootLoadedDrivers(LoaderBlock);
+
+        /* FIXME: Call out into Driver Verifier for initialization  */
+
         /* Check how many pages the system has */
         if (MmNumberOfPhysicalPages <= (13 * _1MB))
         {
@@ -1826,13 +1910,22 @@ MmArmInitSystem(IN ULONG Phase,
         }
         else if (MmNumberOfPhysicalPages <= (19 * _1MB))
         {
-            /* Set small system */
+            /* Set small system and add 100 pages for the cache */
             MmSystemSize = MmSmallSystem;
+            MmSystemCacheWsMinimum += 100;
         }
         else
         {
-            /* Set medium system */
+            /* Set medium system and add 400 pages for the cache */
             MmSystemSize = MmMediumSystem;
+            MmSystemCacheWsMinimum += 400;
+        }
+        
+        /* Check for less than 24MB */
+        if (MmNumberOfPhysicalPages < ((24 * _1MB) / PAGE_SIZE))
+        {
+            /* No more than 32 pages */
+            MmSystemCacheWsMinimum = 32;
         }
 
         /* Check for more than 32MB */
@@ -1854,7 +1947,14 @@ MmArmInitSystem(IN ULONG Phase,
                 }
             }
         }
-
+        
+        /* Check for more than 33 MB */
+        if (MmNumberOfPhysicalPages > ((33 * _1MB) / PAGE_SIZE))
+        {
+            /* Add another 500 pages to the cache */
+            MmSystemCacheWsMinimum += 500;
+        }
+        
         /* Now setup the shared user data fields */
         ASSERT(SharedUserData->NumberOfPhysicalPages == 0);
         SharedUserData->NumberOfPhysicalPages = MmNumberOfPhysicalPages;
@@ -1888,6 +1988,20 @@ MmArmInitSystem(IN ULONG Phase,
 
         /* Update working set tuning parameters */
         MiAdjustWorkingSetManagerParameters(!MmProductType);
+
+        /* Finetune the page count by removing working set and NP expansion */
+        MmResidentAvailablePages -= MiExpansionPoolPagesInitialCharge;
+        MmResidentAvailablePages -= MmSystemCacheWsMinimum;
+        MmResidentAvailableAtInit = MmResidentAvailablePages;
+        if (MmResidentAvailablePages <= 0)
+        {
+            /* This should not happen */
+            DPRINT1("System cache working set too big\n");
+            return FALSE;
+        }
+        
+        /* Size up paged pool and build the shadow system page directory */
+        MiBuildPagedPool();
     }
     
     //
index 5804340..f42abdc 100644 (file)
@@ -18,6 +18,9 @@
 
 /* GLOBALS ********************************************************************/
 
+BOOLEAN MmDynamicPfn;
+BOOLEAN MmMirroring;
+
 MMPFNLIST MmZeroedPageListHead = {0, ZeroedPageList, LIST_HEAD, LIST_HEAD};
 MMPFNLIST MmFreePageListHead = {0, FreePageList, LIST_HEAD, LIST_HEAD};
 MMPFNLIST MmStandbyPageListHead = {0, StandbyPageList, LIST_HEAD, LIST_HEAD};
index bd2f826..10a585e 100644 (file)
@@ -26,6 +26,8 @@ KGUARDED_MUTEX MmPagedPoolMutex;
 MM_PAGED_POOL_INFO MmPagedPoolInfo;
 SIZE_T MmAllocatedNonPagedPool;
 ULONG MmSpecialPoolTag;
+ULONG MmConsumedPoolPercentage;
+BOOLEAN MmProtectFreedNonPagedPool;
 
 /* PRIVATE FUNCTIONS **********************************************************/
 
index 7f2646f..6f5df91 100644 (file)
@@ -36,8 +36,9 @@
 /* The first array contains ReactOS PFNs, the second contains ARM3 PFNs */
 PPHYSICAL_PAGE MmPfnDatabase[2];
 
-ULONG MmAvailablePages;
-ULONG MmResidentAvailablePages;
+PFN_NUMBER MmAvailablePages;
+PFN_NUMBER MmResidentAvailablePages;
+PFN_NUMBER MmResidentAvailableAtInit;
 
 SIZE_T MmTotalCommitLimit;
 SIZE_T MmTotalCommittedPages;
index 8a9fd42..a03ce8e 100644 (file)
@@ -398,15 +398,12 @@ MmInitSystem(IN ULONG Phase,
         /* Initialize paged pool */
         MmInitializePagedPool();
         
+        /* Initialize the loaded module list */
+        MiInitializeLoadedModuleList(LoaderBlock);
+        
         /* Initialize working sets */
         MiInitializeUserPfnBitmap();
         MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
-
-        /* Reload boot drivers */
-        MiReloadBootLoadedDrivers(LoaderBlock);
-
-        /* Initialize the loaded module list */
-        MiInitializeLoadedModuleList(LoaderBlock);
     }
     else if (Phase == 1)
     {
index 1af2fac..1ea2c41 100644 (file)
@@ -86,6 +86,8 @@ ULONG MiFreeSwapPages;
 /* Number of pages that have been allocated for swapping */
 ULONG MiUsedSwapPages;
 
+BOOLEAN MmZeroPageFile;
+
 /*
  * Number of pages that have been reserved for swapping but not yet allocated
  */
index 582af62..fc70895 100644 (file)
@@ -71,6 +71,8 @@ MM_SECTION_PAGEOUT_CONTEXT;
 
 POBJECT_TYPE MmSectionObjectType = NULL;
 
+BOOLEAN MmAllocationFragment;
+
 ULONG_PTR MmSubsectionBase;
 
 static GENERIC_MAPPING MmpSectionMapping = {
index 281a396..36b3ce5 100644 (file)
@@ -44,6 +44,9 @@ PVOID MmLastUnloadedDrivers;
 PVOID MmTriageActionTaken;
 PVOID KernelVerifier;
 
+BOOLEAN MmMakeLowMemory;
+BOOLEAN MmEnforceWriteProtection = TRUE;
+
 /* FUNCTIONS ******************************************************************/
 
 PVOID
@@ -2040,6 +2043,87 @@ Quickie:
     return Status;
 }
 
+PLDR_DATA_TABLE_ENTRY
+NTAPI
+MiLookupDataTableEntry(IN PVOID Address)
+{
+    PLDR_DATA_TABLE_ENTRY LdrEntry, FoundEntry = NULL;
+    PLIST_ENTRY NextEntry;
+    PAGED_CODE();
+    
+    /* Loop entries */
+    NextEntry = PsLoadedModuleList.Flink;
+    do
+    {
+        /* Get the loader entry */
+        LdrEntry =  CONTAINING_RECORD(NextEntry,
+                                      LDR_DATA_TABLE_ENTRY,
+                                      InLoadOrderLinks);
+        
+        /* Check if the address matches */
+        if ((Address >= LdrEntry->DllBase) &&
+            (Address < (PVOID)((ULONG_PTR)LdrEntry->DllBase +
+                               LdrEntry->SizeOfImage)))
+        {
+            /* Found a match */
+            FoundEntry = LdrEntry;
+            break;
+        }
+        
+        /* Move on */
+        NextEntry = NextEntry->Flink;
+    } while(NextEntry != &PsLoadedModuleList);
+    
+    /* Return the entry */
+    return FoundEntry;
+}
+
+/*
+ * @implemented
+ */
+PVOID
+NTAPI
+MmPageEntireDriver(IN PVOID AddressWithinSection)
+{
+    PMMPTE StartPte, EndPte;
+    PLDR_DATA_TABLE_ENTRY LdrEntry;
+    PAGED_CODE();
+
+    /* Get the loader entry */
+    LdrEntry = MiLookupDataTableEntry(AddressWithinSection);
+    if (!LdrEntry) return NULL;
+
+    /* Check if paging of kernel mode is disabled or if the driver is mapped as an image */
+    if ((MmDisablePagingExecutive) || (LdrEntry->SectionPointer))
+    {
+        /* Don't do anything, just return the base address */
+        return LdrEntry->DllBase;
+    }
+
+    /* Wait for active DPCs to finish before we page out the driver */
+    KeFlushQueuedDpcs();
+
+    /* Get the PTE range for the whole driver image */
+    StartPte = MiAddressToPte((ULONG_PTR)LdrEntry->DllBase);
+    EndPte = MiAddressToPte((ULONG_PTR)LdrEntry->DllBase + LdrEntry->SizeOfImage);
+#if 0
+    /* Enable paging for the PTE range */
+    ASSERT(MI_IS_SESSION_IMAGE_ADDRESS(AddressWithinSection) == FALSE);
+    MiSetPagingOfDriver(StartPte, EndPte);
+#endif
+    /* Return the base address */
+    return LdrEntry->DllBase;
+}
+
+/*
+ * @unimplemented
+ */
+VOID
+NTAPI
+MmResetDriverPaging(IN PVOID AddressWithinSection)
+{
+    UNIMPLEMENTED;
+}
 /*
  * @implemented
  */
index a349f88..da129c3 100644 (file)
                        <file>expool.c</file>
                        <file>hypermap.c</file>
                        <file>iosup.c</file>
+                       <file>largepag.c</file>
                        <file>mdlsup.c</file>
                        <file>mminit.c</file>
                        <file>mmsup.c</file>