REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2639
Move Private calculation after TemporaryRamMigration to avoid calculate Private twice. RootCause: 1. ebp is used as Private pointer 2. It is calculated in TemporaryRamMigration again 3. So Private point to the invalid address after second calculation 4. When MigrateMemoryPages consume Private, Segmentation fault happened Detail analysis can refer https://bugzilla.tianocore.org/show_bug.cgi?id=2639#c18 Signed-off-by: Guomin Jiang <guomin.ji...@intel.com> Cc: Jian J Wang <jian.j.w...@intel.com> Cc: Liming Gao <gaolim...@byosoft.com.cn> Cc: Dandan Bi <dandan...@intel.com> Cc: Debkumar De <debkumar...@intel.com> Cc: Harry Han <harry....@intel.com> Cc: Catharine West <catharine.w...@intel.com> --- MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c index 3552feda8f1b..4b6ec00f71bd 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -837,17 +837,6 @@ PeiCheckAndSwitchStack ( DEBUG ((DEBUG_INFO, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (UINT64)Private->HeapOffset, (UINT64)Private->StackOffset)); - // - // Calculate new HandOffTable and PrivateData address in permanent memory's stack - // - if (StackOffsetPositive) { - SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData + StackOffset); - Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private + StackOffset); - } else { - SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData - StackOffset); - Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private - StackOffset); - } - // // Temporary Ram Support PPI is provided by platform, it will copy // temporary memory to permanent memory and do stack switching. @@ -861,6 +850,17 @@ PeiCheckAndSwitchStack ( TemporaryRamSize ); + // + // Calculate new HandOffTable and PrivateData address in permanent memory's stack + // + if (StackOffsetPositive) { + SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData + StackOffset); + Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private + StackOffset); + } else { + SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData - StackOffset); + Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private - StackOffset); + } + // // Migrate memory pages allocated in pre-memory phase. // It could not be called before calling TemporaryRamSupportPpi->TemporaryRamMigration() -- 2.26.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#91757): https://edk2.groups.io/g/devel/message/91757 Mute This Topic: https://groups.io/mt/92564849/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-