Commit c7a51eec authored by Alexandre Julliard's avatar Alexandre Julliard

Only create the 16-bit dummy module when we need really it.

parent 69c71649
......@@ -1272,7 +1272,6 @@ static void MODULE_FlushModrefs(void)
if (wm->dlhandle) wine_dll_unload( wm->dlhandle );
else NtUnmapViewOfSection( GetCurrentProcess(), wm->ldr.BaseAddress );
FreeLibrary16( wm->hDummyMod );
if (cached_modref == wm) cached_modref = NULL;
RtlFreeHeap( ntdll_get_process_heap(), 0, wm->deps );
RtlFreeHeap( ntdll_get_process_heap(), 0, wm );
......
......@@ -130,7 +130,6 @@ typedef struct _wine_modref
{
struct _wine_modref *next;
struct _wine_modref *prev;
HMODULE16 hDummyMod; /* Win16 dummy module */
void *dlhandle; /* handle returned by dlopen() */
LDR_MODULE ldr;
......@@ -184,7 +183,7 @@ enum binary_type
extern NTSTATUS MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved );
extern NTSTATUS MODULE_DllThreadAttach( LPVOID lpReserved );
extern WINE_MODREF *MODULE_FindModule( LPCSTR path );
extern HMODULE16 MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 );
extern HMODULE16 MODULE_CreateDummyModule( HMODULE module32 );
extern enum binary_type MODULE_GetBinaryType( HANDLE hfile );
extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hmodule, LPCSTR name );
extern SEGPTR WINAPI HasGPHandler16( SEGPTR address );
......
......@@ -90,7 +90,7 @@ BOOL WINAPI DisableThreadLibraryCalls( HMODULE hModule )
*
* Create a dummy NE module for Win32 or Winelib.
*/
HMODULE16 MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 )
HMODULE16 MODULE_CreateDummyModule( HMODULE module32 )
{
HMODULE16 hModule;
NE_MODULE *pModule;
......@@ -100,8 +100,13 @@ HMODULE16 MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 )
const char* basename;
OFSTRUCT *ofs;
int of_size, size;
char filename[MAX_PATH];
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( module32 );
if (!nt) return (HMODULE16)11; /* invalid exe */
/* Extract base filename */
GetModuleFileNameA( module32, filename, sizeof(filename) );
basename = strrchr(filename, '\\');
if (!basename) basename = filename;
else basename++;
......@@ -131,7 +136,7 @@ HMODULE16 MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 )
pModule->magic = IMAGE_OS2_SIGNATURE;
pModule->count = 1;
pModule->next = 0;
pModule->flags = 0;
pModule->flags = NE_FFLAGS_WIN32;
pModule->dgroup = 0;
pModule->ss = 1;
pModule->cs = 2;
......@@ -146,15 +151,10 @@ HMODULE16 MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 )
pModule->module32 = module32;
/* Set version and flags */
if (module32)
{
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( module32 );
pModule->expected_version = ((nt->OptionalHeader.MajorSubsystemVersion & 0xff) << 8 ) |
(nt->OptionalHeader.MinorSubsystemVersion & 0xff);
pModule->flags |= NE_FFLAGS_WIN32;
if (nt->FileHeader.Characteristics & IMAGE_FILE_DLL)
pModule->flags |= NE_FFLAGS_LIBMODULE | NE_FFLAGS_SINGLEDATA;
}
pModule->expected_version = ((nt->OptionalHeader.MajorSubsystemVersion & 0xff) << 8 ) |
(nt->OptionalHeader.MinorSubsystemVersion & 0xff);
if (nt->FileHeader.Characteristics & IMAGE_FILE_DLL)
pModule->flags |= NE_FFLAGS_LIBMODULE | NE_FFLAGS_SINGLEDATA;
/* Set loaded file information */
ofs = (OFSTRUCT *)(pModule + 1);
......@@ -186,6 +186,7 @@ HMODULE16 MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 )
(int)pStr - (int)pModule;
NE_RegisterModule( pModule );
LoadLibraryA( filename ); /* increment the ref count of the 32-bit module */
return hModule;
}
......
......@@ -1714,7 +1714,9 @@ BOOL16 WINAPI IsRomFile16( HFILE16 unused )
/***************************************************************************
* MapHModuleLS (KERNEL32.@)
*/
HMODULE16 WINAPI MapHModuleLS(HMODULE hmod) {
HMODULE16 WINAPI MapHModuleLS(HMODULE hmod)
{
HMODULE16 ret;
NE_MODULE *pModule;
if (!hmod)
......@@ -1727,7 +1729,12 @@ HMODULE16 WINAPI MapHModuleLS(HMODULE hmod) {
return pModule->self;
pModule = (NE_MODULE*)GlobalLock16(pModule->next);
}
return 0;
if ((ret = MODULE_CreateDummyModule( hmod )) < 32)
{
SetLastError(ret);
ret = 0;
}
return ret;
}
/***************************************************************************
......
......@@ -41,7 +41,7 @@
#include <sys/mman.h>
#endif
#include <string.h>
#include "wine/winbase16.h"
#include "winbase.h"
#include "winerror.h"
#include "snoop.h"
#include "wine/server.h"
......@@ -183,7 +183,6 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename, DWORD flags,
IMAGE_DATA_DIRECTORY *dir;
IMAGE_EXPORT_DIRECTORY *pe_export = NULL;
WINE_MODREF *wm;
HMODULE16 hModule16;
/* Retrieve DataDirectory entries */
......@@ -247,29 +246,12 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename, DWORD flags,
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 */
if (!(wm = MODULE_AllocModRef( hModule, filename )))
{
FreeLibrary16( hModule16 );
return NULL;
}
wm->hDummyMod = hModule16;
if (!(wm = MODULE_AllocModRef( hModule, filename ))) return NULL;
if ( builtin )
{
NE_MODULE *pModule = (NE_MODULE *)GlobalLock16( hModule16 );
pModule->flags |= NE_FFLAGS_BUILTIN;
wm->ldr.Flags |= LDR_WINE_INTERNAL;
}
else if ( flags & DONT_RESOLVE_DLL_REFERENCES )
wm->ldr.Flags |= LDR_DONT_RESOLVE_REFS;
......
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