]> granicus.if.org Git - strace/blobdiff - signal.c
nlattr: add UID/GID netlink attribute decoders
[strace] / signal.c
index 321b507a4f06986356f9188fbe730f2a6ca0014c..d717e66f443169f64eeb44695c2d2ef56471e857 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -6,7 +6,7 @@
  * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
  *                     Linux for s390 port by D.J. Barrow
  *                    <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
- * Copyright (C) 2001-2017 The strace developers.
+ * Copyright (c) 2001-2018 The strace developers.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -34,6 +34,7 @@
 
 #include "defs.h"
 #include "nsig.h"
+#include "xstring.h"
 
 /* The libc headers do not define this constant since it should only be
    used by the implementation.  So we define it here.  */
  * Some architectures, otherwise, do not define SA_RESTORER in their headers,
  * but actually have sa_restorer.
  */
-#ifdef SA_RESTORER
-# if defined HPPA || defined IA64
-#  define HAVE_SA_RESTORER 0
-# else
-#  define HAVE_SA_RESTORER 1
-# endif
-#else /* !SA_RESTORER */
-# if defined SPARC || defined SPARC64 || defined M68K
+#ifdef HAVE_ARCH_SA_RESTORER
+# define HAVE_SA_RESTORER HAVE_ARCH_SA_RESTORER
+#else /* !HAVE_ARCH_SA_RESTORER */
+# ifdef SA_RESTORER
 #  define HAVE_SA_RESTORER 1
 # else
 #  define HAVE_SA_RESTORER 0
 # endif
-#endif
+#endif /* HAVE_ARCH_SA_RESTORER */
 
 #include "xlat/sa_handler_values.h"
 #include "xlat/sigact_flags.h"
@@ -120,7 +117,7 @@ print_sa_handler(kernel_ulong_t handler)
        const char *sa_handler_str = get_sa_handler_str(handler);
 
        if (sa_handler_str)
-               tprints(sa_handler_str);
+               print_xlat_ex(handler, sa_handler_str, XLAT_STYLE_DEFAULT);
        else
                printaddr(handler);
 }
@@ -137,12 +134,12 @@ signame(const int sig)
                        return signalent[s];
 #ifdef ASM_SIGRTMAX
                if (s >= ASM_SIGRTMIN && s <= (unsigned int) ASM_SIGRTMAX) {
-                       sprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN);
+                       xsprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN);
                        return buf;
                }
 #endif
        }
-       sprintf(buf, "%d", sig);
+       xsprintf(buf, "%d", sig);
        return buf;
 }
 
@@ -209,11 +206,11 @@ sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
                }
 #ifdef ASM_SIGRTMAX
                else if (i >= ASM_SIGRTMIN && i <= ASM_SIGRTMAX) {
-                       s += sprintf(s, "RT_%u", i - ASM_SIGRTMIN);
+                       s = xappendstr(outstr, s, "RT_%u", i - ASM_SIGRTMIN);
                }
 #endif
                else {
-                       s += sprintf(s, "%u", i);
+                       s = xappendstr(outstr, s, "%u", i);
                }
                sep = ' ';
        }
@@ -285,13 +282,13 @@ print_sigset_addr(struct tcb *const tcp, const kernel_ulong_t addr)
        print_sigset_addr_len_limit(tcp, addr, NSIG_BYTES, NSIG_BYTES);
 }
 
-SYS_FUNC(sigsetmask)
+SYS_FUNC(ssetmask)
 {
        if (entering(tcp)) {
-               tprintsigmask_val("", tcp->u_arg[0]);
-       }
-       else if (!syserror(tcp)) {
-               tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
+               tprint_old_sigmask_val("", (unsigned) tcp->u_arg[0]);
+       } else if (!syserror(tcp)) {
+               tcp->auxstr = sprint_old_sigmask_val("old mask ",
+                                                    (unsigned) tcp->u_rval);
                return RVAL_HEX | RVAL_STR;
        }
        return 0;
@@ -299,30 +296,25 @@ SYS_FUNC(sigsetmask)
 
 struct old_sigaction {
        /* sa_handler may be a libc #define, need to use other name: */
-#ifdef MIPS
+#if defined MIPS
        unsigned int sa_flags;
        unsigned long sa_handler__;
-       /* Kernel treats sa_mask as an array of longs. */
-       unsigned long sa_mask[NSIG / sizeof(long)];
+       unsigned long sa_mask;
+#elif defined ALPHA
+       unsigned long sa_handler__;
+       unsigned long sa_mask;
+       unsigned int sa_flags;
 #else
        unsigned long sa_handler__;
        unsigned long sa_mask;
        unsigned long sa_flags;
-#endif /* !MIPS */
-#if HAVE_SA_RESTORER
        unsigned long sa_restorer;
 #endif
-};
-
-struct old_sigaction32 {
-       /* sa_handler may be a libc #define, need to use other name: */
-       uint32_t sa_handler__;
-       uint32_t sa_mask;
-       uint32_t sa_flags;
-#if HAVE_SA_RESTORER
-       uint32_t sa_restorer;
+}
+#ifdef ALPHA
+       ATTRIBUTE_PACKED
 #endif
-};
+;
 
 static void
 decode_old_sigaction(struct tcb *const tcp, const kernel_ulong_t addr)
@@ -331,7 +323,12 @@ decode_old_sigaction(struct tcb *const tcp, const kernel_ulong_t addr)
 
 #ifndef current_wordsize
        if (current_wordsize < sizeof(sa.sa_handler__)) {
-               struct old_sigaction32 sa32;
+               struct old_sigaction32 {
+                       uint32_t sa_handler__;
+                       uint32_t sa_mask;
+                       uint32_t sa_flags;
+                       uint32_t sa_restorer;
+               } sa32;
 
                if (umove_or_printaddr(tcp, addr, &sa32))
                        return;
@@ -339,9 +336,7 @@ decode_old_sigaction(struct tcb *const tcp, const kernel_ulong_t addr)
                memset(&sa, 0, sizeof(sa));
                sa.sa_handler__ = sa32.sa_handler__;
                sa.sa_flags = sa32.sa_flags;
-#if HAVE_SA_RESTORER && defined SA_RESTORER
                sa.sa_restorer = sa32.sa_restorer;
-#endif
                sa.sa_mask = sa32.sa_mask;
        } else
 #endif
@@ -351,15 +346,11 @@ decode_old_sigaction(struct tcb *const tcp, const kernel_ulong_t addr)
        tprints("{sa_handler=");
        print_sa_handler(sa.sa_handler__);
        tprints(", sa_mask=");
-#ifdef MIPS
-       tprintsigmask_addr("", sa.sa_mask);
-#else
-       tprintsigmask_val("", sa.sa_mask);
-#endif
+       tprint_old_sigmask_val("", sa.sa_mask);
        tprints(", sa_flags=");
        printflags(sigact_flags, sa.sa_flags, "SA_???");
-#if HAVE_SA_RESTORER && defined SA_RESTORER
-       if (sa.sa_flags & SA_RESTORER) {
+#if !(defined ALPHA || defined MIPS)
+       if (sa.sa_flags & 0x04000000U) {
                tprints(", sa_restorer=");
                printaddr(sa.sa_restorer);
        }
@@ -370,7 +361,14 @@ decode_old_sigaction(struct tcb *const tcp, const kernel_ulong_t addr)
 SYS_FUNC(sigaction)
 {
        if (entering(tcp)) {
-               printsignal(tcp->u_arg[0]);
+               int signo = tcp->u_arg[0];
+#if defined SPARC || defined SPARC64
+               if (signo < 0) {
+                       tprints("-");
+                       signo = -signo;
+               }
+#endif
+               printsignal(signo);
                tprints(", ");
                decode_old_sigaction(tcp, tcp->u_arg[1]);
                tprints(", ");
@@ -393,12 +391,13 @@ SYS_FUNC(signal)
        return 0;
 }
 
-SYS_FUNC(siggetmask)
+SYS_FUNC(sgetmask)
 {
-       if (exiting(tcp)) {
-               tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
+       if (exiting(tcp) && !syserror(tcp)) {
+               tcp->auxstr = sprint_old_sigmask_val("mask ", tcp->u_rval);
+               return RVAL_HEX | RVAL_STR;
        }
-       return RVAL_HEX | RVAL_STR;
+       return 0;
 }
 
 SYS_FUNC(sigsuspend)
@@ -413,42 +412,46 @@ SYS_FUNC(sigsuspend)
        return RVAL_DECODED;
 }
 
-/* "Old" sigprocmask, which operates with word-sized signal masks */
-SYS_FUNC(sigprocmask)
+#ifdef ALPHA
+/*
+ * The OSF/1 sigprocmask is different: it doesn't pass in two pointers,
+ * but rather passes in the new bitmask as an argument and then returns
+ * the old bitmask.  This "works" because we only have 64 signals to worry
+ * about.  If you want more, use of the rt_sigprocmask syscall is required.
+ *
+ * Alpha:
+ *     old = osf_sigprocmask(how, new);
+ * Everyone else:
+ *     ret = sigprocmask(how, &new, &old, ...);
+ */
+SYS_FUNC(osf_sigprocmask)
 {
-# ifdef ALPHA
        if (entering(tcp)) {
-               /*
-                * Alpha/OSF is different: it doesn't pass in two pointers,
-                * but rather passes in the new bitmask as an argument and
-                * then returns the old bitmask.  This "works" because we
-                * only have 64 signals to worry about.  If you want more,
-                * use of the rt_sigprocmask syscall is required.
-                * Alpha:
-                *      old = osf_sigprocmask(how, new);
-                * Everyone else:
-                *      ret = sigprocmask(how, &new, &old, ...);
-                */
                printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
                tprintsigmask_val(", ", tcp->u_arg[1]);
-       }
-       else if (!syserror(tcp)) {
+       } else if (!syserror(tcp)) {
                tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
                return RVAL_HEX | RVAL_STR;
        }
-# else /* !ALPHA */
+       return 0;
+}
+
+#else /* !ALPHA */
+
+/* "Old" sigprocmask, which operates with word-sized signal masks */
+SYS_FUNC(sigprocmask)
+{
        if (entering(tcp)) {
                printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
                tprints(", ");
                print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
                tprints(", ");
-       }
-       else {
+       } else {
                print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
        }
-# endif /* !ALPHA */
        return 0;
 }
+#endif /* !ALPHA */
 
 SYS_FUNC(kill)
 {
@@ -484,8 +487,7 @@ SYS_FUNC(rt_sigprocmask)
                tprints(", ");
                print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
                tprints(", ");
-       }
-       else {
+       } else {
                print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
                tprintf(", %" PRI_klu, tcp->u_arg[3]);
        }
@@ -493,8 +495,7 @@ SYS_FUNC(rt_sigprocmask)
 }
 
 /* Structure describing the action to be taken when a signal arrives.  */
-struct new_sigaction
-{
+struct new_sigaction {
        /* sa_handler may be a libc #define, need to use other name: */
 #ifdef MIPS
        unsigned int sa_flags;
@@ -510,8 +511,7 @@ struct new_sigaction
        unsigned long sa_mask[NSIG / sizeof(long)];
 };
 /* Same for i386-on-x86_64 and similar cases */
-struct new_sigaction32
-{
+struct new_sigaction32 {
        uint32_t sa_handler__;
        uint32_t sa_flags;
 #if HAVE_SA_RESTORER
@@ -679,7 +679,7 @@ SYS_FUNC(rt_sigtimedwait)
                }
        }
        return 0;
-};
+}
 
 SYS_FUNC(restart_syscall)
 {