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