1999-03-13 12:54:55 +00:00
|
|
|
/*
|
|
|
|
* Win32s Universal Thunk API
|
|
|
|
*
|
2002-05-31 23:06:46 +00:00
|
|
|
* Copyright 1999 Ulrich Weigand
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-03-13 12:54:55 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
1999-07-24 10:27:58 +00:00
|
|
|
#include "wine/winbase16.h"
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2002-09-12 22:07:02 +00:00
|
|
|
#include "winternl.h"
|
2003-02-27 21:09:45 +00:00
|
|
|
#include "wownt32.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
1999-03-13 12:54:55 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(thunk);
|
1999-04-19 14:56:29 +00:00
|
|
|
|
1999-04-25 12:36:53 +00:00
|
|
|
#include "pshpack1.h"
|
1999-03-13 12:54:55 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BYTE popl_eax;
|
|
|
|
BYTE pushl;
|
|
|
|
DWORD target;
|
|
|
|
BYTE pushl_eax;
|
|
|
|
BYTE ljmp;
|
|
|
|
DWORD utglue16;
|
|
|
|
|
|
|
|
} UT16THUNK;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BYTE popl_eax;
|
|
|
|
BYTE pushl;
|
|
|
|
DWORD target;
|
|
|
|
BYTE pushl_eax;
|
|
|
|
BYTE jmp;
|
|
|
|
DWORD utglue32;
|
|
|
|
|
|
|
|
} UT32THUNK;
|
|
|
|
|
1999-04-25 12:36:53 +00:00
|
|
|
#include "poppack.h"
|
1999-03-13 12:54:55 +00:00
|
|
|
|
1999-04-01 10:05:40 +00:00
|
|
|
typedef struct _UTINFO
|
1999-03-13 12:54:55 +00:00
|
|
|
{
|
1999-04-01 10:05:40 +00:00
|
|
|
struct _UTINFO *next;
|
1999-03-13 12:54:55 +00:00
|
|
|
HMODULE hModule;
|
|
|
|
HMODULE16 hModule16;
|
2002-05-31 23:06:46 +00:00
|
|
|
|
1999-03-13 12:54:55 +00:00
|
|
|
UT16THUNK ut16;
|
|
|
|
UT32THUNK ut32;
|
|
|
|
|
|
|
|
} UTINFO;
|
|
|
|
|
2000-12-11 03:48:15 +00:00
|
|
|
static UTINFO *UT_head; /* head of Universal Thunk list */
|
|
|
|
|
2002-02-02 18:42:11 +00:00
|
|
|
typedef DWORD (CALLBACK *UTGLUEPROC)( LPVOID lpBuff, DWORD dwUserDefined );
|
2000-04-15 20:44:21 +00:00
|
|
|
|
2002-05-31 23:06:46 +00:00
|
|
|
BOOL WINAPI UTRegister( HMODULE hModule, LPSTR lpsz16BITDLL,
|
1999-03-13 12:54:55 +00:00
|
|
|
LPSTR lpszInitName, LPSTR lpszProcName,
|
2002-05-31 23:06:46 +00:00
|
|
|
FARPROC *ppfn32Thunk, FARPROC pfnUT32CallBack,
|
1999-03-13 12:54:55 +00:00
|
|
|
LPVOID lpBuff );
|
|
|
|
|
|
|
|
VOID WINAPI UTUnRegister( HMODULE hModule );
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2001-01-25 22:22:21 +00:00
|
|
|
* UTGlue16 (KERNEL.666) (KERNEL Wine-specific export)
|
1999-03-13 12:54:55 +00:00
|
|
|
*/
|
2000-04-15 20:44:21 +00:00
|
|
|
DWORD WINAPI UTGlue16( LPVOID lpBuff, DWORD dwUserDefined, SEGPTR *translationList,
|
|
|
|
UTGLUEPROC target )
|
1999-03-13 12:54:55 +00:00
|
|
|
{
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
/* Convert arguments to flat pointers */
|
|
|
|
|
|
|
|
if ( translationList )
|
|
|
|
for ( i = 0; translationList[i]; i++ )
|
|
|
|
{
|
2000-12-13 20:20:09 +00:00
|
|
|
LPVOID flatPtr = MapSL( translationList[i] );
|
|
|
|
*(LPVOID *)flatPtr = MapSL( *(SEGPTR *)flatPtr );
|
1999-03-13 12:54:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Call 32-bit routine */
|
|
|
|
|
|
|
|
return target( lpBuff, dwUserDefined );
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* UTGlue32
|
|
|
|
*/
|
2002-05-31 23:06:46 +00:00
|
|
|
static DWORD WINAPI UTGlue32( FARPROC16 target, LPVOID lpBuff, DWORD dwUserDefined,
|
1999-06-26 14:58:24 +00:00
|
|
|
LPVOID translationList[] )
|
1999-03-13 12:54:55 +00:00
|
|
|
{
|
|
|
|
SEGPTR segBuff, *segptrList = NULL;
|
|
|
|
INT i, nList = 0;
|
|
|
|
DWORD retv;
|
2003-02-27 21:09:45 +00:00
|
|
|
WORD args[4];
|
1999-03-13 12:54:55 +00:00
|
|
|
|
|
|
|
/* Convert arguments to SEGPTRs */
|
|
|
|
|
|
|
|
if ( translationList )
|
|
|
|
for ( nList = 0; translationList[nList]; nList++ )
|
|
|
|
;
|
|
|
|
|
|
|
|
if ( nList )
|
|
|
|
{
|
|
|
|
segptrList = HeapAlloc( GetProcessHeap(), 0, sizeof(SEGPTR)*nList );
|
|
|
|
if ( !segptrList )
|
|
|
|
{
|
2001-05-09 17:31:31 +00:00
|
|
|
FIXME("Unable to allocate segptrList!\n" );
|
1999-03-13 12:54:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0; i < nList; i++ )
|
2002-05-31 23:06:46 +00:00
|
|
|
segptrList[i] = *(SEGPTR *)translationList[i]
|
1999-03-13 12:54:55 +00:00
|
|
|
= MapLS( *(LPVOID *)translationList[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
segBuff = MapLS( lpBuff );
|
|
|
|
|
|
|
|
/* Call 16-bit routine */
|
|
|
|
|
2003-02-27 21:09:45 +00:00
|
|
|
args[3] = SELECTOROF(segBuff);
|
|
|
|
args[2] = OFFSETOF(segBuff);
|
|
|
|
args[1] = HIWORD(dwUserDefined);
|
|
|
|
args[0] = LOWORD(dwUserDefined);
|
|
|
|
WOWCallback16Ex( (DWORD)target, WCB16_PASCAL, sizeof(args), args, &retv );
|
1999-03-13 12:54:55 +00:00
|
|
|
|
|
|
|
/* Free temporary selectors */
|
|
|
|
|
|
|
|
UnMapLS( segBuff );
|
|
|
|
|
|
|
|
if ( nList )
|
|
|
|
{
|
|
|
|
for ( i = 0; i < nList; i++ )
|
|
|
|
UnMapLS( segptrList[i] );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, segptrList );
|
|
|
|
}
|
|
|
|
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* UTAlloc
|
|
|
|
*/
|
|
|
|
static UTINFO *UTAlloc( HMODULE hModule, HMODULE16 hModule16,
|
|
|
|
FARPROC16 target16, FARPROC target32 )
|
|
|
|
{
|
1999-07-24 10:27:58 +00:00
|
|
|
static FARPROC16 UTGlue16_Segptr = NULL;
|
|
|
|
UTINFO *ut;
|
|
|
|
|
|
|
|
if ( !UTGlue16_Segptr )
|
|
|
|
{
|
2007-12-13 23:18:21 +00:00
|
|
|
HMODULE16 hMod = GetModuleHandle16( "KERNEL" );
|
|
|
|
UTGlue16_Segptr = GetProcAddress16( hMod, "UTGlue16" );
|
1999-07-24 10:27:58 +00:00
|
|
|
if ( !UTGlue16_Segptr ) return NULL;
|
|
|
|
}
|
|
|
|
|
2001-12-05 22:23:02 +00:00
|
|
|
ut = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(UTINFO) );
|
1999-03-13 12:54:55 +00:00
|
|
|
if ( !ut ) return NULL;
|
|
|
|
|
|
|
|
ut->hModule = hModule;
|
|
|
|
ut->hModule16 = hModule16;
|
|
|
|
|
|
|
|
ut->ut16.popl_eax = 0x58;
|
|
|
|
ut->ut16.pushl = 0x68;
|
|
|
|
ut->ut16.target = (DWORD)target32;
|
|
|
|
ut->ut16.pushl_eax = 0x50;
|
|
|
|
ut->ut16.ljmp = 0xea;
|
1999-07-24 10:27:58 +00:00
|
|
|
ut->ut16.utglue16 = (DWORD)UTGlue16_Segptr;
|
1999-03-13 12:54:55 +00:00
|
|
|
|
|
|
|
ut->ut32.popl_eax = 0x58;
|
|
|
|
ut->ut32.pushl = 0x68;
|
|
|
|
ut->ut32.target = (DWORD)target16;
|
|
|
|
ut->ut32.pushl_eax = 0x50;
|
|
|
|
ut->ut32.jmp = 0xe9;
|
|
|
|
ut->ut32.utglue32 = (DWORD)UTGlue32 - ((DWORD)&ut->ut32.utglue32 + sizeof(DWORD));
|
|
|
|
|
2000-12-11 03:48:15 +00:00
|
|
|
ut->next = UT_head;
|
|
|
|
UT_head = ut;
|
1999-03-13 12:54:55 +00:00
|
|
|
|
|
|
|
return ut;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* UTFree
|
|
|
|
*/
|
|
|
|
static void UTFree( UTINFO *ut )
|
|
|
|
{
|
|
|
|
UTINFO **ptr;
|
|
|
|
|
2000-12-11 03:48:15 +00:00
|
|
|
for ( ptr = &UT_head; *ptr; ptr = &(*ptr)->next )
|
1999-03-13 12:54:55 +00:00
|
|
|
if ( *ptr == ut )
|
|
|
|
{
|
|
|
|
*ptr = ut->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-05 22:23:02 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, ut );
|
1999-03-13 12:54:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* UTFind
|
|
|
|
*/
|
|
|
|
static UTINFO *UTFind( HMODULE hModule )
|
|
|
|
{
|
|
|
|
UTINFO *ut;
|
|
|
|
|
2000-12-11 03:48:15 +00:00
|
|
|
for ( ut = UT_head; ut; ut =ut->next )
|
1999-03-13 12:54:55 +00:00
|
|
|
if ( ut->hModule == hModule )
|
|
|
|
break;
|
|
|
|
|
|
|
|
return ut;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* UTRegister (KERNEL32.@)
|
1999-03-13 12:54:55 +00:00
|
|
|
*/
|
2002-05-31 23:06:46 +00:00
|
|
|
BOOL WINAPI UTRegister( HMODULE hModule, LPSTR lpsz16BITDLL,
|
1999-03-13 12:54:55 +00:00
|
|
|
LPSTR lpszInitName, LPSTR lpszProcName,
|
2002-05-31 23:06:46 +00:00
|
|
|
FARPROC *ppfn32Thunk, FARPROC pfnUT32CallBack,
|
1999-03-13 12:54:55 +00:00
|
|
|
LPVOID lpBuff )
|
|
|
|
{
|
|
|
|
UTINFO *ut;
|
2002-05-31 23:06:46 +00:00
|
|
|
HMODULE16 hModule16;
|
|
|
|
FARPROC16 target16, init16;
|
2013-12-11 10:38:50 +00:00
|
|
|
static BOOL done;
|
2010-06-08 10:46:28 +00:00
|
|
|
|
|
|
|
if (!done)
|
|
|
|
{
|
|
|
|
LoadLibrary16( "gdi.exe" );
|
|
|
|
LoadLibrary16( "user.exe" );
|
|
|
|
done = TRUE;
|
|
|
|
}
|
1999-03-13 12:54:55 +00:00
|
|
|
|
|
|
|
/* Load 16-bit DLL and get UTProc16 entry point */
|
|
|
|
|
|
|
|
if ( (hModule16 = LoadLibrary16( lpsz16BITDLL )) <= 32
|
2000-11-27 21:59:08 +00:00
|
|
|
|| (target16 = GetProcAddress16( hModule16, lpszProcName )) == 0 )
|
1999-03-13 12:54:55 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Allocate UTINFO struct */
|
|
|
|
|
2000-12-11 03:48:15 +00:00
|
|
|
RtlAcquirePebLock();
|
1999-03-13 12:54:55 +00:00
|
|
|
if ( (ut = UTFind( hModule )) != NULL )
|
|
|
|
ut = NULL;
|
|
|
|
else
|
|
|
|
ut = UTAlloc( hModule, hModule16, target16, pfnUT32CallBack );
|
2000-12-11 03:48:15 +00:00
|
|
|
RtlReleasePebLock();
|
1999-03-13 12:54:55 +00:00
|
|
|
|
|
|
|
if ( !ut )
|
|
|
|
{
|
|
|
|
FreeLibrary16( hModule16 );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call UTInit16 if present */
|
|
|
|
|
|
|
|
if ( lpszInitName
|
2000-11-27 21:59:08 +00:00
|
|
|
&& (init16 = GetProcAddress16( hModule16, lpszInitName )) != 0 )
|
1999-03-13 12:54:55 +00:00
|
|
|
{
|
2001-12-05 22:23:02 +00:00
|
|
|
SEGPTR callback = MapLS( &ut->ut16 );
|
1999-03-13 12:54:55 +00:00
|
|
|
SEGPTR segBuff = MapLS( lpBuff );
|
2003-02-27 21:09:45 +00:00
|
|
|
WORD args[4];
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
args[3] = SELECTOROF(callback);
|
|
|
|
args[2] = OFFSETOF(callback);
|
|
|
|
args[1] = SELECTOROF(segBuff);
|
|
|
|
args[0] = OFFSETOF(segBuff);
|
|
|
|
WOWCallback16Ex( (DWORD)init16, WCB16_PASCAL, sizeof(args), args, &ret );
|
|
|
|
UnMapLS( segBuff );
|
|
|
|
UnMapLS( callback );
|
|
|
|
if (!ret)
|
1999-03-13 12:54:55 +00:00
|
|
|
{
|
|
|
|
UTUnRegister( hModule );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return 32-bit thunk */
|
|
|
|
|
|
|
|
*ppfn32Thunk = (FARPROC) &ut->ut32;
|
2002-05-31 23:06:46 +00:00
|
|
|
|
1999-03-13 12:54:55 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* UTUnRegister (KERNEL32.@)
|
1999-03-13 12:54:55 +00:00
|
|
|
*/
|
|
|
|
VOID WINAPI UTUnRegister( HMODULE hModule )
|
|
|
|
{
|
|
|
|
UTINFO *ut;
|
|
|
|
HMODULE16 hModule16 = 0;
|
|
|
|
|
2000-12-11 03:48:15 +00:00
|
|
|
RtlAcquirePebLock();
|
1999-03-13 12:54:55 +00:00
|
|
|
ut = UTFind( hModule );
|
2008-02-29 11:12:10 +00:00
|
|
|
if ( ut )
|
1999-03-13 12:54:55 +00:00
|
|
|
{
|
|
|
|
hModule16 = ut->hModule16;
|
|
|
|
UTFree( ut );
|
|
|
|
}
|
2000-12-11 03:48:15 +00:00
|
|
|
RtlReleasePebLock();
|
1999-03-13 12:54:55 +00:00
|
|
|
|
2002-05-31 23:06:46 +00:00
|
|
|
if ( hModule16 )
|
1999-03-13 12:54:55 +00:00
|
|
|
FreeLibrary16( hModule16 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2001-07-02 19:59:40 +00:00
|
|
|
* UTInit (KERNEL.493)
|
1999-03-13 12:54:55 +00:00
|
|
|
*/
|
|
|
|
WORD WINAPI UTInit16( DWORD x1, DWORD x2, DWORD x3, DWORD x4 )
|
|
|
|
{
|
2022-02-11 07:41:35 +00:00
|
|
|
FIXME("(%08lx, %08lx, %08lx, %08lx): stub\n", x1, x2, x3, x4 );
|
1999-03-13 12:54:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|