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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
|
|
|
|
2002-08-29 01:42:34 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2003-08-24 01:30:51 +02:00
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-08-24 01:30:51 +02:00
|
|
|
|
1999-08-18 20:31:26 +02:00
|
|
|
#include "wine/winbase16.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
1999-08-18 20:31:26 +02:00
|
|
|
#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"
|
2003-08-25 02:56:37 +02:00
|
|
|
#include "excpt.h"
|
2005-05-16 19:52:10 +02:00
|
|
|
#include "thread.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2003-09-18 06:39:13 +02:00
|
|
|
#include "kernel_private.h"
|
2005-05-16 21:44:54 +02:00
|
|
|
#include "kernel16_private.h"
|
2003-08-25 02:56:37 +02:00
|
|
|
#include "wine/exception.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);
|
2003-08-24 01:30:51 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
2003-10-09 21:52:23 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(snoop);
|
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
|
|
|
|
|
2003-08-25 02:56:37 +02:00
|
|
|
|
|
|
|
#ifdef __i386__
|
2003-08-26 01:48:30 +02:00
|
|
|
|
2003-08-25 02:56:37 +02:00
|
|
|
/* symbols exported from relay16.s */
|
|
|
|
extern DWORD WINAPI wine_call_to_16( FARPROC16 target, DWORD cbArgs, PEXCEPTION_HANDLER handler );
|
|
|
|
extern void WINAPI wine_call_to_16_regs( CONTEXT86 *context, DWORD cbArgs, PEXCEPTION_HANDLER handler );
|
2005-07-03 13:28:44 +02:00
|
|
|
extern void __wine_call_to_16_ret(void);
|
2003-08-25 02:56:37 +02:00
|
|
|
extern void CALL32_CBClient_Ret();
|
|
|
|
extern void CALL32_CBClientEx_Ret();
|
2004-03-16 02:15:11 +01:00
|
|
|
extern void DPMI_PendingEventCheck();
|
|
|
|
extern void DPMI_PendingEventCheck_Cleanup();
|
|
|
|
extern void DPMI_PendingEventCheck_Return();
|
2005-07-03 13:28:44 +02:00
|
|
|
extern BYTE __wine_call16_start[];
|
|
|
|
extern BYTE __wine_call16_end[];
|
2003-08-25 02:56:37 +02:00
|
|
|
|
2003-10-09 00:41:12 +02:00
|
|
|
extern void RELAY16_InitDebugLists(void);
|
|
|
|
|
2005-07-03 13:28:44 +02:00
|
|
|
static SEGPTR call16_ret_addr; /* segptr to __wine_call_to_16_ret routine */
|
2003-08-25 02:56:37 +02:00
|
|
|
|
2004-03-16 02:15:11 +01:00
|
|
|
static WORD dpmi_checker_selector;
|
|
|
|
static DWORD dpmi_checker_offset_call;
|
|
|
|
static DWORD dpmi_checker_offset_cleanup;
|
|
|
|
static DWORD dpmi_checker_offset_return;
|
|
|
|
|
2003-08-25 02:56:37 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* WOWTHUNK_Init
|
|
|
|
*/
|
|
|
|
BOOL WOWTHUNK_Init(void)
|
|
|
|
{
|
|
|
|
/* allocate the code selector for CallTo16 routines */
|
2005-07-03 13:28:44 +02:00
|
|
|
LDT_ENTRY entry;
|
|
|
|
WORD codesel = wine_ldt_alloc_entries(1);
|
|
|
|
|
2003-08-25 02:56:37 +02:00
|
|
|
if (!codesel) return FALSE;
|
2005-07-03 13:28:44 +02:00
|
|
|
wine_ldt_set_base( &entry, __wine_call16_start );
|
|
|
|
wine_ldt_set_limit( &entry, (BYTE *)(&CallTo16_TebSelector + 1) - __wine_call16_start - 1 );
|
|
|
|
wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
|
|
|
|
wine_ldt_set_entry( codesel, &entry );
|
2003-08-25 02:56:37 +02:00
|
|
|
|
|
|
|
/* Patch the return addresses for CallTo16 routines */
|
|
|
|
|
|
|
|
CallTo16_DataSelector = wine_get_ds();
|
2005-07-03 13:28:44 +02:00
|
|
|
call16_ret_addr = MAKESEGPTR( codesel, (BYTE *)__wine_call_to_16_ret - __wine_call16_start );
|
2003-08-25 02:56:37 +02:00
|
|
|
CALL32_CBClient_RetAddr =
|
2005-07-03 13:28:44 +02:00
|
|
|
MAKESEGPTR( codesel, (BYTE *)CALL32_CBClient_Ret - __wine_call16_start );
|
2003-08-25 02:56:37 +02:00
|
|
|
CALL32_CBClientEx_RetAddr =
|
2005-07-03 13:28:44 +02:00
|
|
|
MAKESEGPTR( codesel, (BYTE *)CALL32_CBClientEx_Ret - __wine_call16_start );
|
2003-10-09 00:41:12 +02:00
|
|
|
|
2004-03-16 02:15:11 +01:00
|
|
|
/* Prepare selector and offsets for DPMI event checking. */
|
|
|
|
dpmi_checker_selector = codesel;
|
2005-07-03 13:28:44 +02:00
|
|
|
dpmi_checker_offset_call = (BYTE *)DPMI_PendingEventCheck - __wine_call16_start;
|
|
|
|
dpmi_checker_offset_cleanup = (BYTE *)DPMI_PendingEventCheck_Cleanup - __wine_call16_start;
|
|
|
|
dpmi_checker_offset_return = (BYTE *)DPMI_PendingEventCheck_Return - __wine_call16_start;
|
2004-03-16 02:15:11 +01:00
|
|
|
|
2003-10-09 21:52:23 +02:00
|
|
|
if (TRACE_ON(relay) || TRACE_ON(snoop)) RELAY16_InitDebugLists();
|
2003-10-28 22:57:24 +01:00
|
|
|
|
2003-08-26 01:48:30 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
* fix_selector
|
|
|
|
*
|
|
|
|
* Fix a selector load that caused an exception if it's in the
|
|
|
|
* 16-bit relay code.
|
|
|
|
*/
|
|
|
|
static BOOL fix_selector( CONTEXT *context )
|
|
|
|
{
|
|
|
|
WORD *stack;
|
|
|
|
BYTE *instr = (BYTE *)context->Eip;
|
|
|
|
|
2005-07-03 13:28:44 +02:00
|
|
|
if (instr < __wine_call16_start || instr >= __wine_call16_end) return FALSE;
|
2003-08-26 01:48:30 +02:00
|
|
|
|
|
|
|
/* skip prefixes */
|
|
|
|
while (*instr == 0x66 || *instr == 0x67) instr++;
|
|
|
|
|
|
|
|
switch(instr[0])
|
|
|
|
{
|
|
|
|
case 0x07: /* pop es */
|
|
|
|
case 0x17: /* pop ss */
|
|
|
|
case 0x1f: /* pop ds */
|
|
|
|
break;
|
|
|
|
case 0x0f: /* extended instruction */
|
|
|
|
switch(instr[1])
|
|
|
|
{
|
|
|
|
case 0xa1: /* pop fs */
|
|
|
|
case 0xa9: /* pop gs */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
stack = wine_ldt_get_ptr( context->SegSs, context->Esp );
|
|
|
|
TRACE( "fixing up selector %x for pop instruction\n", *stack );
|
|
|
|
*stack = 0;
|
2003-08-25 02:56:37 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-16 02:15:11 +01:00
|
|
|
/*************************************************************
|
|
|
|
* insert_event_check
|
|
|
|
*
|
|
|
|
* Make resuming the context check for pending DPMI events
|
|
|
|
* before the original context is restored. This is required
|
|
|
|
* because DPMI events are asynchronous, they are blocked while
|
|
|
|
* Wine 32-bit code is being executed and we want to prevent
|
|
|
|
* a race when returning back to 16-bit or 32-bit DPMI context.
|
|
|
|
*/
|
|
|
|
static void insert_event_check( CONTEXT *context )
|
|
|
|
{
|
|
|
|
char *stack = wine_ldt_get_ptr( context->SegSs, context->Esp );
|
|
|
|
|
2004-09-28 21:18:06 +02:00
|
|
|
/* don't do event check while in system code */
|
|
|
|
if (wine_ldt_is_system(context->SegCs))
|
|
|
|
return;
|
|
|
|
|
2004-03-16 02:15:11 +01:00
|
|
|
if(context->SegCs == dpmi_checker_selector &&
|
|
|
|
context->Eip >= dpmi_checker_offset_call &&
|
|
|
|
context->Eip <= dpmi_checker_offset_cleanup)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Nested call. Stack will be preserved.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else if(context->SegCs == dpmi_checker_selector &&
|
|
|
|
context->Eip == dpmi_checker_offset_return)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Nested call. We have just finished popping the fs
|
|
|
|
* register, lets put it back into stack.
|
|
|
|
*/
|
|
|
|
|
|
|
|
stack -= sizeof(WORD);
|
|
|
|
*(WORD*)stack = context->SegFs;
|
|
|
|
|
|
|
|
context->Esp -= 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Call is not nested.
|
|
|
|
* Push modified registers into stack.
|
|
|
|
* These will be popped by the assembler stub.
|
|
|
|
*/
|
|
|
|
|
|
|
|
stack -= sizeof(DWORD);
|
|
|
|
*(DWORD*)stack = context->EFlags;
|
|
|
|
|
|
|
|
stack -= sizeof(DWORD);
|
|
|
|
*(DWORD*)stack = context->SegCs;
|
|
|
|
|
|
|
|
stack -= sizeof(DWORD);
|
|
|
|
*(DWORD*)stack = context->Eip;
|
|
|
|
|
|
|
|
stack -= sizeof(WORD);
|
|
|
|
*(WORD*)stack = context->SegFs;
|
|
|
|
|
|
|
|
context->Esp -= 14;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modify the context so that we jump into assembler stub.
|
|
|
|
* TEB access is made easier by providing the stub
|
|
|
|
* with the correct fs register value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
context->SegCs = dpmi_checker_selector;
|
|
|
|
context->Eip = dpmi_checker_offset_call;
|
|
|
|
context->SegFs = wine_get_fs();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-25 02:56:37 +02:00
|
|
|
/*************************************************************
|
|
|
|
* call16_handler
|
|
|
|
*
|
|
|
|
* Handler for exceptions occurring in 16-bit code.
|
|
|
|
*/
|
2003-08-28 05:07:56 +02:00
|
|
|
static DWORD call16_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
|
|
|
|
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **pdispatcher )
|
2003-08-25 02:56:37 +02:00
|
|
|
{
|
|
|
|
if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
|
|
|
|
{
|
|
|
|
/* unwinding: restore the stack pointer in the TEB, and leave the Win16 mutex */
|
|
|
|
STACK32FRAME *frame32 = (STACK32FRAME *)((char *)frame - offsetof(STACK32FRAME,frame));
|
2005-05-14 14:16:46 +02:00
|
|
|
NtCurrentTeb()->WOW32Reserved = (void *)frame32->frame16;
|
2003-08-25 02:56:37 +02:00
|
|
|
_LeaveWin16Lock();
|
|
|
|
}
|
2003-09-17 06:34:31 +02:00
|
|
|
else if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
|
|
|
|
record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)
|
2003-08-25 02:56:37 +02:00
|
|
|
{
|
2003-11-17 21:12:56 +01:00
|
|
|
if (wine_ldt_is_system(context->SegCs))
|
2003-08-25 02:56:37 +02:00
|
|
|
{
|
2003-08-26 01:48:30 +02:00
|
|
|
if (fix_selector( context )) return ExceptionContinueExecution;
|
|
|
|
}
|
2003-09-17 06:34:31 +02:00
|
|
|
else
|
2003-08-26 01:48:30 +02:00
|
|
|
{
|
2003-09-17 06:34:31 +02:00
|
|
|
SEGPTR gpHandler;
|
2007-05-18 16:37:23 +02:00
|
|
|
DWORD ret = __wine_emulate_instruction( record, context );
|
2003-09-17 06:34:31 +02:00
|
|
|
|
2004-03-16 02:15:11 +01:00
|
|
|
/*
|
|
|
|
* Insert check for pending DPMI events. Note that this
|
|
|
|
* check must be inserted after instructions have been
|
|
|
|
* emulated because the instruction emulation requires
|
|
|
|
* original CS:IP and the emulation may change TEB.dpmi_vif.
|
|
|
|
*/
|
|
|
|
if(NtCurrentTeb()->dpmi_vif)
|
|
|
|
insert_event_check( context );
|
|
|
|
|
2003-09-17 22:23:33 +02:00
|
|
|
if (ret != ExceptionContinueSearch) return ret;
|
2003-09-17 06:34:31 +02:00
|
|
|
|
|
|
|
/* check for Win16 __GP handler */
|
|
|
|
if ((gpHandler = HasGPHandler16( MAKESEGPTR( context->SegCs, context->Eip ) )))
|
2003-08-26 01:48:30 +02:00
|
|
|
{
|
|
|
|
WORD *stack = wine_ldt_get_ptr( context->SegSs, context->Esp );
|
|
|
|
*--stack = context->SegCs;
|
|
|
|
*--stack = context->Eip;
|
|
|
|
|
|
|
|
if (!IS_SELECTOR_32BIT(context->SegSs))
|
|
|
|
context->Esp = MAKELONG( LOWORD(context->Esp - 2*sizeof(WORD)),
|
|
|
|
HIWORD(context->Esp) );
|
|
|
|
else
|
|
|
|
context->Esp -= 2*sizeof(WORD);
|
|
|
|
|
|
|
|
context->SegCs = SELECTOROF( gpHandler );
|
|
|
|
context->Eip = OFFSETOF( gpHandler );
|
|
|
|
return ExceptionContinueExecution;
|
|
|
|
}
|
2003-08-25 02:56:37 +02:00
|
|
|
}
|
|
|
|
}
|
2004-03-16 02:15:11 +01:00
|
|
|
else if (record->ExceptionCode == EXCEPTION_VM86_STI)
|
|
|
|
{
|
|
|
|
insert_event_check( context );
|
|
|
|
}
|
2003-08-25 02:56:37 +02:00
|
|
|
return ExceptionContinueSearch;
|
|
|
|
}
|
|
|
|
|
2003-09-17 22:23:33 +02:00
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
* vm86_handler
|
|
|
|
*
|
|
|
|
* Handler for exceptions occurring in vm86 code.
|
|
|
|
*/
|
|
|
|
static DWORD vm86_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
|
|
|
|
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **pdispatcher )
|
|
|
|
{
|
|
|
|
if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
|
|
|
|
return ExceptionContinueSearch;
|
|
|
|
|
|
|
|
if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
|
|
|
|
record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)
|
|
|
|
{
|
2007-05-18 16:37:23 +02:00
|
|
|
return __wine_emulate_instruction( record, context );
|
2003-09-17 22:23:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ExceptionContinueSearch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-26 01:48:30 +02:00
|
|
|
#else /* __i386__ */
|
|
|
|
|
|
|
|
BOOL WOWTHUNK_Init(void)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __i386__ */
|
|
|
|
|
2003-08-25 02:56:37 +02:00
|
|
|
|
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:
|
2003-08-28 01:14:29 +02:00
|
|
|
return ((TDB *)GlobalLock16(handle))->teb->ClientId.UniqueThread;
|
2002-10-17 20:26:53 +02:00
|
|
|
|
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:
|
2003-08-23 02:03:40 +02:00
|
|
|
return TASK_GetTaskFromThread( (DWORD)handle );
|
2002-10-17 20:26:53 +02:00
|
|
|
|
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
|
|
|
{
|
2003-08-24 01:30:51 +02:00
|
|
|
#ifdef __i386__
|
1999-08-18 20:31:26 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
*/
|
2004-09-28 21:18:06 +02:00
|
|
|
char *stack = (char *)CURRENT_STACK16 - cbArgs;
|
2003-08-25 02:56:37 +02:00
|
|
|
|
|
|
|
memcpy( stack, pArgs, cbArgs );
|
1999-08-18 20:31:26 +02:00
|
|
|
|
2003-08-24 01:30:51 +02:00
|
|
|
if (dwFlags & (WCB16_REGS|WCB16_REGS_LONG))
|
|
|
|
{
|
|
|
|
CONTEXT *context = (CONTEXT *)pdwRetCode;
|
|
|
|
|
|
|
|
if (TRACE_ON(relay))
|
|
|
|
{
|
|
|
|
DWORD count = cbArgs / sizeof(WORD);
|
2004-09-28 21:18:06 +02:00
|
|
|
WORD * wstack = (WORD *)stack;
|
2003-08-24 01:30:51 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
DPRINTF("%04x:CallTo16(func=%04x:%04x,ds=%04x",
|
2003-08-24 01:30:51 +02:00
|
|
|
GetCurrentThreadId(),
|
|
|
|
context->SegCs, LOWORD(context->Eip), context->SegDs );
|
2004-09-28 21:18:06 +02:00
|
|
|
while (count) DPRINTF( ",%04x", wstack[--count] );
|
2003-08-24 01:30:51 +02:00
|
|
|
DPRINTF(") ss:sp=%04x:%04x",
|
2005-05-14 14:16:46 +02:00
|
|
|
SELECTOROF(NtCurrentTeb()->WOW32Reserved), OFFSETOF(NtCurrentTeb()->WOW32Reserved) );
|
2003-08-24 01:30:51 +02:00
|
|
|
DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x bp=%04x es=%04x fs=%04x\n",
|
|
|
|
(WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
|
|
|
|
(WORD)context->Edx, (WORD)context->Esi, (WORD)context->Edi,
|
|
|
|
(WORD)context->Ebp, (WORD)context->SegEs, (WORD)context->SegFs );
|
|
|
|
SYSLEVEL_CheckNotLevel( 2 );
|
|
|
|
}
|
|
|
|
|
2003-11-15 01:13:20 +01:00
|
|
|
if (context->EFlags & 0x00020000) /* v86 mode */
|
2003-08-25 02:56:37 +02:00
|
|
|
{
|
2003-09-17 22:23:33 +02:00
|
|
|
EXCEPTION_REGISTRATION_RECORD frame;
|
|
|
|
frame.Handler = vm86_handler;
|
|
|
|
__wine_push_frame( &frame );
|
|
|
|
__wine_enter_vm86( context );
|
|
|
|
__wine_pop_frame( &frame );
|
2003-08-25 02:56:37 +02:00
|
|
|
}
|
2003-08-24 01:30:51 +02:00
|
|
|
else
|
2003-08-25 02:56:37 +02:00
|
|
|
{
|
2003-09-17 22:23:33 +02:00
|
|
|
/* push return address */
|
|
|
|
if (dwFlags & WCB16_REGS_LONG)
|
|
|
|
{
|
2004-09-28 21:18:06 +02:00
|
|
|
stack -= sizeof(DWORD);
|
|
|
|
*((DWORD *)stack) = HIWORD(call16_ret_addr);
|
|
|
|
stack -= sizeof(DWORD);
|
|
|
|
*((DWORD *)stack) = LOWORD(call16_ret_addr);
|
2003-09-17 22:23:33 +02:00
|
|
|
cbArgs += 2 * sizeof(DWORD);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-28 21:18:06 +02:00
|
|
|
stack -= sizeof(SEGPTR);
|
|
|
|
*((SEGPTR *)stack) = call16_ret_addr;
|
2003-09-17 22:23:33 +02:00
|
|
|
cbArgs += sizeof(SEGPTR);
|
|
|
|
}
|
2003-08-25 02:56:37 +02:00
|
|
|
|
2004-03-16 02:15:11 +01:00
|
|
|
/*
|
|
|
|
* Start call by checking for pending events.
|
|
|
|
* Note that wine_call_to_16_regs overwrites context stack
|
|
|
|
* pointer so we may modify it here without a problem.
|
|
|
|
*/
|
|
|
|
if (NtCurrentTeb()->dpmi_vif)
|
|
|
|
{
|
|
|
|
context->SegSs = wine_get_ds();
|
|
|
|
context->Esp = (DWORD)stack;
|
|
|
|
insert_event_check( context );
|
|
|
|
cbArgs += (DWORD)stack - context->Esp;
|
|
|
|
}
|
|
|
|
|
2003-09-17 22:23:33 +02:00
|
|
|
_EnterWin16Lock();
|
|
|
|
wine_call_to_16_regs( context, cbArgs, call16_handler );
|
|
|
|
_LeaveWin16Lock();
|
|
|
|
}
|
2003-08-24 01:30:51 +02:00
|
|
|
|
|
|
|
if (TRACE_ON(relay))
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
DPRINTF("%04x:RetFrom16() ss:sp=%04x:%04x ",
|
2005-05-14 14:16:46 +02:00
|
|
|
GetCurrentThreadId(), SELECTOROF(NtCurrentTeb()->WOW32Reserved),
|
|
|
|
OFFSETOF(NtCurrentTeb()->WOW32Reserved));
|
2003-08-24 01:30:51 +02:00
|
|
|
DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x bp=%04x sp=%04x\n",
|
|
|
|
(WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
|
|
|
|
(WORD)context->Edx, (WORD)context->Ebp, (WORD)context->Esp );
|
|
|
|
SYSLEVEL_CheckNotLevel( 2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
if (TRACE_ON(relay))
|
|
|
|
{
|
|
|
|
DWORD count = cbArgs / sizeof(WORD);
|
2004-09-28 21:18:06 +02:00
|
|
|
WORD * wstack = (WORD *)stack;
|
2003-08-24 01:30:51 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
DPRINTF("%04x:CallTo16(func=%04x:%04x,ds=%04x",
|
2003-08-24 01:30:51 +02:00
|
|
|
GetCurrentThreadId(), HIWORD(vpfn16), LOWORD(vpfn16),
|
2005-05-14 14:16:46 +02:00
|
|
|
SELECTOROF(NtCurrentTeb()->WOW32Reserved) );
|
2004-09-28 21:18:06 +02:00
|
|
|
while (count) DPRINTF( ",%04x", wstack[--count] );
|
2003-08-24 01:30:51 +02:00
|
|
|
DPRINTF(") ss:sp=%04x:%04x\n",
|
2005-05-14 14:16:46 +02:00
|
|
|
SELECTOROF(NtCurrentTeb()->WOW32Reserved), OFFSETOF(NtCurrentTeb()->WOW32Reserved) );
|
2003-08-24 01:30:51 +02:00
|
|
|
SYSLEVEL_CheckNotLevel( 2 );
|
|
|
|
}
|
|
|
|
|
2003-08-25 02:56:37 +02:00
|
|
|
/* push return address */
|
2004-09-28 21:18:06 +02:00
|
|
|
stack -= sizeof(SEGPTR);
|
|
|
|
*((SEGPTR *)stack) = call16_ret_addr;
|
2003-08-25 02:56:37 +02:00
|
|
|
cbArgs += sizeof(SEGPTR);
|
|
|
|
|
2003-08-24 01:30:51 +02:00
|
|
|
/*
|
|
|
|
* Actually, we should take care whether the called routine cleans up
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
_EnterWin16Lock();
|
2003-08-25 02:56:37 +02:00
|
|
|
ret = wine_call_to_16( (FARPROC16)vpfn16, cbArgs, call16_handler );
|
2003-08-24 01:30:51 +02:00
|
|
|
if (pdwRetCode) *pdwRetCode = ret;
|
|
|
|
_LeaveWin16Lock();
|
|
|
|
|
|
|
|
if (TRACE_ON(relay))
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
DPRINTF("%04x:RetFrom16() ss:sp=%04x:%04x retval=%08x\n",
|
2005-05-14 14:16:46 +02:00
|
|
|
GetCurrentThreadId(), SELECTOROF(NtCurrentTeb()->WOW32Reserved),
|
|
|
|
OFFSETOF(NtCurrentTeb()->WOW32Reserved), ret);
|
2003-08-24 01:30:51 +02:00
|
|
|
SYSLEVEL_CheckNotLevel( 2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
assert(0); /* cannot call to 16-bit on non-Intel architectures */
|
|
|
|
#endif /* __i386__ */
|
1999-08-18 20:31:26 +02:00
|
|
|
|
|
|
|
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;
|
2000-11-16 00:41:46 +01:00
|
|
|
DWORD mutex_count;
|
2004-03-25 06:32:05 +01:00
|
|
|
OFSTRUCT ofs;
|
|
|
|
const char *p;
|
2002-08-27 03:13:58 +02:00
|
|
|
|
|
|
|
if (!lpszLibFile)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-06 17:44:31 +02:00
|
|
|
/* if the file cannot be found, call LoadLibraryExA anyway, since it might be
|
2004-03-25 06:32:05 +01:00
|
|
|
a builtin module. This case is handled in MODULE_LoadLibraryExA */
|
2000-08-16 14:43:42 +02:00
|
|
|
|
2004-03-25 06:32:05 +01:00
|
|
|
if ((p = strrchr( lpszLibFile, '.' )) && !strchr( p, '\\' )) /* got an extension */
|
|
|
|
{
|
|
|
|
if (OpenFile16( lpszLibFile, &ofs, OF_EXIST ) != HFILE_ERROR16)
|
|
|
|
lpszLibFile = ofs.szPathName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH+4];
|
|
|
|
strcpy( buffer, lpszLibFile );
|
|
|
|
strcat( buffer, ".dll" );
|
|
|
|
if (OpenFile16( buffer, &ofs, OF_EXIST ) != HFILE_ERROR16)
|
|
|
|
lpszLibFile = ofs.szPathName;
|
|
|
|
}
|
1999-08-18 20:31:26 +02:00
|
|
|
|
2000-11-16 00:41:46 +01:00
|
|
|
ReleaseThunkLock( &mutex_count );
|
2004-03-25 06:32:05 +01:00
|
|
|
hModule = LoadLibraryExA( lpszLibFile, (HANDLE)hFile, dwFlags );
|
2000-11-16 00:41:46 +01:00
|
|
|
RestoreThunkLock( mutex_count );
|
2002-08-27 03:13:58 +02:00
|
|
|
|
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
|
|
|
|
*/
|
2003-08-27 04:57:32 +02:00
|
|
|
static DWORD WOW_CallProc32W16( FARPROC proc32, DWORD nrofargs, DWORD *args )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
2003-08-27 04:57:32 +02:00
|
|
|
DWORD ret;
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2003-05-13 02:30:32 +02:00
|
|
|
case 14: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],args[13]);
|
|
|
|
break;
|
|
|
|
case 15: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],args[13],args[14]);
|
|
|
|
break;
|
1999-08-18 20:31:26 +02:00
|
|
|
default:
|
|
|
|
/* FIXME: should go up to 32 arguments */
|
2006-10-12 22:56:29 +02:00
|
|
|
ERR("Unsupported number of arguments %d, please report.\n",nrofargs);
|
1999-08-18 20:31:26 +02:00
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
2000-04-30 14:11:12 +02:00
|
|
|
|
2003-08-27 04:57:32 +02:00
|
|
|
RestoreThunkLock( mutex_count );
|
1999-08-18 20:31:26 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("returns %08x\n",ret);
|
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
|
|
|
*/
|
2003-08-27 04:57:32 +02:00
|
|
|
DWORD WINAPIV CallProc32W16( DWORD nrofargs, DWORD argconvmask, FARPROC proc32, VA_LIST16 valist )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
2003-08-27 04:57:32 +02:00
|
|
|
DWORD args[32];
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("(%d,%d,%p args[",nrofargs,argconvmask,proc32);
|
2003-08-27 04:57:32 +02:00
|
|
|
|
|
|
|
for (i=0;i<nrofargs;i++)
|
|
|
|
{
|
|
|
|
if (argconvmask & (1<<i))
|
|
|
|
{
|
|
|
|
SEGPTR ptr = VA_ARG16( valist, SEGPTR );
|
|
|
|
/* pascal convention, have to reverse the arguments order */
|
|
|
|
args[nrofargs - i - 1] = (DWORD)MapSL(ptr);
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%08x(%p),",ptr,MapSL(ptr));
|
2003-08-27 04:57:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD arg = VA_ARG16( valist, DWORD );
|
|
|
|
/* pascal convention, have to reverse the arguments order */
|
|
|
|
args[nrofargs - i - 1] = arg;
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%d,", arg);
|
2003-08-27 04:57:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE("])\n");
|
|
|
|
|
|
|
|
/* POP nrofargs DWORD arguments and 3 DWORD parameters */
|
|
|
|
stack16_pop( (3 + nrofargs) * sizeof(DWORD) );
|
|
|
|
|
|
|
|
return WOW_CallProc32W16( proc32, nrofargs, args );
|
1999-08-18 20:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* _CallProcEx32W (KERNEL.518)
|
1999-08-18 20:31:26 +02:00
|
|
|
*/
|
2003-08-27 04:57:32 +02:00
|
|
|
DWORD WINAPIV CallProcEx32W16( DWORD nrofargs, DWORD argconvmask, FARPROC proc32, VA_LIST16 valist )
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
2003-08-27 04:57:32 +02:00
|
|
|
DWORD args[32];
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("(%d,%d,%p args[",nrofargs,argconvmask,proc32);
|
2003-08-27 04:57:32 +02:00
|
|
|
|
|
|
|
for (i=0;i<nrofargs;i++)
|
|
|
|
{
|
|
|
|
if (argconvmask & (1<<i))
|
|
|
|
{
|
|
|
|
SEGPTR ptr = VA_ARG16( valist, SEGPTR );
|
|
|
|
args[i] = (DWORD)MapSL(ptr);
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%08x(%p),",ptr,MapSL(ptr));
|
2003-08-27 04:57:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD arg = VA_ARG16( valist, DWORD );
|
|
|
|
args[i] = arg;
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%d,", arg);
|
2003-08-27 04:57:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE("])\n");
|
|
|
|
return WOW_CallProc32W16( proc32, nrofargs, args );
|
1999-08-18 20:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* WOW16Call (KERNEL.500)
|
1999-08-18 20:31:26 +02:00
|
|
|
*
|
|
|
|
* FIXME!!!
|
|
|
|
*
|
|
|
|
*/
|
2003-08-27 04:57:32 +02:00
|
|
|
DWORD WINAPIV WOW16Call(WORD x, WORD y, WORD z, VA_LIST16 args)
|
1999-08-18 20:31:26 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
DWORD calladdr;
|
|
|
|
FIXME("(0x%04x,0x%04x,%d),calling (",x,y,z);
|
|
|
|
|
|
|
|
for (i=0;i<x/2;i++) {
|
|
|
|
WORD a = VA_ARG16(args,WORD);
|
|
|
|
DPRINTF("%04x ",a);
|
|
|
|
}
|
|
|
|
calladdr = VA_ARG16(args,DWORD);
|
2003-08-27 04:57:32 +02:00
|
|
|
stack16_pop( 3*sizeof(WORD) + x + sizeof(DWORD) );
|
2006-10-12 22:56:29 +02:00
|
|
|
DPRINTF(") calling address was 0x%08x\n",calladdr);
|
1999-08-18 20:31:26 +02:00
|
|
|
return 0;
|
|
|
|
}
|