blob: 90e38b70028a1cc5c362dab9a69e80a2d21f3b5d [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000038#include <signal.h>
39#include <sys/user.h>
40#include <fcntl.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041
42#ifdef SVR4
43#include <sys/ucontext.h>
44#endif /* SVR4 */
45
Wichert Akkerman36915a11999-07-13 15:45:02 +000046#ifdef HAVE_SYS_REG_H
47# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000048#ifndef PTRACE_PEEKUSR
Wichert Akkerman36915a11999-07-13 15:45:02 +000049# define PTRACE_PEEKUSR PTRACE_PEEKUSER
Wichert Akkerman15dea971999-10-06 13:06:34 +000050#endif
51#ifndef PTRACE_POKEUSR
Wichert Akkerman36915a11999-07-13 15:45:02 +000052# define PTRACE_POKEUSR PTRACE_POKEUSER
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000053#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000054#elif defined(HAVE_LINUX_PTRACE_H)
55#undef PTRACE_SYSCALL
Roland McGrathb0acdfd2004-03-01 21:31:02 +000056# ifdef HAVE_STRUCT_IA64_FPREG
57# define ia64_fpreg XXX_ia64_fpreg
58# endif
59# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
60# define pt_all_user_regs XXX_pt_all_user_regs
61# endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000062#include <linux/ptrace.h>
Roland McGrathb0acdfd2004-03-01 21:31:02 +000063# undef ia64_fpreg
64# undef pt_all_user_regs
Wichert Akkerman15dea971999-10-06 13:06:34 +000065#endif
Wichert Akkerman36915a11999-07-13 15:45:02 +000066
Wichert Akkermanfaf72222000-02-19 23:59:03 +000067
Wichert Akkerman36915a11999-07-13 15:45:02 +000068#ifdef LINUX
69
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000070#ifdef IA64
71# include <asm/ptrace_offsets.h>
72#endif /* !IA64 */
73
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000074#if HAVE_ASM_REG_H
Roland McGrath6d1a65c2004-07-12 07:44:08 +000075# if defined (SPARC) || defined (SPARC64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000076# define fpq kernel_fpq
77# define fq kernel_fq
78# define fpu kernel_fpu
Roland McGrath30ff45e2003-01-30 20:15:23 +000079# endif
80# include <asm/reg.h>
Roland McGrath6d1a65c2004-07-12 07:44:08 +000081# if defined (SPARC) || defined (SPARC64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000082# undef fpq
83# undef fq
Roland McGratha39c5a12002-12-17 05:10:37 +000084# undef fpu
Roland McGrath30ff45e2003-01-30 20:15:23 +000085# endif
Roland McGrath6d1a65c2004-07-12 07:44:08 +000086#if defined (LINUX) && defined (SPARC64)
87# define r_pc r_tpc
88# undef PTRACE_GETREGS
89# define PTRACE_GETREGS PTRACE_GETREGS64
90# undef PTRACE_SETREGS
91# define PTRACE_SETREGS PTRACE_SETREGS64
92#endif /* LINUX && SPARC64 */
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000093#endif /* HAVE_ASM_REG_H */
Roland McGrath30ff45e2003-01-30 20:15:23 +000094
Roland McGrath6d1a65c2004-07-12 07:44:08 +000095#if defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000096typedef struct {
Wichert Akkerman9ce1a631999-08-29 23:15:07 +000097 struct regs si_regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000098 int si_mask;
99} m_siginfo_t;
Roland McGrath576b7842007-11-04 00:00:00 +0000100#elif defined (MIPS)
101typedef struct {
102 struct pt_regs si_regs;
103 int si_mask;
104} m_siginfo_t;
Roland McGrath30ff45e2003-01-30 20:15:23 +0000105#elif defined HAVE_ASM_SIGCONTEXT_H
106#if !defined(IA64) && !defined(X86_64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000107#include <asm/sigcontext.h>
Roland McGrath30ff45e2003-01-30 20:15:23 +0000108#endif /* !IA64 && !X86_64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000109#else /* !HAVE_ASM_SIGCONTEXT_H */
110#ifdef I386
111struct sigcontext_struct {
112 unsigned short gs, __gsh;
113 unsigned short fs, __fsh;
114 unsigned short es, __esh;
115 unsigned short ds, __dsh;
116 unsigned long edi;
117 unsigned long esi;
118 unsigned long ebp;
119 unsigned long esp;
120 unsigned long ebx;
121 unsigned long edx;
122 unsigned long ecx;
123 unsigned long eax;
124 unsigned long trapno;
125 unsigned long err;
126 unsigned long eip;
127 unsigned short cs, __csh;
128 unsigned long eflags;
129 unsigned long esp_at_signal;
130 unsigned short ss, __ssh;
131 unsigned long i387;
132 unsigned long oldmask;
133 unsigned long cr2;
134};
135#else /* !I386 */
136#ifdef M68K
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000137struct sigcontext
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138{
139 unsigned long sc_mask;
140 unsigned long sc_usp;
141 unsigned long sc_d0;
142 unsigned long sc_d1;
143 unsigned long sc_a0;
144 unsigned long sc_a1;
145 unsigned short sc_sr;
146 unsigned long sc_pc;
147 unsigned short sc_formatvec;
148};
149#endif /* M68K */
150#endif /* !I386 */
151#endif /* !HAVE_ASM_SIGCONTEXT_H */
152#ifndef NSIG
153#define NSIG 32
154#endif
155#ifdef ARM
156#undef NSIG
157#define NSIG 32
158#endif
159#endif /* LINUX */
160
Roland McGrathee36ce12004-09-04 03:53:10 +0000161const char *const signalent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000162#include "signalent.h"
163};
Roland McGrathee36ce12004-09-04 03:53:10 +0000164const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165
166#if SUPPORTED_PERSONALITIES >= 2
Roland McGrathee36ce12004-09-04 03:53:10 +0000167const char *const signalent1[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000168#include "signalent1.h"
169};
Roland McGrathee36ce12004-09-04 03:53:10 +0000170const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000171#endif /* SUPPORTED_PERSONALITIES >= 2 */
172
173#if SUPPORTED_PERSONALITIES >= 3
Roland McGrathee36ce12004-09-04 03:53:10 +0000174const char *const signalent2[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000175#include "signalent2.h"
176};
Roland McGrathee36ce12004-09-04 03:53:10 +0000177const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000178#endif /* SUPPORTED_PERSONALITIES >= 3 */
179
Roland McGrathee36ce12004-09-04 03:53:10 +0000180const char *const *signalent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181int nsignals;
182
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000183#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184
Roland McGrathd9f816f2004-09-04 03:39:20 +0000185static const struct xlat sigvec_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186 { SV_ONSTACK, "SV_ONSTACK" },
187 { SV_INTERRUPT, "SV_INTERRUPT" },
188 { SV_RESETHAND, "SV_RESETHAND" },
189 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
190 { 0, NULL },
191};
192
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000193#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000194
195#ifdef HAVE_SIGACTION
196
Roland McGrath063ae2d2005-02-02 04:16:54 +0000197#if defined LINUX && (defined I386 || defined X86_64)
Roland McGrath2638cb42002-12-15 23:58:41 +0000198/* The libc headers do not define this constant since it should only be
199 used by the implementation. So wwe define it here. */
200# ifndef SA_RESTORER
201# define SA_RESTORER 0x04000000
202# endif
203#endif
204
Roland McGrathd9f816f2004-09-04 03:39:20 +0000205static const struct xlat sigact_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000206#ifdef SA_RESTORER
207 { SA_RESTORER, "SA_RESTORER" },
208#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000209#ifdef SA_STACK
210 { SA_STACK, "SA_STACK" },
211#endif
212#ifdef SA_RESTART
213 { SA_RESTART, "SA_RESTART" },
214#endif
215#ifdef SA_INTERRUPT
216 { SA_INTERRUPT, "SA_INTERRUPT" },
217#endif
218#ifdef SA_NOMASK
219 { SA_NOMASK, "SA_NOMASK" },
220#endif
221#ifdef SA_ONESHOT
222 { SA_ONESHOT, "SA_ONESHOT" },
223#endif
224#ifdef SA_SIGINFO
225 { SA_SIGINFO, "SA_SIGINFO" },
226#endif
227#ifdef SA_RESETHAND
228 { SA_RESETHAND, "SA_RESETHAND" },
229#endif
230#ifdef SA_ONSTACK
231 { SA_ONSTACK, "SA_ONSTACK" },
232#endif
233#ifdef SA_NODEFER
234 { SA_NODEFER, "SA_NODEFER" },
235#endif
236#ifdef SA_NOCLDSTOP
237 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
238#endif
239#ifdef SA_NOCLDWAIT
240 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
241#endif
242#ifdef _SA_BSDCALL
243 { _SA_BSDCALL, "_SA_BSDCALL" },
244#endif
245 { 0, NULL },
246};
247
Roland McGrathd9f816f2004-09-04 03:39:20 +0000248static const struct xlat sigprocmaskcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000249 { SIG_BLOCK, "SIG_BLOCK" },
250 { SIG_UNBLOCK, "SIG_UNBLOCK" },
251 { SIG_SETMASK, "SIG_SETMASK" },
252#ifdef SIG_SETMASK32
253 { SIG_SETMASK32,"SIG_SETMASK32" },
254#endif
255 { 0, NULL },
256};
257
258#endif /* HAVE_SIGACTION */
259
Nate Sammonsce780fc1999-03-29 23:23:13 +0000260/* Anonymous realtime signals. */
261/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
262 constant. This is what we want. Otherwise, just use SIGRTMIN. */
263#ifdef SIGRTMIN
264#ifndef __SIGRTMIN
265#define __SIGRTMIN SIGRTMIN
266#define __SIGRTMAX SIGRTMAX /* likewise */
267#endif
268#endif
269
Roland McGrathee36ce12004-09-04 03:53:10 +0000270const char *
Nate Sammonsce780fc1999-03-29 23:23:13 +0000271signame(sig)
272int sig;
273{
274 static char buf[30];
Roland McGrathad81dce2005-05-09 07:40:30 +0000275 if (sig >= 0 && sig < nsignals) {
Nate Sammonsce780fc1999-03-29 23:23:13 +0000276 return signalent[sig];
277#ifdef SIGRTMIN
Nate Sammons3080aa41999-03-30 00:16:41 +0000278 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000279 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000280 return buf;
281#endif /* SIGRTMIN */
282 } else {
283 sprintf(buf, "%d", sig);
284 return buf;
285 }
286}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000287
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000288#ifndef UNIXWARE
Nate Sammons4a121431999-04-06 01:19:39 +0000289static void
290long_to_sigset(l, s)
291long l;
292sigset_t *s;
293{
294 sigemptyset(s);
295 *(long *)s = l;
296}
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000297#endif
Nate Sammons4a121431999-04-06 01:19:39 +0000298
299static int
300copy_sigset_len(tcp, addr, s, len)
301struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000302long addr;
Nate Sammons4a121431999-04-06 01:19:39 +0000303sigset_t *s;
304int len;
305{
306 if (len > sizeof(*s))
307 len = sizeof(*s);
308 sigemptyset(s);
309 if (umoven(tcp, addr, len, (char *)s) < 0)
310 return -1;
311 return 0;
312}
313
314#ifdef LINUX
315/* Original sigset is unsigned long */
316#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
317#else
318#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
319#endif
320
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000321static const char *
322sprintsigmask(const char *str, sigset_t *mask, int rt)
323/* set might include realtime sigs */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324{
325 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000326 int maxsigs;
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000327 char *format, *s;
Roland McGratha39c5a12002-12-17 05:10:37 +0000328 static char outstr[8 * sizeof(sigset_t) * 8];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000330 strcpy(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331 s = outstr + strlen(outstr);
332 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000333 maxsigs = nsignals;
334#ifdef __SIGRTMAX
335 if (rt)
336 maxsigs = __SIGRTMAX; /* instead */
337#endif
338 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000339 if (sigismember(mask, i) == 1)
340 nsigs++;
341 }
342 if (nsigs >= nsignals * 2 / 3) {
343 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000344 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000345 switch (sigismember(mask, i)) {
346 case 1:
347 sigdelset(mask, i);
348 break;
349 case 0:
350 sigaddset(mask, i);
351 break;
352 }
353 }
354 }
355 format = "%s";
356 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000357 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000359 /* real-time signals on solaris don't have
360 * signalent entries
361 */
362 if (i < nsignals) {
363 sprintf(s, format, signalent[i] + 3);
364 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000365#ifdef SIGRTMIN
366 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
367 char tsig[40];
368 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
369 sprintf(s, format, tsig);
370 }
371#endif /* SIGRTMIN */
John Hughesbdf48f52001-03-06 15:08:09 +0000372 else {
373 char tsig[32];
374 sprintf(tsig, "%u", i);
375 sprintf(s, format, tsig);
376 }
377 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378 format = " %s";
379 }
380 }
381 *s++ = ']';
382 *s = '\0';
383 return outstr;
384}
385
386static void
Nate Sammons4a121431999-04-06 01:19:39 +0000387printsigmask(mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000388sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000389int rt;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000390{
Nate Sammons4a121431999-04-06 01:19:39 +0000391 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392}
393
394void
395printsignal(nr)
396int nr;
397{
Nate Sammonsce780fc1999-03-29 23:23:13 +0000398 tprintf(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399}
400
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000401void
402print_sigset(struct tcb *tcp, long addr, int rt)
403{
404 sigset_t ss;
405
406 if (!addr)
407 tprintf("NULL");
408 else if (copy_sigset(tcp, addr, &ss) < 0)
409 tprintf("%#lx", addr);
410 else
411 printsigmask(&ss, rt);
412}
413
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000414#ifdef LINUX
415
John Hughes58265892001-10-18 15:13:53 +0000416#ifndef ILL_ILLOPC
417#define ILL_ILLOPC 1 /* illegal opcode */
418#define ILL_ILLOPN 2 /* illegal operand */
419#define ILL_ILLADR 3 /* illegal addressing mode */
420#define ILL_ILLTRP 4 /* illegal trap */
421#define ILL_PRVOPC 5 /* privileged opcode */
422#define ILL_PRVREG 6 /* privileged register */
423#define ILL_COPROC 7 /* coprocessor error */
424#define ILL_BADSTK 8 /* internal stack error */
425#define FPE_INTDIV 1 /* integer divide by zero */
426#define FPE_INTOVF 2 /* integer overflow */
427#define FPE_FLTDIV 3 /* floating point divide by zero */
428#define FPE_FLTOVF 4 /* floating point overflow */
429#define FPE_FLTUND 5 /* floating point underflow */
430#define FPE_FLTRES 6 /* floating point inexact result */
431#define FPE_FLTINV 7 /* floating point invalid operation */
432#define FPE_FLTSUB 8 /* subscript out of range */
433#define SEGV_MAPERR 1 /* address not mapped to object */
434#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
435#define BUS_ADRALN 1 /* invalid address alignment */
436#define BUS_ADRERR 2 /* non-existant physical address */
437#define BUS_OBJERR 3 /* object specific hardware error */
438#define TRAP_BRKPT 1 /* process breakpoint */
439#define TRAP_TRACE 2 /* process trace trap */
440#define CLD_EXITED 1 /* child has exited */
441#define CLD_KILLED 2 /* child was killed */
442#define CLD_DUMPED 3 /* child terminated abnormally */
443#define CLD_TRAPPED 4 /* traced child has trapped */
444#define CLD_STOPPED 5 /* child has stopped */
445#define CLD_CONTINUED 6 /* stopped child has continued */
446#define POLL_IN 1 /* data input available */
447#define POLL_OUT 2 /* output buffers available */
448#define POLL_MSG 3 /* input message available */
449#define POLL_ERR 4 /* i/o error */
450#define POLL_PRI 5 /* high priority input available */
451#define POLL_HUP 6 /* device disconnected */
452#define SI_USER 0 /* sent by kill, sigsend, raise */
453#define SI_QUEUE -1 /* sent by sigqueue */
454#define SI_TIMER -2 /* sent by timer expiration */
455#define SI_MESGQ -3 /* sent by real time mesq state change */
456#define SI_ASYNCIO -4 /* sent by AIO completion */
Roland McGrath941b7402003-05-23 00:29:02 +0000457#define SI_SIGIO -5 /* Sent by SIGIO */
458#define SI_TKILL -6 /* Sent by tkill */
John Hughes58265892001-10-18 15:13:53 +0000459#endif
460
461#if __GLIBC_MINOR__ < 1
462/* Type for data associated with a signal. */
463typedef union sigval
464{
465 int sival_int;
466 void *sival_ptr;
467} sigval_t;
468
469# define __SI_MAX_SIZE 128
470# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
471
472typedef struct siginfo
473{
474 int si_signo; /* Signal number. */
475 int si_errno; /* If non-zero, an errno value associated with
476 this signal, as defined in <errno.h>. */
477 int si_code; /* Signal code. */
478
479 union
480 {
481 int _pad[__SI_PAD_SIZE];
482
483 /* kill(). */
484 struct
485 {
486 __pid_t si_pid; /* Sending process ID. */
487 __uid_t si_uid; /* Real user ID of sending process. */
488 } _kill;
489
490 /* POSIX.1b timers. */
491 struct
492 {
493 unsigned int _timer1;
494 unsigned int _timer2;
495 } _timer;
496
497 /* POSIX.1b signals. */
498 struct
499 {
500 __pid_t si_pid; /* Sending process ID. */
501 __uid_t si_uid; /* Real user ID of sending process. */
502 sigval_t si_sigval; /* Signal value. */
503 } _rt;
504
505 /* SIGCHLD. */
506 struct
507 {
508 __pid_t si_pid; /* Which child. */
509 int si_status; /* Exit value or signal. */
510 __clock_t si_utime;
511 __clock_t si_stime;
512 } _sigchld;
513
514 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
515 struct
516 {
517 void *si_addr; /* Faulting insn/memory ref. */
518 } _sigfault;
519
520 /* SIGPOLL. */
521 struct
522 {
523 int si_band; /* Band event for SIGPOLL. */
524 int si_fd;
525 } _sigpoll;
526 } _sifields;
527} siginfo_t;
528
529#define si_pid _sifields._kill.si_pid
530#define si_uid _sifields._kill.si_uid
531#define si_status _sifields._sigchld.si_status
532#define si_utime _sifields._sigchld.si_utime
533#define si_stime _sifields._sigchld.si_stime
534#define si_value _sifields._rt.si_sigval
535#define si_int _sifields._rt.si_sigval.sival_int
536#define si_ptr _sifields._rt.si_sigval.sival_ptr
537#define si_addr _sifields._sigfault.si_addr
538#define si_band _sifields._sigpoll.si_band
539#define si_fd _sifields._sigpoll.si_fd
540
541#endif
542
543#endif
544
545#if defined (SVR4) || defined (LINUX)
546
Roland McGrathd9f816f2004-09-04 03:39:20 +0000547static const struct xlat siginfo_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000548#ifdef SI_NOINFO
549 { SI_NOINFO, "SI_NOINFO" },
550#endif
551#ifdef SI_USER
552 { SI_USER, "SI_USER" },
553#endif
554#ifdef SI_LWP
555 { SI_LWP, "SI_LWP" },
556#endif
557#ifdef SI_QUEUE
558 { SI_QUEUE, "SI_QUEUE" },
559#endif
560#ifdef SI_TIMER
561 { SI_TIMER, "SI_TIMER" },
562#endif
563#ifdef SI_ASYNCIO
564 { SI_ASYNCIO, "SI_ASYNCIO" },
565#endif
566#ifdef SI_MESGQ
567 { SI_MESGQ, "SI_MESGQ" },
568#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000569#ifdef SI_SIGIO
570 { SI_SIGIO, "SI_SIGIO" },
571#endif
572#ifdef SI_TKILL
573 { SI_TKILL, "SI_TKILL" },
574#endif
John Hughes58265892001-10-18 15:13:53 +0000575 { 0, NULL },
576};
577
Roland McGrathd9f816f2004-09-04 03:39:20 +0000578static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000579 { ILL_ILLOPC, "ILL_ILLOPC" },
580 { ILL_ILLOPN, "ILL_ILLOPN" },
581 { ILL_ILLADR, "ILL_ILLADR" },
582 { ILL_ILLTRP, "ILL_ILLTRP" },
583 { ILL_PRVOPC, "ILL_PRVOPC" },
584 { ILL_PRVREG, "ILL_PRVREG" },
585 { ILL_COPROC, "ILL_COPROC" },
586 { ILL_BADSTK, "ILL_BADSTK" },
587 { 0, NULL },
588};
589
Roland McGrathd9f816f2004-09-04 03:39:20 +0000590static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000591 { FPE_INTDIV, "FPE_INTDIV" },
592 { FPE_INTOVF, "FPE_INTOVF" },
593 { FPE_FLTDIV, "FPE_FLTDIV" },
594 { FPE_FLTOVF, "FPE_FLTOVF" },
595 { FPE_FLTUND, "FPE_FLTUND" },
596 { FPE_FLTRES, "FPE_FLTRES" },
597 { FPE_FLTINV, "FPE_FLTINV" },
598 { FPE_FLTSUB, "FPE_FLTSUB" },
599 { 0, NULL },
600};
601
Roland McGrathd9f816f2004-09-04 03:39:20 +0000602static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000603 { TRAP_BRKPT, "TRAP_BRKPT" },
604 { TRAP_TRACE, "TRAP_TRACE" },
605 { 0, NULL },
606};
607
Roland McGrathd9f816f2004-09-04 03:39:20 +0000608static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000609 { CLD_EXITED, "CLD_EXITED" },
610 { CLD_KILLED, "CLD_KILLED" },
611 { CLD_DUMPED, "CLD_DUMPED" },
612 { CLD_TRAPPED, "CLD_TRAPPED" },
613 { CLD_STOPPED, "CLD_STOPPED" },
614 { CLD_CONTINUED,"CLD_CONTINUED" },
615 { 0, NULL },
616};
617
Roland McGrathd9f816f2004-09-04 03:39:20 +0000618static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000619 { POLL_IN, "POLL_IN" },
620 { POLL_OUT, "POLL_OUT" },
621 { POLL_MSG, "POLL_MSG" },
622 { POLL_ERR, "POLL_ERR" },
623 { POLL_PRI, "POLL_PRI" },
624 { POLL_HUP, "POLL_HUP" },
625 { 0, NULL },
626};
627
Roland McGrathd9f816f2004-09-04 03:39:20 +0000628static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000629#ifdef PROF_SIG
630 { PROF_SIG, "PROF_SIG" },
631#endif
632 { 0, NULL },
633};
634
635#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000636static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000637#ifdef EMT_TAGOVF
638 { EMT_TAGOVF, "EMT_TAGOVF" },
639#endif
640 { 0, NULL },
641};
642#endif
643
Roland McGrathd9f816f2004-09-04 03:39:20 +0000644static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000645 { SEGV_MAPERR, "SEGV_MAPERR" },
646 { SEGV_ACCERR, "SEGV_ACCERR" },
647 { 0, NULL },
648};
649
Roland McGrathd9f816f2004-09-04 03:39:20 +0000650static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000651 { BUS_ADRALN, "BUS_ADRALN" },
652 { BUS_ADRERR, "BUS_ADRERR" },
653 { BUS_OBJERR, "BUS_OBJERR" },
654 { 0, NULL },
655};
656
657void
658printsiginfo(sip, verbose)
659siginfo_t *sip;
660int verbose;
661{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000662 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000663
664 if (sip->si_signo == 0) {
665 tprintf ("{}");
666 return;
667 }
668 tprintf("{si_signo=");
669 printsignal(sip->si_signo);
670 code = xlookup(siginfo_codes, sip->si_code);
671 if (!code) {
672 switch (sip->si_signo) {
673 case SIGTRAP:
674 code = xlookup(sigtrap_codes, sip->si_code);
675 break;
676 case SIGCHLD:
677 code = xlookup(sigchld_codes, sip->si_code);
678 break;
679 case SIGPOLL:
680 code = xlookup(sigpoll_codes, sip->si_code);
681 break;
682 case SIGPROF:
683 code = xlookup(sigprof_codes, sip->si_code);
684 break;
685 case SIGILL:
686 code = xlookup(sigill_codes, sip->si_code);
687 break;
688#ifdef SIGEMT
689 case SIGEMT:
690 code = xlookup(sigemt_codes, sip->si_code);
691 break;
692#endif
693 case SIGFPE:
694 code = xlookup(sigfpe_codes, sip->si_code);
695 break;
696 case SIGSEGV:
697 code = xlookup(sigsegv_codes, sip->si_code);
698 break;
699 case SIGBUS:
700 code = xlookup(sigbus_codes, sip->si_code);
701 break;
702 }
703 }
704 if (code)
705 tprintf(", si_code=%s", code);
706 else
707 tprintf(", si_code=%#x", sip->si_code);
708#ifdef SI_NOINFO
709 if (sip->si_code != SI_NOINFO)
710#endif
711 {
712 if (sip->si_errno) {
713 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
714 tprintf(", si_errno=%d", sip->si_errno);
715 else
716 tprintf(", si_errno=%s",
717 errnoent[sip->si_errno]);
718 }
719#ifdef SI_FROMUSER
720 if (SI_FROMUSER(sip)) {
721 tprintf(", si_pid=%ld, si_uid=%ld",
722 sip->si_pid, sip->si_uid);
723#ifdef SI_QUEUE
724 switch (sip->si_code) {
725 case SI_QUEUE:
726#ifdef SI_TIMER
727 case SI_TIMER:
728#endif /* SI_QUEUE */
729 case SI_ASYNCIO:
730#ifdef SI_MESGQ
731 case SI_MESGQ:
732#endif /* SI_MESGQ */
733 tprintf(", si_value=%d",
734 sip->si_value.sival_int);
735 break;
736 }
737#endif /* SI_QUEUE */
738 }
739 else
740#endif /* SI_FROMUSER */
741 {
742 switch (sip->si_signo) {
743 case SIGCHLD:
744 tprintf(", si_pid=%ld, si_status=",
745 (long) sip->si_pid);
746 if (sip->si_code == CLD_EXITED)
747 tprintf("%d", sip->si_status);
748 else
749 printsignal(sip->si_status);
750#if LINUX
751 if (!verbose)
752 tprintf(", ...");
753 else
754 tprintf(", si_utime=%lu, si_stime=%lu",
755 sip->si_utime,
756 sip->si_stime);
757#endif
758 break;
759 case SIGILL: case SIGFPE:
760 case SIGSEGV: case SIGBUS:
761 tprintf(", si_addr=%#lx",
762 (unsigned long) sip->si_addr);
763 break;
764 case SIGPOLL:
765 switch (sip->si_code) {
766 case POLL_IN: case POLL_OUT: case POLL_MSG:
767 tprintf(", si_band=%ld",
768 (long) sip->si_band);
769 break;
770 }
771 break;
772#ifdef LINUX
773 default:
774 tprintf(", si_pid=%lu, si_uid=%lu, ",
775 (unsigned long) sip->si_pid,
776 (unsigned long) sip->si_uid);
777 if (!verbose)
778 tprintf("...");
779 else {
780 tprintf("si_value={int=%u, ptr=%#lx}",
781 sip->si_int,
782 (unsigned long) sip->si_ptr);
783 }
784#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000785
John Hughes58265892001-10-18 15:13:53 +0000786 }
787 }
788 }
789 tprintf("}");
790}
791
792#endif /* SVR4 || LINUX */
793
794#ifdef LINUX
795
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000796static void
797parse_sigset_t (const char *str, sigset_t *set)
798{
Roland McGrathc38feca2003-10-01 07:50:28 +0000799 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000800 unsigned int digit;
801 int i;
802
803 sigemptyset(set);
804
Roland McGrathc38feca2003-10-01 07:50:28 +0000805 p = strchr(str, '\n');
806 if (p == NULL)
807 p = strchr(str, '\0');
808 for (i = 0; p-- > str; i += 4) {
809 if (*p >= '0' && *p <= '9')
810 digit = *p - '0';
811 else if (*p >= 'a' && *p <= 'f')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000812 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000813 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000814 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000815 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000816 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000817 if (digit & 1)
818 sigaddset(set, i + 1);
819 if (digit & 2)
820 sigaddset(set, i + 2);
821 if (digit & 4)
822 sigaddset(set, i + 3);
823 if (digit & 8)
824 sigaddset(set, i + 4);
825 }
826}
827
828#endif
829
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000830/*
831 * Check process TCP for the disposition of signal SIG.
832 * Return 1 if the process would somehow manage to survive signal SIG,
833 * else return 0. This routine will never be called with SIGKILL.
834 */
835int
836sigishandled(tcp, sig)
837struct tcb *tcp;
838int sig;
839{
840#ifdef LINUX
841 int sfd;
842 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000843 char buf[2048];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000844 char *s;
845 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000846 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000848#ifdef SVR4
849 /*
850 * Since procfs doesn't interfere with wait I think it is safe
851 * to punt on this question. If not, the information is there.
852 */
853 return 1;
854#else /* !SVR4 */
855 switch (sig) {
856 case SIGCONT:
857 case SIGSTOP:
858 case SIGTSTP:
859 case SIGTTIN:
860 case SIGTTOU:
861 case SIGCHLD:
862 case SIGIO:
863#if defined(SIGURG) && SIGURG != SIGIO
864 case SIGURG:
865#endif
866 case SIGWINCH:
867 /* Gloria Gaynor says ... */
868 return 1;
869 default:
870 break;
871 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000872#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000873#ifdef LINUX
874
875 /* This is incredibly costly but it's worth it. */
876 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
877 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
878 doesn't handle real-time signals). */
879 sprintf(sname, "/proc/%d/status", tcp->pid);
880 if ((sfd = open(sname, O_RDONLY)) == -1) {
881 perror(sname);
882 return 1;
883 }
884 i = read(sfd, buf, sizeof(buf));
885 buf[i] = '\0';
886 close(sfd);
887 /*
888 * Skip the extraneous fields. We need to skip
889 * command name has any spaces in it. So be it.
890 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000891 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000892 if (!s)
893 {
894 fprintf(stderr, "/proc/pid/status format error\n");
895 return 1;
896 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000897 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000898
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000899 s = strstr(buf, "SigCgt:\t");
900 if (!s)
901 {
902 fprintf(stderr, "/proc/pid/status format error\n");
903 return 1;
904 }
905 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000906
907#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000908 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
909 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000910#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000911 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000912 return 1;
913#endif /* LINUX */
914
915#ifdef SUNOS4
916 void (*u_signal)();
917
918 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
919 (long *) &u_signal) < 0) {
920 return 0;
921 }
922 if (u_signal != SIG_DFL)
923 return 1;
924#endif /* SUNOS4 */
925
926 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927}
928
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000929#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000930
931int
932sys_sigvec(tcp)
933struct tcb *tcp;
934{
935 struct sigvec sv;
936 long addr;
937
938 if (entering(tcp)) {
939 printsignal(tcp->u_arg[0]);
940 tprintf(", ");
941 addr = tcp->u_arg[1];
942 } else {
943 addr = tcp->u_arg[2];
944 }
945 if (addr == 0)
946 tprintf("NULL");
947 else if (!verbose(tcp))
948 tprintf("%#lx", addr);
949 else if (umove(tcp, addr, &sv) < 0)
950 tprintf("{...}");
951 else {
952 switch ((int) sv.sv_handler) {
953 case (int) SIG_ERR:
954 tprintf("{SIG_ERR}");
955 break;
956 case (int) SIG_DFL:
957 tprintf("{SIG_DFL}");
958 break;
959 case (int) SIG_IGN:
960 if (tcp->u_arg[0] == SIGTRAP) {
961 tcp->flags |= TCB_SIGTRAPPED;
962 kill(tcp->pid, SIGSTOP);
963 }
964 tprintf("{SIG_IGN}");
965 break;
966 case (int) SIG_HOLD:
967 if (tcp->u_arg[0] == SIGTRAP) {
968 tcp->flags |= TCB_SIGTRAPPED;
969 kill(tcp->pid, SIGSTOP);
970 }
971 tprintf("SIG_HOLD");
972 break;
973 default:
974 if (tcp->u_arg[0] == SIGTRAP) {
975 tcp->flags |= TCB_SIGTRAPPED;
976 kill(tcp->pid, SIGSTOP);
977 }
978 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000979 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000980 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000981 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982 tprintf("}");
983 }
984 }
985 if (entering(tcp))
986 tprintf(", ");
987 return 0;
988}
989
990int
991sys_sigpause(tcp)
992struct tcb *tcp;
993{
994 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000995 sigset_t sigm;
996 long_to_sigset(tcp->u_arg[0], &sigm);
997 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000998 }
999 return 0;
1000}
1001
1002int
1003sys_sigstack(tcp)
1004struct tcb *tcp;
1005{
1006 struct sigstack ss;
1007 long addr;
1008
1009 if (entering(tcp))
1010 addr = tcp->u_arg[0];
1011 else
1012 addr = tcp->u_arg[1];
1013 if (addr == 0)
1014 tprintf("NULL");
1015 else if (umove(tcp, addr, &ss) < 0)
1016 tprintf("%#lx", addr);
1017 else {
1018 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1019 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1020 }
1021 if (entering(tcp))
1022 tprintf(", ");
1023 return 0;
1024}
1025
1026int
1027sys_sigcleanup(tcp)
1028struct tcb *tcp;
1029{
1030 return 0;
1031}
1032
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001033#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034
1035#ifndef SVR4
1036
1037int
1038sys_sigsetmask(tcp)
1039struct tcb *tcp;
1040{
1041 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001042 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001043 long_to_sigset(tcp->u_arg[0], &sigm);
1044 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001045#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001046 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1047 /* Mark attempt to block SIGTRAP */
1048 tcp->flags |= TCB_SIGTRAPPED;
1049 /* Send unblockable signal */
1050 kill(tcp->pid, SIGSTOP);
1051 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001052#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001053 }
1054 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001055 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001056 long_to_sigset(tcp->u_rval, &sigm);
1057 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001058
1059 return RVAL_HEX | RVAL_STR;
1060 }
1061 return 0;
1062}
1063
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001064#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001065int
1066sys_sigblock(tcp)
1067struct tcb *tcp;
1068{
1069 return sys_sigsetmask(tcp);
1070}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001071#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072
1073#endif /* !SVR4 */
1074
1075#ifdef HAVE_SIGACTION
1076
1077#ifdef LINUX
1078struct old_sigaction {
1079 __sighandler_t __sa_handler;
1080 unsigned long sa_mask;
1081 unsigned long sa_flags;
1082 void (*sa_restorer)(void);
1083};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001084#define SA_HANDLER __sa_handler
1085#endif /* LINUX */
1086
Roland McGratha39c5a12002-12-17 05:10:37 +00001087#ifndef SA_HANDLER
1088#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001089#endif
1090
1091int
1092sys_sigaction(tcp)
1093struct tcb *tcp;
1094{
1095 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001096#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001097 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001098 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099#else
1100 struct sigaction sa;
1101#endif
1102
1103
1104 if (entering(tcp)) {
1105 printsignal(tcp->u_arg[0]);
1106 tprintf(", ");
1107 addr = tcp->u_arg[1];
1108 } else
1109 addr = tcp->u_arg[2];
1110 if (addr == 0)
1111 tprintf("NULL");
1112 else if (!verbose(tcp))
1113 tprintf("%#lx", addr);
1114 else if (umove(tcp, addr, &sa) < 0)
1115 tprintf("{...}");
1116 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001117 switch ((long) sa.SA_HANDLER) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001118 case (long) SIG_ERR:
1119 tprintf("{SIG_ERR}");
1120 break;
1121 case (long) SIG_DFL:
1122 tprintf("{SIG_DFL}");
1123 break;
1124 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001125#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126 if (tcp->u_arg[0] == SIGTRAP) {
1127 tcp->flags |= TCB_SIGTRAPPED;
1128 kill(tcp->pid, SIGSTOP);
1129 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001130#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001131 tprintf("{SIG_IGN}");
1132 break;
1133 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001134#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001135 if (tcp->u_arg[0] == SIGTRAP) {
1136 tcp->flags |= TCB_SIGTRAPPED;
1137 kill(tcp->pid, SIGSTOP);
1138 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001139#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001140 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001141#ifndef LINUX
1142 printsigmask (&sa.sa_mask, 0);
1143#else
Nate Sammons4a121431999-04-06 01:19:39 +00001144 long_to_sigset(sa.sa_mask, &sigset);
1145 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001146#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001147 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001148 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001149#ifdef SA_RESTORER
1150 if (sa.sa_flags & SA_RESTORER)
1151 tprintf(", %p", sa.sa_restorer);
1152#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001153 tprintf("}");
1154 }
1155 }
1156 if (entering(tcp))
1157 tprintf(", ");
1158#ifdef LINUX
1159 else
1160 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1161#endif
1162 return 0;
1163}
1164
1165int
1166sys_signal(tcp)
1167struct tcb *tcp;
1168{
1169 if (entering(tcp)) {
1170 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001171 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001172 switch (tcp->u_arg[1]) {
1173 case (int) SIG_ERR:
1174 tprintf("SIG_ERR");
1175 break;
1176 case (int) SIG_DFL:
1177 tprintf("SIG_DFL");
1178 break;
1179 case (int) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001180#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001181 if (tcp->u_arg[0] == SIGTRAP) {
1182 tcp->flags |= TCB_SIGTRAPPED;
1183 kill(tcp->pid, SIGSTOP);
1184 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001185#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001186 tprintf("SIG_IGN");
1187 break;
1188 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001189#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001190 if (tcp->u_arg[0] == SIGTRAP) {
1191 tcp->flags |= TCB_SIGTRAPPED;
1192 kill(tcp->pid, SIGSTOP);
1193 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001194#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001195 tprintf("%#lx", tcp->u_arg[1]);
1196 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001197 return 0;
1198 }
1199 else {
1200 switch (tcp->u_rval) {
1201 case (int) SIG_ERR:
1202 tcp->auxstr = "SIG_ERR"; break;
1203 case (int) SIG_DFL:
1204 tcp->auxstr = "SIG_DFL"; break;
1205 case (int) SIG_IGN:
1206 tcp->auxstr = "SIG_IGN"; break;
1207 default:
1208 tcp->auxstr = NULL;
1209 }
1210 return RVAL_HEX | RVAL_STR;
1211 }
1212}
1213
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001214#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001215int
1216sys_sighold(tcp)
1217struct tcb *tcp;
1218{
1219 if (entering(tcp)) {
1220 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221 }
1222 return 0;
1223}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001224#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001225
1226#endif /* HAVE_SIGACTION */
1227
1228#ifdef LINUX
1229
1230int
1231sys_sigreturn(tcp)
1232struct tcb *tcp;
1233{
Roland McGrath0f87c492003-06-03 23:29:04 +00001234#ifdef ARM
1235 struct pt_regs regs;
1236 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001237
Roland McGrath0f87c492003-06-03 23:29:04 +00001238 if (entering(tcp)) {
1239 tcp->u_arg[0] = 0;
1240
1241 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1242 return 0;
1243
1244 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1245 return 0;
1246
1247 tcp->u_arg[0] = 1;
1248 tcp->u_arg[1] = sc.oldmask;
1249 } else {
1250 sigset_t sigm;
1251 long_to_sigset(tcp->u_arg[1], &sigm);
1252 tcp->u_rval = tcp->u_error = 0;
1253 if (tcp->u_arg[0] == 0)
1254 return 0;
1255 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1256 return RVAL_NONE | RVAL_STR;
1257 }
1258 return 0;
1259#elif defined(S390) || defined(S390X)
1260 long usp;
1261 struct sigcontext_struct sc;
1262
1263 if (entering(tcp)) {
1264 tcp->u_arg[0] = 0;
1265 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1266 return 0;
1267 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1268 return 0;
1269 tcp->u_arg[0] = 1;
1270 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1271 } else {
1272 tcp->u_rval = tcp->u_error = 0;
1273 if (tcp->u_arg[0] == 0)
1274 return 0;
1275 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1276 return RVAL_NONE | RVAL_STR;
1277 }
1278 return 0;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001279#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001280#ifdef I386
1281 long esp;
1282 struct sigcontext_struct sc;
1283
1284 if (entering(tcp)) {
1285 tcp->u_arg[0] = 0;
1286 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1287 return 0;
1288 if (umove(tcp, esp, &sc) < 0)
1289 return 0;
1290 tcp->u_arg[0] = 1;
1291 tcp->u_arg[1] = sc.oldmask;
1292 }
1293 else {
1294 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001295 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296 tcp->u_rval = tcp->u_error = 0;
1297 if (tcp->u_arg[0] == 0)
1298 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001299 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001300 return RVAL_NONE | RVAL_STR;
1301 }
1302 return 0;
1303#else /* !I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001304#ifdef IA64
1305 struct sigcontext sc;
1306 long sp;
1307
1308 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001309 /* offset of sigcontext in the kernel's sigframe structure: */
1310# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001311 tcp->u_arg[0] = 0;
1312 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1313 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001314 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001315 return 0;
1316 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001317 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001318 }
1319 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001320 sigset_t sigm;
1321
1322 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001323 tcp->u_rval = tcp->u_error = 0;
1324 if (tcp->u_arg[0] == 0)
1325 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001326 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001327 return RVAL_NONE | RVAL_STR;
1328 }
1329 return 0;
1330#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001331#ifdef POWERPC
Roland McGrath0f87c492003-06-03 23:29:04 +00001332 long esp;
1333 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334
Roland McGrath0f87c492003-06-03 23:29:04 +00001335 if (entering(tcp)) {
1336 tcp->u_arg[0] = 0;
1337 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1338 return 0;
1339 if (umove(tcp, esp, &sc) < 0)
1340 return 0;
1341 tcp->u_arg[0] = 1;
1342 tcp->u_arg[1] = sc.oldmask;
1343 }
1344 else {
1345 sigset_t sigm;
1346 long_to_sigset(tcp->u_arg[1], &sigm);
1347 tcp->u_rval = tcp->u_error = 0;
1348 if (tcp->u_arg[0] == 0)
1349 return 0;
1350 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1351 return RVAL_NONE | RVAL_STR;
1352 }
1353 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001354#else /* !POWERPC */
1355#ifdef M68K
1356 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;
1361 if (upeek(tcp->pid, 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;
1378#else /* !M68K */
1379#ifdef ALPHA
1380 long fp;
1381 struct sigcontext_struct sc;
1382
1383 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001384 tcp->u_arg[0] = 0;
1385 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001386 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001387 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001388 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001389 tcp->u_arg[0] = 1;
1390 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001391 }
1392 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001393 sigset_t sigm;
1394 long_to_sigset(tcp->u_arg[1], &sigm);
1395 tcp->u_rval = tcp->u_error = 0;
1396 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001397 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001398 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1399 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001400 }
1401 return 0;
1402#else
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001403#if defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001404 long i1;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001405 struct regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001406 m_siginfo_t si;
1407
1408 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001409 perror("sigreturn: PTRACE_GETREGS ");
1410 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001411 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001412 if(entering(tcp)) {
1413 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001414 i1 = regs.r_o1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001415 if(umove(tcp, i1, &si) < 0) {
1416 perror("sigreturn: umove ");
1417 return 0;
1418 }
1419 tcp->u_arg[0] = 1;
1420 tcp->u_arg[1] = si.si_mask;
1421 } else {
1422 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001423 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424 tcp->u_rval = tcp->u_error = 0;
1425 if(tcp->u_arg[0] == 0)
1426 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001427 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001428 return RVAL_NONE | RVAL_STR;
1429 }
1430 return 0;
Roland McGratha39c5a12002-12-17 05:10:37 +00001431#else
Roland McGrath542c2c62008-05-20 01:11:56 +00001432#if defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
1433 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1434 sigreturn. */
1435 long sp;
1436 struct ucontext uc;
1437
1438 if(entering(tcp)) {
1439 tcp->u_arg[0] = 0;
1440 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1441 return 0;
1442 /* There are six words followed by a 128-byte siginfo. */
1443 sp = sp + 6 * 4 + 128;
1444 if (umove(tcp, sp, &uc) < 0)
1445 return 0;
1446 tcp->u_arg[0] = 1;
1447 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1448 } else {
1449 sigset_t sigm;
1450 long_to_sigset(tcp->u_arg[1], &sigm);
1451 tcp->u_rval = tcp->u_error = 0;
1452 if(tcp->u_arg[0] == 0)
1453 return 0;
1454 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1455 return RVAL_NONE | RVAL_STR;
1456 }
1457 return 0;
1458#else
Wichert Akkermanf90da011999-10-31 21:15:38 +00001459#ifdef MIPS
1460 long sp;
Roland McGrath576b7842007-11-04 00:00:00 +00001461 struct pt_regs regs;
1462 m_siginfo_t si;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001463
Roland McGrath576b7842007-11-04 00:00:00 +00001464 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1465 perror("sigreturn: PTRACE_GETREGS ");
1466 return 0;
1467 }
Wichert Akkermanf90da011999-10-31 21:15:38 +00001468 if(entering(tcp)) {
1469 tcp->u_arg[0] = 0;
Roland McGrath576b7842007-11-04 00:00:00 +00001470 sp = regs.regs[29];
1471 if (umove(tcp, sp, &si) < 0)
Wichert Akkermanf90da011999-10-31 21:15:38 +00001472 tcp->u_arg[0] = 1;
Roland McGrath576b7842007-11-04 00:00:00 +00001473 tcp->u_arg[1] = si.si_mask;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001474 } else {
Roland McGrath576b7842007-11-04 00:00:00 +00001475 sigset_t sigm;
1476 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001477 tcp->u_rval = tcp->u_error = 0;
1478 if(tcp->u_arg[0] == 0)
Roland McGrath576b7842007-11-04 00:00:00 +00001479 return 0;
1480 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkermanf90da011999-10-31 21:15:38 +00001481 return RVAL_NONE | RVAL_STR;
1482 }
1483 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001484#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001485#warning No sys_sigreturn() for this architecture
1486#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001487 return 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001488#endif /* MIPS */
Roland McGrath542c2c62008-05-20 01:11:56 +00001489#endif /* LINUX_MIPSN32 || LINUX_MIPSN64 */
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001490#endif /* SPARC || SPARC64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001491#endif /* ALPHA */
1492#endif /* !M68K */
1493#endif /* !POWERPC */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001494#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001495#endif /* !I386 */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001496#endif /* S390 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001497}
1498
1499int
1500sys_siggetmask(tcp)
1501struct tcb *tcp;
1502{
1503 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001504 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001505 long_to_sigset(tcp->u_rval, &sigm);
1506 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001507 }
1508 return RVAL_HEX | RVAL_STR;
1509}
1510
1511int
1512sys_sigsuspend(tcp)
1513struct tcb *tcp;
1514{
1515 if (entering(tcp)) {
1516 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001517 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001518#if 0
1519 /* first two are not really arguments, but print them anyway */
1520 /* nevermind, they are an anachronism now, too bad... */
1521 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1522#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001523 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001524 }
1525 return 0;
1526}
1527
1528#endif /* LINUX */
1529
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001530#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001531
1532int
1533sys_sigsuspend(tcp)
1534struct tcb *tcp;
1535{
1536 sigset_t sigset;
1537
1538 if (entering(tcp)) {
1539 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1540 tprintf("[?]");
1541 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001542 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001543 }
1544 return 0;
1545}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001546#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001547static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001548 { UC_SIGMASK, "UC_SIGMASK" },
1549 { UC_STACK, "UC_STACK" },
1550 { UC_CPU, "UC_CPU" },
1551#ifdef UC_FPU
1552 { UC_FPU, "UC_FPU" },
1553#endif
1554#ifdef UC_INTR
1555 { UC_INTR, "UC_INTR" },
1556#endif
1557 { 0, NULL },
1558};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001559#endif /* !FREEBSD */
1560#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001561
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001562#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001563#if defined LINUX && !defined SS_ONSTACK
1564#define SS_ONSTACK 1
1565#define SS_DISABLE 2
1566#if __GLIBC_MINOR__ == 0
1567typedef struct
1568{
1569 __ptr_t ss_sp;
1570 int ss_flags;
1571 size_t ss_size;
1572} stack_t;
1573#endif
1574#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001575#ifdef FREEBSD
1576#define stack_t struct sigaltstack
1577#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001578
Roland McGrathd9f816f2004-09-04 03:39:20 +00001579static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001580 { SS_ONSTACK, "SS_ONSTACK" },
1581 { SS_DISABLE, "SS_DISABLE" },
1582 { 0, NULL },
1583};
1584#endif
1585
1586#ifdef SVR4
1587static void
1588printcontext(tcp, ucp)
1589struct tcb *tcp;
1590ucontext_t *ucp;
1591{
1592 tprintf("{");
1593 if (!abbrev(tcp)) {
1594 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001595 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001596 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1597 }
1598 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001599 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001600 if (!abbrev(tcp)) {
1601 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1602 (unsigned long) ucp->uc_stack.ss_sp,
1603 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001604 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001605 tprintf("}");
1606 }
1607 tprintf(", ...}");
1608}
1609
1610int
1611sys_getcontext(tcp)
1612struct tcb *tcp;
1613{
1614 ucontext_t uc;
1615
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001616 if (exiting(tcp)) {
1617 if (tcp->u_error)
1618 tprintf("%#lx", tcp->u_arg[0]);
1619 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001620 tprintf("NULL");
1621 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1622 tprintf("{...}");
1623 else
1624 printcontext(tcp, &uc);
1625 }
1626 return 0;
1627}
1628
1629int
1630sys_setcontext(tcp)
1631struct tcb *tcp;
1632{
1633 ucontext_t uc;
1634
1635 if (entering(tcp)) {
1636 if (!tcp->u_arg[0])
1637 tprintf("NULL");
1638 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1639 tprintf("{...}");
1640 else
1641 printcontext(tcp, &uc);
1642 }
1643 else {
1644 tcp->u_rval = tcp->u_error = 0;
1645 if (tcp->u_arg[0] == 0)
1646 return 0;
1647 return RVAL_NONE;
1648 }
1649 return 0;
1650}
1651
1652#endif /* SVR4 */
1653
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001654#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001655
1656static int
1657print_stack_t(tcp, addr)
1658struct tcb *tcp;
1659unsigned long addr;
1660{
1661 stack_t ss;
1662 if (umove(tcp, addr, &ss) < 0)
1663 return -1;
1664 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001665 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001666 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1667 return 0;
1668}
1669
1670int
1671sys_sigaltstack(tcp)
1672 struct tcb *tcp;
1673{
1674 if (entering(tcp)) {
1675 if (tcp->u_arg[0] == 0)
1676 tprintf("NULL");
1677 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1678 return -1;
1679 }
1680 else {
1681 tprintf(", ");
1682 if (tcp->u_arg[1] == 0)
1683 tprintf("NULL");
1684 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1685 return -1;
1686 }
1687 return 0;
1688}
1689#endif
1690
1691#ifdef HAVE_SIGACTION
1692
1693int
1694sys_sigprocmask(tcp)
1695struct tcb *tcp;
1696{
1697#ifdef ALPHA
1698 if (entering(tcp)) {
1699 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1700 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001701 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001702 }
1703 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001704 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001705 return RVAL_HEX | RVAL_STR;
1706 }
1707#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001708 if (entering(tcp)) {
1709#ifdef SVR4
1710 if (tcp->u_arg[0] == 0)
1711 tprintf("0");
1712 else
1713#endif /* SVR4 */
1714 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1715 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001716 print_sigset(tcp, tcp->u_arg[1], 0);
1717 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001718 }
1719 else {
1720 if (!tcp->u_arg[2])
1721 tprintf("NULL");
1722 else if (syserror(tcp))
1723 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001724 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001725 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001726 }
1727#endif /* !ALPHA */
1728 return 0;
1729}
1730
1731#endif /* HAVE_SIGACTION */
1732
1733int
1734sys_kill(tcp)
1735struct tcb *tcp;
1736{
1737 if (entering(tcp)) {
Nate Sammonsce780fc1999-03-29 23:23:13 +00001738 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001739 }
1740 return 0;
1741}
1742
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001743#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001744int
1745sys_killpg(tcp)
1746struct tcb *tcp;
1747{
1748 return sys_kill(tcp);
1749}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001750#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001751
Roland McGrath8ffc3522003-07-09 09:47:49 +00001752#ifdef LINUX
1753int
1754sys_tgkill(tcp)
1755 struct tcb *tcp;
1756{
1757 if (entering(tcp)) {
1758 tprintf("%ld, %ld, %s",
1759 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1760 }
1761 return 0;
1762}
1763#endif
1764
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001765int
1766sys_sigpending(tcp)
1767struct tcb *tcp;
1768{
1769 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001770
1771 if (exiting(tcp)) {
1772 if (syserror(tcp))
1773 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001774 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001775 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001776 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001777 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001778 }
1779 return 0;
1780}
1781
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001782#ifdef SVR4
John Hughes42162082001-10-18 14:48:26 +00001783int sys_sigwait(tcp)
1784struct tcb *tcp;
1785{
1786 sigset_t sigset;
1787
1788 if (entering(tcp)) {
1789 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1790 tprintf("[?]");
1791 else
1792 printsigmask(&sigset, 0);
1793 }
1794 else {
1795 if (!syserror(tcp)) {
1796 tcp->auxstr = signalent[tcp->u_rval];
1797 return RVAL_DECIMAL | RVAL_STR;
1798 }
1799 }
1800 return 0;
1801}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001802#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001803
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001804#ifdef LINUX
1805
1806 int
1807sys_rt_sigprocmask(tcp)
1808 struct tcb *tcp;
1809{
1810 sigset_t sigset;
1811
Nate Sammons4a121431999-04-06 01:19:39 +00001812 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001813 if (entering(tcp)) {
1814 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1815 tprintf(", ");
1816 if (!tcp->u_arg[1])
1817 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001818 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001819 tprintf("%#lx, ", tcp->u_arg[1]);
1820 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001821 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001822 tprintf(", ");
1823 }
1824 }
1825 else {
1826 if (!tcp->u_arg[2])
1827
1828 tprintf("NULL");
1829 else if (syserror(tcp))
1830 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001831 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001832 tprintf("[?]");
1833 else
Nate Sammons4a121431999-04-06 01:19:39 +00001834 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001835 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001836 }
1837 return 0;
1838}
1839
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001840
1841/* Structure describing the action to be taken when a signal arrives. */
1842struct new_sigaction
1843{
1844 union
1845 {
1846 __sighandler_t __sa_handler;
1847 void (*__sa_sigaction) (int, siginfo_t *, void *);
1848 }
1849 __sigaction_handler;
1850 unsigned long sa_flags;
1851 void (*sa_restorer) (void);
1852 unsigned long int sa_mask[2];
1853};
1854
1855
1856 int
1857sys_rt_sigaction(tcp)
1858 struct tcb *tcp;
1859{
1860 struct new_sigaction sa;
1861 sigset_t sigset;
1862 long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001863
1864 if (entering(tcp)) {
1865 printsignal(tcp->u_arg[0]);
1866 tprintf(", ");
1867 addr = tcp->u_arg[1];
1868 } else
1869 addr = tcp->u_arg[2];
1870 if (addr == 0)
1871 tprintf("NULL");
1872 else if (!verbose(tcp))
1873 tprintf("%#lx", addr);
1874 else if (umove(tcp, addr, &sa) < 0)
1875 tprintf("{...}");
1876 else {
1877 switch ((long) sa.__sigaction_handler.__sa_handler) {
1878 case (long) SIG_ERR:
1879 tprintf("{SIG_ERR}");
1880 break;
1881 case (long) SIG_DFL:
1882 tprintf("{SIG_DFL}");
1883 break;
1884 case (long) SIG_IGN:
1885 tprintf("{SIG_IGN}");
1886 break;
1887 default:
1888 tprintf("{%#lx, ",
1889 (long) sa.__sigaction_handler.__sa_handler);
Nate Sammons4a121431999-04-06 01:19:39 +00001890 sigemptyset(&sigset);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001891#ifdef LINUXSPARC
1892 if (tcp->u_arg[4] <= sizeof(sigset))
1893 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1894#else
Nate Sammons4a121431999-04-06 01:19:39 +00001895 if (tcp->u_arg[3] <= sizeof(sigset))
1896 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001897#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001898 else
1899 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1900 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001901 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001902 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001903#ifdef SA_RESTORER
1904 if (sa.sa_flags & SA_RESTORER)
1905 tprintf(", %p", sa.sa_restorer);
1906#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001907 tprintf("}");
1908 }
1909 }
1910 if (entering(tcp))
1911 tprintf(", ");
1912 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001913#ifdef LINUXSPARC
1914 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1915#elif defined(ALPHA)
1916 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1917#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001918 tprintf(", %lu", addr = tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001919#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001920 return 0;
1921}
1922
1923 int
1924sys_rt_sigpending(tcp)
1925 struct tcb *tcp;
1926{
1927 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001928
1929 if (exiting(tcp)) {
1930 if (syserror(tcp))
1931 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001932 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1933 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001934 tprintf("[?]");
1935 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001936 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001937 }
1938 return 0;
1939}
1940 int
1941sys_rt_sigsuspend(tcp)
1942 struct tcb *tcp;
1943{
1944 if (entering(tcp)) {
1945 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001946 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1947 tprintf("[?]");
1948 else
1949 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001950 }
1951 return 0;
1952}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001953 int
1954sys_rt_sigqueueinfo(tcp)
1955 struct tcb *tcp;
1956{
1957 if (entering(tcp)) {
1958 siginfo_t si;
1959 tprintf("%lu, ", tcp->u_arg[0]);
1960 printsignal(tcp->u_arg[1]);
1961 tprintf(", ");
1962 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1963 tprintf("%#lx", tcp->u_arg[2]);
1964 else
John Hughes58265892001-10-18 15:13:53 +00001965 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001966 }
1967 return 0;
1968}
1969
1970int sys_rt_sigtimedwait(tcp)
1971 struct tcb *tcp;
1972{
1973 if (entering(tcp)) {
1974 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001975
Roland McGratha39c5a12002-12-17 05:10:37 +00001976 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00001977 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001978 tprintf("[?]");
1979 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001980 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001981 tprintf(", ");
1982 }
1983 else {
1984 if (syserror(tcp))
1985 tprintf("%#lx", tcp->u_arg[0]);
1986 else {
1987 siginfo_t si;
1988 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1989 tprintf("%#lx", tcp->u_arg[1]);
1990 else
John Hughes58265892001-10-18 15:13:53 +00001991 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001992 /* XXX For now */
1993 tprintf(", %#lx", tcp->u_arg[2]);
1994 tprintf(", %d", (int) tcp->u_arg[3]);
1995 }
1996 }
1997 return 0;
1998};
1999
Roland McGrath79dcd7a2006-01-12 22:34:50 +00002000int
2001sys_restart_syscall(tcp)
2002struct tcb *tcp;
2003{
2004 if (entering(tcp))
2005 tprintf("<... resuming interrupted call ...>");
2006 return 0;
2007}
2008
Roland McGrathf46ccd32007-08-02 01:15:59 +00002009int
2010sys_signalfd(tcp)
2011struct tcb *tcp;
2012{
2013 if (entering(tcp)) {
2014 tprintf("%ld, ", tcp->u_arg[0]);
2015 print_sigset(tcp, tcp->u_arg[1], 1);
2016 tprintf("%lu", tcp->u_arg[2]);
2017 }
2018 return 0;
2019}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002020#endif /* LINUX */