]> granicus.if.org Git - strace/blobdiff - printsiginfo.c
nlattr: add UID/GID netlink attribute decoders
[strace] / printsiginfo.c
index 699460f3f25ce6352e801ac084d6b60ead1b4d4f..d46003c259fc511ec31a5a106bb68b5d0c51b3a3 100644 (file)
@@ -7,6 +7,7 @@
  * Copyright (c) 2013 Denys Vlasenko <vda.linux@googlemail.com>
  * Copyright (c) 2011-2015 Dmitry V. Levin <ldv@altlinux.org>
  * Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
+ * Copyright (c) 2015-2018 The strace developers.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -41,6 +42,8 @@
 
 #include MPERS_DEFS
 
+#include "nr_prefix.c"
+
 #ifndef IN_MPERS
 #include "printsiginfo.h"
 #endif
@@ -77,7 +80,7 @@ static void
 printsigval(const siginfo_t *sip)
 {
        tprintf(", si_value={int=%d, ptr=", sip->si_int);
-       printaddr((unsigned long) sip->si_ptr);
+       printaddr(ptr_to_kulong(sip->si_ptr));
        tprints("}");
 }
 
@@ -123,10 +126,7 @@ print_si_code(int si_signo, unsigned int si_code)
                }
        }
 
-       if (code)
-               tprints(code);
-       else
-               tprintf("%#x", si_code);
+       print_xlat_ex(si_code, code, XLAT_STYLE_DEFAULT);
 }
 
 static void
@@ -172,13 +172,13 @@ print_si_info(const siginfo_t *sip)
                        else
                                printsignal(sip->si_status);
                        tprintf(", si_utime=%llu, si_stime=%llu",
-                               widen_to_ull(sip->si_utime),
-                               widen_to_ull(sip->si_stime));
+                               zero_extend_signed_to_ull(sip->si_utime),
+                               zero_extend_signed_to_ull(sip->si_stime));
                        break;
                case SIGILL: case SIGFPE:
                case SIGSEGV: case SIGBUS:
                        tprints(", si_addr=");
-                       printaddr((unsigned long) sip->si_addr);
+                       printaddr(ptr_to_kulong(sip->si_addr));
                        break;
                case SIGPOLL:
                        switch (sip->si_code) {
@@ -189,13 +189,38 @@ print_si_info(const siginfo_t *sip)
                        }
                        break;
 #ifdef HAVE_SIGINFO_T_SI_SYSCALL
-               case SIGSYS:
+               case SIGSYS: {
+                       /*
+                        * Note that we can safely use the personlity set in
+                        * current_personality  here (and don't have to guess it
+                        * based on X32_SYSCALL_BIT and si_arch, for example):
+                        *  - The signal is delivered as a result of seccomp
+                        *    filtering to the process executing forbidden
+                        *    syscall.
+                        *  - We have set the personality for the tracee during
+                        *    the syscall entering.
+                        *  - The current_personality is reliably switched in
+                        *    the next_event routine, it is set to the
+                        *    personality of the last call made (the one that
+                        *    triggered the signal delivery).
+                        *  - Looks like there are no other cases where SIGSYS
+                        *    is delivered from the kernel so far.
+                        */
+                       const char *scname = syscall_name(shuffle_scno(
+                               (unsigned) sip->si_syscall));
+
                        tprints(", si_call_addr=");
-                       printaddr((unsigned long) sip->si_call_addr);
-                       tprintf(", si_syscall=__NR_%s, si_arch=",
-                               syscall_name((unsigned) sip->si_syscall));
+                       printaddr(ptr_to_kulong(sip->si_call_addr));
+                       tprints(", si_syscall=");
+                       if (scname)
+                               tprintf("%s%s",
+                                       nr_prefix(sip->si_syscall), scname);
+                       else
+                               tprintf("%u", (unsigned) sip->si_syscall);
+                       tprints(", si_arch=");
                        printxval(audit_arch, sip->si_arch, "AUDIT_ARCH_???");
                        break;
+               }
 #endif
                default:
                        if (sip->si_pid || sip->si_uid)
@@ -231,7 +256,7 @@ printsiginfo(const siginfo_t *sip)
 }
 
 MPERS_PRINTER_DECL(void, printsiginfo_at,
-                  struct tcb *tcp, long addr)
+                  struct tcb *const tcp, const kernel_ulong_t addr)
 {
        siginfo_t si;
 
@@ -246,11 +271,11 @@ print_siginfo_t(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
        return true;
 }
 
-MPERS_PRINTER_DECL(void, print_siginfo_array,
-                  struct tcb *tcp, unsigned long addr, unsigned long len)
+MPERS_PRINTER_DECL(void, print_siginfo_array, struct tcb *const tcp,
+                  const kernel_ulong_t addr, const kernel_ulong_t len)
 {
        siginfo_t si;
 
        print_array(tcp, addr, len, &si, sizeof(si),
-                   umoven_or_printaddr, print_siginfo_t, 0);
+                   tfetch_mem, print_siginfo_t, 0);
 }