wine/if1632/relay.c
Alexandre Julliard c7c217b31c Release 980413
Sun Apr 12 12:22:23 1997  Andreas Mohr <100.30936@germany.net>

	* [files/drive.c]
	Fixed "no free space" problem with partition sizes between 1 and 2 GB
	(cluster_sectors may not exceed 0x40).

	* [windows/msgbox.c] [if1632/user.spec] [include/windows.h]
	Implemented MessageBoxIndirect16, corrected MSGBOXPARAMS16.

	* [loader/task.c]
	DOS environment strings may never exceed 127 chars
	-> truncate Unix environment strings if necessary.

Sun Apr 12 02:51:44 1998  Dimitrie O. Paun  <dimi@mail.cs.toronto.edu>

	* [files/*.c]
	All fprintf statements were converted to appropriate debug
	messages.

	* [tools/find_debug_channels]
	Updated comments at the beginning of the file.

Sat Apr 11 15:27:21 1998  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [loader/module.c] [loader/task.c] [scheduler/process.c]
	Moved some code around to prepare the ground for CreateProcess().

	* [memory/environ.c] [loader/task.c]
	Moved Win32 environment strings functions to environ.c.
	Unified Win16 and Win32 environment management.

	* [scheduler/handle.c] [scheduler/k32obj.c] [scheduler/*.c]
	Implemented handle inheritance and DuplicateHandle().

	* [scheduler/thread.c]
	Create a 16-bit stack for all threads.

	* [windows/dialog.c]
	Implemented DIALOGEX resource format.

Fri Apr 10 20:21:51 1998  Marcus Meissner <marcus@mud.de>

	* [configure.in][include/acconfig.h][*/*][multimedia/*]
	Cleaned up the OSS detection stuff, added some more checks for
	headerfiles/functions.
	Removed a lot of OS specific #ifdefs.
	Lots of dependend multimedia cleanups.

	* [loader/pe_image.c]
	Enhanced comment, added missing reference count increase.

	* [ole/compobj.c]
	Replaced broken StringFromGUID2 by working one.

	* [misc/winsock.c]
	SO_LINGER uses unsigned 16 bit in Win16 and Win32, but unsigned
	int (32bit) for UNIX.

	* [memory/global.c]
	Allow realloc for lockcount 1 too.

Fri Apr 10 15:27:34 1998  Morten Welinder  <terra@diku.dk>

	* [graphics/x11drv/text.c]
	Handle control characters in trace.  Ignore terminating newline.

	* [multimedia/init.c]
	(MULTIMEDIA_Init): Correct allocations.

	* [tools/examine-relay]
 	Tidy up.

	* [windows/syscolor.c]
	Change highlight colour from lightblue to lightgray.  This
	looks correct for menus.

Fri Apr 10 01:49:58 1998  Douglas Ridgway  <ridgway@winehq.com>

	* [configure.in] [Make.rules.in]
	Add check for c2man before using it.

Fri Apr 10 02:59:21 1998  Douglas Ridgway  <ridgway@winehq.com>

	* [DEVELOPERS-HINTS]
	Simple description of adding API calls.

	* [include/wintypes.h] [include/windows.h]
	Get rid of Winelib16, avoid declaring some illegal functions in
	Winelib, add prototypes for some enhanced metafile functions, fix
	GetTextExtentPoint32 declarations.

	* [relay32/gdi32.spec] [objects/enhmetafile.c]
	Cosmetic and functional improvements.

	* [include/wincon.h] [programs/view/*]
	Fixes, improved compatibility with native compilers.

Thu Apr  9 15:48:49 1998  Ulrich Weigand <weigand@informatik.uni-erlangen.de>

	* [win32/kernel32.c]
	Implemented FT_Thunk / FT_Prolog / FT_Exit / FT_PrologPrime.
	Fixed Common32ThkLS thunk function.

	* [tools/build.c] [relay32/relay386.c] [if1632/relay.c]
	Changed relay code to allow register functions to modify stack layout.

	* [memory/selector.c]
	Implemented AllocMappedBuffer / FreeMappedBuffer.

	* [relay32/kernel32.spec] [if1632/kernel.spec] [win32/ordinals.c]
	Added names for undocumented functions.

	* [loader/module.c]
	Bugfix: LoadLibrary16 should *not* silently load 32-bit DLL.

Thu Apr  9 03:54:58 1998  Jim Peterson <jspeter@birch.ee.vt.edu>

	* [windows/keyboard.c]
	Fix an erroneous test in TranslateAccelerator{16,32} for the end
	of the accelerator table.

Thu Apr  8 20:36:28 1998  Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de> 

	* [misc/crtdll.c]
	Implement getenv.

	* [misc/commdlg.c]
	Make Get[Save/Open]FileName work in most situations.

	* [misc/lstr.c]
	Use wvsprintf32A instead of vsprintf in FormatMessage32X

	* [misc/version]
	Make NT3.50 a recognised version

	* [graphics/x11drv/graphics.c]
	Change the algorithme to draw arcs

	* [loader/resource.c]
	Return an empty buffer in LoadString32A if no resource found.

	* [win32/code_page.c]
	Try harder to get the right size in MultiByteToWideChar.

	* [win32/process.c]
	Call WinExec32 for CreateProcess32A.

	* [windows/user.c]
	Install default Int0 Handler in InitApp().

Thu Apr  8 19:29:48 1998  Eric Kohl <ekohl@abo.rhein-zeitung.de>

	* [misc/imagelist.c]
	Preliminary fix for drawing selected images.
	Various improvements.

	* [controls/progress.c][include/progress.c][include/commctrl.h]
	Added progress bar messages and styles for IE4.01 (dll version 4.72)
	compatibility.
	Fixed led size problem.

	* [controls/updown.c][include/commctrl.h]
	Added UDM_GETRANGE32 and UDM_SETRANGE32.

	* [objects/oembitmaps.c][include/windows.h][include/bitmaps/*]
	Added Win95 icons and fixed Win95 cursor and restore button bug.
	Now they should be visible. Sorry!!!

	* [relay32/comctl32.spec]
	Added most missing function names.

Tue Apr  6 18:48:36 1998  Matthew Becker <mbecker@glasscity.net>

	* [objects/font.c] [if1632/gdi.spec]
	GetOutlineTextMetrics: stub

	* [objects/text.c]
	GetTextCharset should just call GetTextCharsetInfo.

	* [misc/mpr.c] [relay32/mpr.spec]
	WNetCachePassword: stub

	* [scheduler/thread.c] [relay32/user32.spec]
	AttachThreadInput: stub
	Updated documentation.

	* [objects/palette.c]
	Updated documentation.

Tue Mar 31 17:06:30 1998  James Juran <jrj120@psu.edu>

	* [*/*.c]
	Finished fixing USER32 ordinal numbers in function documentation.

Mon Mar 30 20:27:38 1998  Morten Welinder  <terra@diku.dk>

	* [misc/debugstr.c] [include/debugstr.h]
	Moved _dumpstr from relay32/relay386.c.  Improved control
	character handling.

	* [msdos/int21.c]
	Implement 215E00 -- get machine name.

	* [windows/winpos.c]
	SetWindowPos32: Make an extra sync when mapping managed
	windows.  This makes sure the reconfigure event has been
	handled.  See Mshearts' what's-your-name window.

Mon Mar 30 01:13:50 1998  Alexander V. Lukyanov <lav@long.yar.ru>

	* [Makefile.in]
	Install includes from TOPSRCDIR.
1998-04-13 12:21:30 +00:00

487 lines
15 KiB
C

/*
* Copyright 1993 Robert J. Amstadt
* Copyright 1995 Alexandre Julliard
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "windows.h"
#include "winnt.h"
#include "global.h"
#include "heap.h"
#include "module.h"
#include "stackframe.h"
#include "task.h"
#include "debugstr.h"
#include "debug.h"
#if 0
/* Make make_debug think these were really used */
TRACE(relay, "test - dummy");
#endif
/***********************************************************************
* RELAY_Init
*/
BOOL32 RELAY_Init(void)
{
WORD codesel;
extern BOOL32 THUNK_Init(void);
/* Allocate the code selector for CallTo16 routines */
extern void CALLTO16_Start(), CALLTO16_End();
extern void CALLTO16_Ret_word(), CALLTO16_Ret_long();
extern void CALLTO16_Ret_eax();
extern DWORD CALLTO16_RetAddr_word;
extern DWORD CALLTO16_RetAddr_long;
extern DWORD CALLTO16_RetAddr_eax;
codesel = GLOBAL_CreateBlock( GMEM_FIXED, (void *)CALLTO16_Start,
(int)CALLTO16_End - (int)CALLTO16_Start,
0, TRUE, TRUE, FALSE, NULL );
if (!codesel) return FALSE;
/* Patch the return addresses for CallTo16 routines */
CALLTO16_RetAddr_word=MAKELONG( (int)CALLTO16_Ret_word-(int)CALLTO16_Start,
codesel );
CALLTO16_RetAddr_long=MAKELONG( (int)CALLTO16_Ret_long-(int)CALLTO16_Start,
codesel );
CALLTO16_RetAddr_eax =MAKELONG( (int)CALLTO16_Ret_eax -(int)CALLTO16_Start,
codesel );
/* Create built-in modules */
if (!BUILTIN_Init()) return FALSE;
/* Initialize thunking */
return THUNK_Init();
}
/***********************************************************************
* RELAY_DebugCallFrom16
*/
void RELAY_DebugCallFrom16( int func_type, char *args,
void *entry_point, CONTEXT *context )
{
STACK16FRAME *frame;
WORD ordinal;
char *args16;
int i;
if (!TRACE_ON(relay)) return;
frame = CURRENT_STACK16;
printf( "Call %s(", BUILTIN_GetEntryPoint16( frame->entry_cs,
frame->entry_ip,
&ordinal ));
VA_START16( args16 );
if (func_type & 4) /* cdecl */
{
while (*args)
{
switch(*args)
{
case 'w':
case 's':
printf( "0x%04x", *(WORD *)args16 );
args16 += 2;
break;
case 'l':
printf( "0x%08x", *(int *)args16 );
args16 += 4;
break;
case 't':
printf( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
if (HIWORD(*(SEGPTR *)args16))
debug_dumpstr( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 ));
args16 += 4;
break;
case 'p':
printf( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
args16 += 4;
break;
case 'T':
printf( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
if (HIWORD( *(SEGPTR *)args16 ))
debug_dumpstr( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 ));
args16 += 4;
break;
}
args++;
if (*args) printf( "," );
}
}
else /* not cdecl */
{
/* Start with the last arg */
for (i = 0; args[i]; i++)
{
switch(args[i])
{
case 'w':
case 's':
args16 += 2;
break;
case 'l':
case 'p':
case 't':
case 'T':
args16 += 4;
break;
}
}
while (*args)
{
switch(*args)
{
case 'w':
case 's':
args16 -= 2;
printf( "0x%04x", *(WORD *)args16 );
break;
case 'l':
args16 -= 4;
printf( "0x%08x", *(int *)args16 );
break;
case 't':
args16 -= 4;
printf( "0x%08x", *(int *)args16 );
if (HIWORD(*(SEGPTR *)args16))
debug_dumpstr( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 ));
break;
case 'p':
args16 -= 4;
printf( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
break;
case 'T':
args16 -= 4;
printf( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
if (HIWORD( *(SEGPTR *)args16 ))
debug_dumpstr( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 ));
break;
}
args++;
if (*args) printf( "," );
}
}
printf( ") ret=%04x:%04x ds=%04x\n", frame->cs, frame->ip, frame->ds );
VA_END16( args16 );
if (func_type & 2) /* register function */
printf( " AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
AX_reg(context), BX_reg(context), CX_reg(context),
DX_reg(context), SI_reg(context), DI_reg(context),
(WORD)ES_reg(context), EFL_reg(context) );
}
/***********************************************************************
* RELAY_DebugCallFrom16Ret
*/
void RELAY_DebugCallFrom16Ret( int func_type, int ret_val, CONTEXT *context)
{
STACK16FRAME *frame;
WORD ordinal;
if (!TRACE_ON(relay)) return;
frame = CURRENT_STACK16;
printf( "Ret %s() ", BUILTIN_GetEntryPoint16( frame->entry_cs,
frame->entry_ip,
&ordinal ));
switch(func_type)
{
case 0: /* long */
printf( "retval=0x%08x ret=%04x:%04x ds=%04x\n",
ret_val, frame->cs, frame->ip, frame->ds );
break;
case 1: /* word */
printf( "retval=0x%04x ret=%04x:%04x ds=%04x\n",
ret_val & 0xffff, frame->cs, frame->ip, frame->ds );
break;
case 2: /* regs */
printf( "retval=none ret=%04x:%04x ds=%04x\n",
(WORD)CS_reg(context), IP_reg(context), (WORD)DS_reg(context));
printf( " AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
AX_reg(context), BX_reg(context), CX_reg(context),
DX_reg(context), SI_reg(context), DI_reg(context),
(WORD)ES_reg(context), EFL_reg(context) );
break;
}
}
/***********************************************************************
* RELAY_Unimplemented16
*
* This function is called for unimplemented 16-bit entry points (declared
* as 'stub' in the spec file).
*/
void RELAY_Unimplemented16(void)
{
WORD ordinal;
STACK16FRAME *frame = CURRENT_STACK16;
fprintf(stderr,"No handler for Win16 routine %s (called from %04x:%04x)\n",
BUILTIN_GetEntryPoint16(frame->entry_cs,frame->entry_ip,&ordinal),
frame->cs, frame->ip );
TASK_KillCurrentTask(1);
}
/***********************************************************************
* RELAY_DebugCallTo16
*
* 'stack' points to the called function address on the 32-bit stack.
* Stack layout:
* ... ...
* (stack+8) arg2
* (stack+4) arg1
* (stack) func to call
*/
void RELAY_DebugCallTo16( int* stack, int nb_args )
{
THDB *thdb;
if (!TRACE_ON(relay)) return;
thdb = THREAD_Current();
if (nb_args == -1) /* Register function */
{
CONTEXT *context = (CONTEXT *)stack[0];
WORD *stack16 = (WORD *)THREAD_STACK16(thdb);
printf( "CallTo16(func=%04lx:%04x,ds=%04lx",
CS_reg(context), IP_reg(context), DS_reg(context) );
nb_args = stack[1] / sizeof(WORD);
while (nb_args--) printf( ",0x%04x", *(--stack16) );
printf( ") ss:sp=%04x:%04x\n", SELECTOROF(thdb->cur_stack),
OFFSETOF(thdb->cur_stack) );
printf( " AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x BP=%04x ES=%04x\n",
AX_reg(context), BX_reg(context), CX_reg(context),
DX_reg(context), SI_reg(context), DI_reg(context),
BP_reg(context), (WORD)ES_reg(context) );
}
else
{
printf( "CallTo16(func=%04x:%04x,ds=%04x",
HIWORD(stack[0]), LOWORD(stack[0]),
SELECTOROF(thdb->cur_stack) );
stack++;
while (nb_args--) printf( ",0x%04x", *stack++ );
printf( ") ss:sp=%04x:%04x\n", SELECTOROF(thdb->cur_stack),
OFFSETOF(thdb->cur_stack) );
}
}
/**********************************************************************
* Catch (KERNEL.55)
*
* Real prototype is:
* INT16 WINAPI Catch( LPCATCHBUF lpbuf );
*/
void WINAPI Catch( CONTEXT *context )
{
VA_LIST16 valist;
SEGPTR buf;
LPCATCHBUF lpbuf;
VA_START16( valist );
buf = VA_ARG16( valist, SEGPTR );
lpbuf = (LPCATCHBUF)PTR_SEG_TO_LIN( buf );
VA_END16( valist );
/* Note: we don't save the current ss, as the catch buffer is */
/* only 9 words long. Hopefully no one will have the silly */
/* idea to change the current stack before calling Throw()... */
/* Windows uses:
* lpbuf[0] = ip
* lpbuf[1] = cs
* lpbuf[2] = sp
* lpbuf[3] = bp
* lpbuf[4] = si
* lpbuf[5] = di
* lpbuf[6] = ds
* lpbuf[7] = unused
* lpbuf[8] = ss
*/
lpbuf[0] = IP_reg(context);
lpbuf[1] = CS_reg(context);
/* Windows pushes 4 more words before saving sp */
lpbuf[2] = SP_reg(context) - 4 * sizeof(WORD);
lpbuf[3] = BP_reg(context);
lpbuf[4] = SI_reg(context);
lpbuf[5] = DI_reg(context);
lpbuf[6] = DS_reg(context);
lpbuf[7] = 0;
lpbuf[8] = SS_reg(context);
AX_reg(context) = 0; /* Return 0 */
}
/**********************************************************************
* Throw (KERNEL.56)
*
* Real prototype is:
* INT16 WINAPI Throw( LPCATCHBUF lpbuf, INT16 retval );
*/
void WINAPI Throw( CONTEXT *context )
{
VA_LIST16 valist;
SEGPTR buf;
LPCATCHBUF lpbuf;
STACK16FRAME *pFrame;
STACK32FRAME *frame32;
THDB *thdb = THREAD_Current();
VA_START16( valist );
AX_reg(context) = VA_ARG16( valist, WORD ); /* retval */
buf = VA_ARG16( valist, SEGPTR );
lpbuf = (LPCATCHBUF)PTR_SEG_TO_LIN( buf );
VA_END16( valist );
/* Find the frame32 corresponding to the frame16 we are jumping to */
pFrame = THREAD_STACK16( thdb );
frame32 = THREAD_STACK16( thdb )->frame32;
while (frame32 && frame32->frame16)
{
if (OFFSETOF(frame32->frame16) < OFFSETOF(thdb->cur_stack))
break; /* Something strange is going on */
if (OFFSETOF(frame32->frame16) > lpbuf[2])
{
/* We found the right frame */
pFrame->frame32 = frame32;
break;
}
frame32 = ((STACK16FRAME *)PTR_SEG_TO_LIN(frame32->frame16))->frame32;
}
IP_reg(context) = lpbuf[0];
CS_reg(context) = lpbuf[1];
SP_reg(context) = lpbuf[2] + 4 * sizeof(WORD) + sizeof(WORD) /*extra arg*/;
BP_reg(context) = lpbuf[3];
SI_reg(context) = lpbuf[4];
DI_reg(context) = lpbuf[5];
DS_reg(context) = lpbuf[6];
if (lpbuf[8] != SS_reg(context))
fprintf( stderr, "Switching stack segment with Throw() not supported; expect crash now\n" );
if (TRACE_ON(relay)) /* Make sure we have a valid entry point address */
{
static FARPROC16 entryPoint = NULL;
if (!entryPoint) /* Get entry point for Throw() */
entryPoint = MODULE_GetEntryPoint( GetModuleHandle16("KERNEL"),
56 );
pFrame->entry_cs = SELECTOROF(entryPoint);
pFrame->entry_ip = OFFSETOF(entryPoint);
}
}
/**********************************************************************
* RELAY_CallProc32W
*
* Helper for CallProc[Ex]32W
*/
static DWORD RELAY_CallProc32W(int Ex)
{
DWORD nrofargs, argconvmask;
FARPROC32 proc32;
DWORD *args, ret;
VA_LIST16 valist;
int i;
dbg_decl_str(relay, 1024);
VA_START16( valist );
nrofargs = VA_ARG16( valist, DWORD );
argconvmask = VA_ARG16( valist, DWORD );
proc32 = VA_ARG16( valist, FARPROC32 );
dsprintf(relay, "CallProc32W(%ld,%ld,%p, Ex%d args[",nrofargs,argconvmask,proc32,Ex);
args = (DWORD*)HEAP_xalloc( GetProcessHeap(), 0,
sizeof(DWORD)*nrofargs );
for (i=0;i<nrofargs;i++) {
if (argconvmask & (1<<i))
{
SEGPTR ptr = VA_ARG16( valist, SEGPTR );
args[nrofargs-i-1] = (DWORD)PTR_SEG_TO_LIN(ptr);
dsprintf(relay,"%08lx(%p),",ptr,PTR_SEG_TO_LIN(ptr));
}
else
{
args[nrofargs-i-1] = VA_ARG16( valist, DWORD );
dsprintf(relay,"%ld,",args[nrofargs-i-1]);
}
}
dsprintf(relay,"])");
VA_END16( valist );
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;
default:
/* FIXME: should go up to 32 arguments */
fprintf(stderr,"CallProc32W: unsupported number of arguments %ld, please report.\n",nrofargs);
ret = 0;
break;
}
/* POP nrofargs DWORD arguments and 3 DWORD parameters */
if (!Ex) STACK16_POP( THREAD_Current(),
(3 + nrofargs) * sizeof(DWORD) );
TRACE(relay,"%s - returns %08lx\n",dbg_str(relay),ret);
HeapFree( GetProcessHeap(), 0, args );
return ret;
}
/**********************************************************************
* CallProc32W (KERNEL.517)
*/
DWORD WINAPI WIN16_CallProc32W()
{
return RELAY_CallProc32W(0);
}
/**********************************************************************
* CallProcEx32W() (KERNEL.518)
*
* C - style linkage to CallProc32W - caller pops stack.
*/
DWORD WINAPI WIN16_CallProcEx32W()
{
return RELAY_CallProc32W(TRUE);
}