linux: refactor bsd_to_linux_regset() out of linux_ptrace.c

This will be used for Linux coredump support.

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D30365
This commit is contained in:
Edward Tomasz Napierala 2021-05-21 07:22:25 +01:00
parent eedbbec3fd
commit 95c19e1d65
4 changed files with 93 additions and 39 deletions

View File

@ -446,4 +446,40 @@ struct linux_robust_list_head {
l_uintptr_t pending_list; l_uintptr_t pending_list;
}; };
/* This corresponds to 'struct user_regs_struct' in Linux. */
struct linux_pt_regset {
l_ulong r15;
l_ulong r14;
l_ulong r13;
l_ulong r12;
l_ulong rbp;
l_ulong rbx;
l_ulong r11;
l_ulong r10;
l_ulong r9;
l_ulong r8;
l_ulong rax;
l_ulong rcx;
l_ulong rdx;
l_ulong rsi;
l_ulong rdi;
l_ulong orig_rax;
l_ulong rip;
l_ulong cs;
l_ulong eflags;
l_ulong rsp;
l_ulong ss;
l_ulong fs_base;
l_ulong gs_base;
l_ulong ds;
l_ulong es;
l_ulong fs;
l_ulong gs;
};
struct reg;
void bsd_to_linux_regset(struct reg *b_reg,
struct linux_pt_regset *l_regset);
#endif /* !_AMD64_LINUX_H_ */ #endif /* !_AMD64_LINUX_H_ */

View File

@ -173,36 +173,6 @@ struct linux_pt_reg {
l_ulong ss; l_ulong ss;
}; };
struct linux_pt_regset {
l_ulong r15;
l_ulong r14;
l_ulong r13;
l_ulong r12;
l_ulong rbp;
l_ulong rbx;
l_ulong r11;
l_ulong r10;
l_ulong r9;
l_ulong r8;
l_ulong rax;
l_ulong rcx;
l_ulong rdx;
l_ulong rsi;
l_ulong rdi;
l_ulong orig_rax;
l_ulong rip;
l_ulong cs;
l_ulong eflags;
l_ulong rsp;
l_ulong ss;
l_ulong fs_base;
l_ulong gs_base;
l_ulong ds;
l_ulong es;
l_ulong fs;
l_ulong gs;
};
/* /*
* Translate amd64 ptrace registers between Linux and FreeBSD formats. * Translate amd64 ptrace registers between Linux and FreeBSD formats.
* The translation is pretty straighforward, for all registers but * The translation is pretty straighforward, for all registers but
@ -235,9 +205,8 @@ map_regs_to_linux(struct reg *b_reg, struct linux_pt_reg *l_reg)
l_reg->ss = b_reg->r_ss; l_reg->ss = b_reg->r_ss;
} }
static void void
map_regs_to_linux_regset(struct reg *b_reg, unsigned long fs_base, bsd_to_linux_regset(struct reg *b_reg, struct linux_pt_regset *l_regset)
unsigned long gs_base, struct linux_pt_regset *l_regset)
{ {
l_regset->r15 = b_reg->r_r15; l_regset->r15 = b_reg->r_r15;
@ -261,8 +230,8 @@ map_regs_to_linux_regset(struct reg *b_reg, unsigned long fs_base,
l_regset->eflags = b_reg->r_rflags; l_regset->eflags = b_reg->r_rflags;
l_regset->rsp = b_reg->r_rsp; l_regset->rsp = b_reg->r_rsp;
l_regset->ss = b_reg->r_ss; l_regset->ss = b_reg->r_ss;
l_regset->fs_base = fs_base; l_regset->fs_base = 0;
l_regset->gs_base = gs_base; l_regset->gs_base = 0;
l_regset->ds = b_reg->r_ds; l_regset->ds = b_reg->r_ds;
l_regset->es = b_reg->r_es; l_regset->es = b_reg->r_es;
l_regset->fs = b_reg->r_fs; l_regset->fs = b_reg->r_fs;
@ -477,7 +446,6 @@ linux_ptrace_getregset_prstatus(struct thread *td, pid_t pid, l_ulong data)
struct linux_pt_regset l_regset; struct linux_pt_regset l_regset;
struct iovec iov; struct iovec iov;
struct pcb *pcb; struct pcb *pcb;
unsigned long fsbase, gsbase;
size_t len; size_t len;
int error; int error;
@ -494,10 +462,10 @@ linux_ptrace_getregset_prstatus(struct thread *td, pid_t pid, l_ulong data)
pcb = td->td_pcb; pcb = td->td_pcb;
if (td == curthread) if (td == curthread)
update_pcb_bases(pcb); update_pcb_bases(pcb);
fsbase = pcb->pcb_fsbase;
gsbase = pcb->pcb_gsbase;
map_regs_to_linux_regset(&b_reg, fsbase, gsbase, &l_regset); bsd_to_linux_regset(&b_reg, &l_regset);
l_regset.fs_base = pcb->pcb_fsbase;
l_regset.gs_base = pcb->pcb_gsbase;
error = kern_ptrace(td, PT_LWPINFO, pid, &lwpinfo, sizeof(lwpinfo)); error = kern_ptrace(td, PT_LWPINFO, pid, &lwpinfo, sizeof(lwpinfo));
if (error != 0) { if (error != 0) {

View File

@ -630,4 +630,30 @@ struct linux_robust_list_head {
l_uintptr_t pending_list; l_uintptr_t pending_list;
}; };
/* This corresponds to 'struct user_regs_struct32' in Linux. */
struct linux_pt_regset32 {
l_uint ebx;
l_uint ecx;
l_uint edx;
l_uint esi;
l_uint edi;
l_uint ebp;
l_uint eax;
l_uint ds;
l_uint es;
l_uint fs;
l_uint gs;
l_uint orig_eax;
l_uint eip;
l_uint cs;
l_uint eflags;
l_uint esp;
l_uint ss;
};
struct reg32;
void bsd_to_linux_regset32(struct reg32 *b_reg,
struct linux_pt_regset32 *l_regset);
#endif /* !_AMD64_LINUX_H_ */ #endif /* !_AMD64_LINUX_H_ */

View File

@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$");
#include <machine/md_var.h> #include <machine/md_var.h>
#include <machine/pcb.h> #include <machine/pcb.h>
#include <machine/psl.h> #include <machine/psl.h>
#include <machine/reg.h>
#include <machine/segments.h> #include <machine/segments.h>
#include <machine/specialreg.h> #include <machine/specialreg.h>
#include <x86/ifunc.h> #include <x86/ifunc.h>
@ -721,6 +722,29 @@ linux_set_thread_area(struct thread *td,
return (0); return (0);
} }
void
bsd_to_linux_regset32(struct reg32 *b_reg, struct linux_pt_regset32 *l_regset)
{
l_regset->ebx = b_reg->r_ebx;
l_regset->ecx = b_reg->r_ecx;
l_regset->edx = b_reg->r_edx;
l_regset->esi = b_reg->r_esi;
l_regset->edi = b_reg->r_edi;
l_regset->ebp = b_reg->r_ebp;
l_regset->eax = b_reg->r_eax;
l_regset->ds = b_reg->r_ds;
l_regset->es = b_reg->r_es;
l_regset->fs = b_reg->r_fs;
l_regset->gs = b_reg->r_gs;
l_regset->orig_eax = b_reg->r_eax;
l_regset->eip = b_reg->r_eip;
l_regset->cs = b_reg->r_cs;
l_regset->eflags = b_reg->r_eflags;
l_regset->esp = b_reg->r_esp;
l_regset->ss = b_reg->r_ss;
}
int futex_xchgl_nosmap(int oparg, uint32_t *uaddr, int *oldval); int futex_xchgl_nosmap(int oparg, uint32_t *uaddr, int *oldval);
int futex_xchgl_smap(int oparg, uint32_t *uaddr, int *oldval); int futex_xchgl_smap(int oparg, uint32_t *uaddr, int *oldval);
DEFINE_IFUNC(, int, futex_xchgl, (int, uint32_t *, int *)) DEFINE_IFUNC(, int, futex_xchgl, (int, uint32_t *, int *))