VirtualBox

Changeset 16933 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Feb 18, 2009 11:42:57 PM (16 years ago)
Author:
vboxsync
Message:

IPRT/PDM,SUPLIb,REM: Extended RTLdrOpen with an architecture argument for use with FAT R0.r0 images later some day. Also added fFlags argument that's currently MBZ case.

Location:
trunk/src/VBox/Runtime/common/ldr
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/ldr/ldrELF.cpp

    r8245 r16933  
    114114 * @returns iprt status code.
    115115 * @param   pReader     The loader reader instance which will provide the raw image bits.
     116 * @param   fFlags      Reserved, MBZ.
     117 * @param   enmArch     Architecture specifier.
    116118 * @param   phLdrMod    Where to store the handle.
    117119 */
    118 int rtldrELFOpen(PRTLDRREADER pReader, PRTLDRMOD phLdrMod)
     120int rtldrELFOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod)
    119121{
    120122    const char *pszLogName = pReader->pfnLogName(pReader); NOREF(pszLogName);
     
    145147    }
    146148    if (e_ident[EI_CLASS] == ELFCLASS32)
    147         rc = rtldrELF32Open(pReader, phLdrMod);
     149        rc = rtldrELF32Open(pReader, fFlags, enmArch, phLdrMod);
    148150    else
    149         rc = rtldrELF64Open(pReader, phLdrMod);
     151        rc = rtldrELF64Open(pReader, fFlags, enmArch, phLdrMod);
    150152    return rc;
    151153}
  • trunk/src/VBox/Runtime/common/ldr/ldrELFRelocatable.cpp.h

    r14049 r16933  
    721721 * @param   cbRawImage  The size of the raw image.
    722722 */
    723 static int RTLDRELF_NAME(ValidateElfHeader)(const Elf_Ehdr *pEhdr, const char *pszLogName, uint64_t cbRawImage)
     723static int RTLDRELF_NAME(ValidateElfHeader)(const Elf_Ehdr *pEhdr, const char *pszLogName, uint64_t cbRawImage, PRTLDRARCH penmArch)
    724724{
    725725    Log3(("RTLdrELF:     e_ident: %.*Rhxs\n"
     
    806806        case EM_386:
    807807        case EM_486:
     808            *penmArch = RTLDRARCH_X86_32;
     809            break;
    808810#elif ELF_MODE == 64
    809811        case EM_X86_64:
     812            *penmArch = RTLDRARCH_AMD64;
     813            break;
    810814#endif
    811             break;
    812815        default:
    813816            Log(("RTLdrELF: %s: machine type %u is not supported!\n", pEhdr->e_machine));
     
    986989 * @returns iprt status code.
    987990 * @param   pReader     The loader reader instance which will provide the raw image bits.
     991 * @param   fFlags      Reserved, MBZ.
     992 * @param   enmArch     Architecture specifier.
    988993 * @param   phLdrMod    Where to store the handle.
    989994 */
    990 static int RTLDRELF_NAME(Open)(PRTLDRREADER pReader, PRTLDRMOD phLdrMod)
     995static int RTLDRELF_NAME(Open)(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod)
    991996{
    992997    const char *pszLogName = pReader->pfnLogName(pReader);
     
    10151020
    10161021    /*
    1017      * Read and validate the ELF header.
     1022     * Read and validate the ELF header and match up the CPU architecture.
    10181023     */
    10191024    int rc = pReader->pfnRead(pReader, &pModElf->Ehdr, sizeof(pModElf->Ehdr), 0);
    10201025    if (RT_SUCCESS(rc))
    1021         rc = RTLDRELF_NAME(ValidateElfHeader)(&pModElf->Ehdr, pszLogName, cbRawImage);
     1026    {
     1027        RTLDRARCH enmArchImage;
     1028        rc = RTLDRELF_NAME(ValidateElfHeader)(&pModElf->Ehdr, pszLogName, cbRawImage, &enmArchImage);
     1029        if (RT_SUCCESS(rc))
     1030        {
     1031            if (    enmArch != RTLDRARCH_WHATEVER
     1032                &&  enmArch != enmArchImage)
     1033                rc = VERR_LDR_ARCH_MISMATCH;
     1034        }
     1035    }
    10221036    if (RT_SUCCESS(rc))
    10231037    {
  • trunk/src/VBox/Runtime/common/ldr/ldrEx.cpp

    r13837 r16933  
    4949 * @returns iprt status code.
    5050 * @param   pReader     The loader reader instance which will provide the raw image bits.
     51 * @param   fFlags      Reserved, MBZ.
     52 * @param   enmArch     Architecture specifier.
    5153 * @param   phMod       Where to store the handle.
    5254 */
    53 int rtldrOpenWithReader(PRTLDRREADER pReader, PRTLDRMOD phMod)
     55int rtldrOpenWithReader(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phMod)
    5456{
    5557    /*
     
    105107    if (uSign.u32 == IMAGE_NT_SIGNATURE)
    106108#ifdef LDR_WITH_PE
    107         rc = rtldrPEOpen(pReader, offHdr, phMod);
     109        rc = rtldrPEOpen(pReader, fFlags, enmArch, offHdr, phMod);
    108110#else
    109111        rc = VERR_PE_EXE_NOT_SUPPORTED;
     
    111113    else if (uSign.u32 == IMAGE_ELF_SIGNATURE)
    112114#if defined(LDR_WITH_ELF)
    113         rc = rtldrELFOpen(pReader, phMod);
     115        rc = rtldrELFOpen(pReader, fFlags, enmArch, phMod);
    114116#else
    115117        rc = VERR_ELF_EXE_NOT_SUPPORTED;
     
    117119    else if (uSign.au16[0] == IMAGE_LX_SIGNATURE)
    118120#ifdef LDR_WITH_LX
    119         rc = rtldrLXOpen(pReader, offHdr, phMod);
     121        rc = rtldrLXOpen(pReader, fFlags, enmArch, offHdr, phMod);
    120122#else
    121123        rc = VERR_LX_EXE_NOT_SUPPORTED;
     
    123125    else if (uSign.au16[0] == IMAGE_LE_SIGNATURE)
    124126#ifdef LDR_WITH_LE
    125         rc = rtldrLEOpen(pReader, phMod);
     127        rc = rtldrLEOpen(pReader, fFlags, enmArch, phMod);
    126128#else
    127129        rc = VERR_LE_EXE_NOT_SUPPORTED;
     
    129131    else if (uSign.au16[0] == IMAGE_NE_SIGNATURE)
    130132#ifdef LDR_WITH_NE
    131         rc = rtldrNEOpen(pReader, phMod);
     133        rc = rtldrNEOpen(pReader, fFlags, enmArch, phMod);
    132134#else
    133135        rc = VERR_NE_EXE_NOT_SUPPORTED;
     
    135137    else if (uSign.au16[0] == IMAGE_DOS_SIGNATURE)
    136138#ifdef LDR_WITH_MZ
    137         rc = rtldrMZOpen(pReader, phMod);
     139        rc = rtldrMZOpen(pReader, fFlags, enmArch, phMod);
    138140#else
    139141        rc = VERR_MZ_EXE_NOT_SUPPORTED;
     
    143145             0)
    144146#ifdef LDR_WITH_AOUT
    145         rc = rtldrAOUTOpen(pReader, phMod);
     147        rc = rtldrAOUTOpen(pReader, fFlags, enmArch, phMod);
    146148#else
    147149        rc = VERR_AOUT_EXE_NOT_SUPPORTED;
     
    158160    /* Try kLdr if it's a format we don't recognize. */
    159161    if (rc <= VERR_INVALID_EXE_SIGNATURE && rc > VERR_BAD_EXE_FORMAT)
    160         rc = rtldrkLdrOpen(pReader, phMod);
     162        rc = rtldrkLdrOpen(pReader, fFlags, enmArch, phMod);
    161163#endif
    162164
  • trunk/src/VBox/Runtime/common/ldr/ldrFile.cpp

    r8245 r16933  
    241241
    242242/**
    243  * Open a binary image file.
     243 * Open a binary image file, extended version.
    244244 *
    245245 * @returns iprt status code.
    246246 * @param   pszFilename Image filename.
    247  * @param   phLdrMod    Where to store the handle to the loaded module.
    248  */
    249 RTDECL(int) RTLdrOpen(const char *pszFilename, PRTLDRMOD phLdrMod)
    250 {
    251     LogFlow(("RTLdrOpen: pszFilename=%p:{%s} phLdrMod=%p\n",
    252              pszFilename, pszFilename, phLdrMod));
     247 * @param   fFlags      Reserved, MBZ.
     248 * @param   enmArch     CPU architecture specifier for the image to be loaded.
     249 * @param   phLdrMod    Where to store the handle to the loader module.
     250 */
     251RTDECL(int) RTLdrOpen(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod)
     252{
     253    LogFlow(("RTLdrOpen: pszFilename=%p:{%s} fFlags=%#x enmArch=%d phLdrMod=%p\n",
     254             pszFilename, pszFilename, fFlags, enmArch, phLdrMod));
     255    AssertMsgReturn(!fFlags, ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
     256    AssertMsgReturn(enmArch > RTLDRARCH_INVALID && enmArch < RTLDRARCH_END, ("%d\n", enmArch), VERR_INVALID_PARAMETER);
     257
     258    /*
     259     * Resolve RTLDRARCH_HOST.
     260     */
     261    if (enmArch == RTLDRARCH_HOST)
     262#if   defined(RT_ARCH_AMD64)
     263        enmArch = RTLDRARCH_AMD64;
     264#elif defined(RT_ARCH_X86)
     265        enmArch = RTLDRARCH_X86_32;
     266#else
     267        enmArch = RTLDRARCH_WHATEVER;
     268#endif
    253269
    254270    /*
     
    259275    if (RT_SUCCESS(rc))
    260276    {
    261         rc = rtldrOpenWithReader(pReader, phLdrMod);
     277        rc = rtldrOpenWithReader(pReader, fFlags, enmArch, phLdrMod);
    262278        if (RT_SUCCESS(rc))
    263279        {
     
    277293 *
    278294 * @returns iprt status code.
    279  * @param   pszFilename     Image filename.
    280  * @param   phLdrMod        Where to store the handle to the loaded module.
     295 * @param   pszFilename Image filename.
     296 * @param   fFlags      Reserved, MBZ.
     297 * @param   enmArch     CPU architecture specifier for the image to be loaded.
     298 * @param   phLdrMod    Where to store the handle to the loaded module.
    281299 * @remark  Primarily for testing the loader.
    282300 */
    283 RTDECL(int) RTLdrOpenkLdr(const char *pszFilename, PRTLDRMOD phLdrMod)
     301RTDECL(int) RTLdrOpenkLdr(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod)
    284302{
    285303#ifdef LDR_WITH_KLDR
    286     LogFlow(("RTLdrOpenkLdr: pszFilename=%p:{%s} phLdrMod=%p\n",
    287              pszFilename, pszFilename, phLdrMod));
     304    LogFlow(("RTLdrOpenkLdr: pszFilename=%p:{%s} fFlags=%#x enmArch=%d phLdrMod=%p\n",
     305             pszFilename, pszFilename, fFlags, enmArch, phLdrMod));
     306
     307    /*
     308     * Resolve RTLDRARCH_HOST.
     309     */
     310    if (enmArch == RTLDRARCH_HOST)
     311# if   defined(RT_ARCH_AMD64)
     312        enmArch = RTLDRARCH_AMD64;
     313# elif defined(RT_ARCH_X86)
     314        enmArch = RTLDRARCH_X86_32;
     315# else
     316        enmArch = RTLDRARCH_WHATEVER;
     317# endif
    288318
    289319    /*
     
    294324    if (RT_SUCCESS(rc))
    295325    {
    296         rc = rtldrkLdrOpen(pReader, phLdrMod);
     326        rc = rtldrkLdrOpen(pReader, fFlags, enmArch, phLdrMod);
    297327        if (RT_SUCCESS(rc))
    298328        {
     
    307337
    308338#else
    309     return RTLdrOpen(pszFilename, phLdrMod);
     339    return RTLdrOpen(pszFilename, fFlags, enmArch, phLdrMod);
    310340#endif
    311341}
  • trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp

    r13837 r16933  
    944944 * @param   pFileHdr    Pointer to the file header that needs validating.
    945945 * @param   pszLogName  The log name to  prefix the errors with.
    946  */
    947 int rtldrPEValidateFileHeader(PIMAGE_FILE_HEADER pFileHdr, const char *pszLogName)
     946 * @param   penmArch    Where to store the CPU architecture.
     947 */
     948int rtldrPEValidateFileHeader(PIMAGE_FILE_HEADER pFileHdr, const char *pszLogName, PRTLDRARCH penmArch)
    948949{
    949950    size_t cbOptionalHeader;
     
    952953        case IMAGE_FILE_MACHINE_I386:
    953954            cbOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER32);
     955            *penmArch = RTLDRARCH_X86_32;
    954956            break;
    955957        case IMAGE_FILE_MACHINE_AMD64:
    956958            cbOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER64);
     959            *penmArch = RTLDRARCH_AMD64;
    957960            break;
    958961
     
    960963            Log(("rtldrPEOpen: %s: Unsupported Machine=%#x\n",
    961964                 pszLogName, pFileHdr->Machine));
     965            *penmArch = RTLDRARCH_INVALID;
    962966            return VERR_BAD_EXE_FORMAT;
    963967    }
     
    14171421 * @returns iprt status code.
    14181422 * @param   pReader     The loader reader instance which will provide the raw image bits.
     1423 * @param   fFlags      Reserved, MBZ.
     1424 * @param   enmArch     Architecture specifier.
    14191425 * @param   offNtHdrs   The offset of the NT headers (where you find "PE\0\0").
    14201426 * @param   phLdrMod    Where to store the handle.
    14211427 */
    1422 int rtldrPEOpen(PRTLDRREADER pReader, RTFOFF offNtHdrs, PRTLDRMOD phLdrMod)
     1428int rtldrPEOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF offNtHdrs, PRTLDRMOD phLdrMod)
    14231429{
    14241430    /*
     
    14291435    if (RT_FAILURE(rc))
    14301436        return rc;
     1437    RTLDRARCH enmArchImage;
    14311438    const char *pszLogName = pReader->pfnLogName(pReader);
    1432     rc = rtldrPEValidateFileHeader(&FileHdr, pszLogName);
     1439    rc = rtldrPEValidateFileHeader(&FileHdr, pszLogName, &enmArchImage);
    14331440    if (RT_FAILURE(rc))
    14341441        return rc;
     1442
     1443    /*
     1444     * Match the CPU architecture.
     1445     */
     1446    if (    enmArch != RTLDRARCH_WHATEVER
     1447        &&  enmArch != enmArchImage)
     1448        return VERR_LDR_ARCH_MISMATCH;
    14351449
    14361450    /*
  • trunk/src/VBox/Runtime/common/ldr/ldrkStuff.cpp

    r16439 r16933  
    636636 * @returns iprt status code.
    637637 * @param   pReader     The loader reader instance which will provide the raw image bits.
     638 * @param   fFlags      Reserved, MBZ.
     639 * @param   enmArch     CPU architecture specifier for the image to be loaded.
    638640 * @param   phLdrMod    Where to store the handle.
    639641 */
    640 int rtldrkLdrOpen(PRTLDRREADER pReader, PRTLDRMOD phLdrMod)
    641 {
     642int rtldrkLdrOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod)
     643{
     644    /* Convert enmArch to k-speak. */
     645    KCPUARCH enmCpuArch;
     646    switch (enmArch)
     647    {
     648        case RTLDRARCH_WHATEVER:
     649            enmCpuArch = KCPUARCH_UNKNOWN;
     650            break;
     651        case RTLDRARCH_X86_32:
     652            enmCpuArch = KCPUARCH_X86_32;
     653            break;
     654        case RTLDRARCH_AMD64:
     655            enmCpuArch = KCPUARCH_AMD64;
     656            break;
     657        default:
     658            return VERR_INVALID_PARAMETER;
     659    }
     660
    642661    /* Create a rtkldrRdr instance. */
    643662    PRTKLDRRDR pRdr = (PRTKLDRRDR)RTMemAllocZ(sizeof(*pRdr));
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