Changeset 2890


Ignore:
Timestamp:
Nov 21, 2006, 5:33:25 PM (19 years ago)
Author:
bird
Message:

LX bugfixing. the unit test succeeds, but there are still things todo.

Location:
trunk/kLdr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdrModLX.c

    r2889 r2890  
    182182    uint32_t i;
    183183    int rc;
     184    int fCanOptimizeMapping;
     185    uint32_t NextRVA;
    184186    *ppModLX = NULL;
    185187
     
    323325    pModLX->pMod = pMod;
    324326    pModLX->pvMapping = 0;
    325     pModLX->cbMapped = Hdr.e32_mpages * Hdr.e32_pagesize;
     327    pModLX->cbMapped = 0;
    326328    pModLX->f32Reserved = 0;
    327329
     
    404406        }
    405407    }
    406     pModLX->cbMapped = pMod->cSegments
    407                      ? pModLX->paObjs[pMod->cSegments - 1].o32_base + pModLX->paObjs[pMod->cSegments - 1].o32_size
    408                        - pModLX->paObjs[pMod->cSegments - 1].o32_size
    409                      : 0;
     408
     409    /*
     410     * Check if we can optimize the mapping by using a different
     411     * object alignment. The linker typically uses 64KB alignment,
     412     * we can easily get away with page alignment in most cases.
     413     */
     414    fCanOptimizeMapping = !(Hdr.e32_mflags & (E32NOINTFIX | E32SYSDLL));
     415    NextRVA = 0;
    410416
    411417    /*
     
    420426        pMod->aSegments[i].cchName = 0;
    421427        pMod->aSegments[i].offFile = -1;
    422         pMod->aSegments[i].cbFile = 0;
     428        pMod->aSegments[i].cbFile = -1;
    423429
    424430        /* size and addresses */
     
    426432        pMod->aSegments[i].cb          = pModLX->paObjs[i].o32_size;
    427433        pMod->aSegments[i].LinkAddress = pModLX->paObjs[i].o32_base;
    428         pMod->aSegments[i].RVA         = pModLX->paObjs[i].o32_base - pModLX->paObjs[0].o32_base;
    429         pMod->aSegments[i].cbMapped    = KLDR_ALIGN_Z(pModLX->paObjs[i].o32_size, 16);
    430         if (i + 1 < pMod->cSegments)
    431             pMod->aSegments[i].cbMapped = pModLX->paObjs[i + 1].o32_base - pModLX->paObjs[i].o32_base;
     434        pMod->aSegments[i].RVA         = NextRVA;
     435        if (fCanOptimizeMapping)
     436            pMod->aSegments[i].cbMapped = KLDR_ALIGN_Z(pModLX->paObjs[i].o32_size, OBJPAGELEN);
     437        else
     438            pMod->aSegments[i].cbMapped = i + 1 < pMod->cSegments
     439                                        ? pModLX->paObjs[i + 1].o32_base - pModLX->paObjs[i].o32_base
     440                                        : KLDR_ALIGN_Z(pModLX->paObjs[i].o32_size, OBJPAGELEN);
     441        NextRVA += pMod->aSegments[i].cbMapped;
    432442
    433443        /* protection */
     
    475485    }
    476486
     487    /* set the mapping size */
     488    pModLX->cbMapped = NextRVA;
     489
    477490    /*
    478491     * We're done.
     
    488501    PKLDRMODLX pModLX = (PKLDRMODLX)pMod->pvData;
    489502    int rc = 0;
    490     KLDRMODLX_ASSERT(pModLX->pvMapping);
     503    KLDRMODLX_ASSERT(!pModLX->pvMapping);
    491504
    492505    if (pMod->pRdr)
     
    922935    kldrModLXResolveBaseAddress(pModLX, &BaseAddress);
    923936
    924     return -1;
     937    return 0;
    925938}
    926939
     
    11931206                case VALID:
    11941207                    if (pMap->o32_pagesize == OBJPAGELEN)
    1195                         rc = kLdrRdrRead(pRdr, pbPage, OBJPAGELEN, pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift);
     1208                        rc = kLdrRdrRead(pRdr, pbPage, OBJPAGELEN,
     1209                                         pModLX->Hdr.e32_datapage + (pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift));
    11961210                    else if (pMap->o32_pagesize < OBJPAGELEN)
    11971211                    {
    1198                         rc = kLdrRdrRead(pRdr, pbPage, pMap->o32_pagesize, pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift);
     1212                        rc = kLdrRdrRead(pRdr, pbPage, pMap->o32_pagesize,
     1213                                         pModLX->Hdr.e32_datapage + (pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift));
    11991214                        kLdrHlpMemSet(pbPage + pMap->o32_pagesize, 0, OBJPAGELEN - pMap->o32_pagesize);
    12001215                    }
     
    12201235
    12211236                    /* read it and ensure 4 extra zero bytes. */
    1222                     rc = kLdrRdrRead(pRdr, pbTmpPage, pMap->o32_pagesize, pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift);
     1237                    rc = kLdrRdrRead(pRdr, pbTmpPage, pMap->o32_pagesize,
     1238                                     pModLX->Hdr.e32_datapage + (pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift));
    12231239                    if (rc)
    12241240                        break;
     
    17091725{
    17101726    PKLDRMODLX pModLX = (PKLDRMODLX)pMod->pvData;
     1727    int rc, rc2;
    17111728
    17121729    /*
     
    17161733        return KLDR_ERR_NOT_MAPPED;
    17171734
    1718     /* the file provider does it all */
    1719     return kLdrRdrRefresh(pMod->pRdr, (void *)pModLX->pvMapping, pMod->cSegments, pMod->aSegments);
     1735    /*
     1736     * Before doing anything we'll have to make all pages writable.
     1737     */
     1738    rc = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 1 /* unprotect */);
     1739    if (rc)
     1740        return rc;
     1741
     1742    /*
     1743     * Load the bits again.
     1744     */
     1745    rc = kldrModLXDoLoadBits(pModLX, (void *)pModLX->pvMapping);
     1746
     1747    /*
     1748     * Restore protection.
     1749     */
     1750    rc2 = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 0 /* protect */);
     1751    if (!rc && rc2)
     1752        rc = rc2;
     1753    return rc;
    17201754}
    17211755
     
    20612095                        if (iModule >= pModLX->Hdr.e32_impmodcnt)
    20622096                            return KLDR_ERR_BAD_FIXUP;
     2097#if 1
     2098                        if (u.prlc->nr_flags & NRICHAIN)
     2099                            return KLDR_ERR_BAD_FIXUP;
     2100#endif
    20632101
    20642102                        /* . */
     
    21052143                            return KLDR_ERR_BAD_FIXUP;
    21062144#if 1
    2107                         if (u.prlc->nr_flags & NRCHAIN)
     2145                        if (u.prlc->nr_flags & NRICHAIN)
    21082146                            return KLDR_ERR_BAD_FIXUP;
    21092147#endif
     
    21602198                 * Deal with the 'source' (i.e. the place that should be modified (very logical).
    21612199                 */
    2162                 if (!(u.prlc->nr_flags & NRCHAIN))
     2200                if (!(u.prlc->nr_stype & NRCHAIN))
    21632201                {
    21642202                    rc = kldrModLXDoReloc(pbPage, u.prlc->r32_soff, uValue, fKind);
     
    21762214                            return rc;
    21772215                    }
     2216                    pb = (const uint8_t *)poffSrc;
    21782217                }
    21792218                else
  • trunk/kLdr/tstkLdrMod.c

    r2878 r2890  
    7979
    8080
     81/**
     82 * Verbose memcmp().
     83 */
     84static int TestMemComp(const void *pv1, const void *pv2, size_t cb)
     85{
     86    size_t          off;
     87    const uint8_t  *pb1 = (const uint8_t *)pv1;
     88    const uint8_t  *pb2 = (const uint8_t *)pv2;
     89    if (!memcmp(pb1, pb2, cb))
     90        return 0;
     91    printf("Mismatching blocks pv1=%p pv2=%p cb=%#x:\n", pv1, pv2, cb);
     92    for (off = 0; off < cb; off++)
     93    {
     94        if (pb1[off] == pb2[off])
     95            continue;
     96        printf("%08x %02x != %02x\n", off, pb1[off], pb2[off]);
     97    }
     98    return memcmp(pb1, pb2, cb); /* lazy */
     99}
     100
    81101
    82102/**
     
    97117    if (rc)
    98118        return Failure("failed to get image bits, rc=%d (a)", rc);
    99     if (memcmp(pvBits2, pvBits, cbImage))
     119    if (TestMemComp(pvBits2, pvBits, cbImage))
    100120        return Failure("relocation test failed, mismatching bits (a)");
    101121
     
    109129    if (rc)
    110130        return Failure("failed to relocate, rc=%d (b2)");
    111     if (memcmp(pvBits2, pvBits, cbImage))
     131    if (TestMemComp(pvBits2, pvBits, cbImage))
    112132        return Failure("relocation test failed, mismatching bits (b)");
    113133
     
    123143    if (rc)
    124144        return Failure("failed to get image bits, rc=%d (c1)", rc);
    125     if (memcmp(pvBits2, pvBits, cbImage))
     145    if (TestMemComp(pvBits2, pvBits, cbImage))
    126146        return Failure("relocation test failed, mismatching bits (c1)");
    127147
     
    134154    if (rc)
    135155        return Failure("failed to get image bits, rc=%d (c2)", rc);
    136     if (memcmp(pvBits2, pvBits, cbImage))
     156    if (TestMemComp(pvBits2, pvBits, cbImage))
    137157        return Failure("relocation test failed, mismatching bits (c2)");
    138158
     
    145165    if (rc)
    146166        return Failure("failed to get image bits, rc=%d (c3)", rc);
    147     if (memcmp(pvBits2, pvBits, cbImage))
     167    if (TestMemComp(pvBits2, pvBits, cbImage))
    148168        return Failure("relocation test failed, mismatching bits (c3)");
    149169
     
    156176    if (rc)
    157177        return Failure("failed to get image bits, rc=%d (c4)", rc);
    158     if (memcmp(pvBits2, pvBits, cbImage))
     178    if (TestMemComp(pvBits2, pvBits, cbImage))
    159179        return Failure("relocation test failed, mismatching bits (c4)");
    160180
     
    167187    if (rc)
    168188        return Failure("failed to get image bits, rc=%d (c5)", rc);
    169     if (memcmp(pvBits2, pvBits, cbImage))
     189    if (TestMemComp(pvBits2, pvBits, cbImage))
    170190        return Failure("relocation test failed, mismatching bits (c5)");
    171191
Note: See TracChangeset for help on using the changeset viewer.