blob: d877c0a0d0a2f4185b0bc582c3faabab7a6030b3 [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. Levinfadf3792015-02-13 00:26:38 +000037#include "ptrace.h"
Dmitry V. Levin5503dd22015-02-13 02:12:14 +000038#include "regs.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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000072#ifdef HAVE_SIGACTION
73
Roland McGrath2638cb42002-12-15 23:58:41 +000074/* The libc headers do not define this constant since it should only be
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020075 used by the implementation. So we define it here. */
Dmitry V. Levin5c7f6272014-02-08 00:26:06 +000076#ifndef SA_RESTORER
77# ifdef ASM_SA_RESTORER
78# define SA_RESTORER ASM_SA_RESTORER
Roland McGrath2638cb42002-12-15 23:58:41 +000079# endif
80#endif
81
Mike Frysingerdd80a872014-08-14 00:30:24 -040082/* Some arches define this in their headers, but don't actually have it,
Mike Frysingerd632e102014-08-09 09:04:18 -040083 so we have to delete the define. */
Mike Frysingerdd80a872014-08-14 00:30:24 -040084#if defined(HPPA) || defined(IA64)
Mike Frysingerd632e102014-08-09 09:04:18 -040085# undef SA_RESTORER
86#endif
87
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000088#include "xlat/sigact_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000089#include "xlat/sigprocmaskcmds.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000090
91#endif /* HAVE_SIGACTION */
92
Nate Sammonsce780fc1999-03-29 23:23:13 +000093/* Anonymous realtime signals. */
94/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
95 constant. This is what we want. Otherwise, just use SIGRTMIN. */
96#ifdef SIGRTMIN
97#ifndef __SIGRTMIN
98#define __SIGRTMIN SIGRTMIN
99#define __SIGRTMAX SIGRTMAX /* likewise */
100#endif
101#endif
102
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200103/* Note on the size of sigset_t:
104 *
105 * In glibc, sigset_t is an array with space for 1024 bits (!),
106 * even though all arches supported by Linux have only 64 signals
107 * except MIPS, which has 128. IOW, it is 128 bytes long.
108 *
109 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
110 * However, some old syscall return only 32 lower bits (one word).
111 * Example: sys_sigpending vs sys_rt_sigpending.
112 *
113 * Be aware of this fact when you try to
114 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
115 * - sizeof(sigset_t) is much bigger than you think,
116 * it may overflow tcp->u_arg[] array, and it may try to copy more data
117 * than is really available in <something>.
118 * Similarly,
119 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
120 * may be a bad idea: it'll try to read much more data than needed
121 * to fetch a sigset_t.
122 * Use (NSIG / 8) as a size instead.
123 */
124
Roland McGrathee36ce12004-09-04 03:53:10 +0000125const char *
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000126signame(const int sig)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000127{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000128 static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200129
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000130 if (sig >= 0) {
131 const unsigned int s = sig;
132
133 if (s < nsignals)
134 return signalent[s];
Nate Sammonsce780fc1999-03-29 23:23:13 +0000135#ifdef SIGRTMIN
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000136 if (s >= __SIGRTMIN && s <= __SIGRTMAX) {
137 sprintf(buf, "SIGRT_%u", s - __SIGRTMIN);
138 return buf;
139 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200140#endif
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000141 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200142 sprintf(buf, "%d", sig);
143 return buf;
Nate Sammonsce780fc1999-03-29 23:23:13 +0000144}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000145
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000146static unsigned int
147popcount32(const uint32_t *a, unsigned int size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000149 unsigned int count = 0;
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200150
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000151 for (; size; ++a, --size) {
152 uint32_t x = *a;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000154#ifdef HAVE___BUILTIN_POPCOUNT
155 count += __builtin_popcount(x);
Denys Vlasenkoa8773792013-07-18 20:42:41 +0200156#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000157 for (; x; ++count)
158 x &= x - 1;
Nate Sammons4a121431999-04-06 01:19:39 +0000159#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100161
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000162 return count;
163}
164
165static const char *
166sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
167{
168 /*
169 * The maximum number of signal names to be printed is NSIG * 2 / 3.
170 * Most of signal names have length 7,
171 * average length of signal names is less than 7.
172 * The length of prefix string does not exceed 16.
173 */
174 static char outstr[128 + 8 * (NSIG * 2 / 3)];
175
176 char *s;
177 const uint32_t *mask;
178 uint32_t inverted_mask[NSIG / 32];
179 unsigned int size;
180 int i;
181 char sep;
182
183 s = stpcpy(outstr, prefix);
184
185 mask = sig_mask;
186 /* length of signal mask in 4-byte words */
187 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
188
189 /* check whether 2/3 or more bits are set */
190 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
191 /* show those signals that are NOT in the mask */
192 unsigned int j;
193 for (j = 0; j < size; ++j)
194 inverted_mask[j] = ~mask[j];
195 mask = inverted_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000196 *s++ = '~';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000197 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100198
199 sep = '[';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000200 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
201 ++i;
202 *s++ = sep;
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000203 if ((unsigned) i < nsignals) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000204 s = stpcpy(s, signalent[i] + 3);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000206#ifdef SIGRTMIN
207 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
208 s += sprintf(s, "RT_%u", i - __SIGRTMIN);
209 }
210#endif
211 else {
212 s += sprintf(s, "%u", i);
213 }
214 sep = ' ';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000215 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100216 if (sep == '[')
217 *s++ = sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218 *s++ = ']';
219 *s = '\0';
220 return outstr;
221}
222
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000223#define tprintsigmask_addr(prefix, mask) \
224 tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
Denys Vlasenko75f4e1f2013-07-18 20:37:06 +0200225
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000226#define sprintsigmask_val(prefix, mask) \
227 sprintsigmask_n((prefix), &(mask), sizeof(mask))
228
229#define tprintsigmask_val(prefix, mask) \
230 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000231
232void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200233printsignal(int nr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200235 tprints(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236}
237
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000238void
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200239print_sigset_addr_len(struct tcb *tcp, long addr, long len)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000240{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000241 char mask[NSIG / 8];
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000242
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200243 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200244 tprints("NULL");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200245 return;
246 }
247 /* Here len is usually equals NSIG / 8 or current_wordsize.
248 * But we code this defensively:
249 */
250 if (len < 0) {
251 bad:
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000252 tprintf("%#lx", addr);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200253 return;
254 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000255 if (len >= NSIG / 8)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200256 len = NSIG / 8;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000257 else
258 len = (len + 3) & ~3;
259
260 if (umoven(tcp, addr, len, mask) < 0)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200261 goto bad;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000262 tprints(sprintsigmask_n("", mask, len));
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000263}
264
John Hughes58265892001-10-18 15:13:53 +0000265#ifndef ILL_ILLOPC
266#define ILL_ILLOPC 1 /* illegal opcode */
267#define ILL_ILLOPN 2 /* illegal operand */
268#define ILL_ILLADR 3 /* illegal addressing mode */
269#define ILL_ILLTRP 4 /* illegal trap */
270#define ILL_PRVOPC 5 /* privileged opcode */
271#define ILL_PRVREG 6 /* privileged register */
272#define ILL_COPROC 7 /* coprocessor error */
273#define ILL_BADSTK 8 /* internal stack error */
274#define FPE_INTDIV 1 /* integer divide by zero */
275#define FPE_INTOVF 2 /* integer overflow */
276#define FPE_FLTDIV 3 /* floating point divide by zero */
277#define FPE_FLTOVF 4 /* floating point overflow */
278#define FPE_FLTUND 5 /* floating point underflow */
279#define FPE_FLTRES 6 /* floating point inexact result */
280#define FPE_FLTINV 7 /* floating point invalid operation */
281#define FPE_FLTSUB 8 /* subscript out of range */
282#define SEGV_MAPERR 1 /* address not mapped to object */
283#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
284#define BUS_ADRALN 1 /* invalid address alignment */
285#define BUS_ADRERR 2 /* non-existant physical address */
286#define BUS_OBJERR 3 /* object specific hardware error */
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000287#define SYS_SECCOMP 1 /* seccomp triggered */
John Hughes58265892001-10-18 15:13:53 +0000288#define TRAP_BRKPT 1 /* process breakpoint */
289#define TRAP_TRACE 2 /* process trace trap */
290#define CLD_EXITED 1 /* child has exited */
291#define CLD_KILLED 2 /* child was killed */
292#define CLD_DUMPED 3 /* child terminated abnormally */
293#define CLD_TRAPPED 4 /* traced child has trapped */
294#define CLD_STOPPED 5 /* child has stopped */
295#define CLD_CONTINUED 6 /* stopped child has continued */
296#define POLL_IN 1 /* data input available */
297#define POLL_OUT 2 /* output buffers available */
298#define POLL_MSG 3 /* input message available */
299#define POLL_ERR 4 /* i/o error */
300#define POLL_PRI 5 /* high priority input available */
301#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000302#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000303#define SI_USER 0 /* sent by kill, sigsend, raise */
304#define SI_QUEUE -1 /* sent by sigqueue */
305#define SI_TIMER -2 /* sent by timer expiration */
306#define SI_MESGQ -3 /* sent by real time mesq state change */
307#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000308#define SI_SIGIO -5 /* sent by SIGIO */
309#define SI_TKILL -6 /* sent by tkill */
Dmitry V. Levinb9d4d212014-03-11 01:57:02 +0000310#define SI_DETHREAD -7 /* sent by execve killing subsidiary threads */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000311#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100312#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000313
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100314#ifndef SI_FROMUSER
315# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
Denys Vlasenko84703742012-02-25 02:38:52 +0100316#endif
John Hughes58265892001-10-18 15:13:53 +0000317
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000318#include "xlat/siginfo_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000319#include "xlat/sigill_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000320#include "xlat/sigfpe_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000321#include "xlat/sigtrap_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000322#include "xlat/sigchld_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000323#include "xlat/sigpoll_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000324#include "xlat/sigprof_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000325
326#ifdef SIGEMT
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000327#include "xlat/sigemt_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000328#endif
329
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000330#include "xlat/sigsegv_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000331#include "xlat/sigbus_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000332
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000333#ifndef SYS_SECCOMP
334# define SYS_SECCOMP 1
335#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000336#include "xlat/sigsys_codes.h"
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000337
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000338static void
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000339printsigsource(const siginfo_t *sip)
340{
341 tprintf(", si_pid=%lu, si_uid=%lu",
342 (unsigned long) sip->si_pid,
343 (unsigned long) sip->si_uid);
344}
345
346static void
347printsigval(const siginfo_t *sip, int verbose)
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000348{
349 if (!verbose)
350 tprints(", ...");
351 else
352 tprintf(", si_value={int=%u, ptr=%#lx}",
353 sip->si_int,
354 (unsigned long) sip->si_ptr);
355}
356
John Hughes58265892001-10-18 15:13:53 +0000357void
Dmitry V. Levind8890b52015-02-07 15:47:24 +0000358printsiginfo(const siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000359{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000360 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000361
362 if (sip->si_signo == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200363 tprints("{}");
John Hughes58265892001-10-18 15:13:53 +0000364 return;
365 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200366 tprints("{si_signo=");
John Hughes58265892001-10-18 15:13:53 +0000367 printsignal(sip->si_signo);
368 code = xlookup(siginfo_codes, sip->si_code);
369 if (!code) {
370 switch (sip->si_signo) {
371 case SIGTRAP:
372 code = xlookup(sigtrap_codes, sip->si_code);
373 break;
374 case SIGCHLD:
375 code = xlookup(sigchld_codes, sip->si_code);
376 break;
377 case SIGPOLL:
378 code = xlookup(sigpoll_codes, sip->si_code);
379 break;
380 case SIGPROF:
381 code = xlookup(sigprof_codes, sip->si_code);
382 break;
383 case SIGILL:
384 code = xlookup(sigill_codes, sip->si_code);
385 break;
386#ifdef SIGEMT
387 case SIGEMT:
388 code = xlookup(sigemt_codes, sip->si_code);
389 break;
390#endif
391 case SIGFPE:
392 code = xlookup(sigfpe_codes, sip->si_code);
393 break;
394 case SIGSEGV:
395 code = xlookup(sigsegv_codes, sip->si_code);
396 break;
397 case SIGBUS:
398 code = xlookup(sigbus_codes, sip->si_code);
399 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000400 case SIGSYS:
401 code = xlookup(sigsys_codes, sip->si_code);
402 break;
John Hughes58265892001-10-18 15:13:53 +0000403 }
404 }
405 if (code)
406 tprintf(", si_code=%s", code);
407 else
408 tprintf(", si_code=%#x", sip->si_code);
409#ifdef SI_NOINFO
410 if (sip->si_code != SI_NOINFO)
411#endif
412 {
413 if (sip->si_errno) {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000414 if (sip->si_errno < 0 || (unsigned) sip->si_errno >= nerrnos)
John Hughes58265892001-10-18 15:13:53 +0000415 tprintf(", si_errno=%d", sip->si_errno);
416 else
417 tprintf(", si_errno=%s",
418 errnoent[sip->si_errno]);
419 }
420#ifdef SI_FROMUSER
421 if (SI_FROMUSER(sip)) {
John Hughes58265892001-10-18 15:13:53 +0000422 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000423#ifdef SI_USER
424 case SI_USER:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000425 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000426 break;
427#endif
428#ifdef SI_TKILL
429 case SI_TKILL:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000430 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000431 break;
432#endif
Dmitry V. Levin36ab3d52015-01-13 09:24:04 +0300433#if defined SI_TIMER \
434 && defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
John Hughes58265892001-10-18 15:13:53 +0000435 case SI_TIMER:
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000436 tprintf(", si_timerid=%#x, si_overrun=%d",
437 sip->si_timerid, sip->si_overrun);
438 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000439 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000440#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000441 default:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000442 printsigsource(sip);
443 if (sip->si_ptr)
444 printsigval(sip, verbose);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000445 break;
John Hughes58265892001-10-18 15:13:53 +0000446 }
John Hughes58265892001-10-18 15:13:53 +0000447 }
448 else
449#endif /* SI_FROMUSER */
450 {
451 switch (sip->si_signo) {
452 case SIGCHLD:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000453 printsigsource(sip);
454 tprints(", si_status=");
John Hughes58265892001-10-18 15:13:53 +0000455 if (sip->si_code == CLD_EXITED)
456 tprintf("%d", sip->si_status);
457 else
458 printsignal(sip->si_status);
John Hughes58265892001-10-18 15:13:53 +0000459 if (!verbose)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200460 tprints(", ...");
John Hughes58265892001-10-18 15:13:53 +0000461 else
H.J. Lu2bb45812012-04-15 11:17:13 -0700462 tprintf(", si_utime=%llu, si_stime=%llu",
463 (unsigned long long) sip->si_utime,
464 (unsigned long long) sip->si_stime);
John Hughes58265892001-10-18 15:13:53 +0000465 break;
466 case SIGILL: case SIGFPE:
467 case SIGSEGV: case SIGBUS:
468 tprintf(", si_addr=%#lx",
469 (unsigned long) sip->si_addr);
470 break;
471 case SIGPOLL:
472 switch (sip->si_code) {
473 case POLL_IN: case POLL_OUT: case POLL_MSG:
474 tprintf(", si_band=%ld",
475 (long) sip->si_band);
476 break;
477 }
478 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000479#ifdef HAVE_SIGINFO_T_SI_SYSCALL
480 case SIGSYS:
481 tprintf(", si_call_addr=%#lx, si_syscall=%d, si_arch=%u",
482 (unsigned long) sip->si_call_addr,
483 sip->si_syscall, sip->si_arch);
484 break;
485#endif
John Hughes58265892001-10-18 15:13:53 +0000486 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000487 if (sip->si_pid || sip->si_uid)
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000488 printsigsource(sip);
489 if (sip->si_ptr)
490 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000491 }
492 }
493 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200494 tprints("}");
John Hughes58265892001-10-18 15:13:53 +0000495}
496
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100497void
498printsiginfo_at(struct tcb *tcp, long addr)
499{
500 siginfo_t si;
501 if (!addr) {
502 tprints("NULL");
503 return;
504 }
505 if (syserror(tcp)) {
506 tprintf("%#lx", addr);
507 return;
508 }
509 if (umove(tcp, addr, &si) < 0) {
510 tprints("{???}");
511 return;
512 }
513 printsiginfo(&si, verbose(tcp));
514}
515
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516int
Denys Vlasenko12014262011-05-30 14:00:14 +0200517sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000518{
519 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000520 tprintsigmask_val("", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521 }
522 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000523 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000524 return RVAL_HEX | RVAL_STR;
525 }
526 return 0;
527}
528
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529#ifdef HAVE_SIGACTION
530
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531struct old_sigaction {
Denys Vlasenko86d94842013-02-08 12:59:13 +0100532 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800533#ifdef MIPS
534 unsigned int sa_flags;
535 void (*__sa_handler)(int);
536 /* Kernel treats sa_mask as an array of longs. */
537 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
538#else
Denys Vlasenko86d94842013-02-08 12:59:13 +0100539 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540 unsigned long sa_mask;
541 unsigned long sa_flags;
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800542#endif /* !MIPS */
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100543#ifdef SA_RESTORER
544 void (*sa_restorer)(void);
545#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547
Elliott Hughes458b3f22014-02-28 23:21:35 +0000548struct old_sigaction32 {
549 /* sa_handler may be a libc #define, need to use other name: */
550 uint32_t __sa_handler;
551 uint32_t sa_mask;
552 uint32_t sa_flags;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100553#ifdef SA_RESTORER
Elliott Hughes458b3f22014-02-28 23:21:35 +0000554 uint32_t sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100555#endif
Elliott Hughes458b3f22014-02-28 23:21:35 +0000556};
557
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000558static void
559decode_old_sigaction(struct tcb *tcp, long addr)
560{
561 struct old_sigaction sa;
Elliott Hughes458b3f22014-02-28 23:21:35 +0000562 int r;
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000563
564 if (!addr) {
565 tprints("NULL");
566 return;
567 }
568 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
569 tprintf("%#lx", addr);
570 return;
571 }
Elliott Hughes458b3f22014-02-28 23:21:35 +0000572
573#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
574 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
575 struct old_sigaction32 sa32;
576 r = umove(tcp, addr, &sa32);
577 if (r >= 0) {
578 memset(&sa, 0, sizeof(sa));
579 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
580 sa.sa_flags = sa32.sa_flags;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100581#ifdef SA_RESTORER
Elliott Hughes458b3f22014-02-28 23:21:35 +0000582 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100583#endif
Elliott Hughes458b3f22014-02-28 23:21:35 +0000584 sa.sa_mask = sa32.sa_mask;
585 }
586 } else
587#endif
588 {
589 r = umove(tcp, addr, &sa);
590 }
591 if (r < 0) {
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000592 tprints("{...}");
593 return;
594 }
595
596 /* Architectures using function pointers, like
597 * hppa, may need to manipulate the function pointer
598 * to compute the result of a comparison. However,
599 * the __sa_handler function pointer exists only in
600 * the address space of the traced process, and can't
601 * be manipulated by strace. In order to prevent the
602 * compiler from generating code to manipulate
603 * __sa_handler we cast the function pointers to long. */
604 if ((long)sa.__sa_handler == (long)SIG_ERR)
605 tprints("{SIG_ERR, ");
606 else if ((long)sa.__sa_handler == (long)SIG_DFL)
607 tprints("{SIG_DFL, ");
608 else if ((long)sa.__sa_handler == (long)SIG_IGN)
609 tprints("{SIG_IGN, ");
610 else
611 tprintf("{%#lx, ", (long) sa.__sa_handler);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800612#ifdef MIPS
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000613 tprintsigmask_addr("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800614#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000615 tprintsigmask_val("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800616#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000617 tprints(", ");
618 printflags(sigact_flags, sa.sa_flags, "SA_???");
619#ifdef SA_RESTORER
620 if (sa.sa_flags & SA_RESTORER)
621 tprintf(", %p", sa.sa_restorer);
622#endif
623 tprints("}");
624}
625
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626int
Denys Vlasenko12014262011-05-30 14:00:14 +0200627sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000628{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000629 if (entering(tcp)) {
630 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200631 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000632 decode_old_sigaction(tcp, tcp->u_arg[1]);
633 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000634 } else
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000635 decode_old_sigaction(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000636 return 0;
637}
638
639int
Denys Vlasenko12014262011-05-30 14:00:14 +0200640sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000641{
642 if (entering(tcp)) {
643 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200644 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000645 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +0000646 case (long) SIG_ERR:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200647 tprints("SIG_ERR");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000648 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000649 case (long) SIG_DFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200650 tprints("SIG_DFL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000651 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000652 case (long) SIG_IGN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200653 tprints("SIG_IGN");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000654 break;
655 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000656 tprintf("%#lx", tcp->u_arg[1]);
657 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000658 return 0;
659 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000660 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000661 switch (tcp->u_rval) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100662 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000663 tcp->auxstr = "SIG_ERR"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100664 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000665 tcp->auxstr = "SIG_DFL"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100666 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000667 tcp->auxstr = "SIG_IGN"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100668 default:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000669 tcp->auxstr = NULL;
670 }
671 return RVAL_HEX | RVAL_STR;
672 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000673 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000674}
675
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000676#endif /* HAVE_SIGACTION */
677
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000678int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000679sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000681#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +0000682 if (entering(tcp)) {
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200683 struct arm_sigcontext {
684 unsigned long trap_no;
685 unsigned long error_code;
686 unsigned long oldmask;
687 unsigned long arm_r0;
688 unsigned long arm_r1;
689 unsigned long arm_r2;
690 unsigned long arm_r3;
691 unsigned long arm_r4;
692 unsigned long arm_r5;
693 unsigned long arm_r6;
694 unsigned long arm_r7;
695 unsigned long arm_r8;
696 unsigned long arm_r9;
697 unsigned long arm_r10;
698 unsigned long arm_fp;
699 unsigned long arm_ip;
700 unsigned long arm_sp;
701 unsigned long arm_lr;
702 unsigned long arm_pc;
703 unsigned long arm_cpsr;
704 unsigned long fault_address;
705 };
706 struct arm_ucontext {
707 unsigned long uc_flags;
708 unsigned long uc_link; /* struct ucontext* */
709 /* The next three members comprise stack_t struct: */
710 unsigned long ss_sp; /* void* */
711 unsigned long ss_flags; /* int */
712 unsigned long ss_size; /* size_t */
713 struct arm_sigcontext sc;
714 /* These two members are sigset_t: */
715 unsigned long uc_sigmask[2];
716 /* more fields follow, which we aren't interested in */
717 };
718 struct arm_ucontext uc;
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200719 if (umove(tcp, arm_regs.ARM_sp, &uc) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000720 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000721 /*
722 * Kernel fills out uc.sc.oldmask too when it sets up signal stack,
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200723 * but for sigmask restore, sigreturn syscall uses uc.uc_sigmask instead.
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200724 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000725 tprintsigmask_addr(") (mask ", uc.uc_sigmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000726 }
Roland McGrath0f87c492003-06-03 23:29:04 +0000727#elif defined(S390) || defined(S390X)
Roland McGrath0f87c492003-06-03 23:29:04 +0000728 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200729 long usp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000730 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200731 if (upeek(tcp->pid, PT_GPR15, &usp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000732 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100733 if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &sc) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000734 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000735 tprintsigmask_addr(") (mask ", sc.oldmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000736 }
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200737#elif defined(I386) || defined(X86_64)
738# if defined(X86_64)
739 if (current_personality == 0) /* 64-bit */
740 return 0;
741# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000742 if (entering(tcp)) {
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200743 struct i386_sigcontext_struct {
744 uint16_t gs, __gsh;
745 uint16_t fs, __fsh;
746 uint16_t es, __esh;
747 uint16_t ds, __dsh;
748 uint32_t edi;
749 uint32_t esi;
750 uint32_t ebp;
751 uint32_t esp;
752 uint32_t ebx;
753 uint32_t edx;
754 uint32_t ecx;
755 uint32_t eax;
756 uint32_t trapno;
757 uint32_t err;
758 uint32_t eip;
759 uint16_t cs, __csh;
760 uint32_t eflags;
761 uint32_t esp_at_signal;
762 uint16_t ss, __ssh;
763 uint32_t i387;
764 uint32_t oldmask;
765 uint32_t cr2;
766 };
767 struct i386_fpstate {
768 uint32_t cw;
769 uint32_t sw;
770 uint32_t tag;
771 uint32_t ipoff;
772 uint32_t cssel;
773 uint32_t dataoff;
774 uint32_t datasel;
775 uint8_t st[8][10]; /* 8*10 bytes: FP regs */
776 uint16_t status;
777 uint16_t magic;
778 uint32_t fxsr_env[6];
779 uint32_t mxcsr;
780 uint32_t reserved;
781 uint8_t stx[8][16]; /* 8*16 bytes: FP regs, each padded to 16 bytes */
782 uint8_t xmm[8][16]; /* 8 XMM regs */
783 uint32_t padding1[44];
784 uint32_t padding2[12]; /* union with struct _fpx_sw_bytes */
785 };
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200786 struct {
787 struct i386_sigcontext_struct sc;
788 struct i386_fpstate fp;
789 uint32_t extramask[1];
790 } signal_stack;
791 /* On i386, sc is followed on stack by struct fpstate
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100792 * and after it an additional u32 extramask[1] which holds
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200793 * upper half of the mask.
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100794 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000795 uint32_t sigmask[2];
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200796 if (umove(tcp, *i386_esp_ptr, &signal_stack) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000797 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000798 sigmask[0] = signal_stack.sc.oldmask;
799 sigmask[1] = signal_stack.extramask[0];
800 tprintsigmask_addr(") (mask ", sigmask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000801 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000802#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000803 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200804 struct sigcontext sc;
805 long sp;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000806 /* offset of sigcontext in the kernel's sigframe structure: */
807# define SIGFRAME_SC_OFFSET 0x90
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200808 if (upeek(tcp->pid, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000809 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000810 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000811 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000812 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000813 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000814#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +0000815 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200816 long esp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000817 struct sigcontext sc;
Anton Blanchardce6e33b2013-06-26 15:53:33 +0200818
819 esp = ppc_regs.gpr[1];
820
Andreas Schwabedb39342010-02-23 00:18:51 +0100821 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200822#ifdef POWERPC64
823 if (current_personality == 0)
824 esp += 128;
825 else
826 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +0100827#else
828 esp += 64;
829#endif
Roland McGrath0f87c492003-06-03 23:29:04 +0000830 if (umove(tcp, esp, &sc) < 0)
831 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000832 tprintsigmask_val(") (mask ", sc.oldmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000833 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000834#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000835 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200836 long usp;
837 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200838 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000839 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +0000840 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000841 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000842 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000843 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000844#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000845 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200846 long fp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000847 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200848 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000849 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +0000850 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000852 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100854#elif defined(SPARC) || defined(SPARC64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200855 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200856 long i1;
Denys Vlasenko56a52982011-06-09 01:36:29 +0200857 m_siginfo_t si;
Denys Vlasenko48e4c1b2013-02-16 08:23:40 +0100858 i1 = sparc_regs.u_regs[U_REG_O1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200859 if (umove(tcp, i1, &si) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100860 perror_msg("sigreturn: umove");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861 return 0;
862 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000863 tprintsigmask_val(") (mask ", si.si_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000864 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100865#elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +0000866 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
867 sigreturn. */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200868 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200869 struct ucontext uc;
Roland McGrath542c2c62008-05-20 01:11:56 +0000870 /* There are six words followed by a 128-byte siginfo. */
Dmitry V. Levin4f2d1ae2015-02-15 03:27:13 +0000871 long sp = mips_REG_SP + 6 * 4 + 128;
Roland McGrath542c2c62008-05-20 01:11:56 +0000872 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000873 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000874 tprintsigmask_val(") (mask ", uc.uc_sigmask);
Roland McGrath542c2c62008-05-20 01:11:56 +0000875 }
Dmitry V. Levin4f2d1ae2015-02-15 03:27:13 +0000876#elif defined(LINUX_MIPSO32)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200877 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200878 m_siginfo_t si;
Dmitry V. Levin4f2d1ae2015-02-15 03:27:13 +0000879 if (umove(tcp, mips_REG_SP, &si) < 0)
Denys Vlasenkofacd45b2011-06-09 01:22:10 +0200880 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000881 tprintsigmask_val(") (mask ", si.si_mask);
Wichert Akkermanf90da011999-10-31 21:15:38 +0000882 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000883#elif defined(CRISV10) || defined(CRISV32)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000884 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200885 struct sigcontext sc;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000886 long regs[PT_MAX+1];
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000887 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100888 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000889 return 0;
890 }
891 if (umove(tcp, regs[PT_USP], &sc) < 0)
892 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000893 tprintsigmask_val(") (mask ", sc.oldmask);
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000894 }
Chris Metcalfc8c66982009-12-28 10:00:15 -0500895#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500896 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200897 struct ucontext uc;
Denys Vlasenko56a52982011-06-09 01:36:29 +0200898
899 /* offset of ucontext in the kernel's sigframe structure */
Chris Metcalf5c0796f2013-05-21 20:25:22 -0400900# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
Chris Metcalf0b99a8a2013-02-05 17:48:33 +0100901 if (umove(tcp, tile_regs.sp + SIGFRAME_UC_OFFSET, &uc) < 0)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500902 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000903 tprintsigmask_val(") (mask ", uc.uc_sigmask);
Chris Metcalfc8c66982009-12-28 10:00:15 -0500904 }
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200905#elif defined(MICROBLAZE)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200906 /* TODO: Verify that this is correct... */
907 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200908 struct sigcontext sc;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200909 long sp;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200910 /* Read r1, the stack pointer. */
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200911 if (upeek(tcp->pid, 1 * 4, &sp) < 0)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200912 return 0;
913 if (umove(tcp, sp, &sc) < 0)
914 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000915 tprintsigmask_val(") (mask ", sc.oldmask);
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200916 }
Chris Zankel8f636ed2013-03-25 10:22:07 -0700917#elif defined(XTENSA)
918 /* Xtensa only has rt_sys_sigreturn */
Vineet Gupta7daacbb2013-08-16 12:47:06 +0530919#elif defined(ARC)
920 /* ARC syscall ABI only supports rt_sys_sigreturn */
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000921#else
Dmitry V. Levinf112d072012-05-15 00:13:59 +0000922# warning No sys_sigreturn() for this architecture
923# warning (no problem, just a reminder :-)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000924#endif
Dmitry V. Levinf112d072012-05-15 00:13:59 +0000925 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000926}
927
928int
Denys Vlasenko12014262011-05-30 14:00:14 +0200929sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000930{
931 if (exiting(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000932 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000933 }
934 return RVAL_HEX | RVAL_STR;
935}
936
937int
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000938sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000939{
940 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000941 tprintsigmask_val("", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000942 }
943 return 0;
944}
945
Denys Vlasenko84703742012-02-25 02:38:52 +0100946#if !defined SS_ONSTACK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000947#define SS_ONSTACK 1
948#define SS_DISABLE 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000949#endif
950
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000951#include "xlat/sigaltstack_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000953static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200954print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000955{
956 stack_t ss;
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000957 int r;
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000958
959 if (!addr) {
960 tprints("NULL");
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000961 return;
962 }
963
964#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
965 if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
966 struct {
967 uint32_t ss_sp;
968 int32_t ss_flags;
969 uint32_t ss_size;
970 } ss32;
971 r = umove(tcp, addr, &ss32);
972 if (r >= 0) {
973 memset(&ss, 0, sizeof(ss));
974 ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
975 ss.ss_flags = ss32.ss_flags;
976 ss.ss_size = (unsigned long) ss32.ss_size;
977 }
978 } else
979#endif
980 {
981 r = umove(tcp, addr, &ss);
982 }
983 if (r < 0) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000984 tprintf("%#lx", addr);
985 } else {
986 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
987 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
988 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
989 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990}
991
992int
Denys Vlasenko12014262011-05-30 14:00:14 +0200993sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000994{
995 if (entering(tcp)) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000996 print_stack_t(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000997 }
998 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200999 tprints(", ");
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001000 print_stack_t(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001001 }
1002 return 0;
1003}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001004
1005#ifdef HAVE_SIGACTION
1006
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001007/* "Old" sigprocmask, which operates with word-sized signal masks */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008int
Denys Vlasenko12014262011-05-30 14:00:14 +02001009sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001010{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001011# ifdef ALPHA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012 if (entering(tcp)) {
Mike Frysingerdde045c2012-03-15 00:45:33 -04001013 /*
1014 * Alpha/OSF is different: it doesn't pass in two pointers,
1015 * but rather passes in the new bitmask as an argument and
1016 * then returns the old bitmask. This "works" because we
1017 * only have 64 signals to worry about. If you want more,
1018 * use of the rt_sigprocmask syscall is required.
1019 * Alpha:
1020 * old = osf_sigprocmask(how, new);
1021 * Everyone else:
1022 * ret = sigprocmask(how, &new, &old, ...);
1023 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001024 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001025 tprintsigmask_val(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026 }
1027 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001028 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029 return RVAL_HEX | RVAL_STR;
1030 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001031# else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001033 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001034 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001035 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001036 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001037 }
1038 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001039 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001040 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001042 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001044# endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001045 return 0;
1046}
1047
1048#endif /* HAVE_SIGACTION */
1049
1050int
Denys Vlasenko12014262011-05-30 14:00:14 +02001051sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052{
1053 if (entering(tcp)) {
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001054 tprintf("%ld, %s",
1055 widen_to_long(tcp->u_arg[0]),
1056 signame(tcp->u_arg[1])
1057 );
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001058 }
1059 return 0;
1060}
1061
Roland McGrath8ffc3522003-07-09 09:47:49 +00001062int
Denys Vlasenko12014262011-05-30 14:00:14 +02001063sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001064{
1065 if (entering(tcp)) {
1066 tprintf("%ld, %ld, %s",
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001067 widen_to_long(tcp->u_arg[0]),
1068 widen_to_long(tcp->u_arg[1]),
1069 signame(tcp->u_arg[2])
1070 );
Roland McGrath8ffc3522003-07-09 09:47:49 +00001071 }
1072 return 0;
1073}
Roland McGrath8ffc3522003-07-09 09:47:49 +00001074
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001075int
Denys Vlasenko12014262011-05-30 14:00:14 +02001076sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001078 if (exiting(tcp)) {
1079 if (syserror(tcp))
1080 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001081 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001082 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001083 }
1084 return 0;
1085}
1086
Denys Vlasenko12014262011-05-30 14:00:14 +02001087int
1088sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001089{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001090 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001091 if (entering(tcp)) {
1092 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001093 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001094 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1095 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096 }
1097 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001098 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001100 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001101 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001102 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001103 }
1104 return 0;
1105}
1106
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001107/* Structure describing the action to be taken when a signal arrives. */
1108struct new_sigaction
1109{
Denys Vlasenko86d94842013-02-08 12:59:13 +01001110 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001111#ifdef MIPS
1112 unsigned int sa_flags;
1113 void (*__sa_handler)(int);
1114#else
Denys Vlasenko86d94842013-02-08 12:59:13 +01001115 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001116 unsigned long sa_flags;
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001117#endif /* !MIPS */
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001118#ifdef SA_RESTORER
1119 void (*sa_restorer)(void);
1120#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001121 /* Kernel treats sa_mask as an array of longs. */
1122 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1123};
1124/* Same for i386-on-x86_64 and similar cases */
1125struct new_sigaction32
1126{
1127 uint32_t __sa_handler;
1128 uint32_t sa_flags;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001129#ifdef SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001130 uint32_t sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001131#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001132 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001133};
1134
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001135static void
1136decode_new_sigaction(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001137{
1138 struct new_sigaction sa;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001139 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001140
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001141 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001142 tprints("NULL");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001143 return;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001144 }
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001145 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001146 tprintf("%#lx", addr);
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001147 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001148 }
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001149#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Denys Vlasenko9fd4f962012-03-19 09:36:42 +01001150 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001151 struct new_sigaction32 sa32;
1152 r = umove(tcp, addr, &sa32);
1153 if (r >= 0) {
1154 memset(&sa, 0, sizeof(sa));
1155 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1156 sa.sa_flags = sa32.sa_flags;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001157#ifdef SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001158 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001159#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001160 /* Kernel treats sa_mask as an array of longs.
1161 * For 32-bit process, "long" is uint32_t, thus, for example,
1162 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1163 * But for (64-bit) kernel, 32th bit in sa_mask is
1164 * 32th bit in 0th (64-bit) long!
1165 * For little-endian, it's the same.
1166 * For big-endian, we swap 32-bit words.
1167 */
1168 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1169 }
1170 } else
1171#endif
1172 {
1173 r = umove(tcp, addr, &sa);
1174 }
1175 if (r < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001176 tprints("{...}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001177 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001178 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001179 /* Architectures using function pointers, like
1180 * hppa, may need to manipulate the function pointer
1181 * to compute the result of a comparison. However,
Denys Vlasenko86d94842013-02-08 12:59:13 +01001182 * the __sa_handler function pointer exists only in
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001183 * the address space of the traced process, and can't
1184 * be manipulated by strace. In order to prevent the
1185 * compiler from generating code to manipulate
Denys Vlasenko86d94842013-02-08 12:59:13 +01001186 * __sa_handler we cast the function pointers to long. */
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001187 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001188 tprints("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001189 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001190 tprints("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001191 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001192 tprints("{SIG_IGN, ");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001193 else
1194 tprintf("{%#lx, ", (long) sa.__sa_handler);
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001195 /*
1196 * Sigset size is in tcp->u_arg[4] (SPARC)
1197 * or in tcp->u_arg[3] (all other),
1198 * but kernel won't handle sys_rt_sigaction
1199 * with wrong sigset size (just returns EINVAL instead).
1200 * We just fetch the right size, which is NSIG / 8.
1201 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001202 tprintsigmask_val("", sa.sa_mask);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001203 tprints(", ");
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001204
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001205 printflags(sigact_flags, sa.sa_flags, "SA_???");
1206#ifdef SA_RESTORER
1207 if (sa.sa_flags & SA_RESTORER)
1208 tprintf(", %p", sa.sa_restorer);
1209#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001210 tprints("}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001211}
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001212
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001213int
1214sys_rt_sigaction(struct tcb *tcp)
1215{
1216 if (entering(tcp)) {
1217 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001218 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001219 decode_new_sigaction(tcp, tcp->u_arg[1]);
1220 tprints(", ");
1221 } else {
1222 decode_new_sigaction(tcp, tcp->u_arg[2]);
Denys Vlasenko9472a272013-02-12 11:43:46 +01001223#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001224 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1225#elif defined(ALPHA)
1226 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1227#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001228 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001229#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001230 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001231 return 0;
1232}
1233
Denys Vlasenko1d632462009-04-14 12:51:00 +00001234int
1235sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001236{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001237 if (exiting(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001238 /*
1239 * One of the few syscalls where sigset size (arg[1])
1240 * is allowed to be <= NSIG / 8, not strictly ==.
1241 * This allows non-rt sigpending() syscall
1242 * to reuse rt_sigpending() code in kernel.
1243 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001244 if (syserror(tcp))
1245 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001246 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001247 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
1253int
1254sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001255{
1256 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001257 /* NB: kernel requires arg[1] == NSIG / 8 */
1258 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1259 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001260 }
1261 return 0;
1262}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001263
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001264static void
1265print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1266{
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001267 printsignal(sig);
1268 tprints(", ");
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001269 printsiginfo_at(tcp, uinfo);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001270}
1271
Denys Vlasenko1d632462009-04-14 12:51:00 +00001272int
1273sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001274{
1275 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001276 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001277 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1278 }
1279 return 0;
1280}
1281
1282int
1283sys_rt_tgsigqueueinfo(struct tcb *tcp)
1284{
1285 if (entering(tcp)) {
1286 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1287 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001288 }
1289 return 0;
1290}
1291
Denys Vlasenko1d632462009-04-14 12:51:00 +00001292int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001293{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001294 /* NB: kernel requires arg[3] == NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001295 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001296 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001297 tprints(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001298 /* This is the only "return" parameter, */
1299 if (tcp->u_arg[1] != 0)
1300 return 0;
1301 /* ... if it's NULL, can decode all on entry */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001302 tprints("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001303 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001304 else if (tcp->u_arg[1] != 0) {
1305 /* syscall exit, and u_arg[1] wasn't NULL */
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001306 printsiginfo_at(tcp, tcp->u_arg[1]);
1307 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001309 else {
1310 /* syscall exit, and u_arg[1] was NULL */
1311 return 0;
1312 }
1313 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001314 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001315 return 0;
1316};
1317
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001318int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001319sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001320{
1321 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001322 tprints("<... resuming interrupted call ...>");
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001323 return 0;
1324}
1325
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001326static int
1327do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00001328{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001329 /* NB: kernel requires arg[2] == NSIG / 8 */
Roland McGrathf46ccd32007-08-02 01:15:59 +00001330 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001331 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001332 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001333 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00001334 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001335 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001336 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001337 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1338 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00001339 }
1340 return 0;
1341}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001342
1343int
1344sys_signalfd(struct tcb *tcp)
1345{
1346 return do_signalfd(tcp, -1);
1347}
1348
1349int
1350sys_signalfd4(struct tcb *tcp)
1351{
1352 return do_signalfd(tcp, 3);
1353}