]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/Image.h
Assert() break point default is DEADLOOP().
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Image.h
CommitLineData
504214c4
LG
1/** @file \r
2 \r
3 Data structure and functions to load and unload PeImage.\r
4 \r
5Copyright (c) 2006 - 2008, Intel Corporation\r
28a00297 6All rights reserved. This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
504214c4 14**/\r
28a00297 15\r
16\r
17#ifndef _IMAGE_H_\r
18#define _IMAGE_H_\r
19\r
20\r
21\r
22#define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','d','r','i')\r
23\r
24typedef struct {\r
25 UINTN Signature;\r
26 EFI_HANDLE Handle; // Image handle\r
27 UINTN Type; // Image type\r
28\r
29 BOOLEAN Started; // If entrypoint has been called\r
30\r
31 EFI_IMAGE_ENTRY_POINT EntryPoint; // The image's entry point\r
32 EFI_LOADED_IMAGE_PROTOCOL Info; // loaded image protocol\r
33\r
34 EFI_PHYSICAL_ADDRESS ImageBasePage; // Location in memory\r
35 UINTN NumberOfPages; // Number of pages\r
36\r
37 CHAR8 *FixupData; // Original fixup data\r
38\r
39 EFI_TPL Tpl; // Tpl of started image\r
40 EFI_STATUS Status; // Status returned by started image\r
41\r
42 UINTN ExitDataSize; // Size of ExitData from started image\r
43 VOID *ExitData; // Pointer to exit data from started image\r
44 VOID *JumpBuffer; // Pointer to pool allocation for context save/retore\r
45 BASE_LIBRARY_JUMP_BUFFER *JumpContext; // Pointer to buffer for context save/retore\r
46 UINT16 Machine; // Machine type from PE image\r
47\r
48 EFI_EBC_PROTOCOL *Ebc; // EBC Protocol pointer\r
49\r
50 EFI_RUNTIME_IMAGE_ENTRY *RuntimeData; // Runtime image list\r
51\r
ba39e316 52 EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath; // Pointer to Loaded Image Device Path Protocl\r
85658066 53\r
28a00297 54 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; // PeCoffLoader ImageContext\r
55\r
56} LOADED_IMAGE_PRIVATE_DATA;\r
57\r
58#define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \\r
59 CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)\r
60\r
61\r
62\r
63#define LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','p','e','i')\r
64\r
65typedef struct {\r
66 UINTN Signature;\r
67 EFI_HANDLE Handle; // Image handle\r
68 EFI_PE32_IMAGE_PROTOCOL Pe32Image;\r
69} LOAD_PE32_IMAGE_PRIVATE_DATA;\r
70\r
71#define LOAD_PE32_IMAGE_PRIVATE_DATA_FROM_THIS(a) \\r
72 CR(a, LOAD_PE32_IMAGE_PRIVATE_DATA, Pe32Image, LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE)\r
73\r
74\r
75\r
76//\r
77// Private Data Types\r
78//\r
79#define IMAGE_FILE_HANDLE_SIGNATURE EFI_SIGNATURE_32('i','m','g','f')\r
80typedef struct {\r
81 UINTN Signature;\r
82 BOOLEAN FreeBuffer;\r
83 VOID *Source;\r
84 UINTN SourceSize;\r
85} IMAGE_FILE_HANDLE;\r
86\r
87\r
88//\r
89// Abstractions for reading image contents\r
90//\r
91\r
92EFI_STATUS\r
93CoreOpenImageFile (\r
94 IN BOOLEAN BootPolicy,\r
95 IN VOID *SourceBuffer OPTIONAL,\r
96 IN UINTN SourceSize,\r
cfe9de52 97 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
28a00297 98 OUT EFI_HANDLE *DeviceHandle,\r
99 IN IMAGE_FILE_HANDLE *ImageFileHandle,\r
100 OUT UINT32 *AuthenticationStatus\r
101 )\r
102/*++\r
103\r
104Routine Description:\r
105\r
106 Opens a file for (simple) reading. The simple read abstraction\r
107 will access the file either from a memory copy, from a file\r
108 system interface, or from the load file interface.\r
109\r
110Arguments:\r
111\r
112 BootPolicy - Policy for Open Image File.\r
113 SourceBuffer - Pointer to the memory location containing copy\r
114 of the image to be loaded.\r
115 SourceSize - The size in bytes of SourceBuffer.\r
116 FilePath - The specific file path from which the image is loaded\r
117 DeviceHandle - Pointer to the return device handle.\r
118 ImageFileHandle - Pointer to the image file handle.\r
119 AuthenticationStatus - Pointer to a caller-allocated UINT32 in which the authentication status is returned.\r
120\r
121Returns:\r
122\r
123 A handle to access the file\r
124\r
125--*/\r
126;\r
127\r
128\r
129EFI_STATUS\r
130EFIAPI\r
131CoreReadImageFile (\r
132 IN VOID *UserHandle,\r
133 IN UINTN Offset,\r
134 IN OUT UINTN *ReadSize,\r
135 OUT VOID *Buffer\r
136 )\r
137/*++\r
138\r
139Routine Description:\r
140\r
141 Read image file (specified by UserHandle) into user specified buffer with specified offset\r
142 and length.\r
143\r
144Arguments:\r
145\r
146 UserHandle - Image file handle\r
147\r
148 Offset - Offset to the source file\r
149\r
150 ReadSize - For input, pointer of size to read;\r
151 For output, pointer of size actually read.\r
152\r
153 Buffer - Buffer to write into\r
154\r
155Returns:\r
156\r
157 EFI_SUCCESS - Successfully read the specified part of file into buffer.\r
158\r
159--*/\r
160;\r
161\r
162VOID\r
163EFIAPI\r
164CoreCloseImageFile (\r
165 IN IMAGE_FILE_HANDLE *ImageFileHandle\r
166 )\r
167/*++\r
168\r
169Routine Description:\r
170\r
171 A function out of date, should be removed.\r
172\r
173Arguments:\r
174\r
175 ImageFileHandle - Handle of the file to close\r
176\r
177Returns:\r
178\r
179 None\r
180\r
181--*/\r
182;\r
183\r
184//\r
185// Image processing worker functions\r
186//\r
187EFI_STATUS\r
188CoreDevicePathToInterface (\r
189 IN EFI_GUID *Protocol,\r
190 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
191 OUT VOID **Interface,\r
192 OUT EFI_HANDLE *Handle\r
193 )\r
194/*++\r
195\r
196Routine Description:\r
197\r
198 Search a handle to a device on a specified device path that supports a specified protocol,\r
199 interface of that protocol on that handle is another output.\r
200\r
201Arguments:\r
202\r
203 Protocol - The protocol to search for\r
204\r
205 FilePath - The specified device path\r
206\r
207 Interface - Interface of the protocol on the handle\r
208\r
209 Handle - The handle to the device on the specified device path that supports the protocol.\r
210\r
211Returns:\r
212\r
213 Status code.\r
214\r
215--*/\r
216;\r
217\r
218EFI_STATUS\r
219CoreLoadPeImage (\r
822360ee 220 IN BOOLEAN BootPolicy,\r
28a00297 221 IN VOID *Pe32Handle,\r
222 IN LOADED_IMAGE_PRIVATE_DATA *Image,\r
223 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,\r
224 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,\r
225 IN UINT32 Attribute\r
226 )\r
227/*++\r
228\r
229Routine Description:\r
230\r
231 Loads, relocates, and invokes a PE/COFF image\r
232\r
233Arguments:\r
234\r
822360ee 235 BootPolicy - Policy for Open Image File.\r
28a00297 236 Pe32Handle - The handle of PE32 image\r
237 Image - PE image to be loaded\r
238 DstBuffer - The buffer to store the image\r
239 EntryPoint - A pointer to the entry point\r
240 Attribute - The bit mask of attributes to set for the load PE image\r
241\r
242Returns:\r
243\r
244 EFI_SUCCESS - The file was loaded, relocated, and invoked\r
245\r
246 EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file\r
247\r
248 EFI_INVALID_PARAMETER - Invalid parameter\r
249\r
250 EFI_BUFFER_TOO_SMALL - Buffer for image is too small\r
251\r
252--*/\r
253;\r
254\r
255LOADED_IMAGE_PRIVATE_DATA *\r
256CoreLoadedImageInfo (\r
257 IN EFI_HANDLE ImageHandle\r
258 )\r
259/*++\r
260\r
261Routine Description:\r
262\r
263 TODO: Add function description\r
264\r
265Arguments:\r
266\r
267 ImageHandle - TODO: add argument description\r
268\r
269Returns:\r
270\r
271 TODO: add return values\r
272\r
273--*/\r
274;\r
275\r
276VOID\r
277CoreUnloadAndCloseImage (\r
278 IN LOADED_IMAGE_PRIVATE_DATA *Image,\r
279 IN BOOLEAN FreePage\r
280 )\r
281/*++\r
282\r
283Routine Description:\r
284\r
285 Unloads EFI image from memory.\r
286\r
287Arguments:\r
288\r
289 Image - EFI image\r
290 FreePage - Free allocated pages\r
291\r
292Returns:\r
293\r
294 None\r
295\r
296--*/\r
297;\r
298\r
299\r
300//\r
301// Exported Image functions\r
302//\r
303\r
304EFI_STATUS\r
305EFIAPI\r
306CoreLoadImageEx (\r
307 IN EFI_PE32_IMAGE_PROTOCOL *This,\r
308 IN EFI_HANDLE ParentImageHandle,\r
309 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
310 IN VOID *SourceBuffer OPTIONAL,\r
311 IN UINTN SourceSize,\r
312 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,\r
313 OUT UINTN *NumberOfPages OPTIONAL,\r
314 OUT EFI_HANDLE *ImageHandle,\r
315 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,\r
316 IN UINT32 Attribute\r
317 )\r
318/*++\r
319\r
320Routine Description:\r
321\r
322 Loads an EFI image into memory and returns a handle to the image with extended parameters.\r
323\r
324Arguments:\r
325\r
326 ParentImageHandle - The caller's image handle.\r
327 FilePath - The specific file path from which the image is loaded.\r
328 SourceBuffer - If not NULL, a pointer to the memory location containing a copy of\r
329 the image to be loaded.\r
330 SourceSize - The size in bytes of SourceBuffer.\r
331 DstBuffer - The buffer to store the image.\r
332 NumberOfPages - For input, specifies the space size of the image by caller if not NULL.\r
333 For output, specifies the actual space size needed.\r
334 ImageHandle - Image handle for output.\r
335 EntryPoint - Image entry point for output.\r
336 Attribute - The bit mask of attributes to set for the load PE image.\r
337\r
338Returns:\r
339\r
340 EFI_SUCCESS - The image was loaded into memory.\r
341 EFI_NOT_FOUND - The FilePath was not found.\r
342 EFI_INVALID_PARAMETER - One of the parameters has an invalid value.\r
343 EFI_UNSUPPORTED - The image type is not supported, or the device path cannot be\r
344 parsed to locate the proper protocol for loading the file.\r
345 EFI_OUT_OF_RESOURCES - Image was not loaded due to insufficient resources.\r
346--*/\r
347;\r
348\r
349EFI_STATUS\r
350EFIAPI\r
351CoreUnloadImageEx (\r
352 IN EFI_PE32_IMAGE_PROTOCOL *This,\r
353 IN EFI_HANDLE ImageHandle\r
354 )\r
355/*++\r
356\r
357Routine Description:\r
358\r
359 Unload the specified image.\r
360\r
361Arguments:\r
362\r
363 This - Indicates the calling context.\r
364\r
365 ImageHandle - The specified image handle.\r
366\r
367Returns:\r
368\r
369 EFI_INVALID_PARAMETER - Image handle is NULL.\r
370\r
371 EFI_UNSUPPORTED - Attempt to unload an unsupported image.\r
372\r
373 EFI_SUCCESS - Image successfully unloaded.\r
374\r
375--*/\r
376;\r
377#endif\r