blob: fde89f28f19920e3a39e57c56fe6a8e0ae49587a [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 McGrath30ff45e2003-01-30 20:15:23 +0000100#elif defined HAVE_ASM_SIGCONTEXT_H
101#if !defined(IA64) && !defined(X86_64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000102#include <asm/sigcontext.h>
Roland McGrath30ff45e2003-01-30 20:15:23 +0000103#endif /* !IA64 && !X86_64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104#else /* !HAVE_ASM_SIGCONTEXT_H */
105#ifdef I386
106struct sigcontext_struct {
107 unsigned short gs, __gsh;
108 unsigned short fs, __fsh;
109 unsigned short es, __esh;
110 unsigned short ds, __dsh;
111 unsigned long edi;
112 unsigned long esi;
113 unsigned long ebp;
114 unsigned long esp;
115 unsigned long ebx;
116 unsigned long edx;
117 unsigned long ecx;
118 unsigned long eax;
119 unsigned long trapno;
120 unsigned long err;
121 unsigned long eip;
122 unsigned short cs, __csh;
123 unsigned long eflags;
124 unsigned long esp_at_signal;
125 unsigned short ss, __ssh;
126 unsigned long i387;
127 unsigned long oldmask;
128 unsigned long cr2;
129};
130#else /* !I386 */
131#ifdef M68K
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000132struct sigcontext
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133{
134 unsigned long sc_mask;
135 unsigned long sc_usp;
136 unsigned long sc_d0;
137 unsigned long sc_d1;
138 unsigned long sc_a0;
139 unsigned long sc_a1;
140 unsigned short sc_sr;
141 unsigned long sc_pc;
142 unsigned short sc_formatvec;
143};
144#endif /* M68K */
145#endif /* !I386 */
146#endif /* !HAVE_ASM_SIGCONTEXT_H */
147#ifndef NSIG
148#define NSIG 32
149#endif
150#ifdef ARM
151#undef NSIG
152#define NSIG 32
153#endif
154#endif /* LINUX */
155
Roland McGrathee36ce12004-09-04 03:53:10 +0000156const char *const signalent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157#include "signalent.h"
158};
Roland McGrathee36ce12004-09-04 03:53:10 +0000159const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160
161#if SUPPORTED_PERSONALITIES >= 2
Roland McGrathee36ce12004-09-04 03:53:10 +0000162const char *const signalent1[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163#include "signalent1.h"
164};
Roland McGrathee36ce12004-09-04 03:53:10 +0000165const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166#endif /* SUPPORTED_PERSONALITIES >= 2 */
167
168#if SUPPORTED_PERSONALITIES >= 3
Roland McGrathee36ce12004-09-04 03:53:10 +0000169const char *const signalent2[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000170#include "signalent2.h"
171};
Roland McGrathee36ce12004-09-04 03:53:10 +0000172const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000173#endif /* SUPPORTED_PERSONALITIES >= 3 */
174
Roland McGrathee36ce12004-09-04 03:53:10 +0000175const char *const *signalent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176int nsignals;
177
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000178#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179
Roland McGrathd9f816f2004-09-04 03:39:20 +0000180static const struct xlat sigvec_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181 { SV_ONSTACK, "SV_ONSTACK" },
182 { SV_INTERRUPT, "SV_INTERRUPT" },
183 { SV_RESETHAND, "SV_RESETHAND" },
184 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
185 { 0, NULL },
186};
187
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000188#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000189
190#ifdef HAVE_SIGACTION
191
Roland McGrath063ae2d2005-02-02 04:16:54 +0000192#if defined LINUX && (defined I386 || defined X86_64)
Roland McGrath2638cb42002-12-15 23:58:41 +0000193/* The libc headers do not define this constant since it should only be
194 used by the implementation. So wwe define it here. */
195# ifndef SA_RESTORER
196# define SA_RESTORER 0x04000000
197# endif
198#endif
199
Roland McGrathd9f816f2004-09-04 03:39:20 +0000200static const struct xlat sigact_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000201#ifdef SA_RESTORER
202 { SA_RESTORER, "SA_RESTORER" },
203#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204#ifdef SA_STACK
205 { SA_STACK, "SA_STACK" },
206#endif
207#ifdef SA_RESTART
208 { SA_RESTART, "SA_RESTART" },
209#endif
210#ifdef SA_INTERRUPT
211 { SA_INTERRUPT, "SA_INTERRUPT" },
212#endif
213#ifdef SA_NOMASK
214 { SA_NOMASK, "SA_NOMASK" },
215#endif
216#ifdef SA_ONESHOT
217 { SA_ONESHOT, "SA_ONESHOT" },
218#endif
219#ifdef SA_SIGINFO
220 { SA_SIGINFO, "SA_SIGINFO" },
221#endif
222#ifdef SA_RESETHAND
223 { SA_RESETHAND, "SA_RESETHAND" },
224#endif
225#ifdef SA_ONSTACK
226 { SA_ONSTACK, "SA_ONSTACK" },
227#endif
228#ifdef SA_NODEFER
229 { SA_NODEFER, "SA_NODEFER" },
230#endif
231#ifdef SA_NOCLDSTOP
232 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
233#endif
234#ifdef SA_NOCLDWAIT
235 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
236#endif
237#ifdef _SA_BSDCALL
238 { _SA_BSDCALL, "_SA_BSDCALL" },
239#endif
240 { 0, NULL },
241};
242
Roland McGrathd9f816f2004-09-04 03:39:20 +0000243static const struct xlat sigprocmaskcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000244 { SIG_BLOCK, "SIG_BLOCK" },
245 { SIG_UNBLOCK, "SIG_UNBLOCK" },
246 { SIG_SETMASK, "SIG_SETMASK" },
247#ifdef SIG_SETMASK32
248 { SIG_SETMASK32,"SIG_SETMASK32" },
249#endif
250 { 0, NULL },
251};
252
253#endif /* HAVE_SIGACTION */
254
Nate Sammonsce780fc1999-03-29 23:23:13 +0000255/* Anonymous realtime signals. */
256/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
257 constant. This is what we want. Otherwise, just use SIGRTMIN. */
258#ifdef SIGRTMIN
259#ifndef __SIGRTMIN
260#define __SIGRTMIN SIGRTMIN
261#define __SIGRTMAX SIGRTMAX /* likewise */
262#endif
263#endif
264
Roland McGrathee36ce12004-09-04 03:53:10 +0000265const char *
Nate Sammonsce780fc1999-03-29 23:23:13 +0000266signame(sig)
267int sig;
268{
269 static char buf[30];
Roland McGrathad81dce2005-05-09 07:40:30 +0000270 if (sig >= 0 && sig < nsignals) {
Nate Sammonsce780fc1999-03-29 23:23:13 +0000271 return signalent[sig];
272#ifdef SIGRTMIN
Nate Sammons3080aa41999-03-30 00:16:41 +0000273 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000274 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000275 return buf;
276#endif /* SIGRTMIN */
277 } else {
278 sprintf(buf, "%d", sig);
279 return buf;
280 }
281}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000282
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000283#ifndef UNIXWARE
Nate Sammons4a121431999-04-06 01:19:39 +0000284static void
285long_to_sigset(l, s)
286long l;
287sigset_t *s;
288{
289 sigemptyset(s);
290 *(long *)s = l;
291}
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000292#endif
Nate Sammons4a121431999-04-06 01:19:39 +0000293
294static int
295copy_sigset_len(tcp, addr, s, len)
296struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000297long addr;
Nate Sammons4a121431999-04-06 01:19:39 +0000298sigset_t *s;
299int len;
300{
301 if (len > sizeof(*s))
302 len = sizeof(*s);
303 sigemptyset(s);
304 if (umoven(tcp, addr, len, (char *)s) < 0)
305 return -1;
306 return 0;
307}
308
309#ifdef LINUX
310/* Original sigset is unsigned long */
311#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
312#else
313#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
314#endif
315
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000316static char *
Nate Sammons4a121431999-04-06 01:19:39 +0000317sprintsigmask(s, mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000318char *s;
319sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000320int rt; /* set might include realtime sigs */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321{
322 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000323 int maxsigs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324 char *format;
Roland McGratha39c5a12002-12-17 05:10:37 +0000325 static char outstr[8 * sizeof(sigset_t) * 8];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000326
327 strcpy(outstr, s);
328 s = outstr + strlen(outstr);
329 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000330 maxsigs = nsignals;
331#ifdef __SIGRTMAX
332 if (rt)
333 maxsigs = __SIGRTMAX; /* instead */
334#endif
335 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336 if (sigismember(mask, i) == 1)
337 nsigs++;
338 }
339 if (nsigs >= nsignals * 2 / 3) {
340 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000341 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000342 switch (sigismember(mask, i)) {
343 case 1:
344 sigdelset(mask, i);
345 break;
346 case 0:
347 sigaddset(mask, i);
348 break;
349 }
350 }
351 }
352 format = "%s";
353 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000354 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000355 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000356 /* real-time signals on solaris don't have
357 * signalent entries
358 */
359 if (i < nsignals) {
360 sprintf(s, format, signalent[i] + 3);
361 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000362#ifdef SIGRTMIN
363 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
364 char tsig[40];
365 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
366 sprintf(s, format, tsig);
367 }
368#endif /* SIGRTMIN */
John Hughesbdf48f52001-03-06 15:08:09 +0000369 else {
370 char tsig[32];
371 sprintf(tsig, "%u", i);
372 sprintf(s, format, tsig);
373 }
374 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000375 format = " %s";
376 }
377 }
378 *s++ = ']';
379 *s = '\0';
380 return outstr;
381}
382
383static void
Nate Sammons4a121431999-04-06 01:19:39 +0000384printsigmask(mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000385sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000386int rt;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387{
Nate Sammons4a121431999-04-06 01:19:39 +0000388 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000389}
390
391void
392printsignal(nr)
393int nr;
394{
Nate Sammonsce780fc1999-03-29 23:23:13 +0000395 tprintf(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000396}
397
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000398void
399print_sigset(struct tcb *tcp, long addr, int rt)
400{
401 sigset_t ss;
402
403 if (!addr)
404 tprintf("NULL");
405 else if (copy_sigset(tcp, addr, &ss) < 0)
406 tprintf("%#lx", addr);
407 else
408 printsigmask(&ss, rt);
409}
410
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000411#ifdef LINUX
412
John Hughes58265892001-10-18 15:13:53 +0000413#ifndef ILL_ILLOPC
414#define ILL_ILLOPC 1 /* illegal opcode */
415#define ILL_ILLOPN 2 /* illegal operand */
416#define ILL_ILLADR 3 /* illegal addressing mode */
417#define ILL_ILLTRP 4 /* illegal trap */
418#define ILL_PRVOPC 5 /* privileged opcode */
419#define ILL_PRVREG 6 /* privileged register */
420#define ILL_COPROC 7 /* coprocessor error */
421#define ILL_BADSTK 8 /* internal stack error */
422#define FPE_INTDIV 1 /* integer divide by zero */
423#define FPE_INTOVF 2 /* integer overflow */
424#define FPE_FLTDIV 3 /* floating point divide by zero */
425#define FPE_FLTOVF 4 /* floating point overflow */
426#define FPE_FLTUND 5 /* floating point underflow */
427#define FPE_FLTRES 6 /* floating point inexact result */
428#define FPE_FLTINV 7 /* floating point invalid operation */
429#define FPE_FLTSUB 8 /* subscript out of range */
430#define SEGV_MAPERR 1 /* address not mapped to object */
431#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
432#define BUS_ADRALN 1 /* invalid address alignment */
433#define BUS_ADRERR 2 /* non-existant physical address */
434#define BUS_OBJERR 3 /* object specific hardware error */
435#define TRAP_BRKPT 1 /* process breakpoint */
436#define TRAP_TRACE 2 /* process trace trap */
437#define CLD_EXITED 1 /* child has exited */
438#define CLD_KILLED 2 /* child was killed */
439#define CLD_DUMPED 3 /* child terminated abnormally */
440#define CLD_TRAPPED 4 /* traced child has trapped */
441#define CLD_STOPPED 5 /* child has stopped */
442#define CLD_CONTINUED 6 /* stopped child has continued */
443#define POLL_IN 1 /* data input available */
444#define POLL_OUT 2 /* output buffers available */
445#define POLL_MSG 3 /* input message available */
446#define POLL_ERR 4 /* i/o error */
447#define POLL_PRI 5 /* high priority input available */
448#define POLL_HUP 6 /* device disconnected */
449#define SI_USER 0 /* sent by kill, sigsend, raise */
450#define SI_QUEUE -1 /* sent by sigqueue */
451#define SI_TIMER -2 /* sent by timer expiration */
452#define SI_MESGQ -3 /* sent by real time mesq state change */
453#define SI_ASYNCIO -4 /* sent by AIO completion */
Roland McGrath941b7402003-05-23 00:29:02 +0000454#define SI_SIGIO -5 /* Sent by SIGIO */
455#define SI_TKILL -6 /* Sent by tkill */
John Hughes58265892001-10-18 15:13:53 +0000456#endif
457
458#if __GLIBC_MINOR__ < 1
459/* Type for data associated with a signal. */
460typedef union sigval
461{
462 int sival_int;
463 void *sival_ptr;
464} sigval_t;
465
466# define __SI_MAX_SIZE 128
467# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
468
469typedef struct siginfo
470{
471 int si_signo; /* Signal number. */
472 int si_errno; /* If non-zero, an errno value associated with
473 this signal, as defined in <errno.h>. */
474 int si_code; /* Signal code. */
475
476 union
477 {
478 int _pad[__SI_PAD_SIZE];
479
480 /* kill(). */
481 struct
482 {
483 __pid_t si_pid; /* Sending process ID. */
484 __uid_t si_uid; /* Real user ID of sending process. */
485 } _kill;
486
487 /* POSIX.1b timers. */
488 struct
489 {
490 unsigned int _timer1;
491 unsigned int _timer2;
492 } _timer;
493
494 /* POSIX.1b signals. */
495 struct
496 {
497 __pid_t si_pid; /* Sending process ID. */
498 __uid_t si_uid; /* Real user ID of sending process. */
499 sigval_t si_sigval; /* Signal value. */
500 } _rt;
501
502 /* SIGCHLD. */
503 struct
504 {
505 __pid_t si_pid; /* Which child. */
506 int si_status; /* Exit value or signal. */
507 __clock_t si_utime;
508 __clock_t si_stime;
509 } _sigchld;
510
511 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
512 struct
513 {
514 void *si_addr; /* Faulting insn/memory ref. */
515 } _sigfault;
516
517 /* SIGPOLL. */
518 struct
519 {
520 int si_band; /* Band event for SIGPOLL. */
521 int si_fd;
522 } _sigpoll;
523 } _sifields;
524} siginfo_t;
525
526#define si_pid _sifields._kill.si_pid
527#define si_uid _sifields._kill.si_uid
528#define si_status _sifields._sigchld.si_status
529#define si_utime _sifields._sigchld.si_utime
530#define si_stime _sifields._sigchld.si_stime
531#define si_value _sifields._rt.si_sigval
532#define si_int _sifields._rt.si_sigval.sival_int
533#define si_ptr _sifields._rt.si_sigval.sival_ptr
534#define si_addr _sifields._sigfault.si_addr
535#define si_band _sifields._sigpoll.si_band
536#define si_fd _sifields._sigpoll.si_fd
537
538#endif
539
540#endif
541
542#if defined (SVR4) || defined (LINUX)
543
Roland McGrathd9f816f2004-09-04 03:39:20 +0000544static const struct xlat siginfo_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000545#ifdef SI_NOINFO
546 { SI_NOINFO, "SI_NOINFO" },
547#endif
548#ifdef SI_USER
549 { SI_USER, "SI_USER" },
550#endif
551#ifdef SI_LWP
552 { SI_LWP, "SI_LWP" },
553#endif
554#ifdef SI_QUEUE
555 { SI_QUEUE, "SI_QUEUE" },
556#endif
557#ifdef SI_TIMER
558 { SI_TIMER, "SI_TIMER" },
559#endif
560#ifdef SI_ASYNCIO
561 { SI_ASYNCIO, "SI_ASYNCIO" },
562#endif
563#ifdef SI_MESGQ
564 { SI_MESGQ, "SI_MESGQ" },
565#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000566#ifdef SI_SIGIO
567 { SI_SIGIO, "SI_SIGIO" },
568#endif
569#ifdef SI_TKILL
570 { SI_TKILL, "SI_TKILL" },
571#endif
John Hughes58265892001-10-18 15:13:53 +0000572 { 0, NULL },
573};
574
Roland McGrathd9f816f2004-09-04 03:39:20 +0000575static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000576 { ILL_ILLOPC, "ILL_ILLOPC" },
577 { ILL_ILLOPN, "ILL_ILLOPN" },
578 { ILL_ILLADR, "ILL_ILLADR" },
579 { ILL_ILLTRP, "ILL_ILLTRP" },
580 { ILL_PRVOPC, "ILL_PRVOPC" },
581 { ILL_PRVREG, "ILL_PRVREG" },
582 { ILL_COPROC, "ILL_COPROC" },
583 { ILL_BADSTK, "ILL_BADSTK" },
584 { 0, NULL },
585};
586
Roland McGrathd9f816f2004-09-04 03:39:20 +0000587static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000588 { FPE_INTDIV, "FPE_INTDIV" },
589 { FPE_INTOVF, "FPE_INTOVF" },
590 { FPE_FLTDIV, "FPE_FLTDIV" },
591 { FPE_FLTOVF, "FPE_FLTOVF" },
592 { FPE_FLTUND, "FPE_FLTUND" },
593 { FPE_FLTRES, "FPE_FLTRES" },
594 { FPE_FLTINV, "FPE_FLTINV" },
595 { FPE_FLTSUB, "FPE_FLTSUB" },
596 { 0, NULL },
597};
598
Roland McGrathd9f816f2004-09-04 03:39:20 +0000599static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000600 { TRAP_BRKPT, "TRAP_BRKPT" },
601 { TRAP_TRACE, "TRAP_TRACE" },
602 { 0, NULL },
603};
604
Roland McGrathd9f816f2004-09-04 03:39:20 +0000605static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000606 { CLD_EXITED, "CLD_EXITED" },
607 { CLD_KILLED, "CLD_KILLED" },
608 { CLD_DUMPED, "CLD_DUMPED" },
609 { CLD_TRAPPED, "CLD_TRAPPED" },
610 { CLD_STOPPED, "CLD_STOPPED" },
611 { CLD_CONTINUED,"CLD_CONTINUED" },
612 { 0, NULL },
613};
614
Roland McGrathd9f816f2004-09-04 03:39:20 +0000615static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000616 { POLL_IN, "POLL_IN" },
617 { POLL_OUT, "POLL_OUT" },
618 { POLL_MSG, "POLL_MSG" },
619 { POLL_ERR, "POLL_ERR" },
620 { POLL_PRI, "POLL_PRI" },
621 { POLL_HUP, "POLL_HUP" },
622 { 0, NULL },
623};
624
Roland McGrathd9f816f2004-09-04 03:39:20 +0000625static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000626#ifdef PROF_SIG
627 { PROF_SIG, "PROF_SIG" },
628#endif
629 { 0, NULL },
630};
631
632#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000633static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000634#ifdef EMT_TAGOVF
635 { EMT_TAGOVF, "EMT_TAGOVF" },
636#endif
637 { 0, NULL },
638};
639#endif
640
Roland McGrathd9f816f2004-09-04 03:39:20 +0000641static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000642 { SEGV_MAPERR, "SEGV_MAPERR" },
643 { SEGV_ACCERR, "SEGV_ACCERR" },
644 { 0, NULL },
645};
646
Roland McGrathd9f816f2004-09-04 03:39:20 +0000647static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000648 { BUS_ADRALN, "BUS_ADRALN" },
649 { BUS_ADRERR, "BUS_ADRERR" },
650 { BUS_OBJERR, "BUS_OBJERR" },
651 { 0, NULL },
652};
653
654void
655printsiginfo(sip, verbose)
656siginfo_t *sip;
657int verbose;
658{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000659 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000660
661 if (sip->si_signo == 0) {
662 tprintf ("{}");
663 return;
664 }
665 tprintf("{si_signo=");
666 printsignal(sip->si_signo);
667 code = xlookup(siginfo_codes, sip->si_code);
668 if (!code) {
669 switch (sip->si_signo) {
670 case SIGTRAP:
671 code = xlookup(sigtrap_codes, sip->si_code);
672 break;
673 case SIGCHLD:
674 code = xlookup(sigchld_codes, sip->si_code);
675 break;
676 case SIGPOLL:
677 code = xlookup(sigpoll_codes, sip->si_code);
678 break;
679 case SIGPROF:
680 code = xlookup(sigprof_codes, sip->si_code);
681 break;
682 case SIGILL:
683 code = xlookup(sigill_codes, sip->si_code);
684 break;
685#ifdef SIGEMT
686 case SIGEMT:
687 code = xlookup(sigemt_codes, sip->si_code);
688 break;
689#endif
690 case SIGFPE:
691 code = xlookup(sigfpe_codes, sip->si_code);
692 break;
693 case SIGSEGV:
694 code = xlookup(sigsegv_codes, sip->si_code);
695 break;
696 case SIGBUS:
697 code = xlookup(sigbus_codes, sip->si_code);
698 break;
699 }
700 }
701 if (code)
702 tprintf(", si_code=%s", code);
703 else
704 tprintf(", si_code=%#x", sip->si_code);
705#ifdef SI_NOINFO
706 if (sip->si_code != SI_NOINFO)
707#endif
708 {
709 if (sip->si_errno) {
710 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
711 tprintf(", si_errno=%d", sip->si_errno);
712 else
713 tprintf(", si_errno=%s",
714 errnoent[sip->si_errno]);
715 }
716#ifdef SI_FROMUSER
717 if (SI_FROMUSER(sip)) {
718 tprintf(", si_pid=%ld, si_uid=%ld",
719 sip->si_pid, sip->si_uid);
720#ifdef SI_QUEUE
721 switch (sip->si_code) {
722 case SI_QUEUE:
723#ifdef SI_TIMER
724 case SI_TIMER:
725#endif /* SI_QUEUE */
726 case SI_ASYNCIO:
727#ifdef SI_MESGQ
728 case SI_MESGQ:
729#endif /* SI_MESGQ */
730 tprintf(", si_value=%d",
731 sip->si_value.sival_int);
732 break;
733 }
734#endif /* SI_QUEUE */
735 }
736 else
737#endif /* SI_FROMUSER */
738 {
739 switch (sip->si_signo) {
740 case SIGCHLD:
741 tprintf(", si_pid=%ld, si_status=",
742 (long) sip->si_pid);
743 if (sip->si_code == CLD_EXITED)
744 tprintf("%d", sip->si_status);
745 else
746 printsignal(sip->si_status);
747#if LINUX
748 if (!verbose)
749 tprintf(", ...");
750 else
751 tprintf(", si_utime=%lu, si_stime=%lu",
752 sip->si_utime,
753 sip->si_stime);
754#endif
755 break;
756 case SIGILL: case SIGFPE:
757 case SIGSEGV: case SIGBUS:
758 tprintf(", si_addr=%#lx",
759 (unsigned long) sip->si_addr);
760 break;
761 case SIGPOLL:
762 switch (sip->si_code) {
763 case POLL_IN: case POLL_OUT: case POLL_MSG:
764 tprintf(", si_band=%ld",
765 (long) sip->si_band);
766 break;
767 }
768 break;
769#ifdef LINUX
770 default:
771 tprintf(", si_pid=%lu, si_uid=%lu, ",
772 (unsigned long) sip->si_pid,
773 (unsigned long) sip->si_uid);
774 if (!verbose)
775 tprintf("...");
776 else {
777 tprintf("si_value={int=%u, ptr=%#lx}",
778 sip->si_int,
779 (unsigned long) sip->si_ptr);
780 }
781#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000782
John Hughes58265892001-10-18 15:13:53 +0000783 }
784 }
785 }
786 tprintf("}");
787}
788
789#endif /* SVR4 || LINUX */
790
791#ifdef LINUX
792
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000793static void
794parse_sigset_t (const char *str, sigset_t *set)
795{
Roland McGrathc38feca2003-10-01 07:50:28 +0000796 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000797 unsigned int digit;
798 int i;
799
800 sigemptyset(set);
801
Roland McGrathc38feca2003-10-01 07:50:28 +0000802 p = strchr(str, '\n');
803 if (p == NULL)
804 p = strchr(str, '\0');
805 for (i = 0; p-- > str; i += 4) {
806 if (*p >= '0' && *p <= '9')
807 digit = *p - '0';
808 else if (*p >= 'a' && *p <= 'f')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000809 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000810 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000811 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000812 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000813 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000814 if (digit & 1)
815 sigaddset(set, i + 1);
816 if (digit & 2)
817 sigaddset(set, i + 2);
818 if (digit & 4)
819 sigaddset(set, i + 3);
820 if (digit & 8)
821 sigaddset(set, i + 4);
822 }
823}
824
825#endif
826
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000827/*
828 * Check process TCP for the disposition of signal SIG.
829 * Return 1 if the process would somehow manage to survive signal SIG,
830 * else return 0. This routine will never be called with SIGKILL.
831 */
832int
833sigishandled(tcp, sig)
834struct tcb *tcp;
835int sig;
836{
837#ifdef LINUX
838 int sfd;
839 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000840 char buf[2048];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000841 char *s;
842 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000843 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000844#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000845#ifdef SVR4
846 /*
847 * Since procfs doesn't interfere with wait I think it is safe
848 * to punt on this question. If not, the information is there.
849 */
850 return 1;
851#else /* !SVR4 */
852 switch (sig) {
853 case SIGCONT:
854 case SIGSTOP:
855 case SIGTSTP:
856 case SIGTTIN:
857 case SIGTTOU:
858 case SIGCHLD:
859 case SIGIO:
860#if defined(SIGURG) && SIGURG != SIGIO
861 case SIGURG:
862#endif
863 case SIGWINCH:
864 /* Gloria Gaynor says ... */
865 return 1;
866 default:
867 break;
868 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000869#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000870#ifdef LINUX
871
872 /* This is incredibly costly but it's worth it. */
873 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
874 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
875 doesn't handle real-time signals). */
876 sprintf(sname, "/proc/%d/status", tcp->pid);
877 if ((sfd = open(sname, O_RDONLY)) == -1) {
878 perror(sname);
879 return 1;
880 }
881 i = read(sfd, buf, sizeof(buf));
882 buf[i] = '\0';
883 close(sfd);
884 /*
885 * Skip the extraneous fields. We need to skip
886 * command name has any spaces in it. So be it.
887 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000888 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000889 if (!s)
890 {
891 fprintf(stderr, "/proc/pid/status format error\n");
892 return 1;
893 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000894 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000895
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000896 s = strstr(buf, "SigCgt:\t");
897 if (!s)
898 {
899 fprintf(stderr, "/proc/pid/status format error\n");
900 return 1;
901 }
902 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000903
904#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000905 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
906 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000907#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000908 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000909 return 1;
910#endif /* LINUX */
911
912#ifdef SUNOS4
913 void (*u_signal)();
914
915 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
916 (long *) &u_signal) < 0) {
917 return 0;
918 }
919 if (u_signal != SIG_DFL)
920 return 1;
921#endif /* SUNOS4 */
922
923 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000924}
925
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000926#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927
928int
929sys_sigvec(tcp)
930struct tcb *tcp;
931{
932 struct sigvec sv;
933 long addr;
934
935 if (entering(tcp)) {
936 printsignal(tcp->u_arg[0]);
937 tprintf(", ");
938 addr = tcp->u_arg[1];
939 } else {
940 addr = tcp->u_arg[2];
941 }
942 if (addr == 0)
943 tprintf("NULL");
944 else if (!verbose(tcp))
945 tprintf("%#lx", addr);
946 else if (umove(tcp, addr, &sv) < 0)
947 tprintf("{...}");
948 else {
949 switch ((int) sv.sv_handler) {
950 case (int) SIG_ERR:
951 tprintf("{SIG_ERR}");
952 break;
953 case (int) SIG_DFL:
954 tprintf("{SIG_DFL}");
955 break;
956 case (int) SIG_IGN:
957 if (tcp->u_arg[0] == SIGTRAP) {
958 tcp->flags |= TCB_SIGTRAPPED;
959 kill(tcp->pid, SIGSTOP);
960 }
961 tprintf("{SIG_IGN}");
962 break;
963 case (int) SIG_HOLD:
964 if (tcp->u_arg[0] == SIGTRAP) {
965 tcp->flags |= TCB_SIGTRAPPED;
966 kill(tcp->pid, SIGSTOP);
967 }
968 tprintf("SIG_HOLD");
969 break;
970 default:
971 if (tcp->u_arg[0] == SIGTRAP) {
972 tcp->flags |= TCB_SIGTRAPPED;
973 kill(tcp->pid, SIGSTOP);
974 }
975 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000976 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000977 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000978 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000979 tprintf("}");
980 }
981 }
982 if (entering(tcp))
983 tprintf(", ");
984 return 0;
985}
986
987int
988sys_sigpause(tcp)
989struct tcb *tcp;
990{
991 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000992 sigset_t sigm;
993 long_to_sigset(tcp->u_arg[0], &sigm);
994 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995 }
996 return 0;
997}
998
999int
1000sys_sigstack(tcp)
1001struct tcb *tcp;
1002{
1003 struct sigstack ss;
1004 long addr;
1005
1006 if (entering(tcp))
1007 addr = tcp->u_arg[0];
1008 else
1009 addr = tcp->u_arg[1];
1010 if (addr == 0)
1011 tprintf("NULL");
1012 else if (umove(tcp, addr, &ss) < 0)
1013 tprintf("%#lx", addr);
1014 else {
1015 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1016 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1017 }
1018 if (entering(tcp))
1019 tprintf(", ");
1020 return 0;
1021}
1022
1023int
1024sys_sigcleanup(tcp)
1025struct tcb *tcp;
1026{
1027 return 0;
1028}
1029
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001030#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031
1032#ifndef SVR4
1033
1034int
1035sys_sigsetmask(tcp)
1036struct tcb *tcp;
1037{
1038 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001039 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001040 long_to_sigset(tcp->u_arg[0], &sigm);
1041 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001042#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1044 /* Mark attempt to block SIGTRAP */
1045 tcp->flags |= TCB_SIGTRAPPED;
1046 /* Send unblockable signal */
1047 kill(tcp->pid, SIGSTOP);
1048 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001049#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050 }
1051 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001053 long_to_sigset(tcp->u_rval, &sigm);
1054 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001055
1056 return RVAL_HEX | RVAL_STR;
1057 }
1058 return 0;
1059}
1060
1061int
1062sys_sigblock(tcp)
1063struct tcb *tcp;
1064{
1065 return sys_sigsetmask(tcp);
1066}
1067
1068#endif /* !SVR4 */
1069
1070#ifdef HAVE_SIGACTION
1071
1072#ifdef LINUX
1073struct old_sigaction {
1074 __sighandler_t __sa_handler;
1075 unsigned long sa_mask;
1076 unsigned long sa_flags;
1077 void (*sa_restorer)(void);
1078};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001079#define SA_HANDLER __sa_handler
1080#endif /* LINUX */
1081
Roland McGratha39c5a12002-12-17 05:10:37 +00001082#ifndef SA_HANDLER
1083#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001084#endif
1085
1086int
1087sys_sigaction(tcp)
1088struct tcb *tcp;
1089{
1090 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001091#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001092 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001093 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094#else
1095 struct sigaction sa;
1096#endif
1097
1098
1099 if (entering(tcp)) {
1100 printsignal(tcp->u_arg[0]);
1101 tprintf(", ");
1102 addr = tcp->u_arg[1];
1103 } else
1104 addr = tcp->u_arg[2];
1105 if (addr == 0)
1106 tprintf("NULL");
1107 else if (!verbose(tcp))
1108 tprintf("%#lx", addr);
1109 else if (umove(tcp, addr, &sa) < 0)
1110 tprintf("{...}");
1111 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001112 switch ((long) sa.SA_HANDLER) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001113 case (long) SIG_ERR:
1114 tprintf("{SIG_ERR}");
1115 break;
1116 case (long) SIG_DFL:
1117 tprintf("{SIG_DFL}");
1118 break;
1119 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001120#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001121 if (tcp->u_arg[0] == SIGTRAP) {
1122 tcp->flags |= TCB_SIGTRAPPED;
1123 kill(tcp->pid, SIGSTOP);
1124 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001125#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126 tprintf("{SIG_IGN}");
1127 break;
1128 default:
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 */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001135 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001136#ifndef LINUX
1137 printsigmask (&sa.sa_mask, 0);
1138#else
Nate Sammons4a121431999-04-06 01:19:39 +00001139 long_to_sigset(sa.sa_mask, &sigset);
1140 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001141#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001142 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001143 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001144#ifdef SA_RESTORER
1145 if (sa.sa_flags & SA_RESTORER)
1146 tprintf(", %p", sa.sa_restorer);
1147#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001148 tprintf("}");
1149 }
1150 }
1151 if (entering(tcp))
1152 tprintf(", ");
1153#ifdef LINUX
1154 else
1155 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1156#endif
1157 return 0;
1158}
1159
1160int
1161sys_signal(tcp)
1162struct tcb *tcp;
1163{
1164 if (entering(tcp)) {
1165 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001166 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001167 switch (tcp->u_arg[1]) {
1168 case (int) SIG_ERR:
1169 tprintf("SIG_ERR");
1170 break;
1171 case (int) SIG_DFL:
1172 tprintf("SIG_DFL");
1173 break;
1174 case (int) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001175#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001176 if (tcp->u_arg[0] == SIGTRAP) {
1177 tcp->flags |= TCB_SIGTRAPPED;
1178 kill(tcp->pid, SIGSTOP);
1179 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001180#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001181 tprintf("SIG_IGN");
1182 break;
1183 default:
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("%#lx", tcp->u_arg[1]);
1191 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001192 return 0;
1193 }
1194 else {
1195 switch (tcp->u_rval) {
1196 case (int) SIG_ERR:
1197 tcp->auxstr = "SIG_ERR"; break;
1198 case (int) SIG_DFL:
1199 tcp->auxstr = "SIG_DFL"; break;
1200 case (int) SIG_IGN:
1201 tcp->auxstr = "SIG_IGN"; break;
1202 default:
1203 tcp->auxstr = NULL;
1204 }
1205 return RVAL_HEX | RVAL_STR;
1206 }
1207}
1208
1209int
1210sys_sighold(tcp)
1211struct tcb *tcp;
1212{
1213 if (entering(tcp)) {
1214 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001215 }
1216 return 0;
1217}
1218
1219#endif /* HAVE_SIGACTION */
1220
1221#ifdef LINUX
1222
1223int
1224sys_sigreturn(tcp)
1225struct tcb *tcp;
1226{
Roland McGrath0f87c492003-06-03 23:29:04 +00001227#ifdef ARM
1228 struct pt_regs regs;
1229 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001230
Roland McGrath0f87c492003-06-03 23:29:04 +00001231 if (entering(tcp)) {
1232 tcp->u_arg[0] = 0;
1233
1234 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1235 return 0;
1236
1237 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1238 return 0;
1239
1240 tcp->u_arg[0] = 1;
1241 tcp->u_arg[1] = sc.oldmask;
1242 } else {
1243 sigset_t sigm;
1244 long_to_sigset(tcp->u_arg[1], &sigm);
1245 tcp->u_rval = tcp->u_error = 0;
1246 if (tcp->u_arg[0] == 0)
1247 return 0;
1248 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1249 return RVAL_NONE | RVAL_STR;
1250 }
1251 return 0;
1252#elif defined(S390) || defined(S390X)
1253 long usp;
1254 struct sigcontext_struct sc;
1255
1256 if (entering(tcp)) {
1257 tcp->u_arg[0] = 0;
1258 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1259 return 0;
1260 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1261 return 0;
1262 tcp->u_arg[0] = 1;
1263 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1264 } else {
1265 tcp->u_rval = tcp->u_error = 0;
1266 if (tcp->u_arg[0] == 0)
1267 return 0;
1268 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1269 return RVAL_NONE | RVAL_STR;
1270 }
1271 return 0;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001272#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001273#ifdef I386
1274 long esp;
1275 struct sigcontext_struct sc;
1276
1277 if (entering(tcp)) {
1278 tcp->u_arg[0] = 0;
1279 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1280 return 0;
1281 if (umove(tcp, esp, &sc) < 0)
1282 return 0;
1283 tcp->u_arg[0] = 1;
1284 tcp->u_arg[1] = sc.oldmask;
1285 }
1286 else {
1287 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001288 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001289 tcp->u_rval = tcp->u_error = 0;
1290 if (tcp->u_arg[0] == 0)
1291 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001292 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001293 return RVAL_NONE | RVAL_STR;
1294 }
1295 return 0;
1296#else /* !I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001297#ifdef IA64
1298 struct sigcontext sc;
1299 long sp;
1300
1301 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001302 /* offset of sigcontext in the kernel's sigframe structure: */
1303# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001304 tcp->u_arg[0] = 0;
1305 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1306 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001307 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001308 return 0;
1309 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001310 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001311 }
1312 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001313 sigset_t sigm;
1314
1315 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001316 tcp->u_rval = tcp->u_error = 0;
1317 if (tcp->u_arg[0] == 0)
1318 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001319 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001320 return RVAL_NONE | RVAL_STR;
1321 }
1322 return 0;
1323#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001324#ifdef POWERPC
Roland McGrath0f87c492003-06-03 23:29:04 +00001325 long esp;
1326 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001327
Roland McGrath0f87c492003-06-03 23:29:04 +00001328 if (entering(tcp)) {
1329 tcp->u_arg[0] = 0;
1330 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1331 return 0;
1332 if (umove(tcp, esp, &sc) < 0)
1333 return 0;
1334 tcp->u_arg[0] = 1;
1335 tcp->u_arg[1] = sc.oldmask;
1336 }
1337 else {
1338 sigset_t sigm;
1339 long_to_sigset(tcp->u_arg[1], &sigm);
1340 tcp->u_rval = tcp->u_error = 0;
1341 if (tcp->u_arg[0] == 0)
1342 return 0;
1343 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1344 return RVAL_NONE | RVAL_STR;
1345 }
1346 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001347#else /* !POWERPC */
1348#ifdef M68K
1349 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001350 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001351
1352 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001353 tcp->u_arg[0] = 0;
1354 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001355 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001356 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001357 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001358 tcp->u_arg[0] = 1;
1359 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001360 }
1361 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001362 sigset_t sigm;
1363 long_to_sigset(tcp->u_arg[1], &sigm);
1364 tcp->u_rval = tcp->u_error = 0;
1365 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001366 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001367 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1368 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001369 }
1370 return 0;
1371#else /* !M68K */
1372#ifdef ALPHA
1373 long fp;
1374 struct sigcontext_struct sc;
1375
1376 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001377 tcp->u_arg[0] = 0;
1378 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001379 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001380 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001381 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001382 tcp->u_arg[0] = 1;
1383 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001384 }
1385 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001386 sigset_t sigm;
1387 long_to_sigset(tcp->u_arg[1], &sigm);
1388 tcp->u_rval = tcp->u_error = 0;
1389 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001390 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001391 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1392 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 }
1394 return 0;
1395#else
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001396#if defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001397 long i1;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001398 struct regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399 m_siginfo_t si;
1400
1401 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001402 perror("sigreturn: PTRACE_GETREGS ");
1403 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001404 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001405 if(entering(tcp)) {
1406 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001407 i1 = regs.r_o1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001408 if(umove(tcp, i1, &si) < 0) {
1409 perror("sigreturn: umove ");
1410 return 0;
1411 }
1412 tcp->u_arg[0] = 1;
1413 tcp->u_arg[1] = si.si_mask;
1414 } else {
1415 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001416 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001417 tcp->u_rval = tcp->u_error = 0;
1418 if(tcp->u_arg[0] == 0)
1419 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001420 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001421 return RVAL_NONE | RVAL_STR;
1422 }
1423 return 0;
Roland McGratha39c5a12002-12-17 05:10:37 +00001424#else
Wichert Akkermanf90da011999-10-31 21:15:38 +00001425#ifdef MIPS
1426 long sp;
1427 struct sigcontext sc;
1428
1429 if(entering(tcp)) {
1430 tcp->u_arg[0] = 0;
1431 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1432 return 0;
1433 if (umove(tcp, sp, &sc) < 0)
1434 return 0;
1435 tcp->u_arg[0] = 1;
1436 tcp->u_arg[1] = sc.sc_sigset;
1437 } else {
1438 tcp->u_rval = tcp->u_error = 0;
1439 if(tcp->u_arg[0] == 0)
1440 return 0;
1441 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1442 return RVAL_NONE | RVAL_STR;
1443 }
1444 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001445#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001446#warning No sys_sigreturn() for this architecture
1447#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001448 return 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001449#endif /* MIPS */
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001450#endif /* SPARC || SPARC64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001451#endif /* ALPHA */
1452#endif /* !M68K */
1453#endif /* !POWERPC */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001454#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001455#endif /* !I386 */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001456#endif /* S390 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001457}
1458
1459int
1460sys_siggetmask(tcp)
1461struct tcb *tcp;
1462{
1463 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001464 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001465 long_to_sigset(tcp->u_rval, &sigm);
1466 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001467 }
1468 return RVAL_HEX | RVAL_STR;
1469}
1470
1471int
1472sys_sigsuspend(tcp)
1473struct tcb *tcp;
1474{
1475 if (entering(tcp)) {
1476 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001477 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001478#if 0
1479 /* first two are not really arguments, but print them anyway */
1480 /* nevermind, they are an anachronism now, too bad... */
1481 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1482#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001483 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001484 }
1485 return 0;
1486}
1487
1488#endif /* LINUX */
1489
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001490#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001491
1492int
1493sys_sigsuspend(tcp)
1494struct tcb *tcp;
1495{
1496 sigset_t sigset;
1497
1498 if (entering(tcp)) {
1499 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1500 tprintf("[?]");
1501 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001502 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001503 }
1504 return 0;
1505}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001506#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001507static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001508 { UC_SIGMASK, "UC_SIGMASK" },
1509 { UC_STACK, "UC_STACK" },
1510 { UC_CPU, "UC_CPU" },
1511#ifdef UC_FPU
1512 { UC_FPU, "UC_FPU" },
1513#endif
1514#ifdef UC_INTR
1515 { UC_INTR, "UC_INTR" },
1516#endif
1517 { 0, NULL },
1518};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001519#endif /* !FREEBSD */
1520#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001521
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001522#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001523#if defined LINUX && !defined SS_ONSTACK
1524#define SS_ONSTACK 1
1525#define SS_DISABLE 2
1526#if __GLIBC_MINOR__ == 0
1527typedef struct
1528{
1529 __ptr_t ss_sp;
1530 int ss_flags;
1531 size_t ss_size;
1532} stack_t;
1533#endif
1534#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001535#ifdef FREEBSD
1536#define stack_t struct sigaltstack
1537#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001538
Roland McGrathd9f816f2004-09-04 03:39:20 +00001539static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001540 { SS_ONSTACK, "SS_ONSTACK" },
1541 { SS_DISABLE, "SS_DISABLE" },
1542 { 0, NULL },
1543};
1544#endif
1545
1546#ifdef SVR4
1547static void
1548printcontext(tcp, ucp)
1549struct tcb *tcp;
1550ucontext_t *ucp;
1551{
1552 tprintf("{");
1553 if (!abbrev(tcp)) {
1554 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001555 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001556 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1557 }
1558 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001559 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001560 if (!abbrev(tcp)) {
1561 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1562 (unsigned long) ucp->uc_stack.ss_sp,
1563 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001564 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001565 tprintf("}");
1566 }
1567 tprintf(", ...}");
1568}
1569
1570int
1571sys_getcontext(tcp)
1572struct tcb *tcp;
1573{
1574 ucontext_t uc;
1575
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001576 if (exiting(tcp)) {
1577 if (tcp->u_error)
1578 tprintf("%#lx", tcp->u_arg[0]);
1579 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001580 tprintf("NULL");
1581 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1582 tprintf("{...}");
1583 else
1584 printcontext(tcp, &uc);
1585 }
1586 return 0;
1587}
1588
1589int
1590sys_setcontext(tcp)
1591struct tcb *tcp;
1592{
1593 ucontext_t uc;
1594
1595 if (entering(tcp)) {
1596 if (!tcp->u_arg[0])
1597 tprintf("NULL");
1598 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1599 tprintf("{...}");
1600 else
1601 printcontext(tcp, &uc);
1602 }
1603 else {
1604 tcp->u_rval = tcp->u_error = 0;
1605 if (tcp->u_arg[0] == 0)
1606 return 0;
1607 return RVAL_NONE;
1608 }
1609 return 0;
1610}
1611
1612#endif /* SVR4 */
1613
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001614#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615
1616static int
1617print_stack_t(tcp, addr)
1618struct tcb *tcp;
1619unsigned long addr;
1620{
1621 stack_t ss;
1622 if (umove(tcp, addr, &ss) < 0)
1623 return -1;
1624 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001625 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001626 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1627 return 0;
1628}
1629
1630int
1631sys_sigaltstack(tcp)
1632 struct tcb *tcp;
1633{
1634 if (entering(tcp)) {
1635 if (tcp->u_arg[0] == 0)
1636 tprintf("NULL");
1637 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1638 return -1;
1639 }
1640 else {
1641 tprintf(", ");
1642 if (tcp->u_arg[1] == 0)
1643 tprintf("NULL");
1644 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1645 return -1;
1646 }
1647 return 0;
1648}
1649#endif
1650
1651#ifdef HAVE_SIGACTION
1652
1653int
1654sys_sigprocmask(tcp)
1655struct tcb *tcp;
1656{
1657#ifdef ALPHA
1658 if (entering(tcp)) {
1659 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1660 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001661 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001662 }
1663 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001664 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001665 return RVAL_HEX | RVAL_STR;
1666 }
1667#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001668 if (entering(tcp)) {
1669#ifdef SVR4
1670 if (tcp->u_arg[0] == 0)
1671 tprintf("0");
1672 else
1673#endif /* SVR4 */
1674 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1675 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001676 print_sigset(tcp, tcp->u_arg[1], 0);
1677 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001678 }
1679 else {
1680 if (!tcp->u_arg[2])
1681 tprintf("NULL");
1682 else if (syserror(tcp))
1683 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001684 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001685 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001686 }
1687#endif /* !ALPHA */
1688 return 0;
1689}
1690
1691#endif /* HAVE_SIGACTION */
1692
1693int
1694sys_kill(tcp)
1695struct tcb *tcp;
1696{
1697 if (entering(tcp)) {
Nate Sammonsce780fc1999-03-29 23:23:13 +00001698 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001699 }
1700 return 0;
1701}
1702
1703int
1704sys_killpg(tcp)
1705struct tcb *tcp;
1706{
1707 return sys_kill(tcp);
1708}
1709
Roland McGrath8ffc3522003-07-09 09:47:49 +00001710#ifdef LINUX
1711int
1712sys_tgkill(tcp)
1713 struct tcb *tcp;
1714{
1715 if (entering(tcp)) {
1716 tprintf("%ld, %ld, %s",
1717 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1718 }
1719 return 0;
1720}
1721#endif
1722
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001723int
1724sys_sigpending(tcp)
1725struct tcb *tcp;
1726{
1727 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001728
1729 if (exiting(tcp)) {
1730 if (syserror(tcp))
1731 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001732 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001733 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001734 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001735 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001736 }
1737 return 0;
1738}
1739
John Hughes42162082001-10-18 14:48:26 +00001740int sys_sigwait(tcp)
1741struct tcb *tcp;
1742{
1743 sigset_t sigset;
1744
1745 if (entering(tcp)) {
1746 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1747 tprintf("[?]");
1748 else
1749 printsigmask(&sigset, 0);
1750 }
1751 else {
1752 if (!syserror(tcp)) {
1753 tcp->auxstr = signalent[tcp->u_rval];
1754 return RVAL_DECIMAL | RVAL_STR;
1755 }
1756 }
1757 return 0;
1758}
1759
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760#ifdef LINUX
1761
1762 int
1763sys_rt_sigprocmask(tcp)
1764 struct tcb *tcp;
1765{
1766 sigset_t sigset;
1767
Nate Sammons4a121431999-04-06 01:19:39 +00001768 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001769 if (entering(tcp)) {
1770 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1771 tprintf(", ");
1772 if (!tcp->u_arg[1])
1773 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001774 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001775 tprintf("%#lx, ", tcp->u_arg[1]);
1776 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001777 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001778 tprintf(", ");
1779 }
1780 }
1781 else {
1782 if (!tcp->u_arg[2])
1783
1784 tprintf("NULL");
1785 else if (syserror(tcp))
1786 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001787 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001788 tprintf("[?]");
1789 else
Nate Sammons4a121431999-04-06 01:19:39 +00001790 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001791 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001792 }
1793 return 0;
1794}
1795
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001796
1797/* Structure describing the action to be taken when a signal arrives. */
1798struct new_sigaction
1799{
1800 union
1801 {
1802 __sighandler_t __sa_handler;
1803 void (*__sa_sigaction) (int, siginfo_t *, void *);
1804 }
1805 __sigaction_handler;
1806 unsigned long sa_flags;
1807 void (*sa_restorer) (void);
1808 unsigned long int sa_mask[2];
1809};
1810
1811
1812 int
1813sys_rt_sigaction(tcp)
1814 struct tcb *tcp;
1815{
1816 struct new_sigaction sa;
1817 sigset_t sigset;
1818 long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001819
1820 if (entering(tcp)) {
1821 printsignal(tcp->u_arg[0]);
1822 tprintf(", ");
1823 addr = tcp->u_arg[1];
1824 } else
1825 addr = tcp->u_arg[2];
1826 if (addr == 0)
1827 tprintf("NULL");
1828 else if (!verbose(tcp))
1829 tprintf("%#lx", addr);
1830 else if (umove(tcp, addr, &sa) < 0)
1831 tprintf("{...}");
1832 else {
1833 switch ((long) sa.__sigaction_handler.__sa_handler) {
1834 case (long) SIG_ERR:
1835 tprintf("{SIG_ERR}");
1836 break;
1837 case (long) SIG_DFL:
1838 tprintf("{SIG_DFL}");
1839 break;
1840 case (long) SIG_IGN:
1841 tprintf("{SIG_IGN}");
1842 break;
1843 default:
1844 tprintf("{%#lx, ",
1845 (long) sa.__sigaction_handler.__sa_handler);
Nate Sammons4a121431999-04-06 01:19:39 +00001846 sigemptyset(&sigset);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001847#ifdef LINUXSPARC
1848 if (tcp->u_arg[4] <= sizeof(sigset))
1849 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1850#else
Nate Sammons4a121431999-04-06 01:19:39 +00001851 if (tcp->u_arg[3] <= sizeof(sigset))
1852 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001853#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001854 else
1855 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1856 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001857 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001858 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001859#ifdef SA_RESTORER
1860 if (sa.sa_flags & SA_RESTORER)
1861 tprintf(", %p", sa.sa_restorer);
1862#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001863 tprintf("}");
1864 }
1865 }
1866 if (entering(tcp))
1867 tprintf(", ");
1868 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001869#ifdef LINUXSPARC
1870 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1871#elif defined(ALPHA)
1872 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1873#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874 tprintf(", %lu", addr = tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001875#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001876 return 0;
1877}
1878
1879 int
1880sys_rt_sigpending(tcp)
1881 struct tcb *tcp;
1882{
1883 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001884
1885 if (exiting(tcp)) {
1886 if (syserror(tcp))
1887 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001888 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1889 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001890 tprintf("[?]");
1891 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001892 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001893 }
1894 return 0;
1895}
1896 int
1897sys_rt_sigsuspend(tcp)
1898 struct tcb *tcp;
1899{
1900 if (entering(tcp)) {
1901 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001902 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1903 tprintf("[?]");
1904 else
1905 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906 }
1907 return 0;
1908}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001909 int
1910sys_rt_sigqueueinfo(tcp)
1911 struct tcb *tcp;
1912{
1913 if (entering(tcp)) {
1914 siginfo_t si;
1915 tprintf("%lu, ", tcp->u_arg[0]);
1916 printsignal(tcp->u_arg[1]);
1917 tprintf(", ");
1918 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1919 tprintf("%#lx", tcp->u_arg[2]);
1920 else
John Hughes58265892001-10-18 15:13:53 +00001921 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001922 }
1923 return 0;
1924}
1925
1926int sys_rt_sigtimedwait(tcp)
1927 struct tcb *tcp;
1928{
1929 if (entering(tcp)) {
1930 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001931
Roland McGratha39c5a12002-12-17 05:10:37 +00001932 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00001933 &sigset, tcp->u_arg[3]) < 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 tprintf(", ");
1938 }
1939 else {
1940 if (syserror(tcp))
1941 tprintf("%#lx", tcp->u_arg[0]);
1942 else {
1943 siginfo_t si;
1944 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1945 tprintf("%#lx", tcp->u_arg[1]);
1946 else
John Hughes58265892001-10-18 15:13:53 +00001947 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001948 /* XXX For now */
1949 tprintf(", %#lx", tcp->u_arg[2]);
1950 tprintf(", %d", (int) tcp->u_arg[3]);
1951 }
1952 }
1953 return 0;
1954};
1955
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001956int
1957sys_restart_syscall(tcp)
1958struct tcb *tcp;
1959{
1960 if (entering(tcp))
1961 tprintf("<... resuming interrupted call ...>");
1962 return 0;
1963}
1964
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001965#endif /* LINUX */