blob: 31f86d7e1ffb0ff74052d9241299d3df03529ce0 [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
Denys Vlasenko7a862d72009-04-15 13:22:59 +000038#include <stdint.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000039#include <signal.h>
40#include <sys/user.h>
41#include <fcntl.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042
43#ifdef SVR4
44#include <sys/ucontext.h>
45#endif /* SVR4 */
46
Wichert Akkerman36915a11999-07-13 15:45:02 +000047#ifdef HAVE_SYS_REG_H
48# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000049#ifndef PTRACE_PEEKUSR
Wichert Akkerman36915a11999-07-13 15:45:02 +000050# define PTRACE_PEEKUSR PTRACE_PEEKUSER
Wichert Akkerman15dea971999-10-06 13:06:34 +000051#endif
52#ifndef PTRACE_POKEUSR
Wichert Akkerman36915a11999-07-13 15:45:02 +000053# define PTRACE_POKEUSR PTRACE_POKEUSER
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000054#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000055#elif defined(HAVE_LINUX_PTRACE_H)
56#undef PTRACE_SYSCALL
Roland McGrathb0acdfd2004-03-01 21:31:02 +000057# ifdef HAVE_STRUCT_IA64_FPREG
58# define ia64_fpreg XXX_ia64_fpreg
59# endif
60# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
61# define pt_all_user_regs XXX_pt_all_user_regs
62# endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000063#include <linux/ptrace.h>
Roland McGrathb0acdfd2004-03-01 21:31:02 +000064# undef ia64_fpreg
65# undef pt_all_user_regs
Wichert Akkerman15dea971999-10-06 13:06:34 +000066#endif
Wichert Akkerman36915a11999-07-13 15:45:02 +000067
Wichert Akkermanfaf72222000-02-19 23:59:03 +000068
Wichert Akkerman36915a11999-07-13 15:45:02 +000069#ifdef LINUX
70
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000071#ifdef IA64
72# include <asm/ptrace_offsets.h>
73#endif /* !IA64 */
74
Roland McGrath6d1a65c2004-07-12 07:44:08 +000075#if defined (LINUX) && defined (SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000076# undef PTRACE_GETREGS
77# define PTRACE_GETREGS PTRACE_GETREGS64
78# undef PTRACE_SETREGS
79# define PTRACE_SETREGS PTRACE_SETREGS64
80#endif /* LINUX && SPARC64 */
Roland McGrath30ff45e2003-01-30 20:15:23 +000081
Mike Frysinger8566c502009-10-12 11:05:14 -040082#if defined (SPARC) || defined (SPARC64) || defined (MIPS)
Roland McGrath576b7842007-11-04 00:00:00 +000083typedef struct {
84 struct pt_regs si_regs;
85 int si_mask;
86} m_siginfo_t;
Roland McGrath30ff45e2003-01-30 20:15:23 +000087#elif defined HAVE_ASM_SIGCONTEXT_H
88#if !defined(IA64) && !defined(X86_64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000089#include <asm/sigcontext.h>
Roland McGrath30ff45e2003-01-30 20:15:23 +000090#endif /* !IA64 && !X86_64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091#else /* !HAVE_ASM_SIGCONTEXT_H */
Roland McGrath0cbb4e42008-05-20 01:26:21 +000092#if defined I386 && !defined HAVE_STRUCT_SIGCONTEXT_STRUCT
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093struct sigcontext_struct {
94 unsigned short gs, __gsh;
95 unsigned short fs, __fsh;
96 unsigned short es, __esh;
97 unsigned short ds, __dsh;
98 unsigned long edi;
99 unsigned long esi;
100 unsigned long ebp;
101 unsigned long esp;
102 unsigned long ebx;
103 unsigned long edx;
104 unsigned long ecx;
105 unsigned long eax;
106 unsigned long trapno;
107 unsigned long err;
108 unsigned long eip;
109 unsigned short cs, __csh;
110 unsigned long eflags;
111 unsigned long esp_at_signal;
112 unsigned short ss, __ssh;
113 unsigned long i387;
114 unsigned long oldmask;
115 unsigned long cr2;
116};
117#else /* !I386 */
Roland McGrath587c7b52009-02-11 03:03:28 +0000118#if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000119struct sigcontext
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000120{
121 unsigned long sc_mask;
122 unsigned long sc_usp;
123 unsigned long sc_d0;
124 unsigned long sc_d1;
125 unsigned long sc_a0;
126 unsigned long sc_a1;
127 unsigned short sc_sr;
128 unsigned long sc_pc;
129 unsigned short sc_formatvec;
130};
131#endif /* M68K */
132#endif /* !I386 */
133#endif /* !HAVE_ASM_SIGCONTEXT_H */
134#ifndef NSIG
135#define NSIG 32
136#endif
137#ifdef ARM
138#undef NSIG
139#define NSIG 32
140#endif
141#endif /* LINUX */
142
Roland McGrathee36ce12004-09-04 03:53:10 +0000143const char *const signalent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000144#include "signalent.h"
145};
Roland McGrathee36ce12004-09-04 03:53:10 +0000146const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000147
148#if SUPPORTED_PERSONALITIES >= 2
Roland McGrathee36ce12004-09-04 03:53:10 +0000149const char *const signalent1[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150#include "signalent1.h"
151};
Roland McGrathee36ce12004-09-04 03:53:10 +0000152const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153#endif /* SUPPORTED_PERSONALITIES >= 2 */
154
155#if SUPPORTED_PERSONALITIES >= 3
Roland McGrathee36ce12004-09-04 03:53:10 +0000156const char *const signalent2[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157#include "signalent2.h"
158};
Roland McGrathee36ce12004-09-04 03:53:10 +0000159const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160#endif /* SUPPORTED_PERSONALITIES >= 3 */
161
Roland McGrathee36ce12004-09-04 03:53:10 +0000162const char *const *signalent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163int nsignals;
164
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000165#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166
Roland McGrathd9f816f2004-09-04 03:39:20 +0000167static const struct xlat sigvec_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000168 { SV_ONSTACK, "SV_ONSTACK" },
169 { SV_INTERRUPT, "SV_INTERRUPT" },
170 { SV_RESETHAND, "SV_RESETHAND" },
171 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
172 { 0, NULL },
173};
174
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000175#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176
177#ifdef HAVE_SIGACTION
178
Roland McGrath063ae2d2005-02-02 04:16:54 +0000179#if defined LINUX && (defined I386 || defined X86_64)
Roland McGrath2638cb42002-12-15 23:58:41 +0000180/* The libc headers do not define this constant since it should only be
181 used by the implementation. So wwe define it here. */
182# ifndef SA_RESTORER
183# define SA_RESTORER 0x04000000
184# endif
185#endif
186
Roland McGrathd9f816f2004-09-04 03:39:20 +0000187static const struct xlat sigact_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000188#ifdef SA_RESTORER
189 { SA_RESTORER, "SA_RESTORER" },
190#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191#ifdef SA_STACK
192 { SA_STACK, "SA_STACK" },
193#endif
194#ifdef SA_RESTART
195 { SA_RESTART, "SA_RESTART" },
196#endif
197#ifdef SA_INTERRUPT
198 { SA_INTERRUPT, "SA_INTERRUPT" },
199#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000200#ifdef SA_NODEFER
201 { SA_NODEFER, "SA_NODEFER" },
202#endif
203#if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204 { SA_NOMASK, "SA_NOMASK" },
205#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000206#ifdef SA_RESETHAND
207 { SA_RESETHAND, "SA_RESETHAND" },
208#endif
209#if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000210 { SA_ONESHOT, "SA_ONESHOT" },
211#endif
212#ifdef SA_SIGINFO
213 { SA_SIGINFO, "SA_SIGINFO" },
214#endif
215#ifdef SA_RESETHAND
216 { SA_RESETHAND, "SA_RESETHAND" },
217#endif
218#ifdef SA_ONSTACK
219 { SA_ONSTACK, "SA_ONSTACK" },
220#endif
221#ifdef SA_NODEFER
222 { SA_NODEFER, "SA_NODEFER" },
223#endif
224#ifdef SA_NOCLDSTOP
225 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
226#endif
227#ifdef SA_NOCLDWAIT
228 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
229#endif
230#ifdef _SA_BSDCALL
231 { _SA_BSDCALL, "_SA_BSDCALL" },
232#endif
233 { 0, NULL },
234};
235
Roland McGrathd9f816f2004-09-04 03:39:20 +0000236static const struct xlat sigprocmaskcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000237 { SIG_BLOCK, "SIG_BLOCK" },
238 { SIG_UNBLOCK, "SIG_UNBLOCK" },
239 { SIG_SETMASK, "SIG_SETMASK" },
240#ifdef SIG_SETMASK32
241 { SIG_SETMASK32,"SIG_SETMASK32" },
242#endif
243 { 0, NULL },
244};
245
246#endif /* HAVE_SIGACTION */
247
Nate Sammonsce780fc1999-03-29 23:23:13 +0000248/* Anonymous realtime signals. */
249/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
250 constant. This is what we want. Otherwise, just use SIGRTMIN. */
251#ifdef SIGRTMIN
252#ifndef __SIGRTMIN
253#define __SIGRTMIN SIGRTMIN
254#define __SIGRTMAX SIGRTMAX /* likewise */
255#endif
256#endif
257
Roland McGrathee36ce12004-09-04 03:53:10 +0000258const char *
Nate Sammonsce780fc1999-03-29 23:23:13 +0000259signame(sig)
260int sig;
261{
262 static char buf[30];
Roland McGrathad81dce2005-05-09 07:40:30 +0000263 if (sig >= 0 && sig < nsignals) {
Nate Sammonsce780fc1999-03-29 23:23:13 +0000264 return signalent[sig];
265#ifdef SIGRTMIN
Nate Sammons3080aa41999-03-30 00:16:41 +0000266 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000267 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000268 return buf;
269#endif /* SIGRTMIN */
270 } else {
271 sprintf(buf, "%d", sig);
272 return buf;
273 }
274}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000276#ifndef UNIXWARE
Nate Sammons4a121431999-04-06 01:19:39 +0000277static void
278long_to_sigset(l, s)
279long l;
280sigset_t *s;
281{
282 sigemptyset(s);
283 *(long *)s = l;
284}
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000285#endif
Nate Sammons4a121431999-04-06 01:19:39 +0000286
287static int
288copy_sigset_len(tcp, addr, s, len)
289struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000290long addr;
Nate Sammons4a121431999-04-06 01:19:39 +0000291sigset_t *s;
292int len;
293{
294 if (len > sizeof(*s))
295 len = sizeof(*s);
296 sigemptyset(s);
297 if (umoven(tcp, addr, len, (char *)s) < 0)
298 return -1;
299 return 0;
300}
301
302#ifdef LINUX
303/* Original sigset is unsigned long */
304#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
305#else
306#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
307#endif
308
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000309static const char *
310sprintsigmask(const char *str, sigset_t *mask, int rt)
311/* set might include realtime sigs */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312{
313 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000314 int maxsigs;
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000315 char *format, *s;
Roland McGratha39c5a12002-12-17 05:10:37 +0000316 static char outstr[8 * sizeof(sigset_t) * 8];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000318 strcpy(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319 s = outstr + strlen(outstr);
320 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000321 maxsigs = nsignals;
322#ifdef __SIGRTMAX
323 if (rt)
324 maxsigs = __SIGRTMAX; /* instead */
325#endif
326 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000327 if (sigismember(mask, i) == 1)
328 nsigs++;
329 }
330 if (nsigs >= nsignals * 2 / 3) {
331 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000332 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000333 switch (sigismember(mask, i)) {
334 case 1:
335 sigdelset(mask, i);
336 break;
337 case 0:
338 sigaddset(mask, i);
339 break;
340 }
341 }
342 }
343 format = "%s";
344 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000345 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000346 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000347 /* real-time signals on solaris don't have
348 * signalent entries
349 */
350 if (i < nsignals) {
351 sprintf(s, format, signalent[i] + 3);
352 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000353#ifdef SIGRTMIN
354 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
355 char tsig[40];
356 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
357 sprintf(s, format, tsig);
358 }
359#endif /* SIGRTMIN */
John Hughesbdf48f52001-03-06 15:08:09 +0000360 else {
361 char tsig[32];
362 sprintf(tsig, "%u", i);
363 sprintf(s, format, tsig);
364 }
365 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366 format = " %s";
367 }
368 }
369 *s++ = ']';
370 *s = '\0';
371 return outstr;
372}
373
374static void
Nate Sammons4a121431999-04-06 01:19:39 +0000375printsigmask(mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000377int rt;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378{
Nate Sammons4a121431999-04-06 01:19:39 +0000379 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380}
381
382void
383printsignal(nr)
384int nr;
385{
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +0000386 tprintf("%s", signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387}
388
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000389void
390print_sigset(struct tcb *tcp, long addr, int rt)
391{
392 sigset_t ss;
393
394 if (!addr)
395 tprintf("NULL");
396 else if (copy_sigset(tcp, addr, &ss) < 0)
397 tprintf("%#lx", addr);
398 else
399 printsigmask(&ss, rt);
400}
401
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000402#ifdef LINUX
403
John Hughes58265892001-10-18 15:13:53 +0000404#ifndef ILL_ILLOPC
405#define ILL_ILLOPC 1 /* illegal opcode */
406#define ILL_ILLOPN 2 /* illegal operand */
407#define ILL_ILLADR 3 /* illegal addressing mode */
408#define ILL_ILLTRP 4 /* illegal trap */
409#define ILL_PRVOPC 5 /* privileged opcode */
410#define ILL_PRVREG 6 /* privileged register */
411#define ILL_COPROC 7 /* coprocessor error */
412#define ILL_BADSTK 8 /* internal stack error */
413#define FPE_INTDIV 1 /* integer divide by zero */
414#define FPE_INTOVF 2 /* integer overflow */
415#define FPE_FLTDIV 3 /* floating point divide by zero */
416#define FPE_FLTOVF 4 /* floating point overflow */
417#define FPE_FLTUND 5 /* floating point underflow */
418#define FPE_FLTRES 6 /* floating point inexact result */
419#define FPE_FLTINV 7 /* floating point invalid operation */
420#define FPE_FLTSUB 8 /* subscript out of range */
421#define SEGV_MAPERR 1 /* address not mapped to object */
422#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
423#define BUS_ADRALN 1 /* invalid address alignment */
424#define BUS_ADRERR 2 /* non-existant physical address */
425#define BUS_OBJERR 3 /* object specific hardware error */
426#define TRAP_BRKPT 1 /* process breakpoint */
427#define TRAP_TRACE 2 /* process trace trap */
428#define CLD_EXITED 1 /* child has exited */
429#define CLD_KILLED 2 /* child was killed */
430#define CLD_DUMPED 3 /* child terminated abnormally */
431#define CLD_TRAPPED 4 /* traced child has trapped */
432#define CLD_STOPPED 5 /* child has stopped */
433#define CLD_CONTINUED 6 /* stopped child has continued */
434#define POLL_IN 1 /* data input available */
435#define POLL_OUT 2 /* output buffers available */
436#define POLL_MSG 3 /* input message available */
437#define POLL_ERR 4 /* i/o error */
438#define POLL_PRI 5 /* high priority input available */
439#define POLL_HUP 6 /* device disconnected */
440#define SI_USER 0 /* sent by kill, sigsend, raise */
441#define SI_QUEUE -1 /* sent by sigqueue */
442#define SI_TIMER -2 /* sent by timer expiration */
443#define SI_MESGQ -3 /* sent by real time mesq state change */
444#define SI_ASYNCIO -4 /* sent by AIO completion */
Roland McGrath941b7402003-05-23 00:29:02 +0000445#define SI_SIGIO -5 /* Sent by SIGIO */
446#define SI_TKILL -6 /* Sent by tkill */
John Hughes58265892001-10-18 15:13:53 +0000447#endif
448
449#if __GLIBC_MINOR__ < 1
450/* Type for data associated with a signal. */
451typedef union sigval
452{
453 int sival_int;
454 void *sival_ptr;
455} sigval_t;
456
457# define __SI_MAX_SIZE 128
458# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
459
460typedef struct siginfo
461{
462 int si_signo; /* Signal number. */
463 int si_errno; /* If non-zero, an errno value associated with
464 this signal, as defined in <errno.h>. */
465 int si_code; /* Signal code. */
466
467 union
468 {
469 int _pad[__SI_PAD_SIZE];
470
471 /* kill(). */
472 struct
473 {
474 __pid_t si_pid; /* Sending process ID. */
475 __uid_t si_uid; /* Real user ID of sending process. */
476 } _kill;
477
478 /* POSIX.1b timers. */
479 struct
480 {
481 unsigned int _timer1;
482 unsigned int _timer2;
483 } _timer;
484
485 /* POSIX.1b signals. */
486 struct
487 {
488 __pid_t si_pid; /* Sending process ID. */
489 __uid_t si_uid; /* Real user ID of sending process. */
490 sigval_t si_sigval; /* Signal value. */
491 } _rt;
492
493 /* SIGCHLD. */
494 struct
495 {
496 __pid_t si_pid; /* Which child. */
497 int si_status; /* Exit value or signal. */
498 __clock_t si_utime;
499 __clock_t si_stime;
500 } _sigchld;
501
502 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
503 struct
504 {
505 void *si_addr; /* Faulting insn/memory ref. */
506 } _sigfault;
507
508 /* SIGPOLL. */
509 struct
510 {
511 int si_band; /* Band event for SIGPOLL. */
512 int si_fd;
513 } _sigpoll;
514 } _sifields;
515} siginfo_t;
516
517#define si_pid _sifields._kill.si_pid
518#define si_uid _sifields._kill.si_uid
519#define si_status _sifields._sigchld.si_status
520#define si_utime _sifields._sigchld.si_utime
521#define si_stime _sifields._sigchld.si_stime
522#define si_value _sifields._rt.si_sigval
523#define si_int _sifields._rt.si_sigval.sival_int
524#define si_ptr _sifields._rt.si_sigval.sival_ptr
525#define si_addr _sifields._sigfault.si_addr
526#define si_band _sifields._sigpoll.si_band
527#define si_fd _sifields._sigpoll.si_fd
528
529#endif
530
531#endif
532
533#if defined (SVR4) || defined (LINUX)
534
Roland McGrathd9f816f2004-09-04 03:39:20 +0000535static const struct xlat siginfo_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000536#ifdef SI_NOINFO
537 { SI_NOINFO, "SI_NOINFO" },
538#endif
539#ifdef SI_USER
540 { SI_USER, "SI_USER" },
541#endif
542#ifdef SI_LWP
543 { SI_LWP, "SI_LWP" },
544#endif
545#ifdef SI_QUEUE
546 { SI_QUEUE, "SI_QUEUE" },
547#endif
548#ifdef SI_TIMER
549 { SI_TIMER, "SI_TIMER" },
550#endif
551#ifdef SI_ASYNCIO
552 { SI_ASYNCIO, "SI_ASYNCIO" },
553#endif
554#ifdef SI_MESGQ
555 { SI_MESGQ, "SI_MESGQ" },
556#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000557#ifdef SI_SIGIO
558 { SI_SIGIO, "SI_SIGIO" },
559#endif
560#ifdef SI_TKILL
561 { SI_TKILL, "SI_TKILL" },
562#endif
John Hughes58265892001-10-18 15:13:53 +0000563 { 0, NULL },
564};
565
Roland McGrathd9f816f2004-09-04 03:39:20 +0000566static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000567 { ILL_ILLOPC, "ILL_ILLOPC" },
568 { ILL_ILLOPN, "ILL_ILLOPN" },
569 { ILL_ILLADR, "ILL_ILLADR" },
570 { ILL_ILLTRP, "ILL_ILLTRP" },
571 { ILL_PRVOPC, "ILL_PRVOPC" },
572 { ILL_PRVREG, "ILL_PRVREG" },
573 { ILL_COPROC, "ILL_COPROC" },
574 { ILL_BADSTK, "ILL_BADSTK" },
575 { 0, NULL },
576};
577
Roland McGrathd9f816f2004-09-04 03:39:20 +0000578static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000579 { FPE_INTDIV, "FPE_INTDIV" },
580 { FPE_INTOVF, "FPE_INTOVF" },
581 { FPE_FLTDIV, "FPE_FLTDIV" },
582 { FPE_FLTOVF, "FPE_FLTOVF" },
583 { FPE_FLTUND, "FPE_FLTUND" },
584 { FPE_FLTRES, "FPE_FLTRES" },
585 { FPE_FLTINV, "FPE_FLTINV" },
586 { FPE_FLTSUB, "FPE_FLTSUB" },
587 { 0, NULL },
588};
589
Roland McGrathd9f816f2004-09-04 03:39:20 +0000590static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000591 { TRAP_BRKPT, "TRAP_BRKPT" },
592 { TRAP_TRACE, "TRAP_TRACE" },
593 { 0, NULL },
594};
595
Roland McGrathd9f816f2004-09-04 03:39:20 +0000596static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000597 { CLD_EXITED, "CLD_EXITED" },
598 { CLD_KILLED, "CLD_KILLED" },
599 { CLD_DUMPED, "CLD_DUMPED" },
600 { CLD_TRAPPED, "CLD_TRAPPED" },
601 { CLD_STOPPED, "CLD_STOPPED" },
602 { CLD_CONTINUED,"CLD_CONTINUED" },
603 { 0, NULL },
604};
605
Roland McGrathd9f816f2004-09-04 03:39:20 +0000606static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000607 { POLL_IN, "POLL_IN" },
608 { POLL_OUT, "POLL_OUT" },
609 { POLL_MSG, "POLL_MSG" },
610 { POLL_ERR, "POLL_ERR" },
611 { POLL_PRI, "POLL_PRI" },
612 { POLL_HUP, "POLL_HUP" },
613 { 0, NULL },
614};
615
Roland McGrathd9f816f2004-09-04 03:39:20 +0000616static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000617#ifdef PROF_SIG
618 { PROF_SIG, "PROF_SIG" },
619#endif
620 { 0, NULL },
621};
622
623#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000624static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000625#ifdef EMT_TAGOVF
626 { EMT_TAGOVF, "EMT_TAGOVF" },
627#endif
628 { 0, NULL },
629};
630#endif
631
Roland McGrathd9f816f2004-09-04 03:39:20 +0000632static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000633 { SEGV_MAPERR, "SEGV_MAPERR" },
634 { SEGV_ACCERR, "SEGV_ACCERR" },
635 { 0, NULL },
636};
637
Roland McGrathd9f816f2004-09-04 03:39:20 +0000638static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000639 { BUS_ADRALN, "BUS_ADRALN" },
640 { BUS_ADRERR, "BUS_ADRERR" },
641 { BUS_OBJERR, "BUS_OBJERR" },
642 { 0, NULL },
643};
644
645void
646printsiginfo(sip, verbose)
647siginfo_t *sip;
648int verbose;
649{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000650 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000651
652 if (sip->si_signo == 0) {
653 tprintf ("{}");
654 return;
655 }
656 tprintf("{si_signo=");
657 printsignal(sip->si_signo);
658 code = xlookup(siginfo_codes, sip->si_code);
659 if (!code) {
660 switch (sip->si_signo) {
661 case SIGTRAP:
662 code = xlookup(sigtrap_codes, sip->si_code);
663 break;
664 case SIGCHLD:
665 code = xlookup(sigchld_codes, sip->si_code);
666 break;
667 case SIGPOLL:
668 code = xlookup(sigpoll_codes, sip->si_code);
669 break;
670 case SIGPROF:
671 code = xlookup(sigprof_codes, sip->si_code);
672 break;
673 case SIGILL:
674 code = xlookup(sigill_codes, sip->si_code);
675 break;
676#ifdef SIGEMT
677 case SIGEMT:
678 code = xlookup(sigemt_codes, sip->si_code);
679 break;
680#endif
681 case SIGFPE:
682 code = xlookup(sigfpe_codes, sip->si_code);
683 break;
684 case SIGSEGV:
685 code = xlookup(sigsegv_codes, sip->si_code);
686 break;
687 case SIGBUS:
688 code = xlookup(sigbus_codes, sip->si_code);
689 break;
690 }
691 }
692 if (code)
693 tprintf(", si_code=%s", code);
694 else
695 tprintf(", si_code=%#x", sip->si_code);
696#ifdef SI_NOINFO
697 if (sip->si_code != SI_NOINFO)
698#endif
699 {
700 if (sip->si_errno) {
701 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
702 tprintf(", si_errno=%d", sip->si_errno);
703 else
704 tprintf(", si_errno=%s",
705 errnoent[sip->si_errno]);
706 }
707#ifdef SI_FROMUSER
708 if (SI_FROMUSER(sip)) {
709 tprintf(", si_pid=%ld, si_uid=%ld",
710 sip->si_pid, sip->si_uid);
711#ifdef SI_QUEUE
712 switch (sip->si_code) {
713 case SI_QUEUE:
714#ifdef SI_TIMER
715 case SI_TIMER:
716#endif /* SI_QUEUE */
717 case SI_ASYNCIO:
718#ifdef SI_MESGQ
719 case SI_MESGQ:
720#endif /* SI_MESGQ */
721 tprintf(", si_value=%d",
722 sip->si_value.sival_int);
723 break;
724 }
725#endif /* SI_QUEUE */
726 }
727 else
728#endif /* SI_FROMUSER */
729 {
730 switch (sip->si_signo) {
731 case SIGCHLD:
732 tprintf(", si_pid=%ld, si_status=",
733 (long) sip->si_pid);
734 if (sip->si_code == CLD_EXITED)
735 tprintf("%d", sip->si_status);
736 else
737 printsignal(sip->si_status);
738#if LINUX
739 if (!verbose)
740 tprintf(", ...");
741 else
742 tprintf(", si_utime=%lu, si_stime=%lu",
743 sip->si_utime,
744 sip->si_stime);
745#endif
746 break;
747 case SIGILL: case SIGFPE:
748 case SIGSEGV: case SIGBUS:
749 tprintf(", si_addr=%#lx",
750 (unsigned long) sip->si_addr);
751 break;
752 case SIGPOLL:
753 switch (sip->si_code) {
754 case POLL_IN: case POLL_OUT: case POLL_MSG:
755 tprintf(", si_band=%ld",
756 (long) sip->si_band);
757 break;
758 }
759 break;
760#ifdef LINUX
761 default:
762 tprintf(", si_pid=%lu, si_uid=%lu, ",
763 (unsigned long) sip->si_pid,
764 (unsigned long) sip->si_uid);
765 if (!verbose)
766 tprintf("...");
767 else {
768 tprintf("si_value={int=%u, ptr=%#lx}",
769 sip->si_int,
770 (unsigned long) sip->si_ptr);
771 }
772#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000773
John Hughes58265892001-10-18 15:13:53 +0000774 }
775 }
776 }
777 tprintf("}");
778}
779
780#endif /* SVR4 || LINUX */
781
782#ifdef LINUX
783
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000784static void
785parse_sigset_t (const char *str, sigset_t *set)
786{
Roland McGrathc38feca2003-10-01 07:50:28 +0000787 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000788 unsigned int digit;
789 int i;
790
791 sigemptyset(set);
792
Roland McGrathc38feca2003-10-01 07:50:28 +0000793 p = strchr(str, '\n');
794 if (p == NULL)
795 p = strchr(str, '\0');
796 for (i = 0; p-- > str; i += 4) {
797 if (*p >= '0' && *p <= '9')
798 digit = *p - '0';
799 else if (*p >= 'a' && *p <= 'f')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000800 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000801 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000802 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000803 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000804 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000805 if (digit & 1)
806 sigaddset(set, i + 1);
807 if (digit & 2)
808 sigaddset(set, i + 2);
809 if (digit & 4)
810 sigaddset(set, i + 3);
811 if (digit & 8)
812 sigaddset(set, i + 4);
813 }
814}
815
816#endif
817
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000818/*
819 * Check process TCP for the disposition of signal SIG.
820 * Return 1 if the process would somehow manage to survive signal SIG,
821 * else return 0. This routine will never be called with SIGKILL.
822 */
823int
824sigishandled(tcp, sig)
825struct tcb *tcp;
826int sig;
827{
828#ifdef LINUX
829 int sfd;
830 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000831 char buf[2048];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000832 char *s;
833 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000834 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000835#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000836#ifdef SVR4
837 /*
838 * Since procfs doesn't interfere with wait I think it is safe
839 * to punt on this question. If not, the information is there.
840 */
841 return 1;
842#else /* !SVR4 */
843 switch (sig) {
844 case SIGCONT:
845 case SIGSTOP:
846 case SIGTSTP:
847 case SIGTTIN:
848 case SIGTTOU:
849 case SIGCHLD:
850 case SIGIO:
851#if defined(SIGURG) && SIGURG != SIGIO
852 case SIGURG:
853#endif
854 case SIGWINCH:
855 /* Gloria Gaynor says ... */
856 return 1;
857 default:
858 break;
859 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000860#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000861#ifdef LINUX
862
863 /* This is incredibly costly but it's worth it. */
864 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
865 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
866 doesn't handle real-time signals). */
867 sprintf(sname, "/proc/%d/status", tcp->pid);
868 if ((sfd = open(sname, O_RDONLY)) == -1) {
869 perror(sname);
870 return 1;
871 }
872 i = read(sfd, buf, sizeof(buf));
873 buf[i] = '\0';
874 close(sfd);
875 /*
876 * Skip the extraneous fields. We need to skip
877 * command name has any spaces in it. So be it.
878 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000879 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000880 if (!s)
881 {
882 fprintf(stderr, "/proc/pid/status format error\n");
883 return 1;
884 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000885 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000886
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000887 s = strstr(buf, "SigCgt:\t");
888 if (!s)
889 {
890 fprintf(stderr, "/proc/pid/status format error\n");
891 return 1;
892 }
893 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000894
895#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000896 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
897 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000898#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000899 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000900 return 1;
901#endif /* LINUX */
902
903#ifdef SUNOS4
904 void (*u_signal)();
905
Denys Vlasenko932fc7d2008-12-16 18:18:40 +0000906 if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal),
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000907 (long *) &u_signal) < 0) {
908 return 0;
909 }
910 if (u_signal != SIG_DFL)
911 return 1;
912#endif /* SUNOS4 */
913
914 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000915}
916
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000917#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000918
919int
920sys_sigvec(tcp)
921struct tcb *tcp;
922{
923 struct sigvec sv;
924 long addr;
925
926 if (entering(tcp)) {
927 printsignal(tcp->u_arg[0]);
928 tprintf(", ");
929 addr = tcp->u_arg[1];
930 } else {
931 addr = tcp->u_arg[2];
932 }
933 if (addr == 0)
934 tprintf("NULL");
935 else if (!verbose(tcp))
936 tprintf("%#lx", addr);
937 else if (umove(tcp, addr, &sv) < 0)
938 tprintf("{...}");
939 else {
940 switch ((int) sv.sv_handler) {
941 case (int) SIG_ERR:
942 tprintf("{SIG_ERR}");
943 break;
944 case (int) SIG_DFL:
945 tprintf("{SIG_DFL}");
946 break;
947 case (int) SIG_IGN:
948 if (tcp->u_arg[0] == SIGTRAP) {
949 tcp->flags |= TCB_SIGTRAPPED;
950 kill(tcp->pid, SIGSTOP);
951 }
952 tprintf("{SIG_IGN}");
953 break;
954 case (int) SIG_HOLD:
955 if (tcp->u_arg[0] == SIGTRAP) {
956 tcp->flags |= TCB_SIGTRAPPED;
957 kill(tcp->pid, SIGSTOP);
958 }
959 tprintf("SIG_HOLD");
960 break;
961 default:
962 if (tcp->u_arg[0] == SIGTRAP) {
963 tcp->flags |= TCB_SIGTRAPPED;
964 kill(tcp->pid, SIGSTOP);
965 }
966 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000967 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000969 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000970 tprintf("}");
971 }
972 }
973 if (entering(tcp))
974 tprintf(", ");
975 return 0;
976}
977
978int
979sys_sigpause(tcp)
980struct tcb *tcp;
981{
982 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000983 sigset_t sigm;
984 long_to_sigset(tcp->u_arg[0], &sigm);
985 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986 }
987 return 0;
988}
989
990int
991sys_sigstack(tcp)
992struct tcb *tcp;
993{
994 struct sigstack ss;
995 long addr;
996
997 if (entering(tcp))
998 addr = tcp->u_arg[0];
999 else
1000 addr = tcp->u_arg[1];
1001 if (addr == 0)
1002 tprintf("NULL");
1003 else if (umove(tcp, addr, &ss) < 0)
1004 tprintf("%#lx", addr);
1005 else {
1006 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1007 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1008 }
1009 if (entering(tcp))
1010 tprintf(", ");
1011 return 0;
1012}
1013
1014int
1015sys_sigcleanup(tcp)
1016struct tcb *tcp;
1017{
1018 return 0;
1019}
1020
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001021#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001022
1023#ifndef SVR4
1024
1025int
1026sys_sigsetmask(tcp)
1027struct tcb *tcp;
1028{
1029 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001030 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001031 long_to_sigset(tcp->u_arg[0], &sigm);
1032 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001033#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1035 /* Mark attempt to block SIGTRAP */
1036 tcp->flags |= TCB_SIGTRAPPED;
1037 /* Send unblockable signal */
1038 kill(tcp->pid, SIGSTOP);
1039 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001040#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041 }
1042 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001044 long_to_sigset(tcp->u_rval, &sigm);
1045 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001046
1047 return RVAL_HEX | RVAL_STR;
1048 }
1049 return 0;
1050}
1051
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001052#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001053int
1054sys_sigblock(tcp)
1055struct tcb *tcp;
1056{
1057 return sys_sigsetmask(tcp);
1058}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001059#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001060
1061#endif /* !SVR4 */
1062
1063#ifdef HAVE_SIGACTION
1064
1065#ifdef LINUX
1066struct old_sigaction {
1067 __sighandler_t __sa_handler;
1068 unsigned long sa_mask;
1069 unsigned long sa_flags;
1070 void (*sa_restorer)(void);
1071};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001072#define SA_HANDLER __sa_handler
1073#endif /* LINUX */
1074
Roland McGratha39c5a12002-12-17 05:10:37 +00001075#ifndef SA_HANDLER
1076#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077#endif
1078
1079int
1080sys_sigaction(tcp)
1081struct tcb *tcp;
1082{
1083 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001084#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001085 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001086 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001087#else
1088 struct sigaction sa;
1089#endif
1090
1091
1092 if (entering(tcp)) {
1093 printsignal(tcp->u_arg[0]);
1094 tprintf(", ");
1095 addr = tcp->u_arg[1];
1096 } else
1097 addr = tcp->u_arg[2];
1098 if (addr == 0)
1099 tprintf("NULL");
1100 else if (!verbose(tcp))
1101 tprintf("%#lx", addr);
1102 else if (umove(tcp, addr, &sa) < 0)
1103 tprintf("{...}");
1104 else {
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001105 /* Architectures using function pointers, like
1106 * hppa, may need to manipulate the function pointer
1107 * to compute the result of a comparison. However,
1108 * the SA_HANDLER function pointer exists only in
1109 * the address space of the traced process, and can't
1110 * be manipulated by strace. In order to prevent the
1111 * compiler from generating code to manipulate
1112 * SA_HANDLER we cast the function pointers to long. */
1113 if ((long)sa.SA_HANDLER == (long)SIG_ERR)
Roland McGrath5f206812008-08-20 01:59:40 +00001114 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001115 else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
Roland McGrath5f206812008-08-20 01:59:40 +00001116 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001117 else if ((long)sa.SA_HANDLER == (long)SIG_IGN) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001118#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001119 if (tcp->u_arg[0] == SIGTRAP) {
1120 tcp->flags |= TCB_SIGTRAPPED;
1121 kill(tcp->pid, SIGSTOP);
1122 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001123#endif /* !USE_PROCFS */
Roland McGrath5f206812008-08-20 01:59:40 +00001124 tprintf("{SIG_IGN, ");
1125 }
1126 else {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001127#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001128 if (tcp->u_arg[0] == SIGTRAP) {
1129 tcp->flags |= TCB_SIGTRAPPED;
1130 kill(tcp->pid, SIGSTOP);
1131 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001132#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001133 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001134#ifndef LINUX
1135 printsigmask (&sa.sa_mask, 0);
1136#else
Nate Sammons4a121431999-04-06 01:19:39 +00001137 long_to_sigset(sa.sa_mask, &sigset);
1138 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001139#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001140 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001141 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001142#ifdef SA_RESTORER
1143 if (sa.sa_flags & SA_RESTORER)
1144 tprintf(", %p", sa.sa_restorer);
1145#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001146 tprintf("}");
1147 }
1148 }
1149 if (entering(tcp))
1150 tprintf(", ");
1151#ifdef LINUX
1152 else
1153 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1154#endif
1155 return 0;
1156}
1157
1158int
1159sys_signal(tcp)
1160struct tcb *tcp;
1161{
1162 if (entering(tcp)) {
1163 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001164 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001165 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001166 case (long) SIG_ERR:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001167 tprintf("SIG_ERR");
1168 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001169 case (long) SIG_DFL:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001170 tprintf("SIG_DFL");
1171 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001172 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001173#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001174 if (tcp->u_arg[0] == SIGTRAP) {
1175 tcp->flags |= TCB_SIGTRAPPED;
1176 kill(tcp->pid, SIGSTOP);
1177 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001178#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001179 tprintf("SIG_IGN");
1180 break;
1181 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001182#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001183 if (tcp->u_arg[0] == SIGTRAP) {
1184 tcp->flags |= TCB_SIGTRAPPED;
1185 kill(tcp->pid, SIGSTOP);
1186 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001187#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001188 tprintf("%#lx", tcp->u_arg[1]);
1189 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001190 return 0;
1191 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001192 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001193 switch (tcp->u_rval) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001194 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001195 tcp->auxstr = "SIG_ERR"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001196 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001197 tcp->auxstr = "SIG_DFL"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001198 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001199 tcp->auxstr = "SIG_IGN"; break;
1200 default:
1201 tcp->auxstr = NULL;
1202 }
1203 return RVAL_HEX | RVAL_STR;
1204 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001205 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001206}
1207
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001208#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001209int
1210sys_sighold(tcp)
1211struct tcb *tcp;
1212{
1213 if (entering(tcp)) {
1214 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001215 }
1216 return 0;
1217}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001218#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001219
1220#endif /* HAVE_SIGACTION */
1221
1222#ifdef LINUX
1223
1224int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001225sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001226{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001227#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001228 struct pt_regs regs;
1229 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001230
Roland McGrath0f87c492003-06-03 23:29:04 +00001231 if (entering(tcp)) {
1232 tcp->u_arg[0] = 0;
1233
1234 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1235 return 0;
1236
1237 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1238 return 0;
1239
1240 tcp->u_arg[0] = 1;
1241 tcp->u_arg[1] = sc.oldmask;
1242 } else {
1243 sigset_t sigm;
1244 long_to_sigset(tcp->u_arg[1], &sigm);
1245 tcp->u_rval = tcp->u_error = 0;
1246 if (tcp->u_arg[0] == 0)
1247 return 0;
1248 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1249 return RVAL_NONE | RVAL_STR;
1250 }
1251 return 0;
1252#elif defined(S390) || defined(S390X)
1253 long usp;
1254 struct sigcontext_struct sc;
1255
1256 if (entering(tcp)) {
1257 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001258 if (upeek(tcp,PT_GPR15,&usp)<0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001259 return 0;
1260 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1261 return 0;
1262 tcp->u_arg[0] = 1;
1263 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1264 } else {
1265 tcp->u_rval = tcp->u_error = 0;
1266 if (tcp->u_arg[0] == 0)
1267 return 0;
1268 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1269 return RVAL_NONE | RVAL_STR;
1270 }
1271 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001272#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001273 long esp;
1274 struct sigcontext_struct sc;
1275
1276 if (entering(tcp)) {
1277 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001278 if (upeek(tcp, 4*UESP, &esp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001279 return 0;
1280 if (umove(tcp, esp, &sc) < 0)
1281 return 0;
1282 tcp->u_arg[0] = 1;
1283 tcp->u_arg[1] = sc.oldmask;
1284 }
1285 else {
1286 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001287 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001288 tcp->u_rval = tcp->u_error = 0;
1289 if (tcp->u_arg[0] == 0)
1290 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001291 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 return RVAL_NONE | RVAL_STR;
1293 }
1294 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001295#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001296 struct sigcontext sc;
1297 long sp;
1298
1299 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001300 /* offset of sigcontext in the kernel's sigframe structure: */
1301# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001302 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001303 if (upeek(tcp, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001304 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001305 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001306 return 0;
1307 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001308 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001309 }
1310 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001311 sigset_t sigm;
1312
1313 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001314 tcp->u_rval = tcp->u_error = 0;
1315 if (tcp->u_arg[0] == 0)
1316 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001317 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001318 return RVAL_NONE | RVAL_STR;
1319 }
1320 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001321#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +00001322 long esp;
1323 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001324
Roland McGrath0f87c492003-06-03 23:29:04 +00001325 if (entering(tcp)) {
1326 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001327 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001328 return 0;
1329 if (umove(tcp, esp, &sc) < 0)
1330 return 0;
1331 tcp->u_arg[0] = 1;
1332 tcp->u_arg[1] = sc.oldmask;
1333 }
1334 else {
1335 sigset_t sigm;
1336 long_to_sigset(tcp->u_arg[1], &sigm);
1337 tcp->u_rval = tcp->u_error = 0;
1338 if (tcp->u_arg[0] == 0)
1339 return 0;
1340 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1341 return RVAL_NONE | RVAL_STR;
1342 }
1343 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001344#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001345 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001346 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001347
1348 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001349 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001350 if (upeek(tcp, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001351 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001352 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001353 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001354 tcp->u_arg[0] = 1;
1355 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001356 }
1357 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001358 sigset_t sigm;
1359 long_to_sigset(tcp->u_arg[1], &sigm);
1360 tcp->u_rval = tcp->u_error = 0;
1361 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001362 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001363 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1364 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001365 }
1366 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001367#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001368 long fp;
1369 struct sigcontext_struct sc;
1370
1371 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001372 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001373 if (upeek(tcp, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001374 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001375 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001376 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001377 tcp->u_arg[0] = 1;
1378 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001379 }
1380 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001381 sigset_t sigm;
1382 long_to_sigset(tcp->u_arg[1], &sigm);
1383 tcp->u_rval = tcp->u_error = 0;
1384 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001386 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1387 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001388 }
1389 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001390#elif defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001391 long i1;
Mike Frysinger8566c502009-10-12 11:05:14 -04001392 struct pt_regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 m_siginfo_t si;
1394
Roland McGratheb9e2e82009-06-02 16:49:22 -07001395 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1396 perror("sigreturn: PTRACE_GETREGS ");
Roland McGrath0f87c492003-06-03 23:29:04 +00001397 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001398 }
Roland McGratheb9e2e82009-06-02 16:49:22 -07001399 if(entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001400 tcp->u_arg[0] = 0;
Mike Frysinger8566c502009-10-12 11:05:14 -04001401 i1 = regs.u_regs[U_REG_O1];
Roland McGratheb9e2e82009-06-02 16:49:22 -07001402 if(umove(tcp, i1, &si) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001403 perror("sigreturn: umove ");
1404 return 0;
1405 }
1406 tcp->u_arg[0] = 1;
1407 tcp->u_arg[1] = si.si_mask;
1408 } else {
1409 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001410 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001411 tcp->u_rval = tcp->u_error = 0;
1412 if(tcp->u_arg[0] == 0)
1413 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001414 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001415 return RVAL_NONE | RVAL_STR;
1416 }
1417 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001418#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001419 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1420 sigreturn. */
1421 long sp;
1422 struct ucontext uc;
1423
1424 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001425 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001426 if (upeek(tcp, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001427 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001428 /* There are six words followed by a 128-byte siginfo. */
1429 sp = sp + 6 * 4 + 128;
1430 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001431 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001432 tcp->u_arg[0] = 1;
1433 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1434 } else {
1435 sigset_t sigm;
1436 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001437 tcp->u_rval = tcp->u_error = 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001438 if(tcp->u_arg[0] == 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001439 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001440 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1441 return RVAL_NONE | RVAL_STR;
1442 }
1443 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001444#elif defined(MIPS)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001445 long sp;
Roland McGrath576b7842007-11-04 00:00:00 +00001446 struct pt_regs regs;
1447 m_siginfo_t si;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001448
Roland McGrath576b7842007-11-04 00:00:00 +00001449 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1450 perror("sigreturn: PTRACE_GETREGS ");
1451 return 0;
1452 }
Wichert Akkermanf90da011999-10-31 21:15:38 +00001453 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001454 tcp->u_arg[0] = 0;
Roland McGrath576b7842007-11-04 00:00:00 +00001455 sp = regs.regs[29];
1456 if (umove(tcp, sp, &si) < 0)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001457 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001458 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001459 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001460 sigset_t sigm;
1461 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001462 tcp->u_rval = tcp->u_error = 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001463 if(tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001464 return 0;
1465 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001466 return RVAL_NONE | RVAL_STR;
1467 }
1468 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001469#elif defined(CRISV10) || defined(CRISV32)
1470 struct sigcontext sc;
1471
1472 if (entering(tcp)) {
1473 long regs[PT_MAX+1];
1474
1475 tcp->u_arg[0] = 0;
1476
1477 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1478 perror("sigreturn: PTRACE_GETREGS");
1479 return 0;
1480 }
1481 if (umove(tcp, regs[PT_USP], &sc) < 0)
1482 return 0;
1483 tcp->u_arg[0] = 1;
1484 tcp->u_arg[1] = sc.oldmask;
1485 } else {
1486 sigset_t sigm;
1487 long_to_sigset(tcp->u_arg[1], &sigm);
1488 tcp->u_rval = tcp->u_error = 0;
1489
1490 if (tcp->u_arg[0] == 0)
1491 return 0;
1492 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1493 return RVAL_NONE | RVAL_STR;
1494 }
1495 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001496#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001497#warning No sys_sigreturn() for this architecture
1498#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001499 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001500#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001501}
1502
1503int
1504sys_siggetmask(tcp)
1505struct tcb *tcp;
1506{
1507 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001508 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001509 long_to_sigset(tcp->u_rval, &sigm);
1510 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001511 }
1512 return RVAL_HEX | RVAL_STR;
1513}
1514
1515int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001516sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001517{
1518 if (entering(tcp)) {
1519 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001520 long_to_sigset(tcp->u_arg[2], &sigm);
Nate Sammons4a121431999-04-06 01:19:39 +00001521 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001522 }
1523 return 0;
1524}
1525
1526#endif /* LINUX */
1527
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001528#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001529
1530int
1531sys_sigsuspend(tcp)
1532struct tcb *tcp;
1533{
1534 sigset_t sigset;
1535
1536 if (entering(tcp)) {
1537 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1538 tprintf("[?]");
1539 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001540 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001541 }
1542 return 0;
1543}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001544#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001545static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001546 { UC_SIGMASK, "UC_SIGMASK" },
1547 { UC_STACK, "UC_STACK" },
1548 { UC_CPU, "UC_CPU" },
1549#ifdef UC_FPU
1550 { UC_FPU, "UC_FPU" },
1551#endif
1552#ifdef UC_INTR
1553 { UC_INTR, "UC_INTR" },
1554#endif
1555 { 0, NULL },
1556};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001557#endif /* !FREEBSD */
1558#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001559
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001560#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001561#if defined LINUX && !defined SS_ONSTACK
1562#define SS_ONSTACK 1
1563#define SS_DISABLE 2
1564#if __GLIBC_MINOR__ == 0
1565typedef struct
1566{
1567 __ptr_t ss_sp;
1568 int ss_flags;
1569 size_t ss_size;
1570} stack_t;
1571#endif
1572#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001573#ifdef FREEBSD
1574#define stack_t struct sigaltstack
1575#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576
Roland McGrathd9f816f2004-09-04 03:39:20 +00001577static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001578 { SS_ONSTACK, "SS_ONSTACK" },
1579 { SS_DISABLE, "SS_DISABLE" },
1580 { 0, NULL },
1581};
1582#endif
1583
1584#ifdef SVR4
1585static void
1586printcontext(tcp, ucp)
1587struct tcb *tcp;
1588ucontext_t *ucp;
1589{
1590 tprintf("{");
1591 if (!abbrev(tcp)) {
1592 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001593 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001594 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1595 }
1596 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001597 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001598 if (!abbrev(tcp)) {
1599 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1600 (unsigned long) ucp->uc_stack.ss_sp,
1601 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001602 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603 tprintf("}");
1604 }
1605 tprintf(", ...}");
1606}
1607
1608int
1609sys_getcontext(tcp)
1610struct tcb *tcp;
1611{
1612 ucontext_t uc;
1613
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001614 if (exiting(tcp)) {
1615 if (tcp->u_error)
1616 tprintf("%#lx", tcp->u_arg[0]);
1617 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001618 tprintf("NULL");
1619 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1620 tprintf("{...}");
1621 else
1622 printcontext(tcp, &uc);
1623 }
1624 return 0;
1625}
1626
1627int
1628sys_setcontext(tcp)
1629struct tcb *tcp;
1630{
1631 ucontext_t uc;
1632
1633 if (entering(tcp)) {
1634 if (!tcp->u_arg[0])
1635 tprintf("NULL");
1636 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1637 tprintf("{...}");
1638 else
1639 printcontext(tcp, &uc);
1640 }
1641 else {
1642 tcp->u_rval = tcp->u_error = 0;
1643 if (tcp->u_arg[0] == 0)
1644 return 0;
1645 return RVAL_NONE;
1646 }
1647 return 0;
1648}
1649
1650#endif /* SVR4 */
1651
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001652#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001653
1654static int
1655print_stack_t(tcp, addr)
1656struct tcb *tcp;
1657unsigned long addr;
1658{
1659 stack_t ss;
1660 if (umove(tcp, addr, &ss) < 0)
1661 return -1;
1662 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001663 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001664 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1665 return 0;
1666}
1667
1668int
1669sys_sigaltstack(tcp)
1670 struct tcb *tcp;
1671{
1672 if (entering(tcp)) {
1673 if (tcp->u_arg[0] == 0)
1674 tprintf("NULL");
1675 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1676 return -1;
1677 }
1678 else {
1679 tprintf(", ");
1680 if (tcp->u_arg[1] == 0)
1681 tprintf("NULL");
1682 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1683 return -1;
1684 }
1685 return 0;
1686}
1687#endif
1688
1689#ifdef HAVE_SIGACTION
1690
1691int
1692sys_sigprocmask(tcp)
1693struct tcb *tcp;
1694{
1695#ifdef ALPHA
1696 if (entering(tcp)) {
1697 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1698 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001699 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001700 }
1701 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001702 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001703 return RVAL_HEX | RVAL_STR;
1704 }
1705#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001706 if (entering(tcp)) {
1707#ifdef SVR4
1708 if (tcp->u_arg[0] == 0)
1709 tprintf("0");
1710 else
1711#endif /* SVR4 */
1712 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1713 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001714 print_sigset(tcp, tcp->u_arg[1], 0);
1715 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001716 }
1717 else {
1718 if (!tcp->u_arg[2])
1719 tprintf("NULL");
1720 else if (syserror(tcp))
1721 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001722 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001723 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001724 }
1725#endif /* !ALPHA */
1726 return 0;
1727}
1728
1729#endif /* HAVE_SIGACTION */
1730
1731int
1732sys_kill(tcp)
1733struct tcb *tcp;
1734{
1735 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001736 /*
1737 * Sign-extend a 32-bit value when that's what it is.
1738 */
1739 long pid = tcp->u_arg[0];
1740 if (personality_wordsize[current_personality] < sizeof pid)
1741 pid = (long) (int) pid;
1742 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001743 }
1744 return 0;
1745}
1746
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001747#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001748int
1749sys_killpg(tcp)
1750struct tcb *tcp;
1751{
1752 return sys_kill(tcp);
1753}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001754#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001755
Roland McGrath8ffc3522003-07-09 09:47:49 +00001756#ifdef LINUX
1757int
1758sys_tgkill(tcp)
1759 struct tcb *tcp;
1760{
1761 if (entering(tcp)) {
1762 tprintf("%ld, %ld, %s",
1763 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1764 }
1765 return 0;
1766}
1767#endif
1768
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001769int
1770sys_sigpending(tcp)
1771struct tcb *tcp;
1772{
1773 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001774
1775 if (exiting(tcp)) {
1776 if (syserror(tcp))
1777 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001778 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001779 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001780 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001781 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001782 }
1783 return 0;
1784}
1785
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001786#ifdef SVR4
John Hughes42162082001-10-18 14:48:26 +00001787int sys_sigwait(tcp)
1788struct tcb *tcp;
1789{
1790 sigset_t sigset;
1791
1792 if (entering(tcp)) {
1793 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1794 tprintf("[?]");
1795 else
1796 printsigmask(&sigset, 0);
1797 }
1798 else {
1799 if (!syserror(tcp)) {
1800 tcp->auxstr = signalent[tcp->u_rval];
1801 return RVAL_DECIMAL | RVAL_STR;
1802 }
1803 }
1804 return 0;
1805}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001806#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001807
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001808#ifdef LINUX
1809
1810 int
1811sys_rt_sigprocmask(tcp)
1812 struct tcb *tcp;
1813{
1814 sigset_t sigset;
1815
Nate Sammons4a121431999-04-06 01:19:39 +00001816 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001817 if (entering(tcp)) {
1818 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1819 tprintf(", ");
1820 if (!tcp->u_arg[1])
1821 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001822 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001823 tprintf("%#lx, ", tcp->u_arg[1]);
1824 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001825 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001826 tprintf(", ");
1827 }
1828 }
1829 else {
1830 if (!tcp->u_arg[2])
1831
1832 tprintf("NULL");
1833 else if (syserror(tcp))
1834 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001835 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001836 tprintf("[?]");
1837 else
Nate Sammons4a121431999-04-06 01:19:39 +00001838 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001839 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001840 }
1841 return 0;
1842}
1843
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001844
1845/* Structure describing the action to be taken when a signal arrives. */
1846struct new_sigaction
1847{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001848 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849 unsigned long sa_flags;
1850 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001851 /* Kernel treats sa_mask as an array of longs. */
1852 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1853};
1854/* Same for i386-on-x86_64 and similar cases */
1855struct new_sigaction32
1856{
1857 uint32_t __sa_handler;
1858 uint32_t sa_flags;
1859 uint32_t sa_restorer;
1860 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001861};
1862
1863
Roland McGrath5f206812008-08-20 01:59:40 +00001864int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001865sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866{
1867 struct new_sigaction sa;
1868 sigset_t sigset;
1869 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001870 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001871
1872 if (entering(tcp)) {
1873 printsignal(tcp->u_arg[0]);
1874 tprintf(", ");
1875 addr = tcp->u_arg[1];
1876 } else
1877 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001878
1879 if (addr == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001880 tprintf("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001881 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001882 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001883 if (!verbose(tcp)) {
1884 tprintf("%#lx", addr);
1885 goto after_sa;
1886 }
1887#if SUPPORTED_PERSONALITIES > 1
1888 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1889 && personality_wordsize[current_personality] == 4
1890 ) {
1891 struct new_sigaction32 sa32;
1892 r = umove(tcp, addr, &sa32);
1893 if (r >= 0) {
1894 memset(&sa, 0, sizeof(sa));
1895 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1896 sa.sa_flags = sa32.sa_flags;
1897 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1898 /* Kernel treats sa_mask as an array of longs.
1899 * For 32-bit process, "long" is uint32_t, thus, for example,
1900 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1901 * But for (64-bit) kernel, 32th bit in sa_mask is
1902 * 32th bit in 0th (64-bit) long!
1903 * For little-endian, it's the same.
1904 * For big-endian, we swap 32-bit words.
1905 */
1906 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1907 }
1908 } else
1909#endif
1910 {
1911 r = umove(tcp, addr, &sa);
1912 }
1913 if (r < 0) {
1914 tprintf("{...}");
1915 goto after_sa;
1916 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001917 /* Architectures using function pointers, like
1918 * hppa, may need to manipulate the function pointer
1919 * to compute the result of a comparison. However,
1920 * the SA_HANDLER function pointer exists only in
1921 * the address space of the traced process, and can't
1922 * be manipulated by strace. In order to prevent the
1923 * compiler from generating code to manipulate
1924 * SA_HANDLER we cast the function pointers to long. */
1925 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001926 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001927 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001928 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001929 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001930 tprintf("{SIG_IGN, ");
1931 else
1932 tprintf("{%#lx, ", (long) sa.__sa_handler);
1933 /* Questionable code below.
1934 * Kernel won't handle sys_rt_sigaction
1935 * with wrong sigset size (just returns EINVAL)
1936 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
1937 * and we always use smaller memcpy. */
1938 sigemptyset(&sigset);
1939#ifdef LINUXSPARC
1940 if (tcp->u_arg[4] <= sizeof(sigset))
1941 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1942#else
1943 if (tcp->u_arg[3] <= sizeof(sigset))
1944 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1945#endif
1946 else
1947 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1948 printsigmask(&sigset, 1);
1949 tprintf(", ");
1950 printflags(sigact_flags, sa.sa_flags, "SA_???");
1951#ifdef SA_RESTORER
1952 if (sa.sa_flags & SA_RESTORER)
1953 tprintf(", %p", sa.sa_restorer);
1954#endif
1955 tprintf("}");
1956
1957 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001958 if (entering(tcp))
1959 tprintf(", ");
1960 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001961#ifdef LINUXSPARC
1962 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1963#elif defined(ALPHA)
1964 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1965#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001966 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001967#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001968 return 0;
1969}
1970
Denys Vlasenko1d632462009-04-14 12:51:00 +00001971int
1972sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001973{
1974 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001975
1976 if (exiting(tcp)) {
1977 if (syserror(tcp))
1978 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001979 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1980 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001981 tprintf("[?]");
1982 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001983 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001984 }
1985 return 0;
1986}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001987
1988int
1989sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001990{
1991 if (entering(tcp)) {
1992 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001993 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1994 tprintf("[?]");
1995 else
1996 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001997 }
1998 return 0;
1999}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002000
2001int
2002sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002003{
2004 if (entering(tcp)) {
2005 siginfo_t si;
2006 tprintf("%lu, ", tcp->u_arg[0]);
2007 printsignal(tcp->u_arg[1]);
2008 tprintf(", ");
2009 if (umove(tcp, tcp->u_arg[2], &si) < 0)
2010 tprintf("%#lx", tcp->u_arg[2]);
2011 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002012 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002013 }
2014 return 0;
2015}
2016
Denys Vlasenko1d632462009-04-14 12:51:00 +00002017int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002018{
2019 if (entering(tcp)) {
2020 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002021
Roland McGratha39c5a12002-12-17 05:10:37 +00002022 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00002023 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002024 tprintf("[?]");
2025 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002026 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002027 tprintf(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002028 /* This is the only "return" parameter, */
2029 if (tcp->u_arg[1] != 0)
2030 return 0;
2031 /* ... if it's NULL, can decode all on entry */
2032 tprintf("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002033 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002034 else if (tcp->u_arg[1] != 0) {
2035 /* syscall exit, and u_arg[1] wasn't NULL */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002036 if (syserror(tcp))
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002037 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002038 else {
2039 siginfo_t si;
2040 if (umove(tcp, tcp->u_arg[1], &si) < 0)
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002041 tprintf("%#lx, ", tcp->u_arg[1]);
2042 else {
Denys Vlasenkof535b542009-01-13 18:30:55 +00002043 printsiginfo(&si, verbose(tcp));
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002044 tprintf(", ");
2045 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046 }
2047 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002048 else {
2049 /* syscall exit, and u_arg[1] was NULL */
2050 return 0;
2051 }
2052 print_timespec(tcp, tcp->u_arg[2]);
2053 tprintf(", %d", (int) tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002054 return 0;
2055};
2056
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002057int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002058sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002059{
2060 if (entering(tcp))
2061 tprintf("<... resuming interrupted call ...>");
2062 return 0;
2063}
2064
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002065static int
2066do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00002067{
2068 if (entering(tcp)) {
2069 tprintf("%ld, ", tcp->u_arg[0]);
2070 print_sigset(tcp, tcp->u_arg[1], 1);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00002071 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002072 if (flags_arg >= 0) {
2073 tprintf(", ");
2074 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2075 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00002076 }
2077 return 0;
2078}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002079
2080int
2081sys_signalfd(struct tcb *tcp)
2082{
2083 return do_signalfd(tcp, -1);
2084}
2085
2086int
2087sys_signalfd4(struct tcb *tcp)
2088{
2089 return do_signalfd(tcp, 3);
2090}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002091#endif /* LINUX */