]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuExceptionHandlerLib: support stack switch for PEI exceptions
authorJian J Wang <jian.j.wang@intel.com>
Mon, 3 Sep 2018 02:36:21 +0000 (10:36 +0800)
committerJian J Wang <jian.j.wang@intel.com>
Mon, 10 Sep 2018 01:28:26 +0000 (09:28 +0800)
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 <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: "Ware, Ryan R" <ryan.r.ware@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf

index 5dd8423d2f5e8c5b0cd6c2fa986f60c676fd67d5..658f1087a258771018d4c6f0d5b21b3dd47be321 100644 (file)
@@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/DebugLib.h>\r
 #include <Library/HobLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
 \r
 CONST UINTN    mDoFarReturnFlag  = 0;\r
 \r
@@ -239,5 +240,29 @@ InitializeCpuExceptionHandlersEx (
   IN CPU_EXCEPTION_INIT_DATA            *InitData OPTIONAL\r
   )\r
 {\r
-  return InitializeCpuExceptionHandlers (VectorInfo);\r
+  EFI_STATUS                        Status;\r
+\r
+  //\r
+  // To avoid repeat initialization of default handlers, the caller should pass\r
+  // an extended init data with InitDefaultHandlers set to FALSE. There's no\r
+  // need to call this method to just initialize default handlers. Call non-ex\r
+  // version instead; or this method must be implemented as a simple wrapper of\r
+  // non-ex version of it, if this version has to be called.\r
+  //\r
+  if (InitData == NULL || InitData->Ia32.InitDefaultHandlers) {\r
+    Status = InitializeCpuExceptionHandlers (VectorInfo);\r
+  } else {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Initializing stack switch is only necessary for Stack Guard functionality.\r
+    //\r
+    if (PcdGetBool (PcdCpuStackGuard) && InitData != NULL) {\r
+      Status = ArchSetupExcpetionStack (InitData);\r
+    }\r
+  }\r
+\r
+  return  Status;\r
 }\r
index 783260e39a857dbab62ee97ade22c9ee5eebbbb4..e192641db293799b7c02a4f475374e438af65e30 100644 (file)
@@ -60,3 +60,7 @@
   HobLib\r
   MemoryAllocationLib\r
   SynchronizationLib\r
+\r
+[Pcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard    # CONSUMES\r
+\r