blob: db5f49b918b50ec75f6c5feec15b68001d494f64 [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
291copy_sigset_len(tcp, addr, s, len)
292struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000293long addr;
Nate Sammons4a121431999-04-06 01:19:39 +0000294sigset_t *s;
295int len;
296{
297 if (len > sizeof(*s))
298 len = sizeof(*s);
299 sigemptyset(s);
300 if (umoven(tcp, addr, len, (char *)s) < 0)
301 return -1;
302 return 0;
303}
304
305#ifdef LINUX
306/* Original sigset is unsigned long */
307#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
308#else
309#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
310#endif
311
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000312static const char *
313sprintsigmask(const char *str, sigset_t *mask, int rt)
314/* set might include realtime sigs */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000315{
316 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000317 int maxsigs;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000318 const char *format;
319 char *s;
Roland McGratha39c5a12002-12-17 05:10:37 +0000320 static char outstr[8 * sizeof(sigset_t) * 8];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000322 strcpy(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000323 s = outstr + strlen(outstr);
324 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000325 maxsigs = nsignals;
326#ifdef __SIGRTMAX
327 if (rt)
328 maxsigs = __SIGRTMAX; /* instead */
329#endif
330 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331 if (sigismember(mask, i) == 1)
332 nsigs++;
333 }
334 if (nsigs >= nsignals * 2 / 3) {
335 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000336 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000337 switch (sigismember(mask, i)) {
338 case 1:
339 sigdelset(mask, i);
340 break;
341 case 0:
342 sigaddset(mask, i);
343 break;
344 }
345 }
346 }
347 format = "%s";
348 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000349 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000350 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000351 /* real-time signals on solaris don't have
352 * signalent entries
353 */
354 if (i < nsignals) {
355 sprintf(s, format, signalent[i] + 3);
356 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000357#ifdef SIGRTMIN
358 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
359 char tsig[40];
360 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
361 sprintf(s, format, tsig);
362 }
363#endif /* SIGRTMIN */
John Hughesbdf48f52001-03-06 15:08:09 +0000364 else {
365 char tsig[32];
366 sprintf(tsig, "%u", i);
367 sprintf(s, format, tsig);
368 }
369 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000370 format = " %s";
371 }
372 }
373 *s++ = ']';
374 *s = '\0';
375 return outstr;
376}
377
378static void
Nate Sammons4a121431999-04-06 01:19:39 +0000379printsigmask(mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000381int rt;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000382{
Nate Sammons4a121431999-04-06 01:19:39 +0000383 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384}
385
386void
387printsignal(nr)
388int nr;
389{
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +0000390 tprintf("%s", signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391}
392
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000393void
394print_sigset(struct tcb *tcp, long addr, int rt)
395{
396 sigset_t ss;
397
398 if (!addr)
399 tprintf("NULL");
400 else if (copy_sigset(tcp, addr, &ss) < 0)
401 tprintf("%#lx", addr);
402 else
403 printsigmask(&ss, rt);
404}
405
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000406#ifdef LINUX
407
John Hughes58265892001-10-18 15:13:53 +0000408#ifndef ILL_ILLOPC
409#define ILL_ILLOPC 1 /* illegal opcode */
410#define ILL_ILLOPN 2 /* illegal operand */
411#define ILL_ILLADR 3 /* illegal addressing mode */
412#define ILL_ILLTRP 4 /* illegal trap */
413#define ILL_PRVOPC 5 /* privileged opcode */
414#define ILL_PRVREG 6 /* privileged register */
415#define ILL_COPROC 7 /* coprocessor error */
416#define ILL_BADSTK 8 /* internal stack error */
417#define FPE_INTDIV 1 /* integer divide by zero */
418#define FPE_INTOVF 2 /* integer overflow */
419#define FPE_FLTDIV 3 /* floating point divide by zero */
420#define FPE_FLTOVF 4 /* floating point overflow */
421#define FPE_FLTUND 5 /* floating point underflow */
422#define FPE_FLTRES 6 /* floating point inexact result */
423#define FPE_FLTINV 7 /* floating point invalid operation */
424#define FPE_FLTSUB 8 /* subscript out of range */
425#define SEGV_MAPERR 1 /* address not mapped to object */
426#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
427#define BUS_ADRALN 1 /* invalid address alignment */
428#define BUS_ADRERR 2 /* non-existant physical address */
429#define BUS_OBJERR 3 /* object specific hardware error */
430#define TRAP_BRKPT 1 /* process breakpoint */
431#define TRAP_TRACE 2 /* process trace trap */
432#define CLD_EXITED 1 /* child has exited */
433#define CLD_KILLED 2 /* child was killed */
434#define CLD_DUMPED 3 /* child terminated abnormally */
435#define CLD_TRAPPED 4 /* traced child has trapped */
436#define CLD_STOPPED 5 /* child has stopped */
437#define CLD_CONTINUED 6 /* stopped child has continued */
438#define POLL_IN 1 /* data input available */
439#define POLL_OUT 2 /* output buffers available */
440#define POLL_MSG 3 /* input message available */
441#define POLL_ERR 4 /* i/o error */
442#define POLL_PRI 5 /* high priority input available */
443#define POLL_HUP 6 /* device disconnected */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000444#define SI_KERNEL 0x80 /* sent by kernel */
John Hughes58265892001-10-18 15:13:53 +0000445#define SI_USER 0 /* sent by kill, sigsend, raise */
446#define SI_QUEUE -1 /* sent by sigqueue */
447#define SI_TIMER -2 /* sent by timer expiration */
448#define SI_MESGQ -3 /* sent by real time mesq state change */
449#define SI_ASYNCIO -4 /* sent by AIO completion */
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000450#define SI_SIGIO -5 /* sent by SIGIO */
451#define SI_TKILL -6 /* sent by tkill */
452#define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
453
454#endif /* LINUX */
John Hughes58265892001-10-18 15:13:53 +0000455
456#if __GLIBC_MINOR__ < 1
457/* Type for data associated with a signal. */
458typedef union sigval
459{
460 int sival_int;
461 void *sival_ptr;
462} sigval_t;
463
464# define __SI_MAX_SIZE 128
465# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
466
467typedef struct siginfo
468{
469 int si_signo; /* Signal number. */
470 int si_errno; /* If non-zero, an errno value associated with
471 this signal, as defined in <errno.h>. */
472 int si_code; /* Signal code. */
473
474 union
475 {
476 int _pad[__SI_PAD_SIZE];
477
478 /* kill(). */
479 struct
480 {
481 __pid_t si_pid; /* Sending process ID. */
482 __uid_t si_uid; /* Real user ID of sending process. */
483 } _kill;
484
485 /* POSIX.1b timers. */
486 struct
487 {
488 unsigned int _timer1;
489 unsigned int _timer2;
490 } _timer;
491
492 /* POSIX.1b signals. */
493 struct
494 {
495 __pid_t si_pid; /* Sending process ID. */
496 __uid_t si_uid; /* Real user ID of sending process. */
497 sigval_t si_sigval; /* Signal value. */
498 } _rt;
499
500 /* SIGCHLD. */
501 struct
502 {
503 __pid_t si_pid; /* Which child. */
504 int si_status; /* Exit value or signal. */
505 __clock_t si_utime;
506 __clock_t si_stime;
507 } _sigchld;
508
509 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
510 struct
511 {
512 void *si_addr; /* Faulting insn/memory ref. */
513 } _sigfault;
514
515 /* SIGPOLL. */
516 struct
517 {
518 int si_band; /* Band event for SIGPOLL. */
519 int si_fd;
520 } _sigpoll;
521 } _sifields;
522} siginfo_t;
523
524#define si_pid _sifields._kill.si_pid
525#define si_uid _sifields._kill.si_uid
526#define si_status _sifields._sigchld.si_status
527#define si_utime _sifields._sigchld.si_utime
528#define si_stime _sifields._sigchld.si_stime
529#define si_value _sifields._rt.si_sigval
530#define si_int _sifields._rt.si_sigval.sival_int
531#define si_ptr _sifields._rt.si_sigval.sival_ptr
532#define si_addr _sifields._sigfault.si_addr
533#define si_band _sifields._sigpoll.si_band
534#define si_fd _sifields._sigpoll.si_fd
535
536#endif
537
538#endif
539
540#if defined (SVR4) || defined (LINUX)
541
Roland McGrathd9f816f2004-09-04 03:39:20 +0000542static const struct xlat siginfo_codes[] = {
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000543#ifdef SI_KERNEL
544 { SI_KERNEL, "SI_KERNEL" },
John Hughes58265892001-10-18 15:13:53 +0000545#endif
546#ifdef SI_USER
547 { SI_USER, "SI_USER" },
548#endif
John Hughes58265892001-10-18 15:13:53 +0000549#ifdef SI_QUEUE
550 { SI_QUEUE, "SI_QUEUE" },
551#endif
552#ifdef SI_TIMER
553 { SI_TIMER, "SI_TIMER" },
554#endif
John Hughes58265892001-10-18 15:13:53 +0000555#ifdef SI_MESGQ
556 { SI_MESGQ, "SI_MESGQ" },
557#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000558#ifdef SI_ASYNCIO
559 { SI_ASYNCIO, "SI_ASYNCIO" },
560#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000561#ifdef SI_SIGIO
562 { SI_SIGIO, "SI_SIGIO" },
563#endif
564#ifdef SI_TKILL
565 { SI_TKILL, "SI_TKILL" },
566#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000567#ifdef SI_ASYNCNL
568 { SI_ASYNCNL, "SI_ASYNCNL" },
569#endif
570#ifdef SI_NOINFO
571 { SI_NOINFO, "SI_NOINFO" },
572#endif
573#ifdef SI_LWP
574 { SI_LWP, "SI_LWP" },
575#endif
John Hughes58265892001-10-18 15:13:53 +0000576 { 0, NULL },
577};
578
Roland McGrathd9f816f2004-09-04 03:39:20 +0000579static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000580 { ILL_ILLOPC, "ILL_ILLOPC" },
581 { ILL_ILLOPN, "ILL_ILLOPN" },
582 { ILL_ILLADR, "ILL_ILLADR" },
583 { ILL_ILLTRP, "ILL_ILLTRP" },
584 { ILL_PRVOPC, "ILL_PRVOPC" },
585 { ILL_PRVREG, "ILL_PRVREG" },
586 { ILL_COPROC, "ILL_COPROC" },
587 { ILL_BADSTK, "ILL_BADSTK" },
588 { 0, NULL },
589};
590
Roland McGrathd9f816f2004-09-04 03:39:20 +0000591static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000592 { FPE_INTDIV, "FPE_INTDIV" },
593 { FPE_INTOVF, "FPE_INTOVF" },
594 { FPE_FLTDIV, "FPE_FLTDIV" },
595 { FPE_FLTOVF, "FPE_FLTOVF" },
596 { FPE_FLTUND, "FPE_FLTUND" },
597 { FPE_FLTRES, "FPE_FLTRES" },
598 { FPE_FLTINV, "FPE_FLTINV" },
599 { FPE_FLTSUB, "FPE_FLTSUB" },
600 { 0, NULL },
601};
602
Roland McGrathd9f816f2004-09-04 03:39:20 +0000603static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000604 { TRAP_BRKPT, "TRAP_BRKPT" },
605 { TRAP_TRACE, "TRAP_TRACE" },
606 { 0, NULL },
607};
608
Roland McGrathd9f816f2004-09-04 03:39:20 +0000609static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000610 { CLD_EXITED, "CLD_EXITED" },
611 { CLD_KILLED, "CLD_KILLED" },
612 { CLD_DUMPED, "CLD_DUMPED" },
613 { CLD_TRAPPED, "CLD_TRAPPED" },
614 { CLD_STOPPED, "CLD_STOPPED" },
615 { CLD_CONTINUED,"CLD_CONTINUED" },
616 { 0, NULL },
617};
618
Roland McGrathd9f816f2004-09-04 03:39:20 +0000619static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000620 { POLL_IN, "POLL_IN" },
621 { POLL_OUT, "POLL_OUT" },
622 { POLL_MSG, "POLL_MSG" },
623 { POLL_ERR, "POLL_ERR" },
624 { POLL_PRI, "POLL_PRI" },
625 { POLL_HUP, "POLL_HUP" },
626 { 0, NULL },
627};
628
Roland McGrathd9f816f2004-09-04 03:39:20 +0000629static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000630#ifdef PROF_SIG
631 { PROF_SIG, "PROF_SIG" },
632#endif
633 { 0, NULL },
634};
635
636#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000637static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000638#ifdef EMT_TAGOVF
639 { EMT_TAGOVF, "EMT_TAGOVF" },
640#endif
641 { 0, NULL },
642};
643#endif
644
Roland McGrathd9f816f2004-09-04 03:39:20 +0000645static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000646 { SEGV_MAPERR, "SEGV_MAPERR" },
647 { SEGV_ACCERR, "SEGV_ACCERR" },
648 { 0, NULL },
649};
650
Roland McGrathd9f816f2004-09-04 03:39:20 +0000651static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000652 { BUS_ADRALN, "BUS_ADRALN" },
653 { BUS_ADRERR, "BUS_ADRERR" },
654 { BUS_OBJERR, "BUS_OBJERR" },
655 { 0, NULL },
656};
657
658void
659printsiginfo(sip, verbose)
660siginfo_t *sip;
661int verbose;
662{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000663 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000664
665 if (sip->si_signo == 0) {
666 tprintf ("{}");
667 return;
668 }
669 tprintf("{si_signo=");
670 printsignal(sip->si_signo);
671 code = xlookup(siginfo_codes, sip->si_code);
672 if (!code) {
673 switch (sip->si_signo) {
674 case SIGTRAP:
675 code = xlookup(sigtrap_codes, sip->si_code);
676 break;
677 case SIGCHLD:
678 code = xlookup(sigchld_codes, sip->si_code);
679 break;
680 case SIGPOLL:
681 code = xlookup(sigpoll_codes, sip->si_code);
682 break;
683 case SIGPROF:
684 code = xlookup(sigprof_codes, sip->si_code);
685 break;
686 case SIGILL:
687 code = xlookup(sigill_codes, sip->si_code);
688 break;
689#ifdef SIGEMT
690 case SIGEMT:
691 code = xlookup(sigemt_codes, sip->si_code);
692 break;
693#endif
694 case SIGFPE:
695 code = xlookup(sigfpe_codes, sip->si_code);
696 break;
697 case SIGSEGV:
698 code = xlookup(sigsegv_codes, sip->si_code);
699 break;
700 case SIGBUS:
701 code = xlookup(sigbus_codes, sip->si_code);
702 break;
703 }
704 }
705 if (code)
706 tprintf(", si_code=%s", code);
707 else
708 tprintf(", si_code=%#x", sip->si_code);
709#ifdef SI_NOINFO
710 if (sip->si_code != SI_NOINFO)
711#endif
712 {
713 if (sip->si_errno) {
714 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
715 tprintf(", si_errno=%d", sip->si_errno);
716 else
717 tprintf(", si_errno=%s",
718 errnoent[sip->si_errno]);
719 }
720#ifdef SI_FROMUSER
721 if (SI_FROMUSER(sip)) {
722 tprintf(", si_pid=%ld, si_uid=%ld",
723 sip->si_pid, sip->si_uid);
724#ifdef SI_QUEUE
725 switch (sip->si_code) {
726 case SI_QUEUE:
727#ifdef SI_TIMER
728 case SI_TIMER:
729#endif /* SI_QUEUE */
730 case SI_ASYNCIO:
731#ifdef SI_MESGQ
732 case SI_MESGQ:
733#endif /* SI_MESGQ */
734 tprintf(", si_value=%d",
735 sip->si_value.sival_int);
736 break;
737 }
738#endif /* SI_QUEUE */
739 }
740 else
741#endif /* SI_FROMUSER */
742 {
743 switch (sip->si_signo) {
744 case SIGCHLD:
745 tprintf(", si_pid=%ld, si_status=",
746 (long) sip->si_pid);
747 if (sip->si_code == CLD_EXITED)
748 tprintf("%d", sip->si_status);
749 else
750 printsignal(sip->si_status);
751#if LINUX
752 if (!verbose)
753 tprintf(", ...");
754 else
755 tprintf(", si_utime=%lu, si_stime=%lu",
756 sip->si_utime,
757 sip->si_stime);
758#endif
759 break;
760 case SIGILL: case SIGFPE:
761 case SIGSEGV: case SIGBUS:
762 tprintf(", si_addr=%#lx",
763 (unsigned long) sip->si_addr);
764 break;
765 case SIGPOLL:
766 switch (sip->si_code) {
767 case POLL_IN: case POLL_OUT: case POLL_MSG:
768 tprintf(", si_band=%ld",
769 (long) sip->si_band);
770 break;
771 }
772 break;
773#ifdef LINUX
774 default:
775 tprintf(", si_pid=%lu, si_uid=%lu, ",
776 (unsigned long) sip->si_pid,
777 (unsigned long) sip->si_uid);
778 if (!verbose)
779 tprintf("...");
780 else {
781 tprintf("si_value={int=%u, ptr=%#lx}",
782 sip->si_int,
783 (unsigned long) sip->si_ptr);
784 }
785#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000786
John Hughes58265892001-10-18 15:13:53 +0000787 }
788 }
789 }
790 tprintf("}");
791}
792
793#endif /* SVR4 || LINUX */
794
795#ifdef LINUX
796
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000797static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000798parse_sigset_t(const char *str, sigset_t *set)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000799{
Roland McGrathc38feca2003-10-01 07:50:28 +0000800 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000801 unsigned int digit;
802 int i;
803
804 sigemptyset(set);
805
Roland McGrathc38feca2003-10-01 07:50:28 +0000806 p = strchr(str, '\n');
807 if (p == NULL)
808 p = strchr(str, '\0');
809 for (i = 0; p-- > str; i += 4) {
810 if (*p >= '0' && *p <= '9')
811 digit = *p - '0';
812 else if (*p >= 'a' && *p <= 'f')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000813 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000814 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000815 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000816 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000817 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000818 if (digit & 1)
819 sigaddset(set, i + 1);
820 if (digit & 2)
821 sigaddset(set, i + 2);
822 if (digit & 4)
823 sigaddset(set, i + 3);
824 if (digit & 8)
825 sigaddset(set, i + 4);
826 }
827}
828
829#endif
830
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000831/*
832 * Check process TCP for the disposition of signal SIG.
833 * Return 1 if the process would somehow manage to survive signal SIG,
834 * else return 0. This routine will never be called with SIGKILL.
835 */
836int
837sigishandled(tcp, sig)
838struct tcb *tcp;
839int sig;
840{
841#ifdef LINUX
842 int sfd;
843 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000844 char buf[2048];
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000845 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000846 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000847 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000848#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000849#ifdef SVR4
850 /*
851 * Since procfs doesn't interfere with wait I think it is safe
852 * to punt on this question. If not, the information is there.
853 */
854 return 1;
855#else /* !SVR4 */
856 switch (sig) {
857 case SIGCONT:
858 case SIGSTOP:
859 case SIGTSTP:
860 case SIGTTIN:
861 case SIGTTOU:
862 case SIGCHLD:
863 case SIGIO:
864#if defined(SIGURG) && SIGURG != SIGIO
865 case SIGURG:
866#endif
867 case SIGWINCH:
868 /* Gloria Gaynor says ... */
869 return 1;
870 default:
871 break;
872 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000873#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000874#ifdef LINUX
875
876 /* This is incredibly costly but it's worth it. */
877 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
878 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
879 doesn't handle real-time signals). */
880 sprintf(sname, "/proc/%d/status", tcp->pid);
881 if ((sfd = open(sname, O_RDONLY)) == -1) {
882 perror(sname);
883 return 1;
884 }
885 i = read(sfd, buf, sizeof(buf));
886 buf[i] = '\0';
887 close(sfd);
888 /*
889 * Skip the extraneous fields. We need to skip
890 * command name has any spaces in it. So be it.
891 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000892 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000893 if (!s)
894 {
895 fprintf(stderr, "/proc/pid/status format error\n");
896 return 1;
897 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000898 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000899
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000900 s = strstr(buf, "SigCgt:\t");
901 if (!s)
902 {
903 fprintf(stderr, "/proc/pid/status format error\n");
904 return 1;
905 }
906 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000907
908#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000909 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
910 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000911#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000912 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000913 return 1;
914#endif /* LINUX */
915
916#ifdef SUNOS4
917 void (*u_signal)();
918
Denys Vlasenko932fc7d2008-12-16 18:18:40 +0000919 if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal),
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000920 (long *) &u_signal) < 0) {
921 return 0;
922 }
923 if (u_signal != SIG_DFL)
924 return 1;
925#endif /* SUNOS4 */
926
927 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000928}
929
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000930#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000931
932int
933sys_sigvec(tcp)
934struct tcb *tcp;
935{
936 struct sigvec sv;
937 long addr;
938
939 if (entering(tcp)) {
940 printsignal(tcp->u_arg[0]);
941 tprintf(", ");
942 addr = tcp->u_arg[1];
943 } else {
944 addr = tcp->u_arg[2];
945 }
946 if (addr == 0)
947 tprintf("NULL");
948 else if (!verbose(tcp))
949 tprintf("%#lx", addr);
950 else if (umove(tcp, addr, &sv) < 0)
951 tprintf("{...}");
952 else {
953 switch ((int) sv.sv_handler) {
954 case (int) SIG_ERR:
955 tprintf("{SIG_ERR}");
956 break;
957 case (int) SIG_DFL:
958 tprintf("{SIG_DFL}");
959 break;
960 case (int) SIG_IGN:
961 if (tcp->u_arg[0] == SIGTRAP) {
962 tcp->flags |= TCB_SIGTRAPPED;
963 kill(tcp->pid, SIGSTOP);
964 }
965 tprintf("{SIG_IGN}");
966 break;
967 case (int) SIG_HOLD:
968 if (tcp->u_arg[0] == SIGTRAP) {
969 tcp->flags |= TCB_SIGTRAPPED;
970 kill(tcp->pid, SIGSTOP);
971 }
972 tprintf("SIG_HOLD");
973 break;
974 default:
975 if (tcp->u_arg[0] == SIGTRAP) {
976 tcp->flags |= TCB_SIGTRAPPED;
977 kill(tcp->pid, SIGSTOP);
978 }
979 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000980 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000981 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000982 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983 tprintf("}");
984 }
985 }
986 if (entering(tcp))
987 tprintf(", ");
988 return 0;
989}
990
991int
992sys_sigpause(tcp)
993struct tcb *tcp;
994{
995 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000996 sigset_t sigm;
997 long_to_sigset(tcp->u_arg[0], &sigm);
998 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000999 }
1000 return 0;
1001}
1002
1003int
1004sys_sigstack(tcp)
1005struct tcb *tcp;
1006{
1007 struct sigstack ss;
1008 long addr;
1009
1010 if (entering(tcp))
1011 addr = tcp->u_arg[0];
1012 else
1013 addr = tcp->u_arg[1];
1014 if (addr == 0)
1015 tprintf("NULL");
1016 else if (umove(tcp, addr, &ss) < 0)
1017 tprintf("%#lx", addr);
1018 else {
1019 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1020 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1021 }
1022 if (entering(tcp))
1023 tprintf(", ");
1024 return 0;
1025}
1026
1027int
1028sys_sigcleanup(tcp)
1029struct tcb *tcp;
1030{
1031 return 0;
1032}
1033
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001034#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001035
1036#ifndef SVR4
1037
1038int
1039sys_sigsetmask(tcp)
1040struct tcb *tcp;
1041{
1042 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001044 long_to_sigset(tcp->u_arg[0], &sigm);
1045 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001046#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001047 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1048 /* Mark attempt to block SIGTRAP */
1049 tcp->flags |= TCB_SIGTRAPPED;
1050 /* Send unblockable signal */
1051 kill(tcp->pid, SIGSTOP);
1052 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001053#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001054 }
1055 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001056 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001057 long_to_sigset(tcp->u_rval, &sigm);
1058 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001059
1060 return RVAL_HEX | RVAL_STR;
1061 }
1062 return 0;
1063}
1064
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001065#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001066int
1067sys_sigblock(tcp)
1068struct tcb *tcp;
1069{
1070 return sys_sigsetmask(tcp);
1071}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001072#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001073
1074#endif /* !SVR4 */
1075
1076#ifdef HAVE_SIGACTION
1077
1078#ifdef LINUX
1079struct old_sigaction {
1080 __sighandler_t __sa_handler;
1081 unsigned long sa_mask;
1082 unsigned long sa_flags;
1083 void (*sa_restorer)(void);
1084};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001085#define SA_HANDLER __sa_handler
1086#endif /* LINUX */
1087
Roland McGratha39c5a12002-12-17 05:10:37 +00001088#ifndef SA_HANDLER
1089#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001090#endif
1091
1092int
1093sys_sigaction(tcp)
1094struct tcb *tcp;
1095{
1096 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001097#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001098 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001100#else
1101 struct sigaction sa;
1102#endif
1103
1104
1105 if (entering(tcp)) {
1106 printsignal(tcp->u_arg[0]);
1107 tprintf(", ");
1108 addr = tcp->u_arg[1];
1109 } else
1110 addr = tcp->u_arg[2];
1111 if (addr == 0)
1112 tprintf("NULL");
1113 else if (!verbose(tcp))
1114 tprintf("%#lx", addr);
1115 else if (umove(tcp, addr, &sa) < 0)
1116 tprintf("{...}");
1117 else {
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001118 /* Architectures using function pointers, like
1119 * hppa, may need to manipulate the function pointer
1120 * to compute the result of a comparison. However,
1121 * the SA_HANDLER function pointer exists only in
1122 * the address space of the traced process, and can't
1123 * be manipulated by strace. In order to prevent the
1124 * compiler from generating code to manipulate
1125 * SA_HANDLER we cast the function pointers to long. */
1126 if ((long)sa.SA_HANDLER == (long)SIG_ERR)
Roland McGrath5f206812008-08-20 01:59:40 +00001127 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001128 else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
Roland McGrath5f206812008-08-20 01:59:40 +00001129 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001130 else if ((long)sa.SA_HANDLER == (long)SIG_IGN) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001131#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001132 if (tcp->u_arg[0] == SIGTRAP) {
1133 tcp->flags |= TCB_SIGTRAPPED;
1134 kill(tcp->pid, SIGSTOP);
1135 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001136#endif /* !USE_PROCFS */
Roland McGrath5f206812008-08-20 01:59:40 +00001137 tprintf("{SIG_IGN, ");
1138 }
1139 else {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001140#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001141 if (tcp->u_arg[0] == SIGTRAP) {
1142 tcp->flags |= TCB_SIGTRAPPED;
1143 kill(tcp->pid, SIGSTOP);
1144 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001145#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001146 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001147#ifndef LINUX
1148 printsigmask (&sa.sa_mask, 0);
1149#else
Nate Sammons4a121431999-04-06 01:19:39 +00001150 long_to_sigset(sa.sa_mask, &sigset);
1151 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001152#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001153 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001154 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001155#ifdef SA_RESTORER
1156 if (sa.sa_flags & SA_RESTORER)
1157 tprintf(", %p", sa.sa_restorer);
1158#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001159 tprintf("}");
1160 }
1161 }
1162 if (entering(tcp))
1163 tprintf(", ");
1164#ifdef LINUX
1165 else
1166 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1167#endif
1168 return 0;
1169}
1170
1171int
1172sys_signal(tcp)
1173struct tcb *tcp;
1174{
1175 if (entering(tcp)) {
1176 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001177 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001178 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001179 case (long) SIG_ERR:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001180 tprintf("SIG_ERR");
1181 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001182 case (long) SIG_DFL:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001183 tprintf("SIG_DFL");
1184 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001185 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001186#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001187 if (tcp->u_arg[0] == SIGTRAP) {
1188 tcp->flags |= TCB_SIGTRAPPED;
1189 kill(tcp->pid, SIGSTOP);
1190 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001191#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001192 tprintf("SIG_IGN");
1193 break;
1194 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001195#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001196 if (tcp->u_arg[0] == SIGTRAP) {
1197 tcp->flags |= TCB_SIGTRAPPED;
1198 kill(tcp->pid, SIGSTOP);
1199 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001200#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001201 tprintf("%#lx", tcp->u_arg[1]);
1202 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001203 return 0;
1204 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001205 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001206 switch (tcp->u_rval) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001207 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001208 tcp->auxstr = "SIG_ERR"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001209 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001210 tcp->auxstr = "SIG_DFL"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001211 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001212 tcp->auxstr = "SIG_IGN"; break;
1213 default:
1214 tcp->auxstr = NULL;
1215 }
1216 return RVAL_HEX | RVAL_STR;
1217 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001218 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001219}
1220
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001221#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001222int
1223sys_sighold(tcp)
1224struct tcb *tcp;
1225{
1226 if (entering(tcp)) {
1227 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228 }
1229 return 0;
1230}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001231#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001232
1233#endif /* HAVE_SIGACTION */
1234
1235#ifdef LINUX
1236
1237int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001238sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001239{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001240#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001241 struct pt_regs regs;
1242 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001243
Roland McGrath0f87c492003-06-03 23:29:04 +00001244 if (entering(tcp)) {
1245 tcp->u_arg[0] = 0;
1246
1247 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1248 return 0;
1249
1250 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1251 return 0;
1252
1253 tcp->u_arg[0] = 1;
1254 tcp->u_arg[1] = sc.oldmask;
1255 } else {
1256 sigset_t sigm;
1257 long_to_sigset(tcp->u_arg[1], &sigm);
1258 tcp->u_rval = tcp->u_error = 0;
1259 if (tcp->u_arg[0] == 0)
1260 return 0;
1261 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1262 return RVAL_NONE | RVAL_STR;
1263 }
1264 return 0;
1265#elif defined(S390) || defined(S390X)
1266 long usp;
1267 struct sigcontext_struct sc;
1268
1269 if (entering(tcp)) {
1270 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001271 if (upeek(tcp,PT_GPR15,&usp)<0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001272 return 0;
1273 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1274 return 0;
1275 tcp->u_arg[0] = 1;
1276 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1277 } else {
1278 tcp->u_rval = tcp->u_error = 0;
1279 if (tcp->u_arg[0] == 0)
1280 return 0;
1281 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1282 return RVAL_NONE | RVAL_STR;
1283 }
1284 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001285#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001286 long esp;
1287 struct sigcontext_struct sc;
1288
1289 if (entering(tcp)) {
1290 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001291 if (upeek(tcp, 4*UESP, &esp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 return 0;
1293 if (umove(tcp, esp, &sc) < 0)
1294 return 0;
1295 tcp->u_arg[0] = 1;
1296 tcp->u_arg[1] = sc.oldmask;
1297 }
1298 else {
1299 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001300 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001301 tcp->u_rval = tcp->u_error = 0;
1302 if (tcp->u_arg[0] == 0)
1303 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001304 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305 return RVAL_NONE | RVAL_STR;
1306 }
1307 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001308#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001309 struct sigcontext sc;
1310 long sp;
1311
1312 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001313 /* offset of sigcontext in the kernel's sigframe structure: */
1314# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001315 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001316 if (upeek(tcp, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001317 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001318 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001319 return 0;
1320 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001321 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001322 }
1323 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001324 sigset_t sigm;
1325
1326 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001327 tcp->u_rval = tcp->u_error = 0;
1328 if (tcp->u_arg[0] == 0)
1329 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001330 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001331 return RVAL_NONE | RVAL_STR;
1332 }
1333 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001334#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +00001335 long esp;
1336 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001337
Roland McGrath0f87c492003-06-03 23:29:04 +00001338 if (entering(tcp)) {
1339 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001340 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001341 return 0;
Andreas Schwabedb39342010-02-23 00:18:51 +01001342 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +02001343#ifdef POWERPC64
1344 if (current_personality == 0)
1345 esp += 128;
1346 else
1347 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +01001348#else
1349 esp += 64;
1350#endif
Roland McGrath0f87c492003-06-03 23:29:04 +00001351 if (umove(tcp, esp, &sc) < 0)
1352 return 0;
1353 tcp->u_arg[0] = 1;
1354 tcp->u_arg[1] = sc.oldmask;
1355 }
1356 else {
1357 sigset_t sigm;
1358 long_to_sigset(tcp->u_arg[1], &sigm);
1359 tcp->u_rval = tcp->u_error = 0;
1360 if (tcp->u_arg[0] == 0)
1361 return 0;
1362 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1363 return RVAL_NONE | RVAL_STR;
1364 }
1365 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001366#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001367 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001368 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001369
1370 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001371 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001372 if (upeek(tcp, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001373 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001374 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001375 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001376 tcp->u_arg[0] = 1;
1377 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378 }
1379 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001380 sigset_t sigm;
1381 long_to_sigset(tcp->u_arg[1], &sigm);
1382 tcp->u_rval = tcp->u_error = 0;
1383 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001384 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001385 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1386 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001387 }
1388 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001389#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001390 long fp;
1391 struct sigcontext_struct sc;
1392
1393 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001394 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001395 if (upeek(tcp, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001396 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001397 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001398 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001399 tcp->u_arg[0] = 1;
1400 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001401 }
1402 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001403 sigset_t sigm;
1404 long_to_sigset(tcp->u_arg[1], &sigm);
1405 tcp->u_rval = tcp->u_error = 0;
1406 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001407 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001408 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1409 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001410 }
1411 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001412#elif defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413 long i1;
Mike Frysinger8566c502009-10-12 11:05:14 -04001414 struct pt_regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001415 m_siginfo_t si;
1416
Roland McGratheb9e2e82009-06-02 16:49:22 -07001417 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1418 perror("sigreturn: PTRACE_GETREGS ");
Roland McGrath0f87c492003-06-03 23:29:04 +00001419 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001420 }
Roland McGratheb9e2e82009-06-02 16:49:22 -07001421 if(entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001422 tcp->u_arg[0] = 0;
Mike Frysinger8566c502009-10-12 11:05:14 -04001423 i1 = regs.u_regs[U_REG_O1];
Roland McGratheb9e2e82009-06-02 16:49:22 -07001424 if(umove(tcp, i1, &si) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001425 perror("sigreturn: umove ");
1426 return 0;
1427 }
1428 tcp->u_arg[0] = 1;
1429 tcp->u_arg[1] = si.si_mask;
1430 } else {
1431 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001432 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433 tcp->u_rval = tcp->u_error = 0;
1434 if(tcp->u_arg[0] == 0)
1435 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001436 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001437 return RVAL_NONE | RVAL_STR;
1438 }
1439 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001440#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001441 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1442 sigreturn. */
1443 long sp;
1444 struct ucontext uc;
1445
1446 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001447 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001448 if (upeek(tcp, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001449 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001450 /* There are six words followed by a 128-byte siginfo. */
1451 sp = sp + 6 * 4 + 128;
1452 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001453 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001454 tcp->u_arg[0] = 1;
1455 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1456 } else {
1457 sigset_t sigm;
1458 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001459 tcp->u_rval = tcp->u_error = 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001460 if(tcp->u_arg[0] == 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001461 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001462 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1463 return RVAL_NONE | RVAL_STR;
1464 }
1465 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001466#elif defined(MIPS)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001467 long sp;
Roland McGrath576b7842007-11-04 00:00:00 +00001468 struct pt_regs regs;
1469 m_siginfo_t si;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001470
Roland McGrath576b7842007-11-04 00:00:00 +00001471 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1472 perror("sigreturn: PTRACE_GETREGS ");
1473 return 0;
1474 }
Wichert Akkermanf90da011999-10-31 21:15:38 +00001475 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001476 tcp->u_arg[0] = 0;
Roland McGrath576b7842007-11-04 00:00:00 +00001477 sp = regs.regs[29];
1478 if (umove(tcp, sp, &si) < 0)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001479 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001480 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001481 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001482 sigset_t sigm;
1483 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001484 tcp->u_rval = tcp->u_error = 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001485 if(tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001486 return 0;
1487 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001488 return RVAL_NONE | RVAL_STR;
1489 }
1490 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001491#elif defined(CRISV10) || defined(CRISV32)
1492 struct sigcontext sc;
1493
1494 if (entering(tcp)) {
1495 long regs[PT_MAX+1];
1496
1497 tcp->u_arg[0] = 0;
1498
1499 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1500 perror("sigreturn: PTRACE_GETREGS");
1501 return 0;
1502 }
1503 if (umove(tcp, regs[PT_USP], &sc) < 0)
1504 return 0;
1505 tcp->u_arg[0] = 1;
1506 tcp->u_arg[1] = sc.oldmask;
1507 } else {
1508 sigset_t sigm;
1509 long_to_sigset(tcp->u_arg[1], &sigm);
1510 tcp->u_rval = tcp->u_error = 0;
1511
1512 if (tcp->u_arg[0] == 0)
1513 return 0;
1514 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1515 return RVAL_NONE | RVAL_STR;
1516 }
1517 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -05001518#elif defined(TILE)
1519 struct ucontext uc;
1520 long sp;
1521
1522 /* offset of ucontext in the kernel's sigframe structure */
1523# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo)
1524
1525 if (entering(tcp)) {
1526 tcp->u_arg[0] = 0;
1527 if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0)
1528 return 0;
1529 if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1530 return 0;
1531 tcp->u_arg[0] = 1;
1532 memcpy(tcp->u_arg + 1, &uc.uc_sigmask, sizeof(uc.uc_sigmask));
1533 }
1534 else {
1535 sigset_t sigm;
1536
1537 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
1538 tcp->u_rval = tcp->u_error = 0;
1539 if (tcp->u_arg[0] == 0)
1540 return 0;
1541 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1542 return RVAL_NONE | RVAL_STR;
1543 }
1544 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001545#elif defined(MICROBLAZE)
1546 struct sigcontext sc;
1547
1548 /* TODO: Verify that this is correct... */
1549 if (entering(tcp)) {
1550 long sp;
1551
1552 tcp->u_arg[0] = 0;
1553
1554 /* Read r1, the stack pointer. */
1555 if (upeek(tcp, 1 * 4, &sp) < 0)
1556 return 0;
1557 if (umove(tcp, sp, &sc) < 0)
1558 return 0;
1559 tcp->u_arg[0] = 1;
1560 tcp->u_arg[1] = sc.oldmask;
1561 } else {
1562 sigset_t sigm;
1563 long_to_sigset(tcp->u_arg[1], &sigm);
1564 tcp->u_rval = tcp->u_error = 0;
1565 if (tcp->u_arg[0] == 0)
1566 return 0;
1567 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1568 return RVAL_NONE | RVAL_STR;
1569 }
1570 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001571#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001572#warning No sys_sigreturn() for this architecture
1573#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001574 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001575#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576}
1577
1578int
1579sys_siggetmask(tcp)
1580struct tcb *tcp;
1581{
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
1606sys_sigsuspend(tcp)
1607struct tcb *tcp;
1608{
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
1661printcontext(tcp, ucp)
1662struct tcb *tcp;
1663ucontext_t *ucp;
1664{
1665 tprintf("{");
1666 if (!abbrev(tcp)) {
1667 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001668 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001669 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1670 }
1671 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001672 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001673 if (!abbrev(tcp)) {
1674 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1675 (unsigned long) ucp->uc_stack.ss_sp,
1676 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001677 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001678 tprintf("}");
1679 }
1680 tprintf(", ...}");
1681}
1682
1683int
1684sys_getcontext(tcp)
1685struct tcb *tcp;
1686{
1687 ucontext_t uc;
1688
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001689 if (exiting(tcp)) {
1690 if (tcp->u_error)
1691 tprintf("%#lx", tcp->u_arg[0]);
1692 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001693 tprintf("NULL");
1694 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1695 tprintf("{...}");
1696 else
1697 printcontext(tcp, &uc);
1698 }
1699 return 0;
1700}
1701
1702int
1703sys_setcontext(tcp)
1704struct tcb *tcp;
1705{
1706 ucontext_t uc;
1707
1708 if (entering(tcp)) {
1709 if (!tcp->u_arg[0])
1710 tprintf("NULL");
1711 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1712 tprintf("{...}");
1713 else
1714 printcontext(tcp, &uc);
1715 }
1716 else {
1717 tcp->u_rval = tcp->u_error = 0;
1718 if (tcp->u_arg[0] == 0)
1719 return 0;
1720 return RVAL_NONE;
1721 }
1722 return 0;
1723}
1724
1725#endif /* SVR4 */
1726
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001727#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001728
1729static int
1730print_stack_t(tcp, addr)
1731struct tcb *tcp;
1732unsigned long addr;
1733{
1734 stack_t ss;
1735 if (umove(tcp, addr, &ss) < 0)
1736 return -1;
1737 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001738 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001739 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1740 return 0;
1741}
1742
1743int
1744sys_sigaltstack(tcp)
1745 struct tcb *tcp;
1746{
1747 if (entering(tcp)) {
1748 if (tcp->u_arg[0] == 0)
1749 tprintf("NULL");
1750 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1751 return -1;
1752 }
1753 else {
1754 tprintf(", ");
1755 if (tcp->u_arg[1] == 0)
1756 tprintf("NULL");
1757 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1758 return -1;
1759 }
1760 return 0;
1761}
1762#endif
1763
1764#ifdef HAVE_SIGACTION
1765
1766int
1767sys_sigprocmask(tcp)
1768struct tcb *tcp;
1769{
1770#ifdef ALPHA
1771 if (entering(tcp)) {
1772 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1773 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001774 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001775 }
1776 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001777 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001778 return RVAL_HEX | RVAL_STR;
1779 }
1780#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001781 if (entering(tcp)) {
1782#ifdef SVR4
1783 if (tcp->u_arg[0] == 0)
1784 tprintf("0");
1785 else
1786#endif /* SVR4 */
1787 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1788 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001789 print_sigset(tcp, tcp->u_arg[1], 0);
1790 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791 }
1792 else {
1793 if (!tcp->u_arg[2])
1794 tprintf("NULL");
1795 else if (syserror(tcp))
1796 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001797 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001798 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001799 }
1800#endif /* !ALPHA */
1801 return 0;
1802}
1803
1804#endif /* HAVE_SIGACTION */
1805
1806int
1807sys_kill(tcp)
1808struct tcb *tcp;
1809{
1810 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001811 /*
1812 * Sign-extend a 32-bit value when that's what it is.
1813 */
1814 long pid = tcp->u_arg[0];
1815 if (personality_wordsize[current_personality] < sizeof pid)
1816 pid = (long) (int) pid;
1817 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001818 }
1819 return 0;
1820}
1821
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001822#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001823int
1824sys_killpg(tcp)
1825struct tcb *tcp;
1826{
1827 return sys_kill(tcp);
1828}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001829#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001830
Roland McGrath8ffc3522003-07-09 09:47:49 +00001831#ifdef LINUX
1832int
1833sys_tgkill(tcp)
1834 struct tcb *tcp;
1835{
1836 if (entering(tcp)) {
1837 tprintf("%ld, %ld, %s",
1838 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1839 }
1840 return 0;
1841}
1842#endif
1843
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001844int
1845sys_sigpending(tcp)
1846struct tcb *tcp;
1847{
1848 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849
1850 if (exiting(tcp)) {
1851 if (syserror(tcp))
1852 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001853 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001854 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001855 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001856 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001857 }
1858 return 0;
1859}
1860
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001861#ifdef SVR4
John Hughes42162082001-10-18 14:48:26 +00001862int sys_sigwait(tcp)
1863struct tcb *tcp;
1864{
1865 sigset_t sigset;
1866
1867 if (entering(tcp)) {
1868 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1869 tprintf("[?]");
1870 else
1871 printsigmask(&sigset, 0);
1872 }
1873 else {
1874 if (!syserror(tcp)) {
1875 tcp->auxstr = signalent[tcp->u_rval];
1876 return RVAL_DECIMAL | RVAL_STR;
1877 }
1878 }
1879 return 0;
1880}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001881#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001882
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883#ifdef LINUX
1884
1885 int
1886sys_rt_sigprocmask(tcp)
1887 struct tcb *tcp;
1888{
1889 sigset_t sigset;
1890
Nate Sammons4a121431999-04-06 01:19:39 +00001891 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001892 if (entering(tcp)) {
1893 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1894 tprintf(", ");
1895 if (!tcp->u_arg[1])
1896 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001897 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001898 tprintf("%#lx, ", tcp->u_arg[1]);
1899 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001900 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001901 tprintf(", ");
1902 }
1903 }
1904 else {
1905 if (!tcp->u_arg[2])
1906
1907 tprintf("NULL");
1908 else if (syserror(tcp))
1909 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001910 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001911 tprintf("[?]");
1912 else
Nate Sammons4a121431999-04-06 01:19:39 +00001913 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001914 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001915 }
1916 return 0;
1917}
1918
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001919
1920/* Structure describing the action to be taken when a signal arrives. */
1921struct new_sigaction
1922{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001923 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001924 unsigned long sa_flags;
1925 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001926 /* Kernel treats sa_mask as an array of longs. */
1927 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1928};
1929/* Same for i386-on-x86_64 and similar cases */
1930struct new_sigaction32
1931{
1932 uint32_t __sa_handler;
1933 uint32_t sa_flags;
1934 uint32_t sa_restorer;
1935 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001936};
1937
1938
Roland McGrath5f206812008-08-20 01:59:40 +00001939int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001940sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001941{
1942 struct new_sigaction sa;
1943 sigset_t sigset;
1944 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001945 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001946
1947 if (entering(tcp)) {
1948 printsignal(tcp->u_arg[0]);
1949 tprintf(", ");
1950 addr = tcp->u_arg[1];
1951 } else
1952 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001953
1954 if (addr == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001955 tprintf("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001956 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001957 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001958 if (!verbose(tcp)) {
1959 tprintf("%#lx", addr);
1960 goto after_sa;
1961 }
1962#if SUPPORTED_PERSONALITIES > 1
1963 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1964 && personality_wordsize[current_personality] == 4
1965 ) {
1966 struct new_sigaction32 sa32;
1967 r = umove(tcp, addr, &sa32);
1968 if (r >= 0) {
1969 memset(&sa, 0, sizeof(sa));
1970 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1971 sa.sa_flags = sa32.sa_flags;
1972 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1973 /* Kernel treats sa_mask as an array of longs.
1974 * For 32-bit process, "long" is uint32_t, thus, for example,
1975 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1976 * But for (64-bit) kernel, 32th bit in sa_mask is
1977 * 32th bit in 0th (64-bit) long!
1978 * For little-endian, it's the same.
1979 * For big-endian, we swap 32-bit words.
1980 */
1981 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1982 }
1983 } else
1984#endif
1985 {
1986 r = umove(tcp, addr, &sa);
1987 }
1988 if (r < 0) {
1989 tprintf("{...}");
1990 goto after_sa;
1991 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001992 /* Architectures using function pointers, like
1993 * hppa, may need to manipulate the function pointer
1994 * to compute the result of a comparison. However,
1995 * the SA_HANDLER function pointer exists only in
1996 * the address space of the traced process, and can't
1997 * be manipulated by strace. In order to prevent the
1998 * compiler from generating code to manipulate
1999 * SA_HANDLER we cast the function pointers to long. */
2000 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00002001 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00002002 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00002003 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00002004 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00002005 tprintf("{SIG_IGN, ");
2006 else
2007 tprintf("{%#lx, ", (long) sa.__sa_handler);
2008 /* Questionable code below.
2009 * Kernel won't handle sys_rt_sigaction
2010 * with wrong sigset size (just returns EINVAL)
2011 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
2012 * and we always use smaller memcpy. */
2013 sigemptyset(&sigset);
2014#ifdef LINUXSPARC
2015 if (tcp->u_arg[4] <= sizeof(sigset))
2016 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
2017#else
2018 if (tcp->u_arg[3] <= sizeof(sigset))
2019 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
2020#endif
2021 else
2022 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
2023 printsigmask(&sigset, 1);
2024 tprintf(", ");
2025 printflags(sigact_flags, sa.sa_flags, "SA_???");
2026#ifdef SA_RESTORER
2027 if (sa.sa_flags & SA_RESTORER)
2028 tprintf(", %p", sa.sa_restorer);
2029#endif
2030 tprintf("}");
2031
2032 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002033 if (entering(tcp))
2034 tprintf(", ");
2035 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00002036#ifdef LINUXSPARC
2037 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
2038#elif defined(ALPHA)
2039 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
2040#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00002041 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00002042#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002043 return 0;
2044}
2045
Denys Vlasenko1d632462009-04-14 12:51:00 +00002046int
2047sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002048{
2049 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002050
2051 if (exiting(tcp)) {
2052 if (syserror(tcp))
2053 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00002054 else if (copy_sigset_len(tcp, tcp->u_arg[0],
2055 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002056 tprintf("[?]");
2057 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002058 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002059 }
2060 return 0;
2061}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002062
2063int
2064sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002065{
2066 if (entering(tcp)) {
2067 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00002068 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
2069 tprintf("[?]");
2070 else
2071 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002072 }
2073 return 0;
2074}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002075
2076int
2077sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002078{
2079 if (entering(tcp)) {
2080 siginfo_t si;
2081 tprintf("%lu, ", tcp->u_arg[0]);
2082 printsignal(tcp->u_arg[1]);
2083 tprintf(", ");
2084 if (umove(tcp, tcp->u_arg[2], &si) < 0)
2085 tprintf("%#lx", tcp->u_arg[2]);
2086 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002087 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002088 }
2089 return 0;
2090}
2091
Denys Vlasenko1d632462009-04-14 12:51:00 +00002092int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002093{
2094 if (entering(tcp)) {
2095 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002096
Roland McGratha39c5a12002-12-17 05:10:37 +00002097 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00002098 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002099 tprintf("[?]");
2100 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002101 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002102 tprintf(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002103 /* This is the only "return" parameter, */
2104 if (tcp->u_arg[1] != 0)
2105 return 0;
2106 /* ... if it's NULL, can decode all on entry */
2107 tprintf("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002108 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002109 else if (tcp->u_arg[1] != 0) {
2110 /* syscall exit, and u_arg[1] wasn't NULL */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002111 if (syserror(tcp))
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002112 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002113 else {
2114 siginfo_t si;
2115 if (umove(tcp, tcp->u_arg[1], &si) < 0)
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002116 tprintf("%#lx, ", tcp->u_arg[1]);
2117 else {
Denys Vlasenkof535b542009-01-13 18:30:55 +00002118 printsiginfo(&si, verbose(tcp));
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002119 tprintf(", ");
2120 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002121 }
2122 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002123 else {
2124 /* syscall exit, and u_arg[1] was NULL */
2125 return 0;
2126 }
2127 print_timespec(tcp, tcp->u_arg[2]);
2128 tprintf(", %d", (int) tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002129 return 0;
2130};
2131
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002132int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002133sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002134{
2135 if (entering(tcp))
2136 tprintf("<... resuming interrupted call ...>");
2137 return 0;
2138}
2139
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002140static int
2141do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00002142{
2143 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002144 printfd(tcp, tcp->u_arg[0]);
2145 tprintf(", ");
Roland McGrathf46ccd32007-08-02 01:15:59 +00002146 print_sigset(tcp, tcp->u_arg[1], 1);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00002147 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002148 if (flags_arg >= 0) {
2149 tprintf(", ");
2150 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2151 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00002152 }
2153 return 0;
2154}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002155
2156int
2157sys_signalfd(struct tcb *tcp)
2158{
2159 return do_signalfd(tcp, -1);
2160}
2161
2162int
2163sys_signalfd4(struct tcb *tcp)
2164{
2165 return do_signalfd(tcp, 3);
2166}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002167#endif /* LINUX */