3 Data structure and functions to load and unload PeImage.
5 Copyright (c) 2006 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','d','r','i')
26 EFI_HANDLE Handle
; // Image handle
27 UINTN Type
; // Image type
29 BOOLEAN Started
; // If entrypoint has been called
31 EFI_IMAGE_ENTRY_POINT EntryPoint
; // The image's entry point
32 EFI_LOADED_IMAGE_PROTOCOL Info
; // loaded image protocol
34 EFI_PHYSICAL_ADDRESS ImageBasePage
; // Location in memory
35 UINTN NumberOfPages
; // Number of pages
37 CHAR8
*FixupData
; // Original fixup data
39 EFI_TPL Tpl
; // Tpl of started image
40 EFI_STATUS Status
; // Status returned by started image
42 UINTN ExitDataSize
; // Size of ExitData from started image
43 VOID
*ExitData
; // Pointer to exit data from started image
44 VOID
*JumpBuffer
; // Pointer to pool allocation for context save/retore
45 BASE_LIBRARY_JUMP_BUFFER
*JumpContext
; // Pointer to buffer for context save/retore
46 UINT16 Machine
; // Machine type from PE image
48 EFI_EBC_PROTOCOL
*Ebc
; // EBC Protocol pointer
50 EFI_RUNTIME_IMAGE_ENTRY
*RuntimeData
; // Runtime image list
52 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
; // Pointer to Loaded Image Device Path Protocl
54 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
; // PeCoffLoader ImageContext
56 } LOADED_IMAGE_PRIVATE_DATA
;
58 #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
59 CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)
63 #define LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','p','e','i')
67 EFI_HANDLE Handle
; // Image handle
68 EFI_PE32_IMAGE_PROTOCOL Pe32Image
;
69 } LOAD_PE32_IMAGE_PRIVATE_DATA
;
71 #define LOAD_PE32_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
72 CR(a, LOAD_PE32_IMAGE_PRIVATE_DATA, Pe32Image, LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE)
79 #define IMAGE_FILE_HANDLE_SIGNATURE EFI_SIGNATURE_32('i','m','g','f')
89 // Abstractions for reading image contents
94 IN BOOLEAN BootPolicy
,
95 IN VOID
*SourceBuffer OPTIONAL
,
97 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
,
98 OUT EFI_HANDLE
*DeviceHandle
,
99 IN IMAGE_FILE_HANDLE
*ImageFileHandle
,
100 OUT UINT32
*AuthenticationStatus
106 Opens a file for (simple) reading. The simple read abstraction
107 will access the file either from a memory copy, from a file
108 system interface, or from the load file interface.
112 BootPolicy - Policy for Open Image File.
113 SourceBuffer - Pointer to the memory location containing copy
114 of the image to be loaded.
115 SourceSize - The size in bytes of SourceBuffer.
116 FilePath - The specific file path from which the image is loaded
117 DeviceHandle - Pointer to the return device handle.
118 ImageFileHandle - Pointer to the image file handle.
119 AuthenticationStatus - Pointer to a caller-allocated UINT32 in which the authentication status is returned.
123 A handle to access the file
134 IN OUT UINTN
*ReadSize
,
141 Read image file (specified by UserHandle) into user specified buffer with specified offset
146 UserHandle - Image file handle
148 Offset - Offset to the source file
150 ReadSize - For input, pointer of size to read;
151 For output, pointer of size actually read.
153 Buffer - Buffer to write into
157 EFI_SUCCESS - Successfully read the specified part of file into buffer.
165 IN IMAGE_FILE_HANDLE
*ImageFileHandle
171 A function out of date, should be removed.
175 ImageFileHandle - Handle of the file to close
185 // Image processing worker functions
188 CoreDevicePathToInterface (
189 IN EFI_GUID
*Protocol
,
190 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
,
191 OUT VOID
**Interface
,
192 OUT EFI_HANDLE
*Handle
198 Search a handle to a device on a specified device path that supports a specified protocol,
199 interface of that protocol on that handle is another output.
203 Protocol - The protocol to search for
205 FilePath - The specified device path
207 Interface - Interface of the protocol on the handle
209 Handle - The handle to the device on the specified device path that supports the protocol.
220 IN BOOLEAN BootPolicy
,
222 IN LOADED_IMAGE_PRIVATE_DATA
*Image
,
223 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL
,
224 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint OPTIONAL
,
231 Loads, relocates, and invokes a PE/COFF image
235 BootPolicy - Policy for Open Image File.
236 Pe32Handle - The handle of PE32 image
237 Image - PE image to be loaded
238 DstBuffer - The buffer to store the image
239 EntryPoint - A pointer to the entry point
240 Attribute - The bit mask of attributes to set for the load PE image
244 EFI_SUCCESS - The file was loaded, relocated, and invoked
246 EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
248 EFI_INVALID_PARAMETER - Invalid parameter
250 EFI_BUFFER_TOO_SMALL - Buffer for image is too small
255 LOADED_IMAGE_PRIVATE_DATA
*
256 CoreLoadedImageInfo (
257 IN EFI_HANDLE ImageHandle
263 TODO: Add function description
267 ImageHandle - TODO: add argument description
271 TODO: add return values
277 CoreUnloadAndCloseImage (
278 IN LOADED_IMAGE_PRIVATE_DATA
*Image
,
285 Unloads EFI image from memory.
290 FreePage - Free allocated pages
301 // Exported Image functions
307 IN EFI_PE32_IMAGE_PROTOCOL
*This
,
308 IN EFI_HANDLE ParentImageHandle
,
309 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
310 IN VOID
*SourceBuffer OPTIONAL
,
312 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL
,
313 OUT UINTN
*NumberOfPages OPTIONAL
,
314 OUT EFI_HANDLE
*ImageHandle
,
315 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint OPTIONAL
,
322 Loads an EFI image into memory and returns a handle to the image with extended parameters.
326 ParentImageHandle - The caller's image handle.
327 FilePath - The specific file path from which the image is loaded.
328 SourceBuffer - If not NULL, a pointer to the memory location containing a copy of
329 the image to be loaded.
330 SourceSize - The size in bytes of SourceBuffer.
331 DstBuffer - The buffer to store the image.
332 NumberOfPages - For input, specifies the space size of the image by caller if not NULL.
333 For output, specifies the actual space size needed.
334 ImageHandle - Image handle for output.
335 EntryPoint - Image entry point for output.
336 Attribute - The bit mask of attributes to set for the load PE image.
340 EFI_SUCCESS - The image was loaded into memory.
341 EFI_NOT_FOUND - The FilePath was not found.
342 EFI_INVALID_PARAMETER - One of the parameters has an invalid value.
343 EFI_UNSUPPORTED - The image type is not supported, or the device path cannot be
344 parsed to locate the proper protocol for loading the file.
345 EFI_OUT_OF_RESOURCES - Image was not loaded due to insufficient resources.
352 IN EFI_PE32_IMAGE_PROTOCOL
*This
,
353 IN EFI_HANDLE ImageHandle
359 Unload the specified image.
363 This - Indicates the calling context.
365 ImageHandle - The specified image handle.
369 EFI_INVALID_PARAMETER - Image handle is NULL.
371 EFI_UNSUPPORTED - Attempt to unload an unsupported image.
373 EFI_SUCCESS - Image successfully unloaded.