diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c index 5dd8423d2f..658f1087a2 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; @@ -239,5 +240,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..e192641db2 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf @@ -60,3 +60,7 @@ HobLib MemoryAllocationLib SynchronizationLib + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard # CONSUMES +