]> granicus.if.org Git - strace/blob - signal.c
Do not call umoven to fetch parameters if we have zero params
[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  *      $Id$
34  */
35
36 #include "defs.h"
37
38 #include <stdint.h>
39 #include <signal.h>
40 #include <sys/user.h>
41 #include <fcntl.h>
42
43 #ifdef SVR4
44 #include <sys/ucontext.h>
45 #endif /* SVR4 */
46
47 #ifdef HAVE_SYS_REG_H
48 # include <sys/reg.h>
49 #ifndef PTRACE_PEEKUSR
50 # define PTRACE_PEEKUSR PTRACE_PEEKUSER
51 #endif
52 #ifndef PTRACE_POKEUSR
53 # define PTRACE_POKEUSR PTRACE_POKEUSER
54 #endif
55 #elif defined(HAVE_LINUX_PTRACE_H)
56 #undef PTRACE_SYSCALL
57 # ifdef HAVE_STRUCT_IA64_FPREG
58 #  define ia64_fpreg XXX_ia64_fpreg
59 # endif
60 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS
61 #  define pt_all_user_regs XXX_pt_all_user_regs
62 # endif
63 #include <linux/ptrace.h>
64 # undef ia64_fpreg
65 # undef pt_all_user_regs
66 #endif
67
68
69 #ifdef LINUX
70
71 #ifdef IA64
72 # include <asm/ptrace_offsets.h>
73 #endif /* !IA64 */
74
75 #if defined (LINUX) && defined (SPARC64)
76 # undef PTRACE_GETREGS
77 # define PTRACE_GETREGS PTRACE_GETREGS64
78 # undef PTRACE_SETREGS
79 # define PTRACE_SETREGS PTRACE_SETREGS64
80 #endif /* LINUX && SPARC64 */
81
82 #if defined (SPARC) || defined (SPARC64) || defined (MIPS)
83 typedef struct {
84         struct pt_regs          si_regs;
85         int                     si_mask;
86 } m_siginfo_t;
87 #elif defined HAVE_ASM_SIGCONTEXT_H
88 #if !defined(IA64) && !defined(X86_64)
89 #include <asm/sigcontext.h>
90 #endif /* !IA64 && !X86_64 */
91 #else /* !HAVE_ASM_SIGCONTEXT_H */
92 #if defined I386 && !defined HAVE_STRUCT_SIGCONTEXT_STRUCT
93 struct sigcontext_struct {
94         unsigned short gs, __gsh;
95         unsigned short fs, __fsh;
96         unsigned short es, __esh;
97         unsigned short ds, __dsh;
98         unsigned long edi;
99         unsigned long esi;
100         unsigned long ebp;
101         unsigned long esp;
102         unsigned long ebx;
103         unsigned long edx;
104         unsigned long ecx;
105         unsigned long eax;
106         unsigned long trapno;
107         unsigned long err;
108         unsigned long eip;
109         unsigned short cs, __csh;
110         unsigned long eflags;
111         unsigned long esp_at_signal;
112         unsigned short ss, __ssh;
113         unsigned long i387;
114         unsigned long oldmask;
115         unsigned long cr2;
116 };
117 #else /* !I386 */
118 #if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
119 struct sigcontext
120 {
121         unsigned long sc_mask;
122         unsigned long sc_usp;
123         unsigned long sc_d0;
124         unsigned long sc_d1;
125         unsigned long sc_a0;
126         unsigned long sc_a1;
127         unsigned short sc_sr;
128         unsigned long sc_pc;
129         unsigned short sc_formatvec;
130 };
131 #endif /* M68K */
132 #endif /* !I386 */
133 #endif /* !HAVE_ASM_SIGCONTEXT_H */
134 #ifndef NSIG
135 #define NSIG 32
136 #endif
137 #ifdef ARM
138 #undef NSIG
139 #define NSIG 32
140 #endif
141 #endif /* LINUX */
142
143 const char *const signalent0[] = {
144 #include "signalent.h"
145 };
146 const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
147
148 #if SUPPORTED_PERSONALITIES >= 2
149 const char *const signalent1[] = {
150 #include "signalent1.h"
151 };
152 const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
153 #endif /* SUPPORTED_PERSONALITIES >= 2 */
154
155 #if SUPPORTED_PERSONALITIES >= 3
156 const char *const signalent2[] = {
157 #include "signalent2.h"
158 };
159 const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
160 #endif /* SUPPORTED_PERSONALITIES >= 3 */
161
162 const char *const *signalent;
163 int nsignals;
164
165 #if defined(SUNOS4) || defined(FREEBSD)
166
167 static const struct xlat sigvec_flags[] = {
168         { SV_ONSTACK,   "SV_ONSTACK"    },
169         { SV_INTERRUPT, "SV_INTERRUPT"  },
170         { SV_RESETHAND, "SV_RESETHAND"  },
171         { SA_NOCLDSTOP, "SA_NOCLDSTOP"  },
172         { 0,            NULL            },
173 };
174
175 #endif /* SUNOS4 || FREEBSD */
176
177 #ifdef HAVE_SIGACTION
178
179 #if defined LINUX && (defined I386 || defined X86_64)
180 /* The libc headers do not define this constant since it should only be
181    used by the implementation.  So wwe define it here.  */
182 # ifndef SA_RESTORER
183 #  define SA_RESTORER 0x04000000
184 # endif
185 #endif
186
187 static const struct xlat sigact_flags[] = {
188 #ifdef SA_RESTORER
189         { SA_RESTORER,  "SA_RESTORER"   },
190 #endif
191 #ifdef SA_STACK
192         { SA_STACK,     "SA_STACK"      },
193 #endif
194 #ifdef SA_RESTART
195         { SA_RESTART,   "SA_RESTART"    },
196 #endif
197 #ifdef SA_INTERRUPT
198         { SA_INTERRUPT, "SA_INTERRUPT"  },
199 #endif
200 #ifdef SA_NODEFER
201         { SA_NODEFER,   "SA_NODEFER"    },
202 #endif
203 #if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
204         { SA_NOMASK,    "SA_NOMASK"     },
205 #endif
206 #ifdef SA_RESETHAND
207         { SA_RESETHAND, "SA_RESETHAND"  },
208 #endif
209 #if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
210         { SA_ONESHOT,   "SA_ONESHOT"    },
211 #endif
212 #ifdef SA_SIGINFO
213         { SA_SIGINFO,   "SA_SIGINFO"    },
214 #endif
215 #ifdef SA_RESETHAND
216         { SA_RESETHAND, "SA_RESETHAND"  },
217 #endif
218 #ifdef SA_ONSTACK
219         { SA_ONSTACK,   "SA_ONSTACK"    },
220 #endif
221 #ifdef SA_NODEFER
222         { SA_NODEFER,   "SA_NODEFER"    },
223 #endif
224 #ifdef SA_NOCLDSTOP
225         { SA_NOCLDSTOP, "SA_NOCLDSTOP"  },
226 #endif
227 #ifdef SA_NOCLDWAIT
228         { SA_NOCLDWAIT, "SA_NOCLDWAIT"  },
229 #endif
230 #ifdef _SA_BSDCALL
231         { _SA_BSDCALL,  "_SA_BSDCALL"   },
232 #endif
233 #ifdef SA_NOPTRACE
234         { SA_NOPTRACE,  "SA_NOPTRACE"   },
235 #endif
236         { 0,            NULL            },
237 };
238
239 static const struct xlat sigprocmaskcmds[] = {
240         { SIG_BLOCK,    "SIG_BLOCK"     },
241         { SIG_UNBLOCK,  "SIG_UNBLOCK"   },
242         { SIG_SETMASK,  "SIG_SETMASK"   },
243 #ifdef SIG_SETMASK32
244         { SIG_SETMASK32,"SIG_SETMASK32" },
245 #endif
246         { 0,            NULL            },
247 };
248
249 #endif /* HAVE_SIGACTION */
250
251 /* Anonymous realtime signals. */
252 /* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
253    constant.  This is what we want.  Otherwise, just use SIGRTMIN. */
254 #ifdef SIGRTMIN
255 #ifndef __SIGRTMIN
256 #define __SIGRTMIN SIGRTMIN
257 #define __SIGRTMAX SIGRTMAX /* likewise */
258 #endif
259 #endif
260
261 const char *
262 signame(int sig)
263 {
264         static char buf[30];
265         if (sig >= 0 && sig < nsignals) {
266                 return signalent[sig];
267 #ifdef SIGRTMIN
268         } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
269                 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
270                 return buf;
271 #endif /* SIGRTMIN */
272         } else {
273                 sprintf(buf, "%d", sig);
274                 return buf;
275         }
276 }
277
278 #ifndef UNIXWARE
279 static void
280 long_to_sigset(long l, sigset_t *s)
281 {
282         sigemptyset(s);
283         *(long *)s = l;
284 }
285 #endif
286
287 static int
288 copy_sigset_len(struct tcb *tcp, long addr, sigset_t *s, int len)
289 {
290         if (len > sizeof(*s))
291                 len = sizeof(*s);
292         sigemptyset(s);
293         if (umoven(tcp, addr, len, (char *)s) < 0)
294                 return -1;
295         return 0;
296 }
297
298 #ifdef LINUX
299 /* Original sigset is unsigned long */
300 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
301 #else
302 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
303 #endif
304
305 static const char *
306 sprintsigmask(const char *str, sigset_t *mask, int rt)
307 /* set might include realtime sigs */
308 {
309         int i, nsigs;
310         int maxsigs;
311         const char *format;
312         char *s;
313         static char outstr[8 * sizeof(sigset_t) * 8];
314
315         strcpy(outstr, str);
316         s = outstr + strlen(outstr);
317         nsigs = 0;
318         maxsigs = nsignals;
319 #ifdef __SIGRTMAX
320         if (rt)
321                 maxsigs = __SIGRTMAX; /* instead */
322 #endif
323         for (i = 1; i < maxsigs; i++) {
324                 if (sigismember(mask, i) == 1)
325                         nsigs++;
326         }
327         if (nsigs >= nsignals * 2 / 3) {
328                 *s++ = '~';
329                 for (i = 1; i < maxsigs; i++) {
330                         switch (sigismember(mask, i)) {
331                         case 1:
332                                 sigdelset(mask, i);
333                                 break;
334                         case 0:
335                                 sigaddset(mask, i);
336                                 break;
337                         }
338                 }
339         }
340         format = "%s";
341         *s++ = '[';
342         for (i = 1; i < maxsigs; i++) {
343                 if (sigismember(mask, i) == 1) {
344                         /* real-time signals on solaris don't have
345                          * signalent entries
346                          */
347                         if (i < nsignals) {
348                                 sprintf(s, format, signalent[i] + 3);
349                         }
350 #ifdef SIGRTMIN
351                         else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
352                                 char tsig[40];
353                                 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
354                                 sprintf(s, format, tsig);
355                         }
356 #endif /* SIGRTMIN */
357                         else {
358                                 char tsig[32];
359                                 sprintf(tsig, "%u", i);
360                                 sprintf(s, format, tsig);
361                         }
362                         s += strlen(s);
363                         format = " %s";
364                 }
365         }
366         *s++ = ']';
367         *s = '\0';
368         return outstr;
369 }
370
371 static void
372 printsigmask(sigset_t *mask, int rt)
373 {
374         tprintf("%s", sprintsigmask("", mask, rt));
375 }
376
377 void
378 printsignal(int nr)
379 {
380         tprintf("%s", signame(nr));
381 }
382
383 void
384 print_sigset(struct tcb *tcp, long addr, int rt)
385 {
386         sigset_t ss;
387
388         if (!addr)
389                 tprintf("NULL");
390         else if (copy_sigset(tcp, addr, &ss) < 0)
391                 tprintf("%#lx", addr);
392         else
393                 printsigmask(&ss, rt);
394 }
395
396 #ifdef LINUX
397
398 #ifndef ILL_ILLOPC
399 #define ILL_ILLOPC      1       /* illegal opcode */
400 #define ILL_ILLOPN      2       /* illegal operand */
401 #define ILL_ILLADR      3       /* illegal addressing mode */
402 #define ILL_ILLTRP      4       /* illegal trap */
403 #define ILL_PRVOPC      5       /* privileged opcode */
404 #define ILL_PRVREG      6       /* privileged register */
405 #define ILL_COPROC      7       /* coprocessor error */
406 #define ILL_BADSTK      8       /* internal stack error */
407 #define FPE_INTDIV      1       /* integer divide by zero */
408 #define FPE_INTOVF      2       /* integer overflow */
409 #define FPE_FLTDIV      3       /* floating point divide by zero */
410 #define FPE_FLTOVF      4       /* floating point overflow */
411 #define FPE_FLTUND      5       /* floating point underflow */
412 #define FPE_FLTRES      6       /* floating point inexact result */
413 #define FPE_FLTINV      7       /* floating point invalid operation */
414 #define FPE_FLTSUB      8       /* subscript out of range */
415 #define SEGV_MAPERR     1       /* address not mapped to object */
416 #define SEGV_ACCERR     2       /* invalid permissions for mapped object */
417 #define BUS_ADRALN      1       /* invalid address alignment */
418 #define BUS_ADRERR      2       /* non-existant physical address */
419 #define BUS_OBJERR      3       /* object specific hardware error */
420 #define TRAP_BRKPT      1       /* process breakpoint */
421 #define TRAP_TRACE      2       /* process trace trap */
422 #define CLD_EXITED      1       /* child has exited */
423 #define CLD_KILLED      2       /* child was killed */
424 #define CLD_DUMPED      3       /* child terminated abnormally */
425 #define CLD_TRAPPED     4       /* traced child has trapped */
426 #define CLD_STOPPED     5       /* child has stopped */
427 #define CLD_CONTINUED   6       /* stopped child has continued */
428 #define POLL_IN         1       /* data input available */
429 #define POLL_OUT        2       /* output buffers available */
430 #define POLL_MSG        3       /* input message available */
431 #define POLL_ERR        4       /* i/o error */
432 #define POLL_PRI        5       /* high priority input available */
433 #define POLL_HUP        6       /* device disconnected */
434 #define SI_KERNEL       0x80    /* sent by kernel */
435 #define SI_USER         0       /* sent by kill, sigsend, raise */
436 #define SI_QUEUE        -1      /* sent by sigqueue */
437 #define SI_TIMER        -2      /* sent by timer expiration */
438 #define SI_MESGQ        -3      /* sent by real time mesq state change */
439 #define SI_ASYNCIO      -4      /* sent by AIO completion */
440 #define SI_SIGIO        -5      /* sent by SIGIO */
441 #define SI_TKILL        -6      /* sent by tkill */
442 #define SI_ASYNCNL      -60     /* sent by asynch name lookup completion */
443
444 #define SI_FROMUSER(sip)        ((sip)->si_code <= 0)
445
446 #endif /* LINUX */
447
448 #if __GLIBC_MINOR__ < 1
449 /* Type for data associated with a signal.  */
450 typedef union sigval
451 {
452         int sival_int;
453         void *sival_ptr;
454 } sigval_t;
455
456 # define __SI_MAX_SIZE     128
457 # define __SI_PAD_SIZE     ((__SI_MAX_SIZE / sizeof(int)) - 3)
458
459 typedef struct siginfo
460 {
461         int si_signo;               /* Signal number.  */
462         int si_errno;               /* If non-zero, an errno value associated with
463                                                                    this signal, as defined in <errno.h>.  */
464         int si_code;                /* Signal code.  */
465
466         union
467         {
468                 int _pad[__SI_PAD_SIZE];
469
470                 /* kill().  */
471                 struct
472                 {
473                         __pid_t si_pid;     /* Sending process ID.  */
474                         __uid_t si_uid;     /* Real user ID of sending process.  */
475                 } _kill;
476
477                 /* POSIX.1b timers.  */
478                 struct
479                 {
480                         unsigned int _timer1;
481                         unsigned int _timer2;
482                 } _timer;
483
484                 /* POSIX.1b signals.  */
485                 struct
486                 {
487                         __pid_t si_pid;     /* Sending process ID.  */
488                         __uid_t si_uid;     /* Real user ID of sending process.  */
489                         sigval_t si_sigval; /* Signal value.  */
490                 } _rt;
491
492                 /* SIGCHLD.  */
493                 struct
494                 {
495                         __pid_t si_pid;     /* Which child.  */
496                         int si_status;      /* Exit value or signal.  */
497                         __clock_t si_utime;
498                         __clock_t si_stime;
499                 } _sigchld;
500
501                 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS.  */
502                 struct
503                 {
504                         void *si_addr;      /* Faulting insn/memory ref.  */
505                 } _sigfault;
506
507                 /* SIGPOLL.  */
508                 struct
509                 {
510                         int si_band;        /* Band event for SIGPOLL.  */
511                         int si_fd;
512                 } _sigpoll;
513         } _sifields;
514 } siginfo_t;
515
516 #define si_pid          _sifields._kill.si_pid
517 #define si_uid          _sifields._kill.si_uid
518 #define si_status       _sifields._sigchld.si_status
519 #define si_utime        _sifields._sigchld.si_utime
520 #define si_stime        _sifields._sigchld.si_stime
521 #define si_value        _sifields._rt.si_sigval
522 #define si_int          _sifields._rt.si_sigval.sival_int
523 #define si_ptr          _sifields._rt.si_sigval.sival_ptr
524 #define si_addr         _sifields._sigfault.si_addr
525 #define si_band         _sifields._sigpoll.si_band
526 #define si_fd           _sifields._sigpoll.si_fd
527
528 #endif
529
530 #endif
531
532 #if defined (SVR4) || defined (LINUX)
533
534 static const struct xlat siginfo_codes[] = {
535 #ifdef SI_KERNEL
536         { SI_KERNEL,    "SI_KERNEL"     },
537 #endif
538 #ifdef SI_USER
539         { SI_USER,      "SI_USER"       },
540 #endif
541 #ifdef SI_QUEUE
542         { SI_QUEUE,     "SI_QUEUE"      },
543 #endif
544 #ifdef SI_TIMER
545         { SI_TIMER,     "SI_TIMER"      },
546 #endif
547 #ifdef SI_MESGQ
548         { SI_MESGQ,     "SI_MESGQ"      },
549 #endif
550 #ifdef SI_ASYNCIO
551         { SI_ASYNCIO,   "SI_ASYNCIO"    },
552 #endif
553 #ifdef SI_SIGIO
554         { SI_SIGIO,     "SI_SIGIO"      },
555 #endif
556 #ifdef SI_TKILL
557         { SI_TKILL,     "SI_TKILL"      },
558 #endif
559 #ifdef SI_ASYNCNL
560         { SI_ASYNCNL,   "SI_ASYNCNL"    },
561 #endif
562 #ifdef SI_NOINFO
563         { SI_NOINFO,    "SI_NOINFO"     },
564 #endif
565 #ifdef SI_LWP
566         { SI_LWP,       "SI_LWP"        },
567 #endif
568         { 0,            NULL            },
569 };
570
571 static const struct xlat sigill_codes[] = {
572         { ILL_ILLOPC,   "ILL_ILLOPC"    },
573         { ILL_ILLOPN,   "ILL_ILLOPN"    },
574         { ILL_ILLADR,   "ILL_ILLADR"    },
575         { ILL_ILLTRP,   "ILL_ILLTRP"    },
576         { ILL_PRVOPC,   "ILL_PRVOPC"    },
577         { ILL_PRVREG,   "ILL_PRVREG"    },
578         { ILL_COPROC,   "ILL_COPROC"    },
579         { ILL_BADSTK,   "ILL_BADSTK"    },
580         { 0,            NULL            },
581 };
582
583 static const struct xlat sigfpe_codes[] = {
584         { FPE_INTDIV,   "FPE_INTDIV"    },
585         { FPE_INTOVF,   "FPE_INTOVF"    },
586         { FPE_FLTDIV,   "FPE_FLTDIV"    },
587         { FPE_FLTOVF,   "FPE_FLTOVF"    },
588         { FPE_FLTUND,   "FPE_FLTUND"    },
589         { FPE_FLTRES,   "FPE_FLTRES"    },
590         { FPE_FLTINV,   "FPE_FLTINV"    },
591         { FPE_FLTSUB,   "FPE_FLTSUB"    },
592         { 0,            NULL            },
593 };
594
595 static const struct xlat sigtrap_codes[] = {
596         { TRAP_BRKPT,   "TRAP_BRKPT"    },
597         { TRAP_TRACE,   "TRAP_TRACE"    },
598         { 0,            NULL            },
599 };
600
601 static const struct xlat sigchld_codes[] = {
602         { CLD_EXITED,   "CLD_EXITED"    },
603         { CLD_KILLED,   "CLD_KILLED"    },
604         { CLD_DUMPED,   "CLD_DUMPED"    },
605         { CLD_TRAPPED,  "CLD_TRAPPED"   },
606         { CLD_STOPPED,  "CLD_STOPPED"   },
607         { CLD_CONTINUED,"CLD_CONTINUED" },
608         { 0,            NULL            },
609 };
610
611 static const struct xlat sigpoll_codes[] = {
612         { POLL_IN,      "POLL_IN"       },
613         { POLL_OUT,     "POLL_OUT"      },
614         { POLL_MSG,     "POLL_MSG"      },
615         { POLL_ERR,     "POLL_ERR"      },
616         { POLL_PRI,     "POLL_PRI"      },
617         { POLL_HUP,     "POLL_HUP"      },
618         { 0,            NULL            },
619 };
620
621 static const struct xlat sigprof_codes[] = {
622 #ifdef PROF_SIG
623         { PROF_SIG,     "PROF_SIG"      },
624 #endif
625         { 0,            NULL            },
626 };
627
628 #ifdef SIGEMT
629 static const struct xlat sigemt_codes[] = {
630 #ifdef EMT_TAGOVF
631         { EMT_TAGOVF,   "EMT_TAGOVF"    },
632 #endif
633         { 0,            NULL            },
634 };
635 #endif
636
637 static const struct xlat sigsegv_codes[] = {
638         { SEGV_MAPERR,  "SEGV_MAPERR"   },
639         { SEGV_ACCERR,  "SEGV_ACCERR"   },
640         { 0,            NULL            },
641 };
642
643 static const struct xlat sigbus_codes[] = {
644         { BUS_ADRALN,   "BUS_ADRALN"    },
645         { BUS_ADRERR,   "BUS_ADRERR"    },
646         { BUS_OBJERR,   "BUS_OBJERR"    },
647         { 0,            NULL            },
648 };
649
650 void
651 printsiginfo(siginfo_t *sip, int verbose)
652 {
653         const char *code;
654
655         if (sip->si_signo == 0) {
656                 tprintf("{}");
657                 return;
658         }
659         tprintf("{si_signo=");
660         printsignal(sip->si_signo);
661         code = xlookup(siginfo_codes, sip->si_code);
662         if (!code) {
663                 switch (sip->si_signo) {
664                 case SIGTRAP:
665                         code = xlookup(sigtrap_codes, sip->si_code);
666                         break;
667                 case SIGCHLD:
668                         code = xlookup(sigchld_codes, sip->si_code);
669                         break;
670                 case SIGPOLL:
671                         code = xlookup(sigpoll_codes, sip->si_code);
672                         break;
673                 case SIGPROF:
674                         code = xlookup(sigprof_codes, sip->si_code);
675                         break;
676                 case SIGILL:
677                         code = xlookup(sigill_codes, sip->si_code);
678                         break;
679 #ifdef SIGEMT
680                 case SIGEMT:
681                         code = xlookup(sigemt_codes, sip->si_code);
682                         break;
683 #endif
684                 case SIGFPE:
685                         code = xlookup(sigfpe_codes, sip->si_code);
686                         break;
687                 case SIGSEGV:
688                         code = xlookup(sigsegv_codes, sip->si_code);
689                         break;
690                 case SIGBUS:
691                         code = xlookup(sigbus_codes, sip->si_code);
692                         break;
693                 }
694         }
695         if (code)
696                 tprintf(", si_code=%s", code);
697         else
698                 tprintf(", si_code=%#x", sip->si_code);
699 #ifdef SI_NOINFO
700         if (sip->si_code != SI_NOINFO)
701 #endif
702         {
703                 if (sip->si_errno) {
704                         if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
705                                 tprintf(", si_errno=%d", sip->si_errno);
706                         else
707                                 tprintf(", si_errno=%s",
708                                         errnoent[sip->si_errno]);
709                 }
710 #ifdef SI_FROMUSER
711                 if (SI_FROMUSER(sip)) {
712                         tprintf(", si_pid=%lu, si_uid=%lu",
713                                 (unsigned long) sip->si_pid,
714                                 (unsigned long) sip->si_uid);
715                         switch (sip->si_code) {
716 #ifdef SI_USER
717                         case SI_USER:
718                                 break;
719 #endif
720 #ifdef SI_TKILL
721                         case SI_TKILL:
722                                 break;
723 #endif
724 #ifdef SI_TIMER
725                         case SI_TIMER:
726                                 tprintf(", si_value=%d", sip->si_int);
727                                 break;
728 #endif
729 #ifdef LINUX
730                         default:
731                                 if (!sip->si_ptr)
732                                         break;
733                                 if (!verbose)
734                                         tprintf(", ...");
735                                 else
736                                         tprintf(", si_value={int=%u, ptr=%#lx}",
737                                                 sip->si_int,
738                                                 (unsigned long) sip->si_ptr);
739                                 break;
740 #endif
741                         }
742                 }
743                 else
744 #endif /* SI_FROMUSER */
745                 {
746                         switch (sip->si_signo) {
747                         case SIGCHLD:
748                                 tprintf(", si_pid=%ld, si_status=",
749                                         (long) sip->si_pid);
750                                 if (sip->si_code == CLD_EXITED)
751                                         tprintf("%d", sip->si_status);
752                                 else
753                                         printsignal(sip->si_status);
754 #if LINUX
755                                 if (!verbose)
756                                         tprintf(", ...");
757                                 else
758                                         tprintf(", si_utime=%lu, si_stime=%lu",
759                                                 sip->si_utime,
760                                                 sip->si_stime);
761 #endif
762                                 break;
763                         case SIGILL: case SIGFPE:
764                         case SIGSEGV: case SIGBUS:
765                                 tprintf(", si_addr=%#lx",
766                                         (unsigned long) sip->si_addr);
767                                 break;
768                         case SIGPOLL:
769                                 switch (sip->si_code) {
770                                 case POLL_IN: case POLL_OUT: case POLL_MSG:
771                                         tprintf(", si_band=%ld",
772                                                 (long) sip->si_band);
773                                         break;
774                                 }
775                                 break;
776 #ifdef LINUX
777                         default:
778                                 if (sip->si_pid || sip->si_uid)
779                                         tprintf(", si_pid=%lu, si_uid=%lu",
780                                                 (unsigned long) sip->si_pid,
781                                                 (unsigned long) sip->si_uid);
782                                 if (!sip->si_ptr)
783                                         break;
784                                 if (!verbose)
785                                         tprintf(", ...");
786                                 else {
787                                         tprintf(", si_value={int=%u, ptr=%#lx}",
788                                                 sip->si_int,
789                                                 (unsigned long) sip->si_ptr);
790                                 }
791 #endif
792
793                         }
794                 }
795         }
796         tprintf("}");
797 }
798
799 #endif /* SVR4 || LINUX */
800
801 #ifdef LINUX
802
803 static void
804 parse_sigset_t(const char *str, sigset_t *set)
805 {
806         const char *p;
807         unsigned int digit;
808         int i;
809
810         sigemptyset(set);
811
812         p = strchr(str, '\n');
813         if (p == NULL)
814                 p = strchr(str, '\0');
815         for (i = 0; p-- > str; i += 4) {
816                 if (*p >= '0' && *p <= '9')
817                         digit = *p - '0';
818                 else if (*p >= 'a' && *p <= 'f')
819                         digit = *p - 'a' + 10;
820                 else if (*p >= 'A' && *p <= 'F')
821                         digit = *p - 'A' + 10;
822                 else
823                         break;
824                 if (digit & 1)
825                         sigaddset(set, i + 1);
826                 if (digit & 2)
827                         sigaddset(set, i + 2);
828                 if (digit & 4)
829                         sigaddset(set, i + 3);
830                 if (digit & 8)
831                         sigaddset(set, i + 4);
832         }
833 }
834
835 #endif
836
837 /*
838  * Check process TCP for the disposition of signal SIG.
839  * Return 1 if the process would somehow manage to  survive signal SIG,
840  * else return 0.  This routine will never be called with SIGKILL.
841  */
842 int
843 sigishandled(struct tcb *tcp, int sig)
844 {
845 #ifdef LINUX
846         int sfd;
847         char sname[32];
848         char buf[2048];
849         const char *s;
850         int i;
851         sigset_t ignored, caught;
852 #endif
853 #ifdef SVR4
854         /*
855          * Since procfs doesn't interfere with wait I think it is safe
856          * to punt on this question.  If not, the information is there.
857          */
858         return 1;
859 #else /* !SVR4 */
860         switch (sig) {
861         case SIGCONT:
862         case SIGSTOP:
863         case SIGTSTP:
864         case SIGTTIN:
865         case SIGTTOU:
866         case SIGCHLD:
867         case SIGIO:
868 #if defined(SIGURG) && SIGURG != SIGIO
869         case SIGURG:
870 #endif
871         case SIGWINCH:
872                 /* Gloria Gaynor says ... */
873                 return 1;
874         default:
875                 break;
876         }
877 #endif /* !SVR4 */
878 #ifdef LINUX
879
880         /* This is incredibly costly but it's worth it. */
881         /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
882            SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
883            doesn't handle real-time signals). */
884         sprintf(sname, "/proc/%d/status", tcp->pid);
885         if ((sfd = open(sname, O_RDONLY)) == -1) {
886                 perror(sname);
887                 return 1;
888         }
889         i = read(sfd, buf, sizeof(buf));
890         buf[i] = '\0';
891         close(sfd);
892         /*
893          * Skip the extraneous fields. We need to skip
894          * command name has any spaces in it.  So be it.
895          */
896         s = strstr(buf, "SigIgn:\t");
897         if (!s)
898         {
899                 fprintf(stderr, "/proc/pid/status format error\n");
900                 return 1;
901         }
902         parse_sigset_t(s + 8, &ignored);
903
904         s = strstr(buf, "SigCgt:\t");
905         if (!s)
906         {
907                 fprintf(stderr, "/proc/pid/status format error\n");
908                 return 1;
909         }
910         parse_sigset_t(s + 8, &caught);
911
912 #ifdef DEBUG
913         fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
914                 *(long long *) &ignored, *(long long *) &caught, sig);
915 #endif
916         if (sigismember(&ignored, sig) || sigismember(&caught, sig))
917                 return 1;
918 #endif /* LINUX */
919
920 #ifdef SUNOS4
921         void (*u_signal)();
922
923         if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal),
924             (long *) &u_signal) < 0) {
925                 return 0;
926         }
927         if (u_signal != SIG_DFL)
928                 return 1;
929 #endif /* SUNOS4 */
930
931         return 0;
932 }
933
934 #if defined(SUNOS4) || defined(FREEBSD)
935
936 int
937 sys_sigvec(struct tcb *tcp)
938 {
939         struct sigvec sv;
940         long addr;
941
942         if (entering(tcp)) {
943                 printsignal(tcp->u_arg[0]);
944                 tprintf(", ");
945                 addr = tcp->u_arg[1];
946         } else {
947                 addr = tcp->u_arg[2];
948         }
949         if (addr == 0)
950                 tprintf("NULL");
951         else if (!verbose(tcp))
952                 tprintf("%#lx", addr);
953         else if (umove(tcp, addr, &sv) < 0)
954                 tprintf("{...}");
955         else {
956                 switch ((int) sv.sv_handler) {
957                 case (int) SIG_ERR:
958                         tprintf("{SIG_ERR}");
959                         break;
960                 case (int) SIG_DFL:
961                         tprintf("{SIG_DFL}");
962                         break;
963                 case (int) SIG_IGN:
964                         if (tcp->u_arg[0] == SIGTRAP) {
965                                 tcp->flags |= TCB_SIGTRAPPED;
966                                 kill(tcp->pid, SIGSTOP);
967                         }
968                         tprintf("{SIG_IGN}");
969                         break;
970                 case (int) SIG_HOLD:
971                         if (tcp->u_arg[0] == SIGTRAP) {
972                                 tcp->flags |= TCB_SIGTRAPPED;
973                                 kill(tcp->pid, SIGSTOP);
974                         }
975                         tprintf("SIG_HOLD");
976                         break;
977                 default:
978                         if (tcp->u_arg[0] == SIGTRAP) {
979                                 tcp->flags |= TCB_SIGTRAPPED;
980                                 kill(tcp->pid, SIGSTOP);
981                         }
982                         tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
983                         printsigmask(&sv.sv_mask, 0);
984                         tprintf(", ");
985                         printflags(sigvec_flags, sv.sv_flags, "SV_???");
986                         tprintf("}");
987                 }
988         }
989         if (entering(tcp))
990                 tprintf(", ");
991         return 0;
992 }
993
994 int
995 sys_sigpause(struct tcb *tcp)
996 {
997         if (entering(tcp)) {    /* WTA: UD had a bug here: he forgot the braces */
998                 sigset_t sigm;
999                 long_to_sigset(tcp->u_arg[0], &sigm);
1000                 printsigmask(&sigm, 0);
1001         }
1002         return 0;
1003 }
1004
1005 int
1006 sys_sigstack(struct tcb *tcp)
1007 {
1008         struct sigstack ss;
1009         long addr;
1010
1011         if (entering(tcp))
1012                 addr = tcp->u_arg[0];
1013         else
1014                 addr = tcp->u_arg[1];
1015         if (addr == 0)
1016                 tprintf("NULL");
1017         else if (umove(tcp, addr, &ss) < 0)
1018                 tprintf("%#lx", addr);
1019         else {
1020                 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1021                 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1022         }
1023         if (entering(tcp))
1024                 tprintf(", ");
1025         return 0;
1026 }
1027
1028 int
1029 sys_sigcleanup(struct tcb *tcp)
1030 {
1031         return 0;
1032 }
1033
1034 #endif /* SUNOS4 || FREEBSD */
1035
1036 #ifndef SVR4
1037
1038 int
1039 sys_sigsetmask(struct tcb *tcp)
1040 {
1041         if (entering(tcp)) {
1042                 sigset_t sigm;
1043                 long_to_sigset(tcp->u_arg[0], &sigm);
1044                 printsigmask(&sigm, 0);
1045 #ifndef USE_PROCFS
1046                 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1047                         /* Mark attempt to block SIGTRAP */
1048                         tcp->flags |= TCB_SIGTRAPPED;
1049                         /* Send unblockable signal */
1050                         kill(tcp->pid, SIGSTOP);
1051                 }
1052 #endif /* !USE_PROCFS */
1053         }
1054         else if (!syserror(tcp)) {
1055                 sigset_t sigm;
1056                 long_to_sigset(tcp->u_rval, &sigm);
1057                 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
1058
1059                 return RVAL_HEX | RVAL_STR;
1060         }
1061         return 0;
1062 }
1063
1064 #if defined(SUNOS4) || defined(FREEBSD)
1065 int
1066 sys_sigblock(struct tcb *tcp)
1067 {
1068         return sys_sigsetmask(tcp);
1069 }
1070 #endif /* SUNOS4 || FREEBSD */
1071
1072 #endif /* !SVR4 */
1073
1074 #ifdef HAVE_SIGACTION
1075
1076 #ifdef LINUX
1077 struct old_sigaction {
1078         __sighandler_t __sa_handler;
1079         unsigned long sa_mask;
1080         unsigned long sa_flags;
1081         void (*sa_restorer)(void);
1082 };
1083 #define SA_HANDLER __sa_handler
1084 #endif /* LINUX */
1085
1086 #ifndef SA_HANDLER
1087 #define SA_HANDLER sa_handler
1088 #endif
1089
1090 int
1091 sys_sigaction(struct tcb *tcp)
1092 {
1093         long addr;
1094 #ifdef LINUX
1095         sigset_t sigset;
1096         struct old_sigaction sa;
1097 #else
1098         struct sigaction sa;
1099 #endif
1100
1101
1102         if (entering(tcp)) {
1103                 printsignal(tcp->u_arg[0]);
1104                 tprintf(", ");
1105                 addr = tcp->u_arg[1];
1106         } else
1107                 addr = tcp->u_arg[2];
1108         if (addr == 0)
1109                 tprintf("NULL");
1110         else if (!verbose(tcp))
1111                 tprintf("%#lx", addr);
1112         else if (umove(tcp, addr, &sa) < 0)
1113                 tprintf("{...}");
1114         else {
1115                 /* Architectures using function pointers, like
1116                  * hppa, may need to manipulate the function pointer
1117                  * to compute the result of a comparison. However,
1118                  * the SA_HANDLER function pointer exists only in
1119                  * the address space of the traced process, and can't
1120                  * be manipulated by strace. In order to prevent the
1121                  * compiler from generating code to manipulate
1122                  * SA_HANDLER we cast the function pointers to long. */
1123                 if ((long)sa.SA_HANDLER == (long)SIG_ERR)
1124                         tprintf("{SIG_ERR, ");
1125                 else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
1126                         tprintf("{SIG_DFL, ");
1127                 else if ((long)sa.SA_HANDLER == (long)SIG_IGN) {
1128 #ifndef USE_PROCFS
1129                         if (tcp->u_arg[0] == SIGTRAP) {
1130                                 tcp->flags |= TCB_SIGTRAPPED;
1131                                 kill(tcp->pid, SIGSTOP);
1132                         }
1133 #endif /* !USE_PROCFS */
1134                         tprintf("{SIG_IGN, ");
1135                 }
1136                 else {
1137 #ifndef USE_PROCFS
1138                         if (tcp->u_arg[0] == SIGTRAP) {
1139                                 tcp->flags |= TCB_SIGTRAPPED;
1140                                 kill(tcp->pid, SIGSTOP);
1141                         }
1142 #endif /* !USE_PROCFS */
1143                         tprintf("{%#lx, ", (long) sa.SA_HANDLER);
1144 #ifndef LINUX
1145                         printsigmask(&sa.sa_mask, 0);
1146 #else
1147                         long_to_sigset(sa.sa_mask, &sigset);
1148                         printsigmask(&sigset, 0);
1149 #endif
1150                         tprintf(", ");
1151                         printflags(sigact_flags, sa.sa_flags, "SA_???");
1152 #ifdef SA_RESTORER
1153                         if (sa.sa_flags & SA_RESTORER)
1154                                 tprintf(", %p", sa.sa_restorer);
1155 #endif
1156                         tprintf("}");
1157                 }
1158         }
1159         if (entering(tcp))
1160                 tprintf(", ");
1161 #ifdef LINUX
1162         else
1163                 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1164 #endif
1165         return 0;
1166 }
1167
1168 int
1169 sys_signal(struct tcb *tcp)
1170 {
1171         if (entering(tcp)) {
1172                 printsignal(tcp->u_arg[0]);
1173                 tprintf(", ");
1174                 switch (tcp->u_arg[1]) {
1175                 case (long) SIG_ERR:
1176                         tprintf("SIG_ERR");
1177                         break;
1178                 case (long) SIG_DFL:
1179                         tprintf("SIG_DFL");
1180                         break;
1181                 case (long) SIG_IGN:
1182 #ifndef USE_PROCFS
1183                         if (tcp->u_arg[0] == SIGTRAP) {
1184                                 tcp->flags |= TCB_SIGTRAPPED;
1185                                 kill(tcp->pid, SIGSTOP);
1186                         }
1187 #endif /* !USE_PROCFS */
1188                         tprintf("SIG_IGN");
1189                         break;
1190                 default:
1191 #ifndef USE_PROCFS
1192                         if (tcp->u_arg[0] == SIGTRAP) {
1193                                 tcp->flags |= TCB_SIGTRAPPED;
1194                                 kill(tcp->pid, SIGSTOP);
1195                         }
1196 #endif /* !USE_PROCFS */
1197                         tprintf("%#lx", tcp->u_arg[1]);
1198                 }
1199                 return 0;
1200         }
1201         else if (!syserror(tcp)) {
1202                 switch (tcp->u_rval) {
1203                     case (long) SIG_ERR:
1204                         tcp->auxstr = "SIG_ERR"; break;
1205                     case (long) SIG_DFL:
1206                         tcp->auxstr = "SIG_DFL"; break;
1207                     case (long) SIG_IGN:
1208                         tcp->auxstr = "SIG_IGN"; break;
1209                     default:
1210                         tcp->auxstr = NULL;
1211                 }
1212                 return RVAL_HEX | RVAL_STR;
1213         }
1214         return 0;
1215 }
1216
1217 #ifdef SVR4
1218 int
1219 sys_sighold(struct tcb *tcp)
1220 {
1221         if (entering(tcp)) {
1222                 printsignal(tcp->u_arg[0]);
1223         }
1224         return 0;
1225 }
1226 #endif /* SVR4 */
1227
1228 #endif /* HAVE_SIGACTION */
1229
1230 #ifdef LINUX
1231
1232 int
1233 sys_sigreturn(struct tcb *tcp)
1234 {
1235 #if defined(ARM)
1236         struct pt_regs regs;
1237         struct sigcontext_struct sc;
1238
1239         if (entering(tcp)) {
1240                 tcp->u_arg[0] = 0;
1241
1242                 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1243                         return 0;
1244
1245                 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1246                         return 0;
1247
1248                 tcp->u_arg[0] = 1;
1249                 tcp->u_arg[1] = sc.oldmask;
1250         } else {
1251                 sigset_t sigm;
1252                 long_to_sigset(tcp->u_arg[1], &sigm);
1253                 tcp->u_rval = tcp->u_error = 0;
1254                 if (tcp->u_arg[0] == 0)
1255                         return 0;
1256                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1257                 return RVAL_NONE | RVAL_STR;
1258         }
1259         return 0;
1260 #elif defined(S390) || defined(S390X)
1261         long usp;
1262         struct sigcontext_struct sc;
1263
1264         if (entering(tcp)) {
1265                 tcp->u_arg[0] = 0;
1266                 if (upeek(tcp, PT_GPR15, &usp) < 0)
1267                         return 0;
1268                 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1269                         return 0;
1270                 tcp->u_arg[0] = 1;
1271                 memcpy(&tcp->u_arg[1], &sc.oldmask[0], sizeof(sigset_t));
1272         } else {
1273                 tcp->u_rval = tcp->u_error = 0;
1274                 if (tcp->u_arg[0] == 0)
1275                         return 0;
1276                 tcp->auxstr = sprintsigmask("mask now ", (sigset_t *)&tcp->u_arg[1], 0);
1277                 return RVAL_NONE | RVAL_STR;
1278         }
1279         return 0;
1280 #elif defined(I386)
1281         long esp;
1282         struct sigcontext_struct sc;
1283
1284         if (entering(tcp)) {
1285                 tcp->u_arg[0] = 0;
1286                 if (upeek(tcp, 4*UESP, &esp) < 0)
1287                         return 0;
1288                 if (umove(tcp, esp, &sc) < 0)
1289                         return 0;
1290                 tcp->u_arg[0] = 1;
1291                 tcp->u_arg[1] = sc.oldmask;
1292         }
1293         else {
1294                 sigset_t sigm;
1295                 long_to_sigset(tcp->u_arg[1], &sigm);
1296                 tcp->u_rval = tcp->u_error = 0;
1297                 if (tcp->u_arg[0] == 0)
1298                         return 0;
1299                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1300                 return RVAL_NONE | RVAL_STR;
1301         }
1302         return 0;
1303 #elif defined(IA64)
1304         struct sigcontext sc;
1305         long sp;
1306
1307         if (entering(tcp)) {
1308                 /* offset of sigcontext in the kernel's sigframe structure: */
1309 #               define SIGFRAME_SC_OFFSET       0x90
1310                 tcp->u_arg[0] = 0;
1311                 if (upeek(tcp, PT_R12, &sp) < 0)
1312                         return 0;
1313                 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
1314                         return 0;
1315                 tcp->u_arg[0] = 1;
1316                 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
1317         }
1318         else {
1319                 sigset_t sigm;
1320
1321                 memcpy(&sigm, tcp->u_arg + 1, sizeof(sigm));
1322                 tcp->u_rval = tcp->u_error = 0;
1323                 if (tcp->u_arg[0] == 0)
1324                         return 0;
1325                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1326                 return RVAL_NONE | RVAL_STR;
1327         }
1328         return 0;
1329 #elif defined(POWERPC)
1330         long esp;
1331         struct sigcontext_struct sc;
1332
1333         if (entering(tcp)) {
1334                 tcp->u_arg[0] = 0;
1335                 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
1336                         return 0;
1337                 /* Skip dummy stack frame. */
1338 #ifdef POWERPC64
1339                 if (current_personality == 0)
1340                         esp += 128;
1341                 else
1342                         esp += 64;
1343 #else
1344                 esp += 64;
1345 #endif
1346                 if (umove(tcp, esp, &sc) < 0)
1347                         return 0;
1348                 tcp->u_arg[0] = 1;
1349                 tcp->u_arg[1] = sc.oldmask;
1350         }
1351         else {
1352                 sigset_t sigm;
1353                 long_to_sigset(tcp->u_arg[1], &sigm);
1354                 tcp->u_rval = tcp->u_error = 0;
1355                 if (tcp->u_arg[0] == 0)
1356                         return 0;
1357                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1358                 return RVAL_NONE | RVAL_STR;
1359         }
1360         return 0;
1361 #elif defined(M68K)
1362         long usp;
1363         struct sigcontext sc;
1364
1365         if (entering(tcp)) {
1366                 tcp->u_arg[0] = 0;
1367                 if (upeek(tcp, 4*PT_USP, &usp) < 0)
1368                         return 0;
1369                 if (umove(tcp, usp, &sc) < 0)
1370                         return 0;
1371                 tcp->u_arg[0] = 1;
1372                 tcp->u_arg[1] = sc.sc_mask;
1373         }
1374         else {
1375                 sigset_t sigm;
1376                 long_to_sigset(tcp->u_arg[1], &sigm);
1377                 tcp->u_rval = tcp->u_error = 0;
1378                 if (tcp->u_arg[0] == 0)
1379                         return 0;
1380                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1381                 return RVAL_NONE | RVAL_STR;
1382         }
1383         return 0;
1384 #elif defined(ALPHA)
1385         long fp;
1386         struct sigcontext_struct sc;
1387
1388         if (entering(tcp)) {
1389                 tcp->u_arg[0] = 0;
1390                 if (upeek(tcp, REG_FP, &fp) < 0)
1391                         return 0;
1392                 if (umove(tcp, fp, &sc) < 0)
1393                         return 0;
1394                 tcp->u_arg[0] = 1;
1395                 tcp->u_arg[1] = sc.sc_mask;
1396         }
1397         else {
1398                 sigset_t sigm;
1399                 long_to_sigset(tcp->u_arg[1], &sigm);
1400                 tcp->u_rval = tcp->u_error = 0;
1401                 if (tcp->u_arg[0] == 0)
1402                         return 0;
1403                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1404                 return RVAL_NONE | RVAL_STR;
1405         }
1406         return 0;
1407 #elif defined (SPARC) || defined (SPARC64)
1408         long i1;
1409         struct pt_regs regs;
1410         m_siginfo_t si;
1411
1412         if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1413                 perror("sigreturn: PTRACE_GETREGS ");
1414                 return 0;
1415         }
1416         if (entering(tcp)) {
1417                 tcp->u_arg[0] = 0;
1418                 i1 = regs.u_regs[U_REG_O1];
1419                 if (umove(tcp, i1, &si) < 0) {
1420                         perror("sigreturn: umove ");
1421                         return 0;
1422                 }
1423                 tcp->u_arg[0] = 1;
1424                 tcp->u_arg[1] = si.si_mask;
1425         } else {
1426                 sigset_t sigm;
1427                 long_to_sigset(tcp->u_arg[1], &sigm);
1428                 tcp->u_rval = tcp->u_error = 0;
1429                 if (tcp->u_arg[0] == 0)
1430                         return 0;
1431                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1432                 return RVAL_NONE | RVAL_STR;
1433         }
1434         return 0;
1435 #elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
1436         /* This decodes rt_sigreturn.  The 64-bit ABIs do not have
1437            sigreturn.  */
1438         long sp;
1439         struct ucontext uc;
1440
1441         if (entering(tcp)) {
1442                 tcp->u_arg[0] = 0;
1443                 if (upeek(tcp, REG_SP, &sp) < 0)
1444                         return 0;
1445                 /* There are six words followed by a 128-byte siginfo.  */
1446                 sp = sp + 6 * 4 + 128;
1447                 if (umove(tcp, sp, &uc) < 0)
1448                         return 0;
1449                 tcp->u_arg[0] = 1;
1450                 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1451         } else {
1452                 sigset_t sigm;
1453                 long_to_sigset(tcp->u_arg[1], &sigm);
1454                 tcp->u_rval = tcp->u_error = 0;
1455                 if (tcp->u_arg[0] == 0)
1456                         return 0;
1457                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1458                 return RVAL_NONE | RVAL_STR;
1459         }
1460         return 0;
1461 #elif defined(MIPS)
1462         long sp;
1463         struct pt_regs regs;
1464         m_siginfo_t si;
1465
1466         if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1467                 perror("sigreturn: PTRACE_GETREGS ");
1468                 return 0;
1469         }
1470         if (entering(tcp)) {
1471                 tcp->u_arg[0] = 0;
1472                 sp = regs.regs[29];
1473                 if (umove(tcp, sp, &si) < 0)
1474                         return 0;
1475                 tcp->u_arg[0] = 1;
1476                 tcp->u_arg[1] = si.si_mask;
1477         } else {
1478                 sigset_t sigm;
1479                 long_to_sigset(tcp->u_arg[1], &sigm);
1480                 tcp->u_rval = tcp->u_error = 0;
1481                 if (tcp->u_arg[0] == 0)
1482                         return 0;
1483                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1484                 return RVAL_NONE | RVAL_STR;
1485         }
1486         return 0;
1487 #elif defined(CRISV10) || defined(CRISV32)
1488         struct sigcontext sc;
1489
1490         if (entering(tcp)) {
1491                 long regs[PT_MAX+1];
1492
1493                 tcp->u_arg[0] = 0;
1494
1495                 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1496                         perror("sigreturn: PTRACE_GETREGS");
1497                         return 0;
1498                 }
1499                 if (umove(tcp, regs[PT_USP], &sc) < 0)
1500                         return 0;
1501                 tcp->u_arg[0] = 1;
1502                 tcp->u_arg[1] = sc.oldmask;
1503         } else {
1504                 sigset_t sigm;
1505                 long_to_sigset(tcp->u_arg[1], &sigm);
1506                 tcp->u_rval = tcp->u_error = 0;
1507
1508                 if (tcp->u_arg[0] == 0)
1509                         return 0;
1510                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1511                 return RVAL_NONE | RVAL_STR;
1512         }
1513         return 0;
1514 #elif defined(TILE)
1515         struct ucontext uc;
1516         long sp;
1517
1518         /* offset of ucontext in the kernel's sigframe structure */
1519 #       define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo)
1520
1521         if (entering(tcp)) {
1522                 tcp->u_arg[0] = 0;
1523                 if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0)
1524                         return 0;
1525                 if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1526                         return 0;
1527                 tcp->u_arg[0] = 1;
1528                 memcpy(tcp->u_arg + 1, &uc.uc_sigmask, sizeof(uc.uc_sigmask));
1529         }
1530         else {
1531                 sigset_t sigm;
1532
1533                 memcpy(&sigm, tcp->u_arg + 1, sizeof(sigm));
1534                 tcp->u_rval = tcp->u_error = 0;
1535                 if (tcp->u_arg[0] == 0)
1536                         return 0;
1537                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1538                 return RVAL_NONE | RVAL_STR;
1539         }
1540         return 0;
1541 #elif defined(MICROBLAZE)
1542         struct sigcontext sc;
1543
1544         /* TODO: Verify that this is correct...  */
1545         if (entering(tcp)) {
1546                 long sp;
1547
1548                 tcp->u_arg[0] = 0;
1549
1550                 /* Read r1, the stack pointer.  */
1551                 if (upeek(tcp, 1 * 4, &sp) < 0)
1552                         return 0;
1553                 if (umove(tcp, sp, &sc) < 0)
1554                         return 0;
1555                 tcp->u_arg[0] = 1;
1556                 tcp->u_arg[1] = sc.oldmask;
1557         } else {
1558                 sigset_t sigm;
1559                 long_to_sigset(tcp->u_arg[1], &sigm);
1560                 tcp->u_rval = tcp->u_error = 0;
1561                 if (tcp->u_arg[0] == 0)
1562                         return 0;
1563                 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1564                 return RVAL_NONE | RVAL_STR;
1565         }
1566         return 0;
1567 #else
1568 #warning No sys_sigreturn() for this architecture
1569 #warning         (no problem, just a reminder :-)
1570         return 0;
1571 #endif
1572 }
1573
1574 int
1575 sys_siggetmask(struct tcb *tcp)
1576 {
1577         if (exiting(tcp)) {
1578                 sigset_t sigm;
1579                 long_to_sigset(tcp->u_rval, &sigm);
1580                 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
1581         }
1582         return RVAL_HEX | RVAL_STR;
1583 }
1584
1585 int
1586 sys_sigsuspend(struct tcb *tcp)
1587 {
1588         if (entering(tcp)) {
1589                 sigset_t sigm;
1590                 long_to_sigset(tcp->u_arg[2], &sigm);
1591                 printsigmask(&sigm, 0);
1592         }
1593         return 0;
1594 }
1595
1596 #endif /* LINUX */
1597
1598 #if defined(SVR4) || defined(FREEBSD)
1599
1600 int
1601 sys_sigsuspend(struct tcb *tcp)
1602 {
1603         sigset_t sigset;
1604
1605         if (entering(tcp)) {
1606                 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1607                         tprintf("[?]");
1608                 else
1609                         printsigmask(&sigset, 0);
1610         }
1611         return 0;
1612 }
1613 #ifndef FREEBSD
1614 static const struct xlat ucontext_flags[] = {
1615         { UC_SIGMASK,   "UC_SIGMASK"    },
1616         { UC_STACK,     "UC_STACK"      },
1617         { UC_CPU,       "UC_CPU"        },
1618 #ifdef UC_FPU
1619         { UC_FPU,       "UC_FPU"        },
1620 #endif
1621 #ifdef UC_INTR
1622         { UC_INTR,      "UC_INTR"       },
1623 #endif
1624         { 0,            NULL            },
1625 };
1626 #endif /* !FREEBSD */
1627 #endif /* SVR4 || FREEBSD */
1628
1629 #if defined SVR4 || defined LINUX || defined FREEBSD
1630 #if defined LINUX && !defined SS_ONSTACK
1631 #define SS_ONSTACK      1
1632 #define SS_DISABLE      2
1633 #if __GLIBC_MINOR__ == 0
1634 typedef struct
1635 {
1636         __ptr_t ss_sp;
1637         int ss_flags;
1638         size_t ss_size;
1639 } stack_t;
1640 #endif
1641 #endif
1642 #ifdef FREEBSD
1643 #define stack_t struct sigaltstack
1644 #endif
1645
1646 static const struct xlat sigaltstack_flags[] = {
1647         { SS_ONSTACK,   "SS_ONSTACK"    },
1648         { SS_DISABLE,   "SS_DISABLE"    },
1649         { 0,            NULL            },
1650 };
1651 #endif
1652
1653 #ifdef SVR4
1654 static void
1655 printcontext(struct tcb *tcp, ucontext_t *ucp)
1656 {
1657         tprintf("{");
1658         if (!abbrev(tcp)) {
1659                 tprintf("uc_flags=");
1660                 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
1661                 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1662         }
1663         tprintf("uc_sigmask=");
1664         printsigmask(&ucp->uc_sigmask, 0);
1665         if (!abbrev(tcp)) {
1666                 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1667                         (unsigned long) ucp->uc_stack.ss_sp,
1668                         ucp->uc_stack.ss_size);
1669                 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
1670                 tprintf("}");
1671         }
1672         tprintf(", ...}");
1673 }
1674
1675 int
1676 sys_getcontext(struct tcb *tcp)
1677 {
1678         ucontext_t uc;
1679
1680         if (exiting(tcp)) {
1681                 if (tcp->u_error)
1682                         tprintf("%#lx", tcp->u_arg[0]);
1683                 else if (!tcp->u_arg[0])
1684                         tprintf("NULL");
1685                 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1686                         tprintf("{...}");
1687                 else
1688                         printcontext(tcp, &uc);
1689         }
1690         return 0;
1691 }
1692
1693 int
1694 sys_setcontext(struct tcb *tcp)
1695 {
1696         ucontext_t uc;
1697
1698         if (entering(tcp)) {
1699                 if (!tcp->u_arg[0])
1700                         tprintf("NULL");
1701                 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1702                         tprintf("{...}");
1703                 else
1704                         printcontext(tcp, &uc);
1705         }
1706         else {
1707                 tcp->u_rval = tcp->u_error = 0;
1708                 if (tcp->u_arg[0] == 0)
1709                         return 0;
1710                 return RVAL_NONE;
1711         }
1712         return 0;
1713 }
1714
1715 #endif /* SVR4 */
1716
1717 #if defined(LINUX) || defined(FREEBSD)
1718
1719 static int
1720 print_stack_t(struct tcb *tcp, unsigned long addr)
1721 {
1722         stack_t ss;
1723         if (umove(tcp, addr, &ss) < 0)
1724                 return -1;
1725         tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1726         printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1727         tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1728         return 0;
1729 }
1730
1731 int
1732 sys_sigaltstack(struct tcb *tcp)
1733 {
1734         if (entering(tcp)) {
1735                 if (tcp->u_arg[0] == 0)
1736                         tprintf("NULL");
1737                 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1738                         return -1;
1739         }
1740         else {
1741                 tprintf(", ");
1742                 if (tcp->u_arg[1] == 0)
1743                         tprintf("NULL");
1744                 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1745                         return -1;
1746         }
1747         return 0;
1748 }
1749 #endif
1750
1751 #ifdef HAVE_SIGACTION
1752
1753 int
1754 sys_sigprocmask(struct tcb *tcp)
1755 {
1756 #ifdef ALPHA
1757         if (entering(tcp)) {
1758                 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1759                 tprintf(", ");
1760                 printsigmask(tcp->u_arg[1], 0);
1761         }
1762         else if (!syserror(tcp)) {
1763                 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
1764                 return RVAL_HEX | RVAL_STR;
1765         }
1766 #else /* !ALPHA */
1767         if (entering(tcp)) {
1768 #ifdef SVR4
1769                 if (tcp->u_arg[0] == 0)
1770                         tprintf("0");
1771                 else
1772 #endif /* SVR4 */
1773                 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1774                 tprintf(", ");
1775                 print_sigset(tcp, tcp->u_arg[1], 0);
1776                 tprintf(", ");
1777         }
1778         else {
1779                 if (!tcp->u_arg[2])
1780                         tprintf("NULL");
1781                 else if (syserror(tcp))
1782                         tprintf("%#lx", tcp->u_arg[2]);
1783                 else
1784                         print_sigset(tcp, tcp->u_arg[2], 0);
1785         }
1786 #endif /* !ALPHA */
1787         return 0;
1788 }
1789
1790 #endif /* HAVE_SIGACTION */
1791
1792 int
1793 sys_kill(struct tcb *tcp)
1794 {
1795         if (entering(tcp)) {
1796                 /*
1797                  * Sign-extend a 32-bit value when that's what it is.
1798                  */
1799                 long pid = tcp->u_arg[0];
1800                 if (personality_wordsize[current_personality] < sizeof pid)
1801                         pid = (long) (int) pid;
1802                 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
1803         }
1804         return 0;
1805 }
1806
1807 #if defined(FREEBSD) || defined(SUNOS4)
1808 int
1809 sys_killpg(struct tcb *tcp)
1810 {
1811         return sys_kill(tcp);
1812 }
1813 #endif /* FREEBSD || SUNOS4 */
1814
1815 #ifdef LINUX
1816 int
1817 sys_tgkill(struct tcb *tcp)
1818 {
1819         if (entering(tcp)) {
1820                 tprintf("%ld, %ld, %s",
1821                         tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1822         }
1823         return 0;
1824 }
1825 #endif
1826
1827 int
1828 sys_sigpending(struct tcb *tcp)
1829 {
1830         sigset_t sigset;
1831
1832         if (exiting(tcp)) {
1833                 if (syserror(tcp))
1834                         tprintf("%#lx", tcp->u_arg[0]);
1835                 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1836                         tprintf("[?]");
1837                 else
1838                         printsigmask(&sigset, 0);
1839         }
1840         return 0;
1841 }
1842
1843 #ifdef SVR4
1844 int sys_sigwait(struct tcb *tcp)
1845 {
1846         sigset_t sigset;
1847
1848         if (entering(tcp)) {
1849                 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1850                         tprintf("[?]");
1851                 else
1852                         printsigmask(&sigset, 0);
1853         }
1854         else {
1855                 if (!syserror(tcp)) {
1856                         tcp->auxstr = signalent[tcp->u_rval];
1857                         return RVAL_DECIMAL | RVAL_STR;
1858                 }
1859         }
1860         return 0;
1861 }
1862 #endif /* SVR4 */
1863
1864 #ifdef LINUX
1865
1866 int
1867 sys_rt_sigprocmask(struct tcb *tcp)
1868 {
1869         sigset_t sigset;
1870
1871         /* Note: arg[3] is the length of the sigset. */
1872         if (entering(tcp)) {
1873                 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1874                 tprintf(", ");
1875                 if (!tcp->u_arg[1])
1876                         tprintf("NULL, ");
1877                 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
1878                         tprintf("%#lx, ", tcp->u_arg[1]);
1879                 else {
1880                         printsigmask(&sigset, 1);
1881                         tprintf(", ");
1882                 }
1883         }
1884         else {
1885                 if (!tcp->u_arg[2])
1886
1887                         tprintf("NULL");
1888                 else if (syserror(tcp))
1889                         tprintf("%#lx", tcp->u_arg[2]);
1890                 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
1891                         tprintf("[?]");
1892                 else
1893                         printsigmask(&sigset, 1);
1894                 tprintf(", %lu", tcp->u_arg[3]);
1895         }
1896         return 0;
1897 }
1898
1899
1900 /* Structure describing the action to be taken when a signal arrives.  */
1901 struct new_sigaction
1902 {
1903         __sighandler_t __sa_handler;
1904         unsigned long sa_flags;
1905         void (*sa_restorer) (void);
1906         /* Kernel treats sa_mask as an array of longs. */
1907         unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1908 };
1909 /* Same for i386-on-x86_64 and similar cases */
1910 struct new_sigaction32
1911 {
1912         uint32_t __sa_handler;
1913         uint32_t sa_flags;
1914         uint32_t sa_restorer;
1915         uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
1916 };
1917
1918
1919 int
1920 sys_rt_sigaction(struct tcb *tcp)
1921 {
1922         struct new_sigaction sa;
1923         sigset_t sigset;
1924         long addr;
1925         int r;
1926
1927         if (entering(tcp)) {
1928                 printsignal(tcp->u_arg[0]);
1929                 tprintf(", ");
1930                 addr = tcp->u_arg[1];
1931         } else
1932                 addr = tcp->u_arg[2];
1933
1934         if (addr == 0) {
1935                 tprintf("NULL");
1936                 goto after_sa;
1937         }
1938         if (!verbose(tcp)) {
1939                 tprintf("%#lx", addr);
1940                 goto after_sa;
1941         }
1942 #if SUPPORTED_PERSONALITIES > 1
1943         if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1944          && personality_wordsize[current_personality] == 4
1945         ) {
1946                 struct new_sigaction32 sa32;
1947                 r = umove(tcp, addr, &sa32);
1948                 if (r >= 0) {
1949                         memset(&sa, 0, sizeof(sa));
1950                         sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1951                         sa.sa_flags     = sa32.sa_flags;
1952                         sa.sa_restorer  = (void*)(unsigned long)sa32.sa_restorer;
1953                         /* Kernel treats sa_mask as an array of longs.
1954                          * For 32-bit process, "long" is uint32_t, thus, for example,
1955                          * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1956                          * But for (64-bit) kernel, 32th bit in sa_mask is
1957                          * 32th bit in 0th (64-bit) long!
1958                          * For little-endian, it's the same.
1959                          * For big-endian, we swap 32-bit words.
1960                          */
1961                         sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1962                 }
1963         } else
1964 #endif
1965         {
1966                 r = umove(tcp, addr, &sa);
1967         }
1968         if (r < 0) {
1969                 tprintf("{...}");
1970                 goto after_sa;
1971         }
1972         /* Architectures using function pointers, like
1973          * hppa, may need to manipulate the function pointer
1974          * to compute the result of a comparison. However,
1975          * the SA_HANDLER function pointer exists only in
1976          * the address space of the traced process, and can't
1977          * be manipulated by strace. In order to prevent the
1978          * compiler from generating code to manipulate
1979          * SA_HANDLER we cast the function pointers to long. */
1980         if ((long)sa.__sa_handler == (long)SIG_ERR)
1981                 tprintf("{SIG_ERR, ");
1982         else if ((long)sa.__sa_handler == (long)SIG_DFL)
1983                 tprintf("{SIG_DFL, ");
1984         else if ((long)sa.__sa_handler == (long)SIG_IGN)
1985                 tprintf("{SIG_IGN, ");
1986         else
1987                 tprintf("{%#lx, ", (long) sa.__sa_handler);
1988         /* Questionable code below.
1989          * Kernel won't handle sys_rt_sigaction
1990          * with wrong sigset size (just returns EINVAL)
1991          * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
1992          * and we always use smaller memcpy. */
1993         sigemptyset(&sigset);
1994 #ifdef LINUXSPARC
1995         if (tcp->u_arg[4] <= sizeof(sigset))
1996                 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1997 #else
1998         if (tcp->u_arg[3] <= sizeof(sigset))
1999                 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
2000 #endif
2001         else
2002                 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
2003         printsigmask(&sigset, 1);
2004         tprintf(", ");
2005         printflags(sigact_flags, sa.sa_flags, "SA_???");
2006 #ifdef SA_RESTORER
2007         if (sa.sa_flags & SA_RESTORER)
2008                 tprintf(", %p", sa.sa_restorer);
2009 #endif
2010         tprintf("}");
2011
2012  after_sa:
2013         if (entering(tcp))
2014                 tprintf(", ");
2015         else
2016 #ifdef LINUXSPARC
2017                 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
2018 #elif defined(ALPHA)
2019                 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
2020 #else
2021                 tprintf(", %lu", tcp->u_arg[3]);
2022 #endif
2023         return 0;
2024 }
2025
2026 int
2027 sys_rt_sigpending(struct tcb *tcp)
2028 {
2029         sigset_t sigset;
2030
2031         if (exiting(tcp)) {
2032                 if (syserror(tcp))
2033                         tprintf("%#lx", tcp->u_arg[0]);
2034                 else if (copy_sigset_len(tcp, tcp->u_arg[0],
2035                                          &sigset, tcp->u_arg[1]) < 0)
2036                         tprintf("[?]");
2037                 else
2038                         printsigmask(&sigset, 1);
2039         }
2040         return 0;
2041 }
2042
2043 int
2044 sys_rt_sigsuspend(struct tcb *tcp)
2045 {
2046         if (entering(tcp)) {
2047                 sigset_t sigm;
2048                 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
2049                         tprintf("[?]");
2050                 else
2051                         printsigmask(&sigm, 1);
2052         }
2053         return 0;
2054 }
2055
2056 int
2057 sys_rt_sigqueueinfo(struct tcb *tcp)
2058 {
2059         if (entering(tcp)) {
2060                 siginfo_t si;
2061                 tprintf("%lu, ", tcp->u_arg[0]);
2062                 printsignal(tcp->u_arg[1]);
2063                 tprintf(", ");
2064                 if (umove(tcp, tcp->u_arg[2], &si) < 0)
2065                         tprintf("%#lx", tcp->u_arg[2]);
2066                 else
2067                         printsiginfo(&si, verbose(tcp));
2068         }
2069         return 0;
2070 }
2071
2072 int sys_rt_sigtimedwait(struct tcb *tcp)
2073 {
2074         if (entering(tcp)) {
2075                 sigset_t sigset;
2076
2077                 if (copy_sigset_len(tcp, tcp->u_arg[0],
2078                                     &sigset, tcp->u_arg[3]) < 0)
2079                         tprintf("[?]");
2080                 else
2081                         printsigmask(&sigset, 1);
2082                 tprintf(", ");
2083                 /* This is the only "return" parameter, */
2084                 if (tcp->u_arg[1] != 0)
2085                         return 0;
2086                 /* ... if it's NULL, can decode all on entry */
2087                 tprintf("NULL, ");
2088         }
2089         else if (tcp->u_arg[1] != 0) {
2090                 /* syscall exit, and u_arg[1] wasn't NULL */
2091                 if (syserror(tcp))
2092                         tprintf("%#lx, ", tcp->u_arg[1]);
2093                 else {
2094                         siginfo_t si;
2095                         if (umove(tcp, tcp->u_arg[1], &si) < 0)
2096                                 tprintf("%#lx, ", tcp->u_arg[1]);
2097                         else {
2098                                 printsiginfo(&si, verbose(tcp));
2099                                 tprintf(", ");
2100                         }
2101                 }
2102         }
2103         else {
2104                 /* syscall exit, and u_arg[1] was NULL */
2105                 return 0;
2106         }
2107         print_timespec(tcp, tcp->u_arg[2]);
2108         tprintf(", %d", (int) tcp->u_arg[3]);
2109         return 0;
2110 };
2111
2112 int
2113 sys_restart_syscall(struct tcb *tcp)
2114 {
2115         if (entering(tcp))
2116                 tprintf("<... resuming interrupted call ...>");
2117         return 0;
2118 }
2119
2120 static int
2121 do_signalfd(struct tcb *tcp, int flags_arg)
2122 {
2123         if (entering(tcp)) {
2124                 printfd(tcp, tcp->u_arg[0]);
2125                 tprintf(", ");
2126                 print_sigset(tcp, tcp->u_arg[1], 1);
2127                 tprintf(", %lu", tcp->u_arg[2]);
2128                 if (flags_arg >= 0) {
2129                         tprintf(", ");
2130                         printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2131                 }
2132         }
2133         return 0;
2134 }
2135
2136 int
2137 sys_signalfd(struct tcb *tcp)
2138 {
2139         return do_signalfd(tcp, -1);
2140 }
2141
2142 int
2143 sys_signalfd4(struct tcb *tcp)
2144 {
2145         return do_signalfd(tcp, 3);
2146 }
2147 #endif /* LINUX */