Commit f8e741bc authored by Alexandre Julliard's avatar Alexandre Julliard

Take into account handle inheritance flag.

parent 50629f03
......@@ -48,7 +48,7 @@ extern BOOL32 (*instr_emu_call)( SIGCONTEXT* );
extern void MZ_Tick( WORD handle );
extern HINSTANCE16 MZ_CreateProcess( LPCSTR name, LPCSTR cmdline, LPCSTR env,
extern HINSTANCE16 MZ_CreateProcess( LPCSTR name, LPCSTR cmdline, LPCSTR env, BOOL32 inherit,
LPSTARTUPINFO32A startup, LPPROCESS_INFORMATION info );
extern int DOSVM_Enter( PCONTEXT context );
......
......@@ -162,7 +162,7 @@ extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
extern FARPROC16 NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
extern int NE_OpenFile( NE_MODULE *pModule );
extern HANDLE32 NE_OpenFile( NE_MODULE *pModule );
extern HINSTANCE16 NE_LoadModule( LPCSTR name, HINSTANCE16 *hPrevInstance,
BOOL32 implicit, BOOL32 lib_only );
......
......@@ -39,7 +39,7 @@ extern DWORD PE_SizeofResource32(HMODULE32,HRSRC32);
extern HMODULE32 PE_LoadLibraryEx32A(LPCSTR,struct _PDB32*,HFILE32,DWORD);
extern HGLOBAL32 PE_LoadResource32(struct _wine_modref *wm,HRSRC32);
extern HINSTANCE16 PE_CreateProcess( LPCSTR name, LPCSTR cmd_line,
LPCSTR env, LPSTARTUPINFO32A startup,
LPCSTR env, BOOL32 inherit, LPSTARTUPINFO32A startup,
LPPROCESS_INFORMATION info );
struct _THDB; /* forward definition */
......
......@@ -157,8 +157,8 @@ extern PDB32 *PROCESS_GetPtr( HANDLE32 handle, DWORD access, int *server_handle
extern PDB32 *PROCESS_IdToPDB( DWORD id );
extern PDB32 *PROCESS_Create( struct _NE_MODULE *pModule, LPCSTR cmd_line,
LPCSTR env, HINSTANCE16 hInstance,
HINSTANCE16 hPrevInstance, STARTUPINFO32A *startup,
PROCESS_INFORMATION *info );
HINSTANCE16 hPrevInstance, BOOL32 inherit,
STARTUPINFO32A *startup, PROCESS_INFORMATION *info );
extern void PROCESS_SuspendOtherThreads(void);
extern void PROCESS_ResumeOtherThreads(void);
extern int PROCESS_PDBList_Getsize (void);
......
......@@ -411,7 +411,7 @@ int MZ_InitTask( LPDOSTASK lpDosTask )
return lpDosTask->hModule;
}
HINSTANCE16 MZ_CreateProcess( LPCSTR name, LPCSTR cmdline, LPCSTR env,
HINSTANCE16 MZ_CreateProcess( LPCSTR name, LPCSTR cmdline, LPCSTR env, BOOL32 inherit,
LPSTARTUPINFO32A startup, LPPROCESS_INFORMATION info )
{
LPDOSTASK lpDosTask = NULL; /* keep gcc from complaining */
......@@ -465,7 +465,7 @@ HINSTANCE16 MZ_CreateProcess( LPCSTR name, LPCSTR cmdline, LPCSTR env,
}
hInstance = NE_CreateInstance(pModule, NULL, (cmdline == NULL));
PROCESS_Create( pModule, cmdline, env, hInstance, 0, startup, info );
PROCESS_Create( pModule, cmdline, env, hInstance, 0, inherit, startup, info );
return hInstance;
} else {
return (err<32) ? err : pTask->hInstance;
......
......@@ -407,7 +407,7 @@ HMODULE32 MODULE_FindModule32(
* NE_CreateProcess
*/
static HINSTANCE16 NE_CreateProcess( LPCSTR name, LPCSTR cmd_line, LPCSTR env,
LPSTARTUPINFO32A startup,
BOOL32 inherit, LPSTARTUPINFO32A startup,
LPPROCESS_INFORMATION info )
{
HINSTANCE16 hInstance, hPrevInstance;
......@@ -430,7 +430,7 @@ static HINSTANCE16 NE_CreateProcess( LPCSTR name, LPCSTR cmd_line, LPCSTR env,
pModule->flags |= NE_FFLAGS_GUI; /* FIXME: is this necessary? */
PROCESS_Create( pModule, cmd_line, env, hInstance,
hPrevInstance, startup, info );
hPrevInstance, inherit, startup, info );
return hInstance;
}
......@@ -488,7 +488,7 @@ HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
}
pdb = PROCESS_Create( pModule, new_cmd_line, env,
hInstance, hPrevInstance, &startup, &info );
hInstance, hPrevInstance, TRUE, &startup, &info );
CloseHandle( info.hThread );
CloseHandle( info.hProcess );
......@@ -605,8 +605,6 @@ BOOL32 WINAPI CreateProcess32A( LPCSTR lpApplicationName, LPSTR lpCommandLine,
FIXME(module, "(%s,...): lpProcessAttributes ignored\n", name);
if (lpThreadAttributes)
FIXME(module, "(%s,...): lpThreadAttributes ignored\n", name);
if (bInheritHandles)
FIXME(module, "(%s,...): bInheritHandles ignored\n", name);
if (dwCreationFlags & DEBUG_PROCESS)
FIXME(module, "(%s,...): DEBUG_PROCESS ignored\n", name);
if (dwCreationFlags & DEBUG_ONLY_THIS_PROCESS)
......@@ -669,17 +667,17 @@ BOOL32 WINAPI CreateProcess32A( LPCSTR lpApplicationName, LPSTR lpCommandLine,
/* Try NE module */
hInstance = NE_CreateProcess( name, cmdline, lpEnvironment,
hInstance = NE_CreateProcess( name, cmdline, lpEnvironment, bInheritHandles,
lpStartupInfo, lpProcessInfo );
/* Try PE module */
if (hInstance == 21)
hInstance = PE_CreateProcess( name, cmdline, lpEnvironment,
hInstance = PE_CreateProcess( name, cmdline, lpEnvironment, bInheritHandles,
lpStartupInfo, lpProcessInfo );
/* Try DOS module */
if (hInstance == 11)
hInstance = MZ_CreateProcess( name, cmdline, lpEnvironment,
hInstance = MZ_CreateProcess( name, cmdline, lpEnvironment, bInheritHandles,
lpStartupInfo, lpProcessInfo );
if (hInstance < 32)
......
......@@ -852,7 +852,7 @@ HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, PDB32 *process,
* due to the PROCESS_Create stuff.
*/
HINSTANCE16 PE_CreateProcess( LPCSTR name, LPCSTR cmd_line,
LPCSTR env, LPSTARTUPINFO32A startup,
LPCSTR env, BOOL32 inherit, LPSTARTUPINFO32A startup,
LPPROCESS_INFORMATION info )
{
HMODULE16 hModule16;
......@@ -879,7 +879,7 @@ HINSTANCE16 PE_CreateProcess( LPCSTR name, LPCSTR cmd_line,
/* Create new process */
hInstance = NE_CreateInstance( pModule, NULL, FALSE );
process = PROCESS_Create( pModule, cmd_line, env,
hInstance, 0, startup, info );
hInstance, 0, inherit, startup, info );
/* Create 32-bit MODREF */
if ( !(wm = PE_CreateModule( process, hModule32, &ofs, 0, FALSE )) )
......
......@@ -129,7 +129,7 @@ static BOOL32 PROCESS_BuildEnvDB( PDB32 *pdb )
* PROCESS_InheritEnvDB
*/
static BOOL32 PROCESS_InheritEnvDB( PDB32 *pdb, LPCSTR cmd_line, LPCSTR env,
STARTUPINFO32A *startup )
BOOL32 inherit_handles, STARTUPINFO32A *startup )
{
if (!(pdb->env_db = HeapAlloc(pdb->heap, HEAP_ZERO_MEMORY, sizeof(ENVDB))))
return FALSE;
......@@ -157,12 +157,13 @@ static BOOL32 PROCESS_InheritEnvDB( PDB32 *pdb, LPCSTR cmd_line, LPCSTR env,
pdb->env_db->hStdout = pdb->env_db->startup_info->hStdOutput;
pdb->env_db->hStderr = pdb->env_db->startup_info->hStdError;
}
else
else if (inherit_handles)
{
pdb->env_db->hStdin = pdb->parent->env_db->hStdin;
pdb->env_db->hStdout = pdb->parent->env_db->hStdout;
pdb->env_db->hStderr = pdb->parent->env_db->hStderr;
}
/* else will be done later on in PROCESS_Create */
return TRUE;
}
......@@ -296,7 +297,7 @@ static void PROCESS_FreePDB( PDB32 *pdb )
* Allocate and fill a PDB structure.
* Runs in the context of the parent process.
*/
static PDB32 *PROCESS_CreatePDB( PDB32 *parent )
static PDB32 *PROCESS_CreatePDB( PDB32 *parent, BOOL32 inherit )
{
PDB32 *pdb = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, sizeof(PDB32) );
......@@ -315,7 +316,7 @@ static PDB32 *PROCESS_CreatePDB( PDB32 *parent )
/* Create the handle table */
if (!HANDLE_CreateTable( pdb, TRUE )) goto error;
if (!HANDLE_CreateTable( pdb, inherit )) goto error;
PROCESS_PDBList_Insert (pdb);
return pdb;
......@@ -356,7 +357,7 @@ BOOL32 PROCESS_Init(void)
if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return FALSE;
/* Create the initial process and thread structures */
if (!(pdb = PROCESS_CreatePDB( NULL ))) return FALSE;
if (!(pdb = PROCESS_CreatePDB( NULL, FALSE ))) return FALSE;
if (!(thdb = THREAD_Create( pdb, 0, FALSE, NULL, NULL, NULL, NULL ))) return FALSE;
thdb->unix_pid = getpid();
......@@ -386,14 +387,15 @@ BOOL32 PROCESS_Init(void)
*/
PDB32 *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
HINSTANCE16 hInstance, HINSTANCE16 hPrevInstance,
STARTUPINFO32A *startup, PROCESS_INFORMATION *info )
BOOL32 inherit, STARTUPINFO32A *startup,
PROCESS_INFORMATION *info )
{
DWORD size, commit;
int server_thandle, server_phandle;
UINT32 cmdShow = 0;
THDB *thdb = NULL;
PDB32 *parent = PROCESS_Current();
PDB32 *pdb = PROCESS_CreatePDB( parent );
PDB32 *pdb = PROCESS_CreatePDB( parent, inherit );
TDB *pTask;
if (!pdb) return NULL;
......@@ -418,7 +420,7 @@ PDB32 *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
/* Inherit the env DB from the parent */
if (!PROCESS_InheritEnvDB( pdb, cmd_line, env, startup )) goto error;
if (!PROCESS_InheritEnvDB( pdb, cmd_line, env, inherit, startup )) goto error;
/* Create the main thread */
......@@ -446,6 +448,18 @@ PDB32 *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
thdb->unix_pid = pTask? pTask->thdb->unix_pid : THREAD_Current()->unix_pid;
#endif
/* Duplicate the standard handles */
if ((!(pdb->env_db->startup_info->dwFlags & STARTF_USESTDHANDLES)) && !inherit)
{
DuplicateHandle( GetCurrentProcess(), pdb->parent->env_db->hStdin,
info->hProcess, &pdb->env_db->hStdin, 0, TRUE, DUPLICATE_SAME_ACCESS );
DuplicateHandle( GetCurrentProcess(), pdb->parent->env_db->hStdout,
info->hProcess, &pdb->env_db->hStdout, 0, TRUE, DUPLICATE_SAME_ACCESS );
DuplicateHandle( GetCurrentProcess(), pdb->parent->env_db->hStderr,
info->hProcess, &pdb->env_db->hStderr, 0, TRUE, DUPLICATE_SAME_ACCESS );
}
/* Create a Win16 task for this process */
if (startup->dwFlags & STARTF_USESHOWWINDOW)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment