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