]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerUefi.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmPkg / Library / DefaultExceptionHandlerLib / DefaultExceptionHandlerUefi.c
1 /** @file
2
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Uefi.h>
10 #include <Library/PeCoffGetEntryPointLib.h>
11 #include <Library/UefiLib.h>
12
13 #include <Guid/DebugImageInfoTable.h>
14
15 /**
16 Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
17 it came from. As long as the PE/COFF image contains a debug directory entry a
18 string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
19 image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
20
21 @param FaultAddress Address to find PE/COFF image for.
22 @param ImageBase Return load address of found image
23 @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
24
25 @retval NULL FaultAddress not in a loaded PE/COFF image.
26 @retval Path and file name of PE/COFF image.
27
28 **/
29 CHAR8 *
30 GetImageName (
31 IN UINTN FaultAddress,
32 OUT UINTN *ImageBase,
33 OUT UINTN *PeCoffSizeOfHeaders
34 )
35 {
36 EFI_STATUS Status;
37 EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *DebugTableHeader;
38 EFI_DEBUG_IMAGE_INFO *DebugTable;
39 UINTN Entry;
40 CHAR8 *Address;
41
42 Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&DebugTableHeader);
43 if (EFI_ERROR (Status)) {
44 return NULL;
45 }
46
47 DebugTable = DebugTableHeader->EfiDebugImageInfoTable;
48 if (DebugTable == NULL) {
49 return NULL;
50 }
51
52 Address = (CHAR8 *)(UINTN)FaultAddress;
53 for (Entry = 0; Entry < DebugTableHeader->TableSize; Entry++, DebugTable++) {
54 if (DebugTable->NormalImage != NULL) {
55 if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&
56 (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL))
57 {
58 if ((Address >= (CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase) &&
59 (Address <= ((CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase + DebugTable->NormalImage->LoadedImageProtocolInstance->ImageSize)))
60 {
61 *ImageBase = (UINTN)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase;
62 *PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)*ImageBase);
63 return PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase);
64 }
65 }
66 }
67 }
68
69 return NULL;
70 }