diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index 650de252895..5b448efbbf1 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -14,6 +14,14 @@ #include #include "ntstrsafe.h" +/* Temporary hack */ +BOOLEAN +NTAPI +MmArmInitSystem( + IN ULONG Phase, + IN PLOADER_PARAMETER_BLOCK LoaderBlock +); + typedef struct _INIT_BUFFER { WCHAR DebugBuffer[256]; @@ -1045,7 +1053,7 @@ ExpInitializeExecutive(IN ULONG Cpu, 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 @@ Phase1InitializationDiscard(IN PVOID Context) 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 @@ Phase1InitializationDiscard(IN PVOID Context) 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); diff --git a/reactos/ntoskrnl/mm/ARM3/miarm.h b/reactos/ntoskrnl/mm/ARM3/miarm.h index 8338173ce16..3d919fdd00b 100644 --- a/reactos/ntoskrnl/mm/ARM3/miarm.h +++ b/reactos/ntoskrnl/mm/ARM3/miarm.h @@ -832,7 +832,7 @@ MiUnlockWorkingSet(IN PETHREAD Thread, KeLeaveGuardedRegion(); } -NTSTATUS +BOOLEAN NTAPI MmArmInitSystem( IN ULONG Phase, diff --git a/reactos/ntoskrnl/mm/ARM3/mminit.c b/reactos/ntoskrnl/mm/ARM3/mminit.c index 56156faeafa..2a63047f837 100644 --- a/reactos/ntoskrnl/mm/ARM3/mminit.c +++ b/reactos/ntoskrnl/mm/ARM3/mminit.c @@ -353,6 +353,14 @@ SIZE_T MmAllocationFragment; SIZE_T MmTotalCommitLimit; SIZE_T MmTotalCommitLimitMaximum; +/* Internal setting used for debugging memory descriptors */ +BOOLEAN MiDbgEnableMdDump = +#ifdef _ARM_ +TRUE; +#else +FALSE; +#endif + /* PRIVATE FUNCTIONS **********************************************************/ PFN_NUMBER @@ -1654,7 +1662,58 @@ MiBuildPagedPool(VOID) 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 @@ MmArmInitSystem(IN ULONG Phase, 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 @@ MmArmInitSystem(IN ULONG Phase, // // Always return success for now // - return STATUS_SUCCESS; + return TRUE; } /* EOF */ diff --git a/reactos/ntoskrnl/mm/mmfault.c b/reactos/ntoskrnl/mm/mmfault.c index 6f78d3f55ed..bf8b2e014c7 100644 --- a/reactos/ntoskrnl/mm/mmfault.c +++ b/reactos/ntoskrnl/mm/mmfault.c @@ -199,7 +199,7 @@ MmAccessFault(IN BOOLEAN StoreInstruction, 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 @@ MmAccessFault(IN BOOLEAN StoreInstruction, #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)) + /* Is there a ReactOS address space yet? */ + if (MmGetKernelAddressSpace()) { - /* Could this be a VAD fault from user-mode? */ - MemoryArea = MmLocateMemoryAreaByAddress(MmGetCurrentAddressSpace(), Address); + /* 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); + } } - 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())) { - // - // Hand it off to more competent hands... - // + /* This is an ARM3 fault */ DPRINT("ARM3 fault %p\n", MemoryArea); return MmArmAccessFault(StoreInstruction, Address, Mode, TrapInformation); } diff --git a/reactos/ntoskrnl/mm/mminit.c b/reactos/ntoskrnl/mm/mminit.c index 60ea7f70cc6..df2140c9cc7 100644 --- a/reactos/ntoskrnl/mm/mminit.c +++ b/reactos/ntoskrnl/mm/mminit.c @@ -19,37 +19,6 @@ 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 @@ ULONG MmReadClusterSize; UCHAR MmDisablePagingExecutive = 1; // Forced to off PMMPTE MmSharedUserDataPte; PMMSUPPORT MmKernelAddressSpace; -BOOLEAN MiDbgEnableMdDump = -#ifdef _ARM_ -TRUE; -#else -FALSE; -#endif /* PRIVATE FUNCTIONS *********************************************************/ @@ -314,27 +277,6 @@ MiDbgDumpAddressSpace(VOID) "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 MmMpwThreadMain(PVOID Ignored) { @@ -428,75 +370,65 @@ MmInitSystem(IN ULONG Phase, 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); + /* Initialize the kernel address space */ + ASSERT(Phase == 1); + KeInitializeGuardedMutex(&PsIdleProcess->AddressCreationLock); + MmKernelAddressSpace = &PsIdleProcess->Vm; - /* Intialize system memory areas */ - MiInitSystemMemoryAreas(); + /* 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(); - } + /* 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; }