3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
28 #define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','d','r','i')
32 EFI_HANDLE Handle
; // Image handle
33 UINTN Type
; // Image type
35 BOOLEAN Started
; // If entrypoint has been called
37 EFI_IMAGE_ENTRY_POINT EntryPoint
; // The image's entry point
38 EFI_LOADED_IMAGE_PROTOCOL Info
; // loaded image protocol
40 EFI_PHYSICAL_ADDRESS ImageBasePage
; // Location in memory
41 UINTN NumberOfPages
; // Number of pages
43 CHAR8
*FixupData
; // Original fixup data
45 EFI_TPL Tpl
; // Tpl of started image
46 EFI_STATUS Status
; // Status returned by started image
48 UINTN ExitDataSize
; // Size of ExitData from started image
49 VOID
*ExitData
; // Pointer to exit data from started image
50 BASE_LIBRARY_JUMP_BUFFER
*JumpContext
; // Pointer to buffer for context save/retore
51 UINT16 Machine
; // Machine type from PE image
53 EFI_EBC_PROTOCOL
*Ebc
; // EBC Protocol pointer
55 BOOLEAN RuntimeFixupValid
; // True if RT image needs fixup
56 VOID
*RuntimeFixup
; // Copy of fixup data;
57 LIST_ENTRY Link
; // List of RT LOADED_IMAGE_PRIVATE_DATA
59 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
; // PeCoffLoader ImageContext
61 } LOADED_IMAGE_PRIVATE_DATA
;
63 #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
64 CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)
68 #define LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','p','e','i')
72 EFI_HANDLE Handle
; // Image handle
73 EFI_PE32_IMAGE_PROTOCOL Pe32Image
;
74 } LOAD_PE32_IMAGE_PRIVATE_DATA
;
76 #define LOAD_PE32_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
77 CR(a, LOAD_PE32_IMAGE_PRIVATE_DATA, Pe32Image, LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE)
84 #define IMAGE_FILE_HANDLE_SIGNATURE EFI_SIGNATURE_32('i','m','g','f')
94 // Abstractions for reading image contents
99 IN BOOLEAN BootPolicy
,
100 IN VOID
*SourceBuffer OPTIONAL
,
102 IN OUT EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
103 OUT EFI_HANDLE
*DeviceHandle
,
104 IN IMAGE_FILE_HANDLE
*ImageFileHandle
,
105 OUT UINT32
*AuthenticationStatus
111 Opens a file for (simple) reading. The simple read abstraction
112 will access the file either from a memory copy, from a file
113 system interface, or from the load file interface.
117 BootPolicy - Policy for Open Image File.
118 SourceBuffer - Pointer to the memory location containing copy
119 of the image to be loaded.
120 SourceSize - The size in bytes of SourceBuffer.
121 FilePath - The specific file path from which the image is loaded
122 DeviceHandle - Pointer to the return device handle.
123 ImageFileHandle - Pointer to the image file handle.
124 AuthenticationStatus - Pointer to a caller-allocated UINT32 in which the authentication status is returned.
128 A handle to access the file
139 IN OUT UINTN
*ReadSize
,
146 Read image file (specified by UserHandle) into user specified buffer with specified offset
151 UserHandle - Image file handle
153 Offset - Offset to the source file
155 ReadSize - For input, pointer of size to read;
156 For output, pointer of size actually read.
158 Buffer - Buffer to write into
162 EFI_SUCCESS - Successfully read the specified part of file into buffer.
170 IN IMAGE_FILE_HANDLE
*ImageFileHandle
176 A function out of date, should be removed.
180 ImageFileHandle - Handle of the file to close
190 // Image processing worker functions
193 CoreDevicePathToInterface (
194 IN EFI_GUID
*Protocol
,
195 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
,
196 OUT VOID
**Interface
,
197 OUT EFI_HANDLE
*Handle
203 Search a handle to a device on a specified device path that supports a specified protocol,
204 interface of that protocol on that handle is another output.
208 Protocol - The protocol to search for
210 FilePath - The specified device path
212 Interface - Interface of the protocol on the handle
214 Handle - The handle to the device on the specified device path that supports the protocol.
226 IN LOADED_IMAGE_PRIVATE_DATA
*Image
,
227 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL
,
228 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint OPTIONAL
,
235 Loads, relocates, and invokes a PE/COFF image
239 Pe32Handle - The handle of PE32 image
240 Image - PE image to be loaded
241 DstBuffer - The buffer to store the image
242 EntryPoint - A pointer to the entry point
243 Attribute - The bit mask of attributes to set for the load PE image
247 EFI_SUCCESS - The file was loaded, relocated, and invoked
249 EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
251 EFI_INVALID_PARAMETER - Invalid parameter
253 EFI_BUFFER_TOO_SMALL - Buffer for image is too small
258 LOADED_IMAGE_PRIVATE_DATA
*
259 CoreLoadedImageInfo (
260 IN EFI_HANDLE ImageHandle
266 TODO: Add function description
270 ImageHandle - TODO: add argument description
274 TODO: add return values
280 CoreUnloadAndCloseImage (
281 IN LOADED_IMAGE_PRIVATE_DATA
*Image
,
288 Unloads EFI image from memory.
293 FreePage - Free allocated pages
304 // Exported Image functions
310 IN EFI_PE32_IMAGE_PROTOCOL
*This
,
311 IN EFI_HANDLE ParentImageHandle
,
312 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
313 IN VOID
*SourceBuffer OPTIONAL
,
315 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL
,
316 OUT UINTN
*NumberOfPages OPTIONAL
,
317 OUT EFI_HANDLE
*ImageHandle
,
318 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint OPTIONAL
,
325 Loads an EFI image into memory and returns a handle to the image with extended parameters.
329 ParentImageHandle - The caller's image handle.
330 FilePath - The specific file path from which the image is loaded.
331 SourceBuffer - If not NULL, a pointer to the memory location containing a copy of
332 the image to be loaded.
333 SourceSize - The size in bytes of SourceBuffer.
334 DstBuffer - The buffer to store the image.
335 NumberOfPages - For input, specifies the space size of the image by caller if not NULL.
336 For output, specifies the actual space size needed.
337 ImageHandle - Image handle for output.
338 EntryPoint - Image entry point for output.
339 Attribute - The bit mask of attributes to set for the load PE image.
343 EFI_SUCCESS - The image was loaded into memory.
344 EFI_NOT_FOUND - The FilePath was not found.
345 EFI_INVALID_PARAMETER - One of the parameters has an invalid value.
346 EFI_UNSUPPORTED - The image type is not supported, or the device path cannot be
347 parsed to locate the proper protocol for loading the file.
348 EFI_OUT_OF_RESOURCES - Image was not loaded due to insufficient resources.
355 IN EFI_PE32_IMAGE_PROTOCOL
*This
,
356 IN EFI_HANDLE ImageHandle
362 Unload the specified image.
366 This - Indicates the calling context.
368 ImageHandle - The specified image handle.
372 EFI_INVALID_PARAMETER - Image handle is NULL.
374 EFI_UNSUPPORTED - Attempt to unload an unsupported image.
376 EFI_SUCCESS - Image successfully unloaded.