From b636f9816f898ddd368d6366fd822a1a4b17e515 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 26 Nov 2020 13:25:06 +0100 Subject: [PATCH] krnl386: Move the 16-bit stack out of the WOW32Reserved field. Based on a patch by Sebastian Lackner. Signed-off-by: Alexandre Julliard --- dlls/dbghelp/cpu_i386.c | 6 +++--- dlls/krnl386.exe16/kernel16_private.h | 1 + dlls/krnl386.exe16/thunk.c | 4 ++-- dlls/krnl386.exe16/wowthunk.c | 2 +- dlls/ntdll/unix/signal_i386.c | 2 +- dlls/toolhelp.dll16/toolhelp.c | 4 ++-- include/wine/winbase16.h | 6 +++--- tools/winebuild/relay.c | 2 +- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/dlls/dbghelp/cpu_i386.c b/dlls/dbghelp/cpu_i386.c index 864b7f76643..45b3bd95df6 100644 --- a/dlls/dbghelp/cpu_i386.c +++ b/dlls/dbghelp/cpu_i386.c @@ -213,16 +213,16 @@ static BOOL i386_stack_walk(struct cpu_stack_walk *csw, STACKFRAME64 *frame, /* Init done */ set_curr_mode((frame->AddrPC.Mode == AddrModeFlat) ? stm_32bit : stm_16bit); - /* cur_switch holds address of WOW32Reserved field in TEB in debuggee + /* cur_switch holds address of SystemReserved1[0] field in TEB in debuggee * address space */ if (NtQueryInformationThread(csw->hThread, ThreadBasicInformation, &info, sizeof(info), NULL) == STATUS_SUCCESS) { - curr_switch = (DWORD_PTR)info.TebBaseAddress + FIELD_OFFSET(TEB, WOW32Reserved); + curr_switch = (DWORD_PTR)info.TebBaseAddress + FIELD_OFFSET(TEB, SystemReserved1); if (!sw_read_mem(csw, curr_switch, &p, sizeof(p))) { - WARN("Can't read TEB:WOW32Reserved\n"); + WARN("Can't read TEB:SystemReserved1\n"); goto done_err; } next_switch = p; diff --git a/dlls/krnl386.exe16/kernel16_private.h b/dlls/krnl386.exe16/kernel16_private.h index 8c93b1dc0a2..279058ac68f 100644 --- a/dlls/krnl386.exe16/kernel16_private.h +++ b/dlls/krnl386.exe16/kernel16_private.h @@ -298,6 +298,7 @@ struct tagSYSLEVEL; struct kernel_thread_data { + SEGPTR stack; /* 16-bit stack pointer */ WORD stack_sel; /* 16-bit stack selector */ WORD htask16; /* Win16 task handle */ DWORD sys_count[4]; /* syslevel mutex entry counters */ diff --git a/dlls/krnl386.exe16/thunk.c b/dlls/krnl386.exe16/thunk.c index ad2c52fab46..98dbf31a770 100644 --- a/dlls/krnl386.exe16/thunk.c +++ b/dlls/krnl386.exe16/thunk.c @@ -1229,7 +1229,7 @@ void WINAPI __regs_K32Thk1632Prolog( CONTEXT *context ) DWORD argSize = context->Ebp - context->Esp; char *stack16 = (char *)context->Esp - 4; STACK16FRAME *frame16 = (STACK16FRAME *)stack16 - 1; - STACK32FRAME *frame32 = NtCurrentTeb()->WOW32Reserved; + STACK32FRAME *frame32 = (STACK32FRAME *)kernel_get_thread_data()->stack; char *stack32 = (char *)frame32 - argSize; WORD stackSel = SELECTOROF(frame32->frame16); DWORD stackBase = GetSelectorBase(stackSel); @@ -1282,7 +1282,7 @@ void WINAPI __regs_K32Thk1632Epilog( CONTEXT *context ) 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; + kernel_get_thread_data()->stack = (SEGPTR)frame16->frame32; context->Esp = (DWORD)stack16 + nArgsPopped; context->Ebp = frame16->ebp; diff --git a/dlls/krnl386.exe16/wowthunk.c b/dlls/krnl386.exe16/wowthunk.c index 2b4deb34e99..73d1565c573 100644 --- a/dlls/krnl386.exe16/wowthunk.c +++ b/dlls/krnl386.exe16/wowthunk.c @@ -127,7 +127,7 @@ static DWORD call16_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RE { /* unwinding: restore the stack pointer in the TEB, and leave the Win16 mutex */ STACK32FRAME *frame32 = CONTAINING_RECORD(frame, STACK32FRAME, frame); - NtCurrentTeb()->WOW32Reserved = (void *)frame32->frame16; + kernel_get_thread_data()->stack = frame32->frame16; _LeaveWin16Lock(); } else if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION || diff --git a/dlls/ntdll/unix/signal_i386.c b/dlls/ntdll/unix/signal_i386.c index 58b79940773..eb4a6653f5e 100644 --- a/dlls/ntdll/unix/signal_i386.c +++ b/dlls/ntdll/unix/signal_i386.c @@ -630,7 +630,7 @@ static inline void *init_handler( const ucontext_t *sigcontext ) * SS is still non-system segment. This is why both CS and SS * are checked. */ - return teb->WOW32Reserved; + return teb->SystemReserved1[0]; } return (void *)(ESP_sig(sigcontext) & ~3); } diff --git a/dlls/toolhelp.dll16/toolhelp.c b/dlls/toolhelp.dll16/toolhelp.c index 5d7bf8f016e..57a95fb8d8f 100644 --- a/dlls/toolhelp.dll16/toolhelp.c +++ b/dlls/toolhelp.dll16/toolhelp.c @@ -491,8 +491,8 @@ BOOL16 WINAPI TaskNext16( TASKENTRY *lpte ) lpte->hTaskParent = pTask->hParent; lpte->hInst = pTask->hInstance; lpte->hModule = pTask->hModule; - lpte->wSS = SELECTOROF( pTask->teb->WOW32Reserved ); - lpte->wSP = OFFSETOF( pTask->teb->WOW32Reserved ); + lpte->wSS = SELECTOROF( pTask->teb->SystemReserved1[0] ); + lpte->wSP = OFFSETOF( pTask->teb->SystemReserved1[0] ); lpte->wStackTop = pInstData->stacktop; lpte->wStackMinimum = pInstData->stackmin; lpte->wStackBottom = pInstData->stackbottom; diff --git a/include/wine/winbase16.h b/include/wine/winbase16.h index a3ff69b264d..71493395f3a 100644 --- a/include/wine/winbase16.h +++ b/include/wine/winbase16.h @@ -562,9 +562,9 @@ BOOL16 WINAPI WritePrivateProfileSection16(LPCSTR,LPCSTR,LPCSTR); BOOL16 WINAPI WritePrivateProfileStruct16(LPCSTR,LPCSTR,LPVOID,UINT16,LPCSTR); BOOL16 WINAPI WriteProfileSection16(LPCSTR,LPCSTR); -#define CURRENT_STACK16 ((STACK16FRAME *)MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved)) +#define CURRENT_STACK16 ((STACK16FRAME *)MapSL((SEGPTR)NtCurrentTeb()->SystemReserved1[0])) #define CURRENT_DS (CURRENT_STACK16->ds) -#define CURRENT_SP (((WORD *)&NtCurrentTeb()->WOW32Reserved)[0]) -#define CURRENT_SS (((WORD *)&NtCurrentTeb()->WOW32Reserved)[1]) +#define CURRENT_SP (((WORD *)NtCurrentTeb()->SystemReserved1)[0]) +#define CURRENT_SS (((WORD *)NtCurrentTeb()->SystemReserved1)[1]) #endif /* __WINE_WINE_WINBASE16_H */ diff --git a/tools/winebuild/relay.c b/tools/winebuild/relay.c index 29d0a74c833..dc0960761a5 100644 --- a/tools/winebuild/relay.c +++ b/tools/winebuild/relay.c @@ -31,7 +31,7 @@ #include "build.h" /* offset of the stack pointer relative to %fs:(0) */ -#define STACKOFFSET 0xc0 /* FIELD_OFFSET(TEB,WOW32Reserved) */ +#define STACKOFFSET 0x10c /* FIELD_OFFSET(TEB,SystemReserved1) */ /* fix this if the x86_thread_data structure is changed */ #define GS_OFFSET 0x1d8 /* FIELD_OFFSET(TEB,SystemReserved2) + FIELD_OFFSET(struct x86_thread_data,gs) */