Ignore:
Timestamp:
Oct 1, 2000, 4:58:21 AM (25 years ago)
Author:
bird
Message:

Implemented tool for generating calltab for kernel imports. (mkcalltab)
Implemented API for accessing memory in another process. (*ProcessReadWrite)
Added kernel imports needed to implemented ProcessReadWrite.
Removed unused kernel imports.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/dev32/d32init.c

    r4307 r4347  
    1 /* $Id: d32init.c,v 1.24 2000-09-22 09:22:35 bird Exp $
     1/* $Id: d32init.c,v 1.25 2000-10-01 02:58:15 bird Exp $
    22 *
    33 * d32init.c - 32-bits init routines.
     
    1212*   Defined Constants                                                          *
    1313*******************************************************************************/
    14 #define MAXSIZE_PROLOG 0x18             /* Note that this must be synced with */
    15                                         /* the one used in calltab.asm.       */
    16 #if  0                                  /* Enable this to have extra debug logging. */
     14/*
     15 * Calltab entry sizes.
     16 */
     17#define OVERLOAD16_ENTRY    0x18
     18#define OVERLOAD32_ENTRY    0x14
     19#define IMPORT16_ENTRY      0x08
     20#define IMPORT32_ENTRY      0x08
     21#define VARIMPORT_ENTRY     0x10
     22
     23#if  0
    1724    #define kprintf2(a) kprintf
    1825#else
    19     #define kprintf2(a) (void)0
     26    #define kprintf2(a) {}//
    2027#endif
    2128
     
    8794
    8895/* extern(s) located in calltab.asm */
    89 extern char     callTab[NBR_OF_KRNLIMPORTS][MAXSIZE_PROLOG];
    90 
    91 /* extern(s) located in mytkExecPgm.asm  */
    92 extern char     mytkExecPgm;
    93 extern char     mytkStartProcess;
     96extern char     callTab[1];
     97extern unsigned auFuncs[NBR_OF_KRNLIMPORTS];
    9498
    9599
     
    10591063    int     i;
    10601064    int     cb;
    1061     int     cbmin;
     1065    int     cbmax;
    10621066
    10631067    /* VerifyImporTab32 is called before the initroutine! */
     
    10841088        if (!aImportTab[i].fFound)
    10851089        {
    1086             if (aImportTab[i].fType & EPT_NOT_REQ)
     1090            if (EPTNotReq(aImportTab[i]))
    10871091                continue;
    10881092            else
     
    11191123        #endif
    11201124
    1121         switch (aImportTab[i].fType & ~(EPT_BIT_MASK | EPT_NOT_REQ))
     1125        switch (aImportTab[i].fType & ~(EPT_BIT_MASK | EPT_NOT_REQ | EPT_WRAPPED))
    11221126        {
    11231127            case EPT_PROC:
     
    11281132                if (EPT32BitEntry(aImportTab[i]))
    11291133                {
    1130                     cb = interpretFunctionProlog32((char*)aImportTab[i].ulAddress,
    1131                                                    aImportTab[i].fType == EPT_PROC32);
    1132                     cbmin = 5; /* Size of the jump instruction */
     1134                    cb = interpretFunctionProlog32((char*)aImportTab[i].ulAddress, EPT32Proc(aImportTab[i]));
     1135                    cbmax = OVERLOAD32_ENTRY - 5; /* 5 = Size of the jump instruction */
    11331136                }
    11341137                else
    11351138                {
    1136                     cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress,
    1137                                                    aImportTab[i].fType == EPT_PROC16);
    1138                     cbmin = 7; /* Size of the far jump instruction */
     1139                    cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress, EPT16Proc(aImportTab[i]));
     1140                    cbmax = OVERLOAD16_ENTRY - 7; /* 7 = Size of the far jump instruction */
    11391141                }
    11401142
     
    11421144                 * Check result of the function prolog interpretations.
    11431145                 */
    1144                 if (cb <= 0 || cb + cbmin >= MAXSIZE_PROLOG)
     1146                if (cb <= 0 || cb > cbmax)
    11451147                {   /* failed, too small or too large. */
    1146                     kprintf(("VerifyImportTab32: verify failed for procedure no.%d (cb=%d)\n", i, cb));
     1148                    kprintf(("VerifyImportTab32: verify failed for procedure no.%d (cb=%d), %s\n", i, cb, aImportTab[i].achName));
    11471149                    return (USHORT)(ERROR_D32_TOO_INVALID_PROLOG | (i << ERROR_D32_PROC_SHIFT) | ERROR_D32_PROC_FLAG);
    11481150                }
     
    11541156
    11551157            default:
    1156                 kprintf(("VerifyImportTab32: invalid type/type not implemented\n",i));
     1158                kprintf(("VerifyImportTab32: invalid type/type not implemented. Proc no.%d, %s\n",i, aImportTab[i].achName));
    11571159                Int3(); /* temporary fix! */
    11581160                return (USHORT)(ERROR_D32_NOT_IMPLEMENTED | (i << ERROR_D32_PROC_SHIFT) | ERROR_D32_PROC_FLAG);
     
    11711173int importTabInit(void)
    11721174{
    1173     /* This table must be updated with the overloading functions.
    1174      * It should also hold NOP functions for functions which are of the
    1175      * not required type.
     1175    int     i;
     1176    int     cb;
     1177    int     cbmax;
     1178    char *  pchCTEntry;                 /* Pointer to current calltab entry. */
     1179
     1180    /*
     1181     * Apply build specific changes to the auFuncs table
    11761182     */
    1177     static unsigned auFuncs[NBR_OF_KRNLIMPORTS] =
    1178     {
    1179         (unsigned)myldrRead,            /* 0 */
    1180         (unsigned)myldrOpen,            /* 1 */
    1181         (unsigned)myldrClose,           /* 2 */
    1182         (unsigned)myLDRQAppType,        /* 3 */
    1183         (unsigned)myldrEnum32bitRelRecs,/* 4 */
    1184         0,                              /* 5 */
    1185         0,                              /* 6 */
    1186         0,                              /* 7 */
    1187         0,                              /* 8 */
    1188         0,                              /* 9 */
    1189         0,                              /* 10 */
    1190         0,                              /* 11 */
    1191         0,                              /* 12 */
    1192         (unsigned)&mytkExecPgm,         /* 13 */
    1193         (unsigned)&mytkStartProcess,    /* 14 */
    1194         0,                              /* 15 */
    1195         0,                              /* 16 */
    1196         0,                              /* 17 */
    1197         0,                              /* 18 */
    1198         0,                              /* 19 */
    1199         (unsigned)myldrOpenPath_old,    /* 20 */
    1200         0,                              /* 21 */
    1201         0,                              /* 22 */
    1202         0,                              /* 23 */
    1203         0,                              /* 24 */
    1204         0,                              /* 25 */
    1205         0,                              /* 26 */
    1206         0,                              /* 27 */
    1207         0,                              /* 28 */
    1208         0,                              /* 29 */
    1209         0,                              /* 30 */
    1210         0,                              /* 31 */
    1211         0,                              /* 32 */
    1212         0,                              /* 33 */
    1213         0,                              /* 34 */
    1214         0,                              /* 35 */
    1215         0,                              /* 36 */
    1216         0,                              /* 37 */
    1217         0,                              /* 38 */
    1218         0,                              /* 39 */
    1219         0,                              /* 40 */
    1220         (unsigned)nopSecPathFromSFN     /* 41 */
    1221         #if 0 /* experimenting */
    1222         ,(unsigned)myldrSetVMflags,     /* 42 */
    1223         #endif
    1224     };
    1225     int i;
    1226     int cb;
    1227     int cbmin;
    1228 
    1229 #ifndef R3TST //New function not currently not implemented by fake.c
    1230     /*
    1231      * Build specific changes to the auFuncs table
    1232      */
    1233     if (options.ulBuild >= 14053)
     1183    if (options.ulBuild < 14053)
    12341184    {
    12351185        #ifdef DEBUG
    1236         if (auFuncs[20] != (unsigned)myldrOpenPath_old)
     1186        if (auFuncs[0] != (unsigned)myldrOpenPath)
    12371187        {
    12381188            kprintf(("importTabInit: ASSERTION FAILED auFuncs don't point at myldrOpenPath\n"));
     
    12401190        }
    12411191        #endif
    1242         auFuncs[20] = (unsigned)myldrOpenPath;
     1192        auFuncs[0] = (unsigned)myldrOpenPath_old;
    12431193    }
    1244 #endif
    12451194
    12461195#ifdef R3TST
     
    12541203    {
    12551204        /* EPT_VARIMPORTs are skipped */
    1256         if ((aImportTab[i].fType & ~EPT_BIT_MASK) == EPT_VARIMPORT)
     1205        if ((aImportTab[i].fType & ~(EPT_BIT_MASK | EPT_NOT_REQ)) == EPT_VARIMPORT)
    12571206            continue;
    12581207        /* EPT_NOT_REQ which is not found are set pointing to the nop function provided. */
    1259         if (!aImportTab[i].fFound && (aImportTab[i].fType & EPT_NOT_REQ))
    1260         {
    1261             aImportTab[i].ulAddress = auFuncs[i];
     1208        if (!aImportTab[i].fFound && EPTNotReq(aImportTab[i]))
    12621209            continue;
    1263         }
    12641210
    12651211        if (EPT32BitEntry(aImportTab[i]))
    12661212        {
    1267             cb = interpretFunctionProlog32((char*)aImportTab[i].ulAddress, aImportTab[i].fType == EPT_PROC32);
    1268             cbmin = 5; /* Size of the jump instruction */
     1213            cb = interpretFunctionProlog32((char*)aImportTab[i].ulAddress, EPT32Proc(aImportTab[i]));
     1214
     1215            cbmax = OVERLOAD16_ENTRY - 5; /* 5 = Size of the jump instruction */
    12691216        }
    12701217        else
    12711218        {
    1272             cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress, aImportTab[i].fType == EPT_PROC16);
    1273             cbmin = 7; /* Size of the far jump instruction */
     1219            cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress, EPT16Proc(aImportTab[i]));
     1220            cbmax = OVERLOAD16_ENTRY - 7; /* 7 = Size of the far jump instruction */
    12741221        }
    1275         if (cb <= 0 || cb + cbmin >= MAXSIZE_PROLOG)
     1222        if (cb <= 0 || cb > cbmax)
    12761223        {
    12771224            kprintf(("ImportTabInit: Verify failed for procedure no.%d, cb=%d\n", i, cb));
     
    12831230     * rehook / import
    12841231     */
     1232    pchCTEntry = &callTab[0];
    12851233    for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
    12861234    {
    1287         switch (aImportTab[i].fType & ~EPT_NOT_REQ)
     1235        switch (aImportTab[i].fType & ~EPT_WRAPPED)
    12881236        {
    12891237            /*
     
    12971245                cb = interpretFunctionProlog32((char*)aImportTab[i].ulAddress, TRUE);
    12981246                aImportTab[i].cbProlog = (char)cb;
    1299                 if (cb >= 5 && cb + 5 < MAXSIZE_PROLOG) /* 5(1st): size of jump instruction in the function prolog which jumps to my overloading function */
    1300                 {                                       /* 5(2nd): size of jump instruction which jumps back to the original function after executing the prolog copied to the callTab entry for this function. */
     1247                if (cb >= 5 && cb + 5 < OVERLOAD32_ENTRY) /* 5(1st): size of jump instruction in the function prolog which jumps to my overloading function */
     1248                {                                         /* 5(2nd): size of jump instruction which jumps back to the original function after executing the prolog copied to the callTab entry for this function. */
    13011249                    /*
    13021250                     * Copy function prolog which will be overwritten by the jmp to calltabl.
    13031251                     */
    1304                     memcpy(callTab[i], (void*)aImportTab[i].ulAddress, (size_t)cb);
     1252                    memcpy(pchCTEntry, (void*)aImportTab[i].ulAddress, (size_t)cb);
    13051253
    13061254                    /*
     
    13091257                     * Note: the displacement is relative to the next instruction
    13101258                     */
    1311                     callTab[i][cb] = 0xE9; /* jmp */
    1312                     *(unsigned long*)(void*)&callTab[i][cb+1] = aImportTab[i].ulAddress + cb - (unsigned long)&callTab[i][cb+5];
     1259                    pchCTEntry[cb] = 0xE9; /* jmp */
     1260                    *(unsigned long*)(void*)&pchCTEntry[cb+1] = aImportTab[i].ulAddress + cb - (unsigned long)&pchCTEntry[cb+5];
    13131261
    13141262                    /*
     
    13241272                    return ERROR_D32_IPE | (i << ERROR_D32_PROC_SHIFT) | ERROR_D32_PROC_FLAG;
    13251273                }
     1274                pchCTEntry += OVERLOAD32_ENTRY;
    13261275                break;
    13271276            }
     
    13391288                cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress, TRUE);
    13401289                aImportTab[i].cbProlog = (char)cb;
    1341                 if (cb >= 8 && cb + 7 < MAXSIZE_PROLOG) /* 8: size of a 16:32 jump which jumps to my overloading function (prefixed with 66h in a 16-bit segment) */
    1342                 {                                       /* 7: size of a 16:32 jump which is added to the call tab */
     1290                if (cb >= 8 && cb + 7 < OVERLOAD16_ENTRY) /* 8: size of a 16:32 jump which jumps to my overloading function (prefixed with 66h in a 16-bit segment) */
     1291                {                                         /* 7: size of a 16:32 jump which is added to the call tab */
    13431292                    /*
    13441293                     * Copy function prolog which is to be overwritten.
    13451294                     */
    1346                     memcpy(callTab[i], (void*)aImportTab[i].ulAddress, (size_t)cb);
     1295                    memcpy(pchCTEntry, (void*)aImportTab[i].ulAddress, (size_t)cb);
    13471296
    13481297                    /*
     
    13501299                     * 0xEA <four byte target address> <two byte target selector>
    13511300                     */
    1352                     callTab[i][cb] = 0xEA; /* jmp far ptr */
    1353                     *(unsigned long*)(void*)&callTab[i][cb+1] = aImportTab[i].offObject;
    1354                     *(unsigned short*)(void*)&callTab[i][cb+5] = aImportTab[i].usSel;
     1301                    pchCTEntry[cb] = 0xEA; /* jmp far ptr */
     1302                    *(unsigned long*)(void*)&pchCTEntry[cb+1] = aImportTab[i].offObject;
     1303                    *(unsigned short*)(void*)&pchCTEntry[cb+5] = aImportTab[i].usSel;
    13551304
    13561305                    /*
     
    13691318                    return ERROR_D32_IPE | (i << ERROR_D32_PROC_SHIFT) | ERROR_D32_PROC_FLAG;
    13701319                }
     1320                pchCTEntry += OVERLOAD16_ENTRY;
    13711321                break;
    13721322            }
     
    13741324
    13751325            /*
    1376              * 32-bit imported procedure
     1326             * 32-bit imported procedure.
    13771327             * This is called by issuing a near call to the callTab entry.
    13781328             */
     1329            case EPT_PROCIMPORTNR32:     /* Not required */
     1330                if (!(pchCTEntry[6] = aImportTab[i].fFound))
     1331                    aImportTab[i].ulAddress = auFuncs[i];
    13791332            case EPT_PROCIMPORT32:
    13801333            {
     
    13881341                     * Note: the displacement is relative to the next instruction
    13891342                     */
    1390                     callTab[i][0] = 0xE9; /* jmp */
    1391                     *(unsigned*)(void*)&callTab[i][1] = aImportTab[i].ulAddress - (unsigned)&callTab[i][5];
     1343                    pchCTEntry[0] = 0xE9; /* jmp */
     1344                    *(unsigned*)(void*)&pchCTEntry[1] = aImportTab[i].ulAddress - (unsigned)&pchCTEntry[5];
    13921345                }
    13931346                else
     
    13971350                    return ERROR_D32_IPE | (i << ERROR_D32_PROC_SHIFT) | ERROR_D32_PROC_FLAG;
    13981351                }
     1352                pchCTEntry += IMPORT32_ENTRY;
    13991353                break;
    14001354            }
     
    14051359             * This is called by issuing a far call to the calltab entry.
    14061360             */
     1361            case EPT_PROCIMPORTNR16:    /* Not required */
     1362                if (!(pchCTEntry[7] = aImportTab[i].fFound))
     1363                {
     1364                    aImportTab[i].ulAddress = auFuncs[i];
     1365                    Int3();
     1366                    break;
     1367                }
    14071368            case EPT_PROCIMPORT16:
    14081369            {
     
    14151376                     * 0xEA <four byte target address> <two byte target selector>
    14161377                     */
    1417                     callTab[i][0] = 0xEA; /* jmp far ptr */
    1418                     *(unsigned long*)(void*)&callTab[i][1] = aImportTab[i].offObject;
    1419                     *(unsigned short*)(void*)&callTab[i][5] = aImportTab[i].usSel;
     1378                    pchCTEntry[0] = 0xEA; /* jmp far ptr */
     1379                    *(unsigned long*)(void*)&pchCTEntry[1] = aImportTab[i].offObject;
     1380                    *(unsigned short*)(void*)&pchCTEntry[5] = aImportTab[i].usSel;
    14201381                }
    14211382                else
     
    14251386                    return ERROR_D32_IPE | (i << ERROR_D32_PROC_SHIFT) | ERROR_D32_PROC_FLAG;
    14261387                }
     1388                pchCTEntry += IMPORT16_ENTRY;
    14271389                break;
    14281390            }
     
    14401402            case EPT_VARIMPORT16:
    14411403                aImportTab[i].cbProlog = (char)0;
    1442                 *(unsigned long*)(void*)&callTab[i][0] = aImportTab[i].ulAddress;
    1443                 *(unsigned long*)(void*)&callTab[i][4] = aImportTab[i].offObject;
    1444                 *(unsigned short*)(void*)&callTab[i][8] = aImportTab[i].usSel;
    1445                 *(unsigned short*)(void*)&callTab[i][0xa] = (unsigned short)aImportTab[i].offObject;
    1446                 *(unsigned short*)(void*)&callTab[i][0xc] = aImportTab[i].usSel;
     1404                *(unsigned long*)(void*)&pchCTEntry[0] = aImportTab[i].ulAddress;
     1405                *(unsigned long*)(void*)&pchCTEntry[4] = aImportTab[i].offObject;
     1406                *(unsigned short*)(void*)&pchCTEntry[8] = aImportTab[i].usSel;
     1407                *(unsigned short*)(void*)&pchCTEntry[0xa] = (unsigned short)aImportTab[i].offObject;
     1408                *(unsigned short*)(void*)&pchCTEntry[0xc] = aImportTab[i].usSel;
     1409                pchCTEntry += VARIMPORT_ENTRY;
    14471410                break;
    14481411
     
    14881451VOID R3TstFixImportTab(VOID)
    14891452{
    1490     struct _TstFaker
    1491     {
    1492         unsigned   uAddress;
    1493         int        fObj;                   /* 1 = CODE32, 2 = CODE16, 3 = DATA32, 4 = DATA16 */
    1494     }
    1495     aTstFakers[NBR_OF_KRNLIMPORTS] =
    1496     {
    1497         {(unsigned)fakeldrRead,             1},
    1498         {(unsigned)fakeldrOpen,             1},
    1499         {(unsigned)fakeldrClose,            1},
    1500         {(unsigned)fakeLDRQAppType,         1},
    1501         {(unsigned)fakeldrEnum32bitRelRecs, 1},
    1502         {(unsigned)fakeIOSftOpen,           1},
    1503         {(unsigned)fakeIOSftClose,          1},
    1504         {(unsigned)fakeIOSftTransPath,      1},
    1505         {(unsigned)fakeIOSftReadAt,         1},
    1506         {(unsigned)fakeIOSftWriteAt,        1},
    1507         {(unsigned)fakeSftFileSize,         1},
    1508         {(unsigned)fakeVMAllocMem,          1},
    1509         {(unsigned)fakeVMGetOwner,          1},
    1510         {(unsigned)fakeg_tkExecPgm,         1},
    1511         {(unsigned)fake_tkStartProcess,     1},
    1512         {(unsigned)fakef_FuStrLenZ,         2},
    1513         {(unsigned)fakef_FuStrLen,          2},
    1514         {(unsigned)fakef_FuBuff,            2},
    1515         {(unsigned)fakeVMObjHandleInfo,     1},
    1516         {(unsigned)fakeldrASMpMTEFromHandle,1},
    1517         {(unsigned)fakeldrOpenPath,         1},
    1518         {(unsigned)fakeLDRClearSem,         1},
    1519         {(unsigned)fakeldrFindModule,       1},
    1520         {(unsigned)fakeKSEMRequestMutex,    1},
    1521         {(unsigned)fakeKSEMReleaseMutex,    1},
    1522         {(unsigned)fakeKSEMQueryMutex,      1},
    1523         {(unsigned)fakeKSEMInit,            1},
    1524         {(unsigned)&fakeLDRSem,             3},
    1525         {(unsigned)&fakeLDRLibPath,         3},
    1526         {(unsigned)fakeTKSuBuff,            1},
    1527         {(unsigned)fakeTKFuBuff,            1},
    1528         {(unsigned)fakeTKFuBufLen,          1},
    1529         {(unsigned)fakeldrValidateMteHandle,1},
    1530         {(unsigned)&fakepTCBCur,            4},
    1531         {(unsigned)&fakepPTDACur,           4},
    1532         {(unsigned)&fakeptda_start,         4},
    1533         {(unsigned)&fakeptda_environ,       4},
    1534         {(unsigned)&fakeptda_ptdasem,       4},
    1535         {(unsigned)&fakeptda_module,        4},
    1536         {(unsigned)&fakeptda_pBeginLIBPATH, 4},
    1537         {(unsigned)&fakeldrpFileNameBuf,    3},
    1538         {(unsigned)&fakeSecPathFromSFN,     3}
    1539         #if 0 /* experimenting */
    1540         ,{(unsigned)&fakeldrSetVMflags,      1}
    1541         #endif
    1542     };
    15431453    int i;
    15441454
    15451455    for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
    15461456    {
    1547         switch (aImportTab[i].fType)
     1457        switch (aImportTab[i].fType & ~EPT_NOT_REQ)
    15481458        {
    15491459            case EPT_PROC32:
Note: See TracChangeset for help on using the changeset viewer.