From: Dmitry V. Levin Date: Mon, 30 Nov 2015 00:01:01 +0000 (+0000) Subject: cleanup: make get_syscall_result.c files more readable X-Git-Tag: v4.11~85 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f51aec6abfad5dae5f3dd77365c2f8275e37437d;p=strace cleanup: make get_syscall_result.c files more readable Make get_syscall_result.c files more self-contained. While they are still being included by syscall.c, the latter no longer provides a function framework for them. * linux/alpha/get_syscall_result.c (get_syscall_result_regs): Define. * linux/bfin/get_syscall_result.c: Likewise. * linux/crisv10/get_syscall_result.c: Likewise. * linux/hppa/get_syscall_result.c: Likewise. * linux/m68k/get_syscall_result.c: Likewise. * linux/microblaze/get_syscall_result.c: Likewise. * linux/sh/get_syscall_result.c: Likewise. * linux/sh64/get_syscall_result.c: Likewise. * linux/xtensa/get_syscall_result.c: Likewise. * syscall.c [!ARCH_REGS_FOR_GETREGSET && !ARCH_REGS_FOR_GETREGS]: Define USE_GET_SYSCALL_RESULT_REGS macro. [USE_GET_SYSCALL_RESULT_REGS]: Include "get_syscall_result.c". (get_syscall_result) [USE_GET_SYSCALL_RESULT_REGS]: Stop including "get_syscall_result.c". Call get_syscall_result_regs. Requested-by: Denys Vlasenko --- diff --git a/linux/alpha/get_syscall_result.c b/linux/alpha/get_syscall_result.c index 11e27362..f4c504f1 100644 --- a/linux/alpha/get_syscall_result.c +++ b/linux/alpha/get_syscall_result.c @@ -1,4 +1,6 @@ -if (upeek(tcp->pid, REG_A3, &alpha_a3) < 0) - return -1; -if (upeek(tcp->pid, REG_R0, &alpha_r0) < 0) - return -1; +static int +get_syscall_result_regs(struct tcb *tcp) +{ + return (upeek(tcp->pid, REG_A3, &alpha_a3) < 0 || + upeek(tcp->pid, REG_R0, &alpha_r0) < 0) ? -1 : 0; +} diff --git a/linux/bfin/get_syscall_result.c b/linux/bfin/get_syscall_result.c index c9d94d48..c189a5fd 100644 --- a/linux/bfin/get_syscall_result.c +++ b/linux/bfin/get_syscall_result.c @@ -1,2 +1,5 @@ -if (upeek(tcp->pid, PT_R0, &bfin_r0) < 0) - return -1; +static int +get_syscall_result_regs(struct tcb *tcp) +{ + return upeek(tcp->pid, PT_R0, &bfin_r0) < 0 ? -1 : 0; +} diff --git a/linux/crisv10/get_syscall_result.c b/linux/crisv10/get_syscall_result.c index 53b087a3..6b3679c1 100644 --- a/linux/crisv10/get_syscall_result.c +++ b/linux/crisv10/get_syscall_result.c @@ -1,2 +1,5 @@ -if (upeek(tcp->pid, 4*PT_R10, &cris_r10) < 0) - return -1; +static int +get_syscall_result_regs(struct tcb *tcp) +{ + return upeek(tcp->pid, 4 * PT_R10, &cris_r10) < 0 ? -1 : 0; +} diff --git a/linux/hppa/get_syscall_result.c b/linux/hppa/get_syscall_result.c index d929b9f1..0d15d4db 100644 --- a/linux/hppa/get_syscall_result.c +++ b/linux/hppa/get_syscall_result.c @@ -1,2 +1,5 @@ -if (upeek(tcp->pid, PT_GR28, &hppa_r28) < 0) - return -1; +static int +get_syscall_result_regs(struct tcb *tcp) +{ + return upeek(tcp->pid, PT_GR28, &hppa_r28) < 0 ? -1 : 0; +} diff --git a/linux/m68k/get_syscall_result.c b/linux/m68k/get_syscall_result.c index fc452b49..005cf60c 100644 --- a/linux/m68k/get_syscall_result.c +++ b/linux/m68k/get_syscall_result.c @@ -1,2 +1,5 @@ -if (upeek(tcp->pid, 4*PT_D0, &m68k_d0) < 0) - return -1; +static int +get_syscall_result_regs(struct tcb *tcp) +{ + return upeek(tcp->pid, 4 * PT_D0, &m68k_d0) < 0 ? -1 : 0; +} diff --git a/linux/microblaze/get_syscall_result.c b/linux/microblaze/get_syscall_result.c index b7ec27f2..9ece53e8 100644 --- a/linux/microblaze/get_syscall_result.c +++ b/linux/microblaze/get_syscall_result.c @@ -1,2 +1,5 @@ -if (upeek(tcp->pid, 3 * 4, µblaze_r3) < 0) - return -1; +static int +get_syscall_result_regs(struct tcb *tcp) +{ + return upeek(tcp->pid, 3 * 4, µblaze_r3) < 0 ? -1 : 0; +} diff --git a/linux/sh/get_syscall_result.c b/linux/sh/get_syscall_result.c index 3ee05467..5db30254 100644 --- a/linux/sh/get_syscall_result.c +++ b/linux/sh/get_syscall_result.c @@ -1,3 +1,6 @@ -/* new syscall ABI returns result in R0 */ -if (upeek(tcp->pid, 4*REG_REG0, (long *)&sh_r0) < 0) - return -1; +static int +get_syscall_result_regs(struct tcb *tcp) +{ + /* new syscall ABI returns result in R0 */ + return upeek(tcp->pid, 4 * REG_REG0, (long *)&sh_r0) < 0 ? -1 : 0; +} diff --git a/linux/sh64/get_syscall_result.c b/linux/sh64/get_syscall_result.c index e53bd0f4..93faf3df 100644 --- a/linux/sh64/get_syscall_result.c +++ b/linux/sh64/get_syscall_result.c @@ -1,3 +1,6 @@ -/* ABI defines result returned in r9 */ -if (upeek(tcp->pid, REG_GENERAL(9), (long *)&sh64_r9) < 0) - return -1; +static int +get_syscall_result_regs(struct tcb *tcp) +{ + /* ABI defines result returned in r9 */ + return upeek(tcp->pid, REG_GENERAL(9), (long *)&sh64_r9) < 0 ? -1 : 0; +} diff --git a/linux/xtensa/get_syscall_result.c b/linux/xtensa/get_syscall_result.c index 0d2e697c..51ad6dea 100644 --- a/linux/xtensa/get_syscall_result.c +++ b/linux/xtensa/get_syscall_result.c @@ -1,2 +1,5 @@ -if (upeek(tcp->pid, REG_A_BASE + 2, &xtensa_a2) < 0) - return -1; +static int +get_syscall_result_regs(struct tcb *tcp) +{ + return upeek(tcp->pid, REG_A_BASE + 2, &xtensa_a2) < 0 ? -1 : 0; +} diff --git a/syscall.c b/syscall.c index 34627f25..9cf3fc54 100644 --- a/syscall.c +++ b/syscall.c @@ -1253,6 +1253,7 @@ get_regset(pid_t pid) void get_regs(pid_t pid) { +#undef USE_GET_SYSCALL_RESULT_REGS #ifdef ARCH_REGS_FOR_GETREGSET # ifdef X86_64 /* Try PTRACE_GETREGSET first, fallback to PTRACE_GETREGS. */ @@ -1295,7 +1296,8 @@ get_regs(pid_t pid) # endif #else /* !ARCH_REGS_FOR_GETREGSET && !ARCH_REGS_FOR_GETREGS */ -# warning get_regs is not implemented for this architecture yet +# define USE_GET_SYSCALL_RESULT_REGS 1 +# warning get_regs is not implemented for this architecture yet get_regs_error = 0; #endif } @@ -1343,6 +1345,9 @@ get_syscall_args(struct tcb *tcp) return 1; } +#ifdef USE_GET_SYSCALL_RESULT_REGS +# include "get_syscall_result.c" +#endif #include "get_error.c" /* Returns: @@ -1353,10 +1358,9 @@ get_syscall_args(struct tcb *tcp) static int get_syscall_result(struct tcb *tcp) { -#if defined ARCH_REGS_FOR_GETREGSET || defined ARCH_REGS_FOR_GETREGS - /* already done by get_regs */ -#else -# include "get_syscall_result.c" +#ifdef USE_GET_SYSCALL_RESULT_REGS + if (get_syscall_result_regs(tcp)) + return -1; #endif tcp->u_error = 0; get_error(tcp, !(tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS));