Message ID | 20210918184527.408540-9-richard.henderson@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | linux-user: Streamline handling of SIGSEGV | expand |
> On Sep 18, 2021, at 12:44 PM, Richard Henderson <richard.henderson@linaro.org> wrote: > > Split host_signal_pc and host_signal_write out of user-exec.c. > Drop the *BSD code, to be re-created under bsd-user/ later. > > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > linux-user/host/ppc/host-signal.h | 25 ++++++++- > linux-user/host/ppc64/host-signal.h | 2 +- > accel/tcg/user-exec.c | 79 +---------------------------- > 3 files changed, 26 insertions(+), 80 deletions(-) This is going to be a little work for me, but I’ll be able to snag most of it from the - lines in this patch. It’s a better structure, to be honest, since we were building user-exec.c for some platforms that never really had bsd-user and a natural consequence of this patch will stop that. Reviewed-by: Warner Losh <imp@bsdimp.com> > diff --git a/linux-user/host/ppc/host-signal.h b/linux-user/host/ppc/host-signal.h > index f4b4d65031..e09756c691 100644 > --- a/linux-user/host/ppc/host-signal.h > +++ b/linux-user/host/ppc/host-signal.h > @@ -1 +1,24 @@ > -#define HOST_SIGNAL_PLACEHOLDER > +/* > + * host-signal.h: signal info dependent on the host architecture > + * > + * Copyright (C) 2021 Linaro Limited > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or later. > + * See the COPYING file in the top-level directory. > + */ > + > +#ifndef PPC_HOST_SIGNAL_H > +#define PPC_HOST_SIGNAL_H > + > +static inline uintptr_t host_signal_pc(ucontext_t *uc) > +{ > + return uc->uc_mcontext.regs->nip; > +} > + > +static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) > +{ > + return uc->uc_mcontext.regs->trap != 0x400 > + && (uc->uc_mcontext.regs->dsisr & 0x02000000); > +} > + > +#endif > diff --git a/linux-user/host/ppc64/host-signal.h b/linux-user/host/ppc64/host-signal.h > index f4b4d65031..a353c22a90 100644 > --- a/linux-user/host/ppc64/host-signal.h > +++ b/linux-user/host/ppc64/host-signal.h > @@ -1 +1 @@ > -#define HOST_SIGNAL_PLACEHOLDER > +#include "../ppc/host-signal.h" > diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c > index b5d06183db..e9e530e2e1 100644 > --- a/accel/tcg/user-exec.c > +++ b/accel/tcg/user-exec.c > @@ -255,84 +255,7 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, > return size ? g2h(env_cpu(env), addr) : NULL; > } > > -#if defined(_ARCH_PPC) > - > -/*********************************************************************** > - * signal context platform-specific definitions > - * From Wine > - */ > -#ifdef linux > -/* All Registers access - only for local access */ > -#define REG_sig(reg_name, context) \ > - ((context)->uc_mcontext.regs->reg_name) > -/* Gpr Registers access */ > -#define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context) > -/* Program counter */ > -#define IAR_sig(context) REG_sig(nip, context) > -/* Machine State Register (Supervisor) */ > -#define MSR_sig(context) REG_sig(msr, context) > -/* Count register */ > -#define CTR_sig(context) REG_sig(ctr, context) > -/* User's integer exception register */ > -#define XER_sig(context) REG_sig(xer, context) > -/* Link register */ > -#define LR_sig(context) REG_sig(link, context) > -/* Condition register */ > -#define CR_sig(context) REG_sig(ccr, context) > - > -/* Float Registers access */ > -#define FLOAT_sig(reg_num, context) \ > - (((double *)((char *)((context)->uc_mcontext.regs + 48 * 4)))[reg_num]) > -#define FPSCR_sig(context) \ > - (*(int *)((char *)((context)->uc_mcontext.regs + (48 + 32 * 2) * 4))) > -/* Exception Registers access */ > -#define DAR_sig(context) REG_sig(dar, context) > -#define DSISR_sig(context) REG_sig(dsisr, context) > -#define TRAP_sig(context) REG_sig(trap, context) > -#endif /* linux */ > - > -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) > -#include <ucontext.h> > -#define IAR_sig(context) ((context)->uc_mcontext.mc_srr0) > -#define MSR_sig(context) ((context)->uc_mcontext.mc_srr1) > -#define CTR_sig(context) ((context)->uc_mcontext.mc_ctr) > -#define XER_sig(context) ((context)->uc_mcontext.mc_xer) > -#define LR_sig(context) ((context)->uc_mcontext.mc_lr) > -#define CR_sig(context) ((context)->uc_mcontext.mc_cr) > -/* Exception Registers access */ > -#define DAR_sig(context) ((context)->uc_mcontext.mc_dar) > -#define DSISR_sig(context) ((context)->uc_mcontext.mc_dsisr) > -#define TRAP_sig(context) ((context)->uc_mcontext.mc_exc) > -#endif /* __FreeBSD__|| __FreeBSD_kernel__ */ > - > -int cpu_signal_handler(int host_signum, void *pinfo, > - void *puc) > -{ > - siginfo_t *info = pinfo; > -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) > - ucontext_t *uc = puc; > -#else > - ucontext_t *uc = puc; > -#endif > - unsigned long pc; > - int is_write; > - > - pc = IAR_sig(uc); > - is_write = 0; > -#if 0 > - /* ppc 4xx case */ > - if (DSISR_sig(uc) & 0x00800000) { > - is_write = 1; > - } > -#else > - if (TRAP_sig(uc) != 0x400 && (DSISR_sig(uc) & 0x02000000)) { > - is_write = 1; > - } > -#endif > - return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); > -} > - > -#elif defined(__alpha__) > +#if defined(__alpha__) > > int cpu_signal_handler(int host_signum, void *pinfo, > void *puc) > -- > 2.25.1 > >
diff --git a/linux-user/host/ppc/host-signal.h b/linux-user/host/ppc/host-signal.h index f4b4d65031..e09756c691 100644 --- a/linux-user/host/ppc/host-signal.h +++ b/linux-user/host/ppc/host-signal.h @@ -1 +1,24 @@ -#define HOST_SIGNAL_PLACEHOLDER +/* + * host-signal.h: signal info dependent on the host architecture + * + * Copyright (C) 2021 Linaro Limited + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef PPC_HOST_SIGNAL_H +#define PPC_HOST_SIGNAL_H + +static inline uintptr_t host_signal_pc(ucontext_t *uc) +{ + return uc->uc_mcontext.regs->nip; +} + +static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) +{ + return uc->uc_mcontext.regs->trap != 0x400 + && (uc->uc_mcontext.regs->dsisr & 0x02000000); +} + +#endif diff --git a/linux-user/host/ppc64/host-signal.h b/linux-user/host/ppc64/host-signal.h index f4b4d65031..a353c22a90 100644 --- a/linux-user/host/ppc64/host-signal.h +++ b/linux-user/host/ppc64/host-signal.h @@ -1 +1 @@ -#define HOST_SIGNAL_PLACEHOLDER +#include "../ppc/host-signal.h" diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index b5d06183db..e9e530e2e1 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -255,84 +255,7 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, return size ? g2h(env_cpu(env), addr) : NULL; } -#if defined(_ARCH_PPC) - -/*********************************************************************** - * signal context platform-specific definitions - * From Wine - */ -#ifdef linux -/* All Registers access - only for local access */ -#define REG_sig(reg_name, context) \ - ((context)->uc_mcontext.regs->reg_name) -/* Gpr Registers access */ -#define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context) -/* Program counter */ -#define IAR_sig(context) REG_sig(nip, context) -/* Machine State Register (Supervisor) */ -#define MSR_sig(context) REG_sig(msr, context) -/* Count register */ -#define CTR_sig(context) REG_sig(ctr, context) -/* User's integer exception register */ -#define XER_sig(context) REG_sig(xer, context) -/* Link register */ -#define LR_sig(context) REG_sig(link, context) -/* Condition register */ -#define CR_sig(context) REG_sig(ccr, context) - -/* Float Registers access */ -#define FLOAT_sig(reg_num, context) \ - (((double *)((char *)((context)->uc_mcontext.regs + 48 * 4)))[reg_num]) -#define FPSCR_sig(context) \ - (*(int *)((char *)((context)->uc_mcontext.regs + (48 + 32 * 2) * 4))) -/* Exception Registers access */ -#define DAR_sig(context) REG_sig(dar, context) -#define DSISR_sig(context) REG_sig(dsisr, context) -#define TRAP_sig(context) REG_sig(trap, context) -#endif /* linux */ - -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -#include <ucontext.h> -#define IAR_sig(context) ((context)->uc_mcontext.mc_srr0) -#define MSR_sig(context) ((context)->uc_mcontext.mc_srr1) -#define CTR_sig(context) ((context)->uc_mcontext.mc_ctr) -#define XER_sig(context) ((context)->uc_mcontext.mc_xer) -#define LR_sig(context) ((context)->uc_mcontext.mc_lr) -#define CR_sig(context) ((context)->uc_mcontext.mc_cr) -/* Exception Registers access */ -#define DAR_sig(context) ((context)->uc_mcontext.mc_dar) -#define DSISR_sig(context) ((context)->uc_mcontext.mc_dsisr) -#define TRAP_sig(context) ((context)->uc_mcontext.mc_exc) -#endif /* __FreeBSD__|| __FreeBSD_kernel__ */ - -int cpu_signal_handler(int host_signum, void *pinfo, - void *puc) -{ - siginfo_t *info = pinfo; -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - ucontext_t *uc = puc; -#else - ucontext_t *uc = puc; -#endif - unsigned long pc; - int is_write; - - pc = IAR_sig(uc); - is_write = 0; -#if 0 - /* ppc 4xx case */ - if (DSISR_sig(uc) & 0x00800000) { - is_write = 1; - } -#else - if (TRAP_sig(uc) != 0x400 && (DSISR_sig(uc) & 0x02000000)) { - is_write = 1; - } -#endif - return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); -} - -#elif defined(__alpha__) +#if defined(__alpha__) int cpu_signal_handler(int host_signum, void *pinfo, void *puc)
Split host_signal_pc and host_signal_write out of user-exec.c. Drop the *BSD code, to be re-created under bsd-user/ later. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- linux-user/host/ppc/host-signal.h | 25 ++++++++- linux-user/host/ppc64/host-signal.h | 2 +- accel/tcg/user-exec.c | 79 +---------------------------- 3 files changed, 26 insertions(+), 80 deletions(-)