]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c
Regenerate Fat binaries for the bug fix of LookupUnicodeString2() in UefiLib (r4655).
[mirror_edk2.git] / MdePkg / Library / DxeMemoryAllocationLib / MemoryAllocationLib.c
index ab020ddc95514cbd821f52b709df1757f14b2d98..773797a291151f032cdb49a7e488525d72ad735d 100644 (file)
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
 \r
-  Module Name:  MemoryAllocationLib.c\r
-\r
 **/\r
 \r
 \r
+#include <PiDxe.h>\r
+\r
+\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#include "MemoryAllocationLibInternals.h"\r
+\r
 /**\r
   Allocates one or more 4KB pages of a certain memory type.\r
 \r
@@ -198,7 +206,7 @@ InternalAllocateAlignedPages (
       return NULL;\r
     }\r
     AlignedMemory  = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;\r
-    UnalignedPages = EFI_SIZE_TO_PAGES ((UINTN) Memory - AlignedMemory);\r
+    UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN) Memory);\r
     if (UnalignedPages > 0) {\r
       //\r
       // Free first unaligned page(s).\r
@@ -1069,3 +1077,17 @@ FreeAlignedPool (
   Status = gBS->FreePool (RawAddress);\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
+\r
+\r
+VOID\r
+EFIAPI\r
+SafeFreePool (\r
+  IN VOID   *Buffer\r
+  )\r
+{\r
+  if (Buffer != NULL) {\r
+    FreePool (Buffer);\r
+    Buffer = NULL;\r
+  }\r
+}\r
+\r