From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Permerror (SPF Permanent Error: Two or more type TXT spf records found.) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8FDA82110E887 for ; Sun, 2 Sep 2018 20:15:55 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Sep 2018 20:15:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,323,1531810800"; d="scan'208";a="259323765" Received: from shwdeopenpsi777.ccr.corp.intel.com ([10.239.158.27]) by fmsmga005.fm.intel.com with ESMTP; 02 Sep 2018 20:15:54 -0700 From: Jian J Wang To: edk2-devel@lists.01.org Cc: Eric Dong , Laszlo Ersek , Ruiyu Ni , Jiewen Yao , Star Zeng , "Ware, Ryan R" Date: Mon, 3 Sep 2018 11:15:48 +0800 Message-Id: <20180903031550.4440-3-jian.j.wang@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20180903031550.4440-1-jian.j.wang@intel.com> References: <20180903031550.4440-1-jian.j.wang@intel.com> Subject: [PATCH 2/4] UefiCpuPkg/CpuExceptionHandlerLib: support stack switch for PEI exceptions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Sep 2018 03:15:55 -0000 Stack Guard needs to setup stack switch capability to allow exception handler to be called with good stack if stack overflow is detected. This patch update InitializeCpuExceptionHandlersEx() to allow pass extra initialization data used to setup exception stack switch for specified exceptions. Cc: Eric Dong Cc: Laszlo Ersek Cc: Ruiyu Ni Cc: Jiewen Yao Cc: Star Zeng Cc: "Ware, Ryan R" Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- .../CpuExceptionHandlerLib/PeiCpuException.c | 27 +++++++++++++++++++++- .../PeiCpuExceptionHandlerLib.inf | 4 ++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c index 6f271983f2..5687c98c0d 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c @@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include CONST UINTN mDoFarReturnFlag = 0; @@ -208,5 +209,29 @@ InitializeCpuExceptionHandlersEx ( IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL ) { - return InitializeCpuExceptionHandlers (VectorInfo); + EFI_STATUS Status; + + // + // To avoid repeat initialization of default handlers, the caller should pass + // an extended init data with InitDefaultHandlers set to FALSE. There's no + // need to call this method to just initialize default handlers. Call non-ex + // version instead; or this method must be implemented as a simple wrapper of + // non-ex version of it, if this version has to be called. + // + if (InitData == NULL || InitData->Ia32.InitDefaultHandlers) { + Status = InitializeCpuExceptionHandlers (VectorInfo); + } else { + Status = EFI_SUCCESS; + } + + if (!EFI_ERROR (Status)) { + // + // Initializing stack switch is only necessary for Stack Guard functionality. + // + if (PcdGetBool (PcdCpuStackGuard) && InitData != NULL) { + Status = ArchSetupExcpetionStack (InitData); + } + } + + return Status; } diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf index 783260e39a..0ea44b3052 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf @@ -60,3 +60,7 @@ HobLib MemoryAllocationLib SynchronizationLib + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard + -- 2.16.2.windows.1