Changeset 2979 for trunk


Ignore:
Timestamp:
Mar 4, 2007, 12:27:30 AM (18 years ago)
Author:
bird
Message:

name resolution. fixed some fixup bugs, works for wlink dlls now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdrModLX.c

    r2974 r2979  
    44 * kLdr - The Module Interpreter for the Linear eXecutable (LX) Format.
    55 *
    6  * Copyright (c) 2006 knut st. osmundsen <bird@anduin.net>
     6 * Copyright (c) 2006-2007 knut st. osmundsen <bird@anduin.net>
    77 *
    88 *
     
    119119static const uint8_t *kldrModLXDoNameTableLookupByOrdinal(const uint8_t *pbNameTable, int32_t cbNameTable, uint32_t iOrdinal);
    120120static int kldrModLXDoNameLookup(PKLDRMODLX pModLX, const char *pchSymbol, uint32_t cchSymbol, uint32_t *piSymbol);
    121 #if 0
    122121static const uint8_t *kldrModLXDoNameTableLookupByName(const uint8_t *pbNameTable, int32_t cbNameTable,
    123                                                        char *pchSymbol, size_t cchSymbol);
    124 #endif
     122                                                       const char *pchSymbol, size_t cchSymbol);
    125123static int kldrModLXDoLoadBits(PKLDRMODLX pModLX, void *pvBits);
    126124static int kldrModLXDoIterDataUnpacking(uint8_t *pbDst, const uint8_t *pbSrc, int cbSrc);
     
    595593     * (The entry table is made up of bundles of similar exports.)
    596594     */
    597     iOrdinal = 0;
     595    iOrdinal = 1;
    598596    pBundle = (const struct b32_bundle *)pModLX->pbEntryTab;
    599     while (!pBundle->b32_cnt && iOrdinal <= iSymbol)
     597    while (pBundle->b32_cnt && iOrdinal <= iSymbol)
    600598    {
    601599        static const size_t s_cbEntry[] = { 0, 3, 5, 5, 7 };
     
    609607            uint32_t offObject;
    610608            const struct e32_entry *pEntry = (const struct e32_entry *)((uintptr_t)(pBundle + 1)
    611                                                                         + iSymbol - (iOrdinal - pBundle->b32_cnt));
     609                                                                        +   (iSymbol - (iOrdinal - pBundle->b32_cnt))
     610                                                                          * s_cbEntry[pBundle->b32_type]);
    612611
    613612            /*
     
    676675            pBundle = (const struct b32_bundle *)((const uint8_t *)pBundle + 2);
    677676        else
    678             pBundle = (const struct b32_bundle *)((const uint8_t *)pBundle + s_cbEntry[pBundle->b32_type] * pBundle->b32_cnt);
     677            pBundle = (const struct b32_bundle *)((const uint8_t *)(pBundle + 1) + s_cbEntry[pBundle->b32_type] * pBundle->b32_cnt);
    679678    }
    680679
     
    698697     * First do a hash table lookup.
    699698     */
    700 
    701 
    702 
    703     /*
    704 
    705     */
    706 
    707     return -1;
     699    /** @todo hash name table for speed. */
     700
     701    /*
     702     * Search the name tables.
     703     */
     704    const uint8_t *pbName = kldrModLXDoNameTableLookupByName(pModLX->pbResNameTab,
     705                                                             pModLX->pbLoaderSectionLast - pModLX->pbResNameTab + 1,
     706                                                             pchSymbol, cchSymbol);
     707    if (!pbName)
     708    {
     709        if (!pModLX->pbNonResNameTab)
     710        {
     711            /* lazy load it */
     712            /** @todo non-resident name table. */
     713        }
     714        if (pModLX->pbNonResNameTab)
     715            pbName = kldrModLXDoNameTableLookupByName(pModLX->pbResNameTab,
     716                                                      pModLX->pbNonResNameTabLast - pModLX->pbResNameTab + 1,
     717                                                      pchSymbol, cchSymbol);
     718    }
     719    if (!pbName)
     720        return KLDR_ERR_SYMBOL_NOT_FOUND;
     721
     722    *piSymbol = *(const uint16_t *)(pbName + 1 + *pbName);
     723    return 0;
    708724}
    709725
     
    737753    return hash;
    738754}
     755#endif
    739756
    740757
     
    750767 */
    751768static const uint8_t *kldrModLXDoNameTableLookupByName(const uint8_t *pbNameTable, int32_t cbNameTable,
    752                                                        char *pchSymbol, size_t cchSymbol)
     769                                                       const char *pchSymbol, size_t cchSymbol)
    753770{
    754771    /*
     
    780797    return NULL;
    781798}
    782 #endif
    783799
    784800
     
    21012117
    21022118                            /* calculate the symbol info. */
    2103                             uValue = offTrgObject + pMod->aSegments[iSeg].MapAddress;
     2119                            uValue = offTrgObject + NewBaseAddress + pMod->aSegments[iTrgObject].RVA;
    21042120                        }
    21052121                        else
    2106                             uValue = pMod->aSegments[iSeg].MapAddress;
     2122                            uValue = NewBaseAddress + pMod->aSegments[iTrgObject].RVA;
    21072123                        if (    (u.prlc->nr_stype & NRALIAS)
    2108                             ||  (pMod->aSegments[iSeg].fFlags & KLDRSEG_FLAG_16BIT))
    2109                             iSelector = pMod->aSegments[iSeg].Sel16bit;
     2124                            ||  (pMod->aSegments[iTrgObject].fFlags & KLDRSEG_FLAG_16BIT))
     2125                            iSelector = pMod->aSegments[iTrgObject].Sel16bit;
    21102126                        else
    2111                             iSelector = pMod->aSegments[iSeg].SelFlat;
     2127                            iSelector = pMod->aSegments[iTrgObject].SelFlat;
    21122128                        fKind = 0;
    21132129                        break;
     
    22352251
    22362252                /*
    2237                  * Deal with the 'source' (i.e. the place that should be modified (very logical).
     2253                 * Deal with the 'source' (i.e. the place that should be modified - very logical).
    22382254                 */
    22392255                if (!(u.prlc->nr_stype & NRCHAIN))
     
    22492265                            &&  off >= 0
    22502266                            &&  off <= OBJPAGELEN - 4)
    2251                         *(uint32_t *)&pbPage[off] = uValue - (PageAddress + off);
     2267                        *(uint32_t *)&pbPage[off] = uValue - (PageAddress + off + 4);
    22522268                    else
    22532269                    {
     
    22852301                            int off = *poffSrc++;
    22862302                            if (off >= 0 && off <= OBJPAGELEN - 4)
    2287                                 *(uint32_t *)&pbPage[off] = uValue - (PageAddress + off);
     2303                                *(uint32_t *)&pbPage[off] = uValue - (PageAddress + off + 4);
    22882304                            else
    22892305                            {
     
    23342350                            int iSelector, KLDRADDR uValue, uint32_t fKind)
    23352351{
    2336     static const uint8_t s_acb[16] =
    2337     {
    2338         1, /* 0: NRSBYT */
    2339         0,
    2340         2, /* 2: NRSSEG - selector */
    2341         4, /* 3: NRSPTR - 16:16 */
    2342         0,
    2343         2, /* 5: NRSOFF - 16-bit offset */
    2344         6, /* 6: NRPTR48 - 16:32 */
    2345         4, /* 7: NROFF32 - 32-bit offset */
    2346         4, /* 8: NRSOFF32 - 32-bit offset self relative */
    2347         0, 0, 0, 0, 0, 0, 0
    2348     };
    23492352#pragma pack(1) /* just to be sure */
    23502353    union
     
    24142417            break;
    24152418        case NRSOFF32:
    2416             uData.off32 = (uint32_t)uValue - (PageAddress + off);
     2419            uData.off32 = (uint32_t)uValue - (PageAddress + off + 4);
    24172420            cb = 4;
    24182421            break;
Note: See TracChangeset for help on using the changeset viewer.