[FREELDR/x64] Allow using memory above 4GB on x64

This splits MM_MAX_PAGE into the maximum addressable PFN (which is 2^20-1 on x86, 2^26-1 on x86PAE and 2^36-1 on x64) and the maximum mapped/accessible virtual memory MM_MAX_PAGE_LOADER (which is 4 GB on x86, since paging is disabled, but only 1 GB on x64, since only that much is identity-mapped).
This commit is contained in:
Timo Kreuzer 2021-06-13 11:26:06 +02:00
parent e6fa62a8d2
commit d0f6d2cf6e
2 changed files with 11 additions and 5 deletions

View file

@ -51,7 +51,12 @@ typedef struct _FREELDR_MEMORY_DESCRIPTOR
#define MM_PAGE_SIZE 4096
#define MM_PAGE_MASK 0xFFF
#define MM_PAGE_SHIFT 12
#define MM_MAX_PAGE 0xFFFFF
#if defined(_X86PAE_)
#define MM_MAX_PAGE 0x3FFFFFF /* 26 bits for the PFN */
#else
#define MM_MAX_PAGE 0xFFFFF /* 20 bits for the PFN */
#endif
#define MM_MAX_PAGE_LOADER 0xFFFFF /* 4 GB flat address range */
#define MM_SIZE_TO_PAGES(a) \
( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) )
@ -63,7 +68,8 @@ typedef struct _FREELDR_MEMORY_DESCRIPTOR
#define MM_PAGE_SIZE 4096
#define MM_PAGE_MASK 0xFFF
#define MM_PAGE_SHIFT 12
#define MM_MAX_PAGE 0x3FFFF /* freeldr only maps 1 GB */
#define MM_MAX_PAGE 0xFFFFFFFFF /* 36 bits for the PFN */
#define MM_MAX_PAGE_LOADER 0x3FFFF /* on x64 freeldr only maps 1 GB */
#define MM_SIZE_TO_PAGES(a) \
( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) )

View file

@ -1,7 +1,7 @@
/*
* FreeLoader
* Copyright (C) 2006-2008 Aleksey Bragin <aleksey@reactos.org>
* Copyright (C) 2006-2009 Hervé Poussineau <hpoussin@reactos.org>
* Copyright (C) 2006-2009 Hervé Poussineau <hpoussin@reactos.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -438,7 +438,7 @@ PVOID MmFindLocationForPageLookupTable(PFN_NUMBER TotalPageCount)
if (MemoryDescriptor->BasePage < CandidateBasePage) continue;
// Continue, if the address is too high
if (MemoryDescriptor->BasePage + RequiredPages >= MM_MAX_PAGE) continue;
if (MemoryDescriptor->BasePage + RequiredPages >= MM_MAX_PAGE_LOADER) continue;
// Memory block is more suitable than the previous one
CandidateBasePage = MemoryDescriptor->BasePage;
@ -447,7 +447,7 @@ PVOID MmFindLocationForPageLookupTable(PFN_NUMBER TotalPageCount)
// Calculate the end address for the lookup table
PageLookupTableEndPage = min(CandidateBasePage + CandidatePageCount,
MM_MAX_PAGE);
MM_MAX_PAGE_LOADER);
// Calculate the virtual address
PageLookupTableMemAddress = (PVOID)((PageLookupTableEndPage * PAGE_SIZE)