]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
PeCoffGetEntryPointLib: Fix spelling issue
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / CpuExceptionCommon.c
index 3d85b0c415ae984196d9e4e864453fc523a140e1..dbfaae1d303806984de3d80189f31e38defafc1a 100644 (file)
@@ -108,80 +108,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 ");\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