Fix bug in latest check-in of "Make sure the base address of stack base and base...
authorklu2 <klu2@de2fecce-e211-0410-80a6-f3fac2684e05>
Sun, 3 Feb 2008 07:41:10 +0000 (07:41 +0000)
committerklu2 <klu2@de2fecce-e211-0410-80a6-f3fac2684e05>
Sun, 3 Feb 2008 07:41:10 +0000 (07:41 +0000)
git-svn-id: https://edk2.tianocore.org/svn/edk2/trunk@4666 de2fecce-e211-0410-80a6-f3fac2684e05

edk2/MdeModulePkg/Core/Pei/Memory/MemoryServices.c

index e2b2ccc..05e65ce 100644 (file)
@@ -115,16 +115,23 @@ Returns:
   UINT64                                EfiFreeMemorySize;\r
   EFI_PHYSICAL_ADDRESS                  PhysicalAddressOfOldHob;\r
 \r
+  if (MemoryLength > (MAX_ADDRESS - MemoryBegin + 1))\r
+    return EFI_INVALID_PARAMETER;\r
+    \r
+   \r
   DEBUG ((EFI_D_INFO, "PeiInstallPeiMemory MemoryBegin 0x%LX, MemoryLength 0x%LX\n", MemoryBegin, MemoryLength));\r
   \r
   PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
 \r
   PrivateData->SwitchStackSignal = TRUE;\r
   PrivateData->PeiMemoryInstalled = TRUE;\r
-\r
-  PrivateData->StackBase = MemoryBegin;\r
   \r
-  PeiStackSize = RShiftU64 (MemoryLength, 1);\r
+  //\r
+  // Ensure the stack base is in page alignment \r
+  //\r
+  PrivateData->StackBase = ((UINTN)MemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;\r
+  PeiStackSize = (RShiftU64 (MemoryLength, 1) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;\r
+  \r
   if (PEI_STACK_SIZE > PeiStackSize) {\r
     PrivateData->StackSize = PeiStackSize;\r
   } else {\r
@@ -133,7 +140,7 @@ Returns:
 \r
   OldHandOffHob = PrivateData->HobList.HandoffInformationTable;\r
 \r
-  PrivateData->HobList.Raw = (VOID *)((UINTN)(MemoryBegin + PrivateData->StackSize));\r
+  PrivateData->HobList.Raw = (VOID *)((UINTN)(PrivateData->StackBase + PrivateData->StackSize));\r
   NewHandOffHob = PrivateData->HobList.HandoffInformationTable;\r
   PhysicalAddressOfOldHob = (EFI_PHYSICAL_ADDRESS) (UINTN) OldHandOffHob;\r
 \r