diff --git a/reactos/boot/freeldr/freeldr/include/mm.h b/reactos/boot/freeldr/freeldr/include/mm.h index c8d17321ad1..3fc446718aa 100644 --- a/reactos/boot/freeldr/freeldr/include/mm.h +++ b/reactos/boot/freeldr/freeldr/include/mm.h @@ -94,6 +94,7 @@ ULONG MmFindAvailablePagesBeforePage(PVOID PageLookupTable, ULONG TotalPageCoun 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 diff --git a/reactos/boot/freeldr/freeldr/mm/mm.c b/reactos/boot/freeldr/freeldr/mm/mm.c index 23a9ae1dba3..445c75acba4 100644 --- a/reactos/boot/freeldr/freeldr/mm/mm.c +++ b/reactos/boot/freeldr/freeldr/mm/mm.c @@ -182,6 +182,22 @@ PVOID MmAllocateMemoryAtAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_ 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; diff --git a/reactos/boot/freeldr/freeldr/windows/peloader.c b/reactos/boot/freeldr/freeldr/windows/peloader.c index aa5e3ad9b80..57378086ab7 100644 --- a/reactos/boot/freeldr/freeldr/windows/peloader.c +++ b/reactos/boot/freeldr/freeldr/windows/peloader.c @@ -405,7 +405,7 @@ WinLdrLoadImage(IN PCHAR FileName, /* 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); } diff --git a/reactos/boot/freeldr/freeldr/windows/wlmemory.c b/reactos/boot/freeldr/freeldr/windows/wlmemory.c index 8156f96a0b1..9720929fdd1 100644 --- a/reactos/boot/freeldr/freeldr/windows/wlmemory.c +++ b/reactos/boot/freeldr/freeldr/windows/wlmemory.c @@ -133,13 +133,15 @@ MempAllocatePageTables() 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) {