From c7a51eec433ce3628729f00263522523bd37a3af Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 20 May 2003 02:32:26 +0000 Subject: [PATCH] Only create the 16-bit dummy module when we need really it. --- dlls/ntdll/loader.c | 1 - include/module.h | 3 +-- loader/module.c | 23 ++++++++++++----------- loader/ne/module.c | 11 +++++++++-- loader/pe_image.c | 22 ++-------------------- 5 files changed, 24 insertions(+), 36 deletions(-) diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 660d0945913..b8c82bcd494 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -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 ); diff --git a/include/module.h b/include/module.h index 6931cd0c2f4..15cb8b4b378 100644 --- a/include/module.h +++ b/include/module.h @@ -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 ); diff --git a/loader/module.c b/loader/module.c index f9b555dbea2..ccef1cf253a 100644 --- a/loader/module.c +++ b/loader/module.c @@ -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; } diff --git a/loader/ne/module.c b/loader/ne/module.c index bc75fb7d25a..82eee9be148 100644 --- a/loader/ne/module.c +++ b/loader/ne/module.c @@ -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; } /*************************************************************************** diff --git a/loader/pe_image.c b/loader/pe_image.c index c74fe2d24ed..6760783586c 100644 --- a/loader/pe_image.c +++ b/loader/pe_image.c @@ -41,7 +41,7 @@ #include #endif #include -#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;