- 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.


svn path=/trunk/; revision=41710
This commit is contained in:
ReactOS Portable Systems Group 2009-06-30 10:45:36 +00:00
parent 15eecb0b40
commit c254a0e212
3 changed files with 32 additions and 137 deletions

View file

@ -160,7 +160,6 @@ ShutdownThreadMain(PVOID Context)
PspShutdownProcessManager(); PspShutdownProcessManager();
CmShutdownSystem(); CmShutdownSystem();
MiShutdownMemoryManager();
IoShutdownRegisteredFileSystems(); IoShutdownRegisteredFileSystems();
IoShutdownRegisteredDevices(); IoShutdownRegisteredDevices();

View file

@ -45,13 +45,10 @@ MemType[] =
"LoaderXIPRom " "LoaderXIPRom "
}; };
BOOLEAN IsThisAnNtAsSystem = FALSE;
MM_SYSTEMSIZE MmSystemSize = MmSmallSystem;
PVOID MiNonPagedPoolStart; PVOID MiNonPagedPoolStart;
ULONG MiNonPagedPoolLength; ULONG MiNonPagedPoolLength;
ULONG MmBootImageSize; ULONG MmBootImageSize;
ULONG MmNumberOfPhysicalPages, MmHighestPhysicalPage, MmLowestPhysicalPage; ULONG MmNumberOfPhysicalPages, MmHighestPhysicalPage, MmLowestPhysicalPage;
ULONG_PTR MiKSeg0Start, MiKSeg0End;
ULONG_PTR MmPfnDatabaseEnd; ULONG_PTR MmPfnDatabaseEnd;
PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor; PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor;
MEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptorOrg; MEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptorOrg;
@ -63,9 +60,6 @@ ULONG MmReadClusterSize;
MM_STATS MmStats; MM_STATS MmStats;
PMMSUPPORT MmKernelAddressSpace; PMMSUPPORT MmKernelAddressSpace;
extern KMUTANT MmSystemLoadLock; extern KMUTANT MmSystemLoadLock;
extern HANDLE MpwThreadHandle;
extern BOOLEAN MpwThreadShouldTerminate;
extern KEVENT MpwThreadEvent;
BOOLEAN MiDbgEnableMdDump = BOOLEAN MiDbgEnableMdDump =
#ifdef _ARM_ #ifdef _ARM_
TRUE; TRUE;
@ -75,41 +69,6 @@ FALSE;
/* PRIVATE FUNCTIONS *********************************************************/ /* 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 VOID
INIT_FUNCTION INIT_FUNCTION
NTAPI NTAPI
@ -223,18 +182,11 @@ MiDbgKernelLayout(VOID)
{ {
DPRINT1("%8s%12s\t\t%s\n", "Start", "End", "Type"); DPRINT1("%8s%12s\t\t%s\n", "Start", "End", "Type");
DPRINT1("0x%p - 0x%p\t%s\n", DPRINT1("0x%p - 0x%p\t%s\n",
KSEG0_BASE, MiKSeg0Start, MmSystemRangeStart, (ULONG_PTR)MmSystemRangeStart + MmBootImageSize,
"Undefined region"); "Boot Image Mapping Region");
DPRINT1("0x%p - 0x%p\t%s\n",
MiKSeg0Start, MiKSeg0End,
"FreeLDR Kernel mapping region");
DPRINT1("0x%p - 0x%p\t%s\n", DPRINT1("0x%p - 0x%p\t%s\n",
MmPfnDatabase, MmPfnDatabaseEnd, MmPfnDatabase, MmPfnDatabaseEnd,
"PFN Database region"); "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", DPRINT1("0x%p - 0x%p\t%s\n",
MiNonPagedPoolStart, (ULONG_PTR)MiNonPagedPoolStart + MiNonPagedPoolLength, MiNonPagedPoolStart, (ULONG_PTR)MiNonPagedPoolStart + MiNonPagedPoolLength,
"Non paged pool region"); "Non paged pool region");
@ -264,38 +216,6 @@ MiDbgDumpMemoryDescriptors(VOID)
DPRINT1("Total: %08lX (%d MB)\n", TotalPages, (TotalPages * PAGE_SIZE) / 1024 / 1024); 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 NTSTATUS
NTAPI NTAPI
MmArmInitSystem(IN ULONG Phase, MmArmInitSystem(IN ULONG Phase,
@ -305,10 +225,7 @@ VOID
INIT_FUNCTION INIT_FUNCTION
NTAPI NTAPI
MmInit1(VOID) MmInit1(VOID)
{ {
PLDR_DATA_TABLE_ENTRY LdrEntry;
ULONG Dummy[2];
/* Dump memory descriptors */ /* Dump memory descriptors */
if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors(); if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
@ -323,47 +240,23 @@ MmInit1(VOID)
DPRINT("MmSystemRangeStart: %08x\n", MmSystemRangeStart); DPRINT("MmSystemRangeStart: %08x\n", MmSystemRangeStart);
DPRINT("MmUserProbeAddress: %08x\n", MmUserProbeAddress); DPRINT("MmUserProbeAddress: %08x\n", MmUserProbeAddress);
DPRINT("MmHighestUserAddress:%08x\n", MmHighestUserAddress); DPRINT("MmHighestUserAddress:%08x\n", MmHighestUserAddress);
/* Initialize memory managment statistics */
RtlZeroMemory(&MmStats, sizeof(MmStats));
/* Count RAM */ /* Count RAM */
MiCountFreePagesInLoaderBlock(KeLoaderBlock); MiCountFreePagesInLoaderBlock(KeLoaderBlock);
DbgPrint("Used memory %dKb\n", (MmNumberOfPhysicalPages * PAGE_SIZE) / 1024); DbgPrint("Used memory %dKb\n", (MmNumberOfPhysicalPages * PAGE_SIZE) / 1024);
/* Initialize the kernel address space */ /* Initialize the kernel address space */
MmInitializeHandBuiltProcess(PsGetCurrentProcess(), Dummy); KeInitializeGuardedMutex(&PsGetCurrentProcess()->AddressCreationLock);
MmKernelAddressSpace = MmGetCurrentAddressSpace(); MmKernelAddressSpace = MmGetCurrentAddressSpace();
MmInitGlobalKernelPageDirectory(); 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 */ /* 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 = (ULONG_PTR)MmPfnDatabase + (MmHighestPhysicalPage * sizeof(MMPFN));
MmPfnDatabaseEnd = PAGE_ROUND_UP(MmPfnDatabaseEnd); MmPfnDatabaseEnd = PAGE_ROUND_UP(MmPfnDatabaseEnd);
/* /* Put nonpaged pool after the PFN database */
* FreeLDR maps 6MB starting at the kernel base address, followed by the MiNonPagedPoolStart = (PVOID)MmPfnDatabaseEnd;
* 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;
}
/* Length of non-paged pool */ /* Length of non-paged pool */
MiNonPagedPoolLength = MM_NONPAGED_POOL_SIZE; MiNonPagedPoolLength = MM_NONPAGED_POOL_SIZE;
@ -461,25 +354,3 @@ MmInitSystem(IN ULONG Phase,
return TRUE; return TRUE;
} }
/* PUBLIC FUNCTIONS **********************************************************/
/*
* @implemented
*/
BOOLEAN
NTAPI
MmIsThisAnNtAsSystem(VOID)
{
return IsThisAnNtAsSystem;
}
/*
* @implemented
*/
MM_SYSTEMSIZE
NTAPI
MmQuerySystemSize(VOID)
{
return MmSystemSize;
}

View file

@ -12,6 +12,11 @@
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
/* GLOBALS ********************************************************************/
BOOLEAN IsThisAnNtAsSystem = FALSE;
MM_SYSTEMSIZE MmSystemSize = MmSmallSystem;
/* PRIVATE FUNCTIONS **********************************************************/ /* PRIVATE FUNCTIONS **********************************************************/
NTSTATUS NTSTATUS
@ -117,4 +122,24 @@ BOOLEAN NTAPI MmIsNonPagedSystemAddressValid(PVOID VirtualAddress)
return MmIsAddressValid(VirtualAddress); return MmIsAddressValid(VirtualAddress);
} }
/*
* @implemented
*/
BOOLEAN
NTAPI
MmIsThisAnNtAsSystem(VOID)
{
return IsThisAnNtAsSystem;
}
/*
* @implemented
*/
MM_SYSTEMSIZE
NTAPI
MmQuerySystemSize(VOID)
{
return MmSystemSize;
}
/* EOF */ /* EOF */