blob: 4f3111a89e2d2be8ac42dd75a674958e1d7e9607 [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
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000075#if HAVE_ASM_REG_H
Roland McGrath6d1a65c2004-07-12 07:44:08 +000076# if defined (SPARC) || defined (SPARC64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000077# define fpq kernel_fpq
78# define fq kernel_fq
79# define fpu kernel_fpu
Roland McGrath30ff45e2003-01-30 20:15:23 +000080# endif
81# include <asm/reg.h>
Roland McGrath6d1a65c2004-07-12 07:44:08 +000082# if defined (SPARC) || defined (SPARC64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000083# undef fpq
84# undef fq
Roland McGratha39c5a12002-12-17 05:10:37 +000085# undef fpu
Roland McGrath30ff45e2003-01-30 20:15:23 +000086# endif
Roland McGrath6d1a65c2004-07-12 07:44:08 +000087#if defined (LINUX) && defined (SPARC64)
88# define r_pc r_tpc
89# undef PTRACE_GETREGS
90# define PTRACE_GETREGS PTRACE_GETREGS64
91# undef PTRACE_SETREGS
92# define PTRACE_SETREGS PTRACE_SETREGS64
93#endif /* LINUX && SPARC64 */
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000094#endif /* HAVE_ASM_REG_H */
Roland McGrath30ff45e2003-01-30 20:15:23 +000095
Roland McGrath6d1a65c2004-07-12 07:44:08 +000096#if defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000097typedef struct {
Wichert Akkerman9ce1a631999-08-29 23:15:07 +000098 struct regs si_regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000099 int si_mask;
100} m_siginfo_t;
Roland McGrath576b7842007-11-04 00:00:00 +0000101#elif defined (MIPS)
102typedef struct {
103 struct pt_regs si_regs;
104 int si_mask;
105} m_siginfo_t;
Roland McGrath30ff45e2003-01-30 20:15:23 +0000106#elif defined HAVE_ASM_SIGCONTEXT_H
107#if !defined(IA64) && !defined(X86_64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000108#include <asm/sigcontext.h>
Roland McGrath30ff45e2003-01-30 20:15:23 +0000109#endif /* !IA64 && !X86_64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000110#else /* !HAVE_ASM_SIGCONTEXT_H */
Roland McGrath0cbb4e42008-05-20 01:26:21 +0000111#if defined I386 && !defined HAVE_STRUCT_SIGCONTEXT_STRUCT
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000112struct sigcontext_struct {
113 unsigned short gs, __gsh;
114 unsigned short fs, __fsh;
115 unsigned short es, __esh;
116 unsigned short ds, __dsh;
117 unsigned long edi;
118 unsigned long esi;
119 unsigned long ebp;
120 unsigned long esp;
121 unsigned long ebx;
122 unsigned long edx;
123 unsigned long ecx;
124 unsigned long eax;
125 unsigned long trapno;
126 unsigned long err;
127 unsigned long eip;
128 unsigned short cs, __csh;
129 unsigned long eflags;
130 unsigned long esp_at_signal;
131 unsigned short ss, __ssh;
132 unsigned long i387;
133 unsigned long oldmask;
134 unsigned long cr2;
135};
136#else /* !I386 */
Roland McGrath587c7b52009-02-11 03:03:28 +0000137#if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000138struct sigcontext
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000139{
140 unsigned long sc_mask;
141 unsigned long sc_usp;
142 unsigned long sc_d0;
143 unsigned long sc_d1;
144 unsigned long sc_a0;
145 unsigned long sc_a1;
146 unsigned short sc_sr;
147 unsigned long sc_pc;
148 unsigned short sc_formatvec;
149};
150#endif /* M68K */
151#endif /* !I386 */
152#endif /* !HAVE_ASM_SIGCONTEXT_H */
153#ifndef NSIG
154#define NSIG 32
155#endif
156#ifdef ARM
157#undef NSIG
158#define NSIG 32
159#endif
160#endif /* LINUX */
161
Roland McGrathee36ce12004-09-04 03:53:10 +0000162const char *const signalent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163#include "signalent.h"
164};
Roland McGrathee36ce12004-09-04 03:53:10 +0000165const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166
167#if SUPPORTED_PERSONALITIES >= 2
Roland McGrathee36ce12004-09-04 03:53:10 +0000168const char *const signalent1[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000169#include "signalent1.h"
170};
Roland McGrathee36ce12004-09-04 03:53:10 +0000171const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172#endif /* SUPPORTED_PERSONALITIES >= 2 */
173
174#if SUPPORTED_PERSONALITIES >= 3
Roland McGrathee36ce12004-09-04 03:53:10 +0000175const char *const signalent2[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176#include "signalent2.h"
177};
Roland McGrathee36ce12004-09-04 03:53:10 +0000178const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179#endif /* SUPPORTED_PERSONALITIES >= 3 */
180
Roland McGrathee36ce12004-09-04 03:53:10 +0000181const char *const *signalent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182int nsignals;
183
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000184#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185
Roland McGrathd9f816f2004-09-04 03:39:20 +0000186static const struct xlat sigvec_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187 { SV_ONSTACK, "SV_ONSTACK" },
188 { SV_INTERRUPT, "SV_INTERRUPT" },
189 { SV_RESETHAND, "SV_RESETHAND" },
190 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
191 { 0, NULL },
192};
193
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000194#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195
196#ifdef HAVE_SIGACTION
197
Roland McGrath063ae2d2005-02-02 04:16:54 +0000198#if defined LINUX && (defined I386 || defined X86_64)
Roland McGrath2638cb42002-12-15 23:58:41 +0000199/* The libc headers do not define this constant since it should only be
200 used by the implementation. So wwe define it here. */
201# ifndef SA_RESTORER
202# define SA_RESTORER 0x04000000
203# endif
204#endif
205
Roland McGrathd9f816f2004-09-04 03:39:20 +0000206static const struct xlat sigact_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000207#ifdef SA_RESTORER
208 { SA_RESTORER, "SA_RESTORER" },
209#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000210#ifdef SA_STACK
211 { SA_STACK, "SA_STACK" },
212#endif
213#ifdef SA_RESTART
214 { SA_RESTART, "SA_RESTART" },
215#endif
216#ifdef SA_INTERRUPT
217 { SA_INTERRUPT, "SA_INTERRUPT" },
218#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000219#ifdef SA_NODEFER
220 { SA_NODEFER, "SA_NODEFER" },
221#endif
222#if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223 { SA_NOMASK, "SA_NOMASK" },
224#endif
Roland McGrath4fef51d2008-07-18 01:02:41 +0000225#ifdef SA_RESETHAND
226 { SA_RESETHAND, "SA_RESETHAND" },
227#endif
228#if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229 { SA_ONESHOT, "SA_ONESHOT" },
230#endif
231#ifdef SA_SIGINFO
232 { SA_SIGINFO, "SA_SIGINFO" },
233#endif
234#ifdef SA_RESETHAND
235 { SA_RESETHAND, "SA_RESETHAND" },
236#endif
237#ifdef SA_ONSTACK
238 { SA_ONSTACK, "SA_ONSTACK" },
239#endif
240#ifdef SA_NODEFER
241 { SA_NODEFER, "SA_NODEFER" },
242#endif
243#ifdef SA_NOCLDSTOP
244 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
245#endif
246#ifdef SA_NOCLDWAIT
247 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
248#endif
249#ifdef _SA_BSDCALL
250 { _SA_BSDCALL, "_SA_BSDCALL" },
251#endif
252 { 0, NULL },
253};
254
Roland McGrathd9f816f2004-09-04 03:39:20 +0000255static const struct xlat sigprocmaskcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000256 { SIG_BLOCK, "SIG_BLOCK" },
257 { SIG_UNBLOCK, "SIG_UNBLOCK" },
258 { SIG_SETMASK, "SIG_SETMASK" },
259#ifdef SIG_SETMASK32
260 { SIG_SETMASK32,"SIG_SETMASK32" },
261#endif
262 { 0, NULL },
263};
264
265#endif /* HAVE_SIGACTION */
266
Nate Sammonsce780fc1999-03-29 23:23:13 +0000267/* Anonymous realtime signals. */
268/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
269 constant. This is what we want. Otherwise, just use SIGRTMIN. */
270#ifdef SIGRTMIN
271#ifndef __SIGRTMIN
272#define __SIGRTMIN SIGRTMIN
273#define __SIGRTMAX SIGRTMAX /* likewise */
274#endif
275#endif
276
Roland McGrathee36ce12004-09-04 03:53:10 +0000277const char *
Nate Sammonsce780fc1999-03-29 23:23:13 +0000278signame(sig)
279int sig;
280{
281 static char buf[30];
Roland McGrathad81dce2005-05-09 07:40:30 +0000282 if (sig >= 0 && sig < nsignals) {
Nate Sammonsce780fc1999-03-29 23:23:13 +0000283 return signalent[sig];
284#ifdef SIGRTMIN
Nate Sammons3080aa41999-03-30 00:16:41 +0000285 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000286 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000287 return buf;
288#endif /* SIGRTMIN */
289 } else {
290 sprintf(buf, "%d", sig);
291 return buf;
292 }
293}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000295#ifndef UNIXWARE
Nate Sammons4a121431999-04-06 01:19:39 +0000296static void
297long_to_sigset(l, s)
298long l;
299sigset_t *s;
300{
301 sigemptyset(s);
302 *(long *)s = l;
303}
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000304#endif
Nate Sammons4a121431999-04-06 01:19:39 +0000305
306static int
307copy_sigset_len(tcp, addr, s, len)
308struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000309long addr;
Nate Sammons4a121431999-04-06 01:19:39 +0000310sigset_t *s;
311int len;
312{
313 if (len > sizeof(*s))
314 len = sizeof(*s);
315 sigemptyset(s);
316 if (umoven(tcp, addr, len, (char *)s) < 0)
317 return -1;
318 return 0;
319}
320
321#ifdef LINUX
322/* Original sigset is unsigned long */
323#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
324#else
325#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
326#endif
327
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000328static const char *
329sprintsigmask(const char *str, sigset_t *mask, int rt)
330/* set might include realtime sigs */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331{
332 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000333 int maxsigs;
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000334 char *format, *s;
Roland McGratha39c5a12002-12-17 05:10:37 +0000335 static char outstr[8 * sizeof(sigset_t) * 8];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000337 strcpy(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338 s = outstr + strlen(outstr);
339 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000340 maxsigs = nsignals;
341#ifdef __SIGRTMAX
342 if (rt)
343 maxsigs = __SIGRTMAX; /* instead */
344#endif
345 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000346 if (sigismember(mask, i) == 1)
347 nsigs++;
348 }
349 if (nsigs >= nsignals * 2 / 3) {
350 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000351 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000352 switch (sigismember(mask, i)) {
353 case 1:
354 sigdelset(mask, i);
355 break;
356 case 0:
357 sigaddset(mask, i);
358 break;
359 }
360 }
361 }
362 format = "%s";
363 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000364 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000365 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000366 /* real-time signals on solaris don't have
367 * signalent entries
368 */
369 if (i < nsignals) {
370 sprintf(s, format, signalent[i] + 3);
371 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000372#ifdef SIGRTMIN
373 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
374 char tsig[40];
375 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
376 sprintf(s, format, tsig);
377 }
378#endif /* SIGRTMIN */
John Hughesbdf48f52001-03-06 15:08:09 +0000379 else {
380 char tsig[32];
381 sprintf(tsig, "%u", i);
382 sprintf(s, format, tsig);
383 }
384 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000385 format = " %s";
386 }
387 }
388 *s++ = ']';
389 *s = '\0';
390 return outstr;
391}
392
393static void
Nate Sammons4a121431999-04-06 01:19:39 +0000394printsigmask(mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000395sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000396int rt;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397{
Nate Sammons4a121431999-04-06 01:19:39 +0000398 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399}
400
401void
402printsignal(nr)
403int nr;
404{
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +0000405 tprintf("%s", signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406}
407
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000408void
409print_sigset(struct tcb *tcp, long addr, int rt)
410{
411 sigset_t ss;
412
413 if (!addr)
414 tprintf("NULL");
415 else if (copy_sigset(tcp, addr, &ss) < 0)
416 tprintf("%#lx", addr);
417 else
418 printsigmask(&ss, rt);
419}
420
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000421#ifdef LINUX
422
John Hughes58265892001-10-18 15:13:53 +0000423#ifndef ILL_ILLOPC
424#define ILL_ILLOPC 1 /* illegal opcode */
425#define ILL_ILLOPN 2 /* illegal operand */
426#define ILL_ILLADR 3 /* illegal addressing mode */
427#define ILL_ILLTRP 4 /* illegal trap */
428#define ILL_PRVOPC 5 /* privileged opcode */
429#define ILL_PRVREG 6 /* privileged register */
430#define ILL_COPROC 7 /* coprocessor error */
431#define ILL_BADSTK 8 /* internal stack error */
432#define FPE_INTDIV 1 /* integer divide by zero */
433#define FPE_INTOVF 2 /* integer overflow */
434#define FPE_FLTDIV 3 /* floating point divide by zero */
435#define FPE_FLTOVF 4 /* floating point overflow */
436#define FPE_FLTUND 5 /* floating point underflow */
437#define FPE_FLTRES 6 /* floating point inexact result */
438#define FPE_FLTINV 7 /* floating point invalid operation */
439#define FPE_FLTSUB 8 /* subscript out of range */
440#define SEGV_MAPERR 1 /* address not mapped to object */
441#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
442#define BUS_ADRALN 1 /* invalid address alignment */
443#define BUS_ADRERR 2 /* non-existant physical address */
444#define BUS_OBJERR 3 /* object specific hardware error */
445#define TRAP_BRKPT 1 /* process breakpoint */
446#define TRAP_TRACE 2 /* process trace trap */
447#define CLD_EXITED 1 /* child has exited */
448#define CLD_KILLED 2 /* child was killed */
449#define CLD_DUMPED 3 /* child terminated abnormally */
450#define CLD_TRAPPED 4 /* traced child has trapped */
451#define CLD_STOPPED 5 /* child has stopped */
452#define CLD_CONTINUED 6 /* stopped child has continued */
453#define POLL_IN 1 /* data input available */
454#define POLL_OUT 2 /* output buffers available */
455#define POLL_MSG 3 /* input message available */
456#define POLL_ERR 4 /* i/o error */
457#define POLL_PRI 5 /* high priority input available */
458#define POLL_HUP 6 /* device disconnected */
459#define SI_USER 0 /* sent by kill, sigsend, raise */
460#define SI_QUEUE -1 /* sent by sigqueue */
461#define SI_TIMER -2 /* sent by timer expiration */
462#define SI_MESGQ -3 /* sent by real time mesq state change */
463#define SI_ASYNCIO -4 /* sent by AIO completion */
Roland McGrath941b7402003-05-23 00:29:02 +0000464#define SI_SIGIO -5 /* Sent by SIGIO */
465#define SI_TKILL -6 /* Sent by tkill */
John Hughes58265892001-10-18 15:13:53 +0000466#endif
467
468#if __GLIBC_MINOR__ < 1
469/* Type for data associated with a signal. */
470typedef union sigval
471{
472 int sival_int;
473 void *sival_ptr;
474} sigval_t;
475
476# define __SI_MAX_SIZE 128
477# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
478
479typedef struct siginfo
480{
481 int si_signo; /* Signal number. */
482 int si_errno; /* If non-zero, an errno value associated with
483 this signal, as defined in <errno.h>. */
484 int si_code; /* Signal code. */
485
486 union
487 {
488 int _pad[__SI_PAD_SIZE];
489
490 /* kill(). */
491 struct
492 {
493 __pid_t si_pid; /* Sending process ID. */
494 __uid_t si_uid; /* Real user ID of sending process. */
495 } _kill;
496
497 /* POSIX.1b timers. */
498 struct
499 {
500 unsigned int _timer1;
501 unsigned int _timer2;
502 } _timer;
503
504 /* POSIX.1b signals. */
505 struct
506 {
507 __pid_t si_pid; /* Sending process ID. */
508 __uid_t si_uid; /* Real user ID of sending process. */
509 sigval_t si_sigval; /* Signal value. */
510 } _rt;
511
512 /* SIGCHLD. */
513 struct
514 {
515 __pid_t si_pid; /* Which child. */
516 int si_status; /* Exit value or signal. */
517 __clock_t si_utime;
518 __clock_t si_stime;
519 } _sigchld;
520
521 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
522 struct
523 {
524 void *si_addr; /* Faulting insn/memory ref. */
525 } _sigfault;
526
527 /* SIGPOLL. */
528 struct
529 {
530 int si_band; /* Band event for SIGPOLL. */
531 int si_fd;
532 } _sigpoll;
533 } _sifields;
534} siginfo_t;
535
536#define si_pid _sifields._kill.si_pid
537#define si_uid _sifields._kill.si_uid
538#define si_status _sifields._sigchld.si_status
539#define si_utime _sifields._sigchld.si_utime
540#define si_stime _sifields._sigchld.si_stime
541#define si_value _sifields._rt.si_sigval
542#define si_int _sifields._rt.si_sigval.sival_int
543#define si_ptr _sifields._rt.si_sigval.sival_ptr
544#define si_addr _sifields._sigfault.si_addr
545#define si_band _sifields._sigpoll.si_band
546#define si_fd _sifields._sigpoll.si_fd
547
548#endif
549
550#endif
551
552#if defined (SVR4) || defined (LINUX)
553
Roland McGrathd9f816f2004-09-04 03:39:20 +0000554static const struct xlat siginfo_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000555#ifdef SI_NOINFO
556 { SI_NOINFO, "SI_NOINFO" },
557#endif
558#ifdef SI_USER
559 { SI_USER, "SI_USER" },
560#endif
561#ifdef SI_LWP
562 { SI_LWP, "SI_LWP" },
563#endif
564#ifdef SI_QUEUE
565 { SI_QUEUE, "SI_QUEUE" },
566#endif
567#ifdef SI_TIMER
568 { SI_TIMER, "SI_TIMER" },
569#endif
570#ifdef SI_ASYNCIO
571 { SI_ASYNCIO, "SI_ASYNCIO" },
572#endif
573#ifdef SI_MESGQ
574 { SI_MESGQ, "SI_MESGQ" },
575#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000576#ifdef SI_SIGIO
577 { SI_SIGIO, "SI_SIGIO" },
578#endif
579#ifdef SI_TKILL
580 { SI_TKILL, "SI_TKILL" },
581#endif
John Hughes58265892001-10-18 15:13:53 +0000582 { 0, NULL },
583};
584
Roland McGrathd9f816f2004-09-04 03:39:20 +0000585static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000586 { ILL_ILLOPC, "ILL_ILLOPC" },
587 { ILL_ILLOPN, "ILL_ILLOPN" },
588 { ILL_ILLADR, "ILL_ILLADR" },
589 { ILL_ILLTRP, "ILL_ILLTRP" },
590 { ILL_PRVOPC, "ILL_PRVOPC" },
591 { ILL_PRVREG, "ILL_PRVREG" },
592 { ILL_COPROC, "ILL_COPROC" },
593 { ILL_BADSTK, "ILL_BADSTK" },
594 { 0, NULL },
595};
596
Roland McGrathd9f816f2004-09-04 03:39:20 +0000597static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000598 { FPE_INTDIV, "FPE_INTDIV" },
599 { FPE_INTOVF, "FPE_INTOVF" },
600 { FPE_FLTDIV, "FPE_FLTDIV" },
601 { FPE_FLTOVF, "FPE_FLTOVF" },
602 { FPE_FLTUND, "FPE_FLTUND" },
603 { FPE_FLTRES, "FPE_FLTRES" },
604 { FPE_FLTINV, "FPE_FLTINV" },
605 { FPE_FLTSUB, "FPE_FLTSUB" },
606 { 0, NULL },
607};
608
Roland McGrathd9f816f2004-09-04 03:39:20 +0000609static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000610 { TRAP_BRKPT, "TRAP_BRKPT" },
611 { TRAP_TRACE, "TRAP_TRACE" },
612 { 0, NULL },
613};
614
Roland McGrathd9f816f2004-09-04 03:39:20 +0000615static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000616 { CLD_EXITED, "CLD_EXITED" },
617 { CLD_KILLED, "CLD_KILLED" },
618 { CLD_DUMPED, "CLD_DUMPED" },
619 { CLD_TRAPPED, "CLD_TRAPPED" },
620 { CLD_STOPPED, "CLD_STOPPED" },
621 { CLD_CONTINUED,"CLD_CONTINUED" },
622 { 0, NULL },
623};
624
Roland McGrathd9f816f2004-09-04 03:39:20 +0000625static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000626 { POLL_IN, "POLL_IN" },
627 { POLL_OUT, "POLL_OUT" },
628 { POLL_MSG, "POLL_MSG" },
629 { POLL_ERR, "POLL_ERR" },
630 { POLL_PRI, "POLL_PRI" },
631 { POLL_HUP, "POLL_HUP" },
632 { 0, NULL },
633};
634
Roland McGrathd9f816f2004-09-04 03:39:20 +0000635static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000636#ifdef PROF_SIG
637 { PROF_SIG, "PROF_SIG" },
638#endif
639 { 0, NULL },
640};
641
642#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000643static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000644#ifdef EMT_TAGOVF
645 { EMT_TAGOVF, "EMT_TAGOVF" },
646#endif
647 { 0, NULL },
648};
649#endif
650
Roland McGrathd9f816f2004-09-04 03:39:20 +0000651static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000652 { SEGV_MAPERR, "SEGV_MAPERR" },
653 { SEGV_ACCERR, "SEGV_ACCERR" },
654 { 0, NULL },
655};
656
Roland McGrathd9f816f2004-09-04 03:39:20 +0000657static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000658 { BUS_ADRALN, "BUS_ADRALN" },
659 { BUS_ADRERR, "BUS_ADRERR" },
660 { BUS_OBJERR, "BUS_OBJERR" },
661 { 0, NULL },
662};
663
664void
665printsiginfo(sip, verbose)
666siginfo_t *sip;
667int verbose;
668{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000669 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000670
671 if (sip->si_signo == 0) {
672 tprintf ("{}");
673 return;
674 }
675 tprintf("{si_signo=");
676 printsignal(sip->si_signo);
677 code = xlookup(siginfo_codes, sip->si_code);
678 if (!code) {
679 switch (sip->si_signo) {
680 case SIGTRAP:
681 code = xlookup(sigtrap_codes, sip->si_code);
682 break;
683 case SIGCHLD:
684 code = xlookup(sigchld_codes, sip->si_code);
685 break;
686 case SIGPOLL:
687 code = xlookup(sigpoll_codes, sip->si_code);
688 break;
689 case SIGPROF:
690 code = xlookup(sigprof_codes, sip->si_code);
691 break;
692 case SIGILL:
693 code = xlookup(sigill_codes, sip->si_code);
694 break;
695#ifdef SIGEMT
696 case SIGEMT:
697 code = xlookup(sigemt_codes, sip->si_code);
698 break;
699#endif
700 case SIGFPE:
701 code = xlookup(sigfpe_codes, sip->si_code);
702 break;
703 case SIGSEGV:
704 code = xlookup(sigsegv_codes, sip->si_code);
705 break;
706 case SIGBUS:
707 code = xlookup(sigbus_codes, sip->si_code);
708 break;
709 }
710 }
711 if (code)
712 tprintf(", si_code=%s", code);
713 else
714 tprintf(", si_code=%#x", sip->si_code);
715#ifdef SI_NOINFO
716 if (sip->si_code != SI_NOINFO)
717#endif
718 {
719 if (sip->si_errno) {
720 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
721 tprintf(", si_errno=%d", sip->si_errno);
722 else
723 tprintf(", si_errno=%s",
724 errnoent[sip->si_errno]);
725 }
726#ifdef SI_FROMUSER
727 if (SI_FROMUSER(sip)) {
728 tprintf(", si_pid=%ld, si_uid=%ld",
729 sip->si_pid, sip->si_uid);
730#ifdef SI_QUEUE
731 switch (sip->si_code) {
732 case SI_QUEUE:
733#ifdef SI_TIMER
734 case SI_TIMER:
735#endif /* SI_QUEUE */
736 case SI_ASYNCIO:
737#ifdef SI_MESGQ
738 case SI_MESGQ:
739#endif /* SI_MESGQ */
740 tprintf(", si_value=%d",
741 sip->si_value.sival_int);
742 break;
743 }
744#endif /* SI_QUEUE */
745 }
746 else
747#endif /* SI_FROMUSER */
748 {
749 switch (sip->si_signo) {
750 case SIGCHLD:
751 tprintf(", si_pid=%ld, si_status=",
752 (long) sip->si_pid);
753 if (sip->si_code == CLD_EXITED)
754 tprintf("%d", sip->si_status);
755 else
756 printsignal(sip->si_status);
757#if LINUX
758 if (!verbose)
759 tprintf(", ...");
760 else
761 tprintf(", si_utime=%lu, si_stime=%lu",
762 sip->si_utime,
763 sip->si_stime);
764#endif
765 break;
766 case SIGILL: case SIGFPE:
767 case SIGSEGV: case SIGBUS:
768 tprintf(", si_addr=%#lx",
769 (unsigned long) sip->si_addr);
770 break;
771 case SIGPOLL:
772 switch (sip->si_code) {
773 case POLL_IN: case POLL_OUT: case POLL_MSG:
774 tprintf(", si_band=%ld",
775 (long) sip->si_band);
776 break;
777 }
778 break;
779#ifdef LINUX
780 default:
781 tprintf(", si_pid=%lu, si_uid=%lu, ",
782 (unsigned long) sip->si_pid,
783 (unsigned long) sip->si_uid);
784 if (!verbose)
785 tprintf("...");
786 else {
787 tprintf("si_value={int=%u, ptr=%#lx}",
788 sip->si_int,
789 (unsigned long) sip->si_ptr);
790 }
791#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000792
John Hughes58265892001-10-18 15:13:53 +0000793 }
794 }
795 }
796 tprintf("}");
797}
798
799#endif /* SVR4 || LINUX */
800
801#ifdef LINUX
802
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000803static void
804parse_sigset_t (const char *str, sigset_t *set)
805{
Roland McGrathc38feca2003-10-01 07:50:28 +0000806 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000807 unsigned int digit;
808 int i;
809
810 sigemptyset(set);
811
Roland McGrathc38feca2003-10-01 07:50:28 +0000812 p = strchr(str, '\n');
813 if (p == NULL)
814 p = strchr(str, '\0');
815 for (i = 0; p-- > str; i += 4) {
816 if (*p >= '0' && *p <= '9')
817 digit = *p - '0';
818 else if (*p >= 'a' && *p <= 'f')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000819 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000820 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000821 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000822 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000823 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000824 if (digit & 1)
825 sigaddset(set, i + 1);
826 if (digit & 2)
827 sigaddset(set, i + 2);
828 if (digit & 4)
829 sigaddset(set, i + 3);
830 if (digit & 8)
831 sigaddset(set, i + 4);
832 }
833}
834
835#endif
836
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000837/*
838 * Check process TCP for the disposition of signal SIG.
839 * Return 1 if the process would somehow manage to survive signal SIG,
840 * else return 0. This routine will never be called with SIGKILL.
841 */
842int
843sigishandled(tcp, sig)
844struct tcb *tcp;
845int sig;
846{
847#ifdef LINUX
848 int sfd;
849 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000850 char buf[2048];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851 char *s;
852 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000853 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000854#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000855#ifdef SVR4
856 /*
857 * Since procfs doesn't interfere with wait I think it is safe
858 * to punt on this question. If not, the information is there.
859 */
860 return 1;
861#else /* !SVR4 */
862 switch (sig) {
863 case SIGCONT:
864 case SIGSTOP:
865 case SIGTSTP:
866 case SIGTTIN:
867 case SIGTTOU:
868 case SIGCHLD:
869 case SIGIO:
870#if defined(SIGURG) && SIGURG != SIGIO
871 case SIGURG:
872#endif
873 case SIGWINCH:
874 /* Gloria Gaynor says ... */
875 return 1;
876 default:
877 break;
878 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000879#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000880#ifdef LINUX
881
882 /* This is incredibly costly but it's worth it. */
883 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
884 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
885 doesn't handle real-time signals). */
886 sprintf(sname, "/proc/%d/status", tcp->pid);
887 if ((sfd = open(sname, O_RDONLY)) == -1) {
888 perror(sname);
889 return 1;
890 }
891 i = read(sfd, buf, sizeof(buf));
892 buf[i] = '\0';
893 close(sfd);
894 /*
895 * Skip the extraneous fields. We need to skip
896 * command name has any spaces in it. So be it.
897 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000898 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000899 if (!s)
900 {
901 fprintf(stderr, "/proc/pid/status format error\n");
902 return 1;
903 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000904 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000905
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000906 s = strstr(buf, "SigCgt:\t");
907 if (!s)
908 {
909 fprintf(stderr, "/proc/pid/status format error\n");
910 return 1;
911 }
912 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000913
914#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000915 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
916 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000917#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000918 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000919 return 1;
920#endif /* LINUX */
921
922#ifdef SUNOS4
923 void (*u_signal)();
924
Denys Vlasenko932fc7d2008-12-16 18:18:40 +0000925 if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal),
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000926 (long *) &u_signal) < 0) {
927 return 0;
928 }
929 if (u_signal != SIG_DFL)
930 return 1;
931#endif /* SUNOS4 */
932
933 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000934}
935
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000936#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000937
938int
939sys_sigvec(tcp)
940struct tcb *tcp;
941{
942 struct sigvec sv;
943 long addr;
944
945 if (entering(tcp)) {
946 printsignal(tcp->u_arg[0]);
947 tprintf(", ");
948 addr = tcp->u_arg[1];
949 } else {
950 addr = tcp->u_arg[2];
951 }
952 if (addr == 0)
953 tprintf("NULL");
954 else if (!verbose(tcp))
955 tprintf("%#lx", addr);
956 else if (umove(tcp, addr, &sv) < 0)
957 tprintf("{...}");
958 else {
959 switch ((int) sv.sv_handler) {
960 case (int) SIG_ERR:
961 tprintf("{SIG_ERR}");
962 break;
963 case (int) SIG_DFL:
964 tprintf("{SIG_DFL}");
965 break;
966 case (int) SIG_IGN:
967 if (tcp->u_arg[0] == SIGTRAP) {
968 tcp->flags |= TCB_SIGTRAPPED;
969 kill(tcp->pid, SIGSTOP);
970 }
971 tprintf("{SIG_IGN}");
972 break;
973 case (int) SIG_HOLD:
974 if (tcp->u_arg[0] == SIGTRAP) {
975 tcp->flags |= TCB_SIGTRAPPED;
976 kill(tcp->pid, SIGSTOP);
977 }
978 tprintf("SIG_HOLD");
979 break;
980 default:
981 if (tcp->u_arg[0] == SIGTRAP) {
982 tcp->flags |= TCB_SIGTRAPPED;
983 kill(tcp->pid, SIGSTOP);
984 }
985 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000986 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000987 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000988 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000989 tprintf("}");
990 }
991 }
992 if (entering(tcp))
993 tprintf(", ");
994 return 0;
995}
996
997int
998sys_sigpause(tcp)
999struct tcb *tcp;
1000{
1001 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +00001002 sigset_t sigm;
1003 long_to_sigset(tcp->u_arg[0], &sigm);
1004 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005 }
1006 return 0;
1007}
1008
1009int
1010sys_sigstack(tcp)
1011struct tcb *tcp;
1012{
1013 struct sigstack ss;
1014 long addr;
1015
1016 if (entering(tcp))
1017 addr = tcp->u_arg[0];
1018 else
1019 addr = tcp->u_arg[1];
1020 if (addr == 0)
1021 tprintf("NULL");
1022 else if (umove(tcp, addr, &ss) < 0)
1023 tprintf("%#lx", addr);
1024 else {
1025 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1026 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1027 }
1028 if (entering(tcp))
1029 tprintf(", ");
1030 return 0;
1031}
1032
1033int
1034sys_sigcleanup(tcp)
1035struct tcb *tcp;
1036{
1037 return 0;
1038}
1039
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001040#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041
1042#ifndef SVR4
1043
1044int
1045sys_sigsetmask(tcp)
1046struct tcb *tcp;
1047{
1048 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001049 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001050 long_to_sigset(tcp->u_arg[0], &sigm);
1051 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001052#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001053 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1054 /* Mark attempt to block SIGTRAP */
1055 tcp->flags |= TCB_SIGTRAPPED;
1056 /* Send unblockable signal */
1057 kill(tcp->pid, SIGSTOP);
1058 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001059#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001060 }
1061 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001062 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001063 long_to_sigset(tcp->u_rval, &sigm);
1064 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001065
1066 return RVAL_HEX | RVAL_STR;
1067 }
1068 return 0;
1069}
1070
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001071#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072int
1073sys_sigblock(tcp)
1074struct tcb *tcp;
1075{
1076 return sys_sigsetmask(tcp);
1077}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001078#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001079
1080#endif /* !SVR4 */
1081
1082#ifdef HAVE_SIGACTION
1083
1084#ifdef LINUX
1085struct old_sigaction {
1086 __sighandler_t __sa_handler;
1087 unsigned long sa_mask;
1088 unsigned long sa_flags;
1089 void (*sa_restorer)(void);
1090};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001091#define SA_HANDLER __sa_handler
1092#endif /* LINUX */
1093
Roland McGratha39c5a12002-12-17 05:10:37 +00001094#ifndef SA_HANDLER
1095#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096#endif
1097
1098int
1099sys_sigaction(tcp)
1100struct tcb *tcp;
1101{
1102 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001103#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001104 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001105 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001106#else
1107 struct sigaction sa;
1108#endif
1109
1110
1111 if (entering(tcp)) {
1112 printsignal(tcp->u_arg[0]);
1113 tprintf(", ");
1114 addr = tcp->u_arg[1];
1115 } else
1116 addr = tcp->u_arg[2];
1117 if (addr == 0)
1118 tprintf("NULL");
1119 else if (!verbose(tcp))
1120 tprintf("%#lx", addr);
1121 else if (umove(tcp, addr, &sa) < 0)
1122 tprintf("{...}");
1123 else {
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001124 /* Architectures using function pointers, like
1125 * hppa, may need to manipulate the function pointer
1126 * to compute the result of a comparison. However,
1127 * the SA_HANDLER function pointer exists only in
1128 * the address space of the traced process, and can't
1129 * be manipulated by strace. In order to prevent the
1130 * compiler from generating code to manipulate
1131 * SA_HANDLER we cast the function pointers to long. */
1132 if ((long)sa.SA_HANDLER == (long)SIG_ERR)
Roland McGrath5f206812008-08-20 01:59:40 +00001133 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001134 else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
Roland McGrath5f206812008-08-20 01:59:40 +00001135 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001136 else if ((long)sa.SA_HANDLER == (long)SIG_IGN) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001137#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001138 if (tcp->u_arg[0] == SIGTRAP) {
1139 tcp->flags |= TCB_SIGTRAPPED;
1140 kill(tcp->pid, SIGSTOP);
1141 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001142#endif /* !USE_PROCFS */
Roland McGrath5f206812008-08-20 01:59:40 +00001143 tprintf("{SIG_IGN, ");
1144 }
1145 else {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001146#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001147 if (tcp->u_arg[0] == SIGTRAP) {
1148 tcp->flags |= TCB_SIGTRAPPED;
1149 kill(tcp->pid, SIGSTOP);
1150 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001151#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001152 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001153#ifndef LINUX
1154 printsigmask (&sa.sa_mask, 0);
1155#else
Nate Sammons4a121431999-04-06 01:19:39 +00001156 long_to_sigset(sa.sa_mask, &sigset);
1157 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001158#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001159 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001160 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001161#ifdef SA_RESTORER
1162 if (sa.sa_flags & SA_RESTORER)
1163 tprintf(", %p", sa.sa_restorer);
1164#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001165 tprintf("}");
1166 }
1167 }
1168 if (entering(tcp))
1169 tprintf(", ");
1170#ifdef LINUX
1171 else
1172 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1173#endif
1174 return 0;
1175}
1176
1177int
1178sys_signal(tcp)
1179struct tcb *tcp;
1180{
1181 if (entering(tcp)) {
1182 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001183 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001184 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001185 case (long) SIG_ERR:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001186 tprintf("SIG_ERR");
1187 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001188 case (long) SIG_DFL:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001189 tprintf("SIG_DFL");
1190 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001191 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001192#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001193 if (tcp->u_arg[0] == SIGTRAP) {
1194 tcp->flags |= TCB_SIGTRAPPED;
1195 kill(tcp->pid, SIGSTOP);
1196 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001197#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001198 tprintf("SIG_IGN");
1199 break;
1200 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001201#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001202 if (tcp->u_arg[0] == SIGTRAP) {
1203 tcp->flags |= TCB_SIGTRAPPED;
1204 kill(tcp->pid, SIGSTOP);
1205 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001206#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001207 tprintf("%#lx", tcp->u_arg[1]);
1208 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001209 return 0;
1210 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001211 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001212 switch (tcp->u_rval) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001213 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001214 tcp->auxstr = "SIG_ERR"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001215 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001216 tcp->auxstr = "SIG_DFL"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001217 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001218 tcp->auxstr = "SIG_IGN"; break;
1219 default:
1220 tcp->auxstr = NULL;
1221 }
1222 return RVAL_HEX | RVAL_STR;
1223 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001224 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001225}
1226
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001227#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001228int
1229sys_sighold(tcp)
1230struct tcb *tcp;
1231{
1232 if (entering(tcp)) {
1233 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001234 }
1235 return 0;
1236}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001237#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001238
1239#endif /* HAVE_SIGACTION */
1240
1241#ifdef LINUX
1242
1243int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001244sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001245{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001246#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001247 struct pt_regs regs;
1248 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001249
Roland McGrath0f87c492003-06-03 23:29:04 +00001250 if (entering(tcp)) {
1251 tcp->u_arg[0] = 0;
1252
1253 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1254 return 0;
1255
1256 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1257 return 0;
1258
1259 tcp->u_arg[0] = 1;
1260 tcp->u_arg[1] = sc.oldmask;
1261 } else {
1262 sigset_t sigm;
1263 long_to_sigset(tcp->u_arg[1], &sigm);
1264 tcp->u_rval = tcp->u_error = 0;
1265 if (tcp->u_arg[0] == 0)
1266 return 0;
1267 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1268 return RVAL_NONE | RVAL_STR;
1269 }
1270 return 0;
1271#elif defined(S390) || defined(S390X)
1272 long usp;
1273 struct sigcontext_struct sc;
1274
1275 if (entering(tcp)) {
1276 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001277 if (upeek(tcp,PT_GPR15,&usp)<0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001278 return 0;
1279 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1280 return 0;
1281 tcp->u_arg[0] = 1;
1282 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1283 } else {
1284 tcp->u_rval = tcp->u_error = 0;
1285 if (tcp->u_arg[0] == 0)
1286 return 0;
1287 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1288 return RVAL_NONE | RVAL_STR;
1289 }
1290 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001291#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 long esp;
1293 struct sigcontext_struct sc;
1294
1295 if (entering(tcp)) {
1296 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001297 if (upeek(tcp, 4*UESP, &esp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298 return 0;
1299 if (umove(tcp, esp, &sc) < 0)
1300 return 0;
1301 tcp->u_arg[0] = 1;
1302 tcp->u_arg[1] = sc.oldmask;
1303 }
1304 else {
1305 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001306 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001307 tcp->u_rval = tcp->u_error = 0;
1308 if (tcp->u_arg[0] == 0)
1309 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001310 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001311 return RVAL_NONE | RVAL_STR;
1312 }
1313 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001314#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001315 struct sigcontext sc;
1316 long sp;
1317
1318 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001319 /* offset of sigcontext in the kernel's sigframe structure: */
1320# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001321 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001322 if (upeek(tcp, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001323 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001324 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001325 return 0;
1326 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001327 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001328 }
1329 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001330 sigset_t sigm;
1331
1332 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001333 tcp->u_rval = tcp->u_error = 0;
1334 if (tcp->u_arg[0] == 0)
1335 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001336 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001337 return RVAL_NONE | RVAL_STR;
1338 }
1339 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001340#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +00001341 long esp;
1342 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001343
Roland McGrath0f87c492003-06-03 23:29:04 +00001344 if (entering(tcp)) {
1345 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001346 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001347 return 0;
1348 if (umove(tcp, esp, &sc) < 0)
1349 return 0;
1350 tcp->u_arg[0] = 1;
1351 tcp->u_arg[1] = sc.oldmask;
1352 }
1353 else {
1354 sigset_t sigm;
1355 long_to_sigset(tcp->u_arg[1], &sigm);
1356 tcp->u_rval = tcp->u_error = 0;
1357 if (tcp->u_arg[0] == 0)
1358 return 0;
1359 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1360 return RVAL_NONE | RVAL_STR;
1361 }
1362 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001363#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001364 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001365 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001366
1367 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001368 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001369 if (upeek(tcp, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001370 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001371 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001372 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001373 tcp->u_arg[0] = 1;
1374 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001375 }
1376 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001377 sigset_t sigm;
1378 long_to_sigset(tcp->u_arg[1], &sigm);
1379 tcp->u_rval = tcp->u_error = 0;
1380 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001381 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001382 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1383 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001384 }
1385 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001386#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001387 long fp;
1388 struct sigcontext_struct sc;
1389
1390 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001391 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001392 if (upeek(tcp, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001394 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001395 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001396 tcp->u_arg[0] = 1;
1397 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001398 }
1399 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001400 sigset_t sigm;
1401 long_to_sigset(tcp->u_arg[1], &sigm);
1402 tcp->u_rval = tcp->u_error = 0;
1403 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001404 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001405 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1406 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001407 }
1408 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001409#elif defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001410 long i1;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001411 struct regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001412 m_siginfo_t si;
1413
Roland McGratheb9e2e82009-06-02 16:49:22 -07001414 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1415 perror("sigreturn: PTRACE_GETREGS ");
Roland McGrath0f87c492003-06-03 23:29:04 +00001416 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001417 }
Roland McGratheb9e2e82009-06-02 16:49:22 -07001418 if(entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001419 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001420 i1 = regs.r_o1;
Roland McGratheb9e2e82009-06-02 16:49:22 -07001421 if(umove(tcp, i1, &si) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001422 perror("sigreturn: umove ");
1423 return 0;
1424 }
1425 tcp->u_arg[0] = 1;
1426 tcp->u_arg[1] = si.si_mask;
1427 } else {
1428 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001429 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001430 tcp->u_rval = tcp->u_error = 0;
1431 if(tcp->u_arg[0] == 0)
1432 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001433 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001434 return RVAL_NONE | RVAL_STR;
1435 }
1436 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001437#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001438 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1439 sigreturn. */
1440 long sp;
1441 struct ucontext uc;
1442
1443 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001444 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001445 if (upeek(tcp, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001446 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001447 /* There are six words followed by a 128-byte siginfo. */
1448 sp = sp + 6 * 4 + 128;
1449 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001450 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001451 tcp->u_arg[0] = 1;
1452 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1453 } else {
1454 sigset_t sigm;
1455 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001456 tcp->u_rval = tcp->u_error = 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001457 if(tcp->u_arg[0] == 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001458 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001459 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1460 return RVAL_NONE | RVAL_STR;
1461 }
1462 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001463#elif defined(MIPS)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001464 long sp;
Roland McGrath576b7842007-11-04 00:00:00 +00001465 struct pt_regs regs;
1466 m_siginfo_t si;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001467
Roland McGrath576b7842007-11-04 00:00:00 +00001468 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1469 perror("sigreturn: PTRACE_GETREGS ");
1470 return 0;
1471 }
Wichert Akkermanf90da011999-10-31 21:15:38 +00001472 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001473 tcp->u_arg[0] = 0;
Roland McGrath576b7842007-11-04 00:00:00 +00001474 sp = regs.regs[29];
1475 if (umove(tcp, sp, &si) < 0)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001476 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001477 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001478 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001479 sigset_t sigm;
1480 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001481 tcp->u_rval = tcp->u_error = 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001482 if(tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001483 return 0;
1484 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001485 return RVAL_NONE | RVAL_STR;
1486 }
1487 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001488#elif defined(CRISV10) || defined(CRISV32)
1489 struct sigcontext sc;
1490
1491 if (entering(tcp)) {
1492 long regs[PT_MAX+1];
1493
1494 tcp->u_arg[0] = 0;
1495
1496 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1497 perror("sigreturn: PTRACE_GETREGS");
1498 return 0;
1499 }
1500 if (umove(tcp, regs[PT_USP], &sc) < 0)
1501 return 0;
1502 tcp->u_arg[0] = 1;
1503 tcp->u_arg[1] = sc.oldmask;
1504 } else {
1505 sigset_t sigm;
1506 long_to_sigset(tcp->u_arg[1], &sigm);
1507 tcp->u_rval = tcp->u_error = 0;
1508
1509 if (tcp->u_arg[0] == 0)
1510 return 0;
1511 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1512 return RVAL_NONE | RVAL_STR;
1513 }
1514 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001515#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001516#warning No sys_sigreturn() for this architecture
1517#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001518 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001519#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001520}
1521
1522int
1523sys_siggetmask(tcp)
1524struct tcb *tcp;
1525{
1526 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001527 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001528 long_to_sigset(tcp->u_rval, &sigm);
1529 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001530 }
1531 return RVAL_HEX | RVAL_STR;
1532}
1533
1534int
1535sys_sigsuspend(tcp)
1536struct tcb *tcp;
1537{
1538 if (entering(tcp)) {
1539 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001540 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001541#if 0
1542 /* first two are not really arguments, but print them anyway */
1543 /* nevermind, they are an anachronism now, too bad... */
1544 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1545#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001546 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001547 }
1548 return 0;
1549}
1550
1551#endif /* LINUX */
1552
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001553#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001554
1555int
1556sys_sigsuspend(tcp)
1557struct tcb *tcp;
1558{
1559 sigset_t sigset;
1560
1561 if (entering(tcp)) {
1562 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1563 tprintf("[?]");
1564 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001565 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001566 }
1567 return 0;
1568}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001569#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001570static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001571 { UC_SIGMASK, "UC_SIGMASK" },
1572 { UC_STACK, "UC_STACK" },
1573 { UC_CPU, "UC_CPU" },
1574#ifdef UC_FPU
1575 { UC_FPU, "UC_FPU" },
1576#endif
1577#ifdef UC_INTR
1578 { UC_INTR, "UC_INTR" },
1579#endif
1580 { 0, NULL },
1581};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001582#endif /* !FREEBSD */
1583#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001584
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001585#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001586#if defined LINUX && !defined SS_ONSTACK
1587#define SS_ONSTACK 1
1588#define SS_DISABLE 2
1589#if __GLIBC_MINOR__ == 0
1590typedef struct
1591{
1592 __ptr_t ss_sp;
1593 int ss_flags;
1594 size_t ss_size;
1595} stack_t;
1596#endif
1597#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001598#ifdef FREEBSD
1599#define stack_t struct sigaltstack
1600#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001601
Roland McGrathd9f816f2004-09-04 03:39:20 +00001602static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603 { SS_ONSTACK, "SS_ONSTACK" },
1604 { SS_DISABLE, "SS_DISABLE" },
1605 { 0, NULL },
1606};
1607#endif
1608
1609#ifdef SVR4
1610static void
1611printcontext(tcp, ucp)
1612struct tcb *tcp;
1613ucontext_t *ucp;
1614{
1615 tprintf("{");
1616 if (!abbrev(tcp)) {
1617 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001618 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001619 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1620 }
1621 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001622 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001623 if (!abbrev(tcp)) {
1624 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1625 (unsigned long) ucp->uc_stack.ss_sp,
1626 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001627 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001628 tprintf("}");
1629 }
1630 tprintf(", ...}");
1631}
1632
1633int
1634sys_getcontext(tcp)
1635struct tcb *tcp;
1636{
1637 ucontext_t uc;
1638
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001639 if (exiting(tcp)) {
1640 if (tcp->u_error)
1641 tprintf("%#lx", tcp->u_arg[0]);
1642 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001643 tprintf("NULL");
1644 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1645 tprintf("{...}");
1646 else
1647 printcontext(tcp, &uc);
1648 }
1649 return 0;
1650}
1651
1652int
1653sys_setcontext(tcp)
1654struct tcb *tcp;
1655{
1656 ucontext_t uc;
1657
1658 if (entering(tcp)) {
1659 if (!tcp->u_arg[0])
1660 tprintf("NULL");
1661 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1662 tprintf("{...}");
1663 else
1664 printcontext(tcp, &uc);
1665 }
1666 else {
1667 tcp->u_rval = tcp->u_error = 0;
1668 if (tcp->u_arg[0] == 0)
1669 return 0;
1670 return RVAL_NONE;
1671 }
1672 return 0;
1673}
1674
1675#endif /* SVR4 */
1676
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001677#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001678
1679static int
1680print_stack_t(tcp, addr)
1681struct tcb *tcp;
1682unsigned long addr;
1683{
1684 stack_t ss;
1685 if (umove(tcp, addr, &ss) < 0)
1686 return -1;
1687 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001688 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001689 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1690 return 0;
1691}
1692
1693int
1694sys_sigaltstack(tcp)
1695 struct tcb *tcp;
1696{
1697 if (entering(tcp)) {
1698 if (tcp->u_arg[0] == 0)
1699 tprintf("NULL");
1700 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1701 return -1;
1702 }
1703 else {
1704 tprintf(", ");
1705 if (tcp->u_arg[1] == 0)
1706 tprintf("NULL");
1707 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1708 return -1;
1709 }
1710 return 0;
1711}
1712#endif
1713
1714#ifdef HAVE_SIGACTION
1715
1716int
1717sys_sigprocmask(tcp)
1718struct tcb *tcp;
1719{
1720#ifdef ALPHA
1721 if (entering(tcp)) {
1722 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1723 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001724 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001725 }
1726 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001727 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001728 return RVAL_HEX | RVAL_STR;
1729 }
1730#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001731 if (entering(tcp)) {
1732#ifdef SVR4
1733 if (tcp->u_arg[0] == 0)
1734 tprintf("0");
1735 else
1736#endif /* SVR4 */
1737 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1738 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001739 print_sigset(tcp, tcp->u_arg[1], 0);
1740 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001741 }
1742 else {
1743 if (!tcp->u_arg[2])
1744 tprintf("NULL");
1745 else if (syserror(tcp))
1746 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001747 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001748 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001749 }
1750#endif /* !ALPHA */
1751 return 0;
1752}
1753
1754#endif /* HAVE_SIGACTION */
1755
1756int
1757sys_kill(tcp)
1758struct tcb *tcp;
1759{
1760 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001761 /*
1762 * Sign-extend a 32-bit value when that's what it is.
1763 */
1764 long pid = tcp->u_arg[0];
1765 if (personality_wordsize[current_personality] < sizeof pid)
1766 pid = (long) (int) pid;
1767 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001768 }
1769 return 0;
1770}
1771
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001772#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001773int
1774sys_killpg(tcp)
1775struct tcb *tcp;
1776{
1777 return sys_kill(tcp);
1778}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001779#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001780
Roland McGrath8ffc3522003-07-09 09:47:49 +00001781#ifdef LINUX
1782int
1783sys_tgkill(tcp)
1784 struct tcb *tcp;
1785{
1786 if (entering(tcp)) {
1787 tprintf("%ld, %ld, %s",
1788 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1789 }
1790 return 0;
1791}
1792#endif
1793
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001794int
1795sys_sigpending(tcp)
1796struct tcb *tcp;
1797{
1798 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001799
1800 if (exiting(tcp)) {
1801 if (syserror(tcp))
1802 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001803 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001804 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001805 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001806 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001807 }
1808 return 0;
1809}
1810
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001811#ifdef SVR4
John Hughes42162082001-10-18 14:48:26 +00001812int sys_sigwait(tcp)
1813struct tcb *tcp;
1814{
1815 sigset_t sigset;
1816
1817 if (entering(tcp)) {
1818 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1819 tprintf("[?]");
1820 else
1821 printsigmask(&sigset, 0);
1822 }
1823 else {
1824 if (!syserror(tcp)) {
1825 tcp->auxstr = signalent[tcp->u_rval];
1826 return RVAL_DECIMAL | RVAL_STR;
1827 }
1828 }
1829 return 0;
1830}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001831#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001832
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001833#ifdef LINUX
1834
1835 int
1836sys_rt_sigprocmask(tcp)
1837 struct tcb *tcp;
1838{
1839 sigset_t sigset;
1840
Nate Sammons4a121431999-04-06 01:19:39 +00001841 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001842 if (entering(tcp)) {
1843 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1844 tprintf(", ");
1845 if (!tcp->u_arg[1])
1846 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001847 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001848 tprintf("%#lx, ", tcp->u_arg[1]);
1849 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001850 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851 tprintf(", ");
1852 }
1853 }
1854 else {
1855 if (!tcp->u_arg[2])
1856
1857 tprintf("NULL");
1858 else if (syserror(tcp))
1859 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001860 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001861 tprintf("[?]");
1862 else
Nate Sammons4a121431999-04-06 01:19:39 +00001863 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001864 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001865 }
1866 return 0;
1867}
1868
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001869
1870/* Structure describing the action to be taken when a signal arrives. */
1871struct new_sigaction
1872{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001873 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874 unsigned long sa_flags;
1875 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001876 /* Kernel treats sa_mask as an array of longs. */
1877 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1878};
1879/* Same for i386-on-x86_64 and similar cases */
1880struct new_sigaction32
1881{
1882 uint32_t __sa_handler;
1883 uint32_t sa_flags;
1884 uint32_t sa_restorer;
1885 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001886};
1887
1888
Roland McGrath5f206812008-08-20 01:59:40 +00001889int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001890sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001891{
1892 struct new_sigaction sa;
1893 sigset_t sigset;
1894 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001895 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001896
1897 if (entering(tcp)) {
1898 printsignal(tcp->u_arg[0]);
1899 tprintf(", ");
1900 addr = tcp->u_arg[1];
1901 } else
1902 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001903
1904 if (addr == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001905 tprintf("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001906 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001907 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001908 if (!verbose(tcp)) {
1909 tprintf("%#lx", addr);
1910 goto after_sa;
1911 }
1912#if SUPPORTED_PERSONALITIES > 1
1913 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1914 && personality_wordsize[current_personality] == 4
1915 ) {
1916 struct new_sigaction32 sa32;
1917 r = umove(tcp, addr, &sa32);
1918 if (r >= 0) {
1919 memset(&sa, 0, sizeof(sa));
1920 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1921 sa.sa_flags = sa32.sa_flags;
1922 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1923 /* Kernel treats sa_mask as an array of longs.
1924 * For 32-bit process, "long" is uint32_t, thus, for example,
1925 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1926 * But for (64-bit) kernel, 32th bit in sa_mask is
1927 * 32th bit in 0th (64-bit) long!
1928 * For little-endian, it's the same.
1929 * For big-endian, we swap 32-bit words.
1930 */
1931 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1932 }
1933 } else
1934#endif
1935 {
1936 r = umove(tcp, addr, &sa);
1937 }
1938 if (r < 0) {
1939 tprintf("{...}");
1940 goto after_sa;
1941 }
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001942 /* Architectures using function pointers, like
1943 * hppa, may need to manipulate the function pointer
1944 * to compute the result of a comparison. However,
1945 * the SA_HANDLER function pointer exists only in
1946 * the address space of the traced process, and can't
1947 * be manipulated by strace. In order to prevent the
1948 * compiler from generating code to manipulate
1949 * SA_HANDLER we cast the function pointers to long. */
1950 if ((long)sa.__sa_handler == (long)SIG_ERR)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001951 tprintf("{SIG_ERR, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001952 else if ((long)sa.__sa_handler == (long)SIG_DFL)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001953 tprintf("{SIG_DFL, ");
Carlos O'Donell4677c8a2009-09-09 18:13:19 +00001954 else if ((long)sa.__sa_handler == (long)SIG_IGN)
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001955 tprintf("{SIG_IGN, ");
1956 else
1957 tprintf("{%#lx, ", (long) sa.__sa_handler);
1958 /* Questionable code below.
1959 * Kernel won't handle sys_rt_sigaction
1960 * with wrong sigset size (just returns EINVAL)
1961 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
1962 * and we always use smaller memcpy. */
1963 sigemptyset(&sigset);
1964#ifdef LINUXSPARC
1965 if (tcp->u_arg[4] <= sizeof(sigset))
1966 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1967#else
1968 if (tcp->u_arg[3] <= sizeof(sigset))
1969 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1970#endif
1971 else
1972 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1973 printsigmask(&sigset, 1);
1974 tprintf(", ");
1975 printflags(sigact_flags, sa.sa_flags, "SA_???");
1976#ifdef SA_RESTORER
1977 if (sa.sa_flags & SA_RESTORER)
1978 tprintf(", %p", sa.sa_restorer);
1979#endif
1980 tprintf("}");
1981
1982 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001983 if (entering(tcp))
1984 tprintf(", ");
1985 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001986#ifdef LINUXSPARC
1987 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1988#elif defined(ALPHA)
1989 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1990#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001991 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001992#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001993 return 0;
1994}
1995
Denys Vlasenko1d632462009-04-14 12:51:00 +00001996int
1997sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001998{
1999 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002000
2001 if (exiting(tcp)) {
2002 if (syserror(tcp))
2003 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00002004 else if (copy_sigset_len(tcp, tcp->u_arg[0],
2005 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002006 tprintf("[?]");
2007 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002008 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002009 }
2010 return 0;
2011}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002012
2013int
2014sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002015{
2016 if (entering(tcp)) {
2017 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00002018 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
2019 tprintf("[?]");
2020 else
2021 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002022 }
2023 return 0;
2024}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002025
2026int
2027sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002028{
2029 if (entering(tcp)) {
2030 siginfo_t si;
2031 tprintf("%lu, ", tcp->u_arg[0]);
2032 printsignal(tcp->u_arg[1]);
2033 tprintf(", ");
2034 if (umove(tcp, tcp->u_arg[2], &si) < 0)
2035 tprintf("%#lx", tcp->u_arg[2]);
2036 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002037 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002038 }
2039 return 0;
2040}
2041
Denys Vlasenko1d632462009-04-14 12:51:00 +00002042int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002043{
2044 if (entering(tcp)) {
2045 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046
Roland McGratha39c5a12002-12-17 05:10:37 +00002047 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00002048 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002049 tprintf("[?]");
2050 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002051 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002052 tprintf(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002053 /* This is the only "return" parameter, */
2054 if (tcp->u_arg[1] != 0)
2055 return 0;
2056 /* ... if it's NULL, can decode all on entry */
2057 tprintf("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002058 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002059 else if (tcp->u_arg[1] != 0) {
2060 /* syscall exit, and u_arg[1] wasn't NULL */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002061 if (syserror(tcp))
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002062 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002063 else {
2064 siginfo_t si;
2065 if (umove(tcp, tcp->u_arg[1], &si) < 0)
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002066 tprintf("%#lx, ", tcp->u_arg[1]);
2067 else {
Denys Vlasenkof535b542009-01-13 18:30:55 +00002068 printsiginfo(&si, verbose(tcp));
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002069 tprintf(", ");
2070 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002071 }
2072 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002073 else {
2074 /* syscall exit, and u_arg[1] was NULL */
2075 return 0;
2076 }
2077 print_timespec(tcp, tcp->u_arg[2]);
2078 tprintf(", %d", (int) tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002079 return 0;
2080};
2081
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002082int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002083sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002084{
2085 if (entering(tcp))
2086 tprintf("<... resuming interrupted call ...>");
2087 return 0;
2088}
2089
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002090static int
2091do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00002092{
2093 if (entering(tcp)) {
2094 tprintf("%ld, ", tcp->u_arg[0]);
2095 print_sigset(tcp, tcp->u_arg[1], 1);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00002096 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002097 if (flags_arg >= 0) {
2098 tprintf(", ");
2099 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2100 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00002101 }
2102 return 0;
2103}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002104
2105int
2106sys_signalfd(struct tcb *tcp)
2107{
2108 return do_signalfd(tcp, -1);
2109}
2110
2111int
2112sys_signalfd4(struct tcb *tcp)
2113{
2114 return do_signalfd(tcp, 3);
2115}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002116#endif /* LINUX */