blob: 990932e9e02d633507c283562e2173810415c0aa [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};
Dmitry V. Levinfcda7a52011-06-13 21:58:43 +0000146const int nsignals0 = ARRAY_SIZE(signalent0);
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};
Dmitry V. Levinfcda7a52011-06-13 21:58:43 +0000152const int nsignals1 = ARRAY_SIZE(signalent1);
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};
Dmitry V. Levinfcda7a52011-06-13 21:58:43 +0000159const int nsignals2 = ARRAY_SIZE(signalent2);
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
Chris Metcalfc8c66982009-12-28 10:00:15 -0500233#ifdef SA_NOPTRACE
234 { SA_NOPTRACE, "SA_NOPTRACE" },
235#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236 { 0, NULL },
237};
238
Roland McGrathd9f816f2004-09-04 03:39:20 +0000239static const struct xlat sigprocmaskcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000240 { SIG_BLOCK, "SIG_BLOCK" },
241 { SIG_UNBLOCK, "SIG_UNBLOCK" },
242 { SIG_SETMASK, "SIG_SETMASK" },
243#ifdef SIG_SETMASK32
244 { SIG_SETMASK32,"SIG_SETMASK32" },
245#endif
246 { 0, NULL },
247};
248
249#endif /* HAVE_SIGACTION */
250
Nate Sammonsce780fc1999-03-29 23:23:13 +0000251/* Anonymous realtime signals. */
252/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
253 constant. This is what we want. Otherwise, just use SIGRTMIN. */
254#ifdef SIGRTMIN
255#ifndef __SIGRTMIN
256#define __SIGRTMIN SIGRTMIN
257#define __SIGRTMAX SIGRTMAX /* likewise */
258#endif
259#endif
260
Roland McGrathee36ce12004-09-04 03:53:10 +0000261const char *
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200262signame(int sig)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000263{
264 static char buf[30];
Roland McGrathad81dce2005-05-09 07:40:30 +0000265 if (sig >= 0 && sig < nsignals) {
Nate Sammonsce780fc1999-03-29 23:23:13 +0000266 return signalent[sig];
267#ifdef SIGRTMIN
Nate Sammons3080aa41999-03-30 00:16:41 +0000268 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000269 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000270 return buf;
271#endif /* SIGRTMIN */
272 } else {
273 sprintf(buf, "%d", sig);
274 return buf;
275 }
276}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000278#ifndef UNIXWARE
Nate Sammons4a121431999-04-06 01:19:39 +0000279static void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200280long_to_sigset(long l, sigset_t *s)
Nate Sammons4a121431999-04-06 01:19:39 +0000281{
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
Denys Vlasenko12014262011-05-30 14:00:14 +0200288copy_sigset_len(struct tcb *tcp, long addr, sigset_t *s, int len)
Nate Sammons4a121431999-04-06 01:19:39 +0000289{
290 if (len > sizeof(*s))
291 len = sizeof(*s);
292 sigemptyset(s);
293 if (umoven(tcp, addr, len, (char *)s) < 0)
294 return -1;
295 return 0;
296}
297
298#ifdef LINUX
299/* Original sigset is unsigned long */
300#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
301#else
302#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
303#endif
304
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000305static const char *
306sprintsigmask(const char *str, sigset_t *mask, int rt)
307/* set might include realtime sigs */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000308{
309 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000310 int maxsigs;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000311 const char *format;
312 char *s;
Roland McGratha39c5a12002-12-17 05:10:37 +0000313 static char outstr[8 * sizeof(sigset_t) * 8];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000314
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000315 strcpy(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000316 s = outstr + strlen(outstr);
317 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000318 maxsigs = nsignals;
319#ifdef __SIGRTMAX
320 if (rt)
321 maxsigs = __SIGRTMAX; /* instead */
322#endif
323 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324 if (sigismember(mask, i) == 1)
325 nsigs++;
326 }
327 if (nsigs >= nsignals * 2 / 3) {
328 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000329 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000330 switch (sigismember(mask, i)) {
331 case 1:
332 sigdelset(mask, i);
333 break;
334 case 0:
335 sigaddset(mask, i);
336 break;
337 }
338 }
339 }
340 format = "%s";
341 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000342 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000343 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000344 /* real-time signals on solaris don't have
345 * signalent entries
346 */
347 if (i < nsignals) {
348 sprintf(s, format, signalent[i] + 3);
349 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000350#ifdef SIGRTMIN
351 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
352 char tsig[40];
353 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
354 sprintf(s, format, tsig);
355 }
356#endif /* SIGRTMIN */
John Hughesbdf48f52001-03-06 15:08:09 +0000357 else {
358 char tsig[32];
359 sprintf(tsig, "%u", i);
360 sprintf(s, format, tsig);
361 }
362 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000363 format = " %s";
364 }
365 }
366 *s++ = ']';
367 *s = '\0';
368 return outstr;
369}
370
371static void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200372printsigmask(sigset_t *mask, int rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000373{
Nate Sammons4a121431999-04-06 01:19:39 +0000374 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000375}
376
377void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200378printsignal(int nr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379{
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +0000380 tprintf("%s", signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381}
382
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000383void
384print_sigset(struct tcb *tcp, long addr, int rt)
385{
386 sigset_t ss;
387
388 if (!addr)
389 tprintf("NULL");
390 else if (copy_sigset(tcp, addr, &ss) < 0)
391 tprintf("%#lx", addr);
392 else
393 printsigmask(&ss, rt);
394}
395
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000396#ifdef LINUX
397
John Hughes58265892001-10-18 15:13:53 +0000398#ifndef ILL_ILLOPC
399#define ILL_ILLOPC 1 /* illegal opcode */
400#define ILL_ILLOPN 2 /* illegal operand */
401#define ILL_ILLADR 3 /* illegal addressing mode */
402#define ILL_ILLTRP 4 /* illegal trap */
403#define ILL_PRVOPC 5 /* privileged opcode */
404#define ILL_PRVREG 6 /* privileged register */
405#define ILL_COPROC 7 /* coprocessor error */
406#define ILL_BADSTK 8 /* internal stack error */
407#define FPE_INTDIV 1 /* integer divide by zero */
408#define FPE_INTOVF 2 /* integer overflow */
409#define FPE_FLTDIV 3 /* floating point divide by zero */
410#define FPE_FLTOVF 4 /* floating point overflow */
411#define FPE_FLTUND 5 /* floating point underflow */
412#define FPE_FLTRES 6 /* floating point inexact result */
413#define FPE_FLTINV 7 /* floating point invalid operation */
414#define FPE_FLTSUB 8 /* subscript out of range */
415#define SEGV_MAPERR 1 /* address not mapped to object */
416#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
417#define BUS_ADRALN 1 /* invalid address alignment */
418#define BUS_ADRERR 2 /* non-existant physical address */
419#define BUS_OBJERR 3 /* object specific hardware error */
420#define TRAP_BRKPT 1 /* process breakpoint */
421#define TRAP_TRACE 2 /* process trace trap */
422#define CLD_EXITED 1 /* child has exited */
423#define CLD_KILLED 2 /* child was killed */
424#define CLD_DUMPED 3 /* child terminated abnormally */
425#define CLD_TRAPPED 4 /* traced child has trapped */
426#define CLD_STOPPED 5 /* child has stopped */
427#define CLD_CONTINUED 6 /* stopped child has continued */
428#define POLL_IN 1 /* data input available */
429#define POLL_OUT 2 /* output buffers available */
430#define POLL_MSG 3 /* input message available */
431#define POLL_ERR 4 /* i/o error */
432#define POLL_PRI 5 /* high priority input available */
433#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000434#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000435#define SI_USER 0 /* sent by kill, sigsend, raise */
436#define SI_QUEUE -1 /* sent by sigqueue */
437#define SI_TIMER -2 /* sent by timer expiration */
438#define SI_MESGQ -3 /* sent by real time mesq state change */
439#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000440#define SI_SIGIO -5 /* sent by SIGIO */
441#define SI_TKILL -6 /* sent by tkill */
442#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
443
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000444#define SI_FROMUSER(sip) ((sip)->si_code <= 0)
445
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000446#endif /* LINUX */
John Hughes58265892001-10-18 15:13:53 +0000447
448#if __GLIBC_MINOR__ < 1
449/* Type for data associated with a signal. */
450typedef union sigval
451{
452 int sival_int;
453 void *sival_ptr;
454} sigval_t;
455
456# define __SI_MAX_SIZE 128
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200457# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof(int)) - 3)
John Hughes58265892001-10-18 15:13:53 +0000458
459typedef struct siginfo
460{
461 int si_signo; /* Signal number. */
462 int si_errno; /* If non-zero, an errno value associated with
463 this signal, as defined in <errno.h>. */
464 int si_code; /* Signal code. */
465
466 union
467 {
468 int _pad[__SI_PAD_SIZE];
469
470 /* kill(). */
471 struct
472 {
473 __pid_t si_pid; /* Sending process ID. */
474 __uid_t si_uid; /* Real user ID of sending process. */
475 } _kill;
476
477 /* POSIX.1b timers. */
478 struct
479 {
480 unsigned int _timer1;
481 unsigned int _timer2;
482 } _timer;
483
484 /* POSIX.1b signals. */
485 struct
486 {
487 __pid_t si_pid; /* Sending process ID. */
488 __uid_t si_uid; /* Real user ID of sending process. */
489 sigval_t si_sigval; /* Signal value. */
490 } _rt;
491
492 /* SIGCHLD. */
493 struct
494 {
495 __pid_t si_pid; /* Which child. */
496 int si_status; /* Exit value or signal. */
497 __clock_t si_utime;
498 __clock_t si_stime;
499 } _sigchld;
500
501 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
502 struct
503 {
504 void *si_addr; /* Faulting insn/memory ref. */
505 } _sigfault;
506
507 /* SIGPOLL. */
508 struct
509 {
510 int si_band; /* Band event for SIGPOLL. */
511 int si_fd;
512 } _sigpoll;
513 } _sifields;
514} siginfo_t;
515
516#define si_pid _sifields._kill.si_pid
517#define si_uid _sifields._kill.si_uid
518#define si_status _sifields._sigchld.si_status
519#define si_utime _sifields._sigchld.si_utime
520#define si_stime _sifields._sigchld.si_stime
521#define si_value _sifields._rt.si_sigval
522#define si_int _sifields._rt.si_sigval.sival_int
523#define si_ptr _sifields._rt.si_sigval.sival_ptr
524#define si_addr _sifields._sigfault.si_addr
525#define si_band _sifields._sigpoll.si_band
526#define si_fd _sifields._sigpoll.si_fd
527
528#endif
529
530#endif
531
532#if defined (SVR4) || defined (LINUX)
533
Roland McGrathd9f816f2004-09-04 03:39:20 +0000534static const struct xlat siginfo_codes[] = {
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000535#ifdef SI_KERNEL
536 { SI_KERNEL, "SI_KERNEL" },
John Hughes58265892001-10-18 15:13:53 +0000537#endif
538#ifdef SI_USER
539 { SI_USER, "SI_USER" },
540#endif
John Hughes58265892001-10-18 15:13:53 +0000541#ifdef SI_QUEUE
542 { SI_QUEUE, "SI_QUEUE" },
543#endif
544#ifdef SI_TIMER
545 { SI_TIMER, "SI_TIMER" },
546#endif
John Hughes58265892001-10-18 15:13:53 +0000547#ifdef SI_MESGQ
548 { SI_MESGQ, "SI_MESGQ" },
549#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000550#ifdef SI_ASYNCIO
551 { SI_ASYNCIO, "SI_ASYNCIO" },
552#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000553#ifdef SI_SIGIO
554 { SI_SIGIO, "SI_SIGIO" },
555#endif
556#ifdef SI_TKILL
557 { SI_TKILL, "SI_TKILL" },
558#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000559#ifdef SI_ASYNCNL
560 { SI_ASYNCNL, "SI_ASYNCNL" },
561#endif
562#ifdef SI_NOINFO
563 { SI_NOINFO, "SI_NOINFO" },
564#endif
565#ifdef SI_LWP
566 { SI_LWP, "SI_LWP" },
567#endif
John Hughes58265892001-10-18 15:13:53 +0000568 { 0, NULL },
569};
570
Roland McGrathd9f816f2004-09-04 03:39:20 +0000571static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000572 { ILL_ILLOPC, "ILL_ILLOPC" },
573 { ILL_ILLOPN, "ILL_ILLOPN" },
574 { ILL_ILLADR, "ILL_ILLADR" },
575 { ILL_ILLTRP, "ILL_ILLTRP" },
576 { ILL_PRVOPC, "ILL_PRVOPC" },
577 { ILL_PRVREG, "ILL_PRVREG" },
578 { ILL_COPROC, "ILL_COPROC" },
579 { ILL_BADSTK, "ILL_BADSTK" },
580 { 0, NULL },
581};
582
Roland McGrathd9f816f2004-09-04 03:39:20 +0000583static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000584 { FPE_INTDIV, "FPE_INTDIV" },
585 { FPE_INTOVF, "FPE_INTOVF" },
586 { FPE_FLTDIV, "FPE_FLTDIV" },
587 { FPE_FLTOVF, "FPE_FLTOVF" },
588 { FPE_FLTUND, "FPE_FLTUND" },
589 { FPE_FLTRES, "FPE_FLTRES" },
590 { FPE_FLTINV, "FPE_FLTINV" },
591 { FPE_FLTSUB, "FPE_FLTSUB" },
592 { 0, NULL },
593};
594
Roland McGrathd9f816f2004-09-04 03:39:20 +0000595static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000596 { TRAP_BRKPT, "TRAP_BRKPT" },
597 { TRAP_TRACE, "TRAP_TRACE" },
598 { 0, NULL },
599};
600
Roland McGrathd9f816f2004-09-04 03:39:20 +0000601static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000602 { CLD_EXITED, "CLD_EXITED" },
603 { CLD_KILLED, "CLD_KILLED" },
604 { CLD_DUMPED, "CLD_DUMPED" },
605 { CLD_TRAPPED, "CLD_TRAPPED" },
606 { CLD_STOPPED, "CLD_STOPPED" },
607 { CLD_CONTINUED,"CLD_CONTINUED" },
608 { 0, NULL },
609};
610
Roland McGrathd9f816f2004-09-04 03:39:20 +0000611static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000612 { POLL_IN, "POLL_IN" },
613 { POLL_OUT, "POLL_OUT" },
614 { POLL_MSG, "POLL_MSG" },
615 { POLL_ERR, "POLL_ERR" },
616 { POLL_PRI, "POLL_PRI" },
617 { POLL_HUP, "POLL_HUP" },
618 { 0, NULL },
619};
620
Roland McGrathd9f816f2004-09-04 03:39:20 +0000621static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000622#ifdef PROF_SIG
623 { PROF_SIG, "PROF_SIG" },
624#endif
625 { 0, NULL },
626};
627
628#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000629static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000630#ifdef EMT_TAGOVF
631 { EMT_TAGOVF, "EMT_TAGOVF" },
632#endif
633 { 0, NULL },
634};
635#endif
636
Roland McGrathd9f816f2004-09-04 03:39:20 +0000637static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000638 { SEGV_MAPERR, "SEGV_MAPERR" },
639 { SEGV_ACCERR, "SEGV_ACCERR" },
640 { 0, NULL },
641};
642
Roland McGrathd9f816f2004-09-04 03:39:20 +0000643static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000644 { BUS_ADRALN, "BUS_ADRALN" },
645 { BUS_ADRERR, "BUS_ADRERR" },
646 { BUS_OBJERR, "BUS_OBJERR" },
647 { 0, NULL },
648};
649
650void
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000651printsiginfo(siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000652{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000653 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000654
655 if (sip->si_signo == 0) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200656 tprintf("{}");
John Hughes58265892001-10-18 15:13:53 +0000657 return;
658 }
659 tprintf("{si_signo=");
660 printsignal(sip->si_signo);
661 code = xlookup(siginfo_codes, sip->si_code);
662 if (!code) {
663 switch (sip->si_signo) {
664 case SIGTRAP:
665 code = xlookup(sigtrap_codes, sip->si_code);
666 break;
667 case SIGCHLD:
668 code = xlookup(sigchld_codes, sip->si_code);
669 break;
670 case SIGPOLL:
671 code = xlookup(sigpoll_codes, sip->si_code);
672 break;
673 case SIGPROF:
674 code = xlookup(sigprof_codes, sip->si_code);
675 break;
676 case SIGILL:
677 code = xlookup(sigill_codes, sip->si_code);
678 break;
679#ifdef SIGEMT
680 case SIGEMT:
681 code = xlookup(sigemt_codes, sip->si_code);
682 break;
683#endif
684 case SIGFPE:
685 code = xlookup(sigfpe_codes, sip->si_code);
686 break;
687 case SIGSEGV:
688 code = xlookup(sigsegv_codes, sip->si_code);
689 break;
690 case SIGBUS:
691 code = xlookup(sigbus_codes, sip->si_code);
692 break;
693 }
694 }
695 if (code)
696 tprintf(", si_code=%s", code);
697 else
698 tprintf(", si_code=%#x", sip->si_code);
699#ifdef SI_NOINFO
700 if (sip->si_code != SI_NOINFO)
701#endif
702 {
703 if (sip->si_errno) {
704 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
705 tprintf(", si_errno=%d", sip->si_errno);
706 else
707 tprintf(", si_errno=%s",
708 errnoent[sip->si_errno]);
709 }
710#ifdef SI_FROMUSER
711 if (SI_FROMUSER(sip)) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000712 tprintf(", si_pid=%lu, si_uid=%lu",
713 (unsigned long) sip->si_pid,
714 (unsigned long) sip->si_uid);
John Hughes58265892001-10-18 15:13:53 +0000715 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000716#ifdef SI_USER
717 case SI_USER:
718 break;
719#endif
720#ifdef SI_TKILL
721 case SI_TKILL:
722 break;
723#endif
John Hughes58265892001-10-18 15:13:53 +0000724#ifdef SI_TIMER
725 case SI_TIMER:
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000726 tprintf(", si_value=%d", sip->si_int);
John Hughes58265892001-10-18 15:13:53 +0000727 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000728#endif
729#ifdef LINUX
730 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000731 if (!sip->si_ptr)
732 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000733 if (!verbose)
734 tprintf(", ...");
735 else
736 tprintf(", si_value={int=%u, ptr=%#lx}",
737 sip->si_int,
738 (unsigned long) sip->si_ptr);
739 break;
740#endif
John Hughes58265892001-10-18 15:13:53 +0000741 }
John Hughes58265892001-10-18 15:13:53 +0000742 }
743 else
744#endif /* SI_FROMUSER */
745 {
746 switch (sip->si_signo) {
747 case SIGCHLD:
748 tprintf(", si_pid=%ld, si_status=",
749 (long) sip->si_pid);
750 if (sip->si_code == CLD_EXITED)
751 tprintf("%d", sip->si_status);
752 else
753 printsignal(sip->si_status);
754#if LINUX
755 if (!verbose)
756 tprintf(", ...");
757 else
758 tprintf(", si_utime=%lu, si_stime=%lu",
759 sip->si_utime,
760 sip->si_stime);
761#endif
762 break;
763 case SIGILL: case SIGFPE:
764 case SIGSEGV: case SIGBUS:
765 tprintf(", si_addr=%#lx",
766 (unsigned long) sip->si_addr);
767 break;
768 case SIGPOLL:
769 switch (sip->si_code) {
770 case POLL_IN: case POLL_OUT: case POLL_MSG:
771 tprintf(", si_band=%ld",
772 (long) sip->si_band);
773 break;
774 }
775 break;
776#ifdef LINUX
777 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000778 if (sip->si_pid || sip->si_uid)
779 tprintf(", si_pid=%lu, si_uid=%lu",
780 (unsigned long) sip->si_pid,
781 (unsigned long) sip->si_uid);
782 if (!sip->si_ptr)
783 break;
John Hughes58265892001-10-18 15:13:53 +0000784 if (!verbose)
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000785 tprintf(", ...");
John Hughes58265892001-10-18 15:13:53 +0000786 else {
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000787 tprintf(", si_value={int=%u, ptr=%#lx}",
John Hughes58265892001-10-18 15:13:53 +0000788 sip->si_int,
789 (unsigned long) sip->si_ptr);
790 }
791#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000792
John Hughes58265892001-10-18 15:13:53 +0000793 }
794 }
795 }
796 tprintf("}");
797}
798
799#endif /* SVR4 || LINUX */
800
801#ifdef LINUX
802
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000803static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000804parse_sigset_t(const char *str, sigset_t *set)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000805{
Roland McGrathc38feca2003-10-01 07:50:28 +0000806 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000807 unsigned int digit;
808 int i;
809
810 sigemptyset(set);
811
Roland McGrathc38feca2003-10-01 07:50:28 +0000812 p = strchr(str, '\n');
813 if (p == NULL)
814 p = strchr(str, '\0');
815 for (i = 0; p-- > str; i += 4) {
816 if (*p >= '0' && *p <= '9')
817 digit = *p - '0';
818 else if (*p >= 'a' && *p <= 'f')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000819 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000820 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000821 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000822 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000823 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000824 if (digit & 1)
825 sigaddset(set, i + 1);
826 if (digit & 2)
827 sigaddset(set, i + 2);
828 if (digit & 4)
829 sigaddset(set, i + 3);
830 if (digit & 8)
831 sigaddset(set, i + 4);
832 }
833}
834
835#endif
836
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000837/*
838 * Check process TCP for the disposition of signal SIG.
839 * Return 1 if the process would somehow manage to survive signal SIG,
840 * else return 0. This routine will never be called with SIGKILL.
841 */
842int
Denys Vlasenko12014262011-05-30 14:00:14 +0200843sigishandled(struct tcb *tcp, int sig)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000844{
845#ifdef LINUX
846 int sfd;
847 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000848 char buf[2048];
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000849 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000850 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000851 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000852#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853#ifdef SVR4
854 /*
855 * Since procfs doesn't interfere with wait I think it is safe
856 * to punt on this question. If not, the information is there.
857 */
858 return 1;
859#else /* !SVR4 */
860 switch (sig) {
861 case SIGCONT:
862 case SIGSTOP:
863 case SIGTSTP:
864 case SIGTTIN:
865 case SIGTTOU:
866 case SIGCHLD:
867 case SIGIO:
868#if defined(SIGURG) && SIGURG != SIGIO
869 case SIGURG:
870#endif
871 case SIGWINCH:
872 /* Gloria Gaynor says ... */
873 return 1;
874 default:
875 break;
876 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000877#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000878#ifdef LINUX
879
880 /* This is incredibly costly but it's worth it. */
881 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
882 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
883 doesn't handle real-time signals). */
884 sprintf(sname, "/proc/%d/status", tcp->pid);
885 if ((sfd = open(sname, O_RDONLY)) == -1) {
886 perror(sname);
887 return 1;
888 }
889 i = read(sfd, buf, sizeof(buf));
890 buf[i] = '\0';
891 close(sfd);
892 /*
893 * Skip the extraneous fields. We need to skip
894 * command name has any spaces in it. So be it.
895 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000896 s = strstr(buf, "SigIgn:\t");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200897 if (!s) {
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000898 fprintf(stderr, "/proc/pid/status format error\n");
899 return 1;
900 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000901 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000902
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000903 s = strstr(buf, "SigCgt:\t");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200904 if (!s) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000905 fprintf(stderr, "/proc/pid/status format error\n");
906 return 1;
907 }
908 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000909
910#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000911 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
912 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000913#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000914 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000915 return 1;
916#endif /* LINUX */
917
918#ifdef SUNOS4
919 void (*u_signal)();
920
Denys Vlasenko932fc7d2008-12-16 18:18:40 +0000921 if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal),
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000922 (long *) &u_signal) < 0) {
923 return 0;
924 }
925 if (u_signal != SIG_DFL)
926 return 1;
927#endif /* SUNOS4 */
928
929 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000930}
931
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000932#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000933
934int
Denys Vlasenko12014262011-05-30 14:00:14 +0200935sys_sigvec(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000936{
937 struct sigvec sv;
938 long addr;
939
940 if (entering(tcp)) {
941 printsignal(tcp->u_arg[0]);
942 tprintf(", ");
943 addr = tcp->u_arg[1];
944 } else {
945 addr = tcp->u_arg[2];
946 }
947 if (addr == 0)
948 tprintf("NULL");
949 else if (!verbose(tcp))
950 tprintf("%#lx", addr);
951 else if (umove(tcp, addr, &sv) < 0)
952 tprintf("{...}");
953 else {
954 switch ((int) sv.sv_handler) {
955 case (int) SIG_ERR:
956 tprintf("{SIG_ERR}");
957 break;
958 case (int) SIG_DFL:
959 tprintf("{SIG_DFL}");
960 break;
961 case (int) SIG_IGN:
962 if (tcp->u_arg[0] == SIGTRAP) {
963 tcp->flags |= TCB_SIGTRAPPED;
964 kill(tcp->pid, SIGSTOP);
965 }
966 tprintf("{SIG_IGN}");
967 break;
968 case (int) SIG_HOLD:
969 if (tcp->u_arg[0] == SIGTRAP) {
970 tcp->flags |= TCB_SIGTRAPPED;
971 kill(tcp->pid, SIGSTOP);
972 }
973 tprintf("SIG_HOLD");
974 break;
975 default:
976 if (tcp->u_arg[0] == SIGTRAP) {
977 tcp->flags |= TCB_SIGTRAPPED;
978 kill(tcp->pid, SIGSTOP);
979 }
980 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000981 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000983 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984 tprintf("}");
985 }
986 }
987 if (entering(tcp))
988 tprintf(", ");
989 return 0;
990}
991
992int
Denys Vlasenko12014262011-05-30 14:00:14 +0200993sys_sigpause(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000994{
995 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000996 sigset_t sigm;
997 long_to_sigset(tcp->u_arg[0], &sigm);
998 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000999 }
1000 return 0;
1001}
1002
1003int
Denys Vlasenko12014262011-05-30 14:00:14 +02001004sys_sigstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005{
1006 struct sigstack ss;
1007 long addr;
1008
1009 if (entering(tcp))
1010 addr = tcp->u_arg[0];
1011 else
1012 addr = tcp->u_arg[1];
1013 if (addr == 0)
1014 tprintf("NULL");
1015 else if (umove(tcp, addr, &ss) < 0)
1016 tprintf("%#lx", addr);
1017 else {
1018 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1019 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1020 }
1021 if (entering(tcp))
1022 tprintf(", ");
1023 return 0;
1024}
1025
1026int
Denys Vlasenko12014262011-05-30 14:00:14 +02001027sys_sigcleanup(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001028{
1029 return 0;
1030}
1031
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001032#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001033
1034#ifndef SVR4
1035
1036int
Denys Vlasenko12014262011-05-30 14:00:14 +02001037sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001038{
1039 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001040 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001041 long_to_sigset(tcp->u_arg[0], &sigm);
1042 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001043#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001044 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1045 /* Mark attempt to block SIGTRAP */
1046 tcp->flags |= TCB_SIGTRAPPED;
1047 /* Send unblockable signal */
1048 kill(tcp->pid, SIGSTOP);
1049 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001050#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001051 }
1052 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001053 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001054 long_to_sigset(tcp->u_rval, &sigm);
1055 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001056
1057 return RVAL_HEX | RVAL_STR;
1058 }
1059 return 0;
1060}
1061
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001062#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063int
Denys Vlasenko12014262011-05-30 14:00:14 +02001064sys_sigblock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001065{
1066 return sys_sigsetmask(tcp);
1067}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001068#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001069
1070#endif /* !SVR4 */
1071
1072#ifdef HAVE_SIGACTION
1073
1074#ifdef LINUX
1075struct old_sigaction {
1076 __sighandler_t __sa_handler;
1077 unsigned long sa_mask;
1078 unsigned long sa_flags;
1079 void (*sa_restorer)(void);
1080};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001081#define SA_HANDLER __sa_handler
1082#endif /* LINUX */
1083
Roland McGratha39c5a12002-12-17 05:10:37 +00001084#ifndef SA_HANDLER
1085#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001086#endif
1087
1088int
Denys Vlasenko12014262011-05-30 14:00:14 +02001089sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001090{
1091 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001092#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001093 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001095#else
1096 struct sigaction sa;
1097#endif
1098
1099
1100 if (entering(tcp)) {
1101 printsignal(tcp->u_arg[0]);
1102 tprintf(", ");
1103 addr = tcp->u_arg[1];
1104 } else
1105 addr = tcp->u_arg[2];
1106 if (addr == 0)
1107 tprintf("NULL");
1108 else if (!verbose(tcp))
1109 tprintf("%#lx", addr);
1110 else if (umove(tcp, addr, &sa) < 0)
1111 tprintf("{...}");
1112 else {
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001113 /* Architectures using function pointers, like
1114 * hppa, may need to manipulate the function pointer
1115 * to compute the result of a comparison. However,
1116 * the SA_HANDLER function pointer exists only in
1117 * the address space of the traced process, and can't
1118 * be manipulated by strace. In order to prevent the
1119 * compiler from generating code to manipulate
1120 * SA_HANDLER we cast the function pointers to long. */
1121 if ((long)sa.SA_HANDLER == (long)SIG_ERR)
Roland McGrath5f206812008-08-20 01:59:40 +00001122 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001123 else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
Roland McGrath5f206812008-08-20 01:59:40 +00001124 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001125 else if ((long)sa.SA_HANDLER == (long)SIG_IGN) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001126#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001127 if (tcp->u_arg[0] == SIGTRAP) {
1128 tcp->flags |= TCB_SIGTRAPPED;
1129 kill(tcp->pid, SIGSTOP);
1130 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001131#endif /* !USE_PROCFS */
Roland McGrath5f206812008-08-20 01:59:40 +00001132 tprintf("{SIG_IGN, ");
1133 }
1134 else {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001135#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001136 if (tcp->u_arg[0] == SIGTRAP) {
1137 tcp->flags |= TCB_SIGTRAPPED;
1138 kill(tcp->pid, SIGSTOP);
1139 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001140#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001141 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001142#ifndef LINUX
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001143 printsigmask(&sa.sa_mask, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001144#else
Nate Sammons4a121431999-04-06 01:19:39 +00001145 long_to_sigset(sa.sa_mask, &sigset);
1146 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001147#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001148 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001149 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001150#ifdef SA_RESTORER
1151 if (sa.sa_flags & SA_RESTORER)
1152 tprintf(", %p", sa.sa_restorer);
1153#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001154 tprintf("}");
1155 }
1156 }
1157 if (entering(tcp))
1158 tprintf(", ");
1159#ifdef LINUX
1160 else
1161 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1162#endif
1163 return 0;
1164}
1165
1166int
Denys Vlasenko12014262011-05-30 14:00:14 +02001167sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001168{
1169 if (entering(tcp)) {
1170 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001171 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001172 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001173 case (long) SIG_ERR:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001174 tprintf("SIG_ERR");
1175 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001176 case (long) SIG_DFL:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001177 tprintf("SIG_DFL");
1178 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001179 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001180#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001181 if (tcp->u_arg[0] == SIGTRAP) {
1182 tcp->flags |= TCB_SIGTRAPPED;
1183 kill(tcp->pid, SIGSTOP);
1184 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001185#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001186 tprintf("SIG_IGN");
1187 break;
1188 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001189#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001190 if (tcp->u_arg[0] == SIGTRAP) {
1191 tcp->flags |= TCB_SIGTRAPPED;
1192 kill(tcp->pid, SIGSTOP);
1193 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001194#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001195 tprintf("%#lx", tcp->u_arg[1]);
1196 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001197 return 0;
1198 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001199 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001200 switch (tcp->u_rval) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001201 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001202 tcp->auxstr = "SIG_ERR"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001203 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001204 tcp->auxstr = "SIG_DFL"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001205 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001206 tcp->auxstr = "SIG_IGN"; break;
1207 default:
1208 tcp->auxstr = NULL;
1209 }
1210 return RVAL_HEX | RVAL_STR;
1211 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001212 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001213}
1214
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001215#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001216int
Denys Vlasenko12014262011-05-30 14:00:14 +02001217sys_sighold(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001218{
1219 if (entering(tcp)) {
1220 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221 }
1222 return 0;
1223}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001224#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001225
1226#endif /* HAVE_SIGACTION */
1227
1228#ifdef LINUX
1229
1230int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001231sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001232{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001233#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001234 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001235 struct pt_regs regs;
1236 struct sigcontext_struct sc;
Roland McGrath0f87c492003-06-03 23:29:04 +00001237 tcp->u_arg[0] = 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001238 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1239 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001240 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1241 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001242 tcp->u_arg[0] = 1;
1243 tcp->u_arg[1] = sc.oldmask;
1244 } else {
1245 sigset_t sigm;
Roland McGrath0f87c492003-06-03 23:29:04 +00001246 tcp->u_rval = tcp->u_error = 0;
1247 if (tcp->u_arg[0] == 0)
1248 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001249 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath0f87c492003-06-03 23:29:04 +00001250 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1251 return RVAL_NONE | RVAL_STR;
1252 }
1253 return 0;
1254#elif defined(S390) || defined(S390X)
Roland McGrath0f87c492003-06-03 23:29:04 +00001255 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001256 long usp;
1257 struct sigcontext_struct sc;
Roland McGrath0f87c492003-06-03 23:29:04 +00001258 tcp->u_arg[0] = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001259 if (upeek(tcp, PT_GPR15, &usp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001260 return 0;
1261 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1262 return 0;
1263 tcp->u_arg[0] = 1;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001264 memcpy(&tcp->u_arg[1], &sc.oldmask[0], sizeof(sigset_t));
Roland McGrath0f87c492003-06-03 23:29:04 +00001265 } else {
1266 tcp->u_rval = tcp->u_error = 0;
1267 if (tcp->u_arg[0] == 0)
1268 return 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001269 tcp->auxstr = sprintsigmask("mask now ", (sigset_t *)&tcp->u_arg[1], 0);
Roland McGrath0f87c492003-06-03 23:29:04 +00001270 return RVAL_NONE | RVAL_STR;
1271 }
1272 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001273#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001274 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001275 long esp;
1276 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001277 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;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001287 tcp->u_rval = tcp->u_error = 0;
1288 if (tcp->u_arg[0] == 0)
1289 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001290 long_to_sigset(tcp->u_arg[1], &sigm);
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 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001297 struct sigcontext sc;
1298 long sp;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001299 /* offset of sigcontext in the kernel's sigframe structure: */
1300# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001301 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001302 if (upeek(tcp, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001303 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001304 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001305 return 0;
1306 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001307 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001308 }
1309 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001310 sigset_t sigm;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001311 tcp->u_rval = tcp->u_error = 0;
1312 if (tcp->u_arg[0] == 0)
1313 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001314 memcpy(&sigm, tcp->u_arg + 1, sizeof(sigm));
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001315 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001316 return RVAL_NONE | RVAL_STR;
1317 }
1318 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001319#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +00001320 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001321 long esp;
1322 struct sigcontext_struct sc;
Roland McGrath0f87c492003-06-03 23:29:04 +00001323 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001324 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001325 return 0;
Andreas Schwabedb39342010-02-23 00:18:51 +01001326 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +02001327#ifdef POWERPC64
1328 if (current_personality == 0)
1329 esp += 128;
1330 else
1331 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +01001332#else
1333 esp += 64;
1334#endif
Roland McGrath0f87c492003-06-03 23:29:04 +00001335 if (umove(tcp, esp, &sc) < 0)
1336 return 0;
1337 tcp->u_arg[0] = 1;
1338 tcp->u_arg[1] = sc.oldmask;
1339 }
1340 else {
1341 sigset_t sigm;
Roland McGrath0f87c492003-06-03 23:29:04 +00001342 tcp->u_rval = tcp->u_error = 0;
1343 if (tcp->u_arg[0] == 0)
1344 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001345 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath0f87c492003-06-03 23:29:04 +00001346 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1347 return RVAL_NONE | RVAL_STR;
1348 }
1349 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001350#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001351 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001352 long usp;
1353 struct sigcontext sc;
Roland McGrath0f87c492003-06-03 23:29:04 +00001354 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001355 if (upeek(tcp, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001356 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001357 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001358 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001359 tcp->u_arg[0] = 1;
1360 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001361 }
1362 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001363 sigset_t sigm;
Roland McGrath0f87c492003-06-03 23:29:04 +00001364 tcp->u_rval = tcp->u_error = 0;
1365 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001366 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001367 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath0f87c492003-06-03 23:29:04 +00001368 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1369 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001370 }
1371 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001372#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001373 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001374 long fp;
1375 struct sigcontext_struct sc;
Roland McGrath0f87c492003-06-03 23:29:04 +00001376 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001377 if (upeek(tcp, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001379 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001380 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001381 tcp->u_arg[0] = 1;
1382 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001383 }
1384 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001385 sigset_t sigm;
Roland McGrath0f87c492003-06-03 23:29:04 +00001386 tcp->u_rval = tcp->u_error = 0;
1387 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001388 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001389 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath0f87c492003-06-03 23:29:04 +00001390 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1391 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001392 }
1393 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001394#elif defined (SPARC) || defined (SPARC64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001395 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001396 long i1;
1397 struct pt_regs regs;
1398 m_siginfo_t si;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399 tcp->u_arg[0] = 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001400 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1401 perror("sigreturn: PTRACE_GETREGS");
1402 return 0;
1403 }
Mike Frysinger8566c502009-10-12 11:05:14 -04001404 i1 = regs.u_regs[U_REG_O1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001405 if (umove(tcp, i1, &si) < 0) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001406 perror("sigreturn: umove");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001407 return 0;
1408 }
1409 tcp->u_arg[0] = 1;
1410 tcp->u_arg[1] = si.si_mask;
1411 } else {
1412 sigset_t sigm;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001414 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001415 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001416 long_to_sigset(tcp->u_arg[1], &sigm);
Nate Sammons4a121431999-04-06 01:19:39 +00001417 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001418 return RVAL_NONE | RVAL_STR;
1419 }
1420 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001421#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001422 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1423 sigreturn. */
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001424 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001425 long sp;
1426 struct ucontext uc;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001427 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001428 if (upeek(tcp, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001429 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001430 /* There are six words followed by a 128-byte siginfo. */
1431 sp = sp + 6 * 4 + 128;
1432 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001433 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001434 tcp->u_arg[0] = 1;
1435 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1436 } else {
1437 sigset_t sigm;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001438 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001439 if (tcp->u_arg[0] == 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001440 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001441 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath542c2c62008-05-20 01:11:56 +00001442 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1443 return RVAL_NONE | RVAL_STR;
1444 }
1445 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001446#elif defined(MIPS)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001447 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001448 long sp;
1449 struct pt_regs regs;
1450 m_siginfo_t si;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001451 tcp->u_arg[0] = 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001452 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1453 perror("sigreturn: PTRACE_GETREGS");
1454 return 0;
1455 }
Roland McGrath576b7842007-11-04 00:00:00 +00001456 sp = regs.regs[29];
1457 if (umove(tcp, sp, &si) < 0)
Denys Vlasenkofacd45b2011-06-09 01:22:10 +02001458 return 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001459 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001460 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001461 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001462 sigset_t sigm;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001463 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001464 if (tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001465 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001466 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath576b7842007-11-04 00:00:00 +00001467 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001468 return RVAL_NONE | RVAL_STR;
1469 }
1470 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001471#elif defined(CRISV10) || defined(CRISV32)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001472 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001473 struct sigcontext sc;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001474 long regs[PT_MAX+1];
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001475 tcp->u_arg[0] = 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001476 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1477 perror("sigreturn: PTRACE_GETREGS");
1478 return 0;
1479 }
1480 if (umove(tcp, regs[PT_USP], &sc) < 0)
1481 return 0;
1482 tcp->u_arg[0] = 1;
1483 tcp->u_arg[1] = sc.oldmask;
1484 } else {
1485 sigset_t sigm;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001486 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001487 if (tcp->u_arg[0] == 0)
1488 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001489 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001490 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1491 return RVAL_NONE | RVAL_STR;
1492 }
1493 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -05001494#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -05001495 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001496 struct ucontext uc;
1497 long sp;
1498
1499 /* offset of ucontext in the kernel's sigframe structure */
1500# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo)
Chris Metcalfc8c66982009-12-28 10:00:15 -05001501 tcp->u_arg[0] = 0;
1502 if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0)
1503 return 0;
1504 if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1505 return 0;
1506 tcp->u_arg[0] = 1;
1507 memcpy(tcp->u_arg + 1, &uc.uc_sigmask, sizeof(uc.uc_sigmask));
1508 }
1509 else {
1510 sigset_t sigm;
Chris Metcalfc8c66982009-12-28 10:00:15 -05001511 tcp->u_rval = tcp->u_error = 0;
1512 if (tcp->u_arg[0] == 0)
1513 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001514 memcpy(&sigm, tcp->u_arg + 1, sizeof(sigm));
Chris Metcalfc8c66982009-12-28 10:00:15 -05001515 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1516 return RVAL_NONE | RVAL_STR;
1517 }
1518 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001519#elif defined(MICROBLAZE)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001520 /* TODO: Verify that this is correct... */
1521 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001522 struct sigcontext sc;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001523 long sp;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001524 tcp->u_arg[0] = 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001525 /* Read r1, the stack pointer. */
1526 if (upeek(tcp, 1 * 4, &sp) < 0)
1527 return 0;
1528 if (umove(tcp, sp, &sc) < 0)
1529 return 0;
1530 tcp->u_arg[0] = 1;
1531 tcp->u_arg[1] = sc.oldmask;
1532 } else {
1533 sigset_t sigm;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001534 tcp->u_rval = tcp->u_error = 0;
1535 if (tcp->u_arg[0] == 0)
1536 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001537 long_to_sigset(tcp->u_arg[1], &sigm);
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001538 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1539 return RVAL_NONE | RVAL_STR;
1540 }
1541 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001542#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001543#warning No sys_sigreturn() for this architecture
1544#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001545 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001546#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001547}
1548
1549int
Denys Vlasenko12014262011-05-30 14:00:14 +02001550sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001551{
1552 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001553 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001554 long_to_sigset(tcp->u_rval, &sigm);
1555 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001556 }
1557 return RVAL_HEX | RVAL_STR;
1558}
1559
1560int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001561sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001562{
1563 if (entering(tcp)) {
1564 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001565 long_to_sigset(tcp->u_arg[2], &sigm);
Nate Sammons4a121431999-04-06 01:19:39 +00001566 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001567 }
1568 return 0;
1569}
1570
1571#endif /* LINUX */
1572
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001573#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001574
1575int
Denys Vlasenko12014262011-05-30 14:00:14 +02001576sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001577{
1578 sigset_t sigset;
1579
1580 if (entering(tcp)) {
1581 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1582 tprintf("[?]");
1583 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001584 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001585 }
1586 return 0;
1587}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001588#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001589static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001590 { UC_SIGMASK, "UC_SIGMASK" },
1591 { UC_STACK, "UC_STACK" },
1592 { UC_CPU, "UC_CPU" },
1593#ifdef UC_FPU
1594 { UC_FPU, "UC_FPU" },
1595#endif
1596#ifdef UC_INTR
1597 { UC_INTR, "UC_INTR" },
1598#endif
1599 { 0, NULL },
1600};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001601#endif /* !FREEBSD */
1602#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001604#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001605#if defined LINUX && !defined SS_ONSTACK
1606#define SS_ONSTACK 1
1607#define SS_DISABLE 2
1608#if __GLIBC_MINOR__ == 0
1609typedef struct
1610{
1611 __ptr_t ss_sp;
1612 int ss_flags;
1613 size_t ss_size;
1614} stack_t;
1615#endif
1616#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001617#ifdef FREEBSD
1618#define stack_t struct sigaltstack
1619#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001620
Roland McGrathd9f816f2004-09-04 03:39:20 +00001621static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001622 { SS_ONSTACK, "SS_ONSTACK" },
1623 { SS_DISABLE, "SS_DISABLE" },
1624 { 0, NULL },
1625};
1626#endif
1627
1628#ifdef SVR4
1629static void
Denys Vlasenko12014262011-05-30 14:00:14 +02001630printcontext(struct tcb *tcp, ucontext_t *ucp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631{
1632 tprintf("{");
1633 if (!abbrev(tcp)) {
1634 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001635 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001636 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1637 }
1638 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001639 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001640 if (!abbrev(tcp)) {
1641 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1642 (unsigned long) ucp->uc_stack.ss_sp,
1643 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001644 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001645 tprintf("}");
1646 }
1647 tprintf(", ...}");
1648}
1649
1650int
Denys Vlasenko12014262011-05-30 14:00:14 +02001651sys_getcontext(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001652{
1653 ucontext_t uc;
1654
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001655 if (exiting(tcp)) {
1656 if (tcp->u_error)
1657 tprintf("%#lx", tcp->u_arg[0]);
1658 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001659 tprintf("NULL");
1660 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1661 tprintf("{...}");
1662 else
1663 printcontext(tcp, &uc);
1664 }
1665 return 0;
1666}
1667
1668int
Denys Vlasenko12014262011-05-30 14:00:14 +02001669sys_setcontext(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001670{
1671 ucontext_t uc;
1672
1673 if (entering(tcp)) {
1674 if (!tcp->u_arg[0])
1675 tprintf("NULL");
1676 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1677 tprintf("{...}");
1678 else
1679 printcontext(tcp, &uc);
1680 }
1681 else {
1682 tcp->u_rval = tcp->u_error = 0;
1683 if (tcp->u_arg[0] == 0)
1684 return 0;
1685 return RVAL_NONE;
1686 }
1687 return 0;
1688}
1689
1690#endif /* SVR4 */
1691
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001692#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001693
1694static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001695print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001696{
1697 stack_t ss;
1698 if (umove(tcp, addr, &ss) < 0)
1699 return -1;
1700 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001701 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001702 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1703 return 0;
1704}
1705
1706int
Denys Vlasenko12014262011-05-30 14:00:14 +02001707sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001708{
1709 if (entering(tcp)) {
1710 if (tcp->u_arg[0] == 0)
1711 tprintf("NULL");
1712 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1713 return -1;
1714 }
1715 else {
1716 tprintf(", ");
1717 if (tcp->u_arg[1] == 0)
1718 tprintf("NULL");
1719 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1720 return -1;
1721 }
1722 return 0;
1723}
1724#endif
1725
1726#ifdef HAVE_SIGACTION
1727
1728int
Denys Vlasenko12014262011-05-30 14:00:14 +02001729sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001730{
1731#ifdef ALPHA
1732 if (entering(tcp)) {
1733 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1734 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001735 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001736 }
1737 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001738 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001739 return RVAL_HEX | RVAL_STR;
1740 }
1741#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001742 if (entering(tcp)) {
1743#ifdef SVR4
1744 if (tcp->u_arg[0] == 0)
1745 tprintf("0");
1746 else
1747#endif /* SVR4 */
1748 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1749 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001750 print_sigset(tcp, tcp->u_arg[1], 0);
1751 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001752 }
1753 else {
1754 if (!tcp->u_arg[2])
1755 tprintf("NULL");
1756 else if (syserror(tcp))
1757 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001758 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001759 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760 }
1761#endif /* !ALPHA */
1762 return 0;
1763}
1764
1765#endif /* HAVE_SIGACTION */
1766
1767int
Denys Vlasenko12014262011-05-30 14:00:14 +02001768sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001769{
1770 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001771 /*
1772 * Sign-extend a 32-bit value when that's what it is.
1773 */
1774 long pid = tcp->u_arg[0];
1775 if (personality_wordsize[current_personality] < sizeof pid)
1776 pid = (long) (int) pid;
1777 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001778 }
1779 return 0;
1780}
1781
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001782#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001783int
Denys Vlasenko12014262011-05-30 14:00:14 +02001784sys_killpg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001785{
1786 return sys_kill(tcp);
1787}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001788#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001789
Roland McGrath8ffc3522003-07-09 09:47:49 +00001790#ifdef LINUX
1791int
Denys Vlasenko12014262011-05-30 14:00:14 +02001792sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001793{
1794 if (entering(tcp)) {
1795 tprintf("%ld, %ld, %s",
1796 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1797 }
1798 return 0;
1799}
1800#endif
1801
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001802int
Denys Vlasenko12014262011-05-30 14:00:14 +02001803sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001804{
1805 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001806
1807 if (exiting(tcp)) {
1808 if (syserror(tcp))
1809 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001810 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001811 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001812 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001813 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814 }
1815 return 0;
1816}
1817
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001818#ifdef SVR4
Denys Vlasenko12014262011-05-30 14:00:14 +02001819int sys_sigwait(struct tcb *tcp)
John Hughes42162082001-10-18 14:48:26 +00001820{
1821 sigset_t sigset;
1822
1823 if (entering(tcp)) {
1824 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1825 tprintf("[?]");
1826 else
1827 printsigmask(&sigset, 0);
1828 }
1829 else {
1830 if (!syserror(tcp)) {
1831 tcp->auxstr = signalent[tcp->u_rval];
1832 return RVAL_DECIMAL | RVAL_STR;
1833 }
1834 }
1835 return 0;
1836}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001837#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001838
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001839#ifdef LINUX
1840
Denys Vlasenko12014262011-05-30 14:00:14 +02001841int
1842sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001843{
1844 sigset_t sigset;
1845
Nate Sammons4a121431999-04-06 01:19:39 +00001846 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001847 if (entering(tcp)) {
1848 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1849 tprintf(", ");
1850 if (!tcp->u_arg[1])
1851 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001852 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001853 tprintf("%#lx, ", tcp->u_arg[1]);
1854 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001855 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001856 tprintf(", ");
1857 }
1858 }
1859 else {
1860 if (!tcp->u_arg[2])
1861
1862 tprintf("NULL");
1863 else if (syserror(tcp))
1864 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001865 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866 tprintf("[?]");
1867 else
Nate Sammons4a121431999-04-06 01:19:39 +00001868 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001869 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001870 }
1871 return 0;
1872}
1873
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874
1875/* Structure describing the action to be taken when a signal arrives. */
1876struct new_sigaction
1877{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001878 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001879 unsigned long sa_flags;
1880 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001881 /* Kernel treats sa_mask as an array of longs. */
1882 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1883};
1884/* Same for i386-on-x86_64 and similar cases */
1885struct new_sigaction32
1886{
1887 uint32_t __sa_handler;
1888 uint32_t sa_flags;
1889 uint32_t sa_restorer;
1890 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001891};
1892
1893
Roland McGrath5f206812008-08-20 01:59:40 +00001894int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001895sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001896{
1897 struct new_sigaction sa;
1898 sigset_t sigset;
1899 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001900 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001901
1902 if (entering(tcp)) {
1903 printsignal(tcp->u_arg[0]);
1904 tprintf(", ");
1905 addr = tcp->u_arg[1];
1906 } else
1907 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001908
1909 if (addr == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910 tprintf("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001911 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001912 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001913 if (!verbose(tcp)) {
1914 tprintf("%#lx", addr);
1915 goto after_sa;
1916 }
1917#if SUPPORTED_PERSONALITIES > 1
1918 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1919 && personality_wordsize[current_personality] == 4
1920 ) {
1921 struct new_sigaction32 sa32;
1922 r = umove(tcp, addr, &sa32);
1923 if (r >= 0) {
1924 memset(&sa, 0, sizeof(sa));
1925 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1926 sa.sa_flags = sa32.sa_flags;
1927 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1928 /* Kernel treats sa_mask as an array of longs.
1929 * For 32-bit process, "long" is uint32_t, thus, for example,
1930 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1931 * But for (64-bit) kernel, 32th bit in sa_mask is
1932 * 32th bit in 0th (64-bit) long!
1933 * For little-endian, it's the same.
1934 * For big-endian, we swap 32-bit words.
1935 */
1936 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1937 }
1938 } else
1939#endif
1940 {
1941 r = umove(tcp, addr, &sa);
1942 }
1943 if (r < 0) {
1944 tprintf("{...}");
1945 goto after_sa;
1946 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001947 /* Architectures using function pointers, like
1948 * hppa, may need to manipulate the function pointer
1949 * to compute the result of a comparison. However,
1950 * the SA_HANDLER function pointer exists only in
1951 * the address space of the traced process, and can't
1952 * be manipulated by strace. In order to prevent the
1953 * compiler from generating code to manipulate
1954 * SA_HANDLER we cast the function pointers to long. */
1955 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001956 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001957 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001958 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001959 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001960 tprintf("{SIG_IGN, ");
1961 else
1962 tprintf("{%#lx, ", (long) sa.__sa_handler);
1963 /* Questionable code below.
1964 * Kernel won't handle sys_rt_sigaction
1965 * with wrong sigset size (just returns EINVAL)
1966 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
1967 * and we always use smaller memcpy. */
1968 sigemptyset(&sigset);
1969#ifdef LINUXSPARC
1970 if (tcp->u_arg[4] <= sizeof(sigset))
1971 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1972#else
1973 if (tcp->u_arg[3] <= sizeof(sigset))
1974 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1975#endif
1976 else
1977 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1978 printsigmask(&sigset, 1);
1979 tprintf(", ");
1980 printflags(sigact_flags, sa.sa_flags, "SA_???");
1981#ifdef SA_RESTORER
1982 if (sa.sa_flags & SA_RESTORER)
1983 tprintf(", %p", sa.sa_restorer);
1984#endif
1985 tprintf("}");
1986
1987 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001988 if (entering(tcp))
1989 tprintf(", ");
1990 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001991#ifdef LINUXSPARC
1992 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1993#elif defined(ALPHA)
1994 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1995#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001996 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001997#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001998 return 0;
1999}
2000
Denys Vlasenko1d632462009-04-14 12:51:00 +00002001int
2002sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002003{
2004 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002005
2006 if (exiting(tcp)) {
2007 if (syserror(tcp))
2008 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00002009 else if (copy_sigset_len(tcp, tcp->u_arg[0],
2010 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002011 tprintf("[?]");
2012 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002013 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002014 }
2015 return 0;
2016}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002017
2018int
2019sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002020{
2021 if (entering(tcp)) {
2022 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00002023 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
2024 tprintf("[?]");
2025 else
2026 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002027 }
2028 return 0;
2029}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002030
2031int
2032sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002033{
2034 if (entering(tcp)) {
2035 siginfo_t si;
2036 tprintf("%lu, ", tcp->u_arg[0]);
2037 printsignal(tcp->u_arg[1]);
2038 tprintf(", ");
2039 if (umove(tcp, tcp->u_arg[2], &si) < 0)
2040 tprintf("%#lx", tcp->u_arg[2]);
2041 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002042 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002043 }
2044 return 0;
2045}
2046
Denys Vlasenko1d632462009-04-14 12:51:00 +00002047int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002048{
2049 if (entering(tcp)) {
2050 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002051
Roland McGratha39c5a12002-12-17 05:10:37 +00002052 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00002053 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002054 tprintf("[?]");
2055 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002056 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002057 tprintf(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002058 /* This is the only "return" parameter, */
2059 if (tcp->u_arg[1] != 0)
2060 return 0;
2061 /* ... if it's NULL, can decode all on entry */
2062 tprintf("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002063 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002064 else if (tcp->u_arg[1] != 0) {
2065 /* syscall exit, and u_arg[1] wasn't NULL */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002066 if (syserror(tcp))
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002067 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002068 else {
2069 siginfo_t si;
2070 if (umove(tcp, tcp->u_arg[1], &si) < 0)
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002071 tprintf("%#lx, ", tcp->u_arg[1]);
2072 else {
Denys Vlasenkof535b542009-01-13 18:30:55 +00002073 printsiginfo(&si, verbose(tcp));
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002074 tprintf(", ");
2075 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002076 }
2077 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002078 else {
2079 /* syscall exit, and u_arg[1] was NULL */
2080 return 0;
2081 }
2082 print_timespec(tcp, tcp->u_arg[2]);
2083 tprintf(", %d", (int) tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002084 return 0;
2085};
2086
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002087int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002088sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002089{
2090 if (entering(tcp))
2091 tprintf("<... resuming interrupted call ...>");
2092 return 0;
2093}
2094
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002095static int
2096do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00002097{
2098 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002099 printfd(tcp, tcp->u_arg[0]);
2100 tprintf(", ");
Roland McGrathf46ccd32007-08-02 01:15:59 +00002101 print_sigset(tcp, tcp->u_arg[1], 1);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00002102 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002103 if (flags_arg >= 0) {
2104 tprintf(", ");
2105 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2106 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00002107 }
2108 return 0;
2109}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002110
2111int
2112sys_signalfd(struct tcb *tcp)
2113{
2114 return do_signalfd(tcp, -1);
2115}
2116
2117int
2118sys_signalfd4(struct tcb *tcp)
2119{
2120 return do_signalfd(tcp, 3);
2121}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002122#endif /* LINUX */