Commit 6e0d3860 authored by Ulrich Weigand's avatar Ulrich Weigand Committed by Alexandre Julliard

Process creation sequence reorganized:

- Removed instance data segment for all but NE modules. - Check binary type in CreateProcess before loading module. - Unix process creation moved from WinExec to CreateProcess. - Bugfix: fill in thdb->teb.htask16 member correctly.
parent 38d9ce81
...@@ -163,8 +163,10 @@ extern FARPROC16 NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal ); ...@@ -163,8 +163,10 @@ 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 NE_LoadModule( LPCSTR name, HINSTANCE16 *hPrevInstance, extern HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL implicit );
BOOL implicit, BOOL lib_only ); extern BOOL NE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line,
LPCSTR env, BOOL inherit, LPSTARTUPINFOA startup,
LPPROCESS_INFORMATION info );
/* loader/ne/resource.c */ /* loader/ne/resource.c */
extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16); extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
......
...@@ -146,7 +146,7 @@ typedef struct _THHOOK ...@@ -146,7 +146,7 @@ typedef struct _THHOOK
extern THHOOK *pThhook; extern THHOOK *pThhook;
extern void (*TASK_AddTaskEntryBreakpoint)( HTASK16 hTask ); extern void (*TASK_AddTaskEntryBreakpoint)( HTASK16 hTask );
extern HTASK16 TASK_Create( struct _THDB *thdb, struct _NE_MODULE *pModule, extern BOOL TASK_Create( struct _THDB *thdb, struct _NE_MODULE *pModule,
HINSTANCE16 hInstance, HINSTANCE16 hPrevInstance, HINSTANCE16 hInstance, HINSTANCE16 hPrevInstance,
UINT16 cmdShow ); UINT16 cmdShow );
extern void TASK_StartTask( HTASK16 hTask ); extern void TASK_StartTask( HTASK16 hTask );
......
...@@ -259,9 +259,6 @@ static void TASK_CallToStart(void) ...@@ -259,9 +259,6 @@ static void TASK_CallToStart(void)
if (PE_HEADER(pModule->module32)->OptionalHeader.Subsystem==IMAGE_SUBSYSTEM_WINDOWS_CUI) if (PE_HEADER(pModule->module32)->OptionalHeader.Subsystem==IMAGE_SUBSYSTEM_WINDOWS_CUI)
AllocConsole(); AllocConsole();
if (pModule->heap_size)
LocalInit16( pTask->hInstance, 0, pModule->heap_size );
MODULE_InitializeDLLs( 0, DLL_PROCESS_ATTACH, (LPVOID)-1 ); MODULE_InitializeDLLs( 0, DLL_PROCESS_ATTACH, (LPVOID)-1 );
TRACE(relay, "(entryproc=%p)\n", entry ); TRACE(relay, "(entryproc=%p)\n", entry );
...@@ -336,7 +333,7 @@ static void TASK_CallToStart(void) ...@@ -336,7 +333,7 @@ static void TASK_CallToStart(void)
* any real problems with that, since we operated merely on a private * any real problems with that, since we operated merely on a private
* TDB structure that is not yet linked into the task list. * TDB structure that is not yet linked into the task list.
*/ */
HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance, BOOL TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance,
HINSTANCE16 hPrevInstance, UINT16 cmdShow) HINSTANCE16 hPrevInstance, UINT16 cmdShow)
{ {
HTASK16 hTask; HTASK16 hTask;
...@@ -354,7 +351,7 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance, ...@@ -354,7 +351,7 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance,
hTask = GLOBAL_Alloc( GMEM_FIXED | GMEM_ZEROINIT, sizeof(TDB), hTask = GLOBAL_Alloc( GMEM_FIXED | GMEM_ZEROINIT, sizeof(TDB),
pModule->self, FALSE, FALSE, FALSE ); pModule->self, FALSE, FALSE, FALSE );
if (!hTask) return 0; if (!hTask) return FALSE;
pTask = (TDB *)GlobalLock16( hTask ); pTask = (TDB *)GlobalLock16( hTask );
/* Fill the task structure */ /* Fill the task structure */
...@@ -369,7 +366,7 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance, ...@@ -369,7 +366,7 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance,
pTask->flags |= TDBF_WINOLDAP; pTask->flags |= TDBF_WINOLDAP;
pTask->version = pModule->expected_version; pTask->version = pModule->expected_version;
pTask->hInstance = hInstance; pTask->hInstance = hInstance? hInstance : pModule->self;
pTask->hPrevInstance = hPrevInstance; pTask->hPrevInstance = hPrevInstance;
pTask->hModule = pModule->self; pTask->hModule = pModule->self;
pTask->hParent = GetCurrentTask(); pTask->hParent = GetCurrentTask();
...@@ -445,16 +442,23 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance, ...@@ -445,16 +442,23 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance,
if ( pInitialTask ) if ( pInitialTask )
pTask->userhandler = pInitialTask->userhandler; pTask->userhandler = pInitialTask->userhandler;
/* Create the 16-bit stack frame */ /* If we have a DGROUP/hInstance, use it for 16-bit stack */
if ( hInstance )
{
if (!(sp = pModule->sp)) if (!(sp = pModule->sp))
sp = pSegTable[pModule->ss-1].minsize + pModule->stack_size; sp = pSegTable[pModule->ss-1].minsize + pModule->stack_size;
sp &= ~1; sp -= 2*sizeof(STACK16FRAME); sp &= ~1; sp -= sizeof(STACK16FRAME);
pTask->thdb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( pTask->hInstance, sp ); pTask->thdb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( hInstance, sp );
}
/* Create the 16-bit stack frame */
pTask->thdb->cur_stack -= sizeof(STACK16FRAME);
frame16 = (STACK16FRAME *)PTR_SEG_TO_LIN( pTask->thdb->cur_stack ); frame16 = (STACK16FRAME *)PTR_SEG_TO_LIN( pTask->thdb->cur_stack );
frame16->ebp = sp + (int)&((STACK16FRAME *)0)->bp; frame16->ebp = OFFSETOF( pTask->thdb->cur_stack ) + (int)&((STACK16FRAME *)0)->bp;
frame16->bp = LOWORD(frame16->ebp); frame16->bp = LOWORD(frame16->ebp);
frame16->ds = frame16->es = pTask->hInstance; frame16->ds = frame16->es = hInstance;
frame16->fs = 0; frame16->fs = 0;
frame16->entry_point = 0; frame16->entry_point = 0;
frame16->entry_cs = 0; frame16->entry_cs = 0;
...@@ -474,11 +478,14 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance, ...@@ -474,11 +478,14 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance,
frame32->retaddr = (DWORD)TASK_CallToStart; frame32->retaddr = (DWORD)TASK_CallToStart;
/* The remaining fields will be initialized in TASK_Reschedule */ /* The remaining fields will be initialized in TASK_Reschedule */
/* Enter task handle into thread and process */
pTask->thdb->teb.htask16 = pTask->thdb->process->task = hTask;
TRACE(task, "module='%s' cmdline='%s' task=%04x\n", TRACE(task, "module='%s' cmdline='%s' task=%04x\n",
name, cmd_line, hTask ); name, cmd_line, hTask );
return hTask; return TRUE;
} }
/*********************************************************************** /***********************************************************************
......
...@@ -420,7 +420,6 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env, ...@@ -420,7 +420,6 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
THDB *thdb = NULL; THDB *thdb = NULL;
PDB *parent = PROCESS_Current(); PDB *parent = PROCESS_Current();
PDB *pdb = PROCESS_CreatePDB( parent, inherit ); PDB *pdb = PROCESS_CreatePDB( parent, inherit );
TDB *pTask;
if (!pdb) return NULL; if (!pdb) return NULL;
info->hThread = info->hProcess = INVALID_HANDLE_VALUE; info->hThread = info->hProcess = INVALID_HANDLE_VALUE;
...@@ -452,8 +451,9 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env, ...@@ -452,8 +451,9 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
size = PE_HEADER(pModule->module32)->OptionalHeader.SizeOfStackReserve; size = PE_HEADER(pModule->module32)->OptionalHeader.SizeOfStackReserve;
else else
size = 0; size = 0;
if (!(thdb = THREAD_Create( pdb, size, FALSE, &server_thandle, &server_phandle, if (!(thdb = THREAD_Create( pdb, size, hInstance == 0,
NULL, NULL ))) goto error; &server_thandle, &server_phandle, NULL, NULL )))
goto error;
if ((info->hThread = HANDLE_Alloc( parent, &thdb->header, THREAD_ALL_ACCESS, if ((info->hThread = HANDLE_Alloc( parent, &thdb->header, THREAD_ALL_ACCESS,
FALSE, server_thandle )) == INVALID_HANDLE_VALUE) FALSE, server_thandle )) == INVALID_HANDLE_VALUE)
goto error; goto error;
...@@ -480,8 +480,8 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env, ...@@ -480,8 +480,8 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
if (startup->dwFlags & STARTF_USESHOWWINDOW) if (startup->dwFlags & STARTF_USESHOWWINDOW)
cmdShow = startup->wShowWindow; cmdShow = startup->wShowWindow;
pdb->task = TASK_Create( thdb, pModule, hInstance, hPrevInstance, cmdShow); if ( !TASK_Create( thdb, pModule, hInstance, hPrevInstance, cmdShow) )
if (!pdb->task) goto error; goto error;
/* Map system DLLs into this process (from initial process) */ /* Map system DLLs into this process (from initial process) */
......
...@@ -226,7 +226,7 @@ THDB *THREAD_CreateInitialThread( PDB *pdb ) ...@@ -226,7 +226,7 @@ THDB *THREAD_CreateInitialThread( PDB *pdb )
/* Now proceed with normal initialization */ /* Now proceed with normal initialization */
if (!THREAD_InitTHDB( &initial_thdb, 0, FALSE, NULL, NULL )) return NULL; if (!THREAD_InitTHDB( &initial_thdb, 0, TRUE, NULL, NULL )) return NULL;
return &initial_thdb; return &initial_thdb;
} }
...@@ -244,7 +244,7 @@ THDB *THREAD_Create( PDB *pdb, DWORD stack_size, BOOL alloc_stack16, ...@@ -244,7 +244,7 @@ THDB *THREAD_Create( PDB *pdb, DWORD stack_size, BOOL alloc_stack16,
thdb->header.refcount = 1; thdb->header.refcount = 1;
thdb->process = pdb; thdb->process = pdb;
thdb->teb.except = (void *)-1; thdb->teb.except = (void *)-1;
thdb->teb.htask16 = 0; /* FIXME */ thdb->teb.htask16 = pdb->task;
thdb->teb.self = &thdb->teb; thdb->teb.self = &thdb->teb;
thdb->teb.flags = (pdb->flags & PDB32_WIN16_PROC)? 0 : TEBF_WIN32; thdb->teb.flags = (pdb->flags & PDB32_WIN16_PROC)? 0 : TEBF_WIN32;
thdb->teb.tls_ptr = thdb->tls_array; thdb->teb.tls_ptr = thdb->tls_array;
......
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