blob: c85e1b56d45d00f9c8bc69ea73d857a47984f806 [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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000103static const struct xlat sigact_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000104#ifdef SA_RESTORER
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000105 XLAT(SA_RESTORER),
Wichert Akkermanc7926982000-04-10 22:22:31 +0000106#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000107#ifdef SA_STACK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000108 XLAT(SA_STACK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000109#endif
110#ifdef SA_RESTART
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000111 XLAT(SA_RESTART),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000112#endif
113#ifdef SA_INTERRUPT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000114 XLAT(SA_INTERRUPT),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000115#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000116#ifdef SA_NODEFER
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000117 XLAT(SA_NODEFER),
Roland McGrath4fef51d2008-07-18 01:02:41 +0000118#endif
119#if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000120 XLAT(SA_NOMASK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000121#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000122#ifdef SA_RESETHAND
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000123 XLAT(SA_RESETHAND),
Roland McGrath4fef51d2008-07-18 01:02:41 +0000124#endif
125#if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000126 XLAT(SA_ONESHOT),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000127#endif
128#ifdef SA_SIGINFO
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000129 XLAT(SA_SIGINFO),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000130#endif
131#ifdef SA_RESETHAND
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000132 XLAT(SA_RESETHAND),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133#endif
134#ifdef SA_ONSTACK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000135 XLAT(SA_ONSTACK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000136#endif
137#ifdef SA_NODEFER
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000138 XLAT(SA_NODEFER),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000139#endif
140#ifdef SA_NOCLDSTOP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000141 XLAT(SA_NOCLDSTOP),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000142#endif
143#ifdef SA_NOCLDWAIT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000144 XLAT(SA_NOCLDWAIT),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000145#endif
146#ifdef _SA_BSDCALL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000147 XLAT(_SA_BSDCALL),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148#endif
Chris Metcalfc8c66982009-12-28 10:00:15 -0500149#ifdef SA_NOPTRACE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000150 XLAT(SA_NOPTRACE),
Chris Metcalfc8c66982009-12-28 10:00:15 -0500151#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000152 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153};
154
Roland McGrathd9f816f2004-09-04 03:39:20 +0000155static const struct xlat sigprocmaskcmds[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000156 XLAT(SIG_BLOCK),
157 XLAT(SIG_UNBLOCK),
158 XLAT(SIG_SETMASK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159#ifdef SIG_SETMASK32
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000160 XLAT(SIG_SETMASK32),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000162 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163};
164
165#endif /* HAVE_SIGACTION */
166
Nate Sammonsce780fc1999-03-29 23:23:13 +0000167/* Anonymous realtime signals. */
168/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
169 constant. This is what we want. Otherwise, just use SIGRTMIN. */
170#ifdef SIGRTMIN
171#ifndef __SIGRTMIN
172#define __SIGRTMIN SIGRTMIN
173#define __SIGRTMAX SIGRTMAX /* likewise */
174#endif
175#endif
176
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200177/* Note on the size of sigset_t:
178 *
179 * In glibc, sigset_t is an array with space for 1024 bits (!),
180 * even though all arches supported by Linux have only 64 signals
181 * except MIPS, which has 128. IOW, it is 128 bytes long.
182 *
183 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
184 * However, some old syscall return only 32 lower bits (one word).
185 * Example: sys_sigpending vs sys_rt_sigpending.
186 *
187 * Be aware of this fact when you try to
188 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
189 * - sizeof(sigset_t) is much bigger than you think,
190 * it may overflow tcp->u_arg[] array, and it may try to copy more data
191 * than is really available in <something>.
192 * Similarly,
193 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
194 * may be a bad idea: it'll try to read much more data than needed
195 * to fetch a sigset_t.
196 * Use (NSIG / 8) as a size instead.
197 */
198
Roland McGrathee36ce12004-09-04 03:53:10 +0000199const char *
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200200signame(int sig)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000201{
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200202 static char buf[sizeof("SIGRT_%d") + sizeof(int)*3];
203
204 if (sig >= 0 && sig < nsignals)
Nate Sammonsce780fc1999-03-29 23:23:13 +0000205 return signalent[sig];
206#ifdef SIGRTMIN
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200207 if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
208 sprintf(buf, "SIGRT_%d", (int)(sig - __SIGRTMIN));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000209 return buf;
210 }
Denys Vlasenko041b3ee2011-08-18 12:48:56 +0200211#endif
212 sprintf(buf, "%d", sig);
213 return buf;
Nate Sammonsce780fc1999-03-29 23:23:13 +0000214}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000215
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000216static unsigned int
217popcount32(const uint32_t *a, unsigned int size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000219 unsigned int count = 0;
Denys Vlasenkod9560c12011-08-19 17:41:28 +0200220
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000221 for (; size; ++a, --size) {
222 uint32_t x = *a;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000224#ifdef HAVE___BUILTIN_POPCOUNT
225 count += __builtin_popcount(x);
Denys Vlasenkoa8773792013-07-18 20:42:41 +0200226#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000227 for (; x; ++count)
228 x &= x - 1;
Nate Sammons4a121431999-04-06 01:19:39 +0000229#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100231
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000232 return count;
233}
234
235static const char *
236sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
237{
238 /*
239 * The maximum number of signal names to be printed is NSIG * 2 / 3.
240 * Most of signal names have length 7,
241 * average length of signal names is less than 7.
242 * The length of prefix string does not exceed 16.
243 */
244 static char outstr[128 + 8 * (NSIG * 2 / 3)];
245
246 char *s;
247 const uint32_t *mask;
248 uint32_t inverted_mask[NSIG / 32];
249 unsigned int size;
250 int i;
251 char sep;
252
253 s = stpcpy(outstr, prefix);
254
255 mask = sig_mask;
256 /* length of signal mask in 4-byte words */
257 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
258
259 /* check whether 2/3 or more bits are set */
260 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
261 /* show those signals that are NOT in the mask */
262 unsigned int j;
263 for (j = 0; j < size; ++j)
264 inverted_mask[j] = ~mask[j];
265 mask = inverted_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000266 *s++ = '~';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000267 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100268
269 sep = '[';
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000270 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
271 ++i;
272 *s++ = sep;
273 if (i < nsignals) {
274 s = stpcpy(s, signalent[i] + 3);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000276#ifdef SIGRTMIN
277 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
278 s += sprintf(s, "RT_%u", i - __SIGRTMIN);
279 }
280#endif
281 else {
282 s += sprintf(s, "%u", i);
283 }
284 sep = ' ';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000285 }
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100286 if (sep == '[')
287 *s++ = sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000288 *s++ = ']';
289 *s = '\0';
290 return outstr;
291}
292
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000293#define tprintsigmask_addr(prefix, mask) \
294 tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
Denys Vlasenko75f4e1f2013-07-18 20:37:06 +0200295
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000296#define sprintsigmask_val(prefix, mask) \
297 sprintsigmask_n((prefix), &(mask), sizeof(mask))
298
299#define tprintsigmask_val(prefix, mask) \
300 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301
302void
Denys Vlasenkoeccc48c2011-06-09 01:28:11 +0200303printsignal(int nr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000304{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200305 tprints(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306}
307
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000308void
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200309print_sigset_addr_len(struct tcb *tcp, long addr, long len)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000310{
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000311 char mask[NSIG / 8];
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000312
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200313 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200314 tprints("NULL");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200315 return;
316 }
317 /* Here len is usually equals NSIG / 8 or current_wordsize.
318 * But we code this defensively:
319 */
320 if (len < 0) {
321 bad:
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000322 tprintf("%#lx", addr);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200323 return;
324 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000325 if (len >= NSIG / 8)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200326 len = NSIG / 8;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000327 else
328 len = (len + 3) & ~3;
329
330 if (umoven(tcp, addr, len, mask) < 0)
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200331 goto bad;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000332 tprints(sprintsigmask_n("", mask, len));
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000333}
334
John Hughes58265892001-10-18 15:13:53 +0000335#ifndef ILL_ILLOPC
336#define ILL_ILLOPC 1 /* illegal opcode */
337#define ILL_ILLOPN 2 /* illegal operand */
338#define ILL_ILLADR 3 /* illegal addressing mode */
339#define ILL_ILLTRP 4 /* illegal trap */
340#define ILL_PRVOPC 5 /* privileged opcode */
341#define ILL_PRVREG 6 /* privileged register */
342#define ILL_COPROC 7 /* coprocessor error */
343#define ILL_BADSTK 8 /* internal stack error */
344#define FPE_INTDIV 1 /* integer divide by zero */
345#define FPE_INTOVF 2 /* integer overflow */
346#define FPE_FLTDIV 3 /* floating point divide by zero */
347#define FPE_FLTOVF 4 /* floating point overflow */
348#define FPE_FLTUND 5 /* floating point underflow */
349#define FPE_FLTRES 6 /* floating point inexact result */
350#define FPE_FLTINV 7 /* floating point invalid operation */
351#define FPE_FLTSUB 8 /* subscript out of range */
352#define SEGV_MAPERR 1 /* address not mapped to object */
353#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
354#define BUS_ADRALN 1 /* invalid address alignment */
355#define BUS_ADRERR 2 /* non-existant physical address */
356#define BUS_OBJERR 3 /* object specific hardware error */
357#define TRAP_BRKPT 1 /* process breakpoint */
358#define TRAP_TRACE 2 /* process trace trap */
359#define CLD_EXITED 1 /* child has exited */
360#define CLD_KILLED 2 /* child was killed */
361#define CLD_DUMPED 3 /* child terminated abnormally */
362#define CLD_TRAPPED 4 /* traced child has trapped */
363#define CLD_STOPPED 5 /* child has stopped */
364#define CLD_CONTINUED 6 /* stopped child has continued */
365#define POLL_IN 1 /* data input available */
366#define POLL_OUT 2 /* output buffers available */
367#define POLL_MSG 3 /* input message available */
368#define POLL_ERR 4 /* i/o error */
369#define POLL_PRI 5 /* high priority input available */
370#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000371#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000372#define SI_USER 0 /* sent by kill, sigsend, raise */
373#define SI_QUEUE -1 /* sent by sigqueue */
374#define SI_TIMER -2 /* sent by timer expiration */
375#define SI_MESGQ -3 /* sent by real time mesq state change */
376#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000377#define SI_SIGIO -5 /* sent by SIGIO */
378#define SI_TKILL -6 /* sent by tkill */
Dmitry V. Levinb9d4d212014-03-11 01:57:02 +0000379#define SI_DETHREAD -7 /* sent by execve killing subsidiary threads */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000380#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100381#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000382
Denys Vlasenko2c4fb902012-03-15 17:24:49 +0100383#ifndef SI_FROMUSER
384# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
Denys Vlasenko84703742012-02-25 02:38:52 +0100385#endif
John Hughes58265892001-10-18 15:13:53 +0000386
Roland McGrathd9f816f2004-09-04 03:39:20 +0000387static const struct xlat siginfo_codes[] = {
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000388#ifdef SI_KERNEL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000389 XLAT(SI_KERNEL),
John Hughes58265892001-10-18 15:13:53 +0000390#endif
391#ifdef SI_USER
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000392 XLAT(SI_USER),
John Hughes58265892001-10-18 15:13:53 +0000393#endif
John Hughes58265892001-10-18 15:13:53 +0000394#ifdef SI_QUEUE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000395 XLAT(SI_QUEUE),
John Hughes58265892001-10-18 15:13:53 +0000396#endif
397#ifdef SI_TIMER
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000398 XLAT(SI_TIMER),
John Hughes58265892001-10-18 15:13:53 +0000399#endif
John Hughes58265892001-10-18 15:13:53 +0000400#ifdef SI_MESGQ
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000401 XLAT(SI_MESGQ),
John Hughes58265892001-10-18 15:13:53 +0000402#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000403#ifdef SI_ASYNCIO
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000404 XLAT(SI_ASYNCIO),
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000405#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000406#ifdef SI_SIGIO
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000407 XLAT(SI_SIGIO),
Roland McGrath941b7402003-05-23 00:29:02 +0000408#endif
409#ifdef SI_TKILL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000410 XLAT(SI_TKILL),
Roland McGrath941b7402003-05-23 00:29:02 +0000411#endif
Dmitry V. Levinb9d4d212014-03-11 01:57:02 +0000412#ifdef SI_DETHREAD
413 XLAT(SI_DETHREAD),
414#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000415#ifdef SI_ASYNCNL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000416 XLAT(SI_ASYNCNL),
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000417#endif
418#ifdef SI_NOINFO
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000419 XLAT(SI_NOINFO),
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000420#endif
421#ifdef SI_LWP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000422 XLAT(SI_LWP),
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000423#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000424 XLAT_END
John Hughes58265892001-10-18 15:13:53 +0000425};
426
Roland McGrathd9f816f2004-09-04 03:39:20 +0000427static const struct xlat sigill_codes[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000428 XLAT(ILL_ILLOPC),
429 XLAT(ILL_ILLOPN),
430 XLAT(ILL_ILLADR),
431 XLAT(ILL_ILLTRP),
432 XLAT(ILL_PRVOPC),
433 XLAT(ILL_PRVREG),
434 XLAT(ILL_COPROC),
435 XLAT(ILL_BADSTK),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000436 XLAT_END
John Hughes58265892001-10-18 15:13:53 +0000437};
438
Roland McGrathd9f816f2004-09-04 03:39:20 +0000439static const struct xlat sigfpe_codes[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000440 XLAT(FPE_INTDIV),
441 XLAT(FPE_INTOVF),
442 XLAT(FPE_FLTDIV),
443 XLAT(FPE_FLTOVF),
444 XLAT(FPE_FLTUND),
445 XLAT(FPE_FLTRES),
446 XLAT(FPE_FLTINV),
447 XLAT(FPE_FLTSUB),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000448 XLAT_END
John Hughes58265892001-10-18 15:13:53 +0000449};
450
Roland McGrathd9f816f2004-09-04 03:39:20 +0000451static const struct xlat sigtrap_codes[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000452 XLAT(TRAP_BRKPT),
453 XLAT(TRAP_TRACE),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000454 XLAT_END
John Hughes58265892001-10-18 15:13:53 +0000455};
456
Roland McGrathd9f816f2004-09-04 03:39:20 +0000457static const struct xlat sigchld_codes[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000458 XLAT(CLD_EXITED),
459 XLAT(CLD_KILLED),
460 XLAT(CLD_DUMPED),
461 XLAT(CLD_TRAPPED),
462 XLAT(CLD_STOPPED),
463 XLAT(CLD_CONTINUED),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000464 XLAT_END
John Hughes58265892001-10-18 15:13:53 +0000465};
466
Roland McGrathd9f816f2004-09-04 03:39:20 +0000467static const struct xlat sigpoll_codes[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000468 XLAT(POLL_IN),
469 XLAT(POLL_OUT),
470 XLAT(POLL_MSG),
471 XLAT(POLL_ERR),
472 XLAT(POLL_PRI),
473 XLAT(POLL_HUP),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000474 XLAT_END
John Hughes58265892001-10-18 15:13:53 +0000475};
476
Roland McGrathd9f816f2004-09-04 03:39:20 +0000477static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000478#ifdef PROF_SIG
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000479 XLAT(PROF_SIG),
John Hughes58265892001-10-18 15:13:53 +0000480#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000481 XLAT_END
John Hughes58265892001-10-18 15:13:53 +0000482};
483
484#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000485static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000486#ifdef EMT_TAGOVF
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000487 XLAT(EMT_TAGOVF),
John Hughes58265892001-10-18 15:13:53 +0000488#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000489 XLAT_END
John Hughes58265892001-10-18 15:13:53 +0000490};
491#endif
492
Roland McGrathd9f816f2004-09-04 03:39:20 +0000493static const struct xlat sigsegv_codes[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000494 XLAT(SEGV_MAPERR),
495 XLAT(SEGV_ACCERR),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000496 XLAT_END
John Hughes58265892001-10-18 15:13:53 +0000497};
498
Roland McGrathd9f816f2004-09-04 03:39:20 +0000499static const struct xlat sigbus_codes[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000500 XLAT(BUS_ADRALN),
501 XLAT(BUS_ADRERR),
502 XLAT(BUS_OBJERR),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000503 XLAT_END
John Hughes58265892001-10-18 15:13:53 +0000504};
505
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000506static void
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000507printsigsource(const siginfo_t *sip)
508{
509 tprintf(", si_pid=%lu, si_uid=%lu",
510 (unsigned long) sip->si_pid,
511 (unsigned long) sip->si_uid);
512}
513
514static void
515printsigval(const siginfo_t *sip, int verbose)
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000516{
517 if (!verbose)
518 tprints(", ...");
519 else
520 tprintf(", si_value={int=%u, ptr=%#lx}",
521 sip->si_int,
522 (unsigned long) sip->si_ptr);
523}
524
John Hughes58265892001-10-18 15:13:53 +0000525void
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000526printsiginfo(siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000527{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000528 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000529
530 if (sip->si_signo == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200531 tprints("{}");
John Hughes58265892001-10-18 15:13:53 +0000532 return;
533 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200534 tprints("{si_signo=");
John Hughes58265892001-10-18 15:13:53 +0000535 printsignal(sip->si_signo);
536 code = xlookup(siginfo_codes, sip->si_code);
537 if (!code) {
538 switch (sip->si_signo) {
539 case SIGTRAP:
540 code = xlookup(sigtrap_codes, sip->si_code);
541 break;
542 case SIGCHLD:
543 code = xlookup(sigchld_codes, sip->si_code);
544 break;
545 case SIGPOLL:
546 code = xlookup(sigpoll_codes, sip->si_code);
547 break;
548 case SIGPROF:
549 code = xlookup(sigprof_codes, sip->si_code);
550 break;
551 case SIGILL:
552 code = xlookup(sigill_codes, sip->si_code);
553 break;
554#ifdef SIGEMT
555 case SIGEMT:
556 code = xlookup(sigemt_codes, sip->si_code);
557 break;
558#endif
559 case SIGFPE:
560 code = xlookup(sigfpe_codes, sip->si_code);
561 break;
562 case SIGSEGV:
563 code = xlookup(sigsegv_codes, sip->si_code);
564 break;
565 case SIGBUS:
566 code = xlookup(sigbus_codes, sip->si_code);
567 break;
568 }
569 }
570 if (code)
571 tprintf(", si_code=%s", code);
572 else
573 tprintf(", si_code=%#x", sip->si_code);
574#ifdef SI_NOINFO
575 if (sip->si_code != SI_NOINFO)
576#endif
577 {
578 if (sip->si_errno) {
579 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
580 tprintf(", si_errno=%d", sip->si_errno);
581 else
582 tprintf(", si_errno=%s",
583 errnoent[sip->si_errno]);
584 }
585#ifdef SI_FROMUSER
586 if (SI_FROMUSER(sip)) {
John Hughes58265892001-10-18 15:13:53 +0000587 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000588#ifdef SI_USER
589 case SI_USER:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000590 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000591 break;
592#endif
593#ifdef SI_TKILL
594 case SI_TKILL:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000595 printsigsource(sip);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000596 break;
597#endif
John Hughes58265892001-10-18 15:13:53 +0000598#ifdef SI_TIMER
599 case SI_TIMER:
Elliott Hughes4dd1e892014-03-10 19:27:22 +0000600 tprintf(", si_timerid=%#x, si_overrun=%d",
601 sip->si_timerid, sip->si_overrun);
602 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000603 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000604#endif
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000605 default:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000606 printsigsource(sip);
607 if (sip->si_ptr)
608 printsigval(sip, verbose);
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000609 break;
John Hughes58265892001-10-18 15:13:53 +0000610 }
John Hughes58265892001-10-18 15:13:53 +0000611 }
612 else
613#endif /* SI_FROMUSER */
614 {
615 switch (sip->si_signo) {
616 case SIGCHLD:
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000617 printsigsource(sip);
618 tprints(", si_status=");
John Hughes58265892001-10-18 15:13:53 +0000619 if (sip->si_code == CLD_EXITED)
620 tprintf("%d", sip->si_status);
621 else
622 printsignal(sip->si_status);
John Hughes58265892001-10-18 15:13:53 +0000623 if (!verbose)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200624 tprints(", ...");
John Hughes58265892001-10-18 15:13:53 +0000625 else
H.J. Lu2bb45812012-04-15 11:17:13 -0700626 tprintf(", si_utime=%llu, si_stime=%llu",
627 (unsigned long long) sip->si_utime,
628 (unsigned long long) sip->si_stime);
John Hughes58265892001-10-18 15:13:53 +0000629 break;
630 case SIGILL: case SIGFPE:
631 case SIGSEGV: case SIGBUS:
632 tprintf(", si_addr=%#lx",
633 (unsigned long) sip->si_addr);
634 break;
635 case SIGPOLL:
636 switch (sip->si_code) {
637 case POLL_IN: case POLL_OUT: case POLL_MSG:
638 tprintf(", si_band=%ld",
639 (long) sip->si_band);
640 break;
641 }
642 break;
John Hughes58265892001-10-18 15:13:53 +0000643 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000644 if (sip->si_pid || sip->si_uid)
Dmitry V. Levin4a524db2014-03-11 00:05:19 +0000645 printsigsource(sip);
646 if (sip->si_ptr)
647 printsigval(sip, verbose);
John Hughes58265892001-10-18 15:13:53 +0000648 }
649 }
650 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200651 tprints("}");
John Hughes58265892001-10-18 15:13:53 +0000652}
653
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100654void
655printsiginfo_at(struct tcb *tcp, long addr)
656{
657 siginfo_t si;
658 if (!addr) {
659 tprints("NULL");
660 return;
661 }
662 if (syserror(tcp)) {
663 tprintf("%#lx", addr);
664 return;
665 }
666 if (umove(tcp, addr, &si) < 0) {
667 tprints("{???}");
668 return;
669 }
670 printsiginfo(&si, verbose(tcp));
671}
672
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000673int
Denys Vlasenko12014262011-05-30 14:00:14 +0200674sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000675{
676 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000677 tprintsigmask_val("", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000678 }
679 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000680 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000681 return RVAL_HEX | RVAL_STR;
682 }
683 return 0;
684}
685
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000686#ifdef HAVE_SIGACTION
687
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688struct old_sigaction {
Denys Vlasenko86d94842013-02-08 12:59:13 +0100689 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800690#ifdef MIPS
691 unsigned int sa_flags;
692 void (*__sa_handler)(int);
693 /* Kernel treats sa_mask as an array of longs. */
694 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
695#else
Denys Vlasenko86d94842013-02-08 12:59:13 +0100696 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000697 unsigned long sa_mask;
698 unsigned long sa_flags;
699 void (*sa_restorer)(void);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800700#endif /* !MIPS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000701};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000702
Elliott Hughes458b3f22014-02-28 23:21:35 +0000703struct old_sigaction32 {
704 /* sa_handler may be a libc #define, need to use other name: */
705 uint32_t __sa_handler;
706 uint32_t sa_mask;
707 uint32_t sa_flags;
708 uint32_t sa_restorer;
709};
710
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000711static void
712decode_old_sigaction(struct tcb *tcp, long addr)
713{
714 struct old_sigaction sa;
Elliott Hughes458b3f22014-02-28 23:21:35 +0000715 int r;
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000716
717 if (!addr) {
718 tprints("NULL");
719 return;
720 }
721 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
722 tprintf("%#lx", addr);
723 return;
724 }
Elliott Hughes458b3f22014-02-28 23:21:35 +0000725
726#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
727 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
728 struct old_sigaction32 sa32;
729 r = umove(tcp, addr, &sa32);
730 if (r >= 0) {
731 memset(&sa, 0, sizeof(sa));
732 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
733 sa.sa_flags = sa32.sa_flags;
734 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
735 sa.sa_mask = sa32.sa_mask;
736 }
737 } else
738#endif
739 {
740 r = umove(tcp, addr, &sa);
741 }
742 if (r < 0) {
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000743 tprints("{...}");
744 return;
745 }
746
747 /* Architectures using function pointers, like
748 * hppa, may need to manipulate the function pointer
749 * to compute the result of a comparison. However,
750 * the __sa_handler function pointer exists only in
751 * the address space of the traced process, and can't
752 * be manipulated by strace. In order to prevent the
753 * compiler from generating code to manipulate
754 * __sa_handler we cast the function pointers to long. */
755 if ((long)sa.__sa_handler == (long)SIG_ERR)
756 tprints("{SIG_ERR, ");
757 else if ((long)sa.__sa_handler == (long)SIG_DFL)
758 tprints("{SIG_DFL, ");
759 else if ((long)sa.__sa_handler == (long)SIG_IGN)
760 tprints("{SIG_IGN, ");
761 else
762 tprintf("{%#lx, ", (long) sa.__sa_handler);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800763#ifdef MIPS
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000764 tprintsigmask_addr("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800765#else
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000766 tprintsigmask_val("", sa.sa_mask);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -0800767#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000768 tprints(", ");
769 printflags(sigact_flags, sa.sa_flags, "SA_???");
770#ifdef SA_RESTORER
771 if (sa.sa_flags & SA_RESTORER)
772 tprintf(", %p", sa.sa_restorer);
773#endif
774 tprints("}");
775}
776
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000777int
Denys Vlasenko12014262011-05-30 14:00:14 +0200778sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000779{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000780 if (entering(tcp)) {
781 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200782 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000783 decode_old_sigaction(tcp, tcp->u_arg[1]);
784 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000785 } else
Dmitry V. Levinac655a82014-01-07 22:41:30 +0000786 decode_old_sigaction(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000787 return 0;
788}
789
790int
Denys Vlasenko12014262011-05-30 14:00:14 +0200791sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000792{
793 if (entering(tcp)) {
794 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200795 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000796 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +0000797 case (long) SIG_ERR:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200798 tprints("SIG_ERR");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000799 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000800 case (long) SIG_DFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200801 tprints("SIG_DFL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000802 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +0000803 case (long) SIG_IGN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200804 tprints("SIG_IGN");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000805 break;
806 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000807 tprintf("%#lx", tcp->u_arg[1]);
808 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000809 return 0;
810 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000811 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000812 switch (tcp->u_rval) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100813 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000814 tcp->auxstr = "SIG_ERR"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100815 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000816 tcp->auxstr = "SIG_DFL"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100817 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000818 tcp->auxstr = "SIG_IGN"; break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100819 default:
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000820 tcp->auxstr = NULL;
821 }
822 return RVAL_HEX | RVAL_STR;
823 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000824 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000825}
826
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000827#endif /* HAVE_SIGACTION */
828
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000829int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000830sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000831{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000832#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +0000833 if (entering(tcp)) {
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200834 struct arm_sigcontext {
835 unsigned long trap_no;
836 unsigned long error_code;
837 unsigned long oldmask;
838 unsigned long arm_r0;
839 unsigned long arm_r1;
840 unsigned long arm_r2;
841 unsigned long arm_r3;
842 unsigned long arm_r4;
843 unsigned long arm_r5;
844 unsigned long arm_r6;
845 unsigned long arm_r7;
846 unsigned long arm_r8;
847 unsigned long arm_r9;
848 unsigned long arm_r10;
849 unsigned long arm_fp;
850 unsigned long arm_ip;
851 unsigned long arm_sp;
852 unsigned long arm_lr;
853 unsigned long arm_pc;
854 unsigned long arm_cpsr;
855 unsigned long fault_address;
856 };
857 struct arm_ucontext {
858 unsigned long uc_flags;
859 unsigned long uc_link; /* struct ucontext* */
860 /* The next three members comprise stack_t struct: */
861 unsigned long ss_sp; /* void* */
862 unsigned long ss_flags; /* int */
863 unsigned long ss_size; /* size_t */
864 struct arm_sigcontext sc;
865 /* These two members are sigset_t: */
866 unsigned long uc_sigmask[2];
867 /* more fields follow, which we aren't interested in */
868 };
869 struct arm_ucontext uc;
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200870 if (umove(tcp, arm_regs.ARM_sp, &uc) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000871 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000872 /*
873 * Kernel fills out uc.sc.oldmask too when it sets up signal stack,
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200874 * but for sigmask restore, sigreturn syscall uses uc.uc_sigmask instead.
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200875 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000876 tprintsigmask_addr(") (mask ", uc.uc_sigmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000877 }
Roland McGrath0f87c492003-06-03 23:29:04 +0000878#elif defined(S390) || defined(S390X)
Roland McGrath0f87c492003-06-03 23:29:04 +0000879 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200880 long usp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000881 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200882 if (upeek(tcp->pid, PT_GPR15, &usp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000883 return 0;
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100884 if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &sc) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +0000885 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000886 tprintsigmask_addr(") (mask ", sc.oldmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000887 }
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200888#elif defined(I386) || defined(X86_64)
889# if defined(X86_64)
890 if (current_personality == 0) /* 64-bit */
891 return 0;
892# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000893 if (entering(tcp)) {
Denys Vlasenko670b21b2013-07-17 17:26:56 +0200894 struct i386_sigcontext_struct {
895 uint16_t gs, __gsh;
896 uint16_t fs, __fsh;
897 uint16_t es, __esh;
898 uint16_t ds, __dsh;
899 uint32_t edi;
900 uint32_t esi;
901 uint32_t ebp;
902 uint32_t esp;
903 uint32_t ebx;
904 uint32_t edx;
905 uint32_t ecx;
906 uint32_t eax;
907 uint32_t trapno;
908 uint32_t err;
909 uint32_t eip;
910 uint16_t cs, __csh;
911 uint32_t eflags;
912 uint32_t esp_at_signal;
913 uint16_t ss, __ssh;
914 uint32_t i387;
915 uint32_t oldmask;
916 uint32_t cr2;
917 };
918 struct i386_fpstate {
919 uint32_t cw;
920 uint32_t sw;
921 uint32_t tag;
922 uint32_t ipoff;
923 uint32_t cssel;
924 uint32_t dataoff;
925 uint32_t datasel;
926 uint8_t st[8][10]; /* 8*10 bytes: FP regs */
927 uint16_t status;
928 uint16_t magic;
929 uint32_t fxsr_env[6];
930 uint32_t mxcsr;
931 uint32_t reserved;
932 uint8_t stx[8][16]; /* 8*16 bytes: FP regs, each padded to 16 bytes */
933 uint8_t xmm[8][16]; /* 8 XMM regs */
934 uint32_t padding1[44];
935 uint32_t padding2[12]; /* union with struct _fpx_sw_bytes */
936 };
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200937 struct {
938 struct i386_sigcontext_struct sc;
939 struct i386_fpstate fp;
940 uint32_t extramask[1];
941 } signal_stack;
942 /* On i386, sc is followed on stack by struct fpstate
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100943 * and after it an additional u32 extramask[1] which holds
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200944 * upper half of the mask.
Denys Vlasenkob11322f2012-01-10 16:40:35 +0100945 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000946 uint32_t sigmask[2];
Denys Vlasenkob51f3642013-07-16 12:06:25 +0200947 if (umove(tcp, *i386_esp_ptr, &signal_stack) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000949 sigmask[0] = signal_stack.sc.oldmask;
950 sigmask[1] = signal_stack.extramask[0];
951 tprintsigmask_addr(") (mask ", sigmask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000953#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000954 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200955 struct sigcontext sc;
956 long sp;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000957 /* offset of sigcontext in the kernel's sigframe structure: */
958# define SIGFRAME_SC_OFFSET 0x90
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200959 if (upeek(tcp->pid, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000960 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000961 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000962 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000963 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000964 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000965#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +0000966 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200967 long esp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000968 struct sigcontext sc;
Anton Blanchardce6e33b2013-06-26 15:53:33 +0200969
970 esp = ppc_regs.gpr[1];
971
Andreas Schwabedb39342010-02-23 00:18:51 +0100972 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200973#ifdef POWERPC64
974 if (current_personality == 0)
975 esp += 128;
976 else
977 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +0100978#else
979 esp += 64;
980#endif
Roland McGrath0f87c492003-06-03 23:29:04 +0000981 if (umove(tcp, esp, &sc) < 0)
982 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000983 tprintsigmask_val(") (mask ", sc.oldmask);
Roland McGrath0f87c492003-06-03 23:29:04 +0000984 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000985#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200987 long usp;
988 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200989 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +0000991 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +0000993 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000994 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000995#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000996 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +0200997 long fp;
Dmitry V. Levine2de3bd2013-11-12 15:27:38 +0000998 struct sigcontext sc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +0200999 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001000 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001001 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001002 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001003 tprintsigmask_val(") (mask ", sc.sc_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001004 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001005#elif defined(SPARC) || defined(SPARC64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001006 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001007 long i1;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001008 m_siginfo_t si;
Denys Vlasenko48e4c1b2013-02-16 08:23:40 +01001009 i1 = sparc_regs.u_regs[U_REG_O1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001010 if (umove(tcp, i1, &si) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +01001011 perror_msg("sigreturn: umove");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012 return 0;
1013 }
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001014 tprintsigmask_val(") (mask ", si.si_mask);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015 }
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001016#elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001017 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1018 sigreturn. */
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001019 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001020 long sp;
1021 struct ucontext uc;
Denys Vlasenko752e5a02013-06-28 14:35:47 +02001022 if (upeek(tcp->pid, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001023 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001024 /* There are six words followed by a 128-byte siginfo. */
1025 sp = sp + 6 * 4 + 128;
1026 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001027 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001028 tprintsigmask_val(") (mask ", uc.uc_sigmask);
Roland McGrath542c2c62008-05-20 01:11:56 +00001029 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001030#elif defined(MIPS)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001031 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001032 long sp;
1033 struct pt_regs regs;
1034 m_siginfo_t si;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001035 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +01001036 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenko56a52982011-06-09 01:36:29 +02001037 return 0;
1038 }
Roland McGrath576b7842007-11-04 00:00:00 +00001039 sp = regs.regs[29];
1040 if (umove(tcp, sp, &si) < 0)
Denys Vlasenkofacd45b2011-06-09 01:22:10 +02001041 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001042 tprintsigmask_val(") (mask ", si.si_mask);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001043 }
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001044#elif defined(CRISV10) || defined(CRISV32)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001045 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001046 struct sigcontext sc;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001047 long regs[PT_MAX+1];
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001048 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
Denys Vlasenko905e8e02013-02-26 12:30:09 +01001049 perror_msg("sigreturn: PTRACE_GETREGS");
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001050 return 0;
1051 }
1052 if (umove(tcp, regs[PT_USP], &sc) < 0)
1053 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001054 tprintsigmask_val(") (mask ", sc.oldmask);
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001055 }
Chris Metcalfc8c66982009-12-28 10:00:15 -05001056#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -05001057 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001058 struct ucontext uc;
Denys Vlasenko56a52982011-06-09 01:36:29 +02001059
1060 /* offset of ucontext in the kernel's sigframe structure */
Chris Metcalf5c0796f2013-05-21 20:25:22 -04001061# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
Chris Metcalf0b99a8a2013-02-05 17:48:33 +01001062 if (umove(tcp, tile_regs.sp + SIGFRAME_UC_OFFSET, &uc) < 0)
Chris Metcalfc8c66982009-12-28 10:00:15 -05001063 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001064 tprintsigmask_val(") (mask ", uc.uc_sigmask);
Chris Metcalfc8c66982009-12-28 10:00:15 -05001065 }
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001066#elif defined(MICROBLAZE)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001067 /* TODO: Verify that this is correct... */
1068 if (entering(tcp)) {
Denys Vlasenko56a52982011-06-09 01:36:29 +02001069 struct sigcontext sc;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001070 long sp;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001071 /* Read r1, the stack pointer. */
Denys Vlasenko752e5a02013-06-28 14:35:47 +02001072 if (upeek(tcp->pid, 1 * 4, &sp) < 0)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001073 return 0;
1074 if (umove(tcp, sp, &sc) < 0)
1075 return 0;
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001076 tprintsigmask_val(") (mask ", sc.oldmask);
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001077 }
Chris Zankel8f636ed2013-03-25 10:22:07 -07001078#elif defined(XTENSA)
1079 /* Xtensa only has rt_sys_sigreturn */
Vineet Gupta7daacbb2013-08-16 12:47:06 +05301080#elif defined(ARC)
1081 /* ARC syscall ABI only supports rt_sys_sigreturn */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001082#else
Dmitry V. Levinf112d072012-05-15 00:13:59 +00001083# warning No sys_sigreturn() for this architecture
1084# warning (no problem, just a reminder :-)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001085#endif
Dmitry V. Levinf112d072012-05-15 00:13:59 +00001086 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001087}
1088
1089int
Denys Vlasenko12014262011-05-30 14:00:14 +02001090sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001091{
1092 if (exiting(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001093 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094 }
1095 return RVAL_HEX | RVAL_STR;
1096}
1097
1098int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001099sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001100{
1101 if (entering(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001102 tprintsigmask_val("", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001103 }
1104 return 0;
1105}
1106
Denys Vlasenko84703742012-02-25 02:38:52 +01001107#if !defined SS_ONSTACK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001108#define SS_ONSTACK 1
1109#define SS_DISABLE 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001110#endif
1111
Roland McGrathd9f816f2004-09-04 03:39:20 +00001112static const struct xlat sigaltstack_flags[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +00001113 XLAT(SS_ONSTACK),
1114 XLAT(SS_DISABLE),
Dmitry V. Levin59452732014-02-05 02:20:51 +00001115 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001116};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001117
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001118static void
Denys Vlasenko12014262011-05-30 14:00:14 +02001119print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001120{
1121 stack_t ss;
Dmitry V. Levind153bfc2014-02-26 22:29:27 +00001122 int r;
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001123
1124 if (!addr) {
1125 tprints("NULL");
Dmitry V. Levind153bfc2014-02-26 22:29:27 +00001126 return;
1127 }
1128
1129#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1130 if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
1131 struct {
1132 uint32_t ss_sp;
1133 int32_t ss_flags;
1134 uint32_t ss_size;
1135 } ss32;
1136 r = umove(tcp, addr, &ss32);
1137 if (r >= 0) {
1138 memset(&ss, 0, sizeof(ss));
1139 ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
1140 ss.ss_flags = ss32.ss_flags;
1141 ss.ss_size = (unsigned long) ss32.ss_size;
1142 }
1143 } else
1144#endif
1145 {
1146 r = umove(tcp, addr, &ss);
1147 }
1148 if (r < 0) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001149 tprintf("%#lx", addr);
1150 } else {
1151 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1152 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1153 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1154 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001155}
1156
1157int
Denys Vlasenko12014262011-05-30 14:00:14 +02001158sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001159{
1160 if (entering(tcp)) {
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001161 print_stack_t(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001162 }
1163 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001164 tprints(", ");
Dmitry V. Levin338c0692013-02-09 02:03:04 +00001165 print_stack_t(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001166 }
1167 return 0;
1168}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001169
1170#ifdef HAVE_SIGACTION
1171
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001172/* "Old" sigprocmask, which operates with word-sized signal masks */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001173int
Denys Vlasenko12014262011-05-30 14:00:14 +02001174sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001175{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001176# ifdef ALPHA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001177 if (entering(tcp)) {
Mike Frysingerdde045c2012-03-15 00:45:33 -04001178 /*
1179 * Alpha/OSF is different: it doesn't pass in two pointers,
1180 * but rather passes in the new bitmask as an argument and
1181 * then returns the old bitmask. This "works" because we
1182 * only have 64 signals to worry about. If you want more,
1183 * use of the rt_sigprocmask syscall is required.
1184 * Alpha:
1185 * old = osf_sigprocmask(how, new);
1186 * Everyone else:
1187 * ret = sigprocmask(how, &new, &old, ...);
1188 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001189 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001190 tprintsigmask_val(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001191 }
1192 else if (!syserror(tcp)) {
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001193 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001194 return RVAL_HEX | RVAL_STR;
1195 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001196# else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001197 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001198 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001199 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001200 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001201 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001202 }
1203 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001204 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001205 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001206 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001207 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001208 }
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001209# endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001210 return 0;
1211}
1212
1213#endif /* HAVE_SIGACTION */
1214
1215int
Denys Vlasenko12014262011-05-30 14:00:14 +02001216sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001217{
1218 if (entering(tcp)) {
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001219 tprintf("%ld, %s",
1220 widen_to_long(tcp->u_arg[0]),
1221 signame(tcp->u_arg[1])
1222 );
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001223 }
1224 return 0;
1225}
1226
Roland McGrath8ffc3522003-07-09 09:47:49 +00001227int
Denys Vlasenko12014262011-05-30 14:00:14 +02001228sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001229{
1230 if (entering(tcp)) {
1231 tprintf("%ld, %ld, %s",
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +01001232 widen_to_long(tcp->u_arg[0]),
1233 widen_to_long(tcp->u_arg[1]),
1234 signame(tcp->u_arg[2])
1235 );
Roland McGrath8ffc3522003-07-09 09:47:49 +00001236 }
1237 return 0;
1238}
Roland McGrath8ffc3522003-07-09 09:47:49 +00001239
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001240int
Denys Vlasenko12014262011-05-30 14:00:14 +02001241sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001242{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001243 if (exiting(tcp)) {
1244 if (syserror(tcp))
1245 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001246 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001247 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248 }
1249 return 0;
1250}
1251
Denys Vlasenko12014262011-05-30 14:00:14 +02001252int
1253sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001254{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001255 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001256 if (entering(tcp)) {
1257 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001258 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001259 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1260 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001261 }
1262 else {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001263 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001264 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001265 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001266 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001267 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001268 }
1269 return 0;
1270}
1271
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001272/* Structure describing the action to be taken when a signal arrives. */
1273struct new_sigaction
1274{
Denys Vlasenko86d94842013-02-08 12:59:13 +01001275 /* sa_handler may be a libc #define, need to use other name: */
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001276#ifdef MIPS
1277 unsigned int sa_flags;
1278 void (*__sa_handler)(int);
1279#else
Denys Vlasenko86d94842013-02-08 12:59:13 +01001280 void (*__sa_handler)(int);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001281 unsigned long sa_flags;
Denys Vlasenko86d94842013-02-08 12:59:13 +01001282 void (*sa_restorer)(void);
Chris Dearman2b4bb1c2013-12-09 19:58:42 -08001283#endif /* !MIPS */
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001284 /* Kernel treats sa_mask as an array of longs. */
1285 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1286};
1287/* Same for i386-on-x86_64 and similar cases */
1288struct new_sigaction32
1289{
1290 uint32_t __sa_handler;
1291 uint32_t sa_flags;
1292 uint32_t sa_restorer;
1293 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294};
1295
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001296static void
1297decode_new_sigaction(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298{
1299 struct new_sigaction sa;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001300 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001301
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001302 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001303 tprints("NULL");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001304 return;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305 }
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001306 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001307 tprintf("%#lx", addr);
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001308 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001309 }
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001310#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Denys Vlasenko9fd4f962012-03-19 09:36:42 +01001311 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001312 struct new_sigaction32 sa32;
1313 r = umove(tcp, addr, &sa32);
1314 if (r >= 0) {
1315 memset(&sa, 0, sizeof(sa));
1316 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1317 sa.sa_flags = sa32.sa_flags;
1318 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1319 /* Kernel treats sa_mask as an array of longs.
1320 * For 32-bit process, "long" is uint32_t, thus, for example,
1321 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1322 * But for (64-bit) kernel, 32th bit in sa_mask is
1323 * 32th bit in 0th (64-bit) long!
1324 * For little-endian, it's the same.
1325 * For big-endian, we swap 32-bit words.
1326 */
1327 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1328 }
1329 } else
1330#endif
1331 {
1332 r = umove(tcp, addr, &sa);
1333 }
1334 if (r < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001335 tprints("{...}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001336 return;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001337 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001338 /* Architectures using function pointers, like
1339 * hppa, may need to manipulate the function pointer
1340 * to compute the result of a comparison. However,
Denys Vlasenko86d94842013-02-08 12:59:13 +01001341 * the __sa_handler function pointer exists only in
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001342 * the address space of the traced process, and can't
1343 * be manipulated by strace. In order to prevent the
1344 * compiler from generating code to manipulate
Denys Vlasenko86d94842013-02-08 12:59:13 +01001345 * __sa_handler we cast the function pointers to long. */
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001346 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001347 tprints("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001348 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001349 tprints("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001350 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001351 tprints("{SIG_IGN, ");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001352 else
1353 tprintf("{%#lx, ", (long) sa.__sa_handler);
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001354 /*
1355 * Sigset size is in tcp->u_arg[4] (SPARC)
1356 * or in tcp->u_arg[3] (all other),
1357 * but kernel won't handle sys_rt_sigaction
1358 * with wrong sigset size (just returns EINVAL instead).
1359 * We just fetch the right size, which is NSIG / 8.
1360 */
Dmitry V. Levin38593e92014-02-26 16:51:28 +00001361 tprintsigmask_val("", sa.sa_mask);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001362 tprints(", ");
Denys Vlasenko80b73a22013-07-18 10:10:46 +02001363
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001364 printflags(sigact_flags, sa.sa_flags, "SA_???");
1365#ifdef SA_RESTORER
1366 if (sa.sa_flags & SA_RESTORER)
1367 tprintf(", %p", sa.sa_restorer);
1368#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001369 tprints("}");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001370}
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001371
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001372int
1373sys_rt_sigaction(struct tcb *tcp)
1374{
1375 if (entering(tcp)) {
1376 printsignal(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001377 tprints(", ");
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001378 decode_new_sigaction(tcp, tcp->u_arg[1]);
1379 tprints(", ");
1380 } else {
1381 decode_new_sigaction(tcp, tcp->u_arg[2]);
Denys Vlasenko9472a272013-02-12 11:43:46 +01001382#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001383 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1384#elif defined(ALPHA)
1385 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1386#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001387 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001388#endif
Dmitry V. Levinac655a82014-01-07 22:41:30 +00001389 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001390 return 0;
1391}
1392
Denys Vlasenko1d632462009-04-14 12:51:00 +00001393int
1394sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001395{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001396 if (exiting(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001397 /*
1398 * One of the few syscalls where sigset size (arg[1])
1399 * is allowed to be <= NSIG / 8, not strictly ==.
1400 * This allows non-rt sigpending() syscall
1401 * to reuse rt_sigpending() code in kernel.
1402 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001403 if (syserror(tcp))
1404 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001405 else
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001406 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1407 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001408 }
1409 return 0;
1410}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001411
1412int
1413sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001414{
1415 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001416 /* NB: kernel requires arg[1] == NSIG / 8 */
1417 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1418 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001419 }
1420 return 0;
1421}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001422
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001423static void
1424print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1425{
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001426 printsignal(sig);
1427 tprints(", ");
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001428 printsiginfo_at(tcp, uinfo);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001429}
1430
Denys Vlasenko1d632462009-04-14 12:51:00 +00001431int
1432sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433{
1434 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001435 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levin297632b2012-03-13 15:51:13 +00001436 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1437 }
1438 return 0;
1439}
1440
1441int
1442sys_rt_tgsigqueueinfo(struct tcb *tcp)
1443{
1444 if (entering(tcp)) {
1445 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1446 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001447 }
1448 return 0;
1449}
1450
Denys Vlasenko1d632462009-04-14 12:51:00 +00001451int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001452{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001453 /* NB: kernel requires arg[3] == NSIG / 8 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001454 if (entering(tcp)) {
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001455 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001456 tprints(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001457 /* This is the only "return" parameter, */
1458 if (tcp->u_arg[1] != 0)
1459 return 0;
1460 /* ... if it's NULL, can decode all on entry */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001461 tprints("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001462 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001463 else if (tcp->u_arg[1] != 0) {
1464 /* syscall exit, and u_arg[1] wasn't NULL */
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +01001465 printsiginfo_at(tcp, tcp->u_arg[1]);
1466 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001467 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00001468 else {
1469 /* syscall exit, and u_arg[1] was NULL */
1470 return 0;
1471 }
1472 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001473 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001474 return 0;
1475};
1476
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001477int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001478sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001479{
1480 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001481 tprints("<... resuming interrupted call ...>");
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001482 return 0;
1483}
1484
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001485static int
1486do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00001487{
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001488 /* NB: kernel requires arg[2] == NSIG / 8 */
Roland McGrathf46ccd32007-08-02 01:15:59 +00001489 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001490 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001491 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +02001492 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00001493 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001494 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001495 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001496 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1497 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00001498 }
1499 return 0;
1500}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001501
1502int
1503sys_signalfd(struct tcb *tcp)
1504{
1505 return do_signalfd(tcp, -1);
1506}
1507
1508int
1509sys_signalfd4(struct tcb *tcp)
1510{
1511 return do_signalfd(tcp, 3);
1512}