]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Image.h
Don't align image address for TeImage, because TeImage section alignment is undefined.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Image.h
1 /** @file
2 Data structure and functions to load and unload PeImage.
3
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15
16 #ifndef _IMAGE_H_
17 #define _IMAGE_H_
18
19
20
21 #define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','d','r','i')
22
23 typedef struct {
24 UINTN Signature;
25 EFI_HANDLE Handle; // Image handle
26 UINTN Type; // Image type
27
28 BOOLEAN Started; // If entrypoint has been called
29
30 EFI_IMAGE_ENTRY_POINT EntryPoint; // The image's entry point
31 EFI_LOADED_IMAGE_PROTOCOL Info; // loaded image protocol
32
33 EFI_PHYSICAL_ADDRESS ImageBasePage; // Location in memory
34 UINTN NumberOfPages; // Number of pages
35
36 CHAR8 *FixupData; // Original fixup data
37
38 EFI_TPL Tpl; // Tpl of started image
39 EFI_STATUS Status; // Status returned by started image
40
41 UINTN ExitDataSize; // Size of ExitData from started image
42 VOID *ExitData; // Pointer to exit data from started image
43 VOID *JumpBuffer; // Pointer to pool allocation for context save/retore
44 BASE_LIBRARY_JUMP_BUFFER *JumpContext; // Pointer to buffer for context save/retore
45 UINT16 Machine; // Machine type from PE image
46
47 EFI_EBC_PROTOCOL *Ebc; // EBC Protocol pointer
48
49 EFI_RUNTIME_IMAGE_ENTRY *RuntimeData; // Runtime image list
50
51 EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath; // Pointer to Loaded Image Device Path Protocl
52
53 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; // PeCoffLoader ImageContext
54
55 } LOADED_IMAGE_PRIVATE_DATA;
56
57 #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
58 CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)
59
60
61
62 #define LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','p','e','i')
63
64 typedef struct {
65 UINTN Signature;
66 EFI_HANDLE Handle; // Image handle
67 EFI_PE32_IMAGE_PROTOCOL Pe32Image;
68 } LOAD_PE32_IMAGE_PRIVATE_DATA;
69
70 #define LOAD_PE32_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
71 CR(a, LOAD_PE32_IMAGE_PRIVATE_DATA, Pe32Image, LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE)
72
73
74
75 //
76 // Private Data Types
77 //
78 #define IMAGE_FILE_HANDLE_SIGNATURE EFI_SIGNATURE_32('i','m','g','f')
79 typedef struct {
80 UINTN Signature;
81 BOOLEAN FreeBuffer;
82 VOID *Source;
83 UINTN SourceSize;
84 } IMAGE_FILE_HANDLE;
85
86
87 //
88 // Abstractions for reading image contents
89 //
90
91
92 /**
93 Opens a file for (simple) reading. The simple read abstraction
94 will access the file either from a memory copy, from a file
95 system interface, or from the load file interface.
96
97 @param BootPolicy Policy for Open Image File.
98 @param SourceBuffer Pointer to the memory location containing copy
99 of the image to be loaded.
100 @param SourceSize The size in bytes of SourceBuffer.
101 @param FilePath The specific file path from which the image is
102 loaded
103 @param DeviceHandle Pointer to the return device handle.
104 @param ImageFileHandle Pointer to the image file handle.
105 @param AuthenticationStatus Pointer to a caller-allocated UINT32 in which
106 the authentication status is returned.
107
108 @retval EFI_SUCCESS Image file successfully opened.
109 @retval EFI_LOAD_ERROR If the caller passed a copy of the file, and
110 SourceSize is 0.
111 @retval EFI_INVALID_PARAMETER File path is not valid.
112 @retval EFI_NOT_FOUND File not found.
113
114 **/
115 EFI_STATUS
116 CoreOpenImageFile (
117 IN BOOLEAN BootPolicy,
118 IN VOID *SourceBuffer OPTIONAL,
119 IN UINTN SourceSize,
120 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,
121 OUT EFI_HANDLE *DeviceHandle,
122 IN IMAGE_FILE_HANDLE *ImageFileHandle,
123 OUT UINT32 *AuthenticationStatus
124 );
125
126
127
128 /**
129 Read image file (specified by UserHandle) into user specified buffer with specified offset
130 and length.
131
132 @param UserHandle Image file handle
133 @param Offset Offset to the source file
134 @param ReadSize For input, pointer of size to read; For output,
135 pointer of size actually read.
136 @param Buffer Buffer to write into
137
138 @retval EFI_SUCCESS Successfully read the specified part of file
139 into buffer.
140
141 **/
142 EFI_STATUS
143 EFIAPI
144 CoreReadImageFile (
145 IN VOID *UserHandle,
146 IN UINTN Offset,
147 IN OUT UINTN *ReadSize,
148 OUT VOID *Buffer
149 );
150
151
152 /**
153 A function out of date, should be removed.
154
155 @param ImageFileHandle Handle of the file to close
156
157 **/
158 VOID
159 EFIAPI
160 CoreCloseImageFile (
161 IN IMAGE_FILE_HANDLE *ImageFileHandle
162 );
163
164
165
166 //
167 // Exported Image functions
168 //
169
170
171 /**
172 Loads an EFI image into memory and returns a handle to the image with extended parameters.
173
174 @param This Calling context
175 @param ParentImageHandle The caller's image handle.
176 @param FilePath The specific file path from which the image is
177 loaded.
178 @param SourceBuffer If not NULL, a pointer to the memory location
179 containing a copy of the image to be loaded.
180 @param SourceSize The size in bytes of SourceBuffer.
181 @param DstBuffer The buffer to store the image.
182 @param NumberOfPages For input, specifies the space size of the
183 image by caller if not NULL. For output,
184 specifies the actual space size needed.
185 @param ImageHandle Image handle for output.
186 @param EntryPoint Image entry point for output.
187 @param Attribute The bit mask of attributes to set for the load
188 PE image.
189
190 @retval EFI_SUCCESS The image was loaded into memory.
191 @retval EFI_NOT_FOUND The FilePath was not found.
192 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
193 @retval EFI_UNSUPPORTED The image type is not supported, or the device
194 path cannot be parsed to locate the proper
195 protocol for loading the file.
196 @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient
197 resources.
198
199 **/
200 EFI_STATUS
201 EFIAPI
202 CoreLoadImageEx (
203 IN EFI_PE32_IMAGE_PROTOCOL *This,
204 IN EFI_HANDLE ParentImageHandle,
205 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
206 IN VOID *SourceBuffer OPTIONAL,
207 IN UINTN SourceSize,
208 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
209 OUT UINTN *NumberOfPages OPTIONAL,
210 OUT EFI_HANDLE *ImageHandle,
211 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
212 IN UINT32 Attribute
213 );
214
215
216 /**
217 Unload the specified image.
218
219 @param This Indicates the calling context.
220 @param ImageHandle The specified image handle.
221
222 @retval EFI_INVALID_PARAMETER Image handle is NULL.
223 @retval EFI_UNSUPPORTED Attempt to unload an unsupported image.
224 @retval EFI_SUCCESS Image successfully unloaded.
225
226 **/
227 EFI_STATUS
228 EFIAPI
229 CoreUnloadImageEx (
230 IN EFI_PE32_IMAGE_PROTOCOL *This,
231 IN EFI_HANDLE ImageHandle
232 );
233 #endif