blob: e2a4af6f703d2c8fd7d3d906461b6a4f9a01c95c [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{
Nate Sammonsce780fc1999-03-29 23:23:13 +0000405 tprintf(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
Denys Vlasenko4dedd562009-02-24 15:17:53 +00001406 if (do_ptrace(PTRACE_GETREGS, tcp, (char *)&regs, 0) < 0) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001407 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001408 }
Denys Vlasenko4dedd562009-02-24 15:17:53 +00001409 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001410 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001411 i1 = regs.r_o1;
Denys Vlasenko4dedd562009-02-24 15:17:53 +00001412 if (umove(tcp, i1, &si) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413 perror("sigreturn: umove ");
1414 return 0;
1415 }
1416 tcp->u_arg[0] = 1;
1417 tcp->u_arg[1] = si.si_mask;
1418 } else {
1419 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001420 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001421 tcp->u_rval = tcp->u_error = 0;
1422 if(tcp->u_arg[0] == 0)
1423 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001424 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001425 return RVAL_NONE | RVAL_STR;
1426 }
1427 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001428#elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
Roland McGrath542c2c62008-05-20 01:11:56 +00001429 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1430 sigreturn. */
1431 long sp;
1432 struct ucontext uc;
1433
1434 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001435 tcp->u_arg[0] = 0;
Denys Vlasenko932fc7d2008-12-16 18:18:40 +00001436 if (upeek(tcp, REG_SP, &sp) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001437 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001438 /* There are six words followed by a 128-byte siginfo. */
1439 sp = sp + 6 * 4 + 128;
1440 if (umove(tcp, sp, &uc) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001441 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001442 tcp->u_arg[0] = 1;
1443 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1444 } else {
1445 sigset_t sigm;
1446 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001447 tcp->u_rval = tcp->u_error = 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001448 if(tcp->u_arg[0] == 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001449 return 0;
Roland McGrath542c2c62008-05-20 01:11:56 +00001450 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1451 return RVAL_NONE | RVAL_STR;
1452 }
1453 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001454#elif defined(MIPS)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001455 long sp;
Roland McGrath576b7842007-11-04 00:00:00 +00001456 struct pt_regs regs;
1457 m_siginfo_t si;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001458
Roland McGrath576b7842007-11-04 00:00:00 +00001459 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1460 perror("sigreturn: PTRACE_GETREGS ");
1461 return 0;
1462 }
Wichert Akkermanf90da011999-10-31 21:15:38 +00001463 if(entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001464 tcp->u_arg[0] = 0;
Roland McGrath576b7842007-11-04 00:00:00 +00001465 sp = regs.regs[29];
1466 if (umove(tcp, sp, &si) < 0)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001467 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001468 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001469 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001470 sigset_t sigm;
1471 long_to_sigset(tcp->u_arg[1], &sigm);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001472 tcp->u_rval = tcp->u_error = 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001473 if(tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001474 return 0;
1475 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001476 return RVAL_NONE | RVAL_STR;
1477 }
1478 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001479#elif defined(CRISV10) || defined(CRISV32)
1480 struct sigcontext sc;
1481
1482 if (entering(tcp)) {
1483 long regs[PT_MAX+1];
1484
1485 tcp->u_arg[0] = 0;
1486
1487 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1488 perror("sigreturn: PTRACE_GETREGS");
1489 return 0;
1490 }
1491 if (umove(tcp, regs[PT_USP], &sc) < 0)
1492 return 0;
1493 tcp->u_arg[0] = 1;
1494 tcp->u_arg[1] = sc.oldmask;
1495 } else {
1496 sigset_t sigm;
1497 long_to_sigset(tcp->u_arg[1], &sigm);
1498 tcp->u_rval = tcp->u_error = 0;
1499
1500 if (tcp->u_arg[0] == 0)
1501 return 0;
1502 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1503 return RVAL_NONE | RVAL_STR;
1504 }
1505 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001506#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001507#warning No sys_sigreturn() for this architecture
1508#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001509 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001510#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001511}
1512
1513int
1514sys_siggetmask(tcp)
1515struct tcb *tcp;
1516{
1517 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001518 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001519 long_to_sigset(tcp->u_rval, &sigm);
1520 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001521 }
1522 return RVAL_HEX | RVAL_STR;
1523}
1524
1525int
1526sys_sigsuspend(tcp)
1527struct tcb *tcp;
1528{
1529 if (entering(tcp)) {
1530 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001531 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001532#if 0
1533 /* first two are not really arguments, but print them anyway */
1534 /* nevermind, they are an anachronism now, too bad... */
1535 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1536#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001537 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001538 }
1539 return 0;
1540}
1541
1542#endif /* LINUX */
1543
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001544#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001545
1546int
1547sys_sigsuspend(tcp)
1548struct tcb *tcp;
1549{
1550 sigset_t sigset;
1551
1552 if (entering(tcp)) {
1553 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1554 tprintf("[?]");
1555 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001556 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001557 }
1558 return 0;
1559}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001560#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001561static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001562 { UC_SIGMASK, "UC_SIGMASK" },
1563 { UC_STACK, "UC_STACK" },
1564 { UC_CPU, "UC_CPU" },
1565#ifdef UC_FPU
1566 { UC_FPU, "UC_FPU" },
1567#endif
1568#ifdef UC_INTR
1569 { UC_INTR, "UC_INTR" },
1570#endif
1571 { 0, NULL },
1572};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001573#endif /* !FREEBSD */
1574#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001575
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001576#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001577#if defined LINUX && !defined SS_ONSTACK
1578#define SS_ONSTACK 1
1579#define SS_DISABLE 2
1580#if __GLIBC_MINOR__ == 0
1581typedef struct
1582{
1583 __ptr_t ss_sp;
1584 int ss_flags;
1585 size_t ss_size;
1586} stack_t;
1587#endif
1588#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001589#ifdef FREEBSD
1590#define stack_t struct sigaltstack
1591#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001592
Roland McGrathd9f816f2004-09-04 03:39:20 +00001593static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001594 { SS_ONSTACK, "SS_ONSTACK" },
1595 { SS_DISABLE, "SS_DISABLE" },
1596 { 0, NULL },
1597};
1598#endif
1599
1600#ifdef SVR4
1601static void
1602printcontext(tcp, ucp)
1603struct tcb *tcp;
1604ucontext_t *ucp;
1605{
1606 tprintf("{");
1607 if (!abbrev(tcp)) {
1608 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001609 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001610 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1611 }
1612 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001613 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001614 if (!abbrev(tcp)) {
1615 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1616 (unsigned long) ucp->uc_stack.ss_sp,
1617 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001618 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001619 tprintf("}");
1620 }
1621 tprintf(", ...}");
1622}
1623
1624int
1625sys_getcontext(tcp)
1626struct tcb *tcp;
1627{
1628 ucontext_t uc;
1629
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001630 if (exiting(tcp)) {
1631 if (tcp->u_error)
1632 tprintf("%#lx", tcp->u_arg[0]);
1633 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001634 tprintf("NULL");
1635 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1636 tprintf("{...}");
1637 else
1638 printcontext(tcp, &uc);
1639 }
1640 return 0;
1641}
1642
1643int
1644sys_setcontext(tcp)
1645struct tcb *tcp;
1646{
1647 ucontext_t uc;
1648
1649 if (entering(tcp)) {
1650 if (!tcp->u_arg[0])
1651 tprintf("NULL");
1652 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1653 tprintf("{...}");
1654 else
1655 printcontext(tcp, &uc);
1656 }
1657 else {
1658 tcp->u_rval = tcp->u_error = 0;
1659 if (tcp->u_arg[0] == 0)
1660 return 0;
1661 return RVAL_NONE;
1662 }
1663 return 0;
1664}
1665
1666#endif /* SVR4 */
1667
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001668#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001669
1670static int
1671print_stack_t(tcp, addr)
1672struct tcb *tcp;
1673unsigned long addr;
1674{
1675 stack_t ss;
1676 if (umove(tcp, addr, &ss) < 0)
1677 return -1;
1678 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001679 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001680 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1681 return 0;
1682}
1683
1684int
1685sys_sigaltstack(tcp)
1686 struct tcb *tcp;
1687{
1688 if (entering(tcp)) {
1689 if (tcp->u_arg[0] == 0)
1690 tprintf("NULL");
1691 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1692 return -1;
1693 }
1694 else {
1695 tprintf(", ");
1696 if (tcp->u_arg[1] == 0)
1697 tprintf("NULL");
1698 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1699 return -1;
1700 }
1701 return 0;
1702}
1703#endif
1704
1705#ifdef HAVE_SIGACTION
1706
1707int
1708sys_sigprocmask(tcp)
1709struct tcb *tcp;
1710{
1711#ifdef ALPHA
1712 if (entering(tcp)) {
1713 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1714 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001715 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001716 }
1717 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001718 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001719 return RVAL_HEX | RVAL_STR;
1720 }
1721#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001722 if (entering(tcp)) {
1723#ifdef SVR4
1724 if (tcp->u_arg[0] == 0)
1725 tprintf("0");
1726 else
1727#endif /* SVR4 */
1728 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1729 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001730 print_sigset(tcp, tcp->u_arg[1], 0);
1731 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001732 }
1733 else {
1734 if (!tcp->u_arg[2])
1735 tprintf("NULL");
1736 else if (syserror(tcp))
1737 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001738 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001739 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001740 }
1741#endif /* !ALPHA */
1742 return 0;
1743}
1744
1745#endif /* HAVE_SIGACTION */
1746
1747int
1748sys_kill(tcp)
1749struct tcb *tcp;
1750{
1751 if (entering(tcp)) {
Roland McGrath4d7ed022008-05-20 01:43:09 +00001752 /*
1753 * Sign-extend a 32-bit value when that's what it is.
1754 */
1755 long pid = tcp->u_arg[0];
1756 if (personality_wordsize[current_personality] < sizeof pid)
1757 pid = (long) (int) pid;
1758 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001759 }
1760 return 0;
1761}
1762
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001763#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001764int
1765sys_killpg(tcp)
1766struct tcb *tcp;
1767{
1768 return sys_kill(tcp);
1769}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001770#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001771
Roland McGrath8ffc3522003-07-09 09:47:49 +00001772#ifdef LINUX
1773int
1774sys_tgkill(tcp)
1775 struct tcb *tcp;
1776{
1777 if (entering(tcp)) {
1778 tprintf("%ld, %ld, %s",
1779 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1780 }
1781 return 0;
1782}
1783#endif
1784
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001785int
1786sys_sigpending(tcp)
1787struct tcb *tcp;
1788{
1789 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001790
1791 if (exiting(tcp)) {
1792 if (syserror(tcp))
1793 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001794 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001795 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001796 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001797 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001798 }
1799 return 0;
1800}
1801
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001802#ifdef SVR4
John Hughes42162082001-10-18 14:48:26 +00001803int sys_sigwait(tcp)
1804struct tcb *tcp;
1805{
1806 sigset_t sigset;
1807
1808 if (entering(tcp)) {
1809 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1810 tprintf("[?]");
1811 else
1812 printsigmask(&sigset, 0);
1813 }
1814 else {
1815 if (!syserror(tcp)) {
1816 tcp->auxstr = signalent[tcp->u_rval];
1817 return RVAL_DECIMAL | RVAL_STR;
1818 }
1819 }
1820 return 0;
1821}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001822#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001823
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001824#ifdef LINUX
1825
1826 int
1827sys_rt_sigprocmask(tcp)
1828 struct tcb *tcp;
1829{
1830 sigset_t sigset;
1831
Nate Sammons4a121431999-04-06 01:19:39 +00001832 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001833 if (entering(tcp)) {
1834 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1835 tprintf(", ");
1836 if (!tcp->u_arg[1])
1837 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001838 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001839 tprintf("%#lx, ", tcp->u_arg[1]);
1840 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001841 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001842 tprintf(", ");
1843 }
1844 }
1845 else {
1846 if (!tcp->u_arg[2])
1847
1848 tprintf("NULL");
1849 else if (syserror(tcp))
1850 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001851 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001852 tprintf("[?]");
1853 else
Nate Sammons4a121431999-04-06 01:19:39 +00001854 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001855 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001856 }
1857 return 0;
1858}
1859
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001860
1861/* Structure describing the action to be taken when a signal arrives. */
1862struct new_sigaction
1863{
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001864 __sighandler_t __sa_handler;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001865 unsigned long sa_flags;
1866 void (*sa_restorer) (void);
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001867 /* Kernel treats sa_mask as an array of longs. */
1868 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1869};
1870/* Same for i386-on-x86_64 and similar cases */
1871struct new_sigaction32
1872{
1873 uint32_t __sa_handler;
1874 uint32_t sa_flags;
1875 uint32_t sa_restorer;
1876 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001877};
1878
1879
Roland McGrath5f206812008-08-20 01:59:40 +00001880int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001881sys_rt_sigaction(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001882{
1883 struct new_sigaction sa;
1884 sigset_t sigset;
1885 long addr;
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001886 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001887
1888 if (entering(tcp)) {
1889 printsignal(tcp->u_arg[0]);
1890 tprintf(", ");
1891 addr = tcp->u_arg[1];
1892 } else
1893 addr = tcp->u_arg[2];
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001894
1895 if (addr == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001896 tprintf("NULL");
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001897 goto after_sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001898 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001899 if (!verbose(tcp)) {
1900 tprintf("%#lx", addr);
1901 goto after_sa;
1902 }
1903#if SUPPORTED_PERSONALITIES > 1
1904 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1905 && personality_wordsize[current_personality] == 4
1906 ) {
1907 struct new_sigaction32 sa32;
1908 r = umove(tcp, addr, &sa32);
1909 if (r >= 0) {
1910 memset(&sa, 0, sizeof(sa));
1911 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1912 sa.sa_flags = sa32.sa_flags;
1913 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1914 /* Kernel treats sa_mask as an array of longs.
1915 * For 32-bit process, "long" is uint32_t, thus, for example,
1916 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1917 * But for (64-bit) kernel, 32th bit in sa_mask is
1918 * 32th bit in 0th (64-bit) long!
1919 * For little-endian, it's the same.
1920 * For big-endian, we swap 32-bit words.
1921 */
1922 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1923 }
1924 } else
1925#endif
1926 {
1927 r = umove(tcp, addr, &sa);
1928 }
1929 if (r < 0) {
1930 tprintf("{...}");
1931 goto after_sa;
1932 }
1933
1934 if (sa.__sa_handler == SIG_ERR)
1935 tprintf("{SIG_ERR, ");
1936 else if (sa.__sa_handler == SIG_DFL)
1937 tprintf("{SIG_DFL, ");
1938 else if (sa.__sa_handler == SIG_IGN)
1939 tprintf("{SIG_IGN, ");
1940 else
1941 tprintf("{%#lx, ", (long) sa.__sa_handler);
1942 /* Questionable code below.
1943 * Kernel won't handle sys_rt_sigaction
1944 * with wrong sigset size (just returns EINVAL)
1945 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
1946 * and we always use smaller memcpy. */
1947 sigemptyset(&sigset);
1948#ifdef LINUXSPARC
1949 if (tcp->u_arg[4] <= sizeof(sigset))
1950 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1951#else
1952 if (tcp->u_arg[3] <= sizeof(sigset))
1953 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1954#endif
1955 else
1956 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1957 printsigmask(&sigset, 1);
1958 tprintf(", ");
1959 printflags(sigact_flags, sa.sa_flags, "SA_???");
1960#ifdef SA_RESTORER
1961 if (sa.sa_flags & SA_RESTORER)
1962 tprintf(", %p", sa.sa_restorer);
1963#endif
1964 tprintf("}");
1965
1966 after_sa:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001967 if (entering(tcp))
1968 tprintf(", ");
1969 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001970#ifdef LINUXSPARC
1971 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1972#elif defined(ALPHA)
1973 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1974#else
Denys Vlasenko7a862d72009-04-15 13:22:59 +00001975 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001976#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001977 return 0;
1978}
1979
Denys Vlasenko1d632462009-04-14 12:51:00 +00001980int
1981sys_rt_sigpending(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001982{
1983 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001984
1985 if (exiting(tcp)) {
1986 if (syserror(tcp))
1987 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001988 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1989 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001990 tprintf("[?]");
1991 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001992 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001993 }
1994 return 0;
1995}
Denys Vlasenko1d632462009-04-14 12:51:00 +00001996
1997int
1998sys_rt_sigsuspend(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001999{
2000 if (entering(tcp)) {
2001 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00002002 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
2003 tprintf("[?]");
2004 else
2005 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002006 }
2007 return 0;
2008}
Denys Vlasenko1d632462009-04-14 12:51:00 +00002009
2010int
2011sys_rt_sigqueueinfo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002012{
2013 if (entering(tcp)) {
2014 siginfo_t si;
2015 tprintf("%lu, ", tcp->u_arg[0]);
2016 printsignal(tcp->u_arg[1]);
2017 tprintf(", ");
2018 if (umove(tcp, tcp->u_arg[2], &si) < 0)
2019 tprintf("%#lx", tcp->u_arg[2]);
2020 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002021 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002022 }
2023 return 0;
2024}
2025
Denys Vlasenko1d632462009-04-14 12:51:00 +00002026int sys_rt_sigtimedwait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002027{
2028 if (entering(tcp)) {
2029 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002030
Roland McGratha39c5a12002-12-17 05:10:37 +00002031 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00002032 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002033 tprintf("[?]");
2034 else
Wichert Akkerman46956571999-11-26 10:12:59 +00002035 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002036 tprintf(", ");
2037 }
2038 else {
2039 if (syserror(tcp))
2040 tprintf("%#lx", tcp->u_arg[0]);
2041 else {
2042 siginfo_t si;
2043 if (umove(tcp, tcp->u_arg[1], &si) < 0)
2044 tprintf("%#lx", tcp->u_arg[1]);
2045 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002046 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002047 /* XXX For now */
2048 tprintf(", %#lx", tcp->u_arg[2]);
2049 tprintf(", %d", (int) tcp->u_arg[3]);
2050 }
2051 }
2052 return 0;
2053};
2054
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002055int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002056sys_restart_syscall(struct tcb *tcp)
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002057{
2058 if (entering(tcp))
2059 tprintf("<... resuming interrupted call ...>");
2060 return 0;
2061}
2062
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002063static int
2064do_signalfd(struct tcb *tcp, int flags_arg)
Roland McGrathf46ccd32007-08-02 01:15:59 +00002065{
2066 if (entering(tcp)) {
2067 tprintf("%ld, ", tcp->u_arg[0]);
2068 print_sigset(tcp, tcp->u_arg[1], 1);
2069 tprintf("%lu", tcp->u_arg[2]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002070 if (flags_arg >= 0) {
2071 tprintf(", ");
2072 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2073 }
Roland McGrathf46ccd32007-08-02 01:15:59 +00002074 }
2075 return 0;
2076}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00002077
2078int
2079sys_signalfd(struct tcb *tcp)
2080{
2081 return do_signalfd(tcp, -1);
2082}
2083
2084int
2085sys_signalfd4(struct tcb *tcp)
2086{
2087 return do_signalfd(tcp, 3);
2088}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002089#endif /* LINUX */