aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Branco <rbranco@suse.de>2026-04-26 14:43:59 +0000
committerPouria Mousavizadeh Tehrani <pouria@FreeBSD.org>2026-06-02 07:25:34 +0000
commitb84d31ee74535a0026ff83f2a34c07b7557f9785 (patch)
tree8206869a7fa457cf430be72eb750903d4924ca18
parent7b26353a59d66dc1bc611fd042a49b9e3bd13699 (diff)
linux: Add linux_pt_fpregset and bsd_to_linux_fpregset() for amd64
Add struct linux_pt_fpregset, the amd64 Linux NT_PRFPREG payload, corresponding to user_i387_struct in Linux. The struct describes the 512-byte FXSAVE area as exposed by PTRACE_GETREGSET. Add bsd_to_linux_fpregset() to translate from FreeBSD's struct fpreg to struct linux_pt_fpregset. Fields are extracted from the fpr_env[] array which stores the FXSAVE environment packed as four 64-bit words. The FP and XMM register banks are bulk-copied as opaque byte arrays. Signed-off-by: Ricardo Branco <rbranco@suse.de> Reviewed by: kib Pull-Request: https://github.com/freebsd/freebsd-src/pull/2165
-rw-r--r--sys/amd64/linux/linux.h18
-rw-r--r--sys/amd64/linux/linux_machdep.c20
2 files changed, 38 insertions, 0 deletions
diff --git a/sys/amd64/linux/linux.h b/sys/amd64/linux/linux.h
index fb7aaa2d731c..8e025b73dbd8 100644
--- a/sys/amd64/linux/linux.h
+++ b/sys/amd64/linux/linux.h
@@ -237,14 +237,32 @@ struct linux_pt_regset {
l_ulong gs;
};
+/* This corresponds to 'user_i387_struct' in Linux. */
+struct linux_pt_fpregset {
+ l_ushort cwd;
+ l_ushort swd;
+ l_ushort twd;
+ l_ushort fop;
+ uint64_t rip;
+ uint64_t rdp;
+ uint32_t mxcsr;
+ uint32_t mxcsr_mask;
+ uint32_t st_space[32];
+ uint32_t xmm_space[64];
+ uint32_t padding[24];
+};
+
#ifdef _KERNEL
struct reg;
+struct fpreg;
struct syscall_info;
void bsd_to_linux_regset(const struct reg *b_reg,
struct linux_pt_regset *l_regset);
void linux_to_bsd_regset(struct reg *b_reg,
const struct linux_pt_regset *l_regset);
+void bsd_to_linux_fpregset(const struct fpreg *b_fpreg,
+ struct linux_pt_fpregset *l_fpregset);
void linux_ptrace_get_syscall_info_machdep(const struct reg *reg,
struct syscall_info *si);
int linux_ptrace_getregs_machdep(struct thread *td, pid_t pid,
diff --git a/sys/amd64/linux/linux_machdep.c b/sys/amd64/linux/linux_machdep.c
index 7ec1ec56bb95..e05f824cbea1 100644
--- a/sys/amd64/linux/linux_machdep.c
+++ b/sys/amd64/linux/linux_machdep.c
@@ -282,6 +282,26 @@ linux_to_bsd_regset(struct reg *b_reg, const struct linux_pt_regset *l_regset)
}
void
+bsd_to_linux_fpregset(const struct fpreg *b_fpreg,
+ struct linux_pt_fpregset *l_fpregset)
+{
+ l_fpregset->cwd = b_fpreg->fpr_env[0];
+ l_fpregset->swd = b_fpreg->fpr_env[0] >> 16;
+ l_fpregset->twd = b_fpreg->fpr_env[0] >> 32;
+ l_fpregset->fop = b_fpreg->fpr_env[0] >> 48;
+ l_fpregset->rip = b_fpreg->fpr_env[1];
+ l_fpregset->rdp = b_fpreg->fpr_env[2];
+ l_fpregset->mxcsr = b_fpreg->fpr_env[3];
+ l_fpregset->mxcsr_mask = b_fpreg->fpr_env[3] >> 32;
+
+ memcpy(l_fpregset->st_space, b_fpreg->fpr_acc,
+ sizeof(l_fpregset->st_space));
+ memcpy(l_fpregset->xmm_space, b_fpreg->fpr_xacc,
+ sizeof(l_fpregset->xmm_space));
+ memset(l_fpregset->padding, 0, sizeof(l_fpregset->padding));
+}
+
+void
linux_ptrace_get_syscall_info_machdep(const struct reg *reg,
struct syscall_info *si)
{