blob: f2d7277cca430c4e893f5605c205daa666939ba8 [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)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001480 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001481 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001482 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001483 sigset_t sigm;
1484 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001485 tcp->u_rval = tcp->u_error = 0;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001486 if (tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001487 return 0;
1488 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001489 return RVAL_NONE | RVAL_STR;
1490 }
1491 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001492#elif defined(CRISV10) || defined(CRISV32)
1493 struct sigcontext sc;
1494
1495 if (entering(tcp)) {
1496 long regs[PT_MAX+1];
1497
1498 tcp->u_arg[0] = 0;
1499
1500 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1501 perror("sigreturn: PTRACE_GETREGS");
1502 return 0;
1503 }
1504 if (umove(tcp, regs[PT_USP], &sc) < 0)
1505 return 0;
1506 tcp->u_arg[0] = 1;
1507 tcp->u_arg[1] = sc.oldmask;
1508 } else {
1509 sigset_t sigm;
1510 long_to_sigset(tcp->u_arg[1], &sigm);
1511 tcp->u_rval = tcp->u_error = 0;
1512
1513 if (tcp->u_arg[0] == 0)
1514 return 0;
1515 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1516 return RVAL_NONE | RVAL_STR;
1517 }
1518 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -05001519#elif defined(TILE)
1520 struct ucontext uc;
1521 long sp;
1522
1523 /* offset of ucontext in the kernel's sigframe structure */
1524# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo)
1525
1526 if (entering(tcp)) {
1527 tcp->u_arg[0] = 0;
1528 if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0)
1529 return 0;
1530 if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1531 return 0;
1532 tcp->u_arg[0] = 1;
1533 memcpy(tcp->u_arg + 1, &uc.uc_sigmask, sizeof(uc.uc_sigmask));
1534 }
1535 else {
1536 sigset_t sigm;
1537
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001538 memcpy(&sigm, tcp->u_arg + 1, sizeof(sigm));
Chris Metcalfc8c66982009-12-28 10:00:15 -05001539 tcp->u_rval = tcp->u_error = 0;
1540 if (tcp->u_arg[0] == 0)
1541 return 0;
1542 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1543 return RVAL_NONE | RVAL_STR;
1544 }
1545 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001546#elif defined(MICROBLAZE)
1547 struct sigcontext sc;
1548
1549 /* TODO: Verify that this is correct... */
1550 if (entering(tcp)) {
1551 long sp;
1552
1553 tcp->u_arg[0] = 0;
1554
1555 /* Read r1, the stack pointer. */
1556 if (upeek(tcp, 1 * 4, &sp) < 0)
1557 return 0;
1558 if (umove(tcp, sp, &sc) < 0)
1559 return 0;
1560 tcp->u_arg[0] = 1;
1561 tcp->u_arg[1] = sc.oldmask;
1562 } else {
1563 sigset_t sigm;
1564 long_to_sigset(tcp->u_arg[1], &sigm);
1565 tcp->u_rval = tcp->u_error = 0;
1566 if (tcp->u_arg[0] == 0)
1567 return 0;
1568 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1569 return RVAL_NONE | RVAL_STR;
1570 }
1571 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001572#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001573#warning No sys_sigreturn() for this architecture
1574#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001575 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001576#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001577}
1578
1579int
Denys Vlasenko12014262011-05-30 14:00:14 +02001580sys_siggetmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001581{
1582 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001583 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001584 long_to_sigset(tcp->u_rval, &sigm);
1585 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001586 }
1587 return RVAL_HEX | RVAL_STR;
1588}
1589
1590int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001591sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001592{
1593 if (entering(tcp)) {
1594 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001595 long_to_sigset(tcp->u_arg[2], &sigm);
Nate Sammons4a121431999-04-06 01:19:39 +00001596 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597 }
1598 return 0;
1599}
1600
1601#endif /* LINUX */
1602
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001603#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001604
1605int
Denys Vlasenko12014262011-05-30 14:00:14 +02001606sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001607{
1608 sigset_t sigset;
1609
1610 if (entering(tcp)) {
1611 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1612 tprintf("[?]");
1613 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001614 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615 }
1616 return 0;
1617}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001618#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001619static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001620 { UC_SIGMASK, "UC_SIGMASK" },
1621 { UC_STACK, "UC_STACK" },
1622 { UC_CPU, "UC_CPU" },
1623#ifdef UC_FPU
1624 { UC_FPU, "UC_FPU" },
1625#endif
1626#ifdef UC_INTR
1627 { UC_INTR, "UC_INTR" },
1628#endif
1629 { 0, NULL },
1630};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001631#endif /* !FREEBSD */
1632#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001633
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001634#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001635#if defined LINUX && !defined SS_ONSTACK
1636#define SS_ONSTACK 1
1637#define SS_DISABLE 2
1638#if __GLIBC_MINOR__ == 0
1639typedef struct
1640{
1641 __ptr_t ss_sp;
1642 int ss_flags;
1643 size_t ss_size;
1644} stack_t;
1645#endif
1646#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001647#ifdef FREEBSD
1648#define stack_t struct sigaltstack
1649#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001650
Roland McGrathd9f816f2004-09-04 03:39:20 +00001651static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001652 { SS_ONSTACK, "SS_ONSTACK" },
1653 { SS_DISABLE, "SS_DISABLE" },
1654 { 0, NULL },
1655};
1656#endif
1657
1658#ifdef SVR4
1659static void
Denys Vlasenko12014262011-05-30 14:00:14 +02001660printcontext(struct tcb *tcp, ucontext_t *ucp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001661{
1662 tprintf("{");
1663 if (!abbrev(tcp)) {
1664 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001665 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001666 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1667 }
1668 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001669 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001670 if (!abbrev(tcp)) {
1671 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1672 (unsigned long) ucp->uc_stack.ss_sp,
1673 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001674 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001675 tprintf("}");
1676 }
1677 tprintf(", ...}");
1678}
1679
1680int
Denys Vlasenko12014262011-05-30 14:00:14 +02001681sys_getcontext(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001682{
1683 ucontext_t uc;
1684
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001685 if (exiting(tcp)) {
1686 if (tcp->u_error)
1687 tprintf("%#lx", tcp->u_arg[0]);
1688 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001689 tprintf("NULL");
1690 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1691 tprintf("{...}");
1692 else
1693 printcontext(tcp, &uc);
1694 }
1695 return 0;
1696}
1697
1698int
Denys Vlasenko12014262011-05-30 14:00:14 +02001699sys_setcontext(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001700{
1701 ucontext_t uc;
1702
1703 if (entering(tcp)) {
1704 if (!tcp->u_arg[0])
1705 tprintf("NULL");
1706 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1707 tprintf("{...}");
1708 else
1709 printcontext(tcp, &uc);
1710 }
1711 else {
1712 tcp->u_rval = tcp->u_error = 0;
1713 if (tcp->u_arg[0] == 0)
1714 return 0;
1715 return RVAL_NONE;
1716 }
1717 return 0;
1718}
1719
1720#endif /* SVR4 */
1721
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001722#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001723
1724static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001725print_stack_t(struct tcb *tcp, unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001726{
1727 stack_t ss;
1728 if (umove(tcp, addr, &ss) < 0)
1729 return -1;
1730 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001731 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001732 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1733 return 0;
1734}
1735
1736int
Denys Vlasenko12014262011-05-30 14:00:14 +02001737sys_sigaltstack(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001738{
1739 if (entering(tcp)) {
1740 if (tcp->u_arg[0] == 0)
1741 tprintf("NULL");
1742 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1743 return -1;
1744 }
1745 else {
1746 tprintf(", ");
1747 if (tcp->u_arg[1] == 0)
1748 tprintf("NULL");
1749 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1750 return -1;
1751 }
1752 return 0;
1753}
1754#endif
1755
1756#ifdef HAVE_SIGACTION
1757
1758int
Denys Vlasenko12014262011-05-30 14:00:14 +02001759sys_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760{
1761#ifdef ALPHA
1762 if (entering(tcp)) {
1763 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1764 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001765 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001766 }
1767 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001768 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001769 return RVAL_HEX | RVAL_STR;
1770 }
1771#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001772 if (entering(tcp)) {
1773#ifdef SVR4
1774 if (tcp->u_arg[0] == 0)
1775 tprintf("0");
1776 else
1777#endif /* SVR4 */
1778 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1779 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001780 print_sigset(tcp, tcp->u_arg[1], 0);
1781 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001782 }
1783 else {
1784 if (!tcp->u_arg[2])
1785 tprintf("NULL");
1786 else if (syserror(tcp))
1787 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001788 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001789 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001790 }
1791#endif /* !ALPHA */
1792 return 0;
1793}
1794
1795#endif /* HAVE_SIGACTION */
1796
1797int
Denys Vlasenko12014262011-05-30 14:00:14 +02001798sys_kill(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001799{
1800 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001801 /*
1802 * Sign-extend a 32-bit value when that's what it is.
1803 */
1804 long pid = tcp->u_arg[0];
1805 if (personality_wordsize[current_personality] < sizeof pid)
1806 pid = (long) (int) pid;
1807 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001808 }
1809 return 0;
1810}
1811
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001812#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001813int
Denys Vlasenko12014262011-05-30 14:00:14 +02001814sys_killpg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001815{
1816 return sys_kill(tcp);
1817}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001818#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001819
Roland McGrath8ffc3522003-07-09 09:47:49 +00001820#ifdef LINUX
1821int
Denys Vlasenko12014262011-05-30 14:00:14 +02001822sys_tgkill(struct tcb *tcp)
Roland McGrath8ffc3522003-07-09 09:47:49 +00001823{
1824 if (entering(tcp)) {
1825 tprintf("%ld, %ld, %s",
1826 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1827 }
1828 return 0;
1829}
1830#endif
1831
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001832int
Denys Vlasenko12014262011-05-30 14:00:14 +02001833sys_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001834{
1835 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001836
1837 if (exiting(tcp)) {
1838 if (syserror(tcp))
1839 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001840 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001841 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001842 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001843 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001844 }
1845 return 0;
1846}
1847
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001848#ifdef SVR4
Denys Vlasenko12014262011-05-30 14:00:14 +02001849int sys_sigwait(struct tcb *tcp)
John Hughes42162082001-10-18 14:48:26 +00001850{
1851 sigset_t sigset;
1852
1853 if (entering(tcp)) {
1854 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1855 tprintf("[?]");
1856 else
1857 printsigmask(&sigset, 0);
1858 }
1859 else {
1860 if (!syserror(tcp)) {
1861 tcp->auxstr = signalent[tcp->u_rval];
1862 return RVAL_DECIMAL | RVAL_STR;
1863 }
1864 }
1865 return 0;
1866}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001867#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001868
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001869#ifdef LINUX
1870
Denys Vlasenko12014262011-05-30 14:00:14 +02001871int
1872sys_rt_sigprocmask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001873{
1874 sigset_t sigset;
1875
Nate Sammons4a121431999-04-06 01:19:39 +00001876 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001877 if (entering(tcp)) {
1878 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1879 tprintf(", ");
1880 if (!tcp->u_arg[1])
1881 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001882 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883 tprintf("%#lx, ", tcp->u_arg[1]);
1884 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001885 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001886 tprintf(", ");
1887 }
1888 }
1889 else {
1890 if (!tcp->u_arg[2])
1891
1892 tprintf("NULL");
1893 else if (syserror(tcp))
1894 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001895 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001896 tprintf("[?]");
1897 else
Nate Sammons4a121431999-04-06 01:19:39 +00001898 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001899 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001900 }
1901 return 0;
1902}
1903
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001904
1905/* Structure describing the action to be taken when a signal arrives. */
1906struct new_sigaction
1907{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001908 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001909 unsigned long sa_flags;
1910 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001911 /* Kernel treats sa_mask as an array of longs. */
1912 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1913};
1914/* Same for i386-on-x86_64 and similar cases */
1915struct new_sigaction32
1916{
1917 uint32_t __sa_handler;
1918 uint32_t sa_flags;
1919 uint32_t sa_restorer;
1920 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001921};
1922
1923
Roland McGrath5f206812008-08-20 01:59:40 +00001924int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001925sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001926{
1927 struct new_sigaction sa;
1928 sigset_t sigset;
1929 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001930 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001931
1932 if (entering(tcp)) {
1933 printsignal(tcp->u_arg[0]);
1934 tprintf(", ");
1935 addr = tcp->u_arg[1];
1936 } else
1937 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001938
1939 if (addr == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001940 tprintf("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001941 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001942 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001943 if (!verbose(tcp)) {
1944 tprintf("%#lx", addr);
1945 goto after_sa;
1946 }
1947#if SUPPORTED_PERSONALITIES > 1
1948 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1949 && personality_wordsize[current_personality] == 4
1950 ) {
1951 struct new_sigaction32 sa32;
1952 r = umove(tcp, addr, &sa32);
1953 if (r >= 0) {
1954 memset(&sa, 0, sizeof(sa));
1955 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1956 sa.sa_flags = sa32.sa_flags;
1957 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1958 /* Kernel treats sa_mask as an array of longs.
1959 * For 32-bit process, "long" is uint32_t, thus, for example,
1960 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1961 * But for (64-bit) kernel, 32th bit in sa_mask is
1962 * 32th bit in 0th (64-bit) long!
1963 * For little-endian, it's the same.
1964 * For big-endian, we swap 32-bit words.
1965 */
1966 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1967 }
1968 } else
1969#endif
1970 {
1971 r = umove(tcp, addr, &sa);
1972 }
1973 if (r < 0) {
1974 tprintf("{...}");
1975 goto after_sa;
1976 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001977 /* Architectures using function pointers, like
1978 * hppa, may need to manipulate the function pointer
1979 * to compute the result of a comparison. However,
1980 * the SA_HANDLER function pointer exists only in
1981 * the address space of the traced process, and can't
1982 * be manipulated by strace. In order to prevent the
1983 * compiler from generating code to manipulate
1984 * SA_HANDLER we cast the function pointers to long. */
1985 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001986 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001987 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001988 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001989 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001990 tprintf("{SIG_IGN, ");
1991 else
1992 tprintf("{%#lx, ", (long) sa.__sa_handler);
1993 /* Questionable code below.
1994 * Kernel won't handle sys_rt_sigaction
1995 * with wrong sigset size (just returns EINVAL)
1996 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
1997 * and we always use smaller memcpy. */
1998 sigemptyset(&sigset);
1999#ifdef LINUXSPARC
2000 if (tcp->u_arg[4] <= sizeof(sigset))
2001 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
2002#else
2003 if (tcp->u_arg[3] <= sizeof(sigset))
2004 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
2005#endif
2006 else
2007 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
2008 printsigmask(&sigset, 1);
2009 tprintf(", ");
2010 printflags(sigact_flags, sa.sa_flags, "SA_???");
2011#ifdef SA_RESTORER
2012 if (sa.sa_flags & SA_RESTORER)
2013 tprintf(", %p", sa.sa_restorer);
2014#endif
2015 tprintf("}");
2016
2017 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002018 if (entering(tcp))
2019 tprintf(", ");
2020 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00002021#ifdef LINUXSPARC
2022 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
2023#elif defined(ALPHA)
2024 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
2025#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00002026 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00002027#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002028 return 0;
2029}
2030
Denys Vlasenko1d632462009-04-14 12:51:00 +00002031int
2032sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002033{
2034 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002035
2036 if (exiting(tcp)) {
2037 if (syserror(tcp))
2038 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00002039 else if (copy_sigset_len(tcp, tcp->u_arg[0],
2040 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002041 tprintf("[?]");
2042 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002043 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002044 }
2045 return 0;
2046}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002047
2048int
2049sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002050{
2051 if (entering(tcp)) {
2052 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00002053 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
2054 tprintf("[?]");
2055 else
2056 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002057 }
2058 return 0;
2059}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002060
2061int
2062sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002063{
2064 if (entering(tcp)) {
2065 siginfo_t si;
2066 tprintf("%lu, ", tcp->u_arg[0]);
2067 printsignal(tcp->u_arg[1]);
2068 tprintf(", ");
2069 if (umove(tcp, tcp->u_arg[2], &si) < 0)
2070 tprintf("%#lx", tcp->u_arg[2]);
2071 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002072 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002073 }
2074 return 0;
2075}
2076
Denys Vlasenko1d632462009-04-14 12:51:00 +00002077int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002078{
2079 if (entering(tcp)) {
2080 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002081
Roland McGratha39c5a12002-12-17 05:10:37 +00002082 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00002083 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002084 tprintf("[?]");
2085 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002086 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002087 tprintf(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002088 /* This is the only "return" parameter, */
2089 if (tcp->u_arg[1] != 0)
2090 return 0;
2091 /* ... if it's NULL, can decode all on entry */
2092 tprintf("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002093 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002094 else if (tcp->u_arg[1] != 0) {
2095 /* syscall exit, and u_arg[1] wasn't NULL */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002096 if (syserror(tcp))
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002097 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002098 else {
2099 siginfo_t si;
2100 if (umove(tcp, tcp->u_arg[1], &si) < 0)
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002101 tprintf("%#lx, ", tcp->u_arg[1]);
2102 else {
Denys Vlasenkof535b542009-01-13 18:30:55 +00002103 printsiginfo(&si, verbose(tcp));
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002104 tprintf(", ");
2105 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002106 }
2107 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002108 else {
2109 /* syscall exit, and u_arg[1] was NULL */
2110 return 0;
2111 }
2112 print_timespec(tcp, tcp->u_arg[2]);
2113 tprintf(", %d", (int) tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002114 return 0;
2115};
2116
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002117int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002118sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002119{
2120 if (entering(tcp))
2121 tprintf("<... resuming interrupted call ...>");
2122 return 0;
2123}
2124
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002125static int
2126do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00002127{
2128 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002129 printfd(tcp, tcp->u_arg[0]);
2130 tprintf(", ");
Roland McGrathf46ccd32007-08-02 01:15:59 +00002131 print_sigset(tcp, tcp->u_arg[1], 1);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00002132 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002133 if (flags_arg >= 0) {
2134 tprintf(", ");
2135 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2136 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00002137 }
2138 return 0;
2139}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002140
2141int
2142sys_signalfd(struct tcb *tcp)
2143{
2144 return do_signalfd(tcp, -1);
2145}
2146
2147int
2148sys_signalfd4(struct tcb *tcp)
2149{
2150 return do_signalfd(tcp, 3);
2151}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002152#endif /* LINUX */