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