Fix a possible overflow of the hal heap in HalpMapPhysicalMemory64 and simplify the code.

svn path=/trunk/; revision=46849
This commit is contained in:
Timo Kreuzer 2010-04-12 19:39:50 +00:00
parent ec9ebec239
commit 8b6a58978f

View file

@ -145,33 +145,31 @@ HalpMapPhysicalMemory64(IN PHYSICAL_ADDRESS PhysicalAddress,
/* Start at the current HAL heap base */ /* Start at the current HAL heap base */
BaseAddress = HalpHeapStart; BaseAddress = HalpHeapStart;
VirtualAddress = BaseAddress;
/* Loop until we have all the pages required */ /* Loop until we have all the pages required */
while (UsedPages < PageCount) while (UsedPages < PageCount)
{ {
/* Begin a new loop cycle */
UsedPages = 0;
VirtualAddress = BaseAddress;
/* If this overflows past the HAL heap, it means there's no space */ /* If this overflows past the HAL heap, it means there's no space */
if (BaseAddress == NULL) return NULL; if (VirtualAddress == NULL) return NULL;
/* Loop until we have all the pages required in a single run */ /* Get the PTE for this address */
while (UsedPages < PageCount) PointerPte = HalAddressToPte(VirtualAddress);
/* Go to the next page */
VirtualAddress = (PVOID)((ULONG_PTR)VirtualAddress + PAGE_SIZE);
/* Check if the page is available */
if (PointerPte->Valid)
{ {
/* Get the PTE for this address and check if it's available */ /* PTE has data, skip it and start with a new base address */
PointerPte = HalAddressToPte(VirtualAddress); BaseAddress = VirtualAddress;
if (*(PULONG)PointerPte) UsedPages = 0;
{ continue;
/* PTE has data, skip it and start with a new base address */
BaseAddress = (PVOID)((ULONG_PTR)VirtualAddress + PAGE_SIZE);
break;
}
/* PTE is available, keep going on this run */
VirtualAddress = (PVOID)((ULONG_PTR)VirtualAddress + PAGE_SIZE);
UsedPages++;
} }
/* PTE is available, keep going on this run */
UsedPages++;
} }
/* Take the base address of the page plus the actual offset in the address */ /* Take the base address of the page plus the actual offset in the address */