]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/Image.h
Change the file name case to follow coding style: The first character should be capital.
[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
162ed594 92\r
93/**\r
94 Opens a file for (simple) reading. The simple read abstraction\r
95 will access the file either from a memory copy, from a file\r
96 system interface, or from the load file interface.\r
97\r
98 @param BootPolicy Policy for Open Image File. \r
99 @param SourceBuffer Pointer to the memory location containing copy \r
100 of the image to be loaded. \r
101 @param SourceSize The size in bytes of SourceBuffer. \r
102 @param FilePath The specific file path from which the image is \r
103 loaded \r
104 @param DeviceHandle Pointer to the return device handle. \r
105 @param ImageFileHandle Pointer to the image file handle. \r
106 @param AuthenticationStatus Pointer to a caller-allocated UINT32 in which \r
107 the authentication status is returned. \r
108\r
109 @retval EFI_SUCCESS Image file successfully opened. \r
110 @retval EFI_LOAD_ERROR If the caller passed a copy of the file, and \r
111 SourceSize is 0. \r
112 @retval EFI_INVALID_PARAMETER File path is not valid. \r
113 @retval EFI_NOT_FOUND File not found.\r
114\r
115**/\r
28a00297 116EFI_STATUS\r
117CoreOpenImageFile (\r
118 IN BOOLEAN BootPolicy,\r
119 IN VOID *SourceBuffer OPTIONAL,\r
120 IN UINTN SourceSize,\r
cfe9de52 121 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
28a00297 122 OUT EFI_HANDLE *DeviceHandle,\r
123 IN IMAGE_FILE_HANDLE *ImageFileHandle,\r
124 OUT UINT32 *AuthenticationStatus\r
125 )\r
162ed594 126;\r
28a00297 127\r
28a00297 128\r
28a00297 129\r
162ed594 130/**\r
131 Read image file (specified by UserHandle) into user specified buffer with specified offset\r
132 and length.\r
28a00297 133\r
162ed594 134 @param UserHandle Image file handle \r
135 @param Offset Offset to the source file \r
136 @param ReadSize For input, pointer of size to read; For output, \r
137 pointer of size actually read. \r
138 @param Buffer Buffer to write into \r
28a00297 139\r
162ed594 140 @retval EFI_SUCCESS Successfully read the specified part of file \r
141 into buffer.\r
28a00297 142\r
162ed594 143**/\r
28a00297 144EFI_STATUS\r
145EFIAPI\r
146CoreReadImageFile (\r
147 IN VOID *UserHandle,\r
148 IN UINTN Offset,\r
149 IN OUT UINTN *ReadSize,\r
150 OUT VOID *Buffer\r
151 )\r
162ed594 152;\r
28a00297 153\r
28a00297 154\r
162ed594 155/**\r
156 A function out of date, should be removed.\r
28a00297 157\r
162ed594 158 @param ImageFileHandle Handle of the file to close\r
28a00297 159\r
162ed594 160**/\r
28a00297 161VOID\r
162EFIAPI\r
163CoreCloseImageFile (\r
164 IN IMAGE_FILE_HANDLE *ImageFileHandle\r
165 )\r
28a00297 166;\r
167\r
168//\r
169// Image processing worker functions\r
170//\r
162ed594 171\r
172/**\r
173 Search a handle to a device on a specified device path that supports a specified protocol,\r
174 interface of that protocol on that handle is another output.\r
175\r
176 @param Protocol The protocol to search for \r
177 @param FilePath The specified device path \r
178 @param Interface Interface of the protocol on the handle \r
179 @param Handle The handle to the device on the specified device \r
180 path that supports the protocol. \r
181\r
182 @return Status code.\r
183\r
184**/\r
28a00297 185EFI_STATUS\r
186CoreDevicePathToInterface (\r
187 IN EFI_GUID *Protocol,\r
188 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
189 OUT VOID **Interface,\r
190 OUT EFI_HANDLE *Handle\r
191 )\r
162ed594 192;\r
28a00297 193\r
28a00297 194\r
162ed594 195/**\r
196 Loads, relocates, and invokes a PE/COFF image\r
28a00297 197\r
162ed594 198 @param BootPolicy If TRUE, indicates that the request originates \r
199 from the boot manager, and that the boot \r
200 manager is attempting to load FilePath as a \r
201 boot selection. \r
202 @param Pe32Handle The handle of PE32 image \r
203 @param Image PE image to be loaded \r
204 @param DstBuffer The buffer to store the image \r
205 @param EntryPoint A pointer to the entry point \r
206 @param Attribute The bit mask of attributes to set for the load \r
207 PE image \r
208\r
209 @retval EFI_SUCCESS The file was loaded, relocated, and invoked \r
210 @retval EFI_OUT_OF_RESOURCES There was not enough memory to load and \r
211 relocate the PE/COFF file \r
212 @retval EFI_INVALID_PARAMETER Invalid parameter \r
213 @retval EFI_BUFFER_TOO_SMALL Buffer for image is too small\r
28a00297 214\r
162ed594 215**/\r
28a00297 216EFI_STATUS\r
217CoreLoadPeImage (\r
822360ee 218 IN BOOLEAN BootPolicy,\r
28a00297 219 IN VOID *Pe32Handle,\r
220 IN LOADED_IMAGE_PRIVATE_DATA *Image,\r
221 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,\r
222 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,\r
223 IN UINT32 Attribute\r
224 )\r
162ed594 225;\r
28a00297 226\r
28a00297 227\r
162ed594 228/**\r
229 Get the image's private data from its handle.\r
28a00297 230\r
162ed594 231 @param ImageHandle The image handle \r
28a00297 232\r
162ed594 233 @return Return the image private data associated with ImageHandle.\r
28a00297 234\r
162ed594 235**/\r
28a00297 236LOADED_IMAGE_PRIVATE_DATA *\r
237CoreLoadedImageInfo (\r
238 IN EFI_HANDLE ImageHandle\r
239 )\r
162ed594 240;\r
28a00297 241\r
28a00297 242\r
162ed594 243/**\r
244 Unloads EFI image from memory.\r
28a00297 245\r
162ed594 246 @param Image EFI image \r
247 @param FreePage Free allocated pages\r
28a00297 248\r
162ed594 249**/\r
28a00297 250VOID\r
251CoreUnloadAndCloseImage (\r
252 IN LOADED_IMAGE_PRIVATE_DATA *Image,\r
253 IN BOOLEAN FreePage\r
254 )\r
28a00297 255;\r
256\r
257\r
258//\r
259// Exported Image functions\r
260//\r
261\r
162ed594 262\r
263/**\r
264 Loads an EFI image into memory and returns a handle to the image with extended parameters.\r
265\r
266 @param This Calling context \r
267 @param ParentImageHandle The caller's image handle. \r
268 @param FilePath The specific file path from which the image is \r
269 loaded. \r
270 @param SourceBuffer If not NULL, a pointer to the memory location \r
271 containing a copy of the image to be loaded. \r
272 @param SourceSize The size in bytes of SourceBuffer. \r
273 @param DstBuffer The buffer to store the image. \r
274 @param NumberOfPages For input, specifies the space size of the \r
275 image by caller if not NULL. For output, \r
276 specifies the actual space size needed. \r
277 @param ImageHandle Image handle for output. \r
278 @param EntryPoint Image entry point for output. \r
279 @param Attribute The bit mask of attributes to set for the load \r
280 PE image. \r
281\r
282 @retval EFI_SUCCESS The image was loaded into memory. \r
283 @retval EFI_NOT_FOUND The FilePath was not found. \r
284 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. \r
285 @retval EFI_UNSUPPORTED The image type is not supported, or the device \r
286 path cannot be parsed to locate the proper \r
287 protocol for loading the file. \r
288 @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient \r
289 resources.\r
290\r
291**/\r
28a00297 292EFI_STATUS\r
293EFIAPI\r
294CoreLoadImageEx (\r
295 IN EFI_PE32_IMAGE_PROTOCOL *This,\r
296 IN EFI_HANDLE ParentImageHandle,\r
297 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
298 IN VOID *SourceBuffer OPTIONAL,\r
299 IN UINTN SourceSize,\r
300 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,\r
301 OUT UINTN *NumberOfPages OPTIONAL,\r
302 OUT EFI_HANDLE *ImageHandle,\r
303 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,\r
304 IN UINT32 Attribute\r
305 )\r
162ed594 306;\r
28a00297 307\r
28a00297 308\r
162ed594 309/**\r
310 Unload the specified image.\r
28a00297 311\r
162ed594 312 @param This Indicates the calling context. \r
313 @param ImageHandle The specified image handle. \r
314\r
315 @retval EFI_INVALID_PARAMETER Image handle is NULL. \r
316 @retval EFI_UNSUPPORTED Attempt to unload an unsupported image. \r
317 @retval EFI_SUCCESS Image successfully unloaded.\r
28a00297 318\r
162ed594 319**/\r
28a00297 320EFI_STATUS\r
321EFIAPI\r
322CoreUnloadImageEx (\r
323 IN EFI_PE32_IMAGE_PROTOCOL *This,\r
324 IN EFI_HANDLE ImageHandle\r
325 )\r
28a00297 326;\r
327#endif\r