]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
UefiCpuPkg/ExceptionLib: Add CET support.
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / CpuExceptionCommon.c
index 3d85b0c415ae984196d9e4e864453fc523a140e1..ca210d1de206cca229d1a4e6e9f0d373c52332e5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU Exception Handler Library common functions.\r
 \r
-  Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2012 - 2019, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -20,7 +20,7 @@
 //\r
 // 1 means an error code will be pushed, otherwise 0\r
 //\r
-CONST UINT32 mErrorCodeFlag = 0x00027d00;\r
+CONST UINT32 mErrorCodeFlag = 0x00227d00;\r
 \r
 //\r
 // Define the maximum message length\r
@@ -49,7 +49,8 @@ CONST CHAR8 *mExceptionNameStr[] = {
   "#AC - Alignment Check",\r
   "#MC - Machine-Check",\r
   "#XM - SIMD floating-point",\r
-  "#VE - Virtualization"\r
+  "#VE - Virtualization",\r
+  "#CP - Control Protection"\r
 };\r
 \r
 #define EXCEPTION_KNOWN_NAME_NUM  (sizeof (mExceptionNameStr) / sizeof (CHAR8 *))\r
@@ -108,80 +109,42 @@ InternalPrintMessage (
   Find and display image base address and return image base and its entry point.\r
 \r
   @param CurrentEip      Current instruction pointer.\r
-  @param EntryPoint      Return module entry point if module header is found.\r
 \r
-  @return !0     Image base address.\r
-  @return 0      Image header cannot be found.\r
 **/\r
-UINTN\r
-FindModuleImageBase (\r
-  IN  UINTN              CurrentEip,\r
-  OUT UINTN              *EntryPoint\r
+VOID\r
+DumpModuleImageInfo (\r
+  IN  UINTN              CurrentEip\r
   )\r
 {\r
+  EFI_STATUS                           Status;\r
   UINTN                                Pe32Data;\r
-  EFI_IMAGE_DOS_HEADER                 *DosHdr;\r
-  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr;\r
   VOID                                 *PdbPointer;\r
+  VOID                                 *EntryPoint;\r
 \r
-  //\r
-  // Find Image Base\r
-  //\r
-  Pe32Data = CurrentEip & ~(mImageAlignSize - 1);\r
-  while (Pe32Data != 0) {\r
-    DosHdr = (EFI_IMAGE_DOS_HEADER *) Pe32Data;\r
-    if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
-      //\r
-      // DOS image header is present, so read the PE header after the DOS image header.\r
-      //\r
-      Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
-      //\r
-      // Make sure PE header address does not overflow and is less than the initial address.\r
-      //\r
-      if (((UINTN)Hdr.Pe32 > Pe32Data) && ((UINTN)Hdr.Pe32 < CurrentEip)) {\r
-        if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
-          //\r
-          // It's PE image.\r
-          //\r
-          InternalPrintMessage ("!!!! Find PE image ");\r
-          *EntryPoint = (UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff);\r
-          break;\r
-        }\r
-      }\r
-    } else {\r
-      //\r
-      // DOS image header is not present, TE header is at the image base.\r
-      //\r
-      Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
-      if ((Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) &&\r
-          ((Hdr.Te->Machine == IMAGE_FILE_MACHINE_I386) || Hdr.Te->Machine == IMAGE_FILE_MACHINE_X64)) {\r
-        //\r
-        // It's TE image, it TE header and Machine type match\r
-        //\r
-        InternalPrintMessage ("!!!! Find TE image ");\r
-        *EntryPoint = (UINTN)Pe32Data + (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) + sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;\r
-        break;\r
-      }\r
-    }\r
-\r
+  Pe32Data = PeCoffSearchImageBase (CurrentEip);\r
+  if (Pe32Data == 0) {\r
+    InternalPrintMessage ("!!!! Can't find image information. !!!!\n");\r
+  } else {\r
     //\r
-    // Not found the image base, check the previous aligned address\r
+    // Find Image Base entry point\r
     //\r
-    Pe32Data -= mImageAlignSize;\r
-  }\r
-\r
-  if (Pe32Data != 0) {\r
+    Status = PeCoffLoaderGetEntryPoint ((VOID *) Pe32Data, &EntryPoint);\r
+    if (EFI_ERROR (Status)) {\r
+      EntryPoint = NULL;\r
+    }\r
+    InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip);\r
     PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *) Pe32Data);\r
     if (PdbPointer != NULL) {\r
       InternalPrintMessage ("%a", PdbPointer);\r
     } else {\r
       InternalPrintMessage ("(No PDB) " );\r
     }\r
-  } else {\r
-    InternalPrintMessage ("!!!! Can't find image information. !!!!\n");\r
+    InternalPrintMessage (\r
+      " (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",\r
+      (VOID *) Pe32Data,\r
+      EntryPoint\r
+      );\r
   }\r
-\r
-  return Pe32Data;\r
 }\r
 \r
 /**\r
@@ -215,4 +178,4 @@ ReadAndVerifyVectorInfo (
     VectorInfo ++;\r
   }\r
   return EFI_SUCCESS;\r
-}
\ No newline at end of file
+}\r