From 81802056c89c4d01cc38479f2fd8a2f88c1b4ea3 Mon Sep 17 00:00:00 2001 From: Michael D Kinney Date: Wed, 22 Jan 2025 17:32:30 -0800 Subject: [PATCH] EmulatorPkg: Move magic page to first allocation The magic page is allocated from a fixed address specified by PcdPeiServicesTablePage. This allocation has been observed to sometimes fail. Move the allocation of this buffer to the very beginning of main() to minimize the change that another allocation is allocated from the PcdPeiServicesTablePage address. Signed-off-by: Michael D Kinney --- EmulatorPkg/Win/Host/WinHost.c | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/EmulatorPkg/Win/Host/WinHost.c b/EmulatorPkg/Win/Host/WinHost.c index a78ca2acff..9a5201f4d1 100644 --- a/EmulatorPkg/Win/Host/WinHost.c +++ b/EmulatorPkg/Win/Host/WinHost.c @@ -452,6 +452,28 @@ Returns: UINTN ResetJumpCode; EMU_THUNK_PPI *SecEmuThunkPpi; + // + // If enabled use the magic page to communicate between modules + // This replaces the PI PeiServicesTable pointer mechanism that + // deos not work in the emulator. It also allows the removal of + // writable globals from SEC, PEI_CORE (libraries), PEIMs + // + EmuMagicPage = (VOID *)(UINTN)(FixedPcdGet64 (PcdPeiServicesTablePage) & MAX_UINTN); + if (EmuMagicPage != NULL) { + UINT64 Size; + Status = WinNtOpenFile ( + NULL, + SIZE_4KB, + 0, + &EmuMagicPage, + &Size + ); + if (EFI_ERROR (Status)) { + SecPrint ("ERROR : Could not allocate PeiServicesTablePage @ %p\n\r", EmuMagicPage); + return EFI_DEVICE_ERROR; + } + } + // // Enable the privilege so that RTC driver can successfully run SetTime() // @@ -575,28 +597,6 @@ Returns: exit (1); } - // - // If enabled use the magic page to communicate between modules - // This replaces the PI PeiServicesTable pointer mechanism that - // deos not work in the emulator. It also allows the removal of - // writable globals from SEC, PEI_CORE (libraries), PEIMs - // - EmuMagicPage = (VOID *)(UINTN)(FixedPcdGet64 (PcdPeiServicesTablePage) & MAX_UINTN); - if (EmuMagicPage != NULL) { - UINT64 Size; - Status = WinNtOpenFile ( - NULL, - SIZE_4KB, - 0, - &EmuMagicPage, - &Size - ); - if (EFI_ERROR (Status)) { - SecPrint ("ERROR : Could not allocate PeiServicesTablePage @ %p\n\r", EmuMagicPage); - return EFI_DEVICE_ERROR; - } - } - // // Open All the firmware volumes and remember the info in the gFdInfo global // Meanwhile, find the SEC Core.