[ros-diffs] [ros-arm-bringup] 41710: - Move MmIsThisAnNtSystem and MmQueryMemorySize to mmsup.c instead of randomly in mminit.c. - Cleanup some externs that were never referenced in mminit.c. - Remove MiShutdownMemoryManager since it was dead code. - There is no need to define the MiKseg0Start/End variables and loop through the memory descriptors to find the last kernel image. We already have this information through LoaderPagesSpanned saved in MmBootImageSize. - Removed these variables, code that depended on them, and MiGetLastKernelAddress, and switch to just using MmBootImageSize, which simplifies things a lot. - Also simplify the way that the initial memory latout is setup. Now the PFN database will always start after MmBootImageSize + KSEG0_BASE, instead of relying on the fact FreeLDR, on certain machines, may have had leftover space in the 6MB allocation that it makes (And worse, assuming FreeLDR on all architectures will allocate 6MB). - This standardizes the PFN database address and makes the code portable. - Same for the nonpaged pool address. - Should not call MmInitializeHandBuiltProcess for the idle process -- this will be called for the system process in PsCreateProcess. - The only thing we need, as the comment says, is the kernel MADDRESS_SPACE, so just initialize the lock for it. - Do not zero MmStats since the load-linker takes care of that for us since it's a global.

ros-arm-bringup at svn.reactos.org ros-arm-bringup at svn.reactos.org
Tue Jun 30 12:45:37 CEST 2009


Author: ros-arm-bringup
Date: Tue Jun 30 14:45:36 2009
New Revision: 41710

URL: http://svn.reactos.org/svn/reactos?rev=41710&view=rev
Log:
- Move MmIsThisAnNtSystem and MmQueryMemorySize to mmsup.c instead of randomly in mminit.c.
- Cleanup some externs that were never referenced in mminit.c.
- Remove MiShutdownMemoryManager since it was dead code.
- There is no need to define the MiKseg0Start/End variables and loop through the memory descriptors to find the last kernel image. We already have this information through LoaderPagesSpanned saved in MmBootImageSize.
  - Removed these variables, code that depended on them, and MiGetLastKernelAddress, and switch to just using MmBootImageSize, which simplifies things a lot.
- Also simplify the way that the initial memory latout is setup. Now the PFN database will always start after MmBootImageSize + KSEG0_BASE, instead of relying on the fact FreeLDR, on certain machines, may have had leftover space in the 6MB allocation that it makes (And worse, assuming FreeLDR on all architectures will allocate 6MB).
  - This standardizes the PFN database address and makes the code portable.
  - Same for the nonpaged pool address.
- Should not call MmInitializeHandBuiltProcess for the idle process -- this will be called for the system process in PsCreateProcess.
  - The only thing we need, as the comment says, is the kernel MADDRESS_SPACE, so just initialize the lock for it.
- Do not zero MmStats since the load-linker takes care of that for us since it's a global.


Modified:
    trunk/reactos/ntoskrnl/ex/shutdown.c
    trunk/reactos/ntoskrnl/mm/mminit.c
    trunk/reactos/ntoskrnl/mm/mmsup.c

Modified: trunk/reactos/ntoskrnl/ex/shutdown.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/shutdown.c?rev=41710&r1=41709&r2=41710&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ex/shutdown.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ex/shutdown.c [iso-8859-1] Tue Jun 30 14:45:36 2009
@@ -160,7 +160,6 @@
    PspShutdownProcessManager();
 
    CmShutdownSystem();
-   MiShutdownMemoryManager();
    IoShutdownRegisteredFileSystems();
    IoShutdownRegisteredDevices();
 

Modified: trunk/reactos/ntoskrnl/mm/mminit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mminit.c?rev=41710&r1=41709&r2=41710&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] Tue Jun 30 14:45:36 2009
@@ -45,13 +45,10 @@
     "LoaderXIPRom      "
 };
 
-BOOLEAN IsThisAnNtAsSystem = FALSE;
-MM_SYSTEMSIZE MmSystemSize = MmSmallSystem;
 PVOID MiNonPagedPoolStart;
 ULONG MiNonPagedPoolLength;
 ULONG MmBootImageSize;
 ULONG MmNumberOfPhysicalPages, MmHighestPhysicalPage, MmLowestPhysicalPage;
-ULONG_PTR MiKSeg0Start, MiKSeg0End;
 ULONG_PTR MmPfnDatabaseEnd;
 PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor;
 MEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptorOrg;
@@ -63,9 +60,6 @@
 MM_STATS MmStats;
 PMMSUPPORT MmKernelAddressSpace;
 extern KMUTANT MmSystemLoadLock;
-extern HANDLE MpwThreadHandle;
-extern BOOLEAN MpwThreadShouldTerminate;
-extern KEVENT MpwThreadEvent;
 BOOLEAN MiDbgEnableMdDump =
 #ifdef _ARM_
 TRUE;
@@ -74,41 +68,6 @@
 #endif
 
 /* PRIVATE FUNCTIONS *********************************************************/
-
-VOID
-NTAPI
-MiShutdownMemoryManager(VOID)
-{
-#if 0
-    ULONG PagesWritten;
-    PETHREAD Thread;
-
-    /* Ask MPW thread to shutdown */
-    MpwThreadShouldTerminate = TRUE;
-    KeSetEvent(&MpwThreadEvent, IO_NO_INCREMENT, FALSE);
-
-    /* Wait for it */
-    ObReferenceObjectByHandle(MpwThreadHandle,
-                              THREAD_ALL_ACCESS,
-                              PsThreadType,
-                              KernelMode,
-                              (PVOID*)&Thread,
-                              NULL);
-
-    KeWaitForSingleObject(Thread,
-                          Executive,
-                          KernelMode,
-                          FALSE,
-                          NULL);
-
-    ObDereferenceObject(Thread);
-
-    /* Check if there are any dirty pages, and flush them.
-       There will be no other chance to do this later, since filesystems
-       are going to be shut down. */
-    CcRosFlushDirtyPages(128, &PagesWritten);
-#endif
-}
 
 VOID
 INIT_FUNCTION
@@ -223,18 +182,11 @@
 {
     DPRINT1("%8s%12s\t\t%s\n", "Start", "End", "Type");
     DPRINT1("0x%p - 0x%p\t%s\n",
-            KSEG0_BASE, MiKSeg0Start,
-            "Undefined region");
-    DPRINT1("0x%p - 0x%p\t%s\n",
-            MiKSeg0Start, MiKSeg0End,
-            "FreeLDR Kernel mapping region");
+            MmSystemRangeStart, (ULONG_PTR)MmSystemRangeStart + MmBootImageSize,
+            "Boot Image Mapping Region");
     DPRINT1("0x%p - 0x%p\t%s\n",
             MmPfnDatabase, MmPfnDatabaseEnd,
             "PFN Database region");
-    if (MmPfnDatabaseEnd != (ULONG_PTR)MiNonPagedPoolStart)
-    DPRINT1("0x%p - 0x%p\t%s\n",
-            MmPfnDatabaseEnd, MiNonPagedPoolStart,
-            "Remaining FreeLDR mapping");
     DPRINT1("0x%p - 0x%p\t%s\n",
              MiNonPagedPoolStart, (ULONG_PTR)MiNonPagedPoolStart + MiNonPagedPoolLength,
             "Non paged pool region");
@@ -264,38 +216,6 @@
     DPRINT1("Total: %08lX (%d MB)\n", TotalPages, (TotalPages * PAGE_SIZE) / 1024 / 1024);
 }
 
-ULONG_PTR
-NTAPI
-MiGetLastKernelAddress(VOID)
-{
-    PLIST_ENTRY NextEntry;
-    PMEMORY_ALLOCATION_DESCRIPTOR Md;
-    ULONG_PTR LastKrnlPhysAddr = 0;
-
-    for (NextEntry = KeLoaderBlock->MemoryDescriptorListHead.Flink;
-         NextEntry != &KeLoaderBlock->MemoryDescriptorListHead;
-         NextEntry = NextEntry->Flink)
-    {
-        Md = CONTAINING_RECORD(NextEntry, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
-
-        if (Md->MemoryType != LoaderFree &&
-            Md->MemoryType != LoaderFirmwareTemporary &&
-            Md->MemoryType != LoaderSpecialMemory)
-        {
-            if (Md->BasePage+Md->PageCount > LastKrnlPhysAddr)
-                LastKrnlPhysAddr = Md->BasePage+Md->PageCount;
-        }
-    }
-
-    /* Convert to a physical address */
-    return LastKrnlPhysAddr << PAGE_SHIFT;
-}
-
-
-VOID
-NTAPI
-MiInitHyperSpace(VOID);
-
 NTSTATUS
 NTAPI
 MmArmInitSystem(IN ULONG Phase,
@@ -305,10 +225,7 @@
 INIT_FUNCTION
 NTAPI
 MmInit1(VOID)
-{
-    PLDR_DATA_TABLE_ENTRY LdrEntry;
-    ULONG Dummy[2];
-    
+{    
     /* Dump memory descriptors */
     if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
 
@@ -323,47 +240,23 @@
     DPRINT("MmSystemRangeStart:  %08x\n", MmSystemRangeStart);
     DPRINT("MmUserProbeAddress:  %08x\n", MmUserProbeAddress);
     DPRINT("MmHighestUserAddress:%08x\n", MmHighestUserAddress);
-
-    /* Initialize memory managment statistics */
-    RtlZeroMemory(&MmStats, sizeof(MmStats));
     
     /* Count RAM */
     MiCountFreePagesInLoaderBlock(KeLoaderBlock);
     DbgPrint("Used memory %dKb\n", (MmNumberOfPhysicalPages * PAGE_SIZE) / 1024);
     
     /* Initialize the kernel address space */
-    MmInitializeHandBuiltProcess(PsGetCurrentProcess(), Dummy);
+    KeInitializeGuardedMutex(&PsGetCurrentProcess()->AddressCreationLock);
     MmKernelAddressSpace = MmGetCurrentAddressSpace();
     MmInitGlobalKernelPageDirectory();
-    
-    /* Get kernel address boundaries */
-    LdrEntry = CONTAINING_RECORD(KeLoaderBlock->LoadOrderListHead.Flink,
-                                 LDR_DATA_TABLE_ENTRY,
-                                 InLoadOrderLinks);
-    MiKSeg0Start = (ULONG_PTR)LdrEntry->DllBase | KSEG0_BASE;
-    MiKSeg0End = PAGE_ROUND_UP(MiGetLastKernelAddress()  | KSEG0_BASE);
 
     /* We'll put the PFN array right after the loaded modules */
-    MmPfnDatabase = (PVOID)MiKSeg0End;
+    MmPfnDatabase = (PVOID)((ULONG_PTR)MmSystemRangeStart + MmBootImageSize);
     MmPfnDatabaseEnd = (ULONG_PTR)MmPfnDatabase + (MmHighestPhysicalPage * sizeof(MMPFN));
     MmPfnDatabaseEnd = PAGE_ROUND_UP(MmPfnDatabaseEnd);
     
-    /*
-     * FreeLDR maps 6MB starting at the kernel base address, followed by the
-     * PFN database. If the PFN database doesn't go over the FreeLDR allocation
-     * then choose the end of the FreeLDR block. If it does go past the FreeLDR
-     * allocation, then choose the next PAGE_SIZE boundary.
-     */
-    if ((ULONG_PTR)MmPfnDatabaseEnd < (MiKSeg0Start + 0x600000))
-    {
-        /* Use the first memory following FreeLDR's 6MB mapping */
-        MiNonPagedPoolStart = (PVOID)((ULONG_PTR)MiKSeg0Start + 0x600000);
-    }
-    else
-    {
-        /* Use the next free available page */
-        MiNonPagedPoolStart = (PVOID)MmPfnDatabaseEnd;
-    }
+    /* Put nonpaged pool after the PFN database */
+    MiNonPagedPoolStart = (PVOID)MmPfnDatabaseEnd;
     
     /* Length of non-paged pool */
     MiNonPagedPoolLength = MM_NONPAGED_POOL_SIZE;
@@ -461,25 +354,3 @@
     return TRUE;
 }
 
-
-/* PUBLIC FUNCTIONS **********************************************************/
-
-/*
- * @implemented
- */
-BOOLEAN
-NTAPI
-MmIsThisAnNtAsSystem(VOID)
-{
-   return IsThisAnNtAsSystem;
-}
-
-/*
- * @implemented
- */
-MM_SYSTEMSIZE
-NTAPI
-MmQuerySystemSize(VOID)
-{
-   return MmSystemSize;
-}

Modified: trunk/reactos/ntoskrnl/mm/mmsup.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mmsup.c?rev=41710&r1=41709&r2=41710&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mmsup.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/mmsup.c [iso-8859-1] Tue Jun 30 14:45:36 2009
@@ -11,6 +11,11 @@
 #include <ntoskrnl.h>
 #define NDEBUG
 #include <debug.h>
+
+/* GLOBALS ********************************************************************/
+
+BOOLEAN IsThisAnNtAsSystem = FALSE;
+MM_SYSTEMSIZE MmSystemSize = MmSmallSystem;
 
 /* PRIVATE FUNCTIONS **********************************************************/
 
@@ -117,4 +122,24 @@
     return MmIsAddressValid(VirtualAddress);
 }
 
+/*
+ * @implemented
+ */
+BOOLEAN
+NTAPI
+MmIsThisAnNtAsSystem(VOID)
+{
+    return IsThisAnNtAsSystem;
+}
+
+/*
+ * @implemented
+ */
+MM_SYSTEMSIZE
+NTAPI
+MmQuerySystemSize(VOID)
+{
+    return MmSystemSize;
+}
+
 /* EOF */



More information about the Ros-diffs mailing list