blob: 27b372e3c37032824edc9cdd98fae140f9cfa75b [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];
270 if (sig < nsignals) {
271 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
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000398#ifdef LINUX
399
John Hughes58265892001-10-18 15:13:53 +0000400#ifndef ILL_ILLOPC
401#define ILL_ILLOPC 1 /* illegal opcode */
402#define ILL_ILLOPN 2 /* illegal operand */
403#define ILL_ILLADR 3 /* illegal addressing mode */
404#define ILL_ILLTRP 4 /* illegal trap */
405#define ILL_PRVOPC 5 /* privileged opcode */
406#define ILL_PRVREG 6 /* privileged register */
407#define ILL_COPROC 7 /* coprocessor error */
408#define ILL_BADSTK 8 /* internal stack error */
409#define FPE_INTDIV 1 /* integer divide by zero */
410#define FPE_INTOVF 2 /* integer overflow */
411#define FPE_FLTDIV 3 /* floating point divide by zero */
412#define FPE_FLTOVF 4 /* floating point overflow */
413#define FPE_FLTUND 5 /* floating point underflow */
414#define FPE_FLTRES 6 /* floating point inexact result */
415#define FPE_FLTINV 7 /* floating point invalid operation */
416#define FPE_FLTSUB 8 /* subscript out of range */
417#define SEGV_MAPERR 1 /* address not mapped to object */
418#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
419#define BUS_ADRALN 1 /* invalid address alignment */
420#define BUS_ADRERR 2 /* non-existant physical address */
421#define BUS_OBJERR 3 /* object specific hardware error */
422#define TRAP_BRKPT 1 /* process breakpoint */
423#define TRAP_TRACE 2 /* process trace trap */
424#define CLD_EXITED 1 /* child has exited */
425#define CLD_KILLED 2 /* child was killed */
426#define CLD_DUMPED 3 /* child terminated abnormally */
427#define CLD_TRAPPED 4 /* traced child has trapped */
428#define CLD_STOPPED 5 /* child has stopped */
429#define CLD_CONTINUED 6 /* stopped child has continued */
430#define POLL_IN 1 /* data input available */
431#define POLL_OUT 2 /* output buffers available */
432#define POLL_MSG 3 /* input message available */
433#define POLL_ERR 4 /* i/o error */
434#define POLL_PRI 5 /* high priority input available */
435#define POLL_HUP 6 /* device disconnected */
436#define SI_USER 0 /* sent by kill, sigsend, raise */
437#define SI_QUEUE -1 /* sent by sigqueue */
438#define SI_TIMER -2 /* sent by timer expiration */
439#define SI_MESGQ -3 /* sent by real time mesq state change */
440#define SI_ASYNCIO -4 /* sent by AIO completion */
Roland McGrath941b7402003-05-23 00:29:02 +0000441#define SI_SIGIO -5 /* Sent by SIGIO */
442#define SI_TKILL -6 /* Sent by tkill */
John Hughes58265892001-10-18 15:13:53 +0000443#endif
444
445#if __GLIBC_MINOR__ < 1
446/* Type for data associated with a signal. */
447typedef union sigval
448{
449 int sival_int;
450 void *sival_ptr;
451} sigval_t;
452
453# define __SI_MAX_SIZE 128
454# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
455
456typedef struct siginfo
457{
458 int si_signo; /* Signal number. */
459 int si_errno; /* If non-zero, an errno value associated with
460 this signal, as defined in <errno.h>. */
461 int si_code; /* Signal code. */
462
463 union
464 {
465 int _pad[__SI_PAD_SIZE];
466
467 /* kill(). */
468 struct
469 {
470 __pid_t si_pid; /* Sending process ID. */
471 __uid_t si_uid; /* Real user ID of sending process. */
472 } _kill;
473
474 /* POSIX.1b timers. */
475 struct
476 {
477 unsigned int _timer1;
478 unsigned int _timer2;
479 } _timer;
480
481 /* POSIX.1b signals. */
482 struct
483 {
484 __pid_t si_pid; /* Sending process ID. */
485 __uid_t si_uid; /* Real user ID of sending process. */
486 sigval_t si_sigval; /* Signal value. */
487 } _rt;
488
489 /* SIGCHLD. */
490 struct
491 {
492 __pid_t si_pid; /* Which child. */
493 int si_status; /* Exit value or signal. */
494 __clock_t si_utime;
495 __clock_t si_stime;
496 } _sigchld;
497
498 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
499 struct
500 {
501 void *si_addr; /* Faulting insn/memory ref. */
502 } _sigfault;
503
504 /* SIGPOLL. */
505 struct
506 {
507 int si_band; /* Band event for SIGPOLL. */
508 int si_fd;
509 } _sigpoll;
510 } _sifields;
511} siginfo_t;
512
513#define si_pid _sifields._kill.si_pid
514#define si_uid _sifields._kill.si_uid
515#define si_status _sifields._sigchld.si_status
516#define si_utime _sifields._sigchld.si_utime
517#define si_stime _sifields._sigchld.si_stime
518#define si_value _sifields._rt.si_sigval
519#define si_int _sifields._rt.si_sigval.sival_int
520#define si_ptr _sifields._rt.si_sigval.sival_ptr
521#define si_addr _sifields._sigfault.si_addr
522#define si_band _sifields._sigpoll.si_band
523#define si_fd _sifields._sigpoll.si_fd
524
525#endif
526
527#endif
528
529#if defined (SVR4) || defined (LINUX)
530
Roland McGrathd9f816f2004-09-04 03:39:20 +0000531static const struct xlat siginfo_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000532#ifdef SI_NOINFO
533 { SI_NOINFO, "SI_NOINFO" },
534#endif
535#ifdef SI_USER
536 { SI_USER, "SI_USER" },
537#endif
538#ifdef SI_LWP
539 { SI_LWP, "SI_LWP" },
540#endif
541#ifdef SI_QUEUE
542 { SI_QUEUE, "SI_QUEUE" },
543#endif
544#ifdef SI_TIMER
545 { SI_TIMER, "SI_TIMER" },
546#endif
547#ifdef SI_ASYNCIO
548 { SI_ASYNCIO, "SI_ASYNCIO" },
549#endif
550#ifdef SI_MESGQ
551 { SI_MESGQ, "SI_MESGQ" },
552#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000553#ifdef SI_SIGIO
554 { SI_SIGIO, "SI_SIGIO" },
555#endif
556#ifdef SI_TKILL
557 { SI_TKILL, "SI_TKILL" },
558#endif
John Hughes58265892001-10-18 15:13:53 +0000559 { 0, NULL },
560};
561
Roland McGrathd9f816f2004-09-04 03:39:20 +0000562static const struct xlat sigill_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000563 { ILL_ILLOPC, "ILL_ILLOPC" },
564 { ILL_ILLOPN, "ILL_ILLOPN" },
565 { ILL_ILLADR, "ILL_ILLADR" },
566 { ILL_ILLTRP, "ILL_ILLTRP" },
567 { ILL_PRVOPC, "ILL_PRVOPC" },
568 { ILL_PRVREG, "ILL_PRVREG" },
569 { ILL_COPROC, "ILL_COPROC" },
570 { ILL_BADSTK, "ILL_BADSTK" },
571 { 0, NULL },
572};
573
Roland McGrathd9f816f2004-09-04 03:39:20 +0000574static const struct xlat sigfpe_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000575 { FPE_INTDIV, "FPE_INTDIV" },
576 { FPE_INTOVF, "FPE_INTOVF" },
577 { FPE_FLTDIV, "FPE_FLTDIV" },
578 { FPE_FLTOVF, "FPE_FLTOVF" },
579 { FPE_FLTUND, "FPE_FLTUND" },
580 { FPE_FLTRES, "FPE_FLTRES" },
581 { FPE_FLTINV, "FPE_FLTINV" },
582 { FPE_FLTSUB, "FPE_FLTSUB" },
583 { 0, NULL },
584};
585
Roland McGrathd9f816f2004-09-04 03:39:20 +0000586static const struct xlat sigtrap_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000587 { TRAP_BRKPT, "TRAP_BRKPT" },
588 { TRAP_TRACE, "TRAP_TRACE" },
589 { 0, NULL },
590};
591
Roland McGrathd9f816f2004-09-04 03:39:20 +0000592static const struct xlat sigchld_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000593 { CLD_EXITED, "CLD_EXITED" },
594 { CLD_KILLED, "CLD_KILLED" },
595 { CLD_DUMPED, "CLD_DUMPED" },
596 { CLD_TRAPPED, "CLD_TRAPPED" },
597 { CLD_STOPPED, "CLD_STOPPED" },
598 { CLD_CONTINUED,"CLD_CONTINUED" },
599 { 0, NULL },
600};
601
Roland McGrathd9f816f2004-09-04 03:39:20 +0000602static const struct xlat sigpoll_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000603 { POLL_IN, "POLL_IN" },
604 { POLL_OUT, "POLL_OUT" },
605 { POLL_MSG, "POLL_MSG" },
606 { POLL_ERR, "POLL_ERR" },
607 { POLL_PRI, "POLL_PRI" },
608 { POLL_HUP, "POLL_HUP" },
609 { 0, NULL },
610};
611
Roland McGrathd9f816f2004-09-04 03:39:20 +0000612static const struct xlat sigprof_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000613#ifdef PROF_SIG
614 { PROF_SIG, "PROF_SIG" },
615#endif
616 { 0, NULL },
617};
618
619#ifdef SIGEMT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000620static const struct xlat sigemt_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000621#ifdef EMT_TAGOVF
622 { EMT_TAGOVF, "EMT_TAGOVF" },
623#endif
624 { 0, NULL },
625};
626#endif
627
Roland McGrathd9f816f2004-09-04 03:39:20 +0000628static const struct xlat sigsegv_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000629 { SEGV_MAPERR, "SEGV_MAPERR" },
630 { SEGV_ACCERR, "SEGV_ACCERR" },
631 { 0, NULL },
632};
633
Roland McGrathd9f816f2004-09-04 03:39:20 +0000634static const struct xlat sigbus_codes[] = {
John Hughes58265892001-10-18 15:13:53 +0000635 { BUS_ADRALN, "BUS_ADRALN" },
636 { BUS_ADRERR, "BUS_ADRERR" },
637 { BUS_OBJERR, "BUS_OBJERR" },
638 { 0, NULL },
639};
640
641void
642printsiginfo(sip, verbose)
643siginfo_t *sip;
644int verbose;
645{
Roland McGrathf9c49b22004-10-06 22:11:54 +0000646 const char *code;
John Hughes58265892001-10-18 15:13:53 +0000647
648 if (sip->si_signo == 0) {
649 tprintf ("{}");
650 return;
651 }
652 tprintf("{si_signo=");
653 printsignal(sip->si_signo);
654 code = xlookup(siginfo_codes, sip->si_code);
655 if (!code) {
656 switch (sip->si_signo) {
657 case SIGTRAP:
658 code = xlookup(sigtrap_codes, sip->si_code);
659 break;
660 case SIGCHLD:
661 code = xlookup(sigchld_codes, sip->si_code);
662 break;
663 case SIGPOLL:
664 code = xlookup(sigpoll_codes, sip->si_code);
665 break;
666 case SIGPROF:
667 code = xlookup(sigprof_codes, sip->si_code);
668 break;
669 case SIGILL:
670 code = xlookup(sigill_codes, sip->si_code);
671 break;
672#ifdef SIGEMT
673 case SIGEMT:
674 code = xlookup(sigemt_codes, sip->si_code);
675 break;
676#endif
677 case SIGFPE:
678 code = xlookup(sigfpe_codes, sip->si_code);
679 break;
680 case SIGSEGV:
681 code = xlookup(sigsegv_codes, sip->si_code);
682 break;
683 case SIGBUS:
684 code = xlookup(sigbus_codes, sip->si_code);
685 break;
686 }
687 }
688 if (code)
689 tprintf(", si_code=%s", code);
690 else
691 tprintf(", si_code=%#x", sip->si_code);
692#ifdef SI_NOINFO
693 if (sip->si_code != SI_NOINFO)
694#endif
695 {
696 if (sip->si_errno) {
697 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
698 tprintf(", si_errno=%d", sip->si_errno);
699 else
700 tprintf(", si_errno=%s",
701 errnoent[sip->si_errno]);
702 }
703#ifdef SI_FROMUSER
704 if (SI_FROMUSER(sip)) {
705 tprintf(", si_pid=%ld, si_uid=%ld",
706 sip->si_pid, sip->si_uid);
707#ifdef SI_QUEUE
708 switch (sip->si_code) {
709 case SI_QUEUE:
710#ifdef SI_TIMER
711 case SI_TIMER:
712#endif /* SI_QUEUE */
713 case SI_ASYNCIO:
714#ifdef SI_MESGQ
715 case SI_MESGQ:
716#endif /* SI_MESGQ */
717 tprintf(", si_value=%d",
718 sip->si_value.sival_int);
719 break;
720 }
721#endif /* SI_QUEUE */
722 }
723 else
724#endif /* SI_FROMUSER */
725 {
726 switch (sip->si_signo) {
727 case SIGCHLD:
728 tprintf(", si_pid=%ld, si_status=",
729 (long) sip->si_pid);
730 if (sip->si_code == CLD_EXITED)
731 tprintf("%d", sip->si_status);
732 else
733 printsignal(sip->si_status);
734#if LINUX
735 if (!verbose)
736 tprintf(", ...");
737 else
738 tprintf(", si_utime=%lu, si_stime=%lu",
739 sip->si_utime,
740 sip->si_stime);
741#endif
742 break;
743 case SIGILL: case SIGFPE:
744 case SIGSEGV: case SIGBUS:
745 tprintf(", si_addr=%#lx",
746 (unsigned long) sip->si_addr);
747 break;
748 case SIGPOLL:
749 switch (sip->si_code) {
750 case POLL_IN: case POLL_OUT: case POLL_MSG:
751 tprintf(", si_band=%ld",
752 (long) sip->si_band);
753 break;
754 }
755 break;
756#ifdef LINUX
757 default:
758 tprintf(", si_pid=%lu, si_uid=%lu, ",
759 (unsigned long) sip->si_pid,
760 (unsigned long) sip->si_uid);
761 if (!verbose)
762 tprintf("...");
763 else {
764 tprintf("si_value={int=%u, ptr=%#lx}",
765 sip->si_int,
766 (unsigned long) sip->si_ptr);
767 }
768#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000769
John Hughes58265892001-10-18 15:13:53 +0000770 }
771 }
772 }
773 tprintf("}");
774}
775
776#endif /* SVR4 || LINUX */
777
778#ifdef LINUX
779
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000780static void
781parse_sigset_t (const char *str, sigset_t *set)
782{
Roland McGrathc38feca2003-10-01 07:50:28 +0000783 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000784 unsigned int digit;
785 int i;
786
787 sigemptyset(set);
788
Roland McGrathc38feca2003-10-01 07:50:28 +0000789 p = strchr(str, '\n');
790 if (p == NULL)
791 p = strchr(str, '\0');
792 for (i = 0; p-- > str; i += 4) {
793 if (*p >= '0' && *p <= '9')
794 digit = *p - '0';
795 else if (*p >= 'a' && *p <= 'f')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000796 digit = *p - 'a' + 10;
Roland McGrathc38feca2003-10-01 07:50:28 +0000797 else if (*p >= 'A' && *p <= 'F')
Roland McGrath92f1d6d2004-08-31 07:03:20 +0000798 digit = *p - 'A' + 10;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000799 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000800 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000801 if (digit & 1)
802 sigaddset(set, i + 1);
803 if (digit & 2)
804 sigaddset(set, i + 2);
805 if (digit & 4)
806 sigaddset(set, i + 3);
807 if (digit & 8)
808 sigaddset(set, i + 4);
809 }
810}
811
812#endif
813
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000814/*
815 * Check process TCP for the disposition of signal SIG.
816 * Return 1 if the process would somehow manage to survive signal SIG,
817 * else return 0. This routine will never be called with SIGKILL.
818 */
819int
820sigishandled(tcp, sig)
821struct tcb *tcp;
822int sig;
823{
824#ifdef LINUX
825 int sfd;
826 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000827 char buf[2048];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000828 char *s;
829 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000830 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000831#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000832#ifdef SVR4
833 /*
834 * Since procfs doesn't interfere with wait I think it is safe
835 * to punt on this question. If not, the information is there.
836 */
837 return 1;
838#else /* !SVR4 */
839 switch (sig) {
840 case SIGCONT:
841 case SIGSTOP:
842 case SIGTSTP:
843 case SIGTTIN:
844 case SIGTTOU:
845 case SIGCHLD:
846 case SIGIO:
847#if defined(SIGURG) && SIGURG != SIGIO
848 case SIGURG:
849#endif
850 case SIGWINCH:
851 /* Gloria Gaynor says ... */
852 return 1;
853 default:
854 break;
855 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000856#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000857#ifdef LINUX
858
859 /* This is incredibly costly but it's worth it. */
860 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
861 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
862 doesn't handle real-time signals). */
863 sprintf(sname, "/proc/%d/status", tcp->pid);
864 if ((sfd = open(sname, O_RDONLY)) == -1) {
865 perror(sname);
866 return 1;
867 }
868 i = read(sfd, buf, sizeof(buf));
869 buf[i] = '\0';
870 close(sfd);
871 /*
872 * Skip the extraneous fields. We need to skip
873 * command name has any spaces in it. So be it.
874 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000875 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000876 if (!s)
877 {
878 fprintf(stderr, "/proc/pid/status format error\n");
879 return 1;
880 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000881 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000882
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000883 s = strstr(buf, "SigCgt:\t");
884 if (!s)
885 {
886 fprintf(stderr, "/proc/pid/status format error\n");
887 return 1;
888 }
889 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000890
891#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000892 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
893 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000894#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000895 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000896 return 1;
897#endif /* LINUX */
898
899#ifdef SUNOS4
900 void (*u_signal)();
901
902 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
903 (long *) &u_signal) < 0) {
904 return 0;
905 }
906 if (u_signal != SIG_DFL)
907 return 1;
908#endif /* SUNOS4 */
909
910 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000911}
912
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000913#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000914
915int
916sys_sigvec(tcp)
917struct tcb *tcp;
918{
919 struct sigvec sv;
920 long addr;
921
922 if (entering(tcp)) {
923 printsignal(tcp->u_arg[0]);
924 tprintf(", ");
925 addr = tcp->u_arg[1];
926 } else {
927 addr = tcp->u_arg[2];
928 }
929 if (addr == 0)
930 tprintf("NULL");
931 else if (!verbose(tcp))
932 tprintf("%#lx", addr);
933 else if (umove(tcp, addr, &sv) < 0)
934 tprintf("{...}");
935 else {
936 switch ((int) sv.sv_handler) {
937 case (int) SIG_ERR:
938 tprintf("{SIG_ERR}");
939 break;
940 case (int) SIG_DFL:
941 tprintf("{SIG_DFL}");
942 break;
943 case (int) SIG_IGN:
944 if (tcp->u_arg[0] == SIGTRAP) {
945 tcp->flags |= TCB_SIGTRAPPED;
946 kill(tcp->pid, SIGSTOP);
947 }
948 tprintf("{SIG_IGN}");
949 break;
950 case (int) SIG_HOLD:
951 if (tcp->u_arg[0] == SIGTRAP) {
952 tcp->flags |= TCB_SIGTRAPPED;
953 kill(tcp->pid, SIGSTOP);
954 }
955 tprintf("SIG_HOLD");
956 break;
957 default:
958 if (tcp->u_arg[0] == SIGTRAP) {
959 tcp->flags |= TCB_SIGTRAPPED;
960 kill(tcp->pid, SIGSTOP);
961 }
962 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000963 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000964 tprintf(", ");
965 if (!printflags(sigvec_flags, sv.sv_flags))
966 tprintf("0");
967 tprintf("}");
968 }
969 }
970 if (entering(tcp))
971 tprintf(", ");
972 return 0;
973}
974
975int
976sys_sigpause(tcp)
977struct tcb *tcp;
978{
979 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000980 sigset_t sigm;
981 long_to_sigset(tcp->u_arg[0], &sigm);
982 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983 }
984 return 0;
985}
986
987int
988sys_sigstack(tcp)
989struct tcb *tcp;
990{
991 struct sigstack ss;
992 long addr;
993
994 if (entering(tcp))
995 addr = tcp->u_arg[0];
996 else
997 addr = tcp->u_arg[1];
998 if (addr == 0)
999 tprintf("NULL");
1000 else if (umove(tcp, addr, &ss) < 0)
1001 tprintf("%#lx", addr);
1002 else {
1003 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1004 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1005 }
1006 if (entering(tcp))
1007 tprintf(", ");
1008 return 0;
1009}
1010
1011int
1012sys_sigcleanup(tcp)
1013struct tcb *tcp;
1014{
1015 return 0;
1016}
1017
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001018#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001019
1020#ifndef SVR4
1021
1022int
1023sys_sigsetmask(tcp)
1024struct tcb *tcp;
1025{
1026 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001027 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001028 long_to_sigset(tcp->u_arg[0], &sigm);
1029 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001030#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1032 /* Mark attempt to block SIGTRAP */
1033 tcp->flags |= TCB_SIGTRAPPED;
1034 /* Send unblockable signal */
1035 kill(tcp->pid, SIGSTOP);
1036 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001037#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001038 }
1039 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001040 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001041 long_to_sigset(tcp->u_rval, &sigm);
1042 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043
1044 return RVAL_HEX | RVAL_STR;
1045 }
1046 return 0;
1047}
1048
1049int
1050sys_sigblock(tcp)
1051struct tcb *tcp;
1052{
1053 return sys_sigsetmask(tcp);
1054}
1055
1056#endif /* !SVR4 */
1057
1058#ifdef HAVE_SIGACTION
1059
1060#ifdef LINUX
1061struct old_sigaction {
1062 __sighandler_t __sa_handler;
1063 unsigned long sa_mask;
1064 unsigned long sa_flags;
1065 void (*sa_restorer)(void);
1066};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001067#define SA_HANDLER __sa_handler
1068#endif /* LINUX */
1069
Roland McGratha39c5a12002-12-17 05:10:37 +00001070#ifndef SA_HANDLER
1071#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072#endif
1073
1074int
1075sys_sigaction(tcp)
1076struct tcb *tcp;
1077{
1078 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001079#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001080 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001081 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001082#else
1083 struct sigaction sa;
1084#endif
1085
1086
1087 if (entering(tcp)) {
1088 printsignal(tcp->u_arg[0]);
1089 tprintf(", ");
1090 addr = tcp->u_arg[1];
1091 } else
1092 addr = tcp->u_arg[2];
1093 if (addr == 0)
1094 tprintf("NULL");
1095 else if (!verbose(tcp))
1096 tprintf("%#lx", addr);
1097 else if (umove(tcp, addr, &sa) < 0)
1098 tprintf("{...}");
1099 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001100 switch ((long) sa.SA_HANDLER) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001101 case (long) SIG_ERR:
1102 tprintf("{SIG_ERR}");
1103 break;
1104 case (long) SIG_DFL:
1105 tprintf("{SIG_DFL}");
1106 break;
1107 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001108#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001109 if (tcp->u_arg[0] == SIGTRAP) {
1110 tcp->flags |= TCB_SIGTRAPPED;
1111 kill(tcp->pid, SIGSTOP);
1112 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001113#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001114 tprintf("{SIG_IGN}");
1115 break;
1116 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001117#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001118 if (tcp->u_arg[0] == SIGTRAP) {
1119 tcp->flags |= TCB_SIGTRAPPED;
1120 kill(tcp->pid, SIGSTOP);
1121 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001122#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001123 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001124#ifndef LINUX
1125 printsigmask (&sa.sa_mask, 0);
1126#else
Nate Sammons4a121431999-04-06 01:19:39 +00001127 long_to_sigset(sa.sa_mask, &sigset);
1128 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001129#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001130 tprintf(", ");
1131 if (!printflags(sigact_flags, sa.sa_flags))
1132 tprintf("0");
Roland McGrath2638cb42002-12-15 23:58:41 +00001133#ifdef SA_RESTORER
1134 if (sa.sa_flags & SA_RESTORER)
1135 tprintf(", %p", sa.sa_restorer);
1136#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001137 tprintf("}");
1138 }
1139 }
1140 if (entering(tcp))
1141 tprintf(", ");
1142#ifdef LINUX
1143 else
1144 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1145#endif
1146 return 0;
1147}
1148
1149int
1150sys_signal(tcp)
1151struct tcb *tcp;
1152{
1153 if (entering(tcp)) {
1154 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001155 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001156 switch (tcp->u_arg[1]) {
1157 case (int) SIG_ERR:
1158 tprintf("SIG_ERR");
1159 break;
1160 case (int) SIG_DFL:
1161 tprintf("SIG_DFL");
1162 break;
1163 case (int) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001164#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001165 if (tcp->u_arg[0] == SIGTRAP) {
1166 tcp->flags |= TCB_SIGTRAPPED;
1167 kill(tcp->pid, SIGSTOP);
1168 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001169#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001170 tprintf("SIG_IGN");
1171 break;
1172 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001173#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001174 if (tcp->u_arg[0] == SIGTRAP) {
1175 tcp->flags |= TCB_SIGTRAPPED;
1176 kill(tcp->pid, SIGSTOP);
1177 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001178#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001179 tprintf("%#lx", tcp->u_arg[1]);
1180 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001181 return 0;
1182 }
1183 else {
1184 switch (tcp->u_rval) {
1185 case (int) SIG_ERR:
1186 tcp->auxstr = "SIG_ERR"; break;
1187 case (int) SIG_DFL:
1188 tcp->auxstr = "SIG_DFL"; break;
1189 case (int) SIG_IGN:
1190 tcp->auxstr = "SIG_IGN"; break;
1191 default:
1192 tcp->auxstr = NULL;
1193 }
1194 return RVAL_HEX | RVAL_STR;
1195 }
1196}
1197
1198int
1199sys_sighold(tcp)
1200struct tcb *tcp;
1201{
1202 if (entering(tcp)) {
1203 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001204 }
1205 return 0;
1206}
1207
1208#endif /* HAVE_SIGACTION */
1209
1210#ifdef LINUX
1211
1212int
1213sys_sigreturn(tcp)
1214struct tcb *tcp;
1215{
Roland McGrath0f87c492003-06-03 23:29:04 +00001216#ifdef ARM
1217 struct pt_regs regs;
1218 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001219
Roland McGrath0f87c492003-06-03 23:29:04 +00001220 if (entering(tcp)) {
1221 tcp->u_arg[0] = 0;
1222
1223 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1224 return 0;
1225
1226 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1227 return 0;
1228
1229 tcp->u_arg[0] = 1;
1230 tcp->u_arg[1] = sc.oldmask;
1231 } else {
1232 sigset_t sigm;
1233 long_to_sigset(tcp->u_arg[1], &sigm);
1234 tcp->u_rval = tcp->u_error = 0;
1235 if (tcp->u_arg[0] == 0)
1236 return 0;
1237 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1238 return RVAL_NONE | RVAL_STR;
1239 }
1240 return 0;
1241#elif defined(S390) || defined(S390X)
1242 long usp;
1243 struct sigcontext_struct sc;
1244
1245 if (entering(tcp)) {
1246 tcp->u_arg[0] = 0;
1247 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1248 return 0;
1249 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1250 return 0;
1251 tcp->u_arg[0] = 1;
1252 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1253 } else {
1254 tcp->u_rval = tcp->u_error = 0;
1255 if (tcp->u_arg[0] == 0)
1256 return 0;
1257 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1258 return RVAL_NONE | RVAL_STR;
1259 }
1260 return 0;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001261#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001262#ifdef I386
1263 long esp;
1264 struct sigcontext_struct sc;
1265
1266 if (entering(tcp)) {
1267 tcp->u_arg[0] = 0;
1268 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1269 return 0;
1270 if (umove(tcp, esp, &sc) < 0)
1271 return 0;
1272 tcp->u_arg[0] = 1;
1273 tcp->u_arg[1] = sc.oldmask;
1274 }
1275 else {
1276 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001277 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001278 tcp->u_rval = tcp->u_error = 0;
1279 if (tcp->u_arg[0] == 0)
1280 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001281 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001282 return RVAL_NONE | RVAL_STR;
1283 }
1284 return 0;
1285#else /* !I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001286#ifdef IA64
1287 struct sigcontext sc;
1288 long sp;
1289
1290 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001291 /* offset of sigcontext in the kernel's sigframe structure: */
1292# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001293 tcp->u_arg[0] = 0;
1294 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1295 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001296 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001297 return 0;
1298 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001299 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001300 }
1301 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001302 sigset_t sigm;
1303
1304 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001305 tcp->u_rval = tcp->u_error = 0;
1306 if (tcp->u_arg[0] == 0)
1307 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001308 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001309 return RVAL_NONE | RVAL_STR;
1310 }
1311 return 0;
1312#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001313#ifdef POWERPC
Roland McGrath0f87c492003-06-03 23:29:04 +00001314 long esp;
1315 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001316
Roland McGrath0f87c492003-06-03 23:29:04 +00001317 if (entering(tcp)) {
1318 tcp->u_arg[0] = 0;
1319 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1320 return 0;
1321 if (umove(tcp, esp, &sc) < 0)
1322 return 0;
1323 tcp->u_arg[0] = 1;
1324 tcp->u_arg[1] = sc.oldmask;
1325 }
1326 else {
1327 sigset_t sigm;
1328 long_to_sigset(tcp->u_arg[1], &sigm);
1329 tcp->u_rval = tcp->u_error = 0;
1330 if (tcp->u_arg[0] == 0)
1331 return 0;
1332 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1333 return RVAL_NONE | RVAL_STR;
1334 }
1335 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001336#else /* !POWERPC */
1337#ifdef M68K
1338 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001339 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001340
1341 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001342 tcp->u_arg[0] = 0;
1343 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001344 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001345 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001346 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001347 tcp->u_arg[0] = 1;
1348 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001349 }
1350 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001351 sigset_t sigm;
1352 long_to_sigset(tcp->u_arg[1], &sigm);
1353 tcp->u_rval = tcp->u_error = 0;
1354 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001355 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001356 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1357 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001358 }
1359 return 0;
1360#else /* !M68K */
1361#ifdef ALPHA
1362 long fp;
1363 struct sigcontext_struct sc;
1364
1365 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001366 tcp->u_arg[0] = 0;
1367 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001368 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001369 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001370 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001371 tcp->u_arg[0] = 1;
1372 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001373 }
1374 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001375 sigset_t sigm;
1376 long_to_sigset(tcp->u_arg[1], &sigm);
1377 tcp->u_rval = tcp->u_error = 0;
1378 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001379 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001380 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1381 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001382 }
1383 return 0;
1384#else
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001385#if defined (SPARC) || defined (SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001386 long i1;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001387 struct regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001388 m_siginfo_t si;
1389
1390 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001391 perror("sigreturn: PTRACE_GETREGS ");
1392 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001394 if(entering(tcp)) {
1395 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001396 i1 = regs.r_o1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001397 if(umove(tcp, i1, &si) < 0) {
1398 perror("sigreturn: umove ");
1399 return 0;
1400 }
1401 tcp->u_arg[0] = 1;
1402 tcp->u_arg[1] = si.si_mask;
1403 } else {
1404 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001405 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001406 tcp->u_rval = tcp->u_error = 0;
1407 if(tcp->u_arg[0] == 0)
1408 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001409 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001410 return RVAL_NONE | RVAL_STR;
1411 }
1412 return 0;
Roland McGratha39c5a12002-12-17 05:10:37 +00001413#else
Wichert Akkermanf90da011999-10-31 21:15:38 +00001414#ifdef MIPS
1415 long sp;
1416 struct sigcontext sc;
1417
1418 if(entering(tcp)) {
1419 tcp->u_arg[0] = 0;
1420 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1421 return 0;
1422 if (umove(tcp, sp, &sc) < 0)
1423 return 0;
1424 tcp->u_arg[0] = 1;
1425 tcp->u_arg[1] = sc.sc_sigset;
1426 } else {
1427 tcp->u_rval = tcp->u_error = 0;
1428 if(tcp->u_arg[0] == 0)
1429 return 0;
1430 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1431 return RVAL_NONE | RVAL_STR;
1432 }
1433 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001434#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001435#warning No sys_sigreturn() for this architecture
1436#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001437 return 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001438#endif /* MIPS */
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001439#endif /* SPARC || SPARC64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001440#endif /* ALPHA */
1441#endif /* !M68K */
1442#endif /* !POWERPC */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001443#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001444#endif /* !I386 */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001445#endif /* S390 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001446}
1447
1448int
1449sys_siggetmask(tcp)
1450struct tcb *tcp;
1451{
1452 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001453 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001454 long_to_sigset(tcp->u_rval, &sigm);
1455 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001456 }
1457 return RVAL_HEX | RVAL_STR;
1458}
1459
1460int
1461sys_sigsuspend(tcp)
1462struct tcb *tcp;
1463{
1464 if (entering(tcp)) {
1465 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001466 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001467#if 0
1468 /* first two are not really arguments, but print them anyway */
1469 /* nevermind, they are an anachronism now, too bad... */
1470 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1471#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001472 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001473 }
1474 return 0;
1475}
1476
1477#endif /* LINUX */
1478
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001479#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001480
1481int
1482sys_sigsuspend(tcp)
1483struct tcb *tcp;
1484{
1485 sigset_t sigset;
1486
1487 if (entering(tcp)) {
1488 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1489 tprintf("[?]");
1490 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001491 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001492 }
1493 return 0;
1494}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001495#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00001496static const struct xlat ucontext_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001497 { UC_SIGMASK, "UC_SIGMASK" },
1498 { UC_STACK, "UC_STACK" },
1499 { UC_CPU, "UC_CPU" },
1500#ifdef UC_FPU
1501 { UC_FPU, "UC_FPU" },
1502#endif
1503#ifdef UC_INTR
1504 { UC_INTR, "UC_INTR" },
1505#endif
1506 { 0, NULL },
1507};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001508#endif /* !FREEBSD */
1509#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001510
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001511#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001512#if defined LINUX && !defined SS_ONSTACK
1513#define SS_ONSTACK 1
1514#define SS_DISABLE 2
1515#if __GLIBC_MINOR__ == 0
1516typedef struct
1517{
1518 __ptr_t ss_sp;
1519 int ss_flags;
1520 size_t ss_size;
1521} stack_t;
1522#endif
1523#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001524#ifdef FREEBSD
1525#define stack_t struct sigaltstack
1526#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001527
Roland McGrathd9f816f2004-09-04 03:39:20 +00001528static const struct xlat sigaltstack_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001529 { SS_ONSTACK, "SS_ONSTACK" },
1530 { SS_DISABLE, "SS_DISABLE" },
1531 { 0, NULL },
1532};
1533#endif
1534
1535#ifdef SVR4
1536static void
1537printcontext(tcp, ucp)
1538struct tcb *tcp;
1539ucontext_t *ucp;
1540{
1541 tprintf("{");
1542 if (!abbrev(tcp)) {
1543 tprintf("uc_flags=");
1544 if (!printflags(ucontext_flags, ucp->uc_flags))
1545 tprintf("0");
1546 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1547 }
1548 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001549 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001550 if (!abbrev(tcp)) {
1551 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1552 (unsigned long) ucp->uc_stack.ss_sp,
1553 ucp->uc_stack.ss_size);
1554 if (!printflags(sigaltstack_flags, ucp->uc_stack.ss_flags))
1555 tprintf("0");
1556 tprintf("}");
1557 }
1558 tprintf(", ...}");
1559}
1560
1561int
1562sys_getcontext(tcp)
1563struct tcb *tcp;
1564{
1565 ucontext_t uc;
1566
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001567 if (exiting(tcp)) {
1568 if (tcp->u_error)
1569 tprintf("%#lx", tcp->u_arg[0]);
1570 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001571 tprintf("NULL");
1572 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1573 tprintf("{...}");
1574 else
1575 printcontext(tcp, &uc);
1576 }
1577 return 0;
1578}
1579
1580int
1581sys_setcontext(tcp)
1582struct tcb *tcp;
1583{
1584 ucontext_t uc;
1585
1586 if (entering(tcp)) {
1587 if (!tcp->u_arg[0])
1588 tprintf("NULL");
1589 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1590 tprintf("{...}");
1591 else
1592 printcontext(tcp, &uc);
1593 }
1594 else {
1595 tcp->u_rval = tcp->u_error = 0;
1596 if (tcp->u_arg[0] == 0)
1597 return 0;
1598 return RVAL_NONE;
1599 }
1600 return 0;
1601}
1602
1603#endif /* SVR4 */
1604
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001605#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001606
1607static int
1608print_stack_t(tcp, addr)
1609struct tcb *tcp;
1610unsigned long addr;
1611{
1612 stack_t ss;
1613 if (umove(tcp, addr, &ss) < 0)
1614 return -1;
1615 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1616 if (!printflags(sigaltstack_flags, ss.ss_flags))
1617 tprintf("0");
1618 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1619 return 0;
1620}
1621
1622int
1623sys_sigaltstack(tcp)
1624 struct tcb *tcp;
1625{
1626 if (entering(tcp)) {
1627 if (tcp->u_arg[0] == 0)
1628 tprintf("NULL");
1629 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1630 return -1;
1631 }
1632 else {
1633 tprintf(", ");
1634 if (tcp->u_arg[1] == 0)
1635 tprintf("NULL");
1636 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1637 return -1;
1638 }
1639 return 0;
1640}
1641#endif
1642
1643#ifdef HAVE_SIGACTION
1644
1645int
1646sys_sigprocmask(tcp)
1647struct tcb *tcp;
1648{
1649#ifdef ALPHA
1650 if (entering(tcp)) {
1651 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1652 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001653 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001654 }
1655 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001656 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001657 return RVAL_HEX | RVAL_STR;
1658 }
1659#else /* !ALPHA */
1660 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001661
1662 if (entering(tcp)) {
1663#ifdef SVR4
1664 if (tcp->u_arg[0] == 0)
1665 tprintf("0");
1666 else
1667#endif /* SVR4 */
1668 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1669 tprintf(", ");
1670 if (!tcp->u_arg[1])
1671 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001672 else if (copy_sigset(tcp, tcp->u_arg[1], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001673 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001674 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001675 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001676 tprintf(", ");
1677 }
1678 }
1679 else {
1680 if (!tcp->u_arg[2])
1681 tprintf("NULL");
1682 else if (syserror(tcp))
1683 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001684 else if (copy_sigset(tcp, tcp->u_arg[2], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001685 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001686 else
Nate Sammons4a121431999-04-06 01:19:39 +00001687 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001688 }
1689#endif /* !ALPHA */
1690 return 0;
1691}
1692
1693#endif /* HAVE_SIGACTION */
1694
1695int
1696sys_kill(tcp)
1697struct tcb *tcp;
1698{
1699 if (entering(tcp)) {
Nate Sammonsce780fc1999-03-29 23:23:13 +00001700 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001701 }
1702 return 0;
1703}
1704
1705int
1706sys_killpg(tcp)
1707struct tcb *tcp;
1708{
1709 return sys_kill(tcp);
1710}
1711
Roland McGrath8ffc3522003-07-09 09:47:49 +00001712#ifdef LINUX
1713int
1714sys_tgkill(tcp)
1715 struct tcb *tcp;
1716{
1717 if (entering(tcp)) {
1718 tprintf("%ld, %ld, %s",
1719 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1720 }
1721 return 0;
1722}
1723#endif
1724
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001725int
1726sys_sigpending(tcp)
1727struct tcb *tcp;
1728{
1729 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001730
1731 if (exiting(tcp)) {
1732 if (syserror(tcp))
1733 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001734 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001735 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001736 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001737 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001738 }
1739 return 0;
1740}
1741
John Hughes42162082001-10-18 14:48:26 +00001742int sys_sigwait(tcp)
1743struct tcb *tcp;
1744{
1745 sigset_t sigset;
1746
1747 if (entering(tcp)) {
1748 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1749 tprintf("[?]");
1750 else
1751 printsigmask(&sigset, 0);
1752 }
1753 else {
1754 if (!syserror(tcp)) {
1755 tcp->auxstr = signalent[tcp->u_rval];
1756 return RVAL_DECIMAL | RVAL_STR;
1757 }
1758 }
1759 return 0;
1760}
1761
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001762#ifdef LINUX
1763
1764 int
1765sys_rt_sigprocmask(tcp)
1766 struct tcb *tcp;
1767{
1768 sigset_t sigset;
1769
Nate Sammons4a121431999-04-06 01:19:39 +00001770 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001771 if (entering(tcp)) {
1772 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1773 tprintf(", ");
1774 if (!tcp->u_arg[1])
1775 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001776 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001777 tprintf("%#lx, ", tcp->u_arg[1]);
1778 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001779 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001780 tprintf(", ");
1781 }
1782 }
1783 else {
1784 if (!tcp->u_arg[2])
1785
1786 tprintf("NULL");
1787 else if (syserror(tcp))
1788 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001789 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001790 tprintf("[?]");
1791 else
Nate Sammons4a121431999-04-06 01:19:39 +00001792 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001793 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001794 }
1795 return 0;
1796}
1797
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001798
1799/* Structure describing the action to be taken when a signal arrives. */
1800struct new_sigaction
1801{
1802 union
1803 {
1804 __sighandler_t __sa_handler;
1805 void (*__sa_sigaction) (int, siginfo_t *, void *);
1806 }
1807 __sigaction_handler;
1808 unsigned long sa_flags;
1809 void (*sa_restorer) (void);
1810 unsigned long int sa_mask[2];
1811};
1812
1813
1814 int
1815sys_rt_sigaction(tcp)
1816 struct tcb *tcp;
1817{
1818 struct new_sigaction sa;
1819 sigset_t sigset;
1820 long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001821
1822 if (entering(tcp)) {
1823 printsignal(tcp->u_arg[0]);
1824 tprintf(", ");
1825 addr = tcp->u_arg[1];
1826 } else
1827 addr = tcp->u_arg[2];
1828 if (addr == 0)
1829 tprintf("NULL");
1830 else if (!verbose(tcp))
1831 tprintf("%#lx", addr);
1832 else if (umove(tcp, addr, &sa) < 0)
1833 tprintf("{...}");
1834 else {
1835 switch ((long) sa.__sigaction_handler.__sa_handler) {
1836 case (long) SIG_ERR:
1837 tprintf("{SIG_ERR}");
1838 break;
1839 case (long) SIG_DFL:
1840 tprintf("{SIG_DFL}");
1841 break;
1842 case (long) SIG_IGN:
1843 tprintf("{SIG_IGN}");
1844 break;
1845 default:
1846 tprintf("{%#lx, ",
1847 (long) sa.__sigaction_handler.__sa_handler);
Nate Sammons4a121431999-04-06 01:19:39 +00001848 sigemptyset(&sigset);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001849#ifdef LINUXSPARC
1850 if (tcp->u_arg[4] <= sizeof(sigset))
1851 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1852#else
Nate Sammons4a121431999-04-06 01:19:39 +00001853 if (tcp->u_arg[3] <= sizeof(sigset))
1854 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001855#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001856 else
1857 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1858 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001859 tprintf(", ");
1860 if (!printflags(sigact_flags, sa.sa_flags))
1861 tprintf("0");
Roland McGrath2638cb42002-12-15 23:58:41 +00001862#ifdef SA_RESTORER
1863 if (sa.sa_flags & SA_RESTORER)
1864 tprintf(", %p", sa.sa_restorer);
1865#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866 tprintf("}");
1867 }
1868 }
1869 if (entering(tcp))
1870 tprintf(", ");
1871 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001872#ifdef LINUXSPARC
1873 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1874#elif defined(ALPHA)
1875 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1876#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001877 tprintf(", %lu", addr = tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001878#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001879 return 0;
1880}
1881
1882 int
1883sys_rt_sigpending(tcp)
1884 struct tcb *tcp;
1885{
1886 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001887
1888 if (exiting(tcp)) {
1889 if (syserror(tcp))
1890 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001891 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1892 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001893 tprintf("[?]");
1894 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001895 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001896 }
1897 return 0;
1898}
1899 int
1900sys_rt_sigsuspend(tcp)
1901 struct tcb *tcp;
1902{
1903 if (entering(tcp)) {
1904 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001905 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1906 tprintf("[?]");
1907 else
1908 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001909 }
1910 return 0;
1911}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001912 int
1913sys_rt_sigqueueinfo(tcp)
1914 struct tcb *tcp;
1915{
1916 if (entering(tcp)) {
1917 siginfo_t si;
1918 tprintf("%lu, ", tcp->u_arg[0]);
1919 printsignal(tcp->u_arg[1]);
1920 tprintf(", ");
1921 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1922 tprintf("%#lx", tcp->u_arg[2]);
1923 else
John Hughes58265892001-10-18 15:13:53 +00001924 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001925 }
1926 return 0;
1927}
1928
1929int sys_rt_sigtimedwait(tcp)
1930 struct tcb *tcp;
1931{
1932 if (entering(tcp)) {
1933 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001934
Roland McGratha39c5a12002-12-17 05:10:37 +00001935 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00001936 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001937 tprintf("[?]");
1938 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001939 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001940 tprintf(", ");
1941 }
1942 else {
1943 if (syserror(tcp))
1944 tprintf("%#lx", tcp->u_arg[0]);
1945 else {
1946 siginfo_t si;
1947 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1948 tprintf("%#lx", tcp->u_arg[1]);
1949 else
John Hughes58265892001-10-18 15:13:53 +00001950 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001951 /* XXX For now */
1952 tprintf(", %#lx", tcp->u_arg[2]);
1953 tprintf(", %d", (int) tcp->u_arg[3]);
1954 }
1955 }
1956 return 0;
1957};
1958
1959#endif /* LINUX */