Changeset 38952 in vbox
- Timestamp:
- Oct 6, 2011 5:28:02 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/Firmware2/VBoxPkg/Library/VBoxPeCoffLib/BasePeCoff.c
r35644 r38952 710 710 711 711 // 712 // Run the relocation information and apply the fixups 713 // 714 FixupData = ImageContext->FixupData; 715 while (RelocBase < RelocBaseEnd) { 716 717 Reloc = (UINT16 *) ((CHAR8 *) RelocBase + sizeof (EFI_IMAGE_BASE_RELOCATION)); 718 RelocEnd = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock); 719 720 // 721 // Make sure RelocEnd is in the Image range. 722 // 723 if ((CHAR8 *) RelocEnd < (CHAR8 *)((UINTN) ImageContext->ImageAddress) || 724 (CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress + (UINTN)ImageContext->ImageSize)) { 725 ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION; 726 return RETURN_LOAD_ERROR; 727 } 728 729 if (!(ImageContext->IsTeImage)) { 730 FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress); 731 if (FixupBase == NULL) { 712 // If Adjust is not zero, then apply fix ups to the image 713 // 714 if (Adjust != 0) { 715 // 716 // Run the relocation information and apply the fixups 717 // 718 FixupData = ImageContext->FixupData; 719 while (RelocBase < RelocBaseEnd) { 720 721 Reloc = (UINT16 *) ((CHAR8 *) RelocBase + sizeof (EFI_IMAGE_BASE_RELOCATION)); 722 RelocEnd = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock); 723 724 // 725 // Make sure RelocEnd is in the Image range. 726 // 727 if ((CHAR8 *) RelocEnd < (CHAR8 *)((UINTN) ImageContext->ImageAddress) || 728 (CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress + (UINTN)ImageContext->ImageSize)) { 729 ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION; 732 730 return RETURN_LOAD_ERROR; 733 731 } 734 } else { 735 FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress + 736 RelocBase->VirtualAddress + 737 sizeof(EFI_TE_IMAGE_HEADER) - 738 Hdr.Te->StrippedSize 739 ); 740 } 741 742 // 743 // Run this relocation record 744 // 745 while (Reloc < RelocEnd) { 746 747 Fixup = FixupBase + (*Reloc & 0xFFF); 748 switch ((*Reloc) >> 12) { 749 case EFI_IMAGE_REL_BASED_ABSOLUTE: 750 break; 751 752 case EFI_IMAGE_REL_BASED_HIGH: 753 Fixup16 = (UINT16 *) Fixup; 754 *Fixup16 = (UINT16) (*Fixup16 + ((UINT16) ((UINT32) Adjust >> 16))); 755 if (FixupData != NULL) { 756 *(UINT16 *) FixupData = *Fixup16; 757 FixupData = FixupData + sizeof (UINT16); 758 } 759 break; 760 761 case EFI_IMAGE_REL_BASED_LOW: 762 Fixup16 = (UINT16 *) Fixup; 763 *Fixup16 = (UINT16) (*Fixup16 + (UINT16) Adjust); 764 if (FixupData != NULL) { 765 *(UINT16 *) FixupData = *Fixup16; 766 FixupData = FixupData + sizeof (UINT16); 767 } 768 break; 769 770 case EFI_IMAGE_REL_BASED_HIGHLOW: 771 Fixup32 = (UINT32 *) Fixup; 772 *Fixup32 = *Fixup32 + (UINT32) Adjust; 773 if (FixupData != NULL) { 774 FixupData = ALIGN_POINTER (FixupData, sizeof (UINT32)); 775 *(UINT32 *)FixupData = *Fixup32; 776 FixupData = FixupData + sizeof (UINT32); 777 } 778 break; 779 780 case EFI_IMAGE_REL_BASED_DIR64: 781 Fixup64 = (UINT64 *) Fixup; 782 *Fixup64 = *Fixup64 + (UINT64) Adjust; 783 if (FixupData != NULL) { 784 FixupData = ALIGN_POINTER (FixupData, sizeof(UINT64)); 785 *(UINT64 *)(FixupData) = *Fixup64; 786 FixupData = FixupData + sizeof(UINT64); 787 } 788 break; 789 790 default: 732 733 if (!(ImageContext->IsTeImage)) { 734 FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress); 735 if (FixupBase == NULL) { 736 return RETURN_LOAD_ERROR; 737 } 738 } else { 739 FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress + 740 RelocBase->VirtualAddress + 741 sizeof(EFI_TE_IMAGE_HEADER) - 742 Hdr.Te->StrippedSize 743 ); 744 } 745 746 // 747 // Run this relocation record 748 // 749 while (Reloc < RelocEnd) { 750 751 Fixup = FixupBase + (*Reloc & 0xFFF); 752 switch ((*Reloc) >> 12) { 753 case EFI_IMAGE_REL_BASED_ABSOLUTE: 754 break; 755 756 case EFI_IMAGE_REL_BASED_HIGH: 757 Fixup16 = (UINT16 *) Fixup; 758 *Fixup16 = (UINT16) (*Fixup16 + ((UINT16) ((UINT32) Adjust >> 16))); 759 if (FixupData != NULL) { 760 *(UINT16 *) FixupData = *Fixup16; 761 FixupData = FixupData + sizeof (UINT16); 762 } 763 break; 764 765 case EFI_IMAGE_REL_BASED_LOW: 766 Fixup16 = (UINT16 *) Fixup; 767 *Fixup16 = (UINT16) (*Fixup16 + (UINT16) Adjust); 768 if (FixupData != NULL) { 769 *(UINT16 *) FixupData = *Fixup16; 770 FixupData = FixupData + sizeof (UINT16); 771 } 772 break; 773 774 case EFI_IMAGE_REL_BASED_HIGHLOW: 775 Fixup32 = (UINT32 *) Fixup; 776 *Fixup32 = *Fixup32 + (UINT32) Adjust; 777 if (FixupData != NULL) { 778 FixupData = ALIGN_POINTER (FixupData, sizeof (UINT32)); 779 *(UINT32 *)FixupData = *Fixup32; 780 FixupData = FixupData + sizeof (UINT32); 781 } 782 break; 783 784 case EFI_IMAGE_REL_BASED_DIR64: 785 Fixup64 = (UINT64 *) Fixup; 786 *Fixup64 = *Fixup64 + (UINT64) Adjust; 787 if (FixupData != NULL) { 788 FixupData = ALIGN_POINTER (FixupData, sizeof(UINT64)); 789 *(UINT64 *)(FixupData) = *Fixup64; 790 FixupData = FixupData + sizeof(UINT64); 791 } 792 break; 793 794 default: 795 // 796 // The common code does not handle some of the stranger IPF relocations 797 // PeCoffLoaderRelocateImageEx () adds support for these complex fixups 798 // on IPF and is a No-Op on other architectures. 799 // 800 Status = PeCoffLoaderRelocateImageEx (Reloc, Fixup, &FixupData, Adjust); 801 if (RETURN_ERROR (Status)) { 802 ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION; 803 return Status; 804 } 805 } 806 791 807 // 792 // The common code does not handle some of the stranger IPF relocations 793 // PeCoffLoaderRelocateImageEx () adds support for these complex fixups 794 // on IPF and is a No-Op on other architectures. 808 // Next relocation record 795 809 // 796 Status = PeCoffLoaderRelocateImageEx (Reloc, Fixup, &FixupData, Adjust); 797 if (RETURN_ERROR (Status)) { 798 ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION; 799 return Status; 800 } 810 Reloc += 1; 801 811 } 802 812 803 813 // 804 // Next relocation record 805 // 806 Reloc += 1; 807 } 808 809 // 810 // Next reloc block 811 // 812 RelocBase = (EFI_IMAGE_BASE_RELOCATION *) RelocEnd; 813 } 814 815 // 816 // Adjust the EntryPoint to match the linked-to address 817 // 818 if (ImageContext->DestinationAddress != 0) { 819 ImageContext->EntryPoint -= (UINT64) ImageContext->ImageAddress; 820 ImageContext->EntryPoint += (UINT64) ImageContext->DestinationAddress; 821 DEBUG((DEBUG_INFO, "%a:%d entry point %x\n", __FILE__, __LINE__, ImageContext->EntryPoint)); 814 // Next reloc block 815 // 816 RelocBase = (EFI_IMAGE_BASE_RELOCATION *) RelocEnd; 817 } 818 819 // 820 // Adjust the EntryPoint to match the linked-to address 821 // 822 if (ImageContext->DestinationAddress != 0) { 823 ImageContext->EntryPoint -= (UINT64) ImageContext->ImageAddress; 824 ImageContext->EntryPoint += (UINT64) ImageContext->DestinationAddress; 825 } 822 826 } 823 827
Note:
See TracChangeset
for help on using the changeset viewer.