mirror of
https://github.com/reactos/reactos.git
synced 2025-04-25 08:00:24 +00:00
- 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. svn path=/trunk/; revision=38487
This commit is contained in:
parent
85e610895c
commit
8172ef5174
4 changed files with 24 additions and 5 deletions
|
@ -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 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
|
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
|
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
|
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
|
PPAGE_LOOKUP_TABLE_ITEM MmGetMemoryMap(ULONG *NoEntries); // Returns a pointer to the memory mapping table and a number of entries in it
|
||||||
|
|
|
@ -182,6 +182,22 @@ PVOID MmAllocateMemoryAtAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_
|
||||||
return MemPointer;
|
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)
|
PVOID MmAllocateHighestMemoryBelowAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType)
|
||||||
{
|
{
|
||||||
ULONG PagesNeeded;
|
ULONG PagesNeeded;
|
||||||
|
|
|
@ -405,7 +405,7 @@ WinLdrLoadImage(IN PCHAR FileName,
|
||||||
/* Size of data is less than the virtual size - fill up the remainder with zeroes */
|
/* Size of data is less than the virtual size - fill up the remainder with zeroes */
|
||||||
if (SizeOfRawData < VirtualSize)
|
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);
|
RtlZeroMemory((PVOID)(SectionHeader->VirtualAddress + (ULONG)PhysicalBase + SizeOfRawData), VirtualSize - SizeOfRawData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,13 +133,15 @@ MempAllocatePageTables()
|
||||||
TotalSize = (1+1+NumPageTables*2)*MM_PAGE_SIZE;
|
TotalSize = (1+1+NumPageTables*2)*MM_PAGE_SIZE;
|
||||||
|
|
||||||
// PDE+HAL+KernelPTEs == MemoryData
|
// PDE+HAL+KernelPTEs == MemoryData
|
||||||
Buffer = MmAllocateMemoryWithType(
|
Buffer = MmAllocateMemoryWithType(TotalSize, LoaderMemoryData);
|
||||||
TotalSize - NumPageTables*MM_PAGE_SIZE, LoaderMemoryData);
|
|
||||||
|
|
||||||
// Physical PTEs = FirmwareTemporary
|
// Physical PTEs = FirmwareTemporary
|
||||||
PhysicalPageTablesBuffer = MmAllocateMemoryWithType(
|
PhysicalPageTablesBuffer = (PUCHAR)Buffer + TotalSize - NumPageTables*MM_PAGE_SIZE;
|
||||||
NumPageTables*MM_PAGE_SIZE, LoaderFirmwareTemporary);
|
MmSetMemoryType(PhysicalPageTablesBuffer,
|
||||||
|
NumPageTables*MM_PAGE_SIZE,
|
||||||
|
LoaderFirmwareTemporary);
|
||||||
|
|
||||||
|
// This check is now redundant
|
||||||
if (Buffer + (TotalSize - NumPageTables*MM_PAGE_SIZE) !=
|
if (Buffer + (TotalSize - NumPageTables*MM_PAGE_SIZE) !=
|
||||||
PhysicalPageTablesBuffer)
|
PhysicalPageTablesBuffer)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue