Ignore:
Timestamp:
Aug 11, 2000, 4:23:19 AM (25 years ago)
Author:
bird
Message:

Corrected bugs. (mostly in OpenPATH)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GRACE/src/win32k/ldr/myldrOpen.cpp

    r3834 r3985  
    1 /* $Id: myldrOpen.cpp,v 1.10.4.1 2000-07-16 22:43:36 bird Exp $
     1/* $Id: myldrOpen.cpp,v 1.10.4.2 2000-08-11 02:23:19 bird Exp $
    22 *
    33 * myldrOpen - ldrOpen.
     
    7474
    7575    /** @sketch
    76      * Try open the file (thats why this function is called anyway)
     76     * Try open the file (that's why this function is called anyway)
    7777     */
    7878    rc = ldrOpen(phFile, pszFilename, pfl);
     
    9797        {
    9898            char               *pach;       /* Pointer to the buffer as char. */
     99            unsigned long      *pul;        /* Pointer to the buffer as unsigned long. */
    99100            PIMAGE_DOS_HEADER   pMzHdr;     /* Use the buffer as a dosheader. */
    100101            PIMAGE_NT_HEADERS   pNtHdrs;    /* Use the buffer as a NT header. */
     
    251252                    }
    252253                    else
     254                    {
    253255                        kprintf(("myldrOpen-%d: Failed to allocate Pe2Lx object.\n", cNesting));
    254 
    255                      goto cleanup;
     256                        rc = ERROR_NOT_ENOUGH_MEMORY;
     257                    }
     258
     259                    goto cleanup;
    256260                }
    257261
     
    312316             * ELF image?
    313317             */
    314             if (u1.pach[0] == ELFMAG0 && u1.pach[1] == ELFMAG1 && u1.pach[2] == ELFMAG2 && u1.pach[3] == ELFMAG3)
     318            if (*u1.pul == ELFMAGICLSB)
    315319            {
    316320                if (isELFDisabled())
     
    332336             * Java image?
    333337             */
    334             if (u1.pach[0] == 0xCA && u1.pach[1] == 0xFE && u1.pach[2] == 0xBA && u1.pach[3] == 0xBE)
     338            if (*u1.pul == 0xBEBAFECAUL) //CAh FEh BAh BEh
    335339            {
    336340                if (isJAVADisabled())
     
    393397                goto cleanup;
    394398            }
     399
    395400        }
    396401        else
     
    505510                     *  Open the new executable file recursively. (psz)
    506511                     */
    507                      if (isLdrStateExecPgm())
    508                      {
    509                          if (*psz2)
    510                             rc = AddArgsToFront(3, psz, psz2, achTkExecPgmFilename);
    511                          else
    512                             rc = AddArgsToFront(2, psz, achTkExecPgmFilename);
    513                          if (rc != NO_ERROR)
    514                          {
    515                              kprintf(("myldrOpen-%d: AddArgsToFront failed with rc=%d\n", cNesting));
    516                              goto cleanup_noerror;
    517                          }
    518                          rc = SetExecName(psz);
    519                          if (rc != NO_ERROR)
    520                              kprintf(("myldrOpen-%d: SetExecName failed with rc=%d\n", cNesting));
    521                      }
    522                      rc = myldrOpen(phFile, psz, pfl);
     512                    if (isLdrStateExecPgm())
     513                    {
     514                        if (*psz2)
     515                           rc = AddArgsToFront(3, psz, psz2, achTkExecPgmFilename);
     516                        else
     517                           rc = AddArgsToFront(2, psz, achTkExecPgmFilename);
     518                        if (rc != NO_ERROR)
     519                        {
     520                            kprintf(("myldrOpen-%d: AddArgsToFront failed with rc=%d\n", cNesting));
     521                            goto cleanup_noerror;
     522                        }
     523                        rc = SetExecName(psz);
     524                        if (rc != NO_ERROR)
     525                            kprintf(("myldrOpen-%d: SetExecName failed with rc=%d\n", cNesting));
     526                    }
     527                    ldrClose(*phFile);
     528                    rc = myldrOpen(phFile, psz, pfl);
     529                    if (rc != NO_ERROR)
     530                    {
     531                        psz2 = psz + strlen(psz);
     532                        if (psz + 4 >= psz2 || strcmp(psz2 - 4, ".EXE") != 0)
     533                        {
     534                            strcpy(psz2, ".EXE");
     535                            rc = myldrOpen(phFile, psz, pfl);
     536                            *psz2 = '\0';
     537                        }
     538                        else
     539                            psz2 = NULL;
     540
     541                        //should we search the PATH??? For a starting, we'll do it.
     542                        if (rc != NO_ERROR
     543                            && (rc = OpenPATH(phFile, psz, pfl)) != NO_ERROR
     544                            && psz2 != NULL)
     545                        {
     546                            *psz2 = '.';
     547                            rc = OpenPATH(phFile, psz, pfl);
     548                        }
     549                    }
    523550                }
    524551                else
     
    677704    }
    678705
    679     cchOldArgs = iSecondArg = strlen(&achTkExecPgmArguments[0]) + 1;
    680     psz = &achTkExecPgmArguments[cchOldArgs];
     706    iSecondArg = strlen(&achTkExecPgmArguments[0]) + 1;
     707    psz = &achTkExecPgmArguments[iSecondArg];
    681708    while (*psz != '\0')
    682         psz = &achTkExecPgmArguments[(cchOldArgs += strlen(psz) + 1)];
     709        psz += strlen(psz) + 1;
     710    cchOldArgs = psz - &achTkExecPgmArguments[iSecondArg];
    683711
    684712    va_start(vaarg, cArgs);
     
    701729     *    !IMPORTANT! in this move as this have to be re-added in this call!    !IMPORTANT!
    702730     */
    703     if (cchOldArgs + 1 + cchNewArgs > CCHARGUMENTS)
     731    if (cchOldArgs + cchNewArgs + 1 > CCHARGUMENTS)
    704732    {
    705733        kprintf(("AddArgsToFront: argument buffer is too small to hold the arguments to add, cchOldArgs=%d, cchNewArgs=%d\n",
     
    708736    }
    709737
    710     if (cchOldArgs > 1)
     738    if (cchOldArgs > 0)
    711739    {
    712740        memmove(&achTkExecPgmArguments[cchNewArgs], &achTkExecPgmArguments[iSecondArg],
    713                 cchOldArgs - iSecondArg + 1);
     741                cchOldArgs + 1);
    714742    }
    715743    else
    716         achTkExecPgmArguments[cchNewArgs + 1] = '\0';
     744        achTkExecPgmArguments[cchNewArgs] = '\0';
    717745
    718746
     
    727755    va_start(vaarg, cArgs);
    728756    psz = va_arg(vaarg, char *);
    729     iSecondArg = strlen(psz) + 1;
    730     memcpy(&achTkExecPgmArguments[0], psz, iSecondArg);
    731 
    732     psz = &achTkExecPgmArguments[iSecondArg];
    733     i = 2;                              /* one in advance to avoid a +1. */
    734     while (1)
    735     {
     757    memcpy(&achTkExecPgmArguments[0], psz, (i = strlen(psz) + 1));
     758    psz = &achTkExecPgmArguments[i];
     759
     760    for (i = 1; i < cArgs; i++)
     761    {
     762        if (i > 1) *psz++ = ' ';    //Add space if not second argument.
    736763        strcpy(psz, va_arg(vaarg, char *));
    737764        psz += strlen(psz);
    738         /* IF more arguments following (new or old) THEN add a space separator ELSE break loop */
    739         if (cchOldArgs > 1 || i < cArgs)
    740             *psz++ = ' ';
    741         else
    742             break;
    743         i++;
    744765    }
    745766    va_end(vaarg);
     767    if (cchOldArgs > 0) *psz++ = ' ';    //Add space if old arguments
    746768
    747769    #ifdef DEBUG /* assertion */
     
    817839    APIRET      rc;
    818840    USHORT      TCBFailErr_save;
    819     int         cchFilename;            /* Filename length + 1. */
     841    int         cchFile;                /* Filename length + 1. */
     842    const char *pszFile;                /* Pointer to filename portion. */
    820843    const char *pszPath = ScanEnv(GetEnv(FALSE), "PATH"); /* Current Process environment? */
    821844
     
    826849        return ERROR_FILE_NOT_FOUND;
    827850
    828     cchFilename = strlen(pszFilename) + 1;
     851    /**@sketch
     852     * Skip any paths in the filename.
     853     */
     854    pszFile = pszFilename + (cchFile = strlen(pszFilename));
     855    while (pszFile >= pszFilename && *pszFile != '\\' && *pszFile != '/')
     856        pszFile--;
     857    cchFile -= pszFile - pszFilename;
     858    pszFile++;
    829859
    830860    /**@sketch
     
    840870    while (*pszPath != '\0')
    841871    {
    842         const char *  pszNext = pszPath;
     872        const char *  pszNext;
    843873        int           cchPath;
    844         char          chEnd, ch;
     874        char          chEnd;
     875        register char ch;
    845876
    846877        /*
     
    848879         */
    849880        while (*pszPath == ' ') pszPath++; //skip leading spaces.
    850         chEnd = *pszPath == '"' ? '"' : ';';
     881        if (*pszPath == '"')
     882        {
     883            chEnd = '"';
     884            pszPath++;
     885        }
     886        else
     887            chEnd = ';';
     888        pszNext = pszPath;
    851889        while ((ch = *pszNext) != chEnd && ch != '\0')
    852890            pszNext++;
    853891
     892        cchPath = pszNext - pszPath;
    854893        if (chEnd == '"')
    855894        {
    856             cchPath = pszNext - (++pszPath); //pszPath points at '"' before incrementing it.
    857             if (ch != '\0')
     895            /* Skip anything between the " and the ; or string end. */
     896            while ((ch = *pszNext) != ';' && ch != '\0')
    858897                pszNext++;
    859898        }
     
    861900        {
    862901            /* Trim the string. */
    863             cchPath = pszNext - pszPath;
    864902            while (cchPath > 0 && pszPath[cchPath-1] == ' ') //??
    865903                cchPath--;
     
    869907         *  No length? No Path! Or path'\'filename too long? => Next
    870908         */
    871         if (cchPath > 0 && cchPath + cchFilename + 1 < CCHMAXPATH)
     909        if (cchPath > 0 && cchPath + cchFile + 1 < CCHMAXPATH)
    872910        {
    873911            static char     achFilename[CCHMAXPATH];
     
    880918            else
    881919                achFilename[cchPath] = '\\';
    882             memcpy(&achFilename[cchPath + 1], pszFilename, cchFilename); /* cchFilename = length + 1; hence we copy the terminator too. */
     920             memcpy(&achFilename[cchPath + 1], pszFile, cchFile); /* cchFile = length + 1; hence we copy the terminator too. */
    883921
    884922            /*
     
    898936
    899937                case NO_ERROR:
     938                    strcpy(pszFilename, achFilename);
    900939                default:
    901940                    tcbSetTCBFailErr(tcbGetCur(), TCBFailErr_save);
Note: See TracChangeset for help on using the changeset viewer.