]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuExceptionHandlerLib: alloc code memory for exception handlers
authorJian J Wang <jian.j.wang@intel.com>
Mon, 15 Jan 2018 01:45:59 +0000 (09:45 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Thu, 18 Jan 2018 09:03:23 +0000 (17:03 +0800)
If PcdDxeNxMemoryProtectionPolicy is set to enable protection for memory
of EfiBootServicesData, EfiConventionalMemory, the BIOS will reset after
timer initialized and started.

The root cause is that the memory used to hold the exception and interrupt
handler is allocated with type of EfiBootServicesData and marked as
non-executable due to NX feature enabled. This patch fixes it by allocating
EfiBootServicesCode type of memory for those handlers instead.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c

index 9a72b37e77d57dd1befef7b3d6b18e17c5101ae5..6d1b54d31d3dc5b38dbc38a4570f364c12f0f115 100644 (file)
@@ -16,6 +16,7 @@
 #include "CpuExceptionCommon.h"\r
 #include <Library/DebugLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
 \r
 CONST UINTN    mDoFarReturnFlag  = 0;\r
 \r
@@ -106,8 +107,12 @@ InitializeCpuInterruptHandlers (
   RESERVED_VECTORS_DATA              *ReservedVectors;\r
   EFI_CPU_INTERRUPT_HANDLER          *ExternalInterruptHandler;\r
 \r
-  ReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM);\r
-  ASSERT (ReservedVectors != NULL);\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesCode,\r
+                  sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM,\r
+                  (VOID **)&ReservedVectors\r
+                  );\r
+  ASSERT (!EFI_ERROR (Status) && ReservedVectors != NULL);\r
   SetMem ((VOID *) ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM, 0xff);\r
   if (VectorInfo != NULL) {\r
     Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors, CPU_INTERRUPT_NUM);\r
@@ -137,8 +142,13 @@ InitializeCpuInterruptHandlers (
 \r
   AsmGetTemplateAddressMap (&TemplateMap);\r
   ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);\r
-  InterruptEntryCode = AllocatePool (TemplateMap.ExceptionStubHeaderSize * CPU_INTERRUPT_NUM);\r
-  ASSERT (InterruptEntryCode != NULL);\r
+\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesCode,\r
+                  TemplateMap.ExceptionStubHeaderSize * CPU_INTERRUPT_NUM,\r
+                  (VOID **)&InterruptEntryCode\r
+                  );\r
+  ASSERT (!EFI_ERROR (Status) && InterruptEntryCode != NULL);\r
 \r
   InterruptEntry = (UINTN) InterruptEntryCode;\r
   for (Index = 0; Index < CPU_INTERRUPT_NUM; Index ++) {\r