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