]> git.proxmox.com Git - mirror_edk2.git/commitdiff
InOsEmuPkg: Make the Guard MemoryAllocationLib handle EFI allocated pages correctly.
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 25 Jun 2011 01:39:09 +0000 (01:39 +0000)
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 25 Jun 2011 01:39:09 +0000 (01:39 +0000)
signed-off-by: andrewfish

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11887 6f19259b-4bc3-4df7-8a09-765794883524

InOsEmuPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c

index 1963c02a07d90618b89301faa609769c49419e8f..c457e7c213134df49e7041877c3569af3521682e 100644 (file)
@@ -150,8 +150,16 @@ FreePages (
   IN UINTN  Pages\r
   )\r
 {\r
+  EFI_STATUS    Status;\r
+\r
   ASSERT (Pages != 0);\r
-  FreePool (Buffer);\r
+  if (!gEmuThunk->Free (Buffer)) {\r
+    // The Free thunk will not free memory allocated in emulated EFI memory.\r
+    // The assmuption is this was allocated directly by EFI. We need this as some \r
+    // times protocols or EFI BootServices can return dynamically allocated buffers.\r
+    Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 }\r
 \r
 /**\r
@@ -178,6 +186,7 @@ InternalAllocateAlignedPages (
   IN UINTN            Alignment\r
   )\r
 {\r
+  EFI_STATUS            Status;\r
   VOID                  *Memory;\r
   UINTN                 AlignedMemory;\r
   UINTN                 AlignmentMask;\r
@@ -213,7 +222,7 @@ InternalAllocateAlignedPages (
       //\r
       // Free first unaligned page(s).\r
       //\r
-      FreePool (Memory);\r
+      FreePages (Memory, UnalignedPages);\r
     }\r
     Memory         = (VOID *) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));\r
     UnalignedPages = RealPages - Pages - UnalignedPages;\r
@@ -221,7 +230,7 @@ InternalAllocateAlignedPages (
       //\r
       // Free last unaligned page(s).\r
       //\r
-      FreePool (Memory);\r
+      FreePages (Memory, UnalignedPages);\r
     }\r
   } else {\r
     //\r
@@ -341,9 +350,7 @@ FreeAlignedPages (
   IN UINTN  Pages\r
   )\r
 {\r
-  ASSERT (Pages != 0);\r
-\r
-  FreePool (Buffer);\r
+  FreePages (Buffer, Pages);\r
 }\r
 \r
 /**\r
@@ -799,13 +806,14 @@ FreePool (
   IN VOID   *Buffer\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  \r
+  EFI_STATUS    Status;\r
+\r
   if (!gEmuThunk->Free (Buffer)) {\r
     // The Free thunk will not free memory allocated in emulated EFI memory.\r
     // The assmuption is this was allocated directly by EFI. We need this as some \r
     // times protocols or EFI BootServices can return dynamically allocated buffers.\r
-    gBS->FreePool (Buffer);\r
+    Status = gBS->FreePool (Buffer);\r
+    ASSERT_EFI_ERROR (Status);\r
   }\r
 }\r
 \r