blob: b7db9463e37eab8ce6184903e9845d7b7062d2b3 [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 {
Roland McGrath5f206812008-08-20 01:59:40 +00001124 if (sa.SA_HANDLER == SIG_ERR)
1125 tprintf("{SIG_ERR, ");
1126 else if (sa.SA_HANDLER == SIG_DFL)
1127 tprintf("{SIG_DFL, ");
Denys Vlasenko73ce40e2008-12-17 17:22:03 +00001128 else if (sa.SA_HANDLER == SIG_IGN) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001129#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001130 if (tcp->u_arg[0] == SIGTRAP) {
1131 tcp->flags |= TCB_SIGTRAPPED;
1132 kill(tcp->pid, SIGSTOP);
1133 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001134#endif /* !USE_PROCFS */
Roland McGrath5f206812008-08-20 01:59:40 +00001135 tprintf("{SIG_IGN, ");
1136 }
1137 else {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001138#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001139 if (tcp->u_arg[0] == SIGTRAP) {
1140 tcp->flags |= TCB_SIGTRAPPED;
1141 kill(tcp->pid, SIGSTOP);
1142 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001143#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001144 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001145#ifndef LINUX
1146 printsigmask (&sa.sa_mask, 0);
1147#else
Nate Sammons4a121431999-04-06 01:19:39 +00001148 long_to_sigset(sa.sa_mask, &sigset);
1149 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001150#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001151 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001152 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001153#ifdef SA_RESTORER
1154 if (sa.sa_flags & SA_RESTORER)
1155 tprintf(", %p", sa.sa_restorer);
1156#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001157 tprintf("}");
1158 }
1159 }
1160 if (entering(tcp))
1161 tprintf(", ");
1162#ifdef LINUX
1163 else
1164 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1165#endif
1166 return 0;
1167}
1168
1169int
1170sys_signal(tcp)
1171struct tcb *tcp;
1172{
1173 if (entering(tcp)) {
1174 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001175 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001176 switch (tcp->u_arg[1]) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001177 case (long) SIG_ERR:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001178 tprintf("SIG_ERR");
1179 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001180 case (long) SIG_DFL:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001181 tprintf("SIG_DFL");
1182 break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001183 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001184#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001185 if (tcp->u_arg[0] == SIGTRAP) {
1186 tcp->flags |= TCB_SIGTRAPPED;
1187 kill(tcp->pid, SIGSTOP);
1188 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001189#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001190 tprintf("SIG_IGN");
1191 break;
1192 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001193#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001194 if (tcp->u_arg[0] == SIGTRAP) {
1195 tcp->flags |= TCB_SIGTRAPPED;
1196 kill(tcp->pid, SIGSTOP);
1197 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001198#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001199 tprintf("%#lx", tcp->u_arg[1]);
1200 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001201 return 0;
1202 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001203 else if (!syserror(tcp)) {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001204 switch (tcp->u_rval) {
Jan Kratochvil1f942712008-08-06 21:38:52 +00001205 case (long) SIG_ERR:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001206 tcp->auxstr = "SIG_ERR"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001207 case (long) SIG_DFL:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001208 tcp->auxstr = "SIG_DFL"; break;
Jan Kratochvil1f942712008-08-06 21:38:52 +00001209 case (long) SIG_IGN:
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001210 tcp->auxstr = "SIG_IGN"; break;
1211 default:
1212 tcp->auxstr = NULL;
1213 }
1214 return RVAL_HEX | RVAL_STR;
1215 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001216 return 0;
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001217}
1218
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001219#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001220int
1221sys_sighold(tcp)
1222struct tcb *tcp;
1223{
1224 if (entering(tcp)) {
1225 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001226 }
1227 return 0;
1228}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001229#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001230
1231#endif /* HAVE_SIGACTION */
1232
1233#ifdef LINUX
1234
1235int
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001236sys_sigreturn(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001237{
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001238#if defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001239 struct pt_regs regs;
1240 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001241
Roland McGrath0f87c492003-06-03 23:29:04 +00001242 if (entering(tcp)) {
1243 tcp->u_arg[0] = 0;
1244
1245 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1246 return 0;
1247
1248 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1249 return 0;
1250
1251 tcp->u_arg[0] = 1;
1252 tcp->u_arg[1] = sc.oldmask;
1253 } else {
1254 sigset_t sigm;
1255 long_to_sigset(tcp->u_arg[1], &sigm);
1256 tcp->u_rval = tcp->u_error = 0;
1257 if (tcp->u_arg[0] == 0)
1258 return 0;
1259 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1260 return RVAL_NONE | RVAL_STR;
1261 }
1262 return 0;
1263#elif defined(S390) || defined(S390X)
1264 long usp;
1265 struct sigcontext_struct sc;
1266
1267 if (entering(tcp)) {
1268 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001269 if (upeek(tcp,PT_GPR15,&usp)<0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001270 return 0;
1271 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1272 return 0;
1273 tcp->u_arg[0] = 1;
1274 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1275 } else {
1276 tcp->u_rval = tcp->u_error = 0;
1277 if (tcp->u_arg[0] == 0)
1278 return 0;
1279 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1280 return RVAL_NONE | RVAL_STR;
1281 }
1282 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001283#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001284 long esp;
1285 struct sigcontext_struct sc;
1286
1287 if (entering(tcp)) {
1288 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001289 if (upeek(tcp, 4*UESP, &esp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290 return 0;
1291 if (umove(tcp, esp, &sc) < 0)
1292 return 0;
1293 tcp->u_arg[0] = 1;
1294 tcp->u_arg[1] = sc.oldmask;
1295 }
1296 else {
1297 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001298 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001299 tcp->u_rval = tcp->u_error = 0;
1300 if (tcp->u_arg[0] == 0)
1301 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001302 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001303 return RVAL_NONE | RVAL_STR;
1304 }
1305 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001306#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001307 struct sigcontext sc;
1308 long sp;
1309
1310 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001311 /* offset of sigcontext in the kernel's sigframe structure: */
1312# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001313 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001314 if (upeek(tcp, PT_R12, &sp) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001315 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001316 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001317 return 0;
1318 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001319 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001320 }
1321 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001322 sigset_t sigm;
1323
1324 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001325 tcp->u_rval = tcp->u_error = 0;
1326 if (tcp->u_arg[0] == 0)
1327 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001328 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001329 return RVAL_NONE | RVAL_STR;
1330 }
1331 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001332#elif defined(POWERPC)
Roland McGrath0f87c492003-06-03 23:29:04 +00001333 long esp;
1334 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001335
Roland McGrath0f87c492003-06-03 23:29:04 +00001336 if (entering(tcp)) {
1337 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001338 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
Roland McGrath0f87c492003-06-03 23:29:04 +00001339 return 0;
1340 if (umove(tcp, esp, &sc) < 0)
1341 return 0;
1342 tcp->u_arg[0] = 1;
1343 tcp->u_arg[1] = sc.oldmask;
1344 }
1345 else {
1346 sigset_t sigm;
1347 long_to_sigset(tcp->u_arg[1], &sigm);
1348 tcp->u_rval = tcp->u_error = 0;
1349 if (tcp->u_arg[0] == 0)
1350 return 0;
1351 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1352 return RVAL_NONE | RVAL_STR;
1353 }
1354 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001355#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001356 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001357 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001358
1359 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001360 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001361 if (upeek(tcp, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001362 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001363 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001364 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001365 tcp->u_arg[0] = 1;
1366 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001367 }
1368 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001369 sigset_t sigm;
1370 long_to_sigset(tcp->u_arg[1], &sigm);
1371 tcp->u_rval = tcp->u_error = 0;
1372 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001373 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001374 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1375 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001376 }
1377 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001378#elif defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001379 long fp;
1380 struct sigcontext_struct sc;
1381
1382 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001383 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001384 if (upeek(tcp, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001386 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001387 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001388 tcp->u_arg[0] = 1;
1389 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001390 }
1391 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001392 sigset_t sigm;
1393 long_to_sigset(tcp->u_arg[1], &sigm);
1394 tcp->u_rval = tcp->u_error = 0;
1395 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001396 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001397 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1398 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399 }
1400 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001401#elif defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001402 long i1;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001403 struct regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001404 m_siginfo_t si;
1405
Roland McGratheb9e2e82009-06-02 16:49:22 -07001406 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1407 perror("sigreturn: PTRACE_GETREGS ");
Roland McGrath0f87c492003-06-03 23:29:04 +00001408 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409 }
Roland McGratheb9e2e82009-06-02 16:49:22 -07001410 if(entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001411 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001412 i1 = regs.r_o1;
Roland McGratheb9e2e82009-06-02 16:49:22 -07001413 if(umove(tcp, i1, &si) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001414 perror("sigreturn: umove ");
1415 return 0;
1416 }
1417 tcp->u_arg[0] = 1;
1418 tcp->u_arg[1] = si.si_mask;
1419 } else {
1420 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001421 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001422 tcp->u_rval = tcp->u_error = 0;
1423 if(tcp->u_arg[0] == 0)
1424 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001425 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001426 return RVAL_NONE | RVAL_STR;
1427 }
1428 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001429#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001430 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1431 sigreturn. */
1432 long sp;
1433 struct ucontext uc;
1434
1435 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001436 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001437 if (upeek(tcp, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001438 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001439 /* There are six words followed by a 128-byte siginfo. */
1440 sp = sp + 6 * 4 + 128;
1441 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001442 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001443 tcp->u_arg[0] = 1;
1444 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1445 } else {
1446 sigset_t sigm;
1447 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001448 tcp->u_rval = tcp->u_error = 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001449 if(tcp->u_arg[0] == 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001450 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001451 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1452 return RVAL_NONE | RVAL_STR;
1453 }
1454 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001455#elif defined(MIPS)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001456 long sp;
Roland McGrath576b7842007-11-04 00:00:00 +00001457 struct pt_regs regs;
1458 m_siginfo_t si;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001459
Roland McGrath576b7842007-11-04 00:00:00 +00001460 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1461 perror("sigreturn: PTRACE_GETREGS ");
1462 return 0;
1463 }
Wichert Akkermanf90da011999-10-31 21:15:38 +00001464 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001465 tcp->u_arg[0] = 0;
Roland McGrath576b7842007-11-04 00:00:00 +00001466 sp = regs.regs[29];
1467 if (umove(tcp, sp, &si) < 0)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001468 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001469 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001470 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001471 sigset_t sigm;
1472 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001473 tcp->u_rval = tcp->u_error = 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001474 if(tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001475 return 0;
1476 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001477 return RVAL_NONE | RVAL_STR;
1478 }
1479 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001480#elif defined(CRISV10) || defined(CRISV32)
1481 struct sigcontext sc;
1482
1483 if (entering(tcp)) {
1484 long regs[PT_MAX+1];
1485
1486 tcp->u_arg[0] = 0;
1487
1488 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1489 perror("sigreturn: PTRACE_GETREGS");
1490 return 0;
1491 }
1492 if (umove(tcp, regs[PT_USP], &sc) < 0)
1493 return 0;
1494 tcp->u_arg[0] = 1;
1495 tcp->u_arg[1] = sc.oldmask;
1496 } else {
1497 sigset_t sigm;
1498 long_to_sigset(tcp->u_arg[1], &sigm);
1499 tcp->u_rval = tcp->u_error = 0;
1500
1501 if (tcp->u_arg[0] == 0)
1502 return 0;
1503 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1504 return RVAL_NONE | RVAL_STR;
1505 }
1506 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001507#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001508#warning No sys_sigreturn() for this architecture
1509#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001510 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001511#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001512}
1513
1514int
1515sys_siggetmask(tcp)
1516struct tcb *tcp;
1517{
1518 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001519 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001520 long_to_sigset(tcp->u_rval, &sigm);
1521 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001522 }
1523 return RVAL_HEX | RVAL_STR;
1524}
1525
1526int
1527sys_sigsuspend(tcp)
1528struct tcb *tcp;
1529{
1530 if (entering(tcp)) {
1531 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001532 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001533#if 0
1534 /* first two are not really arguments, but print them anyway */
1535 /* nevermind, they are an anachronism now, too bad... */
1536 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1537#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001538 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001539 }
1540 return 0;
1541}
1542
1543#endif /* LINUX */
1544
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001545#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001546
1547int
1548sys_sigsuspend(tcp)
1549struct tcb *tcp;
1550{
1551 sigset_t sigset;
1552
1553 if (entering(tcp)) {
1554 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1555 tprintf("[?]");
1556 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001557 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001558 }
1559 return 0;
1560}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001561#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001562static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001563 { UC_SIGMASK, "UC_SIGMASK" },
1564 { UC_STACK, "UC_STACK" },
1565 { UC_CPU, "UC_CPU" },
1566#ifdef UC_FPU
1567 { UC_FPU, "UC_FPU" },
1568#endif
1569#ifdef UC_INTR
1570 { UC_INTR, "UC_INTR" },
1571#endif
1572 { 0, NULL },
1573};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001574#endif /* !FREEBSD */
1575#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001577#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001578#if defined LINUX && !defined SS_ONSTACK
1579#define SS_ONSTACK 1
1580#define SS_DISABLE 2
1581#if __GLIBC_MINOR__ == 0
1582typedef struct
1583{
1584 __ptr_t ss_sp;
1585 int ss_flags;
1586 size_t ss_size;
1587} stack_t;
1588#endif
1589#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001590#ifdef FREEBSD
1591#define stack_t struct sigaltstack
1592#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593
Roland McGrathd9f816f2004-09-04 03:39:20 +00001594static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001595 { SS_ONSTACK, "SS_ONSTACK" },
1596 { SS_DISABLE, "SS_DISABLE" },
1597 { 0, NULL },
1598};
1599#endif
1600
1601#ifdef SVR4
1602static void
1603printcontext(tcp, ucp)
1604struct tcb *tcp;
1605ucontext_t *ucp;
1606{
1607 tprintf("{");
1608 if (!abbrev(tcp)) {
1609 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001610 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001611 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1612 }
1613 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001614 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615 if (!abbrev(tcp)) {
1616 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1617 (unsigned long) ucp->uc_stack.ss_sp,
1618 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001619 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001620 tprintf("}");
1621 }
1622 tprintf(", ...}");
1623}
1624
1625int
1626sys_getcontext(tcp)
1627struct tcb *tcp;
1628{
1629 ucontext_t uc;
1630
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001631 if (exiting(tcp)) {
1632 if (tcp->u_error)
1633 tprintf("%#lx", tcp->u_arg[0]);
1634 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001635 tprintf("NULL");
1636 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1637 tprintf("{...}");
1638 else
1639 printcontext(tcp, &uc);
1640 }
1641 return 0;
1642}
1643
1644int
1645sys_setcontext(tcp)
1646struct tcb *tcp;
1647{
1648 ucontext_t uc;
1649
1650 if (entering(tcp)) {
1651 if (!tcp->u_arg[0])
1652 tprintf("NULL");
1653 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1654 tprintf("{...}");
1655 else
1656 printcontext(tcp, &uc);
1657 }
1658 else {
1659 tcp->u_rval = tcp->u_error = 0;
1660 if (tcp->u_arg[0] == 0)
1661 return 0;
1662 return RVAL_NONE;
1663 }
1664 return 0;
1665}
1666
1667#endif /* SVR4 */
1668
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001669#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001670
1671static int
1672print_stack_t(tcp, addr)
1673struct tcb *tcp;
1674unsigned long addr;
1675{
1676 stack_t ss;
1677 if (umove(tcp, addr, &ss) < 0)
1678 return -1;
1679 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001680 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001681 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1682 return 0;
1683}
1684
1685int
1686sys_sigaltstack(tcp)
1687 struct tcb *tcp;
1688{
1689 if (entering(tcp)) {
1690 if (tcp->u_arg[0] == 0)
1691 tprintf("NULL");
1692 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1693 return -1;
1694 }
1695 else {
1696 tprintf(", ");
1697 if (tcp->u_arg[1] == 0)
1698 tprintf("NULL");
1699 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1700 return -1;
1701 }
1702 return 0;
1703}
1704#endif
1705
1706#ifdef HAVE_SIGACTION
1707
1708int
1709sys_sigprocmask(tcp)
1710struct tcb *tcp;
1711{
1712#ifdef ALPHA
1713 if (entering(tcp)) {
1714 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1715 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001716 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001717 }
1718 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001719 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001720 return RVAL_HEX | RVAL_STR;
1721 }
1722#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001723 if (entering(tcp)) {
1724#ifdef SVR4
1725 if (tcp->u_arg[0] == 0)
1726 tprintf("0");
1727 else
1728#endif /* SVR4 */
1729 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1730 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001731 print_sigset(tcp, tcp->u_arg[1], 0);
1732 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001733 }
1734 else {
1735 if (!tcp->u_arg[2])
1736 tprintf("NULL");
1737 else if (syserror(tcp))
1738 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001739 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001740 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001741 }
1742#endif /* !ALPHA */
1743 return 0;
1744}
1745
1746#endif /* HAVE_SIGACTION */
1747
1748int
1749sys_kill(tcp)
1750struct tcb *tcp;
1751{
1752 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001753 /*
1754 * Sign-extend a 32-bit value when that's what it is.
1755 */
1756 long pid = tcp->u_arg[0];
1757 if (personality_wordsize[current_personality] < sizeof pid)
1758 pid = (long) (int) pid;
1759 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760 }
1761 return 0;
1762}
1763
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001764#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001765int
1766sys_killpg(tcp)
1767struct tcb *tcp;
1768{
1769 return sys_kill(tcp);
1770}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001771#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001772
Roland McGrath8ffc3522003-07-09 09:47:49 +00001773#ifdef LINUX
1774int
1775sys_tgkill(tcp)
1776 struct tcb *tcp;
1777{
1778 if (entering(tcp)) {
1779 tprintf("%ld, %ld, %s",
1780 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1781 }
1782 return 0;
1783}
1784#endif
1785
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001786int
1787sys_sigpending(tcp)
1788struct tcb *tcp;
1789{
1790 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791
1792 if (exiting(tcp)) {
1793 if (syserror(tcp))
1794 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001795 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001796 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001797 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001798 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001799 }
1800 return 0;
1801}
1802
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001803#ifdef SVR4
John Hughes42162082001-10-18 14:48:26 +00001804int sys_sigwait(tcp)
1805struct tcb *tcp;
1806{
1807 sigset_t sigset;
1808
1809 if (entering(tcp)) {
1810 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1811 tprintf("[?]");
1812 else
1813 printsigmask(&sigset, 0);
1814 }
1815 else {
1816 if (!syserror(tcp)) {
1817 tcp->auxstr = signalent[tcp->u_rval];
1818 return RVAL_DECIMAL | RVAL_STR;
1819 }
1820 }
1821 return 0;
1822}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001823#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001824
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001825#ifdef LINUX
1826
1827 int
1828sys_rt_sigprocmask(tcp)
1829 struct tcb *tcp;
1830{
1831 sigset_t sigset;
1832
Nate Sammons4a121431999-04-06 01:19:39 +00001833 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001834 if (entering(tcp)) {
1835 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1836 tprintf(", ");
1837 if (!tcp->u_arg[1])
1838 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001839 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001840 tprintf("%#lx, ", tcp->u_arg[1]);
1841 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001842 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001843 tprintf(", ");
1844 }
1845 }
1846 else {
1847 if (!tcp->u_arg[2])
1848
1849 tprintf("NULL");
1850 else if (syserror(tcp))
1851 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001852 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001853 tprintf("[?]");
1854 else
Nate Sammons4a121431999-04-06 01:19:39 +00001855 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001856 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001857 }
1858 return 0;
1859}
1860
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001861
1862/* Structure describing the action to be taken when a signal arrives. */
1863struct new_sigaction
1864{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001865 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866 unsigned long sa_flags;
1867 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001868 /* Kernel treats sa_mask as an array of longs. */
1869 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1870};
1871/* Same for i386-on-x86_64 and similar cases */
1872struct new_sigaction32
1873{
1874 uint32_t __sa_handler;
1875 uint32_t sa_flags;
1876 uint32_t sa_restorer;
1877 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001878};
1879
1880
Roland McGrath5f206812008-08-20 01:59:40 +00001881int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001882sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883{
1884 struct new_sigaction sa;
1885 sigset_t sigset;
1886 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001887 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001888
1889 if (entering(tcp)) {
1890 printsignal(tcp->u_arg[0]);
1891 tprintf(", ");
1892 addr = tcp->u_arg[1];
1893 } else
1894 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001895
1896 if (addr == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001897 tprintf("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001898 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001899 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001900 if (!verbose(tcp)) {
1901 tprintf("%#lx", addr);
1902 goto after_sa;
1903 }
1904#if SUPPORTED_PERSONALITIES > 1
1905 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1906 && personality_wordsize[current_personality] == 4
1907 ) {
1908 struct new_sigaction32 sa32;
1909 r = umove(tcp, addr, &sa32);
1910 if (r >= 0) {
1911 memset(&sa, 0, sizeof(sa));
1912 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1913 sa.sa_flags = sa32.sa_flags;
1914 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1915 /* Kernel treats sa_mask as an array of longs.
1916 * For 32-bit process, "long" is uint32_t, thus, for example,
1917 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1918 * But for (64-bit) kernel, 32th bit in sa_mask is
1919 * 32th bit in 0th (64-bit) long!
1920 * For little-endian, it's the same.
1921 * For big-endian, we swap 32-bit words.
1922 */
1923 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1924 }
1925 } else
1926#endif
1927 {
1928 r = umove(tcp, addr, &sa);
1929 }
1930 if (r < 0) {
1931 tprintf("{...}");
1932 goto after_sa;
1933 }
1934
1935 if (sa.__sa_handler == SIG_ERR)
1936 tprintf("{SIG_ERR, ");
1937 else if (sa.__sa_handler == SIG_DFL)
1938 tprintf("{SIG_DFL, ");
1939 else if (sa.__sa_handler == SIG_IGN)
1940 tprintf("{SIG_IGN, ");
1941 else
1942 tprintf("{%#lx, ", (long) sa.__sa_handler);
1943 /* Questionable code below.
1944 * Kernel won't handle sys_rt_sigaction
1945 * with wrong sigset size (just returns EINVAL)
1946 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
1947 * and we always use smaller memcpy. */
1948 sigemptyset(&sigset);
1949#ifdef LINUXSPARC
1950 if (tcp->u_arg[4] <= sizeof(sigset))
1951 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1952#else
1953 if (tcp->u_arg[3] <= sizeof(sigset))
1954 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1955#endif
1956 else
1957 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1958 printsigmask(&sigset, 1);
1959 tprintf(", ");
1960 printflags(sigact_flags, sa.sa_flags, "SA_???");
1961#ifdef SA_RESTORER
1962 if (sa.sa_flags & SA_RESTORER)
1963 tprintf(", %p", sa.sa_restorer);
1964#endif
1965 tprintf("}");
1966
1967 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001968 if (entering(tcp))
1969 tprintf(", ");
1970 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001971#ifdef LINUXSPARC
1972 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1973#elif defined(ALPHA)
1974 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1975#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001976 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001977#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001978 return 0;
1979}
1980
Denys Vlasenko1d632462009-04-14 12:51:00 +00001981int
1982sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001983{
1984 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001985
1986 if (exiting(tcp)) {
1987 if (syserror(tcp))
1988 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001989 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1990 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001991 tprintf("[?]");
1992 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001993 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001994 }
1995 return 0;
1996}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001997
1998int
1999sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002000{
2001 if (entering(tcp)) {
2002 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00002003 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
2004 tprintf("[?]");
2005 else
2006 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002007 }
2008 return 0;
2009}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002010
2011int
2012sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002013{
2014 if (entering(tcp)) {
2015 siginfo_t si;
2016 tprintf("%lu, ", tcp->u_arg[0]);
2017 printsignal(tcp->u_arg[1]);
2018 tprintf(", ");
2019 if (umove(tcp, tcp->u_arg[2], &si) < 0)
2020 tprintf("%#lx", tcp->u_arg[2]);
2021 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002022 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002023 }
2024 return 0;
2025}
2026
Denys Vlasenko1d632462009-04-14 12:51:00 +00002027int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002028{
2029 if (entering(tcp)) {
2030 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002031
Roland McGratha39c5a12002-12-17 05:10:37 +00002032 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00002033 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002034 tprintf("[?]");
2035 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002036 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002037 tprintf(", ");
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002038 /* This is the only "return" parameter, */
2039 if (tcp->u_arg[1] != 0)
2040 return 0;
2041 /* ... if it's NULL, can decode all on entry */
2042 tprintf("NULL, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002043 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002044 else if (tcp->u_arg[1] != 0) {
2045 /* syscall exit, and u_arg[1] wasn't NULL */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046 if (syserror(tcp))
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002047 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002048 else {
2049 siginfo_t si;
2050 if (umove(tcp, tcp->u_arg[1], &si) < 0)
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002051 tprintf("%#lx, ", tcp->u_arg[1]);
2052 else {
Denys Vlasenkof535b542009-01-13 18:30:55 +00002053 printsiginfo(&si, verbose(tcp));
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002054 tprintf(", ");
2055 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002056 }
2057 }
Denys Vlasenkob1a78cf2009-04-15 13:31:59 +00002058 else {
2059 /* syscall exit, and u_arg[1] was NULL */
2060 return 0;
2061 }
2062 print_timespec(tcp, tcp->u_arg[2]);
2063 tprintf(", %d", (int) tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002064 return 0;
2065};
2066
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002067int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002068sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002069{
2070 if (entering(tcp))
2071 tprintf("<... resuming interrupted call ...>");
2072 return 0;
2073}
2074
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002075static int
2076do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00002077{
2078 if (entering(tcp)) {
2079 tprintf("%ld, ", tcp->u_arg[0]);
2080 print_sigset(tcp, tcp->u_arg[1], 1);
Dmitry V. Levin9d2ee3d2009-10-05 13:45:19 +00002081 tprintf(", %lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002082 if (flags_arg >= 0) {
2083 tprintf(", ");
2084 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2085 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00002086 }
2087 return 0;
2088}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002089
2090int
2091sys_signalfd(struct tcb *tcp)
2092{
2093 return do_signalfd(tcp, -1);
2094}
2095
2096int
2097sys_signalfd4(struct tcb *tcp)
2098{
2099 return do_signalfd(tcp, 3);
2100}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002101#endif /* LINUX */