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 );
extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
extern HANDLE NE_OpenFile( NE_MODULE *pModule );
extern HINSTANCE16 NE_LoadModule( LPCSTR name, HINSTANCE16 *hPrevInstance,
BOOL implicit, BOOL lib_only );
extern HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL implicit );
extern BOOL NE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line,
LPCSTR env, BOOL inherit, LPSTARTUPINFOA startup,
LPPROCESS_INFORMATION info );
/* loader/ne/resource.c */
extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
......
......@@ -146,7 +146,7 @@ typedef struct _THHOOK
extern THHOOK *pThhook;
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,
UINT16 cmdShow );
extern void TASK_StartTask( HTASK16 hTask );
......
......@@ -259,9 +259,6 @@ static void TASK_CallToStart(void)
if (PE_HEADER(pModule->module32)->OptionalHeader.Subsystem==IMAGE_SUBSYSTEM_WINDOWS_CUI)
AllocConsole();
if (pModule->heap_size)
LocalInit16( pTask->hInstance, 0, pModule->heap_size );
MODULE_InitializeDLLs( 0, DLL_PROCESS_ATTACH, (LPVOID)-1 );
TRACE(relay, "(entryproc=%p)\n", entry );
......@@ -336,7 +333,7 @@ static void TASK_CallToStart(void)
* any real problems with that, since we operated merely on a private
* 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)
{
HTASK16 hTask;
......@@ -354,7 +351,7 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance,
hTask = GLOBAL_Alloc( GMEM_FIXED | GMEM_ZEROINIT, sizeof(TDB),
pModule->self, FALSE, FALSE, FALSE );
if (!hTask) return 0;
if (!hTask) return FALSE;
pTask = (TDB *)GlobalLock16( hTask );
/* Fill the task structure */
......@@ -369,7 +366,7 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance,
pTask->flags |= TDBF_WINOLDAP;
pTask->version = pModule->expected_version;
pTask->hInstance = hInstance;
pTask->hInstance = hInstance? hInstance : pModule->self;
pTask->hPrevInstance = hPrevInstance;
pTask->hModule = pModule->self;
pTask->hParent = GetCurrentTask();
......@@ -445,16 +442,23 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance,
if ( pInitialTask )
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))
sp = pSegTable[pModule->ss-1].minsize + pModule->stack_size;
sp &= ~1; sp -= 2*sizeof(STACK16FRAME);
pTask->thdb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( pTask->hInstance, sp );
sp &= ~1; sp -= sizeof(STACK16FRAME);
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->ebp = sp + (int)&((STACK16FRAME *)0)->bp;
frame16->ebp = OFFSETOF( pTask->thdb->cur_stack ) + (int)&((STACK16FRAME *)0)->bp;
frame16->bp = LOWORD(frame16->ebp);
frame16->ds = frame16->es = pTask->hInstance;
frame16->ds = frame16->es = hInstance;
frame16->fs = 0;
frame16->entry_point = 0;
frame16->entry_cs = 0;
......@@ -474,11 +478,14 @@ HTASK16 TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance,
frame32->retaddr = (DWORD)TASK_CallToStart;
/* 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",
name, cmd_line, hTask );
return hTask;
return TRUE;
}
/***********************************************************************
......
......@@ -420,7 +420,6 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
THDB *thdb = NULL;
PDB *parent = PROCESS_Current();
PDB *pdb = PROCESS_CreatePDB( parent, inherit );
TDB *pTask;
if (!pdb) return NULL;
info->hThread = info->hProcess = INVALID_HANDLE_VALUE;
......@@ -452,8 +451,9 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
size = PE_HEADER(pModule->module32)->OptionalHeader.SizeOfStackReserve;
else
size = 0;
if (!(thdb = THREAD_Create( pdb, size, FALSE, &server_thandle, &server_phandle,
NULL, NULL ))) goto error;
if (!(thdb = THREAD_Create( pdb, size, hInstance == 0,
&server_thandle, &server_phandle, NULL, NULL )))
goto error;
if ((info->hThread = HANDLE_Alloc( parent, &thdb->header, THREAD_ALL_ACCESS,
FALSE, server_thandle )) == INVALID_HANDLE_VALUE)
goto error;
......@@ -480,8 +480,8 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
if (startup->dwFlags & STARTF_USESHOWWINDOW)
cmdShow = startup->wShowWindow;
pdb->task = TASK_Create( thdb, pModule, hInstance, hPrevInstance, cmdShow);
if (!pdb->task) goto error;
if ( !TASK_Create( thdb, pModule, hInstance, hPrevInstance, cmdShow) )
goto error;
/* Map system DLLs into this process (from initial process) */
......
......@@ -226,7 +226,7 @@ THDB *THREAD_CreateInitialThread( PDB *pdb )
/* 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;
}
......@@ -244,7 +244,7 @@ THDB *THREAD_Create( PDB *pdb, DWORD stack_size, BOOL alloc_stack16,
thdb->header.refcount = 1;
thdb->process = pdb;
thdb->teb.except = (void *)-1;
thdb->teb.htask16 = 0; /* FIXME */
thdb->teb.htask16 = pdb->task;
thdb->teb.self = &thdb->teb;
thdb->teb.flags = (pdb->flags & PDB32_WIN16_PROC)? 0 : TEBF_WIN32;
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