Ignore:
Timestamp:
Jun 18, 2009, 11:53:26 AM (16 years ago)
Author:
ydario
Message:

Kernel32 updates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/wprocess.cpp

    r10481 r21302  
    6767ODINDEBUGCHANNEL(KERNEL32-WPROCESS)
    6868
     69
     70//environ.cpp
     71char *CreateNewEnvironment(char *lpEnvironment);
    6972
    7073/*******************************************************************************
     
    19061909 STARTUPINFOA startinfo;
    19071910 TEB *pThreadDB = (TEB*)GetThreadTEB();
    1908  char *cmdline = NULL, *newenv = NULL;
     1911 char *cmdline = NULL, *newenv = NULL, *oldlibpath = NULL;
    19091912 BOOL  rc;
    19101913
     
    19391942
    19401943        memcpy(&startinfo, lpStartupInfo, sizeof(startinfo));
     1944        if(lpStartupInfo->hStdInput) {
    19411945        retcode |= HMHandleTranslateToOS2(lpStartupInfo->hStdInput, &startinfo.hStdInput);
     1946        }
     1947        if(lpStartupInfo->hStdOutput) {
    19421948        retcode |= HMHandleTranslateToOS2(lpStartupInfo->hStdOutput, &startinfo.hStdOutput);
     1949        }
     1950        if(lpStartupInfo->hStdError) {
    19431951        retcode |= HMHandleTranslateToOS2(lpStartupInfo->hStdError, &startinfo.hStdError);
     1952        }
    19441953
    19451954        if(retcode) {
     
    20192028                 break;
    20202029             }
    2021 
     2030             else
     2031             {//maybe it's a short name
     2032                 if(GetLongPathNameA(buffer, szAppName, sizeof(szAppName)))
     2033                 {
     2034                     if(fTerminate) exename++;
     2035                     break;
     2036                 }
     2037             }
    20222038             if(fTerminate) {
    20232039                  *exename = ' ';
     
    20392055    }
    20402056
     2057    if(lpEnvironment) {
     2058        newenv = CreateNewEnvironment((char *)lpEnvironment);
     2059        if(newenv == NULL) {
     2060            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
     2061            rc = FALSE;
     2062            goto finished;
     2063        }
     2064        lpEnvironment = newenv;
     2065    }
     2066
    20412067    DWORD Characteristics, SubSystem, fNEExe, fPEExe;
    20422068
     
    20502076    if(!fPEExe || (fPEExe && fWin32k))
    20512077    {
     2078
     2079    trylaunchagain:
    20522080      if(O32_CreateProcess(szAppName, lpCommandLine, lpProcessAttributes,
    20532081                         lpThreadAttributes, bInheritHandles, dwCreationFlags,
     
    20782106        goto finished;
    20792107      }
    2080 
     2108        else
     2109        if(!oldlibpath)
     2110        {//might have failed because it wants to load dlls in its current directory
     2111            // Add the application directory to the ENDLIBPATH, so dlls can be found there
     2112            // Only necessary for OS/2 applications
     2113            oldlibpath = (char *)calloc(4096, 1);
     2114            if(oldlibpath)
     2115            {
     2116                OSLibQueryBeginLibpath(oldlibpath, 4096);
     2117
     2118                char *tmp = strrchr(szAppName, '\\');
     2119                if(tmp) *tmp = 0;
     2120
     2121                OSLibSetBeginLibpath(szAppName);
     2122                if(tmp) *tmp = '\\';
     2123
     2124                goto trylaunchagain;
     2125            }
     2126
     2127        }
    20812128      // verify why O32_CreateProcess actually failed.
    20822129      // If GetLastError() == 191 (ERROR_INVALID_EXE_SIGNATURE)
     
    21022149    if(fPEExe)
    21032150    {
    2104       char *lpszPE;
    2105       char *lpszExecutable;
     2151      LPCSTR    lpszExecutable;
    21062152      int  iNewCommandLineLength;
    21072153
     
    21102156
    21112157      if(SubSystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
    2112         lpszExecutable = (LPSTR)szPECmdLoader;
     2158        lpszExecutable = szPECmdLoader;
    21132159      else
    2114         lpszExecutable = (LPSTR)szPEGUILoader;
    2115 
    2116       lpszPE = lpszExecutable;
     2160        lpszExecutable = szPEGUILoader;
    21172161
    21182162      // 2002-04-24 PH
    21192163      // set the ODIN32.DEBUG_CHILD environment variable to start new PE processes
    21202164      // under a new instance of the (IPMD) debugger.
     2165      const char *pszDebugChildArg = "";
    21212166#ifdef DEBUG
    2122       CHAR debug_szPE[ 512 ];
    2123       PSZ debug_pszOS2Debugger = getenv("ODIN32.DEBUG_CHILD");
    2124       if (NULL != debug_pszOS2Debugger)
     2167      char          szDebugChild[512];
     2168      const char   *pszChildDebugger = getenv("ODIN32.DEBUG_CHILD");
     2169      if (pszChildDebugger)
    21252170      {
    2126         // build new start command
    2127         strcpy(debug_szPE, debug_pszOS2Debugger);
    2128         strcat(debug_szPE, " ");
    2129         strcat(debug_szPE, lpszExecutable);
    2130 
    2131         // we require more space in the new command line
    2132         iNewCommandLineLength += strlen( debug_szPE );
    2133 
    2134         // only launch the specified executable (ICSDEBUG.EXE)
    2135         lpszPE = debug_szPE;
    2136         lpszExecutable = debug_pszOS2Debugger;
     2171        /*
     2172         * Change the executable to the debugger (icsdebug.exe) and
     2173         * move the previous executable onto the commandline.
     2174         */
     2175        szDebugChild[0] = ' ';
     2176        strcpy(&szDebugChild[1], lpszExecutable);
     2177        iNewCommandLineLength += strlen(&szDebugChild[0]);
     2178
     2179        pszDebugChildArg = &szDebugChild[0];
     2180        lpszExecutable = pszChildDebugger;
    21372181      }
    21382182#endif
     
    21442188
    21452189            newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + iNewCommandLineLength + 64);
    2146             sprintf(newcmdline, " /OPT:[CURDIR=%s] %s %s", lpCurrentDirectory, szAppName, lpCommandLine);
     2190            sprintf(newcmdline, "%s /OPT:[CURDIR=%s] %s %s", pszDebugChildArg, lpCurrentDirectory, szAppName, lpCommandLine);
    21472191            free(cmdline);
    21482192            cmdline = newcmdline;
     
    21522196
    21532197            newcmdline = (char *)malloc(iNewCommandLineLength + 16);
    2154             sprintf(newcmdline, " %s %s", szAppName, lpCommandLine);
     2198            sprintf(newcmdline, "%s %s %s", pszDebugChildArg, szAppName, lpCommandLine);
    21552199            free(cmdline);
    21562200            cmdline = newcmdline;
     
    21922236                               lpProcessInfo);
    21932237    }
     2238    if(!lpEnvironment) {
     2239        // Restore old ENDLIBPATH variable
     2240        // TODO:
     2241    }
     2242
    21942243    if(rc == TRUE)
    21952244    {
     
    22222271finished:
    22232272
     2273    if(oldlibpath) {
     2274        OSLibSetBeginLibpath(oldlibpath);
     2275        free(oldlibpath);
     2276    }
    22242277    if(cmdline) free(cmdline);
    22252278    if(newenv)  free(newenv);
Note: See TracChangeset for help on using the changeset viewer.