]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Memory/MemoryServices.c
Correct the RemainingPages calculation in PEI AllocatePages service.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Memory / MemoryServices.c
index f848fbeccfb982c52dd2df5323253bc39e4c888a..10f21d5628b2d833d8fb585e2706eb99af12cbbf 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI PEI Core memory services\r
   \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -182,7 +182,7 @@ PeiAllocatePages (
   //\r
   // Verify that there is sufficient memory to satisfy the allocation\r
   //\r
-  RemainingPages = EFI_SIZE_TO_PAGES ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom));\r
+  RemainingPages = (UINTN)(*FreeMemoryTop - *FreeMemoryBottom) >> EFI_PAGE_SHIFT;\r
   //\r
   // For page allocation, the overhead sizeof (EFI_HOB_MEMORY_ALLOCATION) needs one extra page.\r
   // So the number of remaining pages needs to be greater than that of the request pages.\r
@@ -249,9 +249,9 @@ PeiAllocatePool (
   \r
   //\r
   // Generally, the size of heap in temporary memory does not exceed to 64K,\r
-  // so the maxmium size of pool is 0x10000 - sizeof (EFI_HOB_MEMORY_POOL)\r
+  // HobLength is multiples of 8 bytes, so the maxmium size of pool is 0xFFF8 - sizeof (EFI_HOB_MEMORY_POOL)\r
   //\r
-  if (Size >= (0x10000 - sizeof (EFI_HOB_MEMORY_POOL))) {\r
+  if (Size > (0xFFF8 - sizeof (EFI_HOB_MEMORY_POOL))) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   \r
@@ -260,6 +260,7 @@ PeiAllocatePool (
              (UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + Size),\r
              (VOID **)&Hob\r
              );\r
+  ASSERT_EFI_ERROR (Status);\r
   *Buffer = Hob+1;  \r
 \r
   return Status;\r