/*********************************************************************** * InitTask (KERNEL.91) * * Called by the application startup code. */ void WINAPI InitTask16( CONTEXT *context ) { TDB *pTask; INSTANCEDATA *pinstance; SEGPTR ptr; context->Eax = 0; if (!(pTask = TASK_GetCurrent())) return; /* Note: we need to trust that BX/CX contain the stack/heap sizes, as some apps, notably Visual Basic apps, *modify* the heap/stack size of the instance data segment before calling InitTask() */ /* Initialize the INSTANCEDATA structure */ pinstance = MapSL( MAKESEGPTR(CURRENT_DS, 0) ); pinstance->stackmin = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + sizeof( STACK16FRAME ); pinstance->stackbottom = pinstance->stackmin; /* yup, that's right. Confused me too. */ pinstance->stacktop = ( pinstance->stackmin > LOWORD(context->Ebx) ? pinstance->stackmin - LOWORD(context->Ebx) : 0 ) + 150; /* Initialize the local heap */ if (LOWORD(context->Ecx)) LocalInit16( GlobalHandleToSel16(pTask->hInstance), 0, LOWORD(context->Ecx) ); /* Initialize implicitly loaded DLLs */ NE_InitializeDLLs( pTask->hModule ); NE_DllProcessAttach( pTask->hModule ); /* Registers on return are: * ax 1 if OK, 0 on error * cx stack limit in bytes * dx cmdShow parameter * si instance handle of the previous instance * di instance handle of the new task * es:bx pointer to command line inside PSP * * 0 (=%bp) is pushed on the stack */ ptr = stack16_push( sizeof(WORD) ); *(WORD *)MapSL(ptr) = 0; context->Esp -= 2; context->Eax = 1; if (!pTask->pdb.cmdLine[0]) context->Ebx = 0x80; else { LPBYTE p = &pTask->pdb.cmdLine[1]; while ((*p == ' ') || (*p == '\t')) p++; context->Ebx = 0x80 + (p - pTask->pdb.cmdLine); } context->Ecx = pinstance->stacktop; context->Edx = pTask->nCmdShow; context->Esi = (DWORD)pTask->hPrevInstance; context->Edi = (DWORD)pTask->hInstance; context->SegEs = (WORD)pTask->hPDB; }
/*********************************************************************** * NE_InitializeDLLs * * Recursively initialize all DLLs (according to the order in which * they where loaded). */ void NE_InitializeDLLs( HMODULE16 hModule ) { NE_MODULE *pModule; HMODULE16 *pDLL; if (!(pModule = NE_GetPtr( hModule ))) return; assert( !(pModule->ne_flags & NE_FFLAGS_WIN32) ); if (pModule->dlls_to_init) { HGLOBAL16 to_init = pModule->dlls_to_init; pModule->dlls_to_init = 0; for (pDLL = GlobalLock16( to_init ); *pDLL; pDLL++) { NE_InitializeDLLs( *pDLL ); } GlobalFree16( to_init ); } NE_InitDLL( pModule ); }