607a0df6 |
1 | /** @file\r |
2 | \r |
3 | Copyright (c) 2006 - 2008, Intel Corporation\r |
4 | Portions copyright (c) 2010, Apple, Inc. All rights reserved.\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 | **/\r |
14 | \r |
15 | #ifndef __PE_COFF_LOADER_H__\r |
16 | #define __PE_COFF_LOADER_H__\r |
17 | \r |
ca3ad58b |
18 | // Needed for PE_COFF_LOADER_IMAGE_CONTEXT\r |
19 | #include <Library/PeCoffLib.h>\r |
20 | \r |
607a0df6 |
21 | // B323179B-97FB-477E-B0FE-D88591FA11AB\r |
22 | #define PE_COFF_LOADER_PROTOCOL_GUID \\r |
23 | { 0xB323179B, 0x97FB, 0x477E, { 0xB0, 0xFE, 0xD8, 0x85, 0x91, 0xFA, 0x11, 0xAB } }\r |
24 | \r |
25 | \r |
26 | typedef struct _PE_COFF_LOADER_PROTOCOL PE_COFF_LOADER_PROTOCOL;\r |
27 | \r |
28 | \r |
29 | \r |
30 | /**\r |
31 | Retrieves information about a PE/COFF image.\r |
32 | \r |
33 | Computes the PeCoffHeaderOffset, IsTeImage, ImageType, ImageAddress, ImageSize, \r |
34 | DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, and \r |
35 | DebugDirectoryEntryRva fields of the ImageContext structure. \r |
36 | If ImageContext is NULL, then return RETURN_INVALID_PARAMETER. \r |
37 | If the PE/COFF image accessed through the ImageRead service in the ImageContext \r |
38 | structure is not a supported PE/COFF image type, then return RETURN_UNSUPPORTED. \r |
39 | If any errors occur while computing the fields of ImageContext, \r |
40 | then the error status is returned in the ImageError field of ImageContext. \r |
41 | If the image is a TE image, then SectionAlignment is set to 0.\r |
42 | The ImageRead and Handle fields of ImageContext structure must be valid prior \r |
43 | to invoking this service.\r |
44 | \r |
45 | @param ImageContext Pointer to the image context structure that describes the PE/COFF\r |
46 | image that needs to be examined by this function.\r |
47 | \r |
48 | @retval RETURN_SUCCESS The information on the PE/COFF image was collected.\r |
49 | @retval RETURN_INVALID_PARAMETER ImageContext is NULL.\r |
50 | @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.\r |
51 | \r |
52 | **/\r |
53 | typedef\r |
54 | RETURN_STATUS\r |
55 | (EFIAPI *PE_COFF_LOADER_GET_IMAGE_INFO) (\r |
56 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r |
57 | );\r |
58 | \r |
59 | \r |
60 | /**\r |
61 | Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r |
62 | \r |
63 | If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r |
64 | ImageContext as the relocation base address. Otherwise, use the DestinationAddress field\r |
65 | of ImageContext as the relocation base address. The caller must allocate the relocation\r |
66 | fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.\r |
67 | \r |
68 | The ImageRead, Handle, PeCoffHeaderOffset, IsTeImage, Machine, ImageType, ImageAddress, \r |
69 | ImageSize, DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, \r |
70 | DebugDirectoryEntryRva, EntryPoint, FixupDataSize, CodeView, PdbPointer, and FixupData of \r |
71 | the ImageContext structure must be valid prior to invoking this service.\r |
72 | \r |
73 | If ImageContext is NULL, then ASSERT().\r |
74 | \r |
75 | Note that if the platform does not maintain coherency between the instruction cache(s) and the data\r |
76 | cache(s) in hardware, then the caller is responsible for performing cache maintenance operations\r |
77 | prior to transferring control to a PE/COFF image that is loaded using this library.\r |
78 | \r |
79 | @param ImageContext Pointer to the image context structure that describes the PE/COFF\r |
80 | image that is being relocated.\r |
81 | \r |
82 | @retval RETURN_SUCCESS The PE/COFF image was relocated.\r |
83 | Extended status information is in the ImageError field of ImageContext.\r |
84 | @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.\r |
85 | Extended status information is in the ImageError field of ImageContext.\r |
86 | @retval RETURN_UNSUPPORTED A relocation record type is not supported.\r |
87 | Extended status information is in the ImageError field of ImageContext.\r |
88 | \r |
89 | **/\r |
90 | typedef\r |
91 | RETURN_STATUS\r |
92 | (EFIAPI *PE_COFF_LOADER_RELOCATE_IMAGE) (\r |
93 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r |
94 | );\r |
95 | \r |
96 | \r |
97 | /**\r |
98 | Loads a PE/COFF image into memory.\r |
99 | \r |
100 | Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r |
101 | specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate\r |
102 | the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r |
103 | The EntryPoint, FixupDataSize, CodeView, PdbPointer and HiiResourceData fields of ImageContext are computed.\r |
104 | The ImageRead, Handle, PeCoffHeaderOffset, IsTeImage, Machine, ImageType, ImageAddress, ImageSize, \r |
105 | DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva \r |
106 | fields of the ImageContext structure must be valid prior to invoking this service.\r |
107 | \r |
108 | If ImageContext is NULL, then ASSERT().\r |
109 | \r |
110 | Note that if the platform does not maintain coherency between the instruction cache(s) and the data\r |
111 | cache(s) in hardware, then the caller is responsible for performing cache maintenance operations\r |
112 | prior to transferring control to a PE/COFF image that is loaded using this library.\r |
113 | \r |
114 | @param ImageContext Pointer to the image context structure that describes the PE/COFF\r |
115 | image that is being loaded.\r |
116 | \r |
117 | @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by\r |
118 | the ImageAddress and ImageSize fields of ImageContext.\r |
119 | Extended status information is in the ImageError field of ImageContext.\r |
120 | @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.\r |
121 | Extended status information is in the ImageError field of ImageContext.\r |
122 | @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.\r |
123 | Extended status information is in the ImageError field of ImageContext.\r |
124 | @retval RETURN_INVALID_PARAMETER The image address is invalid.\r |
125 | Extended status information is in the ImageError field of ImageContext.\r |
126 | \r |
127 | **/\r |
128 | typedef\r |
129 | RETURN_STATUS\r |
130 | (EFIAPI *PE_COFF_LOADER_LOAD_IMAGE) (\r |
131 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r |
132 | );\r |
133 | \r |
134 | \r |
135 | \r |
136 | /**\r |
137 | Reads contents of a PE/COFF image from a buffer in system memory.\r |
138 | \r |
139 | This is the default implementation of a PE_COFF_LOADER_READ_FILE function \r |
140 | that assumes FileHandle pointer to the beginning of a PE/COFF image. \r |
141 | This function reads contents of the PE/COFF image that starts at the system memory \r |
142 | address specified by FileHandle. The read operation copies ReadSize bytes from the \r |
143 | PE/COFF image starting at byte offset FileOffset into the buffer specified by Buffer. \r |
144 | The size of the buffer actually read is returned in ReadSize.\r |
145 | \r |
146 | If FileHandle is NULL, then ASSERT().\r |
147 | If ReadSize is NULL, then ASSERT().\r |
148 | If Buffer is NULL, then ASSERT().\r |
149 | \r |
150 | @param FileHandle Pointer to base of the input stream\r |
151 | @param FileOffset Offset into the PE/COFF image to begin the read operation.\r |
152 | @param ReadSize On input, the size in bytes of the requested read operation. \r |
153 | On output, the number of bytes actually read.\r |
154 | @param Buffer Output buffer that contains the data read from the PE/COFF image.\r |
155 | \r |
156 | @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into \r |
157 | the buffer.\r |
158 | **/\r |
159 | typedef\r |
160 | RETURN_STATUS\r |
161 | (EFIAPI *PE_COFF_LOADER_READ_FROM_MEMORY) (\r |
162 | IN VOID *FileHandle,\r |
163 | IN UINTN FileOffset,\r |
164 | IN OUT UINTN *ReadSize,\r |
165 | OUT VOID *Buffer\r |
166 | );\r |
167 | \r |
168 | \r |
169 | \r |
170 | /**\r |
171 | Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r |
172 | runtime. \r |
173 | \r |
174 | This function reapplies relocation fixups to the PE/COFF image specified by ImageBase \r |
175 | and ImageSize so the image will execute correctly when the PE/COFF image is mapped \r |
176 | to the address specified by VirtualImageBase. RelocationData must be identical \r |
177 | to the FiuxupData buffer from the PE_COFF_LOADER_IMAGE_CONTEXT structure \r |
178 | after this PE/COFF image was relocated with PeCoffLoaderRelocateImage().\r |
179 | \r |
180 | Note that if the platform does not maintain coherency between the instruction cache(s) and the data\r |
181 | cache(s) in hardware, then the caller is responsible for performing cache maintenance operations\r |
182 | prior to transferring control to a PE/COFF image that is loaded using this library.\r |
183 | \r |
184 | @param ImageBase Base address of a PE/COFF image that has been loaded \r |
185 | and relocated into system memory.\r |
186 | @param VirtImageBase The request virtual address that the PE/COFF image is to\r |
187 | be fixed up for.\r |
188 | @param ImageSize The size, in bytes, of the PE/COFF image.\r |
189 | @param RelocationData A pointer to the relocation data that was collected when the PE/COFF \r |
190 | image was relocated using PeCoffLoaderRelocateImage().\r |
191 | \r |
192 | **/\r |
193 | typedef\r |
194 | VOID\r |
195 | (EFIAPI *PE_COFF_LOADER_RELOCATE_IMAGE_FOR_RUNTIME) (\r |
196 | IN PHYSICAL_ADDRESS ImageBase,\r |
197 | IN PHYSICAL_ADDRESS VirtImageBase,\r |
198 | IN UINTN ImageSize,\r |
199 | IN VOID *RelocationData\r |
200 | );\r |
201 | \r |
202 | \r |
203 | \r |
204 | /**\r |
205 | Unloads a loaded PE/COFF image from memory and releases its taken resource.\r |
206 | Releases any environment specific resources that were allocated when the image \r |
207 | specified by ImageContext was loaded using PeCoffLoaderLoadImage(). \r |
208 | \r |
209 | For NT32 emulator, the PE/COFF image loaded by system needs to release.\r |
210 | For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r |
211 | this function can simply return RETURN_SUCCESS.\r |
212 | \r |
213 | If ImageContext is NULL, then ASSERT().\r |
214 | \r |
215 | @param ImageContext Pointer to the image context structure that describes the PE/COFF\r |
216 | image to be unloaded.\r |
217 | \r |
218 | @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.\r |
219 | **/\r |
220 | typedef\r |
221 | RETURN_STATUS\r |
222 | (EFIAPI *PE_COFF_LOADER_UNLOAD_IMAGE) (\r |
223 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r |
224 | );\r |
225 | \r |
226 | \r |
227 | struct _PE_COFF_LOADER_PROTOCOL {\r |
228 | PE_COFF_LOADER_GET_IMAGE_INFO GetImageInfo;\r |
229 | PE_COFF_LOADER_LOAD_IMAGE LoadImage;\r |
230 | PE_COFF_LOADER_RELOCATE_IMAGE RelocateImage;\r |
231 | PE_COFF_LOADER_READ_FROM_MEMORY ReadFromMemory;\r |
232 | PE_COFF_LOADER_RELOCATE_IMAGE_FOR_RUNTIME RelocateImageForRuntime;\r |
233 | PE_COFF_LOADER_UNLOAD_IMAGE UnloadImage;\r |
234 | };\r |
235 | \r |
236 | \r |
237 | extern EFI_GUID gPeCoffLoaderProtocolGuid;\r |
238 | \r |
239 | \r |
240 | #endif\r |
241 | \r |