]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Core/Dxe/Image.h
Some library instance's PCD is missing in FPD file for a module, it break single...
[mirror_edk2.git] / EdkModulePkg / Core / Dxe / Image.h
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 Image.h\r
15\r
16Abstract:\r
17\r
18Revision History\r
19\r
20--*/\r
21\r
22\r
23#ifndef _IMAGE_H_\r
24#define _IMAGE_H_\r
25\r
26\r
27\r
28#define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','d','r','i')\r
29\r
30typedef struct {\r
31 UINTN Signature;\r
32 EFI_HANDLE Handle; // Image handle\r
33 UINTN Type; // Image type\r
34\r
35 BOOLEAN Started; // If entrypoint has been called\r
36\r
37 EFI_IMAGE_ENTRY_POINT EntryPoint; // The image's entry point\r
38 EFI_LOADED_IMAGE_PROTOCOL Info; // loaded image protocol\r
39\r
40 EFI_PHYSICAL_ADDRESS ImageBasePage; // Location in memory\r
41 UINTN NumberOfPages; // Number of pages\r
42\r
43 CHAR8 *FixupData; // Original fixup data\r
44\r
45 EFI_TPL Tpl; // Tpl of started image\r
46 EFI_STATUS Status; // Status returned by started image\r
47\r
48 UINTN ExitDataSize; // Size of ExitData from started image\r
49 VOID *ExitData; // Pointer to exit data from started image\r
50 BASE_LIBRARY_JUMP_BUFFER *JumpContext; // Pointer to buffer for context save/retore\r
51 UINT16 Machine; // Machine type from PE image\r
52\r
53 EFI_EBC_PROTOCOL *Ebc; // EBC Protocol pointer\r
54\r
55 BOOLEAN RuntimeFixupValid; // True if RT image needs fixup\r
56 VOID *RuntimeFixup; // Copy of fixup data;\r
57 LIST_ENTRY Link; // List of RT LOADED_IMAGE_PRIVATE_DATA\r
58\r
59 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; // PeCoffLoader ImageContext\r
60\r
61} LOADED_IMAGE_PRIVATE_DATA;\r
62\r
63#define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \\r
64 CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)\r
65\r
66\r
67\r
68#define LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32('l','p','e','i')\r
69\r
70typedef struct {\r
71 UINTN Signature;\r
72 EFI_HANDLE Handle; // Image handle\r
73 EFI_PE32_IMAGE_PROTOCOL Pe32Image;\r
74} LOAD_PE32_IMAGE_PRIVATE_DATA;\r
75\r
76#define LOAD_PE32_IMAGE_PRIVATE_DATA_FROM_THIS(a) \\r
77 CR(a, LOAD_PE32_IMAGE_PRIVATE_DATA, Pe32Image, LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE)\r
78\r
79\r
80\r
81//\r
82// Private Data Types\r
83//\r
84#define IMAGE_FILE_HANDLE_SIGNATURE EFI_SIGNATURE_32('i','m','g','f')\r
85typedef struct {\r
86 UINTN Signature;\r
87 BOOLEAN FreeBuffer;\r
88 VOID *Source;\r
89 UINTN SourceSize;\r
90} IMAGE_FILE_HANDLE;\r
91\r
92\r
93//\r
94// Abstractions for reading image contents\r
95//\r
96\r
97EFI_STATUS\r
98CoreOpenImageFile (\r
99 IN BOOLEAN BootPolicy,\r
100 IN VOID *SourceBuffer OPTIONAL,\r
101 IN UINTN SourceSize,\r
102 IN OUT EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
103 OUT EFI_HANDLE *DeviceHandle,\r
104 IN IMAGE_FILE_HANDLE *ImageFileHandle,\r
105 OUT UINT32 *AuthenticationStatus\r
106 )\r
107/*++\r
108\r
109Routine Description:\r
110\r
111 Opens a file for (simple) reading. The simple read abstraction\r
112 will access the file either from a memory copy, from a file\r
113 system interface, or from the load file interface.\r
114\r
115Arguments:\r
116\r
117 BootPolicy - Policy for Open Image File.\r
118 SourceBuffer - Pointer to the memory location containing copy\r
119 of the image to be loaded.\r
120 SourceSize - The size in bytes of SourceBuffer.\r
121 FilePath - The specific file path from which the image is loaded\r
122 DeviceHandle - Pointer to the return device handle.\r
123 ImageFileHandle - Pointer to the image file handle.\r
124 AuthenticationStatus - Pointer to a caller-allocated UINT32 in which the authentication status is returned.\r
125\r
126Returns:\r
127\r
128 A handle to access the file\r
129\r
130--*/\r
131;\r
132\r
133\r
134EFI_STATUS\r
135EFIAPI\r
136CoreReadImageFile (\r
137 IN VOID *UserHandle,\r
138 IN UINTN Offset,\r
139 IN OUT UINTN *ReadSize,\r
140 OUT VOID *Buffer\r
141 )\r
142/*++\r
143\r
144Routine Description:\r
145\r
146 Read image file (specified by UserHandle) into user specified buffer with specified offset\r
147 and length.\r
148\r
149Arguments:\r
150\r
151 UserHandle - Image file handle\r
152\r
153 Offset - Offset to the source file\r
154\r
155 ReadSize - For input, pointer of size to read;\r
156 For output, pointer of size actually read.\r
157\r
158 Buffer - Buffer to write into\r
159\r
160Returns:\r
161\r
162 EFI_SUCCESS - Successfully read the specified part of file into buffer.\r
163\r
164--*/\r
165;\r
166\r
167VOID\r
168EFIAPI\r
169CoreCloseImageFile (\r
170 IN IMAGE_FILE_HANDLE *ImageFileHandle\r
171 )\r
172/*++\r
173\r
174Routine Description:\r
175\r
176 A function out of date, should be removed.\r
177\r
178Arguments:\r
179\r
180 ImageFileHandle - Handle of the file to close\r
181\r
182Returns:\r
183\r
184 None\r
185\r
186--*/\r
187;\r
188\r
189//\r
190// Image processing worker functions\r
191//\r
192EFI_STATUS\r
193CoreDevicePathToInterface (\r
194 IN EFI_GUID *Protocol,\r
195 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
196 OUT VOID **Interface,\r
197 OUT EFI_HANDLE *Handle\r
198 )\r
199/*++\r
200\r
201Routine Description:\r
202\r
203 Search a handle to a device on a specified device path that supports a specified protocol,\r
204 interface of that protocol on that handle is another output.\r
205\r
206Arguments:\r
207\r
208 Protocol - The protocol to search for\r
209\r
210 FilePath - The specified device path\r
211\r
212 Interface - Interface of the protocol on the handle\r
213\r
214 Handle - The handle to the device on the specified device path that supports the protocol.\r
215\r
216Returns:\r
217\r
218 Status code.\r
219\r
220--*/\r
221;\r
222\r
223EFI_STATUS\r
224CoreLoadPeImage (\r
225 IN VOID *Pe32Handle,\r
226 IN LOADED_IMAGE_PRIVATE_DATA *Image,\r
227 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,\r
228 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,\r
229 IN UINT32 Attribute\r
230 )\r
231/*++\r
232\r
233Routine Description:\r
234\r
235 Loads, relocates, and invokes a PE/COFF image\r
236\r
237Arguments:\r
238\r
239 Pe32Handle - The handle of PE32 image\r
240 Image - PE image to be loaded\r
241 DstBuffer - The buffer to store the image\r
242 EntryPoint - A pointer to the entry point\r
243 Attribute - The bit mask of attributes to set for the load PE image\r
244\r
245Returns:\r
246\r
247 EFI_SUCCESS - The file was loaded, relocated, and invoked\r
248\r
249 EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file\r
250\r
251 EFI_INVALID_PARAMETER - Invalid parameter\r
252\r
253 EFI_BUFFER_TOO_SMALL - Buffer for image is too small\r
254\r
255--*/\r
256;\r
257\r
258LOADED_IMAGE_PRIVATE_DATA *\r
259CoreLoadedImageInfo (\r
260 IN EFI_HANDLE ImageHandle\r
261 )\r
262/*++\r
263\r
264Routine Description:\r
265\r
266 TODO: Add function description\r
267\r
268Arguments:\r
269\r
270 ImageHandle - TODO: add argument description\r
271\r
272Returns:\r
273\r
274 TODO: add return values\r
275\r
276--*/\r
277;\r
278\r
279VOID\r
280CoreUnloadAndCloseImage (\r
281 IN LOADED_IMAGE_PRIVATE_DATA *Image,\r
282 IN BOOLEAN FreePage\r
283 )\r
284/*++\r
285\r
286Routine Description:\r
287\r
288 Unloads EFI image from memory.\r
289\r
290Arguments:\r
291\r
292 Image - EFI image\r
293 FreePage - Free allocated pages\r
294\r
295Returns:\r
296\r
297 None\r
298\r
299--*/\r
300;\r
301\r
302\r
303//\r
304// Exported Image functions\r
305//\r
306\r
307EFI_STATUS\r
308EFIAPI\r
309CoreLoadImageEx (\r
310 IN EFI_PE32_IMAGE_PROTOCOL *This,\r
311 IN EFI_HANDLE ParentImageHandle,\r
312 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
313 IN VOID *SourceBuffer OPTIONAL,\r
314 IN UINTN SourceSize,\r
315 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,\r
316 OUT UINTN *NumberOfPages OPTIONAL,\r
317 OUT EFI_HANDLE *ImageHandle,\r
318 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,\r
319 IN UINT32 Attribute\r
320 )\r
321/*++\r
322\r
323Routine Description:\r
324\r
325 Loads an EFI image into memory and returns a handle to the image with extended parameters.\r
326\r
327Arguments:\r
328\r
329 ParentImageHandle - The caller's image handle.\r
330 FilePath - The specific file path from which the image is loaded.\r
331 SourceBuffer - If not NULL, a pointer to the memory location containing a copy of\r
332 the image to be loaded.\r
333 SourceSize - The size in bytes of SourceBuffer.\r
334 DstBuffer - The buffer to store the image.\r
335 NumberOfPages - For input, specifies the space size of the image by caller if not NULL.\r
336 For output, specifies the actual space size needed.\r
337 ImageHandle - Image handle for output.\r
338 EntryPoint - Image entry point for output.\r
339 Attribute - The bit mask of attributes to set for the load PE image.\r
340\r
341Returns:\r
342\r
343 EFI_SUCCESS - The image was loaded into memory.\r
344 EFI_NOT_FOUND - The FilePath was not found.\r
345 EFI_INVALID_PARAMETER - One of the parameters has an invalid value.\r
346 EFI_UNSUPPORTED - The image type is not supported, or the device path cannot be\r
347 parsed to locate the proper protocol for loading the file.\r
348 EFI_OUT_OF_RESOURCES - Image was not loaded due to insufficient resources.\r
349--*/\r
350;\r
351\r
352EFI_STATUS\r
353EFIAPI\r
354CoreUnloadImageEx (\r
355 IN EFI_PE32_IMAGE_PROTOCOL *This,\r
356 IN EFI_HANDLE ImageHandle\r
357 )\r
358/*++\r
359\r
360Routine Description:\r
361\r
362 Unload the specified image.\r
363\r
364Arguments:\r
365\r
366 This - Indicates the calling context.\r
367\r
368 ImageHandle - The specified image handle.\r
369\r
370Returns:\r
371\r
372 EFI_INVALID_PARAMETER - Image handle is NULL.\r
373\r
374 EFI_UNSUPPORTED - Attempt to unload an unsupported image.\r
375\r
376 EFI_SUCCESS - Image successfully unloaded.\r
377\r
378--*/\r
379;\r
380#endif\r