Changeset 2831 for trunk/src


Ignore:
Timestamp:
Feb 20, 2000, 12:52:00 AM (26 years ago)
Author:
bird
Message:

Partly finished 16-bit import code++.

Location:
trunk/src/win32k
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/dev16/probkrnl.c

    r2827 r2831  
    1 /* $Id: probkrnl.c,v 1.10 2000-02-19 08:40:29 bird Exp $
     1/* $Id: probkrnl.c,v 1.11 2000-02-19 23:51:59 bird Exp $
    22 *
    33 * Description:   Autoprobes the os2krnl file and os2krnl[*].sym files.
     
    8383
    8484/*
    85  * aProcTab defines the imported and overloaded OS/2 kernel functions.
    86  * IMPORTANT: aProcTab has a sibling array in d32init.c, aulProc, which must
    87  *            match entry by entry. Adding/removing/shuffling aProcTab, aulProc
     85 * aImportTab defines the imported and overloaded OS/2 kernel functions.
     86 * IMPORTANT: aImportTab has a sibling array in d32init.c, aulProc, which must
     87 *            match entry by entry. Adding/removing/shuffling aImportTab, aulProc
    8888 *            has to be updated immediately!
    8989 */
    90 PROCS aProcTab[NUMBER_OF_PROCS] =
    91 {/* iFound     cchName                  offObject     fType */
    92  /*      iObject      achName                 ulAddress     */
    93     {FALSE, -1,  8, "_ldrRead",             -1,  -1, EPT_PROC},        /* 0 */
    94     {FALSE, -1,  8, "_ldrOpen",             -1,  -1, EPT_PROC},        /* 1 */
    95     {FALSE, -1,  9, "_ldrClose",            -1,  -1, EPT_PROC},        /* 2 */
    96     {FALSE, -1, 12, "_LDRQAppType",         -1,  -1, EPT_PROCIMPORT},  /* 3 */ /* to be removed? */
    97     {FALSE, -1, 20, "_ldrEnum32bitRelRecs", -1,  -1, EPT_PROC},        /* 4 */
    98     {FALSE, -1, 10, "_IOSftOpen",           -1,  -1, EPT_PROCIMPORT},  /* 5 */
    99     {FALSE, -1, 11, "_IOSftClose",          -1,  -1, EPT_PROCIMPORT},  /* 6 */
    100     {FALSE, -1, 15, "_IOSftTransPath",      -1,  -1, EPT_PROCIMPORT},  /* 7 */
    101     {FALSE, -1, 12, "_IOSftReadAt",         -1,  -1, EPT_PROCIMPORT},  /* 8 */
    102     {FALSE, -1, 13, "_IOSftWriteAt",        -1,  -1, EPT_PROCIMPORT},  /* 9 */
    103     {FALSE, -1, 12, "_SftFileSize",         -1,  -1, EPT_PROCIMPORT},  /* 10 */
    104     {FALSE, -1, 11, "_VMAllocMem",          -1,  -1, EPT_PROCIMPORT},  /* 11 */
    105     {FALSE, -1, 11, "_VMGetOwner",          -1,  -1, EPT_PROCIMPORT},  /* 12 */
    106     {FALSE, -1, 11, "g_tkExecPgm",          -1,  -1, EPT_PROC}         /* 13 */
     90IMPORTKRNLSYM aImportTab[NBR_OF_KRNLIMPORTS] =
     91{/* iFound     cchName                  offObject    usSel        */
     92 /*      iObject      achName                 ulAddress  fType    */
     93    {FALSE, -1,  8, "_ldrRead",             -1,  -1, -1, EPT_PROC32},        /* 0 */
     94    {FALSE, -1,  8, "_ldrOpen",             -1,  -1, -1, EPT_PROC32},        /* 1 */
     95    {FALSE, -1,  9, "_ldrClose",            -1,  -1, -1, EPT_PROC32},        /* 2 */
     96    {FALSE, -1, 12, "_LDRQAppType",         -1,  -1, -1, EPT_PROCIMPORT32},  /* 3 */ /* to be removed? */
     97    {FALSE, -1, 20, "_ldrEnum32bitRelRecs", -1,  -1, -1, EPT_PROC32},        /* 4 */
     98    {FALSE, -1, 10, "_IOSftOpen",           -1,  -1, -1, EPT_PROCIMPORT32},  /* 5 */
     99    {FALSE, -1, 11, "_IOSftClose",          -1,  -1, -1, EPT_PROCIMPORT32},  /* 6 */
     100    {FALSE, -1, 15, "_IOSftTransPath",      -1,  -1, -1, EPT_PROCIMPORT32},  /* 7 */
     101    {FALSE, -1, 12, "_IOSftReadAt",         -1,  -1, -1, EPT_PROCIMPORT32},  /* 8 */
     102    {FALSE, -1, 13, "_IOSftWriteAt",        -1,  -1, -1, EPT_PROCIMPORT32},  /* 9 */
     103    {FALSE, -1, 12, "_SftFileSize",         -1,  -1, -1, EPT_PROCIMPORT32},  /* 10 */
     104    {FALSE, -1, 11, "_VMAllocMem",          -1,  -1, -1, EPT_PROCIMPORT32},  /* 11 */
     105    {FALSE, -1, 11, "_VMGetOwner",          -1,  -1, -1, EPT_PROCIMPORT32},  /* 12 */
     106    {FALSE, -1, 11, "g_tkExecPgm",          -1,  -1, -1, EPT_PROC32},        /* 13 */
     107    {FALSE, -1, 11, "f_FuStrLenZ",          -1,  -1, -1, EPT_PROCIMPORT16},  /* 14 */
     108    {FALSE, -1,  8, "f_FuBuff",             -1,  -1, -1, EPT_PROCIMPORT16}   /* 15 */
     109/*    {FALSE, -1, 11, "",          -1,  -1, -1, EPT_PROCIMPORT16} */ /* 16 */
    107110};
    108111
     
    156159static void  kmemcpy(char *p1, const char *p2, int len);
    157160static int   kstrcmp(const char *p1, const char *p2);
     161static char *kstrstr(const char *psz1, const char *psz2);
    158162static int   kstrncmp(const char *p1, const char *p2, int len);
    159163static int   kstrlen(const char *p);
     
    177181
    178182
     183
     184
     185/*******************************************************************************
     186*   Implementation of Internal Helper Functions                                *
     187*******************************************************************************/
    179188
    180189/**
     
    309318#endif
    310319
     320
     321
     322/**
     323 * Finds psz2 in psz2.
     324 * @returns   Pointer to occurence of psz2 in psz1.
     325 * @param     psz1  String to be search.
     326 * @param     psz2  Substring to search for.
     327 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     328 */
     329static char *kstrstr(const char *psz1, const char *psz2)
     330{
     331    while (*psz1 != '\0')
     332    {
     333        register int i = 0;
     334        while (psz2[i] != '\0' && psz1[i] == psz2[i])
     335            i++;
     336
     337        /* found it? */
     338        if (psz2[i] == '\0')
     339            return (char*)psz1;
     340        if (psz1[i] == '\0' )
     341            break;
     342        psz1++;
     343    }
     344
     345    return NULL;
     346}
     347
     348
     349
    311350/**
    312351 * kstrncmp - String 'n' compare.
     
    400439
    401440
    402 /**
    403  * Verifies the that the addresses in aProcTab are valid.
     441
     442/*******************************************************************************
     443*   Implementation Of The Important Function                                   *
     444*******************************************************************************/
     445
     446/**
     447 * Verifies the that the addresses in aImportTab are valid.
    404448 * This is done at Ring-0 of course.
    405449 * @returns   0 if ok, not 0 if not ok.
     
    430474
    431475/**
    432  * Check a symbole file. Searches for the wanted entry-point addresses.
     476 * Check a symbol file. Searches for the wanted entry-point addresses.
    433477 * @returns   0 on success - something else on failiure.
    434478 * @param     pszFilename  Name of file to probe.
     
    438482static int ProbeSymFile(char * pszFilename)
    439483{
    440     HFILE          SymFile;
    441     MAPDEF         MapDef;
    442     SEGDEF         SegDef;
    443     SYMDEF32       SymDef32;
    444     SYMDEF16       SymDef16;
    445     char           Buffer[256];
    446     unsigned long  SymNum;
    447     unsigned long  SegOffset, SymOffset, SymPtrOffset;
    448     unsigned long  i;
    449     unsigned long  ulSegments;
    450     int            LeftToFind;
     484    HFILE          hSym;                /* Filehandle */
     485    int            cLeftToFind;         /* Symbols left to find */
     486    unsigned long  iSeg;                /* Outer search loop:  Segment number */
     487    unsigned       iSym;                /* Middle search loop: Symbol number */
     488    unsigned       i;                   /* Inner search loop:  ProcTab index */
    451489    int            rc;
    452490
    453     /* open symbole file */
    454     SymFile = fopen(pszFilename, "rb");
    455     if (SymFile==0)
     491    MAPDEF         MapDef;              /* Mapfile header */
     492    SEGDEF         SegDef;              /* Segment header */
     493    SYMDEF32       SymDef32;            /* Symbol definition 32-bit */
     494    SYMDEF16       SymDef16;            /* Symbol definition 16-bit */
     495    char           achBuffer[256];      /* Name buffer */
     496    unsigned long  offSegment;          /* Segment definition offset */
     497    unsigned long  offSymPtr;           /* Symbol pointer(offset) offset */
     498    unsigned short offSym;              /* Symbol definition offset */
     499
     500
     501    /*
     502     * Open the symbol file
     503     */
     504    hSym = fopen(pszFilename, "rb");
     505    if (hSym==0)
    456506    {
    457507        dprintf(("Error opening file %s\n", pszFilename));
     
    459509    }
    460510
    461     /* read header and display it */
    462     rc = fread(&MapDef, sizeof(MAPDEF), 1, SymFile);
    463     if (rc)
    464     {
    465         Buffer[0] = MapDef.achModName[0];
    466         fread(&Buffer[1], 1, MapDef.cbModName, SymFile);
    467         Buffer[MapDef.cbModName] = '\0';
    468         dprintf(("*Module name: %s\n", Buffer));
    469         dprintf(("*Segments: %d\n*MaxSymbolLength: %d\n", MapDef.cSegs, MapDef.cbMaxSym));
    470         dprintf(("*ppNextMap: 0x%x\n\n", MapDef.ppNextMap ));
    471     }
    472     else
    473     {
    474         fclose(SymFile);
     511
     512    /*
     513     * (Open were successfully.)
     514     * Now read header and display it.
     515     */
     516    rc = fread(&MapDef, sizeof(MAPDEF), 1, hSym);
     517    if (!rc)
     518    {   /* oops! read failed, close file and fail. */
     519        fclose(hSym);
    475520        return -51;
    476521    }
    477 
    478     /* verify module name */
    479     if (MapDef.cbModName == 7 && kstrncmp(Buffer, "OS2KRNL", 7) != 0)
    480     {
     522    achBuffer[0] = MapDef.achModName[0];
     523    fread(&achBuffer[1], 1, MapDef.cbModName, hSym);
     524    achBuffer[MapDef.cbModName] = '\0';
     525    dprintf(("*Module name: %s\n", achBuffer));
     526    dprintf(("*Segments: %d\n*MaxSymbolLength: %d\n", MapDef.cSegs, MapDef.cbMaxSym));
     527    dprintf(("*ppNextMap: 0x%x\n\n", MapDef.ppNextMap ));
     528
     529
     530    /*
     531     * Verify that the modulename of the symbol file is OS2KRNL.
     532     */
     533    if (MapDef.cbModName == 7 && kstrncmp(achBuffer, "OS2KRNL", 7) != 0)
     534    {   /* modulename was not OS2KRNL, fail. */
    481535        dprintf(("Modulename verify failed\n"));
    482         fclose(SymFile);
     536        fclose(hSym);
    483537        return -51;
    484538    }
    485539
    486     /* verify correct number of segments */
    487     ulSegments = MapDef.cSegs;
    488     if (ulSegments != KrnlOTEs.cObjects)
    489     {
     540
     541    /*
     542     * Verify that the number of segments is equal to the number objects in OS2KRNL.
     543     */
     544    if (MapDef.cSegs != KrnlOTEs.cObjects)
     545    {   /* incorrect count of segments. */
    490546        dprintf(("Segment No. verify failed\n"));
    491         fclose(SymFile);
     547        fclose(hSym);
    492548        return -52;
    493549    }
    494550
    495     SegOffset= SEGDEFOFFSET(MapDef);
    496     /* skip to last segment - ASSUMES all imports located in 32-bit code segment. */
    497     for (i = 0; i < ulSegments; i++ )
    498     {
    499         if (fseek(SymFile, SegOffset, SEEK_SET))
    500         {
    501             fclose(SymFile);
     551
     552    /*
     553     * Reset ProcTab
     554     */
     555    for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
     556        aImportTab[i].fFound = 0;
     557
     558
     559    /*
     560     * Fileoffset of the first segment.
     561     * And set cLeftToFind.
     562     */
     563    offSegment = SEGDEFOFFSET(MapDef);
     564    cLeftToFind = NBR_OF_KRNLIMPORTS;
     565
     566    /*
     567     * Search thru the entire file, segment by segment.
     568     *
     569     * ASSUME: last segment is the only 32-bit code segment.
     570     *
     571     */
     572    for (iSeg = 0; iSeg < MapDef.cSegs; iSeg++, offSegment = NEXTSEGDEFOFFSET(SegDef))
     573    {
     574        int     fSegEPTBitType;         /* Type of segment, 16 or 32 bit, expressed in EPT_XXBIT flags */
     575        int     fCode;                  /* Set if this is a code segment, else clear. */
     576
     577        /*
     578         * Read the segment definition.
     579         */
     580        if (fseek(hSym, offSegment, SEEK_SET))
     581        {   /* Failed to seek to the segment definition, fail! */
     582            fclose(hSym);
    502583            return -53;
    503584        }
    504         rc = fread(&SegDef, sizeof(SEGDEF), 1, SymFile);
    505         if (i+1 < ulSegments)
    506             SegOffset = NEXTSEGDEFOFFSET(SegDef);
    507     }
    508 
    509     Buffer[0] = SegDef.achSegName[0];
    510     rc = fread(&Buffer[1], 1, SegDef.cbSegName, SymFile);
    511 
    512     /* verify that this is DOSHIGH32CODE */
    513     if (SegDef.cbSegName != 13 && kstrncmp(Buffer, "DOSHIGH32CODE", 13) != 0)
    514     {
    515         dprintf(("DOSHIGH32CODE verify failed \n"));
    516         fclose(SymFile);
    517         return -54;
    518     }
    519 
    520     for (i = 0; i < NUMBER_OF_PROCS; i++)
    521         aProcTab[i].fFound = 0 ;
    522 
    523     /* search for the entry-point names */
    524     for (LeftToFind = NUMBER_OF_PROCS, SymNum = 0; SymNum < SegDef.cSymbols && LeftToFind; SymNum++)
    525     {
    526         SymPtrOffset = SYMDEFOFFSET(SegOffset, SegDef, SymNum);
    527         rc = fseek(SymFile, SymPtrOffset, SEEK_SET);
    528         rc = fread(&SymOffset, sizeof(unsigned short int), 1, SymFile);
    529         SymOffset &=0xffff;
    530         rc = fseek(SymFile, SymOffset+SegOffset, SEEK_SET);
    531 
    532         if (SegDef.bFlags & 0x01)
     585        rc = fread(&SegDef, sizeof(SEGDEF), 1, hSym);
     586        if (!rc)
     587        {   /* Failed to read the segment definition, fail! */
     588            fclose(hSym);
     589            return -53;
     590        }
     591
     592        /*
     593         * Some debugging info.
     594         */
     595        achBuffer[0] = SegDef.achSegName[0];
     596        fread(&achBuffer[1], 1, SegDef.cbSegName, hSym);
     597        achBuffer[SegDef.cbSegName] = '\0';
     598        dprintf(("Segment %.2li Flags=0x%02x cSymbols=0x%04x Name=%s\n",
     599                 iSeg, SegDef.bFlags, SegDef.cSymbols, &achBuffer[0]));
     600
     601        /*
     602         * Determin segment bit type.
     603         */
     604        fSegEPTBitType = SEG32BitSegment(SegDef) ? EPT_32BIT : EPT_16BIT;
     605        fCode = kstrstr(achBuffer, "CODE") != NULL;
     606
     607        /*
     608         * Search thru all the symbols in this segment
     609         * while we look for the requested symbols in aImportTab.
     610         */
     611        for (iSym = 0; iSym < SegDef.cSymbols && cLeftToFind; iSym++)
    533612        {
    534             rc = fread(&SymDef32, sizeof(SYMDEF32), 1, SymFile);
    535             Buffer[0] = SymDef32.achSymName[0];
    536             rc = fread(&Buffer[1], 1, SymDef32.cbSymName, SymFile);
    537             Buffer[SymDef32.cbSymName] = '\0';
    538         } else
    539         {
    540             rc = fread(&SymDef16, sizeof(SYMDEF16), 1, SymFile);
    541             Buffer[0] = SymDef16.achSymName[0];
    542             rc = fread(&Buffer[1], 1, SymDef16.cbSymName, SymFile);
    543             Buffer[SymDef16.cbSymName] = '\0';
    544         }
    545 
    546         /* search proctable */
    547         for (i = 0; i < NUMBER_OF_PROCS; i++)
    548         {
    549             if (!aProcTab[i].fFound && aProcTab[i].cchName == (SegDef.bFlags & 0x01 ? SymDef32.cbSymName : SymDef16.cbSymName))
     613            unsigned cchName;
     614            /*
     615             * Fileoffset of the current symbol.
     616             * Set filepointer to that position.
     617             * Read word (which is the offset of the symbol).
     618             */
     619            offSymPtr = SYMDEFOFFSET(offSegment, SegDef, iSym);
     620            rc = fseek(hSym, offSymPtr, SEEK_SET);
     621            if (rc)
     622            {   /* Symboloffset seek failed, try read next symbol. */
     623                dprintf(("Warning: Seek failed (offSymPtr=%d, rc=%d)\n", offSymPtr, rc));
     624                continue;
     625            }
     626            rc = fread(&offSym, sizeof(unsigned short int), 1, hSym);
     627            if (!rc)
     628            {   /* Symboloffset read failed, try read next symbol. */
     629                dprintf(("Warning: read failed (offSymPtr=%d, rc=%d)\n", offSymPtr, rc));
     630                continue;
     631            }
     632            rc = fseek(hSym, offSym + offSegment, SEEK_SET);
     633            if (rc)
     634            {   /* Symbol Seek failed, try read next symbol. */
     635                dprintf(("Warning: Seek failed (offSym=%d, rc=%d)\n", offSym, rc));
     636                continue;
     637            }
     638
     639
     640            /*
     641             * Read symbol and symbolname.
     642             */
     643            if (SegDef.bFlags & 0x01)
     644                rc = fread(&SymDef32, sizeof(SYMDEF32), 1, hSym);
     645            else
     646                rc = fread(&SymDef16, sizeof(SYMDEF16), 1, hSym);
     647            if (!rc)
     648            {   /* Symbol read failed, try read next symbol */
     649                dprintf(("Warning: Read(1) failed (offSym=%d, rc=%d)\n", offSym, rc));
     650                continue;
     651            }
     652            achBuffer[0] = (SegDef.bFlags & 0x01) ? SymDef32.achSymName[0] : SymDef16.achSymName[0];
     653            cchName = (SegDef.bFlags & 0x01) ? SymDef32.cbSymName : SymDef16.cbSymName;
     654            rc = fread(&achBuffer[1], 1, cchName, hSym);
     655            if (!rc)
     656            {   /* Symbol read failed, try read next symbol */
     657                dprintf(("Warning: Read(2) failed (offSym=%d, rc=%d)\n", offSym, rc));
     658                continue;
     659            }
     660            achBuffer[cchName] = '\0';
     661
     662
     663            /*
     664             * Search proctable.
     665             */
     666            for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
    550667            {
    551                 if (kstrncmp(aProcTab[i].achName, Buffer, aProcTab[i].cchName) == 0)
    552                 {
    553                     aProcTab[i].offObject = (SegDef.bFlags & 0x01 ? SymDef32.wSymVal : SymDef16.wSymVal);
    554                     aProcTab[i].ulAddress= aProcTab[i].offObject + KrnlOTEs.aObjects[KrnlOTEs.cObjects-1].ote_base;
    555 
    556                     if (aProcTab[i].offObject < KrnlOTEs.aObjects[KrnlOTEs.cObjects-1].ote_size)
     668                if (!aImportTab[i].fFound                                     /* Not allready found */
     669                    && (aImportTab[i].fType & EPT_BIT_MASK) == fSegEPTBitType /* Equal bittype */
     670                    && (fCode || (aImportTab[i].fType & EPT_VARIMPORT))       /* Don't look for code in a data segment and vice versa */
     671                    && aImportTab[i].cchName == cchName                       /* Equal name length */
     672                    && kstrncmp(aImportTab[i].achName, achBuffer, cchName) == 0  /* Equal name */
     673                    )
     674                {   /* Symbol was found */
     675                    aImportTab[i].offObject = (SegDef.bFlags & 0x01 ? SymDef32.wSymVal : SymDef16.wSymVal);
     676                    aImportTab[i].ulAddress = aImportTab[i].offObject + KrnlOTEs.aObjects[iSeg].ote_base;
     677                    aImportTab[i].usSel     = KrnlOTEs.aObjects[iSeg].ote_sel;
     678
     679                    /* Paranoia test! */
     680                    if (aImportTab[i].offObject < KrnlOTEs.aObjects[iSeg].ote_size)
    557681                    {
    558                         aProcTab[i].fFound = TRUE;
    559                         LeftToFind--;
    560                         dprintf(("Found: %s at off 0x%lx addr 0x%lx\n", aProcTab[i].achName, aProcTab[i].offObject, aProcTab[i].ulAddress));
    561                         break;
     682                        aImportTab[i].fFound = TRUE;
     683                        cLeftToFind--;
     684                        dprintf(("Found: %s at off 0x%lx addr 0x%lx, sel=0x%x\n",
     685                                 aImportTab[i].achName, aImportTab[i].offObject,
     686                                 aImportTab[i].ulAddress, aImportTab[i].usSel));
    562687                    }
    563                     else
    564                     {
    565                         fclose(SymFile);
    566                         return -56;
    567                     }
     688                    else/* test failed, continue on next symbol*/
     689                        dprintf(("Error: Paranoia test failed for %s\n", aImportTab[i].achName));;
     690                    break;
    568691                }
    569             }
    570         }
    571     }
    572 
    573     fclose(SymFile);
    574     return LeftToFind == 0 ? VerifyPrologs() : -57;
     692
     693            } /* aImportTab for-loop */
     694
     695        } /* Symbol for-loop */
     696
     697    } /* Segment for-loop */
     698
     699    /*
     700     * Close symbol file.
     701     */
     702    fclose(hSym);
     703
     704    /*
     705     * If not all procedures were found fail.
     706     */
     707    if (cLeftToFind != 0)
     708        return -57;
     709
     710    /*
     711     * Verify function prologs and return.
     712     */
     713    return VerifyPrologs();
    575714}
    576715
     
    598737 * @result    ulBuild is set.
    599738 */
    600 static int ReadOS2Krnl(char * filename)
    601 {
    602     HFILE          krnl;
     739static int ReadOS2Krnl(char * pszFilename)
     740{
     741    HFILE          hKrnl;
    603742    unsigned long  cbKrnl;
    604743    int            rc;
    605744
    606     krnl = fopen(filename, "rb");
    607     if (krnl != 0)
    608     {
    609         cbKrnl = fsize(krnl);
    610         if (!fseek(krnl, 0, SEEK_SET))
    611             rc = ReadOS2Krnl2(krnl, cbKrnl);
     745    hKrnl = fopen(pszFilename, "rb");
     746    if (hKrnl != 0)
     747    {
     748        cbKrnl = fsize(hKrnl);
     749        if (!fseek(hKrnl, 0, SEEK_SET))
     750            rc = ReadOS2Krnl2(hKrnl, cbKrnl);
    612751        else
    613752            rc = -2;
    614         fclose(krnl);
     753        fclose(hKrnl);
    615754    }
    616755    else
     
    626765 * @returns   0 on success.
    627766 *            errorcodes on failure. (-1 >= rc >= -14)
     767 * @param     hKrnl
    628768 * @param
    629769 * @equiv
     
    634774 * @remark
    635775 */
    636 static int ReadOS2Krnl2(HFILE krnl, unsigned long  cbKrnl)
     776static int ReadOS2Krnl2(HFILE hKrnl, unsigned long  cbKrnl)
    637777{
    638778    int            i, j;
    639779    int            rc = 0;
    640     char           Buffer[KERNEL_ID_STRING_LENGTH + KERNEL_READ_SIZE];
     780    char           achBuffer[KERNEL_ID_STRING_LENGTH + KERNEL_READ_SIZE];
    641781    unsigned long  offLXHdr;
    642782    struct e32_exe *pLXHdr;
     
    644784
    645785    /* find bldlevel string - "@#IBM:14.020#@  IBM OS/2 Kernel - 14.020F" */
    646     cbKrnl = fsize(krnl);
    647     if (fseek(krnl, 0, SEEK_SET))
     786    cbKrnl = fsize(hKrnl);
     787    if (fseek(hKrnl, 0, SEEK_SET))
    648788        return -2;
    649789
    650     if (!fread(&Buffer[KERNEL_ID_STRING_LENGTH], 1, KERNEL_READ_SIZE, krnl))
     790    if (!fread(&achBuffer[KERNEL_ID_STRING_LENGTH], 1, KERNEL_READ_SIZE, hKrnl))
    651791        return -3;
    652792
     
    657797        {
    658798
    659             kmemcpy(Buffer, &Buffer[KERNEL_READ_SIZE], KERNEL_ID_STRING_LENGTH);
    660             if (!fread(&Buffer[KERNEL_ID_STRING_LENGTH], 1, cbKrnl > KERNEL_READ_SIZE ? KERNEL_READ_SIZE : (int)cbKrnl, krnl))
     799            kmemcpy(achBuffer, &achBuffer[KERNEL_READ_SIZE], KERNEL_ID_STRING_LENGTH);
     800            if (!fread(&achBuffer[KERNEL_ID_STRING_LENGTH], 1, cbKrnl > KERNEL_READ_SIZE ? KERNEL_READ_SIZE : (int)cbKrnl, hKrnl))
    661801                return -3;
    662802
     
    664804        }
    665805
    666         if (kstrncmp("@#IBM:", &Buffer[i], 6) == 0)
     806        if (kstrncmp("@#IBM:", &achBuffer[i], 6) == 0)
    667807            break;
    668808
     
    674814    if (cbKrnl == 0)
    675815    {
    676         fclose(krnl);
     816        fclose(hKrnl);
    677817        return -4;
    678818    }
     
    680820    /* displacement */
    681821    j = 0;
    682     while (j < 6 && Buffer[i+10+j] != '#')
     822    while (j < 6 && achBuffer[i+10+j] != '#')
    683823        j++;
    684824
    685825    /* verify signature */
    686     if (kstrncmp(&Buffer[i+10+j], "#@  IBM OS/2 Kernel", 19) != 0)
     826    if (kstrncmp(&achBuffer[i+10+j], "#@  IBM OS/2 Kernel", 19) != 0)
    687827        return -5;
    688828
    689829    /* read ulBuild */
    690     ulBuild  = (char)(Buffer[i+6] - '0') * 1000;
    691     if (Buffer[i+7] != '.')
     830    ulBuild  = (char)(achBuffer[i+6] - '0') * 1000;
     831    if (achBuffer[i+7] != '.')
    692832    {
    693833        /* this code is for Warp5 */
    694834        ulBuild *= 10;
    695         ulBuild += (char)(Buffer[i+7] - '0') * 1000;
     835        ulBuild += (char)(achBuffer[i+7] - '0') * 1000;
    696836        i++;
    697837        j--;
    698         if (Buffer[i+7] != '.')
     838        if (achBuffer[i+7] != '.')
    699839        {
    700840            ulBuild = ulBuild * 10;
    701             ulBuild = ulBuild + (unsigned long)(Buffer[i+7] - '0') * 1000;
     841            ulBuild = ulBuild + (unsigned long)(achBuffer[i+7] - '0') * 1000;
    702842            i++;
    703843            j--;
     
    707847    if (j == 0)
    708848    {
    709         ulBuild += (Buffer[i+ 8] - '0') * 10;
    710         ulBuild += (Buffer[i+ 9] - '0') * 1;
     849        ulBuild += (achBuffer[i+ 8] - '0') * 10;
     850        ulBuild += (achBuffer[i+ 9] - '0') * 1;
    711851    } else
    712852    {
    713853        if (j == 3)
    714854            return -9;
    715         ulBuild += (Buffer[i+ 8] - '0') * 100;
    716         ulBuild += (Buffer[i+ 9] - '0') * 10;
    717         ulBuild += (Buffer[i+10] - '0');
     855        ulBuild += (achBuffer[i+ 8] - '0') * 100;
     856        ulBuild += (achBuffer[i+ 9] - '0') * 10;
     857        ulBuild += (achBuffer[i+10] - '0');
    718858    }
    719859
     
    724864    /* get segment number */
    725865    /* read-MZheader */
    726     if (fseek(krnl,0,SEEK_SET))
     866    if (fseek(hKrnl,0,SEEK_SET))
    727867        return -2;
    728868
    729     if (!fread(Buffer, 1, 0x40, krnl))
     869    if (!fread(achBuffer, 1, 0x40, hKrnl))
    730870        return -3;
    731871
    732     offLXHdr = *(unsigned long int *)&Buffer[0x3c];
     872    offLXHdr = *(unsigned long int *)&achBuffer[0x3c];
    733873
    734874    if (offLXHdr > 0x2000 && offLXHdr < 0x80) /* just to detect garbage */
    735875        return -6;
    736876
    737     if (fseek(krnl, offLXHdr, SEEK_SET))
     877    if (fseek(hKrnl, offLXHdr, SEEK_SET))
    738878        return -2;
    739879
    740     if (!fread(Buffer, 1, sizeof(struct e32_exe), krnl))
     880    if (!fread(achBuffer, 1, sizeof(struct e32_exe), hKrnl))
    741881        return -3;
    742882
    743883    /* check LX-magic */
    744     if (Buffer[0] != 'L' || Buffer[1] != 'X')
     884    if (achBuffer[0] != 'L' || achBuffer[1] != 'X')
    745885        return -7;
    746886
    747887#ifndef DEBUGR3
    748888    /* check object count - match it with what we got from the kernel. */
    749     pLXHdr = (struct e32_exe *)Buffer;
     889    pLXHdr = (struct e32_exe *)achBuffer;
    750890    if ((UCHAR)pLXHdr->e32_objcnt != KrnlOTEs.cObjects)
    751891        return -8;
     
    755895
    756896    /* check objects (sizes and flags(?)) */
    757     if (!fseek(krnl, (LONG)offLXHdr + (LONG)pLXHdr->e32_objtab, SEEK_SET))
    758     {
    759         struct o32_obj *pObj = (struct o32_obj *)Buffer;
     897    if (!fseek(hKrnl, (LONG)offLXHdr + (LONG)pLXHdr->e32_objtab, SEEK_SET))
     898    {
     899        struct o32_obj *pObj = (struct o32_obj *)achBuffer;
    760900        for (i = 0; i < (int)KrnlOTEs.cObjects; i++)
    761901        {
    762             if (!fread(Buffer, 1, sizeof(OTE), krnl))
     902            if (!fread(achBuffer, 1, sizeof(OTE), hKrnl))
    763903                return -11;
    764904            if (pObj->o32_size < KrnlOTEs.aObjects[i].ote_size)
     
    779919
    780920    /*  object count */
    781     pLXHdr = (struct e32_exe *)Buffer;
     921    pLXHdr = (struct e32_exe *)achBuffer;
    782922    KrnlOTEs.cObjects = (UCHAR)pLXHdr->e32_objcnt;
    783923
    784924    /* get OTEs */
    785     if (!fseek(krnl, (LONG)offLXHdr + (LONG)pLXHdr->e32_objtab, SEEK_SET))
    786     {
    787         struct o32_obj *pObj = (struct o32_obj *)Buffer;
     925    if (!fseek(hKrnl, (LONG)offLXHdr + (LONG)pLXHdr->e32_objtab, SEEK_SET))
     926    {
     927        struct o32_obj *pObj = (struct o32_obj *)achBuffer;
    788928        for (i = 0; i < (int)KrnlOTEs.cObjects; i++)
    789             if (!fread(&KrnlOTEs.aObjects[i], 1, sizeof(struct o32_obj), krnl))
     929            if (!fread(&KrnlOTEs.aObjects[i], 1, sizeof(struct o32_obj), hKrnl))
    790930                return -11;
    791931    }
     
    9111051                puts(szUsrSym);
    9121052
    913             for (i = 0; i < NUMBER_OF_PROCS; i++)
     1053            for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
    9141054            {
    9151055                if ((i % 2) == 0)
     
    9171057                else
    9181058                    puts("    ");
    919                 puts(aProcTab[i].achName);
    920                 for (j = aProcTab[i].cchName; j < 20; j++)
     1059                puts(aImportTab[i].achName);
     1060                for (j = aImportTab[i].cchName; j < 20; j++)
    9211061                    puts(" ");
    9221062
    9231063                puts(" at ");
    924                 if (aProcTab[i].fFound)
    925                     ShowHexNumber(aProcTab[i].ulAddress);
     1064                if (aImportTab[i].fFound)
     1065                    ShowHexNumber(aImportTab[i].ulAddress);
    9261066                else
    9271067                    puts(szMsgfailed);
  • trunk/src/win32k/dev32/d32init.c

    r2827 r2831  
    1 /* $Id: d32init.c,v 1.10 2000-02-19 08:40:29 bird Exp $
     1/* $Id: d32init.c,v 1.11 2000-02-19 23:51:59 bird Exp $
    22 *
    33 * d32init.c - 32-bits init routines.
     
    5454
    5555/* extern(s) located in calltab.asm */
    56 extern char     callTab[NUMBER_OF_PROCS][MAXSIZE_PROLOG];
     56extern char     callTab[NBR_OF_KRNLIMPORTS][MAXSIZE_PROLOG];
    5757
    5858/* extern(s) located in mytkExecPgm.asm  */
     
    342342
    343343/**
    344  * Verifies the aProcTab.
     344 * Verifies the aImportTab.
    345345 * @returns   0 if ok. !0 if not ok.
    346346 * @remark    Called from IOCtl.
     
    352352
    353353    /* verify */
    354     for (i = 0; i < NUMBER_OF_PROCS; i++)
     354    for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
    355355    {
    356356        /* verify that it is found */
    357         if (!_aProcTab[i].fFound)
     357        if (!_aImportTab[i].fFound)
    358358        {
    359359            kprintf(("VerifyProcTab32: procedure no.%d was not found!\n", i));
     
    362362
    363363        /* verify read/writeable. - FIXME */
    364         if (_aProcTab[i].ulAddress < 0xffe00000UL)
     364        if (_aImportTab[i].ulAddress < 0xffe00000UL)
    365365        {
    366366            kprintf(("VerifyProcTab32: procedure no.%d has an invlalid address, %#08x!\n",
    367                      i, _aProcTab[i].ulAddress));
     367                     i, _aImportTab[i].ulAddress));
    368368            return STATUS_DONE | STERR | 2;
    369369        }
    370370
    371         switch (_aProcTab[i].fType)
     371        switch (_aImportTab[i].fType)
    372372        {
    373373            case EPT_PROC:
    374374            case EPT_PROCIMPORT:
    375375                /* verify known function prolog. */
    376                 if ((cb = interpretFunctionProlog((char*)_aProcTab[i].ulAddress, _aProcTab[i].fType == EPT_PROC))
     376                if ((cb = interpretFunctionProlog((char*)_aImportTab[i].ulAddress, _aImportTab[i].fType == EPT_PROC))
    377377                    <= 0 && cb + 5 >= MAXSIZE_PROLOG)
    378378                {
     
    534534     * verify proctable
    535535     */
    536     for (i = 0; i < NUMBER_OF_PROCS; i++)
    537     {
    538         if (_aProcTab[i].fType != EPT_PROC && _aProcTab[i].fType != EPT_PROCIMPORT)
     536    for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
     537    {
     538        if (_aImportTab[i].fType != EPT_PROC && _aImportTab[i].fType != EPT_PROCIMPORT)
    539539        {
    540540            kprintf(("procInit: EPT_VAR is not supported. (procedure no.%d, cb=%d)\n", i, cb));
    541541            return 1;
    542542        }
    543         cb = interpretFunctionProlog((char*)_aProcTab[i].ulAddress, _aProcTab[i].fType == EPT_PROC);
     543        cb = interpretFunctionProlog((char*)_aImportTab[i].ulAddress, _aImportTab[i].fType == EPT_PROC);
    544544        if (cb <= 0 || cb + 5 >= MAXSIZE_PROLOG)
    545545        {
     
    552552     * rehook / import
    553553     */
    554     for (i = 0; i < NUMBER_OF_PROCS; i++)
    555     {
    556         switch (_aProcTab[i].fType)
     554    for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
     555    {
     556        switch (_aImportTab[i].fType)
    557557        {
    558558            case EPT_PROC:
    559559            {
    560                 cb = interpretFunctionProlog((char*)_aProcTab[i].ulAddress, TRUE);
     560                cb = interpretFunctionProlog((char*)_aImportTab[i].ulAddress, TRUE);
    561561                if (cb > 0 && cb + 5 < MAXSIZE_PROLOG)
    562562                {
    563                     static unsigned auFuncs[NUMBER_OF_PROCS] = /* This table must be updated with the overloading functions. */
     563                    static unsigned auFuncs[NBR_OF_KRNLIMPORTS] = /* This table must be updated with the overloading functions. */
    564564                    {
    565565                        (unsigned)myldrRead,
     
    580580
    581581                    /* copy function prolog */
    582                     memcpy(callTab[i], (void*)_aProcTab[i].ulAddress, (size_t)cb);
     582                    memcpy(callTab[i], (void*)_aImportTab[i].ulAddress, (size_t)cb);
    583583
    584584                    /* jump from calltab to original function */
    585585                    callTab[i][cb] = 0xE9; /* jmp */
    586                     *(unsigned*)(void*)&callTab[i][cb+1] = _aProcTab[i].ulAddress + cb - (unsigned)&callTab[i][cb+5];
     586                    *(unsigned*)(void*)&callTab[i][cb+1] = _aImportTab[i].ulAddress + cb - (unsigned)&callTab[i][cb+5];
    587587
    588588
    589589                    /* jump from original function to my function - an cli(?) could be needed here */
    590                     *(char*)_aProcTab[i].ulAddress = 0xE9; /* jmp */
    591                     *(unsigned*)(_aProcTab[i].ulAddress + 1) = auFuncs[i] - (_aProcTab[i].ulAddress + 5);
     590                    *(char*)_aImportTab[i].ulAddress = 0xE9; /* jmp */
     591                    *(unsigned*)(_aImportTab[i].ulAddress + 1) = auFuncs[i] - (_aImportTab[i].ulAddress + 5);
    592592                }
    593593                else
     
    602602            case EPT_PROCIMPORT:
    603603            {
    604                 cb = interpretFunctionProlog((char*)_aProcTab[i].ulAddress, FALSE);
     604                cb = interpretFunctionProlog((char*)_aImportTab[i].ulAddress, FALSE);
    605605                if (cb > 0 && cb + 5 < MAXSIZE_PROLOG)
    606606                {
    607607                    /* jump from calltab to original function */
    608608                    callTab[i][0] = 0xE9; /* jmp */
    609                     *(unsigned*)(void*)&callTab[i][1] = _aProcTab[i].ulAddress - (unsigned)&callTab[i][cb+5];
     609                    *(unsigned*)(void*)&callTab[i][1] = _aImportTab[i].ulAddress - (unsigned)&callTab[i][cb+5];
    610610                }
    611611                else
  • trunk/src/win32k/include/dev16.h

    r2799 r2831  
    1 /* $Id: dev16.h,v 1.4 2000-02-15 23:39:19 bird Exp $
     1/* $Id: dev16.h,v 1.5 2000-02-19 23:52:00 bird Exp $
    22 * dev16 - 16-bit specific. Should not be used in 32-bit C/C++.
    33 *
     
    4040
    4141/*
    42  * Get Kernel OTEs. No params. No data. aProcTab is used.
     42 * Get Kernel OTEs. No params. No data. aImportTab is used.
    4343 */
    4444#define D16_IOCTL_VERIFYPROCTAB     0x42
  • trunk/src/win32k/include/dev1632.h

    r2799 r2831  
    1 /* $Id: dev1632.h,v 1.2 2000-02-15 23:39:19 bird Exp $
     1/* $Id: dev1632.h,v 1.3 2000-02-19 23:52:00 bird Exp $
    22 * dev1632.h - Common header file for 16-bit and 32-bit C
    33 *
     
    4646#ifdef _OS2Krnl_h_
    4747
     48
    4849#define MAXKRNLOBJECTS 24
    4950typedef struct _KRNLOBJTABLE
  • trunk/src/win32k/include/probkrnl.h

    r2827 r2831  
    1 /* $Id: probkrnl.h,v 1.7 2000-02-19 08:40:30 bird Exp $
     1/* $Id: probkrnl.h,v 1.8 2000-02-19 23:52:00 bird Exp $
    22 *
    33 * Include file for ProbKrnl.
     
    1616*   Defined Constants And Macros                                               *
    1717*******************************************************************************/
    18 #define NUMBER_OF_PROCS      14
    19 #define MAX_LENGTH_NAME      32
     18#define NBR_OF_KRNLIMPORTS      16      /* When this is changed make sure to   */
     19                                        /* update the arrays in d32init.c and  */
     20                                        /* probkrnl32.c */
     21#define MAX_LENGTH_NAME         32      /* Max length for the function. */
    2022
    21 /* entry-point type flag */
    22 #define EPT_PROC              0 /* procedure - overload procedure*/
    23 #define EPT_PROCIMPORT        1 /* procedure - import only */
    24 #define EPT_VAR               2 /* variable/non-procedure - not implemented yet */
     23/* Entry-Point Type flag */
     24#define EPT_PROC                0x00    /* procedure - overload procedure*/
     25#define EPT_PROCIMPORT          0x01    /* procedure 32bit - import only */
     26#define EPT_VARIMPORT           0x02    /* variable/non-procedure 32bit - not implemented yet */
     27#define EPT_32BIT               0x00    /* 16 bit entry-point  */
     28#define EPT_16BIT               0x80    /* 32 bit entry-point */
     29#define EPT_BIT_MASK            0x80    /* Mask bit entry-point */
     30#define EPT16BitEntry(a)    (((a).fType & EPT_BIT_MASK) == EPT_16BIT)
     31#define EPT32BitEntry(a)    (((a).fType & EPT_BIT_MASK) == EPT_32BIT)
     32
     33/* 32bit types */
     34#define EPT_PROC32              (EPT_PROC | EPT_32BIT)
     35#define EPT_PROCIMPORT32        (EPT_PROCIMPORT | EPT_32BIT)
     36
     37/* 16bit types */
     38#define EPT_PROC16              (EPT_PROC | EPT_16BIT)        /* no implemented yet! */
     39#define EPT_PROCIMPORT16        (EPT_PROCIMPORT | EPT_16BIT)  /* far proc in calltab with a far jmp. */
    2540
    2641
     
    2944*******************************************************************************/
    3045#pragma pack(1)
    31 typedef struct tagPROCS
     46typedef struct tagIMPORTKRNLSYM
    3247{
    33    unsigned char       fFound;
    34    unsigned char       iObject;
    35    unsigned short int  cchName;
    36    unsigned char       achName[MAX_LENGTH_NAME];
    37    unsigned long  int  offObject;
    38    unsigned long  int  ulAddress;
    39    unsigned char       fType;
    40 } PROCS;
     48   unsigned char       fFound;          /* This is set when name is found */
     49   unsigned char       iObject;         /* Object number the name was found in*/
     50   unsigned short int  cchName;         /* Length of the name (optmize search) (INPUT) */
     51   unsigned char       achName[MAX_LENGTH_NAME]; /* Name (INPUT) */
     52   unsigned long  int  offObject;       /* Offset into the object */
     53   unsigned long  int  ulAddress;       /* 32-bit flat address */
     54   unsigned short int  usSel;           /* Select of the object */
     55   unsigned char       fType;           /* Entry-Point Type Flags */
     56} IMPORTKRNLSYM;
    4157#pragma pack()
    4258
     
    4763*   NOTE! These are only available at init time!                               *
    4864*******************************************************************************/
    49 extern PROCS _aProcTab[NUMBER_OF_PROCS];    /* 'aProcTab'        in PrbKrnl.c */
    50 extern unsigned long int  _ulBuild;         /* 'ulBuild'         in PrbKrnl.c */
    51 extern unsigned short int _usVerMajor;      /* 'usVerMajor'      in PrbKrnl.c */
    52 extern unsigned short int _usVerMinor;      /* 'usVerMinor'      in PrbKrnl.c */
     65extern IMPORTKRNLSYM _aImportTab[NBR_OF_KRNLIMPORTS]; /* 'aImportTab' in PrbKrnl.c */
     66extern unsigned long int  _ulBuild;     /* 'ulBuild'         in PrbKrnl.c */
     67extern unsigned short int _usVerMajor;  /* 'usVerMajor'      in PrbKrnl.c */
     68extern unsigned short int _usVerMinor;  /* 'usVerMinor'      in PrbKrnl.c */
    5369
    5470#ifdef INCL_16 /* 16-bit only */
  • trunk/src/win32k/include/sym.h

    r1678 r2831  
    1 /* $Id: sym.h,v 1.2 1999-11-10 01:45:34 bird Exp $
     1/* $Id: sym.h,v 1.3 2000-02-19 23:52:00 bird Exp $
    22 *
    33 * Sym-file definitions and structs.
     
    5252} SEGDEF;
    5353
     54#define SEG_FLAGS_32BIT     0x01      /* 32bit segment is set. 16-bit segment if clear */
     55#define SEG32BitSegment(a)  (((a).bFlags & 0x01) == SEG_FLAGS_32BIT)
     56#define SEG16BitSegment(a)  (((a).bFlags & 0x01) == 0)
     57
    5458typedef struct
    5559{
  • trunk/src/win32k/ldr/calltab.asm

    r2827 r2831  
    1 ; $Id: calltab.asm,v 1.6 2000-02-19 08:40:30 bird Exp $
     1; $Id: calltab.asm,v 1.7 2000-02-19 23:52:00 bird Exp $
    22;
    33; callTab - Call back again table - table with entry for each function which is overrided.
     
    5050; Imported and Overrided OS/2 kernel functions are called tru this table.
    5151;
    52 ; This array of near procedures are parallel to the aProcTab array in dev16\ProbKrnl.c.
     52; This array of near procedures are parallel to the aImportTab array in dev16\ProbKrnl.c.
    5353; Remember to update both!.
    5454;
Note: See TracChangeset for help on using the changeset viewer.