blob: a970355c74057a01bd7a4950630990160bd6abb0 [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 <fcntl.h>
Maarten ter Huurne40c174b2014-10-20 01:02:48 +020036
Dmitry V. Levin5503dd22015-02-13 02:12:14 +000037#include "regs.h"
Dmitry V. Levin7211dbc2015-02-28 12:20:21 +000038#include "ptrace.h"
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000039
Denys Vlasenko84703742012-02-25 02:38:52 +010040#if defined(SPARC) || defined(SPARC64) || defined(MIPS)
Roland McGrath576b7842007-11-04 00:00:00 +000041typedef struct {
42 struct pt_regs si_regs;
43 int si_mask;
44} m_siginfo_t;
Roland McGrath30ff45e2003-01-30 20:15:23 +000045#elif defined HAVE_ASM_SIGCONTEXT_H
H.J. Lu35be5812012-04-16 13:00:01 +020046# if !defined(IA64) && !defined(X86_64) && !defined(X32)
Denys Vlasenko84703742012-02-25 02:38:52 +010047# include <asm/sigcontext.h>
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010048# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000049#else /* !HAVE_ASM_SIGCONTEXT_H */
Denys Vlasenkob51f3642013-07-16 12:06:25 +020050# if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
51struct sigcontext {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052 unsigned long sc_mask;
53 unsigned long sc_usp;
54 unsigned long sc_d0;
55 unsigned long sc_d1;
56 unsigned long sc_a0;
57 unsigned long sc_a1;
58 unsigned short sc_sr;
59 unsigned long sc_pc;
60 unsigned short sc_formatvec;
61};
Denys Vlasenkob51f3642013-07-16 12:06:25 +020062# endif /* M68K */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000063#endif /* !HAVE_ASM_SIGCONTEXT_H */
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020064
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000065#ifndef NSIG
Denys Vlasenko84703742012-02-25 02:38:52 +010066# warning: NSIG is not defined, using 32
67# define NSIG 32
Dmitry V. Levin38593e92014-02-26 16:51:28 +000068#elif NSIG < 32
69# error: NSIG < 32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000070#endif
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020071
Roland McGrath2638cb42002-12-15 23:58:41 +000072/* The libc headers do not define this constant since it should only be
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020073 used by the implementation. So we define it here. */
Dmitry V. Levin5c7f6272014-02-08 00:26:06 +000074#ifndef SA_RESTORER
75# ifdef ASM_SA_RESTORER
76# define SA_RESTORER ASM_SA_RESTORER
Roland McGrath2638cb42002-12-15 23:58:41 +000077# endif
78#endif
79
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +000080/*
81 * Some architectures define SA_RESTORER in their headers,
82 * but do not actually have sa_restorer.
83 *
84 * Some architectures, otherwise, do not define SA_RESTORER in their headers,
85 * but actually have sa_restorer.
86 */
87#ifdef SA_RESTORER
88# if defined HPPA || defined IA64
89# define HAVE_SA_RESTORER 0
90# else
91# define HAVE_SA_RESTORER 1
92# endif
93#else /* !SA_RESTORER */
94# if defined SPARC || defined SPARC64
95# define HAVE_SA_RESTORER 1
96# else
97# define HAVE_SA_RESTORER 0
98# endif
Mike Frysingerd632e102014-08-09 09:04:18 -040099#endif
100
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000101#include "xlat/sigact_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000102#include "xlat/sigprocmaskcmds.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000103
Nate Sammonsce780fc1999-03-29 23:23:13 +0000104/* Anonymous realtime signals. */
105/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
106 constant. This is what we want. Otherwise, just use SIGRTMIN. */
107#ifdef SIGRTMIN
108#ifndef __SIGRTMIN
109#define __SIGRTMIN SIGRTMIN
110#define __SIGRTMAX SIGRTMAX /* likewise */
111#endif
112#endif
113
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200114/* Note on the size of sigset_t:
115 *
116 * In glibc, sigset_t is an array with space for 1024 bits (!),
117 * even though all arches supported by Linux have only 64 signals
118 * except MIPS, which has 128. IOW, it is 128 bytes long.
119 *
120 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
121 * However, some old syscall return only 32 lower bits (one word).
122 * Example: sys_sigpending vs sys_rt_sigpending.
123 *
124 * Be aware of this fact when you try to
125 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
126 * - sizeof(sigset_t) is much bigger than you think,
127 * it may overflow tcp->u_arg[] array, and it may try to copy more data
128 * than is really available in <something>.
129 * Similarly,
130 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
131 * may be a bad idea: it'll try to read much more data than needed
132 * to fetch a sigset_t.
133 * Use (NSIG / 8) as a size instead.
134 */
135
Roland McGrathee36ce12004-09-04 03:53:10 +0000136const char *
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000137signame(const int sig)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000138{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000139 static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200140
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000141 if (sig >= 0) {
142 const unsigned int s = sig;
143
144 if (s < nsignals)
145 return signalent[s];
Nate Sammonsce780fc1999-03-29 23:23:13 +0000146#ifdef SIGRTMIN
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000147 if (s >= __SIGRTMIN && s <= __SIGRTMAX) {
148 sprintf(buf, "SIGRT_%u", s - __SIGRTMIN);
149 return buf;
150 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200151#endif
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000152 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200153 sprintf(buf, "%d", sig);
154 return buf;
Nate Sammonsce780fc1999-03-29 23:23:13 +0000155}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000157static unsigned int
158popcount32(const uint32_t *a, unsigned int size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000160 unsigned int count = 0;
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200161
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000162 for (; size; ++a, --size) {
163 uint32_t x = *a;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000165#ifdef HAVE___BUILTIN_POPCOUNT
166 count += __builtin_popcount(x);
Denys Vlasenkoa8773792013-07-18 20:42:41 +0200167#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000168 for (; x; ++count)
169 x &= x - 1;
Nate Sammons4a121431999-04-06 01:19:39 +0000170#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000171 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100172
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000173 return count;
174}
175
176static const char *
177sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
178{
179 /*
180 * The maximum number of signal names to be printed is NSIG * 2 / 3.
181 * Most of signal names have length 7,
182 * average length of signal names is less than 7.
183 * The length of prefix string does not exceed 16.
184 */
185 static char outstr[128 + 8 * (NSIG * 2 / 3)];
186
187 char *s;
188 const uint32_t *mask;
189 uint32_t inverted_mask[NSIG / 32];
190 unsigned int size;
191 int i;
192 char sep;
193
194 s = stpcpy(outstr, prefix);
195
196 mask = sig_mask;
197 /* length of signal mask in 4-byte words */
198 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
199
200 /* check whether 2/3 or more bits are set */
201 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
202 /* show those signals that are NOT in the mask */
203 unsigned int j;
204 for (j = 0; j < size; ++j)
205 inverted_mask[j] = ~mask[j];
206 mask = inverted_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207 *s++ = '~';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000208 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100209
210 sep = '[';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000211 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
212 ++i;
213 *s++ = sep;
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000214 if ((unsigned) i < nsignals) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000215 s = stpcpy(s, signalent[i] + 3);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000216 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000217#ifdef SIGRTMIN
218 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
219 s += sprintf(s, "RT_%u", i - __SIGRTMIN);
220 }
221#endif
222 else {
223 s += sprintf(s, "%u", i);
224 }
225 sep = ' ';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100227 if (sep == '[')
228 *s++ = sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229 *s++ = ']';
230 *s = '\0';
231 return outstr;
232}
233
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000234#define tprintsigmask_addr(prefix, mask) \
235 tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
Denys Vlasenko75f4e1f2013-07-18 20:37:06 +0200236
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000237#define sprintsigmask_val(prefix, mask) \
238 sprintsigmask_n((prefix), &(mask), sizeof(mask))
239
240#define tprintsigmask_val(prefix, mask) \
241 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000242
243void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200244printsignal(int nr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000245{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200246 tprints(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000247}
248
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000249void
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200250print_sigset_addr_len(struct tcb *tcp, long addr, long len)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000251{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000252 char mask[NSIG / 8];
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000253
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200254 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200255 tprints("NULL");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200256 return;
257 }
258 /* Here len is usually equals NSIG / 8 or current_wordsize.
259 * But we code this defensively:
260 */
261 if (len < 0) {
262 bad:
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000263 tprintf("%#lx", addr);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200264 return;
265 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000266 if (len >= NSIG / 8)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200267 len = NSIG / 8;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000268 else
269 len = (len + 3) & ~3;
270
271 if (umoven(tcp, addr, len, mask) < 0)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200272 goto bad;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000273 tprints(sprintsigmask_n("", mask, len));
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000274}
275
John Hughes58265892001-10-18 15:13:53 +0000276#ifndef ILL_ILLOPC
277#define ILL_ILLOPC 1 /* illegal opcode */
278#define ILL_ILLOPN 2 /* illegal operand */
279#define ILL_ILLADR 3 /* illegal addressing mode */
280#define ILL_ILLTRP 4 /* illegal trap */
281#define ILL_PRVOPC 5 /* privileged opcode */
282#define ILL_PRVREG 6 /* privileged register */
283#define ILL_COPROC 7 /* coprocessor error */
284#define ILL_BADSTK 8 /* internal stack error */
285#define FPE_INTDIV 1 /* integer divide by zero */
286#define FPE_INTOVF 2 /* integer overflow */
287#define FPE_FLTDIV 3 /* floating point divide by zero */
288#define FPE_FLTOVF 4 /* floating point overflow */
289#define FPE_FLTUND 5 /* floating point underflow */
290#define FPE_FLTRES 6 /* floating point inexact result */
291#define FPE_FLTINV 7 /* floating point invalid operation */
292#define FPE_FLTSUB 8 /* subscript out of range */
293#define SEGV_MAPERR 1 /* address not mapped to object */
294#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
295#define BUS_ADRALN 1 /* invalid address alignment */
296#define BUS_ADRERR 2 /* non-existant physical address */
297#define BUS_OBJERR 3 /* object specific hardware error */
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000298#define SYS_SECCOMP 1 /* seccomp triggered */
John Hughes58265892001-10-18 15:13:53 +0000299#define TRAP_BRKPT 1 /* process breakpoint */
300#define TRAP_TRACE 2 /* process trace trap */
301#define CLD_EXITED 1 /* child has exited */
302#define CLD_KILLED 2 /* child was killed */
303#define CLD_DUMPED 3 /* child terminated abnormally */
304#define CLD_TRAPPED 4 /* traced child has trapped */
305#define CLD_STOPPED 5 /* child has stopped */
306#define CLD_CONTINUED 6 /* stopped child has continued */
307#define POLL_IN 1 /* data input available */
308#define POLL_OUT 2 /* output buffers available */
309#define POLL_MSG 3 /* input message available */
310#define POLL_ERR 4 /* i/o error */
311#define POLL_PRI 5 /* high priority input available */
312#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000313#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000314#define SI_USER 0 /* sent by kill, sigsend, raise */
315#define SI_QUEUE -1 /* sent by sigqueue */
316#define SI_TIMER -2 /* sent by timer expiration */
317#define SI_MESGQ -3 /* sent by real time mesq state change */
318#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000319#define SI_SIGIO -5 /* sent by SIGIO */
320#define SI_TKILL -6 /* sent by tkill */
Dmitry V. Levinb9d4d212014-03-11 01:57:02 +0000321#define SI_DETHREAD -7 /* sent by execve killing subsidiary threads */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000322#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100323#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000324
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100325#ifndef SI_FROMUSER
326# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
Denys Vlasenko84703742012-02-25 02:38:52 +0100327#endif
John Hughes58265892001-10-18 15:13:53 +0000328
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000329#include "xlat/siginfo_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000330#include "xlat/sigill_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000331#include "xlat/sigfpe_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000332#include "xlat/sigtrap_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000333#include "xlat/sigchld_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000334#include "xlat/sigpoll_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000335#include "xlat/sigprof_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000336
337#ifdef SIGEMT
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000338#include "xlat/sigemt_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000339#endif
340
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000341#include "xlat/sigsegv_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000342#include "xlat/sigbus_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000343
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000344#ifndef SYS_SECCOMP
345# define SYS_SECCOMP 1
346#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000347#include "xlat/sigsys_codes.h"
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000348
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000349static void
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000350printsigsource(const siginfo_t *sip)
351{
352 tprintf(", si_pid=%lu, si_uid=%lu",
353 (unsigned long) sip->si_pid,
354 (unsigned long) sip->si_uid);
355}
356
357static void
358printsigval(const siginfo_t *sip, int verbose)
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000359{
360 if (!verbose)
361 tprints(", ...");
362 else
363 tprintf(", si_value={int=%u, ptr=%#lx}",
364 sip->si_int,
365 (unsigned long) sip->si_ptr);
366}
367
John Hughes58265892001-10-18 15:13:53 +0000368void
Dmitry V. Levind8890b52015-02-07 15:47:24 +0000369printsiginfo(const siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000370{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000371 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000372
373 if (sip->si_signo == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200374 tprints("{}");
John Hughes58265892001-10-18 15:13:53 +0000375 return;
376 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200377 tprints("{si_signo=");
John Hughes58265892001-10-18 15:13:53 +0000378 printsignal(sip->si_signo);
379 code = xlookup(siginfo_codes, sip->si_code);
380 if (!code) {
381 switch (sip->si_signo) {
382 case SIGTRAP:
383 code = xlookup(sigtrap_codes, sip->si_code);
384 break;
385 case SIGCHLD:
386 code = xlookup(sigchld_codes, sip->si_code);
387 break;
388 case SIGPOLL:
389 code = xlookup(sigpoll_codes, sip->si_code);
390 break;
391 case SIGPROF:
392 code = xlookup(sigprof_codes, sip->si_code);
393 break;
394 case SIGILL:
395 code = xlookup(sigill_codes, sip->si_code);
396 break;
397#ifdef SIGEMT
398 case SIGEMT:
399 code = xlookup(sigemt_codes, sip->si_code);
400 break;
401#endif
402 case SIGFPE:
403 code = xlookup(sigfpe_codes, sip->si_code);
404 break;
405 case SIGSEGV:
406 code = xlookup(sigsegv_codes, sip->si_code);
407 break;
408 case SIGBUS:
409 code = xlookup(sigbus_codes, sip->si_code);
410 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000411 case SIGSYS:
412 code = xlookup(sigsys_codes, sip->si_code);
413 break;
John Hughes58265892001-10-18 15:13:53 +0000414 }
415 }
416 if (code)
417 tprintf(", si_code=%s", code);
418 else
419 tprintf(", si_code=%#x", sip->si_code);
420#ifdef SI_NOINFO
421 if (sip->si_code != SI_NOINFO)
422#endif
423 {
424 if (sip->si_errno) {
Dmitry V. Levinb2f8c772015-02-23 03:10:25 +0000425 tprints(", si_errno=");
426 if ((unsigned) sip->si_errno < nerrnos
427 && errnoent[sip->si_errno])
428 tprints(errnoent[sip->si_errno]);
John Hughes58265892001-10-18 15:13:53 +0000429 else
Dmitry V. Levinb2f8c772015-02-23 03:10:25 +0000430 tprintf("%d", sip->si_errno);
John Hughes58265892001-10-18 15:13:53 +0000431 }
432#ifdef SI_FROMUSER
433 if (SI_FROMUSER(sip)) {
John Hughes58265892001-10-18 15:13:53 +0000434 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000435#ifdef SI_USER
436 case SI_USER:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000437 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000438 break;
439#endif
440#ifdef SI_TKILL
441 case SI_TKILL:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000442 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000443 break;
444#endif
Dmitry V. Levin36ab3d52015-01-13 09:24:04 +0300445#if defined SI_TIMER \
446 && defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
John Hughes58265892001-10-18 15:13:53 +0000447 case SI_TIMER:
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000448 tprintf(", si_timerid=%#x, si_overrun=%d",
449 sip->si_timerid, sip->si_overrun);
450 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000451 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000452#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000453 default:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000454 printsigsource(sip);
455 if (sip->si_ptr)
456 printsigval(sip, verbose);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000457 break;
John Hughes58265892001-10-18 15:13:53 +0000458 }
John Hughes58265892001-10-18 15:13:53 +0000459 }
460 else
461#endif /* SI_FROMUSER */
462 {
463 switch (sip->si_signo) {
464 case SIGCHLD:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000465 printsigsource(sip);
466 tprints(", si_status=");
John Hughes58265892001-10-18 15:13:53 +0000467 if (sip->si_code == CLD_EXITED)
468 tprintf("%d", sip->si_status);
469 else
470 printsignal(sip->si_status);
John Hughes58265892001-10-18 15:13:53 +0000471 if (!verbose)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200472 tprints(", ...");
John Hughes58265892001-10-18 15:13:53 +0000473 else
H.J. Lu2bb45812012-04-15 11:17:13 -0700474 tprintf(", si_utime=%llu, si_stime=%llu",
475 (unsigned long long) sip->si_utime,
476 (unsigned long long) sip->si_stime);
John Hughes58265892001-10-18 15:13:53 +0000477 break;
478 case SIGILL: case SIGFPE:
479 case SIGSEGV: case SIGBUS:
480 tprintf(", si_addr=%#lx",
481 (unsigned long) sip->si_addr);
482 break;
483 case SIGPOLL:
484 switch (sip->si_code) {
485 case POLL_IN: case POLL_OUT: case POLL_MSG:
486 tprintf(", si_band=%ld",
487 (long) sip->si_band);
488 break;
489 }
490 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000491#ifdef HAVE_SIGINFO_T_SI_SYSCALL
492 case SIGSYS:
493 tprintf(", si_call_addr=%#lx, si_syscall=%d, si_arch=%u",
494 (unsigned long) sip->si_call_addr,
495 sip->si_syscall, sip->si_arch);
496 break;
497#endif
John Hughes58265892001-10-18 15:13:53 +0000498 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000499 if (sip->si_pid || sip->si_uid)
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000500 printsigsource(sip);
501 if (sip->si_ptr)
502 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000503 }
504 }
505 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200506 tprints("}");
John Hughes58265892001-10-18 15:13:53 +0000507}
508
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100509void
510printsiginfo_at(struct tcb *tcp, long addr)
511{
512 siginfo_t si;
513 if (!addr) {
514 tprints("NULL");
515 return;
516 }
517 if (syserror(tcp)) {
518 tprintf("%#lx", addr);
519 return;
520 }
521 if (umove(tcp, addr, &si) < 0) {
522 tprints("{???}");
523 return;
524 }
525 printsiginfo(&si, verbose(tcp));
526}
527
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528int
Denys Vlasenko12014262011-05-30 14:00:14 +0200529sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530{
531 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000532 tprintsigmask_val("", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533 }
534 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000535 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536 return RVAL_HEX | RVAL_STR;
537 }
538 return 0;
539}
540
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541#ifdef HAVE_SIGACTION
542
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543struct old_sigaction {
Denys Vlasenko86d94842013-02-08 12:59:13 +0100544 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800545#ifdef MIPS
546 unsigned int sa_flags;
547 void (*__sa_handler)(int);
548 /* Kernel treats sa_mask as an array of longs. */
549 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
550#else
Denys Vlasenko86d94842013-02-08 12:59:13 +0100551 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552 unsigned long sa_mask;
553 unsigned long sa_flags;
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800554#endif /* !MIPS */
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000555#if HAVE_SA_RESTORER
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100556 void (*sa_restorer)(void);
557#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559
Elliott Hughes458b3f22014-02-28 23:21:35 +0000560struct old_sigaction32 {
561 /* sa_handler may be a libc #define, need to use other name: */
562 uint32_t __sa_handler;
563 uint32_t sa_mask;
564 uint32_t sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000565#if HAVE_SA_RESTORER
Elliott Hughes458b3f22014-02-28 23:21:35 +0000566 uint32_t sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100567#endif
Elliott Hughes458b3f22014-02-28 23:21:35 +0000568};
569
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000570static void
571decode_old_sigaction(struct tcb *tcp, long addr)
572{
573 struct old_sigaction sa;
Elliott Hughes458b3f22014-02-28 23:21:35 +0000574 int r;
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000575
576 if (!addr) {
577 tprints("NULL");
578 return;
579 }
580 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
581 tprintf("%#lx", addr);
582 return;
583 }
Elliott Hughes458b3f22014-02-28 23:21:35 +0000584
585#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
586 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
587 struct old_sigaction32 sa32;
588 r = umove(tcp, addr, &sa32);
589 if (r >= 0) {
590 memset(&sa, 0, sizeof(sa));
591 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
592 sa.sa_flags = sa32.sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000593#if HAVE_SA_RESTORER && defined SA_RESTORER
Elliott Hughes458b3f22014-02-28 23:21:35 +0000594 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100595#endif
Elliott Hughes458b3f22014-02-28 23:21:35 +0000596 sa.sa_mask = sa32.sa_mask;
597 }
598 } else
599#endif
600 {
601 r = umove(tcp, addr, &sa);
602 }
603 if (r < 0) {
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000604 tprints("{...}");
605 return;
606 }
607
608 /* Architectures using function pointers, like
609 * hppa, may need to manipulate the function pointer
610 * to compute the result of a comparison. However,
611 * the __sa_handler function pointer exists only in
612 * the address space of the traced process, and can't
613 * be manipulated by strace. In order to prevent the
614 * compiler from generating code to manipulate
615 * __sa_handler we cast the function pointers to long. */
616 if ((long)sa.__sa_handler == (long)SIG_ERR)
617 tprints("{SIG_ERR, ");
618 else if ((long)sa.__sa_handler == (long)SIG_DFL)
619 tprints("{SIG_DFL, ");
620 else if ((long)sa.__sa_handler == (long)SIG_IGN)
621 tprints("{SIG_IGN, ");
622 else
623 tprintf("{%#lx, ", (long) sa.__sa_handler);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800624#ifdef MIPS
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000625 tprintsigmask_addr("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800626#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000627 tprintsigmask_val("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800628#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000629 tprints(", ");
630 printflags(sigact_flags, sa.sa_flags, "SA_???");
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000631#if HAVE_SA_RESTORER && defined SA_RESTORER
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000632 if (sa.sa_flags & SA_RESTORER)
633 tprintf(", %p", sa.sa_restorer);
634#endif
635 tprints("}");
636}
637
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638int
Denys Vlasenko12014262011-05-30 14:00:14 +0200639sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000641 if (entering(tcp)) {
642 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200643 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000644 decode_old_sigaction(tcp, tcp->u_arg[1]);
645 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000646 } else
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000647 decode_old_sigaction(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000648 return 0;
649}
650
651int
Denys Vlasenko12014262011-05-30 14:00:14 +0200652sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653{
654 if (entering(tcp)) {
655 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200656 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +0000658 case (long) SIG_ERR:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200659 tprints("SIG_ERR");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000661 case (long) SIG_DFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200662 tprints("SIG_DFL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000663 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000664 case (long) SIG_IGN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200665 tprints("SIG_IGN");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666 break;
667 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000668 tprintf("%#lx", tcp->u_arg[1]);
669 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000670 return 0;
671 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000672 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000673 switch (tcp->u_rval) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100674 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000675 tcp->auxstr = "SIG_ERR"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100676 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000677 tcp->auxstr = "SIG_DFL"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100678 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000679 tcp->auxstr = "SIG_IGN"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100680 default:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000681 tcp->auxstr = NULL;
682 }
683 return RVAL_HEX | RVAL_STR;
684 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000685 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000686}
687
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688#endif /* HAVE_SIGACTION */
689
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000691sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692{
Dmitry V. Levin5b9b7e12015-03-04 23:05:53 +0000693#if defined AARCH64 || defined ARM
Roland McGrath0f87c492003-06-03 23:29:04 +0000694 if (entering(tcp)) {
Dmitry V. Levin5b9b7e12015-03-04 23:05:53 +0000695# define SIZEOF_STRUCT_SIGINFO 128
Dmitry V. Levin26d16c82015-03-04 22:27:35 +0000696# define SIZEOF_STRUCT_SIGCONTEXT (21 * 4)
697# define OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK (5 * 4 + SIZEOF_STRUCT_SIGCONTEXT)
Dmitry V. Levin5b9b7e12015-03-04 23:05:53 +0000698 const long addr =
699# ifdef AARCH64
700 current_personality == 0 ?
701 (*aarch64_sp_ptr + SIZEOF_STRUCT_SIGINFO +
702 offsetof(struct ucontext, uc_sigmask)) :
703# endif
704 (*arm_sp_ptr +
705 OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000706 tprints("{mask=");
Dmitry V. Levin26d16c82015-03-04 22:27:35 +0000707 print_sigset_addr_len(tcp, addr, NSIG / 8);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000708 tprints("}");
Roland McGrath0f87c492003-06-03 23:29:04 +0000709 }
Roland McGrath0f87c492003-06-03 23:29:04 +0000710#elif defined(S390) || defined(S390X)
Roland McGrath0f87c492003-06-03 23:29:04 +0000711 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200712 long usp;
Dmitry V. Levin085411b2015-03-04 21:40:00 +0000713 long mask[NSIG / 8 / sizeof(long)];
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200714 if (upeek(tcp->pid, PT_GPR15, &usp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000715 return 0;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000716 tprints("{mask=");
717 const long addr = usp + __SIGNAL_FRAMESIZE;
718 if (umove(tcp, addr, &mask) < 0) {
719 tprintf("%#lx", addr);
720 } else {
Dmitry V. Levin085411b2015-03-04 21:40:00 +0000721# ifdef S390
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000722 usp = mask[0];
723 mask[0] = mask[1];
724 mask[1] = usp;
Dmitry V. Levin085411b2015-03-04 21:40:00 +0000725# endif
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000726 tprintsigmask_addr("", mask);
727 }
728 tprints("}");
Roland McGrath0f87c492003-06-03 23:29:04 +0000729 }
Dmitry V. Levin5dd336b2015-02-23 16:18:09 +0000730#elif defined I386 || defined X86_64 || defined X32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731 if (entering(tcp)) {
Dmitry V. Levinccb4fda2015-03-04 12:19:55 +0000732# ifndef I386
733 if (current_personality != 1) {
734 const unsigned long addr =
735 (unsigned long) *x86_64_rsp_ptr +
736 offsetof(struct ucontext, uc_sigmask);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000737 tprints("{mask=");
Dmitry V. Levinccb4fda2015-03-04 12:19:55 +0000738 print_sigset_addr_len(tcp, addr, NSIG / 8);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000739 tprints("}");
Dmitry V. Levinccb4fda2015-03-04 12:19:55 +0000740 return 0;
741 }
742# endif
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000743 /*
744 * On i386, sigcontext is followed on stack by struct fpstate
745 * and after it an additional u32 extramask which holds
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200746 * upper half of the mask.
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100747 */
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000748 struct {
749 uint32_t struct_sigcontext_padding1[20];
750 uint32_t oldmask;
751 uint32_t struct_sigcontext_padding2;
752 uint32_t struct_fpstate_padding[156];
753 uint32_t extramask;
754 } frame;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000755 tprints("{mask=");
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000756 if (umove(tcp, *i386_esp_ptr, &frame) < 0) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000757 tprintf("%#lx", (unsigned long) *i386_esp_ptr);
758 } else {
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000759 uint32_t mask[2] = { frame.oldmask, frame.extramask };
760 tprintsigmask_addr("", mask);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000761 }
762 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000763 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000764#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000765 if (entering(tcp)) {
Dmitry V. Levin1e8a4542015-03-04 12:11:31 +0000766 long addr;
767 if (upeek(tcp->pid, PT_R12, &addr) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000768 return 0;
Dmitry V. Levin1e8a4542015-03-04 12:11:31 +0000769 /* offsetof(struct sigframe, sc) */
770# define OFFSETOF_STRUCT_SIGFRAME_SC 0xA0
771 addr += 16 + OFFSETOF_STRUCT_SIGFRAME_SC +
772 offsetof(struct sigcontext, sc_mask);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000773 tprints("{mask=");
Dmitry V. Levin1e8a4542015-03-04 12:11:31 +0000774 print_sigset_addr_len(tcp, addr, NSIG / 8);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000775 tprints("}");
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000776 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000777#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +0000778 if (entering(tcp)) {
Dmitry V. Levin577be252015-03-04 16:01:47 +0000779 long esp = ppc_regs.gpr[1];
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000780 struct sigcontext sc;
Anton Blanchardce6e33b2013-06-26 15:53:33 +0200781
Andreas Schwabedb39342010-02-23 00:18:51 +0100782 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200783#ifdef POWERPC64
784 if (current_personality == 0)
785 esp += 128;
786 else
Andreas Schwabedb39342010-02-23 00:18:51 +0100787#endif
Dmitry V. Levin577be252015-03-04 16:01:47 +0000788 esp += 64;
789
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000790 tprints("{mask=");
Dmitry V. Levin577be252015-03-04 16:01:47 +0000791 if (umove(tcp, esp, &sc) < 0) {
792 tprintf("%#lx", esp);
793 } else {
794 unsigned long mask[NSIG / 8 / sizeof(long)];
795#ifdef POWERPC64
Dmitry V. Levin67dab702015-03-05 04:29:37 +0000796 mask[0] = sc.oldmask | (sc._unused[3] << 32);
797#else
798 mask[0] = sc.oldmask;
799 mask[1] = sc._unused[3];
Dmitry V. Levin577be252015-03-04 16:01:47 +0000800#endif
Dmitry V. Levin577be252015-03-04 16:01:47 +0000801 tprintsigmask_val("", mask);
802 }
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000803 tprints("}");
Roland McGrath0f87c492003-06-03 23:29:04 +0000804 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000805#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000806 if (entering(tcp)) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000807 long addr;
808 if (upeek(tcp->pid, 4*PT_USP, &addr) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809 return 0;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000810 addr += offsetof(struct sigcontext, sc_mask);
811 tprints("{mask=");
812 print_sigset_addr_len(tcp, addr, NSIG / 8);
813 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000814 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000815#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000816 if (entering(tcp)) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000817 long addr;
818 if (upeek(tcp->pid, REG_FP, &addr) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000819 return 0;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000820 addr += offsetof(struct sigcontext, sc_mask);
821 tprints("{mask=");
822 print_sigset_addr_len(tcp, addr, NSIG / 8);
823 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000824 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100825#elif defined(SPARC) || defined(SPARC64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200826 if (entering(tcp)) {
Dmitry V. Levindb199362015-03-04 17:52:42 +0000827 long fp = sparc_regs.u_regs[U_REG_FP] + sizeof(struct sparc_stackf);
828 struct {
829 m_siginfo_t si;
830 void *fpu_save;
831 long insns[2] __attribute__ ((aligned (8)));
832 unsigned int extramask[NSIG / 8 / sizeof(int) - 1];
833 } frame;
834
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000835 tprints("{mask=");
Dmitry V. Levindb199362015-03-04 17:52:42 +0000836 if (umove(tcp, fp, &frame) < 0) {
837 tprintf("%#lx", fp);
838 } else {
839 unsigned int mask[NSIG / 8 / sizeof(int)];
840
841 mask[0] = frame.si.si_mask;
842 memcpy(mask + 1, frame.extramask, sizeof(frame.extramask));
843 tprintsigmask_val("", mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000844 }
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000845 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000846 }
Dmitry V. Levinfd6d2072015-03-04 20:04:02 +0000847#elif defined MIPS
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200848 if (entering(tcp)) {
Dmitry V. Levinfd6d2072015-03-04 20:04:02 +0000849# if defined LINUX_MIPSO32
850 /*
851 * offsetof(struct sigframe, sf_mask) ==
852 * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct sigcontext)
853 */
854 const long addr = mips_REG_SP + 6 * 4 +
855 sizeof(struct sigcontext);
856# else
857 /*
858 * This decodes rt_sigreturn.
859 * The 64-bit ABIs do not have sigreturn.
860 *
861 * offsetof(struct rt_sigframe, rs_uc) ==
862 * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct siginfo)
863 */
864 const long addr = mips_REG_SP + 6 * 4 + 128 +
865 offsetof(struct ucontext, uc_sigmask);
866# endif
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000867 tprints("{mask=");
Dmitry V. Levinfd6d2072015-03-04 20:04:02 +0000868 print_sigset_addr_len(tcp, addr, NSIG / 8);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000869 tprints("}");
Wichert Akkermanf90da011999-10-31 21:15:38 +0000870 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000871#elif defined(CRISV10) || defined(CRISV32)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000872 if (entering(tcp)) {
873 long regs[PT_MAX+1];
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000874 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100875 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000876 return 0;
877 }
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000878 const long addr = regs[PT_USP] +
879 offsetof(struct sigcontext, oldmask);
880 tprints("{mask=");
881 print_sigset_addr_len(tcp, addr, NSIG / 8);
882 tprints("}");
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000883 }
Chris Metcalfc8c66982009-12-28 10:00:15 -0500884#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500885 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200886 /* offset of ucontext in the kernel's sigframe structure */
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000887# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
888 const long addr = tile_regs.sp + SIGFRAME_UC_OFFSET +
889 offsetof(struct ucontext, uc_sigmask);
890 tprints("{mask=");
891 print_sigset_addr_len(tcp, addr, NSIG / 8);
892 tprints("}");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500893 }
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200894#elif defined(MICROBLAZE)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200895 /* TODO: Verify that this is correct... */
896 if (entering(tcp)) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000897 long addr;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200898 /* Read r1, the stack pointer. */
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000899 if (upeek(tcp->pid, 1 * 4, &addr) < 0)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200900 return 0;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000901 addr += offsetof(struct sigcontext, oldmask);
902 tprints("{mask=");
903 print_sigset_addr_len(tcp, addr, NSIG / 8);
904 tprints("}");
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200905 }
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000906#else
Dmitry V. Levind4689922015-03-04 13:12:06 +0000907# warning sigreturn/rt_sigreturn signal mask decoding is not implemented for this architecture
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000908#endif
Dmitry V. Levinf112d072012-05-15 00:13:59 +0000909 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000910}
911
912int
Denys Vlasenko12014262011-05-30 14:00:14 +0200913sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000914{
915 if (exiting(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000916 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000917 }
918 return RVAL_HEX | RVAL_STR;
919}
920
921int
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000922sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000923{
924 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000925 tprintsigmask_val("", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000926 }
927 return 0;
928}
929
Denys Vlasenko84703742012-02-25 02:38:52 +0100930#if !defined SS_ONSTACK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000931#define SS_ONSTACK 1
932#define SS_DISABLE 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000933#endif
934
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000935#include "xlat/sigaltstack_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000936
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000937static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200938print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000939{
940 stack_t ss;
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000941 int r;
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000942
943 if (!addr) {
944 tprints("NULL");
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000945 return;
946 }
947
948#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
949 if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
950 struct {
951 uint32_t ss_sp;
952 int32_t ss_flags;
953 uint32_t ss_size;
954 } ss32;
955 r = umove(tcp, addr, &ss32);
956 if (r >= 0) {
957 memset(&ss, 0, sizeof(ss));
958 ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
959 ss.ss_flags = ss32.ss_flags;
960 ss.ss_size = (unsigned long) ss32.ss_size;
961 }
962 } else
963#endif
964 {
965 r = umove(tcp, addr, &ss);
966 }
967 if (r < 0) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000968 tprintf("%#lx", addr);
969 } else {
970 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
971 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
972 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
973 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000974}
975
976int
Denys Vlasenko12014262011-05-30 14:00:14 +0200977sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000978{
979 if (entering(tcp)) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000980 print_stack_t(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000981 }
982 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200983 tprints(", ");
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000984 print_stack_t(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000985 }
986 return 0;
987}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000988
989#ifdef HAVE_SIGACTION
990
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200991/* "Old" sigprocmask, which operates with word-sized signal masks */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992int
Denys Vlasenko12014262011-05-30 14:00:14 +0200993sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000994{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200995# ifdef ALPHA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000996 if (entering(tcp)) {
Mike Frysingerdde045c2012-03-15 00:45:33 -0400997 /*
998 * Alpha/OSF is different: it doesn't pass in two pointers,
999 * but rather passes in the new bitmask as an argument and
1000 * then returns the old bitmask. This "works" because we
1001 * only have 64 signals to worry about. If you want more,
1002 * use of the rt_sigprocmask syscall is required.
1003 * Alpha:
1004 * old = osf_sigprocmask(how, new);
1005 * Everyone else:
1006 * ret = sigprocmask(how, &new, &old, ...);
1007 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001009 tprintsigmask_val(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001010 }
1011 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001012 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001013 return RVAL_HEX | RVAL_STR;
1014 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001015# else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001017 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001018 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001019 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001020 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021 }
1022 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001023 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001024 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001025 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001026 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001027 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001028# endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029 return 0;
1030}
1031
1032#endif /* HAVE_SIGACTION */
1033
1034int
Denys Vlasenko12014262011-05-30 14:00:14 +02001035sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001036{
1037 if (entering(tcp)) {
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001038 tprintf("%ld, %s",
1039 widen_to_long(tcp->u_arg[0]),
1040 signame(tcp->u_arg[1])
1041 );
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001042 }
1043 return 0;
1044}
1045
Roland McGrath8ffc3522003-07-09 09:47:49 +00001046int
Denys Vlasenko12014262011-05-30 14:00:14 +02001047sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001048{
1049 if (entering(tcp)) {
1050 tprintf("%ld, %ld, %s",
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001051 widen_to_long(tcp->u_arg[0]),
1052 widen_to_long(tcp->u_arg[1]),
1053 signame(tcp->u_arg[2])
1054 );
Roland McGrath8ffc3522003-07-09 09:47:49 +00001055 }
1056 return 0;
1057}
Roland McGrath8ffc3522003-07-09 09:47:49 +00001058
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001059int
Denys Vlasenko12014262011-05-30 14:00:14 +02001060sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001061{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001062 if (exiting(tcp)) {
1063 if (syserror(tcp))
1064 tprintf("%#lx", tcp->u_arg[0]);
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[0], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001067 }
1068 return 0;
1069}
1070
Denys Vlasenko12014262011-05-30 14:00:14 +02001071int
1072sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001073{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001074 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001075 if (entering(tcp)) {
1076 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001077 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001078 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1079 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001080 }
1081 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001082 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001083 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001084 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001085 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001086 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001087 }
1088 return 0;
1089}
1090
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001091/* Structure describing the action to be taken when a signal arrives. */
1092struct new_sigaction
1093{
Denys Vlasenko86d94842013-02-08 12:59:13 +01001094 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001095#ifdef MIPS
1096 unsigned int sa_flags;
1097 void (*__sa_handler)(int);
1098#else
Denys Vlasenko86d94842013-02-08 12:59:13 +01001099 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001100 unsigned long sa_flags;
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001101#endif /* !MIPS */
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001102#if HAVE_SA_RESTORER
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001103 void (*sa_restorer)(void);
1104#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001105 /* Kernel treats sa_mask as an array of longs. */
1106 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1107};
1108/* Same for i386-on-x86_64 and similar cases */
1109struct new_sigaction32
1110{
1111 uint32_t __sa_handler;
1112 uint32_t sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001113#if HAVE_SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001114 uint32_t sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001115#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001116 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001117};
1118
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001119static void
1120decode_new_sigaction(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001121{
1122 struct new_sigaction sa;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001123 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001124
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001125 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001126 tprints("NULL");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001127 return;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001128 }
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001129 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001130 tprintf("%#lx", addr);
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001131 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001132 }
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001133#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Denys Vlasenko9fd4f962012-03-19 09:36:42 +01001134 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001135 struct new_sigaction32 sa32;
1136 r = umove(tcp, addr, &sa32);
1137 if (r >= 0) {
1138 memset(&sa, 0, sizeof(sa));
1139 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1140 sa.sa_flags = sa32.sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001141#if HAVE_SA_RESTORER && defined SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001142 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001143#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001144 /* Kernel treats sa_mask as an array of longs.
1145 * For 32-bit process, "long" is uint32_t, thus, for example,
1146 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1147 * But for (64-bit) kernel, 32th bit in sa_mask is
1148 * 32th bit in 0th (64-bit) long!
1149 * For little-endian, it's the same.
1150 * For big-endian, we swap 32-bit words.
1151 */
1152 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1153 }
1154 } else
1155#endif
1156 {
1157 r = umove(tcp, addr, &sa);
1158 }
1159 if (r < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001160 tprints("{...}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001161 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001162 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001163 /* Architectures using function pointers, like
1164 * hppa, may need to manipulate the function pointer
1165 * to compute the result of a comparison. However,
Denys Vlasenko86d94842013-02-08 12:59:13 +01001166 * the __sa_handler function pointer exists only in
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001167 * the address space of the traced process, and can't
1168 * be manipulated by strace. In order to prevent the
1169 * compiler from generating code to manipulate
Denys Vlasenko86d94842013-02-08 12:59:13 +01001170 * __sa_handler we cast the function pointers to long. */
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001171 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001172 tprints("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001173 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001174 tprints("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001175 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001176 tprints("{SIG_IGN, ");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001177 else
1178 tprintf("{%#lx, ", (long) sa.__sa_handler);
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001179 /*
1180 * Sigset size is in tcp->u_arg[4] (SPARC)
1181 * or in tcp->u_arg[3] (all other),
1182 * but kernel won't handle sys_rt_sigaction
1183 * with wrong sigset size (just returns EINVAL instead).
1184 * We just fetch the right size, which is NSIG / 8.
1185 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001186 tprintsigmask_val("", sa.sa_mask);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001187 tprints(", ");
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001188
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001189 printflags(sigact_flags, sa.sa_flags, "SA_???");
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001190#if HAVE_SA_RESTORER && defined SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001191 if (sa.sa_flags & SA_RESTORER)
1192 tprintf(", %p", sa.sa_restorer);
1193#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001194 tprints("}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001195}
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001196
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001197int
1198sys_rt_sigaction(struct tcb *tcp)
1199{
1200 if (entering(tcp)) {
1201 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001202 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001203 decode_new_sigaction(tcp, tcp->u_arg[1]);
1204 tprints(", ");
1205 } else {
1206 decode_new_sigaction(tcp, tcp->u_arg[2]);
Denys Vlasenko9472a272013-02-12 11:43:46 +01001207#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001208 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1209#elif defined(ALPHA)
1210 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1211#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001212 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001213#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001214 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001215 return 0;
1216}
1217
Denys Vlasenko1d632462009-04-14 12:51:00 +00001218int
1219sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001220{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221 if (exiting(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001222 /*
1223 * One of the few syscalls where sigset size (arg[1])
1224 * is allowed to be <= NSIG / 8, not strictly ==.
1225 * This allows non-rt sigpending() syscall
1226 * to reuse rt_sigpending() code in kernel.
1227 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228 if (syserror(tcp))
1229 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001230 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001231 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1232 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001233 }
1234 return 0;
1235}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001236
1237int
1238sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001239{
1240 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001241 /* NB: kernel requires arg[1] == NSIG / 8 */
1242 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1243 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001244 }
1245 return 0;
1246}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001247
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001248static void
1249print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1250{
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001251 printsignal(sig);
1252 tprints(", ");
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001253 printsiginfo_at(tcp, uinfo);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001254}
1255
Denys Vlasenko1d632462009-04-14 12:51:00 +00001256int
1257sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001258{
1259 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001260 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001261 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1262 }
1263 return 0;
1264}
1265
1266int
1267sys_rt_tgsigqueueinfo(struct tcb *tcp)
1268{
1269 if (entering(tcp)) {
1270 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1271 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001272 }
1273 return 0;
1274}
1275
Denys Vlasenko1d632462009-04-14 12:51:00 +00001276int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001277{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001278 /* NB: kernel requires arg[3] == NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001279 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001280 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001281 tprints(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001282 /* This is the only "return" parameter, */
1283 if (tcp->u_arg[1] != 0)
1284 return 0;
1285 /* ... if it's NULL, can decode all on entry */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001286 tprints("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001287 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001288 else if (tcp->u_arg[1] != 0) {
1289 /* syscall exit, and u_arg[1] wasn't NULL */
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001290 printsiginfo_at(tcp, tcp->u_arg[1]);
1291 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001293 else {
1294 /* syscall exit, and u_arg[1] was NULL */
1295 return 0;
1296 }
1297 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001298 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001299 return 0;
1300};
1301
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001302int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001303sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001304{
1305 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001306 tprints("<... resuming interrupted call ...>");
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001307 return 0;
1308}
1309
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001310static int
1311do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00001312{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001313 /* NB: kernel requires arg[2] == NSIG / 8 */
Roland McGrathf46ccd32007-08-02 01:15:59 +00001314 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001315 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001316 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001317 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00001318 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001319 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001320 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001321 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1322 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00001323 }
1324 return 0;
1325}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001326
1327int
1328sys_signalfd(struct tcb *tcp)
1329{
1330 return do_signalfd(tcp, -1);
1331}
1332
1333int
1334sys_signalfd4(struct tcb *tcp)
1335{
1336 return do_signalfd(tcp, 3);
1337}