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