]> granicus.if.org Git - strace/commitdiff
Factor out code to check addr, fetch and print siginfo
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 13 Feb 2013 15:31:32 +0000 (16:31 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 13 Feb 2013 15:31:32 +0000 (16:31 +0100)
* 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 <vda.linux@googlemail.com>
defs.h
process.c
signal.c

diff --git a/defs.h b/defs.h
index 068ee3dc33a02f02779ea45322dd25315d1463db..ab474cbc97644ef9d00e5c23e53acfa5e59338d2 100644 (file)
--- 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);
index e4d491a2e29b8ecfd7fc24187994d41a49441768..95eb05d121195fac5ae2b2b2209c63cadb377e22 100644 (file)
--- 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
index 5e862ad941d5c29df33cbbc78d1895427fea56ab..55ff3ed743ffc840c6cec5d7d587473fb3cf2416 100644 (file)
--- 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 */