]> granicus.if.org Git - strace/blobdiff - signal.c
Move sysinfo parser to a separate file
[strace] / signal.c
index c85e1b56d45d00f9c8bc69ea73d857a47984f806..5855d136e6ae3f5c1979a06e725763300bc28722 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -100,67 +100,14 @@ struct sigcontext {
 # endif
 #endif
 
-static const struct xlat sigact_flags[] = {
-#ifdef SA_RESTORER
-       XLAT(SA_RESTORER),
-#endif
-#ifdef SA_STACK
-       XLAT(SA_STACK),
-#endif
-#ifdef SA_RESTART
-       XLAT(SA_RESTART),
-#endif
-#ifdef SA_INTERRUPT
-       XLAT(SA_INTERRUPT),
-#endif
-#ifdef SA_NODEFER
-       XLAT(SA_NODEFER),
-#endif
-#if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
-       XLAT(SA_NOMASK),
-#endif
-#ifdef SA_RESETHAND
-       XLAT(SA_RESETHAND),
-#endif
-#if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
-       XLAT(SA_ONESHOT),
-#endif
-#ifdef SA_SIGINFO
-       XLAT(SA_SIGINFO),
-#endif
-#ifdef SA_RESETHAND
-       XLAT(SA_RESETHAND),
+/* Some arches define this in their headers, but don't actually have it,
+   so we have to delete the define.  */
+#if defined(HPPA) || defined(IA64)
+# undef SA_RESTORER
 #endif
-#ifdef SA_ONSTACK
-       XLAT(SA_ONSTACK),
-#endif
-#ifdef SA_NODEFER
-       XLAT(SA_NODEFER),
-#endif
-#ifdef SA_NOCLDSTOP
-       XLAT(SA_NOCLDSTOP),
-#endif
-#ifdef SA_NOCLDWAIT
-       XLAT(SA_NOCLDWAIT),
-#endif
-#ifdef _SA_BSDCALL
-       XLAT(_SA_BSDCALL),
-#endif
-#ifdef SA_NOPTRACE
-       XLAT(SA_NOPTRACE),
-#endif
-       XLAT_END
-};
 
-static const struct xlat sigprocmaskcmds[] = {
-       XLAT(SIG_BLOCK),
-       XLAT(SIG_UNBLOCK),
-       XLAT(SIG_SETMASK),
-#ifdef SIG_SETMASK32
-       XLAT(SIG_SETMASK32),
-#endif
-       XLAT_END
-};
+#include "xlat/sigact_flags.h"
+#include "xlat/sigprocmaskcmds.h"
 
 #endif /* HAVE_SIGACTION */
 
@@ -197,18 +144,22 @@ static const struct xlat sigprocmaskcmds[] = {
  */
 
 const char *
-signame(int sig)
+signame(const int sig)
 {
-       static char buf[sizeof("SIGRT_%d") + sizeof(int)*3];
+       static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
+
+       if (sig >= 0) {
+               const unsigned int s = sig;
 
-       if (sig >= 0 && sig < nsignals)
-               return signalent[sig];
+               if (s < nsignals)
+                       return signalent[s];
 #ifdef SIGRTMIN
-       if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
-               sprintf(buf, "SIGRT_%d", (int)(sig - __SIGRTMIN));
-               return buf;
-       }
+               if (s >= __SIGRTMIN && s <= __SIGRTMAX) {
+                       sprintf(buf, "SIGRT_%u", s - __SIGRTMIN);
+                       return buf;
+               }
 #endif
+       }
        sprintf(buf, "%d", sig);
        return buf;
 }
@@ -270,7 +221,7 @@ sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
        for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
                ++i;
                *s++ = sep;
-               if (i < nsignals) {
+               if ((unsigned) i < nsignals) {
                        s = stpcpy(s, signalent[i] + 3);
                }
 #ifdef SIGRTMIN
@@ -354,6 +305,7 @@ print_sigset_addr_len(struct tcb *tcp, long addr, long len)
 #define BUS_ADRALN      1       /* invalid address alignment */
 #define BUS_ADRERR      2       /* non-existant physical address */
 #define BUS_OBJERR      3       /* object specific hardware error */
+#define SYS_SECCOMP     1       /* seccomp triggered */
 #define TRAP_BRKPT      1       /* process breakpoint */
 #define TRAP_TRACE      2       /* process trace trap */
 #define CLD_EXITED      1       /* child has exited */
@@ -384,124 +336,25 @@ print_sigset_addr_len(struct tcb *tcp, long addr, long len)
 # define SI_FROMUSER(sip)      ((sip)->si_code <= 0)
 #endif
 
-static const struct xlat siginfo_codes[] = {
-#ifdef SI_KERNEL
-       XLAT(SI_KERNEL),
-#endif
-#ifdef SI_USER
-       XLAT(SI_USER),
-#endif
-#ifdef SI_QUEUE
-       XLAT(SI_QUEUE),
-#endif
-#ifdef SI_TIMER
-       XLAT(SI_TIMER),
-#endif
-#ifdef SI_MESGQ
-       XLAT(SI_MESGQ),
-#endif
-#ifdef SI_ASYNCIO
-       XLAT(SI_ASYNCIO),
-#endif
-#ifdef SI_SIGIO
-       XLAT(SI_SIGIO),
-#endif
-#ifdef SI_TKILL
-       XLAT(SI_TKILL),
-#endif
-#ifdef SI_DETHREAD
-       XLAT(SI_DETHREAD),
-#endif
-#ifdef SI_ASYNCNL
-       XLAT(SI_ASYNCNL),
-#endif
-#ifdef SI_NOINFO
-       XLAT(SI_NOINFO),
-#endif
-#ifdef SI_LWP
-       XLAT(SI_LWP),
-#endif
-       XLAT_END
-};
-
-static const struct xlat sigill_codes[] = {
-       XLAT(ILL_ILLOPC),
-       XLAT(ILL_ILLOPN),
-       XLAT(ILL_ILLADR),
-       XLAT(ILL_ILLTRP),
-       XLAT(ILL_PRVOPC),
-       XLAT(ILL_PRVREG),
-       XLAT(ILL_COPROC),
-       XLAT(ILL_BADSTK),
-       XLAT_END
-};
-
-static const struct xlat sigfpe_codes[] = {
-       XLAT(FPE_INTDIV),
-       XLAT(FPE_INTOVF),
-       XLAT(FPE_FLTDIV),
-       XLAT(FPE_FLTOVF),
-       XLAT(FPE_FLTUND),
-       XLAT(FPE_FLTRES),
-       XLAT(FPE_FLTINV),
-       XLAT(FPE_FLTSUB),
-       XLAT_END
-};
-
-static const struct xlat sigtrap_codes[] = {
-       XLAT(TRAP_BRKPT),
-       XLAT(TRAP_TRACE),
-       XLAT_END
-};
-
-static const struct xlat sigchld_codes[] = {
-       XLAT(CLD_EXITED),
-       XLAT(CLD_KILLED),
-       XLAT(CLD_DUMPED),
-       XLAT(CLD_TRAPPED),
-       XLAT(CLD_STOPPED),
-       XLAT(CLD_CONTINUED),
-       XLAT_END
-};
-
-static const struct xlat sigpoll_codes[] = {
-       XLAT(POLL_IN),
-       XLAT(POLL_OUT),
-       XLAT(POLL_MSG),
-       XLAT(POLL_ERR),
-       XLAT(POLL_PRI),
-       XLAT(POLL_HUP),
-       XLAT_END
-};
-
-static const struct xlat sigprof_codes[] = {
-#ifdef PROF_SIG
-       XLAT(PROF_SIG),
-#endif
-       XLAT_END
-};
+#include "xlat/siginfo_codes.h"
+#include "xlat/sigill_codes.h"
+#include "xlat/sigfpe_codes.h"
+#include "xlat/sigtrap_codes.h"
+#include "xlat/sigchld_codes.h"
+#include "xlat/sigpoll_codes.h"
+#include "xlat/sigprof_codes.h"
 
 #ifdef SIGEMT
-static const struct xlat sigemt_codes[] = {
-#ifdef EMT_TAGOVF
-       XLAT(EMT_TAGOVF),
-#endif
-       XLAT_END
-};
+#include "xlat/sigemt_codes.h"
 #endif
 
-static const struct xlat sigsegv_codes[] = {
-       XLAT(SEGV_MAPERR),
-       XLAT(SEGV_ACCERR),
-       XLAT_END
-};
+#include "xlat/sigsegv_codes.h"
+#include "xlat/sigbus_codes.h"
 
-static const struct xlat sigbus_codes[] = {
-       XLAT(BUS_ADRALN),
-       XLAT(BUS_ADRERR),
-       XLAT(BUS_OBJERR),
-       XLAT_END
-};
+#ifndef SYS_SECCOMP
+# define SYS_SECCOMP 1
+#endif
+#include "xlat/sigsys_codes.h"
 
 static void
 printsigsource(const siginfo_t *sip)
@@ -565,6 +418,9 @@ printsiginfo(siginfo_t *sip, int verbose)
                case SIGBUS:
                        code = xlookup(sigbus_codes, sip->si_code);
                        break;
+               case SIGSYS:
+                       code = xlookup(sigsys_codes, sip->si_code);
+                       break;
                }
        }
        if (code)
@@ -576,7 +432,7 @@ printsiginfo(siginfo_t *sip, int verbose)
 #endif
        {
                if (sip->si_errno) {
-                       if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
+                       if (sip->si_errno < 0 || (unsigned) sip->si_errno >= nerrnos)
                                tprintf(", si_errno=%d", sip->si_errno);
                        else
                                tprintf(", si_errno=%s",
@@ -640,6 +496,13 @@ printsiginfo(siginfo_t *sip, int verbose)
                                        break;
                                }
                                break;
+#ifdef HAVE_SIGINFO_T_SI_SYSCALL
+                       case SIGSYS:
+                               tprintf(", si_call_addr=%#lx, si_syscall=%d, si_arch=%u",
+                                       (unsigned long) sip->si_call_addr,
+                                       sip->si_syscall, sip->si_arch);
+                               break;
+#endif
                        default:
                                if (sip->si_pid || sip->si_uid)
                                        printsigsource(sip);
@@ -696,8 +559,10 @@ struct old_sigaction {
        void (*__sa_handler)(int);
        unsigned long sa_mask;
        unsigned long sa_flags;
-       void (*sa_restorer)(void);
 #endif /* !MIPS */
+#ifdef SA_RESTORER
+       void (*sa_restorer)(void);
+#endif
 };
 
 struct old_sigaction32 {
@@ -705,7 +570,9 @@ struct old_sigaction32 {
        uint32_t __sa_handler;
        uint32_t sa_mask;
        uint32_t sa_flags;
+#ifdef SA_RESTORER
        uint32_t sa_restorer;
+#endif
 };
 
 static void
@@ -731,7 +598,9 @@ decode_old_sigaction(struct tcb *tcp, long addr)
                        memset(&sa, 0, sizeof(sa));
                        sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
                        sa.sa_flags = sa32.sa_flags;
+#ifdef SA_RESTORER
                        sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
+#endif
                        sa.sa_mask = sa32.sa_mask;
                }
        } else
@@ -1109,11 +978,7 @@ sys_sigsuspend(struct tcb *tcp)
 #define SS_DISABLE      2
 #endif
 
-static const struct xlat sigaltstack_flags[] = {
-       XLAT(SS_ONSTACK),
-       XLAT(SS_DISABLE),
-       XLAT_END
-};
+#include "xlat/sigaltstack_flags.h"
 
 static void
 print_stack_t(struct tcb *tcp, unsigned long addr)
@@ -1279,8 +1144,10 @@ struct new_sigaction
 #else
        void (*__sa_handler)(int);
        unsigned long sa_flags;
-       void (*sa_restorer)(void);
 #endif /* !MIPS */
+#ifdef SA_RESTORER
+       void (*sa_restorer)(void);
+#endif
        /* Kernel treats sa_mask as an array of longs. */
        unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
 };
@@ -1289,7 +1156,9 @@ struct new_sigaction32
 {
        uint32_t __sa_handler;
        uint32_t sa_flags;
+#ifdef SA_RESTORER
        uint32_t sa_restorer;
+#endif
        uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
 };
 
@@ -1315,7 +1184,9 @@ decode_new_sigaction(struct tcb *tcp, long addr)
                        memset(&sa, 0, sizeof(sa));
                        sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
                        sa.sa_flags     = sa32.sa_flags;
+#ifdef SA_RESTORER
                        sa.sa_restorer  = (void*)(unsigned long)sa32.sa_restorer;
+#endif
                        /* Kernel treats sa_mask as an array of longs.
                         * For 32-bit process, "long" is uint32_t, thus, for example,
                         * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].