[FREELDR]

When generating the memory descriptor list, do not map the pages at the same time, since that requires allocating page tables, which will alter the state of pages, that might already have been processed. Instead map everything beforehand. This has not had any impact on x86, since the pfn database initialization code mindlessly adds all mapped pages as valid, even if they were reported as free by the OS loader. But proper Mm code does not necessarily do this.

svn path=/trunk/; revision=58760
This commit is contained in:
Timo Kreuzer 2013-04-14 18:41:54 +00:00
parent 291e52f39e
commit 6090c3ee06
2 changed files with 45 additions and 42 deletions

View file

@ -183,13 +183,16 @@ MempSetupPaging(IN PFN_NUMBER StartPage,
}
/* Kernel mapping */
if (MempMapRangeOfPages(StartPage * PAGE_SIZE + KSEG0_BASE,
StartPage * PAGE_SIZE,
NumberOfPages) != NumberOfPages)
if (KernelMapping)
{
ERR("Failed to map pages %ld, %ld\n",
StartPage, NumberOfPages);
return FALSE;
if (MempMapRangeOfPages(StartPage * PAGE_SIZE + KSEG0_BASE,
StartPage * PAGE_SIZE,
NumberOfPages) != NumberOfPages)
{
ERR("Failed to map pages %ld, %ld\n",
StartPage, NumberOfPages);
return FALSE;
}
}
return TRUE;
@ -343,7 +346,7 @@ WinLdrSetProcessorContext(void)
/* Disable Interrupts */
_disable();
/* Re-initialize EFLAGS */
/* Re-initalize EFLAGS */
__writeeflags(0);
/* Set the new PML4 */

View file

@ -67,30 +67,21 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
PFN_NUMBER PageCount,
ULONG Type)
{
BOOLEAN Status = TRUE;
TRACE("MempAddMemoryBlock(BasePage=0x%lx, PageCount=0x%lx, Type=%ld)\n",
BasePage, PageCount, Type);
//
// Check for memory block after 4GB - we don't support it yet
// Note: Even last page before 4GB limit is not supported
//
/* Check for memory block after 4GB - we don't support it yet
Note: Even last page before 4GB limit is not supported */
if (BasePage >= MM_MAX_PAGE)
{
//
// Just skip this, without even adding to MAD list
//
/* Just skip this, without even adding to MAD list */
return;
}
//
// Check if last page is after 4GB limit and shorten this block if needed
//
/* Check if last page is after 4GB limit and shorten this block if needed */
if (BasePage + PageCount > MM_MAX_PAGE)
{
//
// shorten this block
//
/* Shorten this block */
PageCount = MM_MAX_PAGE - BasePage;
}
@ -101,36 +92,30 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
return;
}
/* Get rid of the loader heap */
//if (Type == LoaderOsloaderHeap) Type = LoaderFirmwareTemporary;
//
// Set Base page, page count and type
//
/* Set Base page, page count and type */
Mad[MadCount].BasePage = BasePage;
Mad[MadCount].PageCount = PageCount;
Mad[MadCount].MemoryType = Type;
//
// Add descriptor
//
/* Add descriptor */
WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
MadCount++;
}
VOID
MempSetupPagingForRegion(
PFN_NUMBER BasePage,
PFN_NUMBER PageCount,
ULONG Type)
{
BOOLEAN Status = TRUE;
TRACE("MempSetupPagingForRegion(BasePage=0x%lx, PageCount=0x%lx, Type=%ld)\n",
BasePage, PageCount, Type);
/* Make sure we don't map too high */
if (BasePage + PageCount > LoaderPagesSpanned) return;
/* Special handling for page 0 */
if (BasePage == 0)
{
/* If its only one page, ignore it! */
if (PageCount == 1) return;
/* Otherwise, skip first page */
BasePage++;
PageCount--;
}
switch (Type)
{
/* Pages used by the loader */
@ -253,6 +238,21 @@ WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
return FALSE;
}
#endif
/* Before creating the map, we need to map pages to kernel mode */
LastPageIndex = 1;
LastPageType = MemoryMap[1].PageAllocated;
for (i = 2; i < NoEntries; i++)
{
if ((MemoryMap[i].PageAllocated != LastPageType) ||
(i == NoEntries - 1))
{
MempSetupPagingForRegion(LastPageIndex, i - LastPageIndex, LastPageType);
LastPageIndex = i;
LastPageType = MemoryMap[i].PageAllocated;
}
}
// Construct a good memory map from what we've got,
// but mark entries which the memory allocation bitmap takes
// as free entries (this is done in order to have the ability