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 <[email protected]> Cc: Leif Lindholm <[email protected]> Cc: Ard Biesheuvel <[email protected]> --- ArmPlatformPkg/PrePeiCore/PrePeiCore.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ArmPlatformPkg/PrePeiCore/PrePeiCore.c b/ArmPlatformPkg/PrePeiCore/PrePeiCore.c index 65b07b6..3a81e2e 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); -- 2.6.2 _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

