VirtualBox

Changeset 41162 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
May 4, 2012 12:09:51 PM (13 years ago)
Author:
vboxsync
Message:

EFI: EP calculation fix (xTracker/6187).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/DevEFI.cpp

    r40280 r41162  
    571571        {
    572572            *pcbFile = FFS_SIZE(pFfsFile);
     573            LogFunc(("Found %RTuuid of type:%d\n", &pFfsFile->Name, FileType));
    573574            return pFfsFile;
    574575        }
     
    578579}
    579580
    580 static int efiFindEntryPoint(EFI_FFS_FILE_HEADER const *pFfsFile, uint32_t cbFfsFile, RTGCPHYS *pImageBase, uint8_t **ppbImage)
     581static int efiFindRelativeAddressOfEPAndBaseAddressOfModule(EFI_FFS_FILE_HEADER const *pFfsFile, uint32_t cbFfsFile, RTGCPHYS *pImageBase, uint8_t **ppbImage)
    581582{
    582583    /*
     
    637638                              ("%x / %x\n", pHdr->Nt32.FileHeader.Machine, pHdr->Nt32.FileHeader.SizeOfOptionalHeader),
    638639                              VERR_LDR_ARCH_MISMATCH);
     640        EFI_IMAGE_SECTION_HEADER *pSectionsHeaders = NULL;
     641        int cSectionsHeaders = 0;
    639642        if (pHdr->Nt32.FileHeader.Machine == EFI_IMAGE_FILE_MACHINE_I386)
    640643        {
     
    645648            ImageBase = pHdr->Nt32.OptionalHeader.ImageBase;
    646649            EpRVA     = pHdr->Nt32.OptionalHeader.AddressOfEntryPoint;
     650            EpRVA     -= pHdr->Nt32.OptionalHeader.BaseOfCode;
    647651            AssertLogRelMsgReturn(EpRVA < pHdr->Nt32.OptionalHeader.SizeOfImage,
    648652                                  ("%#RGp / %#x\n", EpRVA, pHdr->Nt32.OptionalHeader.SizeOfImage),
    649653                                  VERR_BAD_EXE_FORMAT);
     654            pSectionsHeaders = (EFI_IMAGE_SECTION_HEADER *)((uint8_t *)&pHdr->Nt32.OptionalHeader + pHdr->Nt32.FileHeader.SizeOfOptionalHeader);
     655            cSectionsHeaders = pHdr->Nt32.FileHeader.NumberOfSections;
    650656        }
    651657        else
    652658        {
    653             Log2(("EFI: PE+/AMD64\n"));
     659            Log2(("EFI: PE+/AMD64 %RX16\n", pHdr->Nt32.FileHeader.Machine));
    654660            AssertLogRelMsgReturn(pHdr->Nt64.OptionalHeader.SizeOfImage < cbFfsFile,
    655661                                  ("%#x / %#x\n", pHdr->Nt64.OptionalHeader.SizeOfImage, cbFfsFile),
     
    657663            ImageBase = pHdr->Nt64.OptionalHeader.ImageBase;
    658664            EpRVA     = pHdr->Nt64.OptionalHeader.AddressOfEntryPoint;
     665            EpRVA     -= pHdr->Nt64.OptionalHeader.BaseOfCode;
    659666            AssertLogRelMsgReturn(EpRVA < pHdr->Nt64.OptionalHeader.SizeOfImage,
    660667                                  ("%#RGp / %#x\n", EpRVA, pHdr->Nt64.OptionalHeader.SizeOfImage),
    661668                                  VERR_BAD_EXE_FORMAT);
     669            pSectionsHeaders = (EFI_IMAGE_SECTION_HEADER *)((uint8_t *)&pHdr->Nt64.OptionalHeader + pHdr->Nt64.FileHeader.SizeOfOptionalHeader);
     670            cSectionsHeaders = pHdr->Nt64.FileHeader.NumberOfSections;
     671        }
     672        AssertPtrReturn(pSectionsHeaders, VERR_BAD_EXE_FORMAT);
     673        int idxSection = 0;
     674        for (; idxSection < cSectionsHeaders; ++idxSection)
     675        {
     676            EFI_IMAGE_SECTION_HEADER *pSection = &pSectionsHeaders[idxSection];
     677            if (!RTStrCmp((const char *)&pSection->Name[0], ".text"))
     678            {
     679                EpRVA += pSection->PointerToRawData;
     680                break;
     681            }
    662682        }
    663683    }
     
    684704    if (ppbImage != NULL)
    685705        *ppbImage = (uint8_t *)pbImage;
    686     return ImageBase + EpRVA;
     706    return (EpRVA);
    687707}
    688708
     
    728748    AssertLogRelMsgReturn(pFfsFile, ("No SECURITY_CORE found in the firmware volume\n"), VERR_FILE_NOT_FOUND);
    729749
    730     RTGCPHYS ImageBase;
    731     uint8_t *pbImage;
    732     pThis->GCEntryPoint0 = efiFindEntryPoint(pFfsFile, cbFfsFile, &ImageBase, &pbImage);
    733 
     750    RTGCPHYS ImageBase = NULL;
     751    uint8_t *pbImage = NULL;
     752    pThis->GCEntryPoint0 = efiFindRelativeAddressOfEPAndBaseAddressOfModule(pFfsFile, cbFfsFile, &ImageBase, &pbImage);
     753    pThis->GCEntryPoint0 += pbImage - pThis->pu8EfiRom;
     754    Assert(pThis->pu8EfiRom <= pbImage);
     755    Assert(pbImage < pThis->pu8EfiRom + pThis->cbEfiRom);
    734756    /*
    735757     * Calc the firmware load address from the image base and validate it.
    736758     */
    737759    pThis->GCLoadAddress = ImageBase - (pbImage - pThis->pu8EfiRom);
     760    pThis->GCEntryPoint0 += pThis->GCLoadAddress;
    738761    AssertLogRelMsgReturn(~(pThis->GCLoadAddress & PAGE_OFFSET_MASK),
    739762                          ("%RGp\n", pThis->GCLoadAddress),
     
    751774
    752775    pFfsFile = efiFwVolFindFileByType(pFfsFile, pbFwVolEnd, EFI_FV_FILETYPE_PEI_CORE, &cbFfsFile);
    753     pThis->GCEntryPoint1 = efiFindEntryPoint(pFfsFile, cbFfsFile, NULL, NULL);
     776    pThis->GCEntryPoint1 = efiFindRelativeAddressOfEPAndBaseAddressOfModule(pFfsFile, cbFfsFile, NULL, &pbImage);
     777    pThis->GCEntryPoint1 += pThis->GCLoadAddress;
     778    pThis->GCEntryPoint1 += pbImage - pThis->pu8EfiRom;
    754779    LogRel(("EFI: Firmware volume loading at %RGp, PEI CORE at with EP at %RGp\n",
    755780            pThis->GCLoadAddress, pThis->GCEntryPoint1));
     
    805830                              PGMPHYS_ROM_FLAGS_SHADOWED | PGMPHYS_ROM_FLAGS_PERMANENT_BINARY,
    806831                              "EFI Firmware Volume");
    807     if (RT_FAILURE(rc))
    808         return rc;
     832    AssertRCReturn(rc, rc);
     833    rc = PDMDevHlpROMProtectShadow(pThis->pDevIns, pThis->GCLoadAddress, (uint32_t)cbQuart, PGMROMPROT_READ_RAM_WRITE_IGNORE);
     834    AssertRCReturn(rc, rc);
    809835    rc = PDMDevHlpROMRegister(pThis->pDevIns,
    810836                              pThis->GCLoadAddress + cbQuart,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette