blob: 889134ad57d1a48bb8ad8698bbe7d43a0ec107ea [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>
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020073#endif
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000074
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 */
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200134
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135#ifndef NSIG
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200136#warning: NSIG is not defined, using 32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000137#define NSIG 32
138#endif
139#ifdef ARM
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200140/* Ugh. Is this really correct? ARM has no RT signals?! */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000141#undef NSIG
142#define NSIG 32
143#endif
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200144
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000145#endif /* LINUX */
146
Roland McGrathee36ce12004-09-04 03:53:10 +0000147const char *const signalent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148#include "signalent.h"
149};
Dmitry V. Levinfcda7a52011-06-13 21:58:43 +0000150const int nsignals0 = ARRAY_SIZE(signalent0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151
152#if SUPPORTED_PERSONALITIES >= 2
Roland McGrathee36ce12004-09-04 03:53:10 +0000153const char *const signalent1[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000154#include "signalent1.h"
155};
Dmitry V. Levinfcda7a52011-06-13 21:58:43 +0000156const int nsignals1 = ARRAY_SIZE(signalent1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157#endif /* SUPPORTED_PERSONALITIES >= 2 */
158
159#if SUPPORTED_PERSONALITIES >= 3
Roland McGrathee36ce12004-09-04 03:53:10 +0000160const char *const signalent2[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161#include "signalent2.h"
162};
Dmitry V. Levinfcda7a52011-06-13 21:58:43 +0000163const int nsignals2 = ARRAY_SIZE(signalent2);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164#endif /* SUPPORTED_PERSONALITIES >= 3 */
165
Roland McGrathee36ce12004-09-04 03:53:10 +0000166const char *const *signalent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000167int nsignals;
168
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000169#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000170
Roland McGrathd9f816f2004-09-04 03:39:20 +0000171static const struct xlat sigvec_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172 { SV_ONSTACK, "SV_ONSTACK" },
173 { SV_INTERRUPT, "SV_INTERRUPT" },
174 { SV_RESETHAND, "SV_RESETHAND" },
175 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
176 { 0, NULL },
177};
178
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000179#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000180
181#ifdef HAVE_SIGACTION
182
Roland McGrath063ae2d2005-02-02 04:16:54 +0000183#if defined LINUX && (defined I386 || defined X86_64)
Roland McGrath2638cb42002-12-15 23:58:41 +0000184/* The libc headers do not define this constant since it should only be
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200185 used by the implementation. So we define it here. */
Roland McGrath2638cb42002-12-15 23:58:41 +0000186# ifndef SA_RESTORER
187# define SA_RESTORER 0x04000000
188# endif
189#endif
190
Roland McGrathd9f816f2004-09-04 03:39:20 +0000191static const struct xlat sigact_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000192#ifdef SA_RESTORER
193 { SA_RESTORER, "SA_RESTORER" },
194#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195#ifdef SA_STACK
196 { SA_STACK, "SA_STACK" },
197#endif
198#ifdef SA_RESTART
199 { SA_RESTART, "SA_RESTART" },
200#endif
201#ifdef SA_INTERRUPT
202 { SA_INTERRUPT, "SA_INTERRUPT" },
203#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000204#ifdef SA_NODEFER
205 { SA_NODEFER, "SA_NODEFER" },
206#endif
207#if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208 { SA_NOMASK, "SA_NOMASK" },
209#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000210#ifdef SA_RESETHAND
211 { SA_RESETHAND, "SA_RESETHAND" },
212#endif
213#if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000214 { SA_ONESHOT, "SA_ONESHOT" },
215#endif
216#ifdef SA_SIGINFO
217 { SA_SIGINFO, "SA_SIGINFO" },
218#endif
219#ifdef SA_RESETHAND
220 { SA_RESETHAND, "SA_RESETHAND" },
221#endif
222#ifdef SA_ONSTACK
223 { SA_ONSTACK, "SA_ONSTACK" },
224#endif
225#ifdef SA_NODEFER
226 { SA_NODEFER, "SA_NODEFER" },
227#endif
228#ifdef SA_NOCLDSTOP
229 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
230#endif
231#ifdef SA_NOCLDWAIT
232 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
233#endif
234#ifdef _SA_BSDCALL
235 { _SA_BSDCALL, "_SA_BSDCALL" },
236#endif
Chris Metcalfc8c66982009-12-28 10:00:15 -0500237#ifdef SA_NOPTRACE
238 { SA_NOPTRACE, "SA_NOPTRACE" },
239#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000240 { 0, NULL },
241};
242
Roland McGrathd9f816f2004-09-04 03:39:20 +0000243static const struct xlat sigprocmaskcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000244 { SIG_BLOCK, "SIG_BLOCK" },
245 { SIG_UNBLOCK, "SIG_UNBLOCK" },
246 { SIG_SETMASK, "SIG_SETMASK" },
247#ifdef SIG_SETMASK32
248 { SIG_SETMASK32,"SIG_SETMASK32" },
249#endif
250 { 0, NULL },
251};
252
253#endif /* HAVE_SIGACTION */
254
Nate Sammonsce780fc1999-03-29 23:23:13 +0000255/* Anonymous realtime signals. */
256/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
257 constant. This is what we want. Otherwise, just use SIGRTMIN. */
258#ifdef SIGRTMIN
259#ifndef __SIGRTMIN
260#define __SIGRTMIN SIGRTMIN
261#define __SIGRTMAX SIGRTMAX /* likewise */
262#endif
263#endif
264
Roland McGrathee36ce12004-09-04 03:53:10 +0000265const char *
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200266signame(int sig)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000267{
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200268 static char buf[sizeof("SIGRT_%d") + sizeof(int)*3];
269
270 if (sig >= 0 && sig < nsignals)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000271 return signalent[sig];
272#ifdef SIGRTMIN
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200273 if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
274 sprintf(buf, "SIGRT_%d", (int)(sig - __SIGRTMIN));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000275 return buf;
276 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200277#endif
278 sprintf(buf, "%d", sig);
279 return buf;
Nate Sammonsce780fc1999-03-29 23:23:13 +0000280}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000282#ifndef UNIXWARE
Nate Sammons4a121431999-04-06 01:19:39 +0000283static void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200284long_to_sigset(long l, sigset_t *s)
Nate Sammons4a121431999-04-06 01:19:39 +0000285{
286 sigemptyset(s);
287 *(long *)s = l;
288}
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000289#endif
Nate Sammons4a121431999-04-06 01:19:39 +0000290
291static int
Denys Vlasenko12014262011-05-30 14:00:14 +0200292copy_sigset_len(struct tcb *tcp, long addr, sigset_t *s, int len)
Nate Sammons4a121431999-04-06 01:19:39 +0000293{
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. Levin30145dd2010-09-06 22:08:24 +0000315 const char *format;
316 char *s;
Roland McGratha39c5a12002-12-17 05:10:37 +0000317 static char outstr[8 * sizeof(sigset_t) * 8];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000318
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000319 strcpy(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000320 s = outstr + strlen(outstr);
321 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000322 maxsigs = nsignals;
323#ifdef __SIGRTMAX
324 if (rt)
325 maxsigs = __SIGRTMAX; /* instead */
326#endif
327 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000328 if (sigismember(mask, i) == 1)
329 nsigs++;
330 }
331 if (nsigs >= nsignals * 2 / 3) {
332 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000333 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334 switch (sigismember(mask, i)) {
335 case 1:
336 sigdelset(mask, i);
337 break;
338 case 0:
339 sigaddset(mask, i);
340 break;
341 }
342 }
343 }
344 format = "%s";
345 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000346 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000347 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000348 /* real-time signals on solaris don't have
349 * signalent entries
350 */
351 if (i < nsignals) {
352 sprintf(s, format, signalent[i] + 3);
353 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000354#ifdef SIGRTMIN
355 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
356 char tsig[40];
357 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
358 sprintf(s, format, tsig);
359 }
360#endif /* SIGRTMIN */
John Hughesbdf48f52001-03-06 15:08:09 +0000361 else {
362 char tsig[32];
363 sprintf(tsig, "%u", i);
364 sprintf(s, format, tsig);
365 }
366 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000367 format = " %s";
368 }
369 }
370 *s++ = ']';
371 *s = '\0';
372 return outstr;
373}
374
375static void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200376printsigmask(sigset_t *mask, int rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000377{
Nate Sammons4a121431999-04-06 01:19:39 +0000378 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379}
380
381void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200382printsignal(int nr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383{
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +0000384 tprintf("%s", signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000385}
386
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000387void
388print_sigset(struct tcb *tcp, long addr, int rt)
389{
390 sigset_t ss;
391
392 if (!addr)
393 tprintf("NULL");
394 else if (copy_sigset(tcp, addr, &ss) < 0)
395 tprintf("%#lx", addr);
396 else
397 printsigmask(&ss, rt);
398}
399
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000400#ifdef LINUX
401
John Hughes58265892001-10-18 15:13:53 +0000402#ifndef ILL_ILLOPC
403#define ILL_ILLOPC 1 /* illegal opcode */
404#define ILL_ILLOPN 2 /* illegal operand */
405#define ILL_ILLADR 3 /* illegal addressing mode */
406#define ILL_ILLTRP 4 /* illegal trap */
407#define ILL_PRVOPC 5 /* privileged opcode */
408#define ILL_PRVREG 6 /* privileged register */
409#define ILL_COPROC 7 /* coprocessor error */
410#define ILL_BADSTK 8 /* internal stack error */
411#define FPE_INTDIV 1 /* integer divide by zero */
412#define FPE_INTOVF 2 /* integer overflow */
413#define FPE_FLTDIV 3 /* floating point divide by zero */
414#define FPE_FLTOVF 4 /* floating point overflow */
415#define FPE_FLTUND 5 /* floating point underflow */
416#define FPE_FLTRES 6 /* floating point inexact result */
417#define FPE_FLTINV 7 /* floating point invalid operation */
418#define FPE_FLTSUB 8 /* subscript out of range */
419#define SEGV_MAPERR 1 /* address not mapped to object */
420#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
421#define BUS_ADRALN 1 /* invalid address alignment */
422#define BUS_ADRERR 2 /* non-existant physical address */
423#define BUS_OBJERR 3 /* object specific hardware error */
424#define TRAP_BRKPT 1 /* process breakpoint */
425#define TRAP_TRACE 2 /* process trace trap */
426#define CLD_EXITED 1 /* child has exited */
427#define CLD_KILLED 2 /* child was killed */
428#define CLD_DUMPED 3 /* child terminated abnormally */
429#define CLD_TRAPPED 4 /* traced child has trapped */
430#define CLD_STOPPED 5 /* child has stopped */
431#define CLD_CONTINUED 6 /* stopped child has continued */
432#define POLL_IN 1 /* data input available */
433#define POLL_OUT 2 /* output buffers available */
434#define POLL_MSG 3 /* input message available */
435#define POLL_ERR 4 /* i/o error */
436#define POLL_PRI 5 /* high priority input available */
437#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000438#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000439#define SI_USER 0 /* sent by kill, sigsend, raise */
440#define SI_QUEUE -1 /* sent by sigqueue */
441#define SI_TIMER -2 /* sent by timer expiration */
442#define SI_MESGQ -3 /* sent by real time mesq state change */
443#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000444#define SI_SIGIO -5 /* sent by SIGIO */
445#define SI_TKILL -6 /* sent by tkill */
446#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
447
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000448#define SI_FROMUSER(sip) ((sip)->si_code <= 0)
449
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000450#endif /* LINUX */
John Hughes58265892001-10-18 15:13:53 +0000451
452#if __GLIBC_MINOR__ < 1
453/* Type for data associated with a signal. */
454typedef union sigval
455{
456 int sival_int;
457 void *sival_ptr;
458} sigval_t;
459
460# define __SI_MAX_SIZE 128
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200461# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof(int)) - 3)
John Hughes58265892001-10-18 15:13:53 +0000462
463typedef struct siginfo
464{
465 int si_signo; /* Signal number. */
466 int si_errno; /* If non-zero, an errno value associated with
467 this signal, as defined in <errno.h>. */
468 int si_code; /* Signal code. */
469
470 union
471 {
472 int _pad[__SI_PAD_SIZE];
473
474 /* kill(). */
475 struct
476 {
477 __pid_t si_pid; /* Sending process ID. */
478 __uid_t si_uid; /* Real user ID of sending process. */
479 } _kill;
480
481 /* POSIX.1b timers. */
482 struct
483 {
484 unsigned int _timer1;
485 unsigned int _timer2;
486 } _timer;
487
488 /* POSIX.1b signals. */
489 struct
490 {
491 __pid_t si_pid; /* Sending process ID. */
492 __uid_t si_uid; /* Real user ID of sending process. */
493 sigval_t si_sigval; /* Signal value. */
494 } _rt;
495
496 /* SIGCHLD. */
497 struct
498 {
499 __pid_t si_pid; /* Which child. */
500 int si_status; /* Exit value or signal. */
501 __clock_t si_utime;
502 __clock_t si_stime;
503 } _sigchld;
504
505 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
506 struct
507 {
508 void *si_addr; /* Faulting insn/memory ref. */
509 } _sigfault;
510
511 /* SIGPOLL. */
512 struct
513 {
514 int si_band; /* Band event for SIGPOLL. */
515 int si_fd;
516 } _sigpoll;
517 } _sifields;
518} siginfo_t;
519
520#define si_pid _sifields._kill.si_pid
521#define si_uid _sifields._kill.si_uid
522#define si_status _sifields._sigchld.si_status
523#define si_utime _sifields._sigchld.si_utime
524#define si_stime _sifields._sigchld.si_stime
525#define si_value _sifields._rt.si_sigval
526#define si_int _sifields._rt.si_sigval.sival_int
527#define si_ptr _sifields._rt.si_sigval.sival_ptr
528#define si_addr _sifields._sigfault.si_addr
529#define si_band _sifields._sigpoll.si_band
530#define si_fd _sifields._sigpoll.si_fd
531
532#endif
533
534#endif
535
536#if defined (SVR4) || defined (LINUX)
537
Roland McGrathd9f816f2004-09-04 03:39:20 +0000538static const struct xlat siginfo_codes[] = {
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000539#ifdef SI_KERNEL
540 { SI_KERNEL, "SI_KERNEL" },
John Hughes58265892001-10-18 15:13:53 +0000541#endif
542#ifdef SI_USER
543 { SI_USER, "SI_USER" },
544#endif
John Hughes58265892001-10-18 15:13:53 +0000545#ifdef SI_QUEUE
546 { SI_QUEUE, "SI_QUEUE" },
547#endif
548#ifdef SI_TIMER
549 { SI_TIMER, "SI_TIMER" },
550#endif
John Hughes58265892001-10-18 15:13:53 +0000551#ifdef SI_MESGQ
552 { SI_MESGQ, "SI_MESGQ" },
553#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000554#ifdef SI_ASYNCIO
555 { SI_ASYNCIO, "SI_ASYNCIO" },
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
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000563#ifdef SI_ASYNCNL
564 { SI_ASYNCNL, "SI_ASYNCNL" },
565#endif
566#ifdef SI_NOINFO
567 { SI_NOINFO, "SI_NOINFO" },
568#endif
569#ifdef SI_LWP
570 { SI_LWP, "SI_LWP" },
571#endif
John Hughes58265892001-10-18 15:13:53 +0000572 { 0, NULL },
573};
574
Roland McGrathd9f816f2004-09-04 03:39:20 +0000575static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000576 { ILL_ILLOPC, "ILL_ILLOPC" },
577 { ILL_ILLOPN, "ILL_ILLOPN" },
578 { ILL_ILLADR, "ILL_ILLADR" },
579 { ILL_ILLTRP, "ILL_ILLTRP" },
580 { ILL_PRVOPC, "ILL_PRVOPC" },
581 { ILL_PRVREG, "ILL_PRVREG" },
582 { ILL_COPROC, "ILL_COPROC" },
583 { ILL_BADSTK, "ILL_BADSTK" },
584 { 0, NULL },
585};
586
Roland McGrathd9f816f2004-09-04 03:39:20 +0000587static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000588 { FPE_INTDIV, "FPE_INTDIV" },
589 { FPE_INTOVF, "FPE_INTOVF" },
590 { FPE_FLTDIV, "FPE_FLTDIV" },
591 { FPE_FLTOVF, "FPE_FLTOVF" },
592 { FPE_FLTUND, "FPE_FLTUND" },
593 { FPE_FLTRES, "FPE_FLTRES" },
594 { FPE_FLTINV, "FPE_FLTINV" },
595 { FPE_FLTSUB, "FPE_FLTSUB" },
596 { 0, NULL },
597};
598
Roland McGrathd9f816f2004-09-04 03:39:20 +0000599static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000600 { TRAP_BRKPT, "TRAP_BRKPT" },
601 { TRAP_TRACE, "TRAP_TRACE" },
602 { 0, NULL },
603};
604
Roland McGrathd9f816f2004-09-04 03:39:20 +0000605static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000606 { CLD_EXITED, "CLD_EXITED" },
607 { CLD_KILLED, "CLD_KILLED" },
608 { CLD_DUMPED, "CLD_DUMPED" },
609 { CLD_TRAPPED, "CLD_TRAPPED" },
610 { CLD_STOPPED, "CLD_STOPPED" },
611 { CLD_CONTINUED,"CLD_CONTINUED" },
612 { 0, NULL },
613};
614
Roland McGrathd9f816f2004-09-04 03:39:20 +0000615static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000616 { POLL_IN, "POLL_IN" },
617 { POLL_OUT, "POLL_OUT" },
618 { POLL_MSG, "POLL_MSG" },
619 { POLL_ERR, "POLL_ERR" },
620 { POLL_PRI, "POLL_PRI" },
621 { POLL_HUP, "POLL_HUP" },
622 { 0, NULL },
623};
624
Roland McGrathd9f816f2004-09-04 03:39:20 +0000625static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000626#ifdef PROF_SIG
627 { PROF_SIG, "PROF_SIG" },
628#endif
629 { 0, NULL },
630};
631
632#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000633static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000634#ifdef EMT_TAGOVF
635 { EMT_TAGOVF, "EMT_TAGOVF" },
636#endif
637 { 0, NULL },
638};
639#endif
640
Roland McGrathd9f816f2004-09-04 03:39:20 +0000641static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000642 { SEGV_MAPERR, "SEGV_MAPERR" },
643 { SEGV_ACCERR, "SEGV_ACCERR" },
644 { 0, NULL },
645};
646
Roland McGrathd9f816f2004-09-04 03:39:20 +0000647static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000648 { BUS_ADRALN, "BUS_ADRALN" },
649 { BUS_ADRERR, "BUS_ADRERR" },
650 { BUS_OBJERR, "BUS_OBJERR" },
651 { 0, NULL },
652};
653
654void
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000655printsiginfo(siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000656{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000657 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000658
659 if (sip->si_signo == 0) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200660 tprintf("{}");
John Hughes58265892001-10-18 15:13:53 +0000661 return;
662 }
663 tprintf("{si_signo=");
664 printsignal(sip->si_signo);
665 code = xlookup(siginfo_codes, sip->si_code);
666 if (!code) {
667 switch (sip->si_signo) {
668 case SIGTRAP:
669 code = xlookup(sigtrap_codes, sip->si_code);
670 break;
671 case SIGCHLD:
672 code = xlookup(sigchld_codes, sip->si_code);
673 break;
674 case SIGPOLL:
675 code = xlookup(sigpoll_codes, sip->si_code);
676 break;
677 case SIGPROF:
678 code = xlookup(sigprof_codes, sip->si_code);
679 break;
680 case SIGILL:
681 code = xlookup(sigill_codes, sip->si_code);
682 break;
683#ifdef SIGEMT
684 case SIGEMT:
685 code = xlookup(sigemt_codes, sip->si_code);
686 break;
687#endif
688 case SIGFPE:
689 code = xlookup(sigfpe_codes, sip->si_code);
690 break;
691 case SIGSEGV:
692 code = xlookup(sigsegv_codes, sip->si_code);
693 break;
694 case SIGBUS:
695 code = xlookup(sigbus_codes, sip->si_code);
696 break;
697 }
698 }
699 if (code)
700 tprintf(", si_code=%s", code);
701 else
702 tprintf(", si_code=%#x", sip->si_code);
703#ifdef SI_NOINFO
704 if (sip->si_code != SI_NOINFO)
705#endif
706 {
707 if (sip->si_errno) {
708 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
709 tprintf(", si_errno=%d", sip->si_errno);
710 else
711 tprintf(", si_errno=%s",
712 errnoent[sip->si_errno]);
713 }
714#ifdef SI_FROMUSER
715 if (SI_FROMUSER(sip)) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000716 tprintf(", si_pid=%lu, si_uid=%lu",
717 (unsigned long) sip->si_pid,
718 (unsigned long) sip->si_uid);
John Hughes58265892001-10-18 15:13:53 +0000719 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000720#ifdef SI_USER
721 case SI_USER:
722 break;
723#endif
724#ifdef SI_TKILL
725 case SI_TKILL:
726 break;
727#endif
John Hughes58265892001-10-18 15:13:53 +0000728#ifdef SI_TIMER
729 case SI_TIMER:
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000730 tprintf(", si_value=%d", sip->si_int);
John Hughes58265892001-10-18 15:13:53 +0000731 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000732#endif
733#ifdef LINUX
734 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000735 if (!sip->si_ptr)
736 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000737 if (!verbose)
738 tprintf(", ...");
739 else
740 tprintf(", si_value={int=%u, ptr=%#lx}",
741 sip->si_int,
742 (unsigned long) sip->si_ptr);
743 break;
744#endif
John Hughes58265892001-10-18 15:13:53 +0000745 }
John Hughes58265892001-10-18 15:13:53 +0000746 }
747 else
748#endif /* SI_FROMUSER */
749 {
750 switch (sip->si_signo) {
751 case SIGCHLD:
752 tprintf(", si_pid=%ld, si_status=",
753 (long) sip->si_pid);
754 if (sip->si_code == CLD_EXITED)
755 tprintf("%d", sip->si_status);
756 else
757 printsignal(sip->si_status);
758#if LINUX
759 if (!verbose)
760 tprintf(", ...");
761 else
762 tprintf(", si_utime=%lu, si_stime=%lu",
763 sip->si_utime,
764 sip->si_stime);
765#endif
766 break;
767 case SIGILL: case SIGFPE:
768 case SIGSEGV: case SIGBUS:
769 tprintf(", si_addr=%#lx",
770 (unsigned long) sip->si_addr);
771 break;
772 case SIGPOLL:
773 switch (sip->si_code) {
774 case POLL_IN: case POLL_OUT: case POLL_MSG:
775 tprintf(", si_band=%ld",
776 (long) sip->si_band);
777 break;
778 }
779 break;
780#ifdef LINUX
781 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000782 if (sip->si_pid || sip->si_uid)
783 tprintf(", si_pid=%lu, si_uid=%lu",
784 (unsigned long) sip->si_pid,
785 (unsigned long) sip->si_uid);
786 if (!sip->si_ptr)
787 break;
John Hughes58265892001-10-18 15:13:53 +0000788 if (!verbose)
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000789 tprintf(", ...");
John Hughes58265892001-10-18 15:13:53 +0000790 else {
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000791 tprintf(", si_value={int=%u, ptr=%#lx}",
John Hughes58265892001-10-18 15:13:53 +0000792 sip->si_int,
793 (unsigned long) sip->si_ptr);
794 }
795#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000796
John Hughes58265892001-10-18 15:13:53 +0000797 }
798 }
799 }
800 tprintf("}");
801}
802
803#endif /* SVR4 || LINUX */
804
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000805#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000806
807int
Denys Vlasenko12014262011-05-30 14:00:14 +0200808sys_sigvec(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809{
810 struct sigvec sv;
811 long addr;
812
813 if (entering(tcp)) {
814 printsignal(tcp->u_arg[0]);
815 tprintf(", ");
816 addr = tcp->u_arg[1];
817 } else {
818 addr = tcp->u_arg[2];
819 }
820 if (addr == 0)
821 tprintf("NULL");
822 else if (!verbose(tcp))
823 tprintf("%#lx", addr);
824 else if (umove(tcp, addr, &sv) < 0)
825 tprintf("{...}");
826 else {
827 switch ((int) sv.sv_handler) {
828 case (int) SIG_ERR:
829 tprintf("{SIG_ERR}");
830 break;
831 case (int) SIG_DFL:
832 tprintf("{SIG_DFL}");
833 break;
834 case (int) SIG_IGN:
835 if (tcp->u_arg[0] == SIGTRAP) {
836 tcp->flags |= TCB_SIGTRAPPED;
837 kill(tcp->pid, SIGSTOP);
838 }
839 tprintf("{SIG_IGN}");
840 break;
841 case (int) SIG_HOLD:
842 if (tcp->u_arg[0] == SIGTRAP) {
843 tcp->flags |= TCB_SIGTRAPPED;
844 kill(tcp->pid, SIGSTOP);
845 }
846 tprintf("SIG_HOLD");
847 break;
848 default:
849 if (tcp->u_arg[0] == SIGTRAP) {
850 tcp->flags |= TCB_SIGTRAPPED;
851 kill(tcp->pid, SIGSTOP);
852 }
853 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000854 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000855 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000856 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000857 tprintf("}");
858 }
859 }
860 if (entering(tcp))
861 tprintf(", ");
862 return 0;
863}
864
865int
Denys Vlasenko12014262011-05-30 14:00:14 +0200866sys_sigpause(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000867{
868 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000869 sigset_t sigm;
870 long_to_sigset(tcp->u_arg[0], &sigm);
871 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000872 }
873 return 0;
874}
875
876int
Denys Vlasenko12014262011-05-30 14:00:14 +0200877sys_sigstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000878{
879 struct sigstack ss;
880 long addr;
881
882 if (entering(tcp))
883 addr = tcp->u_arg[0];
884 else
885 addr = tcp->u_arg[1];
886 if (addr == 0)
887 tprintf("NULL");
888 else if (umove(tcp, addr, &ss) < 0)
889 tprintf("%#lx", addr);
890 else {
891 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
892 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
893 }
894 if (entering(tcp))
895 tprintf(", ");
896 return 0;
897}
898
899int
Denys Vlasenko12014262011-05-30 14:00:14 +0200900sys_sigcleanup(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000901{
902 return 0;
903}
904
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000905#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000906
907#ifndef SVR4
908
909int
Denys Vlasenko12014262011-05-30 14:00:14 +0200910sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000911{
912 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000913 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000914 long_to_sigset(tcp->u_arg[0], &sigm);
915 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000916#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000917 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
918 /* Mark attempt to block SIGTRAP */
919 tcp->flags |= TCB_SIGTRAPPED;
920 /* Send unblockable signal */
921 kill(tcp->pid, SIGSTOP);
922 }
Roland McGratha39c5a12002-12-17 05:10:37 +0000923#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000924 }
925 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000926 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000927 long_to_sigset(tcp->u_rval, &sigm);
928 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000929
930 return RVAL_HEX | RVAL_STR;
931 }
932 return 0;
933}
934
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000935#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000936int
Denys Vlasenko12014262011-05-30 14:00:14 +0200937sys_sigblock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000938{
939 return sys_sigsetmask(tcp);
940}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000941#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000942
943#endif /* !SVR4 */
944
945#ifdef HAVE_SIGACTION
946
947#ifdef LINUX
948struct old_sigaction {
949 __sighandler_t __sa_handler;
950 unsigned long sa_mask;
951 unsigned long sa_flags;
952 void (*sa_restorer)(void);
953};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000954#define SA_HANDLER __sa_handler
955#endif /* LINUX */
956
Roland McGratha39c5a12002-12-17 05:10:37 +0000957#ifndef SA_HANDLER
958#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000959#endif
960
961int
Denys Vlasenko12014262011-05-30 14:00:14 +0200962sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000963{
964 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +0000965#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +0000966 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000967 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968#else
969 struct sigaction sa;
970#endif
971
972
973 if (entering(tcp)) {
974 printsignal(tcp->u_arg[0]);
975 tprintf(", ");
976 addr = tcp->u_arg[1];
977 } else
978 addr = tcp->u_arg[2];
979 if (addr == 0)
980 tprintf("NULL");
981 else if (!verbose(tcp))
982 tprintf("%#lx", addr);
983 else if (umove(tcp, addr, &sa) < 0)
984 tprintf("{...}");
985 else {
Carlos O'Donell4677c8a2009-09-09 18:13:19 +0000986 /* Architectures using function pointers, like
987 * hppa, may need to manipulate the function pointer
988 * to compute the result of a comparison. However,
989 * the SA_HANDLER function pointer exists only in
990 * the address space of the traced process, and can't
991 * be manipulated by strace. In order to prevent the
992 * compiler from generating code to manipulate
993 * SA_HANDLER we cast the function pointers to long. */
994 if ((long)sa.SA_HANDLER == (long)SIG_ERR)
Roland McGrath5f206812008-08-20 01:59:40 +0000995 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +0000996 else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
Roland McGrath5f206812008-08-20 01:59:40 +0000997 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +0000998 else if ((long)sa.SA_HANDLER == (long)SIG_IGN) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000999#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001000 if (tcp->u_arg[0] == SIGTRAP) {
1001 tcp->flags |= TCB_SIGTRAPPED;
1002 kill(tcp->pid, SIGSTOP);
1003 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001004#endif /* !USE_PROCFS */
Roland McGrath5f206812008-08-20 01:59:40 +00001005 tprintf("{SIG_IGN, ");
1006 }
1007 else {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001008#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001009 if (tcp->u_arg[0] == SIGTRAP) {
1010 tcp->flags |= TCB_SIGTRAPPED;
1011 kill(tcp->pid, SIGSTOP);
1012 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001013#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001014 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001015#ifndef LINUX
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001016 printsigmask(&sa.sa_mask, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001017#else
Nate Sammons4a121431999-04-06 01:19:39 +00001018 long_to_sigset(sa.sa_mask, &sigset);
1019 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001020#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001022 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001023#ifdef SA_RESTORER
1024 if (sa.sa_flags & SA_RESTORER)
1025 tprintf(", %p", sa.sa_restorer);
1026#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001027 tprintf("}");
1028 }
1029 }
1030 if (entering(tcp))
1031 tprintf(", ");
1032#ifdef LINUX
1033 else
1034 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1035#endif
1036 return 0;
1037}
1038
1039int
Denys Vlasenko12014262011-05-30 14:00:14 +02001040sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041{
1042 if (entering(tcp)) {
1043 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001044 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001045 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001046 case (long) SIG_ERR:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001047 tprintf("SIG_ERR");
1048 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001049 case (long) SIG_DFL:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050 tprintf("SIG_DFL");
1051 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001052 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001053#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001054 if (tcp->u_arg[0] == SIGTRAP) {
1055 tcp->flags |= TCB_SIGTRAPPED;
1056 kill(tcp->pid, SIGSTOP);
1057 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001058#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001059 tprintf("SIG_IGN");
1060 break;
1061 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001062#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063 if (tcp->u_arg[0] == SIGTRAP) {
1064 tcp->flags |= TCB_SIGTRAPPED;
1065 kill(tcp->pid, SIGSTOP);
1066 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001067#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001068 tprintf("%#lx", tcp->u_arg[1]);
1069 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001070 return 0;
1071 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001072 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001073 switch (tcp->u_rval) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001074 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001075 tcp->auxstr = "SIG_ERR"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001076 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001077 tcp->auxstr = "SIG_DFL"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001078 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001079 tcp->auxstr = "SIG_IGN"; break;
1080 default:
1081 tcp->auxstr = NULL;
1082 }
1083 return RVAL_HEX | RVAL_STR;
1084 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001085 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001086}
1087
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001088#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001089int
Denys Vlasenko12014262011-05-30 14:00:14 +02001090sys_sighold(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001091{
1092 if (entering(tcp)) {
1093 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094 }
1095 return 0;
1096}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001097#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001098
1099#endif /* HAVE_SIGACTION */
1100
1101#ifdef LINUX
1102
1103int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001104sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001105{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001106#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001107 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001108 struct pt_regs regs;
1109 struct sigcontext_struct sc;
Roland McGrath0f87c492003-06-03 23:29:04 +00001110 tcp->u_arg[0] = 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001111 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1112 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001113 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1114 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001115 tcp->u_arg[0] = 1;
1116 tcp->u_arg[1] = sc.oldmask;
1117 } else {
1118 sigset_t sigm;
Roland McGrath0f87c492003-06-03 23:29:04 +00001119 tcp->u_rval = tcp->u_error = 0;
1120 if (tcp->u_arg[0] == 0)
1121 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001122 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath0f87c492003-06-03 23:29:04 +00001123 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1124 return RVAL_NONE | RVAL_STR;
1125 }
1126 return 0;
1127#elif defined(S390) || defined(S390X)
Roland McGrath0f87c492003-06-03 23:29:04 +00001128 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001129 long usp;
1130 struct sigcontext_struct sc;
Roland McGrath0f87c492003-06-03 23:29:04 +00001131 tcp->u_arg[0] = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001132 if (upeek(tcp, PT_GPR15, &usp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001133 return 0;
1134 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1135 return 0;
1136 tcp->u_arg[0] = 1;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001137 memcpy(&tcp->u_arg[1], &sc.oldmask[0], sizeof(sigset_t));
Roland McGrath0f87c492003-06-03 23:29:04 +00001138 } else {
1139 tcp->u_rval = tcp->u_error = 0;
1140 if (tcp->u_arg[0] == 0)
1141 return 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001142 tcp->auxstr = sprintsigmask("mask now ", (sigset_t *)&tcp->u_arg[1], 0);
Roland McGrath0f87c492003-06-03 23:29:04 +00001143 return RVAL_NONE | RVAL_STR;
1144 }
1145 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001146#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001147 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001148 long esp;
1149 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001150 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001151 if (upeek(tcp, 4*UESP, &esp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001152 return 0;
1153 if (umove(tcp, esp, &sc) < 0)
1154 return 0;
1155 tcp->u_arg[0] = 1;
1156 tcp->u_arg[1] = sc.oldmask;
1157 }
1158 else {
1159 sigset_t sigm;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001160 tcp->u_rval = tcp->u_error = 0;
1161 if (tcp->u_arg[0] == 0)
1162 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001163 long_to_sigset(tcp->u_arg[1], &sigm);
Nate Sammons4a121431999-04-06 01:19:39 +00001164 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001165 return RVAL_NONE | RVAL_STR;
1166 }
1167 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001168#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001169 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001170 struct sigcontext sc;
1171 long sp;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001172 /* offset of sigcontext in the kernel's sigframe structure: */
1173# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001174 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001175 if (upeek(tcp, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001176 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001177 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001178 return 0;
1179 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001180 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001181 }
1182 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001183 sigset_t sigm;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001184 tcp->u_rval = tcp->u_error = 0;
1185 if (tcp->u_arg[0] == 0)
1186 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001187 memcpy(&sigm, tcp->u_arg + 1, sizeof(sigm));
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001188 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001189 return RVAL_NONE | RVAL_STR;
1190 }
1191 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001192#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +00001193 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001194 long esp;
1195 struct sigcontext_struct sc;
Roland McGrath0f87c492003-06-03 23:29:04 +00001196 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001197 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001198 return 0;
Andreas Schwabedb39342010-02-23 00:18:51 +01001199 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +02001200#ifdef POWERPC64
1201 if (current_personality == 0)
1202 esp += 128;
1203 else
1204 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +01001205#else
1206 esp += 64;
1207#endif
Roland McGrath0f87c492003-06-03 23:29:04 +00001208 if (umove(tcp, esp, &sc) < 0)
1209 return 0;
1210 tcp->u_arg[0] = 1;
1211 tcp->u_arg[1] = sc.oldmask;
1212 }
1213 else {
1214 sigset_t sigm;
Roland McGrath0f87c492003-06-03 23:29:04 +00001215 tcp->u_rval = tcp->u_error = 0;
1216 if (tcp->u_arg[0] == 0)
1217 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001218 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath0f87c492003-06-03 23:29:04 +00001219 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1220 return RVAL_NONE | RVAL_STR;
1221 }
1222 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001223#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001224 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001225 long usp;
1226 struct sigcontext sc;
Roland McGrath0f87c492003-06-03 23:29:04 +00001227 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001228 if (upeek(tcp, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001229 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001230 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001231 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001232 tcp->u_arg[0] = 1;
1233 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001234 }
1235 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001236 sigset_t sigm;
Roland McGrath0f87c492003-06-03 23:29:04 +00001237 tcp->u_rval = tcp->u_error = 0;
1238 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001239 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001240 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath0f87c492003-06-03 23:29:04 +00001241 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1242 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001243 }
1244 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001245#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001246 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001247 long fp;
1248 struct sigcontext_struct sc;
Roland McGrath0f87c492003-06-03 23:29:04 +00001249 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001250 if (upeek(tcp, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001251 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001252 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001253 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001254 tcp->u_arg[0] = 1;
1255 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001256 }
1257 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001258 sigset_t sigm;
Roland McGrath0f87c492003-06-03 23:29:04 +00001259 tcp->u_rval = tcp->u_error = 0;
1260 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001261 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001262 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath0f87c492003-06-03 23:29:04 +00001263 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1264 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001265 }
1266 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001267#elif defined (SPARC) || defined (SPARC64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001268 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001269 long i1;
1270 struct pt_regs regs;
1271 m_siginfo_t si;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001272 tcp->u_arg[0] = 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001273 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1274 perror("sigreturn: PTRACE_GETREGS");
1275 return 0;
1276 }
Mike Frysinger8566c502009-10-12 11:05:14 -04001277 i1 = regs.u_regs[U_REG_O1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001278 if (umove(tcp, i1, &si) < 0) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001279 perror("sigreturn: umove");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001280 return 0;
1281 }
1282 tcp->u_arg[0] = 1;
1283 tcp->u_arg[1] = si.si_mask;
1284 } else {
1285 sigset_t sigm;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001286 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001287 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001288 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001289 long_to_sigset(tcp->u_arg[1], &sigm);
Nate Sammons4a121431999-04-06 01:19:39 +00001290 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001291 return RVAL_NONE | RVAL_STR;
1292 }
1293 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001294#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001295 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1296 sigreturn. */
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001297 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001298 long sp;
1299 struct ucontext uc;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001300 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001301 if (upeek(tcp, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001302 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001303 /* There are six words followed by a 128-byte siginfo. */
1304 sp = sp + 6 * 4 + 128;
1305 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001306 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001307 tcp->u_arg[0] = 1;
1308 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1309 } else {
1310 sigset_t sigm;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001311 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001312 if (tcp->u_arg[0] == 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001313 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001314 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath542c2c62008-05-20 01:11:56 +00001315 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1316 return RVAL_NONE | RVAL_STR;
1317 }
1318 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001319#elif defined(MIPS)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001320 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001321 long sp;
1322 struct pt_regs regs;
1323 m_siginfo_t si;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001324 tcp->u_arg[0] = 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001325 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1326 perror("sigreturn: PTRACE_GETREGS");
1327 return 0;
1328 }
Roland McGrath576b7842007-11-04 00:00:00 +00001329 sp = regs.regs[29];
1330 if (umove(tcp, sp, &si) < 0)
Denys Vlasenkofacd45b2011-06-09 01:22:10 +02001331 return 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001332 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001333 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001334 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001335 sigset_t sigm;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001336 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001337 if (tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001338 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001339 long_to_sigset(tcp->u_arg[1], &sigm);
Roland McGrath576b7842007-11-04 00:00:00 +00001340 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001341 return RVAL_NONE | RVAL_STR;
1342 }
1343 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001344#elif defined(CRISV10) || defined(CRISV32)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001345 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001346 struct sigcontext sc;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001347 long regs[PT_MAX+1];
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001348 tcp->u_arg[0] = 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001349 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1350 perror("sigreturn: PTRACE_GETREGS");
1351 return 0;
1352 }
1353 if (umove(tcp, regs[PT_USP], &sc) < 0)
1354 return 0;
1355 tcp->u_arg[0] = 1;
1356 tcp->u_arg[1] = sc.oldmask;
1357 } else {
1358 sigset_t sigm;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001359 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001360 if (tcp->u_arg[0] == 0)
1361 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001362 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001363 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1364 return RVAL_NONE | RVAL_STR;
1365 }
1366 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -05001367#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -05001368 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001369 struct ucontext uc;
1370 long sp;
1371
1372 /* offset of ucontext in the kernel's sigframe structure */
1373# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo)
Chris Metcalfc8c66982009-12-28 10:00:15 -05001374 tcp->u_arg[0] = 0;
1375 if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0)
1376 return 0;
1377 if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1378 return 0;
1379 tcp->u_arg[0] = 1;
1380 memcpy(tcp->u_arg + 1, &uc.uc_sigmask, sizeof(uc.uc_sigmask));
1381 }
1382 else {
1383 sigset_t sigm;
Chris Metcalfc8c66982009-12-28 10:00:15 -05001384 tcp->u_rval = tcp->u_error = 0;
1385 if (tcp->u_arg[0] == 0)
1386 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001387 memcpy(&sigm, tcp->u_arg + 1, sizeof(sigm));
Chris Metcalfc8c66982009-12-28 10:00:15 -05001388 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1389 return RVAL_NONE | RVAL_STR;
1390 }
1391 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001392#elif defined(MICROBLAZE)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001393 /* TODO: Verify that this is correct... */
1394 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001395 struct sigcontext sc;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001396 long sp;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001397 tcp->u_arg[0] = 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001398 /* Read r1, the stack pointer. */
1399 if (upeek(tcp, 1 * 4, &sp) < 0)
1400 return 0;
1401 if (umove(tcp, sp, &sc) < 0)
1402 return 0;
1403 tcp->u_arg[0] = 1;
1404 tcp->u_arg[1] = sc.oldmask;
1405 } else {
1406 sigset_t sigm;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001407 tcp->u_rval = tcp->u_error = 0;
1408 if (tcp->u_arg[0] == 0)
1409 return 0;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001410 long_to_sigset(tcp->u_arg[1], &sigm);
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001411 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1412 return RVAL_NONE | RVAL_STR;
1413 }
1414 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001415#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001416#warning No sys_sigreturn() for this architecture
1417#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001418 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001419#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001420}
1421
1422int
Denys Vlasenko12014262011-05-30 14:00:14 +02001423sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424{
1425 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001426 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001427 long_to_sigset(tcp->u_rval, &sigm);
1428 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001429 }
1430 return RVAL_HEX | RVAL_STR;
1431}
1432
1433int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001434sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001435{
1436 if (entering(tcp)) {
1437 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001438 long_to_sigset(tcp->u_arg[2], &sigm);
Nate Sammons4a121431999-04-06 01:19:39 +00001439 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001440 }
1441 return 0;
1442}
1443
1444#endif /* LINUX */
1445
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001446#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001447
1448int
Denys Vlasenko12014262011-05-30 14:00:14 +02001449sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001450{
1451 sigset_t sigset;
1452
1453 if (entering(tcp)) {
1454 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1455 tprintf("[?]");
1456 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001457 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001458 }
1459 return 0;
1460}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001461#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001462static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001463 { UC_SIGMASK, "UC_SIGMASK" },
1464 { UC_STACK, "UC_STACK" },
1465 { UC_CPU, "UC_CPU" },
1466#ifdef UC_FPU
1467 { UC_FPU, "UC_FPU" },
1468#endif
1469#ifdef UC_INTR
1470 { UC_INTR, "UC_INTR" },
1471#endif
1472 { 0, NULL },
1473};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001474#endif /* !FREEBSD */
1475#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001476
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001477#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001478#if defined LINUX && !defined SS_ONSTACK
1479#define SS_ONSTACK 1
1480#define SS_DISABLE 2
1481#if __GLIBC_MINOR__ == 0
1482typedef struct
1483{
1484 __ptr_t ss_sp;
1485 int ss_flags;
1486 size_t ss_size;
1487} stack_t;
1488#endif
1489#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001490#ifdef FREEBSD
1491#define stack_t struct sigaltstack
1492#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001493
Roland McGrathd9f816f2004-09-04 03:39:20 +00001494static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001495 { SS_ONSTACK, "SS_ONSTACK" },
1496 { SS_DISABLE, "SS_DISABLE" },
1497 { 0, NULL },
1498};
1499#endif
1500
1501#ifdef SVR4
1502static void
Denys Vlasenko12014262011-05-30 14:00:14 +02001503printcontext(struct tcb *tcp, ucontext_t *ucp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001504{
1505 tprintf("{");
1506 if (!abbrev(tcp)) {
1507 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001508 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001509 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1510 }
1511 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001512 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001513 if (!abbrev(tcp)) {
1514 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1515 (unsigned long) ucp->uc_stack.ss_sp,
1516 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001517 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001518 tprintf("}");
1519 }
1520 tprintf(", ...}");
1521}
1522
1523int
Denys Vlasenko12014262011-05-30 14:00:14 +02001524sys_getcontext(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001525{
1526 ucontext_t uc;
1527
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001528 if (exiting(tcp)) {
1529 if (tcp->u_error)
1530 tprintf("%#lx", tcp->u_arg[0]);
1531 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001532 tprintf("NULL");
1533 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1534 tprintf("{...}");
1535 else
1536 printcontext(tcp, &uc);
1537 }
1538 return 0;
1539}
1540
1541int
Denys Vlasenko12014262011-05-30 14:00:14 +02001542sys_setcontext(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001543{
1544 ucontext_t uc;
1545
1546 if (entering(tcp)) {
1547 if (!tcp->u_arg[0])
1548 tprintf("NULL");
1549 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1550 tprintf("{...}");
1551 else
1552 printcontext(tcp, &uc);
1553 }
1554 else {
1555 tcp->u_rval = tcp->u_error = 0;
1556 if (tcp->u_arg[0] == 0)
1557 return 0;
1558 return RVAL_NONE;
1559 }
1560 return 0;
1561}
1562
1563#endif /* SVR4 */
1564
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001565#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001566
1567static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001568print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001569{
1570 stack_t ss;
1571 if (umove(tcp, addr, &ss) < 0)
1572 return -1;
1573 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001574 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001575 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1576 return 0;
1577}
1578
1579int
Denys Vlasenko12014262011-05-30 14:00:14 +02001580sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001581{
1582 if (entering(tcp)) {
1583 if (tcp->u_arg[0] == 0)
1584 tprintf("NULL");
1585 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1586 return -1;
1587 }
1588 else {
1589 tprintf(", ");
1590 if (tcp->u_arg[1] == 0)
1591 tprintf("NULL");
1592 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1593 return -1;
1594 }
1595 return 0;
1596}
1597#endif
1598
1599#ifdef HAVE_SIGACTION
1600
1601int
Denys Vlasenko12014262011-05-30 14:00:14 +02001602sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603{
1604#ifdef ALPHA
1605 if (entering(tcp)) {
1606 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1607 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001608 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001609 }
1610 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001611 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001612 return RVAL_HEX | RVAL_STR;
1613 }
1614#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615 if (entering(tcp)) {
1616#ifdef SVR4
1617 if (tcp->u_arg[0] == 0)
1618 tprintf("0");
1619 else
1620#endif /* SVR4 */
1621 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1622 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001623 print_sigset(tcp, tcp->u_arg[1], 0);
1624 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625 }
1626 else {
1627 if (!tcp->u_arg[2])
1628 tprintf("NULL");
1629 else if (syserror(tcp))
1630 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001632 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001633 }
1634#endif /* !ALPHA */
1635 return 0;
1636}
1637
1638#endif /* HAVE_SIGACTION */
1639
1640int
Denys Vlasenko12014262011-05-30 14:00:14 +02001641sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642{
1643 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001644 /*
1645 * Sign-extend a 32-bit value when that's what it is.
1646 */
1647 long pid = tcp->u_arg[0];
1648 if (personality_wordsize[current_personality] < sizeof pid)
1649 pid = (long) (int) pid;
1650 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001651 }
1652 return 0;
1653}
1654
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001655#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001656int
Denys Vlasenko12014262011-05-30 14:00:14 +02001657sys_killpg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001658{
1659 return sys_kill(tcp);
1660}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001661#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001662
Roland McGrath8ffc3522003-07-09 09:47:49 +00001663#ifdef LINUX
1664int
Denys Vlasenko12014262011-05-30 14:00:14 +02001665sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001666{
1667 if (entering(tcp)) {
1668 tprintf("%ld, %ld, %s",
1669 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1670 }
1671 return 0;
1672}
1673#endif
1674
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001675int
Denys Vlasenko12014262011-05-30 14:00:14 +02001676sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001677{
1678 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001679
1680 if (exiting(tcp)) {
1681 if (syserror(tcp))
1682 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001683 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001684 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001685 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001686 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001687 }
1688 return 0;
1689}
1690
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001691#ifdef SVR4
Denys Vlasenko12014262011-05-30 14:00:14 +02001692int sys_sigwait(struct tcb *tcp)
John Hughes42162082001-10-18 14:48:26 +00001693{
1694 sigset_t sigset;
1695
1696 if (entering(tcp)) {
1697 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1698 tprintf("[?]");
1699 else
1700 printsigmask(&sigset, 0);
1701 }
1702 else {
1703 if (!syserror(tcp)) {
1704 tcp->auxstr = signalent[tcp->u_rval];
1705 return RVAL_DECIMAL | RVAL_STR;
1706 }
1707 }
1708 return 0;
1709}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001710#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001711
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001712#ifdef LINUX
1713
Denys Vlasenko12014262011-05-30 14:00:14 +02001714int
1715sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001716{
1717 sigset_t sigset;
1718
Nate Sammons4a121431999-04-06 01:19:39 +00001719 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001720 if (entering(tcp)) {
1721 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1722 tprintf(", ");
1723 if (!tcp->u_arg[1])
1724 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001725 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001726 tprintf("%#lx, ", tcp->u_arg[1]);
1727 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001728 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001729 tprintf(", ");
1730 }
1731 }
1732 else {
1733 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001734 tprintf("NULL");
1735 else if (syserror(tcp))
1736 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001737 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001738 tprintf("[?]");
1739 else
Nate Sammons4a121431999-04-06 01:19:39 +00001740 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001741 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001742 }
1743 return 0;
1744}
1745
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001746
1747/* Structure describing the action to be taken when a signal arrives. */
1748struct new_sigaction
1749{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001750 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001751 unsigned long sa_flags;
1752 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001753 /* Kernel treats sa_mask as an array of longs. */
1754 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1755};
1756/* Same for i386-on-x86_64 and similar cases */
1757struct new_sigaction32
1758{
1759 uint32_t __sa_handler;
1760 uint32_t sa_flags;
1761 uint32_t sa_restorer;
1762 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001763};
1764
1765
Roland McGrath5f206812008-08-20 01:59:40 +00001766int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001767sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001768{
1769 struct new_sigaction sa;
1770 sigset_t sigset;
1771 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001772 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001773
1774 if (entering(tcp)) {
1775 printsignal(tcp->u_arg[0]);
1776 tprintf(", ");
1777 addr = tcp->u_arg[1];
1778 } else
1779 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001780
1781 if (addr == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001782 tprintf("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001783 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001784 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001785 if (!verbose(tcp)) {
1786 tprintf("%#lx", addr);
1787 goto after_sa;
1788 }
1789#if SUPPORTED_PERSONALITIES > 1
1790 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1791 && personality_wordsize[current_personality] == 4
1792 ) {
1793 struct new_sigaction32 sa32;
1794 r = umove(tcp, addr, &sa32);
1795 if (r >= 0) {
1796 memset(&sa, 0, sizeof(sa));
1797 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1798 sa.sa_flags = sa32.sa_flags;
1799 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1800 /* Kernel treats sa_mask as an array of longs.
1801 * For 32-bit process, "long" is uint32_t, thus, for example,
1802 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1803 * But for (64-bit) kernel, 32th bit in sa_mask is
1804 * 32th bit in 0th (64-bit) long!
1805 * For little-endian, it's the same.
1806 * For big-endian, we swap 32-bit words.
1807 */
1808 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1809 }
1810 } else
1811#endif
1812 {
1813 r = umove(tcp, addr, &sa);
1814 }
1815 if (r < 0) {
1816 tprintf("{...}");
1817 goto after_sa;
1818 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001819 /* Architectures using function pointers, like
1820 * hppa, may need to manipulate the function pointer
1821 * to compute the result of a comparison. However,
1822 * the SA_HANDLER function pointer exists only in
1823 * the address space of the traced process, and can't
1824 * be manipulated by strace. In order to prevent the
1825 * compiler from generating code to manipulate
1826 * SA_HANDLER we cast the function pointers to long. */
1827 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001828 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001829 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001830 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001831 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001832 tprintf("{SIG_IGN, ");
1833 else
1834 tprintf("{%#lx, ", (long) sa.__sa_handler);
1835 /* Questionable code below.
1836 * Kernel won't handle sys_rt_sigaction
1837 * with wrong sigset size (just returns EINVAL)
1838 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
1839 * and we always use smaller memcpy. */
1840 sigemptyset(&sigset);
1841#ifdef LINUXSPARC
1842 if (tcp->u_arg[4] <= sizeof(sigset))
1843 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1844#else
1845 if (tcp->u_arg[3] <= sizeof(sigset))
1846 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1847#endif
1848 else
1849 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1850 printsigmask(&sigset, 1);
1851 tprintf(", ");
1852 printflags(sigact_flags, sa.sa_flags, "SA_???");
1853#ifdef SA_RESTORER
1854 if (sa.sa_flags & SA_RESTORER)
1855 tprintf(", %p", sa.sa_restorer);
1856#endif
1857 tprintf("}");
1858
1859 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001860 if (entering(tcp))
1861 tprintf(", ");
1862 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001863#ifdef LINUXSPARC
1864 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1865#elif defined(ALPHA)
1866 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1867#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001868 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001869#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001870 return 0;
1871}
1872
Denys Vlasenko1d632462009-04-14 12:51:00 +00001873int
1874sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001875{
1876 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001877
1878 if (exiting(tcp)) {
1879 if (syserror(tcp))
1880 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001881 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1882 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883 tprintf("[?]");
1884 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001885 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001886 }
1887 return 0;
1888}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001889
1890int
1891sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001892{
1893 if (entering(tcp)) {
1894 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001895 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1896 tprintf("[?]");
1897 else
1898 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001899 }
1900 return 0;
1901}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001902
1903int
1904sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001905{
1906 if (entering(tcp)) {
1907 siginfo_t si;
1908 tprintf("%lu, ", tcp->u_arg[0]);
1909 printsignal(tcp->u_arg[1]);
1910 tprintf(", ");
1911 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1912 tprintf("%#lx", tcp->u_arg[2]);
1913 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00001914 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001915 }
1916 return 0;
1917}
1918
Denys Vlasenko1d632462009-04-14 12:51:00 +00001919int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001920{
1921 if (entering(tcp)) {
1922 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001923
Roland McGratha39c5a12002-12-17 05:10:37 +00001924 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00001925 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001926 tprintf("[?]");
1927 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001928 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929 tprintf(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001930 /* This is the only "return" parameter, */
1931 if (tcp->u_arg[1] != 0)
1932 return 0;
1933 /* ... if it's NULL, can decode all on entry */
1934 tprintf("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001935 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001936 else if (tcp->u_arg[1] != 0) {
1937 /* syscall exit, and u_arg[1] wasn't NULL */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001938 if (syserror(tcp))
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001939 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001940 else {
1941 siginfo_t si;
1942 if (umove(tcp, tcp->u_arg[1], &si) < 0)
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001943 tprintf("%#lx, ", tcp->u_arg[1]);
1944 else {
Denys Vlasenkof535b542009-01-13 18:30:55 +00001945 printsiginfo(&si, verbose(tcp));
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001946 tprintf(", ");
1947 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001948 }
1949 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001950 else {
1951 /* syscall exit, and u_arg[1] was NULL */
1952 return 0;
1953 }
1954 print_timespec(tcp, tcp->u_arg[2]);
1955 tprintf(", %d", (int) tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001956 return 0;
1957};
1958
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001959int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001960sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001961{
1962 if (entering(tcp))
1963 tprintf("<... resuming interrupted call ...>");
1964 return 0;
1965}
1966
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001967static int
1968do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00001969{
1970 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001971 printfd(tcp, tcp->u_arg[0]);
1972 tprintf(", ");
Roland McGrathf46ccd32007-08-02 01:15:59 +00001973 print_sigset(tcp, tcp->u_arg[1], 1);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00001974 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001975 if (flags_arg >= 0) {
1976 tprintf(", ");
1977 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1978 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00001979 }
1980 return 0;
1981}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001982
1983int
1984sys_signalfd(struct tcb *tcp)
1985{
1986 return do_signalfd(tcp, -1);
1987}
1988
1989int
1990sys_signalfd4(struct tcb *tcp)
1991{
1992 return do_signalfd(tcp, 3);
1993}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001994#endif /* LINUX */