]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2ce31132 | 2 | Memory Only PE COFF loader. \r |
878ddf1f | 3 | \r |
ddc9ec37 | 4 | Copyright (c) 2006 - 2007, Intel Corporation \r |
24e25d11 | 5 | All rights reserved. This program and the accompanying materials \r |
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 | |
878ddf1f | 9 | \r |
24e25d11 | 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 | |
878ddf1f | 12 | \r |
24e25d11 | 13 | Module Name: PeCoffLib.h\r |
878ddf1f | 14 | \r |
15 | **/\r | |
16 | \r | |
17 | #ifndef __BASE_PE_COFF_LIB_H__\r | |
18 | #define __BASE_PE_COFF_LIB_H__\r | |
19 | \r | |
ddc9ec37 | 20 | #include <Common/PeCoffLoaderImageContext.h>\r |
21 | \r | |
878ddf1f | 22 | //\r |
23 | // Return status codes from the PE/COFF Loader services\r | |
24 | // BUGBUG: Find where used and see if can be replaced by RETURN_STATUS codes\r | |
25 | //\r | |
26 | #define IMAGE_ERROR_SUCCESS 0\r | |
27 | #define IMAGE_ERROR_IMAGE_READ 1 \r | |
28 | #define IMAGE_ERROR_INVALID_PE_HEADER_SIGNATURE 2\r | |
29 | #define IMAGE_ERROR_INVALID_MACHINE_TYPE 3\r | |
30 | #define IMAGE_ERROR_INVALID_SUBSYSTEM 4\r | |
31 | #define IMAGE_ERROR_INVALID_IMAGE_ADDRESS 5\r | |
32 | #define IMAGE_ERROR_INVALID_IMAGE_SIZE 6\r | |
33 | #define IMAGE_ERROR_INVALID_SECTION_ALIGNMENT 7\r | |
34 | #define IMAGE_ERROR_SECTION_NOT_LOADED 8\r | |
35 | #define IMAGE_ERROR_FAILED_RELOCATION 9\r | |
36 | #define IMAGE_ERROR_FAILED_ICACHE_FLUSH 10\r | |
37 | \r | |
38 | \r | |
878ddf1f | 39 | /**\r |
4ba61e5e | 40 | Retrieves information about a PE/COFF image.\r |
878ddf1f | 41 | \r |
4ba61e5e | 42 | Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r |
43 | PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r | |
44 | fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r | |
45 | If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r | |
46 | a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while\r | |
47 | computing the fields of ImageContext, then the error status is returned in the ImageError field of\r | |
48 | ImageContext. \r | |
878ddf1f | 49 | \r |
4ba61e5e | 50 | @param ImageContext Pointer to the image context structure that describes the PE/COFF\r |
51 | image that needs to be examined by this function.\r | |
52 | \r | |
53 | @retval RETURN_SUCCESS The information on the PE/COFF image was collected.\r | |
54 | @retval RETURN_INVALID_PARAMETER ImageContext is NULL.\r | |
55 | @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.\r | |
878ddf1f | 56 | \r |
57 | **/\r | |
58 | RETURN_STATUS\r | |
59 | EFIAPI\r | |
60 | PeCoffLoaderGetImageInfo (\r | |
61 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
62 | )\r | |
63 | ;\r | |
64 | \r | |
65 | /**\r | |
4ba61e5e | 66 | Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r |
67 | \r | |
68 | If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r | |
69 | ImageContext as the relocation base address. Otherwise, use the DestinationAddress field\r | |
70 | of ImageContext as the relocation base address. The caller must allocate the relocation\r | |
71 | fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function. \r | |
72 | If ImageContext is NULL, then ASSERT().\r | |
878ddf1f | 73 | \r |
4ba61e5e | 74 | @param ImageContext Pointer to the image context structure that describes the PE/COFF\r |
75 | image that is being relocated.\r | |
878ddf1f | 76 | \r |
4ba61e5e | 77 | @retval RETURN_SUCCESS The PE/COFF image was relocated.\r |
78 | Extended status information is in the ImageError field of ImageContext.\r | |
79 | @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.\r | |
80 | Extended status information is in the ImageError field of ImageContext.\r | |
81 | @retval RETURN_UNSUPPORTED A relocation record type is not supported.\r | |
82 | Extended status information is in the ImageError field of ImageContext.\r | |
878ddf1f | 83 | \r |
84 | **/\r | |
85 | RETURN_STATUS\r | |
86 | EFIAPI\r | |
87 | PeCoffLoaderRelocateImage (\r | |
88 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
89 | )\r | |
90 | ;\r | |
91 | \r | |
92 | /**\r | |
4ba61e5e | 93 | Loads a PE/COFF image into memory.\r |
94 | \r | |
95 | Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r | |
96 | specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate\r | |
97 | the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r | |
98 | The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r | |
99 | If ImageContext is NULL, then ASSERT().\r | |
100 | \r | |
101 | @param ImageContext Pointer to the image context structure that describes the PE/COFF\r | |
102 | image that is being loaded.\r | |
103 | \r | |
104 | @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by\r | |
105 | the ImageAddress and ImageSize fields of ImageContext.\r | |
106 | Extended status information is in the ImageError field of ImageContext.\r | |
107 | @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.\r | |
108 | Extended status information is in the ImageError field of ImageContext.\r | |
109 | @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.\r | |
110 | Extended status information is in the ImageError field of ImageContext.\r | |
111 | @retval RETURN_INVALID_PARAMETER The image address is invalid.\r | |
112 | Extended status information is in the ImageError field of ImageContext.\r | |
878ddf1f | 113 | \r |
114 | **/\r | |
115 | RETURN_STATUS\r | |
116 | EFIAPI\r | |
117 | PeCoffLoaderLoadImage (\r | |
118 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
119 | )\r | |
120 | ;\r | |
121 | \r | |
2ce31132 | 122 | \r |
123 | /**\r | |
124 | ImageRead function that operates on a memory buffer whos base is passed into\r | |
125 | FileHandle. \r | |
126 | \r | |
127 | @param FileHandle Ponter to baes of the input stream\r | |
128 | @param FileOffset Offset to the start of the buffer\r | |
129 | @param ReadSize Number of bytes to copy into the buffer\r | |
130 | @param Buffer Location to place results of read\r | |
131 | \r | |
132 | @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into \r | |
133 | the buffer.\r | |
134 | **/\r | |
135 | RETURN_STATUS\r | |
136 | EFIAPI\r | |
137 | PeCoffLoaderImageReadFromMemory (\r | |
138 | IN VOID *FileHandle,\r | |
139 | IN UINTN FileOffset,\r | |
140 | IN OUT UINTN *ReadSize,\r | |
141 | OUT VOID *Buffer\r | |
142 | )\r | |
143 | ;\r | |
144 | \r | |
145 | \r | |
146 | /**\r | |
147 | Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r | |
148 | runtime. \r | |
149 | \r | |
150 | PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r | |
151 | the fixups with a virtual mapping.\r | |
152 | \r | |
153 | \r | |
154 | @param ImageBase Base address of relocated image\r | |
155 | @param VirtImageBase Virtual mapping for ImageBase\r | |
156 | @param ImageSize Size of the image to relocate\r | |
157 | @param RelocationData Location to place results of read\r | |
158 | \r | |
159 | **/\r | |
160 | VOID\r | |
161 | EFIAPI\r | |
162 | PeCoffLoaderRelocateImageForRuntime (\r | |
163 | IN PHYSICAL_ADDRESS ImageBase,\r | |
164 | IN PHYSICAL_ADDRESS VirtImageBase,\r | |
165 | IN UINTN ImageSize,\r | |
166 | IN VOID *RelocationData\r | |
167 | )\r | |
168 | ;\r | |
169 | \r | |
170 | \r | |
878ddf1f | 171 | #endif\r |