]>
Commit | Line | Data |
---|---|---|
23c98c94 | 1 | /** @file\r |
504214c4 | 2 | Data structure and functions to load and unload PeImage.\r |
23c98c94 | 3 | \r |
b695e7ff | 4 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r |
cd5ebaa0 | 5 | This program and the accompanying materials\r |
28a00297 | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
504214c4 | 13 | **/\r |
28a00297 | 14 | \r |
15 | \r | |
16 | #ifndef _IMAGE_H_\r | |
17 | #define _IMAGE_H_\r | |
18 | \r | |
f3f2e05d | 19 | #define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE SIGNATURE_32('l','d','r','i')\r |
28a00297 | 20 | \r |
21 | typedef struct {\r | |
853adefc | 22 | UINTN Signature;\r |
23 | /// Image handle\r | |
24 | EFI_HANDLE Handle; \r | |
25 | /// Image type\r | |
26 | UINTN Type; \r | |
27 | /// If entrypoint has been called\r | |
28 | BOOLEAN Started; \r | |
29 | /// The image's entry point\r | |
30 | EFI_IMAGE_ENTRY_POINT EntryPoint; \r | |
31 | /// loaded image protocol\r | |
32 | EFI_LOADED_IMAGE_PROTOCOL Info; \r | |
33 | /// Location in memory\r | |
34 | EFI_PHYSICAL_ADDRESS ImageBasePage; \r | |
35 | /// Number of pages\r | |
36 | UINTN NumberOfPages; \r | |
37 | /// Original fixup data\r | |
38 | CHAR8 *FixupData; \r | |
39 | /// Tpl of started image\r | |
40 | EFI_TPL Tpl; \r | |
41 | /// Status returned by started image\r | |
42 | EFI_STATUS Status; \r | |
43 | /// Size of ExitData from started image\r | |
44 | UINTN ExitDataSize; \r | |
45 | /// Pointer to exit data from started image\r | |
46 | VOID *ExitData; \r | |
47 | /// Pointer to pool allocation for context save/retore\r | |
48 | VOID *JumpBuffer; \r | |
49 | /// Pointer to buffer for context save/retore\r | |
50 | BASE_LIBRARY_JUMP_BUFFER *JumpContext; \r | |
51 | /// Machine type from PE image\r | |
52 | UINT16 Machine; \r | |
53 | /// EBC Protocol pointer\r | |
54 | EFI_EBC_PROTOCOL *Ebc; \r | |
55 | /// Runtime image list\r | |
56 | EFI_RUNTIME_IMAGE_ENTRY *RuntimeData; \r | |
57 | /// Pointer to Loaded Image Device Path Protocl\r | |
58 | EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath; \r | |
59 | /// PeCoffLoader ImageContext\r | |
60 | PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; \r | |
28a00297 | 61 | \r |
62 | } LOADED_IMAGE_PRIVATE_DATA;\r | |
63 | \r | |
64 | #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \\r | |
65 | CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)\r | |
66 | \r | |
67 | \r | |
023c0fec | 68 | #define LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE SIGNATURE_32('l','p','e','i')\r |
69 | \r | |
70 | typedef struct {\r | |
853adefc | 71 | UINTN Signature;\r |
72 | /// Image handle\r | |
73 | EFI_HANDLE Handle; \r | |
74 | EFI_PE32_IMAGE_PROTOCOL Pe32Image;\r | |
023c0fec | 75 | } LOAD_PE32_IMAGE_PRIVATE_DATA;\r |
76 | \r | |
77 | #define LOAD_PE32_IMAGE_PRIVATE_DATA_FROM_THIS(a) \\r | |
78 | CR(a, LOAD_PE32_IMAGE_PRIVATE_DATA, Pe32Image, LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE)\r | |
79 | \r | |
80 | \r | |
28a00297 | 81 | //\r |
82 | // Private Data Types\r | |
83 | //\r | |
f3f2e05d | 84 | #define IMAGE_FILE_HANDLE_SIGNATURE SIGNATURE_32('i','m','g','f')\r |
28a00297 | 85 | typedef 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 | |
023c0fec | 92 | /**\r |
93 | Loads an EFI image into memory and returns a handle to the image with extended parameters.\r | |
94 | \r | |
95 | @param This Calling context\r | |
96 | @param ParentImageHandle The caller's image handle.\r | |
97 | @param FilePath The specific file path from which the image is\r | |
98 | loaded.\r | |
99 | @param SourceBuffer If not NULL, a pointer to the memory location\r | |
100 | containing a copy of the image to be loaded.\r | |
101 | @param SourceSize The size in bytes of SourceBuffer.\r | |
102 | @param DstBuffer The buffer to store the image.\r | |
103 | @param NumberOfPages For input, specifies the space size of the\r | |
104 | image by caller if not NULL. For output,\r | |
105 | specifies the actual space size needed.\r | |
106 | @param ImageHandle Image handle for output.\r | |
107 | @param EntryPoint Image entry point for output.\r | |
108 | @param Attribute The bit mask of attributes to set for the load\r | |
109 | PE image.\r | |
110 | \r | |
111 | @retval EFI_SUCCESS The image was loaded into memory.\r | |
112 | @retval EFI_NOT_FOUND The FilePath was not found.\r | |
113 | @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r | |
114 | @retval EFI_UNSUPPORTED The image type is not supported, or the device\r | |
115 | path cannot be parsed to locate the proper\r | |
116 | protocol for loading the file.\r | |
117 | @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient\r | |
118 | resources.\r | |
b695e7ff LG |
119 | @retval EFI_LOAD_ERROR Image was not loaded because the image format was corrupt or not\r |
120 | understood.\r | |
121 | @retval EFI_DEVICE_ERROR Image was not loaded because the device returned a read error.\r | |
122 | @retval EFI_ACCESS_DENIED Image was not loaded because the platform policy prohibits the \r | |
123 | image from being loaded. NULL is returned in *ImageHandle.\r | |
124 | @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was created with a \r | |
125 | valid EFI_LOADED_IMAGE_PROTOCOL. However, the current \r | |
126 | platform policy specifies that the image should not be started.\r | |
023c0fec | 127 | \r |
128 | **/\r | |
129 | EFI_STATUS\r | |
130 | EFIAPI\r | |
131 | CoreLoadImageEx (\r | |
132 | IN EFI_PE32_IMAGE_PROTOCOL *This,\r | |
133 | IN EFI_HANDLE ParentImageHandle,\r | |
134 | IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r | |
135 | IN VOID *SourceBuffer OPTIONAL,\r | |
136 | IN UINTN SourceSize,\r | |
137 | IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,\r | |
138 | OUT UINTN *NumberOfPages OPTIONAL,\r | |
139 | OUT EFI_HANDLE *ImageHandle,\r | |
140 | OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,\r | |
141 | IN UINT32 Attribute\r | |
142 | );\r | |
143 | \r | |
144 | \r | |
145 | /**\r | |
146 | Unload the specified image.\r | |
147 | \r | |
148 | @param This Indicates the calling context.\r | |
149 | @param ImageHandle The specified image handle.\r | |
162ed594 | 150 | \r |
023c0fec | 151 | @retval EFI_INVALID_PARAMETER Image handle is NULL.\r |
152 | @retval EFI_UNSUPPORTED Attempt to unload an unsupported image.\r | |
153 | @retval EFI_SUCCESS Image successfully unloaded.\r | |
154 | \r | |
155 | **/\r | |
156 | EFI_STATUS\r | |
157 | EFIAPI\r | |
158 | CoreUnloadImageEx (\r | |
159 | IN EFI_PE32_IMAGE_PROTOCOL *This,\r | |
160 | IN EFI_HANDLE ImageHandle\r | |
161 | );\r | |
28a00297 | 162 | #endif\r |