]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg: Fix stack switch bug after commit 7945b29
authorHeyi Guo <heyi.guo@linaro.org>
Thu, 10 Dec 2015 16:07:03 +0000 (16:07 +0000)
committerleiflindholm <leiflindholm@Edk2>
Thu, 10 Dec 2015 16:07:03 +0000 (16:07 +0000)
This is the complementary patch for the commit 7945b29, which strictly
aligns temporary heap size and temporary stack size, but does not do
the same thing when switching stack and heap to permanent memory, and
then it may cause fatal data corruption like PHIT HOB lost and stack
pointer unaligned.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19213 6f19259b-4bc3-4df7-8a09-765794883524

ArmPlatformPkg/PrePeiCore/PrePeiCore.c

index 65b07b6d894112d7380b25a758335179a751d55d..3a81e2e23f2c77b3c20e5244bd8d6d4557b0ec7b 100644 (file)
@@ -117,22 +117,25 @@ PrePeiCoreTemporaryRamSupport (
   VOID                             *NewHeap;\r
   VOID                             *OldStack;\r
   VOID                             *NewStack;\r
+  UINTN                            HeapSize;\r
+\r
+  HeapSize = ALIGN_VALUE (CopySize / 2, CPU_STACK_ALIGNMENT);\r
 \r
   OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;\r
-  NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize >> 1));\r
+  NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize - HeapSize));\r
 \r
-  OldStack = (VOID*)((UINTN)TemporaryMemoryBase + (CopySize >> 1));\r
+  OldStack = (VOID*)((UINTN)TemporaryMemoryBase + HeapSize);\r
   NewStack = (VOID*)(UINTN)PermanentMemoryBase;\r
 \r
   //\r
   // Migrate the temporary memory stack to permanent memory stack.\r
   //\r
-  CopyMem (NewStack, OldStack, CopySize >> 1);\r
+  CopyMem (NewStack, OldStack, CopySize - HeapSize);\r
 \r
   //\r
   // Migrate the temporary memory heap to permanent memory heap.\r
   //\r
-  CopyMem (NewHeap, OldHeap, CopySize >> 1);\r
+  CopyMem (NewHeap, OldHeap, HeapSize);\r
 \r
   SecSwitchStack ((UINTN)NewStack - (UINTN)OldStack);\r
 \r