Commit 237e8e95 authored by Ulrich Weigand's avatar Ulrich Weigand Committed by Alexandre Julliard

Fixed 32-bit module name handling to conform better to Win9x.

Removed OFSTRUCT passing during process creation sequence. Bugfix: don't set exe_modref when LOAD_LIBRARY_AS_DATAFILE is set.
parent 0c0f7d35
......@@ -62,7 +62,7 @@ extern LPDOSTASK MZ_AllocDPMITask( HMODULE16 hModule );
#define V86_FLAG 0x00020000
extern BOOL MZ_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline, LPCSTR env,
extern BOOL MZ_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmdline, LPCSTR env,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
LPPROCESS_INFORMATION info );
......
......@@ -5,7 +5,7 @@
#include "windef.h"
WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR libname, DWORD flags, DWORD *err);
HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname, BOOL implicit);
HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname);
void ELFDLL_UnloadLibrary(WINE_MODREF *wm);
#if defined(HAVE_DL_API)
......
......@@ -146,9 +146,10 @@ typedef struct _wine_modref
int flags;
int refCount;
char *filename;
char *modname;
char *shortname;
char *longname;
char *short_filename;
char *short_modname;
} WINE_MODREF;
#define WINE_MODREF_INTERNAL 0x00000001
......@@ -183,7 +184,7 @@ extern void MODULE_DllThreadDetach( LPVOID lpReserved );
extern WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags );
extern BOOL MODULE_FreeLibrary( WINE_MODREF *wm );
extern WINE_MODREF *MODULE_FindModule( LPCSTR path );
extern HMODULE MODULE_CreateDummyModule( const OFSTRUCT *ofs, LPCSTR modName, WORD version );
extern HMODULE MODULE_CreateDummyModule( LPCSTR filename, WORD version );
extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hmodule, LPCSTR name );
extern SEGPTR WINAPI HasGPHandler16( SEGPTR address );
extern void MODULE_WalkModref( DWORD id );
......@@ -201,7 +202,7 @@ extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop );
extern BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
extern HANDLE NE_OpenFile( NE_MODULE *pModule );
extern BOOL NE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line, LPCSTR env,
extern BOOL NE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR env,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
LPPROCESS_INFORMATION info );
......@@ -231,7 +232,6 @@ extern void NE_InitializeDLLs( HMODULE16 hModule );
HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size );
/* relay32/builtin.c */
extern HMODULE BUILTIN32_LoadImage(LPCSTR name, OFSTRUCT *ofs);
extern WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR name, DWORD flags, DWORD *err);
extern void BUILTIN32_UnloadLibrary(WINE_MODREF *wm);
......
......@@ -28,10 +28,10 @@ extern DWORD PE_SizeofResource(HMODULE,HRSRC);
extern struct _wine_modref *PE_LoadLibraryExA(LPCSTR, DWORD, DWORD *);
extern void PE_UnloadLibrary(struct _wine_modref *);
extern HGLOBAL PE_LoadResource(struct _wine_modref *wm,HRSRC);
extern HMODULE PE_LoadImage( HFILE hFile, OFSTRUCT *ofs, LPCSTR *modName, WORD *version );
extern struct _wine_modref *PE_CreateModule( HMODULE hModule, OFSTRUCT *ofs,
extern HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version );
extern struct _wine_modref *PE_CreateModule( HMODULE hModule, LPCSTR filename,
DWORD flags, BOOL builtin );
extern BOOL PE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line, LPCSTR env,
extern BOOL PE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR env,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
LPPROCESS_INFORMATION info );
......
......@@ -221,7 +221,7 @@ static BOOL MZ_InitMemory( LPDOSTASK lpDosTask, NE_MODULE *pModule )
return TRUE;
}
static BOOL MZ_LoadImage( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline,
static BOOL MZ_LoadImage( HANDLE hFile, LPCSTR filename, LPCSTR cmdline,
LPCSTR env, LPDOSTASK lpDosTask, NE_MODULE *pModule )
{
IMAGE_DOS_HEADER mz_header;
......@@ -230,10 +230,12 @@ static BOOL MZ_LoadImage( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline,
int x,old_com=0;
SEGPTR reloc;
WORD env_seg;
DWORD len;
_llseek(hFile,0,FILE_BEGIN);
if ((_lread(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) ||
(mz_header.e_magic != IMAGE_DOS_SIGNATURE)) {
SetFilePointer(hFile,0,NULL,FILE_BEGIN);
if ( !ReadFile(hFile,&mz_header,sizeof(mz_header),&len,NULL)
|| len != sizeof(mz_header)
|| mz_header.e_magic != IMAGE_DOS_SIGNATURE) {
old_com=1; /* assume .COM file */
image_start=0;
image_size=GetFileSize(hFile,NULL);
......@@ -254,7 +256,7 @@ static BOOL MZ_LoadImage( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline,
MZ_InitMemory(lpDosTask,pModule);
/* allocate environment block */
env_seg=MZ_InitEnvironment(lpDosTask,env,ofs->szPathName);
env_seg=MZ_InitEnvironment(lpDosTask,env,filename);
/* allocate memory for the executable */
TRACE("Allocating DOS memory (min=%ld, max=%ld)\n",min_size,max_size);
......@@ -277,8 +279,8 @@ static BOOL MZ_LoadImage( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline,
/* load executable image */
TRACE("loading DOS %s image, %08lx bytes\n",old_com?"COM":"EXE",image_size);
_llseek(hFile,image_start,FILE_BEGIN);
if ((_lread(hFile,load_start,image_size)) != image_size) {
SetFilePointer(hFile,image_start,NULL,FILE_BEGIN);
if (!ReadFile(hFile,load_start,image_size,&len,NULL) || len != image_size) {
SetLastError(ERROR_BAD_FORMAT);
return FALSE;
}
......@@ -287,9 +289,9 @@ static BOOL MZ_LoadImage( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline,
/* load relocation table */
TRACE("loading DOS EXE relocation table, %d entries\n",mz_header.e_crlc);
/* FIXME: is this too slow without read buffering? */
_llseek(hFile,mz_header.e_lfarlc,FILE_BEGIN);
SetFilePointer(hFile,mz_header.e_lfarlc,NULL,FILE_BEGIN);
for (x=0; x<mz_header.e_crlc; x++) {
if (_lread(hFile,&reloc,sizeof(reloc)) != sizeof(reloc)) {
if (!ReadFile(hFile,&reloc,sizeof(reloc),&len,NULL) || len != sizeof(reloc)) {
SetLastError(ERROR_BAD_FORMAT);
return FALSE;
}
......@@ -450,7 +452,7 @@ BOOL MZ_InitTask( LPDOSTASK lpDosTask )
return TRUE;
}
BOOL MZ_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline, LPCSTR env,
BOOL MZ_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmdline, LPCSTR env,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
LPPROCESS_INFORMATION info )
......@@ -469,7 +471,7 @@ BOOL MZ_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline, LPCSTR env,
if ((!env)&&pdb) env = pdb->env_db->environ;
if (alloc) {
if ((hModule = MODULE_CreateDummyModule(ofs, NULL, 0)) < 32) {
if ((hModule = MODULE_CreateDummyModule(filename, 0)) < 32) {
SetLastError(hModule);
return FALSE;
}
......@@ -480,7 +482,7 @@ BOOL MZ_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline, LPCSTR env,
lpDosTask->img=NULL; lpDosTask->mm_name[0]=0; lpDosTask->mm_fd=-1;
} else lpDosTask=pModule->lpDosTask;
if (!MZ_LoadImage( hFile, ofs, cmdline, env, lpDosTask, pModule )) {
if (!MZ_LoadImage( hFile, filename, cmdline, env, lpDosTask, pModule )) {
if (alloc) {
if (lpDosTask->mm_name[0]!=0) {
if (lpDosTask->img!=NULL) munmap(lpDosTask->img,0x110000-START_OFFSET);
......@@ -558,7 +560,7 @@ LPDOSTASK MZ_Current( void )
#else /* !MZ_SUPPORTED */
BOOL MZ_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmdline, LPCSTR env,
BOOL MZ_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmdline, LPCSTR env,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
LPPROCESS_INFORMATION info )
......
......@@ -45,7 +45,9 @@ WINE_MODREF *ELF_CreateDummyModule( LPCSTR libname, LPCSTR modname )
PROCESS_Current()->modref_list = wm;
wm->modname = HEAP_strdupA( GetProcessHeap(), 0, modname );
wm->longname = HEAP_strdupA( GetProcessHeap(), 0, libname );
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) +
......
......@@ -190,57 +190,67 @@ static WINE_MODREF *ELFDLL_CreateModref(HMODULE hModule, LPCSTR path)
if(dir->Size)
wm->binfmt.pe.pe_resource = (PIMAGE_RESOURCE_DIRECTORY)RVA(hModule, dir->VirtualAddress);
wm->modname = HEAP_strdupA(procheap, 0, (char *)RVA(hModule, wm->binfmt.pe.pe_export->Name));
len = GetLongPathNameA(path, NULL, 0);
wm->longname = (char *)HeapAlloc(procheap, 0, len+1);
GetLongPathNameA(path, wm->longname, len+1);
wm->filename = HEAP_strdupA( procheap, 0, path );
wm->modname = strrchr( wm->filename, '\\' );
if (!wm->modname) wm->modname = wm->filename;
else wm->modname++;
wm->shortname = HEAP_strdupA(procheap, 0, path);
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(!(nt->FileHeader.Characteristics & IMAGE_FILE_DLL))
{
if(PROCESS_Current()->exe_modref)
FIXME_(elfdll)("overwriting old exe_modref... arrgh\n");
PROCESS_Current()->exe_modref = wm;
if ( PROCESS_Current()->exe_modref )
FIXME_(elfdll)( "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 && fixup_imports(wm))
if ( pe_import
&& !( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE )
&& !( wm->flags & WINE_MODREF_DONT_RESOLVE_REFS )
&& fixup_imports( wm ) )
{
/* Error in this module or its dependencies
* remove entry from modref chain
*/
WINE_MODREF **xwm;
for(xwm = &(PROCESS_Current()->modref_list); *xwm; xwm = &((*xwm)->next))
{
if ( *xwm == wm )
{
*xwm = wm->next;
break;
}
}
if(wm == PROCESS_Current()->exe_modref)
ERR_(elfdll)("Have to delete current exe_modref. Expect crash now\n");
HeapFree(procheap, 0, wm->shortname);
HeapFree(procheap, 0, wm->longname);
HeapFree(procheap, 0, wm->modname);
HeapFree(procheap, 0, wm);
return NULL;
/* 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;
/* FIXME: We should traverse back in the recursion
* with an error to unload everything that got loaded
* before this error occurred.
* Too dificult for now though and we don't care at the
* moment. But, it *MUST* be implemented someday because
* we won't be able to map the elf-dll twice in this
* address-space which can cause some unexpected and
* weird problems later on.
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;
......@@ -352,7 +362,7 @@ void ELFDLL_UnloadLibrary(WINE_MODREF *wm)
*
* Implementation of elf-dll loading for NE modules
*/
HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname, BOOL implicit)
HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname)
{
return (HINSTANCE16)ERROR_FILE_NOT_FOUND;
}
......@@ -374,7 +384,7 @@ void ELFDLL_UnloadLibrary(WINE_MODREF *wm)
{
}
HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname, BOOL implicit)
HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname)
{
return (HINSTANCE16)ERROR_FILE_NOT_FOUND;
}
......
......@@ -291,7 +291,6 @@ HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] )
{
WINE_MODREF *wm;
NE_MODULE *pModule;
OFSTRUCT ofs;
HMODULE16 hModule;
/* Main initialization */
......@@ -302,8 +301,7 @@ HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] )
return 0;
PROCESS_Current()->exe_modref = wm;
strcpy( ofs.szPathName, wm->modname );
if ((hModule = MODULE_CreateDummyModule( &ofs, NULL, 0 )) < 32) return 0;
if ((hModule = MODULE_CreateDummyModule( wm->filename, 0 )) < 32) return 0;
pModule = (NE_MODULE *)GlobalLock16( hModule );
pModule->flags = NE_FFLAGS_WIN32;
pModule->module32 = wm->module;
......
......@@ -278,19 +278,8 @@ DWORD fixup_imports( WINE_MODREF *wm )
if (characteristics_detection && !pe_imp->u.Characteristics)
break;
/* don't use MODULE_Load, Win32 creates new task differently */
wmImp = MODULE_LoadLibraryExA( name, 0, 0 );
if (!wmImp) {
char *p,buffer[2000];
/* GetModuleFileName would use the wrong process, so don't use it */
strcpy(buffer,wm->shortname);
if (!(p = strrchr (buffer, '\\')))
p = buffer;
strcpy (p + 1, name);
wmImp = MODULE_LoadLibraryExA( buffer, 0, 0 );
}
if (!wmImp) {
ERR_(module)("Module %s not found\n", name);
return 1;
}
......@@ -459,7 +448,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( HFILE hFile, OFSTRUCT *ofs, LPCSTR *modName, WORD *version )
HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version )
{
HMODULE hModule;
HANDLE mapping;
......@@ -549,7 +538,7 @@ HMODULE PE_LoadImage( HFILE hFile, OFSTRUCT *ofs, LPCSTR *modName, WORD *version
FIXME_(win32)("WARNING: '%s' has an invalid entrypoint (0x%08lx) "
"below the first virtual address (0x%08x) "
"(possible Virus Infection or broken binary)!\n",
ofs->szPathName, aoep, lowest_va );
filename, aoep, lowest_va );
/* FIXME: Hack! While we don't really support shared sections yet,
......@@ -598,7 +587,7 @@ HMODULE PE_LoadImage( HFILE hFile, OFSTRUCT *ofs, LPCSTR *modName, WORD *version
{
FIXME_(win32)(
"FATAL: Need to relocate %s, but no relocation records present (%s). Try to run that file directly !\n",
ofs->szPathName,
filename,
(nt->FileHeader.Characteristics&IMAGE_FILE_RELOCS_STRIPPED)?
"stripped during link" : "unknown reason" );
goto error;
......@@ -619,7 +608,7 @@ HMODULE PE_LoadImage( HFILE hFile, OFSTRUCT *ofs, LPCSTR *modName, WORD *version
TRACE_(win32)("Load addr is %lx (base %lx), range %x\n",
load_addr, nt->OptionalHeader.ImageBase, vma_size );
TRACE_(segment)("Loading %s at %lx, range %x\n",
ofs->szPathName, load_addr, vma_size );
filename, load_addr, vma_size );
/* Store the NT header at the load addr */
*(PIMAGE_DOS_HEADER)load_addr = *(PIMAGE_DOS_HEADER)hModule;
......@@ -658,11 +647,6 @@ HMODULE PE_LoadImage( HFILE hFile, OFSTRUCT *ofs, LPCSTR *modName, WORD *version
if ( reloc )
do_relocations( load_addr, (IMAGE_BASE_RELOCATION *)RVA(reloc) );
/* Get module name */
dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_EXPORT;
if (dir->Size)
*modName = (LPCSTR)RVA(((PIMAGE_EXPORT_DIRECTORY)RVA(dir->VirtualAddress))->Name);
/* Get expected OS / Subsystem version */
*version = ( (nt->OptionalHeader.MajorSubsystemVersion & 0xff) << 8 )
| (nt->OptionalHeader.MinorSubsystemVersion & 0xff);
......@@ -690,7 +674,7 @@ error:
* process that is to own the module to be created.
*/
WINE_MODREF *PE_CreateModule( HMODULE hModule,
OFSTRUCT *ofs, DWORD flags, BOOL builtin )
LPCSTR filename, DWORD flags, BOOL builtin )
{
DWORD load_addr = (DWORD)hModule; /* for RVA */
IMAGE_NT_HEADERS *nt = PE_HEADER(hModule);
......@@ -700,7 +684,6 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
IMAGE_RESOURCE_DIRECTORY *pe_resource = NULL;
WINE_MODREF *wm;
int result;
char *modname;
/* Retrieve DataDirectory entries */
......@@ -799,22 +782,17 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
wm->binfmt.pe.pe_resource = pe_resource;
wm->binfmt.pe.tlsindex = -1;
if ( pe_export )
modname = (char *)RVA( pe_export->Name );
else
{
/* try to find out the name from the OFSTRUCT */
char *s;
modname = ofs->szPathName;
if ((s=strrchr(modname,'\\'))) modname = s+1;
}
wm->modname = HEAP_strdupA( GetProcessHeap(), 0, modname );
result = GetLongPathNameA( ofs->szPathName, NULL, 0 );
wm->longname = (char *)HeapAlloc( GetProcessHeap(), 0, result+1 );
GetLongPathNameA( ofs->szPathName, wm->longname, result+1 );
wm->filename = HEAP_strdupA( GetProcessHeap(), 0, filename );
wm->modname = strrchr( wm->filename, '\\' );
if (!wm->modname) wm->modname = wm->filename;
else wm->modname++;
wm->shortname = HEAP_strdupA( GetProcessHeap(), 0, ofs->szPathName );
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 */
......@@ -824,11 +802,14 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
PROCESS_Current()->modref_list = wm;
if ( wm->next ) wm->next->prev = wm;
if ( !(nt->FileHeader.Characteristics & IMAGE_FILE_DLL) )
if ( !( nt->FileHeader.Characteristics & IMAGE_FILE_DLL )
&& !( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE ) )
{
if ( PROCESS_Current()->exe_modref )
FIXME_(win32)("overwriting old exe_modref... arrgh\n" );
PROCESS_Current()->exe_modref = wm;
FIXME_(win32)( "Trying to load second .EXE file: %s\n", filename );
else
PROCESS_Current()->exe_modref = wm;
}
LeaveCriticalSection( &PROCESS_Current()->crit_section );
......@@ -878,41 +859,41 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule,
*/
WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags, DWORD *err)
{
LPCSTR modName = NULL;
OFSTRUCT ofs;
HMODULE hModule32;
HMODULE16 hModule16;
NE_MODULE *pModule;
WINE_MODREF *wm;
char dllname[256], *p;
HFILE hFile;
char filename[256];
HANDLE hFile;
WORD version = 0;
/* Append .DLL to name if no extension present */
strcpy( dllname, name );
if (!(p = strrchr( dllname, '.')) || strchr( p, '/' ) || strchr( p, '\\'))
strcat( dllname, ".DLL" );
/* Load PE module */
hFile = OpenFile( dllname, &ofs, OF_READ | OF_SHARE_DENY_WRITE );
if ( hFile != HFILE_ERROR )
/* Search for and open PE file */
if ( SearchPathA( NULL, name, ".DLL",
sizeof(filename), filename, NULL ) == 0 )
{
hModule32 = PE_LoadImage( hFile, &ofs, &modName, &version );
CloseHandle( hFile );
if(!hModule32)
{
*err = ERROR_OUTOFMEMORY; /* Not entirely right, but good enough */
return NULL;
}
*err = ERROR_FILE_NOT_FOUND;
return NULL;
}
else
hFile = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, -1 );
if ( hFile == INVALID_HANDLE_VALUE )
{
*err = ERROR_FILE_NOT_FOUND;
return NULL;
}
/* Load PE module */
hModule32 = PE_LoadImage( hFile, filename, &version );
CloseHandle( hFile );
if (!hModule32)
{
*err = ERROR_OUTOFMEMORY; /* Not entirely right, but good enough */
return NULL;
}
/* Create 16-bit dummy module */
if ((hModule16 = MODULE_CreateDummyModule( &ofs, modName, version )) < 32)
if ((hModule16 = MODULE_CreateDummyModule( filename, version )) < 32)
{
*err = (DWORD)hModule16; /* This should give the correct error */
return NULL;
......@@ -922,9 +903,9 @@ WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags, DWORD *err)
pModule->module32 = hModule32;
/* Create 32-bit MODREF */
if ( !(wm = PE_CreateModule( hModule32, &ofs, flags, FALSE )) )
if ( !(wm = PE_CreateModule( hModule32, filename, flags, FALSE )) )
{
ERR_(win32)("can't load %s\n",ofs.szPathName);
ERR_(win32)( "can't load %s\n", filename );
FreeLibrary16( hModule16 );
*err = ERROR_OUTOFMEMORY;
return NULL;
......@@ -953,19 +934,18 @@ void PE_UnloadLibrary(WINE_MODREF *wm)
* FIXME: this function should use PE_LoadLibraryExA, but currently can't
* due to the PROCESS_Create stuff.
*/
BOOL PE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line, LPCSTR env,
BOOL PE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR env,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
LPPROCESS_INFORMATION info )
{
LPCSTR modName = NULL;
WORD version = 0;
HMODULE16 hModule16;
HMODULE hModule32;
NE_MODULE *pModule;
/* Load file */
if ( (hModule32 = PE_LoadImage( hFile, ofs, &modName, &version )) < 32 )
if ( (hModule32 = PE_LoadImage( hFile, filename, &version )) < 32 )
{
SetLastError( hModule32 );
return FALSE;
......@@ -979,7 +959,7 @@ BOOL PE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line, LPCSTR env,
#endif
/* Create 16-bit dummy module */
if ( (hModule16 = MODULE_CreateDummyModule( ofs, modName, version )) < 32 )
if ( (hModule16 = MODULE_CreateDummyModule( filename, version )) < 32 )
{
SetLastError( hModule16 );
return FALSE;
......
......@@ -411,106 +411,77 @@ static HMODULE BUILTIN32_DoLoadImage( BUILTIN32_DLL *dll )
}
/***********************************************************************
* BUILTIN32_LoadImage
* BUILTIN32_LoadLibraryExA
*
* Partly copied from the original PE_ version.
*
* Load a built-in module.
*/
HMODULE BUILTIN32_LoadImage( LPCSTR name, OFSTRUCT *ofs)
WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR path, DWORD flags, DWORD *err)
{
BUILTIN32_DLL *table;
char dllname[16], *p;
HMODULE16 hModule16;
NE_MODULE *pModule;
WINE_MODREF *wm;
char dllname[256], *p;
/* Fix the name in case we have a full path and extension */
if ((p = strrchr( name, '\\' ))) name = p + 1;
lstrcpynA( dllname, name, sizeof(dllname) );
if ((p = strrchr( path, '\\' ))) path = p + 1;
lstrcpynA( dllname, path, sizeof(dllname) );
p = strrchr( dllname, '.' );
if (!p) strcat( dllname, ".dll" );
for (table = BuiltinDLLs; table->descr; table++)
{
if (!lstrcmpiA( table->descr->filename, dllname )) break;
}
/* Search built-in descriptor */
for ( table = BuiltinDLLs; table->descr; table++ )
if (!lstrcmpiA( table->descr->filename, dllname )) break;
if (!table->descr) return 0;
if ( (table->flags & BI32_INSTANTIATED) && (table->flags & BI32_DANGER) )
if ( !table->descr )
{
ERR_(module)("Attemp to instantiate built-in dll '%s' twice in the same address-space. Expect trouble!\n",
table->descr->name);
*err = ERROR_FILE_NOT_FOUND;
return NULL;
}
strcpy( ofs->szPathName, table->descr->filename );
/* Load built-in module */
if ( (table->flags & BI32_INSTANTIATED) && (table->flags & BI32_DANGER) )
ERR_(module)( "Attempt to instantiate built-in dll '%s' twice "
"in the same address-space. Expect trouble!\n",
table->descr->name );
if ( !table->hModule )
table->hModule = BUILTIN32_DoLoadImage( table );
if ( table->hModule )
table->flags |= BI32_INSTANTIATED;
return table->hModule;
}
/***********************************************************************
* BUILTIN32_LoadLibraryExA
*
* Partly copied from the original PE_ version.
*
* Note: This implementation is not very nice and should be one with
* the BUILTIN32_LoadImage function. But, we don't care too much
* because this code will obsolete itself shortly when we get the
* modularization of wine implemented (BS 05-Mar-1999).
*/
WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR path, DWORD flags, DWORD *err)
{
LPCSTR modName = NULL;
OFSTRUCT ofs;
HMODULE hModule32;
HMODULE16 hModule16;
NE_MODULE *pModule;
WINE_MODREF *wm;
char dllname[256], *p;
/* Append .DLL to name if no extension present */
strcpy( dllname, path );
if (!(p = strrchr( dllname, '.')) || strchr( p, '/' ) || strchr( p, '\\'))
strcat( dllname, ".DLL" );
hModule32 = BUILTIN32_LoadImage(path, &ofs);
if(!hModule32)
{
*err = ERROR_FILE_NOT_FOUND;
return NULL;
}
table->flags |= BI32_INSTANTIATED;
else
{
*err = ERROR_FILE_NOT_FOUND;
return NULL;
}
/* Create 16-bit dummy module */
if ((hModule16 = MODULE_CreateDummyModule( &ofs, modName, 0 )) < 32)
{
*err = (DWORD)hModule16;
return NULL; /* FIXME: Should unload the builtin module */
}
/* Create 16-bit dummy module */
if ((hModule16 = MODULE_CreateDummyModule( dllname, 0 )) < 32)
{
*err = (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;
pModule->module32 = hModule32;
pModule = (NE_MODULE *)GlobalLock16( hModule16 );
pModule->flags = NE_FFLAGS_LIBMODULE | NE_FFLAGS_SINGLEDATA | NE_FFLAGS_WIN32 | NE_FFLAGS_BUILTIN;
pModule->module32 = table->hModule;
/* Create 32-bit MODREF */
if ( !(wm = PE_CreateModule( hModule32, &ofs, flags, TRUE )) )
{
ERR_(win32)("can't load %s\n",ofs.szPathName);
FreeLibrary16( hModule16 ); /* FIXME: Should unload the builtin module */
*err = ERROR_OUTOFMEMORY;
return NULL;
}
/* Create 32-bit MODREF */
if ( !(wm = PE_CreateModule( table->hModule, dllname, flags, TRUE )) )
{
ERR_(win32)( "can't load %s\n", path );
FreeLibrary16( hModule16 ); /* FIXME: Should unload the builtin module */
*err = ERROR_OUTOFMEMORY;
return NULL;
}
if (wm->binfmt.pe.pe_export)
SNOOP_RegisterDLL(wm->module,wm->modname,wm->binfmt.pe.pe_export->NumberOfFunctions);
if (wm->binfmt.pe.pe_export)
SNOOP_RegisterDLL(wm->module,wm->modname,wm->binfmt.pe.pe_export->NumberOfFunctions);
*err = 0;
return wm;
*err = 0;
return wm;
}
......
......@@ -9,6 +9,7 @@
#include <string.h>
#include <unistd.h>
#include "wine/winbase16.h"
#include "wine/exception.h"
#include "process.h"
#include "module.h"
#include "neexe.h"
......@@ -55,7 +56,7 @@ void PROCESS_WalkProcess(void)
if (pdb == &initial_pdb)
name = "initial PDB";
else
name = (pdb->exe_modref) ? pdb->exe_modref->shortname : "";
name = (pdb->exe_modref) ? pdb->exe_modref->filename : "";
MESSAGE( " %8p %8p %5d %8p %s\n", pdb->server_pid, pdb,
pdb->threads, pdb->exe_modref, name);
......@@ -389,7 +390,7 @@ void PROCESS_Start(void)
LPTHREAD_START_ROUTINE entry = NULL;
PDB *pdb = PROCESS_Current();
NE_MODULE *pModule = NE_GetPtr( pdb->module );
OFSTRUCT *ofs = (OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo);
LPCSTR filename = ((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName;
IMAGE_OPTIONAL_HEADER *header = !pModule->module32? NULL :
&PE_HEADER(pModule->module32)->OptionalHeader;
......@@ -457,7 +458,7 @@ void PROCESS_Start(void)
DEBUG_SendCreateProcessEvent( -1 /*FIXME*/, pModule->module32, entry );
/* Create 32-bit MODREF */
if (!PE_CreateModule( pModule->module32, ofs, 0, FALSE )) goto error;
if (!PE_CreateModule( pModule->module32, filename, 0, FALSE )) goto error;
/* Increment EXE refcount */
assert( pdb->exe_modref );
......
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