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
.Te
->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
,
492 // @bug Check to make sure ImageSize is correct for the relocated image.
493 // it may only work for the file we start with and not the relocated image
495 if (Address
>= ImageContext
->ImageSize
) {
496 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_IMAGE_ADDRESS
;
500 return (CHAR8
*)((UINTN
) ImageContext
->ImageAddress
+ Address
);
504 Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().
506 If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of
507 ImageContext as the relocation base address. Otherwise, use the DestinationAddress field
508 of ImageContext as the relocation base address. The caller must allocate the relocation
509 fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.
510 If ImageContext is NULL, then ASSERT().
512 @param ImageContext Pointer to the image context structure that describes the PE/COFF
513 image that is being relocated.
515 @retval RETURN_SUCCESS The PE/COFF image was relocated.
516 Extended status information is in the ImageError field of ImageContext.
517 @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.
518 Extended status information is in the ImageError field of ImageContext.
519 @retval RETURN_UNSUPPORTED A relocation record type is not supported.
520 Extended status information is in the ImageError field of ImageContext.
525 PeCoffLoaderRelocateImage (
526 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
529 RETURN_STATUS Status
;
530 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
531 EFI_IMAGE_DATA_DIRECTORY
*RelocDir
;
533 EFI_IMAGE_BASE_RELOCATION
*RelocBase
;
534 EFI_IMAGE_BASE_RELOCATION
*RelocBaseEnd
;
543 PHYSICAL_ADDRESS BaseAddress
;
544 UINT32 NumberOfRvaAndSizes
;
546 ASSERT (ImageContext
!= NULL
);
551 ImageContext
->ImageError
= IMAGE_ERROR_SUCCESS
;
554 // If there are no relocation entries, then we are done
556 if (ImageContext
->RelocationsStripped
) {
557 return RETURN_SUCCESS
;
561 // If the destination address is not 0, use that rather than the
562 // image address as the relocation target.
564 if (ImageContext
->DestinationAddress
!= 0) {
565 BaseAddress
= ImageContext
->DestinationAddress
;
567 BaseAddress
= ImageContext
->ImageAddress
;
570 if (!(ImageContext
->IsTeImage
)) {
571 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)((UINTN
)ImageContext
->ImageAddress
+ ImageContext
->PeCoffHeaderOffset
);
572 if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
576 Adjust
= (UINT64
)BaseAddress
- Hdr
.Pe32
->OptionalHeader
.ImageBase
;
577 Hdr
.Pe32
->OptionalHeader
.ImageBase
= (UINT32
)BaseAddress
;
579 NumberOfRvaAndSizes
= Hdr
.Pe32
->OptionalHeader
.NumberOfRvaAndSizes
;
580 RelocDir
= &Hdr
.Pe32
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
];
585 Adjust
= (UINT64
) BaseAddress
- Hdr
.Pe32Plus
->OptionalHeader
.ImageBase
;
586 Hdr
.Pe32Plus
->OptionalHeader
.ImageBase
= (UINT64
)BaseAddress
;
588 NumberOfRvaAndSizes
= Hdr
.Pe32Plus
->OptionalHeader
.NumberOfRvaAndSizes
;
589 RelocDir
= &Hdr
.Pe32Plus
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
];
593 // Find the relocation block
594 // Per the PE/COFF spec, you can't assume that a given data directory
595 // is present in the image. You have to check the NumberOfRvaAndSizes in
596 // the optional header to verify a desired directory entry is there.
599 if (NumberOfRvaAndSizes
> EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
) {
600 RelocBase
= PeCoffLoaderImageAddress (ImageContext
, RelocDir
->VirtualAddress
);
601 RelocBaseEnd
= PeCoffLoaderImageAddress (
603 RelocDir
->VirtualAddress
+ RelocDir
->Size
- 1
607 // Set base and end to bypass processing below.
609 RelocBase
= RelocBaseEnd
= 0;
612 Hdr
.Te
= (EFI_TE_IMAGE_HEADER
*)(UINTN
)(ImageContext
->ImageAddress
);
613 Adjust
= (UINT64
) (BaseAddress
- Hdr
.Te
->ImageBase
);
614 Hdr
.Te
->ImageBase
= (UINT64
) (BaseAddress
);
617 // Find the relocation block
619 RelocDir
= &Hdr
.Te
->DataDirectory
[0];
620 RelocBase
= (EFI_IMAGE_BASE_RELOCATION
*)(UINTN
)(
621 ImageContext
->ImageAddress
+
622 RelocDir
->VirtualAddress
+
623 sizeof(EFI_TE_IMAGE_HEADER
) -
626 RelocBaseEnd
= (EFI_IMAGE_BASE_RELOCATION
*) ((UINTN
) RelocBase
+ (UINTN
) RelocDir
->Size
- 1);
630 // Run the relocation information and apply the fixups
632 FixupData
= ImageContext
->FixupData
;
633 while (RelocBase
< RelocBaseEnd
) {
635 Reloc
= (UINT16
*) ((CHAR8
*) RelocBase
+ sizeof (EFI_IMAGE_BASE_RELOCATION
));
636 RelocEnd
= (UINT16
*) ((CHAR8
*) RelocBase
+ RelocBase
->SizeOfBlock
);
637 if (!(ImageContext
->IsTeImage
)) {
638 FixupBase
= PeCoffLoaderImageAddress (ImageContext
, RelocBase
->VirtualAddress
);
640 FixupBase
= (CHAR8
*)(UINTN
)(ImageContext
->ImageAddress
+
641 RelocBase
->VirtualAddress
+
642 sizeof(EFI_TE_IMAGE_HEADER
) -
647 if ((CHAR8
*) RelocEnd
< (CHAR8
*) ((UINTN
) ImageContext
->ImageAddress
) ||
648 (CHAR8
*) RelocEnd
> (CHAR8
*)((UINTN
)ImageContext
->ImageAddress
+
649 (UINTN
)ImageContext
->ImageSize
)) {
650 ImageContext
->ImageError
= IMAGE_ERROR_FAILED_RELOCATION
;
651 return RETURN_LOAD_ERROR
;
655 // Run this relocation record
657 while (Reloc
< RelocEnd
) {
659 Fixup
= FixupBase
+ (*Reloc
& 0xFFF);
660 switch ((*Reloc
) >> 12) {
661 case EFI_IMAGE_REL_BASED_ABSOLUTE
:
664 case EFI_IMAGE_REL_BASED_HIGH
:
665 F16
= (UINT16
*) Fixup
;
666 *F16
= (UINT16
) (*F16
+ ((UINT16
) ((UINT32
) Adjust
>> 16)));
667 if (FixupData
!= NULL
) {
668 *(UINT16
*) FixupData
= *F16
;
669 FixupData
= FixupData
+ sizeof (UINT16
);
673 case EFI_IMAGE_REL_BASED_LOW
:
674 F16
= (UINT16
*) Fixup
;
675 *F16
= (UINT16
) (*F16
+ (UINT16
) Adjust
);
676 if (FixupData
!= NULL
) {
677 *(UINT16
*) FixupData
= *F16
;
678 FixupData
= FixupData
+ sizeof (UINT16
);
682 case EFI_IMAGE_REL_BASED_HIGHLOW
:
683 F32
= (UINT32
*) Fixup
;
684 *F32
= *F32
+ (UINT32
) Adjust
;
685 if (FixupData
!= NULL
) {
686 FixupData
= ALIGN_POINTER (FixupData
, sizeof (UINT32
));
687 *(UINT32
*)FixupData
= *F32
;
688 FixupData
= FixupData
+ sizeof (UINT32
);
692 case EFI_IMAGE_REL_BASED_DIR64
:
693 F64
= (UINT64
*) Fixup
;
694 *F64
= *F64
+ (UINT64
) Adjust
;
695 if (FixupData
!= NULL
) {
696 FixupData
= ALIGN_POINTER (FixupData
, sizeof(UINT64
));
697 *(UINT64
*)(FixupData
) = *F64
;
698 FixupData
= FixupData
+ sizeof(UINT64
);
704 // The common code does not handle some of the stranger IPF relocations
705 // PeCoffLoaderRelocateImageEx () addes support for these complex fixups
706 // on IPF and is a No-Op on other archtiectures.
708 Status
= PeCoffLoaderRelocateImageEx (Reloc
, Fixup
, &FixupData
, Adjust
);
709 if (RETURN_ERROR (Status
)) {
710 ImageContext
->ImageError
= IMAGE_ERROR_FAILED_RELOCATION
;
716 // Next relocation record
724 RelocBase
= (EFI_IMAGE_BASE_RELOCATION
*) RelocEnd
;
727 return RETURN_SUCCESS
;
731 Loads a PE/COFF image into memory.
733 Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer
734 specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate
735 the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.
736 The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.
737 If ImageContext is NULL, then ASSERT().
739 @param ImageContext Pointer to the image context structure that describes the PE/COFF
740 image that is being loaded.
742 @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by
743 the ImageAddress and ImageSize fields of ImageContext.
744 Extended status information is in the ImageError field of ImageContext.
745 @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.
746 Extended status information is in the ImageError field of ImageContext.
747 @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.
748 Extended status information is in the ImageError field of ImageContext.
749 @retval RETURN_INVALID_PARAMETER The image address is invalid.
750 Extended status information is in the ImageError field of ImageContext.
755 PeCoffLoaderLoadImage (
756 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
759 RETURN_STATUS Status
;
760 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
761 PE_COFF_LOADER_IMAGE_CONTEXT CheckContext
;
762 EFI_IMAGE_SECTION_HEADER
*FirstSection
;
763 EFI_IMAGE_SECTION_HEADER
*Section
;
764 UINTN NumberOfSections
;
769 EFI_IMAGE_DATA_DIRECTORY
*DirectoryEntry
;
770 EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
*DebugEntry
;
772 UINT32 TempDebugEntryRva
;
773 UINT32 NumberOfRvaAndSizes
;
775 ASSERT (ImageContext
!= NULL
);
780 ImageContext
->ImageError
= IMAGE_ERROR_SUCCESS
;
783 // Copy the provided context info into our local version, get what we
784 // can from the original image, and then use that to make sure everything
787 CopyMem (&CheckContext
, ImageContext
, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT
));
789 Status
= PeCoffLoaderGetImageInfo (&CheckContext
);
790 if (RETURN_ERROR (Status
)) {
795 // Make sure there is enough allocated space for the image being loaded
797 if (ImageContext
->ImageSize
< CheckContext
.ImageSize
) {
798 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_IMAGE_SIZE
;
799 return RETURN_BUFFER_TOO_SMALL
;
801 if (ImageContext
->ImageAddress
== 0) {
803 // Image cannot be loaded into 0 address.
805 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_IMAGE_ADDRESS
;
806 return RETURN_INVALID_PARAMETER
;
809 // If there's no relocations, then make sure it's not a runtime driver,
810 // and that it's being loaded at the linked address.
812 if (CheckContext
.RelocationsStripped
) {
814 // If the image does not contain relocations and it is a runtime driver
815 // then return an error.
817 if (CheckContext
.ImageType
== EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
) {
818 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_SUBSYSTEM
;
819 return RETURN_LOAD_ERROR
;
822 // If the image does not contain relocations, and the requested load address
823 // is not the linked address, then return an error.
825 if (CheckContext
.ImageAddress
!= ImageContext
->ImageAddress
) {
826 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_IMAGE_ADDRESS
;
827 return RETURN_INVALID_PARAMETER
;
831 // Make sure the allocated space has the proper section alignment
833 if (!(ImageContext
->IsTeImage
)) {
834 if ((ImageContext
->ImageAddress
& (CheckContext
.SectionAlignment
- 1)) != 0) {
835 ImageContext
->ImageError
= IMAGE_ERROR_INVALID_SECTION_ALIGNMENT
;
836 return RETURN_INVALID_PARAMETER
;
840 // Read the entire PE/COFF or TE header into memory
842 if (!(ImageContext
->IsTeImage
)) {
843 Status
= ImageContext
->ImageRead (
844 ImageContext
->Handle
,
846 &ImageContext
->SizeOfHeaders
,
847 (VOID
*) (UINTN
) ImageContext
->ImageAddress
850 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)((UINTN
)ImageContext
->ImageAddress
+ ImageContext
->PeCoffHeaderOffset
);
852 FirstSection
= (EFI_IMAGE_SECTION_HEADER
*) (
853 (UINTN
)ImageContext
->ImageAddress
+
854 ImageContext
->PeCoffHeaderOffset
+
856 sizeof(EFI_IMAGE_FILE_HEADER
) +
857 Hdr
.Pe32
->FileHeader
.SizeOfOptionalHeader
859 NumberOfSections
= (UINTN
) (Hdr
.Pe32
->FileHeader
.NumberOfSections
);
861 Status
= ImageContext
->ImageRead (
862 ImageContext
->Handle
,
864 &ImageContext
->SizeOfHeaders
,
865 (void *)(UINTN
)ImageContext
->ImageAddress
868 Hdr
.Te
= (EFI_TE_IMAGE_HEADER
*)(UINTN
)(ImageContext
->ImageAddress
);
870 FirstSection
= (EFI_IMAGE_SECTION_HEADER
*) (
871 (UINTN
)ImageContext
->ImageAddress
+
872 sizeof(EFI_TE_IMAGE_HEADER
)
874 NumberOfSections
= (UINTN
) (Hdr
.Te
->NumberOfSections
);
878 if (RETURN_ERROR (Status
)) {
879 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
880 return RETURN_LOAD_ERROR
;
884 // Load each section of the image
886 Section
= FirstSection
;
887 for (Index
= 0, MaxEnd
= NULL
; Index
< NumberOfSections
; Index
++) {
890 // Compute sections address
892 Base
= PeCoffLoaderImageAddress (ImageContext
, Section
->VirtualAddress
);
893 End
= PeCoffLoaderImageAddress (
895 Section
->VirtualAddress
+ Section
->Misc
.VirtualSize
- 1
897 if (ImageContext
->IsTeImage
) {
898 Base
= (CHAR8
*)((UINTN
) Base
+ sizeof (EFI_TE_IMAGE_HEADER
) - (UINTN
)Hdr
.Te
->StrippedSize
);
899 End
= (CHAR8
*)((UINTN
) End
+ sizeof (EFI_TE_IMAGE_HEADER
) - (UINTN
)Hdr
.Te
->StrippedSize
);
906 // If the base start or end address resolved to 0, then fail.
908 if ((Base
== NULL
) || (End
== NULL
)) {
909 ImageContext
->ImageError
= IMAGE_ERROR_SECTION_NOT_LOADED
;
910 return RETURN_LOAD_ERROR
;
916 Size
= (UINTN
) Section
->Misc
.VirtualSize
;
917 if ((Size
== 0) || (Size
> Section
->SizeOfRawData
)) {
918 Size
= (UINTN
) Section
->SizeOfRawData
;
921 if (Section
->SizeOfRawData
) {
922 if (!(ImageContext
->IsTeImage
)) {
923 Status
= ImageContext
->ImageRead (
924 ImageContext
->Handle
,
925 Section
->PointerToRawData
,
930 Status
= ImageContext
->ImageRead (
931 ImageContext
->Handle
,
932 Section
->PointerToRawData
+ sizeof (EFI_TE_IMAGE_HEADER
) - (UINTN
)Hdr
.Te
->StrippedSize
,
938 if (RETURN_ERROR (Status
)) {
939 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
945 // If raw size is less then virt size, zero fill the remaining
948 if (Size
< Section
->Misc
.VirtualSize
) {
949 ZeroMem (Base
+ Size
, Section
->Misc
.VirtualSize
- Size
);
959 // Get image's entry point
961 if (!(ImageContext
->IsTeImage
)) {
963 // Sizes of AddressOfEntryPoint are different so we need to do this safely
965 if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
969 ImageContext
->EntryPoint
= (PHYSICAL_ADDRESS
)(UINTN
)PeCoffLoaderImageAddress (
971 (UINTN
)Hdr
.Pe32
->OptionalHeader
.AddressOfEntryPoint
977 ImageContext
->EntryPoint
= (PHYSICAL_ADDRESS
)(UINTN
)PeCoffLoaderImageAddress (
979 (UINTN
)Hdr
.Pe32Plus
->OptionalHeader
.AddressOfEntryPoint
983 ImageContext
->EntryPoint
= (PHYSICAL_ADDRESS
) (
984 (UINTN
)ImageContext
->ImageAddress
+
985 (UINTN
)Hdr
.Te
->AddressOfEntryPoint
+
986 (UINTN
)sizeof(EFI_TE_IMAGE_HEADER
) -
987 (UINTN
)Hdr
.Te
->StrippedSize
992 // Determine the size of the fixup data
994 // Per the PE/COFF spec, you can't assume that a given data directory
995 // is present in the image. You have to check the NumberOfRvaAndSizes in
996 // the optional header to verify a desired directory entry is there.
998 if (!(ImageContext
->IsTeImage
)) {
999 if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
1003 NumberOfRvaAndSizes
= Hdr
.Pe32
->OptionalHeader
.NumberOfRvaAndSizes
;
1004 DirectoryEntry
= (EFI_IMAGE_DATA_DIRECTORY
*)&Hdr
.Pe32
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
];
1009 NumberOfRvaAndSizes
= Hdr
.Pe32Plus
->OptionalHeader
.NumberOfRvaAndSizes
;
1010 DirectoryEntry
= (EFI_IMAGE_DATA_DIRECTORY
*)&Hdr
.Pe32Plus
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
];
1013 if (NumberOfRvaAndSizes
> EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
) {
1014 ImageContext
->FixupDataSize
= DirectoryEntry
->Size
/ sizeof (UINT16
) * sizeof (UINTN
);
1016 ImageContext
->FixupDataSize
= 0;
1019 DirectoryEntry
= &Hdr
.Te
->DataDirectory
[0];
1020 ImageContext
->FixupDataSize
= DirectoryEntry
->Size
/ sizeof (UINT16
) * sizeof (UINTN
);
1023 // Consumer must allocate a buffer for the relocation fixup log.
1024 // Only used for runtime drivers.
1026 ImageContext
->FixupData
= NULL
;
1029 // Load the Codeview info if present
1031 if (ImageContext
->DebugDirectoryEntryRva
!= 0) {
1032 if (!(ImageContext
->IsTeImage
)) {
1033 DebugEntry
= PeCoffLoaderImageAddress (
1035 ImageContext
->DebugDirectoryEntryRva
1038 DebugEntry
= (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
*)(UINTN
)(
1039 ImageContext
->ImageAddress
+
1040 ImageContext
->DebugDirectoryEntryRva
+
1041 sizeof(EFI_TE_IMAGE_HEADER
) -
1042 Hdr
.Te
->StrippedSize
1046 if (DebugEntry
!= NULL
) {
1047 TempDebugEntryRva
= DebugEntry
->RVA
;
1048 if (DebugEntry
->RVA
== 0 && DebugEntry
->FileOffset
!= 0) {
1050 if ((UINTN
)Section
->SizeOfRawData
< Section
->Misc
.VirtualSize
) {
1051 TempDebugEntryRva
= Section
->VirtualAddress
+ Section
->Misc
.VirtualSize
;
1053 TempDebugEntryRva
= Section
->VirtualAddress
+ Section
->SizeOfRawData
;
1057 if (TempDebugEntryRva
!= 0) {
1058 if (!(ImageContext
->IsTeImage
)) {
1059 ImageContext
->CodeView
= PeCoffLoaderImageAddress (ImageContext
, TempDebugEntryRva
);
1061 ImageContext
->CodeView
= (VOID
*)(
1062 (UINTN
)ImageContext
->ImageAddress
+
1063 (UINTN
)TempDebugEntryRva
+
1064 (UINTN
)sizeof (EFI_TE_IMAGE_HEADER
) -
1065 (UINTN
) Hdr
.Te
->StrippedSize
1069 if (ImageContext
->CodeView
== NULL
) {
1070 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
1071 return RETURN_LOAD_ERROR
;
1074 if (DebugEntry
->RVA
== 0) {
1075 Size
= DebugEntry
->SizeOfData
;
1076 if (!(ImageContext
->IsTeImage
)) {
1077 Status
= ImageContext
->ImageRead (
1078 ImageContext
->Handle
,
1079 DebugEntry
->FileOffset
,
1081 ImageContext
->CodeView
1084 Status
= ImageContext
->ImageRead (
1085 ImageContext
->Handle
,
1086 DebugEntry
->FileOffset
+ sizeof (EFI_TE_IMAGE_HEADER
) - Hdr
.Te
->StrippedSize
,
1088 ImageContext
->CodeView
1091 // Should we apply fix up to this field according to the size difference between PE and TE?
1092 // Because now we maintain TE header fields unfixed, this field will also remain as they are
1093 // in original PE image.
1097 if (RETURN_ERROR (Status
)) {
1098 ImageContext
->ImageError
= IMAGE_ERROR_IMAGE_READ
;
1099 return RETURN_LOAD_ERROR
;
1102 DebugEntry
->RVA
= TempDebugEntryRva
;
1105 switch (*(UINT32
*) ImageContext
->CodeView
) {
1106 case CODEVIEW_SIGNATURE_NB10
:
1107 ImageContext
->PdbPointer
= (CHAR8
*)ImageContext
->CodeView
+ sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
);
1110 case CODEVIEW_SIGNATURE_RSDS
:
1111 ImageContext
->PdbPointer
= (CHAR8
*)ImageContext
->CodeView
+ sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY
);
1126 Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI
1129 PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply
1130 the fixups with a virtual mapping.
1133 @param ImageBase Base address of relocated image
1134 @param VirtImageBase Virtual mapping for ImageBase
1135 @param ImageSize Size of the image to relocate
1136 @param RelocationData Location to place results of read
1141 PeCoffLoaderRelocateImageForRuntime (
1142 IN PHYSICAL_ADDRESS ImageBase
,
1143 IN PHYSICAL_ADDRESS VirtImageBase
,
1145 IN VOID
*RelocationData
1150 EFI_IMAGE_DOS_HEADER
*DosHdr
;
1151 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
1152 UINT32 NumberOfRvaAndSizes
;
1153 EFI_IMAGE_DATA_DIRECTORY
*DataDirectory
;
1154 EFI_IMAGE_DATA_DIRECTORY
*RelocDir
;
1155 EFI_IMAGE_BASE_RELOCATION
*RelocBase
;
1156 EFI_IMAGE_BASE_RELOCATION
*RelocBaseEnd
;
1166 RETURN_STATUS Status
;
1168 OldBase
= (CHAR8
*)((UINTN
)ImageBase
);
1169 NewBase
= (CHAR8
*)((UINTN
)VirtImageBase
);
1170 Adjust
= (UINTN
) NewBase
- (UINTN
) OldBase
;
1173 // Find the image's relocate dir info
1175 DosHdr
= (EFI_IMAGE_DOS_HEADER
*)OldBase
;
1176 if (DosHdr
->e_magic
== EFI_IMAGE_DOS_SIGNATURE
) {
1178 // Valid DOS header so get address of PE header
1180 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)(((CHAR8
*)DosHdr
) + DosHdr
->e_lfanew
);
1183 // No Dos header so assume image starts with PE header.
1185 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)OldBase
;
1188 if (Hdr
.Pe32
->Signature
!= EFI_IMAGE_NT_SIGNATURE
) {
1190 // Not a valid PE image so Exit
1196 // Get some data from the PE type dependent data
1198 if (Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
1202 NumberOfRvaAndSizes
= Hdr
.Pe32
->OptionalHeader
.NumberOfRvaAndSizes
;
1203 DataDirectory
= (EFI_IMAGE_DATA_DIRECTORY
*)&(Hdr
.Pe32
->OptionalHeader
.DataDirectory
[0]);
1208 NumberOfRvaAndSizes
= Hdr
.Pe32Plus
->OptionalHeader
.NumberOfRvaAndSizes
;
1209 DataDirectory
= (EFI_IMAGE_DATA_DIRECTORY
*)&(Hdr
.Pe32Plus
->OptionalHeader
.DataDirectory
[0]);
1213 // Find the relocation block
1215 // Per the PE/COFF spec, you can't assume that a given data directory
1216 // is present in the image. You have to check the NumberOfRvaAndSizes in
1217 // the optional header to verify a desired directory entry is there.
1219 if (NumberOfRvaAndSizes
> EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
) {
1220 RelocDir
= DataDirectory
+ EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC
;
1221 RelocBase
= (EFI_IMAGE_BASE_RELOCATION
*)(UINTN
)(ImageBase
+ RelocDir
->VirtualAddress
);
1222 RelocBaseEnd
= (EFI_IMAGE_BASE_RELOCATION
*)(UINTN
)(ImageBase
+ RelocDir
->VirtualAddress
+ RelocDir
->Size
);
1225 // Cannot find relocations, cannot continue
1231 ASSERT (RelocBase
!= NULL
&& RelocBaseEnd
!= NULL
);
1234 // Run the whole relocation block. And re-fixup data that has not been
1235 // modified. The FixupData is used to see if the image has been modified
1236 // since it was relocated. This is so data sections that have been updated
1237 // by code will not be fixed up, since that would set them back to
1240 FixupData
= RelocationData
;
1241 while (RelocBase
< RelocBaseEnd
) {
1243 Reloc
= (UINT16
*) ((UINT8
*) RelocBase
+ sizeof (EFI_IMAGE_BASE_RELOCATION
));
1244 RelocEnd
= (UINT16
*) ((UINT8
*) RelocBase
+ RelocBase
->SizeOfBlock
);
1245 FixupBase
= (CHAR8
*) ((UINTN
)ImageBase
) + RelocBase
->VirtualAddress
;
1248 // Run this relocation record
1250 while (Reloc
< RelocEnd
) {
1252 Fixup
= FixupBase
+ (*Reloc
& 0xFFF);
1253 switch ((*Reloc
) >> 12) {
1255 case EFI_IMAGE_REL_BASED_ABSOLUTE
:
1258 case EFI_IMAGE_REL_BASED_HIGH
:
1259 F16
= (UINT16
*) Fixup
;
1260 if (*(UINT16
*) FixupData
== *F16
) {
1261 *F16
= (UINT16
) (*F16
+ ((UINT16
) ((UINT32
) Adjust
>> 16)));
1264 FixupData
= FixupData
+ sizeof (UINT16
);
1267 case EFI_IMAGE_REL_BASED_LOW
:
1268 F16
= (UINT16
*) Fixup
;
1269 if (*(UINT16
*) FixupData
== *F16
) {
1270 *F16
= (UINT16
) (*F16
+ ((UINT16
) Adjust
& 0xffff));
1273 FixupData
= FixupData
+ sizeof (UINT16
);
1276 case EFI_IMAGE_REL_BASED_HIGHLOW
:
1277 F32
= (UINT32
*) Fixup
;
1278 FixupData
= ALIGN_POINTER (FixupData
, sizeof (UINT32
));
1279 if (*(UINT32
*) FixupData
== *F32
) {
1280 *F32
= *F32
+ (UINT32
) Adjust
;
1283 FixupData
= FixupData
+ sizeof (UINT32
);
1286 case EFI_IMAGE_REL_BASED_DIR64
:
1287 F64
= (UINT64
*)Fixup
;
1288 FixupData
= ALIGN_POINTER (FixupData
, sizeof (UINT64
));
1289 if (*(UINT64
*) FixupData
== *F64
) {
1290 *F64
= *F64
+ (UINT64
)Adjust
;
1293 FixupData
= FixupData
+ sizeof (UINT64
);
1296 case EFI_IMAGE_REL_BASED_HIGHADJ
:
1298 // Not implemented, but not used in EFI 1.0
1305 // Only Itanium requires ConvertPeImage_Ex
1307 Status
= PeHotRelocateImageEx (Reloc
, Fixup
, &FixupData
, Adjust
);
1308 if (RETURN_ERROR (Status
)) {
1313 // Next relocation record
1320 RelocBase
= (EFI_IMAGE_BASE_RELOCATION
*) RelocEnd
;
1326 ImageRead function that operates on a memory buffer whos base is passed into
1329 @param FileHandle Ponter to baes of the input stream
1330 @param FileOffset Offset to the start of the buffer
1331 @param ReadSize Number of bytes to copy into the buffer
1332 @param Buffer Location to place results of read
1334 @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
1339 PeCoffLoaderImageReadFromMemory (
1340 IN VOID
*FileHandle
,
1341 IN UINTN FileOffset
,
1342 IN OUT UINTN
*ReadSize
,
1346 CopyMem (Buffer
, ((UINT8
*)FileHandle
) + FileOffset
, *ReadSize
);
1347 return RETURN_SUCCESS
;