Author: sir_richard
Date: Mon Oct 18 23:07:09 2010
New Revision: 49200
URL:
http://svn.reactos.org/svn/reactos?rev=49200&view=rev
Log:
[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.
Modified:
trunk/reactos/ntoskrnl/ex/init.c
trunk/reactos/ntoskrnl/mm/ARM3/miarm.h
trunk/reactos/ntoskrnl/mm/ARM3/mminit.c
trunk/reactos/ntoskrnl/mm/mmfault.c
trunk/reactos/ntoskrnl/mm/mminit.c
Modified: trunk/reactos/ntoskrnl/ex/init.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/init.c?rev=492…
==============================================================================
--- trunk/reactos/ntoskrnl/ex/init.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ex/init.c [iso-8859-1] Mon Oct 18 23:07:09 2010
@@ -13,6 +13,14 @@
#define NDEBUG
#include <debug.h>
#include "ntstrsafe.h"
+
+/* Temporary hack */
+BOOLEAN
+NTAPI
+MmArmInitSystem(
+ IN ULONG Phase,
+ IN PLOADER_PARAMETER_BLOCK LoaderBlock
+);
typedef struct _INIT_BUFFER
{
@@ -1045,7 +1053,7 @@
if (!ExInitSystem()) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
/* 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 */
ExpLoadBootSymbols(LoaderBlock);
@@ -1577,7 +1585,7 @@
if (!MmInitSystem(1, LoaderBlock)) KeBugCheck(MEMORY1_INITIALIZATION_FAILED);
/* Create NLS section */
- ExpInitNls(KeLoaderBlock);
+ ExpInitNls(LoaderBlock);
/* Initialize Cache Views */
if (!CcInitializeCacheManager()) KeBugCheck(CACHE_INITIALIZATION_FAILED);
@@ -1862,8 +1870,8 @@
NtClose(OptionHandle);
}
- /* Unmap Low memory, and initialize the MPW and Balancer Thread */
- MmInitSystem(2, LoaderBlock);
+ /* FIXME: This doesn't do anything for now */
+ MmArmInitSystem(2, LoaderBlock);
/* Update progress bar */
InbvUpdateProgressBar(80);
Modified: trunk/reactos/ntoskrnl/mm/ARM3/miarm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/miarm.h?r…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] Mon Oct 18 23:07:09 2010
@@ -832,7 +832,7 @@
KeLeaveGuardedRegion();
}
-NTSTATUS
+BOOLEAN
NTAPI
MmArmInitSystem(
IN ULONG Phase,
Modified: trunk/reactos/ntoskrnl/mm/ARM3/mminit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/mminit.c?…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/mminit.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/mminit.c [iso-8859-1] Mon Oct 18 23:07:09 2010
@@ -352,6 +352,14 @@
// FIXME: They should be moved elsewhere since it's not an "init" setting?
SIZE_T MmTotalCommitLimit;
SIZE_T MmTotalCommitLimitMaximum;
+
+/* Internal setting used for debugging memory descriptors */
+BOOLEAN MiDbgEnableMdDump =
+#ifdef _ARM_
+TRUE;
+#else
+FALSE;
+#endif
/* PRIVATE FUNCTIONS **********************************************************/
@@ -1654,7 +1662,58 @@
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
MmArmInitSystem(IN ULONG Phase,
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
@@ -1665,6 +1724,9 @@
PPHYSICAL_MEMORY_RUN Run;
PFN_NUMBER PageCount;
+ /* Dump memory descriptors */
+ if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
+
//
// Instantiate memory that we don't consider RAM/usable
// We use the same exclusions that Windows does, in order to try to be
@@ -2065,7 +2127,7 @@
//
// Always return success for now
//
- return STATUS_SUCCESS;
+ return TRUE;
}
/* EOF */
Modified: trunk/reactos/ntoskrnl/mm/mmfault.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mmfault.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mmfault.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/mmfault.c [iso-8859-1] Mon Oct 18 23:07:09 2010
@@ -199,7 +199,7 @@
IN KPROCESSOR_MODE Mode,
IN PVOID TrapInformation)
{
- PMEMORY_AREA MemoryArea;
+ PMEMORY_AREA MemoryArea = NULL;
/* Cute little hack for ROS */
if ((ULONG_PTR)Address >= (ULONG_PTR)MmSystemRangeStart)
@@ -214,27 +214,24 @@
#endif
}
- /*
- * Check if this is an ARM3 memory area or if there's no memory area at all.
- * The latter can happen early in the boot cycle when ARM3 paged pool is in
- * use before having defined the memory areas proper.
- * 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);
- if (!(MemoryArea) && (Address <= MM_HIGHEST_USER_ADDRESS))
- {
- /* Could this be a VAD fault from user-mode? */
- MemoryArea = MmLocateMemoryAreaByAddress(MmGetCurrentAddressSpace(), Address);
- }
- if ((!(MemoryArea) && ((ULONG_PTR)Address >= (ULONG_PTR)MmPagedPoolStart))
||
- ((MemoryArea) && (MemoryArea->Type == MEMORY_AREA_OWNED_BY_ARM3)))
- {
- //
- // Hand it off to more competent hands...
- //
+ /* Is there a ReactOS address space yet? */
+ if (MmGetKernelAddressSpace())
+ {
+ /* Check if this is an ARM3 memory area */
+ MemoryArea = MmLocateMemoryAreaByAddress(MmGetKernelAddressSpace(), Address);
+ if (!(MemoryArea) && (Address <= MM_HIGHEST_USER_ADDRESS))
+ {
+ /* Could this be a VAD fault from user-mode? */
+ MemoryArea = MmLocateMemoryAreaByAddress(MmGetCurrentAddressSpace(),
Address);
+ }
+ }
+
+ /* 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 */
DPRINT("ARM3 fault %p\n", MemoryArea);
return MmArmAccessFault(StoreInstruction, Address, Mode, TrapInformation);
}
Modified: trunk/reactos/ntoskrnl/mm/mminit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mminit.c?rev=4…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] Mon Oct 18 23:07:09 2010
@@ -18,37 +18,6 @@
/* GLOBALS *******************************************************************/
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;
KEVENT MpwThreadEvent;
@@ -61,12 +30,6 @@
UCHAR MmDisablePagingExecutive = 1; // Forced to off
PMMPTE MmSharedUserDataPte;
PMMSUPPORT MmKernelAddressSpace;
-BOOLEAN MiDbgEnableMdDump =
-#ifdef _ARM_
-TRUE;
-#else
-FALSE;
-#endif
/* PRIVATE FUNCTIONS *********************************************************/
@@ -312,27 +275,6 @@
DPRINT1(" 0x%p - 0x%p\t%s\n",
MmNonPagedPoolExpansionStart, MmNonPagedPoolEnd,
"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
@@ -428,75 +370,65 @@
MMPTE TempPte = ValidKernelPte;
PFN_NUMBER PageFrameNumber;
- if (Phase == 0)
- {
- /* Initialize the kernel address space */
- KeInitializeGuardedMutex(&PsGetCurrentProcess()->AddressCreationLock);
- MmKernelAddressSpace = MmGetCurrentAddressSpace();
- MmInitGlobalKernelPageDirectory();
-
- /* Dump memory descriptors */
- if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
-
- /* Initialize ARM³ in phase 0 */
- MmArmInitSystem(0, KeLoaderBlock);
-
- /* Intialize system memory areas */
- MiInitSystemMemoryAreas();
-
- /* Dump the address space */
- MiDbgDumpAddressSpace();
- }
- else if (Phase == 1)
- {
- MiInitializeUserPfnBitmap();
- MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
- MmInitializeRmapList();
- MmInitializePageOp();
- MmInitSectionImplementation();
- MmInitPagingFile();
-
- //
- // Create a PTE to double-map the shared data section. We allocate it
- // from paged pool so that we can't fault when trying to touch the PTE
- // itself (to map it), since paged pool addresses will already be mapped
- // by the fault handler.
- //
- MmSharedUserDataPte = ExAllocatePoolWithTag(PagedPool,
- sizeof(MMPTE),
- ' mM');
- if (!MmSharedUserDataPte) return FALSE;
-
- //
- // Now get the PTE for shared data, and read the PFN that holds it
- //
- PointerPte = MiAddressToPte((PVOID)KI_USER_SHARED_DATA);
- ASSERT(PointerPte->u.Hard.Valid == 1);
- PageFrameNumber = PFN_FROM_PTE(PointerPte);
-
- /* Build the PTE and write it */
- MI_MAKE_HARDWARE_PTE_KERNEL(&TempPte,
- PointerPte,
- MM_READONLY,
- PageFrameNumber);
- *MmSharedUserDataPte = TempPte;
-
- /* Setup the memory threshold events */
- if (!MiInitializeMemoryEvents()) return FALSE;
-
- /*
- * Unmap low memory
- */
- MiInitBalancerThread();
-
- /*
- * Initialise the modified page writer.
- */
- MmInitMpwThread();
-
- /* Initialize the balance set manager */
- MmInitBsmThread();
- }
+ /* Initialize the kernel address space */
+ ASSERT(Phase == 1);
+ KeInitializeGuardedMutex(&PsIdleProcess->AddressCreationLock);
+ MmKernelAddressSpace = &PsIdleProcess->Vm;
+
+ /* Intialize system memory areas */
+ MiInitSystemMemoryAreas();
+
+ /* Dump the address space */
+ MiDbgDumpAddressSpace();
+
+ MmInitGlobalKernelPageDirectory();
+ MiInitializeUserPfnBitmap();
+ MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
+ MmInitializeRmapList();
+ MmInitializePageOp();
+ MmInitSectionImplementation();
+ MmInitPagingFile();
+
+ //
+ // Create a PTE to double-map the shared data section. We allocate it
+ // from paged pool so that we can't fault when trying to touch the PTE
+ // itself (to map it), since paged pool addresses will already be mapped
+ // by the fault handler.
+ //
+ MmSharedUserDataPte = ExAllocatePoolWithTag(PagedPool,
+ sizeof(MMPTE),
+ ' mM');
+ if (!MmSharedUserDataPte) return FALSE;
+
+ //
+ // Now get the PTE for shared data, and read the PFN that holds it
+ //
+ PointerPte = MiAddressToPte((PVOID)KI_USER_SHARED_DATA);
+ ASSERT(PointerPte->u.Hard.Valid == 1);
+ PageFrameNumber = PFN_FROM_PTE(PointerPte);
+
+ /* Build the PTE and write it */
+ MI_MAKE_HARDWARE_PTE_KERNEL(&TempPte,
+ PointerPte,
+ MM_READONLY,
+ PageFrameNumber);
+ *MmSharedUserDataPte = TempPte;
+
+ /* Setup the memory threshold events */
+ if (!MiInitializeMemoryEvents()) return FALSE;
+
+ /*
+ * Unmap low memory
+ */
+ MiInitBalancerThread();
+
+ /*
+ * Initialise the modified page writer.
+ */
+ MmInitMpwThread();
+
+ /* Initialize the balance set manager */
+ MmInitBsmThread();
return TRUE;
}