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