1999-08-18 20:31:26 +02:00
|
|
|
/*
|
|
|
|
* Win32 WOW Generic Thunk API
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* 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-08-18 20:31:26 +02:00
|
|
|
*/
|
|
|
|
|
2002-08-29 01:42:34 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
1999-08-18 20:31:26 +02:00
|
|
|
#include "wine/winbase16.h"
|
|
|
|
#include "winbase.h"
|
2002-08-27 03:13:58 +02:00
|
|
|
#include "winerror.h"
|
1999-08-18 20:31:26 +02:00
|
|
|
#include "wownt32.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2000-08-14 16:42:41 +02:00
|
|
|
#include "file.h"
|
2002-10-17 20:26:53 +02:00
|
|
|
#include "task.h"
|
1999-08-18 20:31:26 +02:00
|
|
|
#include "miscemu.h"
|
|
|
|
#include "stackframe.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-08-18 20:31:26 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(thunk);
|
1999-08-18 20:31:26 +02:00
|
|
|
|
2000-09-27 00:20:14 +02:00
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* These are the 16-bit side WOW routines. They reside in wownt16.h
|
|
|
|
* in the SDK; since we don't support Win16 source code anyway, I've
|
2000-09-27 00:20:14 +02:00
|
|
|
* placed them here for compilation with Wine ...
|
|
|
|
*/
|
|
|
|
|
|
|
|
DWORD WINAPI GetVDMPointer32W16(SEGPTR,UINT16);
|
|
|
|
|
|
|
|
DWORD WINAPI LoadLibraryEx32W16(LPCSTR,DWORD,DWORD);
|
|
|
|
DWORD WINAPI GetProcAddress32W16(DWORD,LPCSTR);
|
|
|
|
DWORD WINAPI FreeLibrary32W16(DWORD);
|
|
|
|
|
|
|
|
#define CPEX_DEST_STDCALL 0x00000000L
|
|
|
|
#define CPEX_DEST_CDECL 0x80000000L
|
|
|
|
|
|
|
|
DWORD WINAPI CallProcExW16(VOID);
|
|
|
|
DWORD WINAPI CallProcEx32W16(VOID);
|
|
|
|
|
2003-02-27 02:57:16 +01:00
|
|
|
/* thunk for 16-bit CreateThread */
|
|
|
|
struct thread_args
|
|
|
|
{
|
|
|
|
FARPROC16 proc;
|
|
|
|
DWORD param;
|
|
|
|
};
|
|
|
|
|
|
|
|
static DWORD CALLBACK start_thread16( LPVOID threadArgs )
|
|
|
|
{
|
|
|
|
struct thread_args args = *(struct thread_args *)threadArgs;
|
|
|
|
HeapFree( GetProcessHeap(), 0, threadArgs );
|
|
|
|
return K32WOWCallback16( (DWORD)args.proc, args.param );
|
|
|
|
}
|
|
|
|
|
1999-08-18 20:31:26 +02:00
|
|
|
/*
|
|
|
|
* 32-bit WOW routines (in WOW32, but actually forwarded to KERNEL32)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWGetDescriptor (KERNEL32.70)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
BOOL WINAPI K32WOWGetDescriptor( SEGPTR segptr, LPLDT_ENTRY ldtent )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
return GetThreadSelectorEntry( GetCurrentThread(),
|
1999-08-18 20:31:26 +02:00
|
|
|
segptr >> 16, ldtent );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWGetVDMPointer (KERNEL32.56)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
LPVOID WINAPI K32WOWGetVDMPointer( DWORD vp, DWORD dwBytes, BOOL fProtectedMode )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
/* FIXME: add size check too */
|
|
|
|
|
|
|
|
if ( fProtectedMode )
|
2000-12-13 21:20:09 +01:00
|
|
|
return MapSL( vp );
|
1999-08-18 20:31:26 +02:00
|
|
|
else
|
|
|
|
return DOSMEM_MapRealToLinear( vp );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWGetVDMPointerFix (KERNEL32.68)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
LPVOID WINAPI K32WOWGetVDMPointerFix( DWORD vp, DWORD dwBytes, BOOL fProtectedMode )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-08-18 20:31:26 +02:00
|
|
|
* Hmmm. According to the docu, we should call:
|
|
|
|
*
|
|
|
|
* GlobalFix16( SELECTOROF(vp) );
|
|
|
|
*
|
|
|
|
* But this is unnecessary under Wine, as we never move global
|
2002-06-01 01:06:46 +02:00
|
|
|
* memory segments in linear memory anyway.
|
1999-08-18 20:31:26 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* (I'm not so sure what we are *supposed* to do if
|
1999-08-18 20:31:26 +02:00
|
|
|
* fProtectedMode is TRUE, anyway ...)
|
|
|
|
*/
|
|
|
|
|
2000-11-27 22:59:08 +01:00
|
|
|
return K32WOWGetVDMPointer( vp, dwBytes, fProtectedMode );
|
1999-08-18 20:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* K32WOWGetVDMPointerUnfix (KERNEL32.69)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
VOID WINAPI K32WOWGetVDMPointerUnfix( DWORD vp )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* See above why we don't call:
|
|
|
|
*
|
|
|
|
* GlobalUnfix16( SELECTOROF(vp) );
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWGlobalAlloc16 (KERNEL32.59)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
WORD WINAPI K32WOWGlobalAlloc16( WORD wFlags, DWORD cb )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
return (WORD)GlobalAlloc16( wFlags, cb );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWGlobalFree16 (KERNEL32.62)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
WORD WINAPI K32WOWGlobalFree16( WORD hMem )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
return (WORD)GlobalFree16( (HGLOBAL16)hMem );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWGlobalUnlock16 (KERNEL32.61)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
BOOL WINAPI K32WOWGlobalUnlock16( WORD hMem )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
return (BOOL)GlobalUnlock16( (HGLOBAL16)hMem );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWGlobalAllocLock16 (KERNEL32.63)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
DWORD WINAPI K32WOWGlobalAllocLock16( WORD wFlags, DWORD cb, WORD *phMem )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
2000-11-27 22:59:08 +01:00
|
|
|
WORD hMem = K32WOWGlobalAlloc16( wFlags, cb );
|
1999-08-18 20:31:26 +02:00
|
|
|
if (phMem) *phMem = hMem;
|
|
|
|
|
2000-11-27 22:59:08 +01:00
|
|
|
return K32WOWGlobalLock16( hMem );
|
1999-08-18 20:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWGlobalLockSize16 (KERNEL32.65)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
DWORD WINAPI K32WOWGlobalLockSize16( WORD hMem, PDWORD pcb )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if ( pcb )
|
1999-08-18 20:31:26 +02:00
|
|
|
*pcb = GlobalSize16( (HGLOBAL16)hMem );
|
|
|
|
|
2000-11-27 22:59:08 +01:00
|
|
|
return K32WOWGlobalLock16( hMem );
|
1999-08-18 20:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWGlobalUnlockFree16 (KERNEL32.64)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
WORD WINAPI K32WOWGlobalUnlockFree16( DWORD vpMem )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
2000-11-27 22:59:08 +01:00
|
|
|
if ( !K32WOWGlobalUnlock16( HIWORD(vpMem) ) )
|
1999-08-18 20:31:26 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2000-11-27 22:59:08 +01:00
|
|
|
return K32WOWGlobalFree16( HIWORD(vpMem) );
|
1999-08-18 20:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWYield16 (KERNEL32.66)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
VOID WINAPI K32WOWYield16( void )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* This does the right thing for both Win16 and Win32 tasks.
|
1999-08-18 20:31:26 +02:00
|
|
|
* More or less, at least :-/
|
|
|
|
*/
|
|
|
|
Yield16();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWDirectedYield16 (KERNEL32.67)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
VOID WINAPI K32WOWDirectedYield16( WORD htask16 )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Argh. Our scheduler doesn't like DirectedYield by Win32
|
2002-06-01 01:06:46 +02:00
|
|
|
* tasks at all. So we do hope that this routine is indeed
|
1999-08-18 20:31:26 +02:00
|
|
|
* only ever called by Win16 tasks that have thunked up ...
|
|
|
|
*/
|
|
|
|
DirectedYield16( (HTASK16)htask16 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWHandle32 (KERNEL32.57)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
HANDLE WINAPI K32WOWHandle32( WORD handle, WOW_HANDLE_TYPE type )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
switch ( type )
|
|
|
|
{
|
|
|
|
case WOW_TYPE_HWND:
|
|
|
|
case WOW_TYPE_HMENU:
|
|
|
|
case WOW_TYPE_HDWP:
|
|
|
|
case WOW_TYPE_HDROP:
|
|
|
|
case WOW_TYPE_HDC:
|
|
|
|
case WOW_TYPE_HFONT:
|
|
|
|
case WOW_TYPE_HRGN:
|
|
|
|
case WOW_TYPE_HBITMAP:
|
|
|
|
case WOW_TYPE_HBRUSH:
|
|
|
|
case WOW_TYPE_HPALETTE:
|
|
|
|
case WOW_TYPE_HPEN:
|
|
|
|
case WOW_TYPE_HACCEL:
|
2002-10-19 01:35:24 +02:00
|
|
|
return (HANDLE)(ULONG_PTR)handle;
|
|
|
|
|
|
|
|
case WOW_TYPE_HMETAFILE:
|
|
|
|
FIXME( "conversion of metafile handles not supported yet\n" );
|
2002-07-31 21:26:03 +02:00
|
|
|
return (HANDLE)(ULONG_PTR)handle;
|
1999-08-18 20:31:26 +02:00
|
|
|
|
2002-10-17 20:26:53 +02:00
|
|
|
case WOW_TYPE_HTASK:
|
|
|
|
return (HANDLE)TASK_GetPtr(handle)->teb->tid;
|
|
|
|
|
2002-10-19 01:35:24 +02:00
|
|
|
case WOW_TYPE_FULLHWND:
|
|
|
|
FIXME( "conversion of full window handles not supported yet\n" );
|
|
|
|
return (HANDLE)(ULONG_PTR)handle;
|
|
|
|
|
1999-08-18 20:31:26 +02:00
|
|
|
default:
|
|
|
|
ERR( "handle 0x%04x of unknown type %d\n", handle, type );
|
2002-07-31 21:26:03 +02:00
|
|
|
return (HANDLE)(ULONG_PTR)handle;
|
1999-08-18 20:31:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWHandle16 (KERNEL32.58)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
WORD WINAPI K32WOWHandle16( HANDLE handle, WOW_HANDLE_TYPE type )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
switch ( type )
|
|
|
|
{
|
|
|
|
case WOW_TYPE_HWND:
|
|
|
|
case WOW_TYPE_HMENU:
|
|
|
|
case WOW_TYPE_HDWP:
|
|
|
|
case WOW_TYPE_HDROP:
|
|
|
|
case WOW_TYPE_HDC:
|
|
|
|
case WOW_TYPE_HFONT:
|
|
|
|
case WOW_TYPE_HRGN:
|
|
|
|
case WOW_TYPE_HBITMAP:
|
|
|
|
case WOW_TYPE_HBRUSH:
|
|
|
|
case WOW_TYPE_HPALETTE:
|
|
|
|
case WOW_TYPE_HPEN:
|
|
|
|
case WOW_TYPE_HACCEL:
|
|
|
|
case WOW_TYPE_FULLHWND:
|
2002-10-29 22:26:23 +01:00
|
|
|
if ( HIWORD(handle ) )
|
|
|
|
ERR( "handle %p of type %d has non-zero HIWORD\n", handle, type );
|
1999-08-18 20:31:26 +02:00
|
|
|
return LOWORD(handle);
|
|
|
|
|
2002-10-19 01:35:24 +02:00
|
|
|
case WOW_TYPE_HMETAFILE:
|
|
|
|
FIXME( "conversion of metafile handles not supported yet\n" );
|
|
|
|
return LOWORD(handle);
|
|
|
|
|
2002-10-17 20:26:53 +02:00
|
|
|
case WOW_TYPE_HTASK:
|
|
|
|
return THREAD_IdToTEB((DWORD)handle)->htask16;
|
|
|
|
|
1999-08-18 20:31:26 +02:00
|
|
|
default:
|
2002-10-25 23:02:30 +02:00
|
|
|
ERR( "handle %p of unknown type %d\n", handle, type );
|
1999-08-18 20:31:26 +02:00
|
|
|
return LOWORD(handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWCallback16Ex (KERNEL32.55)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2000-11-27 22:59:08 +01:00
|
|
|
BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
|
|
|
|
DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Arguments must be prepared in the correct order by the caller
|
|
|
|
* (both for PASCAL and CDECL calling convention), so we simply
|
2002-06-01 01:06:46 +02:00
|
|
|
* copy them to the 16-bit stack ...
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
|
|
|
memcpy( (LPBYTE)CURRENT_STACK16 - cbArgs, (LPBYTE)pArgs, cbArgs );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actually, we should take care whether the called routine cleans up
|
2002-06-01 01:06:46 +02:00
|
|
|
* its stack or not. Fortunately, our wine_call_to_16 core doesn't rely on
|
|
|
|
* the callee to do so; after the routine has returned, the 16-bit
|
|
|
|
* stack pointer is always reset to the position it had before.
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
|
|
|
|
2002-10-18 02:29:32 +02:00
|
|
|
ret = wine_call_to_16( (FARPROC16)vpfn16, cbArgs );
|
1999-08-18 20:31:26 +02:00
|
|
|
|
|
|
|
if ( pdwRetCode )
|
|
|
|
*pdwRetCode = ret;
|
|
|
|
|
|
|
|
return TRUE; /* success */
|
|
|
|
}
|
|
|
|
|
2000-11-27 22:59:08 +01:00
|
|
|
/**********************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* K32WOWCallback16 (KERNEL32.54)
|
2000-11-27 22:59:08 +01:00
|
|
|
*/
|
|
|
|
DWORD WINAPI K32WOWCallback16( DWORD vpfn16, DWORD dwParam )
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if ( !K32WOWCallback16Ex( vpfn16, WCB16_PASCAL,
|
2000-11-27 22:59:08 +01:00
|
|
|
sizeof(DWORD), &dwParam, &ret ) )
|
|
|
|
ret = 0L;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
1999-08-18 20:31:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 16-bit WOW routines (in KERNEL)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* GetVDMPointer32W (KERNEL.516)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetVDMPointer32W16( SEGPTR vp, UINT16 fMode )
|
|
|
|
{
|
2001-12-20 00:59:54 +01:00
|
|
|
GlobalPageLock16(GlobalHandle16(SELECTOROF(vp)));
|
2000-11-27 22:59:08 +01:00
|
|
|
return (DWORD)K32WOWGetVDMPointer( vp, 0, (DWORD)fMode );
|
1999-08-18 20:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* LoadLibraryEx32W (KERNEL.513)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI LoadLibraryEx32W16( LPCSTR lpszLibFile, DWORD hFile, DWORD dwFlags )
|
|
|
|
{
|
|
|
|
HMODULE hModule;
|
2002-06-01 01:06:46 +02:00
|
|
|
DOS_FULL_NAME full_name;
|
2000-11-16 00:41:46 +01:00
|
|
|
DWORD mutex_count;
|
2002-08-27 03:13:58 +02:00
|
|
|
UNICODE_STRING libfileW;
|
|
|
|
LPCWSTR filenameW;
|
|
|
|
static const WCHAR dllW[] = {'.','D','L','L',0};
|
|
|
|
|
|
|
|
if (!lpszLibFile)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RtlCreateUnicodeStringFromAsciiz(&libfileW, lpszLibFile))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
2000-08-07 06:18:00 +02:00
|
|
|
|
2000-08-16 14:43:42 +02:00
|
|
|
/* if the file can not be found, call LoadLibraryExA anyway, since it might be
|
|
|
|
a buildin module. This case is handled in MODULE_LoadLibraryExA */
|
|
|
|
|
2002-08-27 03:13:58 +02:00
|
|
|
filenameW = libfileW.Buffer;
|
|
|
|
if ( DIR_SearchPath( NULL, filenameW, dllW, &full_name, FALSE ) )
|
|
|
|
filenameW = full_name.short_name;
|
1999-08-18 20:31:26 +02:00
|
|
|
|
2000-11-16 00:41:46 +01:00
|
|
|
ReleaseThunkLock( &mutex_count );
|
2002-08-27 03:13:58 +02:00
|
|
|
hModule = LoadLibraryExW( filenameW, (HANDLE)hFile, dwFlags );
|
2000-11-16 00:41:46 +01:00
|
|
|
RestoreThunkLock( mutex_count );
|
2002-08-27 03:13:58 +02:00
|
|
|
|
|
|
|
RtlFreeUnicodeString(&libfileW);
|
|
|
|
|
1999-08-18 20:31:26 +02:00
|
|
|
return (DWORD)hModule;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* GetProcAddress32W (KERNEL.515)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetProcAddress32W16( DWORD hModule, LPCSTR lpszProc )
|
|
|
|
{
|
|
|
|
return (DWORD)GetProcAddress( (HMODULE)hModule, lpszProc );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* FreeLibrary32W (KERNEL.514)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI FreeLibrary32W16( DWORD hLibModule )
|
|
|
|
{
|
|
|
|
BOOL retv;
|
2000-11-16 00:41:46 +01:00
|
|
|
DWORD mutex_count;
|
1999-08-18 20:31:26 +02:00
|
|
|
|
2000-11-16 00:41:46 +01:00
|
|
|
ReleaseThunkLock( &mutex_count );
|
1999-08-18 20:31:26 +02:00
|
|
|
retv = FreeLibrary( (HMODULE)hLibModule );
|
2000-11-16 00:41:46 +01:00
|
|
|
RestoreThunkLock( mutex_count );
|
1999-08-18 20:31:26 +02:00
|
|
|
return (DWORD)retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* WOW_CallProc32W
|
|
|
|
*/
|
|
|
|
static DWORD WOW_CallProc32W16( BOOL Ex )
|
|
|
|
{
|
|
|
|
DWORD nrofargs, argconvmask;
|
|
|
|
FARPROC proc32;
|
|
|
|
DWORD *args, ret;
|
2000-11-16 00:41:46 +01:00
|
|
|
DWORD mutex_count;
|
1999-08-18 20:31:26 +02:00
|
|
|
VA_LIST16 valist;
|
|
|
|
int i;
|
|
|
|
int aix;
|
|
|
|
|
2000-11-16 00:41:46 +01:00
|
|
|
ReleaseThunkLock( &mutex_count );
|
1999-08-18 20:31:26 +02:00
|
|
|
|
|
|
|
VA_START16( valist );
|
|
|
|
nrofargs = VA_ARG16( valist, DWORD );
|
|
|
|
argconvmask = VA_ARG16( valist, DWORD );
|
|
|
|
proc32 = VA_ARG16( valist, FARPROC );
|
|
|
|
TRACE("(%ld,%ld,%p, Ex%d args[",nrofargs,argconvmask,proc32,Ex);
|
2000-04-30 14:11:12 +02:00
|
|
|
args = (DWORD*)HeapAlloc( GetProcessHeap(), 0, sizeof(DWORD)*nrofargs );
|
|
|
|
if(args == NULL) proc32 = NULL; /* maybe we should WARN here? */
|
1999-08-18 20:31:26 +02:00
|
|
|
/* CallProcEx doesn't need its args reversed */
|
|
|
|
for (i=0;i<nrofargs;i++) {
|
|
|
|
if (Ex) {
|
|
|
|
aix = i;
|
|
|
|
} else {
|
|
|
|
aix = nrofargs - i - 1;
|
|
|
|
}
|
|
|
|
if (argconvmask & (1<<i))
|
|
|
|
{
|
|
|
|
SEGPTR ptr = VA_ARG16( valist, SEGPTR );
|
2000-12-13 21:20:09 +01:00
|
|
|
if (args) args[aix] = (DWORD)MapSL(ptr);
|
|
|
|
if (TRACE_ON(thunk)) DPRINTF("%08lx(%p),",ptr,MapSL(ptr));
|
1999-08-18 20:31:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-04-30 14:11:12 +02:00
|
|
|
DWORD arg = VA_ARG16( valist, DWORD );
|
|
|
|
if (args) args[aix] = arg;
|
|
|
|
if (TRACE_ON(thunk)) DPRINTF("%ld,", arg);
|
1999-08-18 20:31:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (TRACE_ON(thunk)) DPRINTF("])\n");
|
|
|
|
VA_END16( valist );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: If ( nrofargs & CPEX_DEST_CDECL ) != 0, we should call a
|
|
|
|
* 32-bit CDECL routine ...
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!proc32) ret = 0;
|
|
|
|
else switch (nrofargs)
|
|
|
|
{
|
|
|
|
case 0: ret = proc32();
|
|
|
|
break;
|
|
|
|
case 1: ret = proc32(args[0]);
|
|
|
|
break;
|
|
|
|
case 2: ret = proc32(args[0],args[1]);
|
|
|
|
break;
|
|
|
|
case 3: ret = proc32(args[0],args[1],args[2]);
|
|
|
|
break;
|
|
|
|
case 4: ret = proc32(args[0],args[1],args[2],args[3]);
|
|
|
|
break;
|
|
|
|
case 5: ret = proc32(args[0],args[1],args[2],args[3],args[4]);
|
|
|
|
break;
|
|
|
|
case 6: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5]);
|
|
|
|
break;
|
|
|
|
case 7: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
|
|
|
|
break;
|
|
|
|
case 8: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]);
|
|
|
|
break;
|
|
|
|
case 9: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]);
|
|
|
|
break;
|
|
|
|
case 10:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9]);
|
|
|
|
break;
|
|
|
|
case 11:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10]);
|
|
|
|
break;
|
2000-08-28 21:29:44 +02:00
|
|
|
case 12:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11]);
|
|
|
|
break;
|
|
|
|
case 13:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12]);
|
|
|
|
break;
|
1999-08-18 20:31:26 +02:00
|
|
|
default:
|
|
|
|
/* FIXME: should go up to 32 arguments */
|
|
|
|
ERR("Unsupported number of arguments %ld, please report.\n",nrofargs);
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
2000-04-30 14:11:12 +02:00
|
|
|
|
1999-08-18 20:31:26 +02:00
|
|
|
/* POP nrofargs DWORD arguments and 3 DWORD parameters */
|
|
|
|
if (!Ex) stack16_pop( (3 + nrofargs) * sizeof(DWORD) );
|
|
|
|
|
|
|
|
TRACE("returns %08lx\n",ret);
|
|
|
|
HeapFree( GetProcessHeap(), 0, args );
|
|
|
|
|
2000-11-16 00:41:46 +01:00
|
|
|
RestoreThunkLock( mutex_count );
|
1999-08-18 20:31:26 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* CallProc32W (KERNEL.517)
|
1999-08-18 20:31:26 +02:00
|
|
|
*
|
|
|
|
* DWORD PASCAL CallProc32W( DWORD p1, ... , DWORD lpProcAddress,
|
|
|
|
* DWORD fAddressConvert, DWORD cParams );
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CallProc32W16( void )
|
|
|
|
{
|
|
|
|
return WOW_CallProc32W16( FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* _CallProcEx32W (KERNEL.518)
|
1999-08-18 20:31:26 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* DWORD CallProcEx32W( DWORD cParams, DWORD fAddressConvert,
|
1999-08-18 20:31:26 +02:00
|
|
|
* DWORD lpProcAddress, DWORD p1, ... );
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CallProcEx32W16( void )
|
|
|
|
{
|
|
|
|
return WOW_CallProc32W16( TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* WOW16Call (KERNEL.500)
|
1999-08-18 20:31:26 +02:00
|
|
|
*
|
|
|
|
* FIXME!!!
|
|
|
|
*
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD WINAPI WOW16Call(WORD x,WORD y,WORD z)
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
DWORD calladdr;
|
|
|
|
VA_LIST16 args;
|
|
|
|
FIXME("(0x%04x,0x%04x,%d),calling (",x,y,z);
|
|
|
|
|
|
|
|
VA_START16(args);
|
|
|
|
for (i=0;i<x/2;i++) {
|
|
|
|
WORD a = VA_ARG16(args,WORD);
|
|
|
|
DPRINTF("%04x ",a);
|
|
|
|
}
|
|
|
|
calladdr = VA_ARG16(args,DWORD);
|
|
|
|
VA_END16(args);
|
|
|
|
stack16_pop( x + sizeof(DWORD) );
|
|
|
|
DPRINTF(") calling address was 0x%08lx\n",calladdr);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-27 02:57:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateThread16 (KERNEL.441)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
|
|
|
|
FARPROC16 start, SEGPTR param,
|
|
|
|
DWORD flags, LPDWORD id )
|
|
|
|
{
|
|
|
|
struct thread_args *args = HeapAlloc( GetProcessHeap(), 0, sizeof(*args) );
|
|
|
|
if (!args) return INVALID_HANDLE_VALUE;
|
|
|
|
args->proc = start;
|
|
|
|
args->param = param;
|
|
|
|
return CreateThread( sa, stack, start_thread16, args, flags, id );
|
|
|
|
}
|