From: Dmitry V. Levin Date: Thu, 4 Jul 2019 18:25:49 +0000 (+0000) Subject: sparc, sparc64: refactor arch_set_error and arch_set_success X-Git-Tag: v5.2~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a9175347d6ca43117685a38a2d8799665c516f38;p=strace sparc, sparc64: refactor arch_set_error and arch_set_success * linux/sparc/set_error.c (sparc_set_o0_psr): New function. (arch_set_error, arch_set_success): Use it. * linux/sparc64/set_error.c (sparc64_set_o0_tstate): New function. (arch_set_error, arch_set_success): Use it. --- diff --git a/linux/sparc/set_error.c b/linux/sparc/set_error.c index 1679df0f..0e5d143f 100644 --- a/linux/sparc/set_error.c +++ b/linux/sparc/set_error.c @@ -6,21 +6,25 @@ */ static int -arch_set_error(struct tcb *tcp) +sparc_set_o0_psr(struct tcb *tcp, const unsigned long o0, + const unsigned long psr_set, const unsigned long psr_clear) { if (ptrace_syscall_info_is_valid() && get_regs(tcp) < 0) return -1; - sparc_regs.psr |= PSR_C; - sparc_regs.u_regs[U_REG_O0] = tcp->u_error; + sparc_regs.u_regs[U_REG_O0] = o0; + sparc_regs.psr |= psr_set; + sparc_regs.psr &= ~psr_clear; return set_regs(tcp->pid); } +static int +arch_set_error(struct tcb *tcp) +{ + return sparc_set_o0_psr(tcp, tcp->u_error, PSR_C, 0); +} + static int arch_set_success(struct tcb *tcp) { - if (ptrace_syscall_info_is_valid() && get_regs(tcp) < 0) - return -1; - sparc_regs.psr &= ~PSR_C; - sparc_regs.u_regs[U_REG_O0] = tcp->u_rval; - return set_regs(tcp->pid); + return sparc_set_o0_psr(tcp, tcp->u_rval, 0, PSR_C); } diff --git a/linux/sparc64/set_error.c b/linux/sparc64/set_error.c index 290fad34..846b7ddd 100644 --- a/linux/sparc64/set_error.c +++ b/linux/sparc64/set_error.c @@ -6,21 +6,26 @@ */ static int -arch_set_error(struct tcb *tcp) +sparc64_set_o0_tstate(struct tcb *tcp, const unsigned long o0, + const unsigned long tstate_set, + const unsigned long tstate_clear) { if (ptrace_syscall_info_is_valid() && get_regs(tcp) < 0) return -1; - sparc_regs.tstate |= 0x1100000000UL; - sparc_regs.u_regs[U_REG_O0] = tcp->u_error; + sparc_regs.u_regs[U_REG_O0] = o0; + sparc_regs.tstate |= tstate_set; + sparc_regs.tstate &= ~tstate_clear; return set_regs(tcp->pid); } +static int +arch_set_error(struct tcb *tcp) +{ + return sparc64_set_o0_tstate(tcp, tcp->u_error, 0x1100000000UL, 0); +} + static int arch_set_success(struct tcb *tcp) { - if (ptrace_syscall_info_is_valid() && get_regs(tcp) < 0) - return -1; - sparc_regs.tstate &= ~0x1100000000UL; - sparc_regs.u_regs[U_REG_O0] = tcp->u_rval; - return set_regs(tcp->pid); + return sparc64_set_o0_tstate(tcp, tcp->u_rval, 0, 0x1100000000UL); }