blob: 242a0f33bc3f644ae17619999b2781c4a74a3539 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * 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>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00009 * 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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000038#include <signal.h>
39#include <sys/user.h>
40#include <fcntl.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041
42#ifdef SVR4
43#include <sys/ucontext.h>
44#endif /* SVR4 */
45
Wichert Akkerman36915a11999-07-13 15:45:02 +000046#ifdef HAVE_SYS_REG_H
47# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000048#ifndef PTRACE_PEEKUSR
Wichert Akkerman36915a11999-07-13 15:45:02 +000049# define PTRACE_PEEKUSR PTRACE_PEEKUSER
Wichert Akkerman15dea971999-10-06 13:06:34 +000050#endif
51#ifndef PTRACE_POKEUSR
Wichert Akkerman36915a11999-07-13 15:45:02 +000052# define PTRACE_POKEUSR PTRACE_POKEUSER
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000053#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000054#elif defined(HAVE_LINUX_PTRACE_H)
55#undef PTRACE_SYSCALL
Roland McGrathb0acdfd2004-03-01 21:31:02 +000056# 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
Wichert Akkermanfaf72222000-02-19 23:59:03 +000062#include <linux/ptrace.h>
Roland McGrathb0acdfd2004-03-01 21:31:02 +000063# undef ia64_fpreg
64# undef pt_all_user_regs
Wichert Akkerman15dea971999-10-06 13:06:34 +000065#endif
Wichert Akkerman36915a11999-07-13 15:45:02 +000066
Wichert Akkermanfaf72222000-02-19 23:59:03 +000067
Wichert Akkerman36915a11999-07-13 15:45:02 +000068#ifdef LINUX
69
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000070#ifdef IA64
71# include <asm/ptrace_offsets.h>
72#endif /* !IA64 */
73
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000074#if HAVE_ASM_REG_H
Roland McGrath6d1a65c2004-07-12 07:44:08 +000075# if defined (SPARC) || defined (SPARC64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000076# define fpq kernel_fpq
77# define fq kernel_fq
78# define fpu kernel_fpu
Roland McGrath30ff45e2003-01-30 20:15:23 +000079# endif
80# include <asm/reg.h>
Roland McGrath6d1a65c2004-07-12 07:44:08 +000081# if defined (SPARC) || defined (SPARC64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000082# undef fpq
83# undef fq
Roland McGratha39c5a12002-12-17 05:10:37 +000084# undef fpu
Roland McGrath30ff45e2003-01-30 20:15:23 +000085# endif
Roland McGrath6d1a65c2004-07-12 07:44:08 +000086#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 */
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000093#endif /* HAVE_ASM_REG_H */
Roland McGrath30ff45e2003-01-30 20:15:23 +000094
Roland McGrath6d1a65c2004-07-12 07:44:08 +000095#if defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000096typedef struct {
Wichert Akkerman9ce1a631999-08-29 23:15:07 +000097 struct regs si_regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000098 int si_mask;
99} m_siginfo_t;
Roland McGrath576b7842007-11-04 00:00:00 +0000100#elif defined (MIPS)
101typedef struct {
102 struct pt_regs si_regs;
103 int si_mask;
104} m_siginfo_t;
Roland McGrath30ff45e2003-01-30 20:15:23 +0000105#elif defined HAVE_ASM_SIGCONTEXT_H
106#if !defined(IA64) && !defined(X86_64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000107#include <asm/sigcontext.h>
Roland McGrath30ff45e2003-01-30 20:15:23 +0000108#endif /* !IA64 && !X86_64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000109#else /* !HAVE_ASM_SIGCONTEXT_H */
Roland McGrath0cbb4e42008-05-20 01:26:21 +0000110#if defined I386 && !defined HAVE_STRUCT_SIGCONTEXT_STRUCT
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000111struct 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 */
Roland McGrath587c7b52009-02-11 03:03:28 +0000136#if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000137struct sigcontext
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138{
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
Roland McGrathee36ce12004-09-04 03:53:10 +0000161const char *const signalent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000162#include "signalent.h"
163};
Roland McGrathee36ce12004-09-04 03:53:10 +0000164const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165
166#if SUPPORTED_PERSONALITIES >= 2
Roland McGrathee36ce12004-09-04 03:53:10 +0000167const char *const signalent1[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000168#include "signalent1.h"
169};
Roland McGrathee36ce12004-09-04 03:53:10 +0000170const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000171#endif /* SUPPORTED_PERSONALITIES >= 2 */
172
173#if SUPPORTED_PERSONALITIES >= 3
Roland McGrathee36ce12004-09-04 03:53:10 +0000174const char *const signalent2[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000175#include "signalent2.h"
176};
Roland McGrathee36ce12004-09-04 03:53:10 +0000177const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000178#endif /* SUPPORTED_PERSONALITIES >= 3 */
179
Roland McGrathee36ce12004-09-04 03:53:10 +0000180const char *const *signalent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181int nsignals;
182
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000183#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184
Roland McGrathd9f816f2004-09-04 03:39:20 +0000185static const struct xlat sigvec_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186 { SV_ONSTACK, "SV_ONSTACK" },
187 { SV_INTERRUPT, "SV_INTERRUPT" },
188 { SV_RESETHAND, "SV_RESETHAND" },
189 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
190 { 0, NULL },
191};
192
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000193#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000194
195#ifdef HAVE_SIGACTION
196
Roland McGrath063ae2d2005-02-02 04:16:54 +0000197#if defined LINUX && (defined I386 || defined X86_64)
Roland McGrath2638cb42002-12-15 23:58:41 +0000198/* 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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000205static const struct xlat sigact_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000206#ifdef SA_RESTORER
207 { SA_RESTORER, "SA_RESTORER" },
208#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000209#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
Roland McGrath4fef51d2008-07-18 01:02:41 +0000218#ifdef SA_NODEFER
219 { SA_NODEFER, "SA_NODEFER" },
220#endif
221#if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 { SA_NOMASK, "SA_NOMASK" },
223#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000224#ifdef SA_RESETHAND
225 { SA_RESETHAND, "SA_RESETHAND" },
226#endif
227#if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000228 { 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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000254static const struct xlat sigprocmaskcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255 { 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
Nate Sammonsce780fc1999-03-29 23:23:13 +0000266/* 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
Roland McGrathee36ce12004-09-04 03:53:10 +0000276const char *
Nate Sammonsce780fc1999-03-29 23:23:13 +0000277signame(sig)
278int sig;
279{
280 static char buf[30];
Roland McGrathad81dce2005-05-09 07:40:30 +0000281 if (sig >= 0 && sig < nsignals) {
Nate Sammonsce780fc1999-03-29 23:23:13 +0000282 return signalent[sig];
283#ifdef SIGRTMIN
Nate Sammons3080aa41999-03-30 00:16:41 +0000284 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000285 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000286 return buf;
287#endif /* SIGRTMIN */
288 } else {
289 sprintf(buf, "%d", sig);
290 return buf;
291 }
292}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000293
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000294#ifndef UNIXWARE
Nate Sammons4a121431999-04-06 01:19:39 +0000295static void
296long_to_sigset(l, s)
297long l;
298sigset_t *s;
299{
300 sigemptyset(s);
301 *(long *)s = l;
302}
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000303#endif
Nate Sammons4a121431999-04-06 01:19:39 +0000304
305static int
306copy_sigset_len(tcp, addr, s, len)
307struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000308long addr;
Nate Sammons4a121431999-04-06 01:19:39 +0000309sigset_t *s;
310int 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
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000327static const char *
328sprintsigmask(const char *str, sigset_t *mask, int rt)
329/* set might include realtime sigs */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000330{
331 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000332 int maxsigs;
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000333 char *format, *s;
Roland McGratha39c5a12002-12-17 05:10:37 +0000334 static char outstr[8 * sizeof(sigset_t) * 8];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000335
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000336 strcpy(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000337 s = outstr + strlen(outstr);
338 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000339 maxsigs = nsignals;
340#ifdef __SIGRTMAX
341 if (rt)
342 maxsigs = __SIGRTMAX; /* instead */
343#endif
344 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000345 if (sigismember(mask, i) == 1)
346 nsigs++;
347 }
348 if (nsigs >= nsignals * 2 / 3) {
349 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000350 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000351 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++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000363 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000364 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000365 /* real-time signals on solaris don't have
366 * signalent entries
367 */
368 if (i < nsignals) {
369 sprintf(s, format, signalent[i] + 3);
370 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000371#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 */
John Hughesbdf48f52001-03-06 15:08:09 +0000378 else {
379 char tsig[32];
380 sprintf(tsig, "%u", i);
381 sprintf(s, format, tsig);
382 }
383 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384 format = " %s";
385 }
386 }
387 *s++ = ']';
388 *s = '\0';
389 return outstr;
390}
391
392static void
Nate Sammons4a121431999-04-06 01:19:39 +0000393printsigmask(mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000395int rt;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000396{
Nate Sammons4a121431999-04-06 01:19:39 +0000397 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000398}
399
400void
401printsignal(nr)
402int nr;
403{
Nate Sammonsce780fc1999-03-29 23:23:13 +0000404 tprintf(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000405}
406
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000407void
408print_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
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000420#ifdef LINUX
421
John Hughes58265892001-10-18 15:13:53 +0000422#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 */
Roland McGrath941b7402003-05-23 00:29:02 +0000463#define SI_SIGIO -5 /* Sent by SIGIO */
464#define SI_TKILL -6 /* Sent by tkill */
John Hughes58265892001-10-18 15:13:53 +0000465#endif
466
467#if __GLIBC_MINOR__ < 1
468/* Type for data associated with a signal. */
469typedef 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
478typedef 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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000553static const struct xlat siginfo_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000554#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
Roland McGrath941b7402003-05-23 00:29:02 +0000575#ifdef SI_SIGIO
576 { SI_SIGIO, "SI_SIGIO" },
577#endif
578#ifdef SI_TKILL
579 { SI_TKILL, "SI_TKILL" },
580#endif
John Hughes58265892001-10-18 15:13:53 +0000581 { 0, NULL },
582};
583
Roland McGrathd9f816f2004-09-04 03:39:20 +0000584static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000585 { 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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000596static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000597 { 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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000608static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000609 { TRAP_BRKPT, "TRAP_BRKPT" },
610 { TRAP_TRACE, "TRAP_TRACE" },
611 { 0, NULL },
612};
613
Roland McGrathd9f816f2004-09-04 03:39:20 +0000614static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000615 { 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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000624static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000625 { 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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000634static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000635#ifdef PROF_SIG
636 { PROF_SIG, "PROF_SIG" },
637#endif
638 { 0, NULL },
639};
640
641#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000642static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000643#ifdef EMT_TAGOVF
644 { EMT_TAGOVF, "EMT_TAGOVF" },
645#endif
646 { 0, NULL },
647};
648#endif
649
Roland McGrathd9f816f2004-09-04 03:39:20 +0000650static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000651 { SEGV_MAPERR, "SEGV_MAPERR" },
652 { SEGV_ACCERR, "SEGV_ACCERR" },
653 { 0, NULL },
654};
655
Roland McGrathd9f816f2004-09-04 03:39:20 +0000656static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000657 { BUS_ADRALN, "BUS_ADRALN" },
658 { BUS_ADRERR, "BUS_ADRERR" },
659 { BUS_OBJERR, "BUS_OBJERR" },
660 { 0, NULL },
661};
662
663void
664printsiginfo(sip, verbose)
665siginfo_t *sip;
666int verbose;
667{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000668 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000669
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
Roland McGratha39c5a12002-12-17 05:10:37 +0000791
John Hughes58265892001-10-18 15:13:53 +0000792 }
793 }
794 }
795 tprintf("}");
796}
797
798#endif /* SVR4 || LINUX */
799
800#ifdef LINUX
801
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000802static void
803parse_sigset_t (const char *str, sigset_t *set)
804{
Roland McGrathc38feca2003-10-01 07:50:28 +0000805 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000806 unsigned int digit;
807 int i;
808
809 sigemptyset(set);
810
Roland McGrathc38feca2003-10-01 07:50:28 +0000811 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')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000818 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000819 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000820 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000821 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000822 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000823 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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000836/*
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 */
841int
842sigishandled(tcp, sig)
843struct tcb *tcp;
844int sig;
845{
846#ifdef LINUX
847 int sfd;
848 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000849 char buf[2048];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000850 char *s;
851 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000852 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000854#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 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000878#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000879#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 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000897 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000898 if (!s)
899 {
900 fprintf(stderr, "/proc/pid/status format error\n");
901 return 1;
902 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000903 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000904
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000905 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);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000912
913#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000914 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
915 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000916#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000917 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000918 return 1;
919#endif /* LINUX */
920
921#ifdef SUNOS4
922 void (*u_signal)();
923
Denys Vlasenko932fc7d2008-12-16 18:18:40 +0000924 if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal),
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000925 (long *) &u_signal) < 0) {
926 return 0;
927 }
928 if (u_signal != SIG_DFL)
929 return 1;
930#endif /* SUNOS4 */
931
932 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000933}
934
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000935#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000936
937int
938sys_sigvec(tcp)
939struct 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);
Nate Sammons4a121431999-04-06 01:19:39 +0000985 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000987 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000988 tprintf("}");
989 }
990 }
991 if (entering(tcp))
992 tprintf(", ");
993 return 0;
994}
995
996int
997sys_sigpause(tcp)
998struct tcb *tcp;
999{
1000 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +00001001 sigset_t sigm;
1002 long_to_sigset(tcp->u_arg[0], &sigm);
1003 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001004 }
1005 return 0;
1006}
1007
1008int
1009sys_sigstack(tcp)
1010struct 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
1032int
1033sys_sigcleanup(tcp)
1034struct tcb *tcp;
1035{
1036 return 0;
1037}
1038
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001039#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001040
1041#ifndef SVR4
1042
1043int
1044sys_sigsetmask(tcp)
1045struct tcb *tcp;
1046{
1047 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001048 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001049 long_to_sigset(tcp->u_arg[0], &sigm);
1050 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001051#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052 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 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001058#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001059 }
1060 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001061 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001062 long_to_sigset(tcp->u_rval, &sigm);
1063 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001064
1065 return RVAL_HEX | RVAL_STR;
1066 }
1067 return 0;
1068}
1069
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001070#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071int
1072sys_sigblock(tcp)
1073struct tcb *tcp;
1074{
1075 return sys_sigsetmask(tcp);
1076}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001077#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001078
1079#endif /* !SVR4 */
1080
1081#ifdef HAVE_SIGACTION
1082
1083#ifdef LINUX
1084struct old_sigaction {
1085 __sighandler_t __sa_handler;
1086 unsigned long sa_mask;
1087 unsigned long sa_flags;
1088 void (*sa_restorer)(void);
1089};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001090#define SA_HANDLER __sa_handler
1091#endif /* LINUX */
1092
Roland McGratha39c5a12002-12-17 05:10:37 +00001093#ifndef SA_HANDLER
1094#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001095#endif
1096
1097int
1098sys_sigaction(tcp)
1099struct tcb *tcp;
1100{
1101 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001102#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001103 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001104 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001105#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 {
Roland McGrath5f206812008-08-20 01:59:40 +00001123 if (sa.SA_HANDLER == SIG_ERR)
1124 tprintf("{SIG_ERR, ");
1125 else if (sa.SA_HANDLER == SIG_DFL)
1126 tprintf("{SIG_DFL, ");
Denys Vlasenko73ce40e2008-12-17 17:22:03 +00001127 else if (sa.SA_HANDLER == SIG_IGN) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001128#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001129 if (tcp->u_arg[0] == SIGTRAP) {
1130 tcp->flags |= TCB_SIGTRAPPED;
1131 kill(tcp->pid, SIGSTOP);
1132 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001133#endif /* !USE_PROCFS */
Roland McGrath5f206812008-08-20 01:59:40 +00001134 tprintf("{SIG_IGN, ");
1135 }
1136 else {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001137#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001138 if (tcp->u_arg[0] == SIGTRAP) {
1139 tcp->flags |= TCB_SIGTRAPPED;
1140 kill(tcp->pid, SIGSTOP);
1141 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001142#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001143 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001144#ifndef LINUX
1145 printsigmask (&sa.sa_mask, 0);
1146#else
Nate Sammons4a121431999-04-06 01:19:39 +00001147 long_to_sigset(sa.sa_mask, &sigset);
1148 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001149#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001150 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001151 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001152#ifdef SA_RESTORER
1153 if (sa.sa_flags & SA_RESTORER)
1154 tprintf(", %p", sa.sa_restorer);
1155#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001156 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
1168int
1169sys_signal(tcp)
1170struct tcb *tcp;
1171{
1172 if (entering(tcp)) {
1173 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001174 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001175 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001176 case (long) SIG_ERR:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001177 tprintf("SIG_ERR");
1178 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001179 case (long) SIG_DFL:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001180 tprintf("SIG_DFL");
1181 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001182 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001183#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001184 if (tcp->u_arg[0] == SIGTRAP) {
1185 tcp->flags |= TCB_SIGTRAPPED;
1186 kill(tcp->pid, SIGSTOP);
1187 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001188#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001189 tprintf("SIG_IGN");
1190 break;
1191 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001192#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001193 if (tcp->u_arg[0] == SIGTRAP) {
1194 tcp->flags |= TCB_SIGTRAPPED;
1195 kill(tcp->pid, SIGSTOP);
1196 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001197#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001198 tprintf("%#lx", tcp->u_arg[1]);
1199 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001200 return 0;
1201 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001202 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001203 switch (tcp->u_rval) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001204 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001205 tcp->auxstr = "SIG_ERR"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001206 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001207 tcp->auxstr = "SIG_DFL"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001208 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001209 tcp->auxstr = "SIG_IGN"; break;
1210 default:
1211 tcp->auxstr = NULL;
1212 }
1213 return RVAL_HEX | RVAL_STR;
1214 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001215 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001216}
1217
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001218#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001219int
1220sys_sighold(tcp)
1221struct tcb *tcp;
1222{
1223 if (entering(tcp)) {
1224 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001225 }
1226 return 0;
1227}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001228#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001229
1230#endif /* HAVE_SIGACTION */
1231
1232#ifdef LINUX
1233
1234int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001235sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001236{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001237#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001238 struct pt_regs regs;
1239 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001240
Roland McGrath0f87c492003-06-03 23:29:04 +00001241 if (entering(tcp)) {
1242 tcp->u_arg[0] = 0;
1243
1244 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1245 return 0;
1246
1247 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1248 return 0;
1249
1250 tcp->u_arg[0] = 1;
1251 tcp->u_arg[1] = sc.oldmask;
1252 } else {
1253 sigset_t sigm;
1254 long_to_sigset(tcp->u_arg[1], &sigm);
1255 tcp->u_rval = tcp->u_error = 0;
1256 if (tcp->u_arg[0] == 0)
1257 return 0;
1258 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1259 return RVAL_NONE | RVAL_STR;
1260 }
1261 return 0;
1262#elif defined(S390) || defined(S390X)
1263 long usp;
1264 struct sigcontext_struct sc;
1265
1266 if (entering(tcp)) {
1267 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001268 if (upeek(tcp,PT_GPR15,&usp)<0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001269 return 0;
1270 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1271 return 0;
1272 tcp->u_arg[0] = 1;
1273 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1274 } else {
1275 tcp->u_rval = tcp->u_error = 0;
1276 if (tcp->u_arg[0] == 0)
1277 return 0;
1278 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1279 return RVAL_NONE | RVAL_STR;
1280 }
1281 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001282#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001283 long esp;
1284 struct sigcontext_struct sc;
1285
1286 if (entering(tcp)) {
1287 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001288 if (upeek(tcp, 4*UESP, &esp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001289 return 0;
1290 if (umove(tcp, esp, &sc) < 0)
1291 return 0;
1292 tcp->u_arg[0] = 1;
1293 tcp->u_arg[1] = sc.oldmask;
1294 }
1295 else {
1296 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001297 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298 tcp->u_rval = tcp->u_error = 0;
1299 if (tcp->u_arg[0] == 0)
1300 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001301 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001302 return RVAL_NONE | RVAL_STR;
1303 }
1304 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001305#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001306 struct sigcontext sc;
1307 long sp;
1308
1309 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001310 /* offset of sigcontext in the kernel's sigframe structure: */
1311# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001312 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001313 if (upeek(tcp, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001314 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001315 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001316 return 0;
1317 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001318 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001319 }
1320 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001321 sigset_t sigm;
1322
1323 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001324 tcp->u_rval = tcp->u_error = 0;
1325 if (tcp->u_arg[0] == 0)
1326 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001327 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001328 return RVAL_NONE | RVAL_STR;
1329 }
1330 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001331#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +00001332 long esp;
1333 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334
Roland McGrath0f87c492003-06-03 23:29:04 +00001335 if (entering(tcp)) {
1336 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001337 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001338 return 0;
1339 if (umove(tcp, esp, &sc) < 0)
1340 return 0;
1341 tcp->u_arg[0] = 1;
1342 tcp->u_arg[1] = sc.oldmask;
1343 }
1344 else {
1345 sigset_t sigm;
1346 long_to_sigset(tcp->u_arg[1], &sigm);
1347 tcp->u_rval = tcp->u_error = 0;
1348 if (tcp->u_arg[0] == 0)
1349 return 0;
1350 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1351 return RVAL_NONE | RVAL_STR;
1352 }
1353 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001354#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001355 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001356 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001357
1358 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001359 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001360 if (upeek(tcp, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001361 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001362 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001363 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001364 tcp->u_arg[0] = 1;
1365 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001366 }
1367 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001368 sigset_t sigm;
1369 long_to_sigset(tcp->u_arg[1], &sigm);
1370 tcp->u_rval = tcp->u_error = 0;
1371 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001372 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001373 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1374 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001375 }
1376 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001377#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378 long fp;
1379 struct sigcontext_struct sc;
1380
1381 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001382 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001383 if (upeek(tcp, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001384 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001385 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001386 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001387 tcp->u_arg[0] = 1;
1388 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001389 }
1390 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001391 sigset_t sigm;
1392 long_to_sigset(tcp->u_arg[1], &sigm);
1393 tcp->u_rval = tcp->u_error = 0;
1394 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001395 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001396 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1397 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001398 }
1399 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001400#elif defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001401 long i1;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001402 struct regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001403 m_siginfo_t si;
1404
Denys Vlasenko4dedd562009-02-24 15:17:53 +00001405 if (do_ptrace(PTRACE_GETREGS, tcp, (char *)&regs, 0) < 0) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001406 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001407 }
Denys Vlasenko4dedd562009-02-24 15:17:53 +00001408 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001410 i1 = regs.r_o1;
Denys Vlasenko4dedd562009-02-24 15:17:53 +00001411 if (umove(tcp, i1, &si) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001412 perror("sigreturn: umove ");
1413 return 0;
1414 }
1415 tcp->u_arg[0] = 1;
1416 tcp->u_arg[1] = si.si_mask;
1417 } else {
1418 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001419 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001420 tcp->u_rval = tcp->u_error = 0;
1421 if(tcp->u_arg[0] == 0)
1422 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001423 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424 return RVAL_NONE | RVAL_STR;
1425 }
1426 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001427#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001428 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1429 sigreturn. */
1430 long sp;
1431 struct ucontext uc;
1432
1433 if(entering(tcp)) {
1434 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001435 if (upeek(tcp, REG_SP, &sp) < 0)
Roland McGrath542c2c62008-05-20 01:11:56 +00001436 return 0;
1437 /* There are six words followed by a 128-byte siginfo. */
1438 sp = sp + 6 * 4 + 128;
1439 if (umove(tcp, sp, &uc) < 0)
1440 return 0;
1441 tcp->u_arg[0] = 1;
1442 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1443 } else {
1444 sigset_t sigm;
1445 long_to_sigset(tcp->u_arg[1], &sigm);
1446 tcp->u_rval = tcp->u_error = 0;
1447 if(tcp->u_arg[0] == 0)
1448 return 0;
1449 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1450 return RVAL_NONE | RVAL_STR;
1451 }
1452 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001453#elif defined(MIPS)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001454 long sp;
Roland McGrath576b7842007-11-04 00:00:00 +00001455 struct pt_regs regs;
1456 m_siginfo_t si;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001457
Roland McGrath576b7842007-11-04 00:00:00 +00001458 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1459 perror("sigreturn: PTRACE_GETREGS ");
1460 return 0;
1461 }
Wichert Akkermanf90da011999-10-31 21:15:38 +00001462 if(entering(tcp)) {
1463 tcp->u_arg[0] = 0;
Roland McGrath576b7842007-11-04 00:00:00 +00001464 sp = regs.regs[29];
1465 if (umove(tcp, sp, &si) < 0)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001466 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001467 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001468 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001469 sigset_t sigm;
1470 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001471 tcp->u_rval = tcp->u_error = 0;
1472 if(tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001473 return 0;
1474 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001475 return RVAL_NONE | RVAL_STR;
1476 }
1477 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001478#elif defined(CRISV10) || defined(CRISV32)
1479 struct sigcontext sc;
1480
1481 if (entering(tcp)) {
1482 long regs[PT_MAX+1];
1483
1484 tcp->u_arg[0] = 0;
1485
1486 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1487 perror("sigreturn: PTRACE_GETREGS");
1488 return 0;
1489 }
1490 if (umove(tcp, regs[PT_USP], &sc) < 0)
1491 return 0;
1492 tcp->u_arg[0] = 1;
1493 tcp->u_arg[1] = sc.oldmask;
1494 } else {
1495 sigset_t sigm;
1496 long_to_sigset(tcp->u_arg[1], &sigm);
1497 tcp->u_rval = tcp->u_error = 0;
1498
1499 if (tcp->u_arg[0] == 0)
1500 return 0;
1501 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1502 return RVAL_NONE | RVAL_STR;
1503 }
1504 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001505#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001506#warning No sys_sigreturn() for this architecture
1507#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001508 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001509#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001510}
1511
1512int
1513sys_siggetmask(tcp)
1514struct tcb *tcp;
1515{
1516 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001517 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001518 long_to_sigset(tcp->u_rval, &sigm);
1519 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001520 }
1521 return RVAL_HEX | RVAL_STR;
1522}
1523
1524int
1525sys_sigsuspend(tcp)
1526struct tcb *tcp;
1527{
1528 if (entering(tcp)) {
1529 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001530 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001531#if 0
1532 /* first two are not really arguments, but print them anyway */
1533 /* nevermind, they are an anachronism now, too bad... */
1534 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1535#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001536 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001537 }
1538 return 0;
1539}
1540
1541#endif /* LINUX */
1542
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001543#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001544
1545int
1546sys_sigsuspend(tcp)
1547struct tcb *tcp;
1548{
1549 sigset_t sigset;
1550
1551 if (entering(tcp)) {
1552 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1553 tprintf("[?]");
1554 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001555 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001556 }
1557 return 0;
1558}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001559#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001560static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001561 { UC_SIGMASK, "UC_SIGMASK" },
1562 { UC_STACK, "UC_STACK" },
1563 { UC_CPU, "UC_CPU" },
1564#ifdef UC_FPU
1565 { UC_FPU, "UC_FPU" },
1566#endif
1567#ifdef UC_INTR
1568 { UC_INTR, "UC_INTR" },
1569#endif
1570 { 0, NULL },
1571};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001572#endif /* !FREEBSD */
1573#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001574
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001575#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576#if defined LINUX && !defined SS_ONSTACK
1577#define SS_ONSTACK 1
1578#define SS_DISABLE 2
1579#if __GLIBC_MINOR__ == 0
1580typedef struct
1581{
1582 __ptr_t ss_sp;
1583 int ss_flags;
1584 size_t ss_size;
1585} stack_t;
1586#endif
1587#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001588#ifdef FREEBSD
1589#define stack_t struct sigaltstack
1590#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001591
Roland McGrathd9f816f2004-09-04 03:39:20 +00001592static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593 { SS_ONSTACK, "SS_ONSTACK" },
1594 { SS_DISABLE, "SS_DISABLE" },
1595 { 0, NULL },
1596};
1597#endif
1598
1599#ifdef SVR4
1600static void
1601printcontext(tcp, ucp)
1602struct tcb *tcp;
1603ucontext_t *ucp;
1604{
1605 tprintf("{");
1606 if (!abbrev(tcp)) {
1607 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001608 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001609 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1610 }
1611 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001612 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001613 if (!abbrev(tcp)) {
1614 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1615 (unsigned long) ucp->uc_stack.ss_sp,
1616 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001617 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001618 tprintf("}");
1619 }
1620 tprintf(", ...}");
1621}
1622
1623int
1624sys_getcontext(tcp)
1625struct tcb *tcp;
1626{
1627 ucontext_t uc;
1628
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001629 if (exiting(tcp)) {
1630 if (tcp->u_error)
1631 tprintf("%#lx", tcp->u_arg[0]);
1632 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001633 tprintf("NULL");
1634 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1635 tprintf("{...}");
1636 else
1637 printcontext(tcp, &uc);
1638 }
1639 return 0;
1640}
1641
1642int
1643sys_setcontext(tcp)
1644struct tcb *tcp;
1645{
1646 ucontext_t uc;
1647
1648 if (entering(tcp)) {
1649 if (!tcp->u_arg[0])
1650 tprintf("NULL");
1651 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1652 tprintf("{...}");
1653 else
1654 printcontext(tcp, &uc);
1655 }
1656 else {
1657 tcp->u_rval = tcp->u_error = 0;
1658 if (tcp->u_arg[0] == 0)
1659 return 0;
1660 return RVAL_NONE;
1661 }
1662 return 0;
1663}
1664
1665#endif /* SVR4 */
1666
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001667#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001668
1669static int
1670print_stack_t(tcp, addr)
1671struct tcb *tcp;
1672unsigned long addr;
1673{
1674 stack_t ss;
1675 if (umove(tcp, addr, &ss) < 0)
1676 return -1;
1677 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001678 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001679 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1680 return 0;
1681}
1682
1683int
1684sys_sigaltstack(tcp)
1685 struct tcb *tcp;
1686{
1687 if (entering(tcp)) {
1688 if (tcp->u_arg[0] == 0)
1689 tprintf("NULL");
1690 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1691 return -1;
1692 }
1693 else {
1694 tprintf(", ");
1695 if (tcp->u_arg[1] == 0)
1696 tprintf("NULL");
1697 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1698 return -1;
1699 }
1700 return 0;
1701}
1702#endif
1703
1704#ifdef HAVE_SIGACTION
1705
1706int
1707sys_sigprocmask(tcp)
1708struct tcb *tcp;
1709{
1710#ifdef ALPHA
1711 if (entering(tcp)) {
1712 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1713 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001714 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001715 }
1716 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001717 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001718 return RVAL_HEX | RVAL_STR;
1719 }
1720#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001721 if (entering(tcp)) {
1722#ifdef SVR4
1723 if (tcp->u_arg[0] == 0)
1724 tprintf("0");
1725 else
1726#endif /* SVR4 */
1727 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1728 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001729 print_sigset(tcp, tcp->u_arg[1], 0);
1730 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001731 }
1732 else {
1733 if (!tcp->u_arg[2])
1734 tprintf("NULL");
1735 else if (syserror(tcp))
1736 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001737 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001738 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001739 }
1740#endif /* !ALPHA */
1741 return 0;
1742}
1743
1744#endif /* HAVE_SIGACTION */
1745
1746int
1747sys_kill(tcp)
1748struct tcb *tcp;
1749{
1750 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001751 /*
1752 * Sign-extend a 32-bit value when that's what it is.
1753 */
1754 long pid = tcp->u_arg[0];
1755 if (personality_wordsize[current_personality] < sizeof pid)
1756 pid = (long) (int) pid;
1757 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001758 }
1759 return 0;
1760}
1761
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001762#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001763int
1764sys_killpg(tcp)
1765struct tcb *tcp;
1766{
1767 return sys_kill(tcp);
1768}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001769#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001770
Roland McGrath8ffc3522003-07-09 09:47:49 +00001771#ifdef LINUX
1772int
1773sys_tgkill(tcp)
1774 struct tcb *tcp;
1775{
1776 if (entering(tcp)) {
1777 tprintf("%ld, %ld, %s",
1778 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1779 }
1780 return 0;
1781}
1782#endif
1783
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001784int
1785sys_sigpending(tcp)
1786struct tcb *tcp;
1787{
1788 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001789
1790 if (exiting(tcp)) {
1791 if (syserror(tcp))
1792 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001793 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001794 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001795 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001796 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001797 }
1798 return 0;
1799}
1800
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001801#ifdef SVR4
John Hughes42162082001-10-18 14:48:26 +00001802int sys_sigwait(tcp)
1803struct tcb *tcp;
1804{
1805 sigset_t sigset;
1806
1807 if (entering(tcp)) {
1808 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1809 tprintf("[?]");
1810 else
1811 printsigmask(&sigset, 0);
1812 }
1813 else {
1814 if (!syserror(tcp)) {
1815 tcp->auxstr = signalent[tcp->u_rval];
1816 return RVAL_DECIMAL | RVAL_STR;
1817 }
1818 }
1819 return 0;
1820}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001821#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001822
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001823#ifdef LINUX
1824
1825 int
1826sys_rt_sigprocmask(tcp)
1827 struct tcb *tcp;
1828{
1829 sigset_t sigset;
1830
Nate Sammons4a121431999-04-06 01:19:39 +00001831 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001832 if (entering(tcp)) {
1833 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1834 tprintf(", ");
1835 if (!tcp->u_arg[1])
1836 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001837 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001838 tprintf("%#lx, ", tcp->u_arg[1]);
1839 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001840 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001841 tprintf(", ");
1842 }
1843 }
1844 else {
1845 if (!tcp->u_arg[2])
1846
1847 tprintf("NULL");
1848 else if (syserror(tcp))
1849 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001850 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851 tprintf("[?]");
1852 else
Nate Sammons4a121431999-04-06 01:19:39 +00001853 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001854 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001855 }
1856 return 0;
1857}
1858
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001859
1860/* Structure describing the action to be taken when a signal arrives. */
1861struct new_sigaction
1862{
1863 union
1864 {
1865 __sighandler_t __sa_handler;
1866 void (*__sa_sigaction) (int, siginfo_t *, void *);
1867 }
1868 __sigaction_handler;
1869 unsigned long sa_flags;
1870 void (*sa_restorer) (void);
1871 unsigned long int sa_mask[2];
1872};
1873
1874
Roland McGrath5f206812008-08-20 01:59:40 +00001875int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001876sys_rt_sigaction(tcp)
1877 struct tcb *tcp;
1878{
1879 struct new_sigaction sa;
1880 sigset_t sigset;
1881 long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001882
1883 if (entering(tcp)) {
1884 printsignal(tcp->u_arg[0]);
1885 tprintf(", ");
1886 addr = tcp->u_arg[1];
1887 } else
1888 addr = tcp->u_arg[2];
1889 if (addr == 0)
1890 tprintf("NULL");
1891 else if (!verbose(tcp))
1892 tprintf("%#lx", addr);
1893 else if (umove(tcp, addr, &sa) < 0)
1894 tprintf("{...}");
1895 else {
Roland McGrath5f206812008-08-20 01:59:40 +00001896 if (sa.__sigaction_handler.__sa_handler == SIG_ERR)
1897 tprintf("{SIG_ERR, ");
1898 else if (sa.__sigaction_handler.__sa_handler == SIG_DFL)
1899 tprintf("{SIG_DFL, ");
Denys Vlasenko73ce40e2008-12-17 17:22:03 +00001900 else if (sa.__sigaction_handler.__sa_handler == SIG_IGN)
Roland McGrath5f206812008-08-20 01:59:40 +00001901 tprintf("{SIG_IGN, ");
1902 else
1903 tprintf("{%#lx, ",
1904 (long) sa.__sigaction_handler.__sa_handler);
1905 sigemptyset(&sigset);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001906#ifdef LINUXSPARC
Roland McGrath5f206812008-08-20 01:59:40 +00001907 if (tcp->u_arg[4] <= sizeof(sigset))
1908 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001909#else
Roland McGrath5f206812008-08-20 01:59:40 +00001910 if (tcp->u_arg[3] <= sizeof(sigset))
1911 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001912#endif
Roland McGrath5f206812008-08-20 01:59:40 +00001913 else
1914 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1915 printsigmask(&sigset, 1);
1916 tprintf(", ");
1917 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001918#ifdef SA_RESTORER
Roland McGrath5f206812008-08-20 01:59:40 +00001919 if (sa.sa_flags & SA_RESTORER)
1920 tprintf(", %p", sa.sa_restorer);
Roland McGrath2638cb42002-12-15 23:58:41 +00001921#endif
Roland McGrath5f206812008-08-20 01:59:40 +00001922 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001923 }
1924 if (entering(tcp))
1925 tprintf(", ");
1926 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001927#ifdef LINUXSPARC
1928 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1929#elif defined(ALPHA)
1930 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1931#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001932 tprintf(", %lu", addr = tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001933#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001934 return 0;
1935}
1936
1937 int
1938sys_rt_sigpending(tcp)
1939 struct tcb *tcp;
1940{
1941 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001942
1943 if (exiting(tcp)) {
1944 if (syserror(tcp))
1945 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001946 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1947 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001948 tprintf("[?]");
1949 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001950 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001951 }
1952 return 0;
1953}
1954 int
1955sys_rt_sigsuspend(tcp)
1956 struct tcb *tcp;
1957{
1958 if (entering(tcp)) {
1959 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001960 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1961 tprintf("[?]");
1962 else
1963 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001964 }
1965 return 0;
1966}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001967 int
1968sys_rt_sigqueueinfo(tcp)
1969 struct tcb *tcp;
1970{
1971 if (entering(tcp)) {
1972 siginfo_t si;
1973 tprintf("%lu, ", tcp->u_arg[0]);
1974 printsignal(tcp->u_arg[1]);
1975 tprintf(", ");
1976 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1977 tprintf("%#lx", tcp->u_arg[2]);
1978 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00001979 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001980 }
1981 return 0;
1982}
1983
1984int sys_rt_sigtimedwait(tcp)
1985 struct tcb *tcp;
1986{
1987 if (entering(tcp)) {
1988 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001989
Roland McGratha39c5a12002-12-17 05:10:37 +00001990 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00001991 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001992 tprintf("[?]");
1993 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001994 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001995 tprintf(", ");
1996 }
1997 else {
1998 if (syserror(tcp))
1999 tprintf("%#lx", tcp->u_arg[0]);
2000 else {
2001 siginfo_t si;
2002 if (umove(tcp, tcp->u_arg[1], &si) < 0)
2003 tprintf("%#lx", tcp->u_arg[1]);
2004 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002005 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002006 /* XXX For now */
2007 tprintf(", %#lx", tcp->u_arg[2]);
2008 tprintf(", %d", (int) tcp->u_arg[3]);
2009 }
2010 }
2011 return 0;
2012};
2013
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002014int
2015sys_restart_syscall(tcp)
2016struct tcb *tcp;
2017{
2018 if (entering(tcp))
2019 tprintf("<... resuming interrupted call ...>");
2020 return 0;
2021}
2022
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002023static int
2024do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00002025{
2026 if (entering(tcp)) {
2027 tprintf("%ld, ", tcp->u_arg[0]);
2028 print_sigset(tcp, tcp->u_arg[1], 1);
2029 tprintf("%lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002030 if (flags_arg >= 0) {
2031 tprintf(", ");
2032 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2033 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00002034 }
2035 return 0;
2036}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002037
2038int
2039sys_signalfd(struct tcb *tcp)
2040{
2041 return do_signalfd(tcp, -1);
2042}
2043
2044int
2045sys_signalfd4(struct tcb *tcp)
2046{
2047 return do_signalfd(tcp, 3);
2048}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002049#endif /* LINUX */