]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | Memory Only PE COFF loader\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation \r | |
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 | |
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 | |
13 | Module Name: PeCoffLib.h\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #ifndef __BASE_PE_COFF_LIB_H__\r | |
18 | #define __BASE_PE_COFF_LIB_H__\r | |
19 | \r | |
20 | //\r | |
21 | // Return status codes from the PE/COFF Loader services\r | |
22 | // BUGBUG: Find where used and see if can be replaced by RETURN_STATUS codes\r | |
23 | //\r | |
24 | #define IMAGE_ERROR_SUCCESS 0\r | |
25 | #define IMAGE_ERROR_IMAGE_READ 1 \r | |
26 | #define IMAGE_ERROR_INVALID_PE_HEADER_SIGNATURE 2\r | |
27 | #define IMAGE_ERROR_INVALID_MACHINE_TYPE 3\r | |
28 | #define IMAGE_ERROR_INVALID_SUBSYSTEM 4\r | |
29 | #define IMAGE_ERROR_INVALID_IMAGE_ADDRESS 5\r | |
30 | #define IMAGE_ERROR_INVALID_IMAGE_SIZE 6\r | |
31 | #define IMAGE_ERROR_INVALID_SECTION_ALIGNMENT 7\r | |
32 | #define IMAGE_ERROR_SECTION_NOT_LOADED 8\r | |
33 | #define IMAGE_ERROR_FAILED_RELOCATION 9\r | |
34 | #define IMAGE_ERROR_FAILED_ICACHE_FLUSH 10\r | |
35 | \r | |
36 | \r | |
37 | //\r | |
38 | // PE/COFF Loader Read Function passed in by caller\r | |
39 | //\r | |
40 | typedef\r | |
41 | RETURN_STATUS\r | |
42 | (EFIAPI *PE_COFF_LOADER_READ_FILE) (\r | |
43 | IN VOID *FileHandle,\r | |
44 | IN UINTN FileOffset,\r | |
45 | IN OUT UINTN *ReadSize,\r | |
46 | OUT VOID *Buffer\r | |
47 | );\r | |
48 | \r | |
49 | //\r | |
50 | // Context structure used while PE/COFF image is being loaded and relocated\r | |
51 | //\r | |
52 | typedef struct {\r | |
53 | PHYSICAL_ADDRESS ImageAddress;\r | |
54 | UINT64 ImageSize;\r | |
55 | PHYSICAL_ADDRESS DestinationAddress;\r | |
56 | PHYSICAL_ADDRESS EntryPoint;\r | |
57 | PE_COFF_LOADER_READ_FILE ImageRead;\r | |
58 | VOID *Handle;\r | |
59 | VOID *FixupData;\r | |
60 | UINT32 SectionAlignment;\r | |
61 | UINT32 PeCoffHeaderOffset;\r | |
62 | UINT32 DebugDirectoryEntryRva;\r | |
63 | VOID *CodeView;\r | |
64 | CHAR8 *PdbPointer;\r | |
65 | UINTN SizeOfHeaders;\r | |
66 | UINT32 ImageCodeMemoryType;\r | |
67 | UINT32 ImageDataMemoryType;\r | |
68 | UINT32 ImageError;\r | |
69 | UINTN FixupDataSize;\r | |
70 | UINT16 Machine;\r | |
71 | UINT16 ImageType;\r | |
72 | BOOLEAN RelocationsStripped;\r | |
73 | BOOLEAN IsTeImage;\r | |
74 | } PE_COFF_LOADER_IMAGE_CONTEXT;\r | |
75 | \r | |
76 | \r | |
77 | /**\r | |
78 | Retrieves information on a PE/COFF image\r | |
79 | \r | |
80 | @param ImageContext The context of the image being loaded\r | |
81 | \r | |
82 | @retval EFI_SUCCESS The information on the PE/COFF image was collected.\r | |
83 | @retval EFI_INVALID_PARAMETER ImageContext is NULL.\r | |
84 | @retval EFI_UNSUPPORTED The PE/COFF image is not supported.\r | |
85 | @retval Otherwise The error status from reading the PE/COFF image using the\r | |
86 | ImageContext->ImageRead() function\r | |
87 | \r | |
88 | **/\r | |
89 | RETURN_STATUS\r | |
90 | EFIAPI\r | |
91 | PeCoffLoaderGetImageInfo (\r | |
92 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
93 | )\r | |
94 | ;\r | |
95 | \r | |
96 | /**\r | |
97 | Relocates a PE/COFF image in memory\r | |
98 | \r | |
99 | @param ImageContext Contains information on the loaded image to relocate\r | |
100 | \r | |
101 | @retval EFI_SUCCESS if the PE/COFF image was relocated\r | |
102 | @retval EFI_LOAD_ERROR if the image is not a valid PE/COFF image\r | |
103 | @retval EFI_UNSUPPORTED not support\r | |
104 | \r | |
105 | **/\r | |
106 | RETURN_STATUS\r | |
107 | EFIAPI\r | |
108 | PeCoffLoaderRelocateImage (\r | |
109 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
110 | )\r | |
111 | ;\r | |
112 | \r | |
113 | /**\r | |
114 | Loads a PE/COFF image into memory\r | |
115 | \r | |
116 | @param ImageContext Contains information on image to load into memory\r | |
117 | \r | |
118 | @retval EFI_SUCCESS if the PE/COFF image was loaded\r | |
119 | @retval EFI_BUFFER_TOO_SMALL if the caller did not provide a large enough buffer\r | |
120 | @retval EFI_LOAD_ERROR if the image is a runtime driver with no relocations\r | |
121 | @retval EFI_INVALID_PARAMETER if the image address is invalid\r | |
122 | \r | |
123 | **/\r | |
124 | RETURN_STATUS\r | |
125 | EFIAPI\r | |
126 | PeCoffLoaderLoadImage (\r | |
127 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
128 | )\r | |
129 | ;\r | |
130 | \r | |
131 | #endif\r |