blob: eb658d7923ef2a97c1af9b1f8c01a71635863fad [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 */
444#define SI_USER 0 /* sent by kill, sigsend, raise */
445#define SI_QUEUE -1 /* sent by sigqueue */
446#define SI_TIMER -2 /* sent by timer expiration */
447#define SI_MESGQ -3 /* sent by real time mesq state change */
448#define SI_ASYNCIO -4 /* sent by AIO completion */
Roland McGrath941b7402003-05-23 00:29:02 +0000449#define SI_SIGIO -5 /* Sent by SIGIO */
450#define SI_TKILL -6 /* Sent by tkill */
John Hughes58265892001-10-18 15:13:53 +0000451#endif
452
453#if __GLIBC_MINOR__ < 1
454/* Type for data associated with a signal. */
455typedef union sigval
456{
457 int sival_int;
458 void *sival_ptr;
459} sigval_t;
460
461# define __SI_MAX_SIZE 128
462# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
463
464typedef struct siginfo
465{
466 int si_signo; /* Signal number. */
467 int si_errno; /* If non-zero, an errno value associated with
468 this signal, as defined in <errno.h>. */
469 int si_code; /* Signal code. */
470
471 union
472 {
473 int _pad[__SI_PAD_SIZE];
474
475 /* kill(). */
476 struct
477 {
478 __pid_t si_pid; /* Sending process ID. */
479 __uid_t si_uid; /* Real user ID of sending process. */
480 } _kill;
481
482 /* POSIX.1b timers. */
483 struct
484 {
485 unsigned int _timer1;
486 unsigned int _timer2;
487 } _timer;
488
489 /* POSIX.1b signals. */
490 struct
491 {
492 __pid_t si_pid; /* Sending process ID. */
493 __uid_t si_uid; /* Real user ID of sending process. */
494 sigval_t si_sigval; /* Signal value. */
495 } _rt;
496
497 /* SIGCHLD. */
498 struct
499 {
500 __pid_t si_pid; /* Which child. */
501 int si_status; /* Exit value or signal. */
502 __clock_t si_utime;
503 __clock_t si_stime;
504 } _sigchld;
505
506 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
507 struct
508 {
509 void *si_addr; /* Faulting insn/memory ref. */
510 } _sigfault;
511
512 /* SIGPOLL. */
513 struct
514 {
515 int si_band; /* Band event for SIGPOLL. */
516 int si_fd;
517 } _sigpoll;
518 } _sifields;
519} siginfo_t;
520
521#define si_pid _sifields._kill.si_pid
522#define si_uid _sifields._kill.si_uid
523#define si_status _sifields._sigchld.si_status
524#define si_utime _sifields._sigchld.si_utime
525#define si_stime _sifields._sigchld.si_stime
526#define si_value _sifields._rt.si_sigval
527#define si_int _sifields._rt.si_sigval.sival_int
528#define si_ptr _sifields._rt.si_sigval.sival_ptr
529#define si_addr _sifields._sigfault.si_addr
530#define si_band _sifields._sigpoll.si_band
531#define si_fd _sifields._sigpoll.si_fd
532
533#endif
534
535#endif
536
537#if defined (SVR4) || defined (LINUX)
538
Roland McGrathd9f816f2004-09-04 03:39:20 +0000539static const struct xlat siginfo_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000540#ifdef SI_NOINFO
541 { SI_NOINFO, "SI_NOINFO" },
542#endif
543#ifdef SI_USER
544 { SI_USER, "SI_USER" },
545#endif
546#ifdef SI_LWP
547 { SI_LWP, "SI_LWP" },
548#endif
549#ifdef SI_QUEUE
550 { SI_QUEUE, "SI_QUEUE" },
551#endif
552#ifdef SI_TIMER
553 { SI_TIMER, "SI_TIMER" },
554#endif
555#ifdef SI_ASYNCIO
556 { SI_ASYNCIO, "SI_ASYNCIO" },
557#endif
558#ifdef SI_MESGQ
559 { SI_MESGQ, "SI_MESGQ" },
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
John Hughes58265892001-10-18 15:13:53 +0000567 { 0, NULL },
568};
569
Roland McGrathd9f816f2004-09-04 03:39:20 +0000570static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000571 { ILL_ILLOPC, "ILL_ILLOPC" },
572 { ILL_ILLOPN, "ILL_ILLOPN" },
573 { ILL_ILLADR, "ILL_ILLADR" },
574 { ILL_ILLTRP, "ILL_ILLTRP" },
575 { ILL_PRVOPC, "ILL_PRVOPC" },
576 { ILL_PRVREG, "ILL_PRVREG" },
577 { ILL_COPROC, "ILL_COPROC" },
578 { ILL_BADSTK, "ILL_BADSTK" },
579 { 0, NULL },
580};
581
Roland McGrathd9f816f2004-09-04 03:39:20 +0000582static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000583 { FPE_INTDIV, "FPE_INTDIV" },
584 { FPE_INTOVF, "FPE_INTOVF" },
585 { FPE_FLTDIV, "FPE_FLTDIV" },
586 { FPE_FLTOVF, "FPE_FLTOVF" },
587 { FPE_FLTUND, "FPE_FLTUND" },
588 { FPE_FLTRES, "FPE_FLTRES" },
589 { FPE_FLTINV, "FPE_FLTINV" },
590 { FPE_FLTSUB, "FPE_FLTSUB" },
591 { 0, NULL },
592};
593
Roland McGrathd9f816f2004-09-04 03:39:20 +0000594static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000595 { TRAP_BRKPT, "TRAP_BRKPT" },
596 { TRAP_TRACE, "TRAP_TRACE" },
597 { 0, NULL },
598};
599
Roland McGrathd9f816f2004-09-04 03:39:20 +0000600static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000601 { CLD_EXITED, "CLD_EXITED" },
602 { CLD_KILLED, "CLD_KILLED" },
603 { CLD_DUMPED, "CLD_DUMPED" },
604 { CLD_TRAPPED, "CLD_TRAPPED" },
605 { CLD_STOPPED, "CLD_STOPPED" },
606 { CLD_CONTINUED,"CLD_CONTINUED" },
607 { 0, NULL },
608};
609
Roland McGrathd9f816f2004-09-04 03:39:20 +0000610static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000611 { POLL_IN, "POLL_IN" },
612 { POLL_OUT, "POLL_OUT" },
613 { POLL_MSG, "POLL_MSG" },
614 { POLL_ERR, "POLL_ERR" },
615 { POLL_PRI, "POLL_PRI" },
616 { POLL_HUP, "POLL_HUP" },
617 { 0, NULL },
618};
619
Roland McGrathd9f816f2004-09-04 03:39:20 +0000620static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000621#ifdef PROF_SIG
622 { PROF_SIG, "PROF_SIG" },
623#endif
624 { 0, NULL },
625};
626
627#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000628static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000629#ifdef EMT_TAGOVF
630 { EMT_TAGOVF, "EMT_TAGOVF" },
631#endif
632 { 0, NULL },
633};
634#endif
635
Roland McGrathd9f816f2004-09-04 03:39:20 +0000636static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000637 { SEGV_MAPERR, "SEGV_MAPERR" },
638 { SEGV_ACCERR, "SEGV_ACCERR" },
639 { 0, NULL },
640};
641
Roland McGrathd9f816f2004-09-04 03:39:20 +0000642static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000643 { BUS_ADRALN, "BUS_ADRALN" },
644 { BUS_ADRERR, "BUS_ADRERR" },
645 { BUS_OBJERR, "BUS_OBJERR" },
646 { 0, NULL },
647};
648
649void
650printsiginfo(sip, verbose)
651siginfo_t *sip;
652int verbose;
653{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000654 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000655
656 if (sip->si_signo == 0) {
657 tprintf ("{}");
658 return;
659 }
660 tprintf("{si_signo=");
661 printsignal(sip->si_signo);
662 code = xlookup(siginfo_codes, sip->si_code);
663 if (!code) {
664 switch (sip->si_signo) {
665 case SIGTRAP:
666 code = xlookup(sigtrap_codes, sip->si_code);
667 break;
668 case SIGCHLD:
669 code = xlookup(sigchld_codes, sip->si_code);
670 break;
671 case SIGPOLL:
672 code = xlookup(sigpoll_codes, sip->si_code);
673 break;
674 case SIGPROF:
675 code = xlookup(sigprof_codes, sip->si_code);
676 break;
677 case SIGILL:
678 code = xlookup(sigill_codes, sip->si_code);
679 break;
680#ifdef SIGEMT
681 case SIGEMT:
682 code = xlookup(sigemt_codes, sip->si_code);
683 break;
684#endif
685 case SIGFPE:
686 code = xlookup(sigfpe_codes, sip->si_code);
687 break;
688 case SIGSEGV:
689 code = xlookup(sigsegv_codes, sip->si_code);
690 break;
691 case SIGBUS:
692 code = xlookup(sigbus_codes, sip->si_code);
693 break;
694 }
695 }
696 if (code)
697 tprintf(", si_code=%s", code);
698 else
699 tprintf(", si_code=%#x", sip->si_code);
700#ifdef SI_NOINFO
701 if (sip->si_code != SI_NOINFO)
702#endif
703 {
704 if (sip->si_errno) {
705 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
706 tprintf(", si_errno=%d", sip->si_errno);
707 else
708 tprintf(", si_errno=%s",
709 errnoent[sip->si_errno]);
710 }
711#ifdef SI_FROMUSER
712 if (SI_FROMUSER(sip)) {
713 tprintf(", si_pid=%ld, si_uid=%ld",
714 sip->si_pid, sip->si_uid);
715#ifdef SI_QUEUE
716 switch (sip->si_code) {
717 case SI_QUEUE:
718#ifdef SI_TIMER
719 case SI_TIMER:
720#endif /* SI_QUEUE */
721 case SI_ASYNCIO:
722#ifdef SI_MESGQ
723 case SI_MESGQ:
724#endif /* SI_MESGQ */
725 tprintf(", si_value=%d",
726 sip->si_value.sival_int);
727 break;
728 }
729#endif /* SI_QUEUE */
730 }
731 else
732#endif /* SI_FROMUSER */
733 {
734 switch (sip->si_signo) {
735 case SIGCHLD:
736 tprintf(", si_pid=%ld, si_status=",
737 (long) sip->si_pid);
738 if (sip->si_code == CLD_EXITED)
739 tprintf("%d", sip->si_status);
740 else
741 printsignal(sip->si_status);
742#if LINUX
743 if (!verbose)
744 tprintf(", ...");
745 else
746 tprintf(", si_utime=%lu, si_stime=%lu",
747 sip->si_utime,
748 sip->si_stime);
749#endif
750 break;
751 case SIGILL: case SIGFPE:
752 case SIGSEGV: case SIGBUS:
753 tprintf(", si_addr=%#lx",
754 (unsigned long) sip->si_addr);
755 break;
756 case SIGPOLL:
757 switch (sip->si_code) {
758 case POLL_IN: case POLL_OUT: case POLL_MSG:
759 tprintf(", si_band=%ld",
760 (long) sip->si_band);
761 break;
762 }
763 break;
764#ifdef LINUX
765 default:
766 tprintf(", si_pid=%lu, si_uid=%lu, ",
767 (unsigned long) sip->si_pid,
768 (unsigned long) sip->si_uid);
769 if (!verbose)
770 tprintf("...");
771 else {
772 tprintf("si_value={int=%u, ptr=%#lx}",
773 sip->si_int,
774 (unsigned long) sip->si_ptr);
775 }
776#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000777
John Hughes58265892001-10-18 15:13:53 +0000778 }
779 }
780 }
781 tprintf("}");
782}
783
784#endif /* SVR4 || LINUX */
785
786#ifdef LINUX
787
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000788static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000789parse_sigset_t(const char *str, sigset_t *set)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000790{
Roland McGrathc38feca2003-10-01 07:50:28 +0000791 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000792 unsigned int digit;
793 int i;
794
795 sigemptyset(set);
796
Roland McGrathc38feca2003-10-01 07:50:28 +0000797 p = strchr(str, '\n');
798 if (p == NULL)
799 p = strchr(str, '\0');
800 for (i = 0; p-- > str; i += 4) {
801 if (*p >= '0' && *p <= '9')
802 digit = *p - '0';
803 else if (*p >= 'a' && *p <= 'f')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000804 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000805 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000806 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000807 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000808 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000809 if (digit & 1)
810 sigaddset(set, i + 1);
811 if (digit & 2)
812 sigaddset(set, i + 2);
813 if (digit & 4)
814 sigaddset(set, i + 3);
815 if (digit & 8)
816 sigaddset(set, i + 4);
817 }
818}
819
820#endif
821
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000822/*
823 * Check process TCP for the disposition of signal SIG.
824 * Return 1 if the process would somehow manage to survive signal SIG,
825 * else return 0. This routine will never be called with SIGKILL.
826 */
827int
828sigishandled(tcp, sig)
829struct tcb *tcp;
830int sig;
831{
832#ifdef LINUX
833 int sfd;
834 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000835 char buf[2048];
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000836 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000837 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000838 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000839#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000840#ifdef SVR4
841 /*
842 * Since procfs doesn't interfere with wait I think it is safe
843 * to punt on this question. If not, the information is there.
844 */
845 return 1;
846#else /* !SVR4 */
847 switch (sig) {
848 case SIGCONT:
849 case SIGSTOP:
850 case SIGTSTP:
851 case SIGTTIN:
852 case SIGTTOU:
853 case SIGCHLD:
854 case SIGIO:
855#if defined(SIGURG) && SIGURG != SIGIO
856 case SIGURG:
857#endif
858 case SIGWINCH:
859 /* Gloria Gaynor says ... */
860 return 1;
861 default:
862 break;
863 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000864#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000865#ifdef LINUX
866
867 /* This is incredibly costly but it's worth it. */
868 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
869 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
870 doesn't handle real-time signals). */
871 sprintf(sname, "/proc/%d/status", tcp->pid);
872 if ((sfd = open(sname, O_RDONLY)) == -1) {
873 perror(sname);
874 return 1;
875 }
876 i = read(sfd, buf, sizeof(buf));
877 buf[i] = '\0';
878 close(sfd);
879 /*
880 * Skip the extraneous fields. We need to skip
881 * command name has any spaces in it. So be it.
882 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000883 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000884 if (!s)
885 {
886 fprintf(stderr, "/proc/pid/status format error\n");
887 return 1;
888 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000889 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000890
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000891 s = strstr(buf, "SigCgt:\t");
892 if (!s)
893 {
894 fprintf(stderr, "/proc/pid/status format error\n");
895 return 1;
896 }
897 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000898
899#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000900 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
901 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000902#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000903 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000904 return 1;
905#endif /* LINUX */
906
907#ifdef SUNOS4
908 void (*u_signal)();
909
Denys Vlasenko932fc7d2008-12-16 18:18:40 +0000910 if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal),
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000911 (long *) &u_signal) < 0) {
912 return 0;
913 }
914 if (u_signal != SIG_DFL)
915 return 1;
916#endif /* SUNOS4 */
917
918 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000919}
920
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000921#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000922
923int
924sys_sigvec(tcp)
925struct tcb *tcp;
926{
927 struct sigvec sv;
928 long addr;
929
930 if (entering(tcp)) {
931 printsignal(tcp->u_arg[0]);
932 tprintf(", ");
933 addr = tcp->u_arg[1];
934 } else {
935 addr = tcp->u_arg[2];
936 }
937 if (addr == 0)
938 tprintf("NULL");
939 else if (!verbose(tcp))
940 tprintf("%#lx", addr);
941 else if (umove(tcp, addr, &sv) < 0)
942 tprintf("{...}");
943 else {
944 switch ((int) sv.sv_handler) {
945 case (int) SIG_ERR:
946 tprintf("{SIG_ERR}");
947 break;
948 case (int) SIG_DFL:
949 tprintf("{SIG_DFL}");
950 break;
951 case (int) SIG_IGN:
952 if (tcp->u_arg[0] == SIGTRAP) {
953 tcp->flags |= TCB_SIGTRAPPED;
954 kill(tcp->pid, SIGSTOP);
955 }
956 tprintf("{SIG_IGN}");
957 break;
958 case (int) SIG_HOLD:
959 if (tcp->u_arg[0] == SIGTRAP) {
960 tcp->flags |= TCB_SIGTRAPPED;
961 kill(tcp->pid, SIGSTOP);
962 }
963 tprintf("SIG_HOLD");
964 break;
965 default:
966 if (tcp->u_arg[0] == SIGTRAP) {
967 tcp->flags |= TCB_SIGTRAPPED;
968 kill(tcp->pid, SIGSTOP);
969 }
970 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000971 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000972 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000973 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000974 tprintf("}");
975 }
976 }
977 if (entering(tcp))
978 tprintf(", ");
979 return 0;
980}
981
982int
983sys_sigpause(tcp)
984struct tcb *tcp;
985{
986 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000987 sigset_t sigm;
988 long_to_sigset(tcp->u_arg[0], &sigm);
989 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990 }
991 return 0;
992}
993
994int
995sys_sigstack(tcp)
996struct tcb *tcp;
997{
998 struct sigstack ss;
999 long addr;
1000
1001 if (entering(tcp))
1002 addr = tcp->u_arg[0];
1003 else
1004 addr = tcp->u_arg[1];
1005 if (addr == 0)
1006 tprintf("NULL");
1007 else if (umove(tcp, addr, &ss) < 0)
1008 tprintf("%#lx", addr);
1009 else {
1010 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1011 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1012 }
1013 if (entering(tcp))
1014 tprintf(", ");
1015 return 0;
1016}
1017
1018int
1019sys_sigcleanup(tcp)
1020struct tcb *tcp;
1021{
1022 return 0;
1023}
1024
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001025#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026
1027#ifndef SVR4
1028
1029int
1030sys_sigsetmask(tcp)
1031struct tcb *tcp;
1032{
1033 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001035 long_to_sigset(tcp->u_arg[0], &sigm);
1036 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001037#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001038 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1039 /* Mark attempt to block SIGTRAP */
1040 tcp->flags |= TCB_SIGTRAPPED;
1041 /* Send unblockable signal */
1042 kill(tcp->pid, SIGSTOP);
1043 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001044#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001045 }
1046 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001047 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001048 long_to_sigset(tcp->u_rval, &sigm);
1049 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050
1051 return RVAL_HEX | RVAL_STR;
1052 }
1053 return 0;
1054}
1055
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001056#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001057int
1058sys_sigblock(tcp)
1059struct tcb *tcp;
1060{
1061 return sys_sigsetmask(tcp);
1062}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001063#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001064
1065#endif /* !SVR4 */
1066
1067#ifdef HAVE_SIGACTION
1068
1069#ifdef LINUX
1070struct old_sigaction {
1071 __sighandler_t __sa_handler;
1072 unsigned long sa_mask;
1073 unsigned long sa_flags;
1074 void (*sa_restorer)(void);
1075};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001076#define SA_HANDLER __sa_handler
1077#endif /* LINUX */
1078
Roland McGratha39c5a12002-12-17 05:10:37 +00001079#ifndef SA_HANDLER
1080#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001081#endif
1082
1083int
1084sys_sigaction(tcp)
1085struct tcb *tcp;
1086{
1087 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001088#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001089 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001090 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001091#else
1092 struct sigaction sa;
1093#endif
1094
1095
1096 if (entering(tcp)) {
1097 printsignal(tcp->u_arg[0]);
1098 tprintf(", ");
1099 addr = tcp->u_arg[1];
1100 } else
1101 addr = tcp->u_arg[2];
1102 if (addr == 0)
1103 tprintf("NULL");
1104 else if (!verbose(tcp))
1105 tprintf("%#lx", addr);
1106 else if (umove(tcp, addr, &sa) < 0)
1107 tprintf("{...}");
1108 else {
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001109 /* Architectures using function pointers, like
1110 * hppa, may need to manipulate the function pointer
1111 * to compute the result of a comparison. However,
1112 * the SA_HANDLER function pointer exists only in
1113 * the address space of the traced process, and can't
1114 * be manipulated by strace. In order to prevent the
1115 * compiler from generating code to manipulate
1116 * SA_HANDLER we cast the function pointers to long. */
1117 if ((long)sa.SA_HANDLER == (long)SIG_ERR)
Roland McGrath5f206812008-08-20 01:59:40 +00001118 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001119 else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
Roland McGrath5f206812008-08-20 01:59:40 +00001120 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001121 else if ((long)sa.SA_HANDLER == (long)SIG_IGN) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001122#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001123 if (tcp->u_arg[0] == SIGTRAP) {
1124 tcp->flags |= TCB_SIGTRAPPED;
1125 kill(tcp->pid, SIGSTOP);
1126 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001127#endif /* !USE_PROCFS */
Roland McGrath5f206812008-08-20 01:59:40 +00001128 tprintf("{SIG_IGN, ");
1129 }
1130 else {
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 */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001137 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001138#ifndef LINUX
1139 printsigmask (&sa.sa_mask, 0);
1140#else
Nate Sammons4a121431999-04-06 01:19:39 +00001141 long_to_sigset(sa.sa_mask, &sigset);
1142 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001143#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001144 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001145 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001146#ifdef SA_RESTORER
1147 if (sa.sa_flags & SA_RESTORER)
1148 tprintf(", %p", sa.sa_restorer);
1149#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001150 tprintf("}");
1151 }
1152 }
1153 if (entering(tcp))
1154 tprintf(", ");
1155#ifdef LINUX
1156 else
1157 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1158#endif
1159 return 0;
1160}
1161
1162int
1163sys_signal(tcp)
1164struct tcb *tcp;
1165{
1166 if (entering(tcp)) {
1167 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001168 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001169 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001170 case (long) SIG_ERR:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001171 tprintf("SIG_ERR");
1172 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001173 case (long) SIG_DFL:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001174 tprintf("SIG_DFL");
1175 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001176 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001177#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001178 if (tcp->u_arg[0] == SIGTRAP) {
1179 tcp->flags |= TCB_SIGTRAPPED;
1180 kill(tcp->pid, SIGSTOP);
1181 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001182#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001183 tprintf("SIG_IGN");
1184 break;
1185 default:
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("%#lx", tcp->u_arg[1]);
1193 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001194 return 0;
1195 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001196 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001197 switch (tcp->u_rval) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001198 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001199 tcp->auxstr = "SIG_ERR"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001200 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001201 tcp->auxstr = "SIG_DFL"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001202 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001203 tcp->auxstr = "SIG_IGN"; break;
1204 default:
1205 tcp->auxstr = NULL;
1206 }
1207 return RVAL_HEX | RVAL_STR;
1208 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001209 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001210}
1211
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001212#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001213int
1214sys_sighold(tcp)
1215struct tcb *tcp;
1216{
1217 if (entering(tcp)) {
1218 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001219 }
1220 return 0;
1221}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001222#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001223
1224#endif /* HAVE_SIGACTION */
1225
1226#ifdef LINUX
1227
1228int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001229sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001230{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001231#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001232 struct pt_regs regs;
1233 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001234
Roland McGrath0f87c492003-06-03 23:29:04 +00001235 if (entering(tcp)) {
1236 tcp->u_arg[0] = 0;
1237
1238 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1239 return 0;
1240
1241 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1242 return 0;
1243
1244 tcp->u_arg[0] = 1;
1245 tcp->u_arg[1] = sc.oldmask;
1246 } else {
1247 sigset_t sigm;
1248 long_to_sigset(tcp->u_arg[1], &sigm);
1249 tcp->u_rval = tcp->u_error = 0;
1250 if (tcp->u_arg[0] == 0)
1251 return 0;
1252 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1253 return RVAL_NONE | RVAL_STR;
1254 }
1255 return 0;
1256#elif defined(S390) || defined(S390X)
1257 long usp;
1258 struct sigcontext_struct sc;
1259
1260 if (entering(tcp)) {
1261 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001262 if (upeek(tcp,PT_GPR15,&usp)<0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001263 return 0;
1264 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1265 return 0;
1266 tcp->u_arg[0] = 1;
1267 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1268 } else {
1269 tcp->u_rval = tcp->u_error = 0;
1270 if (tcp->u_arg[0] == 0)
1271 return 0;
1272 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1273 return RVAL_NONE | RVAL_STR;
1274 }
1275 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001276#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001277 long esp;
1278 struct sigcontext_struct sc;
1279
1280 if (entering(tcp)) {
1281 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001282 if (upeek(tcp, 4*UESP, &esp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001283 return 0;
1284 if (umove(tcp, esp, &sc) < 0)
1285 return 0;
1286 tcp->u_arg[0] = 1;
1287 tcp->u_arg[1] = sc.oldmask;
1288 }
1289 else {
1290 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001291 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 tcp->u_rval = tcp->u_error = 0;
1293 if (tcp->u_arg[0] == 0)
1294 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001295 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296 return RVAL_NONE | RVAL_STR;
1297 }
1298 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001299#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001300 struct sigcontext sc;
1301 long sp;
1302
1303 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001304 /* offset of sigcontext in the kernel's sigframe structure: */
1305# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001306 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001307 if (upeek(tcp, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001308 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001309 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001310 return 0;
1311 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001312 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001313 }
1314 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001315 sigset_t sigm;
1316
1317 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001318 tcp->u_rval = tcp->u_error = 0;
1319 if (tcp->u_arg[0] == 0)
1320 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001321 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001322 return RVAL_NONE | RVAL_STR;
1323 }
1324 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001325#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +00001326 long esp;
1327 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001328
Roland McGrath0f87c492003-06-03 23:29:04 +00001329 if (entering(tcp)) {
1330 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001331 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001332 return 0;
Andreas Schwabedb39342010-02-23 00:18:51 +01001333 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +02001334#ifdef POWERPC64
1335 if (current_personality == 0)
1336 esp += 128;
1337 else
1338 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +01001339#else
1340 esp += 64;
1341#endif
Roland McGrath0f87c492003-06-03 23:29:04 +00001342 if (umove(tcp, esp, &sc) < 0)
1343 return 0;
1344 tcp->u_arg[0] = 1;
1345 tcp->u_arg[1] = sc.oldmask;
1346 }
1347 else {
1348 sigset_t sigm;
1349 long_to_sigset(tcp->u_arg[1], &sigm);
1350 tcp->u_rval = tcp->u_error = 0;
1351 if (tcp->u_arg[0] == 0)
1352 return 0;
1353 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1354 return RVAL_NONE | RVAL_STR;
1355 }
1356 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001357#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001358 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001359 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001360
1361 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001362 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001363 if (upeek(tcp, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001364 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001365 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001366 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001367 tcp->u_arg[0] = 1;
1368 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001369 }
1370 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001371 sigset_t sigm;
1372 long_to_sigset(tcp->u_arg[1], &sigm);
1373 tcp->u_rval = tcp->u_error = 0;
1374 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001375 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001376 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1377 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378 }
1379 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001380#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001381 long fp;
1382 struct sigcontext_struct sc;
1383
1384 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001385 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001386 if (upeek(tcp, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001387 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001388 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001389 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001390 tcp->u_arg[0] = 1;
1391 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001392 }
1393 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001394 sigset_t sigm;
1395 long_to_sigset(tcp->u_arg[1], &sigm);
1396 tcp->u_rval = tcp->u_error = 0;
1397 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001398 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001399 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1400 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001401 }
1402 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001403#elif defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001404 long i1;
Mike Frysinger8566c502009-10-12 11:05:14 -04001405 struct pt_regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001406 m_siginfo_t si;
1407
Roland McGratheb9e2e82009-06-02 16:49:22 -07001408 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1409 perror("sigreturn: PTRACE_GETREGS ");
Roland McGrath0f87c492003-06-03 23:29:04 +00001410 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001411 }
Roland McGratheb9e2e82009-06-02 16:49:22 -07001412 if(entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413 tcp->u_arg[0] = 0;
Mike Frysinger8566c502009-10-12 11:05:14 -04001414 i1 = regs.u_regs[U_REG_O1];
Roland McGratheb9e2e82009-06-02 16:49:22 -07001415 if(umove(tcp, i1, &si) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001416 perror("sigreturn: umove ");
1417 return 0;
1418 }
1419 tcp->u_arg[0] = 1;
1420 tcp->u_arg[1] = si.si_mask;
1421 } else {
1422 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001423 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424 tcp->u_rval = tcp->u_error = 0;
1425 if(tcp->u_arg[0] == 0)
1426 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001427 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001428 return RVAL_NONE | RVAL_STR;
1429 }
1430 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001431#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001432 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1433 sigreturn. */
1434 long sp;
1435 struct ucontext uc;
1436
1437 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001438 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001439 if (upeek(tcp, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001440 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001441 /* There are six words followed by a 128-byte siginfo. */
1442 sp = sp + 6 * 4 + 128;
1443 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001444 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001445 tcp->u_arg[0] = 1;
1446 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1447 } else {
1448 sigset_t sigm;
1449 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001450 tcp->u_rval = tcp->u_error = 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001451 if(tcp->u_arg[0] == 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001452 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001453 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1454 return RVAL_NONE | RVAL_STR;
1455 }
1456 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001457#elif defined(MIPS)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001458 long sp;
Roland McGrath576b7842007-11-04 00:00:00 +00001459 struct pt_regs regs;
1460 m_siginfo_t si;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001461
Roland McGrath576b7842007-11-04 00:00:00 +00001462 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1463 perror("sigreturn: PTRACE_GETREGS ");
1464 return 0;
1465 }
Wichert Akkermanf90da011999-10-31 21:15:38 +00001466 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001467 tcp->u_arg[0] = 0;
Roland McGrath576b7842007-11-04 00:00:00 +00001468 sp = regs.regs[29];
1469 if (umove(tcp, sp, &si) < 0)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001470 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001471 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001472 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001473 sigset_t sigm;
1474 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001475 tcp->u_rval = tcp->u_error = 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001476 if(tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001477 return 0;
1478 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001479 return RVAL_NONE | RVAL_STR;
1480 }
1481 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001482#elif defined(CRISV10) || defined(CRISV32)
1483 struct sigcontext sc;
1484
1485 if (entering(tcp)) {
1486 long regs[PT_MAX+1];
1487
1488 tcp->u_arg[0] = 0;
1489
1490 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1491 perror("sigreturn: PTRACE_GETREGS");
1492 return 0;
1493 }
1494 if (umove(tcp, regs[PT_USP], &sc) < 0)
1495 return 0;
1496 tcp->u_arg[0] = 1;
1497 tcp->u_arg[1] = sc.oldmask;
1498 } else {
1499 sigset_t sigm;
1500 long_to_sigset(tcp->u_arg[1], &sigm);
1501 tcp->u_rval = tcp->u_error = 0;
1502
1503 if (tcp->u_arg[0] == 0)
1504 return 0;
1505 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1506 return RVAL_NONE | RVAL_STR;
1507 }
1508 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -05001509#elif defined(TILE)
1510 struct ucontext uc;
1511 long sp;
1512
1513 /* offset of ucontext in the kernel's sigframe structure */
1514# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo)
1515
1516 if (entering(tcp)) {
1517 tcp->u_arg[0] = 0;
1518 if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0)
1519 return 0;
1520 if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1521 return 0;
1522 tcp->u_arg[0] = 1;
1523 memcpy(tcp->u_arg + 1, &uc.uc_sigmask, sizeof(uc.uc_sigmask));
1524 }
1525 else {
1526 sigset_t sigm;
1527
1528 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
1529 tcp->u_rval = tcp->u_error = 0;
1530 if (tcp->u_arg[0] == 0)
1531 return 0;
1532 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1533 return RVAL_NONE | RVAL_STR;
1534 }
1535 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001536#elif defined(MICROBLAZE)
1537 struct sigcontext sc;
1538
1539 /* TODO: Verify that this is correct... */
1540 if (entering(tcp)) {
1541 long sp;
1542
1543 tcp->u_arg[0] = 0;
1544
1545 /* Read r1, the stack pointer. */
1546 if (upeek(tcp, 1 * 4, &sp) < 0)
1547 return 0;
1548 if (umove(tcp, sp, &sc) < 0)
1549 return 0;
1550 tcp->u_arg[0] = 1;
1551 tcp->u_arg[1] = sc.oldmask;
1552 } else {
1553 sigset_t sigm;
1554 long_to_sigset(tcp->u_arg[1], &sigm);
1555 tcp->u_rval = tcp->u_error = 0;
1556 if (tcp->u_arg[0] == 0)
1557 return 0;
1558 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1559 return RVAL_NONE | RVAL_STR;
1560 }
1561 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001562#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001563#warning No sys_sigreturn() for this architecture
1564#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001565 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001566#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001567}
1568
1569int
1570sys_siggetmask(tcp)
1571struct tcb *tcp;
1572{
1573 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001574 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001575 long_to_sigset(tcp->u_rval, &sigm);
1576 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001577 }
1578 return RVAL_HEX | RVAL_STR;
1579}
1580
1581int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001582sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001583{
1584 if (entering(tcp)) {
1585 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001586 long_to_sigset(tcp->u_arg[2], &sigm);
Nate Sammons4a121431999-04-06 01:19:39 +00001587 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001588 }
1589 return 0;
1590}
1591
1592#endif /* LINUX */
1593
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001594#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001595
1596int
1597sys_sigsuspend(tcp)
1598struct tcb *tcp;
1599{
1600 sigset_t sigset;
1601
1602 if (entering(tcp)) {
1603 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1604 tprintf("[?]");
1605 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001606 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001607 }
1608 return 0;
1609}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001610#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001611static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001612 { UC_SIGMASK, "UC_SIGMASK" },
1613 { UC_STACK, "UC_STACK" },
1614 { UC_CPU, "UC_CPU" },
1615#ifdef UC_FPU
1616 { UC_FPU, "UC_FPU" },
1617#endif
1618#ifdef UC_INTR
1619 { UC_INTR, "UC_INTR" },
1620#endif
1621 { 0, NULL },
1622};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001623#endif /* !FREEBSD */
1624#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001626#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001627#if defined LINUX && !defined SS_ONSTACK
1628#define SS_ONSTACK 1
1629#define SS_DISABLE 2
1630#if __GLIBC_MINOR__ == 0
1631typedef struct
1632{
1633 __ptr_t ss_sp;
1634 int ss_flags;
1635 size_t ss_size;
1636} stack_t;
1637#endif
1638#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001639#ifdef FREEBSD
1640#define stack_t struct sigaltstack
1641#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642
Roland McGrathd9f816f2004-09-04 03:39:20 +00001643static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001644 { SS_ONSTACK, "SS_ONSTACK" },
1645 { SS_DISABLE, "SS_DISABLE" },
1646 { 0, NULL },
1647};
1648#endif
1649
1650#ifdef SVR4
1651static void
1652printcontext(tcp, ucp)
1653struct tcb *tcp;
1654ucontext_t *ucp;
1655{
1656 tprintf("{");
1657 if (!abbrev(tcp)) {
1658 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001659 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001660 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1661 }
1662 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001663 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001664 if (!abbrev(tcp)) {
1665 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1666 (unsigned long) ucp->uc_stack.ss_sp,
1667 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001668 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001669 tprintf("}");
1670 }
1671 tprintf(", ...}");
1672}
1673
1674int
1675sys_getcontext(tcp)
1676struct tcb *tcp;
1677{
1678 ucontext_t uc;
1679
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001680 if (exiting(tcp)) {
1681 if (tcp->u_error)
1682 tprintf("%#lx", tcp->u_arg[0]);
1683 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001684 tprintf("NULL");
1685 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1686 tprintf("{...}");
1687 else
1688 printcontext(tcp, &uc);
1689 }
1690 return 0;
1691}
1692
1693int
1694sys_setcontext(tcp)
1695struct tcb *tcp;
1696{
1697 ucontext_t uc;
1698
1699 if (entering(tcp)) {
1700 if (!tcp->u_arg[0])
1701 tprintf("NULL");
1702 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1703 tprintf("{...}");
1704 else
1705 printcontext(tcp, &uc);
1706 }
1707 else {
1708 tcp->u_rval = tcp->u_error = 0;
1709 if (tcp->u_arg[0] == 0)
1710 return 0;
1711 return RVAL_NONE;
1712 }
1713 return 0;
1714}
1715
1716#endif /* SVR4 */
1717
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001718#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001719
1720static int
1721print_stack_t(tcp, addr)
1722struct tcb *tcp;
1723unsigned long addr;
1724{
1725 stack_t ss;
1726 if (umove(tcp, addr, &ss) < 0)
1727 return -1;
1728 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001729 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001730 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1731 return 0;
1732}
1733
1734int
1735sys_sigaltstack(tcp)
1736 struct tcb *tcp;
1737{
1738 if (entering(tcp)) {
1739 if (tcp->u_arg[0] == 0)
1740 tprintf("NULL");
1741 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1742 return -1;
1743 }
1744 else {
1745 tprintf(", ");
1746 if (tcp->u_arg[1] == 0)
1747 tprintf("NULL");
1748 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1749 return -1;
1750 }
1751 return 0;
1752}
1753#endif
1754
1755#ifdef HAVE_SIGACTION
1756
1757int
1758sys_sigprocmask(tcp)
1759struct tcb *tcp;
1760{
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
1798sys_kill(tcp)
1799struct tcb *tcp;
1800{
1801 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001802 /*
1803 * Sign-extend a 32-bit value when that's what it is.
1804 */
1805 long pid = tcp->u_arg[0];
1806 if (personality_wordsize[current_personality] < sizeof pid)
1807 pid = (long) (int) pid;
1808 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001809 }
1810 return 0;
1811}
1812
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001813#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814int
1815sys_killpg(tcp)
1816struct tcb *tcp;
1817{
1818 return sys_kill(tcp);
1819}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001820#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001821
Roland McGrath8ffc3522003-07-09 09:47:49 +00001822#ifdef LINUX
1823int
1824sys_tgkill(tcp)
1825 struct tcb *tcp;
1826{
1827 if (entering(tcp)) {
1828 tprintf("%ld, %ld, %s",
1829 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1830 }
1831 return 0;
1832}
1833#endif
1834
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001835int
1836sys_sigpending(tcp)
1837struct tcb *tcp;
1838{
1839 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001840
1841 if (exiting(tcp)) {
1842 if (syserror(tcp))
1843 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001844 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001845 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001846 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001847 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001848 }
1849 return 0;
1850}
1851
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001852#ifdef SVR4
John Hughes42162082001-10-18 14:48:26 +00001853int sys_sigwait(tcp)
1854struct tcb *tcp;
1855{
1856 sigset_t sigset;
1857
1858 if (entering(tcp)) {
1859 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1860 tprintf("[?]");
1861 else
1862 printsigmask(&sigset, 0);
1863 }
1864 else {
1865 if (!syserror(tcp)) {
1866 tcp->auxstr = signalent[tcp->u_rval];
1867 return RVAL_DECIMAL | RVAL_STR;
1868 }
1869 }
1870 return 0;
1871}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001872#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001873
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874#ifdef LINUX
1875
1876 int
1877sys_rt_sigprocmask(tcp)
1878 struct tcb *tcp;
1879{
1880 sigset_t sigset;
1881
Nate Sammons4a121431999-04-06 01:19:39 +00001882 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883 if (entering(tcp)) {
1884 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1885 tprintf(", ");
1886 if (!tcp->u_arg[1])
1887 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001888 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001889 tprintf("%#lx, ", tcp->u_arg[1]);
1890 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001891 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001892 tprintf(", ");
1893 }
1894 }
1895 else {
1896 if (!tcp->u_arg[2])
1897
1898 tprintf("NULL");
1899 else if (syserror(tcp))
1900 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001901 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001902 tprintf("[?]");
1903 else
Nate Sammons4a121431999-04-06 01:19:39 +00001904 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001905 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906 }
1907 return 0;
1908}
1909
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910
1911/* Structure describing the action to be taken when a signal arrives. */
1912struct new_sigaction
1913{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001914 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001915 unsigned long sa_flags;
1916 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001917 /* Kernel treats sa_mask as an array of longs. */
1918 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1919};
1920/* Same for i386-on-x86_64 and similar cases */
1921struct new_sigaction32
1922{
1923 uint32_t __sa_handler;
1924 uint32_t sa_flags;
1925 uint32_t sa_restorer;
1926 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001927};
1928
1929
Roland McGrath5f206812008-08-20 01:59:40 +00001930int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001931sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001932{
1933 struct new_sigaction sa;
1934 sigset_t sigset;
1935 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001936 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001937
1938 if (entering(tcp)) {
1939 printsignal(tcp->u_arg[0]);
1940 tprintf(", ");
1941 addr = tcp->u_arg[1];
1942 } else
1943 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001944
1945 if (addr == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001946 tprintf("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001947 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001948 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001949 if (!verbose(tcp)) {
1950 tprintf("%#lx", addr);
1951 goto after_sa;
1952 }
1953#if SUPPORTED_PERSONALITIES > 1
1954 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1955 && personality_wordsize[current_personality] == 4
1956 ) {
1957 struct new_sigaction32 sa32;
1958 r = umove(tcp, addr, &sa32);
1959 if (r >= 0) {
1960 memset(&sa, 0, sizeof(sa));
1961 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1962 sa.sa_flags = sa32.sa_flags;
1963 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1964 /* Kernel treats sa_mask as an array of longs.
1965 * For 32-bit process, "long" is uint32_t, thus, for example,
1966 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1967 * But for (64-bit) kernel, 32th bit in sa_mask is
1968 * 32th bit in 0th (64-bit) long!
1969 * For little-endian, it's the same.
1970 * For big-endian, we swap 32-bit words.
1971 */
1972 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1973 }
1974 } else
1975#endif
1976 {
1977 r = umove(tcp, addr, &sa);
1978 }
1979 if (r < 0) {
1980 tprintf("{...}");
1981 goto after_sa;
1982 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001983 /* Architectures using function pointers, like
1984 * hppa, may need to manipulate the function pointer
1985 * to compute the result of a comparison. However,
1986 * the SA_HANDLER function pointer exists only in
1987 * the address space of the traced process, and can't
1988 * be manipulated by strace. In order to prevent the
1989 * compiler from generating code to manipulate
1990 * SA_HANDLER we cast the function pointers to long. */
1991 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001992 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001993 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001994 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001995 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001996 tprintf("{SIG_IGN, ");
1997 else
1998 tprintf("{%#lx, ", (long) sa.__sa_handler);
1999 /* Questionable code below.
2000 * Kernel won't handle sys_rt_sigaction
2001 * with wrong sigset size (just returns EINVAL)
2002 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
2003 * and we always use smaller memcpy. */
2004 sigemptyset(&sigset);
2005#ifdef LINUXSPARC
2006 if (tcp->u_arg[4] <= sizeof(sigset))
2007 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
2008#else
2009 if (tcp->u_arg[3] <= sizeof(sigset))
2010 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
2011#endif
2012 else
2013 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
2014 printsigmask(&sigset, 1);
2015 tprintf(", ");
2016 printflags(sigact_flags, sa.sa_flags, "SA_???");
2017#ifdef SA_RESTORER
2018 if (sa.sa_flags & SA_RESTORER)
2019 tprintf(", %p", sa.sa_restorer);
2020#endif
2021 tprintf("}");
2022
2023 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002024 if (entering(tcp))
2025 tprintf(", ");
2026 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00002027#ifdef LINUXSPARC
2028 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
2029#elif defined(ALPHA)
2030 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
2031#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00002032 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00002033#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002034 return 0;
2035}
2036
Denys Vlasenko1d632462009-04-14 12:51:00 +00002037int
2038sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002039{
2040 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002041
2042 if (exiting(tcp)) {
2043 if (syserror(tcp))
2044 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00002045 else if (copy_sigset_len(tcp, tcp->u_arg[0],
2046 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002047 tprintf("[?]");
2048 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002049 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002050 }
2051 return 0;
2052}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002053
2054int
2055sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002056{
2057 if (entering(tcp)) {
2058 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00002059 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
2060 tprintf("[?]");
2061 else
2062 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002063 }
2064 return 0;
2065}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002066
2067int
2068sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002069{
2070 if (entering(tcp)) {
2071 siginfo_t si;
2072 tprintf("%lu, ", tcp->u_arg[0]);
2073 printsignal(tcp->u_arg[1]);
2074 tprintf(", ");
2075 if (umove(tcp, tcp->u_arg[2], &si) < 0)
2076 tprintf("%#lx", tcp->u_arg[2]);
2077 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002078 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002079 }
2080 return 0;
2081}
2082
Denys Vlasenko1d632462009-04-14 12:51:00 +00002083int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002084{
2085 if (entering(tcp)) {
2086 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002087
Roland McGratha39c5a12002-12-17 05:10:37 +00002088 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00002089 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002090 tprintf("[?]");
2091 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002092 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002093 tprintf(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002094 /* This is the only "return" parameter, */
2095 if (tcp->u_arg[1] != 0)
2096 return 0;
2097 /* ... if it's NULL, can decode all on entry */
2098 tprintf("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002099 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002100 else if (tcp->u_arg[1] != 0) {
2101 /* syscall exit, and u_arg[1] wasn't NULL */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002102 if (syserror(tcp))
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002103 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002104 else {
2105 siginfo_t si;
2106 if (umove(tcp, tcp->u_arg[1], &si) < 0)
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002107 tprintf("%#lx, ", tcp->u_arg[1]);
2108 else {
Denys Vlasenkof535b542009-01-13 18:30:55 +00002109 printsiginfo(&si, verbose(tcp));
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002110 tprintf(", ");
2111 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002112 }
2113 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002114 else {
2115 /* syscall exit, and u_arg[1] was NULL */
2116 return 0;
2117 }
2118 print_timespec(tcp, tcp->u_arg[2]);
2119 tprintf(", %d", (int) tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002120 return 0;
2121};
2122
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002123int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002124sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002125{
2126 if (entering(tcp))
2127 tprintf("<... resuming interrupted call ...>");
2128 return 0;
2129}
2130
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002131static int
2132do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00002133{
2134 if (entering(tcp)) {
2135 tprintf("%ld, ", tcp->u_arg[0]);
2136 print_sigset(tcp, tcp->u_arg[1], 1);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00002137 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002138 if (flags_arg >= 0) {
2139 tprintf(", ");
2140 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2141 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00002142 }
2143 return 0;
2144}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002145
2146int
2147sys_signalfd(struct tcb *tcp)
2148{
2149 return do_signalfd(tcp, -1);
2150}
2151
2152int
2153sys_signalfd4(struct tcb *tcp)
2154{
2155 return do_signalfd(tcp, 3);
2156}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002157#endif /* LINUX */