diff --git a/reactos/boot/freeldr/freeldr/arcemul/mm.c b/reactos/boot/freeldr/freeldr/arcemul/mm.c index 697481af9ff..0a0472f9f74 100644 --- a/reactos/boot/freeldr/freeldr/arcemul/mm.c +++ b/reactos/boot/freeldr/freeldr/arcemul/mm.c @@ -34,8 +34,8 @@ static const MEMORY_DESCRIPTOR_INT MemoryDescriptors[] = #endif }; -MEMORY_DESCRIPTOR* -ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current) +const MEMORY_DESCRIPTOR* +ArcGetMemoryDescriptor(const MEMORY_DESCRIPTOR* Current) { MEMORY_DESCRIPTOR_INT* CurrentDescriptor; BIOS_MEMORY_MAP BiosMemoryMap[32]; @@ -114,7 +114,7 @@ ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current) // // Return first fixed memory descriptor // - return (MEMORY_DESCRIPTOR*)&MemoryDescriptors[0].m; + return &MemoryDescriptors[0].m; } else { @@ -141,7 +141,7 @@ ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current) // // Return first fixed memory descriptor // - return (MEMORY_DESCRIPTOR*)&MemoryDescriptors[0].m; + return &MemoryDescriptors[0].m; } else { @@ -161,7 +161,7 @@ ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current) // // Return next fixed descriptor // - return (MEMORY_DESCRIPTOR*)&MemoryDescriptors[CurrentDescriptor->Index + 1].m; + return &MemoryDescriptors[CurrentDescriptor->Index + 1].m; } else { diff --git a/reactos/boot/freeldr/freeldr/include/arcemul.h b/reactos/boot/freeldr/freeldr/include/arcemul.h index 45c34ab04b3..2d6a450d2ca 100644 --- a/reactos/boot/freeldr/freeldr/include/arcemul.h +++ b/reactos/boot/freeldr/freeldr/include/arcemul.h @@ -35,8 +35,8 @@ ArcGetConfigurationData( CONFIGURATION_COMPONENT* Component); /* mm.c */ -MEMORY_DESCRIPTOR* -ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current); +const MEMORY_DESCRIPTOR* +ArcGetMemoryDescriptor(const MEMORY_DESCRIPTOR* Current); /* time.c */ TIMEINFO* ArcGetTime(VOID); diff --git a/reactos/boot/freeldr/freeldr/include/machine.h b/reactos/boot/freeldr/freeldr/include/machine.h index ba2be4fdf6a..2ff379368ec 100644 --- a/reactos/boot/freeldr/freeldr/include/machine.h +++ b/reactos/boot/freeldr/freeldr/include/machine.h @@ -92,7 +92,6 @@ VOID MachVideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue); VOID MachVideoGetPaletteColor(UCHAR Color, UCHAR *Red, UCHAR *Green, UCHAR *Blue); VOID MachVideoSync(VOID); VOID MachBeep(VOID); -MEMORY_DESCRIPTOR* ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current); BOOLEAN MachDiskGetBootPath(char *BootPath, unsigned Size); BOOLEAN MachDiskNormalizeSystemPath(char *SystemPath, unsigned Size); BOOLEAN MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); diff --git a/reactos/boot/freeldr/freeldr/include/mm.h b/reactos/boot/freeldr/freeldr/include/mm.h index a7840e37791..7640498344e 100644 --- a/reactos/boot/freeldr/freeldr/include/mm.h +++ b/reactos/boot/freeldr/freeldr/include/mm.h @@ -42,6 +42,7 @@ typedef struct #define MM_PAGE_SIZE 4096 #define MM_PAGE_MASK 0xFFF #define MM_PAGE_SHIFT 12 +#define MM_MAX_PAGE 0xFFFFF #define MM_SIZE_TO_PAGES(a) \ ( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) ) @@ -53,6 +54,7 @@ typedef struct #define MM_PAGE_SIZE 4096 #define MM_PAGE_MASK 0xFFF #define MM_PAGE_SHIFT 12 +#define MM_MAX_PAGE 0xFFFFFFFFFFFFF #define MM_SIZE_TO_PAGES(a) \ ( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) ) diff --git a/reactos/boot/freeldr/freeldr/mm/meminit.c b/reactos/boot/freeldr/freeldr/mm/meminit.c index 3cafb3f6c8f..e8e399bcf3d 100644 --- a/reactos/boot/freeldr/freeldr/mm/meminit.c +++ b/reactos/boot/freeldr/freeldr/mm/meminit.c @@ -57,7 +57,7 @@ extern ULONG_PTR MmHeapStart; BOOLEAN MmInitializeMemoryManager(VOID) { #if DBG - MEMORY_DESCRIPTOR* MemoryDescriptor = NULL; + const MEMORY_DESCRIPTOR* MemoryDescriptor = NULL; #endif DPRINTM(DPRINT_MEMORY, "Initializing Memory Manager.\n"); @@ -158,7 +158,7 @@ ULONG MmGetPageNumberFromAddress(PVOID Address) ULONG MmGetAddressablePageCountIncludingHoles(VOID) { - MEMORY_DESCRIPTOR* MemoryDescriptor = NULL; + const MEMORY_DESCRIPTOR* MemoryDescriptor = NULL; ULONG PageCount; // @@ -197,7 +197,7 @@ ULONG MmGetAddressablePageCountIncludingHoles(VOID) PVOID MmFindLocationForPageLookupTable(ULONG TotalPageCount) { - MEMORY_DESCRIPTOR* MemoryDescriptor = NULL; + const MEMORY_DESCRIPTOR* MemoryDescriptor = NULL; ULONG PageLookupTableSize; ULONG PageLookupTablePages; ULONG PageLookupTableStartPage = 0; @@ -247,6 +247,17 @@ PVOID MmFindLocationForPageLookupTable(ULONG TotalPageCount) continue; } + // + // Can we use this address? + // + if (MemoryDescriptor->BasePage >= MM_MAX_PAGE) + { + // + // No. Process next descriptor + // + continue; + } + // // Memory block is more suitable than the previous one // @@ -263,7 +274,7 @@ PVOID MmFindLocationForPageLookupTable(ULONG TotalPageCount) VOID MmInitPageLookupTable(PVOID PageLookupTable, ULONG TotalPageCount) { - MEMORY_DESCRIPTOR* MemoryDescriptor = NULL; + const MEMORY_DESCRIPTOR* MemoryDescriptor = NULL; TYPE_OF_MEMORY MemoryMapPageAllocated; ULONG PageLookupTableStartPage; ULONG PageLookupTablePageCount; diff --git a/reactos/boot/freeldr/freeldr/windows/wlmemory.c b/reactos/boot/freeldr/freeldr/windows/wlmemory.c index bfa68ab904e..bfb46abebd6 100644 --- a/reactos/boot/freeldr/freeldr/windows/wlmemory.c +++ b/reactos/boot/freeldr/freeldr/windows/wlmemory.c @@ -139,9 +139,10 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, BOOLEAN Status; // - // Check for some weird stuff at the top + // Check for memory block after 4GB - we don't support it yet + // Note: Even last page before 4GB limit is not supported // - if (BasePage + PageCount > 0xF0000) + if (BasePage >= MM_MAX_PAGE) { // // Just skip this, without even adding to MAD list @@ -149,6 +150,17 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, return; } + // + // Check if last page is after 4GB limit and shorten this block if needed + // + if (BasePage + PageCount > MM_MAX_PAGE) + { + // + // shorten this block + // + PageCount = MM_MAX_PAGE - BasePage; + } + // // Set Base page, page count and type // @@ -255,7 +267,7 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, // Calculate parameters of the memory map MemoryMapStartPage = (ULONG_PTR)MemoryMap >> MM_PAGE_SHIFT; - MemoryMapSizeInPages = NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM); + MemoryMapSizeInPages = (NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM) + MM_PAGE_SIZE - 1) / MM_PAGE_SIZE; DPRINTM(DPRINT_WINDOWS, "Got memory map with %d entries\n", NoEntries);