VirtualBox

Changeset 74640 in vbox


Ignore:
Timestamp:
Oct 6, 2018 7:14:10 PM (6 years ago)
Author:
vboxsync
Message:

IPRT: More adjustments to the LX and Mach-O loader code from kStuff. bugref:9232

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

Legend:

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

    r74638 r74640  
    152152static int kldrModLXDoIterData2Unpacking(uint8_t *pbDst, const uint8_t *pbSrc, int cbSrc);
    153153static void kLdrModLXMemCopyW(uint8_t *pbDst, const uint8_t *pbSrc, int cb);
     154static int kldrModLXDoForwarderQuery(PKLDRMODLX pModLX, const struct e32_entry *pEntry,
     155                                     PFNRTLDRIMPORT pfnGetForwarder, void *pvUser, PRTLDRADDR puValue, uint32_t *pfKind);
     156#if 0
    154157static int kldrModLXDoProtect(PKLDRMODLX pModLX, void *pvBits, unsigned fUnprotectOrProtect);
    155158static int kldrModLXDoCallDLL(PKLDRMODLX pModLX, void *pvMapping, unsigned uOp, uintptr_t uHandle);
    156 static int kldrModLXDoForwarderQuery(PKLDRMODLX pModLX, const struct e32_entry *pEntry,
    157                                      PFNRTLDRIMPORT pfnGetForwarder, void *pvUser, PRTLDRADDR puValue, uint32_t *pfKind);
     159static int32_t kldrModLXDoCall(uintptr_t uEntrypoint, uintptr_t uHandle, uint32_t uOp, void *pvReserved);
     160#endif
    158161static int kldrModLXDoLoadFixupSection(PKLDRMODLX pModLX);
    159 static int32_t kldrModLXDoCall(uintptr_t uEntrypoint, uintptr_t uHandle, uint32_t uOp, void *pvReserved);
    160162static int kldrModLXDoReloc(uint8_t *pbPage, int off, RTLDRADDR PageAddress, const struct r32_rlc *prlc,
    161163                            int iSelector, RTLDRADDR uValue, uint32_t fKind);
     
    343345     */
    344346    rc = pRdr->pfnRead(pRdr, (void *)pModLX->pbLoaderSection, pModLX->Hdr.e32_ldrsize, pModLX->Hdr.e32_objtab + pModLX->offHdr);
    345     if (rc)
     347    if (RT_FAILURE(rc))
    346348        return rc;
    347349    ((uint8_t *)pModLX->pbLoaderSectionLast)[1] = 0;
     
    568570    {
    569571        rc = kldrModLXDoNameLookup(pModLX, pchSymbol, cchSymbol, &iSymbol);
    570         if (rc)
     572        if (RT_FAILURE(rc))
    571573            return rc;
    572574    }
     
    644646                         + offObject
    645647                         + pModLX->aSegments[pBundle->b32_obj - 1].RVA;
    646             return 0;
     648            return VINF_SUCCESS;
    647649        }
    648650
     
    680682 * Do name lookup.
    681683 *
    682  * @returns See kLdrModQuerySymbol.
     684 * @returns IPRT status code.
    683685 * @param   pModLX      The module to lookup the symbol in.
    684686 * @param   pchSymbol   The symbol to lookup.
     
    716718
    717719    *piSymbol = *(const uint16_t *)(pbName + 1 + *pbName);
    718     return 0;
     720    return VINF_SUCCESS;
    719721}
    720722
     
    766768 * Deal with a forwarder entry.
    767769 *
    768  * @returns See kLdrModQuerySymbol.
     770 * @returns IPRT status code.
    769771 * @param   pModLX          The PE module interpreter instance.
    770772 * @param   pEntry          The forwarder entry.
     
    811813        {
    812814            rc = kldrModLXDoLoadFixupSection(pModLX);
    813             if (rc)
     815            if (RT_FAILURE(rc))
    814816                return rc;
    815817        }
     
    893895 * The fixup section isn't loaded until it's accessed. It's also freed by kLdrModDone().
    894896 *
    895  * @returns 0 on success, non-zero kLdr or native status code on failure.
     897 * @returns IPRT status code.
    896898 * @param   pModLX          The PE module interpreter instance.
    897899 */
     
    10491051                        szName[*pbName] = '\0';
    10501052                        rc = pfnCallback(pMod, szName, iOrdinal, uValue, /*fKind,*/ pvUser);
    1051                         if (rc)
     1053                        if (rc != VINF_SUCCESS)
    10521054                            return rc;
    10531055
     
    10711073                        szName[*pbName] = '\0';
    10721074                        rc = pfnCallback(pMod, szName, iOrdinal, uValue, /*fKind,*/ pvUser);
    1073                         if (rc)
     1075                        if (rc != VINF_SUCCESS)
    10741076                            return rc;
    10751077
     
    10861088                    RT_NOREF(fKind);
    10871089                    rc = pfnCallback(pMod, NULL /*pszName*/, iOrdinal, uValue, /*fKind,*/ pvUser);
    1088                     if (rc)
     1090                    if (rc != VINF_SUCCESS)
    10891091                        return rc;
    10901092                }
     
    11101112    }
    11111113
    1112     return 0;
     1114    return VINF_SUCCESS;
    11131115}
    11141116
     
    11671169    {
    11681170        rc = kldrModLXDoLoadFixupSection(pModLX);
    1169         if (rc)
     1171        if (RT_FAILURE(rc))
    11701172            return rc;
    11711173    }
     
    11871189        memcpy(pszName, pb + 1, *pb);
    11881190        pszName[*pb] = '\0';
    1189         rc = 0;
     1191        rc = VINF_SUCCESS;
    11901192    }
    11911193    else
     
    12331235    else
    12341236    {
    1235         pStackInfo->Address = NIL_RTLDRADDR;
     1237        pSt0ackInfo->Address = NIL_RTLDRADDR;
    12361238        pStackInfo->LinkAddress = NIL_RTLDRADDR;
    12371239    }
     
    12391241    pStackInfo->cbStackThread = 0;
    12401242
    1241     return 0;
     1243    return VINF_SUCCESS;
    12421244}
    12431245
     
    12581260        ? BaseAddress + pModLX->aSegments[pModLX->Hdr.e32_startobj - 1].RVA + pModLX->Hdr.e32_eip
    12591261        : NIL_RTLDRADDR;
    1260     return 0;
     1262    return VINF_SUCCESS;
    12611263}
    12621264
     
    12781280     */
    12791281    if (kldrModLXHasDbgInfo(pMod, pvBits))
    1280         return 0;
     1282        return VINF_SUCCESS;
    12811283#if 0
    12821284    /*
     
    12861288#endif
    12871289
    1288     return 0;
     1290    return VINF_SUCCESS;
    12891291}
    12901292
     
    13021304        ||  !pModLX->Hdr.e32_debuglen)
    13031305        return VERR_NOT_FOUND;
    1304     return 0;
     1306    return VINF_SUCCESS;
    13051307}
    13061308
     
    13361338    }
    13371339    rc = kHlpPageAlloc(&pvBase, pModLX->cbMapped, KPROT_EXECUTE_READWRITE, fFixed);
    1338     if (rc)
     1340    if (RT_FAILURE(rc))
    13391341        return rc;
    13401342
     
    13431345     */
    13441346    rc = kldrModLXDoLoadBits(pModLX, pvBase);
    1345     if (!rc)
     1347    if (RT_SUCCESS(rc))
    13461348        rc = kldrModLXDoProtect(pModLX, pvBase, 0 /* protect */);
    1347     if (!rc)
     1349    if (RT_SUCCESS(rc))
    13481350    {
    13491351        uint32_t i;
     
    13651367 * Loads the LX pages into the specified memory mapping.
    13661368 *
    1367  * @returns 0 on success.
    1368  * @returns non-zero kLdr or OS status code on failure.
     1369 * @returns IPRT status code.
    13691370 *
    13701371 * @param   pModLX  The LX module interpreter instance.
     
    13751376    const PRTLDRREADER pRdr = pModLX->Core.pReader;
    13761377    uint8_t *pbTmpPage = NULL;
    1377     int rc = 0;
     1378    int rc = VINF_SUCCESS;
    13781379    uint32_t i;
    13791380
     
    13911392         * Iterate the page map pages.
    13921393         */
    1393         for (iPage = 0; !rc && iPage < pObj->o32_mapsize; iPage++, pbPage += OBJPAGELEN)
     1394        for (iPage = 0; RT_SUCCESS(rc) && iPage < pObj->o32_mapsize; iPage++, pbPage += OBJPAGELEN)
    13941395        {
    13951396            const struct o32_map *pMap = &pModLX->paPageMappings[iPage + pObj->o32_pagemap - 1];
     
    14291430                    rc = pRdr->pfnRead(pRdr, pbTmpPage, pMap->o32_pagesize,
    14301431                                       pModLX->Hdr.e32_datapage + (pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift));
    1431                     if (rc)
     1432                    if (RT_FAILURE(rc))
    14321433                        break;
    14331434                    memset(pbTmpPage + pMap->o32_pagesize, 0, 4);
     
    14531454            }
    14541455        }
    1455         if (rc)
     1456        if (RT_FAILURE(rc))
    14561457            break;
    14571458
     
    14721473 * Unpacks iterdata (aka EXEPACK).
    14731474 *
    1474  * @returns 0 on success, non-zero kLdr status code on failure.
     1475 * @returns IPRT status code.
    14751476 * @param   pbDst       Where to put the uncompressed data. (Assumes OBJPAGELEN size.)
    14761477 * @param   pbSrc       The compressed source data.
     
    15361537        memset(pbDst, 0, cbDst);
    15371538
    1538     return 0;
     1539    return VINF_SUCCESS;
    15391540}
    15401541
     
    15431544 * Unpacks iterdata (aka EXEPACK).
    15441545 *
    1545  * @returns 0 on success, non-zero kLdr status code on failure.
     1546 * @returns IPRT status code.
    15461547 * @param   pbDst       Where to put the uncompressed data. (Assumes OBJPAGELEN size.)
    15471548 * @param   pbSrc       The compressed source data.
     
    17511752        memset(pbDst, 0, cbDst);
    17521753
    1753     return 0;
     1754    return VINF_SUCCESS;
    17541755}
    17551756
     
    18021803 * Unprotects or protects the specified image mapping.
    18031804 *
    1804  * @returns 0 on success.
    1805  * @returns non-zero kLdr or OS status code on failure.
     1805 * @returns IPRT status code.
    18061806 *
    18071807 * @param   pModLX  The LX module interpreter instance.
     
    18601860
    18611861        rc = kHlpPageProtect(pv, pModLX->aSegments[i].cbMapped, enmProt);
    1862         if (rc)
     1862        if (RT_FAILURE(rc))
    18631863            break;
    18641864
     
    18661866    }
    18671867
    1868     return 0;
     1868    return VINF_SUCCESS;
    18691869}
    18701870
     
    19061906        && pModLX->pvMapping)
    19071907        return KLDR_ERR_NOT_MAPPED;
    1908     return 0;
     1908    return VINF_SUCCESS;
    19091909}
    19101910
     
    19361936     */
    19371937    rc = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 1 /* unprotect */);
    1938     if (rc)
     1938    if (RT_FAILURE(rc))
    19391939        return rc;
    19401940
     
    19481948     */
    19491949    rc2 = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 0 /* protect */);
    1950     if (!rc && rc2)
     1950    if (RT_SUCCESS(rc) && RT_FAILURE(rc2))
    19511951        rc = rc2;
    19521952    return rc;
     
    19701970     */
    19711971    rc = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 1 /* unprotect */);
    1972     if (rc)
     1972    if (RT_FAILURE(rc))
    19731973        return rc;
    19741974
     
    19831983     */
    19841984    rc2 = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 0 /* protect */);
    1985     if (!rc && rc2)
     1985    if (RT_SUCCESS(rc) && RT_FAILURE(rc2))
    19861986        rc = rc2;
    19871987    return rc;
     
    20112011        rc = kldrModLXDoCallDLL(pModLX, pvMapping, 0 /* attach */, uHandle);
    20122012    else
    2013         rc = 0;
     2013        rc = VINF_SUCCESS;
    20142014    return rc;
    20152015}
     
    20352035    if (    !pModLX->Hdr.e32_startobj
    20362036        ||  pModLX->Hdr.e32_startobj > pModLX->Hdr.e32_objcnt)
    2037         return 0;
     2037        return VINF_SUCCESS;
    20382038
    20392039    /*
     
    20452045                         uHandle, uOp, NULL);
    20462046    if (rc)
    2047         rc = 0;
     2047        rc = VINF_SUCCESS;
    20482048    else if (uOp == 0 /* attach */)
    20492049        rc = KLDR_ERR_MODULE_INIT_FAILED;
    20502050    else /* detach: ignore failures */
    2051         rc = 0;
     2051        rc = VINF_SUCCESS;
    20522052    return rc;
    20532053}
     
    21382138        kldrModLXDoCallDLL(pModLX, pvMapping, 1 /* detach */, uHandle);
    21392139
    2140     return 0;
     2140    return VINF_SUCCESS;
    21412141}
    21422142
     
    21502150    RT_NOREF(uHandle);
    21512151    RT_NOREF(fAttachingOrDetaching);
    2152     return 0;
     2152    return VINF_SUCCESS;
    21532153}
    21542154
     
    22042204        &&  NewBaseAddress == pModLX->paObjs[0].o32_base
    22052205        &&  !pModLX->Hdr.e32_impmodcnt)
    2206         return 0;
     2206        return VINF_SUCCESS;
    22072207
    22082208    /*
     
    22122212    {
    22132213        rc = kldrModLXDoLoadFixupSection(pModLX);
    2214         if (rc)
     2214        if (RT_FAILURE(rc))
    22152215            return rc;
    22162216    }
     
    22292229         * Iterate the page map pages.
    22302230         */
    2231         for (iPage = 0, rc = 0; !rc && iPage < pObj->o32_mapsize; iPage++, pbPage += OBJPAGELEN, PageAddress += OBJPAGELEN)
     2231        for (iPage = 0, rc = VINF_SUCCESS;
     2232             RT_SUCCESS(rc) && iPage < pObj->o32_mapsize;
     2233             iPage++, pbPage += OBJPAGELEN, PageAddress += OBJPAGELEN)
    22322234        {
    22332235            const uint8_t * const   pbFixupRecEnd = pModLX->pbFixupRecs + pModLX->paoffPageFixups[iPage + pObj->o32_pagemap];
     
    22522254                union _rel
    22532255                {
    2254                     const uint8_t *             pb;
     2256
     2257                    const uint8_t          *pb;
    22552258                    const struct r32_rlc   *prlc;
    22562259                } u;
     
    23562359                        /* resolve it. */
    23572360                        rc = pfnGetImport(pMod, szImpModule, NULL, iSymbol, &uValue, /*&fKind,*/ pvUser);
    2358                         if (rc)
     2361                        if (RT_FAILURE(rc))
    23592362                            return rc;
    23602363                        iSelector = -1;
     
    24132416                        /* resolve it. */
    24142417                        rc = pfnGetImport(pMod, szImpModule, szSymbol, UINT32_MAX, &uValue, /*&fKind,*/ pvUser);
    2415                         if (rc)
     2418                        if (RT_FAILURE(rc))
    24162419                            return rc;
    24172420                        iSelector = -1;
     
    24632466                        /* generic */
    24642467                        rc = kldrModLXDoReloc(pbPage, off, PageAddress, u.prlc, iSelector, uValue, fKind);
    2465                         if (rc)
     2468                        if (RT_FAILURE(rc))
    24662469                            return rc;
    24672470                    }
     
    24832486                            {
    24842487                                rc = kldrModLXDoReloc(pbPage, off, PageAddress, u.prlc, iSelector, uValue, fKind);
    2485                                 if (rc)
     2488                                if (RT_FAILURE(rc))
    24862489                                    return rc;
    24872490                            }
     
    24982501                            {
    24992502                                rc = kldrModLXDoReloc(pbPage, off, PageAddress, u.prlc, iSelector, uValue, fKind);
    2500                                 if (rc)
     2503                                if (RT_FAILURE(rc))
    25012504                                    return rc;
    25022505                            }
     
    25082511                        {
    25092512                            rc = kldrModLXDoReloc(pbPage, *poffSrc++, PageAddress, u.prlc, iSelector, uValue, fKind);
    2510                             if (rc)
     2513                            if (RT_FAILURE(rc))
    25112514                                return rc;
    25122515                        }
     
    25242527    }
    25252528
    2526     return 0;
     2529    return VINF_SUCCESS;
    25272530}
    25282531
     
    25342537 * are dealt with seperately.
    25352538 *
    2536  * @returns 0 on success, non-zero kLdr status code on failure.
     2539 * @returns IPRT status code.
    25372540 * @param   pbPage      The page in which to apply the fixup.
    25382541 * @param   off         Page relative offset of where to apply the offset.
     
    25542557            uint16_t    off;
    25552558            uint16_t    Sel;
    2556         }           Far16;
     2559        }               Far16;
    25572560        struct
    25582561        {
    25592562            uint32_t    off;
    25602563            uint16_t    Sel;
    2561         }           Far32;
    2562     }               uData;
     2564        }               Far32;
     2565    }                   uData;
    25632566#pragma pack()
    25642567    const uint8_t      *pbSrc;
     
    26342637    }
    26352638
    2636     return 0;
     2639    return VINF_SUCCESS;
    26372640}
    26382641
     
    26472650    for (uint32_t iSeg = 0; iSeg < cSegments; iSeg++)
    26482651    {
    2649         RTLDRSEG Seg = pThis->aSegments[iSeg];
    2650         int rc = pfnCallback(pMod, &Seg, pvUser);
     2652        int rc = pfnCallback(pMod, &pThis->aSegments[iSeg], pvUser);
    26512653        if (rc != VINF_SUCCESS)
    26522654            return rc;
     
    27532755static DECLCALLBACK(int) rtldrLX_ReadDbgInfo(PRTLDRMODINTERNAL pMod, uint32_t iDbgInfo, RTFOFF off, size_t cb, void *pvBuf)
    27542756{
    2755     //PKLDRMODLX pThis = RT_FROM_MEMBER(pMod, KLDRMODLX, Core);
    2756     RT_NOREF(pMod, iDbgInfo, off, cb, pvBuf);
     2757    PKLDRMODLX pThis = RT_FROM_MEMBER(pMod, KLDRMODLX, Core);
     2758    if (iDbgInfo == 0)
     2759        return pThis->Core.pReader->pfnRead(pThis->Core.pReader, pvBuf, cb, off);
    27572760    return VERR_OUT_OF_RANGE;
    27582761}
    27592762
    27602763
    2761 /** @interface_method_impl{RTLDROPS,pfnQueryProp} */
     2764/**
     2765 * @interface_method_impl{RTLDROPS,pfnQueryProp}
     2766 */
    27622767static DECLCALLBACK(int) rtldrLX_QueryProp(PRTLDRMODINTERNAL pMod, RTLDRPROP enmProp, void const *pvBits,
    27632768                                          void *pvBuf, size_t cbBuf, size_t *pcbRet)
     
    28212826    rtldrLX_SegOffsetToRva,
    28222827    rtldrLX_RvaToSegOffset,
    2823     NULL,
     2828    rtldrLX_ReadDbgInfo,
    28242829    rtldrLX_QueryProp,
    28252830    NULL /*pfnVerifySignature*/,
     
    28532858            pThis->Core.u32Magic = RTLDRMOD_MAGIC;
    28542859            *phLdrMod = &pThis->Core;
    2855             return 0;
     2860            return VINF_SUCCESS;
    28562861        }
    28572862        rc = VERR_LDR_ARCH_MISMATCH;
  • trunk/src/VBox/Runtime/common/ldr/ldrMachO.cpp

    r74638 r74640  
    342342    RTLDRADDR   LinkAddress  = NIL_RTLDRADDR;
    343343    uint8_t     uEffFileType = 0;
    344     if (!rc)
     344    if (RT_SUCCESS(rc))
    345345        rc = kldrModMachOPreParseLoadCommands(pbLoadCommands, &s.Hdr32, pRdr, offImage, fOpenFlags,
    346346                                              &cSegments, &cSections, &cbStringPool, &fCanLoad, &LinkAddress, &uEffFileType);
    347     if (rc)
     347    if (RT_FAILURE(rc))
    348348    {
    349349        RTMemFree(pbLoadCommands);
     
    475475     */
    476476    rc = kldrModMachOParseLoadCommands(pThis, (char *)pThis + cbModAndSegs, cbStringPool);
    477     if (rc)
    478         return rc;
    479477
    480478    /*
    481479     * We're done.
    482480     */
    483     return 0;
     481    return rc;
    484482}
    485483
     
    505503 * debug enumeration callback API.
    506504 *
    507  * @returns 0 on success.
    508  * @returns VERR_LDRMACHO_* on failure.
     505 * @returns IPRT status code.
    509506 * @param   pbLoadCommands  The load commands to parse.
    510507 * @param   pHdr            The header.
     
    579576                section_32_t   *pSect         = pFirstSect;
    580577                uint32_t        cSectionsLeft = pSrcSeg->nsects;
    581                 uint64_t            offSect       = 0;
     578                uint64_t        offSect       = 0;
    582579
    583580                /* Convert and verify the segment. */
     
    10511048    *pcbStringPool = (uint32_t)cbStringPool;
    10521049
    1053     return 0;
     1050    return VINF_SUCCESS;
    10541051}
    10551052
     
    10601057 * This fills in the segment table and perhaps some other properties.
    10611058 *
    1062  * @returns 0 on success.
    1063  * @returns VERR_LDRMACHO_* on failure.
    1064  * @param   pThis       The module.
     1059 * @returns IPRT status code.
     1060 * @param   pThis           The module.
    10651061 * @param   pbStringPool    The string pool
    10661062 * @param   cbStringPool    The size of the string pool.
     
    11051101
    11061102                /* Adds a segment, used by the macro below and thus shared with the 64-bit segment variant. */
    1107                 #define NEW_SEGMENT(a_cBits, a_achName1, a_fObjFile, a_achName2, a_SegAddr, a_cbSeg, a_fFileBits, a_offFile, a_cbFile) \
     1103#define NEW_SEGMENT(a_cBits, a_achName1, a_fObjFile, a_achName2, a_SegAddr, a_cbSeg, a_fFileBits, a_offFile, a_cbFile) \
    11081104                do { \
    11091105                    pDstSeg->SegInfo.pszName = pbStringPool; \
     
    11461142
    11471143                /* Closes the new segment - part of NEW_SEGMENT. */
    1148                 #define CLOSE_SEGMENT() \
     1144#define CLOSE_SEGMENT() \
    11491145                do { \
    11501146                    pDstSeg->cSections = (uint32_t)(pSectExtra - pDstSeg->paSections); \
     
    11541150
    11551151                /* Shared with the 64-bit variant. */
    1156                 #define ADD_SEGMENT_AND_ITS_SECTIONS(a_cBits) \
     1152#define ADD_SEGMENT_AND_ITS_SECTIONS(a_cBits) \
    11571153                do { \
    11581154                    bool fAddSegOuter = false; \
     
    11751171                        && strcmp(pSrcSeg->segname, "__CTF") ) \
    11761172                    { \
    1177                         NEW_SEGMENT(a_cBits, pSrcSeg->segname, false /*a_fObjFile*/, 0 /*a_achName2*/, \
     1173                        NEW_SEGMENT(a_cBits, pSrcSeg->segname, false /*a_fObjFile*/, "" /*a_achName2*/, \
    11781174                                    pSrcSeg->vmaddr, pSrcSeg->vmsize, \
    11791175                                    pSrcSeg->filesize != 0, pSrcSeg->fileoff, pSrcSeg->filesize); \
     
    14091405    }
    14101406
    1411     return 0;
     1407    return VINF_SUCCESS;
    14121408}
    14131409
     
    14191415{
    14201416    PKLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);
    1421     int rc = 0;
     1417    int rc = VINF_SUCCESS;
    14221418    KLDRMODMACHO_ASSERT(!pThis->pvMapping);
    14231419
     
    14541450 * Gets the right base address.
    14551451 *
    1456  * @returns 0 on success.
    1457  * @returns A non-zero status code if the BaseAddress isn't right.
    14581452 * @param   pThis       The interpreter module instance
    14591453 * @param   pBaseAddress    The base address, IN & OUT. Optional.
    14601454 */
    1461 static int kldrModMachOAdjustBaseAddress(PKLDRMODMACHO pThis, PRTLDRADDR pBaseAddress)
     1455static void kldrModMachOAdjustBaseAddress(PKLDRMODMACHO pThis, PRTLDRADDR pBaseAddress)
    14621456{
    14631457    /*
     
    14661460    if (*pBaseAddress == RTLDR_BASEADDRESS_LINK)
    14671461        *pBaseAddress = pThis->LinkAddress;
    1468     return 0;
    14691462}
    14701463
     
    14761469 * and segments.  This function checks for these and returns the right value.
    14771470 *
    1478  * @returns 0 or VERR_SYMBOL_NOT_FOUND.
    1479  * @param   pThis           The interpreter module instance.
     1471 * @returns VINF_SUCCESS or VERR_SYMBOL_NOT_FOUND.
     1472 * @param   pThis               The interpreter module instance.
    14801473 * @param   pchSymbol           The symbol.
    14811474 * @param   cchSymbol           The length of the symbol.
     
    16111604        *puValue = uValue;
    16121605
    1613     return 0;
     1606    return VINF_SUCCESS;
    16141607}
    16151608
     
    16331626     * Resolve defaults.
    16341627     */
    1635     int rc = kldrModMachOAdjustBaseAddress(pThis, &BaseAddress);
    1636     if (rc)
    1637         return rc;
     1628    kldrModMachOAdjustBaseAddress(pThis, &BaseAddress);
    16381629
    16391630    /*
     
    16471638     * Take action according to file type.
    16481639     */
     1640    int rc;
    16491641    if (   pThis->Hdr.filetype == MH_OBJECT
    16501642        || pThis->Hdr.filetype == MH_EXECUTE /** @todo dylib, execute, dsym: symbols */
     
    16551647    {
    16561648        rc = kldrModMachOLoadObjSymTab(pThis);
    1657         if (!rc)
     1649        if (RT_SUCCESS(rc))
    16581650        {
    16591651            if (    pThis->Hdr.magic == IMAGE_MACHO32_SIGNATURE
     
    16961688 * Lookup a symbol in a 32-bit symbol table.
    16971689 *
    1698  * @returns See kLdrModQuerySymbol.
     1690 * @returns IPRT status code.
    16991691 * @param   pThis
    17001692 * @param   paSyms      Pointer to the symbol table.
     
    18171809    }
    18181810
    1819     return 0;
     1811    return VINF_SUCCESS;
    18201812}
    18211813
     
    18241816 * Lookup a symbol in a 64-bit symbol table.
    18251817 *
    1826  * @returns See kLdrModQuerySymbol.
     1818 * @returns IPRT status code.
    18271819 * @param   pThis
    18281820 * @param   paSyms      Pointer to the symbol table.
     
    19451937    }
    19461938
    1947     return 0;
     1939    return VINF_SUCCESS;
    19481940}
    19491941
     
    19561948{
    19571949    PKLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);
     1950    RT_NOREF(pvBits);
     1951
     1952    /*
     1953     * Resolve defaults.
     1954     */
     1955    kldrModMachOAdjustBaseAddress(pThis, &BaseAddress);
     1956
     1957    /*
     1958     * Take action according to file type.
     1959     */
    19581960    int rc;
    1959     RT_NOREF(pvBits);
    1960 
    1961     /*
    1962      * Resolve defaults.
    1963      */
    1964     rc  = kldrModMachOAdjustBaseAddress(pThis, &BaseAddress);
    1965     if (rc)
    1966         return rc;
    1967 
    1968     /*
    1969      * Take action according to file type.
    1970      */
    19711961    if (   pThis->Hdr.filetype == MH_OBJECT
    19721962        || pThis->Hdr.filetype == MH_EXECUTE /** @todo dylib, execute, dsym: symbols */
     
    19771967    {
    19781968        rc = kldrModMachOLoadObjSymTab(pThis);
    1979         if (!rc)
     1969        if (RT_SUCCESS(rc))
    19801970        {
    19811971            if (    pThis->Hdr.magic == IMAGE_MACHO32_SIGNATURE
     
    20001990 * Enum a 32-bit symbol table.
    20011991 *
    2002  * @returns See kLdrModQuerySymbol.
     1992 * @returns IPRT status code.
    20031993 * @param   pThis
    20041994 * @param   paSyms      Pointer to the symbol table.
     
    21022092         */
    21032093        rc = pfnCallback(&pThis->Core, psz, iSym, uValue/*, fKind*/, pvUser);
    2104         if (rc)
     2094        if (rc != VINF_SUCCESS)
    21052095            return rc;
    21062096    }
    2107     return 0;
     2097    return VINF_SUCCESS;
    21082098}
    21092099
     
    21122102 * Enum a 64-bit symbol table.
    21132103 *
    2114  * @returns See kLdrModQuerySymbol.
     2104 * @returns IPRT status code.
    21152105 * @param   pThis
    21162106 * @param   paSyms      Pointer to the symbol table.
     
    22142204         */
    22152205        rc = pfnCallback(&pThis->Core, psz, iSym, uValue/*, fKind*/, pvUser);
    2216         if (rc)
     2206        if (rc != VINF_SUCCESS)
    22172207            return rc;
    22182208    }
    2219     return 0;
     2209    return VINF_SUCCESS;
    22202210}
    22212211
     
    22472237
    22482238    if (pThis->Hdr.filetype == MH_OBJECT)
    2249         return 0;
     2239        return VINF_SUCCESS;
    22502240
    22512241    /* later */
    2252     return 0;
     2242    return VINF_SUCCESS;
    22532243}
    22542244
     
    22672257    /* later */
    22682258
    2269     return 0;
    2270 }
    2271 
    2272 #endif
     2259    return VINF_SUCCESS;
     2260}
    22732261
    22742262
     
    22842272     */
    22852273    rc = kldrModMachOBitsAndBaseAddress(pThis, NULL, &BaseAddress);
    2286     if (rc)
     2274    if (RT_FAILURE(rc))
    22872275        return rc;
    22882276
     
    22992287    RT_NOREF(pMod);
    23002288#endif
    2301     return 0;
    2302 }
    2303 
     2289    return VINF_SUCCESS;
     2290}
     2291
     2292#endif
    23042293
    23052294/** @copydoc kLdrModQueryImageUuid */
     
    23692358        ||  !pThis->Hdrs.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress)
    23702359        return KLDR_ERR_NO_DEBUG_INFO;
    2371     return 0;
     2360    return VINF_SUCCESS;
    23722361#else
    23732362    RT_NOREF(pMod);
     
    24132402    /* try do the prepare */
    24142403    rc = kRdrMap(pMod->pRdr, &pvBase, pMod->cSegments, pMod->aSegments, fFixed);
    2415     if (rc)
     2404    if (RT_FAILURE(rc))
    24162405        return rc;
    24172406
     
    24262415    pThis->pvMapping = pvBase;
    24272416
    2428     return 0;
     2417    return VINF_SUCCESS;
    24292418}
    24302419
     
    24472436     */
    24482437    rc = kRdrUnmap(pMod->pRdr, pThis->pvMapping, pMod->cSegments, pMod->aSegments);
    2449     if (rc)
     2438    if (RT_FAILURE(rc))
    24502439        return rc;
    24512440
     
    24572446        pMod->aSegments[i].MapAddress = 0;
    24582447
    2459     return 0;
     2448    return VINF_SUCCESS;
    24602449}
    24612450
     
    24722461        && !pThis->pvMapping )
    24732462        return KLDR_ERR_NOT_MAPPED;
    2474     return 0;
     2463    return VINF_SUCCESS;
    24752464}
    24762465
     
    25172506     */
    25182507    rc = kRdrProtect(pMod->pRdr, pThis->pvMapping, pMod->cSegments, pMod->aSegments, 1 /* unprotect */);
    2519     if (rc)
     2508    if (RT_FAILURE(rc))
    25202509        return rc;
    25212510
     
    25302519     */
    25312520    rc2 = kRdrProtect(pMod->pRdr, pThis->pvMapping, pMod->cSegments, pMod->aSegments, 0 /* protect */);
    2532     if (!rc && rc2)
     2521    if (RT_SUCCESS(rc) && RT_FAILURE(rc2)
    25332522        rc = rc2;
    25342523    return rc;
     
    25402529 * MH_OBJECT: Resolves undefined symbols (imports).
    25412530 *
    2542  * @returns 0 on success, non-zero kLdr status code on failure.
    2543  * @param   pThis       The Mach-O module interpreter instance.
     2531 * @returns IPRT status code.
     2532 * @param   pThis           The Mach-O module interpreter instance.
    25442533 * @param   pfnGetImport    The callback for resolving an imported symbol.
    25452534 * @param   pvUser          User argument to the callback.
     
    25492538    const uint32_t cSyms = pThis->cSymbols;
    25502539    uint32_t iSym;
    2551     int rc;
    25522540
    25532541    /*
    25542542     * Ensure that we've got the symbol table and section fixups handy.
    25552543     */
    2556     rc = kldrModMachOLoadObjSymTab(pThis);
    2557     if (rc)
     2544    int rc = kldrModMachOLoadObjSymTab(pThis);
     2545    if (RT_FAILURE(rc))
    25582546        return rc;
    25592547
     
    25962584
    25972585                /* Ask the user for an address to the symbol. */
    2598                 if (rc)
     2586                if (RT_FAILURE_NP(rc))
    25992587                    rc = pfnGetImport(&pThis->Core, NULL /*pszModule*/, pszSymbol, iSym, &Value/*, &fKind*/, pvUser);
    2600                 if (rc)
     2588                if (RT_FAILURE(rc))
    26012589                {
    26022590                    /* weak reference? */
     
    26552643
    26562644                /* Ask the user for an address to the symbol. */
    2657                 if (rc)
     2645                if (RT_FAILURE_NP(rc))
    26582646                    rc = pfnGetImport(&pThis->Core, NULL, pszSymbol, iSym, &Value, /*&fKind,*/ pvUser);
    2659                 if (rc)
     2647                if (RT_FAILURE(rc))
    26602648                {
    26612649                    /* weak reference? */
     
    26882676 * MH_OBJECT: Applies base relocations to a (unprotected) image mapping.
    26892677 *
    2690  * @returns 0 on success, non-zero kLdr status code on failure.
    2691  * @param   pThis       The Mach-O module interpreter instance.
     2678 * @returns IPRT status code.
     2679 * @param   pThis           The Mach-O module interpreter instance.
    26922680 * @param   pvMapping       The mapping to fixup.
    26932681 * @param   NewBaseAddress  The address to fixup the mapping to.
     
    26962684static int  kldrModMachOObjDoFixups(PKLDRMODMACHO pThis, void *pvMapping, RTLDRADDR NewBaseAddress)
    26972685{
    2698     uint32_t iSeg;
    2699     int rc;
    2700 
    2701 
    27022686    /*
    27032687     * Ensure that we've got the symbol table and section fixups handy.
    27042688     */
    2705     rc = kldrModMachOLoadObjSymTab(pThis);
    2706     if (rc)
     2689    int rc = kldrModMachOLoadObjSymTab(pThis);
     2690    if (RT_FAILURE(rc))
    27072691        return rc;
    27082692
     
    27102694     * Iterate over the segments and their sections and apply fixups.
    27112695     */
    2712     for (iSeg = rc = 0; !rc && iSeg < pThis->cSegments; iSeg++)
     2696    rc = VINF_SUCCESS;
     2697    for (uint32_t iSeg = 0; RT_SUCCESS(rc) && iSeg < pThis->cSegments; iSeg++)
    27132698    {
    27142699        PKLDRMODMACHOSEG pSeg = &pThis->aSegments[iSeg];
    2715         uint32_t iSect;
    2716 
    2717         for (iSect = 0; iSect < pSeg->cSections; iSect++)
     2700        for (uint32_t iSect = 0; iSect < pSeg->cSections; iSect++)
    27182701        {
    27192702            PKLDRMODMACHOSECT pSect = &pSeg->paSections[iSect];
    2720             uint8_t *pbSectBits;
    27212703
    27222704            /* skip sections without fixups. */
     
    27282710            {
    27292711                rc = kldrModMachOLoadFixups(pThis, pSect->offFixups, pSect->cFixups, &pSect->paFixups);
    2730                 if (rc)
     2712                if (RT_FAILURE(rc))
    27312713                    break;
    27322714            }
     
    27352717             * Apply the fixups.
    27362718             */
    2737             pbSectBits = (uint8_t *)pvMapping + (uintptr_t)pSect->RVA;
     2719            uint8_t *pbSectBits = (uint8_t *)pvMapping + (uintptr_t)pSect->RVA;
    27382720            if (pThis->Hdr.magic == IMAGE_MACHO32_SIGNATURE) /** @todo this aint right. */
    27392721                rc = kldrModMachOFixupSectionGeneric32Bit(pThis, pbSectBits, pSect,
     
    27472729            else
    27482730                KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);
    2749             if (rc)
     2731            if (RT_FAILURE(rc))
    27502732                break;
    27512733        }
     
    27602742 * as the host CPU.
    27612743 *
    2762  * @returns 0 on success, non-zero kLdr status code on failure.
    2763  * @param   pThis       The Mach-O module interpreter instance.
     2744 * @returns IPRT status code.
     2745 * @param   pThis           The Mach-O module interpreter instance.
    27642746 * @param   pbSectBits      Pointer to the section bits.
    27652747 * @param   pFixupSect      The section being fixed up.
     
    27832765    {
    27842766        rc = kldrModMachOMapVirginBits(pThis);
    2785         if (rc)
     2767        if (RT_FAILURE(rc))
    27862768            return rc;
    27872769        pbSectVirginBits = (const uint8_t *)pThis->pvBits + pFixupSect->offFile;
     
    29542936    }
    29552937
    2956     return 0;
     2938    return VINF_SUCCESS;
    29572939}
    29582940
     
    29612943 * Applies AMD64 fixups to a section.
    29622944 *
    2963  * @returns 0 on success, non-zero kLdr status code on failure.
    2964  * @param   pThis       The Mach-O module interpreter instance.
     2945 * @returns IPRT status code.
     2946 * @param   pThis           The Mach-O module interpreter instance.
    29652947 * @param   pbSectBits      Pointer to the section bits.
    29662948 * @param   pFixupSect      The section being fixed up.
     
    29842966    {
    29852967        rc = kldrModMachOMapVirginBits(pThis);
    2986         if (rc)
     2968        if (RT_FAILURE(rc))
    29872969            return rc;
    29882970        pbSectVirginBits = (const uint8_t *)pThis->pvBits + pFixupSect->offFile;
     
    32703252    }
    32713253
    3272     return 0;
     3254    return VINF_SUCCESS;
    32733255}
    32743256
     
    32793261 * The symbol table is pointed to by KLDRMODMACHO::pvaSymbols.
    32803262 *
    3281  * @returns 0 on success, non-zero kLdr status code on failure.
     3263 * @returns IPRT status code.
    32823264 * @param   pThis       The Mach-O module interpreter instance.
    32833265 */
    32843266static int  kldrModMachOLoadObjSymTab(PKLDRMODMACHO pThis)
    32853267{
    3286     int rc = 0;
     3268    int rc = VINF_SUCCESS;
    32873269
    32883270    if (    !pThis->pvaSymbols
     
    33183300                /* read */
    33193301                rc = pThis->Core.pReader->pfnRead(pThis->Core.pReader, pvSyms, cbSyms, pThis->offSymbols);
    3320                 if (!rc && pThis->cchStrings)
     3302                if (RT_SUCCESS(rc) && pThis->cchStrings)
    33213303                    rc = pThis->Core.pReader->pfnRead(pThis->Core.pReader, pvStrings,
    33223304                                                          pThis->cchStrings, pThis->offStrings);
    3323                 if (!rc)
     3305                if (RT_SUCCESS(rc))
    33243306                {
    33253307                    pThis->pvaSymbols = pvSyms;
     
    33523334                    }
    33533335
    3354                     return 0;
     3336                    return VINF_SUCCESS;
    33553337                }
    33563338                RTMemFree(pvStrings);
     
    33703352 * conversion if necessary.
    33713353 *
    3372  * @returns 0 on success, non-zero kLdr status code on failure.
    3373  * @param   pThis       The Mach-O module interpreter instance.
     3354 * @returns IPRT status code.
     3355 * @param   pThis           The Mach-O module interpreter instance.
    33743356 * @param   offFixups       The file offset of the fixups.
    33753357 * @param   cFixups         The number of fixups to load.
     
    33803362    macho_relocation_info_t *paFixups;
    33813363    size_t cbFixups;
    3382     int rc;
    33833364
    33843365    /* allocate the memory. */
     
    33903371
    33913372    /* read the fixups. */
    3392     rc = pThis->Core.pReader->pfnRead(pThis->Core.pReader, paFixups, cbFixups, offFixups);
    3393     if (!rc)
     3373    int rc = pThis->Core.pReader->pfnRead(pThis->Core.pReader, paFixups, cbFixups, offFixups);
     3374    if (RT_SUCCESS(rc))
    33943375    {
    33953376        *ppaFixups = paFixups;
     
    34173398 * Maps the virgin file bits into memory if not already done.
    34183399 *
    3419  * @returns 0 on success, non-zero kLdr status code on failure.
     3400 * @returns IPRT status code.
    34203401 * @param   pThis       The Mach-O module interpreter instance.
    34213402 */
    34223403static int kldrModMachOMapVirginBits(PKLDRMODMACHO pThis)
    34233404{
    3424     int rc = 0;
     3405    int rc = VINF_SUCCESS;
    34253406    if (!pThis->pvBits)
    34263407        rc = pThis->Core.pReader->pfnMap(pThis->Core.pReader, &pThis->pvBits);
     
    34373418    RT_NOREF(pvMapping);
    34383419    RT_NOREF(uHandle);
    3439     return 0;
     3420    return VINF_SUCCESS;
    34403421}
    34413422
     
    34483429    RT_NOREF(pvMapping);
    34493430    RT_NOREF(uHandle);
    3450     return 0;
     3431    return VINF_SUCCESS;
    34513432}
    34523433
     
    34603441    RT_NOREF(uHandle);
    34613442    RT_NOREF(fAttachingOrDetaching);
    3462     return 0;
     3443    return VINF_SUCCESS;
    34633444}
    34643445
     
    34693450 * @interface_method_impl{RTLDROPS,pfnGetImageSize}
    34703451 */
    3471 static size_t rtldrMachO_GetImageSize(PRTLDRMODINTERNAL pMod)
     3452static DECLCALLBACK(size_t) rtldrMachO_GetImageSize(PRTLDRMODINTERNAL pMod)
    34723453{
    34733454    PKLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);
     
    35043485            continue;
    35053486        int rc = pThis->Core.pReader->pfnRead(pThis->Core.pReader,
    3506                                                   (uint8_t *)pvBits + pThis->aSegments[i].SegInfo.RVA,
    3507                                                   pThis->aSegments[i].SegInfo.cbFile,
    3508                                                   pThis->aSegments[i].SegInfo.offFile);
    3509         if (rc)
     3487                                              (uint8_t *)pvBits + pThis->aSegments[i].SegInfo.RVA,
     3488                                              pThis->aSegments[i].SegInfo.cbFile,
     3489                                              pThis->aSegments[i].SegInfo.offFile);
     3490        if (RT_FAILURE(rc))
    35103491            return rc;
    35113492    }
     
    35343515    {
    35353516        rc = kldrModMachOObjDoImports(pThis, NewBaseAddress, pfnGetImport, pvUser);
    3536         if (!rc)
     3517        if (RT_SUCCESS(rc))
    35373518            rc = kldrModMachOObjDoFixups(pThis, pvBits, NewBaseAddress);
    35383519
     
    35423523    /*{
    35433524        rc = kldrModMachODoFixups(pThis, pvBits, NewBaseAddress, OldBaseAddress, pfnGetImport, pvUser);
    3544         if (!rc)
     3525        if (RT_SUCCESS(rc))
    35453526            rc = kldrModMachODoImports(pThis, pvBits, pfnGetImport, pvUser);
    35463527    }*/
     
    35503531     * segment when present.
    35513532     */
    3552     if (!rc && pThis->fMakeGot)
     3533    if (RT_SUCCESS(rc) && pThis->fMakeGot)
    35533534        rc = kldrModMachOMakeGOT(pThis, pvBits, NewBaseAddress);
    35543535
     
    36573638        }
    36583639    }
    3659     return 0;
     3640    return VINF_SUCCESS;
    36603641}
    36613642
     
    36703651    for (uint32_t iSeg = 0; iSeg < cSegments; iSeg++)
    36713652    {
    3672         RTLDRSEG Seg = pThis->aSegments[iSeg].SegInfo;
    3673         int rc = pfnCallback(pMod, &Seg, pvUser);
     3653        int rc = pfnCallback(pMod, &pThis->aSegments[iSeg].SegInfo, pvUser);
    36743654        if (rc != VINF_SUCCESS)
    36753655            return rc;
     
    37793759
    37803760    /** @todo May have to apply fixups here. */
    3781     if (iDbgInfo == iDbgInfo)
     3761    if (iDbgInfo < pThis->cSections)
    37823762        return pThis->Core.pReader->pfnRead(pThis->Core.pReader, pvBuf, cb, off);
    3783     if (iDbgInfo < pThis->cSections)
    3784     {
    3785         return pThis->Core.pReader->pfnRead(pThis->Core.pReader, pvBuf, cb, off);
    3786     }
    37873763    return VERR_OUT_OF_RANGE;
    37883764}
     
    38403816    rtldrMachO_SegOffsetToRva,
    38413817    rtldrMachO_RvaToSegOffset,
    3842     NULL,
     3818    rtldrMachO_ReadDbgInfo,
    38433819    rtldrMachO_QueryProp,
    38443820    NULL /*pfnVerifySignature*/,
     
    38723848            pThis->Core.u32Magic = RTLDRMOD_MAGIC;
    38733849            *phLdrMod = &pThis->Core;
    3874             return 0;
     3850            return VINF_SUCCESS;
    38753851        }
    38763852        rc = VERR_LDR_ARCH_MISMATCH;
     
    39093885    {
    39103886        fat_arch_t FatEntry;
    3911         int rc = pReader->pfnRead(pReader, &FatEntry, sizeof(FatEntry), offEntry);
     3887        rc = pReader->pfnRead(pReader, &FatEntry, sizeof(FatEntry), offEntry);
    39123888        if (RT_FAILURE(rc))
    39133889            return RTErrInfoSetF(pErrInfo, rc, "Read error at offset 0: %Rrc", rc);
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