Changeset 43


Ignore:
Timestamp:
Aug 31, 2011, 4:37:38 PM (14 years ago)
Author:
bird
Message:

kLdrModMachO.cpp: detect debug info and be more flexible wrt unimplemented sections.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdrModMachO.c

    r42 r43  
    131131    /** The size of the mapped image. */
    132132    KLDRADDR                cbImage;
     133    /** Whether we're capable of loading the image. */
     134    KBOOL                   fCanLoad;
    133135    /** Whether we're creating a global offset table segment.
    134136     * This dependes on the cputype and image type. */
     
    186188static int  kldrModMachODoCreate(PKRDR pRdr, KLDRFOFF offImage, PKLDRMODMACHO *ppMod);
    187189static int  kldrModMachOPreParseLoadCommands(KU8 *pbLoadCommands, const mach_header_32_t *pHdr, PKRDR pRdr, KLDRFOFF offImage,
    188                                              KU32 *pcSegments, KU32 *pcSections, KU32 *pcbStringPool);
     190                                             KU32 *pcSegments, KU32 *pcSections, KU32 *pcbStringPool, PKBOOL pfCanLoad);
    189191static int  kldrModMachOParseLoadCommands(PKLDRMODMACHO pModMachO, char *pbStringPool, KU32 cbStringPool);
    190192static int  kldrModMachOAdjustBaseAddress(PKLDRMODMACHO pModMachO, PKLDRADDR pBaseAddress);
     
    289291    KSIZE cb;
    290292    KBOOL fMakeGot;
     293    KBOOL fCanLoad = K_TRUE;
    291294    KU8 cbJmpStub;
    292295    int rc;
     
    348351                  : sizeof(mach_header_64_t) + offImage);
    349352    if (!rc)
    350         rc = kldrModMachOPreParseLoadCommands(pbLoadCommands, &s.Hdr32, pRdr, offImage, &cSegments, &cSections, &cbStringPool);
     353        rc = kldrModMachOPreParseLoadCommands(pbLoadCommands, &s.Hdr32, pRdr, offImage,
     354                                              &cSegments, &cSections, &cbStringPool, &fCanLoad);
    351355    if (rc)
    352356    {
     
    454458    pModMachO->LinkAddress = 0;
    455459    pModMachO->cbImage = 0;
     460    pModMachO->fCanLoad = fCanLoad;
    456461    pModMachO->fMakeGot = fMakeGot;
    457462    pModMachO->cbJmpStub = cbJmpStub;
     
    498503 * @param   pcSegments      Where to store the section count.
    499504 * @param   pcbStringPool   Where to store the string pool size.
     505 * @param   pfCanLoad       Where to store the can-load-image indicator.
    500506 */
    501507static int  kldrModMachOPreParseLoadCommands(KU8 *pbLoadCommands, const mach_header_32_t *pHdr, PKRDR pRdr, KLDRFOFF offImage,
    502                                              KU32 *pcSegments, KU32 *pcSections, KU32 *pcbStringPool)
     508                                             KU32 *pcSegments, KU32 *pcSections, KU32 *pcbStringPool, PKBOOL pfCanLoad)
    503509{
    504510    union
     
    527533    *pcSections = 0;
    528534    *pcbStringPool = 0;
     535    *pfCanLoad = K_TRUE;
    529536
    530537    while (cLeft-- > 0)
     
    636643                            break;
    637644
     645                        case S_SYMBOL_STUBS:
     646                            if (   pSect->reserved1
     647                                || pSect->reserved2 < 1
     648                                || pSect->reserved2 > 64 )
     649                                return KLDR_ERR_MACHO_BAD_SECTION;
     650                            fFileBits = 0;
     651                            break;
     652
     653                        case S_NON_LAZY_SYMBOL_POINTERS:
     654                        case S_LAZY_SYMBOL_POINTERS:
     655                            if (pSect->reserved2) /* (reserved 1 is indirect symbol table index)*/
     656                                return KLDR_ERR_MACHO_BAD_SECTION;
     657                            *pfCanLoad = K_FALSE;
     658                            fFileBits = 0;
     659                            break;
     660
    638661                        case S_LITERAL_POINTERS:
    639662                        case S_INTERPOSING:
    640663                        case S_GB_ZEROFILL:
    641                         case S_NON_LAZY_SYMBOL_POINTERS:
    642                         case S_LAZY_SYMBOL_POINTERS:
    643                         case S_SYMBOL_STUBS:
    644                             return KLDR_ERR_MACHO_UNSUPPORTED_SECTION;
    645664                        case S_MOD_INIT_FUNC_POINTERS:
    646665                            return KLDR_ERR_MACHO_UNSUPPORTED_INIT_SECTION;
     
    687706                            cSections++;
    688707
    689                             /* Don't load debug symbols. (test this) */
    690                             if (pSect->flags & S_ATTR_DEBUG)
     708                            /* Don't load debug symbols. */
     709                            if (   (pSect->flags & S_ATTR_DEBUG)
     710                                || !kHlpStrComp(pSect->segname, "__DWARF"))
    691711                                break;
    692712
     
    807827                            break;
    808828
     829                        case S_SYMBOL_STUBS:
     830                            if (   pSect->reserved1
     831                                || pSect->reserved2 < 1  /* stub size.*/
     832                                || pSect->reserved2 > 64 )
     833                                return KLDR_ERR_MACHO_BAD_SECTION;
     834                            fFileBits = 1;
     835                            break;
     836
     837                        case S_NON_LAZY_SYMBOL_POINTERS:
     838                        case S_LAZY_SYMBOL_POINTERS:
     839                            if (pSect->reserved2) /* (reserved 1 is indirect symbol table index)*/
     840                                return KLDR_ERR_MACHO_BAD_SECTION;
     841                            *pfCanLoad = K_FALSE;
     842                            fFileBits = 0;
     843                            break;
     844
    809845                        case S_LITERAL_POINTERS:
    810846                        case S_INTERPOSING:
    811847                        case S_GB_ZEROFILL:
    812                         case S_NON_LAZY_SYMBOL_POINTERS:
    813                         case S_LAZY_SYMBOL_POINTERS:
    814                         case S_SYMBOL_STUBS:
    815848                            return KLDR_ERR_MACHO_UNSUPPORTED_SECTION;
    816849#if 1 /** @todo this requires a query API or flag... */
     
    866899
    867900                            /* Don't load debug symbols. (test this) */
    868                             if (pSect->flags & S_ATTR_DEBUG)
     901                            if (   (pSect->flags & S_ATTR_DEBUG)
     902                                || !kHlpStrComp(pSect->segname, "__DWARF"))
    869903                                break;
    870904
     
    11091143
    11101144                            /* Don't load debug symbols. (test this!) */
    1111                             if (pSect->flags & S_ATTR_DEBUG)
     1145                            if (   (pSect->flags & S_ATTR_DEBUG)
     1146                                || !kHlpStrComp(pSect->segname, "__DWARF"))
    11121147                            {
    11131148                                pSectExtra++;
     
    12431278
    12441279                            /* Don't load debug symbols. (test this!) */
    1245                             if (pSect->flags & S_ATTR_DEBUG)
     1280                            if (   (pSect->flags & S_ATTR_DEBUG)
     1281                                || !kHlpStrComp(pSect->segname, "__DWARF"))
    12461282                            {
    12471283                                pSectExtra++;
     
    21972233    void *pvBase;
    21982234    int rc;
     2235
     2236    if (!pModMachO->fCanLoad)
     2237        return KLDR_ERR_TODO;
    21992238
    22002239    /*
     
    32483287    int         rc;
    32493288
     3289    if (!pModMachO->fCanLoad)
     3290        return KLDR_ERR_TODO;
     3291
    32503292    /*
    32513293     * Zero the entire buffer first to simplify things.
Note: See TracChangeset for help on using the changeset viewer.