blob: 8fd91b67e2c658464f8bfc8c7794a60d7146c85f [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>
Dmitry V. Levinfadf3792015-02-13 00:26:38 +000036#include <sys/user.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037
Wichert Akkerman36915a11999-07-13 15:45:02 +000038#ifdef HAVE_SYS_REG_H
39# include <sys/reg.h>
Maarten ter Huurne40c174b2014-10-20 01:02:48 +020040#endif
41
Dmitry V. Levinfadf3792015-02-13 00:26:38 +000042#include "ptrace.h"
Wichert Akkerman36915a11999-07-13 15:45:02 +000043
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000044#ifdef IA64
45# include <asm/ptrace_offsets.h>
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020046#endif
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000047
Denys Vlasenko84703742012-02-25 02:38:52 +010048#if defined(SPARC) || defined(SPARC64) || defined(MIPS)
Roland McGrath576b7842007-11-04 00:00:00 +000049typedef struct {
50 struct pt_regs si_regs;
51 int si_mask;
52} m_siginfo_t;
Roland McGrath30ff45e2003-01-30 20:15:23 +000053#elif defined HAVE_ASM_SIGCONTEXT_H
H.J. Lu35be5812012-04-16 13:00:01 +020054# if !defined(IA64) && !defined(X86_64) && !defined(X32)
Denys Vlasenko84703742012-02-25 02:38:52 +010055# include <asm/sigcontext.h>
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010056# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057#else /* !HAVE_ASM_SIGCONTEXT_H */
Denys Vlasenkob51f3642013-07-16 12:06:25 +020058# if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
59struct sigcontext {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000060 unsigned long sc_mask;
61 unsigned long sc_usp;
62 unsigned long sc_d0;
63 unsigned long sc_d1;
64 unsigned long sc_a0;
65 unsigned long sc_a1;
66 unsigned short sc_sr;
67 unsigned long sc_pc;
68 unsigned short sc_formatvec;
69};
Denys Vlasenkob51f3642013-07-16 12:06:25 +020070# endif /* M68K */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071#endif /* !HAVE_ASM_SIGCONTEXT_H */
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020072
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073#ifndef NSIG
Denys Vlasenko84703742012-02-25 02:38:52 +010074# warning: NSIG is not defined, using 32
75# define NSIG 32
Dmitry V. Levin38593e92014-02-26 16:51:28 +000076#elif NSIG < 32
77# error: NSIG < 32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000078#endif
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020079
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000080#ifdef HAVE_SIGACTION
81
Roland McGrath2638cb42002-12-15 23:58:41 +000082/* The libc headers do not define this constant since it should only be
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020083 used by the implementation. So we define it here. */
Dmitry V. Levin5c7f6272014-02-08 00:26:06 +000084#ifndef SA_RESTORER
85# ifdef ASM_SA_RESTORER
86# define SA_RESTORER ASM_SA_RESTORER
Roland McGrath2638cb42002-12-15 23:58:41 +000087# endif
88#endif
89
Mike Frysingerdd80a872014-08-14 00:30:24 -040090/* Some arches define this in their headers, but don't actually have it,
Mike Frysingerd632e102014-08-09 09:04:18 -040091 so we have to delete the define. */
Mike Frysingerdd80a872014-08-14 00:30:24 -040092#if defined(HPPA) || defined(IA64)
Mike Frysingerd632e102014-08-09 09:04:18 -040093# undef SA_RESTORER
94#endif
95
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000096#include "xlat/sigact_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000097#include "xlat/sigprocmaskcmds.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000098
99#endif /* HAVE_SIGACTION */
100
Nate Sammonsce780fc1999-03-29 23:23:13 +0000101/* Anonymous realtime signals. */
102/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
103 constant. This is what we want. Otherwise, just use SIGRTMIN. */
104#ifdef SIGRTMIN
105#ifndef __SIGRTMIN
106#define __SIGRTMIN SIGRTMIN
107#define __SIGRTMAX SIGRTMAX /* likewise */
108#endif
109#endif
110
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200111/* Note on the size of sigset_t:
112 *
113 * In glibc, sigset_t is an array with space for 1024 bits (!),
114 * even though all arches supported by Linux have only 64 signals
115 * except MIPS, which has 128. IOW, it is 128 bytes long.
116 *
117 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
118 * However, some old syscall return only 32 lower bits (one word).
119 * Example: sys_sigpending vs sys_rt_sigpending.
120 *
121 * Be aware of this fact when you try to
122 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
123 * - sizeof(sigset_t) is much bigger than you think,
124 * it may overflow tcp->u_arg[] array, and it may try to copy more data
125 * than is really available in <something>.
126 * Similarly,
127 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
128 * may be a bad idea: it'll try to read much more data than needed
129 * to fetch a sigset_t.
130 * Use (NSIG / 8) as a size instead.
131 */
132
Roland McGrathee36ce12004-09-04 03:53:10 +0000133const char *
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000134signame(const int sig)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000135{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000136 static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200137
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000138 if (sig >= 0) {
139 const unsigned int s = sig;
140
141 if (s < nsignals)
142 return signalent[s];
Nate Sammonsce780fc1999-03-29 23:23:13 +0000143#ifdef SIGRTMIN
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000144 if (s >= __SIGRTMIN && s <= __SIGRTMAX) {
145 sprintf(buf, "SIGRT_%u", s - __SIGRTMIN);
146 return buf;
147 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200148#endif
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000149 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200150 sprintf(buf, "%d", sig);
151 return buf;
Nate Sammonsce780fc1999-03-29 23:23:13 +0000152}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000154static unsigned int
155popcount32(const uint32_t *a, unsigned int size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000157 unsigned int count = 0;
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200158
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000159 for (; size; ++a, --size) {
160 uint32_t x = *a;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000162#ifdef HAVE___BUILTIN_POPCOUNT
163 count += __builtin_popcount(x);
Denys Vlasenkoa8773792013-07-18 20:42:41 +0200164#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000165 for (; x; ++count)
166 x &= x - 1;
Nate Sammons4a121431999-04-06 01:19:39 +0000167#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000168 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100169
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000170 return count;
171}
172
173static const char *
174sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
175{
176 /*
177 * The maximum number of signal names to be printed is NSIG * 2 / 3.
178 * Most of signal names have length 7,
179 * average length of signal names is less than 7.
180 * The length of prefix string does not exceed 16.
181 */
182 static char outstr[128 + 8 * (NSIG * 2 / 3)];
183
184 char *s;
185 const uint32_t *mask;
186 uint32_t inverted_mask[NSIG / 32];
187 unsigned int size;
188 int i;
189 char sep;
190
191 s = stpcpy(outstr, prefix);
192
193 mask = sig_mask;
194 /* length of signal mask in 4-byte words */
195 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
196
197 /* check whether 2/3 or more bits are set */
198 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
199 /* show those signals that are NOT in the mask */
200 unsigned int j;
201 for (j = 0; j < size; ++j)
202 inverted_mask[j] = ~mask[j];
203 mask = inverted_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204 *s++ = '~';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000205 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100206
207 sep = '[';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000208 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
209 ++i;
210 *s++ = sep;
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000211 if ((unsigned) i < nsignals) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000212 s = stpcpy(s, signalent[i] + 3);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000213 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000214#ifdef SIGRTMIN
215 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
216 s += sprintf(s, "RT_%u", i - __SIGRTMIN);
217 }
218#endif
219 else {
220 s += sprintf(s, "%u", i);
221 }
222 sep = ' ';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100224 if (sep == '[')
225 *s++ = sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226 *s++ = ']';
227 *s = '\0';
228 return outstr;
229}
230
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000231#define tprintsigmask_addr(prefix, mask) \
232 tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
Denys Vlasenko75f4e1f2013-07-18 20:37:06 +0200233
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000234#define sprintsigmask_val(prefix, mask) \
235 sprintsigmask_n((prefix), &(mask), sizeof(mask))
236
237#define tprintsigmask_val(prefix, mask) \
238 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000239
240void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200241printsignal(int nr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000242{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200243 tprints(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000244}
245
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000246void
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200247print_sigset_addr_len(struct tcb *tcp, long addr, long len)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000248{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000249 char mask[NSIG / 8];
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000250
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200251 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200252 tprints("NULL");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200253 return;
254 }
255 /* Here len is usually equals NSIG / 8 or current_wordsize.
256 * But we code this defensively:
257 */
258 if (len < 0) {
259 bad:
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000260 tprintf("%#lx", addr);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200261 return;
262 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000263 if (len >= NSIG / 8)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200264 len = NSIG / 8;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000265 else
266 len = (len + 3) & ~3;
267
268 if (umoven(tcp, addr, len, mask) < 0)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200269 goto bad;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000270 tprints(sprintsigmask_n("", mask, len));
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000271}
272
John Hughes58265892001-10-18 15:13:53 +0000273#ifndef ILL_ILLOPC
274#define ILL_ILLOPC 1 /* illegal opcode */
275#define ILL_ILLOPN 2 /* illegal operand */
276#define ILL_ILLADR 3 /* illegal addressing mode */
277#define ILL_ILLTRP 4 /* illegal trap */
278#define ILL_PRVOPC 5 /* privileged opcode */
279#define ILL_PRVREG 6 /* privileged register */
280#define ILL_COPROC 7 /* coprocessor error */
281#define ILL_BADSTK 8 /* internal stack error */
282#define FPE_INTDIV 1 /* integer divide by zero */
283#define FPE_INTOVF 2 /* integer overflow */
284#define FPE_FLTDIV 3 /* floating point divide by zero */
285#define FPE_FLTOVF 4 /* floating point overflow */
286#define FPE_FLTUND 5 /* floating point underflow */
287#define FPE_FLTRES 6 /* floating point inexact result */
288#define FPE_FLTINV 7 /* floating point invalid operation */
289#define FPE_FLTSUB 8 /* subscript out of range */
290#define SEGV_MAPERR 1 /* address not mapped to object */
291#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
292#define BUS_ADRALN 1 /* invalid address alignment */
293#define BUS_ADRERR 2 /* non-existant physical address */
294#define BUS_OBJERR 3 /* object specific hardware error */
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000295#define SYS_SECCOMP 1 /* seccomp triggered */
John Hughes58265892001-10-18 15:13:53 +0000296#define TRAP_BRKPT 1 /* process breakpoint */
297#define TRAP_TRACE 2 /* process trace trap */
298#define CLD_EXITED 1 /* child has exited */
299#define CLD_KILLED 2 /* child was killed */
300#define CLD_DUMPED 3 /* child terminated abnormally */
301#define CLD_TRAPPED 4 /* traced child has trapped */
302#define CLD_STOPPED 5 /* child has stopped */
303#define CLD_CONTINUED 6 /* stopped child has continued */
304#define POLL_IN 1 /* data input available */
305#define POLL_OUT 2 /* output buffers available */
306#define POLL_MSG 3 /* input message available */
307#define POLL_ERR 4 /* i/o error */
308#define POLL_PRI 5 /* high priority input available */
309#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000310#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000311#define SI_USER 0 /* sent by kill, sigsend, raise */
312#define SI_QUEUE -1 /* sent by sigqueue */
313#define SI_TIMER -2 /* sent by timer expiration */
314#define SI_MESGQ -3 /* sent by real time mesq state change */
315#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000316#define SI_SIGIO -5 /* sent by SIGIO */
317#define SI_TKILL -6 /* sent by tkill */
Dmitry V. Levinb9d4d212014-03-11 01:57:02 +0000318#define SI_DETHREAD -7 /* sent by execve killing subsidiary threads */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000319#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100320#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000321
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100322#ifndef SI_FROMUSER
323# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
Denys Vlasenko84703742012-02-25 02:38:52 +0100324#endif
John Hughes58265892001-10-18 15:13:53 +0000325
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000326#include "xlat/siginfo_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000327#include "xlat/sigill_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000328#include "xlat/sigfpe_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000329#include "xlat/sigtrap_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000330#include "xlat/sigchld_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000331#include "xlat/sigpoll_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000332#include "xlat/sigprof_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000333
334#ifdef SIGEMT
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000335#include "xlat/sigemt_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000336#endif
337
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000338#include "xlat/sigsegv_codes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000339#include "xlat/sigbus_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000340
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000341#ifndef SYS_SECCOMP
342# define SYS_SECCOMP 1
343#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000344#include "xlat/sigsys_codes.h"
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000345
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000346static void
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000347printsigsource(const siginfo_t *sip)
348{
349 tprintf(", si_pid=%lu, si_uid=%lu",
350 (unsigned long) sip->si_pid,
351 (unsigned long) sip->si_uid);
352}
353
354static void
355printsigval(const siginfo_t *sip, int verbose)
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000356{
357 if (!verbose)
358 tprints(", ...");
359 else
360 tprintf(", si_value={int=%u, ptr=%#lx}",
361 sip->si_int,
362 (unsigned long) sip->si_ptr);
363}
364
John Hughes58265892001-10-18 15:13:53 +0000365void
Dmitry V. Levind8890b52015-02-07 15:47:24 +0000366printsiginfo(const siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000367{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000368 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000369
370 if (sip->si_signo == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200371 tprints("{}");
John Hughes58265892001-10-18 15:13:53 +0000372 return;
373 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200374 tprints("{si_signo=");
John Hughes58265892001-10-18 15:13:53 +0000375 printsignal(sip->si_signo);
376 code = xlookup(siginfo_codes, sip->si_code);
377 if (!code) {
378 switch (sip->si_signo) {
379 case SIGTRAP:
380 code = xlookup(sigtrap_codes, sip->si_code);
381 break;
382 case SIGCHLD:
383 code = xlookup(sigchld_codes, sip->si_code);
384 break;
385 case SIGPOLL:
386 code = xlookup(sigpoll_codes, sip->si_code);
387 break;
388 case SIGPROF:
389 code = xlookup(sigprof_codes, sip->si_code);
390 break;
391 case SIGILL:
392 code = xlookup(sigill_codes, sip->si_code);
393 break;
394#ifdef SIGEMT
395 case SIGEMT:
396 code = xlookup(sigemt_codes, sip->si_code);
397 break;
398#endif
399 case SIGFPE:
400 code = xlookup(sigfpe_codes, sip->si_code);
401 break;
402 case SIGSEGV:
403 code = xlookup(sigsegv_codes, sip->si_code);
404 break;
405 case SIGBUS:
406 code = xlookup(sigbus_codes, sip->si_code);
407 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000408 case SIGSYS:
409 code = xlookup(sigsys_codes, sip->si_code);
410 break;
John Hughes58265892001-10-18 15:13:53 +0000411 }
412 }
413 if (code)
414 tprintf(", si_code=%s", code);
415 else
416 tprintf(", si_code=%#x", sip->si_code);
417#ifdef SI_NOINFO
418 if (sip->si_code != SI_NOINFO)
419#endif
420 {
421 if (sip->si_errno) {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000422 if (sip->si_errno < 0 || (unsigned) sip->si_errno >= nerrnos)
John Hughes58265892001-10-18 15:13:53 +0000423 tprintf(", si_errno=%d", sip->si_errno);
424 else
425 tprintf(", si_errno=%s",
426 errnoent[sip->si_errno]);
427 }
428#ifdef SI_FROMUSER
429 if (SI_FROMUSER(sip)) {
John Hughes58265892001-10-18 15:13:53 +0000430 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000431#ifdef SI_USER
432 case SI_USER:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000433 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000434 break;
435#endif
436#ifdef SI_TKILL
437 case SI_TKILL:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000438 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000439 break;
440#endif
Dmitry V. Levin36ab3d52015-01-13 09:24:04 +0300441#if defined SI_TIMER \
442 && defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
John Hughes58265892001-10-18 15:13:53 +0000443 case SI_TIMER:
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000444 tprintf(", si_timerid=%#x, si_overrun=%d",
445 sip->si_timerid, sip->si_overrun);
446 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000447 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000448#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000449 default:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000450 printsigsource(sip);
451 if (sip->si_ptr)
452 printsigval(sip, verbose);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000453 break;
John Hughes58265892001-10-18 15:13:53 +0000454 }
John Hughes58265892001-10-18 15:13:53 +0000455 }
456 else
457#endif /* SI_FROMUSER */
458 {
459 switch (sip->si_signo) {
460 case SIGCHLD:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000461 printsigsource(sip);
462 tprints(", si_status=");
John Hughes58265892001-10-18 15:13:53 +0000463 if (sip->si_code == CLD_EXITED)
464 tprintf("%d", sip->si_status);
465 else
466 printsignal(sip->si_status);
John Hughes58265892001-10-18 15:13:53 +0000467 if (!verbose)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200468 tprints(", ...");
John Hughes58265892001-10-18 15:13:53 +0000469 else
H.J. Lu2bb45812012-04-15 11:17:13 -0700470 tprintf(", si_utime=%llu, si_stime=%llu",
471 (unsigned long long) sip->si_utime,
472 (unsigned long long) sip->si_stime);
John Hughes58265892001-10-18 15:13:53 +0000473 break;
474 case SIGILL: case SIGFPE:
475 case SIGSEGV: case SIGBUS:
476 tprintf(", si_addr=%#lx",
477 (unsigned long) sip->si_addr);
478 break;
479 case SIGPOLL:
480 switch (sip->si_code) {
481 case POLL_IN: case POLL_OUT: case POLL_MSG:
482 tprintf(", si_band=%ld",
483 (long) sip->si_band);
484 break;
485 }
486 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000487#ifdef HAVE_SIGINFO_T_SI_SYSCALL
488 case SIGSYS:
489 tprintf(", si_call_addr=%#lx, si_syscall=%d, si_arch=%u",
490 (unsigned long) sip->si_call_addr,
491 sip->si_syscall, sip->si_arch);
492 break;
493#endif
John Hughes58265892001-10-18 15:13:53 +0000494 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000495 if (sip->si_pid || sip->si_uid)
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000496 printsigsource(sip);
497 if (sip->si_ptr)
498 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000499 }
500 }
501 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200502 tprints("}");
John Hughes58265892001-10-18 15:13:53 +0000503}
504
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100505void
506printsiginfo_at(struct tcb *tcp, long addr)
507{
508 siginfo_t si;
509 if (!addr) {
510 tprints("NULL");
511 return;
512 }
513 if (syserror(tcp)) {
514 tprintf("%#lx", addr);
515 return;
516 }
517 if (umove(tcp, addr, &si) < 0) {
518 tprints("{???}");
519 return;
520 }
521 printsiginfo(&si, verbose(tcp));
522}
523
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000524int
Denys Vlasenko12014262011-05-30 14:00:14 +0200525sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526{
527 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000528 tprintsigmask_val("", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529 }
530 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000531 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532 return RVAL_HEX | RVAL_STR;
533 }
534 return 0;
535}
536
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537#ifdef HAVE_SIGACTION
538
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539struct old_sigaction {
Denys Vlasenko86d94842013-02-08 12:59:13 +0100540 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800541#ifdef MIPS
542 unsigned int sa_flags;
543 void (*__sa_handler)(int);
544 /* Kernel treats sa_mask as an array of longs. */
545 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
546#else
Denys Vlasenko86d94842013-02-08 12:59:13 +0100547 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548 unsigned long sa_mask;
549 unsigned long sa_flags;
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800550#endif /* !MIPS */
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100551#ifdef SA_RESTORER
552 void (*sa_restorer)(void);
553#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000554};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555
Elliott Hughes458b3f22014-02-28 23:21:35 +0000556struct old_sigaction32 {
557 /* sa_handler may be a libc #define, need to use other name: */
558 uint32_t __sa_handler;
559 uint32_t sa_mask;
560 uint32_t sa_flags;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100561#ifdef SA_RESTORER
Elliott Hughes458b3f22014-02-28 23:21:35 +0000562 uint32_t sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100563#endif
Elliott Hughes458b3f22014-02-28 23:21:35 +0000564};
565
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000566static void
567decode_old_sigaction(struct tcb *tcp, long addr)
568{
569 struct old_sigaction sa;
Elliott Hughes458b3f22014-02-28 23:21:35 +0000570 int r;
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000571
572 if (!addr) {
573 tprints("NULL");
574 return;
575 }
576 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
577 tprintf("%#lx", addr);
578 return;
579 }
Elliott Hughes458b3f22014-02-28 23:21:35 +0000580
581#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
582 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
583 struct old_sigaction32 sa32;
584 r = umove(tcp, addr, &sa32);
585 if (r >= 0) {
586 memset(&sa, 0, sizeof(sa));
587 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
588 sa.sa_flags = sa32.sa_flags;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100589#ifdef SA_RESTORER
Elliott Hughes458b3f22014-02-28 23:21:35 +0000590 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +0100591#endif
Elliott Hughes458b3f22014-02-28 23:21:35 +0000592 sa.sa_mask = sa32.sa_mask;
593 }
594 } else
595#endif
596 {
597 r = umove(tcp, addr, &sa);
598 }
599 if (r < 0) {
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000600 tprints("{...}");
601 return;
602 }
603
604 /* Architectures using function pointers, like
605 * hppa, may need to manipulate the function pointer
606 * to compute the result of a comparison. However,
607 * the __sa_handler function pointer exists only in
608 * the address space of the traced process, and can't
609 * be manipulated by strace. In order to prevent the
610 * compiler from generating code to manipulate
611 * __sa_handler we cast the function pointers to long. */
612 if ((long)sa.__sa_handler == (long)SIG_ERR)
613 tprints("{SIG_ERR, ");
614 else if ((long)sa.__sa_handler == (long)SIG_DFL)
615 tprints("{SIG_DFL, ");
616 else if ((long)sa.__sa_handler == (long)SIG_IGN)
617 tprints("{SIG_IGN, ");
618 else
619 tprintf("{%#lx, ", (long) sa.__sa_handler);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800620#ifdef MIPS
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000621 tprintsigmask_addr("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800622#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000623 tprintsigmask_val("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800624#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000625 tprints(", ");
626 printflags(sigact_flags, sa.sa_flags, "SA_???");
627#ifdef SA_RESTORER
628 if (sa.sa_flags & SA_RESTORER)
629 tprintf(", %p", sa.sa_restorer);
630#endif
631 tprints("}");
632}
633
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000634int
Denys Vlasenko12014262011-05-30 14:00:14 +0200635sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000636{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000637 if (entering(tcp)) {
638 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200639 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000640 decode_old_sigaction(tcp, tcp->u_arg[1]);
641 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642 } else
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000643 decode_old_sigaction(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000644 return 0;
645}
646
647int
Denys Vlasenko12014262011-05-30 14:00:14 +0200648sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000649{
650 if (entering(tcp)) {
651 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200652 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +0000654 case (long) SIG_ERR:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200655 tprints("SIG_ERR");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000656 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000657 case (long) SIG_DFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200658 tprints("SIG_DFL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000659 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000660 case (long) SIG_IGN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200661 tprints("SIG_IGN");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000662 break;
663 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000664 tprintf("%#lx", tcp->u_arg[1]);
665 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000666 return 0;
667 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000668 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000669 switch (tcp->u_rval) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100670 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000671 tcp->auxstr = "SIG_ERR"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100672 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000673 tcp->auxstr = "SIG_DFL"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100674 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000675 tcp->auxstr = "SIG_IGN"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100676 default:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000677 tcp->auxstr = NULL;
678 }
679 return RVAL_HEX | RVAL_STR;
680 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000681 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000682}
683
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000684#endif /* HAVE_SIGACTION */
685
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000686int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000687sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000689#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +0000690 if (entering(tcp)) {
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200691 struct arm_sigcontext {
692 unsigned long trap_no;
693 unsigned long error_code;
694 unsigned long oldmask;
695 unsigned long arm_r0;
696 unsigned long arm_r1;
697 unsigned long arm_r2;
698 unsigned long arm_r3;
699 unsigned long arm_r4;
700 unsigned long arm_r5;
701 unsigned long arm_r6;
702 unsigned long arm_r7;
703 unsigned long arm_r8;
704 unsigned long arm_r9;
705 unsigned long arm_r10;
706 unsigned long arm_fp;
707 unsigned long arm_ip;
708 unsigned long arm_sp;
709 unsigned long arm_lr;
710 unsigned long arm_pc;
711 unsigned long arm_cpsr;
712 unsigned long fault_address;
713 };
714 struct arm_ucontext {
715 unsigned long uc_flags;
716 unsigned long uc_link; /* struct ucontext* */
717 /* The next three members comprise stack_t struct: */
718 unsigned long ss_sp; /* void* */
719 unsigned long ss_flags; /* int */
720 unsigned long ss_size; /* size_t */
721 struct arm_sigcontext sc;
722 /* These two members are sigset_t: */
723 unsigned long uc_sigmask[2];
724 /* more fields follow, which we aren't interested in */
725 };
726 struct arm_ucontext uc;
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200727 if (umove(tcp, arm_regs.ARM_sp, &uc) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000728 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000729 /*
730 * Kernel fills out uc.sc.oldmask too when it sets up signal stack,
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200731 * but for sigmask restore, sigreturn syscall uses uc.uc_sigmask instead.
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200732 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000733 tprintsigmask_addr(") (mask ", uc.uc_sigmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000734 }
Roland McGrath0f87c492003-06-03 23:29:04 +0000735#elif defined(S390) || defined(S390X)
Roland McGrath0f87c492003-06-03 23:29:04 +0000736 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200737 long usp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000738 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200739 if (upeek(tcp->pid, PT_GPR15, &usp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000740 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100741 if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &sc) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000742 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000743 tprintsigmask_addr(") (mask ", sc.oldmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000744 }
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200745#elif defined(I386) || defined(X86_64)
746# if defined(X86_64)
747 if (current_personality == 0) /* 64-bit */
748 return 0;
749# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000750 if (entering(tcp)) {
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200751 struct i386_sigcontext_struct {
752 uint16_t gs, __gsh;
753 uint16_t fs, __fsh;
754 uint16_t es, __esh;
755 uint16_t ds, __dsh;
756 uint32_t edi;
757 uint32_t esi;
758 uint32_t ebp;
759 uint32_t esp;
760 uint32_t ebx;
761 uint32_t edx;
762 uint32_t ecx;
763 uint32_t eax;
764 uint32_t trapno;
765 uint32_t err;
766 uint32_t eip;
767 uint16_t cs, __csh;
768 uint32_t eflags;
769 uint32_t esp_at_signal;
770 uint16_t ss, __ssh;
771 uint32_t i387;
772 uint32_t oldmask;
773 uint32_t cr2;
774 };
775 struct i386_fpstate {
776 uint32_t cw;
777 uint32_t sw;
778 uint32_t tag;
779 uint32_t ipoff;
780 uint32_t cssel;
781 uint32_t dataoff;
782 uint32_t datasel;
783 uint8_t st[8][10]; /* 8*10 bytes: FP regs */
784 uint16_t status;
785 uint16_t magic;
786 uint32_t fxsr_env[6];
787 uint32_t mxcsr;
788 uint32_t reserved;
789 uint8_t stx[8][16]; /* 8*16 bytes: FP regs, each padded to 16 bytes */
790 uint8_t xmm[8][16]; /* 8 XMM regs */
791 uint32_t padding1[44];
792 uint32_t padding2[12]; /* union with struct _fpx_sw_bytes */
793 };
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200794 struct {
795 struct i386_sigcontext_struct sc;
796 struct i386_fpstate fp;
797 uint32_t extramask[1];
798 } signal_stack;
799 /* On i386, sc is followed on stack by struct fpstate
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100800 * and after it an additional u32 extramask[1] which holds
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200801 * upper half of the mask.
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100802 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000803 uint32_t sigmask[2];
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200804 if (umove(tcp, *i386_esp_ptr, &signal_stack) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000805 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000806 sigmask[0] = signal_stack.sc.oldmask;
807 sigmask[1] = signal_stack.extramask[0];
808 tprintsigmask_addr(") (mask ", sigmask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000810#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000811 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200812 struct sigcontext sc;
813 long sp;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000814 /* offset of sigcontext in the kernel's sigframe structure: */
815# define SIGFRAME_SC_OFFSET 0x90
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200816 if (upeek(tcp->pid, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000817 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000818 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000819 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000820 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000821 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000822#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +0000823 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200824 long esp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000825 struct sigcontext sc;
Anton Blanchardce6e33b2013-06-26 15:53:33 +0200826
827 esp = ppc_regs.gpr[1];
828
Andreas Schwabedb39342010-02-23 00:18:51 +0100829 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200830#ifdef POWERPC64
831 if (current_personality == 0)
832 esp += 128;
833 else
834 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +0100835#else
836 esp += 64;
837#endif
Roland McGrath0f87c492003-06-03 23:29:04 +0000838 if (umove(tcp, esp, &sc) < 0)
839 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000840 tprintsigmask_val(") (mask ", sc.oldmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000841 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000842#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000843 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200844 long usp;
845 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200846 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +0000848 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000849 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000850 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000852#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200854 long fp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000855 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200856 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000857 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +0000858 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000859 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000860 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100862#elif defined(SPARC) || defined(SPARC64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200863 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200864 long i1;
Denys Vlasenko56a52982011-06-09 01:36:29 +0200865 m_siginfo_t si;
Denys Vlasenko48e4c1b2013-02-16 08:23:40 +0100866 i1 = sparc_regs.u_regs[U_REG_O1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200867 if (umove(tcp, i1, &si) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100868 perror_msg("sigreturn: umove");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000869 return 0;
870 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000871 tprintsigmask_val(") (mask ", si.si_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000872 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100873#elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +0000874 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
875 sigreturn. */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200876 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200877 long sp;
878 struct ucontext uc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200879 if (upeek(tcp->pid, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000880 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +0000881 /* There are six words followed by a 128-byte siginfo. */
882 sp = sp + 6 * 4 + 128;
883 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000884 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000885 tprintsigmask_val(") (mask ", uc.uc_sigmask);
Roland McGrath542c2c62008-05-20 01:11:56 +0000886 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000887#elif defined(MIPS)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200888 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200889 long sp;
890 struct pt_regs regs;
891 m_siginfo_t si;
Denys Vlasenko56a52982011-06-09 01:36:29 +0200892 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100893 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenko56a52982011-06-09 01:36:29 +0200894 return 0;
895 }
Roland McGrath576b7842007-11-04 00:00:00 +0000896 sp = regs.regs[29];
897 if (umove(tcp, sp, &si) < 0)
Denys Vlasenkofacd45b2011-06-09 01:22:10 +0200898 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000899 tprintsigmask_val(") (mask ", si.si_mask);
Wichert Akkermanf90da011999-10-31 21:15:38 +0000900 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000901#elif defined(CRISV10) || defined(CRISV32)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000902 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200903 struct sigcontext sc;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000904 long regs[PT_MAX+1];
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000905 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100906 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000907 return 0;
908 }
909 if (umove(tcp, regs[PT_USP], &sc) < 0)
910 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000911 tprintsigmask_val(") (mask ", sc.oldmask);
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000912 }
Chris Metcalfc8c66982009-12-28 10:00:15 -0500913#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500914 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200915 struct ucontext uc;
Denys Vlasenko56a52982011-06-09 01:36:29 +0200916
917 /* offset of ucontext in the kernel's sigframe structure */
Chris Metcalf5c0796f2013-05-21 20:25:22 -0400918# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
Chris Metcalf0b99a8a2013-02-05 17:48:33 +0100919 if (umove(tcp, tile_regs.sp + SIGFRAME_UC_OFFSET, &uc) < 0)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500920 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000921 tprintsigmask_val(") (mask ", uc.uc_sigmask);
Chris Metcalfc8c66982009-12-28 10:00:15 -0500922 }
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200923#elif defined(MICROBLAZE)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200924 /* TODO: Verify that this is correct... */
925 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200926 struct sigcontext sc;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200927 long sp;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200928 /* Read r1, the stack pointer. */
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200929 if (upeek(tcp->pid, 1 * 4, &sp) < 0)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200930 return 0;
931 if (umove(tcp, sp, &sc) < 0)
932 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000933 tprintsigmask_val(") (mask ", sc.oldmask);
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200934 }
Chris Zankel8f636ed2013-03-25 10:22:07 -0700935#elif defined(XTENSA)
936 /* Xtensa only has rt_sys_sigreturn */
Vineet Gupta7daacbb2013-08-16 12:47:06 +0530937#elif defined(ARC)
938 /* ARC syscall ABI only supports rt_sys_sigreturn */
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000939#else
Dmitry V. Levinf112d072012-05-15 00:13:59 +0000940# warning No sys_sigreturn() for this architecture
941# warning (no problem, just a reminder :-)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000942#endif
Dmitry V. Levinf112d072012-05-15 00:13:59 +0000943 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944}
945
946int
Denys Vlasenko12014262011-05-30 14:00:14 +0200947sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948{
949 if (exiting(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000950 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000951 }
952 return RVAL_HEX | RVAL_STR;
953}
954
955int
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000956sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000957{
958 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000959 tprintsigmask_val("", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000960 }
961 return 0;
962}
963
Denys Vlasenko84703742012-02-25 02:38:52 +0100964#if !defined SS_ONSTACK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000965#define SS_ONSTACK 1
966#define SS_DISABLE 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000967#endif
968
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000969#include "xlat/sigaltstack_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000970
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000971static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200972print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000973{
974 stack_t ss;
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000975 int r;
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000976
977 if (!addr) {
978 tprints("NULL");
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000979 return;
980 }
981
982#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
983 if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
984 struct {
985 uint32_t ss_sp;
986 int32_t ss_flags;
987 uint32_t ss_size;
988 } ss32;
989 r = umove(tcp, addr, &ss32);
990 if (r >= 0) {
991 memset(&ss, 0, sizeof(ss));
992 ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
993 ss.ss_flags = ss32.ss_flags;
994 ss.ss_size = (unsigned long) ss32.ss_size;
995 }
996 } else
997#endif
998 {
999 r = umove(tcp, addr, &ss);
1000 }
1001 if (r < 0) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001002 tprintf("%#lx", addr);
1003 } else {
1004 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1005 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1006 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1007 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008}
1009
1010int
Denys Vlasenko12014262011-05-30 14:00:14 +02001011sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012{
1013 if (entering(tcp)) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001014 print_stack_t(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015 }
1016 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001017 tprints(", ");
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001018 print_stack_t(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001019 }
1020 return 0;
1021}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001022
1023#ifdef HAVE_SIGACTION
1024
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001025/* "Old" sigprocmask, which operates with word-sized signal masks */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026int
Denys Vlasenko12014262011-05-30 14:00:14 +02001027sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001028{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001029# ifdef ALPHA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001030 if (entering(tcp)) {
Mike Frysingerdde045c2012-03-15 00:45:33 -04001031 /*
1032 * Alpha/OSF is different: it doesn't pass in two pointers,
1033 * but rather passes in the new bitmask as an argument and
1034 * then returns the old bitmask. This "works" because we
1035 * only have 64 signals to worry about. If you want more,
1036 * use of the rt_sigprocmask syscall is required.
1037 * Alpha:
1038 * old = osf_sigprocmask(how, new);
1039 * Everyone else:
1040 * ret = sigprocmask(how, &new, &old, ...);
1041 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001042 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001043 tprintsigmask_val(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001044 }
1045 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001046 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001047 return RVAL_HEX | RVAL_STR;
1048 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001049# else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001051 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001052 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001053 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001054 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001055 }
1056 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001057 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001058 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001059 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001060 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001061 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001062# endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063 return 0;
1064}
1065
1066#endif /* HAVE_SIGACTION */
1067
1068int
Denys Vlasenko12014262011-05-30 14:00:14 +02001069sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001070{
1071 if (entering(tcp)) {
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001072 tprintf("%ld, %s",
1073 widen_to_long(tcp->u_arg[0]),
1074 signame(tcp->u_arg[1])
1075 );
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001076 }
1077 return 0;
1078}
1079
Roland McGrath8ffc3522003-07-09 09:47:49 +00001080int
Denys Vlasenko12014262011-05-30 14:00:14 +02001081sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001082{
1083 if (entering(tcp)) {
1084 tprintf("%ld, %ld, %s",
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001085 widen_to_long(tcp->u_arg[0]),
1086 widen_to_long(tcp->u_arg[1]),
1087 signame(tcp->u_arg[2])
1088 );
Roland McGrath8ffc3522003-07-09 09:47:49 +00001089 }
1090 return 0;
1091}
Roland McGrath8ffc3522003-07-09 09:47:49 +00001092
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001093int
Denys Vlasenko12014262011-05-30 14:00:14 +02001094sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001095{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096 if (exiting(tcp)) {
1097 if (syserror(tcp))
1098 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001100 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001101 }
1102 return 0;
1103}
1104
Denys Vlasenko12014262011-05-30 14:00:14 +02001105int
1106sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001107{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001108 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001109 if (entering(tcp)) {
1110 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001111 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001112 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1113 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001114 }
1115 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001116 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001117 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001118 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001119 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001120 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001121 }
1122 return 0;
1123}
1124
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001125/* Structure describing the action to be taken when a signal arrives. */
1126struct new_sigaction
1127{
Denys Vlasenko86d94842013-02-08 12:59:13 +01001128 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001129#ifdef MIPS
1130 unsigned int sa_flags;
1131 void (*__sa_handler)(int);
1132#else
Denys Vlasenko86d94842013-02-08 12:59:13 +01001133 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001134 unsigned long sa_flags;
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001135#endif /* !MIPS */
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001136#ifdef SA_RESTORER
1137 void (*sa_restorer)(void);
1138#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001139 /* Kernel treats sa_mask as an array of longs. */
1140 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1141};
1142/* Same for i386-on-x86_64 and similar cases */
1143struct new_sigaction32
1144{
1145 uint32_t __sa_handler;
1146 uint32_t sa_flags;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001147#ifdef SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001148 uint32_t sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001149#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001150 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001151};
1152
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001153static void
1154decode_new_sigaction(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001155{
1156 struct new_sigaction sa;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001157 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001158
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001159 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001160 tprints("NULL");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001161 return;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001162 }
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001163 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001164 tprintf("%#lx", addr);
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001165 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001166 }
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001167#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Denys Vlasenko9fd4f962012-03-19 09:36:42 +01001168 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001169 struct new_sigaction32 sa32;
1170 r = umove(tcp, addr, &sa32);
1171 if (r >= 0) {
1172 memset(&sa, 0, sizeof(sa));
1173 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1174 sa.sa_flags = sa32.sa_flags;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001175#ifdef SA_RESTORER
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001176 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
Vicente Olivert Rierac3a5c012014-09-11 20:05:18 +01001177#endif
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001178 /* Kernel treats sa_mask as an array of longs.
1179 * For 32-bit process, "long" is uint32_t, thus, for example,
1180 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1181 * But for (64-bit) kernel, 32th bit in sa_mask is
1182 * 32th bit in 0th (64-bit) long!
1183 * For little-endian, it's the same.
1184 * For big-endian, we swap 32-bit words.
1185 */
1186 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1187 }
1188 } else
1189#endif
1190 {
1191 r = umove(tcp, addr, &sa);
1192 }
1193 if (r < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001194 tprints("{...}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001195 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001196 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001197 /* Architectures using function pointers, like
1198 * hppa, may need to manipulate the function pointer
1199 * to compute the result of a comparison. However,
Denys Vlasenko86d94842013-02-08 12:59:13 +01001200 * the __sa_handler function pointer exists only in
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001201 * the address space of the traced process, and can't
1202 * be manipulated by strace. In order to prevent the
1203 * compiler from generating code to manipulate
Denys Vlasenko86d94842013-02-08 12:59:13 +01001204 * __sa_handler we cast the function pointers to long. */
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001205 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001206 tprints("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001207 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001208 tprints("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001209 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001210 tprints("{SIG_IGN, ");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001211 else
1212 tprintf("{%#lx, ", (long) sa.__sa_handler);
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001213 /*
1214 * Sigset size is in tcp->u_arg[4] (SPARC)
1215 * or in tcp->u_arg[3] (all other),
1216 * but kernel won't handle sys_rt_sigaction
1217 * with wrong sigset size (just returns EINVAL instead).
1218 * We just fetch the right size, which is NSIG / 8.
1219 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001220 tprintsigmask_val("", sa.sa_mask);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001221 tprints(", ");
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001222
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001223 printflags(sigact_flags, sa.sa_flags, "SA_???");
1224#ifdef SA_RESTORER
1225 if (sa.sa_flags & SA_RESTORER)
1226 tprintf(", %p", sa.sa_restorer);
1227#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001228 tprints("}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001229}
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001230
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001231int
1232sys_rt_sigaction(struct tcb *tcp)
1233{
1234 if (entering(tcp)) {
1235 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001236 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001237 decode_new_sigaction(tcp, tcp->u_arg[1]);
1238 tprints(", ");
1239 } else {
1240 decode_new_sigaction(tcp, tcp->u_arg[2]);
Denys Vlasenko9472a272013-02-12 11:43:46 +01001241#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001242 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1243#elif defined(ALPHA)
1244 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1245#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001246 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001247#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001248 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001249 return 0;
1250}
1251
Denys Vlasenko1d632462009-04-14 12:51:00 +00001252int
1253sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001254{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001255 if (exiting(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001256 /*
1257 * One of the few syscalls where sigset size (arg[1])
1258 * is allowed to be <= NSIG / 8, not strictly ==.
1259 * This allows non-rt sigpending() syscall
1260 * to reuse rt_sigpending() code in kernel.
1261 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001262 if (syserror(tcp))
1263 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001264 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001265 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1266 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001267 }
1268 return 0;
1269}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001270
1271int
1272sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001273{
1274 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001275 /* NB: kernel requires arg[1] == NSIG / 8 */
1276 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1277 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001278 }
1279 return 0;
1280}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001281
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001282static void
1283print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1284{
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001285 printsignal(sig);
1286 tprints(", ");
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001287 printsiginfo_at(tcp, uinfo);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001288}
1289
Denys Vlasenko1d632462009-04-14 12:51:00 +00001290int
1291sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292{
1293 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001295 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1296 }
1297 return 0;
1298}
1299
1300int
1301sys_rt_tgsigqueueinfo(struct tcb *tcp)
1302{
1303 if (entering(tcp)) {
1304 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1305 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001306 }
1307 return 0;
1308}
1309
Denys Vlasenko1d632462009-04-14 12:51:00 +00001310int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001311{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001312 /* NB: kernel requires arg[3] == NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001313 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001314 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001315 tprints(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001316 /* This is the only "return" parameter, */
1317 if (tcp->u_arg[1] != 0)
1318 return 0;
1319 /* ... if it's NULL, can decode all on entry */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001320 tprints("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001321 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001322 else if (tcp->u_arg[1] != 0) {
1323 /* syscall exit, and u_arg[1] wasn't NULL */
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001324 printsiginfo_at(tcp, tcp->u_arg[1]);
1325 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001326 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001327 else {
1328 /* syscall exit, and u_arg[1] was NULL */
1329 return 0;
1330 }
1331 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001332 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001333 return 0;
1334};
1335
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001336int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001337sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001338{
1339 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001340 tprints("<... resuming interrupted call ...>");
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001341 return 0;
1342}
1343
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001344static int
1345do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00001346{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001347 /* NB: kernel requires arg[2] == NSIG / 8 */
Roland McGrathf46ccd32007-08-02 01:15:59 +00001348 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001349 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001350 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001351 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00001352 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001353 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001354 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001355 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1356 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00001357 }
1358 return 0;
1359}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001360
1361int
1362sys_signalfd(struct tcb *tcp)
1363{
1364 return do_signalfd(tcp, -1);
1365}
1366
1367int
1368sys_signalfd4(struct tcb *tcp)
1369{
1370 return do_signalfd(tcp, 3);
1371}