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 VOID
*JumpBuffer
; // Pointer to pool allocation for context save/retore
51 BASE_LIBRARY_JUMP_BUFFER
*JumpContext
; // Pointer to buffer for context save/retore
52 UINT16 Machine
; // Machine type from PE image
54 EFI_EBC_PROTOCOL
*Ebc
; // EBC Protocol pointer
56 BOOLEAN RuntimeFixupValid
; // True if RT image needs fixup
57 VOID
*RuntimeFixup
; // Copy of fixup data;
58 LIST_ENTRY Link
; // List of RT LOADED_IMAGE_PRIVATE_DATA
60 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
; // PeCoffLoader ImageContext
62 } LOADED_IMAGE_PRIVATE_DATA
;
64 #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
65 CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)
69 #define LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','p','e','i')
73 EFI_HANDLE Handle
; // Image handle
74 EFI_PE32_IMAGE_PROTOCOL Pe32Image
;
75 } LOAD_PE32_IMAGE_PRIVATE_DATA
;
77 #define LOAD_PE32_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
78 CR(a, LOAD_PE32_IMAGE_PRIVATE_DATA, Pe32Image, LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE)
85 #define IMAGE_FILE_HANDLE_SIGNATURE EFI_SIGNATURE_32('i','m','g','f')
95 // Abstractions for reading image contents
100 IN BOOLEAN BootPolicy
,
101 IN VOID
*SourceBuffer OPTIONAL
,
103 IN OUT EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
104 OUT EFI_HANDLE
*DeviceHandle
,
105 IN IMAGE_FILE_HANDLE
*ImageFileHandle
,
106 OUT UINT32
*AuthenticationStatus
112 Opens a file for (simple) reading. The simple read abstraction
113 will access the file either from a memory copy, from a file
114 system interface, or from the load file interface.
118 BootPolicy - Policy for Open Image File.
119 SourceBuffer - Pointer to the memory location containing copy
120 of the image to be loaded.
121 SourceSize - The size in bytes of SourceBuffer.
122 FilePath - The specific file path from which the image is loaded
123 DeviceHandle - Pointer to the return device handle.
124 ImageFileHandle - Pointer to the image file handle.
125 AuthenticationStatus - Pointer to a caller-allocated UINT32 in which the authentication status is returned.
129 A handle to access the file
140 IN OUT UINTN
*ReadSize
,
147 Read image file (specified by UserHandle) into user specified buffer with specified offset
152 UserHandle - Image file handle
154 Offset - Offset to the source file
156 ReadSize - For input, pointer of size to read;
157 For output, pointer of size actually read.
159 Buffer - Buffer to write into
163 EFI_SUCCESS - Successfully read the specified part of file into buffer.
171 IN IMAGE_FILE_HANDLE
*ImageFileHandle
177 A function out of date, should be removed.
181 ImageFileHandle - Handle of the file to close
191 // Image processing worker functions
194 CoreDevicePathToInterface (
195 IN EFI_GUID
*Protocol
,
196 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
,
197 OUT VOID
**Interface
,
198 OUT EFI_HANDLE
*Handle
204 Search a handle to a device on a specified device path that supports a specified protocol,
205 interface of that protocol on that handle is another output.
209 Protocol - The protocol to search for
211 FilePath - The specified device path
213 Interface - Interface of the protocol on the handle
215 Handle - The handle to the device on the specified device path that supports the protocol.
227 IN LOADED_IMAGE_PRIVATE_DATA
*Image
,
228 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL
,
229 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint OPTIONAL
,
236 Loads, relocates, and invokes a PE/COFF image
240 Pe32Handle - The handle of PE32 image
241 Image - PE image to be loaded
242 DstBuffer - The buffer to store the image
243 EntryPoint - A pointer to the entry point
244 Attribute - The bit mask of attributes to set for the load PE image
248 EFI_SUCCESS - The file was loaded, relocated, and invoked
250 EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
252 EFI_INVALID_PARAMETER - Invalid parameter
254 EFI_BUFFER_TOO_SMALL - Buffer for image is too small
259 LOADED_IMAGE_PRIVATE_DATA
*
260 CoreLoadedImageInfo (
261 IN EFI_HANDLE ImageHandle
267 TODO: Add function description
271 ImageHandle - TODO: add argument description
275 TODO: add return values
281 CoreUnloadAndCloseImage (
282 IN LOADED_IMAGE_PRIVATE_DATA
*Image
,
289 Unloads EFI image from memory.
294 FreePage - Free allocated pages
305 // Exported Image functions
311 IN EFI_PE32_IMAGE_PROTOCOL
*This
,
312 IN EFI_HANDLE ParentImageHandle
,
313 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
314 IN VOID
*SourceBuffer OPTIONAL
,
316 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL
,
317 OUT UINTN
*NumberOfPages OPTIONAL
,
318 OUT EFI_HANDLE
*ImageHandle
,
319 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint OPTIONAL
,
326 Loads an EFI image into memory and returns a handle to the image with extended parameters.
330 ParentImageHandle - The caller's image handle.
331 FilePath - The specific file path from which the image is loaded.
332 SourceBuffer - If not NULL, a pointer to the memory location containing a copy of
333 the image to be loaded.
334 SourceSize - The size in bytes of SourceBuffer.
335 DstBuffer - The buffer to store the image.
336 NumberOfPages - For input, specifies the space size of the image by caller if not NULL.
337 For output, specifies the actual space size needed.
338 ImageHandle - Image handle for output.
339 EntryPoint - Image entry point for output.
340 Attribute - The bit mask of attributes to set for the load PE image.
344 EFI_SUCCESS - The image was loaded into memory.
345 EFI_NOT_FOUND - The FilePath was not found.
346 EFI_INVALID_PARAMETER - One of the parameters has an invalid value.
347 EFI_UNSUPPORTED - The image type is not supported, or the device path cannot be
348 parsed to locate the proper protocol for loading the file.
349 EFI_OUT_OF_RESOURCES - Image was not loaded due to insufficient resources.
356 IN EFI_PE32_IMAGE_PROTOCOL
*This
,
357 IN EFI_HANDLE ImageHandle
363 Unload the specified image.
367 This - Indicates the calling context.
369 ImageHandle - The specified image handle.
373 EFI_INVALID_PARAMETER - Image handle is NULL.
375 EFI_UNSUPPORTED - Attempt to unload an unsupported image.
377 EFI_SUCCESS - Image successfully unloaded.