Commit 1d90d69f authored by Ulrich Weigand's avatar Ulrich Weigand Committed by Alexandre Julliard

Modified process creation sequence: call PE_CreateModule in the

context of the new process (in TASK_CallToStart). Changed all PE/Module routines so as to always operate on the current process; adapted all callers.
parent 219cfd83
...@@ -143,15 +143,15 @@ typedef struct resource_nameinfo_s NE_NAMEINFO; ...@@ -143,15 +143,15 @@ typedef struct resource_nameinfo_s NE_NAMEINFO;
(((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName) (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
/* module.c */ /* module.c */
extern FARPROC32 MODULE_GetProcAddress32( struct _PDB32*pdb,HMODULE32 hModule,LPCSTR function,BOOL32 snoop ); extern FARPROC32 MODULE_GetProcAddress32( HMODULE32 hModule, LPCSTR function, BOOL32 snoop );
extern WINE_MODREF *MODULE32_LookupHMODULE( struct _PDB32 *process, HMODULE32 hModule ); extern WINE_MODREF *MODULE32_LookupHMODULE( HMODULE32 hModule );
extern void MODULE_InitializeDLLs( struct _PDB32 *process, HMODULE32 root, DWORD type, LPVOID lpReserved ); extern void MODULE_InitializeDLLs( HMODULE32 root, DWORD type, LPVOID lpReserved );
extern HMODULE32 MODULE_FindModule32( struct _PDB32 *process, LPCSTR path ); extern HMODULE32 MODULE_FindModule32( LPCSTR path );
extern HMODULE32 MODULE_CreateDummyModule( const OFSTRUCT *ofs, LPCSTR modName ); extern HMODULE32 MODULE_CreateDummyModule( const OFSTRUCT *ofs, LPCSTR modName );
extern FARPROC16 MODULE_GetWndProcEntry16( const char *name ); extern FARPROC16 MODULE_GetWndProcEntry16( const char *name );
extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE32 hmodule, LPCSTR name ); extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE32 hmodule, LPCSTR name );
extern SEGPTR WINAPI HasGPHandler( SEGPTR address ); 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 */ /* loader/ne/module.c */
extern NE_MODULE *NE_GetPtr( HMODULE16 hModule ); extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
......
...@@ -20,12 +20,9 @@ typedef struct { ...@@ -20,12 +20,9 @@ typedef struct {
int tlsindex; int tlsindex;
} PE_MODREF; } PE_MODREF;
struct _PDB32;
struct _wine_modref; struct _wine_modref;
extern int PE_unloadImage(HMODULE32 hModule); extern int PE_unloadImage(HMODULE32 hModule);
extern FARPROC32 PE_FindExportedFunction( extern FARPROC32 PE_FindExportedFunction(struct _wine_modref *wm, LPCSTR funcName, BOOL32 snoop);
struct _PDB32 *process,struct _wine_modref *wm, LPCSTR funcName, BOOL32 snoop
);
extern BOOL32 PE_EnumResourceTypes32A(HMODULE32,ENUMRESTYPEPROC32A,LONG); extern BOOL32 PE_EnumResourceTypes32A(HMODULE32,ENUMRESTYPEPROC32A,LONG);
extern BOOL32 PE_EnumResourceTypes32W(HMODULE32,ENUMRESTYPEPROC32W,LONG); extern BOOL32 PE_EnumResourceTypes32W(HMODULE32,ENUMRESTYPEPROC32W,LONG);
extern BOOL32 PE_EnumResourceNames32A(HMODULE32,LPCSTR,ENUMRESNAMEPROC32A,LONG); extern BOOL32 PE_EnumResourceNames32A(HMODULE32,LPCSTR,ENUMRESNAMEPROC32A,LONG);
...@@ -34,8 +31,11 @@ extern BOOL32 PE_EnumResourceLanguages32A(HMODULE32,LPCSTR,LPCSTR,ENUMRESLANGPRO ...@@ -34,8 +31,11 @@ extern BOOL32 PE_EnumResourceLanguages32A(HMODULE32,LPCSTR,LPCSTR,ENUMRESLANGPRO
extern BOOL32 PE_EnumResourceLanguages32W(HMODULE32,LPCWSTR,LPCWSTR,ENUMRESLANGPROC32W,LONG); extern BOOL32 PE_EnumResourceLanguages32W(HMODULE32,LPCWSTR,LPCWSTR,ENUMRESLANGPROC32W,LONG);
extern HRSRC32 PE_FindResourceEx32W(struct _wine_modref*,LPCWSTR,LPCWSTR,WORD); extern HRSRC32 PE_FindResourceEx32W(struct _wine_modref*,LPCWSTR,LPCWSTR,WORD);
extern DWORD PE_SizeofResource32(HMODULE32,HRSRC32); 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 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, extern HINSTANCE16 PE_CreateProcess( LPCSTR name, LPCSTR cmd_line,
LPCSTR env, BOOL32 inherit, LPSTARTUPINFO32A startup, LPCSTR env, BOOL32 inherit, LPSTARTUPINFO32A startup,
LPPROCESS_INFORMATION info ); LPPROCESS_INFORMATION info );
...@@ -69,8 +69,8 @@ typedef struct { ...@@ -69,8 +69,8 @@ typedef struct {
ELF_STDCALL_STUB *stubs; ELF_STDCALL_STUB *stubs;
} ELF_MODREF; } ELF_MODREF;
extern struct _wine_modref *ELF_CreateDummyModule(LPCSTR,LPCSTR,struct _PDB32 *); extern struct _wine_modref *ELF_CreateDummyModule(LPCSTR,LPCSTR);
extern HMODULE32 ELF_LoadLibraryEx32A(LPCSTR,struct _PDB32*,HFILE32,DWORD); extern HMODULE32 ELF_LoadLibraryEx32A(LPCSTR,HFILE32,DWORD);
extern FARPROC32 ELF_FindExportedFunction(struct _PDB32 *process,struct _wine_modref *wm, LPCSTR funcName); extern FARPROC32 ELF_FindExportedFunction(struct _wine_modref *wm, LPCSTR funcName);
#endif /* __WINE_PE_IMAGE_H */ #endif /* __WINE_PE_IMAGE_H */
...@@ -25,8 +25,7 @@ ...@@ -25,8 +25,7 @@
#include "module.h" #include "module.h"
#include "debug.h" #include "debug.h"
WINE_MODREF * WINE_MODREF *ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname )
ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname, PDB32 *process )
{ {
PIMAGE_DOS_HEADER dh; PIMAGE_DOS_HEADER dh;
PIMAGE_NT_HEADERS nth; PIMAGE_NT_HEADERS nth;
...@@ -34,17 +33,20 @@ ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname, PDB32 *process ) ...@@ -34,17 +33,20 @@ ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname, PDB32 *process )
WINE_MODREF *wm; WINE_MODREF *wm;
HMODULE32 hmod; 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; wm->type = MODULE32_ELF;
/* FIXME: hmm, order? */ /* FIXME: hmm, order? */
wm->next = process->modref_list; wm->next = PROCESS_Current()->modref_list;
process->modref_list = wm; PROCESS_Current()->modref_list = wm;
wm->modname = HEAP_strdupA(process->heap,0,modname); wm->modname = HEAP_strdupA( GetProcessHeap(), 0, modname );
wm->longname = HEAP_strdupA(process->heap,0,libname); 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 = (PIMAGE_DOS_HEADER)hmod;
dh->e_magic = IMAGE_DOS_SIGNATURE; dh->e_magic = IMAGE_DOS_SIGNATURE;
dh->e_lfanew = sizeof(IMAGE_DOS_HEADER); dh->e_lfanew = sizeof(IMAGE_DOS_HEADER);
...@@ -94,13 +96,14 @@ ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname, PDB32 *process ) ...@@ -94,13 +96,14 @@ ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname, PDB32 *process )
#include <dlfcn.h> #include <dlfcn.h>
HMODULE32 HMODULE32 ELF_LoadLibraryEx32A( LPCSTR libname, HANDLE32 hf, DWORD flags )
ELF_LoadLibraryEx32A(LPCSTR libname,PDB32 *process,HANDLE32 hf,DWORD flags) { {
WINE_MODREF *wm; WINE_MODREF *wm;
char *modname,*s,*t,*x; char *modname,*s,*t,*x;
LPVOID *dlhandle; 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'; *t = '\0';
/* copy path to tempvar ... */ /* copy path to tempvar ... */
s=strrchr(libname,'/'); s=strrchr(libname,'/');
...@@ -130,19 +133,19 @@ ELF_LoadLibraryEx32A(LPCSTR libname,PDB32 *process,HANDLE32 hf,DWORD flags) { ...@@ -130,19 +133,19 @@ ELF_LoadLibraryEx32A(LPCSTR libname,PDB32 *process,HANDLE32 hf,DWORD flags) {
/* ... and open it */ /* ... and open it */
dlhandle = dlopen(t,RTLD_NOW); dlhandle = dlopen(t,RTLD_NOW);
if (!dlhandle) { if (!dlhandle) {
HeapFree(process->heap,0,t); HeapFree( GetProcessHeap(), 0, t );
return 0; return 0;
} }
wm = ELF_CreateDummyModule( t, modname, process ); wm = ELF_CreateDummyModule( t, modname );
wm->binfmt.elf.dlhandle = dlhandle; wm->binfmt.elf.dlhandle = dlhandle;
SNOOP_RegisterDLL(wm->module,libname,STUBSIZE/sizeof(ELF_STDCALL_STUB)); SNOOP_RegisterDLL(wm->module,libname,STUBSIZE/sizeof(ELF_STDCALL_STUB));
return wm->module; return wm->module;
} }
FARPROC32 FARPROC32 ELF_FindExportedFunction( WINE_MODREF *wm, LPCSTR funcName)
ELF_FindExportedFunction( PDB32 *process,WINE_MODREF *wm, LPCSTR funcName) { {
LPVOID fun; LPVOID fun;
int i,nrofargs = 0; int i,nrofargs = 0;
ELF_STDCALL_STUB *stub; ELF_STDCALL_STUB *stub;
...@@ -163,14 +166,14 @@ ELF_FindExportedFunction( PDB32 *process,WINE_MODREF *wm, LPCSTR funcName) { ...@@ -163,14 +166,14 @@ ELF_FindExportedFunction( PDB32 *process,WINE_MODREF *wm, LPCSTR funcName) {
* with nrofargs bytes that are popped at the end * with nrofargs bytes that are popped at the end
*/ */
if (strchr(funcName,'@')) { if (strchr(funcName,'@')) {
LPSTR t,fn = HEAP_strdupA(process->heap,0,funcName); LPSTR t,fn = HEAP_strdupA( GetProcessHeap(), 0, funcName );
t = strchr(fn,'@'); t = strchr(fn,'@');
*t = '\0'; *t = '\0';
nrofargs = 0; nrofargs = 0;
sscanf(t+1,"%d",&nrofargs); sscanf(t+1,"%d",&nrofargs);
fun = dlsym(wm->binfmt.elf.dlhandle,fn); 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 /* We sometimes have Win32 dlls implemented using stdcall but UNIX
...@@ -242,12 +245,12 @@ ELF_FindExportedFunction( PDB32 *process,WINE_MODREF *wm, LPCSTR funcName) { ...@@ -242,12 +245,12 @@ ELF_FindExportedFunction( PDB32 *process,WINE_MODREF *wm, LPCSTR funcName) {
} }
#else #else
HMODULE32 HMODULE32 ELF_LoadLibraryEx32A( LPCSTR libname, HANDLE32 hf, DWORD flags)
ELF_LoadLibraryEx32A(LPCSTR libname,PDB32 *process,HANDLE32 hf,DWORD flags) { {
return 0; return 0;
} }
FARPROC32 FARPROC32 ELF_FindExportedFunction( WINE_MODREF *wm, LPCSTR funcName)
ELF_FindExportedFunction( PDB32 *process,WINE_MODREF *wm, LPCSTR funcName) { {
return (FARPROC32)0; return (FARPROC32)0;
} }
......
...@@ -282,7 +282,7 @@ HINSTANCE32 MAIN_WinelibInit( int *argc, char *argv[] ) ...@@ -282,7 +282,7 @@ HINSTANCE32 MAIN_WinelibInit( int *argc, char *argv[] )
if (!MAIN_KernelInit(0, 0, NULL)) return 0; if (!MAIN_KernelInit(0, 0, NULL)) return 0;
/* Create and switch to initial task */ /* 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; return 0;
PROCESS_Current()->exe_modref = wm; PROCESS_Current()->exe_modref = wm;
......
...@@ -31,9 +31,6 @@ ...@@ -31,9 +31,6 @@
* and 'blocksize' file-aligned (offsets). Since we have 512/1024/2048 (CDROM) * 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 * and other byte blocksizes, we can't do this. However, this could be less
* difficult to support... (See mm/filemap.c). * 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 <errno.h> #include <errno.h>
...@@ -119,7 +116,6 @@ void dump_exports( HMODULE32 hModule ) ...@@ -119,7 +116,6 @@ void dump_exports( HMODULE32 hModule )
* - use ordinal-pe_export->Base as offset into the functionlist * - use ordinal-pe_export->Base as offset into the functionlist
*/ */
FARPROC32 PE_FindExportedFunction( FARPROC32 PE_FindExportedFunction(
PDB32 *process, /* [in] process context */
WINE_MODREF *wm, /* [in] WINE modreference */ WINE_MODREF *wm, /* [in] WINE modreference */
LPCSTR funcName, /* [in] function name */ LPCSTR funcName, /* [in] function name */
BOOL32 snoop ) BOOL32 snoop )
...@@ -207,14 +203,14 @@ FARPROC32 PE_FindExportedFunction( ...@@ -207,14 +203,14 @@ FARPROC32 PE_FindExportedFunction(
assert(end-forward<256); assert(end-forward<256);
strncpy(module, forward, (end - forward)); strncpy(module, forward, (end - forward));
module[end-forward] = 0; module[end-forward] = 0;
hMod = MODULE_FindModule32(process,module); hMod = MODULE_FindModule32( module );
assert(hMod); assert(hMod);
return MODULE_GetProcAddress32( process, hMod, end + 1, snoop ); return MODULE_GetProcAddress32( hMod, end + 1, snoop );
} }
return NULL; return NULL;
} }
DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) DWORD fixup_imports( WINE_MODREF *wm )
{ {
IMAGE_IMPORT_DESCRIPTOR *pe_imp; IMAGE_IMPORT_DESCRIPTOR *pe_imp;
WINE_MODREF *xwm; WINE_MODREF *xwm;
...@@ -252,7 +248,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) ...@@ -252,7 +248,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm)
/* Allocate module dependency list */ /* Allocate module dependency list */
wm->nDeps = i; 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 /* load the imported modules. They are automatically
* added to the modref list of the process. * added to the modref list of the process.
...@@ -268,7 +264,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) ...@@ -268,7 +264,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm)
break; break;
/* don't use MODULE_Load, Win32 creates new task differently */ /* 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) { if (!hImpModule) {
char *p,buffer[2000]; char *p,buffer[2000];
...@@ -277,13 +273,13 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) ...@@ -277,13 +273,13 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm)
if (!(p = strrchr (buffer, '\\'))) if (!(p = strrchr (buffer, '\\')))
p = buffer; p = buffer;
strcpy (p + 1, name); strcpy (p + 1, name);
hImpModule = MODULE_LoadLibraryEx32A( buffer, process, 0, 0 ); hImpModule = MODULE_LoadLibraryEx32A( buffer, 0, 0 );
} }
if (!hImpModule) { if (!hImpModule) {
ERR (module, "Module %s not found\n", name); ERR (module, "Module %s not found\n", name);
return 1; return 1;
} }
xwm = MODULE32_LookupHMODULE(process, hImpModule); xwm = MODULE32_LookupHMODULE( hImpModule );
assert( xwm ); assert( xwm );
wm->deps[i++] = xwm; wm->deps[i++] = xwm;
...@@ -300,7 +296,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) ...@@ -300,7 +296,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm)
TRACE(win32, "--- Ordinal %s,%d\n", name, ordinal); TRACE(win32, "--- Ordinal %s,%d\n", name, ordinal);
thunk_list->u1.Function=MODULE_GetProcAddress32( thunk_list->u1.Function=MODULE_GetProcAddress32(
process, hImpModule, (LPCSTR)ordinal, TRUE hImpModule, (LPCSTR)ordinal, TRUE
); );
if (!thunk_list->u1.Function) { if (!thunk_list->u1.Function) {
ERR(win32,"No implementation for %s.%d, setting to 0xdeadbeef\n", ERR(win32,"No implementation for %s.%d, setting to 0xdeadbeef\n",
...@@ -311,7 +307,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) ...@@ -311,7 +307,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm)
pe_name = (PIMAGE_IMPORT_BY_NAME)RVA(import_list->u1.AddressOfData); pe_name = (PIMAGE_IMPORT_BY_NAME)RVA(import_list->u1.AddressOfData);
TRACE(win32, "--- %s %s.%d\n", pe_name->Name, name, pe_name->Hint); TRACE(win32, "--- %s %s.%d\n", pe_name->Name, name, pe_name->Hint);
thunk_list->u1.Function=MODULE_GetProcAddress32( thunk_list->u1.Function=MODULE_GetProcAddress32(
process, hImpModule, pe_name->Name, TRUE hImpModule, pe_name->Name, TRUE
); );
if (!thunk_list->u1.Function) { if (!thunk_list->u1.Function) {
ERR(win32,"No implementation for %s.%d(%s), setting to 0xdeadbeef\n", ERR(win32,"No implementation for %s.%d(%s), setting to 0xdeadbeef\n",
...@@ -332,7 +328,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) ...@@ -332,7 +328,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm)
TRACE(win32,"--- Ordinal %s.%d\n",name,ordinal); TRACE(win32,"--- Ordinal %s.%d\n",name,ordinal);
thunk_list->u1.Function=MODULE_GetProcAddress32( thunk_list->u1.Function=MODULE_GetProcAddress32(
process, hImpModule, (LPCSTR) ordinal, TRUE hImpModule, (LPCSTR) ordinal, TRUE
); );
if (!thunk_list->u1.Function) { if (!thunk_list->u1.Function) {
ERR(win32, "No implementation for %s.%d, setting to 0xdeadbeef\n", ERR(win32, "No implementation for %s.%d, setting to 0xdeadbeef\n",
...@@ -344,7 +340,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm) ...@@ -344,7 +340,7 @@ DWORD fixup_imports (PDB32 *process,WINE_MODREF *wm)
TRACE(win32,"--- %s %s.%d\n", TRACE(win32,"--- %s %s.%d\n",
pe_name->Name,name,pe_name->Hint); pe_name->Name,name,pe_name->Hint);
thunk_list->u1.Function=MODULE_GetProcAddress32( thunk_list->u1.Function=MODULE_GetProcAddress32(
process, hImpModule, pe_name->Name, TRUE hImpModule, pe_name->Name, TRUE
); );
if (!thunk_list->u1.Function) { if (!thunk_list->u1.Function) {
ERR(win32, "No implementation for %s.%d, setting to 0xdeadbeef\n", 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 ) ...@@ -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 * BUT we have to map the whole image anyway, for Win32 programs sometimes
* want to access them. (HMODULE32 point to the start of it) * 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; HMODULE32 hModule;
HFILE32 hFile; HFILE32 hFile;
...@@ -658,9 +654,12 @@ error: ...@@ -658,9 +654,12 @@ error:
* Note: hModule must point to a correctly allocated PE image, * Note: hModule must point to a correctly allocated PE image,
* with base relocations applied; the 16-bit dummy module * with base relocations applied; the 16-bit dummy module
* associated to hModule must already exist. * 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, WINE_MODREF *PE_CreateModule( HMODULE32 hModule,
OFSTRUCT *ofs, DWORD flags, BOOL32 builtin ) OFSTRUCT *ofs, DWORD flags, BOOL32 builtin )
{ {
DWORD load_addr = (DWORD)hModule; /* for RVA */ DWORD load_addr = (DWORD)hModule; /* for RVA */
IMAGE_NT_HEADERS *nt = PE_HEADER(hModule); IMAGE_NT_HEADERS *nt = PE_HEADER(hModule);
...@@ -728,7 +727,8 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule, ...@@ -728,7 +727,8 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule,
/* Allocate and fill WINE_MODREF */ /* 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->module = hModule;
wm->type = MODULE32_PE; wm->type = MODULE32_PE;
...@@ -747,24 +747,24 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule, ...@@ -747,24 +747,24 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule,
while ((s=strchr(modname,'\\'))) while ((s=strchr(modname,'\\')))
modname = s+1; modname = s+1;
} }
wm->modname = HEAP_strdupA( process->heap, 0, modname ); wm->modname = HEAP_strdupA( GetProcessHeap(), 0, modname );
result = GetLongPathName32A( ofs->szPathName, NULL, 0 ); 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 ); 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 */ /* Link MODREF into process list */
wm->next = process->modref_list; wm->next = PROCESS_Current()->modref_list;
process->modref_list = wm; PROCESS_Current()->modref_list = wm;
if ( !(nt->FileHeader.Characteristics & IMAGE_FILE_DLL) ) if ( !(nt->FileHeader.Characteristics & IMAGE_FILE_DLL) )
{ {
if ( process->exe_modref ) if ( PROCESS_Current()->exe_modref )
FIXME( win32, "overwriting old exe_modref... arrgh\n" ); FIXME( win32, "overwriting old exe_modref... arrgh\n" );
process->exe_modref = wm; PROCESS_Current()->exe_modref = wm;
} }
/* Dump Exports */ /* Dump Exports */
...@@ -774,11 +774,11 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule, ...@@ -774,11 +774,11 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule,
/* Fixup Imports */ /* Fixup Imports */
if ( pe_import && fixup_imports( process, wm ) ) if ( pe_import && fixup_imports( wm ) )
{ {
/* remove entry from modref chain */ /* remove entry from modref chain */
WINE_MODREF **xwm; 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 ) if ( *xwm == wm )
{ {
*xwm = wm->next; *xwm = wm->next;
...@@ -801,7 +801,7 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule, ...@@ -801,7 +801,7 @@ static WINE_MODREF *PE_CreateModule( PDB32 *process, HMODULE32 hModule,
* The PE Library Loader frontend. * The PE Library Loader frontend.
* FIXME: handle the flags. * FIXME: handle the flags.
*/ */
HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, PDB32 *process, HMODULE32 PE_LoadLibraryEx32A (LPCSTR name,
HFILE32 hFile, DWORD flags) HFILE32 hFile, DWORD flags)
{ {
LPCSTR modName = NULL; LPCSTR modName = NULL;
...@@ -813,7 +813,7 @@ HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, PDB32 *process, ...@@ -813,7 +813,7 @@ HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, PDB32 *process,
BOOL32 builtin; BOOL32 builtin;
/* Check for already loaded module */ /* Check for already loaded module */
if ((hModule32 = MODULE_FindModule32( process, name ))) if ((hModule32 = MODULE_FindModule32( name )))
return hModule32; return hModule32;
/* try to load builtin, enabled modules first */ /* try to load builtin, enabled modules first */
...@@ -839,7 +839,7 @@ HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, PDB32 *process, ...@@ -839,7 +839,7 @@ HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, PDB32 *process,
pModule->module32 = hModule32; pModule->module32 = hModule32;
/* Create 32-bit MODREF */ /* 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); ERR(win32,"can't load %s\n",ofs.szPathName);
FreeLibrary16( hModule16 ); FreeLibrary16( hModule16 );
...@@ -868,8 +868,6 @@ HINSTANCE16 PE_CreateProcess( LPCSTR name, LPCSTR cmd_line, ...@@ -868,8 +868,6 @@ HINSTANCE16 PE_CreateProcess( LPCSTR name, LPCSTR cmd_line,
NE_MODULE *pModule; NE_MODULE *pModule;
OFSTRUCT ofs; OFSTRUCT ofs;
PDB32 *process; PDB32 *process;
TDB *pTask;
WINE_MODREF *wm;
/* Load file */ /* Load file */
if ((hModule32 = PE_LoadImage( name, &ofs, &modName )) < 32) if ((hModule32 = PE_LoadImage( name, &ofs, &modName )) < 32)
...@@ -890,16 +888,8 @@ HINSTANCE16 PE_CreateProcess( LPCSTR name, LPCSTR cmd_line, ...@@ -890,16 +888,8 @@ HINSTANCE16 PE_CreateProcess( LPCSTR name, LPCSTR cmd_line,
process = PROCESS_Create( pModule, cmd_line, env, process = PROCESS_Create( pModule, cmd_line, env,
hInstance, 0, inherit, startup, info ); hInstance, 0, inherit, startup, info );
/* Create 32-bit MODREF */ /* Note: PE_CreateModule and the remaining process initialization will
if ( !(wm = PE_CreateModule( process, hModule32, &ofs, 0, FALSE )) ) be done in the context of the new process, in TASK_CallToStart */
{
/* 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 );
return hInstance; return hInstance;
} }
......
...@@ -32,9 +32,8 @@ ...@@ -32,9 +32,8 @@
static PE_MODREF* static PE_MODREF*
HMODULE32toPE_MODREF(HMODULE32 hmod) { HMODULE32toPE_MODREF(HMODULE32 hmod) {
WINE_MODREF *wm; WINE_MODREF *wm;
PDB32 *pdb = PROCESS_Current();
wm = MODULE32_LookupHMODULE( pdb, hmod ); wm = MODULE32_LookupHMODULE( hmod );
if (!wm || wm->type!=MODULE32_PE) if (!wm || wm->type!=MODULE32_PE)
return NULL; return NULL;
return &(wm->binfmt.pe); return &(wm->binfmt.pe);
......
...@@ -176,7 +176,7 @@ HANDLE32 WINAPI FindResourceEx32A( HMODULE32 hModule, LPCSTR type, LPCSTR name, ...@@ -176,7 +176,7 @@ HANDLE32 WINAPI FindResourceEx32A( HMODULE32 hModule, LPCSTR type, LPCSTR name,
HRSRC32 WINAPI FindResourceEx32W( HMODULE32 hModule, LPCWSTR type, HRSRC32 WINAPI FindResourceEx32W( HMODULE32 hModule, LPCWSTR type,
LPCWSTR name, WORD lang ) LPCWSTR name, WORD lang )
{ {
WINE_MODREF *wm = MODULE32_LookupHMODULE(PROCESS_Current(),hModule); WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
HRSRC32 hrsrc; HRSRC32 hrsrc;
TRACE(resource, "module=%08x(%s) type=%s name=%s\n", TRACE(resource, "module=%08x(%s) type=%s name=%s\n",
...@@ -249,7 +249,7 @@ HGLOBAL32 WINAPI LoadResource32( ...@@ -249,7 +249,7 @@ HGLOBAL32 WINAPI LoadResource32(
HINSTANCE32 hModule, /* [in] module handle */ HINSTANCE32 hModule, /* [in] module handle */
HRSRC32 hRsrc ) /* [in] resource 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", TRACE(resource, "module=%04x res=%04x\n",
hModule, hRsrc ); hModule, hRsrc );
...@@ -372,7 +372,7 @@ DWORD WINAPI SizeofResource16( HMODULE16 hModule, HRSRC16 hRsrc ) ...@@ -372,7 +372,7 @@ DWORD WINAPI SizeofResource16( HMODULE16 hModule, HRSRC16 hRsrc )
*/ */
DWORD WINAPI SizeofResource32( HINSTANCE32 hModule, HRSRC32 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 ); TRACE(resource, "module=%08x res=%08x\n", hModule, hRsrc );
if (!wm) return 0; if (!wm) return 0;
......
...@@ -242,16 +242,27 @@ static void TASK_CallToStart(void) ...@@ -242,16 +242,27 @@ static void TASK_CallToStart(void)
{ {
/* FIXME: all this is an ugly hack */ /* FIXME: all this is an ugly hack */
OFSTRUCT *ofs = (OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo);
LPTHREAD_START_ROUTINE entry = (LPTHREAD_START_ROUTINE) LPTHREAD_START_ROUTINE entry = (LPTHREAD_START_ROUTINE)
RVA_PTR(pModule->module32, OptionalHeader.AddressOfEntryPoint); 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) if (PE_HEADER(pModule->module32)->OptionalHeader.Subsystem==IMAGE_SUBSYSTEM_WINDOWS_CUI)
AllocConsole(); AllocConsole();
if (pModule->heap_size) if (pModule->heap_size)
LocalInit( pTask->hInstance, 0, 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 ); TRACE(relay, "(entryproc=%p)\n", entry );
#if 1 #if 1
......
...@@ -317,7 +317,7 @@ void THREAD_Start( THDB *thdb ) ...@@ -317,7 +317,7 @@ void THREAD_Start( THDB *thdb )
LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)thdb->entry_point; LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)thdb->entry_point;
assert( THREAD_Current() == thdb ); assert( THREAD_Current() == thdb );
CLIENT_InitThread(); CLIENT_InitThread();
MODULE_InitializeDLLs( thdb->process, 0, DLL_THREAD_ATTACH, NULL ); MODULE_InitializeDLLs( 0, DLL_THREAD_ATTACH, NULL );
ExitThread( func( thdb->entry_arg ) ); ExitThread( func( thdb->entry_arg ) );
} }
...@@ -362,7 +362,7 @@ void WINAPI ExitThread( ...@@ -362,7 +362,7 @@ void WINAPI ExitThread(
THDB *thdb = THREAD_Current(); THDB *thdb = THREAD_Current();
LONG count; LONG count;
MODULE_InitializeDLLs( thdb->process, 0, DLL_THREAD_DETACH, NULL ); MODULE_InitializeDLLs( 0, DLL_THREAD_DETACH, NULL );
SYSTEM_LOCK(); SYSTEM_LOCK();
thdb->exit_code = code; thdb->exit_code = code;
......
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