]> granicus.if.org Git - strace/blob - signal.c
Rewrite signal mask decoding without sigset_t
[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 TRAP_BRKPT      1       /* process breakpoint */
358 #define TRAP_TRACE      2       /* process trace trap */
359 #define CLD_EXITED      1       /* child has exited */
360 #define CLD_KILLED      2       /* child was killed */
361 #define CLD_DUMPED      3       /* child terminated abnormally */
362 #define CLD_TRAPPED     4       /* traced child has trapped */
363 #define CLD_STOPPED     5       /* child has stopped */
364 #define CLD_CONTINUED   6       /* stopped child has continued */
365 #define POLL_IN         1       /* data input available */
366 #define POLL_OUT        2       /* output buffers available */
367 #define POLL_MSG        3       /* input message available */
368 #define POLL_ERR        4       /* i/o error */
369 #define POLL_PRI        5       /* high priority input available */
370 #define POLL_HUP        6       /* device disconnected */
371 #define SI_KERNEL       0x80    /* sent by kernel */
372 #define SI_USER         0       /* sent by kill, sigsend, raise */
373 #define SI_QUEUE        -1      /* sent by sigqueue */
374 #define SI_TIMER        -2      /* sent by timer expiration */
375 #define SI_MESGQ        -3      /* sent by real time mesq state change */
376 #define SI_ASYNCIO      -4      /* sent by AIO completion */
377 #define SI_SIGIO        -5      /* sent by SIGIO */
378 #define SI_TKILL        -6      /* sent by tkill */
379 #define SI_ASYNCNL      -60     /* sent by asynch name lookup completion */
380 #endif
381
382 #ifndef SI_FROMUSER
383 # define SI_FROMUSER(sip)       ((sip)->si_code <= 0)
384 #endif
385
386 static const struct xlat siginfo_codes[] = {
387 #ifdef SI_KERNEL
388         XLAT(SI_KERNEL),
389 #endif
390 #ifdef SI_USER
391         XLAT(SI_USER),
392 #endif
393 #ifdef SI_QUEUE
394         XLAT(SI_QUEUE),
395 #endif
396 #ifdef SI_TIMER
397         XLAT(SI_TIMER),
398 #endif
399 #ifdef SI_MESGQ
400         XLAT(SI_MESGQ),
401 #endif
402 #ifdef SI_ASYNCIO
403         XLAT(SI_ASYNCIO),
404 #endif
405 #ifdef SI_SIGIO
406         XLAT(SI_SIGIO),
407 #endif
408 #ifdef SI_TKILL
409         XLAT(SI_TKILL),
410 #endif
411 #ifdef SI_ASYNCNL
412         XLAT(SI_ASYNCNL),
413 #endif
414 #ifdef SI_NOINFO
415         XLAT(SI_NOINFO),
416 #endif
417 #ifdef SI_LWP
418         XLAT(SI_LWP),
419 #endif
420         XLAT_END
421 };
422
423 static const struct xlat sigill_codes[] = {
424         XLAT(ILL_ILLOPC),
425         XLAT(ILL_ILLOPN),
426         XLAT(ILL_ILLADR),
427         XLAT(ILL_ILLTRP),
428         XLAT(ILL_PRVOPC),
429         XLAT(ILL_PRVREG),
430         XLAT(ILL_COPROC),
431         XLAT(ILL_BADSTK),
432         XLAT_END
433 };
434
435 static const struct xlat sigfpe_codes[] = {
436         XLAT(FPE_INTDIV),
437         XLAT(FPE_INTOVF),
438         XLAT(FPE_FLTDIV),
439         XLAT(FPE_FLTOVF),
440         XLAT(FPE_FLTUND),
441         XLAT(FPE_FLTRES),
442         XLAT(FPE_FLTINV),
443         XLAT(FPE_FLTSUB),
444         XLAT_END
445 };
446
447 static const struct xlat sigtrap_codes[] = {
448         XLAT(TRAP_BRKPT),
449         XLAT(TRAP_TRACE),
450         XLAT_END
451 };
452
453 static const struct xlat sigchld_codes[] = {
454         XLAT(CLD_EXITED),
455         XLAT(CLD_KILLED),
456         XLAT(CLD_DUMPED),
457         XLAT(CLD_TRAPPED),
458         XLAT(CLD_STOPPED),
459         XLAT(CLD_CONTINUED),
460         XLAT_END
461 };
462
463 static const struct xlat sigpoll_codes[] = {
464         XLAT(POLL_IN),
465         XLAT(POLL_OUT),
466         XLAT(POLL_MSG),
467         XLAT(POLL_ERR),
468         XLAT(POLL_PRI),
469         XLAT(POLL_HUP),
470         XLAT_END
471 };
472
473 static const struct xlat sigprof_codes[] = {
474 #ifdef PROF_SIG
475         XLAT(PROF_SIG),
476 #endif
477         XLAT_END
478 };
479
480 #ifdef SIGEMT
481 static const struct xlat sigemt_codes[] = {
482 #ifdef EMT_TAGOVF
483         XLAT(EMT_TAGOVF),
484 #endif
485         XLAT_END
486 };
487 #endif
488
489 static const struct xlat sigsegv_codes[] = {
490         XLAT(SEGV_MAPERR),
491         XLAT(SEGV_ACCERR),
492         XLAT_END
493 };
494
495 static const struct xlat sigbus_codes[] = {
496         XLAT(BUS_ADRALN),
497         XLAT(BUS_ADRERR),
498         XLAT(BUS_OBJERR),
499         XLAT_END
500 };
501
502 void
503 printsiginfo(siginfo_t *sip, int verbose)
504 {
505         const char *code;
506
507         if (sip->si_signo == 0) {
508                 tprints("{}");
509                 return;
510         }
511         tprints("{si_signo=");
512         printsignal(sip->si_signo);
513         code = xlookup(siginfo_codes, sip->si_code);
514         if (!code) {
515                 switch (sip->si_signo) {
516                 case SIGTRAP:
517                         code = xlookup(sigtrap_codes, sip->si_code);
518                         break;
519                 case SIGCHLD:
520                         code = xlookup(sigchld_codes, sip->si_code);
521                         break;
522                 case SIGPOLL:
523                         code = xlookup(sigpoll_codes, sip->si_code);
524                         break;
525                 case SIGPROF:
526                         code = xlookup(sigprof_codes, sip->si_code);
527                         break;
528                 case SIGILL:
529                         code = xlookup(sigill_codes, sip->si_code);
530                         break;
531 #ifdef SIGEMT
532                 case SIGEMT:
533                         code = xlookup(sigemt_codes, sip->si_code);
534                         break;
535 #endif
536                 case SIGFPE:
537                         code = xlookup(sigfpe_codes, sip->si_code);
538                         break;
539                 case SIGSEGV:
540                         code = xlookup(sigsegv_codes, sip->si_code);
541                         break;
542                 case SIGBUS:
543                         code = xlookup(sigbus_codes, sip->si_code);
544                         break;
545                 }
546         }
547         if (code)
548                 tprintf(", si_code=%s", code);
549         else
550                 tprintf(", si_code=%#x", sip->si_code);
551 #ifdef SI_NOINFO
552         if (sip->si_code != SI_NOINFO)
553 #endif
554         {
555                 if (sip->si_errno) {
556                         if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
557                                 tprintf(", si_errno=%d", sip->si_errno);
558                         else
559                                 tprintf(", si_errno=%s",
560                                         errnoent[sip->si_errno]);
561                 }
562 #ifdef SI_FROMUSER
563                 if (SI_FROMUSER(sip)) {
564                         tprintf(", si_pid=%lu, si_uid=%lu",
565                                 (unsigned long) sip->si_pid,
566                                 (unsigned long) sip->si_uid);
567                         switch (sip->si_code) {
568 #ifdef SI_USER
569                         case SI_USER:
570                                 break;
571 #endif
572 #ifdef SI_TKILL
573                         case SI_TKILL:
574                                 break;
575 #endif
576 #ifdef SI_TIMER
577                         case SI_TIMER:
578                                 tprintf(", si_value=%d", sip->si_int);
579                                 break;
580 #endif
581                         default:
582                                 if (!sip->si_ptr)
583                                         break;
584                                 if (!verbose)
585                                         tprints(", ...");
586                                 else
587                                         tprintf(", si_value={int=%u, ptr=%#lx}",
588                                                 sip->si_int,
589                                                 (unsigned long) sip->si_ptr);
590                                 break;
591                         }
592                 }
593                 else
594 #endif /* SI_FROMUSER */
595                 {
596                         switch (sip->si_signo) {
597                         case SIGCHLD:
598                                 tprintf(", si_pid=%ld, si_status=",
599                                         (long) sip->si_pid);
600                                 if (sip->si_code == CLD_EXITED)
601                                         tprintf("%d", sip->si_status);
602                                 else
603                                         printsignal(sip->si_status);
604                                 if (!verbose)
605                                         tprints(", ...");
606                                 else
607                                         tprintf(", si_utime=%llu, si_stime=%llu",
608                                                 (unsigned long long) sip->si_utime,
609                                                 (unsigned long long) sip->si_stime);
610                                 break;
611                         case SIGILL: case SIGFPE:
612                         case SIGSEGV: case SIGBUS:
613                                 tprintf(", si_addr=%#lx",
614                                         (unsigned long) sip->si_addr);
615                                 break;
616                         case SIGPOLL:
617                                 switch (sip->si_code) {
618                                 case POLL_IN: case POLL_OUT: case POLL_MSG:
619                                         tprintf(", si_band=%ld",
620                                                 (long) sip->si_band);
621                                         break;
622                                 }
623                                 break;
624                         default:
625                                 if (sip->si_pid || sip->si_uid)
626                                         tprintf(", si_pid=%lu, si_uid=%lu",
627                                                 (unsigned long) sip->si_pid,
628                                                 (unsigned long) sip->si_uid);
629                                 if (!sip->si_ptr)
630                                         break;
631                                 if (!verbose)
632                                         tprints(", ...");
633                                 else {
634                                         tprintf(", si_value={int=%u, ptr=%#lx}",
635                                                 sip->si_int,
636                                                 (unsigned long) sip->si_ptr);
637                                 }
638
639                         }
640                 }
641         }
642         tprints("}");
643 }
644
645 void
646 printsiginfo_at(struct tcb *tcp, long addr)
647 {
648         siginfo_t si;
649         if (!addr) {
650                 tprints("NULL");
651                 return;
652         }
653         if (syserror(tcp)) {
654                 tprintf("%#lx", addr);
655                 return;
656         }
657         if (umove(tcp, addr, &si) < 0) {
658                 tprints("{???}");
659                 return;
660         }
661         printsiginfo(&si, verbose(tcp));
662 }
663
664 int
665 sys_sigsetmask(struct tcb *tcp)
666 {
667         if (entering(tcp)) {
668                 tprintsigmask_val("", tcp->u_arg[0]);
669         }
670         else if (!syserror(tcp)) {
671                 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
672                 return RVAL_HEX | RVAL_STR;
673         }
674         return 0;
675 }
676
677 #ifdef HAVE_SIGACTION
678
679 struct old_sigaction {
680         /* sa_handler may be a libc #define, need to use other name: */
681 #ifdef MIPS
682         unsigned int sa_flags;
683         void (*__sa_handler)(int);
684         /* Kernel treats sa_mask as an array of longs. */
685         unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
686 #else
687         void (*__sa_handler)(int);
688         unsigned long sa_mask;
689         unsigned long sa_flags;
690         void (*sa_restorer)(void);
691 #endif /* !MIPS */
692 };
693
694 static void
695 decode_old_sigaction(struct tcb *tcp, long addr)
696 {
697         struct old_sigaction sa;
698
699         if (!addr) {
700                 tprints("NULL");
701                 return;
702         }
703         if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
704                 tprintf("%#lx", addr);
705                 return;
706         }
707         if (umove(tcp, addr, &sa) < 0) {
708                 tprints("{...}");
709                 return;
710         }
711
712         /* Architectures using function pointers, like
713          * hppa, may need to manipulate the function pointer
714          * to compute the result of a comparison. However,
715          * the __sa_handler function pointer exists only in
716          * the address space of the traced process, and can't
717          * be manipulated by strace. In order to prevent the
718          * compiler from generating code to manipulate
719          * __sa_handler we cast the function pointers to long. */
720         if ((long)sa.__sa_handler == (long)SIG_ERR)
721                 tprints("{SIG_ERR, ");
722         else if ((long)sa.__sa_handler == (long)SIG_DFL)
723                 tprints("{SIG_DFL, ");
724         else if ((long)sa.__sa_handler == (long)SIG_IGN)
725                 tprints("{SIG_IGN, ");
726         else
727                 tprintf("{%#lx, ", (long) sa.__sa_handler);
728 #ifdef MIPS
729         tprintsigmask_addr("", sa.sa_mask);
730 #else
731         tprintsigmask_val("", sa.sa_mask);
732 #endif
733         tprints(", ");
734         printflags(sigact_flags, sa.sa_flags, "SA_???");
735 #ifdef SA_RESTORER
736         if (sa.sa_flags & SA_RESTORER)
737                 tprintf(", %p", sa.sa_restorer);
738 #endif
739         tprints("}");
740 }
741
742 int
743 sys_sigaction(struct tcb *tcp)
744 {
745         if (entering(tcp)) {
746                 printsignal(tcp->u_arg[0]);
747                 tprints(", ");
748                 decode_old_sigaction(tcp, tcp->u_arg[1]);
749                 tprints(", ");
750         } else
751                 decode_old_sigaction(tcp, tcp->u_arg[2]);
752         return 0;
753 }
754
755 int
756 sys_signal(struct tcb *tcp)
757 {
758         if (entering(tcp)) {
759                 printsignal(tcp->u_arg[0]);
760                 tprints(", ");
761                 switch (tcp->u_arg[1]) {
762                 case (long) SIG_ERR:
763                         tprints("SIG_ERR");
764                         break;
765                 case (long) SIG_DFL:
766                         tprints("SIG_DFL");
767                         break;
768                 case (long) SIG_IGN:
769                         tprints("SIG_IGN");
770                         break;
771                 default:
772                         tprintf("%#lx", tcp->u_arg[1]);
773                 }
774                 return 0;
775         }
776         else if (!syserror(tcp)) {
777                 switch (tcp->u_rval) {
778                 case (long) SIG_ERR:
779                         tcp->auxstr = "SIG_ERR"; break;
780                 case (long) SIG_DFL:
781                         tcp->auxstr = "SIG_DFL"; break;
782                 case (long) SIG_IGN:
783                         tcp->auxstr = "SIG_IGN"; break;
784                 default:
785                         tcp->auxstr = NULL;
786                 }
787                 return RVAL_HEX | RVAL_STR;
788         }
789         return 0;
790 }
791
792 #endif /* HAVE_SIGACTION */
793
794 int
795 sys_sigreturn(struct tcb *tcp)
796 {
797 #if defined(ARM)
798         if (entering(tcp)) {
799                 struct arm_sigcontext {
800                         unsigned long trap_no;
801                         unsigned long error_code;
802                         unsigned long oldmask;
803                         unsigned long arm_r0;
804                         unsigned long arm_r1;
805                         unsigned long arm_r2;
806                         unsigned long arm_r3;
807                         unsigned long arm_r4;
808                         unsigned long arm_r5;
809                         unsigned long arm_r6;
810                         unsigned long arm_r7;
811                         unsigned long arm_r8;
812                         unsigned long arm_r9;
813                         unsigned long arm_r10;
814                         unsigned long arm_fp;
815                         unsigned long arm_ip;
816                         unsigned long arm_sp;
817                         unsigned long arm_lr;
818                         unsigned long arm_pc;
819                         unsigned long arm_cpsr;
820                         unsigned long fault_address;
821                 };
822                 struct arm_ucontext {
823                         unsigned long uc_flags;
824                         unsigned long uc_link;  /* struct ucontext* */
825                         /* The next three members comprise stack_t struct: */
826                         unsigned long ss_sp;    /* void*   */
827                         unsigned long ss_flags; /* int     */
828                         unsigned long ss_size;  /* size_t  */
829                         struct arm_sigcontext sc;
830                         /* These two members are sigset_t: */
831                         unsigned long uc_sigmask[2];
832                         /* more fields follow, which we aren't interested in */
833                 };
834                 struct arm_ucontext uc;
835                 if (umove(tcp, arm_regs.ARM_sp, &uc) < 0)
836                         return 0;
837                 /*
838                  * Kernel fills out uc.sc.oldmask too when it sets up signal stack,
839                  * but for sigmask restore, sigreturn syscall uses uc.uc_sigmask instead.
840                  */
841                 tprintsigmask_addr(") (mask ", uc.uc_sigmask);
842         }
843 #elif defined(S390) || defined(S390X)
844         if (entering(tcp)) {
845                 long usp;
846                 struct sigcontext sc;
847                 if (upeek(tcp->pid, PT_GPR15, &usp) < 0)
848                         return 0;
849                 if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &sc) < 0)
850                         return 0;
851                 tprintsigmask_addr(") (mask ", sc.oldmask);
852         }
853 #elif defined(I386) || defined(X86_64)
854 # if defined(X86_64)
855         if (current_personality == 0) /* 64-bit */
856                 return 0;
857 # endif
858         if (entering(tcp)) {
859                 struct i386_sigcontext_struct {
860                         uint16_t gs, __gsh;
861                         uint16_t fs, __fsh;
862                         uint16_t es, __esh;
863                         uint16_t ds, __dsh;
864                         uint32_t edi;
865                         uint32_t esi;
866                         uint32_t ebp;
867                         uint32_t esp;
868                         uint32_t ebx;
869                         uint32_t edx;
870                         uint32_t ecx;
871                         uint32_t eax;
872                         uint32_t trapno;
873                         uint32_t err;
874                         uint32_t eip;
875                         uint16_t cs, __csh;
876                         uint32_t eflags;
877                         uint32_t esp_at_signal;
878                         uint16_t ss, __ssh;
879                         uint32_t i387;
880                         uint32_t oldmask;
881                         uint32_t cr2;
882                 };
883                 struct i386_fpstate {
884                         uint32_t cw;
885                         uint32_t sw;
886                         uint32_t tag;
887                         uint32_t ipoff;
888                         uint32_t cssel;
889                         uint32_t dataoff;
890                         uint32_t datasel;
891                         uint8_t  st[8][10]; /* 8*10 bytes: FP regs */
892                         uint16_t status;
893                         uint16_t magic;
894                         uint32_t fxsr_env[6];
895                         uint32_t mxcsr;
896                         uint32_t reserved;
897                         uint8_t  stx[8][16]; /* 8*16 bytes: FP regs, each padded to 16 bytes */
898                         uint8_t  xmm[8][16]; /* 8 XMM regs */
899                         uint32_t padding1[44];
900                         uint32_t padding2[12]; /* union with struct _fpx_sw_bytes */
901                 };
902                 struct {
903                         struct i386_sigcontext_struct sc;
904                         struct i386_fpstate fp;
905                         uint32_t extramask[1];
906                 } signal_stack;
907                 /* On i386, sc is followed on stack by struct fpstate
908                  * and after it an additional u32 extramask[1] which holds
909                  * upper half of the mask.
910                  */
911                 uint32_t sigmask[2];
912                 if (umove(tcp, *i386_esp_ptr, &signal_stack) < 0)
913                         return 0;
914                 sigmask[0] = signal_stack.sc.oldmask;
915                 sigmask[1] = signal_stack.extramask[0];
916                 tprintsigmask_addr(") (mask ", sigmask);
917         }
918 #elif defined(IA64)
919         if (entering(tcp)) {
920                 struct sigcontext sc;
921                 long sp;
922                 /* offset of sigcontext in the kernel's sigframe structure: */
923 #               define SIGFRAME_SC_OFFSET       0x90
924                 if (upeek(tcp->pid, PT_R12, &sp) < 0)
925                         return 0;
926                 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
927                         return 0;
928                 tprintsigmask_val(") (mask ", sc.sc_mask);
929         }
930 #elif defined(POWERPC)
931         if (entering(tcp)) {
932                 long esp;
933                 struct sigcontext sc;
934
935                 esp = ppc_regs.gpr[1];
936
937                 /* Skip dummy stack frame. */
938 #ifdef POWERPC64
939                 if (current_personality == 0)
940                         esp += 128;
941                 else
942                         esp += 64;
943 #else
944                 esp += 64;
945 #endif
946                 if (umove(tcp, esp, &sc) < 0)
947                         return 0;
948                 tprintsigmask_val(") (mask ", sc.oldmask);
949         }
950 #elif defined(M68K)
951         if (entering(tcp)) {
952                 long usp;
953                 struct sigcontext sc;
954                 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
955                         return 0;
956                 if (umove(tcp, usp, &sc) < 0)
957                         return 0;
958                 tprintsigmask_val(") (mask ", sc.sc_mask);
959         }
960 #elif defined(ALPHA)
961         if (entering(tcp)) {
962                 long fp;
963                 struct sigcontext sc;
964                 if (upeek(tcp->pid, REG_FP, &fp) < 0)
965                         return 0;
966                 if (umove(tcp, fp, &sc) < 0)
967                         return 0;
968                 tprintsigmask_val(") (mask ", sc.sc_mask);
969         }
970 #elif defined(SPARC) || defined(SPARC64)
971         if (entering(tcp)) {
972                 long i1;
973                 m_siginfo_t si;
974                 i1 = sparc_regs.u_regs[U_REG_O1];
975                 if (umove(tcp, i1, &si) < 0) {
976                         perror_msg("sigreturn: umove");
977                         return 0;
978                 }
979                 tprintsigmask_val(") (mask ", si.si_mask);
980         }
981 #elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
982         /* This decodes rt_sigreturn.  The 64-bit ABIs do not have
983            sigreturn.  */
984         if (entering(tcp)) {
985                 long sp;
986                 struct ucontext uc;
987                 if (upeek(tcp->pid, REG_SP, &sp) < 0)
988                         return 0;
989                 /* There are six words followed by a 128-byte siginfo.  */
990                 sp = sp + 6 * 4 + 128;
991                 if (umove(tcp, sp, &uc) < 0)
992                         return 0;
993                 tprintsigmask_val(") (mask ", uc.uc_sigmask);
994         }
995 #elif defined(MIPS)
996         if (entering(tcp)) {
997                 long sp;
998                 struct pt_regs regs;
999                 m_siginfo_t si;
1000                 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1001                         perror_msg("sigreturn: PTRACE_GETREGS");
1002                         return 0;
1003                 }
1004                 sp = regs.regs[29];
1005                 if (umove(tcp, sp, &si) < 0)
1006                         return 0;
1007                 tprintsigmask_val(") (mask ", si.si_mask);
1008         }
1009 #elif defined(CRISV10) || defined(CRISV32)
1010         if (entering(tcp)) {
1011                 struct sigcontext sc;
1012                 long regs[PT_MAX+1];
1013                 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1014                         perror_msg("sigreturn: PTRACE_GETREGS");
1015                         return 0;
1016                 }
1017                 if (umove(tcp, regs[PT_USP], &sc) < 0)
1018                         return 0;
1019                 tprintsigmask_val(") (mask ", sc.oldmask);
1020         }
1021 #elif defined(TILE)
1022         if (entering(tcp)) {
1023                 struct ucontext uc;
1024
1025                 /* offset of ucontext in the kernel's sigframe structure */
1026 #               define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
1027                 if (umove(tcp, tile_regs.sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1028                         return 0;
1029                 tprintsigmask_val(") (mask ", uc.uc_sigmask);
1030         }
1031 #elif defined(MICROBLAZE)
1032         /* TODO: Verify that this is correct...  */
1033         if (entering(tcp)) {
1034                 struct sigcontext sc;
1035                 long sp;
1036                 /* Read r1, the stack pointer.  */
1037                 if (upeek(tcp->pid, 1 * 4, &sp) < 0)
1038                         return 0;
1039                 if (umove(tcp, sp, &sc) < 0)
1040                         return 0;
1041                 tprintsigmask_val(") (mask ", sc.oldmask);
1042         }
1043 #elif defined(XTENSA)
1044         /* Xtensa only has rt_sys_sigreturn */
1045 #elif defined(ARC)
1046         /* ARC syscall ABI only supports rt_sys_sigreturn */
1047 #else
1048 # warning No sys_sigreturn() for this architecture
1049 # warning         (no problem, just a reminder :-)
1050 #endif
1051         return 0;
1052 }
1053
1054 int
1055 sys_siggetmask(struct tcb *tcp)
1056 {
1057         if (exiting(tcp)) {
1058                 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
1059         }
1060         return RVAL_HEX | RVAL_STR;
1061 }
1062
1063 int
1064 sys_sigsuspend(struct tcb *tcp)
1065 {
1066         if (entering(tcp)) {
1067                 tprintsigmask_val("", tcp->u_arg[2]);
1068         }
1069         return 0;
1070 }
1071
1072 #if !defined SS_ONSTACK
1073 #define SS_ONSTACK      1
1074 #define SS_DISABLE      2
1075 #endif
1076
1077 static const struct xlat sigaltstack_flags[] = {
1078         XLAT(SS_ONSTACK),
1079         XLAT(SS_DISABLE),
1080         XLAT_END
1081 };
1082
1083 static void
1084 print_stack_t(struct tcb *tcp, unsigned long addr)
1085 {
1086         stack_t ss;
1087
1088         if (!addr) {
1089                 tprints("NULL");
1090         } else if (umove(tcp, addr, &ss) < 0) {
1091                 tprintf("%#lx", addr);
1092         } else {
1093                 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1094                 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1095                 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1096         }
1097 }
1098
1099 int
1100 sys_sigaltstack(struct tcb *tcp)
1101 {
1102         if (entering(tcp)) {
1103                 print_stack_t(tcp, tcp->u_arg[0]);
1104         }
1105         else {
1106                 tprints(", ");
1107                 print_stack_t(tcp, tcp->u_arg[1]);
1108         }
1109         return 0;
1110 }
1111
1112 #ifdef HAVE_SIGACTION
1113
1114 /* "Old" sigprocmask, which operates with word-sized signal masks */
1115 int
1116 sys_sigprocmask(struct tcb *tcp)
1117 {
1118 # ifdef ALPHA
1119         if (entering(tcp)) {
1120                 /*
1121                  * Alpha/OSF is different: it doesn't pass in two pointers,
1122                  * but rather passes in the new bitmask as an argument and
1123                  * then returns the old bitmask.  This "works" because we
1124                  * only have 64 signals to worry about.  If you want more,
1125                  * use of the rt_sigprocmask syscall is required.
1126                  * Alpha:
1127                  *      old = osf_sigprocmask(how, new);
1128                  * Everyone else:
1129                  *      ret = sigprocmask(how, &new, &old, ...);
1130                  */
1131                 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1132                 tprintsigmask_val(", ", tcp->u_arg[1]);
1133         }
1134         else if (!syserror(tcp)) {
1135                 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
1136                 return RVAL_HEX | RVAL_STR;
1137         }
1138 # else /* !ALPHA */
1139         if (entering(tcp)) {
1140                 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1141                 tprints(", ");
1142                 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
1143                 tprints(", ");
1144         }
1145         else {
1146                 if (syserror(tcp))
1147                         tprintf("%#lx", tcp->u_arg[2]);
1148                 else
1149                         print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
1150         }
1151 # endif /* !ALPHA */
1152         return 0;
1153 }
1154
1155 #endif /* HAVE_SIGACTION */
1156
1157 int
1158 sys_kill(struct tcb *tcp)
1159 {
1160         if (entering(tcp)) {
1161                 tprintf("%ld, %s",
1162                         widen_to_long(tcp->u_arg[0]),
1163                         signame(tcp->u_arg[1])
1164                 );
1165         }
1166         return 0;
1167 }
1168
1169 int
1170 sys_tgkill(struct tcb *tcp)
1171 {
1172         if (entering(tcp)) {
1173                 tprintf("%ld, %ld, %s",
1174                         widen_to_long(tcp->u_arg[0]),
1175                         widen_to_long(tcp->u_arg[1]),
1176                         signame(tcp->u_arg[2])
1177                 );
1178         }
1179         return 0;
1180 }
1181
1182 int
1183 sys_sigpending(struct tcb *tcp)
1184 {
1185         if (exiting(tcp)) {
1186                 if (syserror(tcp))
1187                         tprintf("%#lx", tcp->u_arg[0]);
1188                 else
1189                         print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
1190         }
1191         return 0;
1192 }
1193
1194 int
1195 sys_rt_sigprocmask(struct tcb *tcp)
1196 {
1197         /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
1198         if (entering(tcp)) {
1199                 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1200                 tprints(", ");
1201                 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1202                 tprints(", ");
1203         }
1204         else {
1205                 if (syserror(tcp))
1206                         tprintf("%#lx", tcp->u_arg[2]);
1207                 else
1208                         print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
1209                 tprintf(", %lu", tcp->u_arg[3]);
1210         }
1211         return 0;
1212 }
1213
1214 /* Structure describing the action to be taken when a signal arrives.  */
1215 struct new_sigaction
1216 {
1217         /* sa_handler may be a libc #define, need to use other name: */
1218 #ifdef MIPS
1219         unsigned int sa_flags;
1220         void (*__sa_handler)(int);
1221 #else
1222         void (*__sa_handler)(int);
1223         unsigned long sa_flags;
1224         void (*sa_restorer)(void);
1225 #endif /* !MIPS */
1226         /* Kernel treats sa_mask as an array of longs. */
1227         unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1228 };
1229 /* Same for i386-on-x86_64 and similar cases */
1230 struct new_sigaction32
1231 {
1232         uint32_t __sa_handler;
1233         uint32_t sa_flags;
1234         uint32_t sa_restorer;
1235         uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
1236 };
1237
1238 static void
1239 decode_new_sigaction(struct tcb *tcp, long addr)
1240 {
1241         struct new_sigaction sa;
1242         int r;
1243
1244         if (!addr) {
1245                 tprints("NULL");
1246                 return;
1247         }
1248         if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
1249                 tprintf("%#lx", addr);
1250                 return;
1251         }
1252 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1253         if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
1254                 struct new_sigaction32 sa32;
1255                 r = umove(tcp, addr, &sa32);
1256                 if (r >= 0) {
1257                         memset(&sa, 0, sizeof(sa));
1258                         sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1259                         sa.sa_flags     = sa32.sa_flags;
1260                         sa.sa_restorer  = (void*)(unsigned long)sa32.sa_restorer;
1261                         /* Kernel treats sa_mask as an array of longs.
1262                          * For 32-bit process, "long" is uint32_t, thus, for example,
1263                          * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1264                          * But for (64-bit) kernel, 32th bit in sa_mask is
1265                          * 32th bit in 0th (64-bit) long!
1266                          * For little-endian, it's the same.
1267                          * For big-endian, we swap 32-bit words.
1268                          */
1269                         sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1270                 }
1271         } else
1272 #endif
1273         {
1274                 r = umove(tcp, addr, &sa);
1275         }
1276         if (r < 0) {
1277                 tprints("{...}");
1278                 return;
1279         }
1280         /* Architectures using function pointers, like
1281          * hppa, may need to manipulate the function pointer
1282          * to compute the result of a comparison. However,
1283          * the __sa_handler function pointer exists only in
1284          * the address space of the traced process, and can't
1285          * be manipulated by strace. In order to prevent the
1286          * compiler from generating code to manipulate
1287          * __sa_handler we cast the function pointers to long. */
1288         if ((long)sa.__sa_handler == (long)SIG_ERR)
1289                 tprints("{SIG_ERR, ");
1290         else if ((long)sa.__sa_handler == (long)SIG_DFL)
1291                 tprints("{SIG_DFL, ");
1292         else if ((long)sa.__sa_handler == (long)SIG_IGN)
1293                 tprints("{SIG_IGN, ");
1294         else
1295                 tprintf("{%#lx, ", (long) sa.__sa_handler);
1296         /*
1297          * Sigset size is in tcp->u_arg[4] (SPARC)
1298          * or in tcp->u_arg[3] (all other),
1299          * but kernel won't handle sys_rt_sigaction
1300          * with wrong sigset size (just returns EINVAL instead).
1301          * We just fetch the right size, which is NSIG / 8.
1302          */
1303         tprintsigmask_val("", sa.sa_mask);
1304         tprints(", ");
1305
1306         printflags(sigact_flags, sa.sa_flags, "SA_???");
1307 #ifdef SA_RESTORER
1308         if (sa.sa_flags & SA_RESTORER)
1309                 tprintf(", %p", sa.sa_restorer);
1310 #endif
1311         tprints("}");
1312 }
1313
1314 int
1315 sys_rt_sigaction(struct tcb *tcp)
1316 {
1317         if (entering(tcp)) {
1318                 printsignal(tcp->u_arg[0]);
1319                 tprints(", ");
1320                 decode_new_sigaction(tcp, tcp->u_arg[1]);
1321                 tprints(", ");
1322         } else {
1323                 decode_new_sigaction(tcp, tcp->u_arg[2]);
1324 #if defined(SPARC) || defined(SPARC64)
1325                 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1326 #elif defined(ALPHA)
1327                 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1328 #else
1329                 tprintf(", %lu", tcp->u_arg[3]);
1330 #endif
1331         }
1332         return 0;
1333 }
1334
1335 int
1336 sys_rt_sigpending(struct tcb *tcp)
1337 {
1338         if (exiting(tcp)) {
1339                 /*
1340                  * One of the few syscalls where sigset size (arg[1])
1341                  * is allowed to be <= NSIG / 8, not strictly ==.
1342                  * This allows non-rt sigpending() syscall
1343                  * to reuse rt_sigpending() code in kernel.
1344                  */
1345                 if (syserror(tcp))
1346                         tprintf("%#lx", tcp->u_arg[0]);
1347                 else
1348                         print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1349                 tprintf(", %lu", tcp->u_arg[1]);
1350         }
1351         return 0;
1352 }
1353
1354 int
1355 sys_rt_sigsuspend(struct tcb *tcp)
1356 {
1357         if (entering(tcp)) {
1358                 /* NB: kernel requires arg[1] == NSIG / 8 */
1359                 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1360                 tprintf(", %lu", tcp->u_arg[1]);
1361         }
1362         return 0;
1363 }
1364
1365 static void
1366 print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1367 {
1368         printsignal(sig);
1369         tprints(", ");
1370         printsiginfo_at(tcp, uinfo);
1371 }
1372
1373 int
1374 sys_rt_sigqueueinfo(struct tcb *tcp)
1375 {
1376         if (entering(tcp)) {
1377                 tprintf("%lu, ", tcp->u_arg[0]);
1378                 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1379         }
1380         return 0;
1381 }
1382
1383 int
1384 sys_rt_tgsigqueueinfo(struct tcb *tcp)
1385 {
1386         if (entering(tcp)) {
1387                 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1388                 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
1389         }
1390         return 0;
1391 }
1392
1393 int sys_rt_sigtimedwait(struct tcb *tcp)
1394 {
1395         /* NB: kernel requires arg[3] == NSIG / 8 */
1396         if (entering(tcp)) {
1397                 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
1398                 tprints(", ");
1399                 /* This is the only "return" parameter, */
1400                 if (tcp->u_arg[1] != 0)
1401                         return 0;
1402                 /* ... if it's NULL, can decode all on entry */
1403                 tprints("NULL, ");
1404         }
1405         else if (tcp->u_arg[1] != 0) {
1406                 /* syscall exit, and u_arg[1] wasn't NULL */
1407                 printsiginfo_at(tcp, tcp->u_arg[1]);
1408                 tprints(", ");
1409         }
1410         else {
1411                 /* syscall exit, and u_arg[1] was NULL */
1412                 return 0;
1413         }
1414         print_timespec(tcp, tcp->u_arg[2]);
1415         tprintf(", %lu", tcp->u_arg[3]);
1416         return 0;
1417 };
1418
1419 int
1420 sys_restart_syscall(struct tcb *tcp)
1421 {
1422         if (entering(tcp))
1423                 tprints("<... resuming interrupted call ...>");
1424         return 0;
1425 }
1426
1427 static int
1428 do_signalfd(struct tcb *tcp, int flags_arg)
1429 {
1430         /* NB: kernel requires arg[2] == NSIG / 8 */
1431         if (entering(tcp)) {
1432                 printfd(tcp, tcp->u_arg[0]);
1433                 tprints(", ");
1434                 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1435                 tprintf(", %lu", tcp->u_arg[2]);
1436                 if (flags_arg >= 0) {
1437                         tprints(", ");
1438                         printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1439                 }
1440         }
1441         return 0;
1442 }
1443
1444 int
1445 sys_signalfd(struct tcb *tcp)
1446 {
1447         return do_signalfd(tcp, -1);
1448 }
1449
1450 int
1451 sys_signalfd4(struct tcb *tcp)
1452 {
1453         return do_signalfd(tcp, 3);
1454 }