[NTOS]: Clean up Mm initialization, there is now no-more RosMM stuff done in Phase 0 of MmInit, only ARM3 runs. The kernel address space and memory areas are only initialized in Phase 1, because that's where sections are started up, and they're the only thing other than VM which still use memory-areas.

svn path=/trunk/; revision=49200
This commit is contained in:
Sir Richard 2010-10-18 23:07:09 +00:00
parent 619ab27e1d
commit 609dce9faf
5 changed files with 150 additions and 151 deletions

View file

@ -14,6 +14,14 @@
#include <debug.h> #include <debug.h>
#include "ntstrsafe.h" #include "ntstrsafe.h"
/* Temporary hack */
BOOLEAN
NTAPI
MmArmInitSystem(
IN ULONG Phase,
IN PLOADER_PARAMETER_BLOCK LoaderBlock
);
typedef struct _INIT_BUFFER typedef struct _INIT_BUFFER
{ {
WCHAR DebugBuffer[256]; WCHAR DebugBuffer[256];
@ -1045,7 +1053,7 @@ ExpInitializeExecutive(IN ULONG Cpu,
if (!ExInitSystem()) KeBugCheck(PHASE0_INITIALIZATION_FAILED); if (!ExInitSystem()) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
/* Initialize the memory manager at phase 0 */ /* Initialize the memory manager at phase 0 */
if (!MmInitSystem(0, LoaderBlock)) KeBugCheck(PHASE0_INITIALIZATION_FAILED); if (!MmArmInitSystem(0, LoaderBlock)) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
/* Load boot symbols */ /* Load boot symbols */
ExpLoadBootSymbols(LoaderBlock); ExpLoadBootSymbols(LoaderBlock);
@ -1577,7 +1585,7 @@ Phase1InitializationDiscard(IN PVOID Context)
if (!MmInitSystem(1, LoaderBlock)) KeBugCheck(MEMORY1_INITIALIZATION_FAILED); if (!MmInitSystem(1, LoaderBlock)) KeBugCheck(MEMORY1_INITIALIZATION_FAILED);
/* Create NLS section */ /* Create NLS section */
ExpInitNls(KeLoaderBlock); ExpInitNls(LoaderBlock);
/* Initialize Cache Views */ /* Initialize Cache Views */
if (!CcInitializeCacheManager()) KeBugCheck(CACHE_INITIALIZATION_FAILED); if (!CcInitializeCacheManager()) KeBugCheck(CACHE_INITIALIZATION_FAILED);
@ -1862,8 +1870,8 @@ Phase1InitializationDiscard(IN PVOID Context)
NtClose(OptionHandle); NtClose(OptionHandle);
} }
/* Unmap Low memory, and initialize the MPW and Balancer Thread */ /* FIXME: This doesn't do anything for now */
MmInitSystem(2, LoaderBlock); MmArmInitSystem(2, LoaderBlock);
/* Update progress bar */ /* Update progress bar */
InbvUpdateProgressBar(80); InbvUpdateProgressBar(80);

View file

@ -832,7 +832,7 @@ MiUnlockWorkingSet(IN PETHREAD Thread,
KeLeaveGuardedRegion(); KeLeaveGuardedRegion();
} }
NTSTATUS BOOLEAN
NTAPI NTAPI
MmArmInitSystem( MmArmInitSystem(
IN ULONG Phase, IN ULONG Phase,

View file

@ -353,6 +353,14 @@ SIZE_T MmAllocationFragment;
SIZE_T MmTotalCommitLimit; SIZE_T MmTotalCommitLimit;
SIZE_T MmTotalCommitLimitMaximum; SIZE_T MmTotalCommitLimitMaximum;
/* Internal setting used for debugging memory descriptors */
BOOLEAN MiDbgEnableMdDump =
#ifdef _ARM_
TRUE;
#else
FALSE;
#endif
/* PRIVATE FUNCTIONS **********************************************************/ /* PRIVATE FUNCTIONS **********************************************************/
PFN_NUMBER PFN_NUMBER
@ -1654,7 +1662,58 @@ MiBuildPagedPool(VOID)
MiInitializeSystemSpaceMap(NULL); MiInitializeSystemSpaceMap(NULL);
} }
NTSTATUS VOID
NTAPI
MiDbgDumpMemoryDescriptors(VOID)
{
PLIST_ENTRY NextEntry;
PMEMORY_ALLOCATION_DESCRIPTOR Md;
ULONG TotalPages = 0;
PCHAR
MemType[] =
{
"ExceptionBlock ",
"SystemBlock ",
"Free ",
"Bad ",
"LoadedProgram ",
"FirmwareTemporary ",
"FirmwarePermanent ",
"OsloaderHeap ",
"OsloaderStack ",
"SystemCode ",
"HalCode ",
"BootDriver ",
"ConsoleInDriver ",
"ConsoleOutDriver ",
"StartupDpcStack ",
"StartupKernelStack",
"StartupPanicStack ",
"StartupPcrPage ",
"StartupPdrPage ",
"RegistryData ",
"MemoryData ",
"NlsData ",
"SpecialMemory ",
"BBTMemory ",
"LoaderReserve ",
"LoaderXIPRom "
};
DPRINT1("Base\t\tLength\t\tType\n");
for (NextEntry = KeLoaderBlock->MemoryDescriptorListHead.Flink;
NextEntry != &KeLoaderBlock->MemoryDescriptorListHead;
NextEntry = NextEntry->Flink)
{
Md = CONTAINING_RECORD(NextEntry, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
DPRINT1("%08lX\t%08lX\t%s\n", Md->BasePage, Md->PageCount, MemType[Md->MemoryType]);
TotalPages += Md->PageCount;
}
DPRINT1("Total: %08lX (%d MB)\n", TotalPages, (TotalPages * PAGE_SIZE) / 1024 / 1024);
}
BOOLEAN
NTAPI NTAPI
MmArmInitSystem(IN ULONG Phase, MmArmInitSystem(IN ULONG Phase,
IN PLOADER_PARAMETER_BLOCK LoaderBlock) IN PLOADER_PARAMETER_BLOCK LoaderBlock)
@ -1665,6 +1724,9 @@ MmArmInitSystem(IN ULONG Phase,
PPHYSICAL_MEMORY_RUN Run; PPHYSICAL_MEMORY_RUN Run;
PFN_NUMBER PageCount; PFN_NUMBER PageCount;
/* Dump memory descriptors */
if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
// //
// Instantiate memory that we don't consider RAM/usable // Instantiate memory that we don't consider RAM/usable
// We use the same exclusions that Windows does, in order to try to be // We use the same exclusions that Windows does, in order to try to be
@ -2065,7 +2127,7 @@ MmArmInitSystem(IN ULONG Phase,
// //
// Always return success for now // Always return success for now
// //
return STATUS_SUCCESS; return TRUE;
} }
/* EOF */ /* EOF */

View file

@ -199,7 +199,7 @@ MmAccessFault(IN BOOLEAN StoreInstruction,
IN KPROCESSOR_MODE Mode, IN KPROCESSOR_MODE Mode,
IN PVOID TrapInformation) IN PVOID TrapInformation)
{ {
PMEMORY_AREA MemoryArea; PMEMORY_AREA MemoryArea = NULL;
/* Cute little hack for ROS */ /* Cute little hack for ROS */
if ((ULONG_PTR)Address >= (ULONG_PTR)MmSystemRangeStart) if ((ULONG_PTR)Address >= (ULONG_PTR)MmSystemRangeStart)
@ -214,27 +214,24 @@ MmAccessFault(IN BOOLEAN StoreInstruction,
#endif #endif
} }
/* /* Is there a ReactOS address space yet? */
* Check if this is an ARM3 memory area or if there's no memory area at all. if (MmGetKernelAddressSpace())
* The latter can happen early in the boot cycle when ARM3 paged pool is in {
* use before having defined the memory areas proper. /* Check if this is an ARM3 memory area */
* A proper fix would be to define memory areas in the ARM3 code, but we want
* to avoid adding this ReactOS-specific construct to ARM3 code.
* Either way, in the future, as ReactOS-paged pool is eliminated, this hack
* can go away.
*/
MemoryArea = MmLocateMemoryAreaByAddress(MmGetKernelAddressSpace(), Address); MemoryArea = MmLocateMemoryAreaByAddress(MmGetKernelAddressSpace(), Address);
if (!(MemoryArea) && (Address <= MM_HIGHEST_USER_ADDRESS)) if (!(MemoryArea) && (Address <= MM_HIGHEST_USER_ADDRESS))
{ {
/* Could this be a VAD fault from user-mode? */ /* Could this be a VAD fault from user-mode? */
MemoryArea = MmLocateMemoryAreaByAddress(MmGetCurrentAddressSpace(), Address); MemoryArea = MmLocateMemoryAreaByAddress(MmGetCurrentAddressSpace(), Address);
} }
if ((!(MemoryArea) && ((ULONG_PTR)Address >= (ULONG_PTR)MmPagedPoolStart)) || }
((MemoryArea) && (MemoryArea->Type == MEMORY_AREA_OWNED_BY_ARM3)))
/* Is this an ARM3 memory area, or is there no address space yet? */
if (((MemoryArea) && (MemoryArea->Type == MEMORY_AREA_OWNED_BY_ARM3)) ||
(!(MemoryArea) && ((ULONG_PTR)Address >= (ULONG_PTR)MmPagedPoolStart)) ||
(!MmGetKernelAddressSpace()))
{ {
// /* This is an ARM3 fault */
// Hand it off to more competent hands...
//
DPRINT("ARM3 fault %p\n", MemoryArea); DPRINT("ARM3 fault %p\n", MemoryArea);
return MmArmAccessFault(StoreInstruction, Address, Mode, TrapInformation); return MmArmAccessFault(StoreInstruction, Address, Mode, TrapInformation);
} }

View file

@ -19,37 +19,6 @@
VOID NTAPI MiInitializeUserPfnBitmap(VOID); VOID NTAPI MiInitializeUserPfnBitmap(VOID);
PCHAR
MemType[] =
{
"ExceptionBlock ",
"SystemBlock ",
"Free ",
"Bad ",
"LoadedProgram ",
"FirmwareTemporary ",
"FirmwarePermanent ",
"OsloaderHeap ",
"OsloaderStack ",
"SystemCode ",
"HalCode ",
"BootDriver ",
"ConsoleInDriver ",
"ConsoleOutDriver ",
"StartupDpcStack ",
"StartupKernelStack",
"StartupPanicStack ",
"StartupPcrPage ",
"StartupPdrPage ",
"RegistryData ",
"MemoryData ",
"NlsData ",
"SpecialMemory ",
"BBTMemory ",
"LoaderReserve ",
"LoaderXIPRom "
};
HANDLE MpwThreadHandle; HANDLE MpwThreadHandle;
KEVENT MpwThreadEvent; KEVENT MpwThreadEvent;
@ -61,12 +30,6 @@ ULONG MmReadClusterSize;
UCHAR MmDisablePagingExecutive = 1; // Forced to off UCHAR MmDisablePagingExecutive = 1; // Forced to off
PMMPTE MmSharedUserDataPte; PMMPTE MmSharedUserDataPte;
PMMSUPPORT MmKernelAddressSpace; PMMSUPPORT MmKernelAddressSpace;
BOOLEAN MiDbgEnableMdDump =
#ifdef _ARM_
TRUE;
#else
FALSE;
#endif
/* PRIVATE FUNCTIONS *********************************************************/ /* PRIVATE FUNCTIONS *********************************************************/
@ -314,27 +277,6 @@ MiDbgDumpAddressSpace(VOID)
"Non Paged Pool Expansion PTE Space"); "Non Paged Pool Expansion PTE Space");
} }
VOID
NTAPI
MiDbgDumpMemoryDescriptors(VOID)
{
PLIST_ENTRY NextEntry;
PMEMORY_ALLOCATION_DESCRIPTOR Md;
ULONG TotalPages = 0;
DPRINT1("Base\t\tLength\t\tType\n");
for (NextEntry = KeLoaderBlock->MemoryDescriptorListHead.Flink;
NextEntry != &KeLoaderBlock->MemoryDescriptorListHead;
NextEntry = NextEntry->Flink)
{
Md = CONTAINING_RECORD(NextEntry, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
DPRINT1("%08lX\t%08lX\t%s\n", Md->BasePage, Md->PageCount, MemType[Md->MemoryType]);
TotalPages += Md->PageCount;
}
DPRINT1("Total: %08lX (%d MB)\n", TotalPages, (TotalPages * PAGE_SIZE) / 1024 / 1024);
}
NTSTATUS NTAPI NTSTATUS NTAPI
MmMpwThreadMain(PVOID Ignored) MmMpwThreadMain(PVOID Ignored)
{ {
@ -428,27 +370,18 @@ MmInitSystem(IN ULONG Phase,
MMPTE TempPte = ValidKernelPte; MMPTE TempPte = ValidKernelPte;
PFN_NUMBER PageFrameNumber; PFN_NUMBER PageFrameNumber;
if (Phase == 0)
{
/* Initialize the kernel address space */ /* Initialize the kernel address space */
KeInitializeGuardedMutex(&PsGetCurrentProcess()->AddressCreationLock); ASSERT(Phase == 1);
MmKernelAddressSpace = MmGetCurrentAddressSpace(); KeInitializeGuardedMutex(&PsIdleProcess->AddressCreationLock);
MmInitGlobalKernelPageDirectory(); MmKernelAddressSpace = &PsIdleProcess->Vm;
/* Dump memory descriptors */
if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
/* Initialize ARM³ in phase 0 */
MmArmInitSystem(0, KeLoaderBlock);
/* Intialize system memory areas */ /* Intialize system memory areas */
MiInitSystemMemoryAreas(); MiInitSystemMemoryAreas();
/* Dump the address space */ /* Dump the address space */
MiDbgDumpAddressSpace(); MiDbgDumpAddressSpace();
}
else if (Phase == 1) MmInitGlobalKernelPageDirectory();
{
MiInitializeUserPfnBitmap(); MiInitializeUserPfnBitmap();
MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory); MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
MmInitializeRmapList(); MmInitializeRmapList();
@ -496,7 +429,6 @@ MmInitSystem(IN ULONG Phase,
/* Initialize the balance set manager */ /* Initialize the balance set manager */
MmInitBsmThread(); MmInitBsmThread();
}
return TRUE; return TRUE;
} }