summaryrefslogtreecommitdiffstats
path: root/ArmPlatformPkg
diff options
context:
space:
mode:
authorHeyi Guo <heyi.guo@linaro.org>2015-12-10 16:07:03 +0000
committerleiflindholm <leiflindholm@Edk2>2015-12-10 16:07:03 +0000
commit4960d8e00427d52c8db5da492ac7aff38cbc9d30 (patch)
tree12eda1d42249240de411435437cff913280b1808 /ArmPlatformPkg
parentd1baf355b1e5d3363ef7b8abcabffe08af43b8e5 (diff)
downloadedk2-4960d8e00427d52c8db5da492ac7aff38cbc9d30.tar.gz
edk2-4960d8e00427d52c8db5da492ac7aff38cbc9d30.tar.bz2
edk2-4960d8e00427d52c8db5da492ac7aff38cbc9d30.zip
ArmPlatformPkg: Fix stack switch bug after commit 7945b29
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
Diffstat (limited to 'ArmPlatformPkg')
-rw-r--r--ArmPlatformPkg/PrePeiCore/PrePeiCore.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/ArmPlatformPkg/PrePeiCore/PrePeiCore.c b/ArmPlatformPkg/PrePeiCore/PrePeiCore.c
index 65b07b6d89..3a81e2e23f 100644
--- a/ArmPlatformPkg/PrePeiCore/PrePeiCore.c
+++ b/ArmPlatformPkg/PrePeiCore/PrePeiCore.c
@@ -117,22 +117,25 @@ PrePeiCoreTemporaryRamSupport (
VOID *NewHeap;
VOID *OldStack;
VOID *NewStack;
+ UINTN HeapSize;
+
+ HeapSize = ALIGN_VALUE (CopySize / 2, CPU_STACK_ALIGNMENT);
OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;
- NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize >> 1));
+ NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize - HeapSize));
- OldStack = (VOID*)((UINTN)TemporaryMemoryBase + (CopySize >> 1));
+ OldStack = (VOID*)((UINTN)TemporaryMemoryBase + HeapSize);
NewStack = (VOID*)(UINTN)PermanentMemoryBase;
//
// Migrate the temporary memory stack to permanent memory stack.
//
- CopyMem (NewStack, OldStack, CopySize >> 1);
+ CopyMem (NewStack, OldStack, CopySize - HeapSize);
//
// Migrate the temporary memory heap to permanent memory heap.
//
- CopyMem (NewHeap, OldHeap, CopySize >> 1);
+ CopyMem (NewHeap, OldHeap, HeapSize);
SecSwitchStack ((UINTN)NewStack - (UINTN)OldStack);