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 EFI_RUNTIME_IMAGE_ENTRY
*RuntimeData
; // Runtime image list
58 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
; // PeCoffLoader ImageContext
60 } LOADED_IMAGE_PRIVATE_DATA
;
62 #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
63 CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)
67 #define LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','p','e','i')
71 EFI_HANDLE Handle
; // Image handle
72 EFI_PE32_IMAGE_PROTOCOL Pe32Image
;
73 } LOAD_PE32_IMAGE_PRIVATE_DATA
;
75 #define LOAD_PE32_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
76 CR(a, LOAD_PE32_IMAGE_PRIVATE_DATA, Pe32Image, LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE)
83 #define IMAGE_FILE_HANDLE_SIGNATURE EFI_SIGNATURE_32('i','m','g','f')
93 // Abstractions for reading image contents
98 IN BOOLEAN BootPolicy
,
99 IN VOID
*SourceBuffer OPTIONAL
,
101 IN OUT EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
102 OUT EFI_HANDLE
*DeviceHandle
,
103 IN IMAGE_FILE_HANDLE
*ImageFileHandle
,
104 OUT UINT32
*AuthenticationStatus
110 Opens a file for (simple) reading. The simple read abstraction
111 will access the file either from a memory copy, from a file
112 system interface, or from the load file interface.
116 BootPolicy - Policy for Open Image File.
117 SourceBuffer - Pointer to the memory location containing copy
118 of the image to be loaded.
119 SourceSize - The size in bytes of SourceBuffer.
120 FilePath - The specific file path from which the image is loaded
121 DeviceHandle - Pointer to the return device handle.
122 ImageFileHandle - Pointer to the image file handle.
123 AuthenticationStatus - Pointer to a caller-allocated UINT32 in which the authentication status is returned.
127 A handle to access the file
138 IN OUT UINTN
*ReadSize
,
145 Read image file (specified by UserHandle) into user specified buffer with specified offset
150 UserHandle - Image file handle
152 Offset - Offset to the source file
154 ReadSize - For input, pointer of size to read;
155 For output, pointer of size actually read.
157 Buffer - Buffer to write into
161 EFI_SUCCESS - Successfully read the specified part of file into buffer.
169 IN IMAGE_FILE_HANDLE
*ImageFileHandle
175 A function out of date, should be removed.
179 ImageFileHandle - Handle of the file to close
189 // Image processing worker functions
192 CoreDevicePathToInterface (
193 IN EFI_GUID
*Protocol
,
194 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
,
195 OUT VOID
**Interface
,
196 OUT EFI_HANDLE
*Handle
202 Search a handle to a device on a specified device path that supports a specified protocol,
203 interface of that protocol on that handle is another output.
207 Protocol - The protocol to search for
209 FilePath - The specified device path
211 Interface - Interface of the protocol on the handle
213 Handle - The handle to the device on the specified device path that supports the protocol.
225 IN LOADED_IMAGE_PRIVATE_DATA
*Image
,
226 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL
,
227 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint OPTIONAL
,
234 Loads, relocates, and invokes a PE/COFF image
238 Pe32Handle - The handle of PE32 image
239 Image - PE image to be loaded
240 DstBuffer - The buffer to store the image
241 EntryPoint - A pointer to the entry point
242 Attribute - The bit mask of attributes to set for the load PE image
246 EFI_SUCCESS - The file was loaded, relocated, and invoked
248 EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
250 EFI_INVALID_PARAMETER - Invalid parameter
252 EFI_BUFFER_TOO_SMALL - Buffer for image is too small
257 LOADED_IMAGE_PRIVATE_DATA
*
258 CoreLoadedImageInfo (
259 IN EFI_HANDLE ImageHandle
265 TODO: Add function description
269 ImageHandle - TODO: add argument description
273 TODO: add return values
279 CoreUnloadAndCloseImage (
280 IN LOADED_IMAGE_PRIVATE_DATA
*Image
,
287 Unloads EFI image from memory.
292 FreePage - Free allocated pages
303 // Exported Image functions
309 IN EFI_PE32_IMAGE_PROTOCOL
*This
,
310 IN EFI_HANDLE ParentImageHandle
,
311 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
312 IN VOID
*SourceBuffer OPTIONAL
,
314 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL
,
315 OUT UINTN
*NumberOfPages OPTIONAL
,
316 OUT EFI_HANDLE
*ImageHandle
,
317 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint OPTIONAL
,
324 Loads an EFI image into memory and returns a handle to the image with extended parameters.
328 ParentImageHandle - The caller's image handle.
329 FilePath - The specific file path from which the image is loaded.
330 SourceBuffer - If not NULL, a pointer to the memory location containing a copy of
331 the image to be loaded.
332 SourceSize - The size in bytes of SourceBuffer.
333 DstBuffer - The buffer to store the image.
334 NumberOfPages - For input, specifies the space size of the image by caller if not NULL.
335 For output, specifies the actual space size needed.
336 ImageHandle - Image handle for output.
337 EntryPoint - Image entry point for output.
338 Attribute - The bit mask of attributes to set for the load PE image.
342 EFI_SUCCESS - The image was loaded into memory.
343 EFI_NOT_FOUND - The FilePath was not found.
344 EFI_INVALID_PARAMETER - One of the parameters has an invalid value.
345 EFI_UNSUPPORTED - The image type is not supported, or the device path cannot be
346 parsed to locate the proper protocol for loading the file.
347 EFI_OUT_OF_RESOURCES - Image was not loaded due to insufficient resources.
354 IN EFI_PE32_IMAGE_PROTOCOL
*This
,
355 IN EFI_HANDLE ImageHandle
361 Unload the specified image.
365 This - Indicates the calling context.
367 ImageHandle - The specified image handle.
371 EFI_INVALID_PARAMETER - Image handle is NULL.
373 EFI_UNSUPPORTED - Attempt to unload an unsupported image.
375 EFI_SUCCESS - Image successfully unloaded.