Commit da16581e authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Use nameless unions/structs for register contexts.

parent 33598db7
......@@ -24,8 +24,6 @@
#include <stdlib.h>
#include <stdarg.h>
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
......@@ -685,7 +683,7 @@ static void pop_fpregs_range( int first, int last, CONTEXT *context,
for (i = first; i <= last; i++)
{
if (ptrs && i >= 8 && i <= 15) (&ptrs->D8)[i - 8] = (ULONGLONG *)context->Sp;
context->u.D[i] = *(ULONGLONG *)context->Sp;
context->D[i] = *(ULONGLONG *)context->Sp;
context->Sp += 8;
}
}
......@@ -781,32 +779,32 @@ static void *unwind_packed_data( ULONG_PTR base, ULONG_PTR pc, RUNTIME_FUNCTION
CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *ptrs )
{
int i, pos = 0;
int pf = 0, ef = 0, fpoffset = 0, stack = func->u.s.StackAdjust;
int pf = 0, ef = 0, fpoffset = 0, stack = func->StackAdjust;
int prologue_regmask = 0;
int epilogue_regmask = 0;
unsigned int offset, len;
BYTE prologue[10], *prologue_end, epilogue[20], *epilogue_end;
TRACE( "function %lx-%lx: len=%#x flag=%x ret=%u H=%u reg=%u R=%u L=%u C=%u stackadjust=%x\n",
base + func->BeginAddress, base + func->BeginAddress + func->u.s.FunctionLength * 2,
func->u.s.FunctionLength, func->u.s.Flag, func->u.s.Ret,
func->u.s.H, func->u.s.Reg, func->u.s.R, func->u.s.L, func->u.s.C, func->u.s.StackAdjust );
base + func->BeginAddress, base + func->BeginAddress + func->FunctionLength * 2,
func->FunctionLength, func->Flag, func->Ret,
func->H, func->Reg, func->R, func->L, func->C, func->StackAdjust );
offset = (pc - base) - func->BeginAddress;
if (func->u.s.StackAdjust >= 0x03f4)
if (func->StackAdjust >= 0x03f4)
{
pf = func->u.s.StackAdjust & 0x04;
ef = func->u.s.StackAdjust & 0x08;
stack = (func->u.s.StackAdjust & 3) + 1;
pf = func->StackAdjust & 0x04;
ef = func->StackAdjust & 0x08;
stack = (func->StackAdjust & 3) + 1;
}
if (!func->u.s.R || pf)
if (!func->R || pf)
{
int first = 4, last = func->u.s.Reg + 4;
int first = 4, last = func->Reg + 4;
if (pf)
{
first = (~func->u.s.StackAdjust) & 3;
if (func->u.s.R)
first = (~func->StackAdjust) & 3;
if (func->R)
last = 3;
}
for (i = first; i <= last; i++)
......@@ -814,31 +812,31 @@ static void *unwind_packed_data( ULONG_PTR base, ULONG_PTR pc, RUNTIME_FUNCTION
fpoffset = last + 1 - first;
}
if (!func->u.s.R || ef)
if (!func->R || ef)
{
int first = 4, last = func->u.s.Reg + 4;
int first = 4, last = func->Reg + 4;
if (ef)
{
first = (~func->u.s.StackAdjust) & 3;
if (func->u.s.R)
first = (~func->StackAdjust) & 3;
if (func->R)
last = 3;
}
for (i = first; i <= last; i++)
epilogue_regmask |= 1 << i;
}
if (func->u.s.C)
if (func->C)
{
prologue_regmask |= 1 << 11;
epilogue_regmask |= 1 << 11;
}
if (func->u.s.L)
if (func->L)
{
prologue_regmask |= 1 << 14; /* lr */
if (func->u.s.Ret != 0)
if (func->Ret != 0)
epilogue_regmask |= 1 << 14; /* lr */
else if (!func->u.s.H)
else if (!func->H)
epilogue_regmask |= 1 << 15; /* pc */
}
......@@ -856,12 +854,12 @@ static void *unwind_packed_data( ULONG_PTR base, ULONG_PTR pc, RUNTIME_FUNCTION
}
}
if (func->u.s.R && func->u.s.Reg != 7)
prologue[pos++] = 0xe0 | func->u.s.Reg; /* vpush {d8-dX} */
if (func->R && func->Reg != 7)
prologue[pos++] = 0xe0 | func->Reg; /* vpush {d8-dX} */
if (func->u.s.C && fpoffset == 0)
if (func->C && fpoffset == 0)
prologue[pos++] = 0xfb; /* mov r11, sp - handled as nop16 */
else if (func->u.s.C)
else if (func->C)
prologue[pos++] = 0xfc; /* add r11, sp, #x - handled as nop32 */
if (prologue_regmask & 0xf00) /* r8-r11 set */
......@@ -881,7 +879,7 @@ static void *unwind_packed_data( ULONG_PTR base, ULONG_PTR pc, RUNTIME_FUNCTION
prologue[pos++] = bitmask & 0xff;
}
if (func->u.s.H)
if (func->H)
prologue[pos++] = 0x04; /* push {r0-r3} - handled as sub sp, sp, #16 */
prologue[pos++] = 0xff; /* end */
......@@ -902,8 +900,8 @@ static void *unwind_packed_data( ULONG_PTR base, ULONG_PTR pc, RUNTIME_FUNCTION
}
}
if (func->u.s.R && func->u.s.Reg != 7)
epilogue[pos++] = 0xe0 | func->u.s.Reg; /* vpush {d8-dX} */
if (func->R && func->Reg != 7)
epilogue[pos++] = 0xe0 | func->Reg; /* vpush {d8-dX} */
if (epilogue_regmask & 0x7f00) /* r8-r11, lr set */
{
......@@ -922,23 +920,23 @@ static void *unwind_packed_data( ULONG_PTR base, ULONG_PTR pc, RUNTIME_FUNCTION
epilogue[pos++] = bitmask & 0xff;
}
if (func->u.s.H && !(func->u.s.L && func->u.s.Ret == 0))
if (func->H && !(func->L && func->Ret == 0))
epilogue[pos++] = 0x04; /* add sp, sp, #16 */
else if (func->u.s.H && (func->u.s.L && func->u.s.Ret == 0))
else if (func->H && (func->L && func->Ret == 0))
{
epilogue[pos++] = 0xef; /* ldr lr, [sp], #20 */
epilogue[pos++] = 5;
}
if (func->u.s.Ret == 1)
if (func->Ret == 1)
epilogue[pos++] = 0xfd; /* bx lr */
else if (func->u.s.Ret == 2)
else if (func->Ret == 2)
epilogue[pos++] = 0xfe; /* b address */
else
epilogue[pos++] = 0xff; /* end */
epilogue_end = &epilogue[pos];
if (func->u.s.Flag == 1 && offset < 4 * (prologue_end - prologue)) {
if (func->Flag == 1 && offset < 4 * (prologue_end - prologue)) {
/* Check prologue */
len = get_sequence_len( prologue, prologue_end, 0 );
if (offset < len)
......@@ -948,12 +946,12 @@ static void *unwind_packed_data( ULONG_PTR base, ULONG_PTR pc, RUNTIME_FUNCTION
}
}
if (func->u.s.Ret != 3 && 2 * func->u.s.FunctionLength - offset <= 4 * (epilogue_end - epilogue)) {
if (func->Ret != 3 && 2 * func->FunctionLength - offset <= 4 * (epilogue_end - epilogue)) {
/* Check epilogue */
len = get_sequence_len( epilogue, epilogue_end, 1 );
if (offset >= 2 * func->u.s.FunctionLength - len)
if (offset >= 2 * func->FunctionLength - len)
{
process_unwind_codes( epilogue, epilogue_end, context, ptrs, offset - (2 * func->u.s.FunctionLength - len) );
process_unwind_codes( epilogue, epilogue_end, context, ptrs, offset - (2 * func->FunctionLength - len) );
return NULL;
}
}
......@@ -977,7 +975,7 @@ static void *unwind_full_data( ULONG_PTR base, ULONG_PTR pc, RUNTIME_FUNCTION *f
void *data;
BYTE *end;
info = (struct unwind_info *)((char *)base + func->u.UnwindData);
info = (struct unwind_info *)((char *)base + func->UnwindData);
data = info + 1;
epilogs = info->epilog;
codes = info->codes;
......@@ -1066,7 +1064,7 @@ PVOID WINAPI RtlVirtualUnwind( ULONG type, ULONG_PTR base, ULONG_PTR pc,
*handler_data = NULL;
context->Pc = 0;
if (func->u.s.Flag)
if (func->Flag)
handler = unwind_packed_data( base, pc, func, context, ctx_ptr );
else
handler = unwind_full_data( base, pc, func, context, handler_data, ctx_ptr );
......@@ -1171,7 +1169,7 @@ void CDECL RtlRestoreContext( CONTEXT *context, EXCEPTION_RECORD *rec )
context->Fpscr = jmp->Fpscr;
for (i = 0; i < 8; i++)
context->u.D[8+i] = jmp->D[i];
context->D[8+i] = jmp->D[i];
}
else if (rec && rec->ExceptionCode == STATUS_UNWIND_CONSOLIDATE && rec->NumberParameters >= 1)
{
......
......@@ -23,8 +23,6 @@
#include <stdlib.h>
#include <stdarg.h>
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
......@@ -690,14 +688,14 @@ static ULONG64 get_int_reg( CONTEXT *context, int reg )
static void set_int_reg( CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *ctx_ptr, int reg, ULONG64 *val )
{
*(&context->Rax + reg) = *val;
if (ctx_ptr) ctx_ptr->u2.IntegerContext[reg] = val;
if (ctx_ptr) ctx_ptr->IntegerContext[reg] = val;
}
static void set_float_reg( CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *ctx_ptr, int reg, M128A *val )
{
/* Use a memcpy() to avoid issues if val is misaligned. */
memcpy(&context->u.s.Xmm0 + reg, val, sizeof(*val));
if (ctx_ptr) ctx_ptr->u.FloatingContext[reg] = val;
memcpy(&context->Xmm0 + reg, val, sizeof(*val));
if (ctx_ptr) ctx_ptr->FloatingContext[reg] = val;
}
static int get_opcode_size( struct opcode op )
......@@ -1229,19 +1227,19 @@ void CDECL RtlRestoreContext( CONTEXT *context, EXCEPTION_RECORD *rec )
context->R14 = jmp->R14;
context->R15 = jmp->R15;
context->Rip = jmp->Rip;
context->u.s.Xmm6 = jmp->Xmm6;
context->u.s.Xmm7 = jmp->Xmm7;
context->u.s.Xmm8 = jmp->Xmm8;
context->u.s.Xmm9 = jmp->Xmm9;
context->u.s.Xmm10 = jmp->Xmm10;
context->u.s.Xmm11 = jmp->Xmm11;
context->u.s.Xmm12 = jmp->Xmm12;
context->u.s.Xmm13 = jmp->Xmm13;
context->u.s.Xmm14 = jmp->Xmm14;
context->u.s.Xmm15 = jmp->Xmm15;
context->Xmm6 = jmp->Xmm6;
context->Xmm7 = jmp->Xmm7;
context->Xmm8 = jmp->Xmm8;
context->Xmm9 = jmp->Xmm9;
context->Xmm10 = jmp->Xmm10;
context->Xmm11 = jmp->Xmm11;
context->Xmm12 = jmp->Xmm12;
context->Xmm13 = jmp->Xmm13;
context->Xmm14 = jmp->Xmm14;
context->Xmm15 = jmp->Xmm15;
context->MxCsr = jmp->MxCsr;
context->u.FltSave.MxCsr = jmp->MxCsr;
context->u.FltSave.ControlWord = jmp->FpCsr;
context->FltSave.MxCsr = jmp->MxCsr;
context->FltSave.ControlWord = jmp->FpCsr;
}
else if (rec && rec->ExceptionCode == STATUS_UNWIND_CONSOLIDATE && rec->NumberParameters >= 1)
{
......
......@@ -59,8 +59,6 @@
# include <link.h>
#endif
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
......@@ -135,7 +133,7 @@ static void save_fpu( CONTEXT *context, const ucontext_t *sigcontext )
struct vfp_sigframe *frame = get_extended_sigcontext( sigcontext, 0x56465001 );
if (!frame) return;
memcpy( context->u.D, frame->fpregs, sizeof(context->u.D) );
memcpy( context->D, frame->fpregs, sizeof(context->D) );
context->Fpscr = frame->fpscr;
}
......@@ -144,7 +142,7 @@ static void restore_fpu( const CONTEXT *context, ucontext_t *sigcontext )
struct vfp_sigframe *frame = get_extended_sigcontext( sigcontext, 0x56465001 );
if (!frame) return;
memcpy( frame->fpregs, context->u.D, sizeof(context->u.D) );
memcpy( frame->fpregs, context->D, sizeof(context->D) );
frame->fpscr = context->Fpscr;
}
......@@ -288,7 +286,7 @@ static void pop_vfp(CONTEXT *context, int first, int last)
int i;
for (i = first; i <= last; i++)
{
context->u.D[i] = *(ULONGLONG *)context->Sp;
context->D[i] = *(ULONGLONG *)context->Sp;
context->Sp += 8;
}
}
......@@ -943,7 +941,7 @@ NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
if (flags & CONTEXT_FLOATING_POINT)
{
frame->fpscr = context->Fpscr;
memcpy( frame->d, context->u.D, sizeof(context->u.D) );
memcpy( frame->d, context->D, sizeof(context->D) );
}
frame->restore_flags |= flags & ~CONTEXT_INTEGER;
return STATUS_SUCCESS;
......@@ -994,7 +992,7 @@ NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
if (needed_flags & CONTEXT_FLOATING_POINT)
{
context->Fpscr = frame->fpscr;
memcpy( context->u.D, frame->d, sizeof(frame->d) );
memcpy( context->D, frame->d, sizeof(frame->d) );
context->ContextFlags |= CONTEXT_FLOATING_POINT;
}
return STATUS_SUCCESS;
......
......@@ -65,8 +65,6 @@
# include <mach/mach.h>
#endif
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
......@@ -894,8 +892,8 @@ static void save_context( struct xcontext *xcontext, const ucontext_t *sigcontex
XSTATE *xs;
context->ContextFlags |= CONTEXT_FLOATING_POINT;
context->u.FltSave = *FPU_sig(sigcontext);
context->MxCsr = context->u.FltSave.MxCsr;
context->FltSave = *FPU_sig(sigcontext);
context->MxCsr = context->FltSave.MxCsr;
if ((cpu_info.ProcessorFeatureBits & CPU_FEATURE_AVX) && (xs = XState_sig(FPU_sig(sigcontext))))
{
/* xcontext and sigcontext are both on the signal stack, so we can
......@@ -925,7 +923,7 @@ static void restore_context( const struct xcontext *xcontext, ucontext_t *sigcon
amd64_thread_data()->dr6 = context->Dr6;
amd64_thread_data()->dr7 = context->Dr7;
set_sigcontext( context, sigcontext );
if (FPU_sig(sigcontext)) *FPU_sig(sigcontext) = context->u.FltSave;
if (FPU_sig(sigcontext)) *FPU_sig(sigcontext) = context->FltSave;
if ((cpu_info.ProcessorFeatureBits & CPU_FEATURE_AVX) && (xs = XState_sig(FPU_sig(sigcontext))))
xs->CompactionMask = xcontext->host_compaction_mask;
leave_handler( sigcontext );
......@@ -1051,7 +1049,7 @@ NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
}
if (flags & CONTEXT_FLOATING_POINT)
{
frame->xsave = context->u.FltSave;
frame->xsave = context->FltSave;
frame->xstate.Mask |= XSTATE_MASK_LEGACY;
}
if (flags & CONTEXT_XSTATE)
......@@ -1132,34 +1130,34 @@ NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
if (!xstate_compaction_enabled ||
(frame->xstate.Mask & XSTATE_MASK_LEGACY_FLOATING_POINT))
{
memcpy( &context->u.FltSave, &frame->xsave, FIELD_OFFSET( XSAVE_FORMAT, MxCsr ));
memcpy( context->u.FltSave.FloatRegisters, frame->xsave.FloatRegisters,
sizeof( context->u.FltSave.FloatRegisters ));
memcpy( &context->FltSave, &frame->xsave, FIELD_OFFSET( XSAVE_FORMAT, MxCsr ));
memcpy( context->FltSave.FloatRegisters, frame->xsave.FloatRegisters,
sizeof( context->FltSave.FloatRegisters ));
}
else
{
memset( &context->u.FltSave, 0, FIELD_OFFSET( XSAVE_FORMAT, MxCsr ));
memset( context->u.FltSave.FloatRegisters, 0,
sizeof( context->u.FltSave.FloatRegisters ));
context->u.FltSave.ControlWord = 0x37f;
memset( &context->FltSave, 0, FIELD_OFFSET( XSAVE_FORMAT, MxCsr ));
memset( context->FltSave.FloatRegisters, 0,
sizeof( context->FltSave.FloatRegisters ));
context->FltSave.ControlWord = 0x37f;
}
if (!xstate_compaction_enabled || (frame->xstate.Mask & XSTATE_MASK_LEGACY_SSE))
{
memcpy( context->u.FltSave.XmmRegisters, frame->xsave.XmmRegisters,
sizeof( context->u.FltSave.XmmRegisters ));
context->u.FltSave.MxCsr = frame->xsave.MxCsr;
context->u.FltSave.MxCsr_Mask = frame->xsave.MxCsr_Mask;
memcpy( context->FltSave.XmmRegisters, frame->xsave.XmmRegisters,
sizeof( context->FltSave.XmmRegisters ));
context->FltSave.MxCsr = frame->xsave.MxCsr;
context->FltSave.MxCsr_Mask = frame->xsave.MxCsr_Mask;
}
else
{
memset( context->u.FltSave.XmmRegisters, 0,
sizeof( context->u.FltSave.XmmRegisters ));
context->u.FltSave.MxCsr = 0x1f80;
context->u.FltSave.MxCsr_Mask = 0x2ffff;
memset( context->FltSave.XmmRegisters, 0,
sizeof( context->FltSave.XmmRegisters ));
context->FltSave.MxCsr = 0x1f80;
context->FltSave.MxCsr_Mask = 0x2ffff;
}
context->MxCsr = context->u.FltSave.MxCsr;
context->MxCsr = context->FltSave.MxCsr;
context->ContextFlags |= CONTEXT_FLOATING_POINT;
}
if ((needed_flags & CONTEXT_XSTATE) && (cpu_info.ProcessorFeatureBits & CPU_FEATURE_AVX))
......@@ -2548,8 +2546,8 @@ void DECLSPEC_HIDDEN call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, B
context.SegGs = ds64_sel;
context.SegSs = ds64_sel;
context.EFlags = 0x200;
context.u.FltSave.ControlWord = 0x27f;
context.u.FltSave.MxCsr = context.MxCsr = 0x1f80;
context.FltSave.ControlWord = 0x27f;
context.FltSave.MxCsr = context.MxCsr = 0x1f80;
if ((wow_context = get_cpu_area( IMAGE_FILE_MACHINE_I386 )))
{
......@@ -2565,8 +2563,8 @@ void DECLSPEC_HIDDEN call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, B
wow_context->SegGs = context.SegGs;
wow_context->SegSs = context.SegSs;
wow_context->EFlags = 0x202;
wow_context->FloatSave.ControlWord = context.u.FltSave.ControlWord;
*(XSAVE_FORMAT *)wow_context->ExtendedRegisters = context.u.FltSave;
wow_context->FloatSave.ControlWord = context.FltSave.ControlWord;
*(XSAVE_FORMAT *)wow_context->ExtendedRegisters = context.FltSave;
}
if (suspend) wait_suspend( &context );
......
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