From: Denys Vlasenko Date: Wed, 13 Feb 2013 15:31:32 +0000 (+0100) Subject: Factor out code to check addr, fetch and print siginfo X-Git-Tag: v4.8~166 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d4d3edefe74787a194a2472d99a673f6d4a2721a;p=strace Factor out code to check addr, fetch and print siginfo * defs.h: Declare new function printsiginfo_at(tcp, addr). * process.c (sys_waitid): Use printsiginfo_at(). (sys_ptrace): Likewise. * signal.c: (printsiginfo_at): Implement this new function. (sys_rt_sigsuspend): Use printsiginfo_at(). (sys_rt_sigtimedwait): Likewise. Signed-off-by: Denys Vlasenko --- diff --git a/defs.h b/defs.h index 068ee3dc..ab474cbc 100644 --- a/defs.h +++ b/defs.h @@ -637,6 +637,7 @@ extern void print_timespec(struct tcb *, long); extern void sprint_timespec(char *, struct tcb *, long); #ifdef HAVE_SIGINFO_T extern void printsiginfo(siginfo_t *, int); +extern void printsiginfo_at(struct tcb *tcp, long addr); #endif extern void printfd(struct tcb *, int); extern void printsock(struct tcb *, long, int); diff --git a/process.c b/process.c index e4d491a2..95eb05d1 100644 --- a/process.c +++ b/process.c @@ -1126,22 +1126,13 @@ static const struct xlat waitid_types[] = { int sys_waitid(struct tcb *tcp) { - siginfo_t si; - if (entering(tcp)) { printxval(waitid_types, tcp->u_arg[0], "P_???"); tprintf(", %ld, ", tcp->u_arg[1]); } else { /* siginfo */ - if (!tcp->u_arg[2]) - tprints("NULL"); - else if (syserror(tcp)) - tprintf("%#lx", tcp->u_arg[2]); - else if (umove(tcp, tcp->u_arg[2], &si) < 0) - tprints("{???}"); - else - printsiginfo(&si, verbose(tcp)); + printsiginfo_at(tcp, tcp->u_arg[2]); /* options */ tprints(", "); printflags(wait4_options, tcp->u_arg[3], "W???"); @@ -2306,15 +2297,7 @@ sys_ptrace(struct tcb *tcp) #endif #ifdef PTRACE_SETSIGINFO case PTRACE_SETSIGINFO: { - siginfo_t si; - if (!tcp->u_arg[3]) - tprints("NULL"); - else if (syserror(tcp)) - tprintf("%#lx", tcp->u_arg[3]); - else if (umove(tcp, tcp->u_arg[3], &si) < 0) - tprints("{???}"); - else - printsiginfo(&si, verbose(tcp)); + printsiginfo_at(tcp, tcp->u_arg[3]); break; } #endif @@ -2347,15 +2330,7 @@ sys_ptrace(struct tcb *tcp) #endif #ifdef PTRACE_GETSIGINFO case PTRACE_GETSIGINFO: { - siginfo_t si; - if (!tcp->u_arg[3]) - tprints("NULL"); - else if (syserror(tcp)) - tprintf("%#lx", tcp->u_arg[3]); - else if (umove(tcp, tcp->u_arg[3], &si) < 0) - tprints("{???}"); - else - printsiginfo(&si, verbose(tcp)); + printsiginfo_at(tcp, tcp->u_arg[3]); break; } #endif diff --git a/signal.c b/signal.c index 5e862ad9..55ff3ed7 100644 --- a/signal.c +++ b/signal.c @@ -671,6 +671,25 @@ printsiginfo(siginfo_t *sip, int verbose) tprints("}"); } +void +printsiginfo_at(struct tcb *tcp, long addr) +{ + siginfo_t si; + if (!addr) { + tprints("NULL"); + return; + } + if (syserror(tcp)) { + tprintf("%#lx", addr); + return; + } + if (umove(tcp, addr, &si) < 0) { + tprints("{???}"); + return; + } + printsiginfo(&si, verbose(tcp)); +} + int sys_sigsetmask(struct tcb *tcp) { @@ -1209,8 +1228,7 @@ sys_rt_sigaction(struct tcb *tcp) tprintf("%#lx", addr); goto after_sa; } -#if SUPPORTED_PERSONALITIES > 1 -#if SIZEOF_LONG > 4 +#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) { struct new_sigaction32 sa32; r = umove(tcp, addr, &sa32); @@ -1230,7 +1248,6 @@ sys_rt_sigaction(struct tcb *tcp) sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32); } } else -#endif #endif { r = umove(tcp, addr, &sa); @@ -1326,14 +1343,9 @@ sys_rt_sigsuspend(struct tcb *tcp) static void print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo) { - siginfo_t si; - printsignal(sig); tprints(", "); - if (umove(tcp, uinfo, &si) < 0) - tprintf("%#lx", uinfo); - else - printsiginfo(&si, verbose(tcp)); + printsiginfo_at(tcp, uinfo); } int @@ -1375,17 +1387,8 @@ int sys_rt_sigtimedwait(struct tcb *tcp) } else if (tcp->u_arg[1] != 0) { /* syscall exit, and u_arg[1] wasn't NULL */ - if (syserror(tcp)) - tprintf("%#lx, ", tcp->u_arg[1]); - else { - siginfo_t si; - if (umove(tcp, tcp->u_arg[1], &si) < 0) - tprintf("%#lx, ", tcp->u_arg[1]); - else { - printsiginfo(&si, verbose(tcp)); - tprints(", "); - } - } + printsiginfo_at(tcp, tcp->u_arg[1]); + tprints(", "); } else { /* syscall exit, and u_arg[1] was NULL */