4 This PE/COFF loader supports loading any PE32 or PE32+ image type, but
5 only supports relocating IA32, X64, IPF, and EBC images.
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 Module Name: PeCoffLoader.c
22 Performs an Itanium-based specific relocation fixup and is a no-op on other
25 @param Reloc Pointer to the relocation record.
26 @param Fixup Pointer to the address to fix up.
27 @param FixupData Pointer to a buffer to log the fixups.
28 @param Adjust The offset to adjust the fixup.
34 PeCoffLoaderRelocateImageEx (
37 IN OUT CHAR8
**FixupData
,
43 Performs an Itanium-based specific re-relocation fixup and is a no-op on other
44 instruction sets. This is used to re-relocated the image into the EFI virtual
45 space for runtime calls.
47 @param Reloc Pointer to the relocation record.
48 @param Fixup Pointer to the address to fix up.
49 @param FixupData Pointer to a buffer to log the fixups.
50 @param Adjust The offset to adjust the fixup.
56 PeHotRelocateImageEx (
59 IN OUT CHAR8
**FixupData
,
65 Returns TRUE if the machine type of PE/COFF image is supported. Supported
66 does not mean the image can be executed it means the PE/COFF loader supports
67 loading and relocating of the image type. It's up to the caller to support
70 @param Machine Machine type from the PE Header.
72 @return TRUE if this PE/COFF loader can load the image
76 PeCoffLoaderImageFormatSupported (
83 Retrieves the PE or TE Header from a PE/COFF or TE image.
85 @param ImageContext The context of the image being loaded.
86 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.
88 @retval RETURN_SUCCESS The PE or TE Header is read.
89 @retval Other The error status from reading the PE/COFF or TE image using the ImageRead function.
93 PeCoffLoaderGetPeHeader (
94 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
95 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
99 EFI_IMAGE_DOS_HEADER DosHdr
;
103 // Read the DOS image header to check for it's existance
105 Size
= sizeof (EFI_IMAGE_DOS_HEADER
);
106 Status
= ImageContext
->ImageRead (
107 ImageContext
->Handle
,
112 if (RETURN_ERROR (Status
)) {
113 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
117 ImageContext
->PeCoffHeaderOffset
= 0;
118 if (DosHdr
.e_magic
== EFI_IMAGE_DOS_SIGNATURE
) {
120 // DOS image header is present, so read the PE header after the DOS image
123 ImageContext
->PeCoffHeaderOffset
= DosHdr
.e_lfanew
;
127 // Read the PE/COFF Header. For PE32 (32-bit) this will read in too much
128 // data, but that should not hurt anythine. Hdr.Pe32->OptionalHeader.Magic
129 // determins if this is a PE32 or PE32+ image. The magic is in the same
130 // location in both images.
132 Size
= sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION
);
133 Status
= ImageContext
->ImageRead (
134 ImageContext
->Handle
,
135 ImageContext
->PeCoffHeaderOffset
,
139 if (RETURN_ERROR (Status
)) {
140 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
145 // Use Signature to figure out if we understand the image format
147 if (Hdr
.Pe32
->Signature
== EFI_TE_IMAGE_HEADER_SIGNATURE
) {
148 ImageContext
->IsTeImage
= TRUE
;
149 ImageContext
->Machine
= Hdr
.Te
->Machine
;
150 ImageContext
->ImageType
= (UINT16
)(Hdr
.Te
->Subsystem
);
151 ImageContext
->ImageSize
= 0;
152 ImageContext
->SectionAlignment
= 4096;
153 ImageContext
->SizeOfHeaders
= sizeof (EFI_TE_IMAGE_HEADER
) + (UINTN
)Hdr
.Te
->BaseOfCode
- (UINTN
)Hdr
.Te
->StrippedSize
;
155 } else if (Hdr
.Pe32
->Signature
== EFI_IMAGE_NT_SIGNATURE
) {
156 ImageContext
->IsTeImage
= FALSE
;
157 ImageContext
->Machine
= Hdr
.Pe32
->FileHeader
.Machine
;
159 if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
163 ImageContext
->ImageType
= Hdr
.Pe32
->OptionalHeader
.Subsystem
;
164 ImageContext
->ImageSize
= (UINT64
)Hdr
.Pe32
->OptionalHeader
.SizeOfImage
;
165 ImageContext
->SectionAlignment
= Hdr
.Pe32
->OptionalHeader
.SectionAlignment
;
166 ImageContext
->SizeOfHeaders
= Hdr
.Pe32
->OptionalHeader
.SizeOfHeaders
;
168 } else if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
) {
172 ImageContext
->ImageType
= Hdr
.Pe32Plus
->OptionalHeader
.Subsystem
;
173 ImageContext
->ImageSize
= (UINT64
) Hdr
.Pe32Plus
->OptionalHeader
.SizeOfImage
;
174 ImageContext
->SectionAlignment
= Hdr
.Pe32Plus
->OptionalHeader
.SectionAlignment
;
175 ImageContext
->SizeOfHeaders
= Hdr
.Pe32Plus
->OptionalHeader
.SizeOfHeaders
;
177 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_MACHINE_TYPE
;
178 return RETURN_UNSUPPORTED
;
181 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_MACHINE_TYPE
;
182 return RETURN_UNSUPPORTED
;
185 if (!PeCoffLoaderImageFormatSupported (ImageContext
->Machine
)) {
187 // If the PE/COFF loader does not support the image type return
188 // unsupported. This library can suport lots of types of images
189 // this does not mean the user of this library can call the entry
190 // point of the image.
192 return RETURN_UNSUPPORTED
;
195 return RETURN_SUCCESS
;
200 Retrieves information about a PE/COFF image.
202 Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,
203 PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
204 fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
205 If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not
206 a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while
207 computing the fields of ImageContext, then the error status is returned in the ImageError field of
210 @param ImageContext Pointer to the image context structure that describes the PE/COFF
211 image that needs to be examined by this function.
213 @retval RETURN_SUCCESS The information on the PE/COFF image was collected.
214 @retval RETURN_INVALID_PARAMETER ImageContext is NULL.
215 @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.
220 PeCoffLoaderGetImageInfo (
221 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
224 RETURN_STATUS Status
;
225 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData
;
226 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
227 EFI_IMAGE_DATA_DIRECTORY
*DebugDirectoryEntry
;
230 UINTN DebugDirectoryEntryRva
;
231 UINTN DebugDirectoryEntryFileOffset
;
232 UINTN SectionHeaderOffset
;
233 EFI_IMAGE_SECTION_HEADER SectionHeader
;
234 EFI_IMAGE_DEBUG_DIRECTORY_ENTRY DebugEntry
;
235 UINT32 NumberOfRvaAndSizes
;
237 if (NULL
== ImageContext
) {
238 return RETURN_INVALID_PARAMETER
;
243 ImageContext
->ImageError
= IMAGE_ERROR_SUCCESS
;
245 Hdr
.Union
= &HdrData
;
246 Status
= PeCoffLoaderGetPeHeader (ImageContext
, Hdr
);
247 if (RETURN_ERROR (Status
)) {
252 // Retrieve the base address of the image
254 if (!(ImageContext
->IsTeImage
)) {
255 if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
259 ImageContext
->ImageAddress
= Hdr
.Pe32
->OptionalHeader
.ImageBase
;
264 ImageContext
->ImageAddress
= Hdr
.Pe32Plus
->OptionalHeader
.ImageBase
;
267 ImageContext
->ImageAddress
= (PHYSICAL_ADDRESS
)(Hdr
.Te
->ImageBase
);
271 // Initialize the alternate destination address to 0 indicating that it
272 // should not be used.
274 ImageContext
->DestinationAddress
= 0;
277 // Initialize the codeview pointer.
279 ImageContext
->CodeView
= NULL
;
280 ImageContext
->PdbPointer
= NULL
;
283 // Three cases with regards to relocations:
284 // - Image has base relocs, RELOCS_STRIPPED==0 => image is relocatable
285 // - Image has no base relocs, RELOCS_STRIPPED==1 => Image is not relocatable
286 // - Image has no base relocs, RELOCS_STRIPPED==0 => Image is relocatable but
287 // has no base relocs to apply
288 // Obviously having base relocations with RELOCS_STRIPPED==1 is invalid.
290 // Look at the file header to determine if relocations have been stripped, and
291 // save this info in the image context for later use.
293 if ((!(ImageContext
->IsTeImage
)) && ((Hdr
.Pe32
->FileHeader
.Characteristics
& EFI_IMAGE_FILE_RELOCS_STRIPPED
) != 0)) {
294 ImageContext
->RelocationsStripped
= TRUE
;
296 ImageContext
->RelocationsStripped
= FALSE
;
299 if (!(ImageContext
->IsTeImage
)) {
300 if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
304 NumberOfRvaAndSizes
= Hdr
.Pe32
->OptionalHeader
.NumberOfRvaAndSizes
;
305 DebugDirectoryEntry
= (EFI_IMAGE_DATA_DIRECTORY
*)&(Hdr
.Pe32
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG
]);
310 NumberOfRvaAndSizes
= Hdr
.Pe32Plus
->OptionalHeader
.NumberOfRvaAndSizes
;
311 DebugDirectoryEntry
= (EFI_IMAGE_DATA_DIRECTORY
*)&(Hdr
.Pe32Plus
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG
]);
314 if (NumberOfRvaAndSizes
> EFI_IMAGE_DIRECTORY_ENTRY_DEBUG
) {
316 DebugDirectoryEntryRva
= DebugDirectoryEntry
->VirtualAddress
;
319 // Determine the file offset of the debug directory... This means we walk
320 // the sections to find which section contains the RVA of the debug
323 DebugDirectoryEntryFileOffset
= 0;
325 SectionHeaderOffset
= (UINTN
)(
326 ImageContext
->PeCoffHeaderOffset
+
328 sizeof (EFI_IMAGE_FILE_HEADER
) +
329 Hdr
.Pe32
->FileHeader
.SizeOfOptionalHeader
332 for (Index
= 0; Index
< Hdr
.Pe32
->FileHeader
.NumberOfSections
; Index
++) {
334 // Read section header from file
336 Size
= sizeof (EFI_IMAGE_SECTION_HEADER
);
337 Status
= ImageContext
->ImageRead (
338 ImageContext
->Handle
,
343 if (RETURN_ERROR (Status
)) {
344 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
348 if (DebugDirectoryEntryRva
>= SectionHeader
.VirtualAddress
&&
349 DebugDirectoryEntryRva
< SectionHeader
.VirtualAddress
+ SectionHeader
.Misc
.VirtualSize
) {
351 DebugDirectoryEntryFileOffset
= DebugDirectoryEntryRva
- SectionHeader
.VirtualAddress
+ SectionHeader
.PointerToRawData
;
355 SectionHeaderOffset
+= sizeof (EFI_IMAGE_SECTION_HEADER
);
358 if (DebugDirectoryEntryFileOffset
!= 0) {
359 for (Index
= 0; Index
< DebugDirectoryEntry
->Size
; Index
++) {
361 // Read next debug directory entry
363 Size
= sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
);
364 Status
= ImageContext
->ImageRead (
365 ImageContext
->Handle
,
366 DebugDirectoryEntryFileOffset
,
370 if (RETURN_ERROR (Status
)) {
371 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
375 if (DebugEntry
.Type
== EFI_IMAGE_DEBUG_TYPE_CODEVIEW
) {
376 ImageContext
->DebugDirectoryEntryRva
= (UINT32
) (DebugDirectoryEntryRva
+ Index
* sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
));
377 if (DebugEntry
.RVA
== 0 && DebugEntry
.FileOffset
!= 0) {
378 ImageContext
->ImageSize
+= DebugEntry
.SizeOfData
;
381 return RETURN_SUCCESS
;
388 DebugDirectoryEntry
= &Hdr
.Te
->DataDirectory
[1];
389 DebugDirectoryEntryRva
= DebugDirectoryEntry
->VirtualAddress
;
390 SectionHeaderOffset
= (UINTN
)(sizeof (EFI_TE_IMAGE_HEADER
));
392 DebugDirectoryEntryFileOffset
= 0;
394 for (Index
= 0; Index
< Hdr
.Te
->NumberOfSections
;) {
396 // Read section header from file
398 Size
= sizeof (EFI_IMAGE_SECTION_HEADER
);
399 Status
= ImageContext
->ImageRead (
400 ImageContext
->Handle
,
405 if (RETURN_ERROR (Status
)) {
406 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
410 if (DebugDirectoryEntryRva
>= SectionHeader
.VirtualAddress
&&
411 DebugDirectoryEntryRva
< SectionHeader
.VirtualAddress
+ SectionHeader
.Misc
.VirtualSize
) {
412 DebugDirectoryEntryFileOffset
= DebugDirectoryEntryRva
-
413 SectionHeader
.VirtualAddress
+
414 SectionHeader
.PointerToRawData
+
415 sizeof (EFI_TE_IMAGE_HEADER
) -
416 Hdr
.Te
->StrippedSize
;
419 // File offset of the debug directory was found, if this is not the last
420 // section, then skip to the last section for calculating the image size.
422 if (Index
< (UINTN
) Hdr
.Te
->NumberOfSections
- 1) {
423 SectionHeaderOffset
+= (Hdr
.Te
->NumberOfSections
- 1 - Index
) * sizeof (EFI_IMAGE_SECTION_HEADER
);
424 Index
= Hdr
.Te
->NumberOfSections
- 1;
430 // In Te image header there is not a field to describe the ImageSize.
431 // Actually, the ImageSize equals the RVA plus the VirtualSize of
432 // the last section mapped into memory (Must be rounded up to
433 // a mulitple of Section Alignment). Per the PE/COFF specification, the
434 // section headers in the Section Table must appear in order of the RVA
435 // values for the corresponding sections. So the ImageSize can be determined
436 // by the RVA and the VirtualSize of the last section header in the
439 if ((++Index
) == (UINTN
)Hdr
.Te
->NumberOfSections
) {
440 ImageContext
->ImageSize
= (SectionHeader
.VirtualAddress
+ SectionHeader
.Misc
.VirtualSize
+
441 ImageContext
->SectionAlignment
- 1) & ~(ImageContext
->SectionAlignment
- 1);
444 SectionHeaderOffset
+= sizeof (EFI_IMAGE_SECTION_HEADER
);
447 if (DebugDirectoryEntryFileOffset
!= 0) {
448 for (Index
= 0; Index
< DebugDirectoryEntry
->Size
; Index
++) {
450 // Read next debug directory entry
452 Size
= sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
);
453 Status
= ImageContext
->ImageRead (
454 ImageContext
->Handle
,
455 DebugDirectoryEntryFileOffset
,
459 if (RETURN_ERROR (Status
)) {
460 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
464 if (DebugEntry
.Type
== EFI_IMAGE_DEBUG_TYPE_CODEVIEW
) {
465 ImageContext
->DebugDirectoryEntryRva
= (UINT32
) (DebugDirectoryEntryRva
+ Index
* sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
));
466 return RETURN_SUCCESS
;
472 return RETURN_SUCCESS
;
477 Converts an image address to the loaded address.
479 @param ImageContext The context of the image being loaded.
480 @param Address The address to be converted to the loaded address.
482 @return The converted address or NULL if the address can not be converted.
486 PeCoffLoaderImageAddress (
487 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
491 return (CHAR8
*)((UINTN
) ImageContext
->ImageAddress
+ Address
);
495 Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().
497 If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of
498 ImageContext as the relocation base address. Otherwise, use the DestinationAddress field
499 of ImageContext as the relocation base address. The caller must allocate the relocation
500 fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.
501 If ImageContext is NULL, then ASSERT().
503 @param ImageContext Pointer to the image context structure that describes the PE/COFF
504 image that is being relocated.
506 @retval RETURN_SUCCESS The PE/COFF image was relocated.
507 Extended status information is in the ImageError field of ImageContext.
508 @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.
509 Extended status information is in the ImageError field of ImageContext.
510 @retval RETURN_UNSUPPORTED A relocation record type is not supported.
511 Extended status information is in the ImageError field of ImageContext.
516 PeCoffLoaderRelocateImage (
517 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
520 RETURN_STATUS Status
;
521 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
522 EFI_IMAGE_DATA_DIRECTORY
*RelocDir
;
524 EFI_IMAGE_BASE_RELOCATION
*RelocBase
;
525 EFI_IMAGE_BASE_RELOCATION
*RelocBaseEnd
;
534 PHYSICAL_ADDRESS BaseAddress
;
535 UINT32 NumberOfRvaAndSizes
;
537 ASSERT (ImageContext
!= NULL
);
542 ImageContext
->ImageError
= IMAGE_ERROR_SUCCESS
;
545 // If there are no relocation entries, then we are done
547 if (ImageContext
->RelocationsStripped
) {
548 return RETURN_SUCCESS
;
552 // If the destination address is not 0, use that rather than the
553 // image address as the relocation target.
555 if (ImageContext
->DestinationAddress
!= 0) {
556 BaseAddress
= ImageContext
->DestinationAddress
;
558 BaseAddress
= ImageContext
->ImageAddress
;
561 if (!(ImageContext
->IsTeImage
)) {
562 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)((UINTN
)ImageContext
->ImageAddress
+ ImageContext
->PeCoffHeaderOffset
);
563 if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
567 Adjust
= (UINT64
)BaseAddress
- Hdr
.Pe32
->OptionalHeader
.ImageBase
;
568 Hdr
.Pe32
->OptionalHeader
.ImageBase
= (UINT32
)BaseAddress
;
570 NumberOfRvaAndSizes
= Hdr
.Pe32
->OptionalHeader
.NumberOfRvaAndSizes
;
571 RelocDir
= &Hdr
.Pe32
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
];
576 Adjust
= (UINT64
) BaseAddress
- Hdr
.Pe32Plus
->OptionalHeader
.ImageBase
;
577 Hdr
.Pe32Plus
->OptionalHeader
.ImageBase
= (UINT64
)BaseAddress
;
579 NumberOfRvaAndSizes
= Hdr
.Pe32Plus
->OptionalHeader
.NumberOfRvaAndSizes
;
580 RelocDir
= &Hdr
.Pe32Plus
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
];
584 // Find the relocation block
585 // Per the PE/COFF spec, you can't assume that a given data directory
586 // is present in the image. You have to check the NumberOfRvaAndSizes in
587 // the optional header to verify a desired directory entry is there.
590 if (NumberOfRvaAndSizes
> EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
) {
591 RelocBase
= PeCoffLoaderImageAddress (ImageContext
, RelocDir
->VirtualAddress
);
592 RelocBaseEnd
= PeCoffLoaderImageAddress (
594 RelocDir
->VirtualAddress
+ RelocDir
->Size
- 1
598 // Set base and end to bypass processing below.
600 RelocBase
= RelocBaseEnd
= 0;
603 Hdr
.Te
= (EFI_TE_IMAGE_HEADER
*)(UINTN
)(ImageContext
->ImageAddress
);
604 Adjust
= (UINT64
) (BaseAddress
- Hdr
.Te
->ImageBase
);
605 Hdr
.Te
->ImageBase
= (UINT64
) (BaseAddress
);
608 // Find the relocation block
610 RelocDir
= &Hdr
.Te
->DataDirectory
[0];
611 RelocBase
= (EFI_IMAGE_BASE_RELOCATION
*)(UINTN
)(
612 ImageContext
->ImageAddress
+
613 RelocDir
->VirtualAddress
+
614 sizeof(EFI_TE_IMAGE_HEADER
) -
617 RelocBaseEnd
= (EFI_IMAGE_BASE_RELOCATION
*) ((UINTN
) RelocBase
+ (UINTN
) RelocDir
->Size
- 1);
621 // Run the relocation information and apply the fixups
623 FixupData
= ImageContext
->FixupData
;
624 while (RelocBase
< RelocBaseEnd
) {
626 Reloc
= (UINT16
*) ((CHAR8
*) RelocBase
+ sizeof (EFI_IMAGE_BASE_RELOCATION
));
627 RelocEnd
= (UINT16
*) ((CHAR8
*) RelocBase
+ RelocBase
->SizeOfBlock
);
628 if (!(ImageContext
->IsTeImage
)) {
629 FixupBase
= PeCoffLoaderImageAddress (ImageContext
, RelocBase
->VirtualAddress
);
631 FixupBase
= (CHAR8
*)(UINTN
)(ImageContext
->ImageAddress
+
632 RelocBase
->VirtualAddress
+
633 sizeof(EFI_TE_IMAGE_HEADER
) -
638 if ((CHAR8
*) RelocEnd
< (CHAR8
*) ((UINTN
) ImageContext
->ImageAddress
) ||
639 (CHAR8
*) RelocEnd
> (CHAR8
*)((UINTN
)ImageContext
->ImageAddress
+
640 (UINTN
)ImageContext
->ImageSize
)) {
641 ImageContext
->ImageError
= IMAGE_ERROR_FAILED_RELOCATION
;
642 return RETURN_LOAD_ERROR
;
646 // Run this relocation record
648 while (Reloc
< RelocEnd
) {
650 Fixup
= FixupBase
+ (*Reloc
& 0xFFF);
651 switch ((*Reloc
) >> 12) {
652 case EFI_IMAGE_REL_BASED_ABSOLUTE
:
655 case EFI_IMAGE_REL_BASED_HIGH
:
656 F16
= (UINT16
*) Fixup
;
657 *F16
= (UINT16
) ((*F16
<< 16) + (UINT16
) Adjust
);
658 if (FixupData
!= NULL
) {
659 *(UINT16
*) FixupData
= *F16
;
660 FixupData
= FixupData
+ sizeof (UINT16
);
664 case EFI_IMAGE_REL_BASED_LOW
:
665 F16
= (UINT16
*) Fixup
;
666 *F16
= (UINT16
) (*F16
+ (UINT16
) Adjust
);
667 if (FixupData
!= NULL
) {
668 *(UINT16
*) FixupData
= *F16
;
669 FixupData
= FixupData
+ sizeof (UINT16
);
673 case EFI_IMAGE_REL_BASED_HIGHLOW
:
674 F32
= (UINT32
*) Fixup
;
675 *F32
= *F32
+ (UINT32
) Adjust
;
676 if (FixupData
!= NULL
) {
677 FixupData
= ALIGN_POINTER (FixupData
, sizeof (UINT32
));
678 *(UINT32
*)FixupData
= *F32
;
679 FixupData
= FixupData
+ sizeof (UINT32
);
683 case EFI_IMAGE_REL_BASED_DIR64
:
684 F64
= (UINT64
*) Fixup
;
685 *F64
= *F64
+ (UINT64
) Adjust
;
686 if (FixupData
!= NULL
) {
687 FixupData
= ALIGN_POINTER (FixupData
, sizeof(UINT64
));
688 *(UINT64
*)(FixupData
) = *F64
;
689 FixupData
= FixupData
+ sizeof(UINT64
);
695 // The common code does not handle some of the stranger IPF relocations
696 // PeCoffLoaderRelocateImageEx () addes support for these complex fixups
697 // on IPF and is a No-Op on other archtiectures.
699 Status
= PeCoffLoaderRelocateImageEx (Reloc
, Fixup
, &FixupData
, Adjust
);
700 if (RETURN_ERROR (Status
)) {
701 ImageContext
->ImageError
= IMAGE_ERROR_FAILED_RELOCATION
;
707 // Next relocation record
715 RelocBase
= (EFI_IMAGE_BASE_RELOCATION
*) RelocEnd
;
718 return RETURN_SUCCESS
;
722 Loads a PE/COFF image into memory.
724 Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer
725 specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate
726 the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.
727 The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.
728 If ImageContext is NULL, then ASSERT().
730 @param ImageContext Pointer to the image context structure that describes the PE/COFF
731 image that is being loaded.
733 @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by
734 the ImageAddress and ImageSize fields of ImageContext.
735 Extended status information is in the ImageError field of ImageContext.
736 @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.
737 Extended status information is in the ImageError field of ImageContext.
738 @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.
739 Extended status information is in the ImageError field of ImageContext.
740 @retval RETURN_INVALID_PARAMETER The image address is invalid.
741 Extended status information is in the ImageError field of ImageContext.
746 PeCoffLoaderLoadImage (
747 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
750 RETURN_STATUS Status
;
751 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
752 PE_COFF_LOADER_IMAGE_CONTEXT CheckContext
;
753 EFI_IMAGE_SECTION_HEADER
*FirstSection
;
754 EFI_IMAGE_SECTION_HEADER
*Section
;
755 UINTN NumberOfSections
;
760 EFI_IMAGE_DATA_DIRECTORY
*DirectoryEntry
;
761 EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
*DebugEntry
;
763 UINT32 TempDebugEntryRva
;
764 UINT32 NumberOfRvaAndSizes
;
766 ASSERT (ImageContext
!= NULL
);
771 ImageContext
->ImageError
= IMAGE_ERROR_SUCCESS
;
774 // Copy the provided context info into our local version, get what we
775 // can from the original image, and then use that to make sure everything
778 CopyMem (&CheckContext
, ImageContext
, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT
));
780 Status
= PeCoffLoaderGetImageInfo (&CheckContext
);
781 if (RETURN_ERROR (Status
)) {
786 // Make sure there is enough allocated space for the image being loaded
788 if (ImageContext
->ImageSize
< CheckContext
.ImageSize
) {
789 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_IMAGE_SIZE
;
790 return RETURN_BUFFER_TOO_SMALL
;
792 if (ImageContext
->ImageAddress
== 0) {
794 // Image cannot be loaded into 0 address.
796 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_IMAGE_ADDRESS
;
797 return RETURN_INVALID_PARAMETER
;
800 // If there's no relocations, then make sure it's not a runtime driver,
801 // and that it's being loaded at the linked address.
803 if (CheckContext
.RelocationsStripped
) {
805 // If the image does not contain relocations and it is a runtime driver
806 // then return an error.
808 if (CheckContext
.ImageType
== EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
) {
809 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_SUBSYSTEM
;
810 return RETURN_LOAD_ERROR
;
813 // If the image does not contain relocations, and the requested load address
814 // is not the linked address, then return an error.
816 if (CheckContext
.ImageAddress
!= ImageContext
->ImageAddress
) {
817 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_IMAGE_ADDRESS
;
818 return RETURN_INVALID_PARAMETER
;
822 // Make sure the allocated space has the proper section alignment
824 if (!(ImageContext
->IsTeImage
)) {
825 if ((ImageContext
->ImageAddress
& (CheckContext
.SectionAlignment
- 1)) != 0) {
826 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_SECTION_ALIGNMENT
;
827 return RETURN_INVALID_PARAMETER
;
831 // Read the entire PE/COFF or TE header into memory
833 if (!(ImageContext
->IsTeImage
)) {
834 Status
= ImageContext
->ImageRead (
835 ImageContext
->Handle
,
837 &ImageContext
->SizeOfHeaders
,
838 (VOID
*) (UINTN
) ImageContext
->ImageAddress
841 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)((UINTN
)ImageContext
->ImageAddress
+ ImageContext
->PeCoffHeaderOffset
);
843 FirstSection
= (EFI_IMAGE_SECTION_HEADER
*) (
844 (UINTN
)ImageContext
->ImageAddress
+
845 ImageContext
->PeCoffHeaderOffset
+
847 sizeof(EFI_IMAGE_FILE_HEADER
) +
848 Hdr
.Pe32
->FileHeader
.SizeOfOptionalHeader
850 NumberOfSections
= (UINTN
) (Hdr
.Pe32
->FileHeader
.NumberOfSections
);
852 Status
= ImageContext
->ImageRead (
853 ImageContext
->Handle
,
855 &ImageContext
->SizeOfHeaders
,
856 (void *)(UINTN
)ImageContext
->ImageAddress
859 Hdr
.Te
= (EFI_TE_IMAGE_HEADER
*)(UINTN
)(ImageContext
->ImageAddress
);
861 FirstSection
= (EFI_IMAGE_SECTION_HEADER
*) (
862 (UINTN
)ImageContext
->ImageAddress
+
863 sizeof(EFI_TE_IMAGE_HEADER
)
865 NumberOfSections
= (UINTN
) (Hdr
.Te
->NumberOfSections
);
869 if (RETURN_ERROR (Status
)) {
870 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
871 return RETURN_LOAD_ERROR
;
875 // Load each section of the image
877 Section
= FirstSection
;
878 for (Index
= 0, MaxEnd
= NULL
; Index
< NumberOfSections
; Index
++) {
881 // Compute sections address
883 Base
= PeCoffLoaderImageAddress (ImageContext
, Section
->VirtualAddress
);
884 End
= PeCoffLoaderImageAddress (
886 Section
->VirtualAddress
+ Section
->Misc
.VirtualSize
- 1
888 if (ImageContext
->IsTeImage
) {
889 Base
= (CHAR8
*)((UINTN
) Base
+ sizeof (EFI_TE_IMAGE_HEADER
) - (UINTN
)Hdr
.Te
->StrippedSize
);
890 End
= (CHAR8
*)((UINTN
) End
+ sizeof (EFI_TE_IMAGE_HEADER
) - (UINTN
)Hdr
.Te
->StrippedSize
);
897 // If the base start or end address resolved to 0, then fail.
899 if ((Base
== NULL
) || (End
== NULL
)) {
900 ImageContext
->ImageError
= IMAGE_ERROR_SECTION_NOT_LOADED
;
901 return RETURN_LOAD_ERROR
;
907 Size
= (UINTN
) Section
->Misc
.VirtualSize
;
908 if ((Size
== 0) || (Size
> Section
->SizeOfRawData
)) {
909 Size
= (UINTN
) Section
->SizeOfRawData
;
912 if (Section
->SizeOfRawData
) {
913 if (!(ImageContext
->IsTeImage
)) {
914 Status
= ImageContext
->ImageRead (
915 ImageContext
->Handle
,
916 Section
->PointerToRawData
,
921 Status
= ImageContext
->ImageRead (
922 ImageContext
->Handle
,
923 Section
->PointerToRawData
+ sizeof (EFI_TE_IMAGE_HEADER
) - (UINTN
)Hdr
.Te
->StrippedSize
,
929 if (RETURN_ERROR (Status
)) {
930 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
936 // If raw size is less then virt size, zero fill the remaining
939 if (Size
< Section
->Misc
.VirtualSize
) {
940 ZeroMem (Base
+ Size
, Section
->Misc
.VirtualSize
- Size
);
950 // Get image's entry point
952 if (!(ImageContext
->IsTeImage
)) {
954 // Sizes of AddressOfEntryPoint are different so we need to do this safely
956 if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
960 ImageContext
->EntryPoint
= (PHYSICAL_ADDRESS
)(UINTN
)PeCoffLoaderImageAddress (
962 (UINTN
)Hdr
.Pe32
->OptionalHeader
.AddressOfEntryPoint
968 ImageContext
->EntryPoint
= (PHYSICAL_ADDRESS
)(UINTN
)PeCoffLoaderImageAddress (
970 (UINTN
)Hdr
.Pe32Plus
->OptionalHeader
.AddressOfEntryPoint
974 ImageContext
->EntryPoint
= (PHYSICAL_ADDRESS
) (
975 (UINTN
)ImageContext
->ImageAddress
+
976 (UINTN
)Hdr
.Te
->AddressOfEntryPoint
+
977 (UINTN
)sizeof(EFI_TE_IMAGE_HEADER
) -
978 (UINTN
)Hdr
.Te
->StrippedSize
983 // Determine the size of the fixup data
985 // Per the PE/COFF spec, you can't assume that a given data directory
986 // is present in the image. You have to check the NumberOfRvaAndSizes in
987 // the optional header to verify a desired directory entry is there.
989 if (!(ImageContext
->IsTeImage
)) {
990 if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
994 NumberOfRvaAndSizes
= Hdr
.Pe32
->OptionalHeader
.NumberOfRvaAndSizes
;
995 DirectoryEntry
= (EFI_IMAGE_DATA_DIRECTORY
*)&Hdr
.Pe32
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
];
1000 NumberOfRvaAndSizes
= Hdr
.Pe32Plus
->OptionalHeader
.NumberOfRvaAndSizes
;
1001 DirectoryEntry
= (EFI_IMAGE_DATA_DIRECTORY
*)&Hdr
.Pe32Plus
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
];
1004 if (NumberOfRvaAndSizes
> EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
) {
1005 ImageContext
->FixupDataSize
= DirectoryEntry
->Size
/ sizeof (UINT16
) * sizeof (UINTN
);
1007 ImageContext
->FixupDataSize
= 0;
1010 DirectoryEntry
= &Hdr
.Te
->DataDirectory
[0];
1011 ImageContext
->FixupDataSize
= DirectoryEntry
->Size
/ sizeof (UINT16
) * sizeof (UINTN
);
1014 // Consumer must allocate a buffer for the relocation fixup log.
1015 // Only used for runtime drivers.
1017 ImageContext
->FixupData
= NULL
;
1020 // Load the Codeview info if present
1022 if (ImageContext
->DebugDirectoryEntryRva
!= 0) {
1023 if (!(ImageContext
->IsTeImage
)) {
1024 DebugEntry
= PeCoffLoaderImageAddress (
1026 ImageContext
->DebugDirectoryEntryRva
1029 DebugEntry
= (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
*)(UINTN
)(
1030 ImageContext
->ImageAddress
+
1031 ImageContext
->DebugDirectoryEntryRva
+
1032 sizeof(EFI_TE_IMAGE_HEADER
) -
1033 Hdr
.Te
->StrippedSize
1037 if (DebugEntry
!= NULL
) {
1038 TempDebugEntryRva
= DebugEntry
->RVA
;
1039 if (DebugEntry
->RVA
== 0 && DebugEntry
->FileOffset
!= 0) {
1041 if ((UINTN
)Section
->SizeOfRawData
< Section
->Misc
.VirtualSize
) {
1042 TempDebugEntryRva
= Section
->VirtualAddress
+ Section
->Misc
.VirtualSize
;
1044 TempDebugEntryRva
= Section
->VirtualAddress
+ Section
->SizeOfRawData
;
1048 if (TempDebugEntryRva
!= 0) {
1049 if (!(ImageContext
->IsTeImage
)) {
1050 ImageContext
->CodeView
= PeCoffLoaderImageAddress (ImageContext
, TempDebugEntryRva
);
1052 ImageContext
->CodeView
= (VOID
*)(
1053 (UINTN
)ImageContext
->ImageAddress
+
1054 (UINTN
)TempDebugEntryRva
+
1055 (UINTN
)sizeof (EFI_TE_IMAGE_HEADER
) -
1056 (UINTN
) Hdr
.Te
->StrippedSize
1060 if (ImageContext
->CodeView
== NULL
) {
1061 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
1062 return RETURN_LOAD_ERROR
;
1065 if (DebugEntry
->RVA
== 0) {
1066 Size
= DebugEntry
->SizeOfData
;
1067 if (!(ImageContext
->IsTeImage
)) {
1068 Status
= ImageContext
->ImageRead (
1069 ImageContext
->Handle
,
1070 DebugEntry
->FileOffset
,
1072 ImageContext
->CodeView
1075 Status
= ImageContext
->ImageRead (
1076 ImageContext
->Handle
,
1077 DebugEntry
->FileOffset
+ sizeof (EFI_TE_IMAGE_HEADER
) - Hdr
.Te
->StrippedSize
,
1079 ImageContext
->CodeView
1082 // Should we apply fix up to this field according to the size difference between PE and TE?
1083 // Because now we maintain TE header fields unfixed, this field will also remain as they are
1084 // in original PE image.
1088 if (RETURN_ERROR (Status
)) {
1089 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
1090 return RETURN_LOAD_ERROR
;
1093 DebugEntry
->RVA
= TempDebugEntryRva
;
1096 switch (*(UINT32
*) ImageContext
->CodeView
) {
1097 case CODEVIEW_SIGNATURE_NB10
:
1098 ImageContext
->PdbPointer
= (CHAR8
*)ImageContext
->CodeView
+ sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
);
1101 case CODEVIEW_SIGNATURE_RSDS
:
1102 ImageContext
->PdbPointer
= (CHAR8
*)ImageContext
->CodeView
+ sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY
);
1117 Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI
1120 PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply
1121 the fixups with a virtual mapping.
1124 @param ImageBase Base address of relocated image
1125 @param VirtImageBase Virtual mapping for ImageBase
1126 @param ImageSize Size of the image to relocate
1127 @param RelocationData Location to place results of read
1132 PeCoffLoaderRelocateImageForRuntime (
1133 IN PHYSICAL_ADDRESS ImageBase
,
1134 IN PHYSICAL_ADDRESS VirtImageBase
,
1136 IN VOID
*RelocationData
1141 EFI_IMAGE_DOS_HEADER
*DosHdr
;
1142 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
1143 UINT32 NumberOfRvaAndSizes
;
1144 EFI_IMAGE_DATA_DIRECTORY
*DataDirectory
;
1145 EFI_IMAGE_DATA_DIRECTORY
*RelocDir
;
1146 EFI_IMAGE_BASE_RELOCATION
*RelocBase
;
1147 EFI_IMAGE_BASE_RELOCATION
*RelocBaseEnd
;
1157 RETURN_STATUS Status
;
1159 OldBase
= (CHAR8
*)((UINTN
)ImageBase
);
1160 NewBase
= (CHAR8
*)((UINTN
)VirtImageBase
);
1161 Adjust
= (UINTN
) NewBase
- (UINTN
) OldBase
;
1164 // Find the image's relocate dir info
1166 DosHdr
= (EFI_IMAGE_DOS_HEADER
*)OldBase
;
1167 if (DosHdr
->e_magic
== EFI_IMAGE_DOS_SIGNATURE
) {
1169 // Valid DOS header so get address of PE header
1171 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)(((CHAR8
*)DosHdr
) + DosHdr
->e_lfanew
);
1174 // No Dos header so assume image starts with PE header.
1176 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)OldBase
;
1179 if (Hdr
.Pe32
->Signature
!= EFI_IMAGE_NT_SIGNATURE
) {
1181 // Not a valid PE image so Exit
1187 // Get some data from the PE type dependent data
1189 if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
1193 NumberOfRvaAndSizes
= Hdr
.Pe32
->OptionalHeader
.NumberOfRvaAndSizes
;
1194 DataDirectory
= (EFI_IMAGE_DATA_DIRECTORY
*)&(Hdr
.Pe32
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG
]);
1199 NumberOfRvaAndSizes
= Hdr
.Pe32Plus
->OptionalHeader
.NumberOfRvaAndSizes
;
1200 DataDirectory
= (EFI_IMAGE_DATA_DIRECTORY
*)&(Hdr
.Pe32Plus
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG
]);
1204 // Find the relocation block
1206 // Per the PE/COFF spec, you can't assume that a given data directory
1207 // is present in the image. You have to check the NumberOfRvaAndSizes in
1208 // the optional header to verify a desired directory entry is there.
1210 if (NumberOfRvaAndSizes
> EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
) {
1211 RelocDir
= DataDirectory
+ EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
;
1212 RelocBase
= (EFI_IMAGE_BASE_RELOCATION
*)(UINTN
)(ImageBase
+ RelocDir
->VirtualAddress
);
1213 RelocBaseEnd
= (EFI_IMAGE_BASE_RELOCATION
*)(UINTN
)(ImageBase
+ RelocDir
->VirtualAddress
+ RelocDir
->Size
);
1216 // Cannot find relocations, cannot continue
1222 ASSERT (RelocBase
!= NULL
&& RelocBaseEnd
!= NULL
);
1225 // Run the whole relocation block. And re-fixup data that has not been
1226 // modified. The FixupData is used to see if the image has been modified
1227 // since it was relocated. This is so data sections that have been updated
1228 // by code will not be fixed up, since that would set them back to
1231 FixupData
= RelocationData
;
1232 while (RelocBase
< RelocBaseEnd
) {
1234 Reloc
= (UINT16
*) ((UINT8
*) RelocBase
+ sizeof (EFI_IMAGE_BASE_RELOCATION
));
1235 RelocEnd
= (UINT16
*) ((UINT8
*) RelocBase
+ RelocBase
->SizeOfBlock
);
1236 FixupBase
= (CHAR8
*) ((UINTN
)ImageBase
) + RelocBase
->VirtualAddress
;
1239 // Run this relocation record
1241 while (Reloc
< RelocEnd
) {
1243 Fixup
= FixupBase
+ (*Reloc
& 0xFFF);
1244 switch ((*Reloc
) >> 12) {
1246 case EFI_IMAGE_REL_BASED_ABSOLUTE
:
1249 case EFI_IMAGE_REL_BASED_HIGH
:
1250 F16
= (UINT16
*) Fixup
;
1251 if (*(UINT16
*) FixupData
== *F16
) {
1252 *F16
= (UINT16
) ((*F16
<< 16) + ((UINT16
) Adjust
& 0xffff));
1255 FixupData
= FixupData
+ sizeof (UINT16
);
1258 case EFI_IMAGE_REL_BASED_LOW
:
1259 F16
= (UINT16
*) Fixup
;
1260 if (*(UINT16
*) FixupData
== *F16
) {
1261 *F16
= (UINT16
) (*F16
+ ((UINT16
) Adjust
& 0xffff));
1264 FixupData
= FixupData
+ sizeof (UINT16
);
1267 case EFI_IMAGE_REL_BASED_HIGHLOW
:
1268 F32
= (UINT32
*) Fixup
;
1269 FixupData
= ALIGN_POINTER (FixupData
, sizeof (UINT32
));
1270 if (*(UINT32
*) FixupData
== *F32
) {
1271 *F32
= *F32
+ (UINT32
) Adjust
;
1274 FixupData
= FixupData
+ sizeof (UINT32
);
1277 case EFI_IMAGE_REL_BASED_DIR64
:
1278 F64
= (UINT64
*)Fixup
;
1279 FixupData
= ALIGN_POINTER (FixupData
, sizeof (UINT64
));
1280 if (*(UINT32
*) FixupData
== *F64
) {
1281 *F64
= *F64
+ (UINT64
)Adjust
;
1285 case EFI_IMAGE_REL_BASED_HIGHADJ
:
1287 // Not implemented, but not used in EFI 1.0
1294 // Only Itanium requires ConvertPeImage_Ex
1296 Status
= PeHotRelocateImageEx (Reloc
, Fixup
, &FixupData
, Adjust
);
1297 if (RETURN_ERROR (Status
)) {
1302 // Next relocation record
1309 RelocBase
= (EFI_IMAGE_BASE_RELOCATION
*) RelocEnd
;
1315 ImageRead function that operates on a memory buffer whos base is passed into
1318 @param FileHandle Ponter to baes of the input stream
1319 @param FileOffset Offset to the start of the buffer
1320 @param ReadSize Number of bytes to copy into the buffer
1321 @param Buffer Location to place results of read
1323 @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
1328 PeCoffLoaderImageReadFromMemory (
1329 IN VOID
*FileHandle
,
1330 IN UINTN FileOffset
,
1331 IN OUT UINTN
*ReadSize
,
1335 CopyMem (Buffer
, ((UINT8
*)FileHandle
) + FileOffset
, *ReadSize
);
1336 return RETURN_SUCCESS
;