Author: fireball Date: Wed Dec 31 06:21:36 2008 New Revision: 38487
URL: http://svn.reactos.org/svn/reactos?rev=38487&view=rev Log: - Add a new API to Freeldr's memory manager, which allows to override type of an already allocated memory. - WINLDR: Fix page tables buffer memory allocation so that it doesn't rely on luck anymore and always allocates a contiguous area of memory. Fixes spontaneous case of booting problem (immediate black screen after loading drivers, reboot of real hardware, halt of cpu in a virtual machine). - WINLDR: Fix some debug print.
Modified: trunk/reactos/boot/freeldr/freeldr/include/mm.h trunk/reactos/boot/freeldr/freeldr/mm/mm.c trunk/reactos/boot/freeldr/freeldr/windows/peloader.c trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c
Modified: trunk/reactos/boot/freeldr/freeldr/include/mm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/mm.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/mm.h [iso-8859-1] Wed Dec 31 06:21:36 2008 @@ -94,6 +94,7 @@ VOID MmFixupSystemMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG* MapCount); // Removes entries in the memory map that describe memory above 4G VOID MmUpdateLastFreePageHint(PVOID PageLookupTable, ULONG TotalPageCount); // Sets the LastFreePageHint to the last usable page of memory BOOLEAN MmAreMemoryPagesAvailable(PVOID PageLookupTable, ULONG TotalPageCount, PVOID PageAddress, ULONG PageCount); // Returns TRUE if the specified pages of memory are available, otherwise FALSE +VOID MmSetMemoryType(PVOID MemoryAddress, ULONG MemorySize, TYPE_OF_MEMORY NewType); // Use with EXTREME caution!
ULONG GetSystemMemorySize(VOID); // Returns the amount of total memory in the system PPAGE_LOOKUP_TABLE_ITEM MmGetMemoryMap(ULONG *NoEntries); // Returns a pointer to the memory mapping table and a number of entries in it
Modified: trunk/reactos/boot/freeldr/freeldr/mm/mm.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/mm/mm.... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/mm/mm.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/mm/mm.c [iso-8859-1] Wed Dec 31 06:21:36 2008 @@ -182,6 +182,22 @@ return MemPointer; }
+VOID MmSetMemoryType(PVOID MemoryAddress, ULONG MemorySize, TYPE_OF_MEMORY NewType) +{ + ULONG PagesNeeded; + ULONG StartPageNumber; + + // Find out how many blocks it will take to + // satisfy this allocation + PagesNeeded = ROUND_UP(MemorySize, MM_PAGE_SIZE) / MM_PAGE_SIZE; + + // Get the starting page number + StartPageNumber = MmGetPageNumberFromAddress(MemoryAddress); + + // Set new type for these pages + MmAllocatePagesInLookupTable(PageLookupTableAddress, StartPageNumber, PagesNeeded, NewType); +} + PVOID MmAllocateHighestMemoryBelowAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType) { ULONG PagesNeeded;
Modified: trunk/reactos/boot/freeldr/freeldr/windows/peloader.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/window... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/peloader.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/peloader.c [iso-8859-1] Wed Dec 31 06:21:36 2008 @@ -405,7 +405,7 @@ /* Size of data is less than the virtual size - fill up the remainder with zeroes */ if (SizeOfRawData < VirtualSize) { - DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage(): SORD %d < VS %d", SizeOfRawData, VirtualSize)); + DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage(): SORD %d < VS %d\n", SizeOfRawData, VirtualSize)); RtlZeroMemory((PVOID)(SectionHeader->VirtualAddress + (ULONG)PhysicalBase + SizeOfRawData), VirtualSize - SizeOfRawData); }
Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/window... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c [iso-8859-1] Wed Dec 31 06:21:36 2008 @@ -133,13 +133,15 @@ TotalSize = (1+1+NumPageTables*2)*MM_PAGE_SIZE;
// PDE+HAL+KernelPTEs == MemoryData - Buffer = MmAllocateMemoryWithType( - TotalSize - NumPageTables*MM_PAGE_SIZE, LoaderMemoryData); + Buffer = MmAllocateMemoryWithType(TotalSize, LoaderMemoryData);
// Physical PTEs = FirmwareTemporary - PhysicalPageTablesBuffer = MmAllocateMemoryWithType( - NumPageTables*MM_PAGE_SIZE, LoaderFirmwareTemporary); - + PhysicalPageTablesBuffer = (PUCHAR)Buffer + TotalSize - NumPageTables*MM_PAGE_SIZE; + MmSetMemoryType(PhysicalPageTablesBuffer, + NumPageTables*MM_PAGE_SIZE, + LoaderFirmwareTemporary); + + // This check is now redundant if (Buffer + (TotalSize - NumPageTables*MM_PAGE_SIZE) != PhysicalPageTablesBuffer) {