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