From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: michael.d.kinney@intel.com) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by groups.io with SMTP; Fri, 16 Aug 2019 17:57:21 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Aug 2019 17:57:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,395,1559545200"; d="scan'208";a="171574114" Received: from mdkinney-mobl2.amr.corp.intel.com ([10.251.3.193]) by orsmga008.jf.intel.com with ESMTP; 16 Aug 2019 17:57:20 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Andrew Fish , Jordan Justen , Ray Ni Subject: [Patch V5 10/11] EmulatorPkg/Sec: Change scope of PpiArray[10] Date: Fri, 16 Aug 2019 17:57:14 -0700 Message-Id: <20190817005715.9856-11-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190817005715.9856-1-michael.d.kinney@intel.com> References: <20190817005715.9856-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrew Fish The local variable PpiArray[10] is declared in the middle of the SEC module _ModuleEntryPoint() with its own scope. However, PpiArray has a dangling reference to its location on the stack after the scope is closed. This causes issues with some compilers (e.g. XCODE5). The fix is to move the declaration of PpiArray[10] to the beginning of the function, so it is scoped correctly for all references to this local variable and references to its location. Cc: Jordan Justen Cc: Ray Ni Cc: Michael D Kinney Signed-off-by: Andrew Fish Reviewed-by: Michael D Kinney Tested-by: Andrew Fish --- EmulatorPkg/Sec/Sec.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/EmulatorPkg/Sec/Sec.c b/EmulatorPkg/Sec/Sec.c index 701032233b..b734d2bb87 100644 --- a/EmulatorPkg/Sec/Sec.c +++ b/EmulatorPkg/Sec/Sec.c @@ -75,6 +75,7 @@ _ModuleEntryPoint ( EFI_PEI_PPI_DESCRIPTOR *SecPpiList; UINTN SecReseveredMemorySize; UINTN Index; + EFI_PEI_PPI_DESCRIPTOR PpiArray[10]; EMU_MAGIC_PAGE()->PpiList = PpiList; ProcessLibraryConstructorList (); @@ -104,16 +105,13 @@ _ModuleEntryPoint ( SecCoreData->PeiTemporaryRamBase = (VOID *)((UINTN)SecCoreData->PeiTemporaryRamBase + SecReseveredMemorySize); SecCoreData->PeiTemporaryRamSize -= SecReseveredMemorySize; #else - { - // - // When I subtrack from SecCoreData->PeiTemporaryRamBase PEI Core crashes? Either there is a bug - // or I don't understand temp RAM correctly? - // - EFI_PEI_PPI_DESCRIPTOR PpiArray[10]; + // + // When I subtrack from SecCoreData->PeiTemporaryRamBase PEI Core crashes? Either there is a bug + // or I don't understand temp RAM correctly? + // - SecPpiList = &PpiArray[0]; - ASSERT (sizeof (PpiArray) >= SecReseveredMemorySize); - } + SecPpiList = &PpiArray[0]; + ASSERT (sizeof (PpiArray) >= SecReseveredMemorySize); #endif // Copy existing list, and append our entries. CopyMem (SecPpiList, PpiList, sizeof (EFI_PEI_PPI_DESCRIPTOR) * Index); -- 2.21.0.windows.1