Ignore:
Timestamp:
Jan 15, 2004, 11:41:39 AM (22 years ago)
Author:
sandervl
Message:

Updates

File:
1 edited

Legend:

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

    r10380 r10398  
    1 /* $Id: wprocess.cpp,v 1.190 2004-01-11 12:12:34 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.191 2004-01-15 10:41:39 sandervl Exp $ */
    22
    33/*
     
    66 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
    77 * Copyright 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     8 * Copyright 2003 Innotek Systemberatung GmbH (sandervl@innotek.de)
     9 *
    810 *
    911 * NOTE: Even though Odin32 OS/2 apps don't switch FS selectors,
     
    5052
    5153#include <win\ntddk.h>
     54#include <win\psapi.h>
    5255
    5356#include <custombuild.h>
     
    6467ODINDEBUGCHANNEL(KERNEL32-WPROCESS)
    6568
     69
     70//environ.cpp
     71char *CreateNewEnvironment(char *lpEnvironment);
    6672
    6773/*******************************************************************************
     
    268274
    269275    ProcessPDB.unknown10       = (PVOID)&unknownPDBData[0];
    270 
    271276    //initialize the startup info part of the db entry.
    272 ////    O32_GetStartupInfo(&StartupInfo);
     277    O32_GetStartupInfo(&StartupInfo);
    273278    StartupInfo.cb             = sizeof(StartupInfo);
    274279    /* Set some defaults as GetStartupInfo() used to set... */
     
    282287    if (!StartupInfo.lpTitle)
    283288        StartupInfo.lpTitle    = "Title";
    284 
    285289    ProcessENVDB.hStdin  = StartupInfo.hStdInput  = GetStdHandle(STD_INPUT_HANDLE);
    286290    ProcessENVDB.hStdout = StartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
     
    530534    fExitProcess = TRUE;
    531535
     536    // Lower priority of all threads to minimize the chance that they're scheduled
     537    // during ExitProcess. Can't kill them as that's possibly dangerous (deadlocks
     538    // in WGSS for instance)
     539    threadListMutex.enter();
     540    teb = threadList;
     541    while(teb) {
     542        if(teb->o.odin.hThread != hThread) {
     543            dprintf(("Active thread id %d, handle %x", LOWORD(teb->o.odin.threadId), teb->o.odin.hThread));
     544            SetThreadPriority(teb->o.odin.hThread, THREAD_PRIORITY_LOWEST);
     545        }
     546        teb = teb->o.odin.next;
     547    }
     548    threadListMutex.leave();
     549
    532550    HMDeviceCommClass::CloseOverlappedIOHandlers();
    533551
     
    556574    while(teb) {
    557575        dprintf(("Active thread id %d, handle %x", LOWORD(teb->o.odin.threadId), teb->o.odin.hThread));
    558         if(teb->o.odin.hThread != hThread && teb->o.odin.dwSuspend > 0) {
    559             //kill any threads that are suspended; dangerous, but so is calling
    560             //SuspendThread; we assume the app knew what it was doing
    561             TerminateThread(teb->o.odin.hThread, 0);
    562             ResumeThread(teb->o.odin.hThread);
     576        if(teb->o.odin.hThread != hThread) {
     577            if(teb->o.odin.dwSuspend > 0) {
     578                //kill any threads that are suspended; dangerous, but so is calling
     579                //SuspendThread; we assume the app knew what it was doing
     580                TerminateThread(teb->o.odin.hThread, 0);
     581                ResumeThread(teb->o.odin.hThread);
     582            }
     583            else SetThreadPriority(teb->o.odin.hThread, THREAD_PRIORITY_LOWEST);
    563584        }
    564585        teb = teb->o.odin.next;
     
    15751596    }
    15761597
    1577     dprintf(("KERNEL32:  GetCommandLineW: %s\n", pszCmdLineA));
     1598    dprintf(("KERNEL32:  GetCommandLineW: %ls\n", pszCmdLineW));
    15781599    return pszCmdLineW;
    15791600}
     
    18551876                              LPCSTR pszNELoader)
    18561877{
     1878    if(pszPECmdLoader) dprintf(("PE Cmd %s", pszPECmdLoader));
     1879    if(pszPEGUILoader) dprintf(("PE GUI %s", pszPEGUILoader));
     1880    if(pszNELoader)    dprintf(("NE %s", pszNELoader));
    18571881    if(pszPECmdLoader)   strcpy(szPECmdLoader, pszPECmdLoader);
    18581882    if(pszPEGUILoader)   strcpy(szPEGUILoader, pszPEGUILoader);
     
    18851909 STARTUPINFOA startinfo;
    18861910 TEB *pThreadDB = (TEB*)GetThreadTEB();
    1887  char *cmdline = NULL;
     1911 char *cmdline = NULL, *newenv = NULL;
    18881912 BOOL  rc;
    18891913
     
    18921916            lpEnvironment, lpCurrentDirectory, lpStartupInfo));
    18931917
     1918    if(lpEnvironment) {
     1919        newenv = CreateNewEnvironment((char *)lpEnvironment);
     1920        if(newenv == NULL) {
     1921            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
     1922            rc = FALSE;
     1923            goto finished;
     1924        }
     1925        lpEnvironment = newenv;
     1926    }
    18941927#ifdef DEBUG
    18951928    if(lpStartupInfo) {
     
    19241957        if(retcode) {
    19251958            SetLastError(ERROR_INVALID_HANDLE);
    1926             return FALSE;
     1959            rc = FALSE;
     1960            goto finished;
    19271961        }
    19281962
     
    20092043        dprintf(("CreateProcess: can't find executable!"));
    20102044
    2011         if(cmdline)
    2012             free(cmdline);
    2013 
    20142045        SetLastError(ERROR_FILE_NOT_FOUND);
    2015         return FALSE;
     2046
     2047        rc = FALSE;
     2048        goto finished;
    20162049    }
    20172050
     
    20522085        }
    20532086
    2054         if(cmdline)
    2055             free(cmdline);
    2056         return(TRUE);
     2087        rc = TRUE;
     2088        goto finished;
    20572089      }
    20582090
     
    20682100
    20692101          // the current value of GetLastError() is still valid.
    2070           if(cmdline)
    2071               free(cmdline);
    2072 
    2073           return FALSE;
     2102          rc = FALSE;
     2103          goto finished;
    20742104      }
    20752105    }
     
    21902220        pThreadDB->o.odin.pidDebuggee = 0;
    21912221    }
    2192     if(cmdline)
    2193         free(cmdline);
    2194 
    21952222    if(lpProcessInfo)
    21962223    {
     
    22022229    else
    22032230      dprintf(("KERNEL32:  CreateProcess returned %d\n", rc));
     2231
     2232finished:
     2233
     2234    if(cmdline) free(cmdline);
     2235    if(newenv)  free(newenv);
    22042236    return(rc);
    22052237}
     
    23652397{
    23662398 Win32ImageBase *winmod;
    2367  FARPROC   proc;
     2399 FARPROC   proc = 0;
    23682400 ULONG     ulAPIOrdinal;
    23692401
     
    23782410                proc = (FARPROC)winmod->getApi((int)ulAPIOrdinal);
    23792411        }
    2380         else    proc = (FARPROC)winmod->getApi((char *)lpszProc);
     2412        else
     2413        if (lpszProc && *lpszProc) {
     2414                proc = (FARPROC)winmod->getApi((char *)lpszProc);
     2415        }
    23812416        if(proc == 0) {
    23822417#ifdef DEBUG
     
    23872422#endif
    23882423                SetLastError(ERROR_PROC_NOT_FOUND);
     2424                return 0;
    23892425        }
    23902426        if(HIWORD(lpszProc))
     
    24402476#endif
    24412477                SetLastError(ERROR_PROC_NOT_FOUND);
     2478                return (FARPROC)-1;
    24422479        }
    24432480        if(HIWORD(lpszProc))
     
    25072544}
    25082545//******************************************************************************
    2509 //******************************************************************************
    2510 
    2511 
     2546// Forwarder for PSAPI.DLL
     2547//
     2548// Returns the handles of all loaded modules
     2549//
     2550//******************************************************************************
     2551BOOL WINAPI PSAPI_EnumProcessModules(HANDLE hProcess, HMODULE *lphModule,
     2552                                     DWORD cb, LPDWORD lpcbNeeded)
     2553{
     2554  DWORD count;
     2555  DWORD countMax;
     2556  HMODULE     hModule;
     2557
     2558  dprintf(("KERNEL32: EnumProcessModules %p, %ld, %p", lphModule, cb, lpcbNeeded));
     2559
     2560  if ( lphModule == NULL )
     2561        cb = 0;
     2562
     2563  if ( lpcbNeeded != NULL )
     2564       *lpcbNeeded = 0;
     2565 
     2566  count = 0;
     2567  countMax = cb / sizeof(HMODULE);
     2568
     2569  count = Win32DllBase::enumDlls(lphModule, countMax);
     2570   
     2571  if ( lpcbNeeded != NULL )
     2572     *lpcbNeeded = sizeof(HMODULE) * count;
     2573
     2574  return TRUE;
     2575}
     2576//******************************************************************************
     2577// Forwarder for PSAPI.DLL
     2578//
     2579// Returns some information about the module identified by hModule
     2580//
     2581//******************************************************************************
     2582BOOL WINAPI PSAPI_GetModuleInformation(HANDLE hProcess, HMODULE hModule,
     2583                                       LPMODULEINFO lpmodinfo, DWORD cb)
     2584{
     2585    BOOL ret = FALSE;
     2586    Win32DllBase *winmod = NULL;
     2587
     2588    dprintf(("KERNEL32: GetModuleInformation hModule=%x", hModule));
     2589 
     2590    if (!lpmodinfo || cb < sizeof(MODULEINFO)) return FALSE;
     2591
     2592    winmod = Win32DllBase::findModule((HINSTANCE)hModule);
     2593    if (!winmod) {
     2594        dprintf(("GetModuleInformation failed to find module"));
     2595        return FALSE;
     2596    }
     2597
     2598    lpmodinfo->SizeOfImage = winmod->getImageSize();
     2599    lpmodinfo->EntryPoint  = winmod->getEntryPoint();
     2600    lpmodinfo->lpBaseOfDll = (void*)hModule;
     2601
     2602    return TRUE;
     2603}
     2604//******************************************************************************
     2605//******************************************************************************
    25122606/**
    25132607 * Gets the startup info which was passed to CreateProcess when
Note: See TracChangeset for help on using the changeset viewer.