Made stack manipulation macros into inline functions.

Changed a few accesses to context registers to avoid potential
aliasing optimization problems.
This commit is contained in:
Alexandre Julliard 1999-08-01 12:51:55 +00:00
parent b375678277
commit a1089c59b9
8 changed files with 87 additions and 84 deletions

View File

@ -224,7 +224,7 @@ void RELAY_DebugCallFrom16Ret( CONTEXT86 *context, int ret_val )
|| memcmp( args+2, "intr_", 5 ) == 0 ) || memcmp( args+2, "intr_", 5 ) == 0 )
{ {
DPRINTF("retval=none ret=%04x:%04x ds=%04x\n", DPRINTF("retval=none ret=%04x:%04x ds=%04x\n",
(WORD)CS_reg(context), IP_reg(context), (WORD)DS_reg(context)); (WORD)CS_reg(context), LOWORD(EIP_reg(context)), (WORD)DS_reg(context));
DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n", DPRINTF(" 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), AX_reg(context), BX_reg(context), CX_reg(context),
DX_reg(context), SI_reg(context), DI_reg(context), DX_reg(context), SI_reg(context), DI_reg(context),
@ -275,7 +275,7 @@ void RELAY_DebugCallTo16( int* stack, int nb_args )
CONTEXT86 *context = (CONTEXT86 *)stack[0]; CONTEXT86 *context = (CONTEXT86 *)stack[0];
WORD *stack16 = (WORD *)THREAD_STACK16(teb); WORD *stack16 = (WORD *)THREAD_STACK16(teb);
DPRINTF("CallTo16(func=%04lx:%04x,ds=%04lx", DPRINTF("CallTo16(func=%04lx:%04x,ds=%04lx",
CS_reg(context), IP_reg(context), DS_reg(context) ); CS_reg(context), LOWORD(EIP_reg(context)), DS_reg(context) );
nb_args = stack[1] / sizeof(WORD); nb_args = stack[1] / sizeof(WORD);
while (nb_args--) { while (nb_args--) {
--stack16; --stack16;
@ -344,13 +344,13 @@ void WINAPI Catch16( LPCATCHBUF lpbuf, CONTEXT86 *context )
* lpbuf[8] = ss * lpbuf[8] = ss
*/ */
lpbuf[0] = IP_reg(context); lpbuf[0] = LOWORD(EIP_reg(context));
lpbuf[1] = CS_reg(context); lpbuf[1] = CS_reg(context);
/* Windows pushes 4 more words before saving sp */ /* Windows pushes 4 more words before saving sp */
lpbuf[2] = SP_reg(context) - 4 * sizeof(WORD); lpbuf[2] = LOWORD(ESP_reg(context)) - 4 * sizeof(WORD);
lpbuf[3] = BP_reg(context); lpbuf[3] = LOWORD(EBP_reg(context));
lpbuf[4] = SI_reg(context); lpbuf[4] = LOWORD(ESI_reg(context));
lpbuf[5] = DI_reg(context); lpbuf[5] = LOWORD(EDI_reg(context));
lpbuf[6] = DS_reg(context); lpbuf[6] = DS_reg(context);
lpbuf[7] = 0; lpbuf[7] = 0;
lpbuf[8] = SS_reg(context); lpbuf[8] = SS_reg(context);
@ -388,13 +388,13 @@ void WINAPI Throw16( LPCATCHBUF lpbuf, INT16 retval, CONTEXT86 *context )
frame32 = ((STACK16FRAME *)PTR_SEG_TO_LIN(frame32->frame16))->frame32; frame32 = ((STACK16FRAME *)PTR_SEG_TO_LIN(frame32->frame16))->frame32;
} }
IP_reg(context) = lpbuf[0]; EIP_reg(context) = lpbuf[0];
CS_reg(context) = lpbuf[1]; CS_reg(context) = lpbuf[1];
SP_reg(context) = lpbuf[2] + 4 * sizeof(WORD) - sizeof(WORD) /*extra arg*/; ESP_reg(context) = lpbuf[2] + 4 * sizeof(WORD) - sizeof(WORD) /*extra arg*/;
BP_reg(context) = lpbuf[3]; EBP_reg(context) = lpbuf[3];
SI_reg(context) = lpbuf[4]; ESI_reg(context) = lpbuf[4];
DI_reg(context) = lpbuf[5]; EDI_reg(context) = lpbuf[5];
DS_reg(context) = lpbuf[6]; DS_reg(context) = lpbuf[6];
if (lpbuf[8] != SS_reg(context)) if (lpbuf[8] != SS_reg(context))
ERR("Switching stack segment with Throw() not supported; expect crash now\n" ); ERR("Switching stack segment with Throw() not supported; expect crash now\n" );
@ -491,7 +491,7 @@ static DWORD RELAY_CallProc32W(int Ex)
break; break;
} }
/* POP nrofargs DWORD arguments and 3 DWORD parameters */ /* POP nrofargs DWORD arguments and 3 DWORD parameters */
if (!Ex) STACK16_POP( NtCurrentTeb(), (3 + nrofargs) * sizeof(DWORD) ); if (!Ex) stack16_pop( (3 + nrofargs) * sizeof(DWORD) );
TRACE("%s - returns %08lx\n",dbg_str(relay),ret); TRACE("%s - returns %08lx\n",dbg_str(relay),ret);
HeapFree( GetProcessHeap(), 0, args ); HeapFree( GetProcessHeap(), 0, args );

View File

@ -293,7 +293,7 @@ static LRESULT WINAPI THUNK_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
if (offset) if (offset)
{ {
void *s = PTR_SEG_TO_LIN(lParam); void *s = PTR_SEG_TO_LIN(lParam);
lParam = STACK16_PUSH( teb, offset ); lParam = stack16_push( offset );
memcpy( PTR_SEG_TO_LIN(lParam), s, offset ); memcpy( PTR_SEG_TO_LIN(lParam), s, offset );
} }
} }
@ -308,7 +308,7 @@ static LRESULT WINAPI THUNK_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
args[4] = hwnd; args[4] = hwnd;
ret = CallTo16RegisterShort( &context, 5 * sizeof(WORD) ); ret = CallTo16RegisterShort( &context, 5 * sizeof(WORD) );
if (offset) STACK16_POP( teb, offset ); if (offset) stack16_pop( offset );
WIN_RestoreWndsLock(iWndsLocks); WIN_RestoreWndsLock(iWndsLocks);
@ -820,10 +820,10 @@ static void THUNK_CallSystemTimerProc( FARPROC16 proc, WORD timer )
CONTEXT86 context; CONTEXT86 context;
memset( &context, '\0', sizeof(context) ); memset( &context, '\0', sizeof(context) );
CS_reg( &context ) = SELECTOROF( proc ); CS_reg( &context ) = SELECTOROF( proc );
IP_reg( &context ) = OFFSETOF( proc ); EIP_reg( &context ) = OFFSETOF( proc );
BP_reg( &context ) = OFFSETOF( NtCurrentTeb()->cur_stack ) EBP_reg( &context ) = OFFSETOF( NtCurrentTeb()->cur_stack )
+ (WORD)&((STACK16FRAME*)0)->bp; + (WORD)&((STACK16FRAME*)0)->bp;
AX_reg( &context ) = timer; AX_reg( &context ) = timer;
@ -1052,12 +1052,12 @@ void WINAPI C16ThkSL(CONTEXT86 *context)
*((WORD *)x)++ = cs; *((WORD *)x)++ = cs;
/* Jump to the stub code just created */ /* Jump to the stub code just created */
IP_reg(context) = LOWORD(EAX_reg(context)); EIP_reg(context) = LOWORD(EAX_reg(context));
CS_reg(context) = HIWORD(EAX_reg(context)); CS_reg(context) = HIWORD(EAX_reg(context));
/* Since C16ThkSL got called by a jmp, we need to leave the /* Since C16ThkSL got called by a jmp, we need to leave the
orginal return address on the stack */ original return address on the stack */
SP_reg(context) -= 4; ESP_reg(context) -= 4;
} }
/*********************************************************************** /***********************************************************************
@ -1107,12 +1107,12 @@ void WINAPI C16ThkSL01(CONTEXT86 *context)
*((WORD *)x)++ = cs; *((WORD *)x)++ = cs;
/* Jump to the stub code just created */ /* Jump to the stub code just created */
IP_reg(context) = LOWORD(EAX_reg(context)); EIP_reg(context) = LOWORD(EAX_reg(context));
CS_reg(context) = HIWORD(EAX_reg(context)); CS_reg(context) = HIWORD(EAX_reg(context));
/* Since C16ThkSL01 got called by a jmp, we need to leave the /* Since C16ThkSL01 got called by a jmp, we need to leave the
orginal return address on the stack */ orginal return address on the stack */
SP_reg(context) -= 4; ESP_reg(context) -= 4;
} }
else else
{ {
@ -1145,12 +1145,12 @@ void WINAPI C16ThkSL01(CONTEXT86 *context)
} }
else else
{ {
WORD *stack = PTR_SEG_OFF_TO_LIN(SS_reg(context), SP_reg(context)); WORD *stack = PTR_SEG_OFF_TO_LIN(SS_reg(context), LOWORD(ESP_reg(context)));
DX_reg(context) = HIWORD(td->apiDB[targetNr].errorReturnValue); DX_reg(context) = HIWORD(td->apiDB[targetNr].errorReturnValue);
AX_reg(context) = LOWORD(td->apiDB[targetNr].errorReturnValue); AX_reg(context) = LOWORD(td->apiDB[targetNr].errorReturnValue);
IP_reg(context) = stack[2]; EIP_reg(context) = stack[2];
CS_reg(context) = stack[3]; CS_reg(context) = stack[3];
SP_reg(context) += td->apiDB[targetNr].nrArgBytes + 4; ESP_reg(context) += td->apiDB[targetNr].nrArgBytes + 4;
ERR_(thunk)("Process %08lx did not ThunkConnect32 %s to %s\n", ERR_(thunk)("Process %08lx did not ThunkConnect32 %s to %s\n",
(DWORD)PROCESS_Current(), td->pszDll32, td->pszDll16); (DWORD)PROCESS_Current(), td->pszDll32, td->pszDll16);
@ -1162,13 +1162,17 @@ DWORD WINAPI
WOW16Call(WORD x,WORD y,WORD z) { WOW16Call(WORD x,WORD y,WORD z) {
int i; int i;
DWORD calladdr; DWORD calladdr;
VA_LIST16 args;
FIXME_(thunk)("(0x%04x,0x%04x,%d),calling (",x,y,z); FIXME_(thunk)("(0x%04x,0x%04x,%d),calling (",x,y,z);
VA_START16(args);
for (i=0;i<x/2;i++) { for (i=0;i<x/2;i++) {
WORD a = STACK16_POP(NtCurrentTeb(),2); WORD a = VA_ARG16(args,WORD);
DPRINTF("%04x ",a); DPRINTF("%04x ",a);
} }
calladdr = STACK16_POP(NtCurrentTeb(),4); calladdr = VA_ARG16(args,DWORD);
VA_END16(args);
stack16_pop( x + sizeof(DWORD) );
DPRINTF(") calling address was 0x%08lx\n",calladdr); DPRINTF(") calling address was 0x%08lx\n",calladdr);
return 0; return 0;
} }
@ -1536,7 +1540,7 @@ void WINAPI InitCBClient16( FARPROC glueLS )
void WINAPI CBClientGlueSL( CONTEXT86 *context ) void WINAPI CBClientGlueSL( CONTEXT86 *context )
{ {
/* Create stack frame */ /* Create stack frame */
SEGPTR stackSeg = STACK16_PUSH( NtCurrentTeb(), 12 ); SEGPTR stackSeg = stack16_push( 12 );
LPWORD stackLin = PTR_SEG_TO_LIN( stackSeg ); LPWORD stackLin = PTR_SEG_TO_LIN( stackSeg );
SEGPTR glue; SEGPTR glue;
@ -1545,8 +1549,8 @@ void WINAPI CBClientGlueSL( CONTEXT86 *context )
stackLin[1] = DI_reg( context ); stackLin[1] = DI_reg( context );
stackLin[0] = DS_reg( context ); stackLin[0] = DS_reg( context );
BP_reg( context ) = OFFSETOF( stackSeg ) + 6; EBP_reg( context ) = OFFSETOF( stackSeg ) + 6;
SP_reg( context ) = OFFSETOF( stackSeg ) - 4; ESP_reg( context ) = OFFSETOF( stackSeg ) - 4;
GS_reg( context ) = 0; GS_reg( context ) = 0;
/* Jump to 16-bit relay code */ /* Jump to 16-bit relay code */
@ -1591,7 +1595,7 @@ void WINAPI CBClientThunkSLEx( CONTEXT86 *context )
SI_reg( context ) = stackLin[2]; SI_reg( context ) = stackLin[2];
DI_reg( context ) = stackLin[1]; DI_reg( context ) = stackLin[1];
DS_reg( context ) = stackLin[0]; DS_reg( context ) = stackLin[0];
SP_reg( context ) += 16+nArgs; ESP_reg( context ) += 16+nArgs;
/* Return to caller of CBClient thunklet */ /* Return to caller of CBClient thunklet */
CS_reg ( context ) = stackLin[9]; CS_reg ( context ) = stackLin[9];

View File

@ -236,30 +236,6 @@ typedef struct _CONTEXT /* Note 1 */
#endif /* __EMX__ */ #endif /* __EMX__ */
/* Generic definitions */
#define AX_sig(context) (*(WORD*)&EAX_sig(context))
#define BX_sig(context) (*(WORD*)&EBX_sig(context))
#define CX_sig(context) (*(WORD*)&ECX_sig(context))
#define DX_sig(context) (*(WORD*)&EDX_sig(context))
#define SI_sig(context) (*(WORD*)&ESI_sig(context))
#define DI_sig(context) (*(WORD*)&EDI_sig(context))
#define BP_sig(context) (*(WORD*)&EBP_sig(context))
#define AL_sig(context) (*(BYTE*)&EAX_sig(context))
#define AH_sig(context) (*((BYTE*)&EAX_sig(context)+1))
#define BL_sig(context) (*(BYTE*)&EBX_sig(context))
#define BH_sig(context) (*((BYTE*)&EBX_sig(context)+1))
#define CL_sig(context) (*(BYTE*)&ECX_sig(context))
#define CH_sig(context) (*((BYTE*)&ECX_sig(context)+1))
#define DL_sig(context) (*(BYTE*)&EDX_sig(context))
#define DH_sig(context) (*((BYTE*)&EDX_sig(context)+1))
#define IP_sig(context) (*(WORD*)&EIP_sig(context))
#define SP_sig(context) (*(WORD*)&ESP_sig(context))
#define FL_sig(context) (*(WORD*)&EFL_sig(context))
#ifdef FS_sig #ifdef FS_sig
#include "syslevel.h" #include "syslevel.h"
#define HANDLER_INIT() \ #define HANDLER_INIT() \

View File

@ -7,6 +7,7 @@
#ifndef __WINE_STACKFRAME_H #ifndef __WINE_STACKFRAME_H
#define __WINE_STACKFRAME_H #define __WINE_STACKFRAME_H
#include <string.h>
#include "ldt.h" #include "ldt.h"
#include "thread.h" #include "thread.h"
@ -67,26 +68,44 @@ typedef void *VA_LIST16;
*((type *)(void *)((char *)(list) - __VA_ROUNDED16(type)))) *((type *)(void *)((char *)(list) - __VA_ROUNDED16(type))))
#define VA_END16(list) ((void)0) #define VA_END16(list) ((void)0)
/* Push bytes on the 16-bit stack of a thread; /* Push bytes on the 16-bit stack of a thread;
* return a segptr to the first pushed byte * return a segptr to the first pushed byte
*/ */
#define STACK16_PUSH(teb,size) \ static inline SEGPTR WINE_UNUSED stack16_push( int size )
(memmove((char*)THREAD_STACK16(teb)-(size),THREAD_STACK16(teb), \ {
sizeof(STACK16FRAME)), \ TEB *teb = NtCurrentTeb();
(teb)->cur_stack -= (size), \ STACK16FRAME *frame = THREAD_STACK16(teb);
(SEGPTR)((teb)->cur_stack + sizeof(STACK16FRAME))) memmove( (char*)frame - size, frame, sizeof(*frame) );
teb->cur_stack -= size;
return (SEGPTR)(teb->cur_stack + sizeof(*frame));
}
/* Pop bytes from the 16-bit stack of a thread */ /* Pop bytes from the 16-bit stack of a thread */
#define STACK16_POP(teb,size) \ static inline void WINE_UNUSED stack16_pop( int size )
(memmove((char*)THREAD_STACK16(teb)+(size),THREAD_STACK16(teb), \ {
sizeof(STACK16FRAME)), \ TEB *teb = NtCurrentTeb();
(teb)->cur_stack += (size)) STACK16FRAME *frame = THREAD_STACK16(teb);
memmove( (char*)frame + size, frame, sizeof(*frame) );
teb->cur_stack += size;
}
#ifdef __i386__
/* Push a DWORD on the 32-bit stack */ /* Push a DWORD on the 32-bit stack */
#define STACK32_PUSH(context,val) (*--(*(DWORD **)&ESP_reg(context)) = (val)) static inline void WINE_UNUSED stack32_push( CONTEXT *context, DWORD val )
{
ESP_reg(context) -= sizeof(DWORD);
*(DWORD *)ESP_reg(context) = val;
}
/* Pop a DWORD from the 32-bit stack */ /* Pop a DWORD from the 32-bit stack */
#define STACK32_POP(context) (*(*(DWORD **)&ESP_reg(context))++) static inline DWORD WINE_UNUSED stack32_pop( CONTEXT *context )
{
DWORD ret = *(DWORD *)ESP_reg(context);
ESP_reg(context) += sizeof(DWORD);
return ret;
}
#endif /* __i386__ */
/* Win32 register functions */ /* Win32 register functions */
#define REGS_FUNC(name) __regs_##name #define REGS_FUNC(name) __regs_##name

View File

@ -255,8 +255,8 @@ void TASK_CallToStart(void)
EDI_reg(&context) = pTask->hInstance; EDI_reg(&context) = pTask->hInstance;
ESI_reg(&context) = pTask->hPrevInstance; ESI_reg(&context) = pTask->hPrevInstance;
TRACE_(task)("Starting main program: cs:ip=%04lx:%04x ds=%04lx ss:sp=%04x:%04x\n", TRACE_(task)("Starting main program: cs:ip=%04lx:%04lx ds=%04lx ss:sp=%04x:%04x\n",
CS_reg(&context), IP_reg(&context), DS_reg(&context), CS_reg(&context), EIP_reg(&context), DS_reg(&context),
SELECTOROF(pTask->teb->cur_stack), SELECTOROF(pTask->teb->cur_stack),
OFFSETOF(pTask->teb->cur_stack) ); OFFSETOF(pTask->teb->cur_stack) );
@ -736,9 +736,9 @@ void WINAPI InitTask16( CONTEXT86 *context )
* *
* 0 (=%bp) is pushed on the stack * 0 (=%bp) is pushed on the stack
*/ */
ptr = STACK16_PUSH( pTask->teb, sizeof(WORD) ); ptr = stack16_push( sizeof(WORD) );
*(WORD *)PTR_SEG_TO_LIN(ptr) = 0; *(WORD *)PTR_SEG_TO_LIN(ptr) = 0;
SP_reg(context) -= 2; ESP_reg(context) -= 2;
EAX_reg(context) = 1; EAX_reg(context) = 1;

View File

@ -644,6 +644,7 @@ static void StartPM( CONTEXT86 *context, LPDOSTASK lpDosTask )
/* DPMI Raw Mode Switch handler */ /* DPMI Raw Mode Switch handler */
#if 0
void WINAPI DPMI_RawModeSwitch( SIGCONTEXT *context ) void WINAPI DPMI_RawModeSwitch( SIGCONTEXT *context )
{ {
LPDOSTASK lpDosTask = MZ_Current(); LPDOSTASK lpDosTask = MZ_Current();
@ -696,14 +697,17 @@ void WINAPI DPMI_RawModeSwitch( SIGCONTEXT *context )
TRACE("re-entering protected mode at %04x:%08lx\n", TRACE("re-entering protected mode at %04x:%08lx\n",
CS_sig(context), EIP_sig(context)); CS_sig(context), EIP_sig(context));
} }
#endif
#else #else
#if 0
void WINAPI DPMI_RawModeSwitch( SIGCONTEXT *context ) void WINAPI DPMI_RawModeSwitch( SIGCONTEXT *context )
{ {
ERR("don't even think about DPMI raw mode switch without DOS support!\n"); ERR("don't even think about DPMI raw mode switch without DOS support!\n");
ExitProcess(1); ExitProcess(1);
} }
#endif #endif
#endif
#define DOS_APP_ISDOS(addr,base) ((addr) < 0x110000) #define DOS_APP_ISDOS(addr,base) ((addr) < 0x110000)
#define DOS_WINE_ISDOS(addr,base) (((addr) >= (base)) && ((addr) < (base) + 0x110000)) #define DOS_WINE_ISDOS(addr,base) (((addr) >= (base)) && ((addr) < (base) + 0x110000))

View File

@ -235,7 +235,7 @@ void WINAPI REGS_FUNC(RELAY_CallFrom32Regs)( CONTEXT *context )
WORD nb_args = *(WORD *)(relay_addr + 1) / sizeof(int); WORD nb_args = *(WORD *)(relay_addr + 1) / sizeof(int);
/* remove extra stuff from the stack */ /* remove extra stuff from the stack */
EIP_reg(context) = STACK32_POP(context); EIP_reg(context) = stack32_pop(context);
args = (int *)ESP_reg(context); args = (int *)ESP_reg(context);
ESP_reg(context) += 4 * nb_args; ESP_reg(context) += 4 * nb_args;

View File

@ -363,7 +363,7 @@ void WINAPI REGS_FUNC(FT_Prolog)( CONTEXT *context )
{ {
#ifdef __i386__ #ifdef __i386__
/* Build stack frame */ /* Build stack frame */
STACK32_PUSH(context, EBP_reg(context)); stack32_push(context, EBP_reg(context));
EBP_reg(context) = ESP_reg(context); EBP_reg(context) = ESP_reg(context);
/* Allocate 64-byte Thunk Buffer */ /* Allocate 64-byte Thunk Buffer */
@ -469,10 +469,10 @@ static void FT_Exit(CONTEXT *context, int nPopArgs)
/* Clean up stack frame */ /* Clean up stack frame */
ESP_reg(context) = EBP_reg(context); ESP_reg(context) = EBP_reg(context);
EBP_reg(context) = STACK32_POP(context); EBP_reg(context) = stack32_pop(context);
/* Pop return address to CALLER of thunk code */ /* Pop return address to CALLER of thunk code */
EIP_reg(context) = STACK32_POP(context); EIP_reg(context) = stack32_pop(context);
/* Remove arguments */ /* Remove arguments */
ESP_reg(context) += nPopArgs; ESP_reg(context) += nPopArgs;
#endif #endif
@ -774,8 +774,8 @@ void WINAPI REGS_FUNC(FT_PrologPrime)( CONTEXT *context )
ESP_reg(context) -= 4; ESP_reg(context) -= 4;
/* Write FT_Prolog call stub */ /* Write FT_Prolog call stub */
targetTableOffset = STACK32_POP(context); targetTableOffset = stack32_pop(context);
relayCode = (LPBYTE)STACK32_POP(context); relayCode = (LPBYTE)stack32_pop(context);
_write_ftprolog( relayCode, *(DWORD **)(relayCode+targetTableOffset) ); _write_ftprolog( relayCode, *(DWORD **)(relayCode+targetTableOffset) );
/* Jump to the call stub just created */ /* Jump to the call stub just created */
@ -946,7 +946,7 @@ void WINAPI REGS_FUNC(W32S_BackTo32)( CONTEXT *context )
EAX_reg( context ) = proc( stack[1], stack[2], stack[3], stack[4], stack[5], EAX_reg( context ) = proc( stack[1], stack[2], stack[3], stack[4], stack[5],
stack[6], stack[7], stack[8], stack[9], stack[10] ); stack[6], stack[7], stack[8], stack[9], stack[10] );
EIP_reg( context ) = STACK32_POP(context); EIP_reg( context ) = stack32_pop(context);
#endif #endif
} }