3 Copyright (c) 2006, Intel Corporation
\r
4 All rights reserved. This program and the accompanying materials
\r
5 are licensed and made available under the terms and conditions of the BSD License
\r
6 which accompanies this distribution. The full text of the license may be found at
\r
7 http://opensource.org/licenses/bsd-license.php
\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
\r
28 #define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','d','r','i')
\r
32 EFI_HANDLE Handle; // Image handle
\r
33 UINTN Type; // Image type
\r
35 BOOLEAN Started; // If entrypoint has been called
\r
37 EFI_IMAGE_ENTRY_POINT EntryPoint; // The image's entry point
\r
38 EFI_LOADED_IMAGE_PROTOCOL Info; // loaded image protocol
\r
40 EFI_PHYSICAL_ADDRESS ImageBasePage; // Location in memory
\r
41 UINTN NumberOfPages; // Number of pages
\r
43 CHAR8 *FixupData; // Original fixup data
\r
45 EFI_TPL Tpl; // Tpl of started image
\r
46 EFI_STATUS Status; // Status returned by started image
\r
48 UINTN ExitDataSize; // Size of ExitData from started image
\r
49 VOID *ExitData; // Pointer to exit data from started image
\r
50 VOID *JumpBuffer; // Pointer to pool allocation for context save/retore
\r
51 BASE_LIBRARY_JUMP_BUFFER *JumpContext; // Pointer to buffer for context save/retore
\r
52 UINT16 Machine; // Machine type from PE image
\r
54 EFI_EBC_PROTOCOL *Ebc; // EBC Protocol pointer
\r
56 EFI_RUNTIME_IMAGE_ENTRY *RuntimeData; // Runtime image list
\r
58 EFI_DEVICE_PATH_PROTOCOL *DeviceHandleDevicePath;
\r
60 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; // PeCoffLoader ImageContext
\r
62 } LOADED_IMAGE_PRIVATE_DATA;
\r
64 #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
\r
65 CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)
\r
69 #define LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','p','e','i')
\r
73 EFI_HANDLE Handle; // Image handle
\r
74 EFI_PE32_IMAGE_PROTOCOL Pe32Image;
\r
75 } LOAD_PE32_IMAGE_PRIVATE_DATA;
\r
77 #define LOAD_PE32_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
\r
78 CR(a, LOAD_PE32_IMAGE_PRIVATE_DATA, Pe32Image, LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE)
\r
83 // Private Data Types
\r
85 #define IMAGE_FILE_HANDLE_SIGNATURE EFI_SIGNATURE_32('i','m','g','f')
\r
91 } IMAGE_FILE_HANDLE;
\r
95 // Abstractions for reading image contents
\r
100 IN BOOLEAN BootPolicy,
\r
101 IN VOID *SourceBuffer OPTIONAL,
\r
102 IN UINTN SourceSize,
\r
103 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,
\r
104 OUT EFI_HANDLE *DeviceHandle,
\r
105 IN IMAGE_FILE_HANDLE *ImageFileHandle,
\r
106 OUT UINT32 *AuthenticationStatus
\r
110 Routine Description:
\r
112 Opens a file for (simple) reading. The simple read abstraction
\r
113 will access the file either from a memory copy, from a file
\r
114 system interface, or from the load file interface.
\r
118 BootPolicy - Policy for Open Image File.
\r
119 SourceBuffer - Pointer to the memory location containing copy
\r
120 of the image to be loaded.
\r
121 SourceSize - The size in bytes of SourceBuffer.
\r
122 FilePath - The specific file path from which the image is loaded
\r
123 DeviceHandle - Pointer to the return device handle.
\r
124 ImageFileHandle - Pointer to the image file handle.
\r
125 AuthenticationStatus - Pointer to a caller-allocated UINT32 in which the authentication status is returned.
\r
129 A handle to access the file
\r
137 CoreReadImageFile (
\r
138 IN VOID *UserHandle,
\r
140 IN OUT UINTN *ReadSize,
\r
145 Routine Description:
\r
147 Read image file (specified by UserHandle) into user specified buffer with specified offset
\r
152 UserHandle - Image file handle
\r
154 Offset - Offset to the source file
\r
156 ReadSize - For input, pointer of size to read;
\r
157 For output, pointer of size actually read.
\r
159 Buffer - Buffer to write into
\r
163 EFI_SUCCESS - Successfully read the specified part of file into buffer.
\r
170 CoreCloseImageFile (
\r
171 IN IMAGE_FILE_HANDLE *ImageFileHandle
\r
175 Routine Description:
\r
177 A function out of date, should be removed.
\r
181 ImageFileHandle - Handle of the file to close
\r
191 // Image processing worker functions
\r
194 CoreDevicePathToInterface (
\r
195 IN EFI_GUID *Protocol,
\r
196 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,
\r
197 OUT VOID **Interface,
\r
198 OUT EFI_HANDLE *Handle
\r
202 Routine Description:
\r
204 Search a handle to a device on a specified device path that supports a specified protocol,
\r
205 interface of that protocol on that handle is another output.
\r
209 Protocol - The protocol to search for
\r
211 FilePath - The specified device path
\r
213 Interface - Interface of the protocol on the handle
\r
215 Handle - The handle to the device on the specified device path that supports the protocol.
\r
226 IN BOOLEAN BootPolicy,
\r
227 IN VOID *Pe32Handle,
\r
228 IN LOADED_IMAGE_PRIVATE_DATA *Image,
\r
229 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
\r
230 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
\r
231 IN UINT32 Attribute
\r
235 Routine Description:
\r
237 Loads, relocates, and invokes a PE/COFF image
\r
241 BootPolicy - Policy for Open Image File.
\r
242 Pe32Handle - The handle of PE32 image
\r
243 Image - PE image to be loaded
\r
244 DstBuffer - The buffer to store the image
\r
245 EntryPoint - A pointer to the entry point
\r
246 Attribute - The bit mask of attributes to set for the load PE image
\r
250 EFI_SUCCESS - The file was loaded, relocated, and invoked
\r
252 EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
\r
254 EFI_INVALID_PARAMETER - Invalid parameter
\r
256 EFI_BUFFER_TOO_SMALL - Buffer for image is too small
\r
261 LOADED_IMAGE_PRIVATE_DATA *
\r
262 CoreLoadedImageInfo (
\r
263 IN EFI_HANDLE ImageHandle
\r
267 Routine Description:
\r
269 TODO: Add function description
\r
273 ImageHandle - TODO: add argument description
\r
277 TODO: add return values
\r
283 CoreUnloadAndCloseImage (
\r
284 IN LOADED_IMAGE_PRIVATE_DATA *Image,
\r
285 IN BOOLEAN FreePage
\r
289 Routine Description:
\r
291 Unloads EFI image from memory.
\r
296 FreePage - Free allocated pages
\r
307 // Exported Image functions
\r
313 IN EFI_PE32_IMAGE_PROTOCOL *This,
\r
314 IN EFI_HANDLE ParentImageHandle,
\r
315 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
\r
316 IN VOID *SourceBuffer OPTIONAL,
\r
317 IN UINTN SourceSize,
\r
318 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
\r
319 OUT UINTN *NumberOfPages OPTIONAL,
\r
320 OUT EFI_HANDLE *ImageHandle,
\r
321 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
\r
322 IN UINT32 Attribute
\r
326 Routine Description:
\r
328 Loads an EFI image into memory and returns a handle to the image with extended parameters.
\r
332 ParentImageHandle - The caller's image handle.
\r
333 FilePath - The specific file path from which the image is loaded.
\r
334 SourceBuffer - If not NULL, a pointer to the memory location containing a copy of
\r
335 the image to be loaded.
\r
336 SourceSize - The size in bytes of SourceBuffer.
\r
337 DstBuffer - The buffer to store the image.
\r
338 NumberOfPages - For input, specifies the space size of the image by caller if not NULL.
\r
339 For output, specifies the actual space size needed.
\r
340 ImageHandle - Image handle for output.
\r
341 EntryPoint - Image entry point for output.
\r
342 Attribute - The bit mask of attributes to set for the load PE image.
\r
346 EFI_SUCCESS - The image was loaded into memory.
\r
347 EFI_NOT_FOUND - The FilePath was not found.
\r
348 EFI_INVALID_PARAMETER - One of the parameters has an invalid value.
\r
349 EFI_UNSUPPORTED - The image type is not supported, or the device path cannot be
\r
350 parsed to locate the proper protocol for loading the file.
\r
351 EFI_OUT_OF_RESOURCES - Image was not loaded due to insufficient resources.
\r
357 CoreUnloadImageEx (
\r
358 IN EFI_PE32_IMAGE_PROTOCOL *This,
\r
359 IN EFI_HANDLE ImageHandle
\r
363 Routine Description:
\r
365 Unload the specified image.
\r
369 This - Indicates the calling context.
\r
371 ImageHandle - The specified image handle.
\r
375 EFI_INVALID_PARAMETER - Image handle is NULL.
\r
377 EFI_UNSUPPORTED - Attempt to unload an unsupported image.
\r
379 EFI_SUCCESS - Image successfully unloaded.
\r