Changeset 10398 for trunk/src/kernel32/wprocess.cpp
- Timestamp:
- Jan 15, 2004, 11:41:39 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/wprocess.cpp
r10380 r10398 1 /* $Id: wprocess.cpp,v 1.19 0 2004-01-11 12:12:34sandervl Exp $ */1 /* $Id: wprocess.cpp,v 1.191 2004-01-15 10:41:39 sandervl Exp $ */ 2 2 3 3 /* … … 6 6 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl) 7 7 * Copyright 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no) 8 * Copyright 2003 Innotek Systemberatung GmbH (sandervl@innotek.de) 9 * 8 10 * 9 11 * NOTE: Even though Odin32 OS/2 apps don't switch FS selectors, … … 50 52 51 53 #include <win\ntddk.h> 54 #include <win\psapi.h> 52 55 53 56 #include <custombuild.h> … … 64 67 ODINDEBUGCHANNEL(KERNEL32-WPROCESS) 65 68 69 70 //environ.cpp 71 char *CreateNewEnvironment(char *lpEnvironment); 66 72 67 73 /******************************************************************************* … … 268 274 269 275 ProcessPDB.unknown10 = (PVOID)&unknownPDBData[0]; 270 271 276 //initialize the startup info part of the db entry. 272 ////O32_GetStartupInfo(&StartupInfo);277 O32_GetStartupInfo(&StartupInfo); 273 278 StartupInfo.cb = sizeof(StartupInfo); 274 279 /* Set some defaults as GetStartupInfo() used to set... */ … … 282 287 if (!StartupInfo.lpTitle) 283 288 StartupInfo.lpTitle = "Title"; 284 285 289 ProcessENVDB.hStdin = StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); 286 290 ProcessENVDB.hStdout = StartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); … … 530 534 fExitProcess = TRUE; 531 535 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 532 550 HMDeviceCommClass::CloseOverlappedIOHandlers(); 533 551 … … 556 574 while(teb) { 557 575 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); 563 584 } 564 585 teb = teb->o.odin.next; … … 1575 1596 } 1576 1597 1577 dprintf(("KERNEL32: GetCommandLineW: % s\n", pszCmdLineA));1598 dprintf(("KERNEL32: GetCommandLineW: %ls\n", pszCmdLineW)); 1578 1599 return pszCmdLineW; 1579 1600 } … … 1855 1876 LPCSTR pszNELoader) 1856 1877 { 1878 if(pszPECmdLoader) dprintf(("PE Cmd %s", pszPECmdLoader)); 1879 if(pszPEGUILoader) dprintf(("PE GUI %s", pszPEGUILoader)); 1880 if(pszNELoader) dprintf(("NE %s", pszNELoader)); 1857 1881 if(pszPECmdLoader) strcpy(szPECmdLoader, pszPECmdLoader); 1858 1882 if(pszPEGUILoader) strcpy(szPEGUILoader, pszPEGUILoader); … … 1885 1909 STARTUPINFOA startinfo; 1886 1910 TEB *pThreadDB = (TEB*)GetThreadTEB(); 1887 char *cmdline = NULL ;1911 char *cmdline = NULL, *newenv = NULL; 1888 1912 BOOL rc; 1889 1913 … … 1892 1916 lpEnvironment, lpCurrentDirectory, lpStartupInfo)); 1893 1917 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 } 1894 1927 #ifdef DEBUG 1895 1928 if(lpStartupInfo) { … … 1924 1957 if(retcode) { 1925 1958 SetLastError(ERROR_INVALID_HANDLE); 1926 return FALSE; 1959 rc = FALSE; 1960 goto finished; 1927 1961 } 1928 1962 … … 2009 2043 dprintf(("CreateProcess: can't find executable!")); 2010 2044 2011 if(cmdline)2012 free(cmdline);2013 2014 2045 SetLastError(ERROR_FILE_NOT_FOUND); 2015 return FALSE; 2046 2047 rc = FALSE; 2048 goto finished; 2016 2049 } 2017 2050 … … 2052 2085 } 2053 2086 2054 if(cmdline) 2055 free(cmdline); 2056 return(TRUE); 2087 rc = TRUE; 2088 goto finished; 2057 2089 } 2058 2090 … … 2068 2100 2069 2101 // the current value of GetLastError() is still valid. 2070 if(cmdline) 2071 free(cmdline); 2072 2073 return FALSE; 2102 rc = FALSE; 2103 goto finished; 2074 2104 } 2075 2105 } … … 2190 2220 pThreadDB->o.odin.pidDebuggee = 0; 2191 2221 } 2192 if(cmdline)2193 free(cmdline);2194 2195 2222 if(lpProcessInfo) 2196 2223 { … … 2202 2229 else 2203 2230 dprintf(("KERNEL32: CreateProcess returned %d\n", rc)); 2231 2232 finished: 2233 2234 if(cmdline) free(cmdline); 2235 if(newenv) free(newenv); 2204 2236 return(rc); 2205 2237 } … … 2365 2397 { 2366 2398 Win32ImageBase *winmod; 2367 FARPROC proc ;2399 FARPROC proc = 0; 2368 2400 ULONG ulAPIOrdinal; 2369 2401 … … 2378 2410 proc = (FARPROC)winmod->getApi((int)ulAPIOrdinal); 2379 2411 } 2380 else proc = (FARPROC)winmod->getApi((char *)lpszProc); 2412 else 2413 if (lpszProc && *lpszProc) { 2414 proc = (FARPROC)winmod->getApi((char *)lpszProc); 2415 } 2381 2416 if(proc == 0) { 2382 2417 #ifdef DEBUG … … 2387 2422 #endif 2388 2423 SetLastError(ERROR_PROC_NOT_FOUND); 2424 return 0; 2389 2425 } 2390 2426 if(HIWORD(lpszProc)) … … 2440 2476 #endif 2441 2477 SetLastError(ERROR_PROC_NOT_FOUND); 2478 return (FARPROC)-1; 2442 2479 } 2443 2480 if(HIWORD(lpszProc)) … … 2507 2544 } 2508 2545 //****************************************************************************** 2509 //****************************************************************************** 2510 2511 2546 // Forwarder for PSAPI.DLL 2547 // 2548 // Returns the handles of all loaded modules 2549 // 2550 //****************************************************************************** 2551 BOOL 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 //****************************************************************************** 2582 BOOL 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 //****************************************************************************** 2512 2606 /** 2513 2607 * Gets the startup info which was passed to CreateProcess when
Note:
See TracChangeset
for help on using the changeset viewer.