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