Author: tkreuzer
Date: Mon Sep 26 15:01:11 2011
New Revision: 53861

URL: http://svn.reactos.org/svn/reactos?rev=53861&view=rev
Log:
[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.

Modified:
    trunk/reactos/hal/halx86/generic/memory.c

Modified: trunk/reactos/hal/halx86/generic/memory.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/memory.c?rev=53861&r1=53860&r2=53861&view=diff
==============================================================================
--- trunk/reactos/hal/halx86/generic/memory.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/memory.c [iso-8859-1] Mon Sep 26 15:01:11 
2011
@@ -99,7 +99,7 @@
     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 @@
             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 @@
         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 */


Reply via email to