Commit 081ee941 authored by Alexandre Julliard's avatar Alexandre Julliard

- Fixed resource functions to work directly from the HMODULE instead of

requiring a modref. - Attempted to get LOAD_LIBRARY_AS_DATAFILE right (based on patches by Eric Pouech and Dusan Lacko). - Simplified modref structure and handling.
parent e6b51bf2
......@@ -12,7 +12,6 @@
#include "module.h"
#include "debugger.h"
#include "win.h"
#include "pe_image.h"
ldt_copy_entry ldt_copy[LDT_SIZE];
unsigned char ldt_flags_copy[LDT_SIZE];
......
......@@ -25,7 +25,6 @@
#endif
#include "debugger.h"
#include "neexe.h"
#include "pe_image.h"
#include "file.h"
typedef struct {
......
......@@ -17,7 +17,6 @@
#include <string.h>
#include <unistd.h>
#include "pe_image.h"
#include "debugger.h"
#define NR_TYPE_HASH 521
......
......@@ -5,8 +5,6 @@
#include "windef.h"
WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR libname, DWORD flags);
HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname);
void ELFDLL_UnloadLibrary(WINE_MODREF *wm);
#if defined(HAVE_DL_API)
......
......@@ -8,7 +8,7 @@
#define __WINE_MODULE_H
#include "windef.h"
#include "pe_image.h"
#include "winbase.h"
/* In-memory module structure. See 'Windows Internals' p. 219 */
typedef struct _NE_MODULE
......@@ -118,23 +118,15 @@ typedef struct
#include "poppack.h"
/* internal representation of 32bit modules. per process. */
typedef enum {
MODULE32_PE = 1,
MODULE32_ELF,
MODULE32_ELFDLL
} MODULE32_TYPE;
typedef struct _wine_modref
{
struct _wine_modref *next;
struct _wine_modref *prev;
MODULE32_TYPE type;
union {
PE_MODREF pe;
ELF_MODREF elf;
} binfmt;
struct _wine_modref *next;
struct _wine_modref *prev;
HMODULE module;
void *dlhandle; /* handle returned by dlopen() */
int tlsindex; /* TLS index or -1 if none */
HMODULE module;
FARPROC (*find_export)( struct _wine_modref *wm, LPCSTR func, BOOL snoop );
int nDeps;
struct _wine_modref **deps;
......@@ -151,12 +143,10 @@ typedef struct _wine_modref
#define WINE_MODREF_INTERNAL 0x00000001
#define WINE_MODREF_NO_DLL_CALLS 0x00000002
#define WINE_MODREF_PROCESS_ATTACHED 0x00000004
#define WINE_MODREF_LOAD_AS_DATAFILE 0x00000010
#define WINE_MODREF_DONT_RESOLVE_REFS 0x00000020
#define WINE_MODREF_MARKER 0x80000000
/* Resource types */
typedef struct resource_typeinfo_s NE_TYPEINFO;
typedef struct resource_nameinfo_s NE_NAMEINFO;
......@@ -170,9 +160,17 @@ typedef struct resource_nameinfo_s NE_NAMEINFO;
#define NE_MODULE_NAME(pModule) \
(((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
#define PE_HEADER(module) \
((IMAGE_NT_HEADERS*)((LPBYTE)(module) + \
(((IMAGE_DOS_HEADER*)(module))->e_lfanew)))
#define PE_SECTIONS(module) \
((IMAGE_SECTION_HEADER*)((LPBYTE)&PE_HEADER(module)->OptionalHeader + \
PE_HEADER(module)->FileHeader.SizeOfOptionalHeader))
/* module.c */
extern WINE_MODREF *MODULE_AllocModRef( HMODULE hModule, LPCSTR filename );
extern FARPROC MODULE_GetProcAddress( HMODULE hModule, LPCSTR function, BOOL snoop );
extern WINE_MODREF *MODULE32_LookupHMODULE( HMODULE hModule );
extern BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved );
extern void MODULE_DllProcessDetach( BOOL bForceDetach, LPVOID lpReserved );
extern void MODULE_DllThreadAttach( LPVOID lpReserved );
......@@ -223,10 +221,27 @@ extern void NE_DllProcessAttach( HMODULE16 hModule );
/* loader/ne/convert.c */
HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size );
/* loader/pe_resource.c */
extern HRSRC PE_FindResourceExW(HMODULE,LPCWSTR,LPCWSTR,WORD);
extern DWORD PE_SizeofResource(HMODULE,HRSRC);
extern HGLOBAL PE_LoadResource(HMODULE,HRSRC);
extern PIMAGE_RESOURCE_DIRECTORY GetResDirEntryA(PIMAGE_RESOURCE_DIRECTORY,LPCSTR,DWORD,BOOL);
extern PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY,LPCWSTR,DWORD,BOOL);
/* loader/pe_image.c */
extern WINE_MODREF *PE_LoadLibraryExA(LPCSTR, DWORD);
extern HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, DWORD flags );
extern WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename,
DWORD flags, HFILE hFile, BOOL builtin );
extern void PE_InitTls(void);
extern BOOL PE_InitDLL( HMODULE module, DWORD type, LPVOID lpReserved );
/* loader/elf.c */
extern WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags);
/* relay32/builtin.c */
extern WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR name, DWORD flags);
extern HMODULE BUILTIN32_LoadExeModule(void);
extern void BUILTIN32_UnloadLibrary(WINE_MODREF *wm);
extern void *BUILTIN32_dlopen( const char *name );
extern int BUILTIN32_dlclose( void *handle );
......
#ifndef __WINE_PE_IMAGE_H
#define __WINE_PE_IMAGE_H
#include "windef.h"
#include "winbase.h"
#define PE_HEADER(module) \
((IMAGE_NT_HEADERS*)((LPBYTE)(module) + \
(((IMAGE_DOS_HEADER*)(module))->e_lfanew)))
#define PE_SECTIONS(module) \
((IMAGE_SECTION_HEADER*)((LPBYTE)&PE_HEADER(module)->OptionalHeader + \
PE_HEADER(module)->FileHeader.SizeOfOptionalHeader))
#define RVA_PTR(module,field) ((LPBYTE)(module) + PE_HEADER(module)->field)
/* modreference used for attached processes
* all section are calculated here, relocations etc.
*/
typedef struct {
PIMAGE_IMPORT_DESCRIPTOR pe_import;
PIMAGE_EXPORT_DIRECTORY pe_export;
PIMAGE_RESOURCE_DIRECTORY pe_resource;
int tlsindex;
} PE_MODREF;
struct _wine_modref;
extern int PE_unloadImage(HMODULE hModule);
extern FARPROC PE_FindExportedFunction(struct _wine_modref *wm, LPCSTR funcName, BOOL snoop);
extern BOOL PE_EnumResourceTypesA(HMODULE,ENUMRESTYPEPROCA,LONG);
extern BOOL PE_EnumResourceTypesW(HMODULE,ENUMRESTYPEPROCW,LONG);
extern BOOL PE_EnumResourceNamesA(HMODULE,LPCSTR,ENUMRESNAMEPROCA,LONG);
extern BOOL PE_EnumResourceNamesW(HMODULE,LPCWSTR,ENUMRESNAMEPROCW,LONG);
extern BOOL PE_EnumResourceLanguagesA(HMODULE,LPCSTR,LPCSTR,ENUMRESLANGPROCA,LONG);
extern BOOL PE_EnumResourceLanguagesW(HMODULE,LPCWSTR,LPCWSTR,ENUMRESLANGPROCW,LONG);
extern HRSRC PE_FindResourceExW(struct _wine_modref*,LPCWSTR,LPCWSTR,WORD);
extern DWORD PE_SizeofResource(HMODULE,HRSRC);
extern struct _wine_modref *PE_LoadLibraryExA(LPCSTR, DWORD);
extern void PE_UnloadLibrary(struct _wine_modref *);
extern HGLOBAL PE_LoadResource(struct _wine_modref *wm,HRSRC);
extern HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename );
extern struct _wine_modref *PE_CreateModule( HMODULE hModule, LPCSTR filename,
DWORD flags, BOOL builtin );
extern void PE_InitTls(void);
extern BOOL PE_InitDLL(struct _wine_modref *wm, DWORD type, LPVOID lpReserved);
extern PIMAGE_RESOURCE_DIRECTORY GetResDirEntryA(PIMAGE_RESOURCE_DIRECTORY,LPCSTR,DWORD,BOOL);
extern PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY,LPCWSTR,DWORD,BOOL);
typedef DWORD CALLBACK(*DLLENTRYPROC)(HMODULE,DWORD,LPVOID);
typedef struct {
WORD popl WINE_PACKED; /* 0x8f 0x05 */
DWORD addr_popped WINE_PACKED;/* ... */
BYTE pushl1 WINE_PACKED; /* 0x68 */
DWORD newret WINE_PACKED; /* ... */
BYTE pushl2 WINE_PACKED; /* 0x68 */
DWORD origfun WINE_PACKED; /* original function */
BYTE ret1 WINE_PACKED; /* 0xc3 */
WORD addesp WINE_PACKED; /* 0x83 0xc4 */
BYTE nrofargs WINE_PACKED; /* nr of arguments to add esp, */
BYTE pushl3 WINE_PACKED; /* 0x68 */
DWORD oldret WINE_PACKED; /* Filled out from popl above */
BYTE ret2 WINE_PACKED; /* 0xc3 */
} ELF_STDCALL_STUB;
typedef struct {
void* dlhandle;
ELF_STDCALL_STUB *stubs;
} ELF_MODREF;
extern struct _wine_modref *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags);
extern void ELF_UnloadLibrary(struct _wine_modref *);
extern FARPROC ELF_FindExportedFunction(struct _wine_modref *wm, LPCSTR funcName);
#endif /* __WINE_PE_IMAGE_H */
......@@ -21,46 +21,51 @@
#include "neexe.h"
#include "heap.h"
#include "module.h"
#include "pe_image.h"
#include "debugtools.h"
#include "winerror.h"
#include "elfdll.h"
DEFAULT_DEBUG_CHANNEL(win32)
#if defined(HAVE_DL_API)
DEFAULT_DEBUG_CHANNEL(win32);
#ifdef HAVE_DL_API
typedef struct {
WORD popl WINE_PACKED; /* 0x8f 0x05 */
DWORD addr_popped WINE_PACKED;/* ... */
BYTE pushl1 WINE_PACKED; /* 0x68 */
DWORD newret WINE_PACKED; /* ... */
BYTE pushl2 WINE_PACKED; /* 0x68 */
DWORD origfun WINE_PACKED; /* original function */
BYTE ret1 WINE_PACKED; /* 0xc3 */
WORD addesp WINE_PACKED; /* 0x83 0xc4 */
BYTE nrofargs WINE_PACKED; /* nr of arguments to add esp, */
BYTE pushl3 WINE_PACKED; /* 0x68 */
DWORD oldret WINE_PACKED; /* Filled out from popl above */
BYTE ret2 WINE_PACKED; /* 0xc3 */
} ELF_STDCALL_STUB;
#define UNIX_DLL_ENDING "so"
#define STUBSIZE 4095
#define STUBOFFSET (sizeof(IMAGE_DOS_HEADER) + \
sizeof(IMAGE_NT_HEADERS) + \
sizeof(IMAGE_SECTION_HEADER))
#include <dlfcn.h>
static FARPROC ELF_FindExportedFunction( WINE_MODREF *wm, LPCSTR funcName, BOOL snoop );
static WINE_MODREF *ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname )
static HMODULE ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname )
{
PIMAGE_DOS_HEADER dh;
PIMAGE_NT_HEADERS nth;
PIMAGE_SECTION_HEADER sh;
WINE_MODREF *wm;
HMODULE hmod;
wm=(WINE_MODREF*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wm) );
wm->type = MODULE32_ELF;
/* FIXME: hmm, order? */
wm->next = PROCESS_Current()->modref_list;
PROCESS_Current()->modref_list = wm;
wm->modname = HEAP_strdupA( GetProcessHeap(), 0, modname );
wm->filename = HEAP_strdupA( GetProcessHeap(), 0, libname );
wm->short_modname = wm->modname;
wm->short_filename = wm->filename;
hmod = (HMODULE)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(IMAGE_DOS_HEADER) +
sizeof(IMAGE_NT_HEADERS) +
sizeof(IMAGE_SECTION_HEADER) + 100 );
sizeof(IMAGE_SECTION_HEADER) + STUBSIZE );
dh = (PIMAGE_DOS_HEADER)hmod;
dh->e_magic = IMAGE_DOS_SIGNATURE;
dh->e_lfanew = sizeof(IMAGE_DOS_HEADER);
......@@ -92,18 +97,18 @@ static WINE_MODREF *ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname )
*/
sh=(PIMAGE_SECTION_HEADER)(nth+1);
strcpy(sh->Name,".text");
sh->Misc.VirtualSize = 0x7fffffff;
sh->VirtualAddress = 0x42; /* so snoop can use it ... */
sh->SizeOfRawData = 0x7fffffff;
sh->Misc.VirtualSize = STUBSIZE;
sh->VirtualAddress = STUBOFFSET; /* so snoop can use it ... */
sh->SizeOfRawData = STUBSIZE;
sh->PointerToRawData = 0;
sh->Characteristics = IMAGE_SCN_CNT_CODE|IMAGE_SCN_CNT_INITIALIZED_DATA|IMAGE_SCN_MEM_EXECUTE|IMAGE_SCN_MEM_READ;
wm->module = hmod;
return wm;
return hmod;
}
WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags)
{
WINE_MODREF *wm;
HMODULE hmod;
char *modname,*s,*t,*x;
LPVOID *dlhandle;
......@@ -149,29 +154,31 @@ WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags)
return NULL;
}
wm = ELF_CreateDummyModule( t, modname );
wm->binfmt.elf.dlhandle = dlhandle;
hmod = ELF_CreateDummyModule( t, modname );
SNOOP_RegisterDLL(wm->module,libname,STUBSIZE/sizeof(ELF_STDCALL_STUB));
SNOOP_RegisterDLL(hmod,libname,STUBSIZE/sizeof(ELF_STDCALL_STUB));
wm = PE_CreateModule( hmod, modname, 0, -1, FALSE );
wm->find_export = ELF_FindExportedFunction;
wm->dlhandle = dlhandle;
return wm;
}
FARPROC ELF_FindExportedFunction( WINE_MODREF *wm, LPCSTR funcName)
static FARPROC ELF_FindExportedFunction( WINE_MODREF *wm, LPCSTR funcName, BOOL snoop )
{
LPVOID fun;
int i,nrofargs = 0;
ELF_STDCALL_STUB *stub;
ELF_STDCALL_STUB *stub, *first_stub;
assert(wm->type == MODULE32_ELF);
if (!HIWORD(funcName)) {
ERR("Can't import from UNIX dynamic libs by ordinal, sorry.\n");
return (FARPROC)0;
}
fun = dlsym(wm->binfmt.elf.dlhandle,funcName);
fun = dlsym(wm->dlhandle,funcName);
/* we sometimes have an excess '_' at the beginning of the name */
if (!fun && (funcName[0]=='_')) {
funcName++ ;
fun = dlsym(wm->binfmt.elf.dlhandle,funcName);
fun = dlsym(wm->dlhandle,funcName);
}
if (!fun) {
/* Function@nrofargs usually marks a stdcall function
......@@ -184,7 +191,7 @@ FARPROC ELF_FindExportedFunction( WINE_MODREF *wm, LPCSTR funcName)
*t = '\0';
nrofargs = 0;
sscanf(t+1,"%d",&nrofargs);
fun = dlsym(wm->binfmt.elf.dlhandle,fn);
fun = dlsym(wm->dlhandle,fn);
HeapFree( GetProcessHeap(), 0, fn );
}
}
......@@ -192,12 +199,7 @@ FARPROC ELF_FindExportedFunction( WINE_MODREF *wm, LPCSTR funcName)
* dlls using cdecl. If we find out the number of args the function
* uses, we remove them from the stack using two small stubs.
*/
if (!wm->binfmt.elf.stubs) {
/* one page should suffice */
wm->binfmt.elf.stubs = VirtualAlloc(NULL,STUBSIZE,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);
memset(wm->binfmt.elf.stubs,0,STUBSIZE);
}
stub = wm->binfmt.elf.stubs;
stub = first_stub = (ELF_STDCALL_STUB *)((char *)wm->module + STUBOFFSET);
for (i=0;i<STUBSIZE/sizeof(ELF_STDCALL_STUB);i++) {
if (!stub->origfun)
break;
......@@ -252,35 +254,15 @@ FARPROC ELF_FindExportedFunction( WINE_MODREF *wm, LPCSTR funcName)
FIXME("function %s not found: %s\n",funcName,dlerror());
return fun;
}
fun = SNOOP_GetProcAddress(wm->module,funcName,stub-wm->binfmt.elf.stubs,fun);
fun = SNOOP_GetProcAddress(wm->module,funcName,stub-first_stub,fun);
return (FARPROC)fun;
}
/***************************************************************************
* ELF_UnloadLibrary
*
* Unload the elf library and free the modref
*/
void ELF_UnloadLibrary(WINE_MODREF *wm)
{
/* FIXME: do something here */
}
#else
#else /* HAVE_DL_API */
WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags)
{
return NULL;
}
void ELF_UnloadLibrary(WINE_MODREF *wm)
{
}
FARPROC ELF_FindExportedFunction( WINE_MODREF *wm, LPCSTR funcName)
{
return (FARPROC)0;
}
#endif
#endif /* HAVE_DL_API */
......@@ -149,139 +149,6 @@ static LPSTR get_sobasename(LPCSTR path, LPSTR name)
/****************************************************************************
* ELFDLL_CreateModref (internal)
*
* INPUT
* hModule - the header from the elf-dll's data-segment
* path - requested path from original call
*
* OUTPUT
* A WINE_MODREF pointer to the new object
*
* BUGS
* - Does not handle errors due to dependencies correctly
* - path can be wrong
*/
#define RVA(base, va) (((DWORD)base) + ((DWORD)va))
static WINE_MODREF *ELFDLL_CreateModref(HMODULE hModule, LPCSTR path)
{
IMAGE_NT_HEADERS *nt = PE_HEADER(hModule);
IMAGE_DATA_DIRECTORY *dir;
IMAGE_IMPORT_DESCRIPTOR *pe_import = NULL;
WINE_MODREF *wm;
int len;
HANDLE procheap = GetProcessHeap();
wm = (WINE_MODREF *)HeapAlloc(procheap, HEAP_ZERO_MEMORY, sizeof(*wm));
if(!wm)
return NULL;
wm->module = hModule;
wm->type = MODULE32_PE; /* FIXME */
dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_EXPORT;
if(dir->Size)
wm->binfmt.pe.pe_export = (PIMAGE_EXPORT_DIRECTORY)RVA(hModule, dir->VirtualAddress);
dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_IMPORT;
if(dir->Size)
pe_import = wm->binfmt.pe.pe_import = (PIMAGE_IMPORT_DESCRIPTOR)RVA(hModule, dir->VirtualAddress);
dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_RESOURCE;
if(dir->Size)
wm->binfmt.pe.pe_resource = (PIMAGE_RESOURCE_DIRECTORY)RVA(hModule, dir->VirtualAddress);
wm->filename = HEAP_strdupA( procheap, 0, path );
wm->modname = strrchr( wm->filename, '\\' );
if (!wm->modname) wm->modname = wm->filename;
else wm->modname++;
len = GetShortPathNameA( wm->filename, NULL, 0 );
wm->short_filename = (char *)HeapAlloc( procheap, 0, len+1 );
GetShortPathNameA( wm->filename, wm->short_filename, len+1 );
wm->short_modname = strrchr( wm->short_filename, '\\' );
if (!wm->short_modname) wm->short_modname = wm->short_filename;
else wm->short_modname++;
/* Link MODREF into process list */
EnterCriticalSection( &PROCESS_Current()->crit_section );
wm->next = PROCESS_Current()->modref_list;
PROCESS_Current()->modref_list = wm;
if ( wm->next ) wm->next->prev = wm;
if ( !( nt->FileHeader.Characteristics & IMAGE_FILE_DLL )
&& !( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE ) )
{
if ( PROCESS_Current()->exe_modref )
FIXME( "Trying to load second .EXE file: %s\n", path );
else
PROCESS_Current()->exe_modref = wm;
}
LeaveCriticalSection( &PROCESS_Current()->crit_section );
/* Fixup Imports */
if ( pe_import
&& !( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE )
&& !( wm->flags & WINE_MODREF_DONT_RESOLVE_REFS )
&& fixup_imports( wm ) )
{
/* remove entry from modref chain */
EnterCriticalSection( &PROCESS_Current()->crit_section );
if ( !wm->prev )
PROCESS_Current()->modref_list = wm->next;
else
wm->prev->next = wm->next;
if ( wm->next ) wm->next->prev = wm->prev;
wm->next = wm->prev = NULL;
LeaveCriticalSection( &PROCESS_Current()->crit_section );
/* FIXME: there are several more dangling references
* left. Including dlls loaded by this dll before the
* failed one. Unrolling is rather difficult with the
* current structure and we can leave it them lying
* around with no problems, so we don't care.
* As these might reference our wm, we don't free it.
*/
return NULL;
}
return wm;
}
/***********************************************************************
* ELFDLL_CreateNEModule
*
* Create a dummy NE module for the win32 elf-dll based on the supplied
* NE header in the elf-dll.
*/
static HMODULE16 ELFDLL_CreateNEModule(NE_MODULE *ne_image, DWORD size)
{
NE_MODULE *pModule;
HMODULE16 hModule = GLOBAL_CreateBlock(GMEM_MOVEABLE, ne_image, size, 0,
FALSE, FALSE, FALSE, NULL);
if(!hModule)
return (HMODULE16)0;
FarSetOwner16(hModule, hModule);
pModule = (NE_MODULE *)GlobalLock16(hModule);
pModule->self = hModule;
NE_RegisterModule(pModule);
return hModule;
}
/****************************************************************************
* ELFDLL_LoadLibraryExA (internal)
*
* Implementation of elf-dll loading for PE modules
......@@ -292,7 +159,6 @@ WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR path, DWORD flags)
struct elfdll_image *image;
char name[129];
char soname[129];
HMODULE16 hmod16;
WINE_MODREF *wm;
get_sobasename(path, name);
......@@ -320,53 +186,20 @@ WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR path, DWORD flags)
return NULL;
}
/* Create a win16 dummy module */
hmod16 = ELFDLL_CreateNEModule(image->ne_module_start, image->ne_module_size);
if(!hmod16)
{
ERR("Could not create win16 dummy module for %s\n", path);
dlclose(dlhandle);
SetLastError( ERROR_OUTOFMEMORY );
return NULL;
}
image->ne_module_start->module32 = image->pe_module_start;
wm = ELFDLL_CreateModref(image->pe_module_start, path);
wm = PE_CreateModule( image->pe_module_start, path, 0, -1, FALSE );
if(!wm)
{
ERR("Could not create WINE_MODREF for %s\n", path);
GLOBAL_FreeBlock((HGLOBAL16)hmod16);
dlclose(dlhandle);
SetLastError( ERROR_OUTOFMEMORY );
return NULL;
}
wm->dlhandle = dlhandle;
dump_exports(image->pe_module_start);
return wm;
}
/****************************************************************************
* ELFDLL_UnloadLibrary (internal)
*
* Unload an elf-dll completely from memory and deallocate the modref
*/
void ELFDLL_UnloadLibrary(WINE_MODREF *wm)
{
}
/****************************************************************************
* ELFDLL_LoadModule16 (internal)
*
* Implementation of elf-dll loading for NE modules
*/
HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname)
{
return (HINSTANCE16)ERROR_FILE_NOT_FOUND;
}
#else
/*
......@@ -380,13 +213,4 @@ WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR libname, DWORD flags)
return NULL;
}
void ELFDLL_UnloadLibrary(WINE_MODREF *wm)
{
}
HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname)
{
return (HINSTANCE16)ERROR_FILE_NOT_FOUND;
}
#endif
......@@ -20,7 +20,6 @@
#include "module.h"
#include "snoop.h"
#include "neexe.h"
#include "pe_image.h"
#include "dosexe.h"
#include "process.h"
#include "syslevel.h"
......@@ -41,8 +40,9 @@ DECLARE_DEBUG_CHANNEL(win32);
/*************************************************************************
* MODULE32_LookupHMODULE
* looks for the referenced HMODULE in the current process
* NOTE: Assumes that the process critical section is held!
*/
WINE_MODREF *MODULE32_LookupHMODULE( HMODULE hmod )
static WINE_MODREF *MODULE32_LookupHMODULE( HMODULE hmod )
{
WINE_MODREF *wm;
......@@ -51,15 +51,50 @@ WINE_MODREF *MODULE32_LookupHMODULE( HMODULE hmod )
if (!HIWORD(hmod)) {
ERR("tried to lookup 0x%04x in win32 module handler!\n",hmod);
SetLastError( ERROR_INVALID_HANDLE );
return NULL;
}
for ( wm = PROCESS_Current()->modref_list; wm; wm=wm->next )
if (wm->module == hmod)
return wm;
SetLastError( ERROR_INVALID_HANDLE );
return NULL;
}
/*************************************************************************
* MODULE_AllocModRef
*
* Allocate a WINE_MODREF structure and add it to the process list
* NOTE: Assumes that the process critical section is held!
*/
WINE_MODREF *MODULE_AllocModRef( HMODULE hModule, LPCSTR filename )
{
WINE_MODREF *wm;
DWORD len;
if ((wm = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wm) )))
{
wm->module = hModule;
wm->tlsindex = -1;
wm->filename = HEAP_strdupA( GetProcessHeap(), 0, filename );
if ((wm->modname = strrchr( wm->filename, '\\' ))) wm->modname++;
else wm->modname = wm->filename;
len = GetShortPathNameA( wm->filename, NULL, 0 );
wm->short_filename = (char *)HeapAlloc( GetProcessHeap(), 0, len+1 );
GetShortPathNameA( wm->filename, wm->short_filename, len+1 );
if ((wm->short_modname = strrchr( wm->short_filename, '\\' ))) wm->short_modname++;
else wm->short_modname = wm->short_filename;
wm->next = PROCESS_Current()->modref_list;
if (wm->next) wm->next->prev = wm;
PROCESS_Current()->modref_list = wm;
}
return wm;
}
/*************************************************************************
* MODULE_InitDLL
*/
static BOOL MODULE_InitDLL( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
......@@ -70,32 +105,14 @@ static BOOL MODULE_InitDLL( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
"THREAD_ATTACH", "THREAD_DETACH" };
assert( wm );
/* Skip calls for modules loaded with special load flags */
if ( ( wm->flags & WINE_MODREF_DONT_RESOLVE_REFS )
|| ( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE ) )
return TRUE;
if (wm->flags & WINE_MODREF_DONT_RESOLVE_REFS) return TRUE;
TRACE("(%s,%s,%p) - CALL\n", wm->modname, typeName[type], lpReserved );
/* Call the initialization routine */
switch ( wm->type )
{
case MODULE32_PE:
retv = PE_InitDLL( wm, type, lpReserved );
break;
case MODULE32_ELF:
/* no need to do that, dlopen() already does */
break;
default:
ERR("wine_modref type %d not handled.\n", wm->type );
retv = FALSE;
break;
}
retv = PE_InitDLL( wm->module, type, lpReserved );
/* The state of the module list may have changed due to the call
to PE_InitDLL. We cannot assume that this module has not been
......@@ -626,13 +643,13 @@ BOOL MODULE_GetBinaryType( HANDLE hfile, LPCSTR filename, LPDWORD lpBinaryType )
ptr = strrchr( filename, '.' );
if ( ptr && !strchr( ptr, '\\' ) && !strchr( ptr, '/' ) )
{
if ( !lstrcmpiA( ptr, ".COM" ) )
if ( !strcasecmp( ptr, ".COM" ) )
{
*lpBinaryType = SCS_DOS_BINARY;
return TRUE;
}
if ( !lstrcmpiA( ptr, ".PIF" ) )
if ( !strcasecmp( ptr, ".PIF" ) )
{
*lpBinaryType = SCS_PIF_BINARY;
return TRUE;
......@@ -1152,15 +1169,17 @@ HMODULE WINAPI GetModuleHandleW(LPCWSTR module)
DWORD WINAPI GetModuleFileNameA(
HMODULE hModule, /* [in] module handle (32bit) */
LPSTR lpFileName, /* [out] filenamebuffer */
DWORD size /* [in] size of filenamebuffer */
) {
WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
DWORD size ) /* [in] size of filenamebuffer */
{
WINE_MODREF *wm;
EnterCriticalSection( &PROCESS_Current()->crit_section );
if (!wm) /* can happen on start up or the like */
return 0;
lpFileName[0] = 0;
if ((wm = MODULE32_LookupHMODULE( hModule )))
lstrcpynA( lpFileName, wm->filename, size );
lstrcpynA( lpFileName, wm->filename, size );
LeaveCriticalSection( &PROCESS_Current()->crit_section );
TRACE("%s\n", lpFileName );
return strlen(lpFileName);
}
......@@ -1193,6 +1212,25 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
return 0;
}
if (flags & LOAD_LIBRARY_AS_DATAFILE)
{
char filename[256];
HFILE hFile;
HMODULE hmod = 0;
if (!SearchPathA( NULL, libname, ".dll", sizeof(filename), filename, NULL ))
return 0;
/* FIXME: maybe we should use the hfile parameter instead */
hFile = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, -1 );
if (hFile != INVALID_HANDLE_VALUE)
{
hmod = PE_LoadImage( hFile, filename, flags );
CloseHandle( hFile );
}
return hmod;
}
EnterCriticalSection(&PROCESS_Current()->crit_section);
wm = MODULE_LoadLibraryExA( libname, hfile, flags );
......@@ -1237,6 +1275,14 @@ WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags )
{
if(!(pwm->flags & WINE_MODREF_MARKER))
pwm->refCount++;
if ((pwm->flags & WINE_MODREF_DONT_RESOLVE_REFS) &&
!(flags & DONT_RESOLVE_DLL_REFERENCES))
{
extern DWORD fixup_imports(WINE_MODREF *wm); /*FIXME*/
pwm->flags &= ~WINE_MODREF_DONT_RESOLVE_REFS;
fixup_imports( pwm );
}
TRACE("Already loaded module '%s' at 0x%08x, count=%d, \n", libname, pwm->module, pwm->refCount);
LeaveCriticalSection(&PROCESS_Current()->crit_section);
return pwm;
......@@ -1371,23 +1417,12 @@ static void MODULE_FlushModrefs(void)
if(wm == PROCESS_Current()->modref_list)
PROCESS_Current()->modref_list = wm->next;
/*
* The unloaders are also responsible for freeing the modref itself
* because the loaders were responsible for allocating it.
*/
switch(wm->type)
{
case MODULE32_PE: if ( !(wm->flags & WINE_MODREF_INTERNAL) )
PE_UnloadLibrary(wm);
else
BUILTIN32_UnloadLibrary(wm);
break;
case MODULE32_ELF: ELF_UnloadLibrary(wm); break;
case MODULE32_ELFDLL: ELFDLL_UnloadLibrary(wm); break;
default:
ERR("Invalid or unhandled MODREF type %d encountered (wm=%p)\n", wm->type, wm);
}
TRACE(" unloading %s\n", wm->filename);
/* VirtualFree( (LPVOID)wm->module, 0, MEM_RELEASE ); */ /* FIXME */
/* if (wm->dlhandle) dlclose( wm->dlhandle ); */ /* FIXME */
HeapFree( GetProcessHeap(), 0, wm->filename );
HeapFree( GetProcessHeap(), 0, wm->short_filename );
HeapFree( GetProcessHeap(), 0, wm );
}
}
......@@ -1592,32 +1627,22 @@ FARPROC MODULE_GetProcAddress(
LPCSTR function, /* [in] function to be looked up */
BOOL snoop )
{
WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
FARPROC retproc;
WINE_MODREF *wm;
FARPROC retproc = 0;
if (HIWORD(function))
TRACE_(win32)("(%08lx,%s)\n",(DWORD)hModule,function);
else
TRACE_(win32)("(%08lx,%p)\n",(DWORD)hModule,function);
if (!wm) {
SetLastError(ERROR_INVALID_HANDLE);
return (FARPROC)0;
}
switch (wm->type)
EnterCriticalSection( &PROCESS_Current()->crit_section );
if ((wm = MODULE32_LookupHMODULE( hModule )))
{
case MODULE32_PE:
retproc = PE_FindExportedFunction( wm, function, snoop );
if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
return retproc;
case MODULE32_ELF:
retproc = ELF_FindExportedFunction( wm, function);
if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
return retproc;
default:
ERR("wine_modref type %d not handled.\n",wm->type);
SetLastError(ERROR_INVALID_HANDLE);
return (FARPROC)0;
retproc = wm->find_export( wm, function, snoop );
if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
}
LeaveCriticalSection( &PROCESS_Current()->crit_section );
return retproc;
}
......
......@@ -920,11 +920,6 @@ static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_
hinst = NE_LoadModule(libname, lib_only);
break;
case MODULE_LOADORDER_ELFDLL:
TRACE("Trying elfdll '%s'\n", libname);
hinst = ELFDLL_LoadModule16(libname);
break;
case MODULE_LOADORDER_BI:
TRACE("Trying built-in '%s'\n", libname);
hinst = BUILTIN_LoadModule(libname);
......@@ -935,6 +930,7 @@ static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_
/* Fall through */
case MODULE_LOADORDER_SO: /* This is not supported for NE modules */
case MODULE_LOADORDER_ELFDLL: /* This is not supported for NE modules */
case MODULE_LOADORDER_INVALID: /* We ignore this as it is an empty entry */
hinst = 2;
break;
......
......@@ -134,8 +134,6 @@ static HRSRC RES_FindResource2( HMODULE hModule, LPCSTR type,
HRSRC hRsrc = 0;
HMODULE16 hMod16 = MapHModuleLS( hModule );
NE_MODULE *pModule = NE_GetPtr( hMod16 );
WINE_MODREF *wm = pModule && pModule->module32?
MODULE32_LookupHMODULE( pModule->module32 ) : NULL;
TRACE("(%08x %s, %08x%s, %08x%s, %04x, %s, %s)\n",
hModule,
......@@ -148,7 +146,7 @@ static HRSRC RES_FindResource2( HMODULE hModule, LPCSTR type,
if (pModule)
{
if ( wm )
if (pModule->module32)
{
/* 32-bit PE module */
LPWSTR typeStr, nameStr;
......@@ -162,7 +160,7 @@ static HRSRC RES_FindResource2( HMODULE hModule, LPCSTR type,
else
nameStr = (LPWSTR)name;
hRsrc = PE_FindResourceExW( wm, nameStr, typeStr, lang );
hRsrc = PE_FindResourceExW( pModule->module32, nameStr, typeStr, lang );
if ( HIWORD( type ) && !bUnicode )
HeapFree( GetProcessHeap(), 0, typeStr );
......@@ -236,15 +234,13 @@ static DWORD RES_SizeofResource( HMODULE hModule, HRSRC hRsrc, BOOL bRet16 )
HMODULE16 hMod16 = MapHModuleLS( hModule );
NE_MODULE *pModule = NE_GetPtr( hMod16 );
WINE_MODREF *wm = pModule && pModule->module32?
MODULE32_LookupHMODULE( pModule->module32 ) : NULL;
TRACE("(%08x %s, %08x, %s)\n",
hModule, NE_MODULE_NAME(pModule), hRsrc, bRet16? "NE" : "PE" );
if ( !pModule || !hRsrc ) return 0;
if ( wm )
if (pModule->module32)
{
/* 32-bit PE module */
......@@ -274,15 +270,13 @@ static HFILE RES_AccessResource( HMODULE hModule, HRSRC hRsrc, BOOL bRet16 )
HMODULE16 hMod16 = MapHModuleLS( hModule );
NE_MODULE *pModule = NE_GetPtr( hMod16 );
WINE_MODREF *wm = pModule && pModule->module32?
MODULE32_LookupHMODULE( pModule->module32 ) : NULL;
TRACE("(%08x %s, %08x, %s)\n",
hModule, NE_MODULE_NAME(pModule), hRsrc, bRet16? "NE" : "PE" );
if ( !pModule || !hRsrc ) return HFILE_ERROR;
if ( wm )
if (pModule->module32)
{
/* 32-bit PE module */
#if 0
......@@ -322,22 +316,20 @@ static HGLOBAL RES_LoadResource( HMODULE hModule, HRSRC hRsrc, BOOL bRet16 )
HMODULE16 hMod16 = MapHModuleLS( hModule );
NE_MODULE *pModule = NE_GetPtr( hMod16 );
WINE_MODREF *wm = pModule && pModule->module32?
MODULE32_LookupHMODULE( pModule->module32 ) : NULL;
TRACE("(%08x %s, %08x, %s)\n",
hModule, NE_MODULE_NAME(pModule), hRsrc, bRet16? "NE" : "PE" );
if ( !pModule || !hRsrc ) return 0;
if ( wm )
if (pModule->module32)
{
/* 32-bit PE module */
/* If we got a 16-bit hRsrc, convert it */
HRSRC hRsrc32 = HIWORD(hRsrc)? hRsrc : MapHRsrc16To32( pModule, hRsrc );
hMem = PE_LoadResource( wm, hRsrc32 );
hMem = PE_LoadResource( pModule->module32, hRsrc32 );
/* If we need to return a 16-bit resource, convert it */
if ( bRet16 )
......@@ -567,65 +559,3 @@ DWORD WINAPI SizeofResource( HINSTANCE hModule, HRSRC hRsrc )
{
return RES_SizeofResource( hModule, hRsrc, FALSE );
}
/**********************************************************************
* EnumResourceTypesA (KERNEL32.90)
*/
BOOL WINAPI EnumResourceTypesA( HMODULE hmodule,ENUMRESTYPEPROCA lpfun,
LONG lParam)
{
/* FIXME: move WINE_MODREF stuff here */
return PE_EnumResourceTypesA(hmodule,lpfun,lParam);
}
/**********************************************************************
* EnumResourceTypesW (KERNEL32.91)
*/
BOOL WINAPI EnumResourceTypesW( HMODULE hmodule,ENUMRESTYPEPROCW lpfun,
LONG lParam)
{
/* FIXME: move WINE_MODREF stuff here */
return PE_EnumResourceTypesW(hmodule,lpfun,lParam);
}
/**********************************************************************
* EnumResourceNamesA (KERNEL32.88)
*/
BOOL WINAPI EnumResourceNamesA( HMODULE hmodule, LPCSTR type,
ENUMRESNAMEPROCA lpfun, LONG lParam )
{
/* FIXME: move WINE_MODREF stuff here */
return PE_EnumResourceNamesA(hmodule,type,lpfun,lParam);
}
/**********************************************************************
* EnumResourceNamesW (KERNEL32.89)
*/
BOOL WINAPI EnumResourceNamesW( HMODULE hmodule, LPCWSTR type,
ENUMRESNAMEPROCW lpfun, LONG lParam )
{
/* FIXME: move WINE_MODREF stuff here */
return PE_EnumResourceNamesW(hmodule,type,lpfun,lParam);
}
/**********************************************************************
* EnumResourceLanguagesA (KERNEL32.86)
*/
BOOL WINAPI EnumResourceLanguagesA( HMODULE hmodule, LPCSTR type,
LPCSTR name, ENUMRESLANGPROCA lpfun,
LONG lParam)
{
/* FIXME: move WINE_MODREF stuff here */
return PE_EnumResourceLanguagesA(hmodule,type,name,lpfun,lParam);
}
/**********************************************************************
* EnumResourceLanguagesW (KERNEL32.87)
*/
BOOL WINAPI EnumResourceLanguagesW( HMODULE hmodule, LPCWSTR type,
LPCWSTR name, ENUMRESLANGPROCW lpfun,
LONG lParam)
{
/* FIXME: move WINE_MODREF stuff here */
return PE_EnumResourceLanguagesW(hmodule,type,name,lpfun,lParam);
}
......@@ -19,7 +19,6 @@
#include "miscemu.h"
#include "module.h"
#include "neexe.h"
#include "pe_image.h"
#include "process.h"
#include "queue.h"
#include "selectors.h"
......
......@@ -98,7 +98,6 @@ static char * special_dlls[] =
"COMDLG32",
"COMCTL32",
"SHELL32",
"USER32",
"OLE32",
"RPCRT4",
NULL
......@@ -161,29 +160,28 @@ void VERSION_ParseDosVersion( const char *arg )
* shell32.
* If you have a better idea to figure this out...
*/
DWORD VERSION_GetSystemDLLVersion (WINE_MODREF * wm)
static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
{
PE_MODREF * pem = &(wm->binfmt.pe);
if (pem->pe_import)
{
IMAGE_IMPORT_DESCRIPTOR * pe_imp;
for ( pe_imp = pem->pe_import; pe_imp->Name; pe_imp++)
{
char * name = (char*)((unsigned int)wm->module+(unsigned int)(pe_imp->Name));
IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
+ IMAGE_DIRECTORY_ENTRY_IMPORT;
if (dir->Size && dir->VirtualAddress)
{
IMAGE_IMPORT_DESCRIPTOR *pe_imp = (IMAGE_IMPORT_DESCRIPTOR *)((char *)hmod + dir->VirtualAddress);
for ( ; pe_imp->Name; pe_imp++)
{
char * name = (char *)hmod + (unsigned int)pe_imp->Name;
TRACE("%s\n", name);
if (!lstrncmpiA(name, "ntdll", 5))
if (!strncasecmp(name, "ntdll", 5))
{
if (3 == PE_HEADER(wm->module)->OptionalHeader.MajorOperatingSystemVersion)
if (3 == PE_HEADER(hmod)->OptionalHeader.MajorOperatingSystemVersion)
return NT351;
else
return NT40;
}
}
}
return WIN95;
}
}
return WIN95;
}
/**********************************************************************
* VERSION_GetLinkedDllVersion
......@@ -236,15 +234,15 @@ DWORD VERSION_GetLinkedDllVersion(PDB *pdb)
ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
/* test if it is a external (native) dll */
if ( !(wm->flags & WINE_MODREF_INTERNAL) && wm->type==MODULE32_PE)
if (!(wm->flags & WINE_MODREF_INTERNAL))
{
int i;
for (i = 0; special_dlls[i]; i++)
{
/* test if it a special dll */
if (!lstrncmpiA(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
if (!strncasecmp(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
{
DWORD DllVersion = VERSION_GetSystemDLLVersion(wm);
DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
if (WinVersion == NB_WINDOWS_VERSIONS)
WinVersion = DllVersion;
else {
......
......@@ -27,7 +27,6 @@
#include "neexe.h"
#include "heap.h"
#include "main.h"
#include "snoop.h"
#include "winerror.h"
#include "server.h"
#include "debugtools.h"
......@@ -46,37 +45,10 @@ typedef struct
#define MAX_DLLS 60
static const BUILTIN32_DESCRIPTOR *builtin_dlls[MAX_DLLS];
static HMODULE dll_modules[MAX_DLLS];
static int nb_dlls;
/***********************************************************************
* BUILTIN32_WarnSecondInstance
*
* Emit a warning when we are creating a second instance for a DLL
* that is known to not support this.
*/
static void BUILTIN32_WarnSecondInstance( const char *name )
{
static const char * const warning_list[] =
{ "comctl32.dll", "comdlg32.dll", "crtdll.dll",
"imagehlp.dll", "msacm32.dll", "shell32.dll", NULL };
const char * const *ptr = warning_list;
while (*ptr)
{
if (!strcasecmp( *ptr, name ))
{
ERR( "Attempt to instantiate built-in dll '%s' twice "
"in the same address space. Expect trouble!\n", name );
return;
}
ptr++;
}
}
/***********************************************************************
* BUILTIN32_dlopen
*/
void *BUILTIN32_dlopen( const char *name )
......@@ -290,9 +262,7 @@ static HMODULE BUILTIN32_DoLoadImage( const BUILTIN32_DESCRIPTOR *descr )
*/
WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR path, DWORD flags)
{
struct load_dll_request *req = get_req_buffer();
HMODULE16 hModule16;
NE_MODULE *pModule;
HMODULE module;
WINE_MODREF *wm;
char dllname[MAX_PATH], *p;
void *handle;
......@@ -322,39 +292,15 @@ WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR path, DWORD flags)
found:
/* Load built-in module */
if (!dll_modules[i])
{
if (!(dll_modules[i] = BUILTIN32_DoLoadImage( builtin_dlls[i] ))) return NULL;
}
else BUILTIN32_WarnSecondInstance( builtin_dlls[i]->filename );
/* Create 16-bit dummy module */
if ((hModule16 = MODULE_CreateDummyModule( dllname, dll_modules[i] )) < 32)
{
SetLastError( (DWORD)hModule16 );
return NULL; /* FIXME: Should unload the builtin module */
}
pModule = (NE_MODULE *)GlobalLock16( hModule16 );
pModule->flags = NE_FFLAGS_LIBMODULE | NE_FFLAGS_SINGLEDATA | NE_FFLAGS_WIN32 | NE_FFLAGS_BUILTIN;
if (!(module = BUILTIN32_DoLoadImage( builtin_dlls[i] ))) return NULL;
/* Create 32-bit MODREF */
if ( !(wm = PE_CreateModule( pModule->module32, dllname, flags, TRUE )) )
if ( !(wm = PE_CreateModule( module, dllname, flags, -1, TRUE )) )
{
ERR( "can't load %s\n", path );
FreeLibrary16( hModule16 ); /* FIXME: Should unload the builtin module */
SetLastError( ERROR_OUTOFMEMORY );
return NULL;
}
if (wm->binfmt.pe.pe_export)
SNOOP_RegisterDLL(wm->module,wm->modname,wm->binfmt.pe.pe_export->NumberOfFunctions);
req->handle = -1;
req->base = (void *)pModule->module32;
req->dbg_offset = 0;
req->dbg_size = 0;
req->name = &wm->modname;
server_call_noerr( REQ_LOAD_DLL );
return wm;
}
......@@ -385,24 +331,11 @@ HMODULE BUILTIN32_LoadExeModule(void)
}
/* Load built-in module */
if ( !dll_modules[exe] )
if ( !(dll_modules[exe] = BUILTIN32_DoLoadImage( builtin_dlls[exe] )) )
return 0;
return dll_modules[exe];
return BUILTIN32_DoLoadImage( builtin_dlls[exe] );
}
/***********************************************************************
* BUILTIN32_UnloadLibrary
*
* Unload the built-in library and free the modref.
*/
void BUILTIN32_UnloadLibrary(WINE_MODREF *wm)
{
/* FIXME: do something here */
}
/***********************************************************************
* BUILTIN32_RegisterDLL
*
* Register a built-in DLL descriptor.
......
......@@ -27,7 +27,6 @@
#include "syslevel.h"
#include "thread.h"
#include "winerror.h"
#include "pe_image.h"
#include "server.h"
#include "options.h"
#include "callback.h"
......@@ -315,7 +314,6 @@ static void start_process(void)
{
struct init_process_done_request *req = get_req_buffer();
int debugged, console_app;
HMODULE16 hModule16;
UINT cmdShow = SW_SHOWNORMAL;
LPTHREAD_START_ROUTINE entry;
PDB *pdb = PROCESS_Current();
......@@ -328,7 +326,7 @@ static void start_process(void)
if (!(pdb->env_db->cmd_line = build_command_line( main_exe_argv ))) goto error;
/* Retrieve entry point address */
entry = (LPTHREAD_START_ROUTINE)RVA_PTR( module, OptionalHeader.AddressOfEntryPoint );
entry = (LPTHREAD_START_ROUTINE)((char*)module + PE_HEADER(module)->OptionalHeader.AddressOfEntryPoint);
console_app = (PE_HEADER(module)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
if (console_app) pdb->flags |= PDB32_CONSOLE_PROC;
......@@ -349,13 +347,10 @@ static void start_process(void)
/* Load KERNEL (necessary for TASK_Create) */
if (!LoadLibraryA( "KERNEL32" )) goto error;
/* Create 16-bit dummy module */
if ((hModule16 = MODULE_CreateDummyModule( pdb->exe_modref->filename, module )) < 32)
ExitProcess( hModule16 );
/* Create 16-bit task */
if (pdb->env_db->startup_info->dwFlags & STARTF_USESHOWWINDOW)
cmdShow = pdb->env_db->startup_info->wShowWindow;
if (!TASK_Create( (NE_MODULE *)GlobalLock16( hModule16 ), cmdShow,
if (!TASK_Create( (NE_MODULE *)GlobalLock16( MapHModuleLS(module) ), cmdShow,
NtCurrentTeb(), NULL, 0 ))
goto error;
......@@ -387,8 +382,8 @@ static void start_process(void)
* Startup routine of a new Win32 process once the main module has been loaded.
* The filename is free'd by this routine.
*/
static void PROCESS_Start( HMODULE main_module, LPSTR filename ) WINE_NORETURN;
static void PROCESS_Start( HMODULE main_module, LPSTR filename )
static void PROCESS_Start( HMODULE main_module, HFILE hFile, LPSTR filename ) WINE_NORETURN;
static void PROCESS_Start( HMODULE main_module, HFILE hFile, LPSTR filename )
{
if (!filename)
{
......@@ -403,7 +398,7 @@ static void PROCESS_Start( HMODULE main_module, LPSTR filename )
ExitProcess( ERROR_BAD_EXE_FORMAT );
/* Create 32-bit MODREF */
if (!PE_CreateModule( main_module, filename, 0, FALSE ))
if (!PE_CreateModule( main_module, filename, 0, hFile, FALSE ))
goto error;
free( filename );
......@@ -473,8 +468,8 @@ void PROCESS_InitWine( int argc, char *argv[] )
{
case SCS_32BIT_BINARY:
{
HMODULE main_module = PE_LoadImage( main_exe_file, main_exe_name );
if (main_module) PROCESS_Start( main_module, main_exe_name );
HMODULE main_module = PE_LoadImage( main_exe_file, main_exe_name, 0 );
if (main_module) PROCESS_Start( main_module, main_exe_file, main_exe_name );
}
break;
......@@ -486,7 +481,7 @@ void PROCESS_InitWine( int argc, char *argv[] )
NtCurrentTeb()->tibflags &= ~TEBF_WIN32;
PROCESS_Current()->flags |= PDB32_WIN16_PROC;
SYSLEVEL_EnterWin16Lock();
PROCESS_Start( main_module, NULL );
PROCESS_Start( main_module, -1, NULL );
}
break;
......@@ -497,7 +492,7 @@ void PROCESS_InitWine( int argc, char *argv[] )
if (!(main_module = BUILTIN32_LoadExeModule())) goto error;
NtCurrentTeb()->tibflags &= ~TEBF_WIN32;
if (!MZ_LoadImage( main_module, main_exe_file, main_exe_name )) goto error;
PROCESS_Start( main_module, NULL );
PROCESS_Start( main_module, main_exe_file, NULL );
}
break;
......@@ -529,7 +524,7 @@ void PROCESS_InitWinelib( int argc, char *argv[] )
if (!(main_module = BUILTIN32_LoadExeModule())) ExitProcess( GetLastError() );
main_exe_argv = argv;
PROCESS_Start( main_module, NULL );
PROCESS_Start( main_module, -1, NULL );
}
......
......@@ -12,13 +12,12 @@
#include "heap.h"
#include "thread.h"
#include "process.h"
#include "pe_image.h"
#include "file.h"
#include "task.h"
#include "toolhelp.h"
#include "debugtools.h"
DEFAULT_DEBUG_CHANNEL(win32)
DEFAULT_DEBUG_CHANNEL(win32);
/*********************************************************************
......
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