Ignore:
Timestamp:
Jul 17, 2000, 12:43:41 AM (25 years ago)
Author:
bird
Message:

Checkin of current code in the Grace brance for backup purpose.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GRACE/src/win32k/dev32/d32init.c

    r3485 r3834  
    1 /* $Id: d32init.c,v 1.19 2000-05-03 10:46:06 bird Exp $
     1/* $Id: d32init.c,v 1.19.4.1 2000-07-16 22:42:03 bird Exp $
    22 *
    33 * d32init.c - 32-bits init routines.
     
    1414#define MAXSIZE_PROLOG 0x18             /* Note that this must be synced with */
    1515                                        /* the one used in calltab.asm.       */
    16 #define static                          /* just to make all symbols visible in the kernel debugger.  */
    1716#if  0                                  /* Enable this to have extra debug logging. */
    1817    #define kprintf2(a) kprintf
     
    2423#define INCL_NOPMAPI
    2524#define LDR_INCL_INITONLY
     25#define INCL_OS2KRNL_ALL
    2626
    2727/*******************************************************************************
     
    4545#include "macros.h"
    4646
     47#ifdef R3TST
     48    #include "test.h"
     49#endif
     50
    4751
    4852/*******************************************************************************
     
    5357static char * apszInfoLevel[] = {"INFOLEVEL_QUIET", "INFOLEVEL_ERROR", "INFOLEVEL_WARNING", "INFOLEVEL_INFO", "INFOLEVEL_INFOALL", "!invalid!"};
    5458#endif
    55 static PMTE    pKrnlMTE = NULL;
    56 static PSMTE   pKrnlSMTE = NULL;
    57 static POTE    pKrnlOTE = NULL;
     59PMTE    pKrnlMTE = NULL;
     60PSMTE   pKrnlSMTE = NULL;
     61POTE    pKrnlOTE = NULL;
    5862
    5963
     
    6165*   Internal Functions                                                         *
    6266*******************************************************************************/
    63 static ULONG        readnum(const char *pszNum);
    64 _Inline int         ModR_M_32bit(char bModRM);
    65 static int          interpretFunctionProlog32(char *pach, BOOL fOverload);
    66 static int          interpretFunctionProlog16(char *pach, BOOL fOverload);
    67 static int          ImportTabInit(void);
     67 ULONG          readnum(const char *pszNum);
     68_Inline int     ModR_M_32bit(char bModRM);
     69_Inline int     ModR_M_16bit(char bModRM);
     70int             interpretFunctionProlog32(char *pach, BOOL fOverload);
     71int             interpretFunctionProlog16(char *pach, BOOL fOverload);
     72int             importTabInit(void);
     73#ifdef R3TST
     74PMTE            GetOS2KrnlMTETst(void);
     75void            R3TstFixImportTab(void);
     76#endif
     77
    6878
    6979
     
    118128        {
    119129            case 'c':
    120             case 'C': /* -C[1|2] - com-port no, def:-C2 */
    121                 switch (pszTmp[1])
    122                 {
    123                     case '1':
    124                         options.usCom = OUTPUT_COM1;
    125                         break;
    126 
    127                     case '2':
    128                     default:
    129                         options.usCom = OUTPUT_COM2;
    130                 }
     130            case 'C': /* -C[1|2] or -Com:[1|2]  -  com-port no, def:-C2 */
     131                pszTmp2 = strpbrk(pszTmp, ":=/- ");
     132                if (pszTmp2 != NULL && (*pszTmp2 == ':' || *pszTmp2 == '='))
     133                    pszTmp2++;
     134                else
     135                    pszTmp2 = pszTmp + 1;
     136                options.usCom = (USHORT)(*pszTmp2 == '1' ? OUTPUT_COM1 : OUTPUT_COM2);
    131137                break;
    132138
     
    134140            case 'E':/* ELF */
    135141                pszTmp2 = strpbrk(pszTmp, ":=/- ");
    136                 if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1
     142                if (pszTmp2 != NULL
    137143                    && (pszTmp2[1] == 'N' ||pszTmp2[1] == 'n' || pszTmp2[1] == 'D' || pszTmp2[1] == 'd')
    138144                    )
     
    145151            case 'H': /* Heap options */
    146152                pszTmp2 = strpbrk(pszTmp, ":=/- ");
    147                 if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1
    148                     && (*pszTmp2 == ':' || *pszTmp2 == '='))
     153                if (pszTmp2 != NULL && (*pszTmp2 == ':' || *pszTmp2 == '='))
    149154                {
    150155                    ul = readnum(pszTmp2 + 1);
     
    162167            case 'L': /* -L[..]<:|=| >[<Y..|E..| > | <N..|D..>] */
    163168                pszTmp2 = strpbrk(pszTmp, ":=/- ");
    164                 if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1
    165                     && (pszTmp2[1] == 'N' ||pszTmp2[1] == 'n' || pszTmp2[1] == 'D' || pszTmp2[1] == 'd')
     169                if (pszTmp2 != NULL
     170                    && (pszTmp2[1] == 'Y' ||pszTmp2[1] == 'y' || pszTmp2[1] == 'E' || pszTmp2[1] == 'e')
    166171                    )
     172                    options.fLogging = TRUE;
     173                else
    167174                    options.fLogging = FALSE;
    168                 else
    169                     options.fLogging = TRUE;
    170175                break;
    171176
     
    178183            case 'P': /* PE */
    179184                pszTmp2 = strpbrk(pszTmp, ":=/- ");
    180                 if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1
    181                     && (*pszTmp2 == ':' || *pszTmp2 == '='))
     185                if (pszTmp2 != NULL && (*pszTmp2 == ':' || *pszTmp2 == '='))
    182186                {
    183                     pszTmp++;
    184                     if (strnicmp(pszTmp, "pe2lx", 5) == 0)
     187                    pszTmp2++;
     188                    if (strnicmp(pszTmp2, "pe2lx", 5) == 0)
    185189                        options.fPE = FLAGS_PE_PE2LX;
    186                     else if (strnicmp(pszTmp, "pe", 2) == 0)
     190                    else if (strnicmp(pszTmp2, "pe", 2) == 0)
    187191                        options.fPE = FLAGS_PE_PE;
    188                     else if (strnicmp(pszTmp, "mixed", 2) == 0)
     192                    else if (strnicmp(pszTmp2, "mixed", 2) == 0)
    189193                        options.fPE = FLAGS_PE_MIXED;
    190                     else if (strnicmp(pszTmp, "not", 2) == 0)
     194                    else if (strnicmp(pszTmp2, "not", 2) == 0)
    191195                        options.fPE = FLAGS_PE_NOT;
    192196                    else
     
    205209            case 'R': /* ResHeap options */
    206210                pszTmp2 = strpbrk(pszTmp, ":=/- ");
    207                 if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1
    208                     && (*pszTmp2 == ':' || *pszTmp2 == '='))
     211                if (pszTmp2 != NULL && (*pszTmp2 == ':' || *pszTmp2 == '='))
    209212                {
    210213                    ul = readnum(pszTmp2 + 1);
     
    222225            case 'S': /* Sym:<filename> or Script:<Yes|No> or Smp */
    223226                /* SMP kernel */
    224                 if (pszTmp[1] == 'm' || pszTmp[1] == 'M')
    225                     options.fKernel = KF_SMP;
    226                 else
     227                pszTmp2 = strpbrk(pszTmp, ":=/- ");
     228                if (pszTmp[1] == 'c' || pszTmp[1] == 'C')
    227229                {
    228                     if (pszTmp[1] == 'c' || pszTmp[1] == 'C')
    229                     {
    230                         pszTmp2 = strpbrk(pszTmp, ":=/- ");
    231                         options.fScript = pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1
    232                             && (*pszTmp2 == ':' || *pszTmp2 == '=')
    233                             && (pszTmp2[1] == 'Y' || pszTmp2[1] == 'y');
    234                     }
     230                    options.fUNIXScript =
     231                        pszTmp2 != NULL
     232                        && (int)(pszTmp2-pszTmp) < cch-1
     233                        && (*pszTmp2 == ':' || *pszTmp2 == '=')
     234                        && (pszTmp2[1] == 'Y' || pszTmp2[1] == 'y');
    235235                }
    236                 break;
    237 
    238             case 'u':
    239             case 'U': /* UNI kernel */
    240                 options.fKernel = KF_UNI;
    241236                break;
    242237
     
    247242
    248243            case 'w':
    249             case 'W':
     244            case 'W': /* ModuleBase info level; -W<n> or -Warning:<n> */
    250245                if (pszTmp[1] >= '0' && pszTmp[1] <= '4')
    251246                    options.ulInfoLevel = pszTmp[1] - '0';
     
    253248                {
    254249                    pszTmp2 = strpbrk(pszTmp, ":=/- ");
    255                     if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1
    256                         && (*pszTmp2 == ':' || *pszTmp2 == '=')
    257                         && pszTmp2[1] >= '0' && pszTmp2[1] <= '4'
    258                         )
    259                         options.ulInfoLevel = pszTmp2[1] - '0';
     250                    if (pszTmp2 != NULL && (*pszTmp2 == ':' || *pszTmp2 == '='))
     251                        pszTmp2++;
     252                    else
     253                        pszTmp2 = pszTmp + 1;
     254
     255                    if (*pszTmp2 >= '0' && *pszTmp2 <= '4')
     256                        options.ulInfoLevel = *pszTmp2 - '0';
    260257                }
    261258                break;
     
    270267    if (options.cbResHeapInit > options.cbResHeapMax)
    271268        options.cbResHeapMax = options.cbResHeapInit;
    272 
    273     /* Transfer version and build number from 16-bit probkrnl.c */
    274     options.ulBuild    = _usBuild;
    275     options.usVerMajor = _usVerMajor;
    276     options.usVerMinor = _usVerMinor;
    277269
    278270    /* Log option summary */
     
    288280    else
    289281        kprintf(("\tlogging disabled\n"));
    290     kprintf(("\tCom port no.%d\n", options.usCom));
    291 
    292     kprintf(("\tKernel: ver%d.%d  build %d  type %s\n",
     282    kprintf(("\tCom port no.%03xh\n", options.usCom));
     283
     284    kprintf(("\tKernel: v%d.%d  build %d  type ",
    293285                options.usVerMajor,
    294286                options.usVerMinor,
    295                 options.ulBuild,
    296                 (options.fKernel & KF_SMP) ? "SMP" : "UNI"
    297               ));
    298     kprintf(("\tfPE=%d (%s)\n", options.fPE, apszPE[MIN(options.fPE, 5)]));
     287                options.ulBuild));
     288    if (options.fKernel & KF_SMP)
     289        kprintf(("SMP "));
     290    else if (options.fKernel & KF_W4)
     291        kprintf(("W4 "));
     292    else
     293        kprintf(("UNI "));
     294    if (options.fKernel & KF_DEBUG)
     295        kprintf(("DEBUG\n"));
     296    else
     297        kprintf(("\n"));
     298
     299    kprintf(("\tfPE=%d (%s)\n",     options.fPE, apszPE[MIN(options.fPE, 5)]));
    299300    kprintf(("\tulInfoLevel=%d (%s)\n", options.ulInfoLevel, apszInfoLevel[MIN(options.ulInfoLevel, 5)]));
    300     kprintf(("\tfElf=%d\n", options.fElf));
    301     kprintf(("\tfScript=%d\n", options.fScript));
    302     kprintf(("\tfNoLoader=%d\n", options.fNoLoader));
     301    kprintf(("\tfElf=%d\n",         options.fElf));
     302    kprintf(("\tfUNIXScript=%d\n",  options.fUNIXScript));
     303    kprintf(("\tfREXXScript=%d\n",  options.fREXXScript));
     304    kprintf(("\tfJAVA=%d\n",        options.fJava));
     305    kprintf(("\tfNoLoader=%d\n",    options.fNoLoader));
    303306    kprintf(("\tcbSwpHeapInit=0x%08x  cbSwpHeapMax=0x%08x\n",
    304307             options.cbSwpHeapInit, options.cbSwpHeapMax));
    305308    kprintf(("\tcbResHeapInit=0x%08x  cbResHeapMax=0x%08x\n",
    306              options.cbSwpHeapInit, options.cbSwpHeapMax));
     309             options.cbResHeapInit, options.cbResHeapMax));
    307310    kprintf(("Options - Summary - End\n"));
    308311    #endif /* debug */
     
    325328    /* functionoverrides */
    326329    if (!options.fNoLoader)
    327         if (ImportTabInit() != NO_ERROR)
     330        if (importTabInit() != NO_ERROR)
    328331            return STATUS_DONE | STERR | ERROR_I24_QUIET_INIT_FAIL;
    329332
     
    369372 * @author    knut st. osmundsen
    370373 */
    371 static ULONG    readnum(const char *pszNum)
     374ULONG    readnum(const char *pszNum)
    372375{
    373376    ULONG ulRet = 0;
     
    428431
    429432    /* Find the kernel OTE table */
     433#ifndef R3TST
    430434    pKrnlMTE = GetOS2KrnlMTE();
     435#else
     436    pKrnlMTE = GetOS2KrnlMTETst();
     437#endif
    431438    if (pKrnlMTE != NULL)
    432439    {
     
    461468                     * Search for internal revision stuff in the two first objects.
    462469                     */
    463                     pKrnlInfo->usBuild = 0;
    464                     for (i = 0; i < 2 && pKrnlInfo->usBuild == 0; i++)
     470                    pKrnlInfo->ulBuild = 0;
     471                    for (i = 0; i < 2 && pKrnlInfo->ulBuild == 0; i++)
    465472                    {
     473                        #ifndef R3TST
    466474                        const char *psz = (const char*)pKrnlOTE[i].ote_base;
    467                         const char *pszEnd = psz + pKrnlOTE[i].ote_size;
    468 
    469                         while (psz + 100 < pszEnd)
     475                        const char *pszEnd = psz + pKrnlOTE[i].ote_size - 50; /* Last possible search position. */
     476                        #else
     477                        extern const char *pszInternalRevision; /* defined in win32ktst.c */
     478                        const char *psz =  pszInternalRevision;
     479                        const char *pszEnd = psz + 3;
     480                        #endif
     481
     482                        while (psz < pszEnd)
    470483                        {
    471484                            if (strncmp(psz, "Internal revision ", 18) == 0 && (psz[18] >= '0' && psz[18] <= '9'))
    472485                            {
    473486                                int j;
    474                                 kprintf2(("GetOTEs32: found internal revision: '%s'\n", psz));
     487                                kprintf2(("GetKernelInfo32: found internal revision: '%s'\n", psz));
    475488
    476489                                /* skip to end of "Internal revision " string. */
     
    481494                                {
    482495                                    if (*psz != '.')
    483                                         pKrnlInfo->usBuild = (unsigned short)(pKrnlInfo->usBuild * 10 + (*psz - '0'));
     496                                        pKrnlInfo->ulBuild = (unsigned short)(pKrnlInfo->ulBuild * 10 + (*psz - '0'));
    484497                                    psz++;
    485498                                }
    486499
    487500                                /* Check if build number seems valid. */
    488                                 if (   !(pKrnlInfo->usBuild >=  8254 && pKrnlInfo->usBuild <  8383) /* Warp 3 fp 32 -> fp 60 */
    489                                     && !(pKrnlInfo->usBuild >=  9023 && pKrnlInfo->usBuild <= 9036) /* Warp 4 GA -> fp 12 */
    490                                     && !(pKrnlInfo->usBuild >= 14039 && pKrnlInfo->usBuild < 14080) /* Warp 4.5 GA -> fp 40 */
     501                                if (   !(pKrnlInfo->ulBuild >=  8254 && pKrnlInfo->ulBuild <  8383) /* Warp 3 fp 32 -> fp 60 */
     502                                    && !(pKrnlInfo->ulBuild >=  9023 && pKrnlInfo->ulBuild <= 9036) /* Warp 4 GA -> fp 12 */
     503                                    && !(pKrnlInfo->ulBuild >= 14039 && pKrnlInfo->ulBuild < 14080) /* Warp 4.5 GA -> fp 40 */
    491504                                      )
    492505                                {
    493                                     kprintf(("GetOTEs32: info summary: Build %d is invalid - invalid fixpack?\n", pKrnlInfo->usBuild));
    494                                     usRc = 6;
     506                                    kprintf(("GetKernelInfo32: info summary: Build %d is invalid - invalid fixpack?\n", pKrnlInfo->ulBuild));
     507                                    usRc = ERROR_D32_INVALID_BUILD;
    495508                                    break;
    496509                                }
     
    500513                                    || (psz[0] == '_' && (psz[1] == 'S' || psz[1] == 's'))  /* _SMP  */
    501514                                    )
    502                                     pKrnlInfo->fchType = TYPE_SMP;
    503                                 else if (psz[0] == '_' && psz[1] == 'W' && psz[2] == '4')    /* _W4  */
    504                                     pKrnlInfo->fchType = TYPE_W4;
     515                                    pKrnlInfo->fKernel = KF_SMP;
    505516                                else
    506                                     pKrnlInfo->fchType = TYPE_UNI;
     517                                    if (*psz != ','
     518                                        && (psz[0] == '_' && (psz[1] == 'W' || psz[1] == 'w') && psz[2] == '4')  /* _W4 */
     519                                        )
     520                                    pKrnlInfo->fKernel = KF_W4 | KF_UNI;
     521                                else
     522                                    pKrnlInfo->fKernel = KF_UNI;
    507523
    508524
    509525                                /* Check if its a debug kernel (look for DEBUG at start of object 3-5) */
     526                            #ifndef R3TST
    510527                                j = 3;
    511                                 pKrnlInfo->fDebug = FALSE;
    512528                                while (j < 5)
    513529                                {
     
    520536                                        && strncmp((char*)pKrnlOTE[j].ote_base, "DEBUG", 5) == 0)
    521537                                    {
    522                                         pKrnlInfo->fDebug = TRUE;
     538                                        pKrnlInfo->fKernel |= KF_DEBUG;
    523539                                        break;
    524540                                    }
    525541                                    j++;
    526542                                }
     543                            #else
     544                                NOREF(j);
     545                            #endif
    527546
    528547                                /* Display info */
    529                                 kprintf(("GetOTEs32: info summary: Build %d, fchType=%d, fDebug=%d\n",
    530                                          pKrnlInfo->usBuild, pKrnlInfo->fchType, pKrnlInfo->fDebug));
     548                                kprintf(("GetKernelInfo32: info summary: Build %d, fKernel=%d\n",
     549                                         pKrnlInfo->ulBuild, pKrnlInfo->fKernel));
    531550
    532551                                /* Break out */
     
    540559
    541560                    /* Set error code if not found */
    542                     if (pKrnlInfo->usBuild == 0)
     561                    if (pKrnlInfo->ulBuild == 0)
    543562                    {
    544                         usRc = 5;
    545                         kprintf(("GetOTEs32: Internal revision was not found!\n"));
     563                        usRc = ERROR_D32_BUILD_INFO_NOT_FOUND;
     564                        kprintf(("GetKernelInfo32: Internal revision was not found!\n"));
    546565                    }
    547566                }
    548567                else
    549                     usRc = 4;
     568                    usRc = ERROR_D32_NO_OBJECT_TABLE;
    550569            }
    551570            else
    552                 usRc = 3;
     571                usRc = ERROR_D32_TOO_MANY_OBJECTS;
    553572        }
    554573        else
    555             usRc = 2;
     574            usRc = ERROR_D32_NO_SWAPMTE;
    556575    }
    557576    else
    558         usRc = 1;
    559 
    560 
    561     if (usRc != 0)
    562         kprintf(("GetOTEs32: failed. usRc = %d\n", usRc));
     577        usRc = ERROR_D32_GETOS2KRNL_FAILED;
     578
     579    if (usRc != NO_ERROR)
     580        kprintf(("GetKernelInfo32: failed. usRc = %d\n", usRc));
    563581
    564582    return (USHORT)(usRc | (usRc != NO_ERROR ? STATUS_DONE | STERR : STATUS_DONE));
     
    575593 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    576594 */
    577 _Inline int ModR_M_32bit(char bModRM)
     595int ModR_M_32bit(char bModRM)
    578596{
    579597    if ((bModRM & 0xc0) == 0x80  /* ex. mov ax,[ebp+11145543h] */
     
    591609
    592610
     611/**
     612 * Functions which cacluates the instructionsize given a ModR/M byte.
     613 * @returns   Number of bytes to add to cb and pach.
     614 * @param     bModRM  ModR/M byte.
     615 * @status    completely implemented.
     616 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     617 */
     618int ModR_M_16bit(char bModRM)
     619{
     620    if ((bModRM & 0xc0) == 0x80  /* ex. mov ax,[ebp+11145543h] */
     621        || ((bModRM & 0xc0) == 0 && (bModRM & 0x07) == 5)) /* ex. mov ebp,[0ff231234h] */
     622    {   /* 16-bit displacement */
     623        return 4;
     624    }
     625    else if ((bModRM & 0xc0) == 0x40) /* ex. mov ecx,[esi]+4fh */
     626    {   /* 8-bit displacement */
     627        return 2;
     628    }
     629    /* no displacement (only /r byte) */
     630    return 1;
     631}
     632
     633
    593634
    594635
     
    603644 *                       FALSE: Function is to be imported.
    604645 */
    605 static int interpretFunctionProlog32(char *pach, BOOL fOverload)
     646int interpretFunctionProlog32(char *pach, BOOL fOverload)
    606647{
    607648    int cb = -3;
    608 
    609649    kprintf2(("interpretFunctionProlog32(0x%08x, %d):\n"
    610650              "\t%02x %02x %02x %02x - %02x %02x %02x %02x\n"
     
    787827 *                       FALSE: Function is to be imported.
    788828 */
    789 static int interpretFunctionProlog16(char *pach, BOOL fOverload)
     829int interpretFunctionProlog16(char *pach, BOOL fOverload)
    790830{
    791831    int cb = -7;
     
    809849        while (cb < 8 || fForce)        /* 8 is the size of a 66h prefixed far jump instruction. */
    810850        {
     851            int cb2;
    811852            fForce = FALSE;
    812853            switch (*pach)
    813854            {
     855                case 0x06:              /* push es */
     856                case 0x0e:              /* push cs */
     857                case 0x1e:              /* push ds */
     858                case 0x16:              /* push ss */
     859                    break;
     860
    814861                case 0x0f:              /* push gs and push fs */
    815862                    if (pach[1] != 0xA0 && pach[1] != 0xA8)
     
    888935                    break;
    889936
     937                /* complex sized instruction - "/5 ib" */
     938                case 0x80:              /* 5: sub r/m8, imm8  7: cmp r/m8, imm8 */
     939                case 0x83:              /* 5: sub r/m16, imm8 7: cmp r/m16, imm8 */
     940                    if ((pach[1] & 0x38) == (5<<3)
     941                        || (pach[1] & 0x38) == (7<<3)
     942                        )
     943                    {
     944                        cb += cb2 = 1 + ModR_M_16bit(pach[1]); /* 1 is the size of the imm8 */
     945                        pach += cb2;
     946                    }
     947                    else
     948                    {
     949                        kprintf(("interpretFunctionProlog32: unknown instruction (-3) 0x%x 0x%x 0x%x\n", pach[0], pach[1], pach[2]));
     950                        return -3;
     951                    }
     952                    break;
     953
     954
    890955                default:
    891956                    kprintf(("interpretFunctionProlog16: unknown instruction 0x%x 0x%x 0x%x\n", pach[0], pach[1], pach[2]));
     
    913978USHORT _loadds _Far32 _Pascal VerifyImportTab32(void)
    914979{
    915     int i;
    916     int cb;
    917     int cbmin;
     980    USHORT  usRc;
     981    int     i;
     982    int     cb;
     983    int     cbmin;
    918984
    919985    /* VerifyImporTab32 is called before the initroutine! */
    920986    pulTKSSBase32 = (PULONG)_TKSSBase16;
    921987
     988#ifdef R3TST
     989    R3TstFixImportTab();
     990#endif
     991
    922992    /* Check that pKrnlOTE is set */
    923     if (GetKernelInfo32(NULL) != NO_ERROR)
    924         return STATUS_DONE | STERR | 1;
     993    usRc = GetKernelInfo32(NULL);
     994    if (usRc != NO_ERROR)
     995        return (USHORT)(STATUS_DONE | STERR | (usRc & STECODE));
    925996
    926997    /*
     
    9401011        {
    9411012            kprintf(("VerifyImportTab32: procedure no.%d was not fFound!\n", i));
    942             return STATUS_DONE | STERR | 2;
     1013            return STATUS_DONE | STERR | ERROR_D32_PROC_NOT_FOUND;
    9431014        }
    9441015
     1016    #ifndef R3TST
    9451017        /* Verify read/writeable. */
    9461018        if (_aImportTab[i].iObject >= pKrnlSMTE->smte_objcnt                                /* object index valid? */
     
    9561028                     i, &_aImportTab[i].achName[0], _aImportTab[i].ulAddress,
    9571029                     _aImportTab[i].iObject, _aImportTab[i].offObject));
    958             return STATUS_DONE | STERR | 3;
     1030            return STATUS_DONE | STERR | ERROR_D32_INVALID_OBJ_OR_ADDR;
    9591031        }
    9601032
     
    9651037            kprintf(("VerifyImportTab32: procedure no.%d has an invalid address, %#08x!\n",
    9661038                     i, _aImportTab[i].ulAddress));
    967             return STATUS_DONE | STERR | 4;
     1039            return STATUS_DONE | STERR | ERROR_D32_INVALID_ADDRESS;
    9681040        }
     1041    #endif
    9691042
    9701043        switch (_aImportTab[i].fType & ~EPT_BIT_MASK)
     
    9911064                 * Check result of the function prolog interpretations.
    9921065                 */
    993                 if (cb <= 0 && cb + cbmin >= MAXSIZE_PROLOG)
     1066                if (cb <= 0 || cb + cbmin >= MAXSIZE_PROLOG)
    9941067                {   /* failed, too small or too large. */
    9951068                    kprintf(("VerifyImportTab32: verify failed for procedure no.%d (cd=%d)\n", i, cb));
    996                     return STATUS_DONE | STERR | 5;
     1069                    return STATUS_DONE | STERR | ERROR_D32_TOO_INVALID_PROLOG;
    9971070                }
    9981071                break;
     
    10031076
    10041077            default:
    1005                 kprintf(("VerifyImportTab32: only EPT_PROC is implemented\n",i));
     1078                kprintf(("VerifyImportTab32: invalid type/type not implemented\n",i));
    10061079                Int3(); /* temporary fix! */
    1007                 return STATUS_DONE | STERR | 6;
     1080                return STATUS_DONE | STERR | ERROR_D32_NOT_IMPLEMENTED;
    10081081        }
    10091082    }
     
    10171090 * @returns   NO_ERROR on success. !0 on error.
    10181091 */
    1019 static int importTabInit(void)
     1092int importTabInit(void)
    10201093{
    10211094    /* This table must be updated with the overloading functions. */
    10221095    static unsigned auFuncs[NBR_OF_KRNLIMPORTS] =
    10231096    {
    1024         (unsigned)myldrRead,
    1025         (unsigned)myldrOpen,
    1026         (unsigned)myldrClose,
    1027         (unsigned)myLDRQAppType,
    1028         (unsigned)myldrEnum32bitRelRecs,
    1029         0,
    1030         0,
    1031         0,
    1032         0,
    1033         0,
    1034         0,
    1035         0,
    1036         0,
    1037         (unsigned)&mytkExecPgm,
    1038         0,
    1039         0,
    1040         0,
    1041         0
    1042     };
    1043 
     1097        (unsigned)myldrRead,            /* 0 */
     1098        (unsigned)myldrOpen,            /* 1 */
     1099        (unsigned)myldrClose,           /* 2 */
     1100        (unsigned)myLDRQAppType,        /* 3 */
     1101        (unsigned)myldrEnum32bitRelRecs,/* 4 */
     1102        0,                              /* 5 */
     1103        0,                              /* 6 */
     1104        0,                              /* 7 */
     1105        0,                              /* 8 */
     1106        0,                              /* 9 */
     1107        0,                              /* 10 */
     1108        0,                              /* 11 */
     1109        0,                              /* 12 */
     1110        (unsigned)&mytkExecPgm,         /* 13 */
     1111        0,                              /* 14 */
     1112        0,                              /* 15 */
     1113        0,                              /* 16 */
     1114        0,                              /* 17 */
     1115        (unsigned)myldrOpenPath,        /* 18 */
     1116        0,                              /* 19 */
     1117        0,                              /* 20 */
     1118        0,                              /* 21 */
     1119        0,                              /* 22 */
     1120        0,                              /* 23 */
     1121        0,                              /* 24 */
     1122        0,                              /* 25 */
     1123        0,                              /* 26 */
     1124        0,                              /* 27 */
     1125        0,                              /* 28 */
     1126        0                               /* 29 */
     1127    };
    10441128    int i;
    10451129    int cb;
    10461130    int cbmin;
     1131
     1132#ifdef R3TST
     1133    R3TstFixImportTab();
     1134#endif
    10471135
    10481136    /*
     
    10681156        {
    10691157            kprintf(("ImportTabInit: Verify failed for procedure no.%d, cb=%d\n", i, cb));
    1070             return 1;
     1158            return ERROR_D32_VERIFY_FAILED;
    10711159        }
    10721160    }
     
    11141202                    kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when rehooking it!\n",i));
    11151203                    Int3(); /* ipe - later! */
    1116                     return 1;
     1204                    return ERROR_D32_VERIFY_FAILED;
    11171205                }
    11181206                break;
     
    11591247                    kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when rehooking it!\n",i));
    11601248                    Int3(); /* ipe - later! */
    1161                     return 1;
     1249                    return ERROR_D32_VERIFY_FAILED;
    11621250                }
    11631251                break;
     
    11871275                    kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when importing it!\n",i));
    11881276                    Int3(); /* ipe - later! */
    1189                     return 1;
     1277                    return ERROR_D32_VERIFY_FAILED;
    11901278                }
    11911279                break;
     
    12151303                    kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when importing it!\n",i));
    12161304                    Int3(); /* ipe - later! */
    1217                     return 1;
     1305                    return ERROR_D32_VERIFY_FAILED;
    12181306                }
    12191307                break;
     
    12421330                kprintf(("ImportTabInit: unsupported type. (procedure no.%d, cb=%d)\n", i, cb));
    12431331                Int3(); /* ipe - later! */
    1244                 return 1;
     1332                return ERROR_D32_VERIFY_FAILED;
    12451333        } /* switch - type */
    12461334    }   /* for */
     
    12501338#endif /* !DEBUGR3 */
    12511339
     1340
     1341#ifdef R3TST
     1342/**
     1343 * Creates a fake kernel MTE, SMTE and OTE for use while testing in Ring3.
     1344 * @returns Pointer to the fake kernel MTE.
     1345 * @status  completely implemented.
     1346 * @author  knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     1347 */
     1348PMTE GetOS2KrnlMTETst(void)
     1349{
     1350    static MTE    KrnlMTE;
     1351    static SMTE   KrnlSMTE;
     1352    static OTE    aKrnlOTE[17];
     1353
     1354    extern int  cObjectsFake; /* defined in win32ktst.c */
     1355
     1356    KrnlMTE.mte_swapmte = &KrnlSMTE;
     1357    KrnlSMTE.smte_objtab = &aKrnlOTE[0];
     1358    KrnlSMTE.smte_objcnt = cObjectsFake;
     1359
     1360    aKrnlOTE[0].ote_size     = 0x00000FB4;
     1361    aKrnlOTE[0].ote_base     = 0xffe10000;
     1362    aKrnlOTE[0].ote_flags    = 0x80001063;
     1363    aKrnlOTE[0].ote_pagemap  = 1;
     1364    aKrnlOTE[0].ote_mapsize  = 1;
     1365    aKrnlOTE[0].ote_sel      = 0;
     1366    aKrnlOTE[0].ote_hob      = 0;
     1367
     1368    aKrnlOTE[1].ote_size     = 0x0000A7CD;
     1369    aKrnlOTE[1].ote_base     = 0xffe20000;
     1370    aKrnlOTE[1].ote_flags    = 0x80001063;
     1371    aKrnlOTE[1].ote_pagemap  = 0x00000002;
     1372    aKrnlOTE[1].ote_mapsize  = 0x0000000B;
     1373    aKrnlOTE[1].ote_sel      = 0x0;
     1374    aKrnlOTE[1].ote_hob      = 0x0;
     1375
     1376    aKrnlOTE[2].ote_size     = 0x000084C9;
     1377    aKrnlOTE[2].ote_base     = 0xffe30000;
     1378    aKrnlOTE[2].ote_flags    = 0x80001045;
     1379    aKrnlOTE[2].ote_pagemap  = 0x0000000D;
     1380    aKrnlOTE[2].ote_mapsize  = 0x00000009;
     1381    aKrnlOTE[2].ote_sel      = 0x0;
     1382    aKrnlOTE[2].ote_hob      = 0x0;
     1383
     1384    aKrnlOTE[3].ote_size     = 0x00010000;
     1385    aKrnlOTE[3].ote_base     = 0xffe40000;
     1386    aKrnlOTE[3].ote_flags    = 0x800090A3;
     1387    aKrnlOTE[3].ote_pagemap  = 0x00000016;
     1388    aKrnlOTE[3].ote_mapsize  = 0x00000010;
     1389    aKrnlOTE[3].ote_sel      = 0x0;
     1390    aKrnlOTE[3].ote_hob      = 0x0;
     1391
     1392    aKrnlOTE[4].ote_size     = 0x00002A80;
     1393    aKrnlOTE[4].ote_base     = 0xffe50000;
     1394    aKrnlOTE[4].ote_flags    = 0x80009023;
     1395    aKrnlOTE[4].ote_pagemap  = 0x00000026;
     1396    aKrnlOTE[4].ote_mapsize  = 0x00000003;
     1397    aKrnlOTE[4].ote_sel      = 0x0;
     1398    aKrnlOTE[4].ote_hob      = 0x0;
     1399
     1400    aKrnlOTE[5].ote_size     = 0x00005734;
     1401    aKrnlOTE[5].ote_base     = 0xffe60000;
     1402    aKrnlOTE[5].ote_flags    = 0x80001023;
     1403    aKrnlOTE[5].ote_pagemap  = 0x00000029;
     1404    aKrnlOTE[5].ote_mapsize  = 0x00000003;
     1405    aKrnlOTE[5].ote_sel      = 0x0;
     1406    aKrnlOTE[5].ote_hob      = 0x0;
     1407
     1408    aKrnlOTE[6].ote_size     = 0x00002833;
     1409    aKrnlOTE[6].ote_base     = 0xffe70000;
     1410    aKrnlOTE[6].ote_flags    = 0x80001015;
     1411    aKrnlOTE[6].ote_pagemap  = 0x0000002C;
     1412    aKrnlOTE[6].ote_mapsize  = 0x00000003;
     1413    aKrnlOTE[6].ote_sel      = 0x0;
     1414    aKrnlOTE[6].ote_hob      = 0x0;
     1415
     1416    aKrnlOTE[7].ote_size     = 0x000001B0;
     1417    aKrnlOTE[7].ote_base     = 0xffe80000;
     1418    aKrnlOTE[7].ote_flags    = 0x80002213;
     1419    aKrnlOTE[7].ote_pagemap  = 0x0000002F;
     1420    aKrnlOTE[7].ote_mapsize  = 0x00000001;
     1421    aKrnlOTE[7].ote_sel      = 0x0;
     1422    aKrnlOTE[7].ote_hob      = 0x0;
     1423
     1424    aKrnlOTE[8].ote_size     = 0x000027CC;
     1425    aKrnlOTE[8].ote_base     = 0xffe90000;
     1426    aKrnlOTE[8].ote_flags    = 0x80002013;
     1427    aKrnlOTE[8].ote_pagemap  = 0x00000030;
     1428    aKrnlOTE[8].ote_mapsize  = 0x00000003;
     1429    aKrnlOTE[8].ote_sel      = 0x0;
     1430    aKrnlOTE[8].ote_hob      = 0x0;
     1431
     1432    aKrnlOTE[9].ote_size     = 0x0000FDA8;
     1433    aKrnlOTE[9].ote_base     = 0xffeA0000;
     1434    aKrnlOTE[9].ote_flags    = 0x80002033;
     1435    aKrnlOTE[9].ote_pagemap  = 0x00000033;
     1436    aKrnlOTE[9].ote_mapsize  = 0x0000000D;
     1437    aKrnlOTE[9].ote_sel      = 0x0;
     1438    aKrnlOTE[9].ote_hob      = 0x0;
     1439
     1440    aKrnlOTE[10].ote_size     = 0x0000ECD6;
     1441    aKrnlOTE[10].ote_base     = 0xffeB0000;
     1442    aKrnlOTE[10].ote_flags    = 0x80001015;
     1443    aKrnlOTE[10].ote_pagemap  = 0x00000040;
     1444    aKrnlOTE[10].ote_mapsize  = 0x0000000F;
     1445    aKrnlOTE[10].ote_sel      = 0x0;
     1446    aKrnlOTE[10].ote_hob      = 0x0;
     1447
     1448    aKrnlOTE[11].ote_size     = 0x0000EAF4;
     1449    aKrnlOTE[11].ote_base     = 0xffeC0000;
     1450    aKrnlOTE[11].ote_flags    = 0x80001015;
     1451    aKrnlOTE[11].ote_pagemap  = 0x0000004F;
     1452    aKrnlOTE[11].ote_mapsize  = 0x0000000F;
     1453    aKrnlOTE[11].ote_sel      = 0x0;
     1454    aKrnlOTE[11].ote_hob      = 0x0;
     1455
     1456    aKrnlOTE[12].ote_size     = 0x0000D900;
     1457    aKrnlOTE[12].ote_base     = 0xffeD0000;
     1458    aKrnlOTE[12].ote_flags    = 0x80001015;
     1459    aKrnlOTE[12].ote_pagemap  = 0x0000005E;
     1460    aKrnlOTE[12].ote_mapsize  = 0x0000000E;
     1461    aKrnlOTE[12].ote_sel      = 0x0;
     1462    aKrnlOTE[12].ote_hob      = 0x0;
     1463
     1464    aKrnlOTE[13].ote_size     = 0x0000D6DC;
     1465    aKrnlOTE[13].ote_base     = 0xffeE0000;
     1466    aKrnlOTE[13].ote_flags    = 0x80001015;
     1467    aKrnlOTE[13].ote_pagemap  = 0x0000006C;
     1468    aKrnlOTE[13].ote_mapsize  = 0x0000000E;
     1469    aKrnlOTE[13].ote_sel      = 0x0;
     1470    aKrnlOTE[13].ote_hob      = 0x0;
     1471
     1472    aKrnlOTE[14].ote_size     = 0x000B684B;
     1473    aKrnlOTE[14].ote_base     = 0xffeF0000;
     1474    aKrnlOTE[14].ote_flags    = 0x80002015;
     1475    aKrnlOTE[14].ote_pagemap  = 0x0000007A;
     1476    aKrnlOTE[14].ote_mapsize  = 0x000000B7;
     1477    aKrnlOTE[14].ote_sel      = 0x0;
     1478    aKrnlOTE[14].ote_hob      = 0x0;
     1479
     1480    aKrnlOTE[15].ote_size     = 0x000B684B;
     1481    aKrnlOTE[15].ote_base     = 0xffeF0000;
     1482    aKrnlOTE[15].ote_flags    = 0x80002015;
     1483    aKrnlOTE[15].ote_pagemap  = 0x0000007A;
     1484    aKrnlOTE[15].ote_mapsize  = 0x000000B7;
     1485    aKrnlOTE[15].ote_sel      = 0x0;
     1486    aKrnlOTE[15].ote_hob      = 0x0;
     1487
     1488    aKrnlOTE[16].ote_size     = 0x000B684B;
     1489    aKrnlOTE[16].ote_base     = 0xffeF0000;
     1490    aKrnlOTE[16].ote_flags    = 0x80002015;
     1491    aKrnlOTE[16].ote_pagemap  = 0x0000007A;
     1492    aKrnlOTE[16].ote_mapsize  = 0x000000B7;
     1493    aKrnlOTE[16].ote_sel      = 0x0;
     1494    aKrnlOTE[16].ote_hob      = 0x0;
     1495
     1496    return &KrnlMTE;
     1497}
     1498
     1499/**
     1500 * -Ring-3 testing-
     1501 * Changes the entries in _aImportTab to point to their fake equivalents.
     1502 * @returns void
     1503 * @param   void
     1504 * @status  completely implemented.
     1505 * @author  knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     1506 * @remark  Called before the _aImportTab array is used/verified.
     1507 */
     1508VOID R3TstFixImportTab(VOID)
     1509{
     1510    struct _TstFaker
     1511    {
     1512        unsigned   uAddress;
     1513        int        fObj;                   /* 1 = CODE32, 2 = CODE16, 3 = DATA32, 4 = DATA16 */
     1514    }
     1515    aTstFakers[NBR_OF_KRNLIMPORTS] =
     1516    {
     1517        {(unsigned)fakeldrRead,             1},
     1518        {(unsigned)fakeldrOpen,             1},
     1519        {(unsigned)fakeldrClose,            1},
     1520        {(unsigned)fakeLDRQAppType,         1},
     1521        {(unsigned)fakeldrEnum32bitRelRecs, 1},
     1522        {(unsigned)fakeIOSftOpen,           1},
     1523        {(unsigned)fakeIOSftClose,          1},
     1524        {(unsigned)fakeIOSftTransPath,      1},
     1525        {(unsigned)fakeIOSftReadAt,         1},
     1526        {(unsigned)fakeIOSftWriteAt,        1},
     1527        {(unsigned)fakeSftFileSize,         1},
     1528        {(unsigned)fakeVMAllocMem,          1},
     1529        {(unsigned)fakeVMGetOwner,          1},
     1530        {(unsigned)fakeg_tkExecPgm,         1},
     1531        {(unsigned)fakef_FuStrLenZ,         2},
     1532        {(unsigned)fakef_FuStrLen,          2},
     1533        {(unsigned)fakef_FuBuff,            2},
     1534        {(unsigned)fakeVMObjHandleInfo,     1},
     1535        {(unsigned)fakeldrOpenPath,         1},
     1536        {(unsigned)fakeLDRClearSem,         1},
     1537        {(unsigned)fakeKSEMRequestMutex,    1},
     1538        {(unsigned)&fakeLDRSem,             3},
     1539        {(unsigned)fakeTKSuBuff,            1},
     1540        {(unsigned)fakeTKFuBuff,            1},
     1541        {(unsigned)fakeTKFuBufLen,          1},
     1542        {(unsigned)fakeldrValidateMteHandle,1},
     1543        {(unsigned)&fakepTCBCur,            4},
     1544        {(unsigned)&fakepPTDACur,           4},
     1545        {(unsigned)&fakeptda_start,         4},
     1546        {(unsigned)&fakeptda_environ,       4}
     1547    };
     1548    int i;
     1549
     1550    for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
     1551    {
     1552        switch (_aImportTab[i].fType)
     1553        {
     1554            case EPT_PROC32:
     1555                if (aTstFakers[i].fObj != 1)
     1556                    kprintf(("R3TstFixImportTab: invalid segment config for entry %i. (PROC32)\n", i));
     1557                break;
     1558            case EPT_PROCIMPORT32:
     1559                if (aTstFakers[i].fObj != 1)
     1560                    kprintf(("R3TstFixImportTab: invalid segment config for entry %i. (PROCIMPORT32)\n", i));
     1561                break;
     1562            case EPT_PROCIMPORT16:
     1563                if (aTstFakers[i].fObj != 2)
     1564                    kprintf(("R3TstFixImportTab: invalid segment config for entry %i. (PROCIMPORT16)\n", i));
     1565                break;
     1566            case EPT_VARIMPORT32:
     1567            case EPT_VARIMPORT16:
     1568                if (aTstFakers[i].fObj != 3 && aTstFakers[i].fObj != 4)
     1569                    kprintf(("R3TstFixImportTab: invalid segment config for entry %i. (VARIMPORT32/16)\n", i));
     1570                break;
     1571        } /* switch - type */
     1572
     1573        _aImportTab[i].ulAddress = aTstFakers[i].uAddress;
     1574        switch (aTstFakers[i].fObj)
     1575        {
     1576            case 1:
     1577                _aImportTab[i].usSel = GetSelectorCODE32();
     1578                _aImportTab[i].offObject = aTstFakers[i].uAddress - (unsigned)&CODE32START;
     1579                break;
     1580            case 2:
     1581                _aImportTab[i].usSel = GetSelectorCODE16();
     1582                _aImportTab[i].offObject = aTstFakers[i].uAddress - (unsigned)&CODE16START;
     1583                break;
     1584            case 3:
     1585                _aImportTab[i].usSel = GetSelectorDATA32();
     1586                _aImportTab[i].offObject = aTstFakers[i].uAddress - (unsigned)&DATA32START;
     1587                break;
     1588            case 4:
     1589                _aImportTab[i].usSel = GetSelectorDATA16();
     1590                _aImportTab[i].offObject = aTstFakers[i].uAddress - (unsigned)&DATA16START;
     1591                break;
     1592            default:
     1593                kprintf(("R3TstFixImportTab: invalid segment config for entry %i.\n", i));
     1594        }
     1595    } /* for */
     1596}
     1597#endif
    12521598
    12531599
     
    13671713        0xEC, 0x83, 0xEC, 0x0C, 0x53, 0x57, 0x8D, 0x55,
    13681714        0xF8
     1715    };
     1716    char achf_ldrOpenPath[] = {
     1717        0x55, 0xA1, 0xA4, 0x0A, 0x00, 0x00, 0x8B, 0xEC,
     1718        0x83, 0xEC, 0x28, 0x66, 0x8B, 0x80, 0xFE, 0x01,
     1719        0x00, 0x00, 0x53, 0x57, 0x66, 0x89, 0x45, 0xE2
    13691720    };
    13701721
     
    13901741        achf_FuBuff            ,
    13911742        achf_VMObjHandleInfo   ,
     1743        achf_ldrOpenPath       ,
    13921744        NULL
    13931745    };
Note: See TracChangeset for help on using the changeset viewer.