blob: b47b831c1c9c92e14e6a6b40f1da1fe9a9b865e7 [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
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000454#define SI_FROMUSER(sip) ((sip)->si_code <= 0)
455
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000456#endif /* LINUX */
John Hughes58265892001-10-18 15:13:53 +0000457
458#if __GLIBC_MINOR__ < 1
459/* Type for data associated with a signal. */
460typedef union sigval
461{
462 int sival_int;
463 void *sival_ptr;
464} sigval_t;
465
466# define __SI_MAX_SIZE 128
467# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
468
469typedef struct siginfo
470{
471 int si_signo; /* Signal number. */
472 int si_errno; /* If non-zero, an errno value associated with
473 this signal, as defined in <errno.h>. */
474 int si_code; /* Signal code. */
475
476 union
477 {
478 int _pad[__SI_PAD_SIZE];
479
480 /* kill(). */
481 struct
482 {
483 __pid_t si_pid; /* Sending process ID. */
484 __uid_t si_uid; /* Real user ID of sending process. */
485 } _kill;
486
487 /* POSIX.1b timers. */
488 struct
489 {
490 unsigned int _timer1;
491 unsigned int _timer2;
492 } _timer;
493
494 /* POSIX.1b signals. */
495 struct
496 {
497 __pid_t si_pid; /* Sending process ID. */
498 __uid_t si_uid; /* Real user ID of sending process. */
499 sigval_t si_sigval; /* Signal value. */
500 } _rt;
501
502 /* SIGCHLD. */
503 struct
504 {
505 __pid_t si_pid; /* Which child. */
506 int si_status; /* Exit value or signal. */
507 __clock_t si_utime;
508 __clock_t si_stime;
509 } _sigchld;
510
511 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
512 struct
513 {
514 void *si_addr; /* Faulting insn/memory ref. */
515 } _sigfault;
516
517 /* SIGPOLL. */
518 struct
519 {
520 int si_band; /* Band event for SIGPOLL. */
521 int si_fd;
522 } _sigpoll;
523 } _sifields;
524} siginfo_t;
525
526#define si_pid _sifields._kill.si_pid
527#define si_uid _sifields._kill.si_uid
528#define si_status _sifields._sigchld.si_status
529#define si_utime _sifields._sigchld.si_utime
530#define si_stime _sifields._sigchld.si_stime
531#define si_value _sifields._rt.si_sigval
532#define si_int _sifields._rt.si_sigval.sival_int
533#define si_ptr _sifields._rt.si_sigval.sival_ptr
534#define si_addr _sifields._sigfault.si_addr
535#define si_band _sifields._sigpoll.si_band
536#define si_fd _sifields._sigpoll.si_fd
537
538#endif
539
540#endif
541
542#if defined (SVR4) || defined (LINUX)
543
Roland McGrathd9f816f2004-09-04 03:39:20 +0000544static const struct xlat siginfo_codes[] = {
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000545#ifdef SI_KERNEL
546 { SI_KERNEL, "SI_KERNEL" },
John Hughes58265892001-10-18 15:13:53 +0000547#endif
548#ifdef SI_USER
549 { SI_USER, "SI_USER" },
550#endif
John Hughes58265892001-10-18 15:13:53 +0000551#ifdef SI_QUEUE
552 { SI_QUEUE, "SI_QUEUE" },
553#endif
554#ifdef SI_TIMER
555 { SI_TIMER, "SI_TIMER" },
556#endif
John Hughes58265892001-10-18 15:13:53 +0000557#ifdef SI_MESGQ
558 { SI_MESGQ, "SI_MESGQ" },
559#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000560#ifdef SI_ASYNCIO
561 { SI_ASYNCIO, "SI_ASYNCIO" },
562#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000563#ifdef SI_SIGIO
564 { SI_SIGIO, "SI_SIGIO" },
565#endif
566#ifdef SI_TKILL
567 { SI_TKILL, "SI_TKILL" },
568#endif
Dmitry V. Levin7d4bff12011-03-10 21:41:34 +0000569#ifdef SI_ASYNCNL
570 { SI_ASYNCNL, "SI_ASYNCNL" },
571#endif
572#ifdef SI_NOINFO
573 { SI_NOINFO, "SI_NOINFO" },
574#endif
575#ifdef SI_LWP
576 { SI_LWP, "SI_LWP" },
577#endif
John Hughes58265892001-10-18 15:13:53 +0000578 { 0, NULL },
579};
580
Roland McGrathd9f816f2004-09-04 03:39:20 +0000581static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000582 { ILL_ILLOPC, "ILL_ILLOPC" },
583 { ILL_ILLOPN, "ILL_ILLOPN" },
584 { ILL_ILLADR, "ILL_ILLADR" },
585 { ILL_ILLTRP, "ILL_ILLTRP" },
586 { ILL_PRVOPC, "ILL_PRVOPC" },
587 { ILL_PRVREG, "ILL_PRVREG" },
588 { ILL_COPROC, "ILL_COPROC" },
589 { ILL_BADSTK, "ILL_BADSTK" },
590 { 0, NULL },
591};
592
Roland McGrathd9f816f2004-09-04 03:39:20 +0000593static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000594 { FPE_INTDIV, "FPE_INTDIV" },
595 { FPE_INTOVF, "FPE_INTOVF" },
596 { FPE_FLTDIV, "FPE_FLTDIV" },
597 { FPE_FLTOVF, "FPE_FLTOVF" },
598 { FPE_FLTUND, "FPE_FLTUND" },
599 { FPE_FLTRES, "FPE_FLTRES" },
600 { FPE_FLTINV, "FPE_FLTINV" },
601 { FPE_FLTSUB, "FPE_FLTSUB" },
602 { 0, NULL },
603};
604
Roland McGrathd9f816f2004-09-04 03:39:20 +0000605static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000606 { TRAP_BRKPT, "TRAP_BRKPT" },
607 { TRAP_TRACE, "TRAP_TRACE" },
608 { 0, NULL },
609};
610
Roland McGrathd9f816f2004-09-04 03:39:20 +0000611static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000612 { CLD_EXITED, "CLD_EXITED" },
613 { CLD_KILLED, "CLD_KILLED" },
614 { CLD_DUMPED, "CLD_DUMPED" },
615 { CLD_TRAPPED, "CLD_TRAPPED" },
616 { CLD_STOPPED, "CLD_STOPPED" },
617 { CLD_CONTINUED,"CLD_CONTINUED" },
618 { 0, NULL },
619};
620
Roland McGrathd9f816f2004-09-04 03:39:20 +0000621static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000622 { POLL_IN, "POLL_IN" },
623 { POLL_OUT, "POLL_OUT" },
624 { POLL_MSG, "POLL_MSG" },
625 { POLL_ERR, "POLL_ERR" },
626 { POLL_PRI, "POLL_PRI" },
627 { POLL_HUP, "POLL_HUP" },
628 { 0, NULL },
629};
630
Roland McGrathd9f816f2004-09-04 03:39:20 +0000631static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000632#ifdef PROF_SIG
633 { PROF_SIG, "PROF_SIG" },
634#endif
635 { 0, NULL },
636};
637
638#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000639static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000640#ifdef EMT_TAGOVF
641 { EMT_TAGOVF, "EMT_TAGOVF" },
642#endif
643 { 0, NULL },
644};
645#endif
646
Roland McGrathd9f816f2004-09-04 03:39:20 +0000647static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000648 { SEGV_MAPERR, "SEGV_MAPERR" },
649 { SEGV_ACCERR, "SEGV_ACCERR" },
650 { 0, NULL },
651};
652
Roland McGrathd9f816f2004-09-04 03:39:20 +0000653static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000654 { BUS_ADRALN, "BUS_ADRALN" },
655 { BUS_ADRERR, "BUS_ADRERR" },
656 { BUS_OBJERR, "BUS_OBJERR" },
657 { 0, NULL },
658};
659
660void
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000661printsiginfo(siginfo_t *sip, int verbose)
John Hughes58265892001-10-18 15:13:53 +0000662{
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)) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000722 tprintf(", si_pid=%lu, si_uid=%lu",
723 (unsigned long) sip->si_pid,
724 (unsigned long) sip->si_uid);
John Hughes58265892001-10-18 15:13:53 +0000725 switch (sip->si_code) {
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000726#ifdef SI_USER
727 case SI_USER:
728 break;
729#endif
730#ifdef SI_TKILL
731 case SI_TKILL:
732 break;
733#endif
John Hughes58265892001-10-18 15:13:53 +0000734#ifdef SI_TIMER
735 case SI_TIMER:
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000736 tprintf(", si_value=%d", sip->si_int);
John Hughes58265892001-10-18 15:13:53 +0000737 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000738#endif
739#ifdef LINUX
740 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000741 if (!sip->si_ptr)
742 break;
Dmitry V. Levin6d9e8e82011-03-10 22:18:56 +0000743 if (!verbose)
744 tprintf(", ...");
745 else
746 tprintf(", si_value={int=%u, ptr=%#lx}",
747 sip->si_int,
748 (unsigned long) sip->si_ptr);
749 break;
750#endif
John Hughes58265892001-10-18 15:13:53 +0000751 }
John Hughes58265892001-10-18 15:13:53 +0000752 }
753 else
754#endif /* SI_FROMUSER */
755 {
756 switch (sip->si_signo) {
757 case SIGCHLD:
758 tprintf(", si_pid=%ld, si_status=",
759 (long) sip->si_pid);
760 if (sip->si_code == CLD_EXITED)
761 tprintf("%d", sip->si_status);
762 else
763 printsignal(sip->si_status);
764#if LINUX
765 if (!verbose)
766 tprintf(", ...");
767 else
768 tprintf(", si_utime=%lu, si_stime=%lu",
769 sip->si_utime,
770 sip->si_stime);
771#endif
772 break;
773 case SIGILL: case SIGFPE:
774 case SIGSEGV: case SIGBUS:
775 tprintf(", si_addr=%#lx",
776 (unsigned long) sip->si_addr);
777 break;
778 case SIGPOLL:
779 switch (sip->si_code) {
780 case POLL_IN: case POLL_OUT: case POLL_MSG:
781 tprintf(", si_band=%ld",
782 (long) sip->si_band);
783 break;
784 }
785 break;
786#ifdef LINUX
787 default:
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000788 if (sip->si_pid || sip->si_uid)
789 tprintf(", si_pid=%lu, si_uid=%lu",
790 (unsigned long) sip->si_pid,
791 (unsigned long) sip->si_uid);
792 if (!sip->si_ptr)
793 break;
John Hughes58265892001-10-18 15:13:53 +0000794 if (!verbose)
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000795 tprintf(", ...");
John Hughes58265892001-10-18 15:13:53 +0000796 else {
Dmitry V. Levinb41e1c92011-03-10 23:14:47 +0000797 tprintf(", si_value={int=%u, ptr=%#lx}",
John Hughes58265892001-10-18 15:13:53 +0000798 sip->si_int,
799 (unsigned long) sip->si_ptr);
800 }
801#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000802
John Hughes58265892001-10-18 15:13:53 +0000803 }
804 }
805 }
806 tprintf("}");
807}
808
809#endif /* SVR4 || LINUX */
810
811#ifdef LINUX
812
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000813static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000814parse_sigset_t(const char *str, sigset_t *set)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000815{
Roland McGrathc38feca2003-10-01 07:50:28 +0000816 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000817 unsigned int digit;
818 int i;
819
820 sigemptyset(set);
821
Roland McGrathc38feca2003-10-01 07:50:28 +0000822 p = strchr(str, '\n');
823 if (p == NULL)
824 p = strchr(str, '\0');
825 for (i = 0; p-- > str; i += 4) {
826 if (*p >= '0' && *p <= '9')
827 digit = *p - '0';
828 else if (*p >= 'a' && *p <= 'f')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000829 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000830 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000831 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000832 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000833 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000834 if (digit & 1)
835 sigaddset(set, i + 1);
836 if (digit & 2)
837 sigaddset(set, i + 2);
838 if (digit & 4)
839 sigaddset(set, i + 3);
840 if (digit & 8)
841 sigaddset(set, i + 4);
842 }
843}
844
845#endif
846
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847/*
848 * Check process TCP for the disposition of signal SIG.
849 * Return 1 if the process would somehow manage to survive signal SIG,
850 * else return 0. This routine will never be called with SIGKILL.
851 */
852int
853sigishandled(tcp, sig)
854struct tcb *tcp;
855int sig;
856{
857#ifdef LINUX
858 int sfd;
859 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000860 char buf[2048];
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000861 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000862 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000863 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000864#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000865#ifdef SVR4
866 /*
867 * Since procfs doesn't interfere with wait I think it is safe
868 * to punt on this question. If not, the information is there.
869 */
870 return 1;
871#else /* !SVR4 */
872 switch (sig) {
873 case SIGCONT:
874 case SIGSTOP:
875 case SIGTSTP:
876 case SIGTTIN:
877 case SIGTTOU:
878 case SIGCHLD:
879 case SIGIO:
880#if defined(SIGURG) && SIGURG != SIGIO
881 case SIGURG:
882#endif
883 case SIGWINCH:
884 /* Gloria Gaynor says ... */
885 return 1;
886 default:
887 break;
888 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000889#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000890#ifdef LINUX
891
892 /* This is incredibly costly but it's worth it. */
893 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
894 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
895 doesn't handle real-time signals). */
896 sprintf(sname, "/proc/%d/status", tcp->pid);
897 if ((sfd = open(sname, O_RDONLY)) == -1) {
898 perror(sname);
899 return 1;
900 }
901 i = read(sfd, buf, sizeof(buf));
902 buf[i] = '\0';
903 close(sfd);
904 /*
905 * Skip the extraneous fields. We need to skip
906 * command name has any spaces in it. So be it.
907 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000908 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000909 if (!s)
910 {
911 fprintf(stderr, "/proc/pid/status format error\n");
912 return 1;
913 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000914 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000915
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000916 s = strstr(buf, "SigCgt:\t");
917 if (!s)
918 {
919 fprintf(stderr, "/proc/pid/status format error\n");
920 return 1;
921 }
922 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000923
924#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000925 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
926 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000927#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000928 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000929 return 1;
930#endif /* LINUX */
931
932#ifdef SUNOS4
933 void (*u_signal)();
934
Denys Vlasenko932fc7d2008-12-16 18:18:40 +0000935 if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal),
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000936 (long *) &u_signal) < 0) {
937 return 0;
938 }
939 if (u_signal != SIG_DFL)
940 return 1;
941#endif /* SUNOS4 */
942
943 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944}
945
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000946#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000947
948int
949sys_sigvec(tcp)
950struct tcb *tcp;
951{
952 struct sigvec sv;
953 long addr;
954
955 if (entering(tcp)) {
956 printsignal(tcp->u_arg[0]);
957 tprintf(", ");
958 addr = tcp->u_arg[1];
959 } else {
960 addr = tcp->u_arg[2];
961 }
962 if (addr == 0)
963 tprintf("NULL");
964 else if (!verbose(tcp))
965 tprintf("%#lx", addr);
966 else if (umove(tcp, addr, &sv) < 0)
967 tprintf("{...}");
968 else {
969 switch ((int) sv.sv_handler) {
970 case (int) SIG_ERR:
971 tprintf("{SIG_ERR}");
972 break;
973 case (int) SIG_DFL:
974 tprintf("{SIG_DFL}");
975 break;
976 case (int) SIG_IGN:
977 if (tcp->u_arg[0] == SIGTRAP) {
978 tcp->flags |= TCB_SIGTRAPPED;
979 kill(tcp->pid, SIGSTOP);
980 }
981 tprintf("{SIG_IGN}");
982 break;
983 case (int) SIG_HOLD:
984 if (tcp->u_arg[0] == SIGTRAP) {
985 tcp->flags |= TCB_SIGTRAPPED;
986 kill(tcp->pid, SIGSTOP);
987 }
988 tprintf("SIG_HOLD");
989 break;
990 default:
991 if (tcp->u_arg[0] == SIGTRAP) {
992 tcp->flags |= TCB_SIGTRAPPED;
993 kill(tcp->pid, SIGSTOP);
994 }
995 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000996 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000997 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000998 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000999 tprintf("}");
1000 }
1001 }
1002 if (entering(tcp))
1003 tprintf(", ");
1004 return 0;
1005}
1006
1007int
1008sys_sigpause(tcp)
1009struct tcb *tcp;
1010{
1011 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +00001012 sigset_t sigm;
1013 long_to_sigset(tcp->u_arg[0], &sigm);
1014 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015 }
1016 return 0;
1017}
1018
1019int
1020sys_sigstack(tcp)
1021struct tcb *tcp;
1022{
1023 struct sigstack ss;
1024 long addr;
1025
1026 if (entering(tcp))
1027 addr = tcp->u_arg[0];
1028 else
1029 addr = tcp->u_arg[1];
1030 if (addr == 0)
1031 tprintf("NULL");
1032 else if (umove(tcp, addr, &ss) < 0)
1033 tprintf("%#lx", addr);
1034 else {
1035 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1036 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1037 }
1038 if (entering(tcp))
1039 tprintf(", ");
1040 return 0;
1041}
1042
1043int
1044sys_sigcleanup(tcp)
1045struct tcb *tcp;
1046{
1047 return 0;
1048}
1049
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001050#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001051
1052#ifndef SVR4
1053
1054int
1055sys_sigsetmask(tcp)
1056struct tcb *tcp;
1057{
1058 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001059 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001060 long_to_sigset(tcp->u_arg[0], &sigm);
1061 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001062#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1064 /* Mark attempt to block SIGTRAP */
1065 tcp->flags |= TCB_SIGTRAPPED;
1066 /* Send unblockable signal */
1067 kill(tcp->pid, SIGSTOP);
1068 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001069#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001070 }
1071 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001073 long_to_sigset(tcp->u_rval, &sigm);
1074 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001075
1076 return RVAL_HEX | RVAL_STR;
1077 }
1078 return 0;
1079}
1080
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001081#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001082int
1083sys_sigblock(tcp)
1084struct tcb *tcp;
1085{
1086 return sys_sigsetmask(tcp);
1087}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001088#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001089
1090#endif /* !SVR4 */
1091
1092#ifdef HAVE_SIGACTION
1093
1094#ifdef LINUX
1095struct old_sigaction {
1096 __sighandler_t __sa_handler;
1097 unsigned long sa_mask;
1098 unsigned long sa_flags;
1099 void (*sa_restorer)(void);
1100};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001101#define SA_HANDLER __sa_handler
1102#endif /* LINUX */
1103
Roland McGratha39c5a12002-12-17 05:10:37 +00001104#ifndef SA_HANDLER
1105#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001106#endif
1107
1108int
1109sys_sigaction(tcp)
1110struct tcb *tcp;
1111{
1112 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001113#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001114 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001115 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001116#else
1117 struct sigaction sa;
1118#endif
1119
1120
1121 if (entering(tcp)) {
1122 printsignal(tcp->u_arg[0]);
1123 tprintf(", ");
1124 addr = tcp->u_arg[1];
1125 } else
1126 addr = tcp->u_arg[2];
1127 if (addr == 0)
1128 tprintf("NULL");
1129 else if (!verbose(tcp))
1130 tprintf("%#lx", addr);
1131 else if (umove(tcp, addr, &sa) < 0)
1132 tprintf("{...}");
1133 else {
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001134 /* Architectures using function pointers, like
1135 * hppa, may need to manipulate the function pointer
1136 * to compute the result of a comparison. However,
1137 * the SA_HANDLER function pointer exists only in
1138 * the address space of the traced process, and can't
1139 * be manipulated by strace. In order to prevent the
1140 * compiler from generating code to manipulate
1141 * SA_HANDLER we cast the function pointers to long. */
1142 if ((long)sa.SA_HANDLER == (long)SIG_ERR)
Roland McGrath5f206812008-08-20 01:59:40 +00001143 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001144 else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
Roland McGrath5f206812008-08-20 01:59:40 +00001145 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001146 else if ((long)sa.SA_HANDLER == (long)SIG_IGN) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001147#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001148 if (tcp->u_arg[0] == SIGTRAP) {
1149 tcp->flags |= TCB_SIGTRAPPED;
1150 kill(tcp->pid, SIGSTOP);
1151 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001152#endif /* !USE_PROCFS */
Roland McGrath5f206812008-08-20 01:59:40 +00001153 tprintf("{SIG_IGN, ");
1154 }
1155 else {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001156#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001157 if (tcp->u_arg[0] == SIGTRAP) {
1158 tcp->flags |= TCB_SIGTRAPPED;
1159 kill(tcp->pid, SIGSTOP);
1160 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001161#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001162 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001163#ifndef LINUX
1164 printsigmask (&sa.sa_mask, 0);
1165#else
Nate Sammons4a121431999-04-06 01:19:39 +00001166 long_to_sigset(sa.sa_mask, &sigset);
1167 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001168#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001169 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001170 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001171#ifdef SA_RESTORER
1172 if (sa.sa_flags & SA_RESTORER)
1173 tprintf(", %p", sa.sa_restorer);
1174#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001175 tprintf("}");
1176 }
1177 }
1178 if (entering(tcp))
1179 tprintf(", ");
1180#ifdef LINUX
1181 else
1182 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1183#endif
1184 return 0;
1185}
1186
1187int
1188sys_signal(tcp)
1189struct tcb *tcp;
1190{
1191 if (entering(tcp)) {
1192 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001193 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001194 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001195 case (long) SIG_ERR:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001196 tprintf("SIG_ERR");
1197 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001198 case (long) SIG_DFL:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001199 tprintf("SIG_DFL");
1200 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001201 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001202#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001203 if (tcp->u_arg[0] == SIGTRAP) {
1204 tcp->flags |= TCB_SIGTRAPPED;
1205 kill(tcp->pid, SIGSTOP);
1206 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001207#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001208 tprintf("SIG_IGN");
1209 break;
1210 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001211#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001212 if (tcp->u_arg[0] == SIGTRAP) {
1213 tcp->flags |= TCB_SIGTRAPPED;
1214 kill(tcp->pid, SIGSTOP);
1215 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001216#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001217 tprintf("%#lx", tcp->u_arg[1]);
1218 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001219 return 0;
1220 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001221 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001222 switch (tcp->u_rval) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001223 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001224 tcp->auxstr = "SIG_ERR"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001225 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001226 tcp->auxstr = "SIG_DFL"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001227 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001228 tcp->auxstr = "SIG_IGN"; break;
1229 default:
1230 tcp->auxstr = NULL;
1231 }
1232 return RVAL_HEX | RVAL_STR;
1233 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001234 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001235}
1236
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001237#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001238int
1239sys_sighold(tcp)
1240struct tcb *tcp;
1241{
1242 if (entering(tcp)) {
1243 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001244 }
1245 return 0;
1246}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001247#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248
1249#endif /* HAVE_SIGACTION */
1250
1251#ifdef LINUX
1252
1253int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001254sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001255{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001256#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001257 struct pt_regs regs;
1258 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001259
Roland McGrath0f87c492003-06-03 23:29:04 +00001260 if (entering(tcp)) {
1261 tcp->u_arg[0] = 0;
1262
1263 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1264 return 0;
1265
1266 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1267 return 0;
1268
1269 tcp->u_arg[0] = 1;
1270 tcp->u_arg[1] = sc.oldmask;
1271 } else {
1272 sigset_t sigm;
1273 long_to_sigset(tcp->u_arg[1], &sigm);
1274 tcp->u_rval = tcp->u_error = 0;
1275 if (tcp->u_arg[0] == 0)
1276 return 0;
1277 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1278 return RVAL_NONE | RVAL_STR;
1279 }
1280 return 0;
1281#elif defined(S390) || defined(S390X)
1282 long usp;
1283 struct sigcontext_struct sc;
1284
1285 if (entering(tcp)) {
1286 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001287 if (upeek(tcp,PT_GPR15,&usp)<0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001288 return 0;
1289 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1290 return 0;
1291 tcp->u_arg[0] = 1;
1292 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1293 } else {
1294 tcp->u_rval = tcp->u_error = 0;
1295 if (tcp->u_arg[0] == 0)
1296 return 0;
1297 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1298 return RVAL_NONE | RVAL_STR;
1299 }
1300 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001301#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001302 long esp;
1303 struct sigcontext_struct sc;
1304
1305 if (entering(tcp)) {
1306 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001307 if (upeek(tcp, 4*UESP, &esp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308 return 0;
1309 if (umove(tcp, esp, &sc) < 0)
1310 return 0;
1311 tcp->u_arg[0] = 1;
1312 tcp->u_arg[1] = sc.oldmask;
1313 }
1314 else {
1315 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001316 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001317 tcp->u_rval = tcp->u_error = 0;
1318 if (tcp->u_arg[0] == 0)
1319 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001320 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001321 return RVAL_NONE | RVAL_STR;
1322 }
1323 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001324#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001325 struct sigcontext sc;
1326 long sp;
1327
1328 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001329 /* offset of sigcontext in the kernel's sigframe structure: */
1330# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001331 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001332 if (upeek(tcp, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001333 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001334 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001335 return 0;
1336 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001337 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001338 }
1339 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001340 sigset_t sigm;
1341
1342 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001343 tcp->u_rval = tcp->u_error = 0;
1344 if (tcp->u_arg[0] == 0)
1345 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001346 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001347 return RVAL_NONE | RVAL_STR;
1348 }
1349 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001350#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +00001351 long esp;
1352 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001353
Roland McGrath0f87c492003-06-03 23:29:04 +00001354 if (entering(tcp)) {
1355 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001356 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001357 return 0;
Andreas Schwabedb39342010-02-23 00:18:51 +01001358 /* Skip dummy stack frame. */
Andreas Schwabd69fa492010-07-12 21:39:57 +02001359#ifdef POWERPC64
1360 if (current_personality == 0)
1361 esp += 128;
1362 else
1363 esp += 64;
Andreas Schwabedb39342010-02-23 00:18:51 +01001364#else
1365 esp += 64;
1366#endif
Roland McGrath0f87c492003-06-03 23:29:04 +00001367 if (umove(tcp, esp, &sc) < 0)
1368 return 0;
1369 tcp->u_arg[0] = 1;
1370 tcp->u_arg[1] = sc.oldmask;
1371 }
1372 else {
1373 sigset_t sigm;
1374 long_to_sigset(tcp->u_arg[1], &sigm);
1375 tcp->u_rval = tcp->u_error = 0;
1376 if (tcp->u_arg[0] == 0)
1377 return 0;
1378 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1379 return RVAL_NONE | RVAL_STR;
1380 }
1381 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001382#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001383 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001384 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385
1386 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001387 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001388 if (upeek(tcp, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001389 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001390 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001391 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001392 tcp->u_arg[0] = 1;
1393 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001394 }
1395 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001396 sigset_t sigm;
1397 long_to_sigset(tcp->u_arg[1], &sigm);
1398 tcp->u_rval = tcp->u_error = 0;
1399 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001400 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001401 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1402 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001403 }
1404 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001405#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001406 long fp;
1407 struct sigcontext_struct sc;
1408
1409 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001410 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001411 if (upeek(tcp, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001412 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001413 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001414 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001415 tcp->u_arg[0] = 1;
1416 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001417 }
1418 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001419 sigset_t sigm;
1420 long_to_sigset(tcp->u_arg[1], &sigm);
1421 tcp->u_rval = tcp->u_error = 0;
1422 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001423 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001424 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1425 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001426 }
1427 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001428#elif defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001429 long i1;
Mike Frysinger8566c502009-10-12 11:05:14 -04001430 struct pt_regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431 m_siginfo_t si;
1432
Roland McGratheb9e2e82009-06-02 16:49:22 -07001433 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1434 perror("sigreturn: PTRACE_GETREGS ");
Roland McGrath0f87c492003-06-03 23:29:04 +00001435 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001436 }
Roland McGratheb9e2e82009-06-02 16:49:22 -07001437 if(entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001438 tcp->u_arg[0] = 0;
Mike Frysinger8566c502009-10-12 11:05:14 -04001439 i1 = regs.u_regs[U_REG_O1];
Roland McGratheb9e2e82009-06-02 16:49:22 -07001440 if(umove(tcp, i1, &si) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001441 perror("sigreturn: umove ");
1442 return 0;
1443 }
1444 tcp->u_arg[0] = 1;
1445 tcp->u_arg[1] = si.si_mask;
1446 } else {
1447 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001448 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001449 tcp->u_rval = tcp->u_error = 0;
1450 if(tcp->u_arg[0] == 0)
1451 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001452 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001453 return RVAL_NONE | RVAL_STR;
1454 }
1455 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001456#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001457 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1458 sigreturn. */
1459 long sp;
1460 struct ucontext uc;
1461
1462 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001463 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001464 if (upeek(tcp, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001465 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001466 /* There are six words followed by a 128-byte siginfo. */
1467 sp = sp + 6 * 4 + 128;
1468 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001469 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001470 tcp->u_arg[0] = 1;
1471 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1472 } else {
1473 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;
Roland McGrath542c2c62008-05-20 01:11:56 +00001476 if(tcp->u_arg[0] == 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001477 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001478 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1479 return RVAL_NONE | RVAL_STR;
1480 }
1481 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001482#elif defined(MIPS)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001483 long sp;
Roland McGrath576b7842007-11-04 00:00:00 +00001484 struct pt_regs regs;
1485 m_siginfo_t si;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001486
Roland McGrath576b7842007-11-04 00:00:00 +00001487 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1488 perror("sigreturn: PTRACE_GETREGS ");
1489 return 0;
1490 }
Wichert Akkermanf90da011999-10-31 21:15:38 +00001491 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001492 tcp->u_arg[0] = 0;
Roland McGrath576b7842007-11-04 00:00:00 +00001493 sp = regs.regs[29];
1494 if (umove(tcp, sp, &si) < 0)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001495 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001496 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001497 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001498 sigset_t sigm;
1499 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001500 tcp->u_rval = tcp->u_error = 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001501 if(tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001502 return 0;
1503 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001504 return RVAL_NONE | RVAL_STR;
1505 }
1506 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001507#elif defined(CRISV10) || defined(CRISV32)
1508 struct sigcontext sc;
1509
1510 if (entering(tcp)) {
1511 long regs[PT_MAX+1];
1512
1513 tcp->u_arg[0] = 0;
1514
1515 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1516 perror("sigreturn: PTRACE_GETREGS");
1517 return 0;
1518 }
1519 if (umove(tcp, regs[PT_USP], &sc) < 0)
1520 return 0;
1521 tcp->u_arg[0] = 1;
1522 tcp->u_arg[1] = sc.oldmask;
1523 } else {
1524 sigset_t sigm;
1525 long_to_sigset(tcp->u_arg[1], &sigm);
1526 tcp->u_rval = tcp->u_error = 0;
1527
1528 if (tcp->u_arg[0] == 0)
1529 return 0;
1530 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1531 return RVAL_NONE | RVAL_STR;
1532 }
1533 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -05001534#elif defined(TILE)
1535 struct ucontext uc;
1536 long sp;
1537
1538 /* offset of ucontext in the kernel's sigframe structure */
1539# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo)
1540
1541 if (entering(tcp)) {
1542 tcp->u_arg[0] = 0;
1543 if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0)
1544 return 0;
1545 if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1546 return 0;
1547 tcp->u_arg[0] = 1;
1548 memcpy(tcp->u_arg + 1, &uc.uc_sigmask, sizeof(uc.uc_sigmask));
1549 }
1550 else {
1551 sigset_t sigm;
1552
1553 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
1554 tcp->u_rval = tcp->u_error = 0;
1555 if (tcp->u_arg[0] == 0)
1556 return 0;
1557 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1558 return RVAL_NONE | RVAL_STR;
1559 }
1560 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02001561#elif defined(MICROBLAZE)
1562 struct sigcontext sc;
1563
1564 /* TODO: Verify that this is correct... */
1565 if (entering(tcp)) {
1566 long sp;
1567
1568 tcp->u_arg[0] = 0;
1569
1570 /* Read r1, the stack pointer. */
1571 if (upeek(tcp, 1 * 4, &sp) < 0)
1572 return 0;
1573 if (umove(tcp, sp, &sc) < 0)
1574 return 0;
1575 tcp->u_arg[0] = 1;
1576 tcp->u_arg[1] = sc.oldmask;
1577 } else {
1578 sigset_t sigm;
1579 long_to_sigset(tcp->u_arg[1], &sigm);
1580 tcp->u_rval = tcp->u_error = 0;
1581 if (tcp->u_arg[0] == 0)
1582 return 0;
1583 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1584 return RVAL_NONE | RVAL_STR;
1585 }
1586 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001587#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001588#warning No sys_sigreturn() for this architecture
1589#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001590 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001591#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001592}
1593
1594int
1595sys_siggetmask(tcp)
1596struct tcb *tcp;
1597{
1598 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001599 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001600 long_to_sigset(tcp->u_rval, &sigm);
1601 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001602 }
1603 return RVAL_HEX | RVAL_STR;
1604}
1605
1606int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001607sys_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001608{
1609 if (entering(tcp)) {
1610 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001611 long_to_sigset(tcp->u_arg[2], &sigm);
Nate Sammons4a121431999-04-06 01:19:39 +00001612 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001613 }
1614 return 0;
1615}
1616
1617#endif /* LINUX */
1618
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001619#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001620
1621int
1622sys_sigsuspend(tcp)
1623struct tcb *tcp;
1624{
1625 sigset_t sigset;
1626
1627 if (entering(tcp)) {
1628 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1629 tprintf("[?]");
1630 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001631 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001632 }
1633 return 0;
1634}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001635#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001636static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001637 { UC_SIGMASK, "UC_SIGMASK" },
1638 { UC_STACK, "UC_STACK" },
1639 { UC_CPU, "UC_CPU" },
1640#ifdef UC_FPU
1641 { UC_FPU, "UC_FPU" },
1642#endif
1643#ifdef UC_INTR
1644 { UC_INTR, "UC_INTR" },
1645#endif
1646 { 0, NULL },
1647};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001648#endif /* !FREEBSD */
1649#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001650
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001651#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001652#if defined LINUX && !defined SS_ONSTACK
1653#define SS_ONSTACK 1
1654#define SS_DISABLE 2
1655#if __GLIBC_MINOR__ == 0
1656typedef struct
1657{
1658 __ptr_t ss_sp;
1659 int ss_flags;
1660 size_t ss_size;
1661} stack_t;
1662#endif
1663#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001664#ifdef FREEBSD
1665#define stack_t struct sigaltstack
1666#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001667
Roland McGrathd9f816f2004-09-04 03:39:20 +00001668static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001669 { SS_ONSTACK, "SS_ONSTACK" },
1670 { SS_DISABLE, "SS_DISABLE" },
1671 { 0, NULL },
1672};
1673#endif
1674
1675#ifdef SVR4
1676static void
1677printcontext(tcp, ucp)
1678struct tcb *tcp;
1679ucontext_t *ucp;
1680{
1681 tprintf("{");
1682 if (!abbrev(tcp)) {
1683 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001684 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001685 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1686 }
1687 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001688 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001689 if (!abbrev(tcp)) {
1690 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1691 (unsigned long) ucp->uc_stack.ss_sp,
1692 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001693 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001694 tprintf("}");
1695 }
1696 tprintf(", ...}");
1697}
1698
1699int
1700sys_getcontext(tcp)
1701struct tcb *tcp;
1702{
1703 ucontext_t uc;
1704
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001705 if (exiting(tcp)) {
1706 if (tcp->u_error)
1707 tprintf("%#lx", tcp->u_arg[0]);
1708 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001709 tprintf("NULL");
1710 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1711 tprintf("{...}");
1712 else
1713 printcontext(tcp, &uc);
1714 }
1715 return 0;
1716}
1717
1718int
1719sys_setcontext(tcp)
1720struct tcb *tcp;
1721{
1722 ucontext_t uc;
1723
1724 if (entering(tcp)) {
1725 if (!tcp->u_arg[0])
1726 tprintf("NULL");
1727 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1728 tprintf("{...}");
1729 else
1730 printcontext(tcp, &uc);
1731 }
1732 else {
1733 tcp->u_rval = tcp->u_error = 0;
1734 if (tcp->u_arg[0] == 0)
1735 return 0;
1736 return RVAL_NONE;
1737 }
1738 return 0;
1739}
1740
1741#endif /* SVR4 */
1742
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001743#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001744
1745static int
1746print_stack_t(tcp, addr)
1747struct tcb *tcp;
1748unsigned long addr;
1749{
1750 stack_t ss;
1751 if (umove(tcp, addr, &ss) < 0)
1752 return -1;
1753 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001754 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001755 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1756 return 0;
1757}
1758
1759int
1760sys_sigaltstack(tcp)
1761 struct tcb *tcp;
1762{
1763 if (entering(tcp)) {
1764 if (tcp->u_arg[0] == 0)
1765 tprintf("NULL");
1766 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1767 return -1;
1768 }
1769 else {
1770 tprintf(", ");
1771 if (tcp->u_arg[1] == 0)
1772 tprintf("NULL");
1773 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1774 return -1;
1775 }
1776 return 0;
1777}
1778#endif
1779
1780#ifdef HAVE_SIGACTION
1781
1782int
1783sys_sigprocmask(tcp)
1784struct tcb *tcp;
1785{
1786#ifdef ALPHA
1787 if (entering(tcp)) {
1788 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1789 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001790 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791 }
1792 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001793 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001794 return RVAL_HEX | RVAL_STR;
1795 }
1796#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001797 if (entering(tcp)) {
1798#ifdef SVR4
1799 if (tcp->u_arg[0] == 0)
1800 tprintf("0");
1801 else
1802#endif /* SVR4 */
1803 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1804 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001805 print_sigset(tcp, tcp->u_arg[1], 0);
1806 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001807 }
1808 else {
1809 if (!tcp->u_arg[2])
1810 tprintf("NULL");
1811 else if (syserror(tcp))
1812 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001813 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001814 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001815 }
1816#endif /* !ALPHA */
1817 return 0;
1818}
1819
1820#endif /* HAVE_SIGACTION */
1821
1822int
1823sys_kill(tcp)
1824struct tcb *tcp;
1825{
1826 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001827 /*
1828 * Sign-extend a 32-bit value when that's what it is.
1829 */
1830 long pid = tcp->u_arg[0];
1831 if (personality_wordsize[current_personality] < sizeof pid)
1832 pid = (long) (int) pid;
1833 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001834 }
1835 return 0;
1836}
1837
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001838#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001839int
1840sys_killpg(tcp)
1841struct tcb *tcp;
1842{
1843 return sys_kill(tcp);
1844}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001845#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001846
Roland McGrath8ffc3522003-07-09 09:47:49 +00001847#ifdef LINUX
1848int
1849sys_tgkill(tcp)
1850 struct tcb *tcp;
1851{
1852 if (entering(tcp)) {
1853 tprintf("%ld, %ld, %s",
1854 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1855 }
1856 return 0;
1857}
1858#endif
1859
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001860int
1861sys_sigpending(tcp)
1862struct tcb *tcp;
1863{
1864 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001865
1866 if (exiting(tcp)) {
1867 if (syserror(tcp))
1868 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001869 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001870 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001871 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001872 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001873 }
1874 return 0;
1875}
1876
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001877#ifdef SVR4
John Hughes42162082001-10-18 14:48:26 +00001878int sys_sigwait(tcp)
1879struct tcb *tcp;
1880{
1881 sigset_t sigset;
1882
1883 if (entering(tcp)) {
1884 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1885 tprintf("[?]");
1886 else
1887 printsigmask(&sigset, 0);
1888 }
1889 else {
1890 if (!syserror(tcp)) {
1891 tcp->auxstr = signalent[tcp->u_rval];
1892 return RVAL_DECIMAL | RVAL_STR;
1893 }
1894 }
1895 return 0;
1896}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001897#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001898
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001899#ifdef LINUX
1900
1901 int
1902sys_rt_sigprocmask(tcp)
1903 struct tcb *tcp;
1904{
1905 sigset_t sigset;
1906
Nate Sammons4a121431999-04-06 01:19:39 +00001907 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001908 if (entering(tcp)) {
1909 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1910 tprintf(", ");
1911 if (!tcp->u_arg[1])
1912 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001913 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001914 tprintf("%#lx, ", tcp->u_arg[1]);
1915 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001916 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001917 tprintf(", ");
1918 }
1919 }
1920 else {
1921 if (!tcp->u_arg[2])
1922
1923 tprintf("NULL");
1924 else if (syserror(tcp))
1925 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001926 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001927 tprintf("[?]");
1928 else
Nate Sammons4a121431999-04-06 01:19:39 +00001929 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001930 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001931 }
1932 return 0;
1933}
1934
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001935
1936/* Structure describing the action to be taken when a signal arrives. */
1937struct new_sigaction
1938{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001939 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001940 unsigned long sa_flags;
1941 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001942 /* Kernel treats sa_mask as an array of longs. */
1943 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1944};
1945/* Same for i386-on-x86_64 and similar cases */
1946struct new_sigaction32
1947{
1948 uint32_t __sa_handler;
1949 uint32_t sa_flags;
1950 uint32_t sa_restorer;
1951 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001952};
1953
1954
Roland McGrath5f206812008-08-20 01:59:40 +00001955int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001956sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001957{
1958 struct new_sigaction sa;
1959 sigset_t sigset;
1960 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001961 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001962
1963 if (entering(tcp)) {
1964 printsignal(tcp->u_arg[0]);
1965 tprintf(", ");
1966 addr = tcp->u_arg[1];
1967 } else
1968 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001969
1970 if (addr == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001971 tprintf("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001972 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001973 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001974 if (!verbose(tcp)) {
1975 tprintf("%#lx", addr);
1976 goto after_sa;
1977 }
1978#if SUPPORTED_PERSONALITIES > 1
1979 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1980 && personality_wordsize[current_personality] == 4
1981 ) {
1982 struct new_sigaction32 sa32;
1983 r = umove(tcp, addr, &sa32);
1984 if (r >= 0) {
1985 memset(&sa, 0, sizeof(sa));
1986 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1987 sa.sa_flags = sa32.sa_flags;
1988 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1989 /* Kernel treats sa_mask as an array of longs.
1990 * For 32-bit process, "long" is uint32_t, thus, for example,
1991 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1992 * But for (64-bit) kernel, 32th bit in sa_mask is
1993 * 32th bit in 0th (64-bit) long!
1994 * For little-endian, it's the same.
1995 * For big-endian, we swap 32-bit words.
1996 */
1997 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1998 }
1999 } else
2000#endif
2001 {
2002 r = umove(tcp, addr, &sa);
2003 }
2004 if (r < 0) {
2005 tprintf("{...}");
2006 goto after_sa;
2007 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00002008 /* Architectures using function pointers, like
2009 * hppa, may need to manipulate the function pointer
2010 * to compute the result of a comparison. However,
2011 * the SA_HANDLER function pointer exists only in
2012 * the address space of the traced process, and can't
2013 * be manipulated by strace. In order to prevent the
2014 * compiler from generating code to manipulate
2015 * SA_HANDLER we cast the function pointers to long. */
2016 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00002017 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00002018 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00002019 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00002020 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00002021 tprintf("{SIG_IGN, ");
2022 else
2023 tprintf("{%#lx, ", (long) sa.__sa_handler);
2024 /* Questionable code below.
2025 * Kernel won't handle sys_rt_sigaction
2026 * with wrong sigset size (just returns EINVAL)
2027 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
2028 * and we always use smaller memcpy. */
2029 sigemptyset(&sigset);
2030#ifdef LINUXSPARC
2031 if (tcp->u_arg[4] <= sizeof(sigset))
2032 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
2033#else
2034 if (tcp->u_arg[3] <= sizeof(sigset))
2035 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
2036#endif
2037 else
2038 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
2039 printsigmask(&sigset, 1);
2040 tprintf(", ");
2041 printflags(sigact_flags, sa.sa_flags, "SA_???");
2042#ifdef SA_RESTORER
2043 if (sa.sa_flags & SA_RESTORER)
2044 tprintf(", %p", sa.sa_restorer);
2045#endif
2046 tprintf("}");
2047
2048 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002049 if (entering(tcp))
2050 tprintf(", ");
2051 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00002052#ifdef LINUXSPARC
2053 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
2054#elif defined(ALPHA)
2055 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
2056#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00002057 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00002058#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002059 return 0;
2060}
2061
Denys Vlasenko1d632462009-04-14 12:51:00 +00002062int
2063sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002064{
2065 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002066
2067 if (exiting(tcp)) {
2068 if (syserror(tcp))
2069 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00002070 else if (copy_sigset_len(tcp, tcp->u_arg[0],
2071 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002072 tprintf("[?]");
2073 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002074 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002075 }
2076 return 0;
2077}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002078
2079int
2080sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002081{
2082 if (entering(tcp)) {
2083 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00002084 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
2085 tprintf("[?]");
2086 else
2087 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002088 }
2089 return 0;
2090}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002091
2092int
2093sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002094{
2095 if (entering(tcp)) {
2096 siginfo_t si;
2097 tprintf("%lu, ", tcp->u_arg[0]);
2098 printsignal(tcp->u_arg[1]);
2099 tprintf(", ");
2100 if (umove(tcp, tcp->u_arg[2], &si) < 0)
2101 tprintf("%#lx", tcp->u_arg[2]);
2102 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002103 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002104 }
2105 return 0;
2106}
2107
Denys Vlasenko1d632462009-04-14 12:51:00 +00002108int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002109{
2110 if (entering(tcp)) {
2111 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002112
Roland McGratha39c5a12002-12-17 05:10:37 +00002113 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00002114 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002115 tprintf("[?]");
2116 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002117 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002118 tprintf(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002119 /* This is the only "return" parameter, */
2120 if (tcp->u_arg[1] != 0)
2121 return 0;
2122 /* ... if it's NULL, can decode all on entry */
2123 tprintf("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002124 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002125 else if (tcp->u_arg[1] != 0) {
2126 /* syscall exit, and u_arg[1] wasn't NULL */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002127 if (syserror(tcp))
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002128 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002129 else {
2130 siginfo_t si;
2131 if (umove(tcp, tcp->u_arg[1], &si) < 0)
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002132 tprintf("%#lx, ", tcp->u_arg[1]);
2133 else {
Denys Vlasenkof535b542009-01-13 18:30:55 +00002134 printsiginfo(&si, verbose(tcp));
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002135 tprintf(", ");
2136 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002137 }
2138 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002139 else {
2140 /* syscall exit, and u_arg[1] was NULL */
2141 return 0;
2142 }
2143 print_timespec(tcp, tcp->u_arg[2]);
2144 tprintf(", %d", (int) tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002145 return 0;
2146};
2147
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002148int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002149sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002150{
2151 if (entering(tcp))
2152 tprintf("<... resuming interrupted call ...>");
2153 return 0;
2154}
2155
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002156static int
2157do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00002158{
2159 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002160 printfd(tcp, tcp->u_arg[0]);
2161 tprintf(", ");
Roland McGrathf46ccd32007-08-02 01:15:59 +00002162 print_sigset(tcp, tcp->u_arg[1], 1);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00002163 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002164 if (flags_arg >= 0) {
2165 tprintf(", ");
2166 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2167 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00002168 }
2169 return 0;
2170}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002171
2172int
2173sys_signalfd(struct tcb *tcp)
2174{
2175 return do_signalfd(tcp, -1);
2176}
2177
2178int
2179sys_signalfd4(struct tcb *tcp)
2180{
2181 return do_signalfd(tcp, 3);
2182}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002183#endif /* LINUX */