blob: 41f9ad4e364331169b7eb138fa133e7208812f76 [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
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001061#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001062int
1063sys_sigblock(tcp)
1064struct tcb *tcp;
1065{
1066 return sys_sigsetmask(tcp);
1067}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001068#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001069
1070#endif /* !SVR4 */
1071
1072#ifdef HAVE_SIGACTION
1073
1074#ifdef LINUX
1075struct old_sigaction {
1076 __sighandler_t __sa_handler;
1077 unsigned long sa_mask;
1078 unsigned long sa_flags;
1079 void (*sa_restorer)(void);
1080};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001081#define SA_HANDLER __sa_handler
1082#endif /* LINUX */
1083
Roland McGratha39c5a12002-12-17 05:10:37 +00001084#ifndef SA_HANDLER
1085#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001086#endif
1087
1088int
1089sys_sigaction(tcp)
1090struct tcb *tcp;
1091{
1092 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001093#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001094 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001095 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096#else
1097 struct sigaction sa;
1098#endif
1099
1100
1101 if (entering(tcp)) {
1102 printsignal(tcp->u_arg[0]);
1103 tprintf(", ");
1104 addr = tcp->u_arg[1];
1105 } else
1106 addr = tcp->u_arg[2];
1107 if (addr == 0)
1108 tprintf("NULL");
1109 else if (!verbose(tcp))
1110 tprintf("%#lx", addr);
1111 else if (umove(tcp, addr, &sa) < 0)
1112 tprintf("{...}");
1113 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001114 switch ((long) sa.SA_HANDLER) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001115 case (long) SIG_ERR:
1116 tprintf("{SIG_ERR}");
1117 break;
1118 case (long) SIG_DFL:
1119 tprintf("{SIG_DFL}");
1120 break;
1121 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001122#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001123 if (tcp->u_arg[0] == SIGTRAP) {
1124 tcp->flags |= TCB_SIGTRAPPED;
1125 kill(tcp->pid, SIGSTOP);
1126 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001127#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001128 tprintf("{SIG_IGN}");
1129 break;
1130 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001131#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001132 if (tcp->u_arg[0] == SIGTRAP) {
1133 tcp->flags |= TCB_SIGTRAPPED;
1134 kill(tcp->pid, SIGSTOP);
1135 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001136#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001137 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001138#ifndef LINUX
1139 printsigmask (&sa.sa_mask, 0);
1140#else
Nate Sammons4a121431999-04-06 01:19:39 +00001141 long_to_sigset(sa.sa_mask, &sigset);
1142 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001143#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001144 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001145 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001146#ifdef SA_RESTORER
1147 if (sa.sa_flags & SA_RESTORER)
1148 tprintf(", %p", sa.sa_restorer);
1149#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001150 tprintf("}");
1151 }
1152 }
1153 if (entering(tcp))
1154 tprintf(", ");
1155#ifdef LINUX
1156 else
1157 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1158#endif
1159 return 0;
1160}
1161
1162int
1163sys_signal(tcp)
1164struct tcb *tcp;
1165{
1166 if (entering(tcp)) {
1167 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001168 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001169 switch (tcp->u_arg[1]) {
1170 case (int) SIG_ERR:
1171 tprintf("SIG_ERR");
1172 break;
1173 case (int) SIG_DFL:
1174 tprintf("SIG_DFL");
1175 break;
1176 case (int) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001177#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001178 if (tcp->u_arg[0] == SIGTRAP) {
1179 tcp->flags |= TCB_SIGTRAPPED;
1180 kill(tcp->pid, SIGSTOP);
1181 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001182#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001183 tprintf("SIG_IGN");
1184 break;
1185 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001186#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001187 if (tcp->u_arg[0] == SIGTRAP) {
1188 tcp->flags |= TCB_SIGTRAPPED;
1189 kill(tcp->pid, SIGSTOP);
1190 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001191#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001192 tprintf("%#lx", tcp->u_arg[1]);
1193 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001194 return 0;
1195 }
1196 else {
1197 switch (tcp->u_rval) {
1198 case (int) SIG_ERR:
1199 tcp->auxstr = "SIG_ERR"; break;
1200 case (int) SIG_DFL:
1201 tcp->auxstr = "SIG_DFL"; break;
1202 case (int) SIG_IGN:
1203 tcp->auxstr = "SIG_IGN"; break;
1204 default:
1205 tcp->auxstr = NULL;
1206 }
1207 return RVAL_HEX | RVAL_STR;
1208 }
1209}
1210
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001211#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001212int
1213sys_sighold(tcp)
1214struct tcb *tcp;
1215{
1216 if (entering(tcp)) {
1217 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001218 }
1219 return 0;
1220}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001221#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001222
1223#endif /* HAVE_SIGACTION */
1224
1225#ifdef LINUX
1226
1227int
1228sys_sigreturn(tcp)
1229struct tcb *tcp;
1230{
Roland McGrath0f87c492003-06-03 23:29:04 +00001231#ifdef ARM
1232 struct pt_regs regs;
1233 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001234
Roland McGrath0f87c492003-06-03 23:29:04 +00001235 if (entering(tcp)) {
1236 tcp->u_arg[0] = 0;
1237
1238 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1239 return 0;
1240
1241 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1242 return 0;
1243
1244 tcp->u_arg[0] = 1;
1245 tcp->u_arg[1] = sc.oldmask;
1246 } else {
1247 sigset_t sigm;
1248 long_to_sigset(tcp->u_arg[1], &sigm);
1249 tcp->u_rval = tcp->u_error = 0;
1250 if (tcp->u_arg[0] == 0)
1251 return 0;
1252 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1253 return RVAL_NONE | RVAL_STR;
1254 }
1255 return 0;
1256#elif defined(S390) || defined(S390X)
1257 long usp;
1258 struct sigcontext_struct sc;
1259
1260 if (entering(tcp)) {
1261 tcp->u_arg[0] = 0;
1262 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1263 return 0;
1264 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1265 return 0;
1266 tcp->u_arg[0] = 1;
1267 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1268 } else {
1269 tcp->u_rval = tcp->u_error = 0;
1270 if (tcp->u_arg[0] == 0)
1271 return 0;
1272 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1273 return RVAL_NONE | RVAL_STR;
1274 }
1275 return 0;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001276#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001277#ifdef I386
1278 long esp;
1279 struct sigcontext_struct sc;
1280
1281 if (entering(tcp)) {
1282 tcp->u_arg[0] = 0;
1283 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1284 return 0;
1285 if (umove(tcp, esp, &sc) < 0)
1286 return 0;
1287 tcp->u_arg[0] = 1;
1288 tcp->u_arg[1] = sc.oldmask;
1289 }
1290 else {
1291 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001292 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001293 tcp->u_rval = tcp->u_error = 0;
1294 if (tcp->u_arg[0] == 0)
1295 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001296 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001297 return RVAL_NONE | RVAL_STR;
1298 }
1299 return 0;
1300#else /* !I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001301#ifdef IA64
1302 struct sigcontext sc;
1303 long sp;
1304
1305 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001306 /* offset of sigcontext in the kernel's sigframe structure: */
1307# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001308 tcp->u_arg[0] = 0;
1309 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1310 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001311 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001312 return 0;
1313 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001314 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001315 }
1316 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001317 sigset_t sigm;
1318
1319 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001320 tcp->u_rval = tcp->u_error = 0;
1321 if (tcp->u_arg[0] == 0)
1322 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001323 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001324 return RVAL_NONE | RVAL_STR;
1325 }
1326 return 0;
1327#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001328#ifdef POWERPC
Roland McGrath0f87c492003-06-03 23:29:04 +00001329 long esp;
1330 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001331
Roland McGrath0f87c492003-06-03 23:29:04 +00001332 if (entering(tcp)) {
1333 tcp->u_arg[0] = 0;
1334 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1335 return 0;
1336 if (umove(tcp, esp, &sc) < 0)
1337 return 0;
1338 tcp->u_arg[0] = 1;
1339 tcp->u_arg[1] = sc.oldmask;
1340 }
1341 else {
1342 sigset_t sigm;
1343 long_to_sigset(tcp->u_arg[1], &sigm);
1344 tcp->u_rval = tcp->u_error = 0;
1345 if (tcp->u_arg[0] == 0)
1346 return 0;
1347 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1348 return RVAL_NONE | RVAL_STR;
1349 }
1350 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001351#else /* !POWERPC */
1352#ifdef M68K
1353 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001354 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001355
1356 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001357 tcp->u_arg[0] = 0;
1358 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001359 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001360 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001361 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001362 tcp->u_arg[0] = 1;
1363 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001364 }
1365 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001366 sigset_t sigm;
1367 long_to_sigset(tcp->u_arg[1], &sigm);
1368 tcp->u_rval = tcp->u_error = 0;
1369 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001370 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001371 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1372 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001373 }
1374 return 0;
1375#else /* !M68K */
1376#ifdef ALPHA
1377 long fp;
1378 struct sigcontext_struct sc;
1379
1380 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001381 tcp->u_arg[0] = 0;
1382 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001383 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001384 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001386 tcp->u_arg[0] = 1;
1387 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001388 }
1389 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001390 sigset_t sigm;
1391 long_to_sigset(tcp->u_arg[1], &sigm);
1392 tcp->u_rval = tcp->u_error = 0;
1393 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001394 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001395 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1396 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001397 }
1398 return 0;
1399#else
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001400#if defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001401 long i1;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001402 struct regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001403 m_siginfo_t si;
1404
1405 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001406 perror("sigreturn: PTRACE_GETREGS ");
1407 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001408 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409 if(entering(tcp)) {
1410 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001411 i1 = regs.r_o1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001412 if(umove(tcp, i1, &si) < 0) {
1413 perror("sigreturn: umove ");
1414 return 0;
1415 }
1416 tcp->u_arg[0] = 1;
1417 tcp->u_arg[1] = si.si_mask;
1418 } else {
1419 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001420 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001421 tcp->u_rval = tcp->u_error = 0;
1422 if(tcp->u_arg[0] == 0)
1423 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001424 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001425 return RVAL_NONE | RVAL_STR;
1426 }
1427 return 0;
Roland McGratha39c5a12002-12-17 05:10:37 +00001428#else
Wichert Akkermanf90da011999-10-31 21:15:38 +00001429#ifdef MIPS
1430 long sp;
1431 struct sigcontext sc;
1432
1433 if(entering(tcp)) {
1434 tcp->u_arg[0] = 0;
1435 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1436 return 0;
1437 if (umove(tcp, sp, &sc) < 0)
1438 return 0;
1439 tcp->u_arg[0] = 1;
1440 tcp->u_arg[1] = sc.sc_sigset;
1441 } else {
1442 tcp->u_rval = tcp->u_error = 0;
1443 if(tcp->u_arg[0] == 0)
1444 return 0;
1445 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1446 return RVAL_NONE | RVAL_STR;
1447 }
1448 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001449#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001450#warning No sys_sigreturn() for this architecture
1451#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001452 return 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001453#endif /* MIPS */
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001454#endif /* SPARC || SPARC64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001455#endif /* ALPHA */
1456#endif /* !M68K */
1457#endif /* !POWERPC */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001458#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001459#endif /* !I386 */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001460#endif /* S390 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001461}
1462
1463int
1464sys_siggetmask(tcp)
1465struct tcb *tcp;
1466{
1467 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001468 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001469 long_to_sigset(tcp->u_rval, &sigm);
1470 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001471 }
1472 return RVAL_HEX | RVAL_STR;
1473}
1474
1475int
1476sys_sigsuspend(tcp)
1477struct tcb *tcp;
1478{
1479 if (entering(tcp)) {
1480 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001481 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001482#if 0
1483 /* first two are not really arguments, but print them anyway */
1484 /* nevermind, they are an anachronism now, too bad... */
1485 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1486#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001487 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001488 }
1489 return 0;
1490}
1491
1492#endif /* LINUX */
1493
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001494#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001495
1496int
1497sys_sigsuspend(tcp)
1498struct tcb *tcp;
1499{
1500 sigset_t sigset;
1501
1502 if (entering(tcp)) {
1503 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1504 tprintf("[?]");
1505 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001506 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001507 }
1508 return 0;
1509}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001510#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001511static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001512 { UC_SIGMASK, "UC_SIGMASK" },
1513 { UC_STACK, "UC_STACK" },
1514 { UC_CPU, "UC_CPU" },
1515#ifdef UC_FPU
1516 { UC_FPU, "UC_FPU" },
1517#endif
1518#ifdef UC_INTR
1519 { UC_INTR, "UC_INTR" },
1520#endif
1521 { 0, NULL },
1522};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001523#endif /* !FREEBSD */
1524#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001525
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001526#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001527#if defined LINUX && !defined SS_ONSTACK
1528#define SS_ONSTACK 1
1529#define SS_DISABLE 2
1530#if __GLIBC_MINOR__ == 0
1531typedef struct
1532{
1533 __ptr_t ss_sp;
1534 int ss_flags;
1535 size_t ss_size;
1536} stack_t;
1537#endif
1538#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001539#ifdef FREEBSD
1540#define stack_t struct sigaltstack
1541#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001542
Roland McGrathd9f816f2004-09-04 03:39:20 +00001543static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001544 { SS_ONSTACK, "SS_ONSTACK" },
1545 { SS_DISABLE, "SS_DISABLE" },
1546 { 0, NULL },
1547};
1548#endif
1549
1550#ifdef SVR4
1551static void
1552printcontext(tcp, ucp)
1553struct tcb *tcp;
1554ucontext_t *ucp;
1555{
1556 tprintf("{");
1557 if (!abbrev(tcp)) {
1558 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001559 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001560 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1561 }
1562 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001563 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001564 if (!abbrev(tcp)) {
1565 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1566 (unsigned long) ucp->uc_stack.ss_sp,
1567 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001568 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001569 tprintf("}");
1570 }
1571 tprintf(", ...}");
1572}
1573
1574int
1575sys_getcontext(tcp)
1576struct tcb *tcp;
1577{
1578 ucontext_t uc;
1579
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001580 if (exiting(tcp)) {
1581 if (tcp->u_error)
1582 tprintf("%#lx", tcp->u_arg[0]);
1583 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001584 tprintf("NULL");
1585 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1586 tprintf("{...}");
1587 else
1588 printcontext(tcp, &uc);
1589 }
1590 return 0;
1591}
1592
1593int
1594sys_setcontext(tcp)
1595struct tcb *tcp;
1596{
1597 ucontext_t uc;
1598
1599 if (entering(tcp)) {
1600 if (!tcp->u_arg[0])
1601 tprintf("NULL");
1602 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1603 tprintf("{...}");
1604 else
1605 printcontext(tcp, &uc);
1606 }
1607 else {
1608 tcp->u_rval = tcp->u_error = 0;
1609 if (tcp->u_arg[0] == 0)
1610 return 0;
1611 return RVAL_NONE;
1612 }
1613 return 0;
1614}
1615
1616#endif /* SVR4 */
1617
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001618#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001619
1620static int
1621print_stack_t(tcp, addr)
1622struct tcb *tcp;
1623unsigned long addr;
1624{
1625 stack_t ss;
1626 if (umove(tcp, addr, &ss) < 0)
1627 return -1;
1628 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001629 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001630 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1631 return 0;
1632}
1633
1634int
1635sys_sigaltstack(tcp)
1636 struct tcb *tcp;
1637{
1638 if (entering(tcp)) {
1639 if (tcp->u_arg[0] == 0)
1640 tprintf("NULL");
1641 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1642 return -1;
1643 }
1644 else {
1645 tprintf(", ");
1646 if (tcp->u_arg[1] == 0)
1647 tprintf("NULL");
1648 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1649 return -1;
1650 }
1651 return 0;
1652}
1653#endif
1654
1655#ifdef HAVE_SIGACTION
1656
1657int
1658sys_sigprocmask(tcp)
1659struct tcb *tcp;
1660{
1661#ifdef ALPHA
1662 if (entering(tcp)) {
1663 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1664 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001665 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001666 }
1667 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001668 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001669 return RVAL_HEX | RVAL_STR;
1670 }
1671#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001672 if (entering(tcp)) {
1673#ifdef SVR4
1674 if (tcp->u_arg[0] == 0)
1675 tprintf("0");
1676 else
1677#endif /* SVR4 */
1678 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1679 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001680 print_sigset(tcp, tcp->u_arg[1], 0);
1681 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001682 }
1683 else {
1684 if (!tcp->u_arg[2])
1685 tprintf("NULL");
1686 else if (syserror(tcp))
1687 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001688 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001689 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001690 }
1691#endif /* !ALPHA */
1692 return 0;
1693}
1694
1695#endif /* HAVE_SIGACTION */
1696
1697int
1698sys_kill(tcp)
1699struct tcb *tcp;
1700{
1701 if (entering(tcp)) {
Nate Sammonsce780fc1999-03-29 23:23:13 +00001702 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001703 }
1704 return 0;
1705}
1706
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001707#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001708int
1709sys_killpg(tcp)
1710struct tcb *tcp;
1711{
1712 return sys_kill(tcp);
1713}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001714#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001715
Roland McGrath8ffc3522003-07-09 09:47:49 +00001716#ifdef LINUX
1717int
1718sys_tgkill(tcp)
1719 struct tcb *tcp;
1720{
1721 if (entering(tcp)) {
1722 tprintf("%ld, %ld, %s",
1723 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1724 }
1725 return 0;
1726}
1727#endif
1728
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001729int
1730sys_sigpending(tcp)
1731struct tcb *tcp;
1732{
1733 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001734
1735 if (exiting(tcp)) {
1736 if (syserror(tcp))
1737 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001738 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001739 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001740 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001741 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001742 }
1743 return 0;
1744}
1745
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001746#ifdef SVR4
John Hughes42162082001-10-18 14:48:26 +00001747int sys_sigwait(tcp)
1748struct tcb *tcp;
1749{
1750 sigset_t sigset;
1751
1752 if (entering(tcp)) {
1753 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1754 tprintf("[?]");
1755 else
1756 printsigmask(&sigset, 0);
1757 }
1758 else {
1759 if (!syserror(tcp)) {
1760 tcp->auxstr = signalent[tcp->u_rval];
1761 return RVAL_DECIMAL | RVAL_STR;
1762 }
1763 }
1764 return 0;
1765}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001766#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001767
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001768#ifdef LINUX
1769
1770 int
1771sys_rt_sigprocmask(tcp)
1772 struct tcb *tcp;
1773{
1774 sigset_t sigset;
1775
Nate Sammons4a121431999-04-06 01:19:39 +00001776 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001777 if (entering(tcp)) {
1778 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1779 tprintf(", ");
1780 if (!tcp->u_arg[1])
1781 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001782 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001783 tprintf("%#lx, ", tcp->u_arg[1]);
1784 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001785 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001786 tprintf(", ");
1787 }
1788 }
1789 else {
1790 if (!tcp->u_arg[2])
1791
1792 tprintf("NULL");
1793 else if (syserror(tcp))
1794 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001795 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001796 tprintf("[?]");
1797 else
Nate Sammons4a121431999-04-06 01:19:39 +00001798 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001799 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001800 }
1801 return 0;
1802}
1803
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001804
1805/* Structure describing the action to be taken when a signal arrives. */
1806struct new_sigaction
1807{
1808 union
1809 {
1810 __sighandler_t __sa_handler;
1811 void (*__sa_sigaction) (int, siginfo_t *, void *);
1812 }
1813 __sigaction_handler;
1814 unsigned long sa_flags;
1815 void (*sa_restorer) (void);
1816 unsigned long int sa_mask[2];
1817};
1818
1819
1820 int
1821sys_rt_sigaction(tcp)
1822 struct tcb *tcp;
1823{
1824 struct new_sigaction sa;
1825 sigset_t sigset;
1826 long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001827
1828 if (entering(tcp)) {
1829 printsignal(tcp->u_arg[0]);
1830 tprintf(", ");
1831 addr = tcp->u_arg[1];
1832 } else
1833 addr = tcp->u_arg[2];
1834 if (addr == 0)
1835 tprintf("NULL");
1836 else if (!verbose(tcp))
1837 tprintf("%#lx", addr);
1838 else if (umove(tcp, addr, &sa) < 0)
1839 tprintf("{...}");
1840 else {
1841 switch ((long) sa.__sigaction_handler.__sa_handler) {
1842 case (long) SIG_ERR:
1843 tprintf("{SIG_ERR}");
1844 break;
1845 case (long) SIG_DFL:
1846 tprintf("{SIG_DFL}");
1847 break;
1848 case (long) SIG_IGN:
1849 tprintf("{SIG_IGN}");
1850 break;
1851 default:
1852 tprintf("{%#lx, ",
1853 (long) sa.__sigaction_handler.__sa_handler);
Nate Sammons4a121431999-04-06 01:19:39 +00001854 sigemptyset(&sigset);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001855#ifdef LINUXSPARC
1856 if (tcp->u_arg[4] <= sizeof(sigset))
1857 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1858#else
Nate Sammons4a121431999-04-06 01:19:39 +00001859 if (tcp->u_arg[3] <= sizeof(sigset))
1860 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001861#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001862 else
1863 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1864 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001865 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001866 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001867#ifdef SA_RESTORER
1868 if (sa.sa_flags & SA_RESTORER)
1869 tprintf(", %p", sa.sa_restorer);
1870#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001871 tprintf("}");
1872 }
1873 }
1874 if (entering(tcp))
1875 tprintf(", ");
1876 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001877#ifdef LINUXSPARC
1878 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1879#elif defined(ALPHA)
1880 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1881#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001882 tprintf(", %lu", addr = tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001883#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001884 return 0;
1885}
1886
1887 int
1888sys_rt_sigpending(tcp)
1889 struct tcb *tcp;
1890{
1891 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001892
1893 if (exiting(tcp)) {
1894 if (syserror(tcp))
1895 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001896 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1897 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001898 tprintf("[?]");
1899 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001900 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001901 }
1902 return 0;
1903}
1904 int
1905sys_rt_sigsuspend(tcp)
1906 struct tcb *tcp;
1907{
1908 if (entering(tcp)) {
1909 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001910 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1911 tprintf("[?]");
1912 else
1913 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001914 }
1915 return 0;
1916}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001917 int
1918sys_rt_sigqueueinfo(tcp)
1919 struct tcb *tcp;
1920{
1921 if (entering(tcp)) {
1922 siginfo_t si;
1923 tprintf("%lu, ", tcp->u_arg[0]);
1924 printsignal(tcp->u_arg[1]);
1925 tprintf(", ");
1926 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1927 tprintf("%#lx", tcp->u_arg[2]);
1928 else
John Hughes58265892001-10-18 15:13:53 +00001929 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001930 }
1931 return 0;
1932}
1933
1934int sys_rt_sigtimedwait(tcp)
1935 struct tcb *tcp;
1936{
1937 if (entering(tcp)) {
1938 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001939
Roland McGratha39c5a12002-12-17 05:10:37 +00001940 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00001941 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001942 tprintf("[?]");
1943 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001944 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001945 tprintf(", ");
1946 }
1947 else {
1948 if (syserror(tcp))
1949 tprintf("%#lx", tcp->u_arg[0]);
1950 else {
1951 siginfo_t si;
1952 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1953 tprintf("%#lx", tcp->u_arg[1]);
1954 else
John Hughes58265892001-10-18 15:13:53 +00001955 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001956 /* XXX For now */
1957 tprintf(", %#lx", tcp->u_arg[2]);
1958 tprintf(", %d", (int) tcp->u_arg[3]);
1959 }
1960 }
1961 return 0;
1962};
1963
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001964int
1965sys_restart_syscall(tcp)
1966struct tcb *tcp;
1967{
1968 if (entering(tcp))
1969 tprintf("<... resuming interrupted call ...>");
1970 return 0;
1971}
1972
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001973#endif /* LINUX */