krnl386: Move the 16-bit stack out of the WOW32Reserved field.

Based on a patch by Sebastian Lackner.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-11-26 13:25:06 +01:00
parent f87262ea99
commit b636f9816f
8 changed files with 14 additions and 13 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -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 ||

View File

@ -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);
}

View File

@ -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;

View File

@ -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 */

View File

@ -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) */