Ignore:
Timestamp:
Jul 8, 2001, 5:23:44 AM (24 years ago)
Author:
bird
Message:

Three things. Fixed the way we get the environment variables and use our own search methods for the LIBPATHs. Corrected and partly rewrote applyFixup, splitted out delta fixups for performance reasons. Mark all normal executables 'NO INTERNAL FIXUPS' to try force them to load the given address.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/pe2lx/pe2lx.cpp

    r5985 r6234  
    1 /* $Id: pe2lx.cpp,v 1.27 2001-06-13 04:49:11 bird Exp $
     1/* $Id: pe2lx.cpp,v 1.28 2001-07-08 03:23:44 bird Exp $
    22 *
    33 * Pe2Lx class implementation. Ring 0 and Ring 3
     
    1818#define INCL_DOSERRORS                  /* DOS Error codes. */
    1919#define INCL_OS2KRNL_LDR                /* Loader definitions. */
     20#define INCL_OS2KRNL_PTDA               /* PTDA definitions. */
    2021#ifdef RING0
    2122    #define INCL_NOAPI                  /* RING0: No apis. */
     
    101102    #include "ldr.h"                    /* ldr helpers. (ldrGetExePath) */
    102103    #include "env.h"                    /* Environment helpers. */
     104    #include "dev32hlp.h"               /* 32-bit devhlpers. Needs LOCKHANDLE. */
     105    #include "PerTaskW32kData.h"        /* Per Task Win32k Data. */
    103106#endif
    104107#include "modulebase.h"                 /* ModuleBase class definitions, ++. */
     
    587590        }
    588591    }
     592    ulImageBase = pNtHdrs->OptionalHeader.ImageBase;
    589593    LXHdr.e32_mflags = pNtHdrs->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI
    590594        ? E32PMAPI : E32PMW;
     
    592596        LXHdr.e32_mflags |= E32LIBINIT | E32LIBTERM | E32MODDLL;
    593597    else
     598    {
    594599        LXHdr.e32_mflags |= E32MODEXE;
    595     if (pNtHdrs->FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED)
    596         LXHdr.e32_mflags |= E32NOINTFIX;
    597     ulImageBase = pNtHdrs->OptionalHeader.ImageBase;
     600        if (    pNtHdrs->FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED     /* Force location if possible. */
     601            ||  ulImageBase < 0x04000000 && ulImageBase + pNtHdrs->OptionalHeader.SizeOfImage < 0x04000000)
     602            LXHdr.e32_mflags |= E32NOINTFIX;
     603    }
    598604
    599605    /* 13.Convert exports. */
     
    10911097                #ifdef DEBUG
    10921098                if (cObjects != pSMTE->smte_objcnt)
    1093                     printErr(("cObject(%d) != smte_objcnt(%d)\n", cObjects, pSMTE->smte_objcnt));
     1099                    printErr(("cObjects(%d) != smte_objcnt(%d)\n", cObjects, pSMTE->smte_objcnt));
    10941100                #endif
    10951101                fApplyFixups = FALSE;
     
    11081114        }
    11091115
     1116        if (fDeltaOnly)
     1117            return applyFixupsDelta(pvPage, ulDelta, ulRVAPage);
     1118
     1119        /*
     1120         * Iterate thru the fixup chunks until we find one or two with fixups valid for
     1121         * this page. I say one or two since we might have cross page fixups from the previous page
     1122         * So, we'll have to start working at the previous page.
     1123         * ASSUME: -fixups are sorted ascendingly on page RVA. only one chunk per page.
     1124         *         -only one cross page fixup at each end which doesn't overlapp with other fixups.
     1125         */
    11101126        PIMAGE_BASE_RELOCATION pbr = pBaseRelocs;
    1111         ULONG ulBefore;
    1112         ULONG ulAfter;
    1113         ULONG flRead = 0;   /* bitmask: 0 = no read, 1 = ulBefore is read, 2 = ulAfter is read */
    11141127
    11151128        while ((unsigned)pbr - (unsigned)pBaseRelocs + 8 < cbBaseRelocs /* 8= VirtualAddress and SizeOfBlock members */
     
    11171130               && pbr->VirtualAddress < ulRVAPage + PAGESIZE)
    11181131        {
     1132
    11191133            if (pbr->VirtualAddress + PAGESIZE >= ulRVAPage)
    11201134            {
     
    11291143                }
    11301144
     1145
     1146                /*
     1147                 * skip to near end of previous page to save time
     1148                 * I just don't dare to skip to the second last offset,
     1149                 * 7 offsets from the end sounds nice and secure.
     1150                 */
     1151                if (pbr->VirtualAddress < ulRVAPage && cRelocations > 7)
     1152                {
     1153                    pwoffFixup += cRelocations - 7; /*  */
     1154                    cRelocations = 7;
     1155                }
     1156
     1157
     1158                /*
     1159                 * Loop thru the fixups in this chunk.
     1160                 */
    11311161                while (cRelocations != 0)
    11321162                {
    1133                     static char acbFixupTypes[16] = {0x00, 0x02, 0x02, 0x04,
     1163                    /*
     1164                     * Fixup size table. 0xFF for fixups which aren't supported
     1165                     * or is just non-sense.
     1166                     */
     1167                    #define CBFIXUPMAX 4
     1168                    static char acbFixupTypes[16] = {0xFF, 0x02, 0x02, 0x04,
    11341169                                                     0xFF, 0xFF, 0xFF, 0xFF,
    11351170                                                     0xFF, 0xFF, 0xFF, 0xFF,
    11361171                                                     0xFF, 0xFF, 0xFF, 0xFF};
    1137                     int   offFixup  = *pwoffFixup & (PAGESIZE-1);
     1172                    int   offFixup  = *pwoffFixup & (int)(PAGESIZE-1);
    11381173                    int   fType     = *pwoffFixup >> 12;
    11391174                    int   cbFixup   = acbFixupTypes[fType];
    11401175
    1141                     if (cbFixup != 0 && cbFixup <= 4
     1176                    if (cbFixup <= CBFIXUPMAX
    11421177                        && offFixup + pbr->VirtualAddress + (cbFixup-1) >= ulRVAPage
    11431178                        && offFixup + pbr->VirtualAddress < ulRVAPage + PAGESIZE
     
    11461181                        ULONG       iObj;
    11471182                        ULONG       ulTarget;
    1148                         PULONG      pul;        /* Pointer to fixup target */
    1149                         ULONG       ul;         /* Crosspage fixups: Conent of fixup target */
    1150                         unsigned    uShift1;    /* Crosspage fixups: Shift */
    1151                         unsigned    uShift2;    /* Crosspage fixups: Inverse of Shift1 */
     1183                        ULONG       ul;         /* Crosspage fixups: Content of fixup target */
    11521184
    11531185                        if (offFixup + pbr->VirtualAddress < ulRVAPage)
    11541186                        {   /*
    11551187                             * Crosspagefixup - from the page before
     1188                             *  Start by reading the bytes on the previous page. We have to in case
     1189                             *  of carray.
    11561190                             */
    1157                             uShift1 = (unsigned)((offFixup + pbr->VirtualAddress) % cbFixup) * 8;
    1158                             uShift2 = cbFixup * 8 - uShift1;
    1159                             pul     = (PULONG)pvPage;
    1160                             ul      = *pul;
     1191                            //printInf(("Crosspagefixup at offset=%d type=%d\n", offFixup - PAGESIZE, fType));
     1192                            printf("Crosspagefixup at offset=%d type=%d\n", offFixup - PAGESIZE, fType);
     1193                            rc = readAtRVA(ulRVAPage + offFixup - PAGESIZE, SSToDS(&ul), sizeof(ul));
     1194                            if (rc != NO_ERROR)
     1195                            {
     1196                                printErr(("readAtRVA(0x%08x, ul(Before)..) failed with rc=%d\n", ulRVAPage + offFixup - PAGESIZE, rc));
     1197                                return rc;
     1198                            }
     1199
     1200                            /*
     1201                             * If none-delta and highlow fixup try resolve target address.
     1202                             * Falls back on delta fixup. We have to do this because of
     1203                             * object alignment problems.
     1204                             */
     1205                            iObj = ~0UL;
    11611206                            if (!fDeltaOnly && fType == IMAGE_REL_BASED_HIGHLOW)
    11621207                            {
    1163                                 /* Read? */
    1164                                 if ((flRead & 1) == 0)
    1165                                 {
    1166                                     rc = readAtRVA(ulRVAPage - 4, SSToDS(&ulBefore), sizeof(ulBefore));
    1167                                     if (rc != NO_ERROR)
    1168                                     {
    1169                                         printErr(("readAtRVA(0x%08x, ulBefore..) failed with rc=%d\n", ulRVAPage-4, rc));
    1170                                         return rc;
    1171                                     }
    1172                                     flRead |= 1;
    1173                                 }
    11741208                                /* Get target pointer, find it's object and apply the fixup */
    1175                                 ulTarget = (ulBefore >> uShift1) | (ul << uShift2);
    1176                                 ulTarget -= ulImageBase; /* ulTarget is now an RVA */
     1209                                ulTarget = ul - ulImageBase;        /* ulTarget is now an RVA */
    11771210                                iObj = 0UL;
    11781211                                while (iObj < cObjects
     
    11821215                                    iObj++;
    11831216                                if (iObj < cObjects)
    1184                                     *pul = ((pSMTE->smte_objtab[iObj].ote_base + ulTarget - paObjects[iObj].ulRVA) >> uShift2)
    1185                                                          | (ul & ((~0UL) << uShift1));
    1186                                 else
    1187                                     *pul = (((ulDelta >> uShift2) + ul) & ((~0UL) >> uShift2)) | (ul & ((~0UL) << uShift1));
     1217                                    ul = pSMTE->smte_objtab[iObj].ote_base + ulTarget - paObjects[iObj].ulRVA;
    11881218                            }
    1189                             else
    1190                             {   /* apply delta fixup */
     1219
     1220                            /*
     1221                             * Apply delta fixup.
     1222                             */
     1223                            if (iObj >= cObjects)
     1224                            {
    11911225                                switch (fType)
    11921226                                {
     1227                                    case IMAGE_REL_BASED_LOW:
    11931228                                    case IMAGE_REL_BASED_HIGHLOW:
    1194                                         *pul = (((ulDelta >> uShift2) + ul) & ((~0UL) >> uShift2)) | (ul & ((~0UL) << uShift1));
     1229                                        ul += ulDelta;
    11951230                                        break;
    11961231                                    case IMAGE_REL_BASED_HIGH:
    11971232                                    case IMAGE_REL_BASED_HIGHADJ:  /* According to M$ docs these seems to be the same fixups. */
    11981233                                    case IMAGE_REL_BASED_HIGH3ADJ:
    1199                                         *pul = (((ulDelta >> 24) + ul) & 0xFF) | (ul & 0xFFFFFF00UL);
     1234                                        ul += ulDelta >> 16;
    12001235                                        break;
    1201                                     case IMAGE_REL_BASED_LOW:
    1202                                         *pul = (((ulDelta >>  8) + ul) & 0xFF) | (ul & 0xFFFFFF00UL);
     1236                                    case IMAGE_REL_BASED_ABSOLUTE:
    12031237                                        break;
     1238                                    default:
     1239                                        printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup));
    12041240                                }
    12051241                            }
     1242
     1243                            /*
     1244                             * Copy the needed fixup data from ul to the page.
     1245                             */
     1246                            if (cbFixup <= CBFIXUPMAX)
     1247                                memcpy(pvPage, (char*)SSToDS(&ul) + PAGESIZE - offFixup, (size_t)(cbFixup - PAGESIZE + offFixup));
    12061248                        }
    12071249                        else if (offFixup + pbr->VirtualAddress + cbFixup > ulRVAPage + PAGESIZE)
     
    12091251                             * Crosspagefixup - into the page afterwards
    12101252                             */
    1211                             uShift1 = (unsigned)((offFixup + pbr->VirtualAddress) % cbFixup) * 8;
    1212                             uShift2 = cbFixup * 8 - uShift1;
    1213                             pul = (PULONG)((unsigned)pvPage + PAGESIZE - sizeof(ULONG));
    1214                             ul = *pul;
     1253                            printInf(("Crosspagefixup at offset=%d type=%d\n", PAGESIZE-offFixup, fType));
     1254
     1255                            /*
     1256                             * If none-delta and highlow fixup then read the full 4 bytes so we can
     1257                             * resolve the target address and fix it.
     1258                             * If we fail to fix it we'll fall back on delta fixup.
     1259                             */
     1260                            iObj = ~0UL;
    12151261                            if (!fDeltaOnly && fType == IMAGE_REL_BASED_HIGHLOW)
    12161262                            {
    1217                                 /* Read? */
    1218                                 if ((flRead & 2) == 0)
     1263                                rc = readAtRVA(ulRVAPage +  offFixup, SSToDS(&ul), sizeof(ul));
     1264                                if (rc != NO_ERROR)
    12191265                                {
    1220                                     rc = readAtRVA(ulRVAPage+PAGESIZE, SSToDS(&ulAfter), sizeof(ulAfter));
    1221                                     if (rc != NO_ERROR)
    1222                                     {
    1223                                         printErr(("readAtRVA(0x%08x, ulAfter..) failed with rc=%d\n", ulRVAPage+PAGESIZE, rc));
    1224                                         return rc;
    1225                                     }
    1226                                     flRead |= 2;
     1266                                    printErr(("readAtRVA(0x%08x, ul(After)..) failed with rc=%d\n", ulRVAPage+offFixup, rc));
     1267                                    return rc;
    12271268                                }
     1269
    12281270                                /* Get target pointer, find it's object and apply the fixup */
    1229                                 ulTarget = (ulAfter << uShift2) | (ul >> uShift1);
    1230                                 ulTarget -= ulImageBase; /* ulTarget is now an RVA */
     1271                                ulTarget = ul - ulImageBase; /* ulTarget is now an RVA */
    12311272                                iObj = 0UL;
    12321273                                while (iObj < cObjects
     
    12361277                                    iObj++;
    12371278                                if (iObj < cObjects)
    1238                                     *pul = ((pSMTE->smte_objtab[iObj].ote_base + ulTarget - paObjects[iObj].ulRVA) << uShift1)
    1239                                            | (ul & ((~0UL) >> uShift2));
    1240                                 else
    1241                                     *pul += ulDelta << uShift1;
     1279                                    ul = pSMTE->smte_objtab[iObj].ote_base + ulTarget - paObjects[iObj].ulRVA;
    12421280                            }
    1243                             else
    1244                             {   /* apply delta fixup */
     1281
     1282                            /*
     1283                             * Apply delta fixup.
     1284                             */
     1285                            if (iObj >= cObjects)
     1286                            {
     1287                                ul = 0;
     1288                                memcpy(SSToDS(&ul), (char*)pvPage + offFixup, (size_t)(PAGESIZE - offFixup));
    12451289                                switch (fType)
    12461290                                {
     1291                                    case IMAGE_REL_BASED_LOW:
    12471292                                    case IMAGE_REL_BASED_HIGHLOW:
    1248                                         *pul += ulDelta << uShift1;
     1293                                        ul += ulDelta;
    12491294                                        break;
    12501295                                    case IMAGE_REL_BASED_HIGH:
    12511296                                    case IMAGE_REL_BASED_HIGHADJ:  /* According to M$ docs these seems to be the same fixups. */
    12521297                                    case IMAGE_REL_BASED_HIGH3ADJ:
    1253                                         *pul += ulDelta << 8;
     1298                                        ul += ulDelta >> 8;
    12541299                                        break;
    1255                                     case IMAGE_REL_BASED_LOW:
    1256                                         *pul += ulDelta << 24;
     1300                                    case IMAGE_REL_BASED_ABSOLUTE:
    12571301                                        break;
     1302                                    default:
     1303                                        printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup));
    12581304                                }
    12591305                            }
     1306
     1307                            /*
     1308                             * Copy the needed fixup data from ul to the page.
     1309                             */
     1310                            if (cbFixup <= CBFIXUPMAX)
     1311                                memcpy((char*)pvPage + offFixup, (char*)SSToDS(&ul), (size_t)(PAGESIZE - offFixup));
    12601312                        }
    12611313                        else
     
    12631315                             * Common fixup
    12641316                             */
     1317                            PULONG      pul;        /* Pointer to fixup target */
    12651318                            pul = (PULONG)((unsigned)pvPage + offFixup + pbr->VirtualAddress - ulRVAPage);
    12661319                            switch (fType)
     
    12721325                                    else
    12731326                                    {
    1274                                         ulTarget = *pul;
    1275                                         ulTarget -= ulImageBase; /* ulTarget is now an RVA */
     1327                                        ulTarget = *pul - ulImageBase;  /* ulTarget is now an RVA */
    12761328                                        iObj = 0UL;
    12771329                                        while (iObj < cObjects
     
    12861338                                    }
    12871339                                    break;
     1340
     1341                                /* Placeholder. */
     1342                                case IMAGE_REL_BASED_ABSOLUTE:
     1343                                    break;
     1344
    12881345                                /* Will probably not work very well until the 64KB object alignment is gone! */
    12891346                                case IMAGE_REL_BASED_HIGH:
     
    12981355                                    *(PUSHORT)pul += (USHORT)ulDelta;
    12991356                                    break;
     1357                                default:
     1358                                    printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup));
    13001359                            }
    13011360                        }
    13021361                    }
    13031362
    1304                     /* Next offset/type */
     1363                    /*
     1364                     * Next offset/type
     1365                     */
    13051366                    pwoffFixup++;
    13061367                    cRelocations--;
    1307                 }
    1308             }
    1309 
    1310             /* next */
     1368                } /* while loop */
     1369
     1370            } /* else: not touching this page */
     1371
     1372            /*
     1373             * Next Fixup chunk. (i.e. next page)
     1374             */
    13111375            pbr = (PIMAGE_BASE_RELOCATION)((unsigned)pbr + pbr->SizeOfBlock);
    1312         }
    1313     }
     1376        } /* while loop */
     1377    } /* else: don't need to apply fixups */
    13141378    NOREF(iPageTable);
    13151379    NOREF(pvPTDA);
     
    13191383
    13201384
     1385/**
     1386 * applyFixups worker used when only deltas are to be applied.
     1387 */
     1388ULONG  Pe2Lx::applyFixupsDelta(PVOID pvPage, ULONG ulDelta, ULONG ulRVAPage)
     1389{
     1390    /*
     1391     * Iterate thru the fixup chunks until we find one or two with fixups valid for
     1392     * this page. I say one or two since we might have cross page fixups from the previous page
     1393     * So, we'll have to start working at the previous page.
     1394     * ASSUME: -fixups are sorted ascendingly on page RVA. only one chunk per page.
     1395     *         -only one cross page fixup at each end which doesn't overlapp with other fixups.
     1396     */
     1397    PIMAGE_BASE_RELOCATION pbr = pBaseRelocs;
     1398
     1399    while ((unsigned)pbr - (unsigned)pBaseRelocs + 8 < cbBaseRelocs /* 8= VirtualAddress and SizeOfBlock members */
     1400           && pbr->SizeOfBlock >= 8
     1401           && pbr->VirtualAddress < ulRVAPage + PAGESIZE)
     1402    {
     1403
     1404        if (pbr->VirtualAddress + PAGESIZE >= ulRVAPage)
     1405        {
     1406            PWORD pwoffFixup   = &pbr->TypeOffset[0];
     1407            ULONG cRelocations = (pbr->SizeOfBlock - offsetof(IMAGE_BASE_RELOCATION, TypeOffset)) / sizeof(WORD); /* note that sizeof(BaseReloc) is 12 bytes! */
     1408
     1409            /* Some bound checking just to be sure it works... */
     1410            if ((unsigned)pbr - (unsigned)pBaseRelocs + pbr->SizeOfBlock > cbBaseRelocs)
     1411            {
     1412                printWar(("Block ends after BaseRelocation datadirectory.\n"));
     1413                cRelocations = (((unsigned)pBaseRelocs + cbBaseRelocs) - (unsigned)pbr - offsetof(IMAGE_BASE_RELOCATION, TypeOffset)) / sizeof(WORD);
     1414            }
     1415
     1416
     1417            /*
     1418             * skip to near end of previous page to save time
     1419             * I just don't dare to skip to the second last offset,
     1420             * 7 offsets from the end sounds nice and secure.
     1421             */
     1422            if (pbr->VirtualAddress < ulRVAPage && cRelocations > 7)
     1423            {
     1424                pwoffFixup += cRelocations - 7; /*  */
     1425                cRelocations = 7;
     1426            }
     1427
     1428
     1429            /*
     1430             * Loop thru the fixups in this chunk.
     1431             */
     1432            while (cRelocations != 0)
     1433            {
     1434                /*
     1435                 * Fixup size table. 0xFF for fixups which aren't supported
     1436                 * or is just non-sense.
     1437                 */
     1438                #define CBFIXUPMAX 4
     1439                static char acbFixupTypes[16] = {0xFF, 0x02, 0x02, 0x04,
     1440                                                 0xFF, 0xFF, 0xFF, 0xFF,
     1441                                                 0xFF, 0xFF, 0xFF, 0xFF,
     1442                                                 0xFF, 0xFF, 0xFF, 0xFF};
     1443                int   offFixup  = *pwoffFixup & (int)(PAGESIZE-1);
     1444                int   fType     = *pwoffFixup >> 12;
     1445                int   cbFixup   = acbFixupTypes[fType];
     1446
     1447                if (cbFixup <= CBFIXUPMAX
     1448                    && offFixup + pbr->VirtualAddress + (cbFixup-1) >= ulRVAPage
     1449                    && offFixup + pbr->VirtualAddress < ulRVAPage + PAGESIZE
     1450                    )
     1451                {
     1452                    ULONG       ul;         /* Crosspage fixups: Content of fixup target */
     1453
     1454                    if (offFixup + pbr->VirtualAddress < ulRVAPage)
     1455                    {   /*
     1456                         * Crosspagefixup - from the page before
     1457                         *  Start by reading the bytes on the previous page. We have to in case
     1458                         *  of carray.
     1459                         */
     1460                        printInf(("Crosspagefixup at offset=%d type=%d\n", offFixup - PAGESIZE, fType));
     1461                        APIRET rc = readAtRVA(ulRVAPage + offFixup - PAGESIZE, SSToDS(&ul), sizeof(ul));
     1462                        if (rc != NO_ERROR)
     1463                        {
     1464                            printErr(("readAtRVA(0x%08x, ul(Before)..) failed with rc=%d\n", ulRVAPage + offFixup - PAGESIZE, rc));
     1465                            return rc;
     1466                        }
     1467
     1468                        /*
     1469                         * Apply delta fixup.
     1470                         */
     1471                        switch (fType)
     1472                        {
     1473                            case IMAGE_REL_BASED_LOW:
     1474                            case IMAGE_REL_BASED_HIGHLOW:
     1475                                ul += ulDelta;
     1476                                break;
     1477                            case IMAGE_REL_BASED_HIGH:
     1478                            case IMAGE_REL_BASED_HIGHADJ:  /* According to M$ docs these seems to be the same fixups. */
     1479                            case IMAGE_REL_BASED_HIGH3ADJ:
     1480                                ul += ulDelta >> 16;
     1481                                break;
     1482                            case IMAGE_REL_BASED_ABSOLUTE:
     1483                                break;
     1484                            default:
     1485                                printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup));
     1486                        }
     1487
     1488                        /*
     1489                         * Copy the needed fixup data from ul to the page.
     1490                         */
     1491                        if (cbFixup <= CBFIXUPMAX)
     1492                            memcpy(pvPage, (char*)SSToDS(&ul) + PAGESIZE - offFixup, (size_t)(cbFixup - PAGESIZE + offFixup));
     1493                    }
     1494                    else if (offFixup + pbr->VirtualAddress + cbFixup > ulRVAPage + PAGESIZE)
     1495                    {   /*
     1496                         * Crosspagefixup - into the page afterwards
     1497                         */
     1498                        printInf(("Crosspagefixup at offset=%d type=%d\n", PAGESIZE-offFixup, fType));
     1499
     1500                        /*
     1501                         * Apply delta fixup.
     1502                         */
     1503                        ul = 0;
     1504                        memcpy(SSToDS(&ul), (char*)pvPage + offFixup, (size_t)(PAGESIZE - offFixup));
     1505                        switch (fType)
     1506                        {
     1507                            case IMAGE_REL_BASED_LOW:
     1508                            case IMAGE_REL_BASED_HIGHLOW:
     1509                                ul += ulDelta;
     1510                                break;
     1511                            case IMAGE_REL_BASED_HIGH:
     1512                            case IMAGE_REL_BASED_HIGHADJ:  /* According to M$ docs these seems to be the same fixups. */
     1513                            case IMAGE_REL_BASED_HIGH3ADJ:
     1514                                ul += ulDelta >> 8;
     1515                                break;
     1516                            case IMAGE_REL_BASED_ABSOLUTE:
     1517                                break;
     1518                            default:
     1519                                printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup));
     1520                        }
     1521
     1522                        /*
     1523                         * Copy the needed fixup data from ul to the page.
     1524                         */
     1525                        if (cbFixup <= CBFIXUPMAX)
     1526                            memcpy((char*)pvPage + offFixup, (char*)SSToDS(&ul), (size_t)(PAGESIZE - offFixup));
     1527                    }
     1528                    else
     1529                    {   /*
     1530                         * Common fixup
     1531                         */
     1532                        PULONG      pul;        /* Pointer to fixup target */
     1533                        pul = (PULONG)((unsigned)pvPage + offFixup + pbr->VirtualAddress - ulRVAPage);
     1534                        switch (fType)
     1535                        {
     1536                            case IMAGE_REL_BASED_HIGHLOW:
     1537                                printInfA(("IMAGE_REL_BASED_HIGHLOW offset=0x%08x\n", offFixup));
     1538                                *pul += ulDelta;
     1539                                break;
     1540                            /* Placeholder. */
     1541                            case IMAGE_REL_BASED_ABSOLUTE:
     1542                                break;
     1543                            /* Will probably not work very well until the 64KB object alignment is gone! */
     1544                            case IMAGE_REL_BASED_HIGH:
     1545                            case IMAGE_REL_BASED_HIGHADJ:   /* According to M$ docs these seems to be the same fixups. */
     1546                            case IMAGE_REL_BASED_HIGH3ADJ:
     1547                                printInfA(("IMAGE_REL_BASED_HIGH offset=0x%08x\n", offFixup));
     1548                                *(PUSHORT)pul += (USHORT)(ulDelta >> 16);
     1549                                break;
     1550                            /* Will probably not work very well until the 64KB object alignment is gone! */
     1551                            case IMAGE_REL_BASED_LOW:
     1552                                printInfA(("IMAGE_REL_BASED_LOW  offset=0x%08x\n", offFixup));
     1553                                *(PUSHORT)pul += (USHORT)ulDelta;
     1554                                break;
     1555                            default:
     1556                                printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup));
     1557                        }
     1558                    }
     1559                }
     1560
     1561                /*
     1562                 * Next offset/type
     1563                 */
     1564                pwoffFixup++;
     1565                cRelocations--;
     1566            } /* while loop */
     1567
     1568        } /* else: not touching this page */
     1569
     1570        /*
     1571         * Next Fixup chunk. (i.e. next page)
     1572         */
     1573        pbr = (PIMAGE_BASE_RELOCATION)((unsigned)pbr + pbr->SizeOfBlock);
     1574    } /* while loop */
     1575
     1576    return NO_ERROR;
     1577}
    13211578
    13221579/**
     
    13511608     * Initiate the Odin32 Path static variable and call worker.
    13521609     */
     1610    #ifdef DEBUG
     1611    APIRET rc;
     1612    //kprintf(("pe2lx::openPath(%.*s, %d, %x, %x, %x)\n",
     1613    //         cchFilename, pachFilename, cchFilename, pLdrLv, pful, lLibPath));
     1614    rc = openPath2(pachFilename, cchFilename, pLdrLv, pful, lLibPath, initOdin32Path());
     1615    //kprintf(("pe2lx::openPath rc=%d\n", rc));
     1616    return rc;
     1617    #else
    13531618    return openPath2(pachFilename, cchFilename, pLdrLv, pful, lLibPath, initOdin32Path());
     1619    #endif
    13541620
    13551621    #else
     
    13881654 *              (cchFilename should have been USHORT. But, then the compiler would
    13891655 *               treat it as an ULONG.)
     1656 *              TODO: Support quotes.
    13901657 */
    13911658ULONG  Pe2Lx::openPath2(PCHAR pachFilename, ULONG cchFilename, ldrlv_t *pLdrLv, PULONG pful, ULONG lLibPath, BOOL fOdin32PathValid)
     
    14071674    #define FINDDLL_ENDLIBPATH      9   /* uses ldrOpenPath */
    14081675    #define FINDDLL_FIRST           FINDDLL_EXECUTABLEDIR
    1409     #define FINDDLL_LAST            FINDDLL_PATH
     1676    #define FINDDLL_LAST            FINDDLL_ENDLIBPATH
    14101677
    14111678    struct _LocalVars
     
    14241691    pVars = (struct _LocalVars*)rmalloc(sizeof(struct _LocalVars));
    14251692    if (pVars == NULL)
     1693    {
     1694        printErr(("openPath2: rmalloc failed\n"));
    14261695        return ERROR_NOT_ENOUGH_MEMORY;
     1696    }
    14271697
    14281698    cchExt = cchFilename - 1;
     
    14461716            case FINDDLL_EXECUTABLEDIR:
    14471717                if ((pszPath = ldrGetExePath(pVars->szPath, TRUE)) == NULL)
     1718                {
     1719                    //kprintf(("openPath2: failed to find exe path.\n")); //DEBUG
    14481720                    continue;
     1721                }
    14491722                break;
    14501723
     
    14551728            case FINDDLL_SYSTEM32DIR:
    14561729                if (!fOdin32PathValid)
     1730                {
     1731                    //kprintf(("openPath2: invalid odin32 paths.\n"));
    14571732                    continue;
     1733                }
    14581734                pszPath = pVars->szPath;
    14591735                strcpy(pszPath, pszOdin32Path);
     
    14631739            case FINDDLL_SYSTEM16DIR:
    14641740                if (!fOdin32PathValid)
     1741                {
     1742                    //kprintf(("openPath2: invalid odin32 paths.\n"));
    14651743                    continue;
     1744                }
    14661745                pszPath = pVars->szPath;
    14671746                strcpy(pszPath, pszOdin32Path);
     
    14711750            case FINDDLL_WINDIR:
    14721751                if (!fOdin32PathValid)
     1752                {
     1753                    //kprintf(("openPath2: invalid odin32 paths.\n"));
    14731754                    continue;
     1755                }
    14741756                pszPath = pVars->szPath;
    14751757                strcpy(pszPath, pszOdin32Path);
     
    14781760
    14791761            case FINDDLL_PATH:
    1480                 pszPath = (char*)GetEnv(TRUE);
     1762            {
     1763                PPTD    pptd = GetTaskData(0);
     1764                pszPath = NULL;
     1765                if (pptd)
     1766                    pszPath = pptd->pszzOdin32Env;
     1767                if (!pszPath)
     1768                    pszPath = (char*)GetEnv(TRUE);
    14811769                if (pszPath == NULL)
     1770                {
     1771                    //kprintf(("openPath2: failed to GetEnv.\n"));
    14821772                    continue;
     1773                }
    14831774                pszPath = (char*)ScanEnv(pszPath, "PATH");
    14841775                break;
    1485 
    1486             #if 0
     1776            }
     1777
     1778            #if 1
    14871779            case FINDDLL_BEGINLIBPATH:
    1488                 pszPath = ptda_GetBeginLibpath()...  ;
     1780                pszPath = NULL;
     1781                if (ptdaGetCur())
     1782                    pszPath = ptdaGet_ptda_pBeginLIBPATH(ptdaGetCur());
    14891783                if (pszPath == NULL)
    14901784                    continue;
     
    14961790
    14971791            case FINDDLL_ENDLIBPATH:
    1498                 pszPath = ptda_GetEndLibpath()...  ;
     1792                pszPath = NULL;
     1793                if (ptdaGetCur())
     1794                    pszPath = ptdaGet_ptda_pEndLIBPATH(ptdaGetCur());
    14991795                if (pszPath == NULL)
    15001796                    continue;
    15011797                break;
    15021798            #endif
     1799
    15031800            default: /* !internalerror! */
    15041801                printIPE(("Pe2Lx::openPath(%.*s,..): iPath is %d which is invalid.\n", cchFilename, pachFilename, iPath));
     
    15071804        }
    15081805
     1806        //kprintf(("openPath2: level:%d path=%s\n", iPath, pszPath));
    15091807
    15101808        /** @sketch
     
    15971895     */
    15981896    rfree(pVars);
    1599     return ldrOpenPath(pachFilename, (USHORT)cchFilename, pLdrLv, pful, lLibPath);
     1897    return ERROR_FILE_NOT_FOUND;//ldrOpenPath(pachFilename, (USHORT)cchFilename, pLdrLv, pful, lLibPath);
    16001898
    16011899    #else
     
    16321930    makeObjectTable();
    16331931    memcpy(smte.smte_objtab, paObjTab, sizeof(OTE) * cObjects);
    1634     smte.smte_objtab[0].ote_base = 0x125D0000;
     1932    smte.smte_objtab[0].ote_base = 0x132d0000;
    16351933    for (i = 1; i < cObjects; i++)
    16361934        smte.smte_objtab[i].ote_base = ALIGN(smte.smte_objtab[i-1].ote_size + smte.smte_objtab[i-1].ote_base, 0x10000);
     
    16601958                return rc;
    16611959            }
    1662             rc = applyFixups(&mte, 1, 1, &achPage[0], ulAddress, NULL);
     1960            rc = applyFixups(&mte, i, ulRVA >> PAGESHIFT, &achPage[0], ulAddress, NULL);
    16631961            if (rc != NO_ERROR)
    16641962            {
Note: See TracChangeset for help on using the changeset viewer.