blob: 5950831d918e20cb21474b227ca602694d0a6240 [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
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000316static const char *
317sprintsigmask(const char *str, sigset_t *mask, int rt)
318/* set might include realtime sigs */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319{
320 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000321 int maxsigs;
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000322 char *format, *s;
Roland McGratha39c5a12002-12-17 05:10:37 +0000323 static char outstr[8 * sizeof(sigset_t) * 8];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000325 strcpy(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000326 s = outstr + strlen(outstr);
327 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000328 maxsigs = nsignals;
329#ifdef __SIGRTMAX
330 if (rt)
331 maxsigs = __SIGRTMAX; /* instead */
332#endif
333 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334 if (sigismember(mask, i) == 1)
335 nsigs++;
336 }
337 if (nsigs >= nsignals * 2 / 3) {
338 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000339 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000340 switch (sigismember(mask, i)) {
341 case 1:
342 sigdelset(mask, i);
343 break;
344 case 0:
345 sigaddset(mask, i);
346 break;
347 }
348 }
349 }
350 format = "%s";
351 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000352 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000353 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000354 /* real-time signals on solaris don't have
355 * signalent entries
356 */
357 if (i < nsignals) {
358 sprintf(s, format, signalent[i] + 3);
359 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000360#ifdef SIGRTMIN
361 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
362 char tsig[40];
363 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
364 sprintf(s, format, tsig);
365 }
366#endif /* SIGRTMIN */
John Hughesbdf48f52001-03-06 15:08:09 +0000367 else {
368 char tsig[32];
369 sprintf(tsig, "%u", i);
370 sprintf(s, format, tsig);
371 }
372 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000373 format = " %s";
374 }
375 }
376 *s++ = ']';
377 *s = '\0';
378 return outstr;
379}
380
381static void
Nate Sammons4a121431999-04-06 01:19:39 +0000382printsigmask(mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000384int rt;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000385{
Nate Sammons4a121431999-04-06 01:19:39 +0000386 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387}
388
389void
390printsignal(nr)
391int nr;
392{
Nate Sammonsce780fc1999-03-29 23:23:13 +0000393 tprintf(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394}
395
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000396void
397print_sigset(struct tcb *tcp, long addr, int rt)
398{
399 sigset_t ss;
400
401 if (!addr)
402 tprintf("NULL");
403 else if (copy_sigset(tcp, addr, &ss) < 0)
404 tprintf("%#lx", addr);
405 else
406 printsigmask(&ss, rt);
407}
408
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000409#ifdef LINUX
410
John Hughes58265892001-10-18 15:13:53 +0000411#ifndef ILL_ILLOPC
412#define ILL_ILLOPC 1 /* illegal opcode */
413#define ILL_ILLOPN 2 /* illegal operand */
414#define ILL_ILLADR 3 /* illegal addressing mode */
415#define ILL_ILLTRP 4 /* illegal trap */
416#define ILL_PRVOPC 5 /* privileged opcode */
417#define ILL_PRVREG 6 /* privileged register */
418#define ILL_COPROC 7 /* coprocessor error */
419#define ILL_BADSTK 8 /* internal stack error */
420#define FPE_INTDIV 1 /* integer divide by zero */
421#define FPE_INTOVF 2 /* integer overflow */
422#define FPE_FLTDIV 3 /* floating point divide by zero */
423#define FPE_FLTOVF 4 /* floating point overflow */
424#define FPE_FLTUND 5 /* floating point underflow */
425#define FPE_FLTRES 6 /* floating point inexact result */
426#define FPE_FLTINV 7 /* floating point invalid operation */
427#define FPE_FLTSUB 8 /* subscript out of range */
428#define SEGV_MAPERR 1 /* address not mapped to object */
429#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
430#define BUS_ADRALN 1 /* invalid address alignment */
431#define BUS_ADRERR 2 /* non-existant physical address */
432#define BUS_OBJERR 3 /* object specific hardware error */
433#define TRAP_BRKPT 1 /* process breakpoint */
434#define TRAP_TRACE 2 /* process trace trap */
435#define CLD_EXITED 1 /* child has exited */
436#define CLD_KILLED 2 /* child was killed */
437#define CLD_DUMPED 3 /* child terminated abnormally */
438#define CLD_TRAPPED 4 /* traced child has trapped */
439#define CLD_STOPPED 5 /* child has stopped */
440#define CLD_CONTINUED 6 /* stopped child has continued */
441#define POLL_IN 1 /* data input available */
442#define POLL_OUT 2 /* output buffers available */
443#define POLL_MSG 3 /* input message available */
444#define POLL_ERR 4 /* i/o error */
445#define POLL_PRI 5 /* high priority input available */
446#define POLL_HUP 6 /* device disconnected */
447#define SI_USER 0 /* sent by kill, sigsend, raise */
448#define SI_QUEUE -1 /* sent by sigqueue */
449#define SI_TIMER -2 /* sent by timer expiration */
450#define SI_MESGQ -3 /* sent by real time mesq state change */
451#define SI_ASYNCIO -4 /* sent by AIO completion */
Roland McGrath941b7402003-05-23 00:29:02 +0000452#define SI_SIGIO -5 /* Sent by SIGIO */
453#define SI_TKILL -6 /* Sent by tkill */
John Hughes58265892001-10-18 15:13:53 +0000454#endif
455
456#if __GLIBC_MINOR__ < 1
457/* Type for data associated with a signal. */
458typedef union sigval
459{
460 int sival_int;
461 void *sival_ptr;
462} sigval_t;
463
464# define __SI_MAX_SIZE 128
465# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
466
467typedef struct siginfo
468{
469 int si_signo; /* Signal number. */
470 int si_errno; /* If non-zero, an errno value associated with
471 this signal, as defined in <errno.h>. */
472 int si_code; /* Signal code. */
473
474 union
475 {
476 int _pad[__SI_PAD_SIZE];
477
478 /* kill(). */
479 struct
480 {
481 __pid_t si_pid; /* Sending process ID. */
482 __uid_t si_uid; /* Real user ID of sending process. */
483 } _kill;
484
485 /* POSIX.1b timers. */
486 struct
487 {
488 unsigned int _timer1;
489 unsigned int _timer2;
490 } _timer;
491
492 /* POSIX.1b signals. */
493 struct
494 {
495 __pid_t si_pid; /* Sending process ID. */
496 __uid_t si_uid; /* Real user ID of sending process. */
497 sigval_t si_sigval; /* Signal value. */
498 } _rt;
499
500 /* SIGCHLD. */
501 struct
502 {
503 __pid_t si_pid; /* Which child. */
504 int si_status; /* Exit value or signal. */
505 __clock_t si_utime;
506 __clock_t si_stime;
507 } _sigchld;
508
509 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
510 struct
511 {
512 void *si_addr; /* Faulting insn/memory ref. */
513 } _sigfault;
514
515 /* SIGPOLL. */
516 struct
517 {
518 int si_band; /* Band event for SIGPOLL. */
519 int si_fd;
520 } _sigpoll;
521 } _sifields;
522} siginfo_t;
523
524#define si_pid _sifields._kill.si_pid
525#define si_uid _sifields._kill.si_uid
526#define si_status _sifields._sigchld.si_status
527#define si_utime _sifields._sigchld.si_utime
528#define si_stime _sifields._sigchld.si_stime
529#define si_value _sifields._rt.si_sigval
530#define si_int _sifields._rt.si_sigval.sival_int
531#define si_ptr _sifields._rt.si_sigval.sival_ptr
532#define si_addr _sifields._sigfault.si_addr
533#define si_band _sifields._sigpoll.si_band
534#define si_fd _sifields._sigpoll.si_fd
535
536#endif
537
538#endif
539
540#if defined (SVR4) || defined (LINUX)
541
Roland McGrathd9f816f2004-09-04 03:39:20 +0000542static const struct xlat siginfo_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000543#ifdef SI_NOINFO
544 { SI_NOINFO, "SI_NOINFO" },
545#endif
546#ifdef SI_USER
547 { SI_USER, "SI_USER" },
548#endif
549#ifdef SI_LWP
550 { SI_LWP, "SI_LWP" },
551#endif
552#ifdef SI_QUEUE
553 { SI_QUEUE, "SI_QUEUE" },
554#endif
555#ifdef SI_TIMER
556 { SI_TIMER, "SI_TIMER" },
557#endif
558#ifdef SI_ASYNCIO
559 { SI_ASYNCIO, "SI_ASYNCIO" },
560#endif
561#ifdef SI_MESGQ
562 { SI_MESGQ, "SI_MESGQ" },
563#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000564#ifdef SI_SIGIO
565 { SI_SIGIO, "SI_SIGIO" },
566#endif
567#ifdef SI_TKILL
568 { SI_TKILL, "SI_TKILL" },
569#endif
John Hughes58265892001-10-18 15:13:53 +0000570 { 0, NULL },
571};
572
Roland McGrathd9f816f2004-09-04 03:39:20 +0000573static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000574 { ILL_ILLOPC, "ILL_ILLOPC" },
575 { ILL_ILLOPN, "ILL_ILLOPN" },
576 { ILL_ILLADR, "ILL_ILLADR" },
577 { ILL_ILLTRP, "ILL_ILLTRP" },
578 { ILL_PRVOPC, "ILL_PRVOPC" },
579 { ILL_PRVREG, "ILL_PRVREG" },
580 { ILL_COPROC, "ILL_COPROC" },
581 { ILL_BADSTK, "ILL_BADSTK" },
582 { 0, NULL },
583};
584
Roland McGrathd9f816f2004-09-04 03:39:20 +0000585static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000586 { FPE_INTDIV, "FPE_INTDIV" },
587 { FPE_INTOVF, "FPE_INTOVF" },
588 { FPE_FLTDIV, "FPE_FLTDIV" },
589 { FPE_FLTOVF, "FPE_FLTOVF" },
590 { FPE_FLTUND, "FPE_FLTUND" },
591 { FPE_FLTRES, "FPE_FLTRES" },
592 { FPE_FLTINV, "FPE_FLTINV" },
593 { FPE_FLTSUB, "FPE_FLTSUB" },
594 { 0, NULL },
595};
596
Roland McGrathd9f816f2004-09-04 03:39:20 +0000597static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000598 { TRAP_BRKPT, "TRAP_BRKPT" },
599 { TRAP_TRACE, "TRAP_TRACE" },
600 { 0, NULL },
601};
602
Roland McGrathd9f816f2004-09-04 03:39:20 +0000603static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000604 { CLD_EXITED, "CLD_EXITED" },
605 { CLD_KILLED, "CLD_KILLED" },
606 { CLD_DUMPED, "CLD_DUMPED" },
607 { CLD_TRAPPED, "CLD_TRAPPED" },
608 { CLD_STOPPED, "CLD_STOPPED" },
609 { CLD_CONTINUED,"CLD_CONTINUED" },
610 { 0, NULL },
611};
612
Roland McGrathd9f816f2004-09-04 03:39:20 +0000613static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000614 { POLL_IN, "POLL_IN" },
615 { POLL_OUT, "POLL_OUT" },
616 { POLL_MSG, "POLL_MSG" },
617 { POLL_ERR, "POLL_ERR" },
618 { POLL_PRI, "POLL_PRI" },
619 { POLL_HUP, "POLL_HUP" },
620 { 0, NULL },
621};
622
Roland McGrathd9f816f2004-09-04 03:39:20 +0000623static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000624#ifdef PROF_SIG
625 { PROF_SIG, "PROF_SIG" },
626#endif
627 { 0, NULL },
628};
629
630#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000631static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000632#ifdef EMT_TAGOVF
633 { EMT_TAGOVF, "EMT_TAGOVF" },
634#endif
635 { 0, NULL },
636};
637#endif
638
Roland McGrathd9f816f2004-09-04 03:39:20 +0000639static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000640 { SEGV_MAPERR, "SEGV_MAPERR" },
641 { SEGV_ACCERR, "SEGV_ACCERR" },
642 { 0, NULL },
643};
644
Roland McGrathd9f816f2004-09-04 03:39:20 +0000645static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000646 { BUS_ADRALN, "BUS_ADRALN" },
647 { BUS_ADRERR, "BUS_ADRERR" },
648 { BUS_OBJERR, "BUS_OBJERR" },
649 { 0, NULL },
650};
651
652void
653printsiginfo(sip, verbose)
654siginfo_t *sip;
655int verbose;
656{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000657 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000658
659 if (sip->si_signo == 0) {
660 tprintf ("{}");
661 return;
662 }
663 tprintf("{si_signo=");
664 printsignal(sip->si_signo);
665 code = xlookup(siginfo_codes, sip->si_code);
666 if (!code) {
667 switch (sip->si_signo) {
668 case SIGTRAP:
669 code = xlookup(sigtrap_codes, sip->si_code);
670 break;
671 case SIGCHLD:
672 code = xlookup(sigchld_codes, sip->si_code);
673 break;
674 case SIGPOLL:
675 code = xlookup(sigpoll_codes, sip->si_code);
676 break;
677 case SIGPROF:
678 code = xlookup(sigprof_codes, sip->si_code);
679 break;
680 case SIGILL:
681 code = xlookup(sigill_codes, sip->si_code);
682 break;
683#ifdef SIGEMT
684 case SIGEMT:
685 code = xlookup(sigemt_codes, sip->si_code);
686 break;
687#endif
688 case SIGFPE:
689 code = xlookup(sigfpe_codes, sip->si_code);
690 break;
691 case SIGSEGV:
692 code = xlookup(sigsegv_codes, sip->si_code);
693 break;
694 case SIGBUS:
695 code = xlookup(sigbus_codes, sip->si_code);
696 break;
697 }
698 }
699 if (code)
700 tprintf(", si_code=%s", code);
701 else
702 tprintf(", si_code=%#x", sip->si_code);
703#ifdef SI_NOINFO
704 if (sip->si_code != SI_NOINFO)
705#endif
706 {
707 if (sip->si_errno) {
708 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
709 tprintf(", si_errno=%d", sip->si_errno);
710 else
711 tprintf(", si_errno=%s",
712 errnoent[sip->si_errno]);
713 }
714#ifdef SI_FROMUSER
715 if (SI_FROMUSER(sip)) {
716 tprintf(", si_pid=%ld, si_uid=%ld",
717 sip->si_pid, sip->si_uid);
718#ifdef SI_QUEUE
719 switch (sip->si_code) {
720 case SI_QUEUE:
721#ifdef SI_TIMER
722 case SI_TIMER:
723#endif /* SI_QUEUE */
724 case SI_ASYNCIO:
725#ifdef SI_MESGQ
726 case SI_MESGQ:
727#endif /* SI_MESGQ */
728 tprintf(", si_value=%d",
729 sip->si_value.sival_int);
730 break;
731 }
732#endif /* SI_QUEUE */
733 }
734 else
735#endif /* SI_FROMUSER */
736 {
737 switch (sip->si_signo) {
738 case SIGCHLD:
739 tprintf(", si_pid=%ld, si_status=",
740 (long) sip->si_pid);
741 if (sip->si_code == CLD_EXITED)
742 tprintf("%d", sip->si_status);
743 else
744 printsignal(sip->si_status);
745#if LINUX
746 if (!verbose)
747 tprintf(", ...");
748 else
749 tprintf(", si_utime=%lu, si_stime=%lu",
750 sip->si_utime,
751 sip->si_stime);
752#endif
753 break;
754 case SIGILL: case SIGFPE:
755 case SIGSEGV: case SIGBUS:
756 tprintf(", si_addr=%#lx",
757 (unsigned long) sip->si_addr);
758 break;
759 case SIGPOLL:
760 switch (sip->si_code) {
761 case POLL_IN: case POLL_OUT: case POLL_MSG:
762 tprintf(", si_band=%ld",
763 (long) sip->si_band);
764 break;
765 }
766 break;
767#ifdef LINUX
768 default:
769 tprintf(", si_pid=%lu, si_uid=%lu, ",
770 (unsigned long) sip->si_pid,
771 (unsigned long) sip->si_uid);
772 if (!verbose)
773 tprintf("...");
774 else {
775 tprintf("si_value={int=%u, ptr=%#lx}",
776 sip->si_int,
777 (unsigned long) sip->si_ptr);
778 }
779#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000780
John Hughes58265892001-10-18 15:13:53 +0000781 }
782 }
783 }
784 tprintf("}");
785}
786
787#endif /* SVR4 || LINUX */
788
789#ifdef LINUX
790
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000791static void
792parse_sigset_t (const char *str, sigset_t *set)
793{
Roland McGrathc38feca2003-10-01 07:50:28 +0000794 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000795 unsigned int digit;
796 int i;
797
798 sigemptyset(set);
799
Roland McGrathc38feca2003-10-01 07:50:28 +0000800 p = strchr(str, '\n');
801 if (p == NULL)
802 p = strchr(str, '\0');
803 for (i = 0; p-- > str; i += 4) {
804 if (*p >= '0' && *p <= '9')
805 digit = *p - '0';
806 else if (*p >= 'a' && *p <= 'f')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000807 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000808 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000809 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000810 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000811 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000812 if (digit & 1)
813 sigaddset(set, i + 1);
814 if (digit & 2)
815 sigaddset(set, i + 2);
816 if (digit & 4)
817 sigaddset(set, i + 3);
818 if (digit & 8)
819 sigaddset(set, i + 4);
820 }
821}
822
823#endif
824
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000825/*
826 * Check process TCP for the disposition of signal SIG.
827 * Return 1 if the process would somehow manage to survive signal SIG,
828 * else return 0. This routine will never be called with SIGKILL.
829 */
830int
831sigishandled(tcp, sig)
832struct tcb *tcp;
833int sig;
834{
835#ifdef LINUX
836 int sfd;
837 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000838 char buf[2048];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000839 char *s;
840 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000841 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000842#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000843#ifdef SVR4
844 /*
845 * Since procfs doesn't interfere with wait I think it is safe
846 * to punt on this question. If not, the information is there.
847 */
848 return 1;
849#else /* !SVR4 */
850 switch (sig) {
851 case SIGCONT:
852 case SIGSTOP:
853 case SIGTSTP:
854 case SIGTTIN:
855 case SIGTTOU:
856 case SIGCHLD:
857 case SIGIO:
858#if defined(SIGURG) && SIGURG != SIGIO
859 case SIGURG:
860#endif
861 case SIGWINCH:
862 /* Gloria Gaynor says ... */
863 return 1;
864 default:
865 break;
866 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000867#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000868#ifdef LINUX
869
870 /* This is incredibly costly but it's worth it. */
871 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
872 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
873 doesn't handle real-time signals). */
874 sprintf(sname, "/proc/%d/status", tcp->pid);
875 if ((sfd = open(sname, O_RDONLY)) == -1) {
876 perror(sname);
877 return 1;
878 }
879 i = read(sfd, buf, sizeof(buf));
880 buf[i] = '\0';
881 close(sfd);
882 /*
883 * Skip the extraneous fields. We need to skip
884 * command name has any spaces in it. So be it.
885 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000886 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000887 if (!s)
888 {
889 fprintf(stderr, "/proc/pid/status format error\n");
890 return 1;
891 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000892 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000893
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000894 s = strstr(buf, "SigCgt:\t");
895 if (!s)
896 {
897 fprintf(stderr, "/proc/pid/status format error\n");
898 return 1;
899 }
900 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000901
902#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000903 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
904 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000905#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000906 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000907 return 1;
908#endif /* LINUX */
909
910#ifdef SUNOS4
911 void (*u_signal)();
912
913 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
914 (long *) &u_signal) < 0) {
915 return 0;
916 }
917 if (u_signal != SIG_DFL)
918 return 1;
919#endif /* SUNOS4 */
920
921 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000922}
923
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000924#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000925
926int
927sys_sigvec(tcp)
928struct tcb *tcp;
929{
930 struct sigvec sv;
931 long addr;
932
933 if (entering(tcp)) {
934 printsignal(tcp->u_arg[0]);
935 tprintf(", ");
936 addr = tcp->u_arg[1];
937 } else {
938 addr = tcp->u_arg[2];
939 }
940 if (addr == 0)
941 tprintf("NULL");
942 else if (!verbose(tcp))
943 tprintf("%#lx", addr);
944 else if (umove(tcp, addr, &sv) < 0)
945 tprintf("{...}");
946 else {
947 switch ((int) sv.sv_handler) {
948 case (int) SIG_ERR:
949 tprintf("{SIG_ERR}");
950 break;
951 case (int) SIG_DFL:
952 tprintf("{SIG_DFL}");
953 break;
954 case (int) SIG_IGN:
955 if (tcp->u_arg[0] == SIGTRAP) {
956 tcp->flags |= TCB_SIGTRAPPED;
957 kill(tcp->pid, SIGSTOP);
958 }
959 tprintf("{SIG_IGN}");
960 break;
961 case (int) SIG_HOLD:
962 if (tcp->u_arg[0] == SIGTRAP) {
963 tcp->flags |= TCB_SIGTRAPPED;
964 kill(tcp->pid, SIGSTOP);
965 }
966 tprintf("SIG_HOLD");
967 break;
968 default:
969 if (tcp->u_arg[0] == SIGTRAP) {
970 tcp->flags |= TCB_SIGTRAPPED;
971 kill(tcp->pid, SIGSTOP);
972 }
973 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000974 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000976 printflags(sigvec_flags, sv.sv_flags, "SV_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000977 tprintf("}");
978 }
979 }
980 if (entering(tcp))
981 tprintf(", ");
982 return 0;
983}
984
985int
986sys_sigpause(tcp)
987struct tcb *tcp;
988{
989 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000990 sigset_t sigm;
991 long_to_sigset(tcp->u_arg[0], &sigm);
992 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000993 }
994 return 0;
995}
996
997int
998sys_sigstack(tcp)
999struct tcb *tcp;
1000{
1001 struct sigstack ss;
1002 long addr;
1003
1004 if (entering(tcp))
1005 addr = tcp->u_arg[0];
1006 else
1007 addr = tcp->u_arg[1];
1008 if (addr == 0)
1009 tprintf("NULL");
1010 else if (umove(tcp, addr, &ss) < 0)
1011 tprintf("%#lx", addr);
1012 else {
1013 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1014 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1015 }
1016 if (entering(tcp))
1017 tprintf(", ");
1018 return 0;
1019}
1020
1021int
1022sys_sigcleanup(tcp)
1023struct tcb *tcp;
1024{
1025 return 0;
1026}
1027
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001028#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029
1030#ifndef SVR4
1031
1032int
1033sys_sigsetmask(tcp)
1034struct tcb *tcp;
1035{
1036 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001037 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001038 long_to_sigset(tcp->u_arg[0], &sigm);
1039 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001040#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1042 /* Mark attempt to block SIGTRAP */
1043 tcp->flags |= TCB_SIGTRAPPED;
1044 /* Send unblockable signal */
1045 kill(tcp->pid, SIGSTOP);
1046 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001047#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001048 }
1049 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001051 long_to_sigset(tcp->u_rval, &sigm);
1052 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001053
1054 return RVAL_HEX | RVAL_STR;
1055 }
1056 return 0;
1057}
1058
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001059#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001060int
1061sys_sigblock(tcp)
1062struct tcb *tcp;
1063{
1064 return sys_sigsetmask(tcp);
1065}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001066#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001067
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
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001209#ifdef SVR4
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001210int
1211sys_sighold(tcp)
1212struct tcb *tcp;
1213{
1214 if (entering(tcp)) {
1215 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001216 }
1217 return 0;
1218}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001219#endif /* SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001220
1221#endif /* HAVE_SIGACTION */
1222
1223#ifdef LINUX
1224
1225int
1226sys_sigreturn(tcp)
1227struct tcb *tcp;
1228{
Roland McGrath0f87c492003-06-03 23:29:04 +00001229#ifdef ARM
1230 struct pt_regs regs;
1231 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001232
Roland McGrath0f87c492003-06-03 23:29:04 +00001233 if (entering(tcp)) {
1234 tcp->u_arg[0] = 0;
1235
1236 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1237 return 0;
1238
1239 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1240 return 0;
1241
1242 tcp->u_arg[0] = 1;
1243 tcp->u_arg[1] = sc.oldmask;
1244 } else {
1245 sigset_t sigm;
1246 long_to_sigset(tcp->u_arg[1], &sigm);
1247 tcp->u_rval = tcp->u_error = 0;
1248 if (tcp->u_arg[0] == 0)
1249 return 0;
1250 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1251 return RVAL_NONE | RVAL_STR;
1252 }
1253 return 0;
1254#elif defined(S390) || defined(S390X)
1255 long usp;
1256 struct sigcontext_struct sc;
1257
1258 if (entering(tcp)) {
1259 tcp->u_arg[0] = 0;
1260 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1261 return 0;
1262 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1263 return 0;
1264 tcp->u_arg[0] = 1;
1265 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1266 } else {
1267 tcp->u_rval = tcp->u_error = 0;
1268 if (tcp->u_arg[0] == 0)
1269 return 0;
1270 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1271 return RVAL_NONE | RVAL_STR;
1272 }
1273 return 0;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001274#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001275#ifdef I386
1276 long esp;
1277 struct sigcontext_struct sc;
1278
1279 if (entering(tcp)) {
1280 tcp->u_arg[0] = 0;
1281 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1282 return 0;
1283 if (umove(tcp, esp, &sc) < 0)
1284 return 0;
1285 tcp->u_arg[0] = 1;
1286 tcp->u_arg[1] = sc.oldmask;
1287 }
1288 else {
1289 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001290 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001291 tcp->u_rval = tcp->u_error = 0;
1292 if (tcp->u_arg[0] == 0)
1293 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001294 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001295 return RVAL_NONE | RVAL_STR;
1296 }
1297 return 0;
1298#else /* !I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001299#ifdef IA64
1300 struct sigcontext sc;
1301 long sp;
1302
1303 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001304 /* offset of sigcontext in the kernel's sigframe structure: */
1305# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001306 tcp->u_arg[0] = 0;
1307 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1308 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001309 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001310 return 0;
1311 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001312 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001313 }
1314 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001315 sigset_t sigm;
1316
1317 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001318 tcp->u_rval = tcp->u_error = 0;
1319 if (tcp->u_arg[0] == 0)
1320 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001321 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001322 return RVAL_NONE | RVAL_STR;
1323 }
1324 return 0;
1325#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001326#ifdef POWERPC
Roland McGrath0f87c492003-06-03 23:29:04 +00001327 long esp;
1328 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001329
Roland McGrath0f87c492003-06-03 23:29:04 +00001330 if (entering(tcp)) {
1331 tcp->u_arg[0] = 0;
1332 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1333 return 0;
1334 if (umove(tcp, esp, &sc) < 0)
1335 return 0;
1336 tcp->u_arg[0] = 1;
1337 tcp->u_arg[1] = sc.oldmask;
1338 }
1339 else {
1340 sigset_t sigm;
1341 long_to_sigset(tcp->u_arg[1], &sigm);
1342 tcp->u_rval = tcp->u_error = 0;
1343 if (tcp->u_arg[0] == 0)
1344 return 0;
1345 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1346 return RVAL_NONE | RVAL_STR;
1347 }
1348 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001349#else /* !POWERPC */
1350#ifdef M68K
1351 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001352 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001353
1354 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001355 tcp->u_arg[0] = 0;
1356 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001357 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001358 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001359 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001360 tcp->u_arg[0] = 1;
1361 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001362 }
1363 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001364 sigset_t sigm;
1365 long_to_sigset(tcp->u_arg[1], &sigm);
1366 tcp->u_rval = tcp->u_error = 0;
1367 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001368 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001369 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1370 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001371 }
1372 return 0;
1373#else /* !M68K */
1374#ifdef ALPHA
1375 long fp;
1376 struct sigcontext_struct sc;
1377
1378 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001379 tcp->u_arg[0] = 0;
1380 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001381 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001382 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001383 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001384 tcp->u_arg[0] = 1;
1385 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001386 }
1387 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001388 sigset_t sigm;
1389 long_to_sigset(tcp->u_arg[1], &sigm);
1390 tcp->u_rval = tcp->u_error = 0;
1391 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001392 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001393 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1394 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001395 }
1396 return 0;
1397#else
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001398#if defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399 long i1;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001400 struct regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001401 m_siginfo_t si;
1402
1403 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001404 perror("sigreturn: PTRACE_GETREGS ");
1405 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001406 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001407 if(entering(tcp)) {
1408 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001409 i1 = regs.r_o1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001410 if(umove(tcp, i1, &si) < 0) {
1411 perror("sigreturn: umove ");
1412 return 0;
1413 }
1414 tcp->u_arg[0] = 1;
1415 tcp->u_arg[1] = si.si_mask;
1416 } else {
1417 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001418 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001419 tcp->u_rval = tcp->u_error = 0;
1420 if(tcp->u_arg[0] == 0)
1421 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001422 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001423 return RVAL_NONE | RVAL_STR;
1424 }
1425 return 0;
Roland McGratha39c5a12002-12-17 05:10:37 +00001426#else
Wichert Akkermanf90da011999-10-31 21:15:38 +00001427#ifdef MIPS
1428 long sp;
1429 struct sigcontext sc;
1430
1431 if(entering(tcp)) {
1432 tcp->u_arg[0] = 0;
1433 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1434 return 0;
1435 if (umove(tcp, sp, &sc) < 0)
1436 return 0;
1437 tcp->u_arg[0] = 1;
Roland McGrathfece3222007-07-05 19:08:42 +00001438# ifdef HAVE_STRUCT_SIGCONTEXT_SC_HI2
1439 tcp->u_arg[1] = sc.sc_hi2;
1440# else
Wichert Akkermanf90da011999-10-31 21:15:38 +00001441 tcp->u_arg[1] = sc.sc_sigset;
Roland McGrathfece3222007-07-05 19:08:42 +00001442# endif
Wichert Akkermanf90da011999-10-31 21:15:38 +00001443 } else {
1444 tcp->u_rval = tcp->u_error = 0;
1445 if(tcp->u_arg[0] == 0)
1446 return 0;
1447 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1448 return RVAL_NONE | RVAL_STR;
1449 }
1450 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001451#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001452#warning No sys_sigreturn() for this architecture
1453#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001454 return 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001455#endif /* MIPS */
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001456#endif /* SPARC || SPARC64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001457#endif /* ALPHA */
1458#endif /* !M68K */
1459#endif /* !POWERPC */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001460#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001461#endif /* !I386 */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001462#endif /* S390 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001463}
1464
1465int
1466sys_siggetmask(tcp)
1467struct tcb *tcp;
1468{
1469 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001470 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001471 long_to_sigset(tcp->u_rval, &sigm);
1472 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001473 }
1474 return RVAL_HEX | RVAL_STR;
1475}
1476
1477int
1478sys_sigsuspend(tcp)
1479struct tcb *tcp;
1480{
1481 if (entering(tcp)) {
1482 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001483 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001484#if 0
1485 /* first two are not really arguments, but print them anyway */
1486 /* nevermind, they are an anachronism now, too bad... */
1487 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1488#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001489 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001490 }
1491 return 0;
1492}
1493
1494#endif /* LINUX */
1495
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001496#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001497
1498int
1499sys_sigsuspend(tcp)
1500struct tcb *tcp;
1501{
1502 sigset_t sigset;
1503
1504 if (entering(tcp)) {
1505 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1506 tprintf("[?]");
1507 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001508 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001509 }
1510 return 0;
1511}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001512#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001513static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001514 { UC_SIGMASK, "UC_SIGMASK" },
1515 { UC_STACK, "UC_STACK" },
1516 { UC_CPU, "UC_CPU" },
1517#ifdef UC_FPU
1518 { UC_FPU, "UC_FPU" },
1519#endif
1520#ifdef UC_INTR
1521 { UC_INTR, "UC_INTR" },
1522#endif
1523 { 0, NULL },
1524};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001525#endif /* !FREEBSD */
1526#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001527
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001528#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001529#if defined LINUX && !defined SS_ONSTACK
1530#define SS_ONSTACK 1
1531#define SS_DISABLE 2
1532#if __GLIBC_MINOR__ == 0
1533typedef struct
1534{
1535 __ptr_t ss_sp;
1536 int ss_flags;
1537 size_t ss_size;
1538} stack_t;
1539#endif
1540#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001541#ifdef FREEBSD
1542#define stack_t struct sigaltstack
1543#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001544
Roland McGrathd9f816f2004-09-04 03:39:20 +00001545static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001546 { SS_ONSTACK, "SS_ONSTACK" },
1547 { SS_DISABLE, "SS_DISABLE" },
1548 { 0, NULL },
1549};
1550#endif
1551
1552#ifdef SVR4
1553static void
1554printcontext(tcp, ucp)
1555struct tcb *tcp;
1556ucontext_t *ucp;
1557{
1558 tprintf("{");
1559 if (!abbrev(tcp)) {
1560 tprintf("uc_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001561 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001562 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1563 }
1564 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001565 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001566 if (!abbrev(tcp)) {
1567 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1568 (unsigned long) ucp->uc_stack.ss_sp,
1569 ucp->uc_stack.ss_size);
Roland McGrathb2dee132005-06-01 19:02:36 +00001570 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001571 tprintf("}");
1572 }
1573 tprintf(", ...}");
1574}
1575
1576int
1577sys_getcontext(tcp)
1578struct tcb *tcp;
1579{
1580 ucontext_t uc;
1581
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001582 if (exiting(tcp)) {
1583 if (tcp->u_error)
1584 tprintf("%#lx", tcp->u_arg[0]);
1585 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001586 tprintf("NULL");
1587 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1588 tprintf("{...}");
1589 else
1590 printcontext(tcp, &uc);
1591 }
1592 return 0;
1593}
1594
1595int
1596sys_setcontext(tcp)
1597struct tcb *tcp;
1598{
1599 ucontext_t uc;
1600
1601 if (entering(tcp)) {
1602 if (!tcp->u_arg[0])
1603 tprintf("NULL");
1604 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1605 tprintf("{...}");
1606 else
1607 printcontext(tcp, &uc);
1608 }
1609 else {
1610 tcp->u_rval = tcp->u_error = 0;
1611 if (tcp->u_arg[0] == 0)
1612 return 0;
1613 return RVAL_NONE;
1614 }
1615 return 0;
1616}
1617
1618#endif /* SVR4 */
1619
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001620#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621
1622static int
1623print_stack_t(tcp, addr)
1624struct tcb *tcp;
1625unsigned long addr;
1626{
1627 stack_t ss;
1628 if (umove(tcp, addr, &ss) < 0)
1629 return -1;
1630 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
Roland McGrathb2dee132005-06-01 19:02:36 +00001631 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001632 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1633 return 0;
1634}
1635
1636int
1637sys_sigaltstack(tcp)
1638 struct tcb *tcp;
1639{
1640 if (entering(tcp)) {
1641 if (tcp->u_arg[0] == 0)
1642 tprintf("NULL");
1643 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1644 return -1;
1645 }
1646 else {
1647 tprintf(", ");
1648 if (tcp->u_arg[1] == 0)
1649 tprintf("NULL");
1650 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1651 return -1;
1652 }
1653 return 0;
1654}
1655#endif
1656
1657#ifdef HAVE_SIGACTION
1658
1659int
1660sys_sigprocmask(tcp)
1661struct tcb *tcp;
1662{
1663#ifdef ALPHA
1664 if (entering(tcp)) {
1665 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1666 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001667 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001668 }
1669 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001670 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001671 return RVAL_HEX | RVAL_STR;
1672 }
1673#else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001674 if (entering(tcp)) {
1675#ifdef SVR4
1676 if (tcp->u_arg[0] == 0)
1677 tprintf("0");
1678 else
1679#endif /* SVR4 */
1680 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1681 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001682 print_sigset(tcp, tcp->u_arg[1], 0);
1683 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001684 }
1685 else {
1686 if (!tcp->u_arg[2])
1687 tprintf("NULL");
1688 else if (syserror(tcp))
1689 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001690 else
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001691 print_sigset(tcp, tcp->u_arg[2], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001692 }
1693#endif /* !ALPHA */
1694 return 0;
1695}
1696
1697#endif /* HAVE_SIGACTION */
1698
1699int
1700sys_kill(tcp)
1701struct tcb *tcp;
1702{
1703 if (entering(tcp)) {
Nate Sammonsce780fc1999-03-29 23:23:13 +00001704 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001705 }
1706 return 0;
1707}
1708
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001709#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001710int
1711sys_killpg(tcp)
1712struct tcb *tcp;
1713{
1714 return sys_kill(tcp);
1715}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001716#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001717
Roland McGrath8ffc3522003-07-09 09:47:49 +00001718#ifdef LINUX
1719int
1720sys_tgkill(tcp)
1721 struct tcb *tcp;
1722{
1723 if (entering(tcp)) {
1724 tprintf("%ld, %ld, %s",
1725 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1726 }
1727 return 0;
1728}
1729#endif
1730
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001731int
1732sys_sigpending(tcp)
1733struct tcb *tcp;
1734{
1735 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001736
1737 if (exiting(tcp)) {
1738 if (syserror(tcp))
1739 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001740 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001741 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001742 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001743 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001744 }
1745 return 0;
1746}
1747
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001748#ifdef SVR4
John Hughes42162082001-10-18 14:48:26 +00001749int sys_sigwait(tcp)
1750struct tcb *tcp;
1751{
1752 sigset_t sigset;
1753
1754 if (entering(tcp)) {
1755 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1756 tprintf("[?]");
1757 else
1758 printsigmask(&sigset, 0);
1759 }
1760 else {
1761 if (!syserror(tcp)) {
1762 tcp->auxstr = signalent[tcp->u_rval];
1763 return RVAL_DECIMAL | RVAL_STR;
1764 }
1765 }
1766 return 0;
1767}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001768#endif /* SVR4 */
John Hughes42162082001-10-18 14:48:26 +00001769
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001770#ifdef LINUX
1771
1772 int
1773sys_rt_sigprocmask(tcp)
1774 struct tcb *tcp;
1775{
1776 sigset_t sigset;
1777
Nate Sammons4a121431999-04-06 01:19:39 +00001778 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001779 if (entering(tcp)) {
1780 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1781 tprintf(", ");
1782 if (!tcp->u_arg[1])
1783 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001784 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001785 tprintf("%#lx, ", tcp->u_arg[1]);
1786 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001787 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001788 tprintf(", ");
1789 }
1790 }
1791 else {
1792 if (!tcp->u_arg[2])
1793
1794 tprintf("NULL");
1795 else if (syserror(tcp))
1796 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001797 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001798 tprintf("[?]");
1799 else
Nate Sammons4a121431999-04-06 01:19:39 +00001800 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001801 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001802 }
1803 return 0;
1804}
1805
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001806
1807/* Structure describing the action to be taken when a signal arrives. */
1808struct new_sigaction
1809{
1810 union
1811 {
1812 __sighandler_t __sa_handler;
1813 void (*__sa_sigaction) (int, siginfo_t *, void *);
1814 }
1815 __sigaction_handler;
1816 unsigned long sa_flags;
1817 void (*sa_restorer) (void);
1818 unsigned long int sa_mask[2];
1819};
1820
1821
1822 int
1823sys_rt_sigaction(tcp)
1824 struct tcb *tcp;
1825{
1826 struct new_sigaction sa;
1827 sigset_t sigset;
1828 long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001829
1830 if (entering(tcp)) {
1831 printsignal(tcp->u_arg[0]);
1832 tprintf(", ");
1833 addr = tcp->u_arg[1];
1834 } else
1835 addr = tcp->u_arg[2];
1836 if (addr == 0)
1837 tprintf("NULL");
1838 else if (!verbose(tcp))
1839 tprintf("%#lx", addr);
1840 else if (umove(tcp, addr, &sa) < 0)
1841 tprintf("{...}");
1842 else {
1843 switch ((long) sa.__sigaction_handler.__sa_handler) {
1844 case (long) SIG_ERR:
1845 tprintf("{SIG_ERR}");
1846 break;
1847 case (long) SIG_DFL:
1848 tprintf("{SIG_DFL}");
1849 break;
1850 case (long) SIG_IGN:
1851 tprintf("{SIG_IGN}");
1852 break;
1853 default:
1854 tprintf("{%#lx, ",
1855 (long) sa.__sigaction_handler.__sa_handler);
Nate Sammons4a121431999-04-06 01:19:39 +00001856 sigemptyset(&sigset);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001857#ifdef LINUXSPARC
1858 if (tcp->u_arg[4] <= sizeof(sigset))
1859 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1860#else
Nate Sammons4a121431999-04-06 01:19:39 +00001861 if (tcp->u_arg[3] <= sizeof(sigset))
1862 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001863#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001864 else
1865 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1866 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001867 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001868 printflags(sigact_flags, sa.sa_flags, "SA_???");
Roland McGrath2638cb42002-12-15 23:58:41 +00001869#ifdef SA_RESTORER
1870 if (sa.sa_flags & SA_RESTORER)
1871 tprintf(", %p", sa.sa_restorer);
1872#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001873 tprintf("}");
1874 }
1875 }
1876 if (entering(tcp))
1877 tprintf(", ");
1878 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001879#ifdef LINUXSPARC
1880 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1881#elif defined(ALPHA)
1882 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1883#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001884 tprintf(", %lu", addr = tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001885#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001886 return 0;
1887}
1888
1889 int
1890sys_rt_sigpending(tcp)
1891 struct tcb *tcp;
1892{
1893 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894
1895 if (exiting(tcp)) {
1896 if (syserror(tcp))
1897 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001898 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1899 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001900 tprintf("[?]");
1901 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001902 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001903 }
1904 return 0;
1905}
1906 int
1907sys_rt_sigsuspend(tcp)
1908 struct tcb *tcp;
1909{
1910 if (entering(tcp)) {
1911 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001912 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1913 tprintf("[?]");
1914 else
1915 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001916 }
1917 return 0;
1918}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001919 int
1920sys_rt_sigqueueinfo(tcp)
1921 struct tcb *tcp;
1922{
1923 if (entering(tcp)) {
1924 siginfo_t si;
1925 tprintf("%lu, ", tcp->u_arg[0]);
1926 printsignal(tcp->u_arg[1]);
1927 tprintf(", ");
1928 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1929 tprintf("%#lx", tcp->u_arg[2]);
1930 else
John Hughes58265892001-10-18 15:13:53 +00001931 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001932 }
1933 return 0;
1934}
1935
1936int sys_rt_sigtimedwait(tcp)
1937 struct tcb *tcp;
1938{
1939 if (entering(tcp)) {
1940 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001941
Roland McGratha39c5a12002-12-17 05:10:37 +00001942 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00001943 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001944 tprintf("[?]");
1945 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001946 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001947 tprintf(", ");
1948 }
1949 else {
1950 if (syserror(tcp))
1951 tprintf("%#lx", tcp->u_arg[0]);
1952 else {
1953 siginfo_t si;
1954 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1955 tprintf("%#lx", tcp->u_arg[1]);
1956 else
John Hughes58265892001-10-18 15:13:53 +00001957 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001958 /* XXX For now */
1959 tprintf(", %#lx", tcp->u_arg[2]);
1960 tprintf(", %d", (int) tcp->u_arg[3]);
1961 }
1962 }
1963 return 0;
1964};
1965
Roland McGrath79dcd7a2006-01-12 22:34:50 +00001966int
1967sys_restart_syscall(tcp)
1968struct tcb *tcp;
1969{
1970 if (entering(tcp))
1971 tprintf("<... resuming interrupted call ...>");
1972 return 0;
1973}
1974
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001975#endif /* LINUX */