Commit 09e00cf4 authored by Alexandre Julliard's avatar Alexandre Julliard

Better handling of 16-bit native dlls when a 32-bit builtin with the

same name exists; should help with the 16-bit cards.dll issue. Replace some magic error numbers by the corresponding names.
parent d99df2b7
...@@ -632,17 +632,17 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -632,17 +632,17 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
if (!read_data( handle, 0, &mz_header, sizeof(mz_header)) || if (!read_data( handle, 0, &mz_header, sizeof(mz_header)) ||
(mz_header.e_magic != IMAGE_DOS_SIGNATURE)) (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
if (!read_data( handle, mz_header.e_lfanew, &ne_header, sizeof(ne_header) )) if (!read_data( handle, mz_header.e_lfanew, &ne_header, sizeof(ne_header) ))
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
if (ne_header.ne_magic == IMAGE_NT_SIGNATURE) return (HMODULE16)21; /* win32 exe */ if (ne_header.ne_magic == IMAGE_NT_SIGNATURE) return (HMODULE16)21; /* win32 exe */
if (ne_header.ne_magic == IMAGE_OS2_SIGNATURE_LX) { if (ne_header.ne_magic == IMAGE_OS2_SIGNATURE_LX) {
MESSAGE("Sorry, this is an OS/2 linear executable (LX) file!\n"); MESSAGE("Sorry, this is an OS/2 linear executable (LX) file!\n");
return (HMODULE16)12; return (HMODULE16)12;
} }
if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE) return (HMODULE16)11; /* invalid exe */ if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE) return ERROR_BAD_FORMAT;
/* We now have a valid NE header */ /* We now have a valid NE header */
...@@ -651,7 +651,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -651,7 +651,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
* (only fail for OS/2 ne_exetyp 0x01 here?) */ * (only fail for OS/2 ne_exetyp 0x01 here?) */
if ((ne_header.ne_exetyp != 0x02 /* Windows */) if ((ne_header.ne_exetyp != 0x02 /* Windows */)
&& (ne_header.ne_exetyp != 0x04) /* Windows 386 */) && (ne_header.ne_exetyp != 0x04) /* Windows 386 */)
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
size = sizeof(NE_MODULE) + size = sizeof(NE_MODULE) +
/* segment table */ /* segment table */
...@@ -673,7 +673,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -673,7 +673,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
sizeof(OFSTRUCT) - sizeof(ofs->szPathName) + strlen(path) + 1; sizeof(OFSTRUCT) - sizeof(ofs->szPathName) + strlen(path) + 1;
hModule = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, size ); hModule = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, size );
if (!hModule) return (HMODULE16)11; /* invalid exe */ if (!hModule) return ERROR_BAD_FORMAT;
FarSetOwner16( hModule, hModule ); FarSetOwner16( hModule, hModule );
pModule = (NE_MODULE *)GlobalLock16( hModule ); pModule = (NE_MODULE *)GlobalLock16( hModule );
...@@ -728,7 +728,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -728,7 +728,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
HeapFree( GetProcessHeap(), 0, buffer ); HeapFree( GetProcessHeap(), 0, buffer );
HeapFree( GetProcessHeap(), 0, fastload ); HeapFree( GetProcessHeap(), 0, fastload );
GlobalFree16( hModule ); GlobalFree16( hModule );
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
} }
pSeg = (struct ne_segment_table_entry_s *)buffer; pSeg = (struct ne_segment_table_entry_s *)buffer;
for (i = ne_header.ne_cseg; i > 0; i--, pSeg++) for (i = ne_header.ne_cseg; i > 0; i--, pSeg++)
...@@ -742,7 +742,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -742,7 +742,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
{ {
HeapFree( GetProcessHeap(), 0, fastload ); HeapFree( GetProcessHeap(), 0, fastload );
GlobalFree16( hModule ); GlobalFree16( hModule );
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
} }
/* Get the resource table */ /* Get the resource table */
...@@ -753,7 +753,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -753,7 +753,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
if (!READ(mz_header.e_lfanew + ne_header.ne_rsrctab, if (!READ(mz_header.e_lfanew + ne_header.ne_rsrctab,
ne_header.ne_restab - ne_header.ne_rsrctab, ne_header.ne_restab - ne_header.ne_rsrctab,
pData )) pData ))
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
pData += ne_header.ne_restab - ne_header.ne_rsrctab; pData += ne_header.ne_restab - ne_header.ne_rsrctab;
NE_InitResourceHandler( pModule ); NE_InitResourceHandler( pModule );
} }
...@@ -768,7 +768,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -768,7 +768,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
{ {
HeapFree( GetProcessHeap(), 0, fastload ); HeapFree( GetProcessHeap(), 0, fastload );
GlobalFree16( hModule ); GlobalFree16( hModule );
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
} }
pData += ne_header.ne_modtab - ne_header.ne_restab; pData += ne_header.ne_modtab - ne_header.ne_restab;
...@@ -783,7 +783,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -783,7 +783,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
{ {
HeapFree( GetProcessHeap(), 0, fastload ); HeapFree( GetProcessHeap(), 0, fastload );
GlobalFree16( hModule ); GlobalFree16( hModule );
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
} }
pData += ne_header.ne_cmod * sizeof(WORD); pData += ne_header.ne_cmod * sizeof(WORD);
} }
...@@ -798,7 +798,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -798,7 +798,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
{ {
HeapFree( GetProcessHeap(), 0, fastload ); HeapFree( GetProcessHeap(), 0, fastload );
GlobalFree16( hModule ); GlobalFree16( hModule );
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
} }
pData += ne_header.ne_enttab - ne_header.ne_imptab; pData += ne_header.ne_enttab - ne_header.ne_imptab;
...@@ -816,7 +816,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -816,7 +816,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
HeapFree( GetProcessHeap(), 0, pTempEntryTable ); HeapFree( GetProcessHeap(), 0, pTempEntryTable );
HeapFree( GetProcessHeap(), 0, fastload ); HeapFree( GetProcessHeap(), 0, fastload );
GlobalFree16( hModule ); GlobalFree16( hModule );
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
} }
s = pTempEntryTable; s = pTempEntryTable;
...@@ -870,7 +870,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -870,7 +870,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
bundle->first = bundle->last = bundle->first = bundle->last =
oldbundle->last + nr_entries; oldbundle->last + nr_entries;
bundle->next = 0; bundle->next = 0;
entry = (ET_ENTRY*)(((BYTE*)entry)+sizeof(ET_BUNDLE)); entry = (ET_ENTRY*)(((BYTE*)entry)+sizeof(ET_BUNDLE));
} }
} }
} }
...@@ -880,7 +880,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -880,7 +880,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
{ {
HeapFree( GetProcessHeap(), 0, fastload ); HeapFree( GetProcessHeap(), 0, fastload );
GlobalFree16( hModule ); GlobalFree16( hModule );
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
} }
pData += ne_header.ne_cbenttab + sizeof(ET_BUNDLE) + pData += ne_header.ne_cbenttab + sizeof(ET_BUNDLE) +
...@@ -912,7 +912,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -912,7 +912,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
if (!pModule->nrname_handle) if (!pModule->nrname_handle)
{ {
GlobalFree16( hModule ); GlobalFree16( hModule );
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
} }
FarSetOwner16( pModule->nrname_handle, hModule ); FarSetOwner16( pModule->nrname_handle, hModule );
buffer = GlobalLock16( pModule->nrname_handle ); buffer = GlobalLock16( pModule->nrname_handle );
...@@ -920,7 +920,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -920,7 +920,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
{ {
GlobalFree16( pModule->nrname_handle ); GlobalFree16( pModule->nrname_handle );
GlobalFree16( hModule ); GlobalFree16( hModule );
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
} }
} }
else pModule->nrname_handle = 0; else pModule->nrname_handle = 0;
...@@ -935,7 +935,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -935,7 +935,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
{ {
if (pModule->nrname_handle) GlobalFree16( pModule->nrname_handle ); if (pModule->nrname_handle) GlobalFree16( pModule->nrname_handle );
GlobalFree16( hModule ); GlobalFree16( hModule );
return (HMODULE16)11; /* invalid exe */ return ERROR_BAD_FORMAT;
} }
FarSetOwner16( pModule->dlls_to_init, hModule ); FarSetOwner16( pModule->dlls_to_init, hModule );
} }
...@@ -1159,6 +1159,7 @@ static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_ ...@@ -1159,6 +1159,7 @@ static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_
const BUILTIN16_DESCRIPTOR *descr = NULL; const BUILTIN16_DESCRIPTOR *descr = NULL;
char dllname[20], owner[20], *p; char dllname[20], owner[20], *p;
const char *basename; const char *basename;
int owner_exists;
/* strip path information */ /* strip path information */
...@@ -1169,23 +1170,21 @@ static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_ ...@@ -1169,23 +1170,21 @@ static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_
if (strlen(basename) < sizeof(dllname)-4) if (strlen(basename) < sizeof(dllname)-4)
{ {
int file_exists;
strcpy( dllname, basename ); strcpy( dllname, basename );
p = strrchr( dllname, '.' ); p = strrchr( dllname, '.' );
if (!p) strcat( dllname, ".dll" ); if (!p) strcat( dllname, ".dll" );
for (p = dllname; *p; p++) if (*p >= 'A' && *p <= 'Z') *p += 32; for (p = dllname; *p; p++) if (*p >= 'A' && *p <= 'Z') *p += 32;
if (wine_dll_get_owner( dllname, owner, sizeof(owner), &file_exists ) == -1) if (wine_dll_get_owner( dllname, owner, sizeof(owner), &owner_exists ) != -1)
{
if (file_exists) return 21; /* it may be a Win32 module then */
}
else /* found 32-bit owner, try to load it */
{ {
HMODULE mod32 = LoadLibraryA( owner ); HMODULE mod32 = LoadLibraryA( owner );
if (mod32) if (mod32)
{ {
if (!(descr = find_dll_descr( dllname ))) FreeLibrary( mod32 ); if (!(descr = find_dll_descr( dllname )))
{
FreeLibrary( mod32 );
owner_exists = 0;
}
/* loading the 32-bit library can have the side effect of loading the module */ /* loading the 32-bit library can have the side effect of loading the module */
/* if so, simply incr the ref count and return the module */ /* if so, simply incr the ref count and return the module */
if ((hModule = GetModuleHandle16( libname ))) if ((hModule = GetModuleHandle16( libname )))
...@@ -1216,6 +1215,7 @@ static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_ ...@@ -1216,6 +1215,7 @@ static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_
TRACE("Trying native dll '%s'\n", libname); TRACE("Trying native dll '%s'\n", libname);
hinst = NE_LoadModule(libname, lib_only); hinst = NE_LoadModule(libname, lib_only);
if (hinst > 32) TRACE_(loaddll)("Loaded module %s : native\n", debugstr_a(libname)); if (hinst > 32) TRACE_(loaddll)("Loaded module %s : native\n", debugstr_a(libname));
if (hinst == ERROR_FILE_NOT_FOUND && owner_exists) hinst = 21; /* win32 module */
} }
if (hinst > 32 && !implicit) if (hinst > 32 && !implicit)
...@@ -1310,7 +1310,7 @@ HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock ) ...@@ -1310,7 +1310,7 @@ HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
{ {
/* Special case: second instance of an already loaded NE module */ /* Special case: second instance of an already loaded NE module */
if ( !( pModule = NE_GetPtr( hModule ) ) ) return (HINSTANCE16)11; if ( !( pModule = NE_GetPtr( hModule ) ) ) return ERROR_BAD_FORMAT;
if ( pModule->module32 ) return (HINSTANCE16)21; if ( pModule->module32 ) return (HINSTANCE16)21;
/* Increment refcount */ /* Increment refcount */
...@@ -1325,7 +1325,7 @@ HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock ) ...@@ -1325,7 +1325,7 @@ HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
return hModule; return hModule;
if ( !(pModule = NE_GetPtr( hModule )) ) if ( !(pModule = NE_GetPtr( hModule )) )
return (HINSTANCE16)11; return ERROR_BAD_FORMAT;
} }
/* If library module, we just retrieve the instance handle */ /* If library module, we just retrieve the instance handle */
...@@ -1827,7 +1827,7 @@ HINSTANCE16 WINAPI WinExec16( LPCSTR lpCmdLine, UINT16 nCmdShow ) ...@@ -1827,7 +1827,7 @@ HINSTANCE16 WINAPI WinExec16( LPCSTR lpCmdLine, UINT16 nCmdShow )
HeapFree( GetProcessHeap(), 0, cmdline ); HeapFree( GetProcessHeap(), 0, cmdline );
if (name != lpCmdLine) HeapFree( GetProcessHeap(), 0, name ); if (name != lpCmdLine) HeapFree( GetProcessHeap(), 0, name );
if (ret == 21 || ret == 11) /* 32-bit module or unknown executable*/ if (ret == 21 || ret == ERROR_BAD_FORMAT) /* 32-bit module or unknown executable*/
{ {
DWORD count; DWORD count;
ReleaseThunkLock( &count ); ReleaseThunkLock( &count );
...@@ -2094,11 +2094,11 @@ static HMODULE16 create_dummy_module( HMODULE module32 ) ...@@ -2094,11 +2094,11 @@ static HMODULE16 create_dummy_module( HMODULE module32 )
char filename[MAX_PATH]; char filename[MAX_PATH];
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( module32 ); IMAGE_NT_HEADERS *nt = RtlImageNtHeader( module32 );
if (!nt) return (HMODULE16)11; /* invalid exe */ if (!nt) return ERROR_BAD_FORMAT;
/* Extract base filename */ /* Extract base filename */
len = GetModuleFileNameA( module32, filename, sizeof(filename) ); len = GetModuleFileNameA( module32, filename, sizeof(filename) );
if (!len || len >= sizeof(filename)) return (HMODULE16)11; /* invalid exe */ if (!len || len >= sizeof(filename)) return ERROR_BAD_FORMAT;
basename = strrchr(filename, '\\'); basename = strrchr(filename, '\\');
if (!basename) basename = filename; if (!basename) basename = filename;
else basename++; else basename++;
...@@ -2119,7 +2119,7 @@ static HMODULE16 create_dummy_module( HMODULE module32 ) ...@@ -2119,7 +2119,7 @@ static HMODULE16 create_dummy_module( HMODULE module32 )
8; 8;
hModule = GlobalAlloc16( GMEM_MOVEABLE | GMEM_ZEROINIT, size ); hModule = GlobalAlloc16( GMEM_MOVEABLE | GMEM_ZEROINIT, size );
if (!hModule) return (HMODULE16)11; /* invalid exe */ if (!hModule) return ERROR_BAD_FORMAT;
FarSetOwner16( hModule, hModule ); FarSetOwner16( hModule, hModule );
pModule = (NE_MODULE *)GlobalLock16( hModule ); pModule = (NE_MODULE *)GlobalLock16( hModule );
......
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