1 /** @file
2   Declaration of internal functions in PE/COFF Lib.
3 
4   Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5   SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #ifndef __BASE_PECOFF_LIB_INTERNALS__
10 #define __BASE_PECOFF_LIB_INTERNALS__
11 
12 #include <Base.h>
13 #include <Library/PeCoffLib.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/DebugLib.h>
16 #include <Library/PeCoffExtraActionLib.h>
17 #include <IndustryStandard/PeImage.h>
18 
19 
20 
21 /**
22   Performs an Itanium-based specific relocation fixup and is a no-op on other
23   instruction sets.
24 
25   @param  Reloc       The pointer to the relocation record.
26   @param  Fixup       The pointer to the address to fix up.
27   @param  FixupData   The pointer to a buffer to log the fixups.
28   @param  Adjust      The offset to adjust the fixup.
29 
30   @return Status code.
31 
32 **/
33 RETURN_STATUS
34 PeCoffLoaderRelocateImageEx (
35   IN UINT16      *Reloc,
36   IN OUT CHAR8   *Fixup,
37   IN OUT CHAR8   **FixupData,
38   IN UINT64      Adjust
39   );
40 
41 
42 /**
43   Performs an Itanium-based specific re-relocation fixup and is a no-op on other
44   instruction sets. This is used to re-relocated the image into the EFI virtual
45   space for runtime calls.
46 
47   @param  Reloc       The pointer to the relocation record.
48   @param  Fixup       The pointer to the address to fix up.
49   @param  FixupData   The pointer to a buffer to log the fixups.
50   @param  Adjust      The offset to adjust the fixup.
51 
52   @return Status code.
53 
54 **/
55 RETURN_STATUS
56 PeHotRelocateImageEx (
57   IN UINT16      *Reloc,
58   IN OUT CHAR8   *Fixup,
59   IN OUT CHAR8   **FixupData,
60   IN UINT64      Adjust
61   );
62 
63 
64 /**
65   Returns TRUE if the machine type of PE/COFF image is supported. Supported
66   does not mean the image can be executed it means the PE/COFF loader supports
67   loading and relocating of the image type. It's up to the caller to support
68   the entry point.
69 
70   @param  Machine   Machine type from the PE Header.
71 
72   @return TRUE if this PE/COFF loader can load the image
73 
74 **/
75 BOOLEAN
76 PeCoffLoaderImageFormatSupported (
77   IN  UINT16  Machine
78   );
79 
80 /**
81   Retrieves the magic value from the PE/COFF header.
82 
83   @param  Hdr             The buffer in which to return the PE32, PE32+, or TE header.
84 
85   @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32
86   @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+
87 
88 **/
89 UINT16
90 PeCoffLoaderGetPeHeaderMagicValue (
91   IN  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr
92   );
93 
94 /**
95   Retrieves the PE or TE Header from a PE/COFF or TE image.
96 
97   @param  ImageContext    The context of the image being loaded.
98   @param  Hdr             The buffer in which to return the PE32, PE32+, or TE header.
99 
100   @retval RETURN_SUCCESS  The PE or TE Header is read.
101   @retval Other           The error status from reading the PE/COFF or TE image using the ImageRead function.
102 
103 **/
104 RETURN_STATUS
105 PeCoffLoaderGetPeHeader (
106   IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext,
107   OUT    EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr
108   );
109 
110 /**
111   Converts an image address to the loaded address.
112 
113   @param  ImageContext      The context of the image being loaded.
114   @param  Address           The address to be converted to the loaded address.
115   @param  TeStrippedOffset  Stripped offset for TE image.
116 
117   @return The converted address or NULL if the address can not be converted.
118 
119 **/
120 VOID *
121 PeCoffLoaderImageAddress (
122   IN OUT PE_COFF_LOADER_IMAGE_CONTEXT          *ImageContext,
123   IN     UINTN                                 Address,
124   IN     UINTN                                 TeStrippedOffset
125   );
126 
127 #endif
128