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