blob: 74e0fd90735da4f9b3e23d5a997f7bc5f8b26111 [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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032 */
33
34#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035#include <sys/user.h>
36#include <fcntl.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037
Wichert Akkerman36915a11999-07-13 15:45:02 +000038#ifdef HAVE_SYS_REG_H
39# include <sys/reg.h>
Wichert Akkermanfaf72222000-02-19 23:59:03 +000040#elif defined(HAVE_LINUX_PTRACE_H)
Denys Vlasenko84703742012-02-25 02:38:52 +010041# undef PTRACE_SYSCALL
Roland McGrathb0acdfd2004-03-01 21:31:02 +000042# ifdef HAVE_STRUCT_IA64_FPREG
43# define ia64_fpreg XXX_ia64_fpreg
44# endif
45# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
46# define pt_all_user_regs XXX_pt_all_user_regs
47# endif
Ali Polatel0b4060f2013-09-24 20:04:32 +030048# ifdef HAVE_STRUCT_PTRACE_PEEKSIGINFO_ARGS
49# define ptrace_peeksiginfo_args XXX_ptrace_peeksiginfo_args
50# endif
Denys Vlasenko84703742012-02-25 02:38:52 +010051# include <linux/ptrace.h>
Ali Polatel0b4060f2013-09-24 20:04:32 +030052# undef ptrace_peeksiginfo_args
Roland McGrathb0acdfd2004-03-01 21:31:02 +000053# undef ia64_fpreg
54# undef pt_all_user_regs
Wichert Akkerman15dea971999-10-06 13:06:34 +000055#endif
Wichert Akkerman36915a11999-07-13 15:45:02 +000056
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000057#ifdef IA64
58# include <asm/ptrace_offsets.h>
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020059#endif
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000060
Denys Vlasenko84703742012-02-25 02:38:52 +010061#if defined(SPARC) || defined(SPARC64) || defined(MIPS)
Roland McGrath576b7842007-11-04 00:00:00 +000062typedef struct {
63 struct pt_regs si_regs;
64 int si_mask;
65} m_siginfo_t;
Roland McGrath30ff45e2003-01-30 20:15:23 +000066#elif defined HAVE_ASM_SIGCONTEXT_H
H.J. Lu35be5812012-04-16 13:00:01 +020067# if !defined(IA64) && !defined(X86_64) && !defined(X32)
Denys Vlasenko84703742012-02-25 02:38:52 +010068# include <asm/sigcontext.h>
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010069# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000070#else /* !HAVE_ASM_SIGCONTEXT_H */
Denys Vlasenkob51f3642013-07-16 12:06:25 +020071# if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
72struct sigcontext {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073 unsigned long sc_mask;
74 unsigned long sc_usp;
75 unsigned long sc_d0;
76 unsigned long sc_d1;
77 unsigned long sc_a0;
78 unsigned long sc_a1;
79 unsigned short sc_sr;
80 unsigned long sc_pc;
81 unsigned short sc_formatvec;
82};
Denys Vlasenkob51f3642013-07-16 12:06:25 +020083# endif /* M68K */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084#endif /* !HAVE_ASM_SIGCONTEXT_H */
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020085
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000086#ifndef NSIG
Denys Vlasenko84703742012-02-25 02:38:52 +010087# warning: NSIG is not defined, using 32
88# define NSIG 32
Dmitry V. Levin38593e92014-02-26 16:51:28 +000089#elif NSIG < 32
90# error: NSIG < 32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091#endif
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020092
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093#ifdef HAVE_SIGACTION
94
Roland McGrath2638cb42002-12-15 23:58:41 +000095/* The libc headers do not define this constant since it should only be
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020096 used by the implementation. So we define it here. */
Dmitry V. Levin5c7f6272014-02-08 00:26:06 +000097#ifndef SA_RESTORER
98# ifdef ASM_SA_RESTORER
99# define SA_RESTORER ASM_SA_RESTORER
Roland McGrath2638cb42002-12-15 23:58:41 +0000100# endif
101#endif
102
Mike Frysingerdd80a872014-08-14 00:30:24 -0400103/* Some arches define this in their headers, but don't actually have it,
Mike Frysingerd632e102014-08-09 09:04:18 -0400104 so we have to delete the define. */
Mike Frysingerdd80a872014-08-14 00:30:24 -0400105#if defined(HPPA) || defined(IA64)
Mike Frysingerd632e102014-08-09 09:04:18 -0400106# undef SA_RESTORER
107#endif
108
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000109#include "xlat/sigact_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000110#include "xlat/sigprocmaskcmds.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000111
112#endif /* HAVE_SIGACTION */
113
Nate Sammonsce780fc1999-03-29 23:23:13 +0000114/* Anonymous realtime signals. */
115/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
116 constant. This is what we want. Otherwise, just use SIGRTMIN. */
117#ifdef SIGRTMIN
118#ifndef __SIGRTMIN
119#define __SIGRTMIN SIGRTMIN
120#define __SIGRTMAX SIGRTMAX /* likewise */
121#endif
122#endif
123
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200124/* Note on the size of sigset_t:
125 *
126 * In glibc, sigset_t is an array with space for 1024 bits (!),
127 * even though all arches supported by Linux have only 64 signals
128 * except MIPS, which has 128. IOW, it is 128 bytes long.
129 *
130 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
131 * However, some old syscall return only 32 lower bits (one word).
132 * Example: sys_sigpending vs sys_rt_sigpending.
133 *
134 * Be aware of this fact when you try to
135 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
136 * - sizeof(sigset_t) is much bigger than you think,
137 * it may overflow tcp->u_arg[] array, and it may try to copy more data
138 * than is really available in <something>.
139 * Similarly,
140 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
141 * may be a bad idea: it'll try to read much more data than needed
142 * to fetch a sigset_t.
143 * Use (NSIG / 8) as a size instead.
144 */
145
Roland McGrathee36ce12004-09-04 03:53:10 +0000146const char *
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000147signame(const int sig)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000148{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000149 static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200150
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000151 if (sig >= 0) {
152 const unsigned int s = sig;
153
154 if (s < nsignals)
155 return signalent[s];
Nate Sammonsce780fc1999-03-29 23:23:13 +0000156#ifdef SIGRTMIN
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000157 if (s >= __SIGRTMIN && s <= __SIGRTMAX) {
158 sprintf(buf, "SIGRT_%u", s - __SIGRTMIN);
159 return buf;
160 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200161#endif
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000162 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200163 sprintf(buf, "%d", sig);
164 return buf;
Nate Sammonsce780fc1999-03-29 23:23:13 +0000165}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000167static unsigned int
168popcount32(const uint32_t *a, unsigned int size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000169{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000170 unsigned int count = 0;
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200171
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000172 for (; size; ++a, --size) {
173 uint32_t x = *a;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000175#ifdef HAVE___BUILTIN_POPCOUNT
176 count += __builtin_popcount(x);
Denys Vlasenkoa8773792013-07-18 20:42:41 +0200177#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000178 for (; x; ++count)
179 x &= x - 1;
Nate Sammons4a121431999-04-06 01:19:39 +0000180#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100182
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000183 return count;
184}
185
186static const char *
187sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
188{
189 /*
190 * The maximum number of signal names to be printed is NSIG * 2 / 3.
191 * Most of signal names have length 7,
192 * average length of signal names is less than 7.
193 * The length of prefix string does not exceed 16.
194 */
195 static char outstr[128 + 8 * (NSIG * 2 / 3)];
196
197 char *s;
198 const uint32_t *mask;
199 uint32_t inverted_mask[NSIG / 32];
200 unsigned int size;
201 int i;
202 char sep;
203
204 s = stpcpy(outstr, prefix);
205
206 mask = sig_mask;
207 /* length of signal mask in 4-byte words */
208 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
209
210 /* check whether 2/3 or more bits are set */
211 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
212 /* show those signals that are NOT in the mask */
213 unsigned int j;
214 for (j = 0; j < size; ++j)
215 inverted_mask[j] = ~mask[j];
216 mask = inverted_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000217 *s++ = '~';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000218 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100219
220 sep = '[';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000221 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
222 ++i;
223 *s++ = sep;
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000224 if ((unsigned) i < nsignals) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000225 s = stpcpy(s, signalent[i] + 3);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000227#ifdef SIGRTMIN
228 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
229 s += sprintf(s, "RT_%u", i - __SIGRTMIN);
230 }
231#endif
232 else {
233 s += sprintf(s, "%u", i);
234 }
235 sep = ' ';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100237 if (sep == '[')
238 *s++ = sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000239 *s++ = ']';
240 *s = '\0';
241 return outstr;
242}
243
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000244#define tprintsigmask_addr(prefix, mask) \
245 tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
Denys Vlasenko75f4e1f2013-07-18 20:37:06 +0200246
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000247#define sprintsigmask_val(prefix, mask) \
248 sprintsigmask_n((prefix), &(mask), sizeof(mask))
249
250#define tprintsigmask_val(prefix, mask) \
251 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000252
253void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200254printsignal(int nr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200256 tprints(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000257}
258
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000259void
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200260print_sigset_addr_len(struct tcb *tcp, long addr, long len)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000261{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000262 char mask[NSIG / 8];
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000263
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200264 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200265 tprints("NULL");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200266 return;
267 }
268 /* Here len is usually equals NSIG / 8 or current_wordsize.
269 * But we code this defensively:
270 */
271 if (len < 0) {
272 bad:
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000273 tprintf("%#lx", addr);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200274 return;
275 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000276 if (len >= NSIG / 8)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200277 len = NSIG / 8;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000278 else
279 len = (len + 3) & ~3;
280
281 if (umoven(tcp, addr, len, mask) < 0)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200282 goto bad;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000283 tprints(sprintsigmask_n("", mask, len));
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000284}
285
John Hughes58265892001-10-18 15:13:53 +0000286#ifndef ILL_ILLOPC
287#define ILL_ILLOPC 1 /* illegal opcode */
288#define ILL_ILLOPN 2 /* illegal operand */
289#define ILL_ILLADR 3 /* illegal addressing mode */
290#define ILL_ILLTRP 4 /* illegal trap */
291#define ILL_PRVOPC 5 /* privileged opcode */
292#define ILL_PRVREG 6 /* privileged register */
293#define ILL_COPROC 7 /* coprocessor error */
294#define ILL_BADSTK 8 /* internal stack error */
295#define FPE_INTDIV 1 /* integer divide by zero */
296#define FPE_INTOVF 2 /* integer overflow */
297#define FPE_FLTDIV 3 /* floating point divide by zero */
298#define FPE_FLTOVF 4 /* floating point overflow */
299#define FPE_FLTUND 5 /* floating point underflow */
300#define FPE_FLTRES 6 /* floating point inexact result */
301#define FPE_FLTINV 7 /* floating point invalid operation */
302#define FPE_FLTSUB 8 /* subscript out of range */
303#define SEGV_MAPERR 1 /* address not mapped to object */
304#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
305#define BUS_ADRALN 1 /* invalid address alignment */
306#define BUS_ADRERR 2 /* non-existant physical address */
307#define BUS_OBJERR 3 /* object specific hardware error */
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000308#define SYS_SECCOMP 1 /* seccomp triggered */
John Hughes58265892001-10-18 15:13:53 +0000309#define TRAP_BRKPT 1 /* process breakpoint */
310#define TRAP_TRACE 2 /* process trace trap */
311#define CLD_EXITED 1 /* child has exited */
312#define CLD_KILLED 2 /* child was killed */
313#define CLD_DUMPED 3 /* child terminated abnormally */
314#define CLD_TRAPPED 4 /* traced child has trapped */
315#define CLD_STOPPED 5 /* child has stopped */
316#define CLD_CONTINUED 6 /* stopped child has continued */
317#define POLL_IN 1 /* data input available */
318#define POLL_OUT 2 /* output buffers available */
319#define POLL_MSG 3 /* input message available */
320#define POLL_ERR 4 /* i/o error */
321#define POLL_PRI 5 /* high priority input available */
322#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000323#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000324#define SI_USER 0 /* sent by kill, sigsend, raise */
325#define SI_QUEUE -1 /* sent by sigqueue */
326#define SI_TIMER -2 /* sent by timer expiration */
327#define SI_MESGQ -3 /* sent by real time mesq state change */
328#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000329#define SI_SIGIO -5 /* sent by SIGIO */
330#define SI_TKILL -6 /* sent by tkill */
Dmitry V. Levinb9d4d212014-03-11 01:57:02 +0000331#define SI_DETHREAD -7 /* sent by execve killing subsidiary threads */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000332#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100333#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000334
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100335#ifndef SI_FROMUSER
336# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
Denys Vlasenko84703742012-02-25 02:38:52 +0100337#endif
John Hughes58265892001-10-18 15:13:53 +0000338
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000339#include "xlat/siginfo_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000340#include "xlat/sigill_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000341#include "xlat/sigfpe_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000342#include "xlat/sigtrap_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000343#include "xlat/sigchld_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000344#include "xlat/sigpoll_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000345#include "xlat/sigprof_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000346
347#ifdef SIGEMT
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000348#include "xlat/sigemt_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000349#endif
350
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000351#include "xlat/sigsegv_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000352#include "xlat/sigbus_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000353
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000354#ifndef SYS_SECCOMP
355# define SYS_SECCOMP 1
356#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000357#include "xlat/sigsys_codes.h"
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000358
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000359static void
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000360printsigsource(const siginfo_t *sip)
361{
362 tprintf(", si_pid=%lu, si_uid=%lu",
363 (unsigned long) sip->si_pid,
364 (unsigned long) sip->si_uid);
365}
366
367static void
368printsigval(const siginfo_t *sip, int verbose)
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000369{
370 if (!verbose)
371 tprints(", ...");
372 else
373 tprintf(", si_value={int=%u, ptr=%#lx}",
374 sip->si_int,
375 (unsigned long) sip->si_ptr);
376}
377
John Hughes58265892001-10-18 15:13:53 +0000378void
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000379printsiginfo(siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000380{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000381 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000382
383 if (sip->si_signo == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200384 tprints("{}");
John Hughes58265892001-10-18 15:13:53 +0000385 return;
386 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200387 tprints("{si_signo=");
John Hughes58265892001-10-18 15:13:53 +0000388 printsignal(sip->si_signo);
389 code = xlookup(siginfo_codes, sip->si_code);
390 if (!code) {
391 switch (sip->si_signo) {
392 case SIGTRAP:
393 code = xlookup(sigtrap_codes, sip->si_code);
394 break;
395 case SIGCHLD:
396 code = xlookup(sigchld_codes, sip->si_code);
397 break;
398 case SIGPOLL:
399 code = xlookup(sigpoll_codes, sip->si_code);
400 break;
401 case SIGPROF:
402 code = xlookup(sigprof_codes, sip->si_code);
403 break;
404 case SIGILL:
405 code = xlookup(sigill_codes, sip->si_code);
406 break;
407#ifdef SIGEMT
408 case SIGEMT:
409 code = xlookup(sigemt_codes, sip->si_code);
410 break;
411#endif
412 case SIGFPE:
413 code = xlookup(sigfpe_codes, sip->si_code);
414 break;
415 case SIGSEGV:
416 code = xlookup(sigsegv_codes, sip->si_code);
417 break;
418 case SIGBUS:
419 code = xlookup(sigbus_codes, sip->si_code);
420 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000421 case SIGSYS:
422 code = xlookup(sigsys_codes, sip->si_code);
423 break;
John Hughes58265892001-10-18 15:13:53 +0000424 }
425 }
426 if (code)
427 tprintf(", si_code=%s", code);
428 else
429 tprintf(", si_code=%#x", sip->si_code);
430#ifdef SI_NOINFO
431 if (sip->si_code != SI_NOINFO)
432#endif
433 {
434 if (sip->si_errno) {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000435 if (sip->si_errno < 0 || (unsigned) sip->si_errno >= nerrnos)
John Hughes58265892001-10-18 15:13:53 +0000436 tprintf(", si_errno=%d", sip->si_errno);
437 else
438 tprintf(", si_errno=%s",
439 errnoent[sip->si_errno]);
440 }
441#ifdef SI_FROMUSER
442 if (SI_FROMUSER(sip)) {
John Hughes58265892001-10-18 15:13:53 +0000443 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000444#ifdef SI_USER
445 case SI_USER:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000446 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000447 break;
448#endif
449#ifdef SI_TKILL
450 case SI_TKILL:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000451 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000452 break;
453#endif
John Hughes58265892001-10-18 15:13:53 +0000454#ifdef SI_TIMER
455 case SI_TIMER:
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000456 tprintf(", si_timerid=%#x, si_overrun=%d",
457 sip->si_timerid, sip->si_overrun);
458 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000459 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000460#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000461 default:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000462 printsigsource(sip);
463 if (sip->si_ptr)
464 printsigval(sip, verbose);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000465 break;
John Hughes58265892001-10-18 15:13:53 +0000466 }
John Hughes58265892001-10-18 15:13:53 +0000467 }
468 else
469#endif /* SI_FROMUSER */
470 {
471 switch (sip->si_signo) {
472 case SIGCHLD:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000473 printsigsource(sip);
474 tprints(", si_status=");
John Hughes58265892001-10-18 15:13:53 +0000475 if (sip->si_code == CLD_EXITED)
476 tprintf("%d", sip->si_status);
477 else
478 printsignal(sip->si_status);
John Hughes58265892001-10-18 15:13:53 +0000479 if (!verbose)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200480 tprints(", ...");
John Hughes58265892001-10-18 15:13:53 +0000481 else
H.J. Lu2bb45812012-04-15 11:17:13 -0700482 tprintf(", si_utime=%llu, si_stime=%llu",
483 (unsigned long long) sip->si_utime,
484 (unsigned long long) sip->si_stime);
John Hughes58265892001-10-18 15:13:53 +0000485 break;
486 case SIGILL: case SIGFPE:
487 case SIGSEGV: case SIGBUS:
488 tprintf(", si_addr=%#lx",
489 (unsigned long) sip->si_addr);
490 break;
491 case SIGPOLL:
492 switch (sip->si_code) {
493 case POLL_IN: case POLL_OUT: case POLL_MSG:
494 tprintf(", si_band=%ld",
495 (long) sip->si_band);
496 break;
497 }
498 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000499#ifdef HAVE_SIGINFO_T_SI_SYSCALL
500 case SIGSYS:
501 tprintf(", si_call_addr=%#lx, si_syscall=%d, si_arch=%u",
502 (unsigned long) sip->si_call_addr,
503 sip->si_syscall, sip->si_arch);
504 break;
505#endif
John Hughes58265892001-10-18 15:13:53 +0000506 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000507 if (sip->si_pid || sip->si_uid)
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000508 printsigsource(sip);
509 if (sip->si_ptr)
510 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000511 }
512 }
513 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200514 tprints("}");
John Hughes58265892001-10-18 15:13:53 +0000515}
516
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100517void
518printsiginfo_at(struct tcb *tcp, long addr)
519{
520 siginfo_t si;
521 if (!addr) {
522 tprints("NULL");
523 return;
524 }
525 if (syserror(tcp)) {
526 tprintf("%#lx", addr);
527 return;
528 }
529 if (umove(tcp, addr, &si) < 0) {
530 tprints("{???}");
531 return;
532 }
533 printsiginfo(&si, verbose(tcp));
534}
535
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536int
Denys Vlasenko12014262011-05-30 14:00:14 +0200537sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538{
539 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000540 tprintsigmask_val("", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541 }
542 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000543 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544 return RVAL_HEX | RVAL_STR;
545 }
546 return 0;
547}
548
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549#ifdef HAVE_SIGACTION
550
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000551struct old_sigaction {
Denys Vlasenko86d94842013-02-08 12:59:13 +0100552 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800553#ifdef MIPS
554 unsigned int sa_flags;
555 void (*__sa_handler)(int);
556 /* Kernel treats sa_mask as an array of longs. */
557 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
558#else
Denys Vlasenko86d94842013-02-08 12:59:13 +0100559 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560 unsigned long sa_mask;
561 unsigned long sa_flags;
562 void (*sa_restorer)(void);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800563#endif /* !MIPS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565
Elliott Hughes458b3f22014-02-28 23:21:35 +0000566struct old_sigaction32 {
567 /* sa_handler may be a libc #define, need to use other name: */
568 uint32_t __sa_handler;
569 uint32_t sa_mask;
570 uint32_t sa_flags;
571 uint32_t sa_restorer;
572};
573
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000574static void
575decode_old_sigaction(struct tcb *tcp, long addr)
576{
577 struct old_sigaction sa;
Elliott Hughes458b3f22014-02-28 23:21:35 +0000578 int r;
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000579
580 if (!addr) {
581 tprints("NULL");
582 return;
583 }
584 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
585 tprintf("%#lx", addr);
586 return;
587 }
Elliott Hughes458b3f22014-02-28 23:21:35 +0000588
589#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
590 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
591 struct old_sigaction32 sa32;
592 r = umove(tcp, addr, &sa32);
593 if (r >= 0) {
594 memset(&sa, 0, sizeof(sa));
595 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
596 sa.sa_flags = sa32.sa_flags;
597 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
598 sa.sa_mask = sa32.sa_mask;
599 }
600 } else
601#endif
602 {
603 r = umove(tcp, addr, &sa);
604 }
605 if (r < 0) {
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000606 tprints("{...}");
607 return;
608 }
609
610 /* Architectures using function pointers, like
611 * hppa, may need to manipulate the function pointer
612 * to compute the result of a comparison. However,
613 * the __sa_handler function pointer exists only in
614 * the address space of the traced process, and can't
615 * be manipulated by strace. In order to prevent the
616 * compiler from generating code to manipulate
617 * __sa_handler we cast the function pointers to long. */
618 if ((long)sa.__sa_handler == (long)SIG_ERR)
619 tprints("{SIG_ERR, ");
620 else if ((long)sa.__sa_handler == (long)SIG_DFL)
621 tprints("{SIG_DFL, ");
622 else if ((long)sa.__sa_handler == (long)SIG_IGN)
623 tprints("{SIG_IGN, ");
624 else
625 tprintf("{%#lx, ", (long) sa.__sa_handler);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800626#ifdef MIPS
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000627 tprintsigmask_addr("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800628#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000629 tprintsigmask_val("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800630#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000631 tprints(", ");
632 printflags(sigact_flags, sa.sa_flags, "SA_???");
633#ifdef SA_RESTORER
634 if (sa.sa_flags & SA_RESTORER)
635 tprintf(", %p", sa.sa_restorer);
636#endif
637 tprints("}");
638}
639
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640int
Denys Vlasenko12014262011-05-30 14:00:14 +0200641sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000643 if (entering(tcp)) {
644 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200645 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000646 decode_old_sigaction(tcp, tcp->u_arg[1]);
647 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000648 } else
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000649 decode_old_sigaction(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650 return 0;
651}
652
653int
Denys Vlasenko12014262011-05-30 14:00:14 +0200654sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655{
656 if (entering(tcp)) {
657 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200658 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000659 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +0000660 case (long) SIG_ERR:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200661 tprints("SIG_ERR");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000662 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000663 case (long) SIG_DFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200664 tprints("SIG_DFL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000665 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000666 case (long) SIG_IGN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200667 tprints("SIG_IGN");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000668 break;
669 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000670 tprintf("%#lx", tcp->u_arg[1]);
671 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000672 return 0;
673 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000674 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000675 switch (tcp->u_rval) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100676 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000677 tcp->auxstr = "SIG_ERR"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100678 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000679 tcp->auxstr = "SIG_DFL"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100680 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000681 tcp->auxstr = "SIG_IGN"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100682 default:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000683 tcp->auxstr = NULL;
684 }
685 return RVAL_HEX | RVAL_STR;
686 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000687 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000688}
689
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690#endif /* HAVE_SIGACTION */
691
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000693sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000694{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000695#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +0000696 if (entering(tcp)) {
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200697 struct arm_sigcontext {
698 unsigned long trap_no;
699 unsigned long error_code;
700 unsigned long oldmask;
701 unsigned long arm_r0;
702 unsigned long arm_r1;
703 unsigned long arm_r2;
704 unsigned long arm_r3;
705 unsigned long arm_r4;
706 unsigned long arm_r5;
707 unsigned long arm_r6;
708 unsigned long arm_r7;
709 unsigned long arm_r8;
710 unsigned long arm_r9;
711 unsigned long arm_r10;
712 unsigned long arm_fp;
713 unsigned long arm_ip;
714 unsigned long arm_sp;
715 unsigned long arm_lr;
716 unsigned long arm_pc;
717 unsigned long arm_cpsr;
718 unsigned long fault_address;
719 };
720 struct arm_ucontext {
721 unsigned long uc_flags;
722 unsigned long uc_link; /* struct ucontext* */
723 /* The next three members comprise stack_t struct: */
724 unsigned long ss_sp; /* void* */
725 unsigned long ss_flags; /* int */
726 unsigned long ss_size; /* size_t */
727 struct arm_sigcontext sc;
728 /* These two members are sigset_t: */
729 unsigned long uc_sigmask[2];
730 /* more fields follow, which we aren't interested in */
731 };
732 struct arm_ucontext uc;
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200733 if (umove(tcp, arm_regs.ARM_sp, &uc) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000734 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000735 /*
736 * Kernel fills out uc.sc.oldmask too when it sets up signal stack,
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200737 * but for sigmask restore, sigreturn syscall uses uc.uc_sigmask instead.
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200738 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000739 tprintsigmask_addr(") (mask ", uc.uc_sigmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000740 }
Roland McGrath0f87c492003-06-03 23:29:04 +0000741#elif defined(S390) || defined(S390X)
Roland McGrath0f87c492003-06-03 23:29:04 +0000742 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200743 long usp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000744 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200745 if (upeek(tcp->pid, PT_GPR15, &usp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000746 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100747 if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &sc) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000748 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000749 tprintsigmask_addr(") (mask ", sc.oldmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000750 }
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200751#elif defined(I386) || defined(X86_64)
752# if defined(X86_64)
753 if (current_personality == 0) /* 64-bit */
754 return 0;
755# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000756 if (entering(tcp)) {
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200757 struct i386_sigcontext_struct {
758 uint16_t gs, __gsh;
759 uint16_t fs, __fsh;
760 uint16_t es, __esh;
761 uint16_t ds, __dsh;
762 uint32_t edi;
763 uint32_t esi;
764 uint32_t ebp;
765 uint32_t esp;
766 uint32_t ebx;
767 uint32_t edx;
768 uint32_t ecx;
769 uint32_t eax;
770 uint32_t trapno;
771 uint32_t err;
772 uint32_t eip;
773 uint16_t cs, __csh;
774 uint32_t eflags;
775 uint32_t esp_at_signal;
776 uint16_t ss, __ssh;
777 uint32_t i387;
778 uint32_t oldmask;
779 uint32_t cr2;
780 };
781 struct i386_fpstate {
782 uint32_t cw;
783 uint32_t sw;
784 uint32_t tag;
785 uint32_t ipoff;
786 uint32_t cssel;
787 uint32_t dataoff;
788 uint32_t datasel;
789 uint8_t st[8][10]; /* 8*10 bytes: FP regs */
790 uint16_t status;
791 uint16_t magic;
792 uint32_t fxsr_env[6];
793 uint32_t mxcsr;
794 uint32_t reserved;
795 uint8_t stx[8][16]; /* 8*16 bytes: FP regs, each padded to 16 bytes */
796 uint8_t xmm[8][16]; /* 8 XMM regs */
797 uint32_t padding1[44];
798 uint32_t padding2[12]; /* union with struct _fpx_sw_bytes */
799 };
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200800 struct {
801 struct i386_sigcontext_struct sc;
802 struct i386_fpstate fp;
803 uint32_t extramask[1];
804 } signal_stack;
805 /* On i386, sc is followed on stack by struct fpstate
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100806 * and after it an additional u32 extramask[1] which holds
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200807 * upper half of the mask.
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100808 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000809 uint32_t sigmask[2];
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200810 if (umove(tcp, *i386_esp_ptr, &signal_stack) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000811 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000812 sigmask[0] = signal_stack.sc.oldmask;
813 sigmask[1] = signal_stack.extramask[0];
814 tprintsigmask_addr(") (mask ", sigmask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000815 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000816#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000817 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200818 struct sigcontext sc;
819 long sp;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000820 /* offset of sigcontext in the kernel's sigframe structure: */
821# define SIGFRAME_SC_OFFSET 0x90
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200822 if (upeek(tcp->pid, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000823 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000824 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000825 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000826 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000827 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000828#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +0000829 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200830 long esp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000831 struct sigcontext sc;
Anton Blanchardce6e33b2013-06-26 15:53:33 +0200832
833 esp = ppc_regs.gpr[1];
834
Andreas Schwabedb39342010-02-23 00:18:51 +0100835 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200836#ifdef POWERPC64
837 if (current_personality == 0)
838 esp += 128;
839 else
840 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +0100841#else
842 esp += 64;
843#endif
Roland McGrath0f87c492003-06-03 23:29:04 +0000844 if (umove(tcp, esp, &sc) < 0)
845 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000846 tprintsigmask_val(") (mask ", sc.oldmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000847 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000848#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000849 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200850 long usp;
851 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200852 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +0000854 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000855 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000856 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000857 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000858#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000859 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200860 long fp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000861 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200862 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000863 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +0000864 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000865 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000866 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000867 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100868#elif defined(SPARC) || defined(SPARC64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200869 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200870 long i1;
Denys Vlasenko56a52982011-06-09 01:36:29 +0200871 m_siginfo_t si;
Denys Vlasenko48e4c1b2013-02-16 08:23:40 +0100872 i1 = sparc_regs.u_regs[U_REG_O1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200873 if (umove(tcp, i1, &si) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100874 perror_msg("sigreturn: umove");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000875 return 0;
876 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000877 tprintsigmask_val(") (mask ", si.si_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000878 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100879#elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +0000880 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
881 sigreturn. */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200882 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200883 long sp;
884 struct ucontext uc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200885 if (upeek(tcp->pid, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000886 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +0000887 /* There are six words followed by a 128-byte siginfo. */
888 sp = sp + 6 * 4 + 128;
889 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000890 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000891 tprintsigmask_val(") (mask ", uc.uc_sigmask);
Roland McGrath542c2c62008-05-20 01:11:56 +0000892 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000893#elif defined(MIPS)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200894 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200895 long sp;
896 struct pt_regs regs;
897 m_siginfo_t si;
Denys Vlasenko56a52982011-06-09 01:36:29 +0200898 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100899 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenko56a52982011-06-09 01:36:29 +0200900 return 0;
901 }
Roland McGrath576b7842007-11-04 00:00:00 +0000902 sp = regs.regs[29];
903 if (umove(tcp, sp, &si) < 0)
Denys Vlasenkofacd45b2011-06-09 01:22:10 +0200904 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000905 tprintsigmask_val(") (mask ", si.si_mask);
Wichert Akkermanf90da011999-10-31 21:15:38 +0000906 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000907#elif defined(CRISV10) || defined(CRISV32)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000908 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200909 struct sigcontext sc;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000910 long regs[PT_MAX+1];
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000911 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100912 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000913 return 0;
914 }
915 if (umove(tcp, regs[PT_USP], &sc) < 0)
916 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000917 tprintsigmask_val(") (mask ", sc.oldmask);
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000918 }
Chris Metcalfc8c66982009-12-28 10:00:15 -0500919#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500920 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200921 struct ucontext uc;
Denys Vlasenko56a52982011-06-09 01:36:29 +0200922
923 /* offset of ucontext in the kernel's sigframe structure */
Chris Metcalf5c0796f2013-05-21 20:25:22 -0400924# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
Chris Metcalf0b99a8a2013-02-05 17:48:33 +0100925 if (umove(tcp, tile_regs.sp + SIGFRAME_UC_OFFSET, &uc) < 0)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500926 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000927 tprintsigmask_val(") (mask ", uc.uc_sigmask);
Chris Metcalfc8c66982009-12-28 10:00:15 -0500928 }
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200929#elif defined(MICROBLAZE)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200930 /* TODO: Verify that this is correct... */
931 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200932 struct sigcontext sc;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200933 long sp;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200934 /* Read r1, the stack pointer. */
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200935 if (upeek(tcp->pid, 1 * 4, &sp) < 0)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200936 return 0;
937 if (umove(tcp, sp, &sc) < 0)
938 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000939 tprintsigmask_val(") (mask ", sc.oldmask);
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200940 }
Chris Zankel8f636ed2013-03-25 10:22:07 -0700941#elif defined(XTENSA)
942 /* Xtensa only has rt_sys_sigreturn */
Vineet Gupta7daacbb2013-08-16 12:47:06 +0530943#elif defined(ARC)
944 /* ARC syscall ABI only supports rt_sys_sigreturn */
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000945#else
Dmitry V. Levinf112d072012-05-15 00:13:59 +0000946# warning No sys_sigreturn() for this architecture
947# warning (no problem, just a reminder :-)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000948#endif
Dmitry V. Levinf112d072012-05-15 00:13:59 +0000949 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000950}
951
952int
Denys Vlasenko12014262011-05-30 14:00:14 +0200953sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000954{
955 if (exiting(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000956 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000957 }
958 return RVAL_HEX | RVAL_STR;
959}
960
961int
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000962sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000963{
964 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000965 tprintsigmask_val("", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000966 }
967 return 0;
968}
969
Denys Vlasenko84703742012-02-25 02:38:52 +0100970#if !defined SS_ONSTACK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000971#define SS_ONSTACK 1
972#define SS_DISABLE 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000973#endif
974
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000975#include "xlat/sigaltstack_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000976
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000977static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200978print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000979{
980 stack_t ss;
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000981 int r;
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000982
983 if (!addr) {
984 tprints("NULL");
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000985 return;
986 }
987
988#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
989 if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
990 struct {
991 uint32_t ss_sp;
992 int32_t ss_flags;
993 uint32_t ss_size;
994 } ss32;
995 r = umove(tcp, addr, &ss32);
996 if (r >= 0) {
997 memset(&ss, 0, sizeof(ss));
998 ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
999 ss.ss_flags = ss32.ss_flags;
1000 ss.ss_size = (unsigned long) ss32.ss_size;
1001 }
1002 } else
1003#endif
1004 {
1005 r = umove(tcp, addr, &ss);
1006 }
1007 if (r < 0) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001008 tprintf("%#lx", addr);
1009 } else {
1010 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1011 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1012 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1013 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001014}
1015
1016int
Denys Vlasenko12014262011-05-30 14:00:14 +02001017sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018{
1019 if (entering(tcp)) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001020 print_stack_t(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021 }
1022 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001023 tprints(", ");
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001024 print_stack_t(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001025 }
1026 return 0;
1027}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001028
1029#ifdef HAVE_SIGACTION
1030
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001031/* "Old" sigprocmask, which operates with word-sized signal masks */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032int
Denys Vlasenko12014262011-05-30 14:00:14 +02001033sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001035# ifdef ALPHA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001036 if (entering(tcp)) {
Mike Frysingerdde045c2012-03-15 00:45:33 -04001037 /*
1038 * Alpha/OSF is different: it doesn't pass in two pointers,
1039 * but rather passes in the new bitmask as an argument and
1040 * then returns the old bitmask. This "works" because we
1041 * only have 64 signals to worry about. If you want more,
1042 * use of the rt_sigprocmask syscall is required.
1043 * Alpha:
1044 * old = osf_sigprocmask(how, new);
1045 * Everyone else:
1046 * ret = sigprocmask(how, &new, &old, ...);
1047 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001048 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001049 tprintsigmask_val(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050 }
1051 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001052 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001053 return RVAL_HEX | RVAL_STR;
1054 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001055# else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001056 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001057 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001058 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001059 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001060 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001061 }
1062 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001063 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001064 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001065 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001066 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001067 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001068# endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001069 return 0;
1070}
1071
1072#endif /* HAVE_SIGACTION */
1073
1074int
Denys Vlasenko12014262011-05-30 14:00:14 +02001075sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001076{
1077 if (entering(tcp)) {
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001078 tprintf("%ld, %s",
1079 widen_to_long(tcp->u_arg[0]),
1080 signame(tcp->u_arg[1])
1081 );
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001082 }
1083 return 0;
1084}
1085
Roland McGrath8ffc3522003-07-09 09:47:49 +00001086int
Denys Vlasenko12014262011-05-30 14:00:14 +02001087sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001088{
1089 if (entering(tcp)) {
1090 tprintf("%ld, %ld, %s",
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001091 widen_to_long(tcp->u_arg[0]),
1092 widen_to_long(tcp->u_arg[1]),
1093 signame(tcp->u_arg[2])
1094 );
Roland McGrath8ffc3522003-07-09 09:47:49 +00001095 }
1096 return 0;
1097}
Roland McGrath8ffc3522003-07-09 09:47:49 +00001098
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099int
Denys Vlasenko12014262011-05-30 14:00:14 +02001100sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001101{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001102 if (exiting(tcp)) {
1103 if (syserror(tcp))
1104 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001105 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001106 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001107 }
1108 return 0;
1109}
1110
Denys Vlasenko12014262011-05-30 14:00:14 +02001111int
1112sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001113{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001114 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001115 if (entering(tcp)) {
1116 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001117 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001118 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1119 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001120 }
1121 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001122 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001123 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001124 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001125 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001126 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001127 }
1128 return 0;
1129}
1130
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001131/* Structure describing the action to be taken when a signal arrives. */
1132struct new_sigaction
1133{
Denys Vlasenko86d94842013-02-08 12:59:13 +01001134 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001135#ifdef MIPS
1136 unsigned int sa_flags;
1137 void (*__sa_handler)(int);
1138#else
Denys Vlasenko86d94842013-02-08 12:59:13 +01001139 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001140 unsigned long sa_flags;
Mike Frysingerdd80a872014-08-14 00:30:24 -04001141# if !defined(ALPHA) && !defined(HPPA) && !defined(IA64)
Denys Vlasenko86d94842013-02-08 12:59:13 +01001142 void (*sa_restorer)(void);
Mike Frysingerdd80a872014-08-14 00:30:24 -04001143# endif /* !ALPHA && !HPPA && !IA64 */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001144#endif /* !MIPS */
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001145 /* Kernel treats sa_mask as an array of longs. */
1146 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1147};
1148/* Same for i386-on-x86_64 and similar cases */
1149struct new_sigaction32
1150{
1151 uint32_t __sa_handler;
1152 uint32_t sa_flags;
1153 uint32_t sa_restorer;
1154 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001155};
1156
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001157static void
1158decode_new_sigaction(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001159{
1160 struct new_sigaction sa;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001161 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001162
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001163 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001164 tprints("NULL");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001165 return;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001166 }
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001167 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001168 tprintf("%#lx", addr);
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001169 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001170 }
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001171#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Denys Vlasenko9fd4f962012-03-19 09:36:42 +01001172 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001173 struct new_sigaction32 sa32;
1174 r = umove(tcp, addr, &sa32);
1175 if (r >= 0) {
1176 memset(&sa, 0, sizeof(sa));
1177 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1178 sa.sa_flags = sa32.sa_flags;
1179 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1180 /* Kernel treats sa_mask as an array of longs.
1181 * For 32-bit process, "long" is uint32_t, thus, for example,
1182 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1183 * But for (64-bit) kernel, 32th bit in sa_mask is
1184 * 32th bit in 0th (64-bit) long!
1185 * For little-endian, it's the same.
1186 * For big-endian, we swap 32-bit words.
1187 */
1188 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1189 }
1190 } else
1191#endif
1192 {
1193 r = umove(tcp, addr, &sa);
1194 }
1195 if (r < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001196 tprints("{...}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001197 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001198 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001199 /* Architectures using function pointers, like
1200 * hppa, may need to manipulate the function pointer
1201 * to compute the result of a comparison. However,
Denys Vlasenko86d94842013-02-08 12:59:13 +01001202 * the __sa_handler function pointer exists only in
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001203 * the address space of the traced process, and can't
1204 * be manipulated by strace. In order to prevent the
1205 * compiler from generating code to manipulate
Denys Vlasenko86d94842013-02-08 12:59:13 +01001206 * __sa_handler we cast the function pointers to long. */
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001207 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001208 tprints("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001209 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001210 tprints("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001211 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001212 tprints("{SIG_IGN, ");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001213 else
1214 tprintf("{%#lx, ", (long) sa.__sa_handler);
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001215 /*
1216 * Sigset size is in tcp->u_arg[4] (SPARC)
1217 * or in tcp->u_arg[3] (all other),
1218 * but kernel won't handle sys_rt_sigaction
1219 * with wrong sigset size (just returns EINVAL instead).
1220 * We just fetch the right size, which is NSIG / 8.
1221 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001222 tprintsigmask_val("", sa.sa_mask);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001223 tprints(", ");
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001224
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001225 printflags(sigact_flags, sa.sa_flags, "SA_???");
1226#ifdef SA_RESTORER
1227 if (sa.sa_flags & SA_RESTORER)
1228 tprintf(", %p", sa.sa_restorer);
1229#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001230 tprints("}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001231}
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001232
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001233int
1234sys_rt_sigaction(struct tcb *tcp)
1235{
1236 if (entering(tcp)) {
1237 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001238 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001239 decode_new_sigaction(tcp, tcp->u_arg[1]);
1240 tprints(", ");
1241 } else {
1242 decode_new_sigaction(tcp, tcp->u_arg[2]);
Denys Vlasenko9472a272013-02-12 11:43:46 +01001243#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001244 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1245#elif defined(ALPHA)
1246 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1247#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001248 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001249#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001250 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001251 return 0;
1252}
1253
Denys Vlasenko1d632462009-04-14 12:51:00 +00001254int
1255sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001256{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001257 if (exiting(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001258 /*
1259 * One of the few syscalls where sigset size (arg[1])
1260 * is allowed to be <= NSIG / 8, not strictly ==.
1261 * This allows non-rt sigpending() syscall
1262 * to reuse rt_sigpending() code in kernel.
1263 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001264 if (syserror(tcp))
1265 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001266 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001267 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1268 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001269 }
1270 return 0;
1271}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001272
1273int
1274sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001275{
1276 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001277 /* NB: kernel requires arg[1] == NSIG / 8 */
1278 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1279 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001280 }
1281 return 0;
1282}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001283
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001284static void
1285print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1286{
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001287 printsignal(sig);
1288 tprints(", ");
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001289 printsiginfo_at(tcp, uinfo);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001290}
1291
Denys Vlasenko1d632462009-04-14 12:51:00 +00001292int
1293sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294{
1295 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001297 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1298 }
1299 return 0;
1300}
1301
1302int
1303sys_rt_tgsigqueueinfo(struct tcb *tcp)
1304{
1305 if (entering(tcp)) {
1306 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1307 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308 }
1309 return 0;
1310}
1311
Denys Vlasenko1d632462009-04-14 12:51:00 +00001312int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001313{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001314 /* NB: kernel requires arg[3] == NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001315 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001316 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001317 tprints(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001318 /* This is the only "return" parameter, */
1319 if (tcp->u_arg[1] != 0)
1320 return 0;
1321 /* ... if it's NULL, can decode all on entry */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001322 tprints("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001323 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001324 else if (tcp->u_arg[1] != 0) {
1325 /* syscall exit, and u_arg[1] wasn't NULL */
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001326 printsiginfo_at(tcp, tcp->u_arg[1]);
1327 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001328 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001329 else {
1330 /* syscall exit, and u_arg[1] was NULL */
1331 return 0;
1332 }
1333 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001334 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001335 return 0;
1336};
1337
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001338int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001339sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001340{
1341 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001342 tprints("<... resuming interrupted call ...>");
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001343 return 0;
1344}
1345
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001346static int
1347do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00001348{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001349 /* NB: kernel requires arg[2] == NSIG / 8 */
Roland McGrathf46ccd32007-08-02 01:15:59 +00001350 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001351 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001352 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001353 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00001354 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001355 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001356 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001357 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1358 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00001359 }
1360 return 0;
1361}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001362
1363int
1364sys_signalfd(struct tcb *tcp)
1365{
1366 return do_signalfd(tcp, -1);
1367}
1368
1369int
1370sys_signalfd4(struct tcb *tcp)
1371{
1372 return do_signalfd(tcp, 3);
1373}