Make sure the base address of stack base and base address of hob start is in page...
authorklu2 <klu2@de2fecce-e211-0410-80a6-f3fac2684e05>
Thu, 31 Jan 2008 08:41:14 +0000 (08:41 +0000)
committerklu2 <klu2@de2fecce-e211-0410-80a6-f3fac2684e05>
Thu, 31 Jan 2008 08:41:14 +0000 (08:41 +0000)
git-svn-id: https://edk2.tianocore.org/svn/edk2/trunk@4646 de2fecce-e211-0410-80a6-f3fac2684e05

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

index e2b2ccc..3be63fb 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_SIZE - 1)) & EFI_PAGE_SIZE;\r
+  \r
+  PeiStackSize = (RShiftU64 (MemoryLength, 1) + (EFI_PAGE_SIZE - 1)) & EFI_PAGE_SIZE;\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