From a7a26172232fc0eb09d8d45e14f4173489405b8d Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Mon, 26 Sep 2011 15:01:11 +0000 Subject: [PATCH] [HAL] - Fix a typo in HalpAllocPhysicalMemory, that caused the function to remove MADs that still had pages rather than removing those who are empty. Fixes an assertion on VMWare. Kudos go to Kamil for tracking it down. - Fix another bug in HalpAllocPhysicalMemory, where the size of the newly allocated MAD was set to the alignment value instead of the original MAD, this lead to conflicting MADs and possible reuse of hal memory by the kernel. This seems to fix a bugcheck 0x19 with halacpi. svn path=/trunk/; revision=53861 --- reactos/hal/halx86/generic/memory.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/reactos/hal/halx86/generic/memory.c b/reactos/hal/halx86/generic/memory.c index 68e000a6533..de50be48dce 100644 --- a/reactos/hal/halx86/generic/memory.c +++ b/reactos/hal/halx86/generic/memory.c @@ -99,7 +99,7 @@ HalpAllocPhysicalMemory(IN PLOADER_PARAMETER_BLOCK LoaderBlock, if (Alignment) { /* Check if we had leftovers */ - if ((MdBlock->PageCount - Alignment) != PageCount) + if (MdBlock->PageCount > (PageCount + Alignment)) { /* Get the next descriptor */ FreeBlock = &HalpAllocationDescriptorArray[UsedDescriptors]; @@ -113,8 +113,10 @@ HalpAllocPhysicalMemory(IN PLOADER_PARAMETER_BLOCK LoaderBlock, InsertHeadList(&MdBlock->ListEntry, &FreeBlock->ListEntry); } - /* Use this descriptor */ - NewBlock->PageCount = Alignment; + /* Trim the original block to the alignment only */ + MdBlock->PageCount = Alignment; + + /* Insert the descriptor after the original one */ InsertHeadList(&MdBlock->ListEntry, &NewBlock->ListEntry); } else @@ -123,11 +125,11 @@ HalpAllocPhysicalMemory(IN PLOADER_PARAMETER_BLOCK LoaderBlock, MdBlock->BasePage += (ULONG)PageCount; MdBlock->PageCount -= (ULONG)PageCount; - /* Insert the descriptor */ + /* Insert the descriptor before the original one */ InsertTailList(&MdBlock->ListEntry, &NewBlock->ListEntry); /* Remove the entry if the whole block was allocated */ - if (!MdBlock->PageCount == 0) RemoveEntryList(&MdBlock->ListEntry); + if (MdBlock->PageCount == 0) RemoveEntryList(&MdBlock->ListEntry); } /* Return the address */