- 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.
This commit is contained in:
Alexandre Julliard 2000-08-07 04:12:41 +00:00
parent e6b51bf25f
commit 081ee94117
18 changed files with 422 additions and 874 deletions

View File

@ -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];

View File

@ -25,7 +25,6 @@
#endif
#include "debugger.h"
#include "neexe.h"
#include "pe_image.h"
#include "file.h"
typedef struct {

View File

@ -17,7 +17,6 @@
#include <string.h>
#include <unistd.h>
#include "pe_image.h"
#include "debugger.h"
#define NR_TYPE_HASH 521

View File

@ -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)

View File

@ -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 );

View File

@ -1,76 +0,0 @@
#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 */

View File

@ -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)
DEFAULT_DEBUG_CHANNEL(win32);
#if defined(HAVE_DL_API)
#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 */

View File

@ -148,139 +148,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)
*
@ -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

View File

@ -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,14 +51,49 @@ 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
*/
@ -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;
if (!wm) /* can happen on start up or the like */
return 0;
EnterCriticalSection( &PROCESS_Current()->crit_section );
lstrcpynA( lpFileName, wm->filename, size );
lpFileName[0] = 0;
if ((wm = MODULE32_LookupHMODULE( hModule )))
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;
}

View File

@ -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;

View File

@ -56,7 +56,6 @@
#include "neexe.h"
#include "process.h"
#include "thread.h"
#include "pe_image.h"
#include "module.h"
#include "global.h"
#include "task.h"
@ -72,6 +71,27 @@ DECLARE_DEBUG_CHANNEL(relay);
DECLARE_DEBUG_CHANNEL(segment);
static IMAGE_EXPORT_DIRECTORY *get_exports( HMODULE hmod )
{
IMAGE_EXPORT_DIRECTORY *ret = NULL;
IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
+ IMAGE_DIRECTORY_ENTRY_EXPORT;
if (dir->Size && dir->VirtualAddress)
ret = (IMAGE_EXPORT_DIRECTORY *)((char *)hmod + dir->VirtualAddress);
return ret;
}
static IMAGE_IMPORT_DESCRIPTOR *get_imports( HMODULE hmod )
{
IMAGE_IMPORT_DESCRIPTOR *ret = NULL;
IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
+ IMAGE_DIRECTORY_ENTRY_IMPORT;
if (dir->Size && dir->VirtualAddress)
ret = (IMAGE_IMPORT_DESCRIPTOR *)((char *)hmod + dir->VirtualAddress);
return ret;
}
/* convert PE image VirtualAddress to Real Address */
#define RVA(x) ((void *)((char *)load_addr+(unsigned int)(x)))
@ -130,7 +150,7 @@ void dump_exports( HMODULE hModule )
* If it is a ordinal:
* - use ordinal-pe_export->Base as offset into the functionlist
*/
FARPROC PE_FindExportedFunction(
static FARPROC PE_FindExportedFunction(
WINE_MODREF *wm, /* [in] WINE modreference */
LPCSTR funcName, /* [in] function name */
BOOL snoop )
@ -139,11 +159,10 @@ FARPROC PE_FindExportedFunction(
u_long * function;
u_char ** name, *ename = NULL;
int i, ordinal;
PE_MODREF *pem = &(wm->binfmt.pe);
IMAGE_EXPORT_DIRECTORY *exports = pem->pe_export;
unsigned int load_addr = wm->module;
u_long rva_start, rva_end, addr;
char * forward;
IMAGE_EXPORT_DIRECTORY *exports = get_exports(wm->module);
if (HIWORD(funcName))
TRACE("(%s)\n",funcName);
@ -154,7 +173,7 @@ FARPROC PE_FindExportedFunction(
* GetProcAddress(0,"RegisterPenApp") which triggers this
* case.
*/
WARN("Module %08x(%s)/MODREF %p doesn't have a exports table.\n",wm->module,wm->modname,pem);
WARN("Module %08x(%s)/MODREF %p doesn't have a exports table.\n",wm->module,wm->modname,wm);
return NULL;
}
ordinals= (u_short*) RVA(exports->AddressOfNameOrdinals);
@ -253,25 +272,24 @@ FARPROC PE_FindExportedFunction(
DWORD fixup_imports( WINE_MODREF *wm )
{
IMAGE_IMPORT_DESCRIPTOR *pe_imp;
PE_MODREF *pem;
unsigned int load_addr = wm->module;
int i,characteristics_detection=1;
char *modname;
IMAGE_EXPORT_DIRECTORY *exports = get_exports(wm->module);
IMAGE_IMPORT_DESCRIPTOR *imports = get_imports(wm->module);
assert(wm->type==MODULE32_PE);
pem = &(wm->binfmt.pe);
if (pem->pe_export)
modname = (char*) RVA(pem->pe_export->Name);
if (exports)
modname = (char*) RVA(exports->Name);
else
modname = "<unknown>";
/* first, count the number of imported non-internal modules */
pe_imp = imports;
if (!pe_imp) return 0;
/* OK, now dump the import list */
TRACE("Dumping imports list\n");
/* first, count the number of imported non-internal modules */
pe_imp = pem->pe_import;
if (!pe_imp) return 0;
/* We assume that we have at least one import with !0 characteristics and
* detect broken imports with all characteristics 0 (notably Borland) and
* switch the detection off for them.
@ -293,7 +311,7 @@ DWORD fixup_imports( WINE_MODREF *wm )
* added to the modref list of the process.
*/
for (i = 0, pe_imp = pem->pe_import; pe_imp->Name ; pe_imp++) {
for (i = 0, pe_imp = imports; pe_imp->Name ; pe_imp++) {
WINE_MODREF *wmImp;
IMAGE_IMPORT_BY_NAME *pe_name;
PIMAGE_THUNK_DATA import_list,thunk_list;
@ -472,7 +490,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)
*/
HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename )
HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, DWORD flags )
{
HMODULE hModule;
HANDLE mapping;
@ -612,7 +630,20 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename )
load_addr = (DWORD)VirtualAlloc( (void*)load_addr, vma_size,
MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE );
if (load_addr == 0)
if (!load_addr)
{
load_addr = (DWORD)VirtualAlloc( NULL, vma_size,
MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE );
if (!load_addr)
{
FIXME_(win32)(
"FATAL: Couldn't load module %s (out of memory, %d needed)!\n", filename, vma_size);
goto error;
}
}
if (load_addr != nt->OptionalHeader.ImageBase && !(flags & LOAD_LIBRARY_AS_DATAFILE))
{
/* We need to perform base relocations */
WARN("Info: base relocations needed for %s\n", filename);
@ -635,17 +666,8 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename )
* really make sure that the *new* base address is also > 2GB.
* Some DLLs really check the MSB of the module handle :-/
*/
if ( nt->OptionalHeader.ImageBase & 0x80000000 )
if ((nt->OptionalHeader.ImageBase & 0x80000000) && !(load_addr & 0x80000000))
ERR( "Forced to relocate system DLL (base > 2GB). This is not good.\n" );
load_addr = (DWORD)VirtualAlloc( NULL, vma_size,
MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE );
if (!load_addr) {
FIXME_(win32)(
"FATAL: Couldn't load module %s (out of memory, %d needed)!\n", filename, vma_size);
goto error;
}
}
TRACE("Load addr is %lx (base %lx), range %x\n",
@ -653,17 +675,6 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename )
TRACE_(segment)("Loading %s at %lx, range %x\n",
filename, load_addr, vma_size );
#if 0
/* Store the NT header at the load addr */
*(PIMAGE_DOS_HEADER)load_addr = *(PIMAGE_DOS_HEADER)hModule;
*PE_HEADER( load_addr ) = *nt;
memcpy( PE_SECTIONS(load_addr), PE_SECTIONS(hModule),
sizeof(IMAGE_SECTION_HEADER) * nt->FileHeader.NumberOfSections );
/* Copies all stuff up to the first section. Including win32 viruses. */
memcpy( load_addr, hModule, lowest_fa );
#endif
req->handle = hFile;
server_call_fd( REQ_GET_READ_FD, -1, &unix_handle );
if (unix_handle == -1) goto error;
@ -735,19 +746,18 @@ error:
*
* Note: This routine must always be called in the context of the
* process that is to own the module to be created.
*
* Note: Assumes that the process critical section is held
*/
WINE_MODREF *PE_CreateModule( HMODULE hModule,
LPCSTR filename, DWORD flags, BOOL builtin )
WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename, DWORD flags,
HFILE hFile, BOOL builtin )
{
DWORD load_addr = (DWORD)hModule; /* for RVA */
IMAGE_NT_HEADERS *nt = PE_HEADER(hModule);
IMAGE_DATA_DIRECTORY *dir;
IMAGE_IMPORT_DESCRIPTOR *pe_import = NULL;
IMAGE_EXPORT_DIRECTORY *pe_export = NULL;
IMAGE_RESOURCE_DIRECTORY *pe_resource = NULL;
WINE_MODREF *wm;
int result;
HMODULE16 hModule16;
/* Retrieve DataDirectory entries */
@ -755,14 +765,6 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
if (dir->Size)
pe_export = (PIMAGE_EXPORT_DIRECTORY)RVA(dir->VirtualAddress);
dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_IMPORT;
if (dir->Size)
pe_import = (PIMAGE_IMPORT_DESCRIPTOR)RVA(dir->VirtualAddress);
dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_RESOURCE;
if (dir->Size)
pe_resource = (PIMAGE_RESOURCE_DIRECTORY)RVA(dir->VirtualAddress);
dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_EXCEPTION;
if (dir->Size) FIXME("Exception directory ignored\n" );
@ -772,12 +774,6 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
/* IMAGE_DIRECTORY_ENTRY_BASERELOC handled in PE_LoadImage */
/* IMAGE_DIRECTORY_ENTRY_DEBUG handled by debugger */
dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_DEBUG;
if (dir->Size) TRACE("Debug directory ignored\n" );
dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_COPYRIGHT;
if (dir->Size) FIXME("Copyright string ignored\n" );
dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_GLOBALPTR;
if (dir->Size) FIXME("Global Pointer (MIPS) ignored\n" );
@ -825,58 +821,33 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
dir = nt->OptionalHeader.DataDirectory+15;
if (dir->Size) FIXME("Unknown directory 15 ignored\n" );
/* Create 16-bit dummy module */
if ((hModule16 = MODULE_CreateDummyModule( filename, hModule )) < 32)
{
SetLastError( (DWORD)hModule16 ); /* This should give the correct error */
return NULL;
}
/* Allocate and fill WINE_MODREF */
wm = (WINE_MODREF *)HeapAlloc( GetProcessHeap(),
HEAP_ZERO_MEMORY, sizeof(*wm) );
wm->module = hModule;
if ( builtin )
wm->flags |= WINE_MODREF_INTERNAL;
if ( flags & DONT_RESOLVE_DLL_REFERENCES )
wm->flags |= WINE_MODREF_DONT_RESOLVE_REFS;
if ( flags & LOAD_LIBRARY_AS_DATAFILE )
wm->flags |= WINE_MODREF_LOAD_AS_DATAFILE;
wm->type = MODULE32_PE;
wm->binfmt.pe.pe_export = pe_export;
wm->binfmt.pe.pe_import = pe_import;
wm->binfmt.pe.pe_resource = pe_resource;
wm->binfmt.pe.tlsindex = -1;
wm->filename = HEAP_strdupA( GetProcessHeap(), 0, filename );
wm->modname = strrchr( wm->filename, '\\' );
if (!wm->modname) wm->modname = wm->filename;
else wm->modname++;
result = GetShortPathNameA( wm->filename, NULL, 0 );
wm->short_filename = (char *)HeapAlloc( GetProcessHeap(), 0, result+1 );
GetShortPathNameA( wm->filename, wm->short_filename, result+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 (!(wm = MODULE_AllocModRef( hModule, filename )))
{
if ( PROCESS_Current()->exe_modref )
FIXME( "Trying to load second .EXE file: %s\n", filename );
else
PROCESS_Current()->exe_modref = wm;
FreeLibrary16( hModule16 );
return NULL;
}
LeaveCriticalSection( &PROCESS_Current()->crit_section );
if ( builtin )
{
NE_MODULE *pModule = (NE_MODULE *)GlobalLock16( hModule16 );
pModule->flags |= NE_FFLAGS_BUILTIN;
wm->flags |= WINE_MODREF_INTERNAL;
}
if ( flags & DONT_RESOLVE_DLL_REFERENCES )
wm->flags |= WINE_MODREF_DONT_RESOLVE_REFS;
wm->find_export = PE_FindExportedFunction;
/* Dump Exports */
@ -885,13 +856,9 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
/* Fixup Imports */
if ( pe_import
&& !( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE )
&& !( wm->flags & WINE_MODREF_DONT_RESOLVE_REFS )
&& fixup_imports( wm ) )
if (!(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;
@ -901,8 +868,6 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
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
@ -913,6 +878,29 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
return NULL;
}
if (pe_export)
SNOOP_RegisterDLL( hModule, wm->modname, pe_export->NumberOfFunctions );
/* Send DLL load event */
if (nt->FileHeader.Characteristics & IMAGE_FILE_DLL)
{
struct load_dll_request *req = get_req_buffer();
req->handle = hFile;
req->base = (void *)hModule;
req->dbg_offset = nt->FileHeader.PointerToSymbolTable;
req->dbg_size = nt->FileHeader.NumberOfSymbols;
req->name = &wm->filename;
server_call_noerr( REQ_LOAD_DLL );
}
else /* we don't need to send a dll event for the main exe */
{
if ( PROCESS_Current()->exe_modref )
FIXME( "Trying to load second .EXE file: %s\n", filename );
else
PROCESS_Current()->exe_modref = wm;
}
return wm;
}
@ -922,9 +910,7 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
*/
WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags)
{
struct load_dll_request *req = get_req_buffer();
HMODULE hModule32;
HMODULE16 hModule16;
WINE_MODREF *wm;
char filename[256];
HANDLE hFile;
@ -938,78 +924,48 @@ WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags)
if ( hFile == INVALID_HANDLE_VALUE ) return NULL;
/* Load PE module */
hModule32 = PE_LoadImage( hFile, filename );
hModule32 = PE_LoadImage( hFile, filename, flags );
if (!hModule32)
{
CloseHandle( hFile );
return NULL;
}
/* Create 16-bit dummy module */
if ((hModule16 = MODULE_CreateDummyModule( filename, hModule32 )) < 32)
{
CloseHandle( hFile );
SetLastError( (DWORD)hModule16 ); /* This should give the correct error */
return NULL;
}
/* Create 32-bit MODREF */
if ( !(wm = PE_CreateModule( hModule32, filename, flags, FALSE )) )
if ( !(wm = PE_CreateModule( hModule32, filename, flags, -1, FALSE )) )
{
ERR( "can't load %s\n", filename );
FreeLibrary16( hModule16 );
CloseHandle( hFile );
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 = hFile;
req->base = (void *)hModule32;
req->dbg_offset = PE_HEADER(hModule32)->FileHeader.PointerToSymbolTable;
req->dbg_size = PE_HEADER(hModule32)->FileHeader.NumberOfSymbols;
req->name = &wm->filename;
server_call_noerr( REQ_LOAD_DLL );
CloseHandle( hFile );
return wm;
}
/*****************************************************************************
* PE_UnloadLibrary
*
* Unload the library unmapping the image and freeing the modref structure.
*/
void PE_UnloadLibrary(WINE_MODREF *wm)
{
TRACE(" unloading %s\n", wm->filename);
/* VirtualFree( (LPVOID)wm->module, 0, MEM_RELEASE ); */ /* FIXME */
HeapFree( GetProcessHeap(), 0, wm->filename );
HeapFree( GetProcessHeap(), 0, wm->short_filename );
HeapFree( GetProcessHeap(), 0, wm );
}
/* Called if the library is loaded or freed.
* NOTE: if a thread attaches a DLL, the current thread will only do
* DLL_PROCESS_ATTACH. Only new created threads do DLL_THREAD_ATTACH
* (SDK)
*/
BOOL PE_InitDLL( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
typedef DWORD CALLBACK(*DLLENTRYPROC)(HMODULE,DWORD,LPVOID);
BOOL PE_InitDLL( HMODULE module, DWORD type, LPVOID lpReserved )
{
BOOL retv = TRUE;
assert( wm->type == MODULE32_PE );
IMAGE_NT_HEADERS *nt = PE_HEADER(module);
/* Is this a library? And has it got an entrypoint? */
if ((PE_HEADER(wm->module)->FileHeader.Characteristics & IMAGE_FILE_DLL) &&
(PE_HEADER(wm->module)->OptionalHeader.AddressOfEntryPoint)
) {
DLLENTRYPROC entry = (void*)RVA_PTR( wm->module,OptionalHeader.AddressOfEntryPoint );
if ((nt->FileHeader.Characteristics & IMAGE_FILE_DLL) &&
(nt->OptionalHeader.AddressOfEntryPoint))
{
DLLENTRYPROC entry = (void*)((char*)module + nt->OptionalHeader.AddressOfEntryPoint);
TRACE_(relay)("CallTo32(entryproc=%p,module=%08x,type=%ld,res=%p)\n",
entry, wm->module, type, lpReserved );
entry, module, type, lpReserved );
retv = entry( wm->module, type, lpReserved );
retv = entry( module, type, lpReserved );
}
return retv;
@ -1036,7 +992,6 @@ _fixup_address(PIMAGE_OPTIONAL_HEADER opt,int delta,LPVOID addr) {
void PE_InitTls( void )
{
WINE_MODREF *wm;
PE_MODREF *pem;
IMAGE_NT_HEADERS *peh;
DWORD size,datasize;
LPVOID mem;
@ -1044,9 +999,6 @@ void PE_InitTls( void )
int delta;
for (wm = PROCESS_Current()->modref_list;wm;wm=wm->next) {
if (wm->type!=MODULE32_PE)
continue;
pem = &(wm->binfmt.pe);
peh = PE_HEADER(wm->module);
delta = wm->module - peh->OptionalHeader.ImageBase;
if (!peh->OptionalHeader.DataDirectory[IMAGE_FILE_THREAD_LOCAL_STORAGE].VirtualAddress)
@ -1055,13 +1007,13 @@ void PE_InitTls( void )
DataDirectory[IMAGE_FILE_THREAD_LOCAL_STORAGE].VirtualAddress);
if ( pem->tlsindex == -1 ) {
if ( wm->tlsindex == -1 ) {
LPDWORD xaddr;
pem->tlsindex = TlsAlloc();
wm->tlsindex = TlsAlloc();
xaddr = _fixup_address(&(peh->OptionalHeader),delta,
pdir->AddressOfIndex
);
*xaddr=pem->tlsindex;
*xaddr=wm->tlsindex;
}
datasize= pdir->EndAddressOfRawData-pdir->StartAddressOfRawData;
size = datasize + pdir->SizeOfZeroFill;
@ -1075,7 +1027,7 @@ void PE_InitTls( void )
FIXME("TLS Callbacks aren't going to be called\n");
}
TlsSetValue( pem->tlsindex, mem );
TlsSetValue( wm->tlsindex, mem );
}
}

View File

@ -16,7 +16,6 @@
#include "wine/unicode.h"
#include "windef.h"
#include "winnls.h"
#include "pe_image.h"
#include "module.h"
#include "heap.h"
#include "task.h"
@ -26,20 +25,23 @@
#include "debugtools.h"
/**********************************************************************
* HMODULE32toPE_MODREF
* get_resdir
*
* small helper function to get a PE_MODREF from a passed HMODULE32
* Get the resource directory of a PE module
*/
static PE_MODREF*
HMODULE32toPE_MODREF(HMODULE hmod) {
WINE_MODREF *wm;
static IMAGE_RESOURCE_DIRECTORY* get_resdir( HMODULE hmod )
{
IMAGE_DATA_DIRECTORY *dir;
IMAGE_RESOURCE_DIRECTORY *ret = NULL;
wm = MODULE32_LookupHMODULE( hmod );
if (!wm || wm->type!=MODULE32_PE)
return NULL;
return &(wm->binfmt.pe);
if (!hmod) hmod = GetModuleHandleA( NULL );
dir = &PE_HEADER(hmod)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE];
if (dir->Size && dir->VirtualAddress)
ret = (IMAGE_RESOURCE_DIRECTORY *)((char *)hmod + dir->VirtualAddress);
return ret;
}
/**********************************************************************
* GetResDirEntryW
*
@ -57,14 +59,12 @@ PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY resdirptr,
if (HIWORD(name)) {
if (name[0]=='#') {
char buf[10];
lstrcpynWtoA(buf,name+1,10);
if (!WideCharToMultiByte( CP_ACP, 0, name+1, -1, buf, sizeof(buf), NULL, NULL ))
return NULL;
return GetResDirEntryW(resdirptr,(LPCWSTR)atoi(buf),root,allowdefault);
}
entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
(BYTE *) resdirptr +
sizeof(IMAGE_RESOURCE_DIRECTORY));
namelen = lstrlenW(name);
entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdirptr + 1);
namelen = strlenW(name);
for (entrynum = 0; entrynum < resdirptr->NumberOfNamedEntries; entrynum++)
{
PIMAGE_RESOURCE_DIR_STRING_U str =
@ -116,20 +116,16 @@ PIMAGE_RESOURCE_DIRECTORY GetResDirEntryA( PIMAGE_RESOURCE_DIRECTORY resdirptr,
}
/**********************************************************************
* PE_FindResourceEx32W
* PE_FindResourceExW
*/
HANDLE PE_FindResourceExW(
WINE_MODREF *wm,LPCWSTR name,LPCWSTR type,WORD lang
) {
PIMAGE_RESOURCE_DIRECTORY resdirptr;
HANDLE PE_FindResourceExW( HMODULE hmod, LPCWSTR name, LPCWSTR type, WORD lang )
{
PIMAGE_RESOURCE_DIRECTORY resdirptr = get_resdir(hmod);
DWORD root;
HANDLE result;
PE_MODREF *pem = &(wm->binfmt.pe);
if (!pem || !pem->pe_resource)
return 0;
if (!resdirptr) return 0;
resdirptr = pem->pe_resource;
root = (DWORD) resdirptr;
if ((resdirptr = GetResDirEntryW(resdirptr, type, root, FALSE)) == NULL)
return 0;
@ -151,13 +147,12 @@ HANDLE PE_FindResourceExW(
/**********************************************************************
* PE_LoadResource32
* PE_LoadResource
*/
HANDLE PE_LoadResource( WINE_MODREF *wm, HANDLE hRsrc )
HANDLE PE_LoadResource( HMODULE hmod, HANDLE hRsrc )
{
if (!hRsrc || !wm || wm->type!=MODULE32_PE)
return 0;
return (HANDLE) (wm->module + ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->OffsetToData);
if (!hRsrc) return 0;
return (HANDLE)(hmod + ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->OffsetToData);
}
@ -172,29 +167,27 @@ DWORD PE_SizeofResource( HINSTANCE hModule, HANDLE hRsrc )
return ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->Size;
}
/**********************************************************************
* PE_EnumResourceTypes32A
* EnumResourceTypesA (KERNEL32.90)
*/
BOOL
PE_EnumResourceTypesA(HMODULE hmod,ENUMRESTYPEPROCA lpfun,LONG lparam) {
PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
BOOL WINAPI EnumResourceTypesA( HMODULE hmod, ENUMRESTYPEPROCA lpfun, LONG lparam)
{
int i;
PIMAGE_RESOURCE_DIRECTORY resdir;
PIMAGE_RESOURCE_DIRECTORY resdir = get_resdir(hmod);
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
BOOL ret;
HANDLE heap = GetProcessHeap();
if (!pem || !pem->pe_resource)
return FALSE;
if (!resdir) return FALSE;
resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdir + 1);
ret = FALSE;
for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
LPSTR name;
if (et[i].u1.s.NameIsString)
name = HEAP_strdupWtoA(heap,0,(LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset));
name = HEAP_strdupWtoA(heap,0,(LPWSTR)((LPBYTE)resdir + et[i].u1.s.NameOffset));
else
name = (LPSTR)(int)et[i].u1.Id;
ret = lpfun(hmod,name,lparam);
@ -206,27 +199,25 @@ PE_EnumResourceTypesA(HMODULE hmod,ENUMRESTYPEPROCA lpfun,LONG lparam) {
return ret;
}
/**********************************************************************
* PE_EnumResourceTypes32W
* EnumResourceTypesW (KERNEL32.91)
*/
BOOL
PE_EnumResourceTypesW(HMODULE hmod,ENUMRESTYPEPROCW lpfun,LONG lparam) {
PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
BOOL WINAPI EnumResourceTypesW( HMODULE hmod, ENUMRESTYPEPROCW lpfun, LONG lparam)
{
int i;
PIMAGE_RESOURCE_DIRECTORY resdir;
PIMAGE_RESOURCE_DIRECTORY resdir = get_resdir(hmod);
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
BOOL ret;
if (!pem || !pem->pe_resource)
return FALSE;
if (!resdir) return FALSE;
resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdir + 1);
ret = FALSE;
for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
LPWSTR type;
if (et[i].u1.s.NameIsString)
type = (LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset);
type = (LPWSTR)((LPBYTE)resdir + et[i].u1.s.NameOffset);
else
type = (LPWSTR)(int)et[i].u1.Id;
@ -237,40 +228,38 @@ PE_EnumResourceTypesW(HMODULE hmod,ENUMRESTYPEPROCW lpfun,LONG lparam) {
return ret;
}
/**********************************************************************
* PE_EnumResourceNames32A
* EnumResourceNamesA (KERNEL32.88)
*/
BOOL
PE_EnumResourceNamesA(
HMODULE hmod,LPCSTR type,ENUMRESNAMEPROCA lpfun,LONG lparam
) {
PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
BOOL WINAPI EnumResourceNamesA( HMODULE hmod, LPCSTR type, ENUMRESNAMEPROCA lpfun, LONG lparam )
{
int i;
PIMAGE_RESOURCE_DIRECTORY basedir = get_resdir(hmod);
PIMAGE_RESOURCE_DIRECTORY resdir;
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
BOOL ret;
HANDLE heap = GetProcessHeap();
LPWSTR typeW;
if (!pem || !pem->pe_resource)
return FALSE;
resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
if (!basedir) return FALSE;
if (HIWORD(type))
typeW = HEAP_strdupAtoW(heap,0,type);
else
typeW = (LPWSTR)type;
resdir = GetResDirEntryW(resdir,typeW,(DWORD)pem->pe_resource,FALSE);
resdir = GetResDirEntryW(basedir,typeW,(DWORD)basedir,FALSE);
if (HIWORD(typeW))
HeapFree(heap,0,typeW);
if (!resdir)
return FALSE;
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdir + 1);
ret = FALSE;
for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
LPSTR name;
if (et[i].u1.s.NameIsString)
name = HEAP_strdupWtoA(heap,0,(LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset));
name = HEAP_strdupWtoA(heap,0,(LPWSTR)((LPBYTE)basedir + et[i].u1.s.NameOffset));
else
name = (LPSTR)(int)et[i].u1.Id;
ret = lpfun(hmod,type,name,lparam);
@ -281,32 +270,29 @@ PE_EnumResourceNamesA(
return ret;
}
/**********************************************************************
* PE_EnumResourceNames32W
* EnumResourceNamesW (KERNEL32.89)
*/
BOOL
PE_EnumResourceNamesW(
HMODULE hmod,LPCWSTR type,ENUMRESNAMEPROCW lpfun,LONG lparam
) {
PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
BOOL WINAPI EnumResourceNamesW( HMODULE hmod, LPCWSTR type, ENUMRESNAMEPROCW lpfun, LONG lparam )
{
int i;
PIMAGE_RESOURCE_DIRECTORY basedir = get_resdir(hmod);
PIMAGE_RESOURCE_DIRECTORY resdir;
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
BOOL ret;
if (!pem || !pem->pe_resource)
return FALSE;
if (!basedir) return FALSE;
resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
resdir = GetResDirEntryW(resdir,type,(DWORD)pem->pe_resource,FALSE);
resdir = GetResDirEntryW(basedir,type,(DWORD)basedir,FALSE);
if (!resdir)
return FALSE;
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
et = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdir + 1);
ret = FALSE;
for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
LPWSTR name;
if (et[i].u1.s.NameIsString)
name = (LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset);
name = (LPWSTR)((LPBYTE)basedir + et[i].u1.s.NameOffset);
else
name = (LPWSTR)(int)et[i].u1.Id;
ret = lpfun(hmod,type,name,lparam);
@ -316,83 +302,78 @@ PE_EnumResourceNamesW(
return ret;
}
/**********************************************************************
* PE_EnumResourceNames32A
* EnumResourceLanguagesA (KERNEL32.86)
*/
BOOL
PE_EnumResourceLanguagesA(
HMODULE hmod,LPCSTR name,LPCSTR type,ENUMRESLANGPROCA lpfun,
LONG lparam
) {
PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
BOOL WINAPI EnumResourceLanguagesA( HMODULE hmod, LPCSTR type, LPCSTR name,
ENUMRESLANGPROCA lpfun, LONG lparam )
{
int i;
PIMAGE_RESOURCE_DIRECTORY basedir = get_resdir(hmod);
PIMAGE_RESOURCE_DIRECTORY resdir;
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
BOOL ret;
HANDLE heap = GetProcessHeap();
LPWSTR nameW,typeW;
if (!pem || !pem->pe_resource)
return FALSE;
if (!basedir) return FALSE;
resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
if (HIWORD(name))
nameW = HEAP_strdupAtoW(heap,0,name);
else
nameW = (LPWSTR)name;
resdir = GetResDirEntryW(resdir,nameW,(DWORD)pem->pe_resource,FALSE);
if (HIWORD(nameW))
HeapFree(heap,0,nameW);
if (!resdir)
return FALSE;
if (HIWORD(type))
typeW = HEAP_strdupAtoW(heap,0,type);
else
typeW = (LPWSTR)type;
resdir = GetResDirEntryW(resdir,typeW,(DWORD)pem->pe_resource,FALSE);
if (HIWORD(typeW))
{
LPWSTR typeW = HEAP_strdupAtoW(heap,0,type);
resdir = GetResDirEntryW(basedir,typeW,(DWORD)basedir,FALSE);
HeapFree(heap,0,typeW);
}
else resdir = GetResDirEntryW(basedir,(LPWSTR)type,(DWORD)basedir,FALSE);
if (!resdir)
return FALSE;
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
if (HIWORD(name))
{
LPWSTR nameW = HEAP_strdupAtoW(heap,0,name);
resdir = GetResDirEntryW(resdir,nameW,(DWORD)basedir,FALSE);
HeapFree(heap,0,nameW);
}
else resdir = GetResDirEntryW(resdir,(LPWSTR)name,(DWORD)basedir,FALSE);
if (!resdir)
return FALSE;
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdir + 1);
ret = FALSE;
for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
/* languages are just ids... I hopem */
ret = lpfun(hmod,name,type,et[i].u1.Id,lparam);
/* languages are just ids... I hope */
ret = lpfun(hmod,type,name,et[i].u1.Id,lparam);
if (!ret)
break;
}
return ret;
}
/**********************************************************************
* PE_EnumResourceLanguages32W
* EnumResourceLanguagesW (KERNEL32.87)
*/
BOOL
PE_EnumResourceLanguagesW(
HMODULE hmod,LPCWSTR name,LPCWSTR type,ENUMRESLANGPROCW lpfun,
LONG lparam
) {
PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
BOOL WINAPI EnumResourceLanguagesW( HMODULE hmod, LPCWSTR type, LPCWSTR name,
ENUMRESLANGPROCW lpfun, LONG lparam )
{
int i;
PIMAGE_RESOURCE_DIRECTORY basedir = get_resdir(hmod);
PIMAGE_RESOURCE_DIRECTORY resdir;
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
BOOL ret;
if (!pem || !pem->pe_resource)
return FALSE;
if (!basedir) return FALSE;
resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
resdir = GetResDirEntryW(resdir,name,(DWORD)pem->pe_resource,FALSE);
resdir = GetResDirEntryW(basedir,type,(DWORD)basedir,FALSE);
if (!resdir)
return FALSE;
resdir = GetResDirEntryW(resdir,type,(DWORD)pem->pe_resource,FALSE);
resdir = GetResDirEntryW(resdir,name,(DWORD)basedir,FALSE);
if (!resdir)
return FALSE;
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdir + 1);
ret = FALSE;
for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
ret = lpfun(hmod,name,type,et[i].u1.Id,lparam);
ret = lpfun(hmod,type,name,et[i].u1.Id,lparam);
if (!ret)
break;
}

View File

@ -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);
}

View File

@ -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"

View File

@ -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 {

View File

@ -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,36 +45,9 @@ 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
*/
@ -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,23 +331,10 @@ 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
*

View File

@ -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 );
}

View File

@ -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);
/*********************************************************************