blob: 6aab54f700cd4a75356a15709f6ddcafc83fd2c4 [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)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200720 long usp;
Dmitry V. Levin085411b2015-03-04 21:40:00 +0000721 long mask[NSIG / 8 / sizeof(long)];
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200722 if (upeek(tcp->pid, PT_GPR15, &usp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000723 return 0;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000724 tprints("{mask=");
725 const long addr = usp + __SIGNAL_FRAMESIZE;
726 if (umove(tcp, addr, &mask) < 0) {
727 tprintf("%#lx", addr);
728 } else {
Dmitry V. Levin085411b2015-03-04 21:40:00 +0000729# ifdef S390
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000730 usp = mask[0];
731 mask[0] = mask[1];
732 mask[1] = usp;
Dmitry V. Levin085411b2015-03-04 21:40:00 +0000733# endif
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000734 tprintsigmask_addr("", mask);
735 }
736 tprints("}");
Roland McGrath0f87c492003-06-03 23:29:04 +0000737 }
Dmitry V. Levin5dd336b2015-02-23 16:18:09 +0000738#elif defined I386 || defined X86_64 || defined X32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739 if (entering(tcp)) {
Dmitry V. Levinccb4fda2015-03-04 12:19:55 +0000740# ifndef I386
741 if (current_personality != 1) {
742 const unsigned long addr =
743 (unsigned long) *x86_64_rsp_ptr +
744 offsetof(struct ucontext, uc_sigmask);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000745 tprints("{mask=");
Dmitry V. Levinccb4fda2015-03-04 12:19:55 +0000746 print_sigset_addr_len(tcp, addr, NSIG / 8);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000747 tprints("}");
Dmitry V. Levinccb4fda2015-03-04 12:19:55 +0000748 return 0;
749 }
750# endif
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000751 /*
752 * On i386, sigcontext is followed on stack by struct fpstate
753 * and after it an additional u32 extramask which holds
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200754 * upper half of the mask.
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100755 */
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000756 struct {
757 uint32_t struct_sigcontext_padding1[20];
758 uint32_t oldmask;
759 uint32_t struct_sigcontext_padding2;
760 uint32_t struct_fpstate_padding[156];
761 uint32_t extramask;
762 } frame;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000763 tprints("{mask=");
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000764 if (umove(tcp, *i386_esp_ptr, &frame) < 0) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000765 tprintf("%#lx", (unsigned long) *i386_esp_ptr);
766 } else {
Dmitry V. Levina1c5e072015-03-05 01:14:33 +0000767 uint32_t mask[2] = { frame.oldmask, frame.extramask };
768 tprintsigmask_addr("", mask);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000769 }
770 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000771 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000772#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000773 if (entering(tcp)) {
Dmitry V. Levin1e8a4542015-03-04 12:11:31 +0000774 long addr;
775 if (upeek(tcp->pid, PT_R12, &addr) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000776 return 0;
Dmitry V. Levin1e8a4542015-03-04 12:11:31 +0000777 /* offsetof(struct sigframe, sc) */
778# define OFFSETOF_STRUCT_SIGFRAME_SC 0xA0
779 addr += 16 + OFFSETOF_STRUCT_SIGFRAME_SC +
780 offsetof(struct sigcontext, sc_mask);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000781 tprints("{mask=");
Dmitry V. Levin1e8a4542015-03-04 12:11:31 +0000782 print_sigset_addr_len(tcp, addr, NSIG / 8);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000783 tprints("}");
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000784 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000785#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +0000786 if (entering(tcp)) {
Dmitry V. Levin577be252015-03-04 16:01:47 +0000787 long esp = ppc_regs.gpr[1];
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000788 struct sigcontext sc;
Anton Blanchardce6e33b2013-06-26 15:53:33 +0200789
Andreas Schwabedb39342010-02-23 00:18:51 +0100790 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200791#ifdef POWERPC64
792 if (current_personality == 0)
793 esp += 128;
794 else
Andreas Schwabedb39342010-02-23 00:18:51 +0100795#endif
Dmitry V. Levin577be252015-03-04 16:01:47 +0000796 esp += 64;
797
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000798 tprints("{mask=");
Dmitry V. Levin577be252015-03-04 16:01:47 +0000799 if (umove(tcp, esp, &sc) < 0) {
800 tprintf("%#lx", esp);
801 } else {
802 unsigned long mask[NSIG / 8 / sizeof(long)];
803#ifdef POWERPC64
Dmitry V. Levin67dab702015-03-05 04:29:37 +0000804 mask[0] = sc.oldmask | (sc._unused[3] << 32);
805#else
806 mask[0] = sc.oldmask;
807 mask[1] = sc._unused[3];
Dmitry V. Levin577be252015-03-04 16:01:47 +0000808#endif
Dmitry V. Levin577be252015-03-04 16:01:47 +0000809 tprintsigmask_val("", mask);
810 }
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000811 tprints("}");
Roland McGrath0f87c492003-06-03 23:29:04 +0000812 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000813#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000814 if (entering(tcp)) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000815 long addr;
816 if (upeek(tcp->pid, 4*PT_USP, &addr) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000817 return 0;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000818 addr += offsetof(struct sigcontext, sc_mask);
819 tprints("{mask=");
820 print_sigset_addr_len(tcp, addr, NSIG / 8);
821 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000822 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000823#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000824 if (entering(tcp)) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000825 long addr;
826 if (upeek(tcp->pid, REG_FP, &addr) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000827 return 0;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000828 addr += offsetof(struct sigcontext, sc_mask);
829 tprints("{mask=");
830 print_sigset_addr_len(tcp, addr, NSIG / 8);
831 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000832 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100833#elif defined(SPARC) || defined(SPARC64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200834 if (entering(tcp)) {
Dmitry V. Levindb199362015-03-04 17:52:42 +0000835 long fp = sparc_regs.u_regs[U_REG_FP] + sizeof(struct sparc_stackf);
836 struct {
837 m_siginfo_t si;
838 void *fpu_save;
839 long insns[2] __attribute__ ((aligned (8)));
840 unsigned int extramask[NSIG / 8 / sizeof(int) - 1];
841 } frame;
842
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000843 tprints("{mask=");
Dmitry V. Levindb199362015-03-04 17:52:42 +0000844 if (umove(tcp, fp, &frame) < 0) {
845 tprintf("%#lx", fp);
846 } else {
847 unsigned int mask[NSIG / 8 / sizeof(int)];
848
849 mask[0] = frame.si.si_mask;
850 memcpy(mask + 1, frame.extramask, sizeof(frame.extramask));
851 tprintsigmask_val("", mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000852 }
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000853 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000854 }
Dmitry V. Levinfd6d2072015-03-04 20:04:02 +0000855#elif defined MIPS
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200856 if (entering(tcp)) {
Dmitry V. Levinfd6d2072015-03-04 20:04:02 +0000857# if defined LINUX_MIPSO32
858 /*
859 * offsetof(struct sigframe, sf_mask) ==
860 * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct sigcontext)
861 */
862 const long addr = mips_REG_SP + 6 * 4 +
863 sizeof(struct sigcontext);
864# else
865 /*
866 * This decodes rt_sigreturn.
867 * The 64-bit ABIs do not have sigreturn.
868 *
869 * offsetof(struct rt_sigframe, rs_uc) ==
870 * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct siginfo)
871 */
872 const long addr = mips_REG_SP + 6 * 4 + 128 +
873 offsetof(struct ucontext, uc_sigmask);
874# endif
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000875 tprints("{mask=");
Dmitry V. Levinfd6d2072015-03-04 20:04:02 +0000876 print_sigset_addr_len(tcp, addr, NSIG / 8);
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000877 tprints("}");
Wichert Akkermanf90da011999-10-31 21:15:38 +0000878 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000879#elif defined(CRISV10) || defined(CRISV32)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000880 if (entering(tcp)) {
881 long regs[PT_MAX+1];
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000882 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100883 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000884 return 0;
885 }
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000886 const long addr = regs[PT_USP] +
887 offsetof(struct sigcontext, oldmask);
888 tprints("{mask=");
889 print_sigset_addr_len(tcp, addr, NSIG / 8);
890 tprints("}");
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000891 }
Chris Metcalfc8c66982009-12-28 10:00:15 -0500892#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500893 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200894 /* offset of ucontext in the kernel's sigframe structure */
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000895# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
896 const long addr = tile_regs.sp + SIGFRAME_UC_OFFSET +
897 offsetof(struct ucontext, uc_sigmask);
898 tprints("{mask=");
899 print_sigset_addr_len(tcp, addr, NSIG / 8);
900 tprints("}");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500901 }
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200902#elif defined(MICROBLAZE)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200903 /* TODO: Verify that this is correct... */
904 if (entering(tcp)) {
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000905 long addr;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200906 /* Read r1, the stack pointer. */
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000907 if (upeek(tcp->pid, 1 * 4, &addr) < 0)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200908 return 0;
Dmitry V. Levinf3582cd2015-03-04 23:55:25 +0000909 addr += offsetof(struct sigcontext, oldmask);
910 tprints("{mask=");
911 print_sigset_addr_len(tcp, addr, NSIG / 8);
912 tprints("}");
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200913 }
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000914#else
Dmitry V. Levind4689922015-03-04 13:12:06 +0000915# warning sigreturn/rt_sigreturn signal mask decoding is not implemented for this architecture
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000916#endif
Dmitry V. Levinf112d072012-05-15 00:13:59 +0000917 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000918}
919
920int
Denys Vlasenko12014262011-05-30 14:00:14 +0200921sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000922{
923 if (exiting(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000924 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000925 }
926 return RVAL_HEX | RVAL_STR;
927}
928
929int
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000930sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000931{
932 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000933 tprintsigmask_val("", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000934 }
935 return 0;
936}
937
Denys Vlasenko84703742012-02-25 02:38:52 +0100938#if !defined SS_ONSTACK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000939#define SS_ONSTACK 1
940#define SS_DISABLE 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000941#endif
942
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000943#include "xlat/sigaltstack_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000945static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200946print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000947{
948 stack_t ss;
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000949 int r;
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000950
951 if (!addr) {
952 tprints("NULL");
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000953 return;
954 }
955
956#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
957 if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
958 struct {
959 uint32_t ss_sp;
960 int32_t ss_flags;
961 uint32_t ss_size;
962 } ss32;
963 r = umove(tcp, addr, &ss32);
964 if (r >= 0) {
965 memset(&ss, 0, sizeof(ss));
966 ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
967 ss.ss_flags = ss32.ss_flags;
968 ss.ss_size = (unsigned long) ss32.ss_size;
969 }
970 } else
971#endif
972 {
973 r = umove(tcp, addr, &ss);
974 }
975 if (r < 0) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000976 tprintf("%#lx", addr);
977 } else {
978 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
979 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
980 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
981 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982}
983
984int
Denys Vlasenko12014262011-05-30 14:00:14 +0200985sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986{
987 if (entering(tcp)) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000988 print_stack_t(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000989 }
990 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200991 tprints(", ");
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000992 print_stack_t(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000993 }
994 return 0;
995}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000996
997#ifdef HAVE_SIGACTION
998
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200999/* "Old" sigprocmask, which operates with word-sized signal masks */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001000int
Denys Vlasenko12014262011-05-30 14:00:14 +02001001sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001002{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001003# ifdef ALPHA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001004 if (entering(tcp)) {
Mike Frysingerdde045c2012-03-15 00:45:33 -04001005 /*
1006 * Alpha/OSF is different: it doesn't pass in two pointers,
1007 * but rather passes in the new bitmask as an argument and
1008 * then returns the old bitmask. This "works" because we
1009 * only have 64 signals to worry about. If you want more,
1010 * use of the rt_sigprocmask syscall is required.
1011 * Alpha:
1012 * old = osf_sigprocmask(how, new);
1013 * Everyone else:
1014 * ret = sigprocmask(how, &new, &old, ...);
1015 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001017 tprintsigmask_val(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018 }
1019 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001020 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021 return RVAL_HEX | RVAL_STR;
1022 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001023# else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001024 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001025 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001026 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001027 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001028 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029 }
1030 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001031 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001033 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001034 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001035 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001036# endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001037 return 0;
1038}
1039
1040#endif /* HAVE_SIGACTION */
1041
1042int
Denys Vlasenko12014262011-05-30 14:00:14 +02001043sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001044{
1045 if (entering(tcp)) {
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001046 tprintf("%ld, %s",
1047 widen_to_long(tcp->u_arg[0]),
1048 signame(tcp->u_arg[1])
1049 );
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050 }
1051 return 0;
1052}
1053
Roland McGrath8ffc3522003-07-09 09:47:49 +00001054int
Denys Vlasenko12014262011-05-30 14:00:14 +02001055sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001056{
1057 if (entering(tcp)) {
1058 tprintf("%ld, %ld, %s",
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001059 widen_to_long(tcp->u_arg[0]),
1060 widen_to_long(tcp->u_arg[1]),
1061 signame(tcp->u_arg[2])
1062 );
Roland McGrath8ffc3522003-07-09 09:47:49 +00001063 }
1064 return 0;
1065}
Roland McGrath8ffc3522003-07-09 09:47:49 +00001066
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001067int
Denys Vlasenko12014262011-05-30 14:00:14 +02001068sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001069{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001070 if (exiting(tcp)) {
1071 if (syserror(tcp))
1072 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001073 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001074 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001075 }
1076 return 0;
1077}
1078
Denys Vlasenko12014262011-05-30 14:00:14 +02001079int
1080sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001081{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001082 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001083 if (entering(tcp)) {
1084 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001085 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001086 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1087 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001088 }
1089 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001090 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001091 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001092 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001093 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001094 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001095 }
1096 return 0;
1097}
1098
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099/* Structure describing the action to be taken when a signal arrives. */
1100struct new_sigaction
1101{
Denys Vlasenko86d94842013-02-08 12:59:13 +01001102 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001103#ifdef MIPS
1104 unsigned int sa_flags;
1105 void (*__sa_handler)(int);
1106#else
Denys Vlasenko86d94842013-02-08 12:59:13 +01001107 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001108 unsigned long sa_flags;
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001109#endif /* !MIPS */
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001110#if HAVE_SA_RESTORER
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001111 void (*sa_restorer)(void);
1112#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001113 /* Kernel treats sa_mask as an array of longs. */
1114 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1115};
1116/* Same for i386-on-x86_64 and similar cases */
1117struct new_sigaction32
1118{
1119 uint32_t __sa_handler;
1120 uint32_t sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001121#if HAVE_SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001122 uint32_t sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001123#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001124 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001125};
1126
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001127static void
1128decode_new_sigaction(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001129{
1130 struct new_sigaction sa;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001131 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001132
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001133 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001134 tprints("NULL");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001135 return;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001136 }
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001137 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001138 tprintf("%#lx", addr);
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001139 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001140 }
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001141#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Denys Vlasenko9fd4f962012-03-19 09:36:42 +01001142 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001143 struct new_sigaction32 sa32;
1144 r = umove(tcp, addr, &sa32);
1145 if (r >= 0) {
1146 memset(&sa, 0, sizeof(sa));
1147 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1148 sa.sa_flags = sa32.sa_flags;
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001149#if HAVE_SA_RESTORER && defined SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001150 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001151#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001152 /* Kernel treats sa_mask as an array of longs.
1153 * For 32-bit process, "long" is uint32_t, thus, for example,
1154 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1155 * But for (64-bit) kernel, 32th bit in sa_mask is
1156 * 32th bit in 0th (64-bit) long!
1157 * For little-endian, it's the same.
1158 * For big-endian, we swap 32-bit words.
1159 */
1160 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1161 }
1162 } else
1163#endif
1164 {
1165 r = umove(tcp, addr, &sa);
1166 }
1167 if (r < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001168 tprints("{...}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001169 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001170 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001171 /* Architectures using function pointers, like
1172 * hppa, may need to manipulate the function pointer
1173 * to compute the result of a comparison. However,
Denys Vlasenko86d94842013-02-08 12:59:13 +01001174 * the __sa_handler function pointer exists only in
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001175 * the address space of the traced process, and can't
1176 * be manipulated by strace. In order to prevent the
1177 * compiler from generating code to manipulate
Denys Vlasenko86d94842013-02-08 12:59:13 +01001178 * __sa_handler we cast the function pointers to long. */
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001179 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001180 tprints("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001181 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001182 tprints("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001183 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001184 tprints("{SIG_IGN, ");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001185 else
1186 tprintf("{%#lx, ", (long) sa.__sa_handler);
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001187 /*
1188 * Sigset size is in tcp->u_arg[4] (SPARC)
1189 * or in tcp->u_arg[3] (all other),
1190 * but kernel won't handle sys_rt_sigaction
1191 * with wrong sigset size (just returns EINVAL instead).
1192 * We just fetch the right size, which is NSIG / 8.
1193 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001194 tprintsigmask_val("", sa.sa_mask);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001195 tprints(", ");
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001196
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001197 printflags(sigact_flags, sa.sa_flags, "SA_???");
Dmitry V. Levin24b8eb02015-02-28 17:17:09 +00001198#if HAVE_SA_RESTORER && defined SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001199 if (sa.sa_flags & SA_RESTORER)
1200 tprintf(", %p", sa.sa_restorer);
1201#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001202 tprints("}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001203}
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001204
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001205int
1206sys_rt_sigaction(struct tcb *tcp)
1207{
1208 if (entering(tcp)) {
1209 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001210 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001211 decode_new_sigaction(tcp, tcp->u_arg[1]);
1212 tprints(", ");
1213 } else {
1214 decode_new_sigaction(tcp, tcp->u_arg[2]);
Denys Vlasenko9472a272013-02-12 11:43:46 +01001215#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001216 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1217#elif defined(ALPHA)
1218 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1219#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001220 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001221#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001222 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001223 return 0;
1224}
1225
Denys Vlasenko1d632462009-04-14 12:51:00 +00001226int
1227sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001229 if (exiting(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001230 /*
1231 * One of the few syscalls where sigset size (arg[1])
1232 * is allowed to be <= NSIG / 8, not strictly ==.
1233 * This allows non-rt sigpending() syscall
1234 * to reuse rt_sigpending() code in kernel.
1235 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001236 if (syserror(tcp))
1237 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001238 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001239 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1240 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001241 }
1242 return 0;
1243}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001244
1245int
1246sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001247{
1248 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001249 /* NB: kernel requires arg[1] == NSIG / 8 */
1250 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1251 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001252 }
1253 return 0;
1254}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001255
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001256static void
1257print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1258{
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001259 printsignal(sig);
1260 tprints(", ");
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001261 printsiginfo_at(tcp, uinfo);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001262}
1263
Denys Vlasenko1d632462009-04-14 12:51:00 +00001264int
1265sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001266{
1267 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001268 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001269 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1270 }
1271 return 0;
1272}
1273
1274int
1275sys_rt_tgsigqueueinfo(struct tcb *tcp)
1276{
1277 if (entering(tcp)) {
1278 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1279 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001280 }
1281 return 0;
1282}
1283
Denys Vlasenko1d632462009-04-14 12:51:00 +00001284int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001285{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001286 /* NB: kernel requires arg[3] == NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001287 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001288 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001289 tprints(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001290 /* This is the only "return" parameter, */
1291 if (tcp->u_arg[1] != 0)
1292 return 0;
1293 /* ... if it's NULL, can decode all on entry */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001294 tprints("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001295 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001296 else if (tcp->u_arg[1] != 0) {
1297 /* syscall exit, and u_arg[1] wasn't NULL */
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001298 printsiginfo_at(tcp, tcp->u_arg[1]);
1299 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001300 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001301 else {
1302 /* syscall exit, and u_arg[1] was NULL */
1303 return 0;
1304 }
1305 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001306 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001307 return 0;
1308};
1309
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001310int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001311sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001312{
1313 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001314 tprints("<... resuming interrupted call ...>");
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001315 return 0;
1316}
1317
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001318static int
1319do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00001320{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001321 /* NB: kernel requires arg[2] == NSIG / 8 */
Roland McGrathf46ccd32007-08-02 01:15:59 +00001322 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001323 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001324 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001325 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00001326 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001327 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001328 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001329 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1330 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00001331 }
1332 return 0;
1333}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001334
1335int
1336sys_signalfd(struct tcb *tcp)
1337{
1338 return do_signalfd(tcp, -1);
1339}
1340
1341int
1342sys_signalfd4(struct tcb *tcp)
1343{
1344 return do_signalfd(tcp, 3);
1345}