blob: 710fb19b158361f4cfebbcd01777f699ee6e3ac8 [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"
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020035
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036#ifndef NSIG
Dmitry V. Levin74219ea2015-03-06 01:47:18 +000037# warning NSIG is not defined, using 32
Denys Vlasenko84703742012-02-25 02:38:52 +010038# define NSIG 32
Dmitry V. Levin38593e92014-02-26 16:51:28 +000039#elif NSIG < 32
Dmitry V. Levin74219ea2015-03-06 01:47:18 +000040# error NSIG < 32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041#endif
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020042
Roland McGrath2638cb42002-12-15 23:58:41 +000043/* The libc headers do not define this constant since it should only be
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020044 used by the implementation. So we define it here. */
Dmitry V. Levin5c7f6272014-02-08 00:26:06 +000045#ifndef SA_RESTORER
46# ifdef ASM_SA_RESTORER
47# define SA_RESTORER ASM_SA_RESTORER
Roland McGrath2638cb42002-12-15 23:58:41 +000048# endif
49#endif
50
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +000051/*
52 * Some architectures define SA_RESTORER in their headers,
53 * but do not actually have sa_restorer.
54 *
55 * Some architectures, otherwise, do not define SA_RESTORER in their headers,
56 * but actually have sa_restorer.
57 */
58#ifdef SA_RESTORER
59# if defined HPPA || defined IA64
60# define HAVE_SA_RESTORER 0
61# else
62# define HAVE_SA_RESTORER 1
63# endif
64#else /* !SA_RESTORER */
65# if defined SPARC || defined SPARC64
66# define HAVE_SA_RESTORER 1
67# else
68# define HAVE_SA_RESTORER 0
69# endif
Mike Frysingerd632e102014-08-09 09:04:18 -040070#endif
71
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000072#include "xlat/sigact_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000073#include "xlat/sigprocmaskcmds.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074
Nate Sammonsce780fc1999-03-29 23:23:13 +000075/* Anonymous realtime signals. */
Dmitry V. Levin59f63d32015-03-05 05:03:41 +000076#ifndef ASM_SIGRTMIN
77/* Linux kernel >= 3.18 defines SIGRTMIN to 32 on all architectures. */
78# define ASM_SIGRTMIN 32
Nate Sammonsce780fc1999-03-29 23:23:13 +000079#endif
Dmitry V. Levin59f63d32015-03-05 05:03:41 +000080#ifndef ASM_SIGRTMAX
81/* Under glibc 2.1, SIGRTMAX et al are functions, but __SIGRTMAX is a
82 constant. This is what we want. Otherwise, just use SIGRTMAX. */
83# ifdef SIGRTMAX
84# ifndef __SIGRTMAX
85# define __SIGRTMAX SIGRTMAX
86# endif
87# endif
88# ifdef __SIGRTMAX
89# define ASM_SIGRTMAX __SIGRTMAX
90# endif
Nate Sammonsce780fc1999-03-29 23:23:13 +000091#endif
92
Denys Vlasenkod9560c12011-08-19 17:41:28 +020093/* Note on the size of sigset_t:
94 *
95 * In glibc, sigset_t is an array with space for 1024 bits (!),
96 * even though all arches supported by Linux have only 64 signals
97 * except MIPS, which has 128. IOW, it is 128 bytes long.
98 *
99 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
100 * However, some old syscall return only 32 lower bits (one word).
101 * Example: sys_sigpending vs sys_rt_sigpending.
102 *
103 * Be aware of this fact when you try to
104 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
105 * - sizeof(sigset_t) is much bigger than you think,
106 * it may overflow tcp->u_arg[] array, and it may try to copy more data
107 * than is really available in <something>.
108 * Similarly,
109 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
110 * may be a bad idea: it'll try to read much more data than needed
111 * to fetch a sigset_t.
112 * Use (NSIG / 8) as a size instead.
113 */
114
Roland McGrathee36ce12004-09-04 03:53:10 +0000115const char *
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000116signame(const int sig)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000117{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000118 static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200119
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000120 if (sig >= 0) {
121 const unsigned int s = sig;
122
123 if (s < nsignals)
124 return signalent[s];
Dmitry V. Levin59f63d32015-03-05 05:03:41 +0000125#ifdef ASM_SIGRTMAX
126 if (s >= ASM_SIGRTMIN && s <= ASM_SIGRTMAX) {
127 sprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN);
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000128 return buf;
129 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200130#endif
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000131 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200132 sprintf(buf, "%d", sig);
133 return buf;
Nate Sammonsce780fc1999-03-29 23:23:13 +0000134}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000136static unsigned int
137popcount32(const uint32_t *a, unsigned int size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000139 unsigned int count = 0;
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200140
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000141 for (; size; ++a, --size) {
142 uint32_t x = *a;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000143
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000144#ifdef HAVE___BUILTIN_POPCOUNT
145 count += __builtin_popcount(x);
Denys Vlasenkoa8773792013-07-18 20:42:41 +0200146#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000147 for (; x; ++count)
148 x &= x - 1;
Nate Sammons4a121431999-04-06 01:19:39 +0000149#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100151
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000152 return count;
153}
154
Dmitry V. Levin74219ea2015-03-06 01:47:18 +0000155const char *
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000156sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
157{
158 /*
159 * The maximum number of signal names to be printed is NSIG * 2 / 3.
160 * Most of signal names have length 7,
161 * average length of signal names is less than 7.
162 * The length of prefix string does not exceed 16.
163 */
164 static char outstr[128 + 8 * (NSIG * 2 / 3)];
165
166 char *s;
167 const uint32_t *mask;
168 uint32_t inverted_mask[NSIG / 32];
169 unsigned int size;
170 int i;
171 char sep;
172
173 s = stpcpy(outstr, prefix);
174
175 mask = sig_mask;
176 /* length of signal mask in 4-byte words */
177 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
178
179 /* check whether 2/3 or more bits are set */
180 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
181 /* show those signals that are NOT in the mask */
182 unsigned int j;
183 for (j = 0; j < size; ++j)
184 inverted_mask[j] = ~mask[j];
185 mask = inverted_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186 *s++ = '~';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000187 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100188
189 sep = '[';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000190 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
191 ++i;
192 *s++ = sep;
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000193 if ((unsigned) i < nsignals) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000194 s = stpcpy(s, signalent[i] + 3);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195 }
Dmitry V. Levin59f63d32015-03-05 05:03:41 +0000196#ifdef ASM_SIGRTMAX
197 else if (i >= ASM_SIGRTMIN && i <= ASM_SIGRTMAX) {
198 s += sprintf(s, "RT_%u", i - ASM_SIGRTMIN);
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000199 }
200#endif
201 else {
202 s += sprintf(s, "%u", i);
203 }
204 sep = ' ';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100206 if (sep == '[')
207 *s++ = sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208 *s++ = ']';
209 *s = '\0';
210 return outstr;
211}
212
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000213#define sprintsigmask_val(prefix, mask) \
214 sprintsigmask_n((prefix), &(mask), sizeof(mask))
215
216#define tprintsigmask_val(prefix, mask) \
217 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218
219void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200220printsignal(int nr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000221{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200222 tprints(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223}
224
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000225void
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200226print_sigset_addr_len(struct tcb *tcp, long addr, long len)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000227{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000228 char mask[NSIG / 8];
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000229
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200230 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200231 tprints("NULL");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200232 return;
233 }
234 /* Here len is usually equals NSIG / 8 or current_wordsize.
235 * But we code this defensively:
236 */
237 if (len < 0) {
238 bad:
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000239 tprintf("%#lx", addr);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200240 return;
241 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000242 if (len >= NSIG / 8)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200243 len = NSIG / 8;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000244 else
245 len = (len + 3) & ~3;
246
247 if (umoven(tcp, addr, len, mask) < 0)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200248 goto bad;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000249 tprints(sprintsigmask_n("", mask, len));
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000250}
251
John Hughes58265892001-10-18 15:13:53 +0000252#ifndef ILL_ILLOPC
253#define ILL_ILLOPC 1 /* illegal opcode */
254#define ILL_ILLOPN 2 /* illegal operand */
255#define ILL_ILLADR 3 /* illegal addressing mode */
256#define ILL_ILLTRP 4 /* illegal trap */
257#define ILL_PRVOPC 5 /* privileged opcode */
258#define ILL_PRVREG 6 /* privileged register */
259#define ILL_COPROC 7 /* coprocessor error */
260#define ILL_BADSTK 8 /* internal stack error */
261#define FPE_INTDIV 1 /* integer divide by zero */
262#define FPE_INTOVF 2 /* integer overflow */
263#define FPE_FLTDIV 3 /* floating point divide by zero */
264#define FPE_FLTOVF 4 /* floating point overflow */
265#define FPE_FLTUND 5 /* floating point underflow */
266#define FPE_FLTRES 6 /* floating point inexact result */
267#define FPE_FLTINV 7 /* floating point invalid operation */
268#define FPE_FLTSUB 8 /* subscript out of range */
269#define SEGV_MAPERR 1 /* address not mapped to object */
270#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
271#define BUS_ADRALN 1 /* invalid address alignment */
272#define BUS_ADRERR 2 /* non-existant physical address */
273#define BUS_OBJERR 3 /* object specific hardware error */
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000274#define SYS_SECCOMP 1 /* seccomp triggered */
John Hughes58265892001-10-18 15:13:53 +0000275#define TRAP_BRKPT 1 /* process breakpoint */
276#define TRAP_TRACE 2 /* process trace trap */
277#define CLD_EXITED 1 /* child has exited */
278#define CLD_KILLED 2 /* child was killed */
279#define CLD_DUMPED 3 /* child terminated abnormally */
280#define CLD_TRAPPED 4 /* traced child has trapped */
281#define CLD_STOPPED 5 /* child has stopped */
282#define CLD_CONTINUED 6 /* stopped child has continued */
283#define POLL_IN 1 /* data input available */
284#define POLL_OUT 2 /* output buffers available */
285#define POLL_MSG 3 /* input message available */
286#define POLL_ERR 4 /* i/o error */
287#define POLL_PRI 5 /* high priority input available */
288#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000289#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000290#define SI_USER 0 /* sent by kill, sigsend, raise */
291#define SI_QUEUE -1 /* sent by sigqueue */
292#define SI_TIMER -2 /* sent by timer expiration */
293#define SI_MESGQ -3 /* sent by real time mesq state change */
294#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000295#define SI_SIGIO -5 /* sent by SIGIO */
296#define SI_TKILL -6 /* sent by tkill */
Dmitry V. Levinb9d4d212014-03-11 01:57:02 +0000297#define SI_DETHREAD -7 /* sent by execve killing subsidiary threads */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000298#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100299#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000300
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100301#ifndef SI_FROMUSER
302# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
Denys Vlasenko84703742012-02-25 02:38:52 +0100303#endif
John Hughes58265892001-10-18 15:13:53 +0000304
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000305#include "xlat/siginfo_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000306#include "xlat/sigill_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000307#include "xlat/sigfpe_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000308#include "xlat/sigtrap_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000309#include "xlat/sigchld_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000310#include "xlat/sigpoll_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000311#include "xlat/sigprof_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000312
313#ifdef SIGEMT
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000314#include "xlat/sigemt_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000315#endif
316
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000317#include "xlat/sigsegv_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000318#include "xlat/sigbus_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000319
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000320#ifndef SYS_SECCOMP
321# define SYS_SECCOMP 1
322#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000323#include "xlat/sigsys_codes.h"
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000324
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000325static void
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000326printsigsource(const siginfo_t *sip)
327{
328 tprintf(", si_pid=%lu, si_uid=%lu",
329 (unsigned long) sip->si_pid,
330 (unsigned long) sip->si_uid);
331}
332
333static void
334printsigval(const siginfo_t *sip, int verbose)
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000335{
336 if (!verbose)
337 tprints(", ...");
338 else
339 tprintf(", si_value={int=%u, ptr=%#lx}",
340 sip->si_int,
341 (unsigned long) sip->si_ptr);
342}
343
John Hughes58265892001-10-18 15:13:53 +0000344void
Dmitry V. Levind8890b52015-02-07 15:47:24 +0000345printsiginfo(const siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000346{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000347 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000348
349 if (sip->si_signo == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200350 tprints("{}");
John Hughes58265892001-10-18 15:13:53 +0000351 return;
352 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200353 tprints("{si_signo=");
John Hughes58265892001-10-18 15:13:53 +0000354 printsignal(sip->si_signo);
355 code = xlookup(siginfo_codes, sip->si_code);
356 if (!code) {
357 switch (sip->si_signo) {
358 case SIGTRAP:
359 code = xlookup(sigtrap_codes, sip->si_code);
360 break;
361 case SIGCHLD:
362 code = xlookup(sigchld_codes, sip->si_code);
363 break;
364 case SIGPOLL:
365 code = xlookup(sigpoll_codes, sip->si_code);
366 break;
367 case SIGPROF:
368 code = xlookup(sigprof_codes, sip->si_code);
369 break;
370 case SIGILL:
371 code = xlookup(sigill_codes, sip->si_code);
372 break;
373#ifdef SIGEMT
374 case SIGEMT:
375 code = xlookup(sigemt_codes, sip->si_code);
376 break;
377#endif
378 case SIGFPE:
379 code = xlookup(sigfpe_codes, sip->si_code);
380 break;
381 case SIGSEGV:
382 code = xlookup(sigsegv_codes, sip->si_code);
383 break;
384 case SIGBUS:
385 code = xlookup(sigbus_codes, sip->si_code);
386 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000387 case SIGSYS:
388 code = xlookup(sigsys_codes, sip->si_code);
389 break;
John Hughes58265892001-10-18 15:13:53 +0000390 }
391 }
392 if (code)
393 tprintf(", si_code=%s", code);
394 else
395 tprintf(", si_code=%#x", sip->si_code);
396#ifdef SI_NOINFO
397 if (sip->si_code != SI_NOINFO)
398#endif
399 {
400 if (sip->si_errno) {
Dmitry V. Levinb2f8c772015-02-23 03:10:25 +0000401 tprints(", si_errno=");
402 if ((unsigned) sip->si_errno < nerrnos
403 && errnoent[sip->si_errno])
404 tprints(errnoent[sip->si_errno]);
John Hughes58265892001-10-18 15:13:53 +0000405 else
Dmitry V. Levinb2f8c772015-02-23 03:10:25 +0000406 tprintf("%d", sip->si_errno);
John Hughes58265892001-10-18 15:13:53 +0000407 }
408#ifdef SI_FROMUSER
409 if (SI_FROMUSER(sip)) {
John Hughes58265892001-10-18 15:13:53 +0000410 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000411#ifdef SI_USER
412 case SI_USER:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000413 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000414 break;
415#endif
416#ifdef SI_TKILL
417 case SI_TKILL:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000418 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000419 break;
420#endif
Dmitry V. Levin36ab3d52015-01-13 09:24:04 +0300421#if defined SI_TIMER \
422 && defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
John Hughes58265892001-10-18 15:13:53 +0000423 case SI_TIMER:
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000424 tprintf(", si_timerid=%#x, si_overrun=%d",
425 sip->si_timerid, sip->si_overrun);
426 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000427 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000428#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000429 default:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000430 printsigsource(sip);
431 if (sip->si_ptr)
432 printsigval(sip, verbose);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000433 break;
John Hughes58265892001-10-18 15:13:53 +0000434 }
John Hughes58265892001-10-18 15:13:53 +0000435 }
436 else
437#endif /* SI_FROMUSER */
438 {
439 switch (sip->si_signo) {
440 case SIGCHLD:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000441 printsigsource(sip);
442 tprints(", si_status=");
John Hughes58265892001-10-18 15:13:53 +0000443 if (sip->si_code == CLD_EXITED)
444 tprintf("%d", sip->si_status);
445 else
446 printsignal(sip->si_status);
John Hughes58265892001-10-18 15:13:53 +0000447 if (!verbose)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200448 tprints(", ...");
John Hughes58265892001-10-18 15:13:53 +0000449 else
H.J. Lu2bb45812012-04-15 11:17:13 -0700450 tprintf(", si_utime=%llu, si_stime=%llu",
451 (unsigned long long) sip->si_utime,
452 (unsigned long long) sip->si_stime);
John Hughes58265892001-10-18 15:13:53 +0000453 break;
454 case SIGILL: case SIGFPE:
455 case SIGSEGV: case SIGBUS:
456 tprintf(", si_addr=%#lx",
457 (unsigned long) sip->si_addr);
458 break;
459 case SIGPOLL:
460 switch (sip->si_code) {
461 case POLL_IN: case POLL_OUT: case POLL_MSG:
462 tprintf(", si_band=%ld",
463 (long) sip->si_band);
464 break;
465 }
466 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000467#ifdef HAVE_SIGINFO_T_SI_SYSCALL
468 case SIGSYS:
469 tprintf(", si_call_addr=%#lx, si_syscall=%d, si_arch=%u",
470 (unsigned long) sip->si_call_addr,
471 sip->si_syscall, sip->si_arch);
472 break;
473#endif
John Hughes58265892001-10-18 15:13:53 +0000474 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000475 if (sip->si_pid || sip->si_uid)
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000476 printsigsource(sip);
477 if (sip->si_ptr)
478 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000479 }
480 }
481 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200482 tprints("}");
John Hughes58265892001-10-18 15:13:53 +0000483}
484
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100485void
486printsiginfo_at(struct tcb *tcp, long addr)
487{
488 siginfo_t si;
489 if (!addr) {
490 tprints("NULL");
491 return;
492 }
493 if (syserror(tcp)) {
494 tprintf("%#lx", addr);
495 return;
496 }
497 if (umove(tcp, addr, &si) < 0) {
498 tprints("{???}");
499 return;
500 }
501 printsiginfo(&si, verbose(tcp));
502}
503
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504int
Denys Vlasenko12014262011-05-30 14:00:14 +0200505sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000506{
507 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000508 tprintsigmask_val("", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509 }
510 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000511 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000512 return RVAL_HEX | RVAL_STR;
513 }
514 return 0;
515}
516
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517#ifdef HAVE_SIGACTION
518
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000519struct old_sigaction {
Denys Vlasenko86d94842013-02-08 12:59:13 +0100520 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800521#ifdef MIPS
522 unsigned int sa_flags;
523 void (*__sa_handler)(int);
524 /* Kernel treats sa_mask as an array of longs. */
525 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
526#else
Denys Vlasenko86d94842013-02-08 12:59:13 +0100527 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528 unsigned long sa_mask;
529 unsigned long sa_flags;
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800530#endif /* !MIPS */
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000531#if HAVE_SA_RESTORER
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100532 void (*sa_restorer)(void);
533#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000534};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535
Elliott Hughes458b3f22014-02-28 23:21:35 +0000536struct old_sigaction32 {
537 /* sa_handler may be a libc #define, need to use other name: */
538 uint32_t __sa_handler;
539 uint32_t sa_mask;
540 uint32_t sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000541#if HAVE_SA_RESTORER
Elliott Hughes458b3f22014-02-28 23:21:35 +0000542 uint32_t sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100543#endif
Elliott Hughes458b3f22014-02-28 23:21:35 +0000544};
545
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000546static void
547decode_old_sigaction(struct tcb *tcp, long addr)
548{
549 struct old_sigaction sa;
Elliott Hughes458b3f22014-02-28 23:21:35 +0000550 int r;
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000551
552 if (!addr) {
553 tprints("NULL");
554 return;
555 }
556 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
557 tprintf("%#lx", addr);
558 return;
559 }
Elliott Hughes458b3f22014-02-28 23:21:35 +0000560
561#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
562 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
563 struct old_sigaction32 sa32;
564 r = umove(tcp, addr, &sa32);
565 if (r >= 0) {
566 memset(&sa, 0, sizeof(sa));
567 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
568 sa.sa_flags = sa32.sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000569#if HAVE_SA_RESTORER && defined SA_RESTORER
Elliott Hughes458b3f22014-02-28 23:21:35 +0000570 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100571#endif
Elliott Hughes458b3f22014-02-28 23:21:35 +0000572 sa.sa_mask = sa32.sa_mask;
573 }
574 } else
575#endif
576 {
577 r = umove(tcp, addr, &sa);
578 }
579 if (r < 0) {
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000580 tprints("{...}");
581 return;
582 }
583
584 /* Architectures using function pointers, like
585 * hppa, may need to manipulate the function pointer
586 * to compute the result of a comparison. However,
587 * the __sa_handler function pointer exists only in
588 * the address space of the traced process, and can't
589 * be manipulated by strace. In order to prevent the
590 * compiler from generating code to manipulate
591 * __sa_handler we cast the function pointers to long. */
592 if ((long)sa.__sa_handler == (long)SIG_ERR)
593 tprints("{SIG_ERR, ");
594 else if ((long)sa.__sa_handler == (long)SIG_DFL)
595 tprints("{SIG_DFL, ");
596 else if ((long)sa.__sa_handler == (long)SIG_IGN)
597 tprints("{SIG_IGN, ");
598 else
599 tprintf("{%#lx, ", (long) sa.__sa_handler);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800600#ifdef MIPS
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000601 tprintsigmask_addr("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800602#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000603 tprintsigmask_val("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800604#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000605 tprints(", ");
606 printflags(sigact_flags, sa.sa_flags, "SA_???");
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000607#if HAVE_SA_RESTORER && defined SA_RESTORER
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000608 if (sa.sa_flags & SA_RESTORER)
609 tprintf(", %p", sa.sa_restorer);
610#endif
611 tprints("}");
612}
613
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614int
Denys Vlasenko12014262011-05-30 14:00:14 +0200615sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000616{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000617 if (entering(tcp)) {
618 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200619 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000620 decode_old_sigaction(tcp, tcp->u_arg[1]);
621 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000622 } else
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000623 decode_old_sigaction(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000624 return 0;
625}
626
627int
Denys Vlasenko12014262011-05-30 14:00:14 +0200628sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000629{
630 if (entering(tcp)) {
631 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200632 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +0000634 case (long) SIG_ERR:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200635 tprints("SIG_ERR");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000636 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000637 case (long) SIG_DFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200638 tprints("SIG_DFL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000639 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000640 case (long) SIG_IGN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200641 tprints("SIG_IGN");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642 break;
643 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000644 tprintf("%#lx", tcp->u_arg[1]);
645 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000646 return 0;
647 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000648 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000649 switch (tcp->u_rval) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100650 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000651 tcp->auxstr = "SIG_ERR"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100652 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000653 tcp->auxstr = "SIG_DFL"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100654 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000655 tcp->auxstr = "SIG_IGN"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100656 default:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000657 tcp->auxstr = NULL;
658 }
659 return RVAL_HEX | RVAL_STR;
660 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000661 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000662}
663
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000664#endif /* HAVE_SIGACTION */
665
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666int
Denys Vlasenko12014262011-05-30 14:00:14 +0200667sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000668{
669 if (exiting(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000670 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000671 }
672 return RVAL_HEX | RVAL_STR;
673}
674
675int
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000676sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000677{
678 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000679 tprintsigmask_val("", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680 }
681 return 0;
682}
683
Denys Vlasenko84703742012-02-25 02:38:52 +0100684#if !defined SS_ONSTACK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000685#define SS_ONSTACK 1
686#define SS_DISABLE 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000687#endif
688
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000689#include "xlat/sigaltstack_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000691static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200692print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000693{
694 stack_t ss;
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000695 int r;
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000696
697 if (!addr) {
698 tprints("NULL");
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000699 return;
700 }
701
702#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
703 if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
704 struct {
705 uint32_t ss_sp;
706 int32_t ss_flags;
707 uint32_t ss_size;
708 } ss32;
709 r = umove(tcp, addr, &ss32);
710 if (r >= 0) {
711 memset(&ss, 0, sizeof(ss));
712 ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
713 ss.ss_flags = ss32.ss_flags;
714 ss.ss_size = (unsigned long) ss32.ss_size;
715 }
716 } else
717#endif
718 {
719 r = umove(tcp, addr, &ss);
720 }
721 if (r < 0) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000722 tprintf("%#lx", addr);
723 } else {
724 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
725 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
726 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
727 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000728}
729
730int
Denys Vlasenko12014262011-05-30 14:00:14 +0200731sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000732{
733 if (entering(tcp)) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000734 print_stack_t(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000735 }
736 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200737 tprints(", ");
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000738 print_stack_t(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739 }
740 return 0;
741}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000742
743#ifdef HAVE_SIGACTION
744
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200745/* "Old" sigprocmask, which operates with word-sized signal masks */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000746int
Denys Vlasenko12014262011-05-30 14:00:14 +0200747sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000748{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200749# ifdef ALPHA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000750 if (entering(tcp)) {
Mike Frysingerdde045c2012-03-15 00:45:33 -0400751 /*
752 * Alpha/OSF is different: it doesn't pass in two pointers,
753 * but rather passes in the new bitmask as an argument and
754 * then returns the old bitmask. This "works" because we
755 * only have 64 signals to worry about. If you want more,
756 * use of the rt_sigprocmask syscall is required.
757 * Alpha:
758 * old = osf_sigprocmask(how, new);
759 * Everyone else:
760 * ret = sigprocmask(how, &new, &old, ...);
761 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000762 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000763 tprintsigmask_val(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764 }
765 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000766 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767 return RVAL_HEX | RVAL_STR;
768 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200769# else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000770 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000771 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200772 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200773 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200774 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000775 }
776 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200777 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000778 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000779 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200780 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000781 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200782# endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000783 return 0;
784}
785
786#endif /* HAVE_SIGACTION */
787
788int
Denys Vlasenko12014262011-05-30 14:00:14 +0200789sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000790{
791 if (entering(tcp)) {
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +0100792 tprintf("%ld, %s",
793 widen_to_long(tcp->u_arg[0]),
794 signame(tcp->u_arg[1])
795 );
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000796 }
797 return 0;
798}
799
Roland McGrath8ffc3522003-07-09 09:47:49 +0000800int
Denys Vlasenko12014262011-05-30 14:00:14 +0200801sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +0000802{
803 if (entering(tcp)) {
804 tprintf("%ld, %ld, %s",
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +0100805 widen_to_long(tcp->u_arg[0]),
806 widen_to_long(tcp->u_arg[1]),
807 signame(tcp->u_arg[2])
808 );
Roland McGrath8ffc3522003-07-09 09:47:49 +0000809 }
810 return 0;
811}
Roland McGrath8ffc3522003-07-09 09:47:49 +0000812
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000813int
Denys Vlasenko12014262011-05-30 14:00:14 +0200814sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000815{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000816 if (exiting(tcp)) {
817 if (syserror(tcp))
818 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000819 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200820 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821 }
822 return 0;
823}
824
Denys Vlasenko12014262011-05-30 14:00:14 +0200825int
826sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000827{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200828 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000829 if (entering(tcp)) {
830 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200831 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200832 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
833 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000834 }
835 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200836 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000837 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000838 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200839 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Nate Sammonsdab325a1999-03-29 23:33:35 +0000840 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000841 }
842 return 0;
843}
844
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000845/* Structure describing the action to be taken when a signal arrives. */
846struct new_sigaction
847{
Denys Vlasenko86d94842013-02-08 12:59:13 +0100848 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800849#ifdef MIPS
850 unsigned int sa_flags;
851 void (*__sa_handler)(int);
852#else
Denys Vlasenko86d94842013-02-08 12:59:13 +0100853 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000854 unsigned long sa_flags;
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800855#endif /* !MIPS */
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000856#if HAVE_SA_RESTORER
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100857 void (*sa_restorer)(void);
858#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000859 /* Kernel treats sa_mask as an array of longs. */
860 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
861};
862/* Same for i386-on-x86_64 and similar cases */
863struct new_sigaction32
864{
865 uint32_t __sa_handler;
866 uint32_t sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000867#if HAVE_SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000868 uint32_t sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100869#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000870 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000871};
872
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000873static void
874decode_new_sigaction(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000875{
876 struct new_sigaction sa;
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000877 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000878
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000879 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200880 tprints("NULL");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000881 return;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882 }
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000883 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000884 tprintf("%#lx", addr);
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000885 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000886 }
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100887#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100888 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000889 struct new_sigaction32 sa32;
890 r = umove(tcp, addr, &sa32);
891 if (r >= 0) {
892 memset(&sa, 0, sizeof(sa));
893 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
894 sa.sa_flags = sa32.sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000895#if HAVE_SA_RESTORER && defined SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000896 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100897#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000898 /* Kernel treats sa_mask as an array of longs.
899 * For 32-bit process, "long" is uint32_t, thus, for example,
900 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
901 * But for (64-bit) kernel, 32th bit in sa_mask is
902 * 32th bit in 0th (64-bit) long!
903 * For little-endian, it's the same.
904 * For big-endian, we swap 32-bit words.
905 */
906 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
907 }
908 } else
909#endif
910 {
911 r = umove(tcp, addr, &sa);
912 }
913 if (r < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200914 tprints("{...}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000915 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000916 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +0000917 /* Architectures using function pointers, like
918 * hppa, may need to manipulate the function pointer
919 * to compute the result of a comparison. However,
Denys Vlasenko86d94842013-02-08 12:59:13 +0100920 * the __sa_handler function pointer exists only in
Carlos O'Donell4677c8a2009-09-09 18:13:19 +0000921 * the address space of the traced process, and can't
922 * be manipulated by strace. In order to prevent the
923 * compiler from generating code to manipulate
Denys Vlasenko86d94842013-02-08 12:59:13 +0100924 * __sa_handler we cast the function pointers to long. */
Carlos O'Donell4677c8a2009-09-09 18:13:19 +0000925 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200926 tprints("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +0000927 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200928 tprints("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +0000929 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200930 tprints("{SIG_IGN, ");
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000931 else
932 tprintf("{%#lx, ", (long) sa.__sa_handler);
Denys Vlasenko80b73a22013-07-18 10:10:46 +0200933 /*
934 * Sigset size is in tcp->u_arg[4] (SPARC)
935 * or in tcp->u_arg[3] (all other),
936 * but kernel won't handle sys_rt_sigaction
937 * with wrong sigset size (just returns EINVAL instead).
938 * We just fetch the right size, which is NSIG / 8.
939 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000940 tprintsigmask_val("", sa.sa_mask);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200941 tprints(", ");
Denys Vlasenko80b73a22013-07-18 10:10:46 +0200942
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000943 printflags(sigact_flags, sa.sa_flags, "SA_???");
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000944#if HAVE_SA_RESTORER && defined SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000945 if (sa.sa_flags & SA_RESTORER)
946 tprintf(", %p", sa.sa_restorer);
947#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200948 tprints("}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000949}
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000950
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000951int
952sys_rt_sigaction(struct tcb *tcp)
953{
954 if (entering(tcp)) {
955 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200956 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000957 decode_new_sigaction(tcp, tcp->u_arg[1]);
958 tprints(", ");
959 } else {
960 decode_new_sigaction(tcp, tcp->u_arg[2]);
Denys Vlasenko9472a272013-02-12 11:43:46 +0100961#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000962 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
963#elif defined(ALPHA)
964 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
965#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000966 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000967#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000968 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000969 return 0;
970}
971
Denys Vlasenko1d632462009-04-14 12:51:00 +0000972int
973sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000974{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975 if (exiting(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200976 /*
977 * One of the few syscalls where sigset size (arg[1])
978 * is allowed to be <= NSIG / 8, not strictly ==.
979 * This allows non-rt sigpending() syscall
980 * to reuse rt_sigpending() code in kernel.
981 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982 if (syserror(tcp))
983 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200985 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
986 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000987 }
988 return 0;
989}
Denys Vlasenko1d632462009-04-14 12:51:00 +0000990
991int
992sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000993{
994 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200995 /* NB: kernel requires arg[1] == NSIG / 8 */
996 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
997 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000998 }
999 return 0;
1000}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001001
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001002static void
1003print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1004{
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001005 printsignal(sig);
1006 tprints(", ");
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001007 printsiginfo_at(tcp, uinfo);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001008}
1009
Denys Vlasenko1d632462009-04-14 12:51:00 +00001010int
1011sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012{
1013 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001014 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001015 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1016 }
1017 return 0;
1018}
1019
1020int
1021sys_rt_tgsigqueueinfo(struct tcb *tcp)
1022{
1023 if (entering(tcp)) {
1024 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1025 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026 }
1027 return 0;
1028}
1029
Denys Vlasenko1d632462009-04-14 12:51:00 +00001030int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001032 /* NB: kernel requires arg[3] == NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001033 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001034 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001035 tprints(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001036 /* This is the only "return" parameter, */
1037 if (tcp->u_arg[1] != 0)
1038 return 0;
1039 /* ... if it's NULL, can decode all on entry */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001040 tprints("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001042 else if (tcp->u_arg[1] != 0) {
1043 /* syscall exit, and u_arg[1] wasn't NULL */
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001044 printsiginfo_at(tcp, tcp->u_arg[1]);
1045 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001046 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001047 else {
1048 /* syscall exit, and u_arg[1] was NULL */
1049 return 0;
1050 }
1051 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001052 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001053 return 0;
1054};
1055
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001056int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001057sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001058{
1059 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001060 tprints("<... resuming interrupted call ...>");
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001061 return 0;
1062}
1063
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001064static int
1065do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00001066{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001067 /* NB: kernel requires arg[2] == NSIG / 8 */
Roland McGrathf46ccd32007-08-02 01:15:59 +00001068 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001069 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001070 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001071 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00001072 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001073 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001074 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001075 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1076 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00001077 }
1078 return 0;
1079}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001080
1081int
1082sys_signalfd(struct tcb *tcp)
1083{
1084 return do_signalfd(tcp, -1);
1085}
1086
1087int
1088sys_signalfd4(struct tcb *tcp)
1089{
1090 return do_signalfd(tcp, 3);
1091}