Commit a906f13f authored by Brendan Shanks's avatar Brendan Shanks Committed by Alexandre Julliard

ntdll: Ensure CONTEXT_EX on exception stack is initialized.

On non-AVX CPUs, CONTEXT_EX is not being initialized. In WOW64 mode, this results in invalid exception records when dispatch_wow_exception() uses RtlCopyContext(). Signed-off-by: 's avatarBrendan Shanks <bshanks@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent b73e3102
......@@ -581,12 +581,23 @@ static inline void context_init_xstate( CONTEXT *context, void *xstate_buffer )
xctx->Legacy.Length = sizeof(CONTEXT);
xctx->Legacy.Offset = -(LONG)sizeof(CONTEXT);
if (xstate_buffer)
{
xctx->XState.Length = sizeof(XSTATE);
xctx->XState.Offset = (BYTE *)xstate_buffer - (BYTE *)xctx;
context->ContextFlags |= CONTEXT_XSTATE;
xctx->All.Length = sizeof(CONTEXT) + xctx->XState.Offset + xctx->XState.Length;
}
else
{
xctx->XState.Length = 25;
xctx->XState.Offset = 0;
xctx->All.Length = sizeof(CONTEXT) + 24; /* sizeof(CONTEXT_EX) minus 8 alignment bytes on x64. */
}
xctx->All.Offset = -(LONG)sizeof(CONTEXT);
context->ContextFlags |= CONTEXT_XSTATE;
}
......@@ -1456,6 +1467,10 @@ C_ASSERT( (offsetof(struct stack_layout, xstate) == sizeof(struct stack_layout))
memcpy( &dst_xs->YmmContext, &src_xs->YmmContext, sizeof(dst_xs->YmmContext) );
}
}
else
{
context_init_xstate( &stack->context, NULL );
}
stack->rec_ptr = &stack->rec;
stack->context_ptr = &stack->context;
......
......@@ -411,12 +411,23 @@ static inline void context_init_xstate( CONTEXT *context, void *xstate_buffer )
xctx->Legacy.Length = sizeof(CONTEXT);
xctx->Legacy.Offset = -(LONG)sizeof(CONTEXT);
if (xstate_buffer)
{
xctx->XState.Length = sizeof(XSTATE);
xctx->XState.Offset = (BYTE *)xstate_buffer - (BYTE *)xctx;
context->ContextFlags |= CONTEXT_XSTATE;
xctx->All.Length = sizeof(CONTEXT) + xctx->XState.Offset + xctx->XState.Length;
}
else
{
xctx->XState.Length = 25;
xctx->XState.Offset = 0;
xctx->All.Length = sizeof(CONTEXT) + 24; /* sizeof(CONTEXT_EX) minus 8 alignment bytes on x64. */
}
xctx->All.Offset = -(LONG)sizeof(CONTEXT);
context->ContextFlags |= CONTEXT_XSTATE;
}
static USHORT cs32_sel; /* selector for %cs in 32-bit mode */
......@@ -2195,6 +2206,10 @@ static void setup_raise_exception( ucontext_t *sigcontext, EXCEPTION_RECORD *rec
memcpy( &dst_xs->YmmContext, &src_xs->YmmContext, sizeof(dst_xs->YmmContext) );
}
}
else
{
context_init_xstate( &stack->context, NULL );
}
CS_sig(sigcontext) = cs64_sel;
RIP_sig(sigcontext) = (ULONG_PTR)pKiUserExceptionDispatcher;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment