From c93f39ca5b859f02c90c6a9940831d8a3a989afb Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 12 Nov 2016 10:44:18 +0000 Subject: [PATCH] syscall.c: factor out ptrace_getregs from get_regs Move the code that calls ptrace(PTRACE_GETREGS) to a separate function. * syscall.c (ptrace_getregs): New function. (get_regs): Use it. --- syscall.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/syscall.c b/syscall.c index 7d0cc738..966c3542 100644 --- a/syscall.c +++ b/syscall.c @@ -1250,7 +1250,21 @@ ptrace_getregset(pid_t pid) # endif } -#endif /* ARCH_REGS_FOR_GETREGSET */ + +#elif defined ARCH_REGS_FOR_GETREGS + +static long +ptrace_getregs(pid_t pid) +{ +# if defined SPARC || defined SPARC64 + /* SPARC systems have the meaning of data and addr reversed */ + return ptrace(PTRACE_GETREGS, pid, (void *) &ARCH_REGS_FOR_GETREGS, 0); +# else + return ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS); +# endif +} + +#endif /* ARCH_REGS_FOR_GETREGSET || ARCH_REGS_FOR_GETREGS */ void get_regs(pid_t pid) @@ -1279,15 +1293,11 @@ get_regs(pid_t pid) get_regs_error = ptrace_getregset(pid); # endif #elif defined ARCH_REGS_FOR_GETREGS -# if defined SPARC || defined SPARC64 - /* SPARC systems have the meaning of data and addr reversed */ - get_regs_error = - ptrace(PTRACE_GETREGS, pid, (void *) &ARCH_REGS_FOR_GETREGS, 0); -# elif defined POWERPC +# ifdef POWERPC static bool old_kernel = 0; if (old_kernel) goto old; - get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS); + get_regs_error = ptrace_getregs(pid); if (get_regs_error && errno == EIO) { old_kernel = 1; old: @@ -1295,7 +1305,7 @@ get_regs(pid_t pid) } # else /* Assume that PTRACE_GETREGS works. */ - get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS); + get_regs_error = ptrace_getregs(pid); # endif #else /* !ARCH_REGS_FOR_GETREGSET && !ARCH_REGS_FOR_GETREGS */