Commit fbea5308 authored by Ulrich Weigand's avatar Ulrich Weigand Committed by Alexandre Julliard

On NE process creation, move major part of NE EXE module loading and

NE instance creation into the child process.
parent 3922ca74
...@@ -202,11 +202,12 @@ extern FARPROC16 NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal ); ...@@ -202,11 +202,12 @@ extern FARPROC16 NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop ); extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset ); extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
extern HANDLE NE_OpenFile( NE_MODULE *pModule ); extern HANDLE NE_OpenFile( NE_MODULE *pModule );
extern HINSTANCE16 MODULE_LoadModule16( LPCSTR name, BOOL implicit );
extern BOOL NE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line, LPCSTR env, extern BOOL NE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line, LPCSTR env,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa, LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags, LPSTARTUPINFOA startup, BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
LPPROCESS_INFORMATION info ); LPPROCESS_INFORMATION info );
extern BOOL NE_InitProcess( NE_MODULE *pModule );
/* loader/ne/resource.c */ /* loader/ne/resource.c */
extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16); extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
......
...@@ -95,8 +95,6 @@ typedef struct _PDB ...@@ -95,8 +95,6 @@ typedef struct _PDB
HANDLE *dos_handles; /* Handles mapping DOS -> Win32 */ HANDLE *dos_handles; /* Handles mapping DOS -> Win32 */
struct _PDB *next; /* List reference - list of PDB's */ struct _PDB *next; /* List reference - list of PDB's */
WORD winver; /* Windows version figured out by VERSION_GetVersion */ WORD winver; /* Windows version figured out by VERSION_GetVersion */
WORD hInstance; /* hInstance on startup */
WORD hPrevInstance; /* hPrevInstance on startup */
struct _SERVICETABLE *service_table; /* Service table for service thread */ struct _SERVICETABLE *service_table; /* Service table for service thread */
} PDB; } PDB;
...@@ -161,7 +159,6 @@ extern PDB *PROCESS_IdToPDB( DWORD id ); ...@@ -161,7 +159,6 @@ extern PDB *PROCESS_IdToPDB( DWORD id );
extern void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule ); extern void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule );
extern PDB *PROCESS_Create( struct _NE_MODULE *pModule, extern PDB *PROCESS_Create( struct _NE_MODULE *pModule,
LPCSTR cmd_line, LPCSTR env, LPCSTR cmd_line, LPCSTR env,
HINSTANCE16 hInstance, HINSTANCE16 hPrevInstance,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa, LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags, BOOL inherit, DWORD flags,
STARTUPINFOA *startup, PROCESS_INFORMATION *info ); STARTUPINFOA *startup, PROCESS_INFORMATION *info );
......
...@@ -146,9 +146,7 @@ typedef struct _THHOOK ...@@ -146,9 +146,7 @@ typedef struct _THHOOK
extern THHOOK *pThhook; extern THHOOK *pThhook;
extern void (*TASK_AddTaskEntryBreakpoint)( HTASK16 hTask ); extern void (*TASK_AddTaskEntryBreakpoint)( HTASK16 hTask );
extern BOOL TASK_Create( struct _NE_MODULE *pModule, extern BOOL TASK_Create( struct _NE_MODULE *pModule, UINT16 cmdShow );
HINSTANCE16 hInstance, HINSTANCE16 hPrevInstance,
UINT16 cmdShow );
extern void TASK_KillTask( HTASK16 hTask ); extern void TASK_KillTask( HTASK16 hTask );
extern HTASK16 TASK_GetNextTask( HTASK16 hTask ); extern HTASK16 TASK_GetNextTask( HTASK16 hTask );
extern void TASK_Reschedule(void); extern void TASK_Reschedule(void);
......
...@@ -498,7 +498,7 @@ BOOL MZ_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline, LPCSTR env, ...@@ -498,7 +498,7 @@ BOOL MZ_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline, LPCSTR env,
return FALSE; return FALSE;
} }
inherit = TRUE; /* bad hack for inheriting the CreatePipe... */ inherit = TRUE; /* bad hack for inheriting the CreatePipe... */
if (!PROCESS_Create( pModule, cmdline, env, 0, 0, if (!PROCESS_Create( pModule, cmdline, env,
psa, tsa, inherit, flags, startup, info )) psa, tsa, inherit, flags, startup, info ))
return FALSE; return FALSE;
} }
......
...@@ -309,7 +309,7 @@ HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] ) ...@@ -309,7 +309,7 @@ HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] )
pModule->flags = NE_FFLAGS_WIN32; pModule->flags = NE_FFLAGS_WIN32;
pModule->module32 = wm->module; pModule->module32 = wm->module;
if (!TASK_Create( pModule, 0, 0, FALSE )) return 0; if (!TASK_Create( pModule, FALSE )) return 0;
/* Initialize GDI and USER */ /* Initialize GDI and USER */
if (!LoadLibraryA( "GDI32.DLL" )) return 0; if (!LoadLibraryA( "GDI32.DLL" )) return 0;
......
...@@ -984,7 +984,7 @@ BOOL PE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line, LPCSTR env, ...@@ -984,7 +984,7 @@ BOOL PE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line, LPCSTR env,
/* Create new process */ /* Create new process */
if ( !PROCESS_Create( pModule, cmd_line, env, if ( !PROCESS_Create( pModule, cmd_line, env,
0, 0, psa, tsa, inherit, flags, startup, info ) ) psa, tsa, inherit, flags, startup, info ) )
return FALSE; return FALSE;
/* Note: PE_CreateModule and the remaining process initialization will /* Note: PE_CreateModule and the remaining process initialization will
......
...@@ -275,16 +275,13 @@ void TASK_CallToStart(void) ...@@ -275,16 +275,13 @@ void TASK_CallToStart(void)
* by entering the Win16Lock while linking the task into the * by entering the Win16Lock while linking the task into the
* global task list. * global task list.
*/ */
BOOL TASK_Create( NE_MODULE *pModule, HINSTANCE16 hInstance, BOOL TASK_Create( NE_MODULE *pModule, UINT16 cmdShow)
HINSTANCE16 hPrevInstance, UINT16 cmdShow)
{ {
HTASK16 hTask; HTASK16 hTask;
TDB *pTask; TDB *pTask;
LPSTR cmd_line; LPSTR cmd_line;
WORD sp;
char name[10]; char name[10];
PDB *pdb32 = PROCESS_Current(); PDB *pdb32 = PROCESS_Current();
SEGTABLEENTRY *pSegTable = NE_SEG_TABLE( pModule );
/* Allocate the task structure */ /* Allocate the task structure */
...@@ -304,9 +301,12 @@ BOOL TASK_Create( NE_MODULE *pModule, HINSTANCE16 hInstance, ...@@ -304,9 +301,12 @@ BOOL TASK_Create( NE_MODULE *pModule, HINSTANCE16 hInstance,
if (pModule->lpDosTask) if (pModule->lpDosTask)
pTask->flags |= TDBF_WINOLDAP; pTask->flags |= TDBF_WINOLDAP;
pTask->hInstance = pModule->self;
pTask->hPrevInstance = 0;
/* NOTE: for 16-bit tasks, the instance handles are updated later on
in NE_InitProcess */
pTask->version = pModule->expected_version; pTask->version = pModule->expected_version;
pTask->hInstance = hInstance? hInstance : pModule->self;
pTask->hPrevInstance = hPrevInstance;
pTask->hModule = pModule->self; pTask->hModule = pModule->self;
pTask->hParent = GetCurrentTask(); pTask->hParent = GetCurrentTask();
pTask->magic = TDB_MAGIC; pTask->magic = TDB_MAGIC;
...@@ -388,16 +388,6 @@ BOOL TASK_Create( NE_MODULE *pModule, HINSTANCE16 hInstance, ...@@ -388,16 +388,6 @@ BOOL TASK_Create( NE_MODULE *pModule, HINSTANCE16 hInstance,
pTask->teb->htask16 = pTask->teb->process->task = hTask; pTask->teb->htask16 = pTask->teb->process->task = hTask;
TRACE_(task)("module='%s' cmdline='%s' task=%04x\n", name, cmd_line, hTask ); TRACE_(task)("module='%s' cmdline='%s' task=%04x\n", name, cmd_line, hTask );
/* If we have a DGROUP/hInstance, use it for 16-bit stack */
if ( hInstance )
{
if (!(sp = pModule->sp))
sp = pSegTable[pModule->ss-1].minsize + pModule->stack_size;
sp &= ~1; sp -= sizeof(STACK16FRAME);
pTask->teb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( hInstance, sp );
}
/* If requested, add entry point breakpoint */ /* If requested, add entry point breakpoint */
if ( TASK_AddTaskEntryBreakpoint ) if ( TASK_AddTaskEntryBreakpoint )
......
...@@ -168,7 +168,7 @@ int main( int argc, char *argv[] ) ...@@ -168,7 +168,7 @@ int main( int argc, char *argv[] )
/* Create initial task */ /* Create initial task */
if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1; if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
if ( !TASK_Create( pModule, 0, 0, FALSE ) ) return 1; if ( !TASK_Create( pModule, FALSE ) ) return 1;
/* Switch to initial task */ /* Switch to initial task */
PostEvent16( PROCESS_Current()->task ); PostEvent16( PROCESS_Current()->task );
......
...@@ -411,9 +411,14 @@ void PROCESS_Start(void) ...@@ -411,9 +411,14 @@ void PROCESS_Start(void)
/* Create a task for this process */ /* Create a task for this process */
if (pdb->env_db->startup_info->dwFlags & STARTF_USESHOWWINDOW) if (pdb->env_db->startup_info->dwFlags & STARTF_USESHOWWINDOW)
cmdShow = pdb->env_db->startup_info->wShowWindow; cmdShow = pdb->env_db->startup_info->wShowWindow;
if (!TASK_Create( pModule, pdb->hInstance, pdb->hPrevInstance, cmdShow )) if (!TASK_Create( pModule, cmdShow ))
goto error; goto error;
/* Perform Win16 specific process initialization */
if ( type == PROC_WIN16 )
if ( !NE_InitProcess( pModule ) )
goto error;
/* Note: The USIG_PROCESS_CREATE signal is supposed to be sent in the /* Note: The USIG_PROCESS_CREATE signal is supposed to be sent in the
* context of the parent process. Actually, the USER signal proc * context of the parent process. Actually, the USER signal proc
* doesn't really care about that, but it *does* require that the * doesn't really care about that, but it *does* require that the
...@@ -502,13 +507,13 @@ void PROCESS_Start(void) ...@@ -502,13 +507,13 @@ void PROCESS_Start(void)
* Create a new process database and associated info. * Create a new process database and associated info.
*/ */
PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env, PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
HINSTANCE16 hInstance, HINSTANCE16 hPrevInstance,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa, LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags, STARTUPINFOA *startup, BOOL inherit, DWORD flags, STARTUPINFOA *startup,
PROCESS_INFORMATION *info ) PROCESS_INFORMATION *info )
{ {
HANDLE handles[2], load_done_evt = INVALID_HANDLE_VALUE; HANDLE handles[2], load_done_evt = INVALID_HANDLE_VALUE;
DWORD exitcode, size; DWORD exitcode, size;
BOOL alloc_stack16;
int server_thandle; int server_thandle;
struct new_process_request *req = get_req_buffer(); struct new_process_request *req = get_req_buffer();
TEB *teb = NULL; TEB *teb = NULL;
...@@ -554,21 +559,24 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env, ...@@ -554,21 +559,24 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
size = header->SizeOfStackReserve; size = header->SizeOfStackReserve;
if (header->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI) if (header->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
pdb->flags |= PDB32_CONSOLE_PROC; pdb->flags |= PDB32_CONSOLE_PROC;
alloc_stack16 = TRUE;
} }
else if (!pModule->dos_image) /* Win16 process */ else if (!pModule->dos_image) /* Win16 process */
{ {
alloc_stack16 = FALSE;
size = 0; size = 0;
pdb->flags |= PDB32_WIN16_PROC; pdb->flags |= PDB32_WIN16_PROC;
} }
else /* DOS process */ else /* DOS process */
{ {
alloc_stack16 = FALSE;
size = 0; size = 0;
pdb->flags |= PDB32_DOS_PROC; pdb->flags |= PDB32_DOS_PROC;
} }
/* Create the main thread */ /* Create the main thread */
if (!(teb = THREAD_Create( pdb, 0L, size, hInstance == 0, tsa, &server_thandle ))) if (!(teb = THREAD_Create( pdb, 0L, size, alloc_stack16, tsa, &server_thandle )))
goto error; goto error;
info->hThread = server_thandle; info->hThread = server_thandle;
info->dwThreadId = (DWORD)teb->tid; info->dwThreadId = (DWORD)teb->tid;
...@@ -579,10 +587,8 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env, ...@@ -579,10 +587,8 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
DuplicateHandle( GetCurrentProcess(), load_done_evt, DuplicateHandle( GetCurrentProcess(), load_done_evt,
info->hProcess, &pdb->load_done_evt, 0, TRUE, DUPLICATE_SAME_ACCESS ); info->hProcess, &pdb->load_done_evt, 0, TRUE, DUPLICATE_SAME_ACCESS );
/* Pass module/instance to new process (FIXME: hack) */ /* Pass module to new process (FIXME: hack) */
pdb->module = pModule->self; pdb->module = pModule->self;
pdb->hInstance = hInstance;
pdb->hPrevInstance = hPrevInstance;
SYSDEPS_SpawnThread( teb ); SYSDEPS_SpawnThread( teb );
/* Wait until process is initialized (or initialization failed) */ /* Wait until process is initialized (or initialization failed) */
......
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