1999-03-13 13:54:55 +01:00
|
|
|
/*
|
|
|
|
* Win32s Universal Thunk API
|
|
|
|
*
|
|
|
|
* Copyright 1999 Ulrich Weigand
|
2002-03-10 00:29:33 +01: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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-03-13 13:54:55 +01:00
|
|
|
*/
|
|
|
|
|
1999-07-24 12:27:58 +02:00
|
|
|
#include "wine/winbase16.h"
|
2000-12-11 04:48:15 +01:00
|
|
|
#include "ntddk.h"
|
1999-03-13 13:54:55 +01:00
|
|
|
#include "module.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-03-13 13:54:55 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(thunk);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1999-04-25 14:36:53 +02:00
|
|
|
#include "pshpack1.h"
|
1999-03-13 13:54:55 +01: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 14:36:53 +02:00
|
|
|
#include "poppack.h"
|
1999-03-13 13:54:55 +01:00
|
|
|
|
1999-04-01 12:05:40 +02:00
|
|
|
typedef struct _UTINFO
|
1999-03-13 13:54:55 +01:00
|
|
|
{
|
1999-04-01 12:05:40 +02:00
|
|
|
struct _UTINFO *next;
|
1999-03-13 13:54:55 +01:00
|
|
|
HMODULE hModule;
|
|
|
|
HMODULE16 hModule16;
|
|
|
|
|
|
|
|
UT16THUNK ut16;
|
|
|
|
UT32THUNK ut32;
|
|
|
|
|
|
|
|
} UTINFO;
|
|
|
|
|
2000-12-11 04:48:15 +01:00
|
|
|
static UTINFO *UT_head; /* head of Universal Thunk list */
|
|
|
|
|
2002-02-02 19:42:11 +01:00
|
|
|
typedef DWORD (CALLBACK *UTGLUEPROC)( LPVOID lpBuff, DWORD dwUserDefined );
|
2000-04-15 22:44:21 +02:00
|
|
|
|
1999-03-13 13:54:55 +01:00
|
|
|
BOOL WINAPI UTRegister( HMODULE hModule, LPSTR lpsz16BITDLL,
|
|
|
|
LPSTR lpszInitName, LPSTR lpszProcName,
|
|
|
|
FARPROC *ppfn32Thunk, FARPROC pfnUT32CallBack,
|
|
|
|
LPVOID lpBuff );
|
|
|
|
|
|
|
|
VOID WINAPI UTUnRegister( HMODULE hModule );
|
|
|
|
|
2000-08-14 16:29:22 +02:00
|
|
|
/* ### start build ### */
|
|
|
|
extern LONG CALLBACK UTTHUNK_CallTo16_long_ll(FARPROC16,LONG,LONG);
|
|
|
|
/* ### stop build ### */
|
1999-03-13 13:54:55 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* UTGlue16 (KERNEL.666) (KERNEL Wine-specific export)
|
1999-03-13 13:54:55 +01:00
|
|
|
*/
|
2000-04-15 22:44:21 +02:00
|
|
|
DWORD WINAPI UTGlue16( LPVOID lpBuff, DWORD dwUserDefined, SEGPTR *translationList,
|
|
|
|
UTGLUEPROC target )
|
1999-03-13 13:54:55 +01:00
|
|
|
{
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
/* Convert arguments to flat pointers */
|
|
|
|
|
|
|
|
if ( translationList )
|
|
|
|
for ( i = 0; translationList[i]; i++ )
|
|
|
|
{
|
2000-12-13 21:20:09 +01:00
|
|
|
LPVOID flatPtr = MapSL( translationList[i] );
|
|
|
|
*(LPVOID *)flatPtr = MapSL( *(SEGPTR *)flatPtr );
|
1999-03-13 13:54:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Call 32-bit routine */
|
|
|
|
|
|
|
|
return target( lpBuff, dwUserDefined );
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* UTGlue32
|
|
|
|
*/
|
1999-06-26 16:58:24 +02:00
|
|
|
static DWORD WINAPI UTGlue32( FARPROC16 target, LPVOID lpBuff, DWORD dwUserDefined,
|
|
|
|
LPVOID translationList[] )
|
1999-03-13 13:54:55 +01:00
|
|
|
{
|
|
|
|
SEGPTR segBuff, *segptrList = NULL;
|
|
|
|
INT i, nList = 0;
|
|
|
|
DWORD retv;
|
|
|
|
|
|
|
|
/* 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 19:31:31 +02:00
|
|
|
FIXME("Unable to allocate segptrList!\n" );
|
1999-03-13 13:54:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0; i < nList; i++ )
|
|
|
|
segptrList[i] = *(SEGPTR *)translationList[i]
|
|
|
|
= MapLS( *(LPVOID *)translationList[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
segBuff = MapLS( lpBuff );
|
|
|
|
|
|
|
|
/* Call 16-bit routine */
|
|
|
|
|
2000-08-14 16:29:22 +02:00
|
|
|
retv = UTTHUNK_CallTo16_long_ll( target, segBuff, dwUserDefined );
|
1999-03-13 13:54:55 +01: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 12:27:58 +02:00
|
|
|
static FARPROC16 UTGlue16_Segptr = NULL;
|
|
|
|
UTINFO *ut;
|
|
|
|
|
|
|
|
if ( !UTGlue16_Segptr )
|
|
|
|
{
|
2000-12-01 22:25:31 +01:00
|
|
|
HMODULE16 hModule = GetModuleHandle16( "KERNEL" );
|
|
|
|
UTGlue16_Segptr = GetProcAddress16( hModule, "UTGlue16" );
|
1999-07-24 12:27:58 +02:00
|
|
|
if ( !UTGlue16_Segptr ) return NULL;
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:23:02 +01:00
|
|
|
ut = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(UTINFO) );
|
1999-03-13 13:54:55 +01: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 12:27:58 +02:00
|
|
|
ut->ut16.utglue16 = (DWORD)UTGlue16_Segptr;
|
1999-03-13 13:54:55 +01: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 04:48:15 +01:00
|
|
|
ut->next = UT_head;
|
|
|
|
UT_head = ut;
|
1999-03-13 13:54:55 +01:00
|
|
|
|
|
|
|
return ut;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* UTFree
|
|
|
|
*/
|
|
|
|
static void UTFree( UTINFO *ut )
|
|
|
|
{
|
|
|
|
UTINFO **ptr;
|
|
|
|
|
2000-12-11 04:48:15 +01:00
|
|
|
for ( ptr = &UT_head; *ptr; ptr = &(*ptr)->next )
|
1999-03-13 13:54:55 +01:00
|
|
|
if ( *ptr == ut )
|
|
|
|
{
|
|
|
|
*ptr = ut->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:23:02 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, ut );
|
1999-03-13 13:54:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* UTFind
|
|
|
|
*/
|
|
|
|
static UTINFO *UTFind( HMODULE hModule )
|
|
|
|
{
|
|
|
|
UTINFO *ut;
|
|
|
|
|
2000-12-11 04:48:15 +01:00
|
|
|
for ( ut = UT_head; ut; ut =ut->next )
|
1999-03-13 13:54:55 +01:00
|
|
|
if ( ut->hModule == hModule )
|
|
|
|
break;
|
|
|
|
|
|
|
|
return ut;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* UTRegister (KERNEL32.@)
|
1999-03-13 13:54:55 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI UTRegister( HMODULE hModule, LPSTR lpsz16BITDLL,
|
|
|
|
LPSTR lpszInitName, LPSTR lpszProcName,
|
|
|
|
FARPROC *ppfn32Thunk, FARPROC pfnUT32CallBack,
|
|
|
|
LPVOID lpBuff )
|
|
|
|
{
|
|
|
|
UTINFO *ut;
|
|
|
|
HMODULE16 hModule16;
|
|
|
|
FARPROC16 target16, init16;
|
|
|
|
|
|
|
|
/* Load 16-bit DLL and get UTProc16 entry point */
|
|
|
|
|
|
|
|
if ( (hModule16 = LoadLibrary16( lpsz16BITDLL )) <= 32
|
2000-11-27 22:59:08 +01:00
|
|
|
|| (target16 = GetProcAddress16( hModule16, lpszProcName )) == 0 )
|
1999-03-13 13:54:55 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Allocate UTINFO struct */
|
|
|
|
|
2000-12-11 04:48:15 +01:00
|
|
|
RtlAcquirePebLock();
|
1999-03-13 13:54:55 +01:00
|
|
|
if ( (ut = UTFind( hModule )) != NULL )
|
|
|
|
ut = NULL;
|
|
|
|
else
|
|
|
|
ut = UTAlloc( hModule, hModule16, target16, pfnUT32CallBack );
|
2000-12-11 04:48:15 +01:00
|
|
|
RtlReleasePebLock();
|
1999-03-13 13:54:55 +01:00
|
|
|
|
|
|
|
if ( !ut )
|
|
|
|
{
|
|
|
|
FreeLibrary16( hModule16 );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call UTInit16 if present */
|
|
|
|
|
|
|
|
if ( lpszInitName
|
2000-11-27 22:59:08 +01:00
|
|
|
&& (init16 = GetProcAddress16( hModule16, lpszInitName )) != 0 )
|
1999-03-13 13:54:55 +01:00
|
|
|
{
|
2001-12-05 23:23:02 +01:00
|
|
|
SEGPTR callback = MapLS( &ut->ut16 );
|
1999-03-13 13:54:55 +01:00
|
|
|
SEGPTR segBuff = MapLS( lpBuff );
|
|
|
|
|
2000-08-14 16:29:22 +02:00
|
|
|
if ( !UTTHUNK_CallTo16_long_ll( init16, callback, segBuff ) )
|
1999-03-13 13:54:55 +01:00
|
|
|
{
|
|
|
|
UnMapLS( segBuff );
|
2001-12-05 23:23:02 +01:00
|
|
|
UnMapLS( callback );
|
1999-03-13 13:54:55 +01:00
|
|
|
UTUnRegister( hModule );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
UnMapLS( segBuff );
|
2001-12-05 23:23:02 +01:00
|
|
|
UnMapLS( callback );
|
1999-03-13 13:54:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return 32-bit thunk */
|
|
|
|
|
|
|
|
*ppfn32Thunk = (FARPROC) &ut->ut32;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* UTUnRegister (KERNEL32.@)
|
1999-03-13 13:54:55 +01:00
|
|
|
*/
|
|
|
|
VOID WINAPI UTUnRegister( HMODULE hModule )
|
|
|
|
{
|
|
|
|
UTINFO *ut;
|
|
|
|
HMODULE16 hModule16 = 0;
|
|
|
|
|
2000-12-11 04:48:15 +01:00
|
|
|
RtlAcquirePebLock();
|
1999-03-13 13:54:55 +01:00
|
|
|
ut = UTFind( hModule );
|
|
|
|
if ( !ut )
|
|
|
|
{
|
|
|
|
hModule16 = ut->hModule16;
|
|
|
|
UTFree( ut );
|
|
|
|
}
|
2000-12-11 04:48:15 +01:00
|
|
|
RtlReleasePebLock();
|
1999-03-13 13:54:55 +01:00
|
|
|
|
|
|
|
if ( hModule16 )
|
|
|
|
FreeLibrary16( hModule16 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* UTInit (KERNEL.493)
|
1999-03-13 13:54:55 +01:00
|
|
|
*/
|
|
|
|
WORD WINAPI UTInit16( DWORD x1, DWORD x2, DWORD x3, DWORD x4 )
|
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("(%08lx, %08lx, %08lx, %08lx): stub\n", x1, x2, x3, x4 );
|
1999-03-13 13:54:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|