blob: aca6345f6e191507a2ae4c3a15fa1bddbda34ee6 [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
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000147#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148
Roland McGrathd9f816f2004-09-04 03:39:20 +0000149static const struct xlat sigvec_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150 { SV_ONSTACK, "SV_ONSTACK" },
151 { SV_INTERRUPT, "SV_INTERRUPT" },
152 { SV_RESETHAND, "SV_RESETHAND" },
153 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
154 { 0, NULL },
155};
156
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000157#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000158
159#ifdef HAVE_SIGACTION
160
Roland McGrath063ae2d2005-02-02 04:16:54 +0000161#if defined LINUX && (defined I386 || defined X86_64)
Roland McGrath2638cb42002-12-15 23:58:41 +0000162/* The libc headers do not define this constant since it should only be
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200163 used by the implementation. So we define it here. */
Roland McGrath2638cb42002-12-15 23:58:41 +0000164# ifndef SA_RESTORER
165# define SA_RESTORER 0x04000000
166# endif
167#endif
168
Roland McGrathd9f816f2004-09-04 03:39:20 +0000169static const struct xlat sigact_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000170#ifdef SA_RESTORER
171 { SA_RESTORER, "SA_RESTORER" },
172#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000173#ifdef SA_STACK
174 { SA_STACK, "SA_STACK" },
175#endif
176#ifdef SA_RESTART
177 { SA_RESTART, "SA_RESTART" },
178#endif
179#ifdef SA_INTERRUPT
180 { SA_INTERRUPT, "SA_INTERRUPT" },
181#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000182#ifdef SA_NODEFER
183 { SA_NODEFER, "SA_NODEFER" },
184#endif
185#if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186 { SA_NOMASK, "SA_NOMASK" },
187#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000188#ifdef SA_RESETHAND
189 { SA_RESETHAND, "SA_RESETHAND" },
190#endif
191#if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000192 { SA_ONESHOT, "SA_ONESHOT" },
193#endif
194#ifdef SA_SIGINFO
195 { SA_SIGINFO, "SA_SIGINFO" },
196#endif
197#ifdef SA_RESETHAND
198 { SA_RESETHAND, "SA_RESETHAND" },
199#endif
200#ifdef SA_ONSTACK
201 { SA_ONSTACK, "SA_ONSTACK" },
202#endif
203#ifdef SA_NODEFER
204 { SA_NODEFER, "SA_NODEFER" },
205#endif
206#ifdef SA_NOCLDSTOP
207 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
208#endif
209#ifdef SA_NOCLDWAIT
210 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
211#endif
212#ifdef _SA_BSDCALL
213 { _SA_BSDCALL, "_SA_BSDCALL" },
214#endif
Chris Metcalfc8c66982009-12-28 10:00:15 -0500215#ifdef SA_NOPTRACE
216 { SA_NOPTRACE, "SA_NOPTRACE" },
217#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218 { 0, NULL },
219};
220
Roland McGrathd9f816f2004-09-04 03:39:20 +0000221static const struct xlat sigprocmaskcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 { SIG_BLOCK, "SIG_BLOCK" },
223 { SIG_UNBLOCK, "SIG_UNBLOCK" },
224 { SIG_SETMASK, "SIG_SETMASK" },
225#ifdef SIG_SETMASK32
226 { SIG_SETMASK32,"SIG_SETMASK32" },
227#endif
228 { 0, NULL },
229};
230
231#endif /* HAVE_SIGACTION */
232
Nate Sammonsce780fc1999-03-29 23:23:13 +0000233/* Anonymous realtime signals. */
234/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
235 constant. This is what we want. Otherwise, just use SIGRTMIN. */
236#ifdef SIGRTMIN
237#ifndef __SIGRTMIN
238#define __SIGRTMIN SIGRTMIN
239#define __SIGRTMAX SIGRTMAX /* likewise */
240#endif
241#endif
242
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200243/* Note on the size of sigset_t:
244 *
245 * In glibc, sigset_t is an array with space for 1024 bits (!),
246 * even though all arches supported by Linux have only 64 signals
247 * except MIPS, which has 128. IOW, it is 128 bytes long.
248 *
249 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
250 * However, some old syscall return only 32 lower bits (one word).
251 * Example: sys_sigpending vs sys_rt_sigpending.
252 *
253 * Be aware of this fact when you try to
254 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
255 * - sizeof(sigset_t) is much bigger than you think,
256 * it may overflow tcp->u_arg[] array, and it may try to copy more data
257 * than is really available in <something>.
258 * Similarly,
259 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
260 * may be a bad idea: it'll try to read much more data than needed
261 * to fetch a sigset_t.
262 * Use (NSIG / 8) as a size instead.
263 */
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{
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200313 /* Was [8 * sizeof(sigset_t) * 8], but
314 * glibc sigset_t is huge (1024 bits = 128 *bytes*),
315 * and we were ending up with 8k (!) buffer here.
316 *
317 * No Unix system can have sig > 255
318 * (waitpid API won't be able to indicate death from one)
319 * and sig 0 doesn't exist either.
320 * Therefore max possible no of sigs is 255: 1..255
321 */
322 static char outstr[8 * 255];
323
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000325 int maxsigs;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000326 const char *format;
327 char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000328
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000329 strcpy(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000330 s = outstr + strlen(outstr);
331 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000332 maxsigs = nsignals;
333#ifdef __SIGRTMAX
334 if (rt)
335 maxsigs = __SIGRTMAX; /* instead */
336#endif
337 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338 if (sigismember(mask, i) == 1)
339 nsigs++;
340 }
341 if (nsigs >= nsignals * 2 / 3) {
342 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000343 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344 switch (sigismember(mask, i)) {
345 case 1:
346 sigdelset(mask, i);
347 break;
348 case 0:
349 sigaddset(mask, i);
350 break;
351 }
352 }
353 }
354 format = "%s";
355 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000356 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000357 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000358 /* real-time signals on solaris don't have
359 * signalent entries
360 */
361 if (i < nsignals) {
362 sprintf(s, format, signalent[i] + 3);
363 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000364#ifdef SIGRTMIN
365 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
366 char tsig[40];
367 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
368 sprintf(s, format, tsig);
369 }
370#endif /* SIGRTMIN */
John Hughesbdf48f52001-03-06 15:08:09 +0000371 else {
372 char tsig[32];
373 sprintf(tsig, "%u", i);
374 sprintf(s, format, tsig);
375 }
376 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000377 format = " %s";
378 }
379 }
380 *s++ = ']';
381 *s = '\0';
382 return outstr;
383}
384
385static void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200386printsigmask(sigset_t *mask, int rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200388 tprints(sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000389}
390
391void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200392printsignal(int nr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200394 tprints(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000395}
396
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000397void
398print_sigset(struct tcb *tcp, long addr, int rt)
399{
400 sigset_t ss;
401
402 if (!addr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200403 tprints("NULL");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000404 else if (copy_sigset(tcp, addr, &ss) < 0)
405 tprintf("%#lx", addr);
406 else
407 printsigmask(&ss, rt);
408}
409
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000410#ifdef LINUX
411
John Hughes58265892001-10-18 15:13:53 +0000412#ifndef ILL_ILLOPC
413#define ILL_ILLOPC 1 /* illegal opcode */
414#define ILL_ILLOPN 2 /* illegal operand */
415#define ILL_ILLADR 3 /* illegal addressing mode */
416#define ILL_ILLTRP 4 /* illegal trap */
417#define ILL_PRVOPC 5 /* privileged opcode */
418#define ILL_PRVREG 6 /* privileged register */
419#define ILL_COPROC 7 /* coprocessor error */
420#define ILL_BADSTK 8 /* internal stack error */
421#define FPE_INTDIV 1 /* integer divide by zero */
422#define FPE_INTOVF 2 /* integer overflow */
423#define FPE_FLTDIV 3 /* floating point divide by zero */
424#define FPE_FLTOVF 4 /* floating point overflow */
425#define FPE_FLTUND 5 /* floating point underflow */
426#define FPE_FLTRES 6 /* floating point inexact result */
427#define FPE_FLTINV 7 /* floating point invalid operation */
428#define FPE_FLTSUB 8 /* subscript out of range */
429#define SEGV_MAPERR 1 /* address not mapped to object */
430#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
431#define BUS_ADRALN 1 /* invalid address alignment */
432#define BUS_ADRERR 2 /* non-existant physical address */
433#define BUS_OBJERR 3 /* object specific hardware error */
434#define TRAP_BRKPT 1 /* process breakpoint */
435#define TRAP_TRACE 2 /* process trace trap */
436#define CLD_EXITED 1 /* child has exited */
437#define CLD_KILLED 2 /* child was killed */
438#define CLD_DUMPED 3 /* child terminated abnormally */
439#define CLD_TRAPPED 4 /* traced child has trapped */
440#define CLD_STOPPED 5 /* child has stopped */
441#define CLD_CONTINUED 6 /* stopped child has continued */
442#define POLL_IN 1 /* data input available */
443#define POLL_OUT 2 /* output buffers available */
444#define POLL_MSG 3 /* input message available */
445#define POLL_ERR 4 /* i/o error */
446#define POLL_PRI 5 /* high priority input available */
447#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000448#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000449#define SI_USER 0 /* sent by kill, sigsend, raise */
450#define SI_QUEUE -1 /* sent by sigqueue */
451#define SI_TIMER -2 /* sent by timer expiration */
452#define SI_MESGQ -3 /* sent by real time mesq state change */
453#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000454#define SI_SIGIO -5 /* sent by SIGIO */
455#define SI_TKILL -6 /* sent by tkill */
456#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
457
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000458#define SI_FROMUSER(sip) ((sip)->si_code <= 0)
459
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000460#endif /* LINUX */
John Hughes58265892001-10-18 15:13:53 +0000461
462#if __GLIBC_MINOR__ < 1
463/* Type for data associated with a signal. */
464typedef union sigval
465{
466 int sival_int;
467 void *sival_ptr;
468} sigval_t;
469
470# define __SI_MAX_SIZE 128
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200471# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof(int)) - 3)
John Hughes58265892001-10-18 15:13:53 +0000472
473typedef struct siginfo
474{
475 int si_signo; /* Signal number. */
476 int si_errno; /* If non-zero, an errno value associated with
477 this signal, as defined in <errno.h>. */
478 int si_code; /* Signal code. */
479
480 union
481 {
482 int _pad[__SI_PAD_SIZE];
483
484 /* kill(). */
485 struct
486 {
487 __pid_t si_pid; /* Sending process ID. */
488 __uid_t si_uid; /* Real user ID of sending process. */
489 } _kill;
490
491 /* POSIX.1b timers. */
492 struct
493 {
494 unsigned int _timer1;
495 unsigned int _timer2;
496 } _timer;
497
498 /* POSIX.1b signals. */
499 struct
500 {
501 __pid_t si_pid; /* Sending process ID. */
502 __uid_t si_uid; /* Real user ID of sending process. */
503 sigval_t si_sigval; /* Signal value. */
504 } _rt;
505
506 /* SIGCHLD. */
507 struct
508 {
509 __pid_t si_pid; /* Which child. */
510 int si_status; /* Exit value or signal. */
511 __clock_t si_utime;
512 __clock_t si_stime;
513 } _sigchld;
514
515 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
516 struct
517 {
518 void *si_addr; /* Faulting insn/memory ref. */
519 } _sigfault;
520
521 /* SIGPOLL. */
522 struct
523 {
524 int si_band; /* Band event for SIGPOLL. */
525 int si_fd;
526 } _sigpoll;
527 } _sifields;
528} siginfo_t;
529
530#define si_pid _sifields._kill.si_pid
531#define si_uid _sifields._kill.si_uid
532#define si_status _sifields._sigchld.si_status
533#define si_utime _sifields._sigchld.si_utime
534#define si_stime _sifields._sigchld.si_stime
535#define si_value _sifields._rt.si_sigval
536#define si_int _sifields._rt.si_sigval.sival_int
537#define si_ptr _sifields._rt.si_sigval.sival_ptr
538#define si_addr _sifields._sigfault.si_addr
539#define si_band _sifields._sigpoll.si_band
540#define si_fd _sifields._sigpoll.si_fd
541
542#endif
543
544#endif
545
546#if defined (SVR4) || defined (LINUX)
547
Roland McGrathd9f816f2004-09-04 03:39:20 +0000548static const struct xlat siginfo_codes[] = {
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000549#ifdef SI_KERNEL
550 { SI_KERNEL, "SI_KERNEL" },
John Hughes58265892001-10-18 15:13:53 +0000551#endif
552#ifdef SI_USER
553 { SI_USER, "SI_USER" },
554#endif
John Hughes58265892001-10-18 15:13:53 +0000555#ifdef SI_QUEUE
556 { SI_QUEUE, "SI_QUEUE" },
557#endif
558#ifdef SI_TIMER
559 { SI_TIMER, "SI_TIMER" },
560#endif
John Hughes58265892001-10-18 15:13:53 +0000561#ifdef SI_MESGQ
562 { SI_MESGQ, "SI_MESGQ" },
563#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000564#ifdef SI_ASYNCIO
565 { SI_ASYNCIO, "SI_ASYNCIO" },
566#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000567#ifdef SI_SIGIO
568 { SI_SIGIO, "SI_SIGIO" },
569#endif
570#ifdef SI_TKILL
571 { SI_TKILL, "SI_TKILL" },
572#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000573#ifdef SI_ASYNCNL
574 { SI_ASYNCNL, "SI_ASYNCNL" },
575#endif
576#ifdef SI_NOINFO
577 { SI_NOINFO, "SI_NOINFO" },
578#endif
579#ifdef SI_LWP
580 { SI_LWP, "SI_LWP" },
581#endif
John Hughes58265892001-10-18 15:13:53 +0000582 { 0, NULL },
583};
584
Roland McGrathd9f816f2004-09-04 03:39:20 +0000585static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000586 { ILL_ILLOPC, "ILL_ILLOPC" },
587 { ILL_ILLOPN, "ILL_ILLOPN" },
588 { ILL_ILLADR, "ILL_ILLADR" },
589 { ILL_ILLTRP, "ILL_ILLTRP" },
590 { ILL_PRVOPC, "ILL_PRVOPC" },
591 { ILL_PRVREG, "ILL_PRVREG" },
592 { ILL_COPROC, "ILL_COPROC" },
593 { ILL_BADSTK, "ILL_BADSTK" },
594 { 0, NULL },
595};
596
Roland McGrathd9f816f2004-09-04 03:39:20 +0000597static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000598 { FPE_INTDIV, "FPE_INTDIV" },
599 { FPE_INTOVF, "FPE_INTOVF" },
600 { FPE_FLTDIV, "FPE_FLTDIV" },
601 { FPE_FLTOVF, "FPE_FLTOVF" },
602 { FPE_FLTUND, "FPE_FLTUND" },
603 { FPE_FLTRES, "FPE_FLTRES" },
604 { FPE_FLTINV, "FPE_FLTINV" },
605 { FPE_FLTSUB, "FPE_FLTSUB" },
606 { 0, NULL },
607};
608
Roland McGrathd9f816f2004-09-04 03:39:20 +0000609static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000610 { TRAP_BRKPT, "TRAP_BRKPT" },
611 { TRAP_TRACE, "TRAP_TRACE" },
612 { 0, NULL },
613};
614
Roland McGrathd9f816f2004-09-04 03:39:20 +0000615static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000616 { CLD_EXITED, "CLD_EXITED" },
617 { CLD_KILLED, "CLD_KILLED" },
618 { CLD_DUMPED, "CLD_DUMPED" },
619 { CLD_TRAPPED, "CLD_TRAPPED" },
620 { CLD_STOPPED, "CLD_STOPPED" },
621 { CLD_CONTINUED,"CLD_CONTINUED" },
622 { 0, NULL },
623};
624
Roland McGrathd9f816f2004-09-04 03:39:20 +0000625static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000626 { POLL_IN, "POLL_IN" },
627 { POLL_OUT, "POLL_OUT" },
628 { POLL_MSG, "POLL_MSG" },
629 { POLL_ERR, "POLL_ERR" },
630 { POLL_PRI, "POLL_PRI" },
631 { POLL_HUP, "POLL_HUP" },
632 { 0, NULL },
633};
634
Roland McGrathd9f816f2004-09-04 03:39:20 +0000635static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000636#ifdef PROF_SIG
637 { PROF_SIG, "PROF_SIG" },
638#endif
639 { 0, NULL },
640};
641
642#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000643static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000644#ifdef EMT_TAGOVF
645 { EMT_TAGOVF, "EMT_TAGOVF" },
646#endif
647 { 0, NULL },
648};
649#endif
650
Roland McGrathd9f816f2004-09-04 03:39:20 +0000651static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000652 { SEGV_MAPERR, "SEGV_MAPERR" },
653 { SEGV_ACCERR, "SEGV_ACCERR" },
654 { 0, NULL },
655};
656
Roland McGrathd9f816f2004-09-04 03:39:20 +0000657static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000658 { BUS_ADRALN, "BUS_ADRALN" },
659 { BUS_ADRERR, "BUS_ADRERR" },
660 { BUS_OBJERR, "BUS_OBJERR" },
661 { 0, NULL },
662};
663
664void
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000665printsiginfo(siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000666{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000667 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000668
669 if (sip->si_signo == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200670 tprints("{}");
John Hughes58265892001-10-18 15:13:53 +0000671 return;
672 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200673 tprints("{si_signo=");
John Hughes58265892001-10-18 15:13:53 +0000674 printsignal(sip->si_signo);
675 code = xlookup(siginfo_codes, sip->si_code);
676 if (!code) {
677 switch (sip->si_signo) {
678 case SIGTRAP:
679 code = xlookup(sigtrap_codes, sip->si_code);
680 break;
681 case SIGCHLD:
682 code = xlookup(sigchld_codes, sip->si_code);
683 break;
684 case SIGPOLL:
685 code = xlookup(sigpoll_codes, sip->si_code);
686 break;
687 case SIGPROF:
688 code = xlookup(sigprof_codes, sip->si_code);
689 break;
690 case SIGILL:
691 code = xlookup(sigill_codes, sip->si_code);
692 break;
693#ifdef SIGEMT
694 case SIGEMT:
695 code = xlookup(sigemt_codes, sip->si_code);
696 break;
697#endif
698 case SIGFPE:
699 code = xlookup(sigfpe_codes, sip->si_code);
700 break;
701 case SIGSEGV:
702 code = xlookup(sigsegv_codes, sip->si_code);
703 break;
704 case SIGBUS:
705 code = xlookup(sigbus_codes, sip->si_code);
706 break;
707 }
708 }
709 if (code)
710 tprintf(", si_code=%s", code);
711 else
712 tprintf(", si_code=%#x", sip->si_code);
713#ifdef SI_NOINFO
714 if (sip->si_code != SI_NOINFO)
715#endif
716 {
717 if (sip->si_errno) {
718 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
719 tprintf(", si_errno=%d", sip->si_errno);
720 else
721 tprintf(", si_errno=%s",
722 errnoent[sip->si_errno]);
723 }
724#ifdef SI_FROMUSER
725 if (SI_FROMUSER(sip)) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000726 tprintf(", si_pid=%lu, si_uid=%lu",
727 (unsigned long) sip->si_pid,
728 (unsigned long) sip->si_uid);
John Hughes58265892001-10-18 15:13:53 +0000729 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000730#ifdef SI_USER
731 case SI_USER:
732 break;
733#endif
734#ifdef SI_TKILL
735 case SI_TKILL:
736 break;
737#endif
John Hughes58265892001-10-18 15:13:53 +0000738#ifdef SI_TIMER
739 case SI_TIMER:
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000740 tprintf(", si_value=%d", sip->si_int);
John Hughes58265892001-10-18 15:13:53 +0000741 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000742#endif
743#ifdef LINUX
744 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000745 if (!sip->si_ptr)
746 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000747 if (!verbose)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200748 tprints(", ...");
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000749 else
750 tprintf(", si_value={int=%u, ptr=%#lx}",
751 sip->si_int,
752 (unsigned long) sip->si_ptr);
753 break;
754#endif
John Hughes58265892001-10-18 15:13:53 +0000755 }
John Hughes58265892001-10-18 15:13:53 +0000756 }
757 else
758#endif /* SI_FROMUSER */
759 {
760 switch (sip->si_signo) {
761 case SIGCHLD:
762 tprintf(", si_pid=%ld, si_status=",
763 (long) sip->si_pid);
764 if (sip->si_code == CLD_EXITED)
765 tprintf("%d", sip->si_status);
766 else
767 printsignal(sip->si_status);
768#if LINUX
769 if (!verbose)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200770 tprints(", ...");
John Hughes58265892001-10-18 15:13:53 +0000771 else
772 tprintf(", si_utime=%lu, si_stime=%lu",
773 sip->si_utime,
774 sip->si_stime);
775#endif
776 break;
777 case SIGILL: case SIGFPE:
778 case SIGSEGV: case SIGBUS:
779 tprintf(", si_addr=%#lx",
780 (unsigned long) sip->si_addr);
781 break;
782 case SIGPOLL:
783 switch (sip->si_code) {
784 case POLL_IN: case POLL_OUT: case POLL_MSG:
785 tprintf(", si_band=%ld",
786 (long) sip->si_band);
787 break;
788 }
789 break;
790#ifdef LINUX
791 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000792 if (sip->si_pid || sip->si_uid)
793 tprintf(", si_pid=%lu, si_uid=%lu",
794 (unsigned long) sip->si_pid,
795 (unsigned long) sip->si_uid);
796 if (!sip->si_ptr)
797 break;
John Hughes58265892001-10-18 15:13:53 +0000798 if (!verbose)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200799 tprints(", ...");
John Hughes58265892001-10-18 15:13:53 +0000800 else {
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000801 tprintf(", si_value={int=%u, ptr=%#lx}",
John Hughes58265892001-10-18 15:13:53 +0000802 sip->si_int,
803 (unsigned long) sip->si_ptr);
804 }
805#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000806
John Hughes58265892001-10-18 15:13:53 +0000807 }
808 }
809 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200810 tprints("}");
John Hughes58265892001-10-18 15:13:53 +0000811}
812
813#endif /* SVR4 || LINUX */
814
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000815#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000816
817int
Denys Vlasenko12014262011-05-30 14:00:14 +0200818sys_sigvec(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000819{
820 struct sigvec sv;
821 long addr;
822
823 if (entering(tcp)) {
824 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200825 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000826 addr = tcp->u_arg[1];
827 } else {
828 addr = tcp->u_arg[2];
829 }
830 if (addr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200831 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000832 else if (!verbose(tcp))
833 tprintf("%#lx", addr);
834 else if (umove(tcp, addr, &sv) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200835 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000836 else {
837 switch ((int) sv.sv_handler) {
838 case (int) SIG_ERR:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200839 tprints("{SIG_ERR}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000840 break;
841 case (int) SIG_DFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200842 tprints("{SIG_DFL}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000843 break;
844 case (int) SIG_IGN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200845 tprints("{SIG_IGN}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000846 break;
847 case (int) SIG_HOLD:
Denys Vlasenko023b7702012-01-18 16:30:47 +0100848 tprints("{SIG_HOLD}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000849 break;
850 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000852 printsigmask(&sv.sv_mask, 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200853 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000854 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200855 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000856 }
857 }
858 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200859 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000860 return 0;
861}
862
863int
Denys Vlasenko12014262011-05-30 14:00:14 +0200864sys_sigpause(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000865{
866 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000867 sigset_t sigm;
868 long_to_sigset(tcp->u_arg[0], &sigm);
869 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000870 }
871 return 0;
872}
873
874int
Denys Vlasenko12014262011-05-30 14:00:14 +0200875sys_sigstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000876{
877 struct sigstack ss;
878 long addr;
879
880 if (entering(tcp))
881 addr = tcp->u_arg[0];
882 else
883 addr = tcp->u_arg[1];
884 if (addr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200885 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000886 else if (umove(tcp, addr, &ss) < 0)
887 tprintf("%#lx", addr);
888 else {
889 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
890 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
891 }
892 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200893 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000894 return 0;
895}
896
897int
Denys Vlasenko12014262011-05-30 14:00:14 +0200898sys_sigcleanup(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899{
900 return 0;
901}
902
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000903#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000904
905#ifndef SVR4
906
907int
Denys Vlasenko12014262011-05-30 14:00:14 +0200908sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000909{
910 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000911 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000912 long_to_sigset(tcp->u_arg[0], &sigm);
913 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000914 }
915 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000916 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000917 long_to_sigset(tcp->u_rval, &sigm);
918 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000919
920 return RVAL_HEX | RVAL_STR;
921 }
922 return 0;
923}
924
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000925#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000926int
Denys Vlasenko12014262011-05-30 14:00:14 +0200927sys_sigblock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000928{
929 return sys_sigsetmask(tcp);
930}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000931#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000932
933#endif /* !SVR4 */
934
935#ifdef HAVE_SIGACTION
936
937#ifdef LINUX
938struct old_sigaction {
939 __sighandler_t __sa_handler;
940 unsigned long sa_mask;
941 unsigned long sa_flags;
942 void (*sa_restorer)(void);
943};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000944#define SA_HANDLER __sa_handler
945#endif /* LINUX */
946
Roland McGratha39c5a12002-12-17 05:10:37 +0000947#ifndef SA_HANDLER
948#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000949#endif
950
951int
Denys Vlasenko12014262011-05-30 14:00:14 +0200952sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953{
954 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +0000955#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +0000956 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000957 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000958#else
959 struct sigaction sa;
960#endif
961
962
963 if (entering(tcp)) {
964 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200965 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000966 addr = tcp->u_arg[1];
967 } else
968 addr = tcp->u_arg[2];
969 if (addr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200970 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000971 else if (!verbose(tcp))
972 tprintf("%#lx", addr);
973 else if (umove(tcp, addr, &sa) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200974 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975 else {
Carlos O'Donell4677c8a2009-09-09 18:13:19 +0000976 /* Architectures using function pointers, like
977 * hppa, may need to manipulate the function pointer
978 * to compute the result of a comparison. However,
979 * the SA_HANDLER function pointer exists only in
980 * the address space of the traced process, and can't
981 * be manipulated by strace. In order to prevent the
982 * compiler from generating code to manipulate
983 * SA_HANDLER we cast the function pointers to long. */
984 if ((long)sa.SA_HANDLER == (long)SIG_ERR)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200985 tprints("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +0000986 else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200987 tprints("{SIG_DFL, ");
Denys Vlasenko023b7702012-01-18 16:30:47 +0100988 else if ((long)sa.SA_HANDLER == (long)SIG_IGN)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200989 tprints("{SIG_IGN, ");
Denys Vlasenko023b7702012-01-18 16:30:47 +0100990 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000991 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Denys Vlasenkobbe29b32012-01-18 15:30:56 +0100992#ifndef LINUX
993 printsigmask(&sa.sa_mask, 0);
994#else
995 long_to_sigset(sa.sa_mask, &sigset);
996 printsigmask(&sigset, 0);
997#endif
998 tprints(", ");
999 printflags(sigact_flags, sa.sa_flags, "SA_???");
1000#ifdef SA_RESTORER
1001 if (sa.sa_flags & SA_RESTORER)
1002 tprintf(", %p", sa.sa_restorer);
1003#endif
1004 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005 }
1006 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001007 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008#ifdef LINUX
1009 else
1010 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1011#endif
1012 return 0;
1013}
1014
1015int
Denys Vlasenko12014262011-05-30 14:00:14 +02001016sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001017{
1018 if (entering(tcp)) {
1019 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001020 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001022 case (long) SIG_ERR:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001023 tprints("SIG_ERR");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001024 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001025 case (long) SIG_DFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001026 tprints("SIG_DFL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001027 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001028 case (long) SIG_IGN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001029 tprints("SIG_IGN");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001030 break;
1031 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032 tprintf("%#lx", tcp->u_arg[1]);
1033 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001034 return 0;
1035 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001036 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001037 switch (tcp->u_rval) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001038 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001039 tcp->auxstr = "SIG_ERR"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001040 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001041 tcp->auxstr = "SIG_DFL"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001042 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001043 tcp->auxstr = "SIG_IGN"; break;
1044 default:
1045 tcp->auxstr = NULL;
1046 }
1047 return RVAL_HEX | RVAL_STR;
1048 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001049 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001050}
1051
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001052#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001053int
Denys Vlasenko12014262011-05-30 14:00:14 +02001054sys_sighold(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001055{
1056 if (entering(tcp)) {
1057 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001058 }
1059 return 0;
1060}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001061#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001062
1063#endif /* HAVE_SIGACTION */
1064
1065#ifdef LINUX
1066
1067int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001068sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001069{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001070#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001071 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001072 struct pt_regs regs;
1073 struct sigcontext_struct sc;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001074 sigset_t sigm;
Roland McGrath0f87c492003-06-03 23:29:04 +00001075 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1076 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001077 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1078 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001079 long_to_sigset(sc.oldmask, &sigm);
Andreas Schwaba7920a82012-01-17 17:56:44 +01001080 tprints(sprintsigmask(") (mask ", &sigm, 0));
Roland McGrath0f87c492003-06-03 23:29:04 +00001081 }
1082 return 0;
1083#elif defined(S390) || defined(S390X)
Roland McGrath0f87c492003-06-03 23:29:04 +00001084 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001085 long usp;
1086 struct sigcontext_struct sc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001087 if (upeek(tcp, PT_GPR15, &usp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001088 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001089 if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &sc) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001090 return 0;
Andreas Schwaba7920a82012-01-17 17:56:44 +01001091 tprints(sprintsigmask(") (mask ", (sigset_t *)&sc.oldmask[0], 0));
Roland McGrath0f87c492003-06-03 23:29:04 +00001092 }
1093 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001094#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001095 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001096 struct sigcontext_struct sc;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001097 /* Note: on i386, sc is followed on stack by struct fpstate
1098 * and after it an additional u32 extramask[1] which holds
1099 * upper half of the mask. We can fetch it there
1100 * if/when we'd want to display the full mask...
1101 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001102 sigset_t sigm;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001103 if (umove(tcp, i386_regs.esp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001104 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001105 long_to_sigset(sc.oldmask, &sigm);
1106 tprints(sprintsigmask(") (mask ", &sigm, 0));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001107 }
1108 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001109#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001110 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001111 struct sigcontext sc;
1112 long sp;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001113 sigset_t sigm;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001114 /* offset of sigcontext in the kernel's sigframe structure: */
1115# define SIGFRAME_SC_OFFSET 0x90
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001116 if (upeek(tcp, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001117 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001118 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001119 return 0;
Denys Vlasenkod9560c12011-08-19 17:41:28 +02001120 sigemptyset(&sigm);
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001121 memcpy(&sigm, &sc.sc_mask, NSIG / 8);
Andreas Schwaba7920a82012-01-17 17:56:44 +01001122 tprints(sprintsigmask(") (mask ", &sigm, 0));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001123 }
1124 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001125#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +00001126 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001127 long esp;
1128 struct sigcontext_struct sc;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001129 sigset_t sigm;
1130 if (upeek(tcp, sizeof(unsigned long) * PT_R1, &esp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001131 return 0;
Andreas Schwabedb39342010-02-23 00:18:51 +01001132 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +02001133#ifdef POWERPC64
1134 if (current_personality == 0)
1135 esp += 128;
1136 else
1137 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +01001138#else
1139 esp += 64;
1140#endif
Roland McGrath0f87c492003-06-03 23:29:04 +00001141 if (umove(tcp, esp, &sc) < 0)
1142 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001143 long_to_sigset(sc.oldmask, &sigm);
Andreas Schwaba7920a82012-01-17 17:56:44 +01001144 tprints(sprintsigmask(") (mask ", &sigm, 0));
Roland McGrath0f87c492003-06-03 23:29:04 +00001145 }
1146 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001147#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001148 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001149 long usp;
1150 struct sigcontext sc;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001151 sigset_t sigm;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001152 if (upeek(tcp, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001153 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001154 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001155 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001156 long_to_sigset(sc.sc_mask, &sigm);
Andreas Schwaba7920a82012-01-17 17:56:44 +01001157 tprints(sprintsigmask(") (mask ", &sigm, 0));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001158 }
1159 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001160#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001161 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001162 long fp;
1163 struct sigcontext_struct sc;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001164 sigset_t sigm;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001165 if (upeek(tcp, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001166 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001167 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001168 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001169 long_to_sigset(sc.sc_mask, &sigm);
Andreas Schwaba7920a82012-01-17 17:56:44 +01001170 tprints(sprintsigmask(") (mask ", &sigm, 0));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001171 }
1172 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001173#elif defined (SPARC) || defined (SPARC64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001174 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001175 long i1;
1176 struct pt_regs regs;
1177 m_siginfo_t si;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001178 sigset_t sigm;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001179 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1180 perror("sigreturn: PTRACE_GETREGS");
1181 return 0;
1182 }
Mike Frysinger8566c502009-10-12 11:05:14 -04001183 i1 = regs.u_regs[U_REG_O1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001184 if (umove(tcp, i1, &si) < 0) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001185 perror("sigreturn: umove");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001186 return 0;
1187 }
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001188 long_to_sigset(si.si_mask, &sigm);
Andreas Schwaba7920a82012-01-17 17:56:44 +01001189 tprints(sprintsigmask(") (mask ", &sigm, 0));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001190 }
1191 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001192#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001193 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1194 sigreturn. */
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001195 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001196 long sp;
1197 struct ucontext uc;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001198 sigset_t sigm;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001199 if (upeek(tcp, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001200 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001201 /* There are six words followed by a 128-byte siginfo. */
1202 sp = sp + 6 * 4 + 128;
1203 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001204 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001205 long_to_sigset(*(long *) &uc.uc_sigmask, &sigm);
Andreas Schwaba7920a82012-01-17 17:56:44 +01001206 tprints(sprintsigmask(") (mask ", &sigm, 0));
Roland McGrath542c2c62008-05-20 01:11:56 +00001207 }
1208 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001209#elif defined(MIPS)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001210 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001211 long sp;
1212 struct pt_regs regs;
1213 m_siginfo_t si;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001214 sigset_t sigm;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001215 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1216 perror("sigreturn: PTRACE_GETREGS");
1217 return 0;
1218 }
Roland McGrath576b7842007-11-04 00:00:00 +00001219 sp = regs.regs[29];
1220 if (umove(tcp, sp, &si) < 0)
Denys Vlasenkofacd45b2011-06-09 01:22:10 +02001221 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001222 long_to_sigset(si.si_mask, &sigm);
Andreas Schwaba7920a82012-01-17 17:56:44 +01001223 tprints(sprintsigmask(") (mask ", &sigm, 0));
Wichert Akkermanf90da011999-10-31 21:15:38 +00001224 }
1225 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001226#elif defined(CRISV10) || defined(CRISV32)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001227 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001228 struct sigcontext sc;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001229 long regs[PT_MAX+1];
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001230 sigset_t sigm;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001231 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1232 perror("sigreturn: PTRACE_GETREGS");
1233 return 0;
1234 }
1235 if (umove(tcp, regs[PT_USP], &sc) < 0)
1236 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001237 long_to_sigset(sc.oldmask, &sigm);
Andreas Schwaba7920a82012-01-17 17:56:44 +01001238 tprints(sprintsigmask(") (mask ", &sigm, 0));
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001239 }
1240 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -05001241#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -05001242 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001243 struct ucontext uc;
1244 long sp;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001245 sigset_t sigm;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001246
1247 /* offset of ucontext in the kernel's sigframe structure */
1248# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo)
Chris Metcalfc8c66982009-12-28 10:00:15 -05001249 if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0)
1250 return 0;
1251 if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1252 return 0;
Denys Vlasenkod9560c12011-08-19 17:41:28 +02001253 sigemptyset(&sigm);
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001254 memcpy(&sigm, &uc.uc_sigmask, NSIG / 8);
Andreas Schwaba7920a82012-01-17 17:56:44 +01001255 tprints(sprintsigmask(") (mask ", &sigm, 0));
Chris Metcalfc8c66982009-12-28 10:00:15 -05001256 }
1257 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001258#elif defined(MICROBLAZE)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001259 /* TODO: Verify that this is correct... */
1260 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001261 struct sigcontext sc;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001262 long sp;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001263 sigset_t sigm;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001264 /* Read r1, the stack pointer. */
1265 if (upeek(tcp, 1 * 4, &sp) < 0)
1266 return 0;
1267 if (umove(tcp, sp, &sc) < 0)
1268 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +01001269 long_to_sigset(sc.oldmask, &sigm);
Andreas Schwaba7920a82012-01-17 17:56:44 +01001270 tprints(sprintsigmask(") (mask ", &sigm, 0));
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001271 }
1272 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001273#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001274#warning No sys_sigreturn() for this architecture
1275#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001276 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001277#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001278}
1279
1280int
Denys Vlasenko12014262011-05-30 14:00:14 +02001281sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001282{
1283 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001284 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001285 long_to_sigset(tcp->u_rval, &sigm);
1286 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001287 }
1288 return RVAL_HEX | RVAL_STR;
1289}
1290
1291int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001292sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001293{
1294 if (entering(tcp)) {
1295 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001296 long_to_sigset(tcp->u_arg[2], &sigm);
Nate Sammons4a121431999-04-06 01:19:39 +00001297 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298 }
1299 return 0;
1300}
1301
1302#endif /* LINUX */
1303
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001304#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305
1306int
Denys Vlasenko12014262011-05-30 14:00:14 +02001307sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308{
1309 sigset_t sigset;
1310
1311 if (entering(tcp)) {
1312 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001313 tprints("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001315 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001316 }
1317 return 0;
1318}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001319#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001320static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001321 { UC_SIGMASK, "UC_SIGMASK" },
1322 { UC_STACK, "UC_STACK" },
1323 { UC_CPU, "UC_CPU" },
1324#ifdef UC_FPU
1325 { UC_FPU, "UC_FPU" },
1326#endif
1327#ifdef UC_INTR
1328 { UC_INTR, "UC_INTR" },
1329#endif
1330 { 0, NULL },
1331};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001332#endif /* !FREEBSD */
1333#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001335#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001336#if defined LINUX && !defined SS_ONSTACK
1337#define SS_ONSTACK 1
1338#define SS_DISABLE 2
1339#if __GLIBC_MINOR__ == 0
1340typedef struct
1341{
1342 __ptr_t ss_sp;
1343 int ss_flags;
1344 size_t ss_size;
1345} stack_t;
1346#endif
1347#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001348#ifdef FREEBSD
1349#define stack_t struct sigaltstack
1350#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001351
Roland McGrathd9f816f2004-09-04 03:39:20 +00001352static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001353 { SS_ONSTACK, "SS_ONSTACK" },
1354 { SS_DISABLE, "SS_DISABLE" },
1355 { 0, NULL },
1356};
1357#endif
1358
1359#ifdef SVR4
1360static void
Denys Vlasenko12014262011-05-30 14:00:14 +02001361printcontext(struct tcb *tcp, ucontext_t *ucp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001362{
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001363 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001364 if (!abbrev(tcp)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001365 tprints("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001366 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001367 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1368 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001369 tprints("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001370 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001371 if (!abbrev(tcp)) {
1372 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1373 (unsigned long) ucp->uc_stack.ss_sp,
1374 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001375 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001376 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001377 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001378 tprints(", ...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001379}
1380
1381int
Denys Vlasenko12014262011-05-30 14:00:14 +02001382sys_getcontext(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001383{
1384 ucontext_t uc;
1385
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001386 if (exiting(tcp)) {
1387 if (tcp->u_error)
1388 tprintf("%#lx", tcp->u_arg[0]);
1389 else if (!tcp->u_arg[0])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001390 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001391 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001392 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 else
1394 printcontext(tcp, &uc);
1395 }
1396 return 0;
1397}
1398
1399int
Denys Vlasenko12014262011-05-30 14:00:14 +02001400sys_setcontext(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001401{
1402 ucontext_t uc;
1403
1404 if (entering(tcp)) {
1405 if (!tcp->u_arg[0])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001406 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001407 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001408 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409 else
1410 printcontext(tcp, &uc);
1411 }
1412 else {
1413 tcp->u_rval = tcp->u_error = 0;
1414 if (tcp->u_arg[0] == 0)
1415 return 0;
1416 return RVAL_NONE;
1417 }
1418 return 0;
1419}
1420
1421#endif /* SVR4 */
1422
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001423#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424
1425static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001426print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001427{
1428 stack_t ss;
1429 if (umove(tcp, addr, &ss) < 0)
1430 return -1;
1431 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001432 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1434 return 0;
1435}
1436
1437int
Denys Vlasenko12014262011-05-30 14:00:14 +02001438sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001439{
1440 if (entering(tcp)) {
1441 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001442 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001443 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1444 return -1;
1445 }
1446 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001447 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001448 if (tcp->u_arg[1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001449 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001450 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1451 return -1;
1452 }
1453 return 0;
1454}
1455#endif
1456
1457#ifdef HAVE_SIGACTION
1458
1459int
Denys Vlasenko12014262011-05-30 14:00:14 +02001460sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001461{
1462#ifdef ALPHA
1463 if (entering(tcp)) {
1464 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001465 tprints(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001466 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001467 }
1468 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001469 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001470 return RVAL_HEX | RVAL_STR;
1471 }
1472#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001473 if (entering(tcp)) {
1474#ifdef SVR4
1475 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001476 tprints("0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001477 else
1478#endif /* SVR4 */
1479 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001480 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001481 print_sigset(tcp, tcp->u_arg[1], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001482 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001483 }
1484 else {
1485 if (!tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001486 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001487 else if (syserror(tcp))
1488 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001489 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001490 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001491 }
1492#endif /* !ALPHA */
1493 return 0;
1494}
1495
1496#endif /* HAVE_SIGACTION */
1497
1498int
Denys Vlasenko12014262011-05-30 14:00:14 +02001499sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001500{
1501 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001502 long pid = tcp->u_arg[0];
Denys Vlasenkoa7949742011-08-21 17:26:55 +02001503#if SUPPORTED_PERSONALITIES > 1
1504 /* Sign-extend a 32-bit value when that's what it is. */
Roland McGrath4d7ed022008-05-20 01:43:09 +00001505 if (personality_wordsize[current_personality] < sizeof pid)
1506 pid = (long) (int) pid;
Denys Vlasenkoa7949742011-08-21 17:26:55 +02001507#endif
Roland McGrath4d7ed022008-05-20 01:43:09 +00001508 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001509 }
1510 return 0;
1511}
1512
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001513#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001514int
Denys Vlasenko12014262011-05-30 14:00:14 +02001515sys_killpg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001516{
1517 return sys_kill(tcp);
1518}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001519#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001520
Roland McGrath8ffc3522003-07-09 09:47:49 +00001521#ifdef LINUX
1522int
Denys Vlasenko12014262011-05-30 14:00:14 +02001523sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001524{
1525 if (entering(tcp)) {
1526 tprintf("%ld, %ld, %s",
1527 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1528 }
1529 return 0;
1530}
1531#endif
1532
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001533int
Denys Vlasenko12014262011-05-30 14:00:14 +02001534sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001535{
1536 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001537
1538 if (exiting(tcp)) {
1539 if (syserror(tcp))
1540 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001541 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001542 tprints("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001543 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001544 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001545 }
1546 return 0;
1547}
1548
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001549#ifdef SVR4
Denys Vlasenko12014262011-05-30 14:00:14 +02001550int sys_sigwait(struct tcb *tcp)
John Hughes42162082001-10-18 14:48:26 +00001551{
1552 sigset_t sigset;
1553
1554 if (entering(tcp)) {
1555 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001556 tprints("[?]");
John Hughes42162082001-10-18 14:48:26 +00001557 else
1558 printsigmask(&sigset, 0);
1559 }
1560 else {
1561 if (!syserror(tcp)) {
1562 tcp->auxstr = signalent[tcp->u_rval];
1563 return RVAL_DECIMAL | RVAL_STR;
1564 }
1565 }
1566 return 0;
1567}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001568#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001569
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001570#ifdef LINUX
1571
Denys Vlasenko12014262011-05-30 14:00:14 +02001572int
1573sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001574{
1575 sigset_t sigset;
1576
Nate Sammons4a121431999-04-06 01:19:39 +00001577 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001578 if (entering(tcp)) {
1579 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001580 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001581 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001582 tprints("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001583 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001584 tprintf("%#lx, ", tcp->u_arg[1]);
1585 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001586 printsigmask(&sigset, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001587 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001588 }
1589 }
1590 else {
1591 if (!tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001592 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593 else if (syserror(tcp))
1594 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001595 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001596 tprints("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597 else
Nate Sammons4a121431999-04-06 01:19:39 +00001598 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001599 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001600 }
1601 return 0;
1602}
1603
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001604
1605/* Structure describing the action to be taken when a signal arrives. */
1606struct new_sigaction
1607{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001608 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001609 unsigned long sa_flags;
1610 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001611 /* Kernel treats sa_mask as an array of longs. */
1612 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1613};
1614/* Same for i386-on-x86_64 and similar cases */
1615struct new_sigaction32
1616{
1617 uint32_t __sa_handler;
1618 uint32_t sa_flags;
1619 uint32_t sa_restorer;
1620 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621};
1622
1623
Roland McGrath5f206812008-08-20 01:59:40 +00001624int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001625sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001626{
1627 struct new_sigaction sa;
1628 sigset_t sigset;
1629 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001630 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631
1632 if (entering(tcp)) {
1633 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001634 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001635 addr = tcp->u_arg[1];
1636 } else
1637 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001638
1639 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001640 tprints("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001641 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001643 if (!verbose(tcp)) {
1644 tprintf("%#lx", addr);
1645 goto after_sa;
1646 }
1647#if SUPPORTED_PERSONALITIES > 1
1648 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1649 && personality_wordsize[current_personality] == 4
1650 ) {
1651 struct new_sigaction32 sa32;
1652 r = umove(tcp, addr, &sa32);
1653 if (r >= 0) {
1654 memset(&sa, 0, sizeof(sa));
1655 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1656 sa.sa_flags = sa32.sa_flags;
1657 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1658 /* Kernel treats sa_mask as an array of longs.
1659 * For 32-bit process, "long" is uint32_t, thus, for example,
1660 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1661 * But for (64-bit) kernel, 32th bit in sa_mask is
1662 * 32th bit in 0th (64-bit) long!
1663 * For little-endian, it's the same.
1664 * For big-endian, we swap 32-bit words.
1665 */
1666 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1667 }
1668 } else
1669#endif
1670 {
1671 r = umove(tcp, addr, &sa);
1672 }
1673 if (r < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001674 tprints("{...}");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001675 goto after_sa;
1676 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001677 /* Architectures using function pointers, like
1678 * hppa, may need to manipulate the function pointer
1679 * to compute the result of a comparison. However,
1680 * the SA_HANDLER function pointer exists only in
1681 * the address space of the traced process, and can't
1682 * be manipulated by strace. In order to prevent the
1683 * compiler from generating code to manipulate
1684 * SA_HANDLER we cast the function pointers to long. */
1685 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001686 tprints("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001687 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001688 tprints("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001689 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001690 tprints("{SIG_IGN, ");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001691 else
1692 tprintf("{%#lx, ", (long) sa.__sa_handler);
1693 /* Questionable code below.
1694 * Kernel won't handle sys_rt_sigaction
1695 * with wrong sigset size (just returns EINVAL)
1696 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
1697 * and we always use smaller memcpy. */
1698 sigemptyset(&sigset);
1699#ifdef LINUXSPARC
1700 if (tcp->u_arg[4] <= sizeof(sigset))
1701 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1702#else
1703 if (tcp->u_arg[3] <= sizeof(sigset))
1704 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1705#endif
1706 else
1707 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1708 printsigmask(&sigset, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001709 tprints(", ");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001710 printflags(sigact_flags, sa.sa_flags, "SA_???");
1711#ifdef SA_RESTORER
1712 if (sa.sa_flags & SA_RESTORER)
1713 tprintf(", %p", sa.sa_restorer);
1714#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001715 tprints("}");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001716
1717 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001718 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001719 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001720 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001721#ifdef LINUXSPARC
1722 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1723#elif defined(ALPHA)
1724 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1725#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001726 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001727#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001728 return 0;
1729}
1730
Denys Vlasenko1d632462009-04-14 12:51:00 +00001731int
1732sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001733{
1734 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001735
1736 if (exiting(tcp)) {
1737 if (syserror(tcp))
1738 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001739 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1740 &sigset, tcp->u_arg[1]) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001741 tprints("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001742 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001743 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001744 }
1745 return 0;
1746}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001747
1748int
1749sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001750{
1751 if (entering(tcp)) {
1752 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001753 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001754 tprints("[?]");
Nate Sammons4a121431999-04-06 01:19:39 +00001755 else
1756 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001757 }
1758 return 0;
1759}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001760
1761int
1762sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001763{
1764 if (entering(tcp)) {
1765 siginfo_t si;
1766 tprintf("%lu, ", tcp->u_arg[0]);
1767 printsignal(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001768 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001769 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1770 tprintf("%#lx", tcp->u_arg[2]);
1771 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00001772 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001773 }
1774 return 0;
1775}
1776
Denys Vlasenko1d632462009-04-14 12:51:00 +00001777int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001778{
1779 if (entering(tcp)) {
1780 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001781
Roland McGratha39c5a12002-12-17 05:10:37 +00001782 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00001783 &sigset, tcp->u_arg[3]) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001784 tprints("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001785 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001786 printsigmask(&sigset, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001787 tprints(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001788 /* This is the only "return" parameter, */
1789 if (tcp->u_arg[1] != 0)
1790 return 0;
1791 /* ... if it's NULL, can decode all on entry */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001792 tprints("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001793 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001794 else if (tcp->u_arg[1] != 0) {
1795 /* syscall exit, and u_arg[1] wasn't NULL */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001796 if (syserror(tcp))
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001797 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001798 else {
1799 siginfo_t si;
1800 if (umove(tcp, tcp->u_arg[1], &si) < 0)
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001801 tprintf("%#lx, ", tcp->u_arg[1]);
1802 else {
Denys Vlasenkof535b542009-01-13 18:30:55 +00001803 printsiginfo(&si, verbose(tcp));
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001804 tprints(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001805 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001806 }
1807 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001808 else {
1809 /* syscall exit, and u_arg[1] was NULL */
1810 return 0;
1811 }
1812 print_timespec(tcp, tcp->u_arg[2]);
1813 tprintf(", %d", (int) tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814 return 0;
1815};
1816
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001817int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001818sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001819{
1820 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001821 tprints("<... resuming interrupted call ...>");
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001822 return 0;
1823}
1824
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001825static int
1826do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00001827{
1828 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001829 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001830 tprints(", ");
Roland McGrathf46ccd32007-08-02 01:15:59 +00001831 print_sigset(tcp, tcp->u_arg[1], 1);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00001832 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001833 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001834 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001835 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1836 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00001837 }
1838 return 0;
1839}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001840
1841int
1842sys_signalfd(struct tcb *tcp)
1843{
1844 return do_signalfd(tcp, -1);
1845}
1846
1847int
1848sys_signalfd4(struct tcb *tcp)
1849{
1850 return do_signalfd(tcp, 3);
1851}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001852#endif /* LINUX */