blob: d2e5953d4bd8b671b1737527f9e32711fd3d69e1 [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.
32 *
33 * $Id$
34 */
35
36#include "defs.h"
37
Denys Vlasenko7a862d72009-04-15 13:22:59 +000038#include <stdint.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000039#include <signal.h>
40#include <sys/user.h>
41#include <fcntl.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042
43#ifdef SVR4
44#include <sys/ucontext.h>
45#endif /* SVR4 */
46
Wichert Akkerman36915a11999-07-13 15:45:02 +000047#ifdef HAVE_SYS_REG_H
48# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000049#ifndef PTRACE_PEEKUSR
Wichert Akkerman36915a11999-07-13 15:45:02 +000050# define PTRACE_PEEKUSR PTRACE_PEEKUSER
Wichert Akkerman15dea971999-10-06 13:06:34 +000051#endif
52#ifndef PTRACE_POKEUSR
Wichert Akkerman36915a11999-07-13 15:45:02 +000053# define PTRACE_POKEUSR PTRACE_POKEUSER
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000054#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000055#elif defined(HAVE_LINUX_PTRACE_H)
56#undef PTRACE_SYSCALL
Roland McGrathb0acdfd2004-03-01 21:31:02 +000057# ifdef HAVE_STRUCT_IA64_FPREG
58# define ia64_fpreg XXX_ia64_fpreg
59# endif
60# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
61# define pt_all_user_regs XXX_pt_all_user_regs
62# endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000063#include <linux/ptrace.h>
Roland McGrathb0acdfd2004-03-01 21:31:02 +000064# undef ia64_fpreg
65# undef pt_all_user_regs
Wichert Akkerman15dea971999-10-06 13:06:34 +000066#endif
Wichert Akkerman36915a11999-07-13 15:45:02 +000067
Wichert Akkermanfaf72222000-02-19 23:59:03 +000068
Wichert Akkerman36915a11999-07-13 15:45:02 +000069#ifdef LINUX
70
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000071#ifdef IA64
72# include <asm/ptrace_offsets.h>
73#endif /* !IA64 */
74
Roland McGrath6d1a65c2004-07-12 07:44:08 +000075#if defined (LINUX) && defined (SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000076# undef PTRACE_GETREGS
77# define PTRACE_GETREGS PTRACE_GETREGS64
78# undef PTRACE_SETREGS
79# define PTRACE_SETREGS PTRACE_SETREGS64
80#endif /* LINUX && SPARC64 */
Roland McGrath30ff45e2003-01-30 20:15:23 +000081
Mike Frysinger8566c502009-10-12 11:05:14 -040082#if defined (SPARC) || defined (SPARC64) || defined (MIPS)
Roland McGrath576b7842007-11-04 00:00:00 +000083typedef struct {
84 struct pt_regs si_regs;
85 int si_mask;
86} m_siginfo_t;
Roland McGrath30ff45e2003-01-30 20:15:23 +000087#elif defined HAVE_ASM_SIGCONTEXT_H
88#if !defined(IA64) && !defined(X86_64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000089#include <asm/sigcontext.h>
Roland McGrath30ff45e2003-01-30 20:15:23 +000090#endif /* !IA64 && !X86_64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091#else /* !HAVE_ASM_SIGCONTEXT_H */
Roland McGrath0cbb4e42008-05-20 01:26:21 +000092#if defined I386 && !defined HAVE_STRUCT_SIGCONTEXT_STRUCT
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093struct sigcontext_struct {
94 unsigned short gs, __gsh;
95 unsigned short fs, __fsh;
96 unsigned short es, __esh;
97 unsigned short ds, __dsh;
98 unsigned long edi;
99 unsigned long esi;
100 unsigned long ebp;
101 unsigned long esp;
102 unsigned long ebx;
103 unsigned long edx;
104 unsigned long ecx;
105 unsigned long eax;
106 unsigned long trapno;
107 unsigned long err;
108 unsigned long eip;
109 unsigned short cs, __csh;
110 unsigned long eflags;
111 unsigned long esp_at_signal;
112 unsigned short ss, __ssh;
113 unsigned long i387;
114 unsigned long oldmask;
115 unsigned long cr2;
116};
117#else /* !I386 */
Roland McGrath587c7b52009-02-11 03:03:28 +0000118#if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000119struct sigcontext
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000120{
121 unsigned long sc_mask;
122 unsigned long sc_usp;
123 unsigned long sc_d0;
124 unsigned long sc_d1;
125 unsigned long sc_a0;
126 unsigned long sc_a1;
127 unsigned short sc_sr;
128 unsigned long sc_pc;
129 unsigned short sc_formatvec;
130};
131#endif /* M68K */
132#endif /* !I386 */
133#endif /* !HAVE_ASM_SIGCONTEXT_H */
134#ifndef NSIG
135#define NSIG 32
136#endif
137#ifdef ARM
138#undef NSIG
139#define NSIG 32
140#endif
141#endif /* LINUX */
142
Roland McGrathee36ce12004-09-04 03:53:10 +0000143const char *const signalent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000144#include "signalent.h"
145};
Roland McGrathee36ce12004-09-04 03:53:10 +0000146const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000147
148#if SUPPORTED_PERSONALITIES >= 2
Roland McGrathee36ce12004-09-04 03:53:10 +0000149const char *const signalent1[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150#include "signalent1.h"
151};
Roland McGrathee36ce12004-09-04 03:53:10 +0000152const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153#endif /* SUPPORTED_PERSONALITIES >= 2 */
154
155#if SUPPORTED_PERSONALITIES >= 3
Roland McGrathee36ce12004-09-04 03:53:10 +0000156const char *const signalent2[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157#include "signalent2.h"
158};
Roland McGrathee36ce12004-09-04 03:53:10 +0000159const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160#endif /* SUPPORTED_PERSONALITIES >= 3 */
161
Roland McGrathee36ce12004-09-04 03:53:10 +0000162const char *const *signalent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163int nsignals;
164
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000165#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166
Roland McGrathd9f816f2004-09-04 03:39:20 +0000167static const struct xlat sigvec_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000168 { SV_ONSTACK, "SV_ONSTACK" },
169 { SV_INTERRUPT, "SV_INTERRUPT" },
170 { SV_RESETHAND, "SV_RESETHAND" },
171 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
172 { 0, NULL },
173};
174
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000175#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176
177#ifdef HAVE_SIGACTION
178
Roland McGrath063ae2d2005-02-02 04:16:54 +0000179#if defined LINUX && (defined I386 || defined X86_64)
Roland McGrath2638cb42002-12-15 23:58:41 +0000180/* The libc headers do not define this constant since it should only be
181 used by the implementation. So wwe define it here. */
182# ifndef SA_RESTORER
183# define SA_RESTORER 0x04000000
184# endif
185#endif
186
Roland McGrathd9f816f2004-09-04 03:39:20 +0000187static const struct xlat sigact_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000188#ifdef SA_RESTORER
189 { SA_RESTORER, "SA_RESTORER" },
190#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191#ifdef SA_STACK
192 { SA_STACK, "SA_STACK" },
193#endif
194#ifdef SA_RESTART
195 { SA_RESTART, "SA_RESTART" },
196#endif
197#ifdef SA_INTERRUPT
198 { SA_INTERRUPT, "SA_INTERRUPT" },
199#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000200#ifdef SA_NODEFER
201 { SA_NODEFER, "SA_NODEFER" },
202#endif
203#if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204 { SA_NOMASK, "SA_NOMASK" },
205#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000206#ifdef SA_RESETHAND
207 { SA_RESETHAND, "SA_RESETHAND" },
208#endif
209#if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000210 { SA_ONESHOT, "SA_ONESHOT" },
211#endif
212#ifdef SA_SIGINFO
213 { SA_SIGINFO, "SA_SIGINFO" },
214#endif
215#ifdef SA_RESETHAND
216 { SA_RESETHAND, "SA_RESETHAND" },
217#endif
218#ifdef SA_ONSTACK
219 { SA_ONSTACK, "SA_ONSTACK" },
220#endif
221#ifdef SA_NODEFER
222 { SA_NODEFER, "SA_NODEFER" },
223#endif
224#ifdef SA_NOCLDSTOP
225 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
226#endif
227#ifdef SA_NOCLDWAIT
228 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
229#endif
230#ifdef _SA_BSDCALL
231 { _SA_BSDCALL, "_SA_BSDCALL" },
232#endif
Chris Metcalfc8c66982009-12-28 10:00:15 -0500233#ifdef SA_NOPTRACE
234 { SA_NOPTRACE, "SA_NOPTRACE" },
235#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236 { 0, NULL },
237};
238
Roland McGrathd9f816f2004-09-04 03:39:20 +0000239static const struct xlat sigprocmaskcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000240 { SIG_BLOCK, "SIG_BLOCK" },
241 { SIG_UNBLOCK, "SIG_UNBLOCK" },
242 { SIG_SETMASK, "SIG_SETMASK" },
243#ifdef SIG_SETMASK32
244 { SIG_SETMASK32,"SIG_SETMASK32" },
245#endif
246 { 0, NULL },
247};
248
249#endif /* HAVE_SIGACTION */
250
Nate Sammonsce780fc1999-03-29 23:23:13 +0000251/* Anonymous realtime signals. */
252/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
253 constant. This is what we want. Otherwise, just use SIGRTMIN. */
254#ifdef SIGRTMIN
255#ifndef __SIGRTMIN
256#define __SIGRTMIN SIGRTMIN
257#define __SIGRTMAX SIGRTMAX /* likewise */
258#endif
259#endif
260
Roland McGrathee36ce12004-09-04 03:53:10 +0000261const char *
Nate Sammonsce780fc1999-03-29 23:23:13 +0000262signame(sig)
263int sig;
264{
265 static char buf[30];
Roland McGrathad81dce2005-05-09 07:40:30 +0000266 if (sig >= 0 && sig < nsignals) {
Nate Sammonsce780fc1999-03-29 23:23:13 +0000267 return signalent[sig];
268#ifdef SIGRTMIN
Nate Sammons3080aa41999-03-30 00:16:41 +0000269 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000270 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000271 return buf;
272#endif /* SIGRTMIN */
273 } else {
274 sprintf(buf, "%d", sig);
275 return buf;
276 }
277}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000278
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000279#ifndef UNIXWARE
Nate Sammons4a121431999-04-06 01:19:39 +0000280static void
281long_to_sigset(l, s)
282long l;
283sigset_t *s;
284{
285 sigemptyset(s);
286 *(long *)s = l;
287}
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000288#endif
Nate Sammons4a121431999-04-06 01:19:39 +0000289
290static int
Denys Vlasenko12014262011-05-30 14:00:14 +0200291copy_sigset_len(struct tcb *tcp, long addr, sigset_t *s, int len)
Nate Sammons4a121431999-04-06 01:19:39 +0000292{
293 if (len > sizeof(*s))
294 len = sizeof(*s);
295 sigemptyset(s);
296 if (umoven(tcp, addr, len, (char *)s) < 0)
297 return -1;
298 return 0;
299}
300
301#ifdef LINUX
302/* Original sigset is unsigned long */
303#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
304#else
305#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
306#endif
307
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000308static const char *
309sprintsigmask(const char *str, sigset_t *mask, int rt)
310/* set might include realtime sigs */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000311{
312 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000313 int maxsigs;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000314 const char *format;
315 char *s;
Roland McGratha39c5a12002-12-17 05:10:37 +0000316 static char outstr[8 * sizeof(sigset_t) * 8];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000318 strcpy(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319 s = outstr + strlen(outstr);
320 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000321 maxsigs = nsignals;
322#ifdef __SIGRTMAX
323 if (rt)
324 maxsigs = __SIGRTMAX; /* instead */
325#endif
326 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000327 if (sigismember(mask, i) == 1)
328 nsigs++;
329 }
330 if (nsigs >= nsignals * 2 / 3) {
331 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000332 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000333 switch (sigismember(mask, i)) {
334 case 1:
335 sigdelset(mask, i);
336 break;
337 case 0:
338 sigaddset(mask, i);
339 break;
340 }
341 }
342 }
343 format = "%s";
344 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000345 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000346 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000347 /* real-time signals on solaris don't have
348 * signalent entries
349 */
350 if (i < nsignals) {
351 sprintf(s, format, signalent[i] + 3);
352 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000353#ifdef SIGRTMIN
354 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
355 char tsig[40];
356 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
357 sprintf(s, format, tsig);
358 }
359#endif /* SIGRTMIN */
John Hughesbdf48f52001-03-06 15:08:09 +0000360 else {
361 char tsig[32];
362 sprintf(tsig, "%u", i);
363 sprintf(s, format, tsig);
364 }
365 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366 format = " %s";
367 }
368 }
369 *s++ = ']';
370 *s = '\0';
371 return outstr;
372}
373
374static void
Nate Sammons4a121431999-04-06 01:19:39 +0000375printsigmask(mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000377int rt;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378{
Nate Sammons4a121431999-04-06 01:19:39 +0000379 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380}
381
382void
383printsignal(nr)
384int nr;
385{
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +0000386 tprintf("%s", signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387}
388
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000389void
390print_sigset(struct tcb *tcp, long addr, int rt)
391{
392 sigset_t ss;
393
394 if (!addr)
395 tprintf("NULL");
396 else if (copy_sigset(tcp, addr, &ss) < 0)
397 tprintf("%#lx", addr);
398 else
399 printsigmask(&ss, rt);
400}
401
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000402#ifdef LINUX
403
John Hughes58265892001-10-18 15:13:53 +0000404#ifndef ILL_ILLOPC
405#define ILL_ILLOPC 1 /* illegal opcode */
406#define ILL_ILLOPN 2 /* illegal operand */
407#define ILL_ILLADR 3 /* illegal addressing mode */
408#define ILL_ILLTRP 4 /* illegal trap */
409#define ILL_PRVOPC 5 /* privileged opcode */
410#define ILL_PRVREG 6 /* privileged register */
411#define ILL_COPROC 7 /* coprocessor error */
412#define ILL_BADSTK 8 /* internal stack error */
413#define FPE_INTDIV 1 /* integer divide by zero */
414#define FPE_INTOVF 2 /* integer overflow */
415#define FPE_FLTDIV 3 /* floating point divide by zero */
416#define FPE_FLTOVF 4 /* floating point overflow */
417#define FPE_FLTUND 5 /* floating point underflow */
418#define FPE_FLTRES 6 /* floating point inexact result */
419#define FPE_FLTINV 7 /* floating point invalid operation */
420#define FPE_FLTSUB 8 /* subscript out of range */
421#define SEGV_MAPERR 1 /* address not mapped to object */
422#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
423#define BUS_ADRALN 1 /* invalid address alignment */
424#define BUS_ADRERR 2 /* non-existant physical address */
425#define BUS_OBJERR 3 /* object specific hardware error */
426#define TRAP_BRKPT 1 /* process breakpoint */
427#define TRAP_TRACE 2 /* process trace trap */
428#define CLD_EXITED 1 /* child has exited */
429#define CLD_KILLED 2 /* child was killed */
430#define CLD_DUMPED 3 /* child terminated abnormally */
431#define CLD_TRAPPED 4 /* traced child has trapped */
432#define CLD_STOPPED 5 /* child has stopped */
433#define CLD_CONTINUED 6 /* stopped child has continued */
434#define POLL_IN 1 /* data input available */
435#define POLL_OUT 2 /* output buffers available */
436#define POLL_MSG 3 /* input message available */
437#define POLL_ERR 4 /* i/o error */
438#define POLL_PRI 5 /* high priority input available */
439#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000440#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000441#define SI_USER 0 /* sent by kill, sigsend, raise */
442#define SI_QUEUE -1 /* sent by sigqueue */
443#define SI_TIMER -2 /* sent by timer expiration */
444#define SI_MESGQ -3 /* sent by real time mesq state change */
445#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000446#define SI_SIGIO -5 /* sent by SIGIO */
447#define SI_TKILL -6 /* sent by tkill */
448#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
449
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000450#define SI_FROMUSER(sip) ((sip)->si_code <= 0)
451
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000452#endif /* LINUX */
John Hughes58265892001-10-18 15:13:53 +0000453
454#if __GLIBC_MINOR__ < 1
455/* Type for data associated with a signal. */
456typedef union sigval
457{
458 int sival_int;
459 void *sival_ptr;
460} sigval_t;
461
462# define __SI_MAX_SIZE 128
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200463# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof(int)) - 3)
John Hughes58265892001-10-18 15:13:53 +0000464
465typedef struct siginfo
466{
467 int si_signo; /* Signal number. */
468 int si_errno; /* If non-zero, an errno value associated with
469 this signal, as defined in <errno.h>. */
470 int si_code; /* Signal code. */
471
472 union
473 {
474 int _pad[__SI_PAD_SIZE];
475
476 /* kill(). */
477 struct
478 {
479 __pid_t si_pid; /* Sending process ID. */
480 __uid_t si_uid; /* Real user ID of sending process. */
481 } _kill;
482
483 /* POSIX.1b timers. */
484 struct
485 {
486 unsigned int _timer1;
487 unsigned int _timer2;
488 } _timer;
489
490 /* POSIX.1b signals. */
491 struct
492 {
493 __pid_t si_pid; /* Sending process ID. */
494 __uid_t si_uid; /* Real user ID of sending process. */
495 sigval_t si_sigval; /* Signal value. */
496 } _rt;
497
498 /* SIGCHLD. */
499 struct
500 {
501 __pid_t si_pid; /* Which child. */
502 int si_status; /* Exit value or signal. */
503 __clock_t si_utime;
504 __clock_t si_stime;
505 } _sigchld;
506
507 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
508 struct
509 {
510 void *si_addr; /* Faulting insn/memory ref. */
511 } _sigfault;
512
513 /* SIGPOLL. */
514 struct
515 {
516 int si_band; /* Band event for SIGPOLL. */
517 int si_fd;
518 } _sigpoll;
519 } _sifields;
520} siginfo_t;
521
522#define si_pid _sifields._kill.si_pid
523#define si_uid _sifields._kill.si_uid
524#define si_status _sifields._sigchld.si_status
525#define si_utime _sifields._sigchld.si_utime
526#define si_stime _sifields._sigchld.si_stime
527#define si_value _sifields._rt.si_sigval
528#define si_int _sifields._rt.si_sigval.sival_int
529#define si_ptr _sifields._rt.si_sigval.sival_ptr
530#define si_addr _sifields._sigfault.si_addr
531#define si_band _sifields._sigpoll.si_band
532#define si_fd _sifields._sigpoll.si_fd
533
534#endif
535
536#endif
537
538#if defined (SVR4) || defined (LINUX)
539
Roland McGrathd9f816f2004-09-04 03:39:20 +0000540static const struct xlat siginfo_codes[] = {
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000541#ifdef SI_KERNEL
542 { SI_KERNEL, "SI_KERNEL" },
John Hughes58265892001-10-18 15:13:53 +0000543#endif
544#ifdef SI_USER
545 { SI_USER, "SI_USER" },
546#endif
John Hughes58265892001-10-18 15:13:53 +0000547#ifdef SI_QUEUE
548 { SI_QUEUE, "SI_QUEUE" },
549#endif
550#ifdef SI_TIMER
551 { SI_TIMER, "SI_TIMER" },
552#endif
John Hughes58265892001-10-18 15:13:53 +0000553#ifdef SI_MESGQ
554 { SI_MESGQ, "SI_MESGQ" },
555#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000556#ifdef SI_ASYNCIO
557 { SI_ASYNCIO, "SI_ASYNCIO" },
558#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000559#ifdef SI_SIGIO
560 { SI_SIGIO, "SI_SIGIO" },
561#endif
562#ifdef SI_TKILL
563 { SI_TKILL, "SI_TKILL" },
564#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000565#ifdef SI_ASYNCNL
566 { SI_ASYNCNL, "SI_ASYNCNL" },
567#endif
568#ifdef SI_NOINFO
569 { SI_NOINFO, "SI_NOINFO" },
570#endif
571#ifdef SI_LWP
572 { SI_LWP, "SI_LWP" },
573#endif
John Hughes58265892001-10-18 15:13:53 +0000574 { 0, NULL },
575};
576
Roland McGrathd9f816f2004-09-04 03:39:20 +0000577static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000578 { ILL_ILLOPC, "ILL_ILLOPC" },
579 { ILL_ILLOPN, "ILL_ILLOPN" },
580 { ILL_ILLADR, "ILL_ILLADR" },
581 { ILL_ILLTRP, "ILL_ILLTRP" },
582 { ILL_PRVOPC, "ILL_PRVOPC" },
583 { ILL_PRVREG, "ILL_PRVREG" },
584 { ILL_COPROC, "ILL_COPROC" },
585 { ILL_BADSTK, "ILL_BADSTK" },
586 { 0, NULL },
587};
588
Roland McGrathd9f816f2004-09-04 03:39:20 +0000589static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000590 { FPE_INTDIV, "FPE_INTDIV" },
591 { FPE_INTOVF, "FPE_INTOVF" },
592 { FPE_FLTDIV, "FPE_FLTDIV" },
593 { FPE_FLTOVF, "FPE_FLTOVF" },
594 { FPE_FLTUND, "FPE_FLTUND" },
595 { FPE_FLTRES, "FPE_FLTRES" },
596 { FPE_FLTINV, "FPE_FLTINV" },
597 { FPE_FLTSUB, "FPE_FLTSUB" },
598 { 0, NULL },
599};
600
Roland McGrathd9f816f2004-09-04 03:39:20 +0000601static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000602 { TRAP_BRKPT, "TRAP_BRKPT" },
603 { TRAP_TRACE, "TRAP_TRACE" },
604 { 0, NULL },
605};
606
Roland McGrathd9f816f2004-09-04 03:39:20 +0000607static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000608 { CLD_EXITED, "CLD_EXITED" },
609 { CLD_KILLED, "CLD_KILLED" },
610 { CLD_DUMPED, "CLD_DUMPED" },
611 { CLD_TRAPPED, "CLD_TRAPPED" },
612 { CLD_STOPPED, "CLD_STOPPED" },
613 { CLD_CONTINUED,"CLD_CONTINUED" },
614 { 0, NULL },
615};
616
Roland McGrathd9f816f2004-09-04 03:39:20 +0000617static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000618 { POLL_IN, "POLL_IN" },
619 { POLL_OUT, "POLL_OUT" },
620 { POLL_MSG, "POLL_MSG" },
621 { POLL_ERR, "POLL_ERR" },
622 { POLL_PRI, "POLL_PRI" },
623 { POLL_HUP, "POLL_HUP" },
624 { 0, NULL },
625};
626
Roland McGrathd9f816f2004-09-04 03:39:20 +0000627static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000628#ifdef PROF_SIG
629 { PROF_SIG, "PROF_SIG" },
630#endif
631 { 0, NULL },
632};
633
634#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000635static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000636#ifdef EMT_TAGOVF
637 { EMT_TAGOVF, "EMT_TAGOVF" },
638#endif
639 { 0, NULL },
640};
641#endif
642
Roland McGrathd9f816f2004-09-04 03:39:20 +0000643static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000644 { SEGV_MAPERR, "SEGV_MAPERR" },
645 { SEGV_ACCERR, "SEGV_ACCERR" },
646 { 0, NULL },
647};
648
Roland McGrathd9f816f2004-09-04 03:39:20 +0000649static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000650 { BUS_ADRALN, "BUS_ADRALN" },
651 { BUS_ADRERR, "BUS_ADRERR" },
652 { BUS_OBJERR, "BUS_OBJERR" },
653 { 0, NULL },
654};
655
656void
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000657printsiginfo(siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000658{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000659 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000660
661 if (sip->si_signo == 0) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200662 tprintf("{}");
John Hughes58265892001-10-18 15:13:53 +0000663 return;
664 }
665 tprintf("{si_signo=");
666 printsignal(sip->si_signo);
667 code = xlookup(siginfo_codes, sip->si_code);
668 if (!code) {
669 switch (sip->si_signo) {
670 case SIGTRAP:
671 code = xlookup(sigtrap_codes, sip->si_code);
672 break;
673 case SIGCHLD:
674 code = xlookup(sigchld_codes, sip->si_code);
675 break;
676 case SIGPOLL:
677 code = xlookup(sigpoll_codes, sip->si_code);
678 break;
679 case SIGPROF:
680 code = xlookup(sigprof_codes, sip->si_code);
681 break;
682 case SIGILL:
683 code = xlookup(sigill_codes, sip->si_code);
684 break;
685#ifdef SIGEMT
686 case SIGEMT:
687 code = xlookup(sigemt_codes, sip->si_code);
688 break;
689#endif
690 case SIGFPE:
691 code = xlookup(sigfpe_codes, sip->si_code);
692 break;
693 case SIGSEGV:
694 code = xlookup(sigsegv_codes, sip->si_code);
695 break;
696 case SIGBUS:
697 code = xlookup(sigbus_codes, sip->si_code);
698 break;
699 }
700 }
701 if (code)
702 tprintf(", si_code=%s", code);
703 else
704 tprintf(", si_code=%#x", sip->si_code);
705#ifdef SI_NOINFO
706 if (sip->si_code != SI_NOINFO)
707#endif
708 {
709 if (sip->si_errno) {
710 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
711 tprintf(", si_errno=%d", sip->si_errno);
712 else
713 tprintf(", si_errno=%s",
714 errnoent[sip->si_errno]);
715 }
716#ifdef SI_FROMUSER
717 if (SI_FROMUSER(sip)) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000718 tprintf(", si_pid=%lu, si_uid=%lu",
719 (unsigned long) sip->si_pid,
720 (unsigned long) sip->si_uid);
John Hughes58265892001-10-18 15:13:53 +0000721 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000722#ifdef SI_USER
723 case SI_USER:
724 break;
725#endif
726#ifdef SI_TKILL
727 case SI_TKILL:
728 break;
729#endif
John Hughes58265892001-10-18 15:13:53 +0000730#ifdef SI_TIMER
731 case SI_TIMER:
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000732 tprintf(", si_value=%d", sip->si_int);
John Hughes58265892001-10-18 15:13:53 +0000733 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000734#endif
735#ifdef LINUX
736 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000737 if (!sip->si_ptr)
738 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000739 if (!verbose)
740 tprintf(", ...");
741 else
742 tprintf(", si_value={int=%u, ptr=%#lx}",
743 sip->si_int,
744 (unsigned long) sip->si_ptr);
745 break;
746#endif
John Hughes58265892001-10-18 15:13:53 +0000747 }
John Hughes58265892001-10-18 15:13:53 +0000748 }
749 else
750#endif /* SI_FROMUSER */
751 {
752 switch (sip->si_signo) {
753 case SIGCHLD:
754 tprintf(", si_pid=%ld, si_status=",
755 (long) sip->si_pid);
756 if (sip->si_code == CLD_EXITED)
757 tprintf("%d", sip->si_status);
758 else
759 printsignal(sip->si_status);
760#if LINUX
761 if (!verbose)
762 tprintf(", ...");
763 else
764 tprintf(", si_utime=%lu, si_stime=%lu",
765 sip->si_utime,
766 sip->si_stime);
767#endif
768 break;
769 case SIGILL: case SIGFPE:
770 case SIGSEGV: case SIGBUS:
771 tprintf(", si_addr=%#lx",
772 (unsigned long) sip->si_addr);
773 break;
774 case SIGPOLL:
775 switch (sip->si_code) {
776 case POLL_IN: case POLL_OUT: case POLL_MSG:
777 tprintf(", si_band=%ld",
778 (long) sip->si_band);
779 break;
780 }
781 break;
782#ifdef LINUX
783 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000784 if (sip->si_pid || sip->si_uid)
785 tprintf(", si_pid=%lu, si_uid=%lu",
786 (unsigned long) sip->si_pid,
787 (unsigned long) sip->si_uid);
788 if (!sip->si_ptr)
789 break;
John Hughes58265892001-10-18 15:13:53 +0000790 if (!verbose)
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000791 tprintf(", ...");
John Hughes58265892001-10-18 15:13:53 +0000792 else {
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000793 tprintf(", si_value={int=%u, ptr=%#lx}",
John Hughes58265892001-10-18 15:13:53 +0000794 sip->si_int,
795 (unsigned long) sip->si_ptr);
796 }
797#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000798
John Hughes58265892001-10-18 15:13:53 +0000799 }
800 }
801 }
802 tprintf("}");
803}
804
805#endif /* SVR4 || LINUX */
806
807#ifdef LINUX
808
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000809static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000810parse_sigset_t(const char *str, sigset_t *set)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000811{
Roland McGrathc38feca2003-10-01 07:50:28 +0000812 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000813 unsigned int digit;
814 int i;
815
816 sigemptyset(set);
817
Roland McGrathc38feca2003-10-01 07:50:28 +0000818 p = strchr(str, '\n');
819 if (p == NULL)
820 p = strchr(str, '\0');
821 for (i = 0; p-- > str; i += 4) {
822 if (*p >= '0' && *p <= '9')
823 digit = *p - '0';
824 else if (*p >= 'a' && *p <= 'f')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000825 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000826 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000827 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000828 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000829 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000830 if (digit & 1)
831 sigaddset(set, i + 1);
832 if (digit & 2)
833 sigaddset(set, i + 2);
834 if (digit & 4)
835 sigaddset(set, i + 3);
836 if (digit & 8)
837 sigaddset(set, i + 4);
838 }
839}
840
841#endif
842
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000843/*
844 * Check process TCP for the disposition of signal SIG.
845 * Return 1 if the process would somehow manage to survive signal SIG,
846 * else return 0. This routine will never be called with SIGKILL.
847 */
848int
Denys Vlasenko12014262011-05-30 14:00:14 +0200849sigishandled(struct tcb *tcp, int sig)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000850{
851#ifdef LINUX
852 int sfd;
853 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000854 char buf[2048];
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000855 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000856 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000857 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000858#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000859#ifdef SVR4
860 /*
861 * Since procfs doesn't interfere with wait I think it is safe
862 * to punt on this question. If not, the information is there.
863 */
864 return 1;
865#else /* !SVR4 */
866 switch (sig) {
867 case SIGCONT:
868 case SIGSTOP:
869 case SIGTSTP:
870 case SIGTTIN:
871 case SIGTTOU:
872 case SIGCHLD:
873 case SIGIO:
874#if defined(SIGURG) && SIGURG != SIGIO
875 case SIGURG:
876#endif
877 case SIGWINCH:
878 /* Gloria Gaynor says ... */
879 return 1;
880 default:
881 break;
882 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000883#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000884#ifdef LINUX
885
886 /* This is incredibly costly but it's worth it. */
887 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
888 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
889 doesn't handle real-time signals). */
890 sprintf(sname, "/proc/%d/status", tcp->pid);
891 if ((sfd = open(sname, O_RDONLY)) == -1) {
892 perror(sname);
893 return 1;
894 }
895 i = read(sfd, buf, sizeof(buf));
896 buf[i] = '\0';
897 close(sfd);
898 /*
899 * Skip the extraneous fields. We need to skip
900 * command name has any spaces in it. So be it.
901 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000902 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000903 if (!s)
904 {
905 fprintf(stderr, "/proc/pid/status format error\n");
906 return 1;
907 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000908 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000909
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000910 s = strstr(buf, "SigCgt:\t");
911 if (!s)
912 {
913 fprintf(stderr, "/proc/pid/status format error\n");
914 return 1;
915 }
916 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000917
918#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000919 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
920 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000921#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000922 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000923 return 1;
924#endif /* LINUX */
925
926#ifdef SUNOS4
927 void (*u_signal)();
928
Denys Vlasenko932fc7d2008-12-16 18:18:40 +0000929 if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal),
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000930 (long *) &u_signal) < 0) {
931 return 0;
932 }
933 if (u_signal != SIG_DFL)
934 return 1;
935#endif /* SUNOS4 */
936
937 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000938}
939
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000940#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000941
942int
Denys Vlasenko12014262011-05-30 14:00:14 +0200943sys_sigvec(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944{
945 struct sigvec sv;
946 long addr;
947
948 if (entering(tcp)) {
949 printsignal(tcp->u_arg[0]);
950 tprintf(", ");
951 addr = tcp->u_arg[1];
952 } else {
953 addr = tcp->u_arg[2];
954 }
955 if (addr == 0)
956 tprintf("NULL");
957 else if (!verbose(tcp))
958 tprintf("%#lx", addr);
959 else if (umove(tcp, addr, &sv) < 0)
960 tprintf("{...}");
961 else {
962 switch ((int) sv.sv_handler) {
963 case (int) SIG_ERR:
964 tprintf("{SIG_ERR}");
965 break;
966 case (int) SIG_DFL:
967 tprintf("{SIG_DFL}");
968 break;
969 case (int) SIG_IGN:
970 if (tcp->u_arg[0] == SIGTRAP) {
971 tcp->flags |= TCB_SIGTRAPPED;
972 kill(tcp->pid, SIGSTOP);
973 }
974 tprintf("{SIG_IGN}");
975 break;
976 case (int) SIG_HOLD:
977 if (tcp->u_arg[0] == SIGTRAP) {
978 tcp->flags |= TCB_SIGTRAPPED;
979 kill(tcp->pid, SIGSTOP);
980 }
981 tprintf("SIG_HOLD");
982 break;
983 default:
984 if (tcp->u_arg[0] == SIGTRAP) {
985 tcp->flags |= TCB_SIGTRAPPED;
986 kill(tcp->pid, SIGSTOP);
987 }
988 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000989 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000991 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992 tprintf("}");
993 }
994 }
995 if (entering(tcp))
996 tprintf(", ");
997 return 0;
998}
999
1000int
Denys Vlasenko12014262011-05-30 14:00:14 +02001001sys_sigpause(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001002{
1003 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +00001004 sigset_t sigm;
1005 long_to_sigset(tcp->u_arg[0], &sigm);
1006 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001007 }
1008 return 0;
1009}
1010
1011int
Denys Vlasenko12014262011-05-30 14:00:14 +02001012sys_sigstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001013{
1014 struct sigstack ss;
1015 long addr;
1016
1017 if (entering(tcp))
1018 addr = tcp->u_arg[0];
1019 else
1020 addr = tcp->u_arg[1];
1021 if (addr == 0)
1022 tprintf("NULL");
1023 else if (umove(tcp, addr, &ss) < 0)
1024 tprintf("%#lx", addr);
1025 else {
1026 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1027 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1028 }
1029 if (entering(tcp))
1030 tprintf(", ");
1031 return 0;
1032}
1033
1034int
Denys Vlasenko12014262011-05-30 14:00:14 +02001035sys_sigcleanup(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001036{
1037 return 0;
1038}
1039
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001040#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041
1042#ifndef SVR4
1043
1044int
Denys Vlasenko12014262011-05-30 14:00:14 +02001045sys_sigsetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001046{
1047 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001048 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001049 long_to_sigset(tcp->u_arg[0], &sigm);
1050 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001051#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1053 /* Mark attempt to block SIGTRAP */
1054 tcp->flags |= TCB_SIGTRAPPED;
1055 /* Send unblockable signal */
1056 kill(tcp->pid, SIGSTOP);
1057 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001058#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001059 }
1060 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001061 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001062 long_to_sigset(tcp->u_rval, &sigm);
1063 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001064
1065 return RVAL_HEX | RVAL_STR;
1066 }
1067 return 0;
1068}
1069
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001070#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071int
Denys Vlasenko12014262011-05-30 14:00:14 +02001072sys_sigblock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001073{
1074 return sys_sigsetmask(tcp);
1075}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001076#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077
1078#endif /* !SVR4 */
1079
1080#ifdef HAVE_SIGACTION
1081
1082#ifdef LINUX
1083struct old_sigaction {
1084 __sighandler_t __sa_handler;
1085 unsigned long sa_mask;
1086 unsigned long sa_flags;
1087 void (*sa_restorer)(void);
1088};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001089#define SA_HANDLER __sa_handler
1090#endif /* LINUX */
1091
Roland McGratha39c5a12002-12-17 05:10:37 +00001092#ifndef SA_HANDLER
1093#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094#endif
1095
1096int
Denys Vlasenko12014262011-05-30 14:00:14 +02001097sys_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001098{
1099 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001100#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001101 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001102 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001103#else
1104 struct sigaction sa;
1105#endif
1106
1107
1108 if (entering(tcp)) {
1109 printsignal(tcp->u_arg[0]);
1110 tprintf(", ");
1111 addr = tcp->u_arg[1];
1112 } else
1113 addr = tcp->u_arg[2];
1114 if (addr == 0)
1115 tprintf("NULL");
1116 else if (!verbose(tcp))
1117 tprintf("%#lx", addr);
1118 else if (umove(tcp, addr, &sa) < 0)
1119 tprintf("{...}");
1120 else {
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001121 /* Architectures using function pointers, like
1122 * hppa, may need to manipulate the function pointer
1123 * to compute the result of a comparison. However,
1124 * the SA_HANDLER function pointer exists only in
1125 * the address space of the traced process, and can't
1126 * be manipulated by strace. In order to prevent the
1127 * compiler from generating code to manipulate
1128 * SA_HANDLER we cast the function pointers to long. */
1129 if ((long)sa.SA_HANDLER == (long)SIG_ERR)
Roland McGrath5f206812008-08-20 01:59:40 +00001130 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001131 else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
Roland McGrath5f206812008-08-20 01:59:40 +00001132 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001133 else if ((long)sa.SA_HANDLER == (long)SIG_IGN) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001134#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001135 if (tcp->u_arg[0] == SIGTRAP) {
1136 tcp->flags |= TCB_SIGTRAPPED;
1137 kill(tcp->pid, SIGSTOP);
1138 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001139#endif /* !USE_PROCFS */
Roland McGrath5f206812008-08-20 01:59:40 +00001140 tprintf("{SIG_IGN, ");
1141 }
1142 else {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001143#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001144 if (tcp->u_arg[0] == SIGTRAP) {
1145 tcp->flags |= TCB_SIGTRAPPED;
1146 kill(tcp->pid, SIGSTOP);
1147 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001148#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001149 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001150#ifndef LINUX
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001151 printsigmask(&sa.sa_mask, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001152#else
Nate Sammons4a121431999-04-06 01:19:39 +00001153 long_to_sigset(sa.sa_mask, &sigset);
1154 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001155#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001156 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001157 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001158#ifdef SA_RESTORER
1159 if (sa.sa_flags & SA_RESTORER)
1160 tprintf(", %p", sa.sa_restorer);
1161#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001162 tprintf("}");
1163 }
1164 }
1165 if (entering(tcp))
1166 tprintf(", ");
1167#ifdef LINUX
1168 else
1169 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1170#endif
1171 return 0;
1172}
1173
1174int
Denys Vlasenko12014262011-05-30 14:00:14 +02001175sys_signal(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001176{
1177 if (entering(tcp)) {
1178 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001179 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001180 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001181 case (long) SIG_ERR:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001182 tprintf("SIG_ERR");
1183 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001184 case (long) SIG_DFL:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001185 tprintf("SIG_DFL");
1186 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001187 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001188#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001189 if (tcp->u_arg[0] == SIGTRAP) {
1190 tcp->flags |= TCB_SIGTRAPPED;
1191 kill(tcp->pid, SIGSTOP);
1192 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001193#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001194 tprintf("SIG_IGN");
1195 break;
1196 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001197#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001198 if (tcp->u_arg[0] == SIGTRAP) {
1199 tcp->flags |= TCB_SIGTRAPPED;
1200 kill(tcp->pid, SIGSTOP);
1201 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001202#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001203 tprintf("%#lx", tcp->u_arg[1]);
1204 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001205 return 0;
1206 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001207 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001208 switch (tcp->u_rval) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001209 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001210 tcp->auxstr = "SIG_ERR"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001211 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001212 tcp->auxstr = "SIG_DFL"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001213 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001214 tcp->auxstr = "SIG_IGN"; break;
1215 default:
1216 tcp->auxstr = NULL;
1217 }
1218 return RVAL_HEX | RVAL_STR;
1219 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001220 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001221}
1222
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001223#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001224int
Denys Vlasenko12014262011-05-30 14:00:14 +02001225sys_sighold(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001226{
1227 if (entering(tcp)) {
1228 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001229 }
1230 return 0;
1231}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001232#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001233
1234#endif /* HAVE_SIGACTION */
1235
1236#ifdef LINUX
1237
1238int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001239sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001240{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001241#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001242 struct pt_regs regs;
1243 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001244
Roland McGrath0f87c492003-06-03 23:29:04 +00001245 if (entering(tcp)) {
1246 tcp->u_arg[0] = 0;
1247
1248 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1249 return 0;
1250
1251 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1252 return 0;
1253
1254 tcp->u_arg[0] = 1;
1255 tcp->u_arg[1] = sc.oldmask;
1256 } else {
1257 sigset_t sigm;
1258 long_to_sigset(tcp->u_arg[1], &sigm);
1259 tcp->u_rval = tcp->u_error = 0;
1260 if (tcp->u_arg[0] == 0)
1261 return 0;
1262 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1263 return RVAL_NONE | RVAL_STR;
1264 }
1265 return 0;
1266#elif defined(S390) || defined(S390X)
1267 long usp;
1268 struct sigcontext_struct sc;
1269
1270 if (entering(tcp)) {
1271 tcp->u_arg[0] = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001272 if (upeek(tcp, PT_GPR15, &usp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001273 return 0;
1274 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1275 return 0;
1276 tcp->u_arg[0] = 1;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001277 memcpy(&tcp->u_arg[1], &sc.oldmask[0], sizeof(sigset_t));
Roland McGrath0f87c492003-06-03 23:29:04 +00001278 } else {
1279 tcp->u_rval = tcp->u_error = 0;
1280 if (tcp->u_arg[0] == 0)
1281 return 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001282 tcp->auxstr = sprintsigmask("mask now ", (sigset_t *)&tcp->u_arg[1], 0);
Roland McGrath0f87c492003-06-03 23:29:04 +00001283 return RVAL_NONE | RVAL_STR;
1284 }
1285 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001286#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001287 long esp;
1288 struct sigcontext_struct sc;
1289
1290 if (entering(tcp)) {
1291 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001292 if (upeek(tcp, 4*UESP, &esp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001293 return 0;
1294 if (umove(tcp, esp, &sc) < 0)
1295 return 0;
1296 tcp->u_arg[0] = 1;
1297 tcp->u_arg[1] = sc.oldmask;
1298 }
1299 else {
1300 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001301 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001302 tcp->u_rval = tcp->u_error = 0;
1303 if (tcp->u_arg[0] == 0)
1304 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001305 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001306 return RVAL_NONE | RVAL_STR;
1307 }
1308 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001309#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001310 struct sigcontext sc;
1311 long sp;
1312
1313 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001314 /* offset of sigcontext in the kernel's sigframe structure: */
1315# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001316 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001317 if (upeek(tcp, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001318 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001319 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001320 return 0;
1321 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001322 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001323 }
1324 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001325 sigset_t sigm;
1326
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001327 memcpy(&sigm, tcp->u_arg + 1, sizeof(sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001328 tcp->u_rval = tcp->u_error = 0;
1329 if (tcp->u_arg[0] == 0)
1330 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001331 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001332 return RVAL_NONE | RVAL_STR;
1333 }
1334 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001335#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +00001336 long esp;
1337 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001338
Roland McGrath0f87c492003-06-03 23:29:04 +00001339 if (entering(tcp)) {
1340 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001341 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001342 return 0;
Andreas Schwabedb39342010-02-23 00:18:51 +01001343 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +02001344#ifdef POWERPC64
1345 if (current_personality == 0)
1346 esp += 128;
1347 else
1348 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +01001349#else
1350 esp += 64;
1351#endif
Roland McGrath0f87c492003-06-03 23:29:04 +00001352 if (umove(tcp, esp, &sc) < 0)
1353 return 0;
1354 tcp->u_arg[0] = 1;
1355 tcp->u_arg[1] = sc.oldmask;
1356 }
1357 else {
1358 sigset_t sigm;
1359 long_to_sigset(tcp->u_arg[1], &sigm);
1360 tcp->u_rval = tcp->u_error = 0;
1361 if (tcp->u_arg[0] == 0)
1362 return 0;
1363 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1364 return RVAL_NONE | RVAL_STR;
1365 }
1366 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001367#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001368 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001369 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001370
1371 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001372 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001373 if (upeek(tcp, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001374 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001375 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001376 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001377 tcp->u_arg[0] = 1;
1378 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001379 }
1380 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001381 sigset_t sigm;
1382 long_to_sigset(tcp->u_arg[1], &sigm);
1383 tcp->u_rval = tcp->u_error = 0;
1384 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001386 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1387 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001388 }
1389 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001390#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001391 long fp;
1392 struct sigcontext_struct sc;
1393
1394 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001395 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001396 if (upeek(tcp, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001397 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001398 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001400 tcp->u_arg[0] = 1;
1401 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001402 }
1403 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001404 sigset_t sigm;
1405 long_to_sigset(tcp->u_arg[1], &sigm);
1406 tcp->u_rval = tcp->u_error = 0;
1407 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001408 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001409 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1410 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001411 }
1412 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001413#elif defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001414 long i1;
Mike Frysinger8566c502009-10-12 11:05:14 -04001415 struct pt_regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001416 m_siginfo_t si;
1417
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001418 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Roland McGratheb9e2e82009-06-02 16:49:22 -07001419 perror("sigreturn: PTRACE_GETREGS ");
Roland McGrath0f87c492003-06-03 23:29:04 +00001420 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001421 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001422 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001423 tcp->u_arg[0] = 0;
Mike Frysinger8566c502009-10-12 11:05:14 -04001424 i1 = regs.u_regs[U_REG_O1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001425 if (umove(tcp, i1, &si) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001426 perror("sigreturn: umove ");
1427 return 0;
1428 }
1429 tcp->u_arg[0] = 1;
1430 tcp->u_arg[1] = si.si_mask;
1431 } else {
1432 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001433 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001434 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001435 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001436 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001437 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001438 return RVAL_NONE | RVAL_STR;
1439 }
1440 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001441#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001442 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1443 sigreturn. */
1444 long sp;
1445 struct ucontext uc;
1446
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001447 if (entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001448 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001449 if (upeek(tcp, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001450 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001451 /* There are six words followed by a 128-byte siginfo. */
1452 sp = sp + 6 * 4 + 128;
1453 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001454 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001455 tcp->u_arg[0] = 1;
1456 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1457 } else {
1458 sigset_t sigm;
1459 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001460 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001461 if (tcp->u_arg[0] == 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001462 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001463 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1464 return RVAL_NONE | RVAL_STR;
1465 }
1466 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001467#elif defined(MIPS)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001468 long sp;
Roland McGrath576b7842007-11-04 00:00:00 +00001469 struct pt_regs regs;
1470 m_siginfo_t si;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001471
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001472 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Roland McGrath576b7842007-11-04 00:00:00 +00001473 perror("sigreturn: PTRACE_GETREGS ");
1474 return 0;
1475 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001476 if (entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001477 tcp->u_arg[0] = 0;
Roland McGrath576b7842007-11-04 00:00:00 +00001478 sp = regs.regs[29];
1479 if (umove(tcp, sp, &si) < 0)
Denys Vlasenkofacd45b2011-06-09 01:22:10 +02001480 return 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001481 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001482 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001483 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001484 sigset_t sigm;
1485 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001486 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001487 if (tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001488 return 0;
1489 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001490 return RVAL_NONE | RVAL_STR;
1491 }
1492 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001493#elif defined(CRISV10) || defined(CRISV32)
1494 struct sigcontext sc;
1495
1496 if (entering(tcp)) {
1497 long regs[PT_MAX+1];
1498
1499 tcp->u_arg[0] = 0;
1500
1501 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1502 perror("sigreturn: PTRACE_GETREGS");
1503 return 0;
1504 }
1505 if (umove(tcp, regs[PT_USP], &sc) < 0)
1506 return 0;
1507 tcp->u_arg[0] = 1;
1508 tcp->u_arg[1] = sc.oldmask;
1509 } else {
1510 sigset_t sigm;
1511 long_to_sigset(tcp->u_arg[1], &sigm);
1512 tcp->u_rval = tcp->u_error = 0;
1513
1514 if (tcp->u_arg[0] == 0)
1515 return 0;
1516 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1517 return RVAL_NONE | RVAL_STR;
1518 }
1519 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -05001520#elif defined(TILE)
1521 struct ucontext uc;
1522 long sp;
1523
1524 /* offset of ucontext in the kernel's sigframe structure */
1525# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo)
1526
1527 if (entering(tcp)) {
1528 tcp->u_arg[0] = 0;
1529 if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0)
1530 return 0;
1531 if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1532 return 0;
1533 tcp->u_arg[0] = 1;
1534 memcpy(tcp->u_arg + 1, &uc.uc_sigmask, sizeof(uc.uc_sigmask));
1535 }
1536 else {
1537 sigset_t sigm;
1538
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001539 memcpy(&sigm, tcp->u_arg + 1, sizeof(sigm));
Chris Metcalfc8c66982009-12-28 10:00:15 -05001540 tcp->u_rval = tcp->u_error = 0;
1541 if (tcp->u_arg[0] == 0)
1542 return 0;
1543 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1544 return RVAL_NONE | RVAL_STR;
1545 }
1546 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001547#elif defined(MICROBLAZE)
1548 struct sigcontext sc;
1549
1550 /* TODO: Verify that this is correct... */
1551 if (entering(tcp)) {
1552 long sp;
1553
1554 tcp->u_arg[0] = 0;
1555
1556 /* Read r1, the stack pointer. */
1557 if (upeek(tcp, 1 * 4, &sp) < 0)
1558 return 0;
1559 if (umove(tcp, sp, &sc) < 0)
1560 return 0;
1561 tcp->u_arg[0] = 1;
1562 tcp->u_arg[1] = sc.oldmask;
1563 } else {
1564 sigset_t sigm;
1565 long_to_sigset(tcp->u_arg[1], &sigm);
1566 tcp->u_rval = tcp->u_error = 0;
1567 if (tcp->u_arg[0] == 0)
1568 return 0;
1569 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1570 return RVAL_NONE | RVAL_STR;
1571 }
1572 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001573#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001574#warning No sys_sigreturn() for this architecture
1575#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001576 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001577#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001578}
1579
1580int
Denys Vlasenko12014262011-05-30 14:00:14 +02001581sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001582{
1583 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001584 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001585 long_to_sigset(tcp->u_rval, &sigm);
1586 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001587 }
1588 return RVAL_HEX | RVAL_STR;
1589}
1590
1591int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001592sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593{
1594 if (entering(tcp)) {
1595 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001596 long_to_sigset(tcp->u_arg[2], &sigm);
Nate Sammons4a121431999-04-06 01:19:39 +00001597 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001598 }
1599 return 0;
1600}
1601
1602#endif /* LINUX */
1603
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001604#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001605
1606int
Denys Vlasenko12014262011-05-30 14:00:14 +02001607sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001608{
1609 sigset_t sigset;
1610
1611 if (entering(tcp)) {
1612 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1613 tprintf("[?]");
1614 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001615 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001616 }
1617 return 0;
1618}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001619#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001620static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621 { UC_SIGMASK, "UC_SIGMASK" },
1622 { UC_STACK, "UC_STACK" },
1623 { UC_CPU, "UC_CPU" },
1624#ifdef UC_FPU
1625 { UC_FPU, "UC_FPU" },
1626#endif
1627#ifdef UC_INTR
1628 { UC_INTR, "UC_INTR" },
1629#endif
1630 { 0, NULL },
1631};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001632#endif /* !FREEBSD */
1633#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001634
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001635#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001636#if defined LINUX && !defined SS_ONSTACK
1637#define SS_ONSTACK 1
1638#define SS_DISABLE 2
1639#if __GLIBC_MINOR__ == 0
1640typedef struct
1641{
1642 __ptr_t ss_sp;
1643 int ss_flags;
1644 size_t ss_size;
1645} stack_t;
1646#endif
1647#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001648#ifdef FREEBSD
1649#define stack_t struct sigaltstack
1650#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001651
Roland McGrathd9f816f2004-09-04 03:39:20 +00001652static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001653 { SS_ONSTACK, "SS_ONSTACK" },
1654 { SS_DISABLE, "SS_DISABLE" },
1655 { 0, NULL },
1656};
1657#endif
1658
1659#ifdef SVR4
1660static void
Denys Vlasenko12014262011-05-30 14:00:14 +02001661printcontext(struct tcb *tcp, ucontext_t *ucp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001662{
1663 tprintf("{");
1664 if (!abbrev(tcp)) {
1665 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001666 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001667 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1668 }
1669 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001670 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001671 if (!abbrev(tcp)) {
1672 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1673 (unsigned long) ucp->uc_stack.ss_sp,
1674 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001675 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001676 tprintf("}");
1677 }
1678 tprintf(", ...}");
1679}
1680
1681int
Denys Vlasenko12014262011-05-30 14:00:14 +02001682sys_getcontext(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001683{
1684 ucontext_t uc;
1685
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001686 if (exiting(tcp)) {
1687 if (tcp->u_error)
1688 tprintf("%#lx", tcp->u_arg[0]);
1689 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001690 tprintf("NULL");
1691 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1692 tprintf("{...}");
1693 else
1694 printcontext(tcp, &uc);
1695 }
1696 return 0;
1697}
1698
1699int
Denys Vlasenko12014262011-05-30 14:00:14 +02001700sys_setcontext(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001701{
1702 ucontext_t uc;
1703
1704 if (entering(tcp)) {
1705 if (!tcp->u_arg[0])
1706 tprintf("NULL");
1707 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1708 tprintf("{...}");
1709 else
1710 printcontext(tcp, &uc);
1711 }
1712 else {
1713 tcp->u_rval = tcp->u_error = 0;
1714 if (tcp->u_arg[0] == 0)
1715 return 0;
1716 return RVAL_NONE;
1717 }
1718 return 0;
1719}
1720
1721#endif /* SVR4 */
1722
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001723#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001724
1725static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001726print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001727{
1728 stack_t ss;
1729 if (umove(tcp, addr, &ss) < 0)
1730 return -1;
1731 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001732 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001733 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1734 return 0;
1735}
1736
1737int
Denys Vlasenko12014262011-05-30 14:00:14 +02001738sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001739{
1740 if (entering(tcp)) {
1741 if (tcp->u_arg[0] == 0)
1742 tprintf("NULL");
1743 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1744 return -1;
1745 }
1746 else {
1747 tprintf(", ");
1748 if (tcp->u_arg[1] == 0)
1749 tprintf("NULL");
1750 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1751 return -1;
1752 }
1753 return 0;
1754}
1755#endif
1756
1757#ifdef HAVE_SIGACTION
1758
1759int
Denys Vlasenko12014262011-05-30 14:00:14 +02001760sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001761{
1762#ifdef ALPHA
1763 if (entering(tcp)) {
1764 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1765 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001766 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001767 }
1768 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001769 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001770 return RVAL_HEX | RVAL_STR;
1771 }
1772#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001773 if (entering(tcp)) {
1774#ifdef SVR4
1775 if (tcp->u_arg[0] == 0)
1776 tprintf("0");
1777 else
1778#endif /* SVR4 */
1779 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1780 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001781 print_sigset(tcp, tcp->u_arg[1], 0);
1782 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001783 }
1784 else {
1785 if (!tcp->u_arg[2])
1786 tprintf("NULL");
1787 else if (syserror(tcp))
1788 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001789 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001790 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791 }
1792#endif /* !ALPHA */
1793 return 0;
1794}
1795
1796#endif /* HAVE_SIGACTION */
1797
1798int
Denys Vlasenko12014262011-05-30 14:00:14 +02001799sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001800{
1801 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001802 /*
1803 * Sign-extend a 32-bit value when that's what it is.
1804 */
1805 long pid = tcp->u_arg[0];
1806 if (personality_wordsize[current_personality] < sizeof pid)
1807 pid = (long) (int) pid;
1808 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001809 }
1810 return 0;
1811}
1812
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001813#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814int
Denys Vlasenko12014262011-05-30 14:00:14 +02001815sys_killpg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001816{
1817 return sys_kill(tcp);
1818}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001819#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001820
Roland McGrath8ffc3522003-07-09 09:47:49 +00001821#ifdef LINUX
1822int
Denys Vlasenko12014262011-05-30 14:00:14 +02001823sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001824{
1825 if (entering(tcp)) {
1826 tprintf("%ld, %ld, %s",
1827 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1828 }
1829 return 0;
1830}
1831#endif
1832
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001833int
Denys Vlasenko12014262011-05-30 14:00:14 +02001834sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001835{
1836 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001837
1838 if (exiting(tcp)) {
1839 if (syserror(tcp))
1840 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001841 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001842 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001843 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001844 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001845 }
1846 return 0;
1847}
1848
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001849#ifdef SVR4
Denys Vlasenko12014262011-05-30 14:00:14 +02001850int sys_sigwait(struct tcb *tcp)
John Hughes42162082001-10-18 14:48:26 +00001851{
1852 sigset_t sigset;
1853
1854 if (entering(tcp)) {
1855 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1856 tprintf("[?]");
1857 else
1858 printsigmask(&sigset, 0);
1859 }
1860 else {
1861 if (!syserror(tcp)) {
1862 tcp->auxstr = signalent[tcp->u_rval];
1863 return RVAL_DECIMAL | RVAL_STR;
1864 }
1865 }
1866 return 0;
1867}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001868#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001869
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001870#ifdef LINUX
1871
Denys Vlasenko12014262011-05-30 14:00:14 +02001872int
1873sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874{
1875 sigset_t sigset;
1876
Nate Sammons4a121431999-04-06 01:19:39 +00001877 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001878 if (entering(tcp)) {
1879 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1880 tprintf(", ");
1881 if (!tcp->u_arg[1])
1882 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001883 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001884 tprintf("%#lx, ", tcp->u_arg[1]);
1885 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001886 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001887 tprintf(", ");
1888 }
1889 }
1890 else {
1891 if (!tcp->u_arg[2])
1892
1893 tprintf("NULL");
1894 else if (syserror(tcp))
1895 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001896 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001897 tprintf("[?]");
1898 else
Nate Sammons4a121431999-04-06 01:19:39 +00001899 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001900 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001901 }
1902 return 0;
1903}
1904
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001905
1906/* Structure describing the action to be taken when a signal arrives. */
1907struct new_sigaction
1908{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001909 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910 unsigned long sa_flags;
1911 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001912 /* Kernel treats sa_mask as an array of longs. */
1913 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1914};
1915/* Same for i386-on-x86_64 and similar cases */
1916struct new_sigaction32
1917{
1918 uint32_t __sa_handler;
1919 uint32_t sa_flags;
1920 uint32_t sa_restorer;
1921 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001922};
1923
1924
Roland McGrath5f206812008-08-20 01:59:40 +00001925int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001926sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001927{
1928 struct new_sigaction sa;
1929 sigset_t sigset;
1930 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001931 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001932
1933 if (entering(tcp)) {
1934 printsignal(tcp->u_arg[0]);
1935 tprintf(", ");
1936 addr = tcp->u_arg[1];
1937 } else
1938 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001939
1940 if (addr == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001941 tprintf("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001942 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001943 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001944 if (!verbose(tcp)) {
1945 tprintf("%#lx", addr);
1946 goto after_sa;
1947 }
1948#if SUPPORTED_PERSONALITIES > 1
1949 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1950 && personality_wordsize[current_personality] == 4
1951 ) {
1952 struct new_sigaction32 sa32;
1953 r = umove(tcp, addr, &sa32);
1954 if (r >= 0) {
1955 memset(&sa, 0, sizeof(sa));
1956 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1957 sa.sa_flags = sa32.sa_flags;
1958 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1959 /* Kernel treats sa_mask as an array of longs.
1960 * For 32-bit process, "long" is uint32_t, thus, for example,
1961 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1962 * But for (64-bit) kernel, 32th bit in sa_mask is
1963 * 32th bit in 0th (64-bit) long!
1964 * For little-endian, it's the same.
1965 * For big-endian, we swap 32-bit words.
1966 */
1967 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1968 }
1969 } else
1970#endif
1971 {
1972 r = umove(tcp, addr, &sa);
1973 }
1974 if (r < 0) {
1975 tprintf("{...}");
1976 goto after_sa;
1977 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001978 /* Architectures using function pointers, like
1979 * hppa, may need to manipulate the function pointer
1980 * to compute the result of a comparison. However,
1981 * the SA_HANDLER function pointer exists only in
1982 * the address space of the traced process, and can't
1983 * be manipulated by strace. In order to prevent the
1984 * compiler from generating code to manipulate
1985 * SA_HANDLER we cast the function pointers to long. */
1986 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001987 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001988 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001989 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001990 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001991 tprintf("{SIG_IGN, ");
1992 else
1993 tprintf("{%#lx, ", (long) sa.__sa_handler);
1994 /* Questionable code below.
1995 * Kernel won't handle sys_rt_sigaction
1996 * with wrong sigset size (just returns EINVAL)
1997 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
1998 * and we always use smaller memcpy. */
1999 sigemptyset(&sigset);
2000#ifdef LINUXSPARC
2001 if (tcp->u_arg[4] <= sizeof(sigset))
2002 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
2003#else
2004 if (tcp->u_arg[3] <= sizeof(sigset))
2005 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
2006#endif
2007 else
2008 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
2009 printsigmask(&sigset, 1);
2010 tprintf(", ");
2011 printflags(sigact_flags, sa.sa_flags, "SA_???");
2012#ifdef SA_RESTORER
2013 if (sa.sa_flags & SA_RESTORER)
2014 tprintf(", %p", sa.sa_restorer);
2015#endif
2016 tprintf("}");
2017
2018 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002019 if (entering(tcp))
2020 tprintf(", ");
2021 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00002022#ifdef LINUXSPARC
2023 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
2024#elif defined(ALPHA)
2025 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
2026#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00002027 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00002028#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002029 return 0;
2030}
2031
Denys Vlasenko1d632462009-04-14 12:51:00 +00002032int
2033sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002034{
2035 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002036
2037 if (exiting(tcp)) {
2038 if (syserror(tcp))
2039 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00002040 else if (copy_sigset_len(tcp, tcp->u_arg[0],
2041 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002042 tprintf("[?]");
2043 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002044 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002045 }
2046 return 0;
2047}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002048
2049int
2050sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002051{
2052 if (entering(tcp)) {
2053 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00002054 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
2055 tprintf("[?]");
2056 else
2057 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002058 }
2059 return 0;
2060}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002061
2062int
2063sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002064{
2065 if (entering(tcp)) {
2066 siginfo_t si;
2067 tprintf("%lu, ", tcp->u_arg[0]);
2068 printsignal(tcp->u_arg[1]);
2069 tprintf(", ");
2070 if (umove(tcp, tcp->u_arg[2], &si) < 0)
2071 tprintf("%#lx", tcp->u_arg[2]);
2072 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002073 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002074 }
2075 return 0;
2076}
2077
Denys Vlasenko1d632462009-04-14 12:51:00 +00002078int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002079{
2080 if (entering(tcp)) {
2081 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002082
Roland McGratha39c5a12002-12-17 05:10:37 +00002083 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00002084 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002085 tprintf("[?]");
2086 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002087 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002088 tprintf(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002089 /* This is the only "return" parameter, */
2090 if (tcp->u_arg[1] != 0)
2091 return 0;
2092 /* ... if it's NULL, can decode all on entry */
2093 tprintf("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002094 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002095 else if (tcp->u_arg[1] != 0) {
2096 /* syscall exit, and u_arg[1] wasn't NULL */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002097 if (syserror(tcp))
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002098 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002099 else {
2100 siginfo_t si;
2101 if (umove(tcp, tcp->u_arg[1], &si) < 0)
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002102 tprintf("%#lx, ", tcp->u_arg[1]);
2103 else {
Denys Vlasenkof535b542009-01-13 18:30:55 +00002104 printsiginfo(&si, verbose(tcp));
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002105 tprintf(", ");
2106 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002107 }
2108 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002109 else {
2110 /* syscall exit, and u_arg[1] was NULL */
2111 return 0;
2112 }
2113 print_timespec(tcp, tcp->u_arg[2]);
2114 tprintf(", %d", (int) tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002115 return 0;
2116};
2117
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002118int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002119sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002120{
2121 if (entering(tcp))
2122 tprintf("<... resuming interrupted call ...>");
2123 return 0;
2124}
2125
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002126static int
2127do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00002128{
2129 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002130 printfd(tcp, tcp->u_arg[0]);
2131 tprintf(", ");
Roland McGrathf46ccd32007-08-02 01:15:59 +00002132 print_sigset(tcp, tcp->u_arg[1], 1);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00002133 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002134 if (flags_arg >= 0) {
2135 tprintf(", ");
2136 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2137 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00002138 }
2139 return 0;
2140}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002141
2142int
2143sys_signalfd(struct tcb *tcp)
2144{
2145 return do_signalfd(tcp, -1);
2146}
2147
2148int
2149sys_signalfd4(struct tcb *tcp)
2150{
2151 return do_signalfd(tcp, 3);
2152}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002153#endif /* LINUX */