From f87262ea9935f5bc62d1f2f9c0146c7723ef7b59 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 26 Nov 2020 12:49:41 +0100 Subject: [PATCH] include: Add CURRENT_SS/SP macros for 16-bit code. Signed-off-by: Alexandre Julliard --- dlls/commdlg.dll16/filedlg.c | 4 +-- dlls/krnl386.exe16/kernel.c | 7 ++--- dlls/krnl386.exe16/kernel16_private.h | 9 +++--- dlls/krnl386.exe16/ne_module.c | 8 ++--- dlls/krnl386.exe16/ne_segment.c | 24 +++++++-------- dlls/krnl386.exe16/task.c | 37 ++++++++++++----------- dlls/krnl386.exe16/thunk.c | 42 ++++++++++++--------------- dlls/krnl386.exe16/wowthunk.c | 15 ++++------ dlls/system.drv16/system.c | 2 +- dlls/user.exe16/message.c | 6 ++-- include/wine/winbase16.h | 2 ++ 11 files changed, 73 insertions(+), 83 deletions(-) diff --git a/dlls/commdlg.dll16/filedlg.c b/dlls/commdlg.dll16/filedlg.c index 050cddb0dd5..4fa62c15d6c 100644 --- a/dlls/commdlg.dll16/filedlg.c +++ b/dlls/commdlg.dll16/filedlg.c @@ -221,10 +221,10 @@ static LRESULT call_hook16( WNDPROC16 hook, HWND hwnd, UINT msg, WPARAM wp, LPAR TRACE( "%p: %p %08x %lx %lx: stub\n", hook, hwnd, msg, wp, lp ); memset( &context, 0, sizeof(context) ); - context.SegDs = context.SegEs = SELECTOROF( NtCurrentTeb()->WOW32Reserved ); + context.SegDs = context.SegEs = CURRENT_SS; context.SegCs = SELECTOROF( hook ); context.Eip = OFFSETOF( hook ); - context.Ebp = OFFSETOF( NtCurrentTeb()->WOW32Reserved ) + FIELD_OFFSET( STACK16FRAME, bp ); + context.Ebp = CURRENT_SP + FIELD_OFFSET( STACK16FRAME, bp ); context.Eax = context.SegDs; params[4] = HWND_16( hwnd ); diff --git a/dlls/krnl386.exe16/kernel.c b/dlls/krnl386.exe16/kernel.c index 07a57d0d937..374fcb654d4 100644 --- a/dlls/krnl386.exe16/kernel.c +++ b/dlls/krnl386.exe16/kernel.c @@ -46,9 +46,8 @@ static void thread_attach(void) { /* allocate the 16-bit stack (FIXME: should be done lazily) */ HGLOBAL16 hstack = WOWGlobalAlloc16( GMEM_FIXED, 0x10000 ); - kernel_get_thread_data()->stack_sel = GlobalHandleToSel16( hstack ); - NtCurrentTeb()->WOW32Reserved = (void *)MAKESEGPTR( kernel_get_thread_data()->stack_sel, - 0x10000 - sizeof(STACK16FRAME) ); + CURRENT_SS = kernel_get_thread_data()->stack_sel = GlobalHandleToSel16( hstack ); + CURRENT_SP = 0x10000 - sizeof(STACK16FRAME); memset( (char *)GlobalLock16(hstack) + 0x10000 - sizeof(STACK16FRAME), 0, sizeof(STACK16FRAME) ); } @@ -60,7 +59,7 @@ static void thread_detach(void) { /* free the 16-bit stack */ WOWGlobalFree16( kernel_get_thread_data()->stack_sel ); - NtCurrentTeb()->WOW32Reserved = 0; + CURRENT_SS = CURRENT_SP = 0; if (NtCurrentTeb()->Tib.SubSystemTib) TASK_ExitTask(); } diff --git a/dlls/krnl386.exe16/kernel16_private.h b/dlls/krnl386.exe16/kernel16_private.h index 1e3935aa48a..8c93b1dc0a2 100644 --- a/dlls/krnl386.exe16/kernel16_private.h +++ b/dlls/krnl386.exe16/kernel16_private.h @@ -101,7 +101,8 @@ typedef struct typedef struct { WORD null; /* Always 0 */ - DWORD old_ss_sp; /* Stack pointer; used by SwitchTaskTo() */ + WORD old_sp; /* Stack pointer; used by SwitchTaskTo() */ + WORD old_ss; WORD heap; /* Pointer to the local heap information (if any) */ WORD atomtable; /* Pointer to the local atom table (if any) */ WORD stacktop; /* Top of the stack */ @@ -174,8 +175,8 @@ static inline SEGPTR stack16_push( int size ) { STACK16FRAME *frame = CURRENT_STACK16; memmove( (char*)frame - size, frame, sizeof(*frame) ); - NtCurrentTeb()->WOW32Reserved = (char *)NtCurrentTeb()->WOW32Reserved - size; - return (SEGPTR)((char *)NtCurrentTeb()->WOW32Reserved + sizeof(*frame)); + CURRENT_SP -= size; + return MAKESEGPTR( CURRENT_SS, CURRENT_SP + sizeof(*frame) ); } /* pop bytes from the 16-bit stack of a thread */ @@ -183,7 +184,7 @@ static inline void stack16_pop( int size ) { STACK16FRAME *frame = CURRENT_STACK16; memmove( (char*)frame + size, frame, sizeof(*frame) ); - NtCurrentTeb()->WOW32Reserved = (char *)NtCurrentTeb()->WOW32Reserved + size; + CURRENT_SP += size; } /* dosmem.c */ diff --git a/dlls/krnl386.exe16/ne_module.c b/dlls/krnl386.exe16/ne_module.c index f1e1a14dd67..c26fe778253 100644 --- a/dlls/krnl386.exe16/ne_module.c +++ b/dlls/krnl386.exe16/ne_module.c @@ -1207,8 +1207,8 @@ DWORD NE_StartTask(void) if (!(sp = OFFSETOF(pModule->ne_sssp))) sp = pSegTable[SELECTOROF(pModule->ne_sssp)-1].minsize + pModule->ne_stack; sp &= ~1; - sp -= sizeof(STACK16FRAME); - NtCurrentTeb()->WOW32Reserved = (void *)MAKESEGPTR( GlobalHandleToSel16(hInstance), sp ); + CURRENT_SS = GlobalHandleToSel16(hInstance); + CURRENT_SP = sp - sizeof(STACK16FRAME); /* Registers at initialization must be: * ax zero @@ -1235,9 +1235,7 @@ DWORD NE_StartTask(void) /* Now call 16-bit entry point */ TRACE("Starting main program: cs:ip=%04x:%04x ds=%04x ss:sp=%04x:%04x\n", - context.SegCs, context.Eip, context.SegDs, - SELECTOROF(NtCurrentTeb()->WOW32Reserved), - OFFSETOF(NtCurrentTeb()->WOW32Reserved) ); + context.SegCs, context.Eip, context.SegDs, CURRENT_SS, CURRENT_SP); WOWCallback16Ex( 0, WCB16_REGS, 0, NULL, (DWORD *)&context ); ExitThread( LOWORD(context.Eax) ); diff --git a/dlls/krnl386.exe16/ne_segment.c b/dlls/krnl386.exe16/ne_segment.c index aa886148029..fd01dba540e 100644 --- a/dlls/krnl386.exe16/ne_segment.c +++ b/dlls/krnl386.exe16/ne_segment.c @@ -364,15 +364,14 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ) { /* Implement self-loading segments */ SELFLOADHEADER *selfloadheader; - void *oldstack; + WORD old_ss = CURRENT_SS, old_sp = CURRENT_SP; HFILE16 hFile16; WORD args[3]; DWORD ret; selfloadheader = MapSL( MAKESEGPTR(SEL(pSegTable->hSeg),0) ); - oldstack = NtCurrentTeb()->WOW32Reserved; - NtCurrentTeb()->WOW32Reserved = (void *)MAKESEGPTR(pModule->self_loading_sel, - 0xff00 - sizeof(STACK16FRAME)); + CURRENT_SS = pModule->self_loading_sel; + CURRENT_SP = 0xff00 - sizeof(STACK16FRAME); hFile16 = NE_OpenFile( pModule ); TRACE_(dll)("Call LoadAppSegProc(hmodule=0x%04x,hf=%x,segnum=%d)\n", @@ -384,7 +383,8 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ) pSeg->hSeg = LOWORD(ret); TRACE_(dll)("Ret LoadAppSegProc: hSeg=0x%04x\n", pSeg->hSeg); _lclose16( hFile16 ); - NtCurrentTeb()->WOW32Reserved = oldstack; + CURRENT_SS = old_ss; + CURRENT_SP = old_sp; pSeg->flags |= NE_SEGFLAGS_LOADED; return TRUE; @@ -462,7 +462,7 @@ BOOL NE_LoadAllSegments( NE_MODULE *pModule ) /* Handle self-loading modules */ SELFLOADHEADER *selfloadheader; HMODULE16 mod = GetModuleHandle16("KERNEL"); - void *oldstack; + WORD old_ss = CURRENT_SS, old_sp = CURRENT_SP; WORD args[2]; TRACE_(module)("%.*s is a self-loading module!\n", @@ -476,9 +476,8 @@ BOOL NE_LoadAllSegments( NE_MODULE *pModule ) sel = GlobalAlloc16( GMEM_ZEROINIT, 0xFF00 ); pModule->self_loading_sel = SEL(sel); FarSetOwner16( sel, pModule->self ); - oldstack = NtCurrentTeb()->WOW32Reserved; - NtCurrentTeb()->WOW32Reserved = (void *)MAKESEGPTR(pModule->self_loading_sel, - 0xff00 - sizeof(STACK16FRAME) ); + CURRENT_SS = pModule->self_loading_sel; + CURRENT_SP = 0xff00 - sizeof(STACK16FRAME); hFile16 = NE_OpenFile(pModule); TRACE_(dll)("CallBootAppProc(hModule=0x%04x,hf=0x%04x)\n", @@ -488,7 +487,8 @@ BOOL NE_LoadAllSegments( NE_MODULE *pModule ) WOWCallback16Ex( (DWORD)selfloadheader->BootApp, WCB16_PASCAL, sizeof(args), args, NULL ); TRACE_(dll)("Return from CallBootAppProc\n"); _lclose16(hFile16); - NtCurrentTeb()->WOW32Reserved = oldstack; + CURRENT_SS = old_ss; + CURRENT_SP = old_sp; for (i = 2; i <= pModule->ne_cseg; i++) if (!NE_LoadSegment( pModule, i )) return FALSE; @@ -680,7 +680,7 @@ static BOOL NE_InitDLL( NE_MODULE *pModule ) context.SegEs = ds; /* who knows ... */ context.SegCs = SEL(pSegTable[SELECTOROF(pModule->ne_csip)-1].hSeg); context.Eip = OFFSETOF(pModule->ne_csip); - context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME,bp); + context.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME,bp); pModule->ne_csip = 0; /* Don't initialize it twice */ TRACE_(dll)("Calling LibMain for %.*s, cs:ip=%04x:%04x ds=%04x di=%04x cx=%04x\n", @@ -782,7 +782,7 @@ static void NE_CallDllEntryPoint( NE_MODULE *pModule, DWORD dwReason ) context.SegEs = ds; /* who knows ... */ context.SegCs = HIWORD(entryPoint); context.Eip = LOWORD(entryPoint); - context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME,bp); + context.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME,bp); args[7] = HIWORD(dwReason); args[6] = LOWORD(dwReason); diff --git a/dlls/krnl386.exe16/task.c b/dlls/krnl386.exe16/task.c index 39a60cb97a9..892f4d19f07 100644 --- a/dlls/krnl386.exe16/task.c +++ b/dlls/krnl386.exe16/task.c @@ -624,7 +624,7 @@ void WINAPI InitTask16( CONTEXT *context ) /* Initialize the INSTANCEDATA structure */ pinstance = MapSL( MAKESEGPTR(CURRENT_DS, 0) ); - pinstance->stackmin = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + sizeof( STACK16FRAME ); + pinstance->stackmin = CURRENT_SP + sizeof( STACK16FRAME ); pinstance->stackbottom = pinstance->stackmin; /* yup, that's right. Confused me too. */ pinstance->stacktop = ( pinstance->stackmin > LOWORD(context->Ebx) ? pinstance->stackmin - LOWORD(context->Ebx) : 0 ) + 150; @@ -1094,17 +1094,15 @@ void WINAPI SwitchStackTo16( WORD seg, WORD ptr, WORD top ) UINT16 copySize; if (!(pData = GlobalLock16( seg ))) return; - TRACE("old=%04x:%04x new=%04x:%04x\n", - SELECTOROF( NtCurrentTeb()->WOW32Reserved ), - OFFSETOF( NtCurrentTeb()->WOW32Reserved ), seg, ptr ); + TRACE( "old=%04x:%04x new=%04x:%04x\n", CURRENT_SS, CURRENT_SP, seg, ptr ); /* Save the old stack */ oldFrame = CURRENT_STACK16; /* pop frame + args and push bp */ - pData->old_ss_sp = (SEGPTR)NtCurrentTeb()->WOW32Reserved + sizeof(STACK16FRAME) - + 2 * sizeof(WORD); - *(WORD *)MapSL(pData->old_ss_sp) = oldFrame->bp; + pData->old_ss = CURRENT_SS; + pData->old_sp = CURRENT_SP + sizeof(STACK16FRAME) + 2 * sizeof(WORD); + *(WORD *)MapSL(MAKESEGPTR(pData->old_ss, pData->old_sp)) = oldFrame->bp; pData->stacktop = top; pData->stackmin = ptr; pData->stackbottom = ptr; @@ -1114,9 +1112,10 @@ void WINAPI SwitchStackTo16( WORD seg, WORD ptr, WORD top ) /* Note: we need to take the 3 arguments into account; otherwise, * the stack will underflow upon return from this function. */ - copySize = oldFrame->bp - OFFSETOF(pData->old_ss_sp); + copySize = oldFrame->bp - pData->old_sp; copySize += 3 * sizeof(WORD) + sizeof(STACK16FRAME); - NtCurrentTeb()->WOW32Reserved = (void *)MAKESEGPTR( seg, ptr - copySize ); + CURRENT_SS = seg; + CURRENT_SP = ptr - copySize; newFrame = CURRENT_STACK16; /* Copy the stack frame and the local variables to the new stack */ @@ -1135,29 +1134,29 @@ void WINAPI SwitchStackBack16( CONTEXT *context ) STACK16FRAME *oldFrame, *newFrame; INSTANCEDATA *pData; - if (!(pData = GlobalLock16(SELECTOROF(NtCurrentTeb()->WOW32Reserved)))) + if (!(pData = GlobalLock16(CURRENT_SS))) return; - if (!pData->old_ss_sp) + if (!pData->old_ss) { WARN("No previous SwitchStackTo\n" ); return; } - TRACE("restoring stack %04x:%04x\n", - SELECTOROF(pData->old_ss_sp), OFFSETOF(pData->old_ss_sp) ); + TRACE( "restoring stack %04x:%04x\n", pData->old_ss, pData->old_sp ); oldFrame = CURRENT_STACK16; /* Pop bp from the previous stack */ - context->Ebp = (context->Ebp & ~0xffff) | *(WORD *)MapSL(pData->old_ss_sp); - pData->old_ss_sp += sizeof(WORD); + context->Ebp = (context->Ebp & ~0xffff) | *(WORD *)MapSL(MAKESEGPTR(pData->old_ss, pData->old_sp)); + pData->old_sp += sizeof(WORD); /* Switch back to the old stack */ - NtCurrentTeb()->WOW32Reserved = (void *)(pData->old_ss_sp - sizeof(STACK16FRAME)); - context->SegSs = SELECTOROF(pData->old_ss_sp); - context->Esp = OFFSETOF(pData->old_ss_sp) - sizeof(DWORD); /*ret addr*/ - pData->old_ss_sp = 0; + CURRENT_SS = pData->old_ss; + CURRENT_SP = pData->old_sp - sizeof(STACK16FRAME); + context->SegSs = pData->old_ss; + context->Esp = pData->old_sp - sizeof(DWORD); /*ret addr*/ + pData->old_ss = pData->old_sp = 0; /* Build a stack frame for the return */ diff --git a/dlls/krnl386.exe16/thunk.c b/dlls/krnl386.exe16/thunk.c index 832cc71d9be..ad2c52fab46 100644 --- a/dlls/krnl386.exe16/thunk.c +++ b/dlls/krnl386.exe16/thunk.c @@ -429,7 +429,7 @@ void WINAPI __regs_QT_Thunk( CONTEXT *context ) context16.Eip = LOWORD(context->Edx); /* point EBP to the STACK16FRAME on the stack * for the call_to_16 to set up the register content on calling */ - context16.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME,bp); + context16.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME,bp); /* * used to be (problematic): @@ -450,8 +450,7 @@ void WINAPI __regs_QT_Thunk( CONTEXT *context ) /* make sure to update the Win32 ESP, too, in order to throw away * the number of parameters that the Win16 function * accepted (that it popped from the corresponding Win16 stack) */ - context->Esp += LOWORD(context16.Esp) - - ( OFFSETOF(NtCurrentTeb()->WOW32Reserved) - argsize ); + context->Esp += LOWORD(context16.Esp) - (CURRENT_SP - argsize); } DEFINE_REGS_ENTRYPOINT( QT_Thunk ) @@ -555,7 +554,7 @@ void WINAPI __regs_FT_Thunk( CONTEXT *context ) context16.SegCs = HIWORD(callTarget); context16.Eip = LOWORD(callTarget); - context16.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME,bp); + context16.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME,bp); argsize = context->Ebp-context->Esp-0x40; if (argsize > sizeof(newstack)) argsize = sizeof(newstack); @@ -567,9 +566,7 @@ void WINAPI __regs_FT_Thunk( CONTEXT *context ) if (mapESPrelative & (1 << i)) { SEGPTR *arg = (SEGPTR *)newstack[i]; - *arg = MAKESEGPTR(SELECTOROF(NtCurrentTeb()->WOW32Reserved), - OFFSETOF(NtCurrentTeb()->WOW32Reserved) - argsize - + (*(LPBYTE *)arg - oldstack)); + *arg = MAKESEGPTR( CURRENT_SS, CURRENT_SP - argsize + (*(LPBYTE *)arg - oldstack)); } WOWCallback16Ex( 0, WCB16_REGS, argsize, newstack, (DWORD *)&context16 ); @@ -577,8 +574,7 @@ void WINAPI __regs_FT_Thunk( CONTEXT *context ) context->Edx = context16.Edx; context->Ecx = context16.Ecx; - context->Esp += LOWORD(context16.Esp) - - ( OFFSETOF(NtCurrentTeb()->WOW32Reserved) - argsize ); + context->Esp += LOWORD(context16.Esp) - (CURRENT_SP - argsize); /* Copy modified buffers back to 32-bit stack */ memcpy( oldstack, newstack, argsize ); @@ -713,7 +709,7 @@ void WINAPI __regs_Common32ThkLS( CONTEXT *context ) context16.Edi = LOWORD(context->Ecx); context16.SegCs = HIWORD(context->Eax); context16.Eip = LOWORD(context->Eax); - context16.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME,bp); + context16.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME,bp); argsize = HIWORD(context->Edx) * 4; @@ -769,7 +765,7 @@ void WINAPI __regs_OT_32ThkLSF( CONTEXT *context ) context16.SegCs = HIWORD(context->Edx); context16.Eip = LOWORD(context->Edx); - context16.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME,bp); + context16.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME,bp); argsize = 2 * *(WORD *)context->Esp + 2; @@ -781,8 +777,7 @@ void WINAPI __regs_OT_32ThkLSF( CONTEXT *context ) memcpy( (LPBYTE)context->Esp, (LPBYTE)CURRENT_STACK16 - argsize, argsize ); - context->Esp += LOWORD(context16.Esp) - - ( OFFSETOF(NtCurrentTeb()->WOW32Reserved) - argsize ); + context->Esp += LOWORD(context16.Esp) - (CURRENT_SP - argsize); } DEFINE_REGS_ENTRYPOINT( OT_32ThkLSF ) @@ -1239,21 +1234,22 @@ void WINAPI __regs_K32Thk1632Prolog( CONTEXT *context ) WORD stackSel = SELECTOROF(frame32->frame16); DWORD stackBase = GetSelectorBase(stackSel); - TRACE("before SYSTHUNK hack: EBP: %08x ESP: %08x cur_stack: %p\n", - context->Ebp, context->Esp, NtCurrentTeb()->WOW32Reserved); + TRACE("before SYSTHUNK hack: EBP: %08x ESP: %08x cur_stack: %04x:%04x\n", + context->Ebp, context->Esp, CURRENT_SS, CURRENT_SP); memset(frame16, '\0', sizeof(STACK16FRAME)); frame16->frame32 = frame32; frame16->ebp = context->Ebp; memcpy(stack32, stack16, argSize); - NtCurrentTeb()->WOW32Reserved = (void *)MAKESEGPTR(stackSel, (DWORD)frame16 - stackBase); + CURRENT_SS = stackSel; + CURRENT_SP = (DWORD)frame16 - stackBase; context->Esp = (DWORD)stack32 + 4; context->Ebp = context->Esp + argSize; - TRACE("after SYSTHUNK hack: EBP: %08x ESP: %08x cur_stack: %p\n", - context->Ebp, context->Esp, NtCurrentTeb()->WOW32Reserved); + TRACE("after SYSTHUNK hack: EBP: %08x ESP: %08x cur_stack: %04x:%04x\n", + context->Ebp, context->Esp, CURRENT_SS, CURRENT_SP); } /* entry_point is never used again once the entry point has @@ -1283,16 +1279,16 @@ void WINAPI __regs_K32Thk1632Epilog( CONTEXT *context ) DWORD nArgsPopped = context->Esp - (DWORD)stack32; - TRACE("before SYSTHUNK hack: EBP: %08x ESP: %08x cur_stack: %p\n", - context->Ebp, context->Esp, NtCurrentTeb()->WOW32Reserved); + TRACE("before SYSTHUNK hack: EBP: %08x ESP: %08x cur_stack: %04x:%04x\n", + context->Ebp, context->Esp, CURRENT_SS, CURRENT_SP); NtCurrentTeb()->WOW32Reserved = frame16->frame32; context->Esp = (DWORD)stack16 + nArgsPopped; context->Ebp = frame16->ebp; - TRACE("after SYSTHUNK hack: EBP: %08x ESP: %08x cur_stack: %p\n", - context->Ebp, context->Esp, NtCurrentTeb()->WOW32Reserved); + TRACE("after SYSTHUNK hack: EBP: %08x ESP: %08x cur_stack: %04x:%04x\n", + context->Ebp, context->Esp, CURRENT_SS, CURRENT_SP); } } DEFINE_REGS_ENTRYPOINT( K32Thk1632Epilog ) @@ -2303,7 +2299,7 @@ void WINAPI Throw16( LPCATCHBUF lpbuf, INT16 retval, CONTEXT *context ) frame32 = pFrame->frame32; while (frame32 && frame32->frame16) { - if (OFFSETOF(frame32->frame16) < OFFSETOF(NtCurrentTeb()->WOW32Reserved)) + if (OFFSETOF(frame32->frame16) < CURRENT_SP) break; /* Something strange is going on */ if (OFFSETOF(frame32->frame16) > lpbuf[2]) { diff --git a/dlls/krnl386.exe16/wowthunk.c b/dlls/krnl386.exe16/wowthunk.c index 2dddbf93289..2b4deb34e99 100644 --- a/dlls/krnl386.exe16/wowthunk.c +++ b/dlls/krnl386.exe16/wowthunk.c @@ -412,8 +412,7 @@ BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags, TRACE_(relay)( "\1CallTo16(func=%04x:%04x", context->SegCs, LOWORD(context->Eip) ); while (count) TRACE_(relay)( ",%04x", wstack[--count] ); TRACE_(relay)( ") ss:sp=%04x:%04x ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x bp=%04x ds=%04x es=%04x\n", - SELECTOROF(NtCurrentTeb()->WOW32Reserved), - OFFSETOF(NtCurrentTeb()->WOW32Reserved), + CURRENT_SS, CURRENT_SP, (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx, (WORD)context->Edx, (WORD)context->Esi, (WORD)context->Edi, (WORD)context->Ebp, (WORD)context->SegDs, (WORD)context->SegEs ); @@ -443,8 +442,7 @@ BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags, if (TRACE_ON(relay)) { TRACE_(relay)( "\1RetFrom16() ss:sp=%04x:%04x ax=%04x bx=%04x cx=%04x dx=%04x bp=%04x sp=%04x\n", - SELECTOROF(NtCurrentTeb()->WOW32Reserved), - OFFSETOF(NtCurrentTeb()->WOW32Reserved), + CURRENT_SS, CURRENT_SP, (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx, (WORD)context->Edx, (WORD)context->Ebp, (WORD)context->Esp ); SYSLEVEL_CheckNotLevel( 2 ); @@ -460,10 +458,9 @@ BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags, WORD * wstack = (WORD *)stack; TRACE_(relay)( "\1CallTo16(func=%04x:%04x,ds=%04x", - HIWORD(vpfn16), LOWORD(vpfn16), SELECTOROF(NtCurrentTeb()->WOW32Reserved) ); + HIWORD(vpfn16), LOWORD(vpfn16), CURRENT_SS ); while (count) TRACE_(relay)( ",%04x", wstack[--count] ); - TRACE_(relay)( ") ss:sp=%04x:%04x\n", SELECTOROF(NtCurrentTeb()->WOW32Reserved), - OFFSETOF(NtCurrentTeb()->WOW32Reserved) ); + TRACE_(relay)( ") ss:sp=%04x:%04x\n", CURRENT_SS, CURRENT_SP ); SYSLEVEL_CheckNotLevel( 2 ); } @@ -485,9 +482,7 @@ BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags, if (TRACE_ON(relay)) { - TRACE_(relay)( "\1RetFrom16() ss:sp=%04x:%04x retval=%08x\n", - SELECTOROF(NtCurrentTeb()->WOW32Reserved), - OFFSETOF(NtCurrentTeb()->WOW32Reserved), ret ); + TRACE_(relay)( "\1RetFrom16() ss:sp=%04x:%04x retval=%08x\n", CURRENT_SS, CURRENT_SP, ret ); SYSLEVEL_CheckNotLevel( 2 ); } } diff --git a/dlls/system.drv16/system.c b/dlls/system.drv16/system.c index b6fd51c05f0..78cc0b03c7b 100644 --- a/dlls/system.drv16/system.c +++ b/dlls/system.drv16/system.c @@ -70,7 +70,7 @@ static void CALLBACK SYSTEM_TimerTick( LPVOID arg, DWORD low, DWORD high ) memset( &context, 0, sizeof(context) ); context.SegCs = SELECTOROF( proc ); context.Eip = OFFSETOF( proc ); - context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME, bp); + context.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME, bp); context.Eax = i + 1; WOWCallback16Ex( 0, WCB16_REGS, 0, NULL, (DWORD *)&context ); diff --git a/dlls/user.exe16/message.c b/dlls/user.exe16/message.c index ca90a31bfa6..93e2cc018bf 100644 --- a/dlls/user.exe16/message.c +++ b/dlls/user.exe16/message.c @@ -240,11 +240,11 @@ static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPA /* Window procedures want ax = hInstance, ds = es = ss */ memset(&context, 0, sizeof(context)); - context.SegDs = context.SegEs = SELECTOROF(NtCurrentTeb()->WOW32Reserved); + context.SegDs = context.SegEs = CURRENT_SS; if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs; context.SegCs = SELECTOROF(func); context.Eip = OFFSETOF(func); - context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME, bp); + context.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME, bp); if (lParam) { @@ -267,7 +267,7 @@ static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPA if (size) { memcpy( &args.u, MapSL(lParam), size ); - lParam = PtrToUlong(NtCurrentTeb()->WOW32Reserved) - size; + lParam = MAKESEGPTR( CURRENT_SS, CURRENT_SP - size ); } } diff --git a/include/wine/winbase16.h b/include/wine/winbase16.h index 11ac4533736..a3ff69b264d 100644 --- a/include/wine/winbase16.h +++ b/include/wine/winbase16.h @@ -564,5 +564,7 @@ BOOL16 WINAPI WriteProfileSection16(LPCSTR,LPCSTR); #define CURRENT_STACK16 ((STACK16FRAME *)MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved)) #define CURRENT_DS (CURRENT_STACK16->ds) +#define CURRENT_SP (((WORD *)&NtCurrentTeb()->WOW32Reserved)[0]) +#define CURRENT_SS (((WORD *)&NtCurrentTeb()->WOW32Reserved)[1]) #endif /* __WINE_WINE_WINBASE16_H */