Commit 8ff37b8f authored by Alexandre Julliard's avatar Alexandre Julliard

Set low-order bit of module handle for LOAD_LIBRARY_AS_DATAFILE.

Cleaned up a few HMODULE/HMODULE16 mismatches.
parent a3b562f7
......@@ -171,7 +171,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( LPCSTR filename, HMODULE module32 );
extern HMODULE16 MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 );
extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hmodule, LPCSTR name );
extern SEGPTR WINAPI HasGPHandler16( SEGPTR address );
extern void MODULE_WalkModref( DWORD id );
......@@ -255,7 +255,7 @@ extern int BUILTIN32_dlclose( void *handle );
#define USIG_PROCESS_LOADED 0x0600
/* scheduler/process.c */
extern void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule );
extern void PROCESS_CallUserSignalProc( UINT uCode, HMODULE16 hModule );
extern BOOL PROCESS_Create( HANDLE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags,
......
......@@ -334,9 +334,9 @@ BOOL WINAPI DisableThreadLibraryCalls( HMODULE hModule )
*
* Create a dummy NE module for Win32 or Winelib.
*/
HMODULE MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 )
HMODULE16 MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 )
{
HMODULE hModule;
HMODULE16 hModule;
NE_MODULE *pModule;
SEGTABLEENTRY *pSegment;
char *pStr,*s;
......@@ -366,7 +366,7 @@ HMODULE MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 )
8;
hModule = GlobalAlloc16( GMEM_MOVEABLE | GMEM_ZEROINIT, size );
if (!hModule) return (HMODULE)11; /* invalid exe */
if (!hModule) return (HMODULE16)11; /* invalid exe */
FarSetOwner16( hModule, hModule );
pModule = (NE_MODULE *)GlobalLock16( hModule );
......@@ -819,7 +819,7 @@ HINSTANCE16 WINAPI WinExec16( LPCSTR lpCmdLine, UINT16 nCmdShow )
{
DWORD count;
ReleaseThunkLock( &count );
ret = WinExec( lpCmdLine, nCmdShow );
ret = LOWORD( WinExec( lpCmdLine, nCmdShow ) );
RestoreThunkLock( count );
}
return ret;
......@@ -850,15 +850,15 @@ HINSTANCE WINAPI WinExec( LPCSTR lpCmdLine, UINT nCmdShow )
if (Callout.WaitForInputIdle &&
Callout.WaitForInputIdle( info.hProcess, 30000 ) == 0xFFFFFFFF)
WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
hInstance = 33;
hInstance = (HINSTANCE)33;
/* Close off the handles */
CloseHandle( info.hThread );
CloseHandle( info.hProcess );
}
else if ((hInstance = GetLastError()) >= 32)
else if ((hInstance = (HINSTANCE)GetLastError()) >= (HINSTANCE)32)
{
FIXME("Strange error set by CreateProcess: %d\n", hInstance );
hInstance = 11;
hInstance = (HINSTANCE)11;
}
HeapFree( GetProcessHeap(), 0, cmdline );
return hInstance;
......@@ -877,15 +877,15 @@ HINSTANCE WINAPI LoadModule( LPCSTR name, LPVOID paramBlock )
char filename[MAX_PATH];
BYTE len;
if (!name) return ERROR_FILE_NOT_FOUND;
if (!name) return (HINSTANCE)ERROR_FILE_NOT_FOUND;
if (!SearchPathA( NULL, name, ".exe", sizeof(filename), filename, NULL ) &&
!SearchPathA( NULL, name, NULL, sizeof(filename), filename, NULL ))
return GetLastError();
return (HINSTANCE)GetLastError();
len = (BYTE)params->lpCmdLine[0];
if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + len + 2 )))
return ERROR_NOT_ENOUGH_MEMORY;
return (HINSTANCE)ERROR_NOT_ENOUGH_MEMORY;
strcpy( cmdline, filename );
p = cmdline + strlen(cmdline);
......@@ -908,15 +908,15 @@ HINSTANCE WINAPI LoadModule( LPCSTR name, LPVOID paramBlock )
if (Callout.WaitForInputIdle &&
Callout.WaitForInputIdle( info.hProcess, 30000 ) == 0xFFFFFFFF )
WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
hInstance = 33;
hInstance = (HINSTANCE)33;
/* Close off the handles */
CloseHandle( info.hThread );
CloseHandle( info.hProcess );
}
else if ((hInstance = GetLastError()) >= 32)
else if ((hInstance = (HINSTANCE)GetLastError()) >= (HINSTANCE)32)
{
FIXME("Strange error set by CreateProcess: %d\n", hInstance );
hInstance = 11;
hInstance = (HINSTANCE)11;
}
HeapFree( GetProcessHeap(), 0, cmdline );
......@@ -1268,7 +1268,7 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
hmod = PE_LoadImage( hFile, filename, flags );
CloseHandle( hFile );
}
if (hmod) return hmod;
if (hmod) return (HMODULE)((ULONG_PTR)hmod + 1);
}
flags |= DONT_RESOLVE_DLL_REFERENCES; /* Just in case */
/* Fallback to normal behaviour */
......@@ -1537,14 +1537,24 @@ BOOL WINAPI FreeLibrary(HINSTANCE hLibModule)
BOOL retv = FALSE;
WINE_MODREF *wm;
if (!hLibModule)
{
SetLastError( ERROR_INVALID_HANDLE );
return FALSE;
}
if ((ULONG_PTR)hLibModule & 1)
{
/* this is a LOAD_LIBRARY_AS_DATAFILE module */
char *ptr = (char *)hLibModule - 1;
UnmapViewOfFile( ptr );
return TRUE;
}
RtlAcquirePebLock();
free_lib_count++;
wm = MODULE32_LookupHMODULE( hLibModule );
if ( !wm || !hLibModule )
SetLastError( ERROR_INVALID_HANDLE );
else
retv = MODULE_FreeLibrary( wm );
if ((wm = MODULE32_LookupHMODULE( hLibModule ))) retv = MODULE_FreeLibrary( wm );
free_lib_count--;
RtlReleasePebLock();
......@@ -1627,9 +1637,9 @@ VOID WINAPI FreeLibraryAndExitThread(HINSTANCE hLibModule, DWORD dwExitCode)
*
* FIXME: rough guesswork, don't know what "Private" means
*/
HINSTANCE WINAPI PrivateLoadLibrary(LPCSTR libname)
HINSTANCE16 WINAPI PrivateLoadLibrary(LPCSTR libname)
{
return (HINSTANCE)LoadLibrary16(libname);
return LoadLibrary16(libname);
}
......@@ -1639,9 +1649,9 @@ HINSTANCE WINAPI PrivateLoadLibrary(LPCSTR libname)
*
* FIXME: rough guesswork, don't know what "Private" means
*/
void WINAPI PrivateFreeLibrary(HINSTANCE handle)
void WINAPI PrivateFreeLibrary(HINSTANCE16 handle)
{
FreeLibrary16((HINSTANCE16)handle);
FreeLibrary16(handle);
}
......@@ -1660,7 +1670,7 @@ FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hModule, LPCSTR name )
WARN("hModule is Win32 handle (%08x)\n", hModule );
return (FARPROC16)0;
}
return GetProcAddress16( hModule, name );
return GetProcAddress16( LOWORD(hModule), name );
}
/***********************************************************************
......
......@@ -26,6 +26,27 @@
DEFAULT_DEBUG_CHANNEL(resource);
/**********************************************************************
* get_module_base
*
* Get the base address of a module
*/
static const void *get_module_base( HMODULE hmod )
{
if (!hmod) hmod = GetModuleHandleA( NULL );
else if (!HIWORD(hmod))
{
FIXME("Enumeration of 16-bit resources is not supported\n");
SetLastError(ERROR_INVALID_HANDLE);
return NULL;
}
/* clear low order bit in case of LOAD_LIBRARY_AS_DATAFILE module */
return (void *)((ULONG_PTR)hmod & ~1);
}
/**********************************************************************
* get_resdir
*
......@@ -35,17 +56,14 @@ static const IMAGE_RESOURCE_DIRECTORY* get_resdir( HMODULE hmod )
{
const IMAGE_DATA_DIRECTORY *dir;
const IMAGE_RESOURCE_DIRECTORY *ret = NULL;
const void *base = get_module_base( hmod );
if (!hmod) hmod = GetModuleHandleA( NULL );
else if (!HIWORD(hmod))
if (base)
{
FIXME("Enumeration of 16-bit resources is not supported\n");
SetLastError(ERROR_INVALID_HANDLE);
return NULL;
dir = &PE_HEADER(base)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE];
if (dir->Size && dir->VirtualAddress)
ret = (IMAGE_RESOURCE_DIRECTORY *)((char *)base + dir->VirtualAddress);
}
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;
}
......@@ -254,8 +272,9 @@ HRSRC PE_FindResourceW( HMODULE hmod, LPCWSTR name, LPCWSTR type )
*/
HGLOBAL PE_LoadResource( HMODULE hmod, HRSRC hRsrc )
{
const void *base = get_module_base( hmod );
if (!hRsrc) return 0;
return (HANDLE)(hmod + ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->OffsetToData);
return (HANDLE)((char *)base + ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->OffsetToData);
}
......
......@@ -180,12 +180,14 @@ extern BOOL MAIN_MainInit(void);
* USIG_FLAGS_FAULT
* The signal is being sent due to a fault.
*/
void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule )
void PROCESS_CallUserSignalProc( UINT uCode, HMODULE16 hModule )
{
DWORD flags = current_process.flags;
DWORD startup_flags = current_startupinfo.dwFlags;
DWORD dwFlags = 0;
if (!Callout.UserSignalProc) return;
/* Determine dwFlags */
if ( !(flags & PDB32_WIN16_PROC) ) dwFlags |= USIG_FLAGS_WIN32;
......@@ -205,20 +207,12 @@ void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule )
dwFlags |= USIG_FLAGS_FEEDBACK;
}
/* Convert module handle to 16-bit */
if ( HIWORD( hModule ) )
hModule = MapHModuleLS( hModule );
/* Call USER signal proc */
if ( Callout.UserSignalProc )
{
if ( uCode == USIG_THREAD_INIT || uCode == USIG_THREAD_EXIT )
Callout.UserSignalProc( uCode, GetCurrentThreadId(), dwFlags, hModule );
else
Callout.UserSignalProc( uCode, GetCurrentProcessId(), dwFlags, hModule );
}
if ( uCode == USIG_THREAD_INIT || uCode == USIG_THREAD_EXIT )
Callout.UserSignalProc( uCode, GetCurrentThreadId(), dwFlags, hModule );
else
Callout.UserSignalProc( uCode, GetCurrentProcessId(), dwFlags, 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