Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit bf15d88

Browse files
committed
Merge pull request #3095 from krytarowski/netbsd-support-38
Add support for Floating Point registers in ucontext_t on NetBSD
2 parents 57793e3 + 6cb0c4b commit bf15d88

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/pal/src/include/pal/context.h

+14
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ typedef ucontext_t native_context_t;
6868
#define MCREG_R15(mc) ((mc).__gregs[_REG_R15])
6969
#define MCREG_EFlags(mc) ((mc).__gregs[_REG_RFLAGS])
7070

71+
#define FPREG_Xmm(uc, index) *(M128A*)&(((struct fxsave*)(&(uc)->uc_mcontext.__fpregs))->fx_xmm[index])
72+
73+
#define FPREG_St(uc, index) *(M128A*)&(((struct fxsave*)(&(uc)->uc_mcontext.__fpregs))->fx_87_ac[index])
74+
75+
#define FPREG_ControlWord(uc) (((struct fxsave*)(&(uc)->uc_mcontext.__fpregs))->fx_cw)
76+
#define FPREG_StatusWord(uc) (((struct fxsave*)(&(uc)->uc_mcontext.__fpregs))->fx_sw)
77+
#define FPREG_TagWord(uc) (((struct fxsave*)(&(uc)->uc_mcontext.__fpregs))->fx_tw)
78+
#define FPREG_ErrorOffset(uc) (*(DWORD*) &(((struct fxsave*)(&(uc)->uc_mcontext.__fpregs))->fx_ip))
79+
#define FPREG_ErrorSelector(uc) *((WORD*) &(((struct fxsave*)(&(uc)->uc_mcontext.__fpregs))->fx_ip) + 2)
80+
#define FPREG_DataOffset(uc) (*(DWORD*) &(((struct fxsave*)(&(uc)->uc_mcontext.__fpregs))->fx_dp))
81+
#define FPREG_DataSelector(uc) *((WORD*) &(((struct fxsave*)(&(uc)->uc_mcontext.__fpregs))->fx_dp) + 2)
82+
#define FPREG_MxCsr(uc) (((struct fxsave*)(&(uc)->uc_mcontext.__fpregs))->fx_mxcsr)
83+
#define FPREG_MxCsr_Mask(uc) (((struct fxsave*)(&(uc)->uc_mcontext.__fpregs))->fx_mxcsr_mask)
84+
7185
#else // BIT64
7286

7387
#define MCREG_Ebx(mc) ((mc).__gregs[_REG_EBX])

src/pal/src/thread/context.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,12 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native)
423423
}
424424
#undef ASSIGN_REG
425425

426+
#if HAVE_GREGSET_T || HAVE_GREGSET_T
426427
#if HAVE_GREGSET_T
427428
if (native->uc_mcontext.fpregs == nullptr)
429+
#elif HAVE___GREGSET_T
430+
if (native->uc_mcontext.__fpregs == nullptr)
431+
#endif
428432
{
429433
// If the pointer to the floating point state in the native context
430434
// is not valid, we can't copy floating point registers regardless of
@@ -492,8 +496,12 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex
492496
}
493497
#undef ASSIGN_REG
494498

499+
#if HAVE_GREGSET_T || HAVE___GREGSET_T
495500
#if HAVE_GREGSET_T
496501
if (native->uc_mcontext.fpregs == nullptr)
502+
#elif HAVE___GREGSET_T
503+
if (native->uc_mcontext.__fpregs == nullptr)
504+
#endif
497505
{
498506
// Reset the CONTEXT_FLOATING_POINT bit(s) so it's clear that the floating point
499507
// data in the CONTEXT is not valid. Since CONTEXT_FLOATING_POINT is defined as

0 commit comments

Comments
 (0)