]> granicus.if.org Git - strace/blob - signal.c
printsiginfo: add SIGSYS decoding
[strace] / signal.c
1 /*
2  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6  * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7  *                     Linux for s390 port by D.J. Barrow
8  *                    <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include "defs.h"
35 #include <sys/user.h>
36 #include <fcntl.h>
37
38 #ifdef HAVE_SYS_REG_H
39 # include <sys/reg.h>
40 #elif defined(HAVE_LINUX_PTRACE_H)
41 # undef PTRACE_SYSCALL
42 # ifdef HAVE_STRUCT_IA64_FPREG
43 #  define ia64_fpreg XXX_ia64_fpreg
44 # endif
45 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS
46 #  define pt_all_user_regs XXX_pt_all_user_regs
47 # endif
48 # ifdef HAVE_STRUCT_PTRACE_PEEKSIGINFO_ARGS
49 #  define ptrace_peeksiginfo_args XXX_ptrace_peeksiginfo_args
50 # endif
51 # include <linux/ptrace.h>
52 # undef ptrace_peeksiginfo_args
53 # undef ia64_fpreg
54 # undef pt_all_user_regs
55 #endif
56
57 #ifdef IA64
58 # include <asm/ptrace_offsets.h>
59 #endif
60
61 #if defined(SPARC) || defined(SPARC64) || defined(MIPS)
62 typedef struct {
63         struct pt_regs          si_regs;
64         int                     si_mask;
65 } m_siginfo_t;
66 #elif defined HAVE_ASM_SIGCONTEXT_H
67 # if !defined(IA64) && !defined(X86_64) && !defined(X32)
68 #  include <asm/sigcontext.h>
69 # endif
70 #else /* !HAVE_ASM_SIGCONTEXT_H */
71 # if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
72 struct sigcontext {
73         unsigned long sc_mask;
74         unsigned long sc_usp;
75         unsigned long sc_d0;
76         unsigned long sc_d1;
77         unsigned long sc_a0;
78         unsigned long sc_a1;
79         unsigned short sc_sr;
80         unsigned long sc_pc;
81         unsigned short sc_formatvec;
82 };
83 # endif /* M68K */
84 #endif /* !HAVE_ASM_SIGCONTEXT_H */
85
86 #ifndef NSIG
87 # warning: NSIG is not defined, using 32
88 # define NSIG 32
89 #elif NSIG < 32
90 # error: NSIG < 32
91 #endif
92
93 #ifdef HAVE_SIGACTION
94
95 /* The libc headers do not define this constant since it should only be
96    used by the implementation.  So we define it here.  */
97 #ifndef SA_RESTORER
98 # ifdef ASM_SA_RESTORER
99 #  define SA_RESTORER ASM_SA_RESTORER
100 # endif
101 #endif
102
103 static const struct xlat sigact_flags[] = {
104 #ifdef SA_RESTORER
105         XLAT(SA_RESTORER),
106 #endif
107 #ifdef SA_STACK
108         XLAT(SA_STACK),
109 #endif
110 #ifdef SA_RESTART
111         XLAT(SA_RESTART),
112 #endif
113 #ifdef SA_INTERRUPT
114         XLAT(SA_INTERRUPT),
115 #endif
116 #ifdef SA_NODEFER
117         XLAT(SA_NODEFER),
118 #endif
119 #if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
120         XLAT(SA_NOMASK),
121 #endif
122 #ifdef SA_RESETHAND
123         XLAT(SA_RESETHAND),
124 #endif
125 #if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
126         XLAT(SA_ONESHOT),
127 #endif
128 #ifdef SA_SIGINFO
129         XLAT(SA_SIGINFO),
130 #endif
131 #ifdef SA_RESETHAND
132         XLAT(SA_RESETHAND),
133 #endif
134 #ifdef SA_ONSTACK
135         XLAT(SA_ONSTACK),
136 #endif
137 #ifdef SA_NODEFER
138         XLAT(SA_NODEFER),
139 #endif
140 #ifdef SA_NOCLDSTOP
141         XLAT(SA_NOCLDSTOP),
142 #endif
143 #ifdef SA_NOCLDWAIT
144         XLAT(SA_NOCLDWAIT),
145 #endif
146 #ifdef _SA_BSDCALL
147         XLAT(_SA_BSDCALL),
148 #endif
149 #ifdef SA_NOPTRACE
150         XLAT(SA_NOPTRACE),
151 #endif
152         XLAT_END
153 };
154
155 static const struct xlat sigprocmaskcmds[] = {
156         XLAT(SIG_BLOCK),
157         XLAT(SIG_UNBLOCK),
158         XLAT(SIG_SETMASK),
159 #ifdef SIG_SETMASK32
160         XLAT(SIG_SETMASK32),
161 #endif
162         XLAT_END
163 };
164
165 #endif /* HAVE_SIGACTION */
166
167 /* Anonymous realtime signals. */
168 /* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
169    constant.  This is what we want.  Otherwise, just use SIGRTMIN. */
170 #ifdef SIGRTMIN
171 #ifndef __SIGRTMIN
172 #define __SIGRTMIN SIGRTMIN
173 #define __SIGRTMAX SIGRTMAX /* likewise */
174 #endif
175 #endif
176
177 /* Note on the size of sigset_t:
178  *
179  * In glibc, sigset_t is an array with space for 1024 bits (!),
180  * even though all arches supported by Linux have only 64 signals
181  * except MIPS, which has 128. IOW, it is 128 bytes long.
182  *
183  * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
184  * However, some old syscall return only 32 lower bits (one word).
185  * Example: sys_sigpending vs sys_rt_sigpending.
186  *
187  * Be aware of this fact when you try to
188  *     memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
189  * - sizeof(sigset_t) is much bigger than you think,
190  * it may overflow tcp->u_arg[] array, and it may try to copy more data
191  * than is really available in <something>.
192  * Similarly,
193  *     umoven(tcp, addr, sizeof(sigset_t), &sigset)
194  * may be a bad idea: it'll try to read much more data than needed
195  * to fetch a sigset_t.
196  * Use (NSIG / 8) as a size instead.
197  */
198
199 const char *
200 signame(int sig)
201 {
202         static char buf[sizeof("SIGRT_%d") + sizeof(int)*3];
203
204         if (sig >= 0 && sig < nsignals)
205                 return signalent[sig];
206 #ifdef SIGRTMIN
207         if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
208                 sprintf(buf, "SIGRT_%d", (int)(sig - __SIGRTMIN));
209                 return buf;
210         }
211 #endif
212         sprintf(buf, "%d", sig);
213         return buf;
214 }
215
216 static unsigned int
217 popcount32(const uint32_t *a, unsigned int size)
218 {
219         unsigned int count = 0;
220
221         for (; size; ++a, --size) {
222                 uint32_t x = *a;
223
224 #ifdef HAVE___BUILTIN_POPCOUNT
225                 count += __builtin_popcount(x);
226 #else
227                 for (; x; ++count)
228                         x &= x - 1;
229 #endif
230         }
231
232         return count;
233 }
234
235 static const char *
236 sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
237 {
238         /*
239          * The maximum number of signal names to be printed is NSIG * 2 / 3.
240          * Most of signal names have length 7,
241          * average length of signal names is less than 7.
242          * The length of prefix string does not exceed 16.
243          */
244         static char outstr[128 + 8 * (NSIG * 2 / 3)];
245
246         char *s;
247         const uint32_t *mask;
248         uint32_t inverted_mask[NSIG / 32];
249         unsigned int size;
250         int i;
251         char sep;
252
253         s = stpcpy(outstr, prefix);
254
255         mask = sig_mask;
256         /* length of signal mask in 4-byte words */
257         size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
258
259         /* check whether 2/3 or more bits are set */
260         if (popcount32(mask, size) >= size * 32 * 2 / 3) {
261                 /* show those signals that are NOT in the mask */
262                 unsigned int j;
263                 for (j = 0; j < size; ++j)
264                         inverted_mask[j] = ~mask[j];
265                 mask = inverted_mask;
266                 *s++ = '~';
267         }
268
269         sep = '[';
270         for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
271                 ++i;
272                 *s++ = sep;
273                 if (i < nsignals) {
274                         s = stpcpy(s, signalent[i] + 3);
275                 }
276 #ifdef SIGRTMIN
277                 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
278                         s += sprintf(s, "RT_%u", i - __SIGRTMIN);
279                 }
280 #endif
281                 else {
282                         s += sprintf(s, "%u", i);
283                 }
284                 sep = ' ';
285         }
286         if (sep == '[')
287                 *s++ = sep;
288         *s++ = ']';
289         *s = '\0';
290         return outstr;
291 }
292
293 #define tprintsigmask_addr(prefix, mask) \
294         tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
295
296 #define sprintsigmask_val(prefix, mask) \
297         sprintsigmask_n((prefix), &(mask), sizeof(mask))
298
299 #define tprintsigmask_val(prefix, mask) \
300         tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
301
302 void
303 printsignal(int nr)
304 {
305         tprints(signame(nr));
306 }
307
308 void
309 print_sigset_addr_len(struct tcb *tcp, long addr, long len)
310 {
311         char mask[NSIG / 8];
312
313         if (!addr) {
314                 tprints("NULL");
315                 return;
316         }
317         /* Here len is usually equals NSIG / 8 or current_wordsize.
318          * But we code this defensively:
319          */
320         if (len < 0) {
321  bad:
322                 tprintf("%#lx", addr);
323                 return;
324         }
325         if (len >= NSIG / 8)
326                 len = NSIG / 8;
327         else
328                 len = (len + 3) & ~3;
329
330         if (umoven(tcp, addr, len, mask) < 0)
331                 goto bad;
332         tprints(sprintsigmask_n("", mask, len));
333 }
334
335 #ifndef ILL_ILLOPC
336 #define ILL_ILLOPC      1       /* illegal opcode */
337 #define ILL_ILLOPN      2       /* illegal operand */
338 #define ILL_ILLADR      3       /* illegal addressing mode */
339 #define ILL_ILLTRP      4       /* illegal trap */
340 #define ILL_PRVOPC      5       /* privileged opcode */
341 #define ILL_PRVREG      6       /* privileged register */
342 #define ILL_COPROC      7       /* coprocessor error */
343 #define ILL_BADSTK      8       /* internal stack error */
344 #define FPE_INTDIV      1       /* integer divide by zero */
345 #define FPE_INTOVF      2       /* integer overflow */
346 #define FPE_FLTDIV      3       /* floating point divide by zero */
347 #define FPE_FLTOVF      4       /* floating point overflow */
348 #define FPE_FLTUND      5       /* floating point underflow */
349 #define FPE_FLTRES      6       /* floating point inexact result */
350 #define FPE_FLTINV      7       /* floating point invalid operation */
351 #define FPE_FLTSUB      8       /* subscript out of range */
352 #define SEGV_MAPERR     1       /* address not mapped to object */
353 #define SEGV_ACCERR     2       /* invalid permissions for mapped object */
354 #define BUS_ADRALN      1       /* invalid address alignment */
355 #define BUS_ADRERR      2       /* non-existant physical address */
356 #define BUS_OBJERR      3       /* object specific hardware error */
357 #define SYS_SECCOMP     1       /* seccomp triggered */
358 #define TRAP_BRKPT      1       /* process breakpoint */
359 #define TRAP_TRACE      2       /* process trace trap */
360 #define CLD_EXITED      1       /* child has exited */
361 #define CLD_KILLED      2       /* child was killed */
362 #define CLD_DUMPED      3       /* child terminated abnormally */
363 #define CLD_TRAPPED     4       /* traced child has trapped */
364 #define CLD_STOPPED     5       /* child has stopped */
365 #define CLD_CONTINUED   6       /* stopped child has continued */
366 #define POLL_IN         1       /* data input available */
367 #define POLL_OUT        2       /* output buffers available */
368 #define POLL_MSG        3       /* input message available */
369 #define POLL_ERR        4       /* i/o error */
370 #define POLL_PRI        5       /* high priority input available */
371 #define POLL_HUP        6       /* device disconnected */
372 #define SI_KERNEL       0x80    /* sent by kernel */
373 #define SI_USER         0       /* sent by kill, sigsend, raise */
374 #define SI_QUEUE        -1      /* sent by sigqueue */
375 #define SI_TIMER        -2      /* sent by timer expiration */
376 #define SI_MESGQ        -3      /* sent by real time mesq state change */
377 #define SI_ASYNCIO      -4      /* sent by AIO completion */
378 #define SI_SIGIO        -5      /* sent by SIGIO */
379 #define SI_TKILL        -6      /* sent by tkill */
380 #define SI_DETHREAD     -7      /* sent by execve killing subsidiary threads */
381 #define SI_ASYNCNL      -60     /* sent by asynch name lookup completion */
382 #endif
383
384 #ifndef SI_FROMUSER
385 # define SI_FROMUSER(sip)       ((sip)->si_code <= 0)
386 #endif
387
388 static const struct xlat siginfo_codes[] = {
389 #ifdef SI_KERNEL
390         XLAT(SI_KERNEL),
391 #endif
392 #ifdef SI_USER
393         XLAT(SI_USER),
394 #endif
395 #ifdef SI_QUEUE
396         XLAT(SI_QUEUE),
397 #endif
398 #ifdef SI_TIMER
399         XLAT(SI_TIMER),
400 #endif
401 #ifdef SI_MESGQ
402         XLAT(SI_MESGQ),
403 #endif
404 #ifdef SI_ASYNCIO
405         XLAT(SI_ASYNCIO),
406 #endif
407 #ifdef SI_SIGIO
408         XLAT(SI_SIGIO),
409 #endif
410 #ifdef SI_TKILL
411         XLAT(SI_TKILL),
412 #endif
413 #ifdef SI_DETHREAD
414         XLAT(SI_DETHREAD),
415 #endif
416 #ifdef SI_ASYNCNL
417         XLAT(SI_ASYNCNL),
418 #endif
419 #ifdef SI_NOINFO
420         XLAT(SI_NOINFO),
421 #endif
422 #ifdef SI_LWP
423         XLAT(SI_LWP),
424 #endif
425         XLAT_END
426 };
427
428 static const struct xlat sigill_codes[] = {
429         XLAT(ILL_ILLOPC),
430         XLAT(ILL_ILLOPN),
431         XLAT(ILL_ILLADR),
432         XLAT(ILL_ILLTRP),
433         XLAT(ILL_PRVOPC),
434         XLAT(ILL_PRVREG),
435         XLAT(ILL_COPROC),
436         XLAT(ILL_BADSTK),
437         XLAT_END
438 };
439
440 static const struct xlat sigfpe_codes[] = {
441         XLAT(FPE_INTDIV),
442         XLAT(FPE_INTOVF),
443         XLAT(FPE_FLTDIV),
444         XLAT(FPE_FLTOVF),
445         XLAT(FPE_FLTUND),
446         XLAT(FPE_FLTRES),
447         XLAT(FPE_FLTINV),
448         XLAT(FPE_FLTSUB),
449         XLAT_END
450 };
451
452 static const struct xlat sigtrap_codes[] = {
453         XLAT(TRAP_BRKPT),
454         XLAT(TRAP_TRACE),
455         XLAT_END
456 };
457
458 static const struct xlat sigchld_codes[] = {
459         XLAT(CLD_EXITED),
460         XLAT(CLD_KILLED),
461         XLAT(CLD_DUMPED),
462         XLAT(CLD_TRAPPED),
463         XLAT(CLD_STOPPED),
464         XLAT(CLD_CONTINUED),
465         XLAT_END
466 };
467
468 static const struct xlat sigpoll_codes[] = {
469         XLAT(POLL_IN),
470         XLAT(POLL_OUT),
471         XLAT(POLL_MSG),
472         XLAT(POLL_ERR),
473         XLAT(POLL_PRI),
474         XLAT(POLL_HUP),
475         XLAT_END
476 };
477
478 static const struct xlat sigprof_codes[] = {
479 #ifdef PROF_SIG
480         XLAT(PROF_SIG),
481 #endif
482         XLAT_END
483 };
484
485 #ifdef SIGEMT
486 static const struct xlat sigemt_codes[] = {
487 #ifdef EMT_TAGOVF
488         XLAT(EMT_TAGOVF),
489 #endif
490         XLAT_END
491 };
492 #endif
493
494 static const struct xlat sigsegv_codes[] = {
495         XLAT(SEGV_MAPERR),
496         XLAT(SEGV_ACCERR),
497         XLAT_END
498 };
499
500 static const struct xlat sigbus_codes[] = {
501         XLAT(BUS_ADRALN),
502         XLAT(BUS_ADRERR),
503         XLAT(BUS_OBJERR),
504         XLAT_END
505 };
506
507 #ifndef SYS_SECCOMP
508 # define SYS_SECCOMP 1
509 #endif
510 static const struct xlat sigsys_codes[] = {
511         XLAT(SYS_SECCOMP),
512         XLAT_END
513 };
514
515 static void
516 printsigsource(const siginfo_t *sip)
517 {
518         tprintf(", si_pid=%lu, si_uid=%lu",
519                 (unsigned long) sip->si_pid,
520                 (unsigned long) sip->si_uid);
521 }
522
523 static void
524 printsigval(const siginfo_t *sip, int verbose)
525 {
526         if (!verbose)
527                 tprints(", ...");
528         else
529                 tprintf(", si_value={int=%u, ptr=%#lx}",
530                         sip->si_int,
531                         (unsigned long) sip->si_ptr);
532 }
533
534 void
535 printsiginfo(siginfo_t *sip, int verbose)
536 {
537         const char *code;
538
539         if (sip->si_signo == 0) {
540                 tprints("{}");
541                 return;
542         }
543         tprints("{si_signo=");
544         printsignal(sip->si_signo);
545         code = xlookup(siginfo_codes, sip->si_code);
546         if (!code) {
547                 switch (sip->si_signo) {
548                 case SIGTRAP:
549                         code = xlookup(sigtrap_codes, sip->si_code);
550                         break;
551                 case SIGCHLD:
552                         code = xlookup(sigchld_codes, sip->si_code);
553                         break;
554                 case SIGPOLL:
555                         code = xlookup(sigpoll_codes, sip->si_code);
556                         break;
557                 case SIGPROF:
558                         code = xlookup(sigprof_codes, sip->si_code);
559                         break;
560                 case SIGILL:
561                         code = xlookup(sigill_codes, sip->si_code);
562                         break;
563 #ifdef SIGEMT
564                 case SIGEMT:
565                         code = xlookup(sigemt_codes, sip->si_code);
566                         break;
567 #endif
568                 case SIGFPE:
569                         code = xlookup(sigfpe_codes, sip->si_code);
570                         break;
571                 case SIGSEGV:
572                         code = xlookup(sigsegv_codes, sip->si_code);
573                         break;
574                 case SIGBUS:
575                         code = xlookup(sigbus_codes, sip->si_code);
576                         break;
577                 case SIGSYS:
578                         code = xlookup(sigsys_codes, sip->si_code);
579                         break;
580                 }
581         }
582         if (code)
583                 tprintf(", si_code=%s", code);
584         else
585                 tprintf(", si_code=%#x", sip->si_code);
586 #ifdef SI_NOINFO
587         if (sip->si_code != SI_NOINFO)
588 #endif
589         {
590                 if (sip->si_errno) {
591                         if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
592                                 tprintf(", si_errno=%d", sip->si_errno);
593                         else
594                                 tprintf(", si_errno=%s",
595                                         errnoent[sip->si_errno]);
596                 }
597 #ifdef SI_FROMUSER
598                 if (SI_FROMUSER(sip)) {
599                         switch (sip->si_code) {
600 #ifdef SI_USER
601                         case SI_USER:
602                                 printsigsource(sip);
603                                 break;
604 #endif
605 #ifdef SI_TKILL
606                         case SI_TKILL:
607                                 printsigsource(sip);
608                                 break;
609 #endif
610 #ifdef SI_TIMER
611                         case SI_TIMER:
612                                 tprintf(", si_timerid=%#x, si_overrun=%d",
613                                         sip->si_timerid, sip->si_overrun);
614                                 printsigval(sip, verbose);
615                                 break;
616 #endif
617                         default:
618                                 printsigsource(sip);
619                                 if (sip->si_ptr)
620                                         printsigval(sip, verbose);
621                                 break;
622                         }
623                 }
624                 else
625 #endif /* SI_FROMUSER */
626                 {
627                         switch (sip->si_signo) {
628                         case SIGCHLD:
629                                 printsigsource(sip);
630                                 tprints(", si_status=");
631                                 if (sip->si_code == CLD_EXITED)
632                                         tprintf("%d", sip->si_status);
633                                 else
634                                         printsignal(sip->si_status);
635                                 if (!verbose)
636                                         tprints(", ...");
637                                 else
638                                         tprintf(", si_utime=%llu, si_stime=%llu",
639                                                 (unsigned long long) sip->si_utime,
640                                                 (unsigned long long) sip->si_stime);
641                                 break;
642                         case SIGILL: case SIGFPE:
643                         case SIGSEGV: case SIGBUS:
644                                 tprintf(", si_addr=%#lx",
645                                         (unsigned long) sip->si_addr);
646                                 break;
647                         case SIGPOLL:
648                                 switch (sip->si_code) {
649                                 case POLL_IN: case POLL_OUT: case POLL_MSG:
650                                         tprintf(", si_band=%ld",
651                                                 (long) sip->si_band);
652                                         break;
653                                 }
654                                 break;
655 #ifdef HAVE_SIGINFO_T_SI_SYSCALL
656                         case SIGSYS:
657                                 tprintf(", si_call_addr=%#lx, si_syscall=%d, si_arch=%u",
658                                         (unsigned long) sip->si_call_addr,
659                                         sip->si_syscall, sip->si_arch);
660                                 break;
661 #endif
662                         default:
663                                 if (sip->si_pid || sip->si_uid)
664                                         printsigsource(sip);
665                                 if (sip->si_ptr)
666                                         printsigval(sip, verbose);
667                         }
668                 }
669         }
670         tprints("}");
671 }
672
673 void
674 printsiginfo_at(struct tcb *tcp, long addr)
675 {
676         siginfo_t si;
677         if (!addr) {
678                 tprints("NULL");
679                 return;
680         }
681         if (syserror(tcp)) {
682                 tprintf("%#lx", addr);
683                 return;
684         }
685         if (umove(tcp, addr, &si) < 0) {
686                 tprints("{???}");
687                 return;
688         }
689         printsiginfo(&si, verbose(tcp));
690 }
691
692 int
693 sys_sigsetmask(struct tcb *tcp)
694 {
695         if (entering(tcp)) {
696                 tprintsigmask_val("", tcp->u_arg[0]);
697         }
698         else if (!syserror(tcp)) {
699                 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
700                 return RVAL_HEX | RVAL_STR;
701         }
702         return 0;
703 }
704
705 #ifdef HAVE_SIGACTION
706
707 struct old_sigaction {
708         /* sa_handler may be a libc #define, need to use other name: */
709 #ifdef MIPS
710         unsigned int sa_flags;
711         void (*__sa_handler)(int);
712         /* Kernel treats sa_mask as an array of longs. */
713         unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
714 #else
715         void (*__sa_handler)(int);
716         unsigned long sa_mask;
717         unsigned long sa_flags;
718         void (*sa_restorer)(void);
719 #endif /* !MIPS */
720 };
721
722 struct old_sigaction32 {
723         /* sa_handler may be a libc #define, need to use other name: */
724         uint32_t __sa_handler;
725         uint32_t sa_mask;
726         uint32_t sa_flags;
727         uint32_t sa_restorer;
728 };
729
730 static void
731 decode_old_sigaction(struct tcb *tcp, long addr)
732 {
733         struct old_sigaction sa;
734         int r;
735
736         if (!addr) {
737                 tprints("NULL");
738                 return;
739         }
740         if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
741                 tprintf("%#lx", addr);
742                 return;
743         }
744
745 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
746         if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
747                 struct old_sigaction32 sa32;
748                 r = umove(tcp, addr, &sa32);
749                 if (r >= 0) {
750                         memset(&sa, 0, sizeof(sa));
751                         sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
752                         sa.sa_flags = sa32.sa_flags;
753                         sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
754                         sa.sa_mask = sa32.sa_mask;
755                 }
756         } else
757 #endif
758         {
759                 r = umove(tcp, addr, &sa);
760         }
761         if (r < 0) {
762                 tprints("{...}");
763                 return;
764         }
765
766         /* Architectures using function pointers, like
767          * hppa, may need to manipulate the function pointer
768          * to compute the result of a comparison. However,
769          * the __sa_handler function pointer exists only in
770          * the address space of the traced process, and can't
771          * be manipulated by strace. In order to prevent the
772          * compiler from generating code to manipulate
773          * __sa_handler we cast the function pointers to long. */
774         if ((long)sa.__sa_handler == (long)SIG_ERR)
775                 tprints("{SIG_ERR, ");
776         else if ((long)sa.__sa_handler == (long)SIG_DFL)
777                 tprints("{SIG_DFL, ");
778         else if ((long)sa.__sa_handler == (long)SIG_IGN)
779                 tprints("{SIG_IGN, ");
780         else
781                 tprintf("{%#lx, ", (long) sa.__sa_handler);
782 #ifdef MIPS
783         tprintsigmask_addr("", sa.sa_mask);
784 #else
785         tprintsigmask_val("", sa.sa_mask);
786 #endif
787         tprints(", ");
788         printflags(sigact_flags, sa.sa_flags, "SA_???");
789 #ifdef SA_RESTORER
790         if (sa.sa_flags & SA_RESTORER)
791                 tprintf(", %p", sa.sa_restorer);
792 #endif
793         tprints("}");
794 }
795
796 int
797 sys_sigaction(struct tcb *tcp)
798 {
799         if (entering(tcp)) {
800                 printsignal(tcp->u_arg[0]);
801                 tprints(", ");
802                 decode_old_sigaction(tcp, tcp->u_arg[1]);
803                 tprints(", ");
804         } else
805                 decode_old_sigaction(tcp, tcp->u_arg[2]);
806         return 0;
807 }
808
809 int
810 sys_signal(struct tcb *tcp)
811 {
812         if (entering(tcp)) {
813                 printsignal(tcp->u_arg[0]);
814                 tprints(", ");
815                 switch (tcp->u_arg[1]) {
816                 case (long) SIG_ERR:
817                         tprints("SIG_ERR");
818                         break;
819                 case (long) SIG_DFL:
820                         tprints("SIG_DFL");
821                         break;
822                 case (long) SIG_IGN:
823                         tprints("SIG_IGN");
824                         break;
825                 default:
826                         tprintf("%#lx", tcp->u_arg[1]);
827                 }
828                 return 0;
829         }
830         else if (!syserror(tcp)) {
831                 switch (tcp->u_rval) {
832                 case (long) SIG_ERR:
833                         tcp->auxstr = "SIG_ERR"; break;
834                 case (long) SIG_DFL:
835                         tcp->auxstr = "SIG_DFL"; break;
836                 case (long) SIG_IGN:
837                         tcp->auxstr = "SIG_IGN"; break;
838                 default:
839                         tcp->auxstr = NULL;
840                 }
841                 return RVAL_HEX | RVAL_STR;
842         }
843         return 0;
844 }
845
846 #endif /* HAVE_SIGACTION */
847
848 int
849 sys_sigreturn(struct tcb *tcp)
850 {
851 #if defined(ARM)
852         if (entering(tcp)) {
853                 struct arm_sigcontext {
854                         unsigned long trap_no;
855                         unsigned long error_code;
856                         unsigned long oldmask;
857                         unsigned long arm_r0;
858                         unsigned long arm_r1;
859                         unsigned long arm_r2;
860                         unsigned long arm_r3;
861                         unsigned long arm_r4;
862                         unsigned long arm_r5;
863                         unsigned long arm_r6;
864                         unsigned long arm_r7;
865                         unsigned long arm_r8;
866                         unsigned long arm_r9;
867                         unsigned long arm_r10;
868                         unsigned long arm_fp;
869                         unsigned long arm_ip;
870                         unsigned long arm_sp;
871                         unsigned long arm_lr;
872                         unsigned long arm_pc;
873                         unsigned long arm_cpsr;
874                         unsigned long fault_address;
875                 };
876                 struct arm_ucontext {
877                         unsigned long uc_flags;
878                         unsigned long uc_link;  /* struct ucontext* */
879                         /* The next three members comprise stack_t struct: */
880                         unsigned long ss_sp;    /* void*   */
881                         unsigned long ss_flags; /* int     */
882                         unsigned long ss_size;  /* size_t  */
883                         struct arm_sigcontext sc;
884                         /* These two members are sigset_t: */
885                         unsigned long uc_sigmask[2];
886                         /* more fields follow, which we aren't interested in */
887                 };
888                 struct arm_ucontext uc;
889                 if (umove(tcp, arm_regs.ARM_sp, &uc) < 0)
890                         return 0;
891                 /*
892                  * Kernel fills out uc.sc.oldmask too when it sets up signal stack,
893                  * but for sigmask restore, sigreturn syscall uses uc.uc_sigmask instead.
894                  */
895                 tprintsigmask_addr(") (mask ", uc.uc_sigmask);
896         }
897 #elif defined(S390) || defined(S390X)
898         if (entering(tcp)) {
899                 long usp;
900                 struct sigcontext sc;
901                 if (upeek(tcp->pid, PT_GPR15, &usp) < 0)
902                         return 0;
903                 if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &sc) < 0)
904                         return 0;
905                 tprintsigmask_addr(") (mask ", sc.oldmask);
906         }
907 #elif defined(I386) || defined(X86_64)
908 # if defined(X86_64)
909         if (current_personality == 0) /* 64-bit */
910                 return 0;
911 # endif
912         if (entering(tcp)) {
913                 struct i386_sigcontext_struct {
914                         uint16_t gs, __gsh;
915                         uint16_t fs, __fsh;
916                         uint16_t es, __esh;
917                         uint16_t ds, __dsh;
918                         uint32_t edi;
919                         uint32_t esi;
920                         uint32_t ebp;
921                         uint32_t esp;
922                         uint32_t ebx;
923                         uint32_t edx;
924                         uint32_t ecx;
925                         uint32_t eax;
926                         uint32_t trapno;
927                         uint32_t err;
928                         uint32_t eip;
929                         uint16_t cs, __csh;
930                         uint32_t eflags;
931                         uint32_t esp_at_signal;
932                         uint16_t ss, __ssh;
933                         uint32_t i387;
934                         uint32_t oldmask;
935                         uint32_t cr2;
936                 };
937                 struct i386_fpstate {
938                         uint32_t cw;
939                         uint32_t sw;
940                         uint32_t tag;
941                         uint32_t ipoff;
942                         uint32_t cssel;
943                         uint32_t dataoff;
944                         uint32_t datasel;
945                         uint8_t  st[8][10]; /* 8*10 bytes: FP regs */
946                         uint16_t status;
947                         uint16_t magic;
948                         uint32_t fxsr_env[6];
949                         uint32_t mxcsr;
950                         uint32_t reserved;
951                         uint8_t  stx[8][16]; /* 8*16 bytes: FP regs, each padded to 16 bytes */
952                         uint8_t  xmm[8][16]; /* 8 XMM regs */
953                         uint32_t padding1[44];
954                         uint32_t padding2[12]; /* union with struct _fpx_sw_bytes */
955                 };
956                 struct {
957                         struct i386_sigcontext_struct sc;
958                         struct i386_fpstate fp;
959                         uint32_t extramask[1];
960                 } signal_stack;
961                 /* On i386, sc is followed on stack by struct fpstate
962                  * and after it an additional u32 extramask[1] which holds
963                  * upper half of the mask.
964                  */
965                 uint32_t sigmask[2];
966                 if (umove(tcp, *i386_esp_ptr, &signal_stack) < 0)
967                         return 0;
968                 sigmask[0] = signal_stack.sc.oldmask;
969                 sigmask[1] = signal_stack.extramask[0];
970                 tprintsigmask_addr(") (mask ", sigmask);
971         }
972 #elif defined(IA64)
973         if (entering(tcp)) {
974                 struct sigcontext sc;
975                 long sp;
976                 /* offset of sigcontext in the kernel's sigframe structure: */
977 #               define SIGFRAME_SC_OFFSET       0x90
978                 if (upeek(tcp->pid, PT_R12, &sp) < 0)
979                         return 0;
980                 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
981                         return 0;
982                 tprintsigmask_val(") (mask ", sc.sc_mask);
983         }
984 #elif defined(POWERPC)
985         if (entering(tcp)) {
986                 long esp;
987                 struct sigcontext sc;
988
989                 esp = ppc_regs.gpr[1];
990
991                 /* Skip dummy stack frame. */
992 #ifdef POWERPC64
993                 if (current_personality == 0)
994                         esp += 128;
995                 else
996                         esp += 64;
997 #else
998                 esp += 64;
999 #endif
1000                 if (umove(tcp, esp, &sc) < 0)
1001                         return 0;
1002                 tprintsigmask_val(") (mask ", sc.oldmask);
1003         }
1004 #elif defined(M68K)
1005         if (entering(tcp)) {
1006                 long usp;
1007                 struct sigcontext sc;
1008                 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
1009                         return 0;
1010                 if (umove(tcp, usp, &sc) < 0)
1011                         return 0;
1012                 tprintsigmask_val(") (mask ", sc.sc_mask);
1013         }
1014 #elif defined(ALPHA)
1015         if (entering(tcp)) {
1016                 long fp;
1017                 struct sigcontext sc;
1018                 if (upeek(tcp->pid, REG_FP, &fp) < 0)
1019                         return 0;
1020                 if (umove(tcp, fp, &sc) < 0)
1021                         return 0;
1022                 tprintsigmask_val(") (mask ", sc.sc_mask);
1023         }
1024 #elif defined(SPARC) || defined(SPARC64)
1025         if (entering(tcp)) {
1026                 long i1;
1027                 m_siginfo_t si;
1028                 i1 = sparc_regs.u_regs[U_REG_O1];
1029                 if (umove(tcp, i1, &si) < 0) {
1030                         perror_msg("sigreturn: umove");
1031                         return 0;
1032                 }
1033                 tprintsigmask_val(") (mask ", si.si_mask);
1034         }
1035 #elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
1036         /* This decodes rt_sigreturn.  The 64-bit ABIs do not have
1037            sigreturn.  */
1038         if (entering(tcp)) {
1039                 long sp;
1040                 struct ucontext uc;
1041                 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1042                         return 0;
1043                 /* There are six words followed by a 128-byte siginfo.  */
1044                 sp = sp + 6 * 4 + 128;
1045                 if (umove(tcp, sp, &uc) < 0)
1046                         return 0;
1047                 tprintsigmask_val(") (mask ", uc.uc_sigmask);
1048         }
1049 #elif defined(MIPS)
1050         if (entering(tcp)) {
1051                 long sp;
1052                 struct pt_regs regs;
1053                 m_siginfo_t si;
1054                 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1055                         perror_msg("sigreturn: PTRACE_GETREGS");
1056                         return 0;
1057                 }
1058                 sp = regs.regs[29];
1059                 if (umove(tcp, sp, &si) < 0)
1060                         return 0;
1061                 tprintsigmask_val(") (mask ", si.si_mask);
1062         }
1063 #elif defined(CRISV10) || defined(CRISV32)
1064         if (entering(tcp)) {
1065                 struct sigcontext sc;
1066                 long regs[PT_MAX+1];
1067                 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1068                         perror_msg("sigreturn: PTRACE_GETREGS");
1069                         return 0;
1070                 }
1071                 if (umove(tcp, regs[PT_USP], &sc) < 0)
1072                         return 0;
1073                 tprintsigmask_val(") (mask ", sc.oldmask);
1074         }
1075 #elif defined(TILE)
1076         if (entering(tcp)) {
1077                 struct ucontext uc;
1078
1079                 /* offset of ucontext in the kernel's sigframe structure */
1080 #               define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
1081                 if (umove(tcp, tile_regs.sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1082                         return 0;
1083                 tprintsigmask_val(") (mask ", uc.uc_sigmask);
1084         }
1085 #elif defined(MICROBLAZE)
1086         /* TODO: Verify that this is correct...  */
1087         if (entering(tcp)) {
1088                 struct sigcontext sc;
1089                 long sp;
1090                 /* Read r1, the stack pointer.  */
1091                 if (upeek(tcp->pid, 1 * 4, &sp) < 0)
1092                         return 0;
1093                 if (umove(tcp, sp, &sc) < 0)
1094                         return 0;
1095                 tprintsigmask_val(") (mask ", sc.oldmask);
1096         }
1097 #elif defined(XTENSA)
1098         /* Xtensa only has rt_sys_sigreturn */
1099 #elif defined(ARC)
1100         /* ARC syscall ABI only supports rt_sys_sigreturn */
1101 #else
1102 # warning No sys_sigreturn() for this architecture
1103 # warning         (no problem, just a reminder :-)
1104 #endif
1105         return 0;
1106 }
1107
1108 int
1109 sys_siggetmask(struct tcb *tcp)
1110 {
1111         if (exiting(tcp)) {
1112                 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
1113         }
1114         return RVAL_HEX | RVAL_STR;
1115 }
1116
1117 int
1118 sys_sigsuspend(struct tcb *tcp)
1119 {
1120         if (entering(tcp)) {
1121                 tprintsigmask_val("", tcp->u_arg[2]);
1122         }
1123         return 0;
1124 }
1125
1126 #if !defined SS_ONSTACK
1127 #define SS_ONSTACK      1
1128 #define SS_DISABLE      2
1129 #endif
1130
1131 static const struct xlat sigaltstack_flags[] = {
1132         XLAT(SS_ONSTACK),
1133         XLAT(SS_DISABLE),
1134         XLAT_END
1135 };
1136
1137 static void
1138 print_stack_t(struct tcb *tcp, unsigned long addr)
1139 {
1140         stack_t ss;
1141         int r;
1142
1143         if (!addr) {
1144                 tprints("NULL");
1145                 return;
1146         }
1147
1148 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1149         if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
1150                 struct {
1151                         uint32_t ss_sp;
1152                         int32_t ss_flags;
1153                         uint32_t ss_size;
1154                 } ss32;
1155                 r = umove(tcp, addr, &ss32);
1156                 if (r >= 0) {
1157                         memset(&ss, 0, sizeof(ss));
1158                         ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
1159                         ss.ss_flags = ss32.ss_flags;
1160                         ss.ss_size = (unsigned long) ss32.ss_size;
1161                 }
1162         } else
1163 #endif
1164         {
1165                 r = umove(tcp, addr, &ss);
1166         }
1167         if (r < 0) {
1168                 tprintf("%#lx", addr);
1169         } else {
1170                 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1171                 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1172                 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1173         }
1174 }
1175
1176 int
1177 sys_sigaltstack(struct tcb *tcp)
1178 {
1179         if (entering(tcp)) {
1180                 print_stack_t(tcp, tcp->u_arg[0]);
1181         }
1182         else {
1183                 tprints(", ");
1184                 print_stack_t(tcp, tcp->u_arg[1]);
1185         }
1186         return 0;
1187 }
1188
1189 #ifdef HAVE_SIGACTION
1190
1191 /* "Old" sigprocmask, which operates with word-sized signal masks */
1192 int
1193 sys_sigprocmask(struct tcb *tcp)
1194 {
1195 # ifdef ALPHA
1196         if (entering(tcp)) {
1197                 /*
1198                  * Alpha/OSF is different: it doesn't pass in two pointers,
1199                  * but rather passes in the new bitmask as an argument and
1200                  * then returns the old bitmask.  This "works" because we
1201                  * only have 64 signals to worry about.  If you want more,
1202                  * use of the rt_sigprocmask syscall is required.
1203                  * Alpha:
1204                  *      old = osf_sigprocmask(how, new);
1205                  * Everyone else:
1206                  *      ret = sigprocmask(how, &new, &old, ...);
1207                  */
1208                 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1209                 tprintsigmask_val(", ", tcp->u_arg[1]);
1210         }
1211         else if (!syserror(tcp)) {
1212                 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
1213                 return RVAL_HEX | RVAL_STR;
1214         }
1215 # else /* !ALPHA */
1216         if (entering(tcp)) {
1217                 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1218                 tprints(", ");
1219                 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
1220                 tprints(", ");
1221         }
1222         else {
1223                 if (syserror(tcp))
1224                         tprintf("%#lx", tcp->u_arg[2]);
1225                 else
1226                         print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
1227         }
1228 # endif /* !ALPHA */
1229         return 0;
1230 }
1231
1232 #endif /* HAVE_SIGACTION */
1233
1234 int
1235 sys_kill(struct tcb *tcp)
1236 {
1237         if (entering(tcp)) {
1238                 tprintf("%ld, %s",
1239                         widen_to_long(tcp->u_arg[0]),
1240                         signame(tcp->u_arg[1])
1241                 );
1242         }
1243         return 0;
1244 }
1245
1246 int
1247 sys_tgkill(struct tcb *tcp)
1248 {
1249         if (entering(tcp)) {
1250                 tprintf("%ld, %ld, %s",
1251                         widen_to_long(tcp->u_arg[0]),
1252                         widen_to_long(tcp->u_arg[1]),
1253                         signame(tcp->u_arg[2])
1254                 );
1255         }
1256         return 0;
1257 }
1258
1259 int
1260 sys_sigpending(struct tcb *tcp)
1261 {
1262         if (exiting(tcp)) {
1263                 if (syserror(tcp))
1264                         tprintf("%#lx", tcp->u_arg[0]);
1265                 else
1266                         print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
1267         }
1268         return 0;
1269 }
1270
1271 int
1272 sys_rt_sigprocmask(struct tcb *tcp)
1273 {
1274         /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
1275         if (entering(tcp)) {
1276                 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1277                 tprints(", ");
1278                 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1279                 tprints(", ");
1280         }
1281         else {
1282                 if (syserror(tcp))
1283                         tprintf("%#lx", tcp->u_arg[2]);
1284                 else
1285                         print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
1286                 tprintf(", %lu", tcp->u_arg[3]);
1287         }
1288         return 0;
1289 }
1290
1291 /* Structure describing the action to be taken when a signal arrives.  */
1292 struct new_sigaction
1293 {
1294         /* sa_handler may be a libc #define, need to use other name: */
1295 #ifdef MIPS
1296         unsigned int sa_flags;
1297         void (*__sa_handler)(int);
1298 #else
1299         void (*__sa_handler)(int);
1300         unsigned long sa_flags;
1301         void (*sa_restorer)(void);
1302 #endif /* !MIPS */
1303         /* Kernel treats sa_mask as an array of longs. */
1304         unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1305 };
1306 /* Same for i386-on-x86_64 and similar cases */
1307 struct new_sigaction32
1308 {
1309         uint32_t __sa_handler;
1310         uint32_t sa_flags;
1311         uint32_t sa_restorer;
1312         uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
1313 };
1314
1315 static void
1316 decode_new_sigaction(struct tcb *tcp, long addr)
1317 {
1318         struct new_sigaction sa;
1319         int r;
1320
1321         if (!addr) {
1322                 tprints("NULL");
1323                 return;
1324         }
1325         if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
1326                 tprintf("%#lx", addr);
1327                 return;
1328         }
1329 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1330         if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
1331                 struct new_sigaction32 sa32;
1332                 r = umove(tcp, addr, &sa32);
1333                 if (r >= 0) {
1334                         memset(&sa, 0, sizeof(sa));
1335                         sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1336                         sa.sa_flags     = sa32.sa_flags;
1337                         sa.sa_restorer  = (void*)(unsigned long)sa32.sa_restorer;
1338                         /* Kernel treats sa_mask as an array of longs.
1339                          * For 32-bit process, "long" is uint32_t, thus, for example,
1340                          * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1341                          * But for (64-bit) kernel, 32th bit in sa_mask is
1342                          * 32th bit in 0th (64-bit) long!
1343                          * For little-endian, it's the same.
1344                          * For big-endian, we swap 32-bit words.
1345                          */
1346                         sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1347                 }
1348         } else
1349 #endif
1350         {
1351                 r = umove(tcp, addr, &sa);
1352         }
1353         if (r < 0) {
1354                 tprints("{...}");
1355                 return;
1356         }
1357         /* Architectures using function pointers, like
1358          * hppa, may need to manipulate the function pointer
1359          * to compute the result of a comparison. However,
1360          * the __sa_handler function pointer exists only in
1361          * the address space of the traced process, and can't
1362          * be manipulated by strace. In order to prevent the
1363          * compiler from generating code to manipulate
1364          * __sa_handler we cast the function pointers to long. */
1365         if ((long)sa.__sa_handler == (long)SIG_ERR)
1366                 tprints("{SIG_ERR, ");
1367         else if ((long)sa.__sa_handler == (long)SIG_DFL)
1368                 tprints("{SIG_DFL, ");
1369         else if ((long)sa.__sa_handler == (long)SIG_IGN)
1370                 tprints("{SIG_IGN, ");
1371         else
1372                 tprintf("{%#lx, ", (long) sa.__sa_handler);
1373         /*
1374          * Sigset size is in tcp->u_arg[4] (SPARC)
1375          * or in tcp->u_arg[3] (all other),
1376          * but kernel won't handle sys_rt_sigaction
1377          * with wrong sigset size (just returns EINVAL instead).
1378          * We just fetch the right size, which is NSIG / 8.
1379          */
1380         tprintsigmask_val("", sa.sa_mask);
1381         tprints(", ");
1382
1383         printflags(sigact_flags, sa.sa_flags, "SA_???");
1384 #ifdef SA_RESTORER
1385         if (sa.sa_flags & SA_RESTORER)
1386                 tprintf(", %p", sa.sa_restorer);
1387 #endif
1388         tprints("}");
1389 }
1390
1391 int
1392 sys_rt_sigaction(struct tcb *tcp)
1393 {
1394         if (entering(tcp)) {
1395                 printsignal(tcp->u_arg[0]);
1396                 tprints(", ");
1397                 decode_new_sigaction(tcp, tcp->u_arg[1]);
1398                 tprints(", ");
1399         } else {
1400                 decode_new_sigaction(tcp, tcp->u_arg[2]);
1401 #if defined(SPARC) || defined(SPARC64)
1402                 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1403 #elif defined(ALPHA)
1404                 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1405 #else
1406                 tprintf(", %lu", tcp->u_arg[3]);
1407 #endif
1408         }
1409         return 0;
1410 }
1411
1412 int
1413 sys_rt_sigpending(struct tcb *tcp)
1414 {
1415         if (exiting(tcp)) {
1416                 /*
1417                  * One of the few syscalls where sigset size (arg[1])
1418                  * is allowed to be <= NSIG / 8, not strictly ==.
1419                  * This allows non-rt sigpending() syscall
1420                  * to reuse rt_sigpending() code in kernel.
1421                  */
1422                 if (syserror(tcp))
1423                         tprintf("%#lx", tcp->u_arg[0]);
1424                 else
1425                         print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1426                 tprintf(", %lu", tcp->u_arg[1]);
1427         }
1428         return 0;
1429 }
1430
1431 int
1432 sys_rt_sigsuspend(struct tcb *tcp)
1433 {
1434         if (entering(tcp)) {
1435                 /* NB: kernel requires arg[1] == NSIG / 8 */
1436                 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1437                 tprintf(", %lu", tcp->u_arg[1]);
1438         }
1439         return 0;
1440 }
1441
1442 static void
1443 print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1444 {
1445         printsignal(sig);
1446         tprints(", ");
1447         printsiginfo_at(tcp, uinfo);
1448 }
1449
1450 int
1451 sys_rt_sigqueueinfo(struct tcb *tcp)
1452 {
1453         if (entering(tcp)) {
1454                 tprintf("%lu, ", tcp->u_arg[0]);
1455                 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1456         }
1457         return 0;
1458 }
1459
1460 int
1461 sys_rt_tgsigqueueinfo(struct tcb *tcp)
1462 {
1463         if (entering(tcp)) {
1464                 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1465                 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
1466         }
1467         return 0;
1468 }
1469
1470 int sys_rt_sigtimedwait(struct tcb *tcp)
1471 {
1472         /* NB: kernel requires arg[3] == NSIG / 8 */
1473         if (entering(tcp)) {
1474                 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
1475                 tprints(", ");
1476                 /* This is the only "return" parameter, */
1477                 if (tcp->u_arg[1] != 0)
1478                         return 0;
1479                 /* ... if it's NULL, can decode all on entry */
1480                 tprints("NULL, ");
1481         }
1482         else if (tcp->u_arg[1] != 0) {
1483                 /* syscall exit, and u_arg[1] wasn't NULL */
1484                 printsiginfo_at(tcp, tcp->u_arg[1]);
1485                 tprints(", ");
1486         }
1487         else {
1488                 /* syscall exit, and u_arg[1] was NULL */
1489                 return 0;
1490         }
1491         print_timespec(tcp, tcp->u_arg[2]);
1492         tprintf(", %lu", tcp->u_arg[3]);
1493         return 0;
1494 };
1495
1496 int
1497 sys_restart_syscall(struct tcb *tcp)
1498 {
1499         if (entering(tcp))
1500                 tprints("<... resuming interrupted call ...>");
1501         return 0;
1502 }
1503
1504 static int
1505 do_signalfd(struct tcb *tcp, int flags_arg)
1506 {
1507         /* NB: kernel requires arg[2] == NSIG / 8 */
1508         if (entering(tcp)) {
1509                 printfd(tcp, tcp->u_arg[0]);
1510                 tprints(", ");
1511                 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1512                 tprintf(", %lu", tcp->u_arg[2]);
1513                 if (flags_arg >= 0) {
1514                         tprints(", ");
1515                         printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1516                 }
1517         }
1518         return 0;
1519 }
1520
1521 int
1522 sys_signalfd(struct tcb *tcp)
1523 {
1524         return do_signalfd(tcp, -1);
1525 }
1526
1527 int
1528 sys_signalfd4(struct tcb *tcp)
1529 {
1530         return do_signalfd(tcp, 3);
1531 }