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