blob: b11dc6a5c9e46f86582b2732511a374073352453 [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 <sys/user.h>
36#include <fcntl.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>
Wichert Akkermanfaf72222000-02-19 23:59:03 +000040#elif defined(HAVE_LINUX_PTRACE_H)
Denys Vlasenko84703742012-02-25 02:38:52 +010041# undef PTRACE_SYSCALL
Roland McGrathb0acdfd2004-03-01 21:31:02 +000042# ifdef HAVE_STRUCT_IA64_FPREG
43# define ia64_fpreg XXX_ia64_fpreg
44# endif
45# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
46# define pt_all_user_regs XXX_pt_all_user_regs
47# endif
Ali Polatel0b4060f2013-09-24 20:04:32 +030048# ifdef HAVE_STRUCT_PTRACE_PEEKSIGINFO_ARGS
49# define ptrace_peeksiginfo_args XXX_ptrace_peeksiginfo_args
50# endif
Denys Vlasenko84703742012-02-25 02:38:52 +010051# include <linux/ptrace.h>
Ali Polatel0b4060f2013-09-24 20:04:32 +030052# undef ptrace_peeksiginfo_args
Roland McGrathb0acdfd2004-03-01 21:31:02 +000053# undef ia64_fpreg
54# undef pt_all_user_regs
Wichert Akkerman15dea971999-10-06 13:06:34 +000055#endif
Wichert Akkerman36915a11999-07-13 15:45:02 +000056
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000057#ifdef IA64
58# include <asm/ptrace_offsets.h>
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020059#endif
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000060
Denys Vlasenko84703742012-02-25 02:38:52 +010061#if defined(SPARC) || defined(SPARC64) || defined(MIPS)
Roland McGrath576b7842007-11-04 00:00:00 +000062typedef struct {
63 struct pt_regs si_regs;
64 int si_mask;
65} m_siginfo_t;
Roland McGrath30ff45e2003-01-30 20:15:23 +000066#elif defined HAVE_ASM_SIGCONTEXT_H
H.J. Lu35be5812012-04-16 13:00:01 +020067# if !defined(IA64) && !defined(X86_64) && !defined(X32)
Denys Vlasenko84703742012-02-25 02:38:52 +010068# include <asm/sigcontext.h>
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010069# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000070#else /* !HAVE_ASM_SIGCONTEXT_H */
Denys Vlasenkob51f3642013-07-16 12:06:25 +020071# if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
72struct sigcontext {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073 unsigned long sc_mask;
74 unsigned long sc_usp;
75 unsigned long sc_d0;
76 unsigned long sc_d1;
77 unsigned long sc_a0;
78 unsigned long sc_a1;
79 unsigned short sc_sr;
80 unsigned long sc_pc;
81 unsigned short sc_formatvec;
82};
Denys Vlasenkob51f3642013-07-16 12:06:25 +020083# endif /* M68K */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084#endif /* !HAVE_ASM_SIGCONTEXT_H */
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020085
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000086#ifndef NSIG
Denys Vlasenko84703742012-02-25 02:38:52 +010087# warning: NSIG is not defined, using 32
88# define NSIG 32
Dmitry V. Levin38593e92014-02-26 16:51:28 +000089#elif NSIG < 32
90# error: NSIG < 32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091#endif
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020092
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093#ifdef HAVE_SIGACTION
94
Roland McGrath2638cb42002-12-15 23:58:41 +000095/* The libc headers do not define this constant since it should only be
Denys Vlasenko041b3ee2011-08-18 12:48:56 +020096 used by the implementation. So we define it here. */
Dmitry V. Levin5c7f6272014-02-08 00:26:06 +000097#ifndef SA_RESTORER
98# ifdef ASM_SA_RESTORER
99# define SA_RESTORER ASM_SA_RESTORER
Roland McGrath2638cb42002-12-15 23:58:41 +0000100# endif
101#endif
102
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000103#include "xlat/sigact_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000105#include "xlat/sigprocmaskcmds.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000106
107#endif /* HAVE_SIGACTION */
108
Nate Sammonsce780fc1999-03-29 23:23:13 +0000109/* Anonymous realtime signals. */
110/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
111 constant. This is what we want. Otherwise, just use SIGRTMIN. */
112#ifdef SIGRTMIN
113#ifndef __SIGRTMIN
114#define __SIGRTMIN SIGRTMIN
115#define __SIGRTMAX SIGRTMAX /* likewise */
116#endif
117#endif
118
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200119/* Note on the size of sigset_t:
120 *
121 * In glibc, sigset_t is an array with space for 1024 bits (!),
122 * even though all arches supported by Linux have only 64 signals
123 * except MIPS, which has 128. IOW, it is 128 bytes long.
124 *
125 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
126 * However, some old syscall return only 32 lower bits (one word).
127 * Example: sys_sigpending vs sys_rt_sigpending.
128 *
129 * Be aware of this fact when you try to
130 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
131 * - sizeof(sigset_t) is much bigger than you think,
132 * it may overflow tcp->u_arg[] array, and it may try to copy more data
133 * than is really available in <something>.
134 * Similarly,
135 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
136 * may be a bad idea: it'll try to read much more data than needed
137 * to fetch a sigset_t.
138 * Use (NSIG / 8) as a size instead.
139 */
140
Roland McGrathee36ce12004-09-04 03:53:10 +0000141const char *
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200142signame(int sig)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000143{
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200144 static char buf[sizeof("SIGRT_%d") + sizeof(int)*3];
145
146 if (sig >= 0 && sig < nsignals)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000147 return signalent[sig];
148#ifdef SIGRTMIN
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200149 if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
150 sprintf(buf, "SIGRT_%d", (int)(sig - __SIGRTMIN));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000151 return buf;
152 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200153#endif
154 sprintf(buf, "%d", sig);
155 return buf;
Nate Sammonsce780fc1999-03-29 23:23:13 +0000156}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000158static unsigned int
159popcount32(const uint32_t *a, unsigned int size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000161 unsigned int count = 0;
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200162
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000163 for (; size; ++a, --size) {
164 uint32_t x = *a;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000166#ifdef HAVE___BUILTIN_POPCOUNT
167 count += __builtin_popcount(x);
Denys Vlasenkoa8773792013-07-18 20:42:41 +0200168#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000169 for (; x; ++count)
170 x &= x - 1;
Nate Sammons4a121431999-04-06 01:19:39 +0000171#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100173
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000174 return count;
175}
176
177static const char *
178sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
179{
180 /*
181 * The maximum number of signal names to be printed is NSIG * 2 / 3.
182 * Most of signal names have length 7,
183 * average length of signal names is less than 7.
184 * The length of prefix string does not exceed 16.
185 */
186 static char outstr[128 + 8 * (NSIG * 2 / 3)];
187
188 char *s;
189 const uint32_t *mask;
190 uint32_t inverted_mask[NSIG / 32];
191 unsigned int size;
192 int i;
193 char sep;
194
195 s = stpcpy(outstr, prefix);
196
197 mask = sig_mask;
198 /* length of signal mask in 4-byte words */
199 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
200
201 /* check whether 2/3 or more bits are set */
202 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
203 /* show those signals that are NOT in the mask */
204 unsigned int j;
205 for (j = 0; j < size; ++j)
206 inverted_mask[j] = ~mask[j];
207 mask = inverted_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208 *s++ = '~';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000209 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100210
211 sep = '[';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000212 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
213 ++i;
214 *s++ = sep;
215 if (i < nsignals) {
216 s = stpcpy(s, signalent[i] + 3);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000217 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000218#ifdef SIGRTMIN
219 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
220 s += sprintf(s, "RT_%u", i - __SIGRTMIN);
221 }
222#endif
223 else {
224 s += sprintf(s, "%u", i);
225 }
226 sep = ' ';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000227 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100228 if (sep == '[')
229 *s++ = sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230 *s++ = ']';
231 *s = '\0';
232 return outstr;
233}
234
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000235#define tprintsigmask_addr(prefix, mask) \
236 tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
Denys Vlasenko75f4e1f2013-07-18 20:37:06 +0200237
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000238#define sprintsigmask_val(prefix, mask) \
239 sprintsigmask_n((prefix), &(mask), sizeof(mask))
240
241#define tprintsigmask_val(prefix, mask) \
242 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000243
244void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200245printsignal(int nr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000246{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200247 tprints(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248}
249
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000250void
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200251print_sigset_addr_len(struct tcb *tcp, long addr, long len)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000252{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000253 char mask[NSIG / 8];
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000254
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200255 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200256 tprints("NULL");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200257 return;
258 }
259 /* Here len is usually equals NSIG / 8 or current_wordsize.
260 * But we code this defensively:
261 */
262 if (len < 0) {
263 bad:
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000264 tprintf("%#lx", addr);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200265 return;
266 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000267 if (len >= NSIG / 8)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200268 len = NSIG / 8;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000269 else
270 len = (len + 3) & ~3;
271
272 if (umoven(tcp, addr, len, mask) < 0)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200273 goto bad;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000274 tprints(sprintsigmask_n("", mask, len));
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000275}
276
John Hughes58265892001-10-18 15:13:53 +0000277#ifndef ILL_ILLOPC
278#define ILL_ILLOPC 1 /* illegal opcode */
279#define ILL_ILLOPN 2 /* illegal operand */
280#define ILL_ILLADR 3 /* illegal addressing mode */
281#define ILL_ILLTRP 4 /* illegal trap */
282#define ILL_PRVOPC 5 /* privileged opcode */
283#define ILL_PRVREG 6 /* privileged register */
284#define ILL_COPROC 7 /* coprocessor error */
285#define ILL_BADSTK 8 /* internal stack error */
286#define FPE_INTDIV 1 /* integer divide by zero */
287#define FPE_INTOVF 2 /* integer overflow */
288#define FPE_FLTDIV 3 /* floating point divide by zero */
289#define FPE_FLTOVF 4 /* floating point overflow */
290#define FPE_FLTUND 5 /* floating point underflow */
291#define FPE_FLTRES 6 /* floating point inexact result */
292#define FPE_FLTINV 7 /* floating point invalid operation */
293#define FPE_FLTSUB 8 /* subscript out of range */
294#define SEGV_MAPERR 1 /* address not mapped to object */
295#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
296#define BUS_ADRALN 1 /* invalid address alignment */
297#define BUS_ADRERR 2 /* non-existant physical address */
298#define BUS_OBJERR 3 /* object specific hardware error */
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000299#define SYS_SECCOMP 1 /* seccomp triggered */
John Hughes58265892001-10-18 15:13:53 +0000300#define TRAP_BRKPT 1 /* process breakpoint */
301#define TRAP_TRACE 2 /* process trace trap */
302#define CLD_EXITED 1 /* child has exited */
303#define CLD_KILLED 2 /* child was killed */
304#define CLD_DUMPED 3 /* child terminated abnormally */
305#define CLD_TRAPPED 4 /* traced child has trapped */
306#define CLD_STOPPED 5 /* child has stopped */
307#define CLD_CONTINUED 6 /* stopped child has continued */
308#define POLL_IN 1 /* data input available */
309#define POLL_OUT 2 /* output buffers available */
310#define POLL_MSG 3 /* input message available */
311#define POLL_ERR 4 /* i/o error */
312#define POLL_PRI 5 /* high priority input available */
313#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000314#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000315#define SI_USER 0 /* sent by kill, sigsend, raise */
316#define SI_QUEUE -1 /* sent by sigqueue */
317#define SI_TIMER -2 /* sent by timer expiration */
318#define SI_MESGQ -3 /* sent by real time mesq state change */
319#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000320#define SI_SIGIO -5 /* sent by SIGIO */
321#define SI_TKILL -6 /* sent by tkill */
Dmitry V. Levinb9d4d212014-03-11 01:57:02 +0000322#define SI_DETHREAD -7 /* sent by execve killing subsidiary threads */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000323#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100324#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000325
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100326#ifndef SI_FROMUSER
327# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
Denys Vlasenko84703742012-02-25 02:38:52 +0100328#endif
John Hughes58265892001-10-18 15:13:53 +0000329
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000330#include "xlat/siginfo_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000331
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000332#include "xlat/sigill_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000333
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000334#include "xlat/sigfpe_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000335
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000336#include "xlat/sigtrap_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000337
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000338#include "xlat/sigchld_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000339
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000340#include "xlat/sigpoll_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000341
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000342#include "xlat/sigprof_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000343
344#ifdef SIGEMT
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000345#include "xlat/sigemt_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000346#endif
347
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000348#include "xlat/sigsegv_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000349
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000350#include "xlat/sigbus_codes.h"
John Hughes58265892001-10-18 15:13:53 +0000351
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000352#ifndef SYS_SECCOMP
353# define SYS_SECCOMP 1
354#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000355#include "xlat/sigsys_codes.h"
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000356
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000357static void
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000358printsigsource(const siginfo_t *sip)
359{
360 tprintf(", si_pid=%lu, si_uid=%lu",
361 (unsigned long) sip->si_pid,
362 (unsigned long) sip->si_uid);
363}
364
365static void
366printsigval(const siginfo_t *sip, int verbose)
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000367{
368 if (!verbose)
369 tprints(", ...");
370 else
371 tprintf(", si_value={int=%u, ptr=%#lx}",
372 sip->si_int,
373 (unsigned long) sip->si_ptr);
374}
375
John Hughes58265892001-10-18 15:13:53 +0000376void
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000377printsiginfo(siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000378{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000379 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000380
381 if (sip->si_signo == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200382 tprints("{}");
John Hughes58265892001-10-18 15:13:53 +0000383 return;
384 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200385 tprints("{si_signo=");
John Hughes58265892001-10-18 15:13:53 +0000386 printsignal(sip->si_signo);
387 code = xlookup(siginfo_codes, sip->si_code);
388 if (!code) {
389 switch (sip->si_signo) {
390 case SIGTRAP:
391 code = xlookup(sigtrap_codes, sip->si_code);
392 break;
393 case SIGCHLD:
394 code = xlookup(sigchld_codes, sip->si_code);
395 break;
396 case SIGPOLL:
397 code = xlookup(sigpoll_codes, sip->si_code);
398 break;
399 case SIGPROF:
400 code = xlookup(sigprof_codes, sip->si_code);
401 break;
402 case SIGILL:
403 code = xlookup(sigill_codes, sip->si_code);
404 break;
405#ifdef SIGEMT
406 case SIGEMT:
407 code = xlookup(sigemt_codes, sip->si_code);
408 break;
409#endif
410 case SIGFPE:
411 code = xlookup(sigfpe_codes, sip->si_code);
412 break;
413 case SIGSEGV:
414 code = xlookup(sigsegv_codes, sip->si_code);
415 break;
416 case SIGBUS:
417 code = xlookup(sigbus_codes, sip->si_code);
418 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000419 case SIGSYS:
420 code = xlookup(sigsys_codes, sip->si_code);
421 break;
John Hughes58265892001-10-18 15:13:53 +0000422 }
423 }
424 if (code)
425 tprintf(", si_code=%s", code);
426 else
427 tprintf(", si_code=%#x", sip->si_code);
428#ifdef SI_NOINFO
429 if (sip->si_code != SI_NOINFO)
430#endif
431 {
432 if (sip->si_errno) {
433 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
434 tprintf(", si_errno=%d", sip->si_errno);
435 else
436 tprintf(", si_errno=%s",
437 errnoent[sip->si_errno]);
438 }
439#ifdef SI_FROMUSER
440 if (SI_FROMUSER(sip)) {
John Hughes58265892001-10-18 15:13:53 +0000441 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000442#ifdef SI_USER
443 case SI_USER:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000444 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000445 break;
446#endif
447#ifdef SI_TKILL
448 case SI_TKILL:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000449 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000450 break;
451#endif
John Hughes58265892001-10-18 15:13:53 +0000452#ifdef SI_TIMER
453 case SI_TIMER:
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000454 tprintf(", si_timerid=%#x, si_overrun=%d",
455 sip->si_timerid, sip->si_overrun);
456 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000457 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000458#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000459 default:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000460 printsigsource(sip);
461 if (sip->si_ptr)
462 printsigval(sip, verbose);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000463 break;
John Hughes58265892001-10-18 15:13:53 +0000464 }
John Hughes58265892001-10-18 15:13:53 +0000465 }
466 else
467#endif /* SI_FROMUSER */
468 {
469 switch (sip->si_signo) {
470 case SIGCHLD:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000471 printsigsource(sip);
472 tprints(", si_status=");
John Hughes58265892001-10-18 15:13:53 +0000473 if (sip->si_code == CLD_EXITED)
474 tprintf("%d", sip->si_status);
475 else
476 printsignal(sip->si_status);
John Hughes58265892001-10-18 15:13:53 +0000477 if (!verbose)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200478 tprints(", ...");
John Hughes58265892001-10-18 15:13:53 +0000479 else
H.J. Lu2bb45812012-04-15 11:17:13 -0700480 tprintf(", si_utime=%llu, si_stime=%llu",
481 (unsigned long long) sip->si_utime,
482 (unsigned long long) sip->si_stime);
John Hughes58265892001-10-18 15:13:53 +0000483 break;
484 case SIGILL: case SIGFPE:
485 case SIGSEGV: case SIGBUS:
486 tprintf(", si_addr=%#lx",
487 (unsigned long) sip->si_addr);
488 break;
489 case SIGPOLL:
490 switch (sip->si_code) {
491 case POLL_IN: case POLL_OUT: case POLL_MSG:
492 tprintf(", si_band=%ld",
493 (long) sip->si_band);
494 break;
495 }
496 break;
Dmitry V. Levinbc091e32014-03-11 22:18:40 +0000497#ifdef HAVE_SIGINFO_T_SI_SYSCALL
498 case SIGSYS:
499 tprintf(", si_call_addr=%#lx, si_syscall=%d, si_arch=%u",
500 (unsigned long) sip->si_call_addr,
501 sip->si_syscall, sip->si_arch);
502 break;
503#endif
John Hughes58265892001-10-18 15:13:53 +0000504 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000505 if (sip->si_pid || sip->si_uid)
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000506 printsigsource(sip);
507 if (sip->si_ptr)
508 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000509 }
510 }
511 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200512 tprints("}");
John Hughes58265892001-10-18 15:13:53 +0000513}
514
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100515void
516printsiginfo_at(struct tcb *tcp, long addr)
517{
518 siginfo_t si;
519 if (!addr) {
520 tprints("NULL");
521 return;
522 }
523 if (syserror(tcp)) {
524 tprintf("%#lx", addr);
525 return;
526 }
527 if (umove(tcp, addr, &si) < 0) {
528 tprints("{???}");
529 return;
530 }
531 printsiginfo(&si, verbose(tcp));
532}
533
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000534int
Denys Vlasenko12014262011-05-30 14:00:14 +0200535sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536{
537 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000538 tprintsigmask_val("", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539 }
540 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000541 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542 return RVAL_HEX | RVAL_STR;
543 }
544 return 0;
545}
546
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547#ifdef HAVE_SIGACTION
548
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549struct old_sigaction {
Denys Vlasenko86d94842013-02-08 12:59:13 +0100550 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800551#ifdef MIPS
552 unsigned int sa_flags;
553 void (*__sa_handler)(int);
554 /* Kernel treats sa_mask as an array of longs. */
555 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
556#else
Denys Vlasenko86d94842013-02-08 12:59:13 +0100557 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558 unsigned long sa_mask;
559 unsigned long sa_flags;
560 void (*sa_restorer)(void);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800561#endif /* !MIPS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000563
Elliott Hughes458b3f22014-02-28 23:21:35 +0000564struct old_sigaction32 {
565 /* sa_handler may be a libc #define, need to use other name: */
566 uint32_t __sa_handler;
567 uint32_t sa_mask;
568 uint32_t sa_flags;
569 uint32_t sa_restorer;
570};
571
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000572static void
573decode_old_sigaction(struct tcb *tcp, long addr)
574{
575 struct old_sigaction sa;
Elliott Hughes458b3f22014-02-28 23:21:35 +0000576 int r;
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000577
578 if (!addr) {
579 tprints("NULL");
580 return;
581 }
582 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
583 tprintf("%#lx", addr);
584 return;
585 }
Elliott Hughes458b3f22014-02-28 23:21:35 +0000586
587#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
588 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
589 struct old_sigaction32 sa32;
590 r = umove(tcp, addr, &sa32);
591 if (r >= 0) {
592 memset(&sa, 0, sizeof(sa));
593 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
594 sa.sa_flags = sa32.sa_flags;
595 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
596 sa.sa_mask = sa32.sa_mask;
597 }
598 } else
599#endif
600 {
601 r = umove(tcp, addr, &sa);
602 }
603 if (r < 0) {
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000604 tprints("{...}");
605 return;
606 }
607
608 /* Architectures using function pointers, like
609 * hppa, may need to manipulate the function pointer
610 * to compute the result of a comparison. However,
611 * the __sa_handler function pointer exists only in
612 * the address space of the traced process, and can't
613 * be manipulated by strace. In order to prevent the
614 * compiler from generating code to manipulate
615 * __sa_handler we cast the function pointers to long. */
616 if ((long)sa.__sa_handler == (long)SIG_ERR)
617 tprints("{SIG_ERR, ");
618 else if ((long)sa.__sa_handler == (long)SIG_DFL)
619 tprints("{SIG_DFL, ");
620 else if ((long)sa.__sa_handler == (long)SIG_IGN)
621 tprints("{SIG_IGN, ");
622 else
623 tprintf("{%#lx, ", (long) sa.__sa_handler);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800624#ifdef MIPS
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000625 tprintsigmask_addr("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800626#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000627 tprintsigmask_val("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800628#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000629 tprints(", ");
630 printflags(sigact_flags, sa.sa_flags, "SA_???");
631#ifdef SA_RESTORER
632 if (sa.sa_flags & SA_RESTORER)
633 tprintf(", %p", sa.sa_restorer);
634#endif
635 tprints("}");
636}
637
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638int
Denys Vlasenko12014262011-05-30 14:00:14 +0200639sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000641 if (entering(tcp)) {
642 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200643 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000644 decode_old_sigaction(tcp, tcp->u_arg[1]);
645 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000646 } else
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000647 decode_old_sigaction(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000648 return 0;
649}
650
651int
Denys Vlasenko12014262011-05-30 14:00:14 +0200652sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653{
654 if (entering(tcp)) {
655 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200656 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +0000658 case (long) SIG_ERR:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200659 tprints("SIG_ERR");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000661 case (long) SIG_DFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200662 tprints("SIG_DFL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000663 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000664 case (long) SIG_IGN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200665 tprints("SIG_IGN");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666 break;
667 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000668 tprintf("%#lx", tcp->u_arg[1]);
669 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000670 return 0;
671 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000672 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000673 switch (tcp->u_rval) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100674 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000675 tcp->auxstr = "SIG_ERR"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100676 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000677 tcp->auxstr = "SIG_DFL"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100678 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000679 tcp->auxstr = "SIG_IGN"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100680 default:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000681 tcp->auxstr = NULL;
682 }
683 return RVAL_HEX | RVAL_STR;
684 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000685 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000686}
687
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688#endif /* HAVE_SIGACTION */
689
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000691sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000693#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +0000694 if (entering(tcp)) {
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200695 struct arm_sigcontext {
696 unsigned long trap_no;
697 unsigned long error_code;
698 unsigned long oldmask;
699 unsigned long arm_r0;
700 unsigned long arm_r1;
701 unsigned long arm_r2;
702 unsigned long arm_r3;
703 unsigned long arm_r4;
704 unsigned long arm_r5;
705 unsigned long arm_r6;
706 unsigned long arm_r7;
707 unsigned long arm_r8;
708 unsigned long arm_r9;
709 unsigned long arm_r10;
710 unsigned long arm_fp;
711 unsigned long arm_ip;
712 unsigned long arm_sp;
713 unsigned long arm_lr;
714 unsigned long arm_pc;
715 unsigned long arm_cpsr;
716 unsigned long fault_address;
717 };
718 struct arm_ucontext {
719 unsigned long uc_flags;
720 unsigned long uc_link; /* struct ucontext* */
721 /* The next three members comprise stack_t struct: */
722 unsigned long ss_sp; /* void* */
723 unsigned long ss_flags; /* int */
724 unsigned long ss_size; /* size_t */
725 struct arm_sigcontext sc;
726 /* These two members are sigset_t: */
727 unsigned long uc_sigmask[2];
728 /* more fields follow, which we aren't interested in */
729 };
730 struct arm_ucontext uc;
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200731 if (umove(tcp, arm_regs.ARM_sp, &uc) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000732 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000733 /*
734 * Kernel fills out uc.sc.oldmask too when it sets up signal stack,
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200735 * but for sigmask restore, sigreturn syscall uses uc.uc_sigmask instead.
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200736 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000737 tprintsigmask_addr(") (mask ", uc.uc_sigmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000738 }
Roland McGrath0f87c492003-06-03 23:29:04 +0000739#elif defined(S390) || defined(S390X)
Roland McGrath0f87c492003-06-03 23:29:04 +0000740 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200741 long usp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000742 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200743 if (upeek(tcp->pid, PT_GPR15, &usp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000744 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100745 if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &sc) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000746 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000747 tprintsigmask_addr(") (mask ", sc.oldmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000748 }
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200749#elif defined(I386) || defined(X86_64)
750# if defined(X86_64)
751 if (current_personality == 0) /* 64-bit */
752 return 0;
753# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000754 if (entering(tcp)) {
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200755 struct i386_sigcontext_struct {
756 uint16_t gs, __gsh;
757 uint16_t fs, __fsh;
758 uint16_t es, __esh;
759 uint16_t ds, __dsh;
760 uint32_t edi;
761 uint32_t esi;
762 uint32_t ebp;
763 uint32_t esp;
764 uint32_t ebx;
765 uint32_t edx;
766 uint32_t ecx;
767 uint32_t eax;
768 uint32_t trapno;
769 uint32_t err;
770 uint32_t eip;
771 uint16_t cs, __csh;
772 uint32_t eflags;
773 uint32_t esp_at_signal;
774 uint16_t ss, __ssh;
775 uint32_t i387;
776 uint32_t oldmask;
777 uint32_t cr2;
778 };
779 struct i386_fpstate {
780 uint32_t cw;
781 uint32_t sw;
782 uint32_t tag;
783 uint32_t ipoff;
784 uint32_t cssel;
785 uint32_t dataoff;
786 uint32_t datasel;
787 uint8_t st[8][10]; /* 8*10 bytes: FP regs */
788 uint16_t status;
789 uint16_t magic;
790 uint32_t fxsr_env[6];
791 uint32_t mxcsr;
792 uint32_t reserved;
793 uint8_t stx[8][16]; /* 8*16 bytes: FP regs, each padded to 16 bytes */
794 uint8_t xmm[8][16]; /* 8 XMM regs */
795 uint32_t padding1[44];
796 uint32_t padding2[12]; /* union with struct _fpx_sw_bytes */
797 };
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200798 struct {
799 struct i386_sigcontext_struct sc;
800 struct i386_fpstate fp;
801 uint32_t extramask[1];
802 } signal_stack;
803 /* On i386, sc is followed on stack by struct fpstate
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100804 * and after it an additional u32 extramask[1] which holds
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200805 * upper half of the mask.
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100806 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000807 uint32_t sigmask[2];
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200808 if (umove(tcp, *i386_esp_ptr, &signal_stack) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000810 sigmask[0] = signal_stack.sc.oldmask;
811 sigmask[1] = signal_stack.extramask[0];
812 tprintsigmask_addr(") (mask ", sigmask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000813 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000814#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000815 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200816 struct sigcontext sc;
817 long sp;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000818 /* offset of sigcontext in the kernel's sigframe structure: */
819# define SIGFRAME_SC_OFFSET 0x90
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200820 if (upeek(tcp->pid, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000821 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000822 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000823 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000824 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000825 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000826#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +0000827 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200828 long esp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000829 struct sigcontext sc;
Anton Blanchardce6e33b2013-06-26 15:53:33 +0200830
831 esp = ppc_regs.gpr[1];
832
Andreas Schwabedb39342010-02-23 00:18:51 +0100833 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200834#ifdef POWERPC64
835 if (current_personality == 0)
836 esp += 128;
837 else
838 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +0100839#else
840 esp += 64;
841#endif
Roland McGrath0f87c492003-06-03 23:29:04 +0000842 if (umove(tcp, esp, &sc) < 0)
843 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000844 tprintsigmask_val(") (mask ", sc.oldmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000845 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000846#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200848 long usp;
849 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200850 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +0000852 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000854 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000855 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000856#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000857 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200858 long fp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000859 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200860 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +0000862 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000863 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000864 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000865 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100866#elif defined(SPARC) || defined(SPARC64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200867 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200868 long i1;
Denys Vlasenko56a52982011-06-09 01:36:29 +0200869 m_siginfo_t si;
Denys Vlasenko48e4c1b2013-02-16 08:23:40 +0100870 i1 = sparc_regs.u_regs[U_REG_O1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200871 if (umove(tcp, i1, &si) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100872 perror_msg("sigreturn: umove");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000873 return 0;
874 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000875 tprintsigmask_val(") (mask ", si.si_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000876 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100877#elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +0000878 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
879 sigreturn. */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200880 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200881 long sp;
882 struct ucontext uc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200883 if (upeek(tcp->pid, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000884 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +0000885 /* There are six words followed by a 128-byte siginfo. */
886 sp = sp + 6 * 4 + 128;
887 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000888 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000889 tprintsigmask_val(") (mask ", uc.uc_sigmask);
Roland McGrath542c2c62008-05-20 01:11:56 +0000890 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000891#elif defined(MIPS)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200892 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200893 long sp;
894 struct pt_regs regs;
895 m_siginfo_t si;
Denys Vlasenko56a52982011-06-09 01:36:29 +0200896 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100897 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenko56a52982011-06-09 01:36:29 +0200898 return 0;
899 }
Roland McGrath576b7842007-11-04 00:00:00 +0000900 sp = regs.regs[29];
901 if (umove(tcp, sp, &si) < 0)
Denys Vlasenkofacd45b2011-06-09 01:22:10 +0200902 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000903 tprintsigmask_val(") (mask ", si.si_mask);
Wichert Akkermanf90da011999-10-31 21:15:38 +0000904 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000905#elif defined(CRISV10) || defined(CRISV32)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000906 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200907 struct sigcontext sc;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000908 long regs[PT_MAX+1];
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000909 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +0100910 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000911 return 0;
912 }
913 if (umove(tcp, regs[PT_USP], &sc) < 0)
914 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000915 tprintsigmask_val(") (mask ", sc.oldmask);
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000916 }
Chris Metcalfc8c66982009-12-28 10:00:15 -0500917#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500918 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200919 struct ucontext uc;
Denys Vlasenko56a52982011-06-09 01:36:29 +0200920
921 /* offset of ucontext in the kernel's sigframe structure */
Chris Metcalf5c0796f2013-05-21 20:25:22 -0400922# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
Chris Metcalf0b99a8a2013-02-05 17:48:33 +0100923 if (umove(tcp, tile_regs.sp + SIGFRAME_UC_OFFSET, &uc) < 0)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500924 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000925 tprintsigmask_val(") (mask ", uc.uc_sigmask);
Chris Metcalfc8c66982009-12-28 10:00:15 -0500926 }
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200927#elif defined(MICROBLAZE)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200928 /* TODO: Verify that this is correct... */
929 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200930 struct sigcontext sc;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200931 long sp;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200932 /* Read r1, the stack pointer. */
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200933 if (upeek(tcp->pid, 1 * 4, &sp) < 0)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200934 return 0;
935 if (umove(tcp, sp, &sc) < 0)
936 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000937 tprintsigmask_val(") (mask ", sc.oldmask);
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200938 }
Chris Zankel8f636ed2013-03-25 10:22:07 -0700939#elif defined(XTENSA)
940 /* Xtensa only has rt_sys_sigreturn */
Vineet Gupta7daacbb2013-08-16 12:47:06 +0530941#elif defined(ARC)
942 /* ARC syscall ABI only supports rt_sys_sigreturn */
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000943#else
Dmitry V. Levinf112d072012-05-15 00:13:59 +0000944# warning No sys_sigreturn() for this architecture
945# warning (no problem, just a reminder :-)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000946#endif
Dmitry V. Levinf112d072012-05-15 00:13:59 +0000947 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948}
949
950int
Denys Vlasenko12014262011-05-30 14:00:14 +0200951sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952{
953 if (exiting(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000954 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000955 }
956 return RVAL_HEX | RVAL_STR;
957}
958
959int
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000960sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000961{
962 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000963 tprintsigmask_val("", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000964 }
965 return 0;
966}
967
Denys Vlasenko84703742012-02-25 02:38:52 +0100968#if !defined SS_ONSTACK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000969#define SS_ONSTACK 1
970#define SS_DISABLE 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000971#endif
972
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000973#include "xlat/sigaltstack_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000974
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000975static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200976print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000977{
978 stack_t ss;
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000979 int r;
Dmitry V. Levin338c0692013-02-09 02:03:04 +0000980
981 if (!addr) {
982 tprints("NULL");
Dmitry V. Levind153bfc2014-02-26 22:29:27 +0000983 return;
984 }
985
986#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
987 if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
988 struct {
989 uint32_t ss_sp;
990 int32_t ss_flags;
991 uint32_t ss_size;
992 } ss32;
993 r = umove(tcp, addr, &ss32);
994 if (r >= 0) {
995 memset(&ss, 0, sizeof(ss));
996 ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
997 ss.ss_flags = ss32.ss_flags;
998 ss.ss_size = (unsigned long) ss32.ss_size;
999 }
1000 } else
1001#endif
1002 {
1003 r = umove(tcp, addr, &ss);
1004 }
1005 if (r < 0) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001006 tprintf("%#lx", addr);
1007 } else {
1008 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1009 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1010 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1011 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012}
1013
1014int
Denys Vlasenko12014262011-05-30 14:00:14 +02001015sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016{
1017 if (entering(tcp)) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001018 print_stack_t(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001019 }
1020 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001021 tprints(", ");
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001022 print_stack_t(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001023 }
1024 return 0;
1025}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026
1027#ifdef HAVE_SIGACTION
1028
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001029/* "Old" sigprocmask, which operates with word-sized signal masks */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001030int
Denys Vlasenko12014262011-05-30 14:00:14 +02001031sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001033# ifdef ALPHA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034 if (entering(tcp)) {
Mike Frysingerdde045c2012-03-15 00:45:33 -04001035 /*
1036 * Alpha/OSF is different: it doesn't pass in two pointers,
1037 * but rather passes in the new bitmask as an argument and
1038 * then returns the old bitmask. This "works" because we
1039 * only have 64 signals to worry about. If you want more,
1040 * use of the rt_sigprocmask syscall is required.
1041 * Alpha:
1042 * old = osf_sigprocmask(how, new);
1043 * Everyone else:
1044 * ret = sigprocmask(how, &new, &old, ...);
1045 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001046 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001047 tprintsigmask_val(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001048 }
1049 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001050 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001051 return RVAL_HEX | RVAL_STR;
1052 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001053# else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001054 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001055 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001056 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001057 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001058 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001059 }
1060 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001061 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001062 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001064 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001065 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001066# endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001067 return 0;
1068}
1069
1070#endif /* HAVE_SIGACTION */
1071
1072int
Denys Vlasenko12014262011-05-30 14:00:14 +02001073sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001074{
1075 if (entering(tcp)) {
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001076 tprintf("%ld, %s",
1077 widen_to_long(tcp->u_arg[0]),
1078 signame(tcp->u_arg[1])
1079 );
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001080 }
1081 return 0;
1082}
1083
Roland McGrath8ffc3522003-07-09 09:47:49 +00001084int
Denys Vlasenko12014262011-05-30 14:00:14 +02001085sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001086{
1087 if (entering(tcp)) {
1088 tprintf("%ld, %ld, %s",
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001089 widen_to_long(tcp->u_arg[0]),
1090 widen_to_long(tcp->u_arg[1]),
1091 signame(tcp->u_arg[2])
1092 );
Roland McGrath8ffc3522003-07-09 09:47:49 +00001093 }
1094 return 0;
1095}
Roland McGrath8ffc3522003-07-09 09:47:49 +00001096
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001097int
Denys Vlasenko12014262011-05-30 14:00:14 +02001098sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001100 if (exiting(tcp)) {
1101 if (syserror(tcp))
1102 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001103 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001104 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001105 }
1106 return 0;
1107}
1108
Denys Vlasenko12014262011-05-30 14:00:14 +02001109int
1110sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001111{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001112 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001113 if (entering(tcp)) {
1114 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001115 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001116 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1117 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001118 }
1119 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001120 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001121 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001122 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001123 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001124 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001125 }
1126 return 0;
1127}
1128
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001129/* Structure describing the action to be taken when a signal arrives. */
1130struct new_sigaction
1131{
Denys Vlasenko86d94842013-02-08 12:59:13 +01001132 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001133#ifdef MIPS
1134 unsigned int sa_flags;
1135 void (*__sa_handler)(int);
1136#else
Denys Vlasenko86d94842013-02-08 12:59:13 +01001137 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001138 unsigned long sa_flags;
Denys Vlasenko86d94842013-02-08 12:59:13 +01001139 void (*sa_restorer)(void);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001140#endif /* !MIPS */
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001141 /* Kernel treats sa_mask as an array of longs. */
1142 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1143};
1144/* Same for i386-on-x86_64 and similar cases */
1145struct new_sigaction32
1146{
1147 uint32_t __sa_handler;
1148 uint32_t sa_flags;
1149 uint32_t sa_restorer;
1150 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;
1175 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1176 /* Kernel treats sa_mask as an array of longs.
1177 * For 32-bit process, "long" is uint32_t, thus, for example,
1178 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1179 * But for (64-bit) kernel, 32th bit in sa_mask is
1180 * 32th bit in 0th (64-bit) long!
1181 * For little-endian, it's the same.
1182 * For big-endian, we swap 32-bit words.
1183 */
1184 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1185 }
1186 } else
1187#endif
1188 {
1189 r = umove(tcp, addr, &sa);
1190 }
1191 if (r < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001192 tprints("{...}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001193 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001194 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001195 /* Architectures using function pointers, like
1196 * hppa, may need to manipulate the function pointer
1197 * to compute the result of a comparison. However,
Denys Vlasenko86d94842013-02-08 12:59:13 +01001198 * the __sa_handler function pointer exists only in
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001199 * the address space of the traced process, and can't
1200 * be manipulated by strace. In order to prevent the
1201 * compiler from generating code to manipulate
Denys Vlasenko86d94842013-02-08 12:59:13 +01001202 * __sa_handler we cast the function pointers to long. */
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001203 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001204 tprints("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001205 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001206 tprints("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001207 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001208 tprints("{SIG_IGN, ");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001209 else
1210 tprintf("{%#lx, ", (long) sa.__sa_handler);
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001211 /*
1212 * Sigset size is in tcp->u_arg[4] (SPARC)
1213 * or in tcp->u_arg[3] (all other),
1214 * but kernel won't handle sys_rt_sigaction
1215 * with wrong sigset size (just returns EINVAL instead).
1216 * We just fetch the right size, which is NSIG / 8.
1217 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001218 tprintsigmask_val("", sa.sa_mask);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001219 tprints(", ");
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001220
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001221 printflags(sigact_flags, sa.sa_flags, "SA_???");
1222#ifdef SA_RESTORER
1223 if (sa.sa_flags & SA_RESTORER)
1224 tprintf(", %p", sa.sa_restorer);
1225#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001226 tprints("}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001227}
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001228
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001229int
1230sys_rt_sigaction(struct tcb *tcp)
1231{
1232 if (entering(tcp)) {
1233 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001234 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001235 decode_new_sigaction(tcp, tcp->u_arg[1]);
1236 tprints(", ");
1237 } else {
1238 decode_new_sigaction(tcp, tcp->u_arg[2]);
Denys Vlasenko9472a272013-02-12 11:43:46 +01001239#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001240 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1241#elif defined(ALPHA)
1242 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1243#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001244 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001245#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001246 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001247 return 0;
1248}
1249
Denys Vlasenko1d632462009-04-14 12:51:00 +00001250int
1251sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001252{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001253 if (exiting(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001254 /*
1255 * One of the few syscalls where sigset size (arg[1])
1256 * is allowed to be <= NSIG / 8, not strictly ==.
1257 * This allows non-rt sigpending() syscall
1258 * to reuse rt_sigpending() code in kernel.
1259 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001260 if (syserror(tcp))
1261 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001262 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001263 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1264 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001265 }
1266 return 0;
1267}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001268
1269int
1270sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001271{
1272 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001273 /* NB: kernel requires arg[1] == NSIG / 8 */
1274 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1275 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001276 }
1277 return 0;
1278}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001279
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001280static void
1281print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1282{
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001283 printsignal(sig);
1284 tprints(", ");
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001285 printsiginfo_at(tcp, uinfo);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001286}
1287
Denys Vlasenko1d632462009-04-14 12:51:00 +00001288int
1289sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290{
1291 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001293 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1294 }
1295 return 0;
1296}
1297
1298int
1299sys_rt_tgsigqueueinfo(struct tcb *tcp)
1300{
1301 if (entering(tcp)) {
1302 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1303 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001304 }
1305 return 0;
1306}
1307
Denys Vlasenko1d632462009-04-14 12:51:00 +00001308int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001309{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001310 /* NB: kernel requires arg[3] == NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001311 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001312 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001313 tprints(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001314 /* This is the only "return" parameter, */
1315 if (tcp->u_arg[1] != 0)
1316 return 0;
1317 /* ... if it's NULL, can decode all on entry */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001318 tprints("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001319 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001320 else if (tcp->u_arg[1] != 0) {
1321 /* syscall exit, and u_arg[1] wasn't NULL */
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001322 printsiginfo_at(tcp, tcp->u_arg[1]);
1323 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001324 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001325 else {
1326 /* syscall exit, and u_arg[1] was NULL */
1327 return 0;
1328 }
1329 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001330 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001331 return 0;
1332};
1333
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001334int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001335sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001336{
1337 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001338 tprints("<... resuming interrupted call ...>");
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001339 return 0;
1340}
1341
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001342static int
1343do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00001344{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001345 /* NB: kernel requires arg[2] == NSIG / 8 */
Roland McGrathf46ccd32007-08-02 01:15:59 +00001346 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001347 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001348 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001349 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00001350 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001351 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001352 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001353 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1354 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00001355 }
1356 return 0;
1357}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001358
1359int
1360sys_signalfd(struct tcb *tcp)
1361{
1362 return do_signalfd(tcp, -1);
1363}
1364
1365int
1366sys_signalfd4(struct tcb *tcp)
1367{
1368 return do_signalfd(tcp, 3);
1369}