diff --git a/include/module.h b/include/module.h index 55894224715..5b7c3848aeb 100644 --- a/include/module.h +++ b/include/module.h @@ -143,15 +143,15 @@ typedef struct resource_nameinfo_s NE_NAMEINFO; (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName) /* module.c */ -extern FARPROC32 MODULE_GetProcAddress32( struct _PDB32*pdb,HMODULE32 hModule,LPCSTR function,BOOL32 snoop ); -extern WINE_MODREF *MODULE32_LookupHMODULE( struct _PDB32 *process, HMODULE32 hModule ); -extern void MODULE_InitializeDLLs( struct _PDB32 *process, HMODULE32 root, DWORD type, LPVOID lpReserved ); -extern HMODULE32 MODULE_FindModule32( struct _PDB32 *process, LPCSTR path ); +extern FARPROC32 MODULE_GetProcAddress32( HMODULE32 hModule, LPCSTR function, BOOL32 snoop ); +extern WINE_MODREF *MODULE32_LookupHMODULE( HMODULE32 hModule ); +extern void MODULE_InitializeDLLs( HMODULE32 root, DWORD type, LPVOID lpReserved ); +extern HMODULE32 MODULE_FindModule32( LPCSTR path ); extern HMODULE32 MODULE_CreateDummyModule( const OFSTRUCT *ofs, LPCSTR modName ); extern FARPROC16 MODULE_GetWndProcEntry16( const char *name ); extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE32 hmodule, LPCSTR name ); extern SEGPTR WINAPI HasGPHandler( SEGPTR address ); -HMODULE32 MODULE_LoadLibraryEx32A(LPCSTR libname,struct _PDB32*process,HFILE32 hfile,DWORD flags); +HMODULE32 MODULE_LoadLibraryEx32A( LPCSTR libname, HFILE32 hfile, DWORD flags ); /* loader/ne/module.c */ extern NE_MODULE *NE_GetPtr( HMODULE16 hModule ); diff --git a/include/pe_image.h b/include/pe_image.h index 88084d87365..0b50343a446 100644 --- a/include/pe_image.h +++ b/include/pe_image.h @@ -20,12 +20,9 @@ typedef struct { int tlsindex; } PE_MODREF; -struct _PDB32; struct _wine_modref; extern int PE_unloadImage(HMODULE32 hModule); -extern FARPROC32 PE_FindExportedFunction( - struct _PDB32 *process,struct _wine_modref *wm, LPCSTR funcName, BOOL32 snoop -); +extern FARPROC32 PE_FindExportedFunction(struct _wine_modref *wm, LPCSTR funcName, BOOL32 snoop); extern BOOL32 PE_EnumResourceTypes32A(HMODULE32,ENUMRESTYPEPROC32A,LONG); extern BOOL32 PE_EnumResourceTypes32W(HMODULE32,ENUMRESTYPEPROC32W,LONG); extern BOOL32 PE_EnumResourceNames32A(HMODULE32,LPCSTR,ENUMRESNAMEPROC32A,LONG); @@ -34,8 +31,11 @@ extern BOOL32 PE_EnumResourceLanguages32A(HMODULE32,LPCSTR,LPCSTR,ENUMRESLANGPRO extern BOOL32 PE_EnumResourceLanguages32W(HMODULE32,LPCWSTR,LPCWSTR,ENUMRESLANGPROC32W,LONG); extern HRSRC32 PE_FindResourceEx32W(struct _wine_modref*,LPCWSTR,LPCWSTR,WORD); extern DWORD PE_SizeofResource32(HMODULE32,HRSRC32); -extern HMODULE32 PE_LoadLibraryEx32A(LPCSTR,struct _PDB32*,HFILE32,DWORD); +extern HMODULE32 PE_LoadLibraryEx32A(LPCSTR,HFILE32,DWORD); extern HGLOBAL32 PE_LoadResource32(struct _wine_modref *wm,HRSRC32); +extern HMODULE32 PE_LoadImage( LPCSTR name, OFSTRUCT *ofs, LPCSTR *modName ); +extern struct _wine_modref *PE_CreateModule( HMODULE32 hModule, OFSTRUCT *ofs, + DWORD flags, BOOL32 builtin ); extern HINSTANCE16 PE_CreateProcess( LPCSTR name, LPCSTR cmd_line, LPCSTR env, BOOL32 inherit, LPSTARTUPINFO32A startup, LPPROCESS_INFORMATION info ); @@ -69,8 +69,8 @@ typedef struct { ELF_STDCALL_STUB *stubs; } ELF_MODREF; -extern struct _wine_modref *ELF_CreateDummyModule(LPCSTR,LPCSTR,struct _PDB32 *); -extern HMODULE32 ELF_LoadLibraryEx32A(LPCSTR,struct _PDB32*,HFILE32,DWORD); -extern FARPROC32 ELF_FindExportedFunction(struct _PDB32 *process,struct _wine_modref *wm, LPCSTR funcName); +extern struct _wine_modref *ELF_CreateDummyModule(LPCSTR,LPCSTR); +extern HMODULE32 ELF_LoadLibraryEx32A(LPCSTR,HFILE32,DWORD); +extern FARPROC32 ELF_FindExportedFunction(struct _wine_modref *wm, LPCSTR funcName); #endif /* __WINE_PE_IMAGE_H */ diff --git a/loader/elf.c b/loader/elf.c index 203b995c7ac..23655375982 100644 --- a/loader/elf.c +++ b/loader/elf.c @@ -25,8 +25,7 @@ #include "module.h" #include "debug.h" -WINE_MODREF * -ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname, PDB32 *process ) +WINE_MODREF *ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname ) { PIMAGE_DOS_HEADER dh; PIMAGE_NT_HEADERS nth; @@ -34,17 +33,20 @@ ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname, PDB32 *process ) WINE_MODREF *wm; HMODULE32 hmod; - wm=(WINE_MODREF*)HeapAlloc(process->heap,HEAP_ZERO_MEMORY,sizeof(*wm)); + wm=(WINE_MODREF*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wm) ); wm->type = MODULE32_ELF; /* FIXME: hmm, order? */ - wm->next = process->modref_list; - process->modref_list = wm; + wm->next = PROCESS_Current()->modref_list; + PROCESS_Current()->modref_list = wm; - wm->modname = HEAP_strdupA(process->heap,0,modname); - wm->longname = HEAP_strdupA(process->heap,0,libname); + wm->modname = HEAP_strdupA( GetProcessHeap(), 0, modname ); + wm->longname = HEAP_strdupA( GetProcessHeap(), 0, libname ); - hmod = (HMODULE32)HeapAlloc(process->heap,HEAP_ZERO_MEMORY,sizeof(IMAGE_DOS_HEADER)+sizeof(IMAGE_NT_HEADERS)+sizeof(IMAGE_SECTION_HEADER)+100); + hmod = (HMODULE32)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, + sizeof(IMAGE_DOS_HEADER) + + sizeof(IMAGE_NT_HEADERS) + + sizeof(IMAGE_SECTION_HEADER) + 100 ); dh = (PIMAGE_DOS_HEADER)hmod; dh->e_magic = IMAGE_DOS_SIGNATURE; dh->e_lfanew = sizeof(IMAGE_DOS_HEADER); @@ -94,13 +96,14 @@ ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname, PDB32 *process ) #include -HMODULE32 -ELF_LoadLibraryEx32A(LPCSTR libname,PDB32 *process,HANDLE32 hf,DWORD flags) { +HMODULE32 ELF_LoadLibraryEx32A( LPCSTR libname, HANDLE32 hf, DWORD flags ) +{ WINE_MODREF *wm; char *modname,*s,*t,*x; LPVOID *dlhandle; - t = HeapAlloc(process->heap,HEAP_ZERO_MEMORY,strlen(libname)+strlen("lib.so")+1); + t = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, + strlen(libname) + strlen("lib.so") + 1 ); *t = '\0'; /* copy path to tempvar ... */ s=strrchr(libname,'/'); @@ -130,19 +133,19 @@ ELF_LoadLibraryEx32A(LPCSTR libname,PDB32 *process,HANDLE32 hf,DWORD flags) { /* ... and open it */ dlhandle = dlopen(t,RTLD_NOW); if (!dlhandle) { - HeapFree(process->heap,0,t); + HeapFree( GetProcessHeap(), 0, t ); return 0; } - wm = ELF_CreateDummyModule( t, modname, process ); + wm = ELF_CreateDummyModule( t, modname ); wm->binfmt.elf.dlhandle = dlhandle; SNOOP_RegisterDLL(wm->module,libname,STUBSIZE/sizeof(ELF_STDCALL_STUB)); return wm->module; } -FARPROC32 -ELF_FindExportedFunction( PDB32 *process,WINE_MODREF *wm, LPCSTR funcName) { +FARPROC32 ELF_FindExportedFunction( WINE_MODREF *wm, LPCSTR funcName) +{ LPVOID fun; int i,nrofargs = 0; ELF_STDCALL_STUB *stub; @@ -163,14 +166,14 @@ ELF_FindExportedFunction( PDB32 *process,WINE_MODREF *wm, LPCSTR funcName) { * with nrofargs bytes that are popped at the end */ if (strchr(funcName,'@')) { - LPSTR t,fn = HEAP_strdupA(process->heap,0,funcName); + LPSTR t,fn = HEAP_strdupA( GetProcessHeap(), 0, funcName ); t = strchr(fn,'@'); *t = '\0'; nrofargs = 0; sscanf(t+1,"%d",&nrofargs); fun = dlsym(wm->binfmt.elf.dlhandle,fn); - HeapFree(process->heap,0,fn); + HeapFree( GetProcessHeap(), 0, fn ); } } /* We sometimes have Win32 dlls implemented using stdcall but UNIX @@ -242,12 +245,12 @@ ELF_FindExportedFunction( PDB32 *process,WINE_MODREF *wm, LPCSTR funcName) { } #else -HMODULE32 -ELF_LoadLibraryEx32A(LPCSTR libname,PDB32 *process,HANDLE32 hf,DWORD flags) { +HMODULE32 ELF_LoadLibraryEx32A( LPCSTR libname, HANDLE32 hf, DWORD flags) +{ return 0; } -FARPROC32 -ELF_FindExportedFunction( PDB32 *process,WINE_MODREF *wm, LPCSTR funcName) { +FARPROC32 ELF_FindExportedFunction( WINE_MODREF *wm, LPCSTR funcName) +{ return (FARPROC32)0; } diff --git a/loader/main.c b/loader/main.c index 173bd479a7e..106452ab5c9 100644 --- a/loader/main.c +++ b/loader/main.c @@ -282,7 +282,7 @@ HINSTANCE32 MAIN_WinelibInit( int *argc, char *argv[] ) if (!MAIN_KernelInit(0, 0, NULL)) return 0; /* Create and switch to initial task */ - if (!(wm = ELF_CreateDummyModule( argv[0], argv[0], PROCESS_Current() ))) + if (!(wm = ELF_CreateDummyModule( argv[0], argv[0] ))) return 0; PROCESS_Current()->exe_modref = wm; diff --git a/loader/module.c b/loader/module.c index 802a6ac5944..916ce5d0c31 100644 --- a/loader/module.c +++ b/loader/module.c @@ -36,17 +36,18 @@ extern BOOL32 THREAD_InitDone; * MODULE32_LookupHMODULE * looks for the referenced HMODULE in the current process */ -WINE_MODREF* -MODULE32_LookupHMODULE(PDB32 *process,HMODULE32 hmod) { +WINE_MODREF *MODULE32_LookupHMODULE( HMODULE32 hmod ) +{ WINE_MODREF *wm; if (!hmod) - return process->exe_modref; + return PROCESS_Current()->exe_modref; + if (!HIWORD(hmod)) { ERR(module,"tried to lookup 0x%04x in win32 module handler!\n",hmod); return NULL; } - for (wm = process->modref_list;wm;wm=wm->next) + for ( wm = PROCESS_Current()->modref_list; wm; wm=wm->next ) if (wm->module == hmod) return wm; return NULL; @@ -70,14 +71,14 @@ MODULE32_LookupHMODULE(PDB32 *process,HMODULE32 hmod) { * from itself, but also via LoadLibrary from one of the called initialization * routines.) */ -static void MODULE_DoInitializeDLLs( PDB32 *process, WINE_MODREF *wm, +static void MODULE_DoInitializeDLLs( WINE_MODREF *wm, DWORD type, LPVOID lpReserved ) { int i; assert( wm && !wm->initDone ); - TRACE( module, "(%p,%08x,%ld,%p) - START\n", - process, wm->module, type, lpReserved ); + TRACE( module, "(%08x,%ld,%p) - START\n", + wm->module, type, lpReserved ); /* Tag current MODREF to prevent recursive loop */ wm->initDone = TRUE; @@ -85,8 +86,7 @@ static void MODULE_DoInitializeDLLs( PDB32 *process, WINE_MODREF *wm, /* Recursively initialize all child DLLs */ for ( i = 0; i < wm->nDeps; i++ ) if ( wm->deps[i] && !wm->deps[i]->initDone ) - MODULE_DoInitializeDLLs( process, - wm->deps[i], type, lpReserved ); + MODULE_DoInitializeDLLs( wm->deps[i], type, lpReserved ); /* Now we can call the initialization routine */ switch ( wm->type ) @@ -103,24 +103,23 @@ static void MODULE_DoInitializeDLLs( PDB32 *process, WINE_MODREF *wm, break; } - TRACE( module, "(%p,%08x,%ld,%p) - END\n", - process, wm->module, type, lpReserved ); + TRACE( module, "(%08x,%ld,%p) - END\n", + wm->module, type, lpReserved ); } -void MODULE_InitializeDLLs( PDB32 *process, HMODULE32 root, - DWORD type, LPVOID lpReserved ) +void MODULE_InitializeDLLs( HMODULE32 root, DWORD type, LPVOID lpReserved ) { BOOL32 inProgress = FALSE; WINE_MODREF *wm; /* Grab the process critical section to protect the recursion flags */ /* FIXME: This is probably overkill! */ - EnterCriticalSection( &process->crit_section ); + EnterCriticalSection( &PROCESS_Current()->crit_section ); - TRACE( module, "(%p,%08x,%ld,%p) - START\n", process, root, type, lpReserved ); + TRACE( module, "(%08x,%ld,%p) - START\n", root, type, lpReserved ); /* First, check whether initialization is currently in progress */ - for ( wm = process->modref_list; wm; wm = wm->next ) + for ( wm = PROCESS_Current()->modref_list; wm; wm = wm->next ) if ( wm->initDone ) { inProgress = TRUE; @@ -136,9 +135,9 @@ void MODULE_InitializeDLLs( PDB32 *process, HMODULE32 root, */ if ( root ) { - wm = MODULE32_LookupHMODULE( process, root ); + wm = MODULE32_LookupHMODULE( root ); if ( wm && !wm->initDone ) - MODULE_DoInitializeDLLs( process, wm, type, lpReserved ); + MODULE_DoInitializeDLLs( wm, type, lpReserved ); } else FIXME(module, "Invalid recursion!\n"); @@ -149,26 +148,26 @@ void MODULE_InitializeDLLs( PDB32 *process, HMODULE32 root, if ( !root ) { /* If called for main EXE, initialize all DLLs */ - for ( wm = process->modref_list; wm; wm = wm->next ) + for ( wm = PROCESS_Current()->modref_list; wm; wm = wm->next ) if ( !wm->initDone ) - MODULE_DoInitializeDLLs( process, wm, type, lpReserved ); + MODULE_DoInitializeDLLs( wm, type, lpReserved ); } else { /* If called for a specific DLL, initialize only it and its children */ - wm = MODULE32_LookupHMODULE( process, root ); - if (wm) MODULE_DoInitializeDLLs( process, wm, type, lpReserved ); + wm = MODULE32_LookupHMODULE( root ); + if (wm) MODULE_DoInitializeDLLs( wm, type, lpReserved ); } /* We're finished, so we reset all recursion flags */ - for ( wm = process->modref_list; wm; wm = wm->next ) + for ( wm = PROCESS_Current()->modref_list; wm; wm = wm->next ) wm->initDone = FALSE; } - TRACE( module, "(%p,%08x,%ld,%p) - END\n", process, root, type, lpReserved ); + TRACE( module, "(%08x,%ld,%p) - END\n", root, type, lpReserved ); /* Release critical section */ - LeaveCriticalSection( &process->crit_section ); + LeaveCriticalSection( &PROCESS_Current()->crit_section ); } @@ -339,26 +338,23 @@ FARPROC16 MODULE_GetWndProcEntry16( LPCSTR name ) * 0 if not */ HMODULE32 MODULE_FindModule32( - PDB32* process, /* [in] process in which to find the library */ LPCSTR path /* [in] pathname of module/library to be found */ ) { LPSTR filename; LPSTR dotptr; WINE_MODREF *wm; - if (!process) - return 0; if (!(filename = strrchr( path, '\\' ))) - filename = HEAP_strdupA(process->heap,0,path); + filename = HEAP_strdupA( GetProcessHeap(), 0, path ); else - filename = HEAP_strdupA(process->heap,0,filename+1); + filename = HEAP_strdupA( GetProcessHeap(), 0, filename+1 ); dotptr=strrchr(filename,'.'); - for (wm=process->modref_list;wm;wm=wm->next) { + for ( wm = PROCESS_Current()->modref_list; wm; wm=wm->next ) { LPSTR xmodname,xdotptr; assert (wm->modname); - xmodname = HEAP_strdupA(process->heap,0,wm->modname); + xmodname = HEAP_strdupA( GetProcessHeap(), 0, wm->modname ); xdotptr=strrchr(xmodname,'.'); if ( (xdotptr && !dotptr) || (!xdotptr && dotptr) @@ -367,16 +363,16 @@ HMODULE32 MODULE_FindModule32( if (xdotptr) *xdotptr = '\0'; } if (!strcasecmp( filename, xmodname)) { - HeapFree(process->heap,0,filename); - HeapFree(process->heap,0,xmodname); + HeapFree( GetProcessHeap(), 0, filename ); + HeapFree( GetProcessHeap(), 0, xmodname ); return wm->module; } if (dotptr) *dotptr='.'; /* FIXME: add paths, shortname */ - HeapFree(process->heap,0,xmodname); + HeapFree( GetProcessHeap(), 0, xmodname ); } /* if that fails, try looking for the filename... */ - for (wm=process->modref_list;wm;wm=wm->next) { + for ( wm = PROCESS_Current()->modref_list; wm; wm=wm->next ) { LPSTR xlname,xdotptr; assert (wm->longname); @@ -385,7 +381,7 @@ HMODULE32 MODULE_FindModule32( xlname = wm->longname; else xlname++; - xlname = HEAP_strdupA(process->heap,0,xlname); + xlname = HEAP_strdupA( GetProcessHeap(), 0, xlname ); xdotptr=strrchr(xlname,'.'); if ( (xdotptr && !dotptr) || (!xdotptr && dotptr) @@ -394,15 +390,15 @@ HMODULE32 MODULE_FindModule32( if (xdotptr) *xdotptr = '\0'; } if (!strcasecmp( filename, xlname)) { - HeapFree(process->heap,0,filename); - HeapFree(process->heap,0,xlname); + HeapFree( GetProcessHeap(), 0, filename ); + HeapFree( GetProcessHeap(), 0, xlname ); return wm->module; } if (dotptr) *dotptr='.'; /* FIXME: add paths, shortname */ - HeapFree(process->heap,0,xlname); + HeapFree( GetProcessHeap(), 0, xlname ); } - HeapFree(process->heap,0,filename); + HeapFree( GetProcessHeap(), 0, filename ); return 0; } @@ -748,7 +744,7 @@ HMODULE32 WINAPI GetModuleHandle32A(LPCSTR module) if (module == NULL) return PROCESS_Current()->exe_modref->module; else - return MODULE_FindModule32(PROCESS_Current(),module); + return MODULE_FindModule32( module ); } HMODULE32 WINAPI GetModuleHandle32W(LPCWSTR module) @@ -769,7 +765,7 @@ DWORD WINAPI GetModuleFileName32A( LPSTR lpFileName, /* [out] filenamebuffer */ DWORD size /* [in] size of filenamebuffer */ ) { - WINE_MODREF *wm = MODULE32_LookupHMODULE(PROCESS_Current(),hModule); + WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule ); if (!wm) /* can happen on start up or the like */ return 0; @@ -815,7 +811,7 @@ HMODULE32 WINAPI LoadLibraryEx32W16( LPCSTR libname, HANDLE16 hf, HMODULE32 WINAPI LoadLibraryEx32A(LPCSTR libname,HFILE32 hfile,DWORD flags) { HMODULE32 hmod; - hmod = MODULE_LoadLibraryEx32A(libname,PROCESS_Current(),hfile,flags); + hmod = MODULE_LoadLibraryEx32A( libname, hfile, flags ); /* at least call not the dllmain...*/ if ( DONT_RESOLVE_DLL_REFERENCES==flags || LOAD_LIBRARY_AS_DATAFILE==flags ) @@ -825,20 +821,19 @@ HMODULE32 WINAPI LoadLibraryEx32A(LPCSTR libname,HFILE32 hfile,DWORD flags) /* initialize DLL just loaded */ if ( hmod >= 32 ) - MODULE_InitializeDLLs( PROCESS_Current(), hmod, - DLL_PROCESS_ATTACH, (LPVOID)-1 ); + MODULE_InitializeDLLs( hmod, DLL_PROCESS_ATTACH, (LPVOID)-1 ); return hmod; } -HMODULE32 MODULE_LoadLibraryEx32A(LPCSTR libname,PDB32*process,HFILE32 hfile,DWORD flags) +HMODULE32 MODULE_LoadLibraryEx32A( LPCSTR libname, HFILE32 hfile, DWORD flags ) { HMODULE32 hmod; - hmod = ELF_LoadLibraryEx32A(libname,process,hfile,flags); + hmod = ELF_LoadLibraryEx32A( libname, hfile, flags ); if (hmod) return hmod; - hmod = PE_LoadLibraryEx32A(libname,process,hfile,flags); + hmod = PE_LoadLibraryEx32A( libname, hfile, flags ); return hmod; } @@ -1130,7 +1125,7 @@ FARPROC16 WINAPI GetProcAddress16( HMODULE16 hModule, SEGPTR name ) */ FARPROC32 WINAPI GetProcAddress32( HMODULE32 hModule, LPCSTR function ) { - return MODULE_GetProcAddress32( PROCESS_Current(), hModule, function, TRUE ); + return MODULE_GetProcAddress32( hModule, function, TRUE ); } /*********************************************************************** @@ -1138,19 +1133,18 @@ FARPROC32 WINAPI GetProcAddress32( HMODULE32 hModule, LPCSTR function ) */ FARPROC32 WINAPI WIN16_GetProcAddress32( HMODULE32 hModule, LPCSTR function ) { - return MODULE_GetProcAddress32( PROCESS_Current(), hModule, function, FALSE ); + return MODULE_GetProcAddress32( hModule, function, FALSE ); } /*********************************************************************** * MODULE_GetProcAddress32 (internal) */ FARPROC32 MODULE_GetProcAddress32( - PDB32 *process, /* [in] process context */ HMODULE32 hModule, /* [in] current module handle */ LPCSTR function, /* [in] function to be looked up */ BOOL32 snoop ) { - WINE_MODREF *wm = MODULE32_LookupHMODULE(process,hModule); + WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule ); if (HIWORD(function)) TRACE(win32,"(%08lx,%s)\n",(DWORD)hModule,function); @@ -1161,9 +1155,9 @@ FARPROC32 MODULE_GetProcAddress32( switch (wm->type) { case MODULE32_PE: - return PE_FindExportedFunction( process, wm, function, snoop ); + return PE_FindExportedFunction( wm, function, snoop ); case MODULE32_ELF: - return ELF_FindExportedFunction( process, wm, function); + return ELF_FindExportedFunction( wm, function); default: ERR(module,"wine_modref type %d not handled.\n",wm->type); return (FARPROC32)0; @@ -1181,7 +1175,7 @@ PIMAGE_NT_HEADERS WINAPI RtlImageNtHeader(HMODULE32 hModule) * but we could get HMODULE16 or the like (think builtin modules) */ - WINE_MODREF *wm = MODULE32_LookupHMODULE( PROCESS_Current(), hModule ); + WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule ); if (!wm || (wm->type != MODULE32_PE)) return (PIMAGE_NT_HEADERS)0; return PE_HEADER(wm->module); } diff --git a/loader/pe_image.c b/loader/pe_image.c index 719937704cd..accf0388fcf 100644 --- a/loader/pe_image.c +++ b/loader/pe_image.c @@ -31,9 +31,6 @@ * and 'blocksize' file-aligned (offsets). Since we have 512/1024/2048 (CDROM) * and other byte blocksizes, we can't do this. However, this could be less * difficult to support... (See mm/filemap.c). - * - All those function map things into a new addresspace. From the wrong - * process and the wrong thread. So calling other API functions will mess - * things up badly sometimes. */ #include @@ -119,7 +116,6 @@ void dump_exports( HMODULE32 hModule ) * - use ordinal-pe_export->Base as offset into the functionlist */ FARPROC32 PE_FindExportedFunction( - PDB32 *process, /* [in] process context */ WINE_MODREF *wm, /* [in] WINE modreference */ LPCSTR funcName, /* [in] function name */ BOOL32 snoop ) @@ -207,14 +203,14 @@ FARPROC32 PE_FindExportedFunction( assert(end-forward<256); strncpy(module, forward, (end - forward)); module[end-forward] = 0; - hMod = MODULE_FindModule32(process,module); + hMod = MODULE_FindModule32( module ); assert(hMod); - return MODULE_GetProcAddress32( process, hMod, end + 1, snoop ); + return MODULE_GetProcAddress32( hMod, end + 1, snoop ); } return NULL; } -DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) +DWORD fixup_imports( WINE_MODREF *wm ) { IMAGE_IMPORT_DESCRIPTOR *pe_imp; WINE_MODREF *xwm; @@ -252,7 +248,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) /* Allocate module dependency list */ wm->nDeps = i; - wm->deps = HeapAlloc(process->heap, 0, i*sizeof(WINE_MODREF *)); + wm->deps = HeapAlloc( GetProcessHeap(), 0, i*sizeof(WINE_MODREF *) ); /* load the imported modules. They are automatically * added to the modref list of the process. @@ -268,7 +264,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) break; /* don't use MODULE_Load, Win32 creates new task differently */ - hImpModule = MODULE_LoadLibraryEx32A( name, process, 0, 0 ); + hImpModule = MODULE_LoadLibraryEx32A( name, 0, 0 ); if (!hImpModule) { char *p,buffer[2000]; @@ -277,13 +273,13 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) if (!(p = strrchr (buffer, '\\'))) p = buffer; strcpy (p + 1, name); - hImpModule = MODULE_LoadLibraryEx32A( buffer, process, 0, 0 ); + hImpModule = MODULE_LoadLibraryEx32A( buffer, 0, 0 ); } if (!hImpModule) { ERR (module, "Module %s not found\n", name); return 1; } - xwm = MODULE32_LookupHMODULE(process, hImpModule); + xwm = MODULE32_LookupHMODULE( hImpModule ); assert( xwm ); wm->deps[i++] = xwm; @@ -300,7 +296,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) TRACE(win32, "--- Ordinal %s,%d\n", name, ordinal); thunk_list->u1.Function=MODULE_GetProcAddress32( - process, hImpModule, (LPCSTR)ordinal, TRUE + hImpModule, (LPCSTR)ordinal, TRUE ); if (!thunk_list->u1.Function) { ERR(win32,"No implementation for %s.%d, setting to 0xdeadbeef\n", @@ -311,7 +307,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) pe_name = (PIMAGE_IMPORT_BY_NAME)RVA(import_list->u1.AddressOfData); TRACE(win32, "--- %s %s.%d\n", pe_name->Name, name, pe_name->Hint); thunk_list->u1.Function=MODULE_GetProcAddress32( - process, hImpModule, pe_name->Name, TRUE + hImpModule, pe_name->Name, TRUE ); if (!thunk_list->u1.Function) { ERR(win32,"No implementation for %s.%d(%s), setting to 0xdeadbeef\n", @@ -332,7 +328,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) TRACE(win32,"--- Ordinal %s.%d\n",name,ordinal); thunk_list->u1.Function=MODULE_GetProcAddress32( - process, hImpModule, (LPCSTR) ordinal, TRUE + hImpModule, (LPCSTR) ordinal, TRUE ); if (!thunk_list->u1.Function) { ERR(win32, "No implementation for %s.%d, setting to 0xdeadbeef\n", @@ -344,7 +340,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) TRACE(win32,"--- %s %s.%d\n", pe_name->Name,name,pe_name->Hint); thunk_list->u1.Function=MODULE_GetProcAddress32( - process, hImpModule, pe_name->Name, TRUE + hImpModule, pe_name->Name, TRUE ); if (!thunk_list->u1.Function) { ERR(win32, "No implementation for %s.%d, setting to 0xdeadbeef\n", @@ -456,7 +452,7 @@ static void do_relocations( unsigned int load_addr, IMAGE_BASE_RELOCATION *r ) * BUT we have to map the whole image anyway, for Win32 programs sometimes * want to access them. (HMODULE32 point to the start of it) */ -static HMODULE32 PE_LoadImage( LPCSTR name, OFSTRUCT *ofs, LPCSTR *modName ) +HMODULE32 PE_LoadImage( LPCSTR name, OFSTRUCT *ofs, LPCSTR *modName ) { HMODULE32 hModule; HFILE32 hFile; @@ -658,9 +654,12 @@ error: * Note: hModule must point to a correctly allocated PE image, * with base relocations applied; the 16-bit dummy module * associated to hModule must already exist. + * + * Note: This routine must always be called in the context of the + * process that is to own the module to be created. */ -static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule, - OFSTRUCT *ofs, DWORD flags, BOOL32 builtin ) +WINE_MODREF *PE_CreateModule( HMODULE32 hModule, + OFSTRUCT *ofs, DWORD flags, BOOL32 builtin ) { DWORD load_addr = (DWORD)hModule; /* for RVA */ IMAGE_NT_HEADERS *nt = PE_HEADER(hModule); @@ -728,7 +727,8 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule, /* Allocate and fill WINE_MODREF */ - wm = (WINE_MODREF *)HeapAlloc( process->heap, HEAP_ZERO_MEMORY, sizeof(*wm) ); + wm = (WINE_MODREF *)HeapAlloc( GetProcessHeap(), + HEAP_ZERO_MEMORY, sizeof(*wm) ); wm->module = hModule; wm->type = MODULE32_PE; @@ -747,24 +747,24 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule, while ((s=strchr(modname,'\\'))) modname = s+1; } - wm->modname = HEAP_strdupA( process->heap, 0, modname ); + wm->modname = HEAP_strdupA( GetProcessHeap(), 0, modname ); result = GetLongPathName32A( ofs->szPathName, NULL, 0 ); - wm->longname = (char *)HeapAlloc( process->heap, 0, result+1 ); + wm->longname = (char *)HeapAlloc( GetProcessHeap(), 0, result+1 ); GetLongPathName32A( ofs->szPathName, wm->longname, result+1 ); - wm->shortname = HEAP_strdupA( process->heap, 0, ofs->szPathName ); + wm->shortname = HEAP_strdupA( GetProcessHeap(), 0, ofs->szPathName ); /* Link MODREF into process list */ - wm->next = process->modref_list; - process->modref_list = wm; + wm->next = PROCESS_Current()->modref_list; + PROCESS_Current()->modref_list = wm; if ( !(nt->FileHeader.Characteristics & IMAGE_FILE_DLL) ) { - if ( process->exe_modref ) + if ( PROCESS_Current()->exe_modref ) FIXME( win32, "overwriting old exe_modref... arrgh\n" ); - process->exe_modref = wm; + PROCESS_Current()->exe_modref = wm; } /* Dump Exports */ @@ -774,11 +774,11 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule, /* Fixup Imports */ - if ( pe_import && fixup_imports( process, wm ) ) + if ( pe_import && fixup_imports( wm ) ) { /* remove entry from modref chain */ WINE_MODREF **xwm; - for ( xwm = &process->modref_list; *xwm; xwm = &(*xwm)->next ) + for ( xwm = &PROCESS_Current()->modref_list; *xwm; xwm = &(*xwm)->next ) if ( *xwm == wm ) { *xwm = wm->next; @@ -801,7 +801,7 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule, * The PE Library Loader frontend. * FIXME: handle the flags. */ -HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, PDB32 *process, +HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, HFILE32 hFile, DWORD flags) { LPCSTR modName = NULL; @@ -813,7 +813,7 @@ HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, PDB32 *process, BOOL32 builtin; /* Check for already loaded module */ - if ((hModule32 = MODULE_FindModule32( process, name ))) + if ((hModule32 = MODULE_FindModule32( name ))) return hModule32; /* try to load builtin, enabled modules first */ @@ -839,7 +839,7 @@ HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, PDB32 *process, pModule->module32 = hModule32; /* Create 32-bit MODREF */ - if ( !(wm = PE_CreateModule( process, hModule32, &ofs, flags, builtin )) ) + if ( !(wm = PE_CreateModule( hModule32, &ofs, flags, builtin )) ) { ERR(win32,"can't load %s\n",ofs.szPathName); FreeLibrary16( hModule16 ); @@ -868,8 +868,6 @@ HINSTANCE16 PE_CreateProcess( LPCSTR name, LPCSTR cmd_line, NE_MODULE *pModule; OFSTRUCT ofs; PDB32 *process; - TDB *pTask; - WINE_MODREF *wm; /* Load file */ if ((hModule32 = PE_LoadImage( name, &ofs, &modName )) < 32) @@ -890,16 +888,8 @@ HINSTANCE16 PE_CreateProcess( LPCSTR name, LPCSTR cmd_line, process = PROCESS_Create( pModule, cmd_line, env, hInstance, 0, inherit, startup, info ); - /* Create 32-bit MODREF */ - if ( !(wm = PE_CreateModule( process, hModule32, &ofs, 0, FALSE )) ) - { - /* FIXME: should destroy the task created and free referenced stuff */ - return 0; - } - - /* FIXME: Yuck. Is there no other good place to do that? */ - pTask = (TDB *)GlobalLock16( process->task ); - PE_InitTls( pTask->thdb ); + /* Note: PE_CreateModule and the remaining process initialization will + be done in the context of the new process, in TASK_CallToStart */ return hInstance; } diff --git a/loader/pe_resource.c b/loader/pe_resource.c index 0e2ab767c12..531b71b5c01 100644 --- a/loader/pe_resource.c +++ b/loader/pe_resource.c @@ -32,9 +32,8 @@ static PE_MODREF* HMODULE32toPE_MODREF(HMODULE32 hmod) { WINE_MODREF *wm; - PDB32 *pdb = PROCESS_Current(); - wm = MODULE32_LookupHMODULE( pdb, hmod ); + wm = MODULE32_LookupHMODULE( hmod ); if (!wm || wm->type!=MODULE32_PE) return NULL; return &(wm->binfmt.pe); diff --git a/loader/resource.c b/loader/resource.c index d14f0c16098..6ba4f78ec0c 100644 --- a/loader/resource.c +++ b/loader/resource.c @@ -176,7 +176,7 @@ HANDLE32 WINAPI FindResourceEx32A( HMODULE32 hModule, LPCSTR type, LPCSTR name, HRSRC32 WINAPI FindResourceEx32W( HMODULE32 hModule, LPCWSTR type, LPCWSTR name, WORD lang ) { - WINE_MODREF *wm = MODULE32_LookupHMODULE(PROCESS_Current(),hModule); + WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule ); HRSRC32 hrsrc; TRACE(resource, "module=%08x(%s) type=%s name=%s\n", @@ -249,7 +249,7 @@ HGLOBAL32 WINAPI LoadResource32( HINSTANCE32 hModule, /* [in] module handle */ HRSRC32 hRsrc ) /* [in] resource handle */ { - WINE_MODREF *wm = MODULE32_LookupHMODULE(PROCESS_Current(),hModule); + WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule ); TRACE(resource, "module=%04x res=%04x\n", hModule, hRsrc ); @@ -372,7 +372,7 @@ DWORD WINAPI SizeofResource16( HMODULE16 hModule, HRSRC16 hRsrc ) */ DWORD WINAPI SizeofResource32( HINSTANCE32 hModule, HRSRC32 hRsrc ) { - WINE_MODREF *wm = MODULE32_LookupHMODULE(PROCESS_Current(),hModule); + WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule ); TRACE(resource, "module=%08x res=%08x\n", hModule, hRsrc ); if (!wm) return 0; diff --git a/loader/task.c b/loader/task.c index 2d65a29ad69..84d90c95d7c 100644 --- a/loader/task.c +++ b/loader/task.c @@ -242,16 +242,27 @@ static void TASK_CallToStart(void) { /* FIXME: all this is an ugly hack */ + OFSTRUCT *ofs = (OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo); LPTHREAD_START_ROUTINE entry = (LPTHREAD_START_ROUTINE) RVA_PTR(pModule->module32, OptionalHeader.AddressOfEntryPoint); + /* Create 32-bit MODREF */ + if ( !PE_CreateModule( pModule->module32, ofs, 0, FALSE ) ) + { + ERR( task, "Could not initialize process\n" ); + ExitProcess( 1 ); + } + + /* Initialize Thread-Local Storage */ + PE_InitTls( pTask->thdb ); + if (PE_HEADER(pModule->module32)->OptionalHeader.Subsystem==IMAGE_SUBSYSTEM_WINDOWS_CUI) AllocConsole(); if (pModule->heap_size) LocalInit( pTask->hInstance, 0, pModule->heap_size ); - MODULE_InitializeDLLs( PROCESS_Current(), 0, DLL_PROCESS_ATTACH, (LPVOID)-1 ); + MODULE_InitializeDLLs( 0, DLL_PROCESS_ATTACH, (LPVOID)-1 ); TRACE(relay, "(entryproc=%p)\n", entry ); #if 1 diff --git a/scheduler/thread.c b/scheduler/thread.c index 347b67a13f7..5802f05c043 100644 --- a/scheduler/thread.c +++ b/scheduler/thread.c @@ -317,7 +317,7 @@ void THREAD_Start( THDB *thdb ) LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)thdb->entry_point; assert( THREAD_Current() == thdb ); CLIENT_InitThread(); - MODULE_InitializeDLLs( thdb->process, 0, DLL_THREAD_ATTACH, NULL ); + MODULE_InitializeDLLs( 0, DLL_THREAD_ATTACH, NULL ); ExitThread( func( thdb->entry_arg ) ); } @@ -362,7 +362,7 @@ void WINAPI ExitThread( THDB *thdb = THREAD_Current(); LONG count; - MODULE_InitializeDLLs( thdb->process, 0, DLL_THREAD_DETACH, NULL ); + MODULE_InitializeDLLs( 0, DLL_THREAD_DETACH, NULL ); SYSTEM_LOCK(); thdb->exit_code = code;