blob: 69a47bb6ea316d643de06ffa910172d98886124f [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. */
Dmitry V. Levin59f63d32015-03-05 05:03:41 +0000105#ifndef ASM_SIGRTMIN
106/* Linux kernel >= 3.18 defines SIGRTMIN to 32 on all architectures. */
107# define ASM_SIGRTMIN 32
Nate Sammonsce780fc1999-03-29 23:23:13 +0000108#endif
Dmitry V. Levin59f63d32015-03-05 05:03:41 +0000109#ifndef ASM_SIGRTMAX
110/* Under glibc 2.1, SIGRTMAX et al are functions, but __SIGRTMAX is a
111 constant. This is what we want. Otherwise, just use SIGRTMAX. */
112# ifdef SIGRTMAX
113# ifndef __SIGRTMAX
114# define __SIGRTMAX SIGRTMAX
115# endif
116# endif
117# ifdef __SIGRTMAX
118# define ASM_SIGRTMAX __SIGRTMAX
119# endif
Nate Sammonsce780fc1999-03-29 23:23:13 +0000120#endif
121
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200122/* Note on the size of sigset_t:
123 *
124 * In glibc, sigset_t is an array with space for 1024 bits (!),
125 * even though all arches supported by Linux have only 64 signals
126 * except MIPS, which has 128. IOW, it is 128 bytes long.
127 *
128 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
129 * However, some old syscall return only 32 lower bits (one word).
130 * Example: sys_sigpending vs sys_rt_sigpending.
131 *
132 * Be aware of this fact when you try to
133 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
134 * - sizeof(sigset_t) is much bigger than you think,
135 * it may overflow tcp->u_arg[] array, and it may try to copy more data
136 * than is really available in <something>.
137 * Similarly,
138 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
139 * may be a bad idea: it'll try to read much more data than needed
140 * to fetch a sigset_t.
141 * Use (NSIG / 8) as a size instead.
142 */
143
Roland McGrathee36ce12004-09-04 03:53:10 +0000144const char *
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000145signame(const int sig)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000146{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000147 static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200148
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000149 if (sig >= 0) {
150 const unsigned int s = sig;
151
152 if (s < nsignals)
153 return signalent[s];
Dmitry V. Levin59f63d32015-03-05 05:03:41 +0000154#ifdef ASM_SIGRTMAX
155 if (s >= ASM_SIGRTMIN && s <= ASM_SIGRTMAX) {
156 sprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN);
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000157 return buf;
158 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200159#endif
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000160 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200161 sprintf(buf, "%d", sig);
162 return buf;
Nate Sammonsce780fc1999-03-29 23:23:13 +0000163}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000165static unsigned int
166popcount32(const uint32_t *a, unsigned int size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000167{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000168 unsigned int count = 0;
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200169
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000170 for (; size; ++a, --size) {
171 uint32_t x = *a;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000173#ifdef HAVE___BUILTIN_POPCOUNT
174 count += __builtin_popcount(x);
Denys Vlasenkoa8773792013-07-18 20:42:41 +0200175#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000176 for (; x; ++count)
177 x &= x - 1;
Nate Sammons4a121431999-04-06 01:19:39 +0000178#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100180
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000181 return count;
182}
183
184static const char *
185sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
186{
187 /*
188 * The maximum number of signal names to be printed is NSIG * 2 / 3.
189 * Most of signal names have length 7,
190 * average length of signal names is less than 7.
191 * The length of prefix string does not exceed 16.
192 */
193 static char outstr[128 + 8 * (NSIG * 2 / 3)];
194
195 char *s;
196 const uint32_t *mask;
197 uint32_t inverted_mask[NSIG / 32];
198 unsigned int size;
199 int i;
200 char sep;
201
202 s = stpcpy(outstr, prefix);
203
204 mask = sig_mask;
205 /* length of signal mask in 4-byte words */
206 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
207
208 /* check whether 2/3 or more bits are set */
209 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
210 /* show those signals that are NOT in the mask */
211 unsigned int j;
212 for (j = 0; j < size; ++j)
213 inverted_mask[j] = ~mask[j];
214 mask = inverted_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000215 *s++ = '~';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000216 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100217
218 sep = '[';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000219 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
220 ++i;
221 *s++ = sep;
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000222 if ((unsigned) i < nsignals) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000223 s = stpcpy(s, signalent[i] + 3);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 }
Dmitry V. Levin59f63d32015-03-05 05:03:41 +0000225#ifdef ASM_SIGRTMAX
226 else if (i >= ASM_SIGRTMIN && i <= ASM_SIGRTMAX) {
227 s += sprintf(s, "RT_%u", i - ASM_SIGRTMIN);
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000228 }
229#endif
230 else {
231 s += sprintf(s, "%u", i);
232 }
233 sep = ' ';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100235 if (sep == '[')
236 *s++ = sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000237 *s++ = ']';
238 *s = '\0';
239 return outstr;
240}
241
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000242#define tprintsigmask_addr(prefix, mask) \
243 tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
Denys Vlasenko75f4e1f2013-07-18 20:37:06 +0200244
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000245#define sprintsigmask_val(prefix, mask) \
246 sprintsigmask_n((prefix), &(mask), sizeof(mask))
247
248#define tprintsigmask_val(prefix, mask) \
249 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000250
251void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200252printsignal(int nr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000253{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200254 tprints(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255}
256
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000257void
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200258print_sigset_addr_len(struct tcb *tcp, long addr, long len)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000259{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000260 char mask[NSIG / 8];
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000261
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200262 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200263 tprints("NULL");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200264 return;
265 }
266 /* Here len is usually equals NSIG / 8 or current_wordsize.
267 * But we code this defensively:
268 */
269 if (len < 0) {
270 bad:
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000271 tprintf("%#lx", addr);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200272 return;
273 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000274 if (len >= NSIG / 8)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200275 len = NSIG / 8;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000276 else
277 len = (len + 3) & ~3;
278
279 if (umoven(tcp, addr, len, mask) < 0)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200280 goto bad;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000281 tprints(sprintsigmask_n("", mask, len));
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000282}
283
John Hughes58265892001-10-18 15:13:53 +0000284#ifndef ILL_ILLOPC
285#define ILL_ILLOPC 1 /* illegal opcode */
286#define ILL_ILLOPN 2 /* illegal operand */
287#define ILL_ILLADR 3 /* illegal addressing mode */
288#define ILL_ILLTRP 4 /* illegal trap */
289#define ILL_PRVOPC 5 /* privileged opcode */
290#define ILL_PRVREG 6 /* privileged register */
291#define ILL_COPROC 7 /* coprocessor error */
292#define ILL_BADSTK 8 /* internal stack error */
293#define FPE_INTDIV 1 /* integer divide by zero */
294#define FPE_INTOVF 2 /* integer overflow */
295#define FPE_FLTDIV 3 /* floating point divide by zero */
296#define FPE_FLTOVF 4 /* floating point overflow */
297#define FPE_FLTUND 5 /* floating point underflow */
298#define FPE_FLTRES 6 /* floating point inexact result */
299#define FPE_FLTINV 7 /* floating point invalid operation */
300#define FPE_FLTSUB 8 /* subscript out of range */
301#define SEGV_MAPERR 1 /* address not mapped to object */
302#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
303#define BUS_ADRALN 1 /* invalid address alignment */
304#define BUS_ADRERR 2 /* non-existant physical address */
305#define BUS_OBJERR 3 /* object specific hardware error */
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000306#define SYS_SECCOMP 1 /* seccomp triggered */
John Hughes58265892001-10-18 15:13:53 +0000307#define TRAP_BRKPT 1 /* process breakpoint */
308#define TRAP_TRACE 2 /* process trace trap */
309#define CLD_EXITED 1 /* child has exited */
310#define CLD_KILLED 2 /* child was killed */
311#define CLD_DUMPED 3 /* child terminated abnormally */
312#define CLD_TRAPPED 4 /* traced child has trapped */
313#define CLD_STOPPED 5 /* child has stopped */
314#define CLD_CONTINUED 6 /* stopped child has continued */
315#define POLL_IN 1 /* data input available */
316#define POLL_OUT 2 /* output buffers available */
317#define POLL_MSG 3 /* input message available */
318#define POLL_ERR 4 /* i/o error */
319#define POLL_PRI 5 /* high priority input available */
320#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000321#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000322#define SI_USER 0 /* sent by kill, sigsend, raise */
323#define SI_QUEUE -1 /* sent by sigqueue */
324#define SI_TIMER -2 /* sent by timer expiration */
325#define SI_MESGQ -3 /* sent by real time mesq state change */
326#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000327#define SI_SIGIO -5 /* sent by SIGIO */
328#define SI_TKILL -6 /* sent by tkill */
Dmitry V. Levinb9d4d212014-03-11 01:57:02 +0000329#define SI_DETHREAD -7 /* sent by execve killing subsidiary threads */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000330#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100331#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000332
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100333#ifndef SI_FROMUSER
334# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
Denys Vlasenko84703742012-02-25 02:38:52 +0100335#endif
John Hughes58265892001-10-18 15:13:53 +0000336
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000337#include "xlat/siginfo_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000338#include "xlat/sigill_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000339#include "xlat/sigfpe_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000340#include "xlat/sigtrap_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000341#include "xlat/sigchld_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000342#include "xlat/sigpoll_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000343#include "xlat/sigprof_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000344
345#ifdef SIGEMT
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000346#include "xlat/sigemt_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000347#endif
348
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000349#include "xlat/sigsegv_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000350#include "xlat/sigbus_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000351
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000352#ifndef SYS_SECCOMP
353# define SYS_SECCOMP 1
354#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000355#include "xlat/sigsys_codes.h"
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000356
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000357static void
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000358printsigsource(const siginfo_t *sip)
359{
360 tprintf(", si_pid=%lu, si_uid=%lu",
361 (unsigned long) sip->si_pid,
362 (unsigned long) sip->si_uid);
363}
364
365static void
366printsigval(const siginfo_t *sip, int verbose)
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000367{
368 if (!verbose)
369 tprints(", ...");
370 else
371 tprintf(", si_value={int=%u, ptr=%#lx}",
372 sip->si_int,
373 (unsigned long) sip->si_ptr);
374}
375
John Hughes58265892001-10-18 15:13:53 +0000376void
Dmitry V. Levind8890b52015-02-07 15:47:24 +0000377printsiginfo(const siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000378{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000379 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000380
381 if (sip->si_signo == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200382 tprints("{}");
John Hughes58265892001-10-18 15:13:53 +0000383 return;
384 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200385 tprints("{si_signo=");
John Hughes58265892001-10-18 15:13:53 +0000386 printsignal(sip->si_signo);
387 code = xlookup(siginfo_codes, sip->si_code);
388 if (!code) {
389 switch (sip->si_signo) {
390 case SIGTRAP:
391 code = xlookup(sigtrap_codes, sip->si_code);
392 break;
393 case SIGCHLD:
394 code = xlookup(sigchld_codes, sip->si_code);
395 break;
396 case SIGPOLL:
397 code = xlookup(sigpoll_codes, sip->si_code);
398 break;
399 case SIGPROF:
400 code = xlookup(sigprof_codes, sip->si_code);
401 break;
402 case SIGILL:
403 code = xlookup(sigill_codes, sip->si_code);
404 break;
405#ifdef SIGEMT
406 case SIGEMT:
407 code = xlookup(sigemt_codes, sip->si_code);
408 break;
409#endif
410 case SIGFPE:
411 code = xlookup(sigfpe_codes, sip->si_code);
412 break;
413 case SIGSEGV:
414 code = xlookup(sigsegv_codes, sip->si_code);
415 break;
416 case SIGBUS:
417 code = xlookup(sigbus_codes, sip->si_code);
418 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000419 case SIGSYS:
420 code = xlookup(sigsys_codes, sip->si_code);
421 break;
John Hughes58265892001-10-18 15:13:53 +0000422 }
423 }
424 if (code)
425 tprintf(", si_code=%s", code);
426 else
427 tprintf(", si_code=%#x", sip->si_code);
428#ifdef SI_NOINFO
429 if (sip->si_code != SI_NOINFO)
430#endif
431 {
432 if (sip->si_errno) {
Dmitry V. Levinb2f8c772015-02-23 03:10:25 +0000433 tprints(", si_errno=");
434 if ((unsigned) sip->si_errno < nerrnos
435 && errnoent[sip->si_errno])
436 tprints(errnoent[sip->si_errno]);
John Hughes58265892001-10-18 15:13:53 +0000437 else
Dmitry V. Levinb2f8c772015-02-23 03:10:25 +0000438 tprintf("%d", sip->si_errno);
John Hughes58265892001-10-18 15:13:53 +0000439 }
440#ifdef SI_FROMUSER
441 if (SI_FROMUSER(sip)) {
John Hughes58265892001-10-18 15:13:53 +0000442 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000443#ifdef SI_USER
444 case SI_USER:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000445 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000446 break;
447#endif
448#ifdef SI_TKILL
449 case SI_TKILL:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000450 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000451 break;
452#endif
Dmitry V. Levin36ab3d52015-01-13 09:24:04 +0300453#if defined SI_TIMER \
454 && defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
John Hughes58265892001-10-18 15:13:53 +0000455 case SI_TIMER:
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000456 tprintf(", si_timerid=%#x, si_overrun=%d",
457 sip->si_timerid, sip->si_overrun);
458 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000459 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000460#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000461 default:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000462 printsigsource(sip);
463 if (sip->si_ptr)
464 printsigval(sip, verbose);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000465 break;
John Hughes58265892001-10-18 15:13:53 +0000466 }
John Hughes58265892001-10-18 15:13:53 +0000467 }
468 else
469#endif /* SI_FROMUSER */
470 {
471 switch (sip->si_signo) {
472 case SIGCHLD:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000473 printsigsource(sip);
474 tprints(", si_status=");
John Hughes58265892001-10-18 15:13:53 +0000475 if (sip->si_code == CLD_EXITED)
476 tprintf("%d", sip->si_status);
477 else
478 printsignal(sip->si_status);
John Hughes58265892001-10-18 15:13:53 +0000479 if (!verbose)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200480 tprints(", ...");
John Hughes58265892001-10-18 15:13:53 +0000481 else
H.J. Lu2bb45812012-04-15 11:17:13 -0700482 tprintf(", si_utime=%llu, si_stime=%llu",
483 (unsigned long long) sip->si_utime,
484 (unsigned long long) sip->si_stime);
John Hughes58265892001-10-18 15:13:53 +0000485 break;
486 case SIGILL: case SIGFPE:
487 case SIGSEGV: case SIGBUS:
488 tprintf(", si_addr=%#lx",
489 (unsigned long) sip->si_addr);
490 break;
491 case SIGPOLL:
492 switch (sip->si_code) {
493 case POLL_IN: case POLL_OUT: case POLL_MSG:
494 tprintf(", si_band=%ld",
495 (long) sip->si_band);
496 break;
497 }
498 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000499#ifdef HAVE_SIGINFO_T_SI_SYSCALL
500 case SIGSYS:
501 tprintf(", si_call_addr=%#lx, si_syscall=%d, si_arch=%u",
502 (unsigned long) sip->si_call_addr,
503 sip->si_syscall, sip->si_arch);
504 break;
505#endif
John Hughes58265892001-10-18 15:13:53 +0000506 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000507 if (sip->si_pid || sip->si_uid)
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000508 printsigsource(sip);
509 if (sip->si_ptr)
510 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000511 }
512 }
513 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200514 tprints("}");
John Hughes58265892001-10-18 15:13:53 +0000515}
516
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100517void
518printsiginfo_at(struct tcb *tcp, long addr)
519{
520 siginfo_t si;
521 if (!addr) {
522 tprints("NULL");
523 return;
524 }
525 if (syserror(tcp)) {
526 tprintf("%#lx", addr);
527 return;
528 }
529 if (umove(tcp, addr, &si) < 0) {
530 tprints("{???}");
531 return;
532 }
533 printsiginfo(&si, verbose(tcp));
534}
535
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536int
Denys Vlasenko12014262011-05-30 14:00:14 +0200537sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538{
539 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000540 tprintsigmask_val("", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541 }
542 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000543 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544 return RVAL_HEX | RVAL_STR;
545 }
546 return 0;
547}
548
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549#ifdef HAVE_SIGACTION
550
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000551struct old_sigaction {
Denys Vlasenko86d94842013-02-08 12:59:13 +0100552 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800553#ifdef MIPS
554 unsigned int sa_flags;
555 void (*__sa_handler)(int);
556 /* Kernel treats sa_mask as an array of longs. */
557 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
558#else
Denys Vlasenko86d94842013-02-08 12:59:13 +0100559 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560 unsigned long sa_mask;
561 unsigned long sa_flags;
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800562#endif /* !MIPS */
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000563#if HAVE_SA_RESTORER
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100564 void (*sa_restorer)(void);
565#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567
Elliott Hughes458b3f22014-02-28 23:21:35 +0000568struct old_sigaction32 {
569 /* sa_handler may be a libc #define, need to use other name: */
570 uint32_t __sa_handler;
571 uint32_t sa_mask;
572 uint32_t sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000573#if HAVE_SA_RESTORER
Elliott Hughes458b3f22014-02-28 23:21:35 +0000574 uint32_t sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100575#endif
Elliott Hughes458b3f22014-02-28 23:21:35 +0000576};
577
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000578static void
579decode_old_sigaction(struct tcb *tcp, long addr)
580{
581 struct old_sigaction sa;
Elliott Hughes458b3f22014-02-28 23:21:35 +0000582 int r;
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000583
584 if (!addr) {
585 tprints("NULL");
586 return;
587 }
588 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
589 tprintf("%#lx", addr);
590 return;
591 }
Elliott Hughes458b3f22014-02-28 23:21:35 +0000592
593#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
594 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
595 struct old_sigaction32 sa32;
596 r = umove(tcp, addr, &sa32);
597 if (r >= 0) {
598 memset(&sa, 0, sizeof(sa));
599 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
600 sa.sa_flags = sa32.sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000601#if HAVE_SA_RESTORER && defined SA_RESTORER
Elliott Hughes458b3f22014-02-28 23:21:35 +0000602 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100603#endif
Elliott Hughes458b3f22014-02-28 23:21:35 +0000604 sa.sa_mask = sa32.sa_mask;
605 }
606 } else
607#endif
608 {
609 r = umove(tcp, addr, &sa);
610 }
611 if (r < 0) {
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000612 tprints("{...}");
613 return;
614 }
615
616 /* Architectures using function pointers, like
617 * hppa, may need to manipulate the function pointer
618 * to compute the result of a comparison. However,
619 * the __sa_handler function pointer exists only in
620 * the address space of the traced process, and can't
621 * be manipulated by strace. In order to prevent the
622 * compiler from generating code to manipulate
623 * __sa_handler we cast the function pointers to long. */
624 if ((long)sa.__sa_handler == (long)SIG_ERR)
625 tprints("{SIG_ERR, ");
626 else if ((long)sa.__sa_handler == (long)SIG_DFL)
627 tprints("{SIG_DFL, ");
628 else if ((long)sa.__sa_handler == (long)SIG_IGN)
629 tprints("{SIG_IGN, ");
630 else
631 tprintf("{%#lx, ", (long) sa.__sa_handler);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800632#ifdef MIPS
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000633 tprintsigmask_addr("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800634#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000635 tprintsigmask_val("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800636#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000637 tprints(", ");
638 printflags(sigact_flags, sa.sa_flags, "SA_???");
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +0000639#if HAVE_SA_RESTORER && defined SA_RESTORER
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000640 if (sa.sa_flags & SA_RESTORER)
641 tprintf(", %p", sa.sa_restorer);
642#endif
643 tprints("}");
644}
645
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000646int
Denys Vlasenko12014262011-05-30 14:00:14 +0200647sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000648{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000649 if (entering(tcp)) {
650 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200651 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000652 decode_old_sigaction(tcp, tcp->u_arg[1]);
653 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000654 } else
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000655 decode_old_sigaction(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000656 return 0;
657}
658
659int
Denys Vlasenko12014262011-05-30 14:00:14 +0200660sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000661{
662 if (entering(tcp)) {
663 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200664 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000665 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +0000666 case (long) SIG_ERR:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200667 tprints("SIG_ERR");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000668 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000669 case (long) SIG_DFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200670 tprints("SIG_DFL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000671 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000672 case (long) SIG_IGN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200673 tprints("SIG_IGN");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000674 break;
675 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000676 tprintf("%#lx", tcp->u_arg[1]);
677 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000678 return 0;
679 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000680 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000681 switch (tcp->u_rval) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100682 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000683 tcp->auxstr = "SIG_ERR"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100684 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000685 tcp->auxstr = "SIG_DFL"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100686 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000687 tcp->auxstr = "SIG_IGN"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100688 default:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000689 tcp->auxstr = NULL;
690 }
691 return RVAL_HEX | RVAL_STR;
692 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000693 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000694}
695
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000696#endif /* HAVE_SIGACTION */
697
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000698int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000699sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000700{
Dmitry V. Levin5b9b7e12015-03-04 23:05:53 +0000701#if defined AARCH64 || defined ARM
Roland McGrath0f87c492003-06-03 23:29:04 +0000702 if (entering(tcp)) {
Dmitry V. Levin5b9b7e12015-03-04 23:05:53 +0000703# define SIZEOF_STRUCT_SIGINFO 128
Dmitry V. Levin26d16c82015-03-04 22:27:35 +0000704# define SIZEOF_STRUCT_SIGCONTEXT (21 * 4)
705# define OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK (5 * 4 + SIZEOF_STRUCT_SIGCONTEXT)
Dmitry V. Levin5b9b7e12015-03-04 23:05:53 +0000706 const long addr =
707# ifdef AARCH64
708 current_personality == 0 ?
709 (*aarch64_sp_ptr + SIZEOF_STRUCT_SIGINFO +
710 offsetof(struct ucontext, uc_sigmask)) :
711# endif
712 (*arm_sp_ptr +
713 OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000714 tprints("{mask=");
Dmitry V. Levin26d16c82015-03-04 22:27:35 +0000715 print_sigset_addr_len(tcp, addr, NSIG / 8);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000716 tprints("}");
Roland McGrath0f87c492003-06-03 23:29:04 +0000717 }
Roland McGrath0f87c492003-06-03 23:29:04 +0000718#elif defined(S390) || defined(S390X)
Roland McGrath0f87c492003-06-03 23:29:04 +0000719 if (entering(tcp)) {
Dmitry V. Levin085411b2015-03-04 21:40:00 +0000720 long mask[NSIG / 8 / sizeof(long)];
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000721 tprints("{mask=");
Dmitry V. Levin20eca8a2015-03-05 22:10:15 +0000722 const long addr = *s390_frame_ptr + __SIGNAL_FRAMESIZE;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000723 if (umove(tcp, addr, &mask) < 0) {
724 tprintf("%#lx", addr);
725 } else {
Dmitry V. Levin085411b2015-03-04 21:40:00 +0000726# ifdef S390
Dmitry V. Levin20eca8a2015-03-05 22:10:15 +0000727 long v = mask[0];
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000728 mask[0] = mask[1];
Dmitry V. Levin20eca8a2015-03-05 22:10:15 +0000729 mask[1] = v;
Dmitry V. Levin085411b2015-03-04 21:40:00 +0000730# endif
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000731 tprintsigmask_addr("", mask);
732 }
733 tprints("}");
Roland McGrath0f87c492003-06-03 23:29:04 +0000734 }
Dmitry V. Levin5dd336b2015-02-23 16:18:09 +0000735#elif defined I386 || defined X86_64 || defined X32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000736 if (entering(tcp)) {
Dmitry V. Levinccb4fda2015-03-04 12:19:55 +0000737# ifndef I386
738 if (current_personality != 1) {
739 const unsigned long addr =
740 (unsigned long) *x86_64_rsp_ptr +
741 offsetof(struct ucontext, uc_sigmask);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000742 tprints("{mask=");
Dmitry V. Levinccb4fda2015-03-04 12:19:55 +0000743 print_sigset_addr_len(tcp, addr, NSIG / 8);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000744 tprints("}");
Dmitry V. Levinccb4fda2015-03-04 12:19:55 +0000745 return 0;
746 }
747# endif
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000748 /*
749 * On i386, sigcontext is followed on stack by struct fpstate
750 * and after it an additional u32 extramask which holds
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200751 * upper half of the mask.
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100752 */
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000753 struct {
754 uint32_t struct_sigcontext_padding1[20];
755 uint32_t oldmask;
756 uint32_t struct_sigcontext_padding2;
757 uint32_t struct_fpstate_padding[156];
758 uint32_t extramask;
759 } frame;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000760 tprints("{mask=");
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000761 if (umove(tcp, *i386_esp_ptr, &frame) < 0) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000762 tprintf("%#lx", (unsigned long) *i386_esp_ptr);
763 } else {
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000764 uint32_t mask[2] = { frame.oldmask, frame.extramask };
765 tprintsigmask_addr("", mask);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000766 }
767 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000768 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000769#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000770 if (entering(tcp)) {
Dmitry V. Levin1e8a4542015-03-04 12:11:31 +0000771 long addr;
772 if (upeek(tcp->pid, PT_R12, &addr) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000773 return 0;
Dmitry V. Levin1e8a4542015-03-04 12:11:31 +0000774 /* offsetof(struct sigframe, sc) */
775# define OFFSETOF_STRUCT_SIGFRAME_SC 0xA0
776 addr += 16 + OFFSETOF_STRUCT_SIGFRAME_SC +
777 offsetof(struct sigcontext, sc_mask);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000778 tprints("{mask=");
Dmitry V. Levin1e8a4542015-03-04 12:11:31 +0000779 print_sigset_addr_len(tcp, addr, NSIG / 8);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000780 tprints("}");
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000781 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000782#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +0000783 if (entering(tcp)) {
Dmitry V. Levin577be252015-03-04 16:01:47 +0000784 long esp = ppc_regs.gpr[1];
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000785 struct sigcontext sc;
Anton Blanchardce6e33b2013-06-26 15:53:33 +0200786
Andreas Schwabedb39342010-02-23 00:18:51 +0100787 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200788#ifdef POWERPC64
789 if (current_personality == 0)
790 esp += 128;
791 else
Andreas Schwabedb39342010-02-23 00:18:51 +0100792#endif
Dmitry V. Levin577be252015-03-04 16:01:47 +0000793 esp += 64;
794
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000795 tprints("{mask=");
Dmitry V. Levin577be252015-03-04 16:01:47 +0000796 if (umove(tcp, esp, &sc) < 0) {
797 tprintf("%#lx", esp);
798 } else {
799 unsigned long mask[NSIG / 8 / sizeof(long)];
800#ifdef POWERPC64
Dmitry V. Levin67dab702015-03-05 04:29:37 +0000801 mask[0] = sc.oldmask | (sc._unused[3] << 32);
802#else
803 mask[0] = sc.oldmask;
804 mask[1] = sc._unused[3];
Dmitry V. Levin577be252015-03-04 16:01:47 +0000805#endif
Dmitry V. Levin577be252015-03-04 16:01:47 +0000806 tprintsigmask_val("", mask);
807 }
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000808 tprints("}");
Roland McGrath0f87c492003-06-03 23:29:04 +0000809 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000810#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000811 if (entering(tcp)) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000812 long addr;
813 if (upeek(tcp->pid, 4*PT_USP, &addr) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000814 return 0;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000815 addr += offsetof(struct sigcontext, sc_mask);
816 tprints("{mask=");
817 print_sigset_addr_len(tcp, addr, NSIG / 8);
818 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000819 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000820#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821 if (entering(tcp)) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000822 long addr;
823 if (upeek(tcp->pid, REG_FP, &addr) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000824 return 0;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000825 addr += offsetof(struct sigcontext, sc_mask);
826 tprints("{mask=");
827 print_sigset_addr_len(tcp, addr, NSIG / 8);
828 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000829 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100830#elif defined(SPARC) || defined(SPARC64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200831 if (entering(tcp)) {
Dmitry V. Levindb199362015-03-04 17:52:42 +0000832 long fp = sparc_regs.u_regs[U_REG_FP] + sizeof(struct sparc_stackf);
833 struct {
834 m_siginfo_t si;
835 void *fpu_save;
836 long insns[2] __attribute__ ((aligned (8)));
837 unsigned int extramask[NSIG / 8 / sizeof(int) - 1];
838 } frame;
839
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000840 tprints("{mask=");
Dmitry V. Levindb199362015-03-04 17:52:42 +0000841 if (umove(tcp, fp, &frame) < 0) {
842 tprintf("%#lx", fp);
843 } else {
844 unsigned int mask[NSIG / 8 / sizeof(int)];
845
846 mask[0] = frame.si.si_mask;
847 memcpy(mask + 1, frame.extramask, sizeof(frame.extramask));
848 tprintsigmask_val("", mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000849 }
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000850 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851 }
Dmitry V. Levinfd6d2072015-03-04 20:04:02 +0000852#elif defined MIPS
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200853 if (entering(tcp)) {
Dmitry V. Levinfd6d2072015-03-04 20:04:02 +0000854# if defined LINUX_MIPSO32
855 /*
856 * offsetof(struct sigframe, sf_mask) ==
857 * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct sigcontext)
858 */
859 const long addr = mips_REG_SP + 6 * 4 +
860 sizeof(struct sigcontext);
861# else
862 /*
863 * This decodes rt_sigreturn.
864 * The 64-bit ABIs do not have sigreturn.
865 *
866 * offsetof(struct rt_sigframe, rs_uc) ==
867 * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct siginfo)
868 */
869 const long addr = mips_REG_SP + 6 * 4 + 128 +
870 offsetof(struct ucontext, uc_sigmask);
871# endif
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000872 tprints("{mask=");
Dmitry V. Levinfd6d2072015-03-04 20:04:02 +0000873 print_sigset_addr_len(tcp, addr, NSIG / 8);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000874 tprints("}");
Wichert Akkermanf90da011999-10-31 21:15:38 +0000875 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000876#elif defined(CRISV10) || defined(CRISV32)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000877 if (entering(tcp)) {
878 long regs[PT_MAX+1];
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000879 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100880 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000881 return 0;
882 }
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000883 const long addr = regs[PT_USP] +
884 offsetof(struct sigcontext, oldmask);
885 tprints("{mask=");
886 print_sigset_addr_len(tcp, addr, NSIG / 8);
887 tprints("}");
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000888 }
Chris Metcalfc8c66982009-12-28 10:00:15 -0500889#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500890 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200891 /* offset of ucontext in the kernel's sigframe structure */
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000892# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
893 const long addr = tile_regs.sp + SIGFRAME_UC_OFFSET +
894 offsetof(struct ucontext, uc_sigmask);
895 tprints("{mask=");
896 print_sigset_addr_len(tcp, addr, NSIG / 8);
897 tprints("}");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500898 }
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200899#elif defined(MICROBLAZE)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200900 /* TODO: Verify that this is correct... */
901 if (entering(tcp)) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000902 long addr;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200903 /* Read r1, the stack pointer. */
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000904 if (upeek(tcp->pid, 1 * 4, &addr) < 0)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200905 return 0;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000906 addr += offsetof(struct sigcontext, oldmask);
907 tprints("{mask=");
908 print_sigset_addr_len(tcp, addr, NSIG / 8);
909 tprints("}");
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200910 }
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000911#else
Dmitry V. Levind4689922015-03-04 13:12:06 +0000912# warning sigreturn/rt_sigreturn signal mask decoding is not implemented for this architecture
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000913#endif
Dmitry V. Levinf112d072012-05-15 00:13:59 +0000914 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000915}
916
917int
Denys Vlasenko12014262011-05-30 14:00:14 +0200918sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000919{
920 if (exiting(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000921 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000922 }
923 return RVAL_HEX | RVAL_STR;
924}
925
926int
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000927sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000928{
929 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000930 tprintsigmask_val("", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000931 }
932 return 0;
933}
934
Denys Vlasenko84703742012-02-25 02:38:52 +0100935#if !defined SS_ONSTACK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000936#define SS_ONSTACK 1
937#define SS_DISABLE 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000938#endif
939
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000940#include "xlat/sigaltstack_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000941
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000942static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200943print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944{
945 stack_t ss;
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000946 int r;
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000947
948 if (!addr) {
949 tprints("NULL");
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000950 return;
951 }
952
953#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
954 if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
955 struct {
956 uint32_t ss_sp;
957 int32_t ss_flags;
958 uint32_t ss_size;
959 } ss32;
960 r = umove(tcp, addr, &ss32);
961 if (r >= 0) {
962 memset(&ss, 0, sizeof(ss));
963 ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
964 ss.ss_flags = ss32.ss_flags;
965 ss.ss_size = (unsigned long) ss32.ss_size;
966 }
967 } else
968#endif
969 {
970 r = umove(tcp, addr, &ss);
971 }
972 if (r < 0) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000973 tprintf("%#lx", addr);
974 } else {
975 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
976 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
977 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
978 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000979}
980
981int
Denys Vlasenko12014262011-05-30 14:00:14 +0200982sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983{
984 if (entering(tcp)) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000985 print_stack_t(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986 }
987 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200988 tprints(", ");
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000989 print_stack_t(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990 }
991 return 0;
992}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000993
994#ifdef HAVE_SIGACTION
995
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200996/* "Old" sigprocmask, which operates with word-sized signal masks */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000997int
Denys Vlasenko12014262011-05-30 14:00:14 +0200998sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000999{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001000# ifdef ALPHA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001001 if (entering(tcp)) {
Mike Frysingerdde045c2012-03-15 00:45:33 -04001002 /*
1003 * Alpha/OSF is different: it doesn't pass in two pointers,
1004 * but rather passes in the new bitmask as an argument and
1005 * then returns the old bitmask. This "works" because we
1006 * only have 64 signals to worry about. If you want more,
1007 * use of the rt_sigprocmask syscall is required.
1008 * Alpha:
1009 * old = osf_sigprocmask(how, new);
1010 * Everyone else:
1011 * ret = sigprocmask(how, &new, &old, ...);
1012 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001013 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001014 tprintsigmask_val(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015 }
1016 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001017 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018 return RVAL_HEX | RVAL_STR;
1019 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001020# else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001022 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001023 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001024 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001025 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026 }
1027 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001028 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001030 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001031 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001033# endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034 return 0;
1035}
1036
1037#endif /* HAVE_SIGACTION */
1038
1039int
Denys Vlasenko12014262011-05-30 14:00:14 +02001040sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041{
1042 if (entering(tcp)) {
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001043 tprintf("%ld, %s",
1044 widen_to_long(tcp->u_arg[0]),
1045 signame(tcp->u_arg[1])
1046 );
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001047 }
1048 return 0;
1049}
1050
Roland McGrath8ffc3522003-07-09 09:47:49 +00001051int
Denys Vlasenko12014262011-05-30 14:00:14 +02001052sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001053{
1054 if (entering(tcp)) {
1055 tprintf("%ld, %ld, %s",
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001056 widen_to_long(tcp->u_arg[0]),
1057 widen_to_long(tcp->u_arg[1]),
1058 signame(tcp->u_arg[2])
1059 );
Roland McGrath8ffc3522003-07-09 09:47:49 +00001060 }
1061 return 0;
1062}
Roland McGrath8ffc3522003-07-09 09:47:49 +00001063
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001064int
Denys Vlasenko12014262011-05-30 14:00:14 +02001065sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001066{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001067 if (exiting(tcp)) {
1068 if (syserror(tcp))
1069 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001070 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001071 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072 }
1073 return 0;
1074}
1075
Denys Vlasenko12014262011-05-30 14:00:14 +02001076int
1077sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001078{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001079 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001080 if (entering(tcp)) {
1081 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001082 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001083 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1084 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001085 }
1086 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001087 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001088 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001089 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001090 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001091 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001092 }
1093 return 0;
1094}
1095
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096/* Structure describing the action to be taken when a signal arrives. */
1097struct new_sigaction
1098{
Denys Vlasenko86d94842013-02-08 12:59:13 +01001099 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001100#ifdef MIPS
1101 unsigned int sa_flags;
1102 void (*__sa_handler)(int);
1103#else
Denys Vlasenko86d94842013-02-08 12:59:13 +01001104 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001105 unsigned long sa_flags;
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001106#endif /* !MIPS */
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001107#if HAVE_SA_RESTORER
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001108 void (*sa_restorer)(void);
1109#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001110 /* Kernel treats sa_mask as an array of longs. */
1111 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1112};
1113/* Same for i386-on-x86_64 and similar cases */
1114struct new_sigaction32
1115{
1116 uint32_t __sa_handler;
1117 uint32_t sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001118#if HAVE_SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001119 uint32_t sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001120#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001121 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001122};
1123
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001124static void
1125decode_new_sigaction(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126{
1127 struct new_sigaction sa;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001128 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001129
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001130 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001131 tprints("NULL");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001132 return;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001133 }
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001134 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001135 tprintf("%#lx", addr);
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001136 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001137 }
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001138#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Denys Vlasenko9fd4f962012-03-19 09:36:42 +01001139 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001140 struct new_sigaction32 sa32;
1141 r = umove(tcp, addr, &sa32);
1142 if (r >= 0) {
1143 memset(&sa, 0, sizeof(sa));
1144 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1145 sa.sa_flags = sa32.sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001146#if HAVE_SA_RESTORER && defined SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001147 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001148#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001149 /* Kernel treats sa_mask as an array of longs.
1150 * For 32-bit process, "long" is uint32_t, thus, for example,
1151 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1152 * But for (64-bit) kernel, 32th bit in sa_mask is
1153 * 32th bit in 0th (64-bit) long!
1154 * For little-endian, it's the same.
1155 * For big-endian, we swap 32-bit words.
1156 */
1157 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1158 }
1159 } else
1160#endif
1161 {
1162 r = umove(tcp, addr, &sa);
1163 }
1164 if (r < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001165 tprints("{...}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001166 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001167 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001168 /* Architectures using function pointers, like
1169 * hppa, may need to manipulate the function pointer
1170 * to compute the result of a comparison. However,
Denys Vlasenko86d94842013-02-08 12:59:13 +01001171 * the __sa_handler function pointer exists only in
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001172 * the address space of the traced process, and can't
1173 * be manipulated by strace. In order to prevent the
1174 * compiler from generating code to manipulate
Denys Vlasenko86d94842013-02-08 12:59:13 +01001175 * __sa_handler we cast the function pointers to long. */
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001176 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001177 tprints("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001178 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001179 tprints("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001180 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001181 tprints("{SIG_IGN, ");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001182 else
1183 tprintf("{%#lx, ", (long) sa.__sa_handler);
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001184 /*
1185 * Sigset size is in tcp->u_arg[4] (SPARC)
1186 * or in tcp->u_arg[3] (all other),
1187 * but kernel won't handle sys_rt_sigaction
1188 * with wrong sigset size (just returns EINVAL instead).
1189 * We just fetch the right size, which is NSIG / 8.
1190 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001191 tprintsigmask_val("", sa.sa_mask);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001192 tprints(", ");
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001193
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001194 printflags(sigact_flags, sa.sa_flags, "SA_???");
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001195#if HAVE_SA_RESTORER && defined SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001196 if (sa.sa_flags & SA_RESTORER)
1197 tprintf(", %p", sa.sa_restorer);
1198#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001199 tprints("}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001200}
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001201
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001202int
1203sys_rt_sigaction(struct tcb *tcp)
1204{
1205 if (entering(tcp)) {
1206 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001207 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001208 decode_new_sigaction(tcp, tcp->u_arg[1]);
1209 tprints(", ");
1210 } else {
1211 decode_new_sigaction(tcp, tcp->u_arg[2]);
Denys Vlasenko9472a272013-02-12 11:43:46 +01001212#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001213 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1214#elif defined(ALPHA)
1215 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1216#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001217 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001218#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001219 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001220 return 0;
1221}
1222
Denys Vlasenko1d632462009-04-14 12:51:00 +00001223int
1224sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001225{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001226 if (exiting(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001227 /*
1228 * One of the few syscalls where sigset size (arg[1])
1229 * is allowed to be <= NSIG / 8, not strictly ==.
1230 * This allows non-rt sigpending() syscall
1231 * to reuse rt_sigpending() code in kernel.
1232 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001233 if (syserror(tcp))
1234 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001235 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001236 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1237 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001238 }
1239 return 0;
1240}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001241
1242int
1243sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001244{
1245 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001246 /* NB: kernel requires arg[1] == NSIG / 8 */
1247 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1248 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001249 }
1250 return 0;
1251}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001252
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001253static void
1254print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1255{
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001256 printsignal(sig);
1257 tprints(", ");
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001258 printsiginfo_at(tcp, uinfo);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001259}
1260
Denys Vlasenko1d632462009-04-14 12:51:00 +00001261int
1262sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001263{
1264 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001265 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001266 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1267 }
1268 return 0;
1269}
1270
1271int
1272sys_rt_tgsigqueueinfo(struct tcb *tcp)
1273{
1274 if (entering(tcp)) {
1275 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1276 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001277 }
1278 return 0;
1279}
1280
Denys Vlasenko1d632462009-04-14 12:51:00 +00001281int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001282{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001283 /* NB: kernel requires arg[3] == NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001284 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001285 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001286 tprints(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001287 /* This is the only "return" parameter, */
1288 if (tcp->u_arg[1] != 0)
1289 return 0;
1290 /* ... if it's NULL, can decode all on entry */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001291 tprints("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001293 else if (tcp->u_arg[1] != 0) {
1294 /* syscall exit, and u_arg[1] wasn't NULL */
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001295 printsiginfo_at(tcp, tcp->u_arg[1]);
1296 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001297 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001298 else {
1299 /* syscall exit, and u_arg[1] was NULL */
1300 return 0;
1301 }
1302 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001303 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001304 return 0;
1305};
1306
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001307int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001308sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001309{
1310 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001311 tprints("<... resuming interrupted call ...>");
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001312 return 0;
1313}
1314
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001315static int
1316do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00001317{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001318 /* NB: kernel requires arg[2] == NSIG / 8 */
Roland McGrathf46ccd32007-08-02 01:15:59 +00001319 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001320 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001321 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001322 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00001323 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001324 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001325 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001326 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1327 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00001328 }
1329 return 0;
1330}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001331
1332int
1333sys_signalfd(struct tcb *tcp)
1334{
1335 return do_signalfd(tcp, -1);
1336}
1337
1338int
1339sys_signalfd4(struct tcb *tcp)
1340{
1341 return do_signalfd(tcp, 3);
1342}