]>
Commit | Line | Data |
---|---|---|
23c98c94 | 1 | /** @file\r |
504214c4 | 2 | Data structure and functions to load and unload PeImage.\r |
23c98c94 | 3 | \r |
4 | Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r | |
28a00297 | 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 | |
504214c4 | 13 | **/\r |
28a00297 | 14 | \r |
15 | \r | |
16 | #ifndef _IMAGE_H_\r | |
17 | #define _IMAGE_H_\r | |
18 | \r | |
19 | \r | |
20 | \r | |
21 | #define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','d','r','i')\r | |
22 | \r | |
23 | typedef struct {\r | |
24 | UINTN Signature;\r | |
25 | EFI_HANDLE Handle; // Image handle\r | |
26 | UINTN Type; // Image type\r | |
27 | \r | |
28 | BOOLEAN Started; // If entrypoint has been called\r | |
29 | \r | |
30 | EFI_IMAGE_ENTRY_POINT EntryPoint; // The image's entry point\r | |
31 | EFI_LOADED_IMAGE_PROTOCOL Info; // loaded image protocol\r | |
32 | \r | |
33 | EFI_PHYSICAL_ADDRESS ImageBasePage; // Location in memory\r | |
34 | UINTN NumberOfPages; // Number of pages\r | |
35 | \r | |
36 | CHAR8 *FixupData; // Original fixup data\r | |
37 | \r | |
38 | EFI_TPL Tpl; // Tpl of started image\r | |
39 | EFI_STATUS Status; // Status returned by started image\r | |
40 | \r | |
41 | UINTN ExitDataSize; // Size of ExitData from started image\r | |
42 | VOID *ExitData; // Pointer to exit data from started image\r | |
43 | VOID *JumpBuffer; // Pointer to pool allocation for context save/retore\r | |
44 | BASE_LIBRARY_JUMP_BUFFER *JumpContext; // Pointer to buffer for context save/retore\r | |
45 | UINT16 Machine; // Machine type from PE image\r | |
46 | \r | |
47 | EFI_EBC_PROTOCOL *Ebc; // EBC Protocol pointer\r | |
48 | \r | |
49 | EFI_RUNTIME_IMAGE_ENTRY *RuntimeData; // Runtime image list\r | |
50 | \r | |
ba39e316 | 51 | EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath; // Pointer to Loaded Image Device Path Protocl\r |
85658066 | 52 | \r |
28a00297 | 53 | PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; // PeCoffLoader ImageContext\r |
54 | \r | |
55 | } LOADED_IMAGE_PRIVATE_DATA;\r | |
56 | \r | |
57 | #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \\r | |
58 | CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)\r | |
59 | \r | |
60 | \r | |
61 | \r | |
62 | #define LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','p','e','i')\r | |
63 | \r | |
64 | typedef struct {\r | |
65 | UINTN Signature;\r | |
66 | EFI_HANDLE Handle; // Image handle\r | |
67 | EFI_PE32_IMAGE_PROTOCOL Pe32Image;\r | |
68 | } LOAD_PE32_IMAGE_PRIVATE_DATA;\r | |
69 | \r | |
70 | #define LOAD_PE32_IMAGE_PRIVATE_DATA_FROM_THIS(a) \\r | |
71 | CR(a, LOAD_PE32_IMAGE_PRIVATE_DATA, Pe32Image, LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE)\r | |
72 | \r | |
73 | \r | |
74 | \r | |
75 | //\r | |
76 | // Private Data Types\r | |
77 | //\r | |
78 | #define IMAGE_FILE_HANDLE_SIGNATURE EFI_SIGNATURE_32('i','m','g','f')\r | |
79 | typedef struct {\r | |
80 | UINTN Signature;\r | |
81 | BOOLEAN FreeBuffer;\r | |
82 | VOID *Source;\r | |
83 | UINTN SourceSize;\r | |
84 | } IMAGE_FILE_HANDLE;\r | |
85 | \r | |
86 | \r | |
87 | //\r | |
88 | // Abstractions for reading image contents\r | |
89 | //\r | |
90 | \r | |
162ed594 | 91 | \r |
92 | /**\r | |
93 | Opens a file for (simple) reading. The simple read abstraction\r | |
94 | will access the file either from a memory copy, from a file\r | |
95 | system interface, or from the load file interface.\r | |
96 | \r | |
97 | @param BootPolicy Policy for Open Image File. \r | |
98 | @param SourceBuffer Pointer to the memory location containing copy \r | |
99 | of the image to be loaded. \r | |
100 | @param SourceSize The size in bytes of SourceBuffer. \r | |
101 | @param FilePath The specific file path from which the image is \r | |
102 | loaded \r | |
103 | @param DeviceHandle Pointer to the return device handle. \r | |
104 | @param ImageFileHandle Pointer to the image file handle. \r | |
105 | @param AuthenticationStatus Pointer to a caller-allocated UINT32 in which \r | |
106 | the authentication status is returned. \r | |
107 | \r | |
108 | @retval EFI_SUCCESS Image file successfully opened. \r | |
109 | @retval EFI_LOAD_ERROR If the caller passed a copy of the file, and \r | |
110 | SourceSize is 0. \r | |
111 | @retval EFI_INVALID_PARAMETER File path is not valid. \r | |
112 | @retval EFI_NOT_FOUND File not found.\r | |
113 | \r | |
114 | **/\r | |
28a00297 | 115 | EFI_STATUS\r |
116 | CoreOpenImageFile (\r | |
117 | IN BOOLEAN BootPolicy,\r | |
118 | IN VOID *SourceBuffer OPTIONAL,\r | |
119 | IN UINTN SourceSize,\r | |
cfe9de52 | 120 | IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r |
28a00297 | 121 | OUT EFI_HANDLE *DeviceHandle,\r |
122 | IN IMAGE_FILE_HANDLE *ImageFileHandle,\r | |
123 | OUT UINT32 *AuthenticationStatus\r | |
23c98c94 | 124 | );\r |
28a00297 | 125 | \r |
28a00297 | 126 | \r |
28a00297 | 127 | \r |
162ed594 | 128 | /**\r |
129 | Read image file (specified by UserHandle) into user specified buffer with specified offset\r | |
130 | and length.\r | |
28a00297 | 131 | \r |
162ed594 | 132 | @param UserHandle Image file handle \r |
133 | @param Offset Offset to the source file \r | |
134 | @param ReadSize For input, pointer of size to read; For output, \r | |
135 | pointer of size actually read. \r | |
136 | @param Buffer Buffer to write into \r | |
28a00297 | 137 | \r |
162ed594 | 138 | @retval EFI_SUCCESS Successfully read the specified part of file \r |
139 | into buffer.\r | |
28a00297 | 140 | \r |
162ed594 | 141 | **/\r |
28a00297 | 142 | EFI_STATUS\r |
143 | EFIAPI\r | |
144 | CoreReadImageFile (\r | |
23c98c94 | 145 | IN VOID *UserHandle,\r |
146 | IN UINTN Offset,\r | |
147 | IN OUT UINTN *ReadSize,\r | |
148 | OUT VOID *Buffer\r | |
149 | );\r | |
28a00297 | 150 | \r |
28a00297 | 151 | \r |
162ed594 | 152 | /**\r |
153 | A function out of date, should be removed.\r | |
28a00297 | 154 | \r |
162ed594 | 155 | @param ImageFileHandle Handle of the file to close\r |
28a00297 | 156 | \r |
162ed594 | 157 | **/\r |
28a00297 | 158 | VOID\r |
159 | EFIAPI\r | |
160 | CoreCloseImageFile (\r | |
161 | IN IMAGE_FILE_HANDLE *ImageFileHandle\r | |
23c98c94 | 162 | );\r |
28a00297 | 163 | \r |
164 | //\r | |
165 | // Image processing worker functions\r | |
166 | //\r | |
162ed594 | 167 | \r |
168 | /**\r | |
169 | Search a handle to a device on a specified device path that supports a specified protocol,\r | |
170 | interface of that protocol on that handle is another output.\r | |
171 | \r | |
172 | @param Protocol The protocol to search for \r | |
173 | @param FilePath The specified device path \r | |
174 | @param Interface Interface of the protocol on the handle \r | |
175 | @param Handle The handle to the device on the specified device \r | |
176 | path that supports the protocol. \r | |
177 | \r | |
178 | @return Status code.\r | |
179 | \r | |
180 | **/\r | |
28a00297 | 181 | EFI_STATUS\r |
182 | CoreDevicePathToInterface (\r | |
183 | IN EFI_GUID *Protocol,\r | |
23c98c94 | 184 | IN EFI_DEVICE_PATH_PROTOCOL **FilePath,\r |
28a00297 | 185 | OUT VOID **Interface,\r |
186 | OUT EFI_HANDLE *Handle\r | |
23c98c94 | 187 | );\r |
28a00297 | 188 | \r |
28a00297 | 189 | \r |
162ed594 | 190 | /**\r |
191 | Loads, relocates, and invokes a PE/COFF image\r | |
28a00297 | 192 | \r |
162ed594 | 193 | @param BootPolicy If TRUE, indicates that the request originates \r |
194 | from the boot manager, and that the boot \r | |
195 | manager is attempting to load FilePath as a \r | |
196 | boot selection. \r | |
197 | @param Pe32Handle The handle of PE32 image \r | |
198 | @param Image PE image to be loaded \r | |
199 | @param DstBuffer The buffer to store the image \r | |
200 | @param EntryPoint A pointer to the entry point \r | |
201 | @param Attribute The bit mask of attributes to set for the load \r | |
202 | PE image \r | |
203 | \r | |
204 | @retval EFI_SUCCESS The file was loaded, relocated, and invoked \r | |
205 | @retval EFI_OUT_OF_RESOURCES There was not enough memory to load and \r | |
206 | relocate the PE/COFF file \r | |
207 | @retval EFI_INVALID_PARAMETER Invalid parameter \r | |
208 | @retval EFI_BUFFER_TOO_SMALL Buffer for image is too small\r | |
28a00297 | 209 | \r |
162ed594 | 210 | **/\r |
28a00297 | 211 | EFI_STATUS\r |
212 | CoreLoadPeImage (\r | |
23c98c94 | 213 | IN BOOLEAN BootPolicy, \r |
214 | IN VOID *Pe32Handle,\r | |
215 | IN LOADED_IMAGE_PRIVATE_DATA *Image,\r | |
216 | IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,\r | |
28a00297 | 217 | OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,\r |
218 | IN UINT32 Attribute\r | |
23c98c94 | 219 | );\r |
28a00297 | 220 | \r |
28a00297 | 221 | \r |
162ed594 | 222 | /**\r |
223 | Get the image's private data from its handle.\r | |
28a00297 | 224 | \r |
162ed594 | 225 | @param ImageHandle The image handle \r |
28a00297 | 226 | \r |
162ed594 | 227 | @return Return the image private data associated with ImageHandle.\r |
28a00297 | 228 | \r |
162ed594 | 229 | **/\r |
28a00297 | 230 | LOADED_IMAGE_PRIVATE_DATA *\r |
231 | CoreLoadedImageInfo (\r | |
232 | IN EFI_HANDLE ImageHandle\r | |
23c98c94 | 233 | );\r |
28a00297 | 234 | \r |
28a00297 | 235 | \r |
162ed594 | 236 | /**\r |
237 | Unloads EFI image from memory.\r | |
28a00297 | 238 | \r |
162ed594 | 239 | @param Image EFI image \r |
240 | @param FreePage Free allocated pages\r | |
28a00297 | 241 | \r |
162ed594 | 242 | **/\r |
28a00297 | 243 | VOID\r |
244 | CoreUnloadAndCloseImage (\r | |
245 | IN LOADED_IMAGE_PRIVATE_DATA *Image,\r | |
246 | IN BOOLEAN FreePage\r | |
23c98c94 | 247 | );\r |
28a00297 | 248 | \r |
249 | \r | |
250 | //\r | |
251 | // Exported Image functions\r | |
252 | //\r | |
253 | \r | |
162ed594 | 254 | \r |
255 | /**\r | |
256 | Loads an EFI image into memory and returns a handle to the image with extended parameters.\r | |
257 | \r | |
258 | @param This Calling context \r | |
259 | @param ParentImageHandle The caller's image handle. \r | |
260 | @param FilePath The specific file path from which the image is \r | |
261 | loaded. \r | |
262 | @param SourceBuffer If not NULL, a pointer to the memory location \r | |
263 | containing a copy of the image to be loaded. \r | |
264 | @param SourceSize The size in bytes of SourceBuffer. \r | |
265 | @param DstBuffer The buffer to store the image. \r | |
266 | @param NumberOfPages For input, specifies the space size of the \r | |
267 | image by caller if not NULL. For output, \r | |
268 | specifies the actual space size needed. \r | |
269 | @param ImageHandle Image handle for output. \r | |
270 | @param EntryPoint Image entry point for output. \r | |
271 | @param Attribute The bit mask of attributes to set for the load \r | |
272 | PE image. \r | |
273 | \r | |
274 | @retval EFI_SUCCESS The image was loaded into memory. \r | |
275 | @retval EFI_NOT_FOUND The FilePath was not found. \r | |
276 | @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. \r | |
277 | @retval EFI_UNSUPPORTED The image type is not supported, or the device \r | |
278 | path cannot be parsed to locate the proper \r | |
279 | protocol for loading the file. \r | |
280 | @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient \r | |
281 | resources.\r | |
282 | \r | |
283 | **/\r | |
28a00297 | 284 | EFI_STATUS\r |
285 | EFIAPI\r | |
286 | CoreLoadImageEx (\r | |
23c98c94 | 287 | IN EFI_PE32_IMAGE_PROTOCOL *This,\r |
28a00297 | 288 | IN EFI_HANDLE ParentImageHandle,\r |
289 | IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r | |
290 | IN VOID *SourceBuffer OPTIONAL,\r | |
291 | IN UINTN SourceSize,\r | |
292 | IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,\r | |
293 | OUT UINTN *NumberOfPages OPTIONAL,\r | |
294 | OUT EFI_HANDLE *ImageHandle,\r | |
295 | OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,\r | |
296 | IN UINT32 Attribute\r | |
23c98c94 | 297 | );\r |
28a00297 | 298 | \r |
28a00297 | 299 | \r |
162ed594 | 300 | /**\r |
301 | Unload the specified image.\r | |
28a00297 | 302 | \r |
162ed594 | 303 | @param This Indicates the calling context. \r |
304 | @param ImageHandle The specified image handle. \r | |
305 | \r | |
306 | @retval EFI_INVALID_PARAMETER Image handle is NULL. \r | |
307 | @retval EFI_UNSUPPORTED Attempt to unload an unsupported image. \r | |
308 | @retval EFI_SUCCESS Image successfully unloaded.\r | |
28a00297 | 309 | \r |
162ed594 | 310 | **/\r |
28a00297 | 311 | EFI_STATUS\r |
312 | EFIAPI\r | |
313 | CoreUnloadImageEx (\r | |
23c98c94 | 314 | IN EFI_PE32_IMAGE_PROTOCOL *This,\r |
28a00297 | 315 | IN EFI_HANDLE ImageHandle\r |
23c98c94 | 316 | );\r |
28a00297 | 317 | #endif\r |