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