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