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