]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Include/Library/EdkIIGluePeCoffLib.h
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Include / Library / EdkIIGluePeCoffLib.h
CommitLineData
3eb9473e 1/*++\r
2\r
2c7e5c2f
HT
3Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials \r
3eb9473e 5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12\r
13Module Name:\r
14\r
15 EdkIIGluePeCoffLib.h\r
16\r
17Abstract: \r
18\r
19 Public header file for PeCoff Lib\r
20\r
21--*/\r
22\r
23#ifndef __EDKII_GLUE_BASE_PE_COFF_LIB_H__\r
24#define __EDKII_GLUE_BASE_PE_COFF_LIB_H__\r
25\r
26\r
27#define PeCoffLoaderGetImageInfo(_IMAGECONTEXT) GluePeCoffLoaderGetImageInfo(_IMAGECONTEXT)\r
28#define PeCoffLoaderRelocateImage(_IMAGECONTEXT) GluePeCoffLoaderRelocateImage(_IMAGECONTEXT)\r
29#define PeCoffLoaderLoadImage(_IMAGECONTEXT) GluePeCoffLoaderLoadImage(_IMAGECONTEXT)\r
30#define PeCoffLoaderGetPeHeader(_IMAGECONTEXT, _HDR) GluePeCoffLoaderGetPeHeader(_IMAGECONTEXT, _HDR)\r
31#define PeCoffLoaderImageAddress(_IMAGECONTEXT, _ADR) GluePeCoffLoaderImageAddress(_IMAGECONTEXT, _ADR)\r
32#define PeCoffLoaderRelocateImage(_IMAGECONTEXT) GluePeCoffLoaderRelocateImage(_IMAGECONTEXT)\r
33#define PeCoffLoaderRelocateImageEx(_RELOC, _FIXUP, _FIXUPDATA, _ADJUST) \\r
34 GluePeCoffLoaderRelocateImageEx(_RELOC, _FIXUP, _FIXUPDATA, _ADJUST)\r
35#define PeHotRelocateImageEx(_RELOC, _FIXUP, _FIXUPDATA, _ADJUST) \\r
36 GluePeHotRelocateImageEx(_RELOC, _FIXUP, _FIXUPDATA, _ADJUST)\r
37\r
38\r
39//\r
40// Return status codes from the PE/COFF Loader services\r
41// BUGBUG: Find where used and see if can be replaced by RETURN_STATUS codes\r
42//\r
43#define IMAGE_ERROR_SUCCESS 0\r
44#define IMAGE_ERROR_IMAGE_READ 1 \r
45#define IMAGE_ERROR_INVALID_PE_HEADER_SIGNATURE 2\r
46#define IMAGE_ERROR_INVALID_MACHINE_TYPE 3\r
47#define IMAGE_ERROR_INVALID_SUBSYSTEM 4\r
48#define IMAGE_ERROR_INVALID_IMAGE_ADDRESS 5\r
49#define IMAGE_ERROR_INVALID_IMAGE_SIZE 6\r
50#define IMAGE_ERROR_INVALID_SECTION_ALIGNMENT 7\r
51#define IMAGE_ERROR_SECTION_NOT_LOADED 8\r
52#define IMAGE_ERROR_FAILED_RELOCATION 9\r
53#define IMAGE_ERROR_FAILED_ICACHE_FLUSH 10\r
54\r
55//\r
56// PE/COFF Loader Read Function passed in by caller\r
57//\r
58typedef\r
59RETURN_STATUS\r
60(EFIAPI *PE_COFF_LOADER_READ_FILE) (\r
61 IN VOID *FileHandle,\r
62 IN UINTN FileOffset,\r
63 IN OUT UINTN *ReadSize,\r
64 OUT VOID *Buffer\r
65 );\r
66\r
67//\r
68// Context structure used while PE/COFF image is being loaded and relocated\r
69//\r
70typedef struct {\r
71 PHYSICAL_ADDRESS ImageAddress;\r
72 UINT64 ImageSize;\r
73 PHYSICAL_ADDRESS DestinationAddress;\r
74 PHYSICAL_ADDRESS EntryPoint;\r
75 PE_COFF_LOADER_READ_FILE ImageRead;\r
76 VOID *Handle;\r
77 VOID *FixupData;\r
78 UINT32 SectionAlignment;\r
79 UINT32 PeCoffHeaderOffset;\r
80 UINT32 DebugDirectoryEntryRva;\r
81 VOID *CodeView;\r
82 CHAR8 *PdbPointer;\r
83 UINTN SizeOfHeaders;\r
84 UINT32 ImageCodeMemoryType;\r
85 UINT32 ImageDataMemoryType;\r
86 UINT32 ImageError;\r
87 UINTN FixupDataSize;\r
88 UINT16 Machine;\r
89 UINT16 ImageType;\r
90 BOOLEAN RelocationsStripped;\r
91 BOOLEAN IsTeImage;\r
92} PE_COFF_LOADER_IMAGE_CONTEXT;\r
93\r
94/**\r
95 Retrieves information about a PE/COFF image.\r
96\r
97 Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
98 PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
99 fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
100 If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
101 a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while\r
102 computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
103 ImageContext. \r
104\r
105 @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
106 image that needs to be examined by this function.\r
107\r
108 @retval RETURN_SUCCESS The information on the PE/COFF image was collected.\r
109 @retval RETURN_INVALID_PARAMETER ImageContext is NULL.\r
110 @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.\r
111\r
112**/\r
113RETURN_STATUS\r
114EFIAPI\r
115GluePeCoffLoaderGetImageInfo (\r
116 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
e00e1d46 117 );\r
3eb9473e 118\r
119/**\r
120 Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
121\r
122 If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
123 ImageContext as the relocation base address. Otherwise, use the DestinationAddress field\r
124 of ImageContext as the relocation base address. The caller must allocate the relocation\r
125 fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function. \r
126 If ImageContext is NULL, then ASSERT().\r
127\r
128 @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
129 image that is being relocated.\r
130\r
131 @retval RETURN_SUCCESS The PE/COFF image was relocated.\r
132 Extended status information is in the ImageError field of ImageContext.\r
133 @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.\r
134 Extended status information is in the ImageError field of ImageContext.\r
135 @retval RETURN_UNSUPPORTED A relocation record type is not supported.\r
136 Extended status information is in the ImageError field of ImageContext.\r
137\r
138**/\r
139RETURN_STATUS\r
140EFIAPI\r
141GluePeCoffLoaderRelocateImage (\r
142 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
e00e1d46 143 );\r
3eb9473e 144\r
145/**\r
146 Loads a PE/COFF image into memory.\r
147\r
148 Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
149 specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate\r
150 the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
151 The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
152 If ImageContext is NULL, then ASSERT().\r
153\r
154 @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
155 image that is being loaded.\r
156\r
157 @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by\r
158 the ImageAddress and ImageSize fields of ImageContext.\r
159 Extended status information is in the ImageError field of ImageContext.\r
160 @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.\r
161 Extended status information is in the ImageError field of ImageContext.\r
162 @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.\r
163 Extended status information is in the ImageError field of ImageContext.\r
164 @retval RETURN_INVALID_PARAMETER The image address is invalid.\r
165 Extended status information is in the ImageError field of ImageContext.\r
166\r
167**/\r
168RETURN_STATUS\r
169EFIAPI\r
170GluePeCoffLoaderLoadImage (\r
171 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
e00e1d46 172 );\r
3eb9473e 173\r
174\r
175/**\r
176 ImageRead function that operates on a memory buffer whos base is passed into\r
177 FileHandle. \r
178\r
179 @param FileHandle Ponter to baes of the input stream\r
180 @param FileOffset Offset to the start of the buffer\r
181 @param ReadSize Number of bytes to copy into the buffer\r
182 @param Buffer Location to place results of read\r
183\r
184 @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into \r
185 the buffer.\r
186**/\r
187RETURN_STATUS\r
188EFIAPI\r
189PeCoffLoaderImageReadFromMemory (\r
190 IN VOID *FileHandle,\r
191 IN UINTN FileOffset,\r
192 IN OUT UINTN *ReadSize,\r
193 OUT VOID *Buffer\r
e00e1d46 194 );\r
3eb9473e 195\r
196\r
197/**\r
198 Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
199 runtime. \r
200 \r
201 PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
202 the fixups with a virtual mapping.\r
203\r
204\r
205 @param ImageBase Base address of relocated image\r
206 @param VirtImageBase Virtual mapping for ImageBase\r
207 @param ImageSize Size of the image to relocate\r
208 @param RelocationData Location to place results of read\r
209 \r
210**/\r
211VOID\r
212EFIAPI\r
213PeCoffLoaderRelocateImageForRuntime (\r
214 IN PHYSICAL_ADDRESS ImageBase,\r
215 IN PHYSICAL_ADDRESS VirtImageBase,\r
216 IN UINTN ImageSize,\r
217 IN VOID *RelocationData\r
e00e1d46 218 );\r
3eb9473e 219\r
220\r
221#endif\r