Changeset 2955 for trunk


Ignore:
Timestamp:
Feb 7, 2007, 8:07:16 AM (19 years ago)
Author:
bird
Message:

Completed kldrModMachOParseLoadCommands and kldrModMachOSize. Added an kLdrErrStr API.

Location:
trunk/kLdr
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/Makefile.kmk

    r2954 r2955  
    100100        kLdrDyldMod.c \
    101101        kLdrDyldOS.c \
     102        kLdrErr.c \
    102103        kLdrHlp.c \
    103104        kLdrHlpHeap.c \
     
    125126kLdr_SOURCES.win64 = $(kLdr_SOURCES.win)
    126127
     128kLdrErr.c_DEPS = $(PATH_TARGET)/kldrErrConsts.h
     129kLdrErr.c_INCS = $(PATH_TARGET)
     130
    127131#
    128132# The OS/2 stub program.
     
    190194
    191195
    192 # generate rules.
     196# Generate rules.
    193197include $(PATH_KBUILD)/footer.kmk
    194198
     199
     200#
     201# Generate case statements for kLdrErrStr().
     202#
     203$(PATH_TARGET)/kldrErrConsts.h: kLdr.h Makefile.kmk | $(call DIRDEP,$(PATH_TARGET))
     204        $(RM) -f $@
     205        $(SED) \
     206                -e '/^#define  *\(KLDR_ERR_[^ ()]*\) .*$$/!d' \
     207                -e 's/^#define  *\(KLDR_ERR_[^ ()]*\) .*$$/ERR_CONST(\1)/' \
     208                -e '/KLDR_ERR_[^_]*_BASE/d' \
     209                kLdr.h > $@
     210
  • trunk/kLdr/kLdr-os2.def

    r2884 r2955  
    107107;    _kLdrDlFunc
    108108
     109    ; Error APIs:
     110    _kLdrErrStr
     111
     112
  • trunk/kLdr/kLdr-win.def

    r2877 r2955  
    106106;    _kLdrDlFunc
    107107
     108    ; Error APIs:
     109    kLdrErrStr
     110
  • trunk/kLdr/kLdr.h

    r2954 r2955  
    12651265/** The sections aren't ordered by segment as expected by the loader. */
    12661266#define KLDR_ERR_MACHO_BAD_SECTION_ORDER                    (KLDR_ERR_MACHO_BASE + 11)
     1267/** The image is 32-bit and contains 64-bit load commands or vise versa. */
     1268#define KLDR_ERR_MACHO_BIT_MIX                              (KLDR_ERR_MACHO_BASE + 12)
     1269/** The bad MH_OBJECT file. */
     1270#define KLDR_ERR_MACHO_BAD_OBJECT_FILE                      (KLDR_ERR_MACHO_BASE + 13)
    12671271/** @} */
    12681272
    12691273/** End of the valid kLdr status codes. */
    1270 #define KLDR_ERR_END                                        (KLDR_ERR_MACHO_BASE + 12)
     1274#define KLDR_ERR_END                                        (KLDR_ERR_MACHO_BASE + 14)
     1275
     1276const char *kLdrErrStr(int rc);
    12711277
    12721278/** @} */
  • trunk/kLdr/kLdrHlp.h

    r2954 r2955  
    4343/** Align a void * value. */
    4444#define KLDR_ALIGN_P(pv, align)     ( (void *)( ((uintptr_t)(pv) + ((align) - 1)) & ~(uintptr_t)((align) - 1) ) )
     45/** Align a size_t value. */
     46#define KLDR_ALIGN_ADDR(val, align) ( ((val) + ((align) - 1)) & ~(KLDRADDR)((align) - 1) )
    4547/** Number of elements in an array. */
    4648#define KLDR_ELEMENTS(a)            ( sizeof(a) / sizeof((a)[0]) )
     
    239241#endif
    240242
     243size_t  kLdrHlpStrNLen(const char *psz, size_t cchMax);
    241244int     kLdrHlpMemIComp(const void *pv1, const void *pv2, size_t cb);
    242245int     kLdrHlpStrIComp(const char *pv1, const char *pv2);
  • trunk/kLdr/kLdrHlpStr.c

    r2944 r2955  
    7878
    7979    return pszRet;
     80}
     81
     82
     83size_t  kLdrHlpStrNLen(const char *psz, size_t cchMax)
     84{
     85    const char * const pszStart = psz;
     86    while (*psz && cchMax--)
     87        psz++;
     88    return psz - pszStart;
    8089}
    8190
  • trunk/kLdr/kLdrModMachO.c

    r2954 r2955  
    9999    /** The link address. */
    100100    KLDRADDR                LinkAddress;
     101    /** The size of the mapped image. */
     102    KLDRADDR                cbImage;
     103    /** When set the load commands will be used when mapping / loading the bits.
     104     * This is the case when segments are made up of sections that doesn't have
     105     * proper ordering and/or aligning in the file alignment. */
     106    int                     fMapUsingLoadCommands;
    101107
    102108    /** Pointer to the load commands. (endian converted) */
     
    353359        pModMachO->Hdr.reserved = 0;
    354360    pModMachO->LinkAddress = 0;
     361    pModMachO->cbImage = 0;
     362    pModMachO->fMapUsingLoadCommands = 0;
    355363    pModMachO->offSymbols = 0;
    356364    pModMachO->cSymbols = 0;
     
    408416    uint32_t cbLeft = pHdr->sizeofcmds;
    409417    uint8_t *pb = pbLoadCommands;
     418    int      cSegmentCommands = 0;
    410419    int      fConvertEndian = pHdr->magic == IMAGE_MACHO32_SIGNATURE_OE
    411420                           || pHdr->magic == IMAGE_MACHO64_SIGNATURE_OE;
     
    447456                if (u.pLoadCmd->cmdsize < sizeof(segment_command_32_t))
    448457                    return KLDR_ERR_MACHO_BAD_LOAD_COMMAND;
     458                if (    pHdr->magic != IMAGE_MACHO32_SIGNATURE_OE
     459                    &&  pHdr->magic != IMAGE_MACHO32_SIGNATURE)
     460                    return KLDR_ERR_MACHO_BIT_MIX;
    449461                if (fConvertEndian)
    450462                {
     
    473485                if (u.pSeg32->nsects * sizeof(section_32_t) > u.pLoadCmd->cmdsize - sizeof(segment_command_32_t))
    474486                    return KLDR_ERR_MACHO_BAD_LOAD_COMMAND;
     487                if (    pHdr->filetype == MH_OBJECT
     488                    &&  cSegmentCommands > 0)
     489                    return KLDR_ERR_MACHO_BAD_OBJECT_FILE;
     490                cSegmentCommands++;
    475491
    476492                /*
     
    566582
    567583                            /* a new segment? */
    568                             if (    pSect == pFirstSect
     584                            if (    !cSegments
    569585                                ||  kLdrHlpStrNComp(pSect->segname, (pSect - 1)->segname, sizeof(pSect->segname)))
    570586                            {
     
    580596                                /* ok. count it and the string. */
    581597                                cSegments++;
    582                                 cbStringPool += kLdrHlpStrLen(pSect->segname) + 1;
     598                                cbStringPool += kLdrHlpStrNLen(&pSect->segname[0], sizeof(pSect->segname)) + 1;
    583599                            }
    584600                            break;
     
    595611            }
    596612
    597             case LC_SEGMENT_64:
    598                 /* copy 32-bit code */
     613            /*case LC_SEGMENT_64:
     614                 copy 32-bit code
    599615                break;
     616            */
    600617
    601618            case LC_SYMTAB:
     
    656673                break;
    657674
     675            case LC_SEGMENT_64:
    658676            case LC_LOADFVMLIB:
    659677            case LC_IDFVMLIB:
     
    684702    }
    685703
    686     /* be strict (for now). */
     704    /* be strict. */
    687705    if (cbLeft)
    688706        return KLDR_ERR_MACHO_BAD_LOAD_COMMAND;
    689707
     708    switch (pHdr->filetype)
     709    {
     710        case MH_OBJECT:
     711            if (!cSegments)
     712                return KLDR_ERR_MACHO_BAD_OBJECT_FILE;
     713            break;
     714    }
     715
    690716    *pcSegments = cSegments;
    691     *pcbStringPool = cLeft;
     717    *pcbStringPool = cbStringPool;
    692718
    693719    return 0;
     
    708734static int  kldrModMachOParseLoadCommands(PKLDRMODMACHO pModMachO, char *pbStringPool, uint32_t cbStringPool)
    709735{
     736    union
     737    {
     738        const uint8_t              *pb;
     739        const load_command_t       *pLoadCmd;
     740        const segment_command_32_t *pSeg32;
     741        const segment_command_64_t *pSeg64;
     742        const symtab_command_t     *pSymTab;
     743    } u;
     744    uint32_t cLeft = pModMachO->Hdr.ncmds;
     745    uint32_t cbLeft = pModMachO->Hdr.sizeofcmds;
     746    const uint8_t *pb = pModMachO->pbLoadCommands;
     747    int fFirstSegment = 1;
     748    PKLDRSEG pSeg = &pModMachO->pMod->aSegments[0];
     749    const uint32_t cSegments = pModMachO->pMod->cSegments;
     750    uint32_t i;
     751
     752    while (cLeft-- > 0)
     753    {
     754        u.pb = pb;
     755        cbLeft -= u.pLoadCmd->cmdsize;
     756        pb += u.pLoadCmd->cmdsize;
     757
     758        /*
     759         * Convert endian if needed, parse and validate the command.
     760         */
     761        switch (u.pLoadCmd->cmd)
     762        {
     763            case LC_SEGMENT_32:
     764            {
     765                section_32_t *pSect;
     766                section_32_t *pFirstSect;
     767                uint32_t cSectionsLeft;
     768
     769                pModMachO->LinkAddress = u.pSeg32->vmaddr;
     770
     771                /*
     772                 * convert, validate and parse the sections.
     773                 */
     774                cSectionsLeft = u.pSeg32->nsects;
     775                pFirstSect = pSect = (section_32_t *)(u.pSeg32 + 1);
     776                while (cSectionsLeft-- > 0)
     777                {
     778                    switch (pModMachO->Hdr.filetype)
     779                    {
     780                        case MH_OBJECT:
     781                        {
     782                            /* Don't load debug symbols. (test this) */
     783                            if (pSect->flags & S_ATTR_DEBUG)
     784                                break;
     785
     786                            if (    fFirstSegment
     787                                ||  kLdrHlpStrNComp(pSect->segname, (pSect - 1)->segname, sizeof(pSect->segname)))
     788                            {
     789                                /* new segment. */
     790                                pSeg->pvUser = NULL;
     791                                pSeg->pchName = pbStringPool;
     792                                pSeg->cchName = (uint32_t)kLdrHlpStrNLen(&pSect->segname[0], sizeof(pSect->sectname));
     793                                kLdrHlpMemCopy(pbStringPool, &pSect->segname[0], pSeg->cchName);
     794                                pbStringPool += pSeg->cchName;
     795                                *pbStringPool++ = '\0';
     796                                pSeg->SelFlat = 0;
     797                                pSeg->Sel16bit = 0;
     798                                pSeg->fFlags = 0;
     799                                pSeg->enmProt = KLDRPROT_EXECUTE_WRITECOPY; /** @todo fixme! */
     800                                pSeg->cb = pSect->size;
     801                                pSeg->Alignment = (1 << pSect->align);
     802                                pSeg->LinkAddress = pSect->addr;
     803                                pSeg->offFile = pSect->offset ? pSect->offset : -1;
     804                                pSeg->cbFile  = pSect->offset ? pSect->size : -1;
     805                                pSeg->RVA = pSect->addr - pModMachO->LinkAddress;
     806                                pSeg->cbMapped = 0;
     807                                pSeg->MapAddress = 0;
     808
     809                                pSeg++;
     810                                fFirstSegment = 0;
     811                            }
     812                            else if (!fFirstSegment)
     813                            {
     814                                /* update exiting segment */
     815                                if (pSeg[-1].Alignment < (1 << pSect->align))
     816                                    pSeg[-1].Alignment = (1 << pSect->align);
     817                                if (pSect->addr < pSeg[-1].LinkAddress)
     818                                    return KLDR_ERR_MACHO_BAD_SECTION; /** @todo move up! */
     819
     820                                if (    pSect->offset
     821                                    &&  pSeg[-1].cbFile == pSeg[-1].cb)
     822                                {
     823                                    if (    pSeg[-1].offFile + pSeg[-1].cbFile == pSect->offset
     824                                        &&  pSeg[-1].cbFile == pSect->addr - pSeg[-1].LinkAddress)
     825                                        pSeg[-1].cbFile = (off_t)(pSect->addr - pSeg[-1].LinkAddress) + pSect->size;
     826                                    else
     827                                    {
     828                                        pSeg[-1].cbFile = pSeg[-1].offFile = -1;
     829                                        pModMachO->fMapUsingLoadCommands = 1;
     830                                    }
     831                                }
     832                                pSeg[-1].cb = pSect->addr - pSeg[-1].LinkAddress + pSect->size;
     833
     834                                /** @todo update the protection... */
     835                            }
     836                            break;
     837                        }
     838
     839                        default:
     840                            return KLDR_ERR_INVALID_PARAMETER;
     841                    }
     842
     843                    /* next */
     844                    pSect++;
     845                }
     846                break;
     847            }
     848
     849            default:
     850                break;
     851        }
     852    }
     853
     854    /*
     855     * Adjust mapping addresses calculating the image size.
     856     */
     857    pSeg = &pModMachO->pMod->aSegments[0];
     858    switch (pModMachO->Hdr.filetype)
     859    {
     860        case MH_OBJECT:
     861        {
     862            KLDRADDR cb1;
     863            size_t cb2;
     864
     865            for (i = 0; i < cSegments - 1; i++)
     866            {
     867                cb1 = pSeg[i + 1].LinkAddress - pSeg[i].LinkAddress;
     868                cb2 = (size_t)cb1;
     869                pSeg[i].cbMapped = cb2 == cb1 ? cb2 : ~(size_t)0;
     870            }
     871            cb1 = KLDR_ALIGN_ADDR(pSeg[i].cb, pSeg[i].Alignment);
     872            cb2 = (size_t)cb1;
     873            pSeg[i].cbMapped = cb2 == cb1 ? cb2 : ~(size_t)0;
     874
     875            pModMachO->cbImage = pSeg[i].RVA + cb1;
     876            break;
     877        }
     878    }
     879
    710880    return 0;
    711881}
     
    19782148static KLDRADDR kldrModMachOSize(PKLDRMOD pMod)
    19792149{
    1980 #if 0
    19812150    PKLDRMODMACHO pModMachO = (PKLDRMODMACHO)pMod->pvData;
    1982     return pModMachO->Hdrs.OptionalHeader.SizeOfImage;
    1983 #else
    1984     return 0;
    1985 #endif
     2151    return pModMachO->cbImage;
    19862152}
    19872153
  • trunk/kLdr/tstkLdrMod.c

    r2899 r2955  
    116116    rc = kLdrModGetBits(pMod, pvBits2, (uintptr_t)pvBits, BasicTestsGetImport, NULL);
    117117    if (rc)
    118         return Failure("failed to get image bits, rc=%d (a)", rc);
     118        return Failure("failed to get image bits, rc=%d (%s) (a)", rc, kLdrErrStr(rc));
    119119    if (TestMemComp(pvBits2, pvBits, cbImage))
    120120        return Failure("relocation test failed, mismatching bits (a)");
     
    125125    rc = kLdrModRelocateBits(pMod, pvBits2, 0x1000, (uintptr_t)pvBits, BasicTestsGetImport, NULL);
    126126    if (rc)
    127         return Failure("failed to relocate, rc=%d (b1)");
     127        return Failure("failed to relocate, rc=%d (%s) (b1)", rc, kLdrErrStr(rc));
    128128    rc = kLdrModRelocateBits(pMod, pvBits2, (uintptr_t)pvBits, 0x1000, BasicTestsGetImport, NULL);
    129129    if (rc)
    130         return Failure("failed to relocate, rc=%d (b2)");
     130        return Failure("failed to relocate, rc=%d (%s) (b2)", rc, kLdrErrStr(rc));
    131131    if (TestMemComp(pvBits2, pvBits, cbImage))
    132132        return Failure("relocation test failed, mismatching bits (b)");
     
    138138    rc = kLdrModRelocateBits(pMod, pvBits, 0x1000000, (uintptr_t)pvBits, BasicTestsGetImport, NULL);
    139139    if (rc)
    140         return Failure("failed to relocate, rc=%d (c1)");
     140        return Failure("failed to relocate, rc=%d (%s) (c1)", rc, kLdrErrStr(rc));
    141141    memset(pvBits2, 0xfe, cbImage);
    142142    rc = kLdrModGetBits(pMod, pvBits2, 0x1000000, BasicTestsGetImport, NULL);
    143143    if (rc)
    144         return Failure("failed to get image bits, rc=%d (c1)", rc);
     144        return Failure("failed to get image bits, rc=%d (%s) (c1)", rc, kLdrErrStr(rc));
    145145    if (TestMemComp(pvBits2, pvBits, cbImage))
    146146        return Failure("relocation test failed, mismatching bits (c1)");
     
    149149    rc = kLdrModRelocateBits(pMod, pvBits, ~(uintptr_t)0x1010000, 0x1000000, BasicTestsGetImport, NULL);
    150150    if (rc)
    151         return Failure("failed to relocate, rc=%d (c2)");
     151        return Failure("failed to relocate, rc=%d (%s) (c2)", rc, kLdrErrStr(rc));
    152152    memset(pvBits2, 0xef, cbImage);
    153153    rc = kLdrModGetBits(pMod, pvBits2, ~(uintptr_t)0x1010000, BasicTestsGetImport, NULL);
    154154    if (rc)
    155         return Failure("failed to get image bits, rc=%d (c2)", rc);
     155        return Failure("failed to get image bits, rc=%d (%s) (c2)", rc, kLdrErrStr(rc));
    156156    if (TestMemComp(pvBits2, pvBits, cbImage))
    157157        return Failure("relocation test failed, mismatching bits (c2)");
     
    160160    rc = kLdrModRelocateBits(pMod, pvBits, MY_BASEADDRESS, ~(uintptr_t)0x1010000, BasicTestsGetImport, NULL);
    161161    if (rc)
    162         return Failure("failed to relocate, rc=%d (c3)");
     162        return Failure("failed to relocate, rc=%d (%s) (c3)", rc, kLdrErrStr(rc));
    163163    memset(pvBits2, 0xef, cbImage);
    164164    rc = kLdrModGetBits(pMod, pvBits2, MY_BASEADDRESS, BasicTestsGetImport, NULL);
    165165    if (rc)
    166         return Failure("failed to get image bits, rc=%d (c3)", rc);
     166        return Failure("failed to get image bits, rc=%d (%s) (c3)", rc, kLdrErrStr(rc));
    167167    if (TestMemComp(pvBits2, pvBits, cbImage))
    168168        return Failure("relocation test failed, mismatching bits (c3)");
     
    171171    rc = kLdrModRelocateBits(pMod, pvBits, ~(uintptr_t)0 / 2 - 0x10000, MY_BASEADDRESS, BasicTestsGetImport, NULL);
    172172    if (rc)
    173         return Failure("failed to relocate, rc=%d (c4)");
     173        return Failure("failed to relocate, rc=%d %(s) (c4)", rc, kLdrErrStr(rc));
    174174    memset(pvBits2, 0xdc, cbImage);
    175175    rc = kLdrModGetBits(pMod, pvBits2, ~(uintptr_t)0 / 2 - 0x10000, BasicTestsGetImport, NULL);
    176176    if (rc)
    177         return Failure("failed to get image bits, rc=%d (c4)", rc);
     177        return Failure("failed to get image bits, rc=%d (%s) (c4)", rc, kLdrErrStr(rc));
    178178    if (TestMemComp(pvBits2, pvBits, cbImage))
    179179        return Failure("relocation test failed, mismatching bits (c4)");
     
    182182    rc = kLdrModRelocateBits(pMod, pvBits, (uintptr_t)pvBits, ~(uintptr_t)0 / 2 - 0x10000, BasicTestsGetImport, NULL);
    183183    if (rc)
    184         return Failure("failed to relocate, rc=%d (c5)");
     184        return Failure("failed to relocate, rc=%d (%s) (c5)", rc, kLdrErrStr(rc));
    185185    memset(pvBits2, 0xcd, cbImage);
    186186    rc = kLdrModGetBits(pMod, pvBits2, (uintptr_t)pvBits, BasicTestsGetImport, NULL);
    187187    if (rc)
    188         return Failure("failed to get image bits, rc=%d (c5)", rc);
     188        return Failure("failed to get image bits, rc=%d (%s) (c5)", rc, kLdrErrStr(rc));
    189189    if (TestMemComp(pvBits2, pvBits, cbImage))
    190190        return Failure("relocation test failed, mismatching bits (c5)");
     
    216216                                &uValue2, &fKind2);
    217217        if (rc)
    218             return Failure("Couldn't find symbol %#x (%.*s) by ordinal. rc=%d", iSymbol, cchSymbol, pchSymbol, rc);
     218            return Failure("Couldn't find symbol %#x (%.*s) by ordinal. rc=%d (%s)", iSymbol, cchSymbol, pchSymbol, rc, kLdrErrStr(rc));
    219219        if (uValue != uValue2)
    220220            return Failure("Symbol %#x (%.*s): Value mismatch %016" PRI_KLDRADDR " != %016" PRI_KLDRADDR " (enum!=query/ord)  pvBits=%p",
     
    231231                                NULL, NULL, &uValue2, &fKind2);
    232232        if (rc)
    233             return Failure("Couldn't find symbol %#x (%.*s) by name. rc=%d", iSymbol, cchSymbol, pchSymbol, rc);
     233            return Failure("Couldn't find symbol %#x (%.*s) by name. rc=%d (%s)", iSymbol, cchSymbol, pchSymbol, rc, kLdrErrStr(rc));
    234234        if (uValue != uValue2)
    235235            return Failure("Symbol %#x (%.*s): Value mismatch %016" PRI_KLDRADDR " != %016" PRI_KLDRADDR " (enum!=query/name) pvBits=%p",
     
    292292        rc = kLdrModGetImport(pMod, pvBits, i, szImportModule, sizeof(szImportModule));
    293293        if (rc)
    294             return Failure("failed to get import module name, rc=%d. (%.260s)", rc, szImportModule);
     294            return Failure("failed to get import module name, rc=%d (%s). (%.260s)", rc, kLdrErrStr(rc), szImportModule);
    295295        printf("import #%d: '%s'\n", i, szImportModule);
    296296    }
     
    305305    rc = kLdrModGetStackInfo(pMod, pvBits, MY_BASEADDRESS, &StackInfo);
    306306    if (rc)
    307         return Failure("kLdrModGetStackInfo failed with rc=%d", rc);
     307        return Failure("kLdrModGetStackInfo failed with rc=%d (%s)", rc, kLdrErrStr(rc));
    308308    printf("Stack: Address=%016" PRI_KLDRADDR "   LinkAddress=%016" PRI_KLDRADDR "\n"
    309309           "       cbStack=%016" PRI_KLDRSIZE " cbStackThread=%016" PRI_KLDRSIZE "\n",
     
    324324    rc = kLdrModQueryMainEntrypoint(pMod, pvBits, MY_BASEADDRESS, &MainEPAddress);
    325325    if (rc)
    326         return Failure("kLdrModQueryMainEntrypoint failed with rc=%d", rc);
     326        return Failure("kLdrModQueryMainEntrypoint failed with rc=%d (%s)", rc, kLdrErrStr(rc));
    327327    printf("Entrypoint: %016" PRI_KLDRADDR "\n", MainEPAddress);
    328328    if (MainEPAddress == ~(KLDRADDR)42)
     
    342342        printf("NO Debugger Information\n");
    343343    else
    344         return Failure("kLdrModHasDbgInfo failed with rc=%d", rc);
     344        return Failure("kLdrModHasDbgInfo failed with rc=%d (%s)", rc, kLdrErrStr(rc));
    345345    rc = kLdrModEnumDbgInfo(pMod, pvBits, BasicTestEnumDbgInfoCallback, NULL);
    346346    if (rc)
    347         return Failure("kLdrModEnumDbgInfo failed with rc=%d", rc);
     347        return Failure("kLdrModEnumDbgInfo failed with rc=%d (%s)", rc, kLdrErrStr(rc));
    348348
    349349
     
    381381    rc = kLdrModEnumSymbols(pMod, pvBits, MY_BASEADDRESS, 0, BasicTestsEnumSymCallback, pvBits);
    382382    if (rc)
    383         return Failure("kLdrModEnumSymbols failed with rc=%d", rc);
     383        return Failure("kLdrModEnumSymbols failed with rc=%d (%s)", rc, kLdrErrStr(rc));
    384384
    385385
     
    490490    rc = kLdrModGetBits(pMod, pvBits, (uintptr_t)pvBits, BasicTestsGetImport, NULL);
    491491    if (rc)
    492         return Failure("failed to get image bits, rc=%d", rc);
     492        return Failure("failed to get image bits, rc=%d (%s)", rc, kLdrErrStr(rc));
    493493
    494494    /*
     
    525525    rc = kLdrModFixupMapping(pMod, BasicTestsGetImport, NULL);
    526526    if (rc)
    527         return Failure("kLdrModFixupMapping (a) failed, rc=%d", rc);
     527        return Failure("kLdrModFixupMapping (a) failed, rc=%d (%s)", rc, kLdrErrStr(rc));
    528528
    529529    rc = kLdrModReload(pMod);
    530530    if (rc)
    531         return Failure("kLdrModReload (a) failed, rc=%d", rc);
     531        return Failure("kLdrModReload (a) failed, rc=%d (%s)", rc, kLdrErrStr(rc));
    532532
    533533    rc = kLdrModReload(pMod);
    534534    if (rc)
    535         return Failure("kLdrModReload (b) failed, rc=%d", rc);
     535        return Failure("kLdrModReload (b) failed, rc=%d (%s)", rc, kLdrErrStr(rc));
    536536
    537537    rc = kLdrModFixupMapping(pMod, BasicTestsGetImport, NULL);
    538538    if (rc)
    539         return Failure("kLdrModFixupMapping (b) failed, rc=%d", rc);
     539        return Failure("kLdrModFixupMapping (b) failed, rc=%d (%s)", rc, kLdrErrStr(rc));
    540540
    541541    rc = kLdrModAllocTLS(pMod);
    542542    if (rc)
    543         return Failure("kLdrModAllocTLS (a) failed, rc=%d", rc);
     543        return Failure("kLdrModAllocTLS (a) failed, rc=%d (%s)", rc, kLdrErrStr(rc));
    544544    kLdrModFreeTLS(pMod);
    545545
    546546    rc = kLdrModAllocTLS(pMod);
    547547    if (rc)
    548         return Failure("kLdrModAllocTLS (b) failed, rc=%d", rc);
     548        return Failure("kLdrModAllocTLS (b) failed, rc=%d (%s)", rc, kLdrErrStr(rc));
    549549    kLdrModFreeTLS(pMod);
    550550
     
    555555    rc = BasicTestsSub2(pMod, NULL);
    556556    if (rc)
    557         return Failure("BasicTestsSub2 in Map2 failed, rc=%d", rc);
     557        return Failure("BasicTestsSub2 in Map2 failed, rc=%d (%s)", rc, kLdrErrStr(rc));
    558558    return 0;
    559559}
     
    570570    rc = kLdrModMap(pMod);
    571571    if (rc)
    572         return Failure("kLdrModMap failed, rc=%d", rc);
     572        return Failure("kLdrModMap failed, rc=%d (%s)", rc, kLdrErrStr(rc));
    573573    rc = BasicTestsSubMap2(pMod);
    574574    rc2 = kLdrModUnmap(pMod);
    575575    if (rc2)
    576576    {
    577         Failure("kLdrModUnmap failed, rc=%d", rc2);
     577        Failure("kLdrModUnmap failed, rc=%d (%s)", rc2, kLdrErrStr(rc2));
    578578        rc = rc ? rc : rc2;
    579579    }
     
    603603        rc2 = kLdrModClose(pMod);
    604604        if (rc2)
    605             Failure("failed to close '%s', rc=%d", pszFilename, rc);
     605            Failure("failed to close '%s', rc=%d (%s)", pszFilename, rc, kLdrErrStr(rc));
    606606        if (rc2 && !rc)
    607607            rc = rc2;
    608608    }
    609609    else
    610         Failure("Failed to open '%s', rc=%d", pszFilename, rc);
     610        Failure("Failed to open '%s', rc=%d (%s)", pszFilename, rc, kLdrErrStr(rc));
    611611    return rc ? 1 : 0;
    612612}
Note: See TracChangeset for help on using the changeset viewer.