blob: 0dbc3e9f20a032494df7e2f0926019e337bcd8f3 [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
56#include <linux/ptrace.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000057#endif
Wichert Akkerman36915a11999-07-13 15:45:02 +000058
Wichert Akkermanfaf72222000-02-19 23:59:03 +000059
Wichert Akkerman36915a11999-07-13 15:45:02 +000060#ifdef LINUX
61
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000062#ifdef IA64
63# include <asm/ptrace_offsets.h>
64#endif /* !IA64 */
65
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000066#if HAVE_ASM_REG_H
Roland McGrath30ff45e2003-01-30 20:15:23 +000067# ifdef SPARC
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000068# define fpq kernel_fpq
69# define fq kernel_fq
70# define fpu kernel_fpu
Roland McGrath30ff45e2003-01-30 20:15:23 +000071# endif
72# include <asm/reg.h>
73# ifdef SPARC
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000074# undef fpq
75# undef fq
Roland McGratha39c5a12002-12-17 05:10:37 +000076# undef fpu
Roland McGrath30ff45e2003-01-30 20:15:23 +000077# endif
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000078#endif /* HAVE_ASM_REG_H */
Roland McGrath30ff45e2003-01-30 20:15:23 +000079
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000080#ifdef SPARC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000081typedef struct {
Wichert Akkerman9ce1a631999-08-29 23:15:07 +000082 struct regs si_regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000083 int si_mask;
84} m_siginfo_t;
Roland McGrath30ff45e2003-01-30 20:15:23 +000085#elif defined HAVE_ASM_SIGCONTEXT_H
86#if !defined(IA64) && !defined(X86_64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000087#include <asm/sigcontext.h>
Roland McGrath30ff45e2003-01-30 20:15:23 +000088#endif /* !IA64 && !X86_64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000089#else /* !HAVE_ASM_SIGCONTEXT_H */
90#ifdef I386
91struct sigcontext_struct {
92 unsigned short gs, __gsh;
93 unsigned short fs, __fsh;
94 unsigned short es, __esh;
95 unsigned short ds, __dsh;
96 unsigned long edi;
97 unsigned long esi;
98 unsigned long ebp;
99 unsigned long esp;
100 unsigned long ebx;
101 unsigned long edx;
102 unsigned long ecx;
103 unsigned long eax;
104 unsigned long trapno;
105 unsigned long err;
106 unsigned long eip;
107 unsigned short cs, __csh;
108 unsigned long eflags;
109 unsigned long esp_at_signal;
110 unsigned short ss, __ssh;
111 unsigned long i387;
112 unsigned long oldmask;
113 unsigned long cr2;
114};
115#else /* !I386 */
116#ifdef M68K
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000117struct sigcontext
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000118{
119 unsigned long sc_mask;
120 unsigned long sc_usp;
121 unsigned long sc_d0;
122 unsigned long sc_d1;
123 unsigned long sc_a0;
124 unsigned long sc_a1;
125 unsigned short sc_sr;
126 unsigned long sc_pc;
127 unsigned short sc_formatvec;
128};
129#endif /* M68K */
130#endif /* !I386 */
131#endif /* !HAVE_ASM_SIGCONTEXT_H */
132#ifndef NSIG
133#define NSIG 32
134#endif
135#ifdef ARM
136#undef NSIG
137#define NSIG 32
138#endif
139#endif /* LINUX */
140
141char *signalent0[] = {
142#include "signalent.h"
143};
144int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
145
146#if SUPPORTED_PERSONALITIES >= 2
147char *signalent1[] = {
148#include "signalent1.h"
149};
150int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
151#endif /* SUPPORTED_PERSONALITIES >= 2 */
152
153#if SUPPORTED_PERSONALITIES >= 3
154char *signalent2[] = {
155#include "signalent2.h"
156};
157int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
158#endif /* SUPPORTED_PERSONALITIES >= 3 */
159
160char **signalent;
161int nsignals;
162
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000163#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164
165static struct xlat sigvec_flags[] = {
166 { SV_ONSTACK, "SV_ONSTACK" },
167 { SV_INTERRUPT, "SV_INTERRUPT" },
168 { SV_RESETHAND, "SV_RESETHAND" },
169 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
170 { 0, NULL },
171};
172
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000173#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174
175#ifdef HAVE_SIGACTION
176
Roland McGrath2638cb42002-12-15 23:58:41 +0000177#if defined LINUX && defined I386
178/* The libc headers do not define this constant since it should only be
179 used by the implementation. So wwe define it here. */
180# ifndef SA_RESTORER
181# define SA_RESTORER 0x04000000
182# endif
183#endif
184
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185static struct xlat sigact_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000186#ifdef SA_RESTORER
187 { SA_RESTORER, "SA_RESTORER" },
188#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000189#ifdef SA_STACK
190 { SA_STACK, "SA_STACK" },
191#endif
192#ifdef SA_RESTART
193 { SA_RESTART, "SA_RESTART" },
194#endif
195#ifdef SA_INTERRUPT
196 { SA_INTERRUPT, "SA_INTERRUPT" },
197#endif
198#ifdef SA_NOMASK
199 { SA_NOMASK, "SA_NOMASK" },
200#endif
201#ifdef SA_ONESHOT
202 { SA_ONESHOT, "SA_ONESHOT" },
203#endif
204#ifdef SA_SIGINFO
205 { SA_SIGINFO, "SA_SIGINFO" },
206#endif
207#ifdef SA_RESETHAND
208 { SA_RESETHAND, "SA_RESETHAND" },
209#endif
210#ifdef SA_ONSTACK
211 { SA_ONSTACK, "SA_ONSTACK" },
212#endif
213#ifdef SA_NODEFER
214 { SA_NODEFER, "SA_NODEFER" },
215#endif
216#ifdef SA_NOCLDSTOP
217 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
218#endif
219#ifdef SA_NOCLDWAIT
220 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
221#endif
222#ifdef _SA_BSDCALL
223 { _SA_BSDCALL, "_SA_BSDCALL" },
224#endif
225 { 0, NULL },
226};
227
228static struct xlat sigprocmaskcmds[] = {
229 { SIG_BLOCK, "SIG_BLOCK" },
230 { SIG_UNBLOCK, "SIG_UNBLOCK" },
231 { SIG_SETMASK, "SIG_SETMASK" },
232#ifdef SIG_SETMASK32
233 { SIG_SETMASK32,"SIG_SETMASK32" },
234#endif
235 { 0, NULL },
236};
237
238#endif /* HAVE_SIGACTION */
239
Nate Sammonsce780fc1999-03-29 23:23:13 +0000240/* Anonymous realtime signals. */
241/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
242 constant. This is what we want. Otherwise, just use SIGRTMIN. */
243#ifdef SIGRTMIN
244#ifndef __SIGRTMIN
245#define __SIGRTMIN SIGRTMIN
246#define __SIGRTMAX SIGRTMAX /* likewise */
247#endif
248#endif
249
250char *
251signame(sig)
252int sig;
253{
254 static char buf[30];
255 if (sig < nsignals) {
256 return signalent[sig];
257#ifdef SIGRTMIN
Nate Sammons3080aa41999-03-30 00:16:41 +0000258 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000259 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000260 return buf;
261#endif /* SIGRTMIN */
262 } else {
263 sprintf(buf, "%d", sig);
264 return buf;
265 }
266}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000268#ifndef UNIXWARE
Nate Sammons4a121431999-04-06 01:19:39 +0000269static void
270long_to_sigset(l, s)
271long l;
272sigset_t *s;
273{
274 sigemptyset(s);
275 *(long *)s = l;
276}
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000277#endif
Nate Sammons4a121431999-04-06 01:19:39 +0000278
279static int
280copy_sigset_len(tcp, addr, s, len)
281struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000282long addr;
Nate Sammons4a121431999-04-06 01:19:39 +0000283sigset_t *s;
284int len;
285{
286 if (len > sizeof(*s))
287 len = sizeof(*s);
288 sigemptyset(s);
289 if (umoven(tcp, addr, len, (char *)s) < 0)
290 return -1;
291 return 0;
292}
293
294#ifdef LINUX
295/* Original sigset is unsigned long */
296#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
297#else
298#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
299#endif
300
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301static char *
Nate Sammons4a121431999-04-06 01:19:39 +0000302sprintsigmask(s, mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000303char *s;
304sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000305int rt; /* set might include realtime sigs */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306{
307 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000308 int maxsigs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000309 char *format;
Roland McGratha39c5a12002-12-17 05:10:37 +0000310 static char outstr[8 * sizeof(sigset_t) * 8];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000311
312 strcpy(outstr, s);
313 s = outstr + strlen(outstr);
314 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000315 maxsigs = nsignals;
316#ifdef __SIGRTMAX
317 if (rt)
318 maxsigs = __SIGRTMAX; /* instead */
319#endif
320 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321 if (sigismember(mask, i) == 1)
322 nsigs++;
323 }
324 if (nsigs >= nsignals * 2 / 3) {
325 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000326 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000327 switch (sigismember(mask, i)) {
328 case 1:
329 sigdelset(mask, i);
330 break;
331 case 0:
332 sigaddset(mask, i);
333 break;
334 }
335 }
336 }
337 format = "%s";
338 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000339 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000340 if (sigismember(mask, i) == 1) {
John Hughesbdf48f52001-03-06 15:08:09 +0000341 /* real-time signals on solaris don't have
342 * signalent entries
343 */
344 if (i < nsignals) {
345 sprintf(s, format, signalent[i] + 3);
346 }
Roland McGrath90b4cb52003-09-23 22:19:32 +0000347#ifdef SIGRTMIN
348 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
349 char tsig[40];
350 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
351 sprintf(s, format, tsig);
352 }
353#endif /* SIGRTMIN */
John Hughesbdf48f52001-03-06 15:08:09 +0000354 else {
355 char tsig[32];
356 sprintf(tsig, "%u", i);
357 sprintf(s, format, tsig);
358 }
359 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000360 format = " %s";
361 }
362 }
363 *s++ = ']';
364 *s = '\0';
365 return outstr;
366}
367
368static void
Nate Sammons4a121431999-04-06 01:19:39 +0000369printsigmask(mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000370sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000371int rt;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372{
Nate Sammons4a121431999-04-06 01:19:39 +0000373 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374}
375
376void
377printsignal(nr)
378int nr;
379{
Nate Sammonsce780fc1999-03-29 23:23:13 +0000380 tprintf(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381}
382
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000383#ifdef LINUX
384
John Hughes58265892001-10-18 15:13:53 +0000385#ifndef ILL_ILLOPC
386#define ILL_ILLOPC 1 /* illegal opcode */
387#define ILL_ILLOPN 2 /* illegal operand */
388#define ILL_ILLADR 3 /* illegal addressing mode */
389#define ILL_ILLTRP 4 /* illegal trap */
390#define ILL_PRVOPC 5 /* privileged opcode */
391#define ILL_PRVREG 6 /* privileged register */
392#define ILL_COPROC 7 /* coprocessor error */
393#define ILL_BADSTK 8 /* internal stack error */
394#define FPE_INTDIV 1 /* integer divide by zero */
395#define FPE_INTOVF 2 /* integer overflow */
396#define FPE_FLTDIV 3 /* floating point divide by zero */
397#define FPE_FLTOVF 4 /* floating point overflow */
398#define FPE_FLTUND 5 /* floating point underflow */
399#define FPE_FLTRES 6 /* floating point inexact result */
400#define FPE_FLTINV 7 /* floating point invalid operation */
401#define FPE_FLTSUB 8 /* subscript out of range */
402#define SEGV_MAPERR 1 /* address not mapped to object */
403#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
404#define BUS_ADRALN 1 /* invalid address alignment */
405#define BUS_ADRERR 2 /* non-existant physical address */
406#define BUS_OBJERR 3 /* object specific hardware error */
407#define TRAP_BRKPT 1 /* process breakpoint */
408#define TRAP_TRACE 2 /* process trace trap */
409#define CLD_EXITED 1 /* child has exited */
410#define CLD_KILLED 2 /* child was killed */
411#define CLD_DUMPED 3 /* child terminated abnormally */
412#define CLD_TRAPPED 4 /* traced child has trapped */
413#define CLD_STOPPED 5 /* child has stopped */
414#define CLD_CONTINUED 6 /* stopped child has continued */
415#define POLL_IN 1 /* data input available */
416#define POLL_OUT 2 /* output buffers available */
417#define POLL_MSG 3 /* input message available */
418#define POLL_ERR 4 /* i/o error */
419#define POLL_PRI 5 /* high priority input available */
420#define POLL_HUP 6 /* device disconnected */
421#define SI_USER 0 /* sent by kill, sigsend, raise */
422#define SI_QUEUE -1 /* sent by sigqueue */
423#define SI_TIMER -2 /* sent by timer expiration */
424#define SI_MESGQ -3 /* sent by real time mesq state change */
425#define SI_ASYNCIO -4 /* sent by AIO completion */
Roland McGrath941b7402003-05-23 00:29:02 +0000426#define SI_SIGIO -5 /* Sent by SIGIO */
427#define SI_TKILL -6 /* Sent by tkill */
John Hughes58265892001-10-18 15:13:53 +0000428#endif
429
430#if __GLIBC_MINOR__ < 1
431/* Type for data associated with a signal. */
432typedef union sigval
433{
434 int sival_int;
435 void *sival_ptr;
436} sigval_t;
437
438# define __SI_MAX_SIZE 128
439# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
440
441typedef struct siginfo
442{
443 int si_signo; /* Signal number. */
444 int si_errno; /* If non-zero, an errno value associated with
445 this signal, as defined in <errno.h>. */
446 int si_code; /* Signal code. */
447
448 union
449 {
450 int _pad[__SI_PAD_SIZE];
451
452 /* kill(). */
453 struct
454 {
455 __pid_t si_pid; /* Sending process ID. */
456 __uid_t si_uid; /* Real user ID of sending process. */
457 } _kill;
458
459 /* POSIX.1b timers. */
460 struct
461 {
462 unsigned int _timer1;
463 unsigned int _timer2;
464 } _timer;
465
466 /* POSIX.1b signals. */
467 struct
468 {
469 __pid_t si_pid; /* Sending process ID. */
470 __uid_t si_uid; /* Real user ID of sending process. */
471 sigval_t si_sigval; /* Signal value. */
472 } _rt;
473
474 /* SIGCHLD. */
475 struct
476 {
477 __pid_t si_pid; /* Which child. */
478 int si_status; /* Exit value or signal. */
479 __clock_t si_utime;
480 __clock_t si_stime;
481 } _sigchld;
482
483 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
484 struct
485 {
486 void *si_addr; /* Faulting insn/memory ref. */
487 } _sigfault;
488
489 /* SIGPOLL. */
490 struct
491 {
492 int si_band; /* Band event for SIGPOLL. */
493 int si_fd;
494 } _sigpoll;
495 } _sifields;
496} siginfo_t;
497
498#define si_pid _sifields._kill.si_pid
499#define si_uid _sifields._kill.si_uid
500#define si_status _sifields._sigchld.si_status
501#define si_utime _sifields._sigchld.si_utime
502#define si_stime _sifields._sigchld.si_stime
503#define si_value _sifields._rt.si_sigval
504#define si_int _sifields._rt.si_sigval.sival_int
505#define si_ptr _sifields._rt.si_sigval.sival_ptr
506#define si_addr _sifields._sigfault.si_addr
507#define si_band _sifields._sigpoll.si_band
508#define si_fd _sifields._sigpoll.si_fd
509
510#endif
511
512#endif
513
514#if defined (SVR4) || defined (LINUX)
515
516static struct xlat siginfo_codes[] = {
517#ifdef SI_NOINFO
518 { SI_NOINFO, "SI_NOINFO" },
519#endif
520#ifdef SI_USER
521 { SI_USER, "SI_USER" },
522#endif
523#ifdef SI_LWP
524 { SI_LWP, "SI_LWP" },
525#endif
526#ifdef SI_QUEUE
527 { SI_QUEUE, "SI_QUEUE" },
528#endif
529#ifdef SI_TIMER
530 { SI_TIMER, "SI_TIMER" },
531#endif
532#ifdef SI_ASYNCIO
533 { SI_ASYNCIO, "SI_ASYNCIO" },
534#endif
535#ifdef SI_MESGQ
536 { SI_MESGQ, "SI_MESGQ" },
537#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000538#ifdef SI_SIGIO
539 { SI_SIGIO, "SI_SIGIO" },
540#endif
541#ifdef SI_TKILL
542 { SI_TKILL, "SI_TKILL" },
543#endif
John Hughes58265892001-10-18 15:13:53 +0000544 { 0, NULL },
545};
546
547static struct xlat sigill_codes[] = {
548 { ILL_ILLOPC, "ILL_ILLOPC" },
549 { ILL_ILLOPN, "ILL_ILLOPN" },
550 { ILL_ILLADR, "ILL_ILLADR" },
551 { ILL_ILLTRP, "ILL_ILLTRP" },
552 { ILL_PRVOPC, "ILL_PRVOPC" },
553 { ILL_PRVREG, "ILL_PRVREG" },
554 { ILL_COPROC, "ILL_COPROC" },
555 { ILL_BADSTK, "ILL_BADSTK" },
556 { 0, NULL },
557};
558
559static struct xlat sigfpe_codes[] = {
560 { FPE_INTDIV, "FPE_INTDIV" },
561 { FPE_INTOVF, "FPE_INTOVF" },
562 { FPE_FLTDIV, "FPE_FLTDIV" },
563 { FPE_FLTOVF, "FPE_FLTOVF" },
564 { FPE_FLTUND, "FPE_FLTUND" },
565 { FPE_FLTRES, "FPE_FLTRES" },
566 { FPE_FLTINV, "FPE_FLTINV" },
567 { FPE_FLTSUB, "FPE_FLTSUB" },
568 { 0, NULL },
569};
570
571static struct xlat sigtrap_codes[] = {
572 { TRAP_BRKPT, "TRAP_BRKPT" },
573 { TRAP_TRACE, "TRAP_TRACE" },
574 { 0, NULL },
575};
576
577static struct xlat sigchld_codes[] = {
578 { CLD_EXITED, "CLD_EXITED" },
579 { CLD_KILLED, "CLD_KILLED" },
580 { CLD_DUMPED, "CLD_DUMPED" },
581 { CLD_TRAPPED, "CLD_TRAPPED" },
582 { CLD_STOPPED, "CLD_STOPPED" },
583 { CLD_CONTINUED,"CLD_CONTINUED" },
584 { 0, NULL },
585};
586
587static struct xlat sigpoll_codes[] = {
588 { POLL_IN, "POLL_IN" },
589 { POLL_OUT, "POLL_OUT" },
590 { POLL_MSG, "POLL_MSG" },
591 { POLL_ERR, "POLL_ERR" },
592 { POLL_PRI, "POLL_PRI" },
593 { POLL_HUP, "POLL_HUP" },
594 { 0, NULL },
595};
596
597static struct xlat sigprof_codes[] = {
598#ifdef PROF_SIG
599 { PROF_SIG, "PROF_SIG" },
600#endif
601 { 0, NULL },
602};
603
604#ifdef SIGEMT
605static struct xlat sigemt_codes[] = {
606#ifdef EMT_TAGOVF
607 { EMT_TAGOVF, "EMT_TAGOVF" },
608#endif
609 { 0, NULL },
610};
611#endif
612
613static struct xlat sigsegv_codes[] = {
614 { SEGV_MAPERR, "SEGV_MAPERR" },
615 { SEGV_ACCERR, "SEGV_ACCERR" },
616 { 0, NULL },
617};
618
619static struct xlat sigbus_codes[] = {
620 { BUS_ADRALN, "BUS_ADRALN" },
621 { BUS_ADRERR, "BUS_ADRERR" },
622 { BUS_OBJERR, "BUS_OBJERR" },
623 { 0, NULL },
624};
625
626void
627printsiginfo(sip, verbose)
628siginfo_t *sip;
629int verbose;
630{
631 char *code;
632
633 if (sip->si_signo == 0) {
634 tprintf ("{}");
635 return;
636 }
637 tprintf("{si_signo=");
638 printsignal(sip->si_signo);
639 code = xlookup(siginfo_codes, sip->si_code);
640 if (!code) {
641 switch (sip->si_signo) {
642 case SIGTRAP:
643 code = xlookup(sigtrap_codes, sip->si_code);
644 break;
645 case SIGCHLD:
646 code = xlookup(sigchld_codes, sip->si_code);
647 break;
648 case SIGPOLL:
649 code = xlookup(sigpoll_codes, sip->si_code);
650 break;
651 case SIGPROF:
652 code = xlookup(sigprof_codes, sip->si_code);
653 break;
654 case SIGILL:
655 code = xlookup(sigill_codes, sip->si_code);
656 break;
657#ifdef SIGEMT
658 case SIGEMT:
659 code = xlookup(sigemt_codes, sip->si_code);
660 break;
661#endif
662 case SIGFPE:
663 code = xlookup(sigfpe_codes, sip->si_code);
664 break;
665 case SIGSEGV:
666 code = xlookup(sigsegv_codes, sip->si_code);
667 break;
668 case SIGBUS:
669 code = xlookup(sigbus_codes, sip->si_code);
670 break;
671 }
672 }
673 if (code)
674 tprintf(", si_code=%s", code);
675 else
676 tprintf(", si_code=%#x", sip->si_code);
677#ifdef SI_NOINFO
678 if (sip->si_code != SI_NOINFO)
679#endif
680 {
681 if (sip->si_errno) {
682 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
683 tprintf(", si_errno=%d", sip->si_errno);
684 else
685 tprintf(", si_errno=%s",
686 errnoent[sip->si_errno]);
687 }
688#ifdef SI_FROMUSER
689 if (SI_FROMUSER(sip)) {
690 tprintf(", si_pid=%ld, si_uid=%ld",
691 sip->si_pid, sip->si_uid);
692#ifdef SI_QUEUE
693 switch (sip->si_code) {
694 case SI_QUEUE:
695#ifdef SI_TIMER
696 case SI_TIMER:
697#endif /* SI_QUEUE */
698 case SI_ASYNCIO:
699#ifdef SI_MESGQ
700 case SI_MESGQ:
701#endif /* SI_MESGQ */
702 tprintf(", si_value=%d",
703 sip->si_value.sival_int);
704 break;
705 }
706#endif /* SI_QUEUE */
707 }
708 else
709#endif /* SI_FROMUSER */
710 {
711 switch (sip->si_signo) {
712 case SIGCHLD:
713 tprintf(", si_pid=%ld, si_status=",
714 (long) sip->si_pid);
715 if (sip->si_code == CLD_EXITED)
716 tprintf("%d", sip->si_status);
717 else
718 printsignal(sip->si_status);
719#if LINUX
720 if (!verbose)
721 tprintf(", ...");
722 else
723 tprintf(", si_utime=%lu, si_stime=%lu",
724 sip->si_utime,
725 sip->si_stime);
726#endif
727 break;
728 case SIGILL: case SIGFPE:
729 case SIGSEGV: case SIGBUS:
730 tprintf(", si_addr=%#lx",
731 (unsigned long) sip->si_addr);
732 break;
733 case SIGPOLL:
734 switch (sip->si_code) {
735 case POLL_IN: case POLL_OUT: case POLL_MSG:
736 tprintf(", si_band=%ld",
737 (long) sip->si_band);
738 break;
739 }
740 break;
741#ifdef LINUX
742 default:
743 tprintf(", si_pid=%lu, si_uid=%lu, ",
744 (unsigned long) sip->si_pid,
745 (unsigned long) sip->si_uid);
746 if (!verbose)
747 tprintf("...");
748 else {
749 tprintf("si_value={int=%u, ptr=%#lx}",
750 sip->si_int,
751 (unsigned long) sip->si_ptr);
752 }
753#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000754
John Hughes58265892001-10-18 15:13:53 +0000755 }
756 }
757 }
758 tprintf("}");
759}
760
761#endif /* SVR4 || LINUX */
762
763#ifdef LINUX
764
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000765static void
766parse_sigset_t (const char *str, sigset_t *set)
767{
Roland McGrathc38feca2003-10-01 07:50:28 +0000768 const char *p;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000769 unsigned int digit;
770 int i;
771
772 sigemptyset(set);
773
Roland McGrathc38feca2003-10-01 07:50:28 +0000774 p = strchr(str, '\n');
775 if (p == NULL)
776 p = strchr(str, '\0');
777 for (i = 0; p-- > str; i += 4) {
778 if (*p >= '0' && *p <= '9')
779 digit = *p - '0';
780 else if (*p >= 'a' && *p <= 'f')
781 digit = *p - 'a';
782 else if (*p >= 'A' && *p <= 'F')
783 digit = *p - 'A';
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000784 else
Roland McGrathc38feca2003-10-01 07:50:28 +0000785 break;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000786 if (digit & 1)
787 sigaddset(set, i + 1);
788 if (digit & 2)
789 sigaddset(set, i + 2);
790 if (digit & 4)
791 sigaddset(set, i + 3);
792 if (digit & 8)
793 sigaddset(set, i + 4);
794 }
795}
796
797#endif
798
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000799/*
800 * Check process TCP for the disposition of signal SIG.
801 * Return 1 if the process would somehow manage to survive signal SIG,
802 * else return 0. This routine will never be called with SIGKILL.
803 */
804int
805sigishandled(tcp, sig)
806struct tcb *tcp;
807int sig;
808{
809#ifdef LINUX
810 int sfd;
811 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000812 char buf[2048];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000813 char *s;
814 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000815 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000816#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000817#ifdef SVR4
818 /*
819 * Since procfs doesn't interfere with wait I think it is safe
820 * to punt on this question. If not, the information is there.
821 */
822 return 1;
823#else /* !SVR4 */
824 switch (sig) {
825 case SIGCONT:
826 case SIGSTOP:
827 case SIGTSTP:
828 case SIGTTIN:
829 case SIGTTOU:
830 case SIGCHLD:
831 case SIGIO:
832#if defined(SIGURG) && SIGURG != SIGIO
833 case SIGURG:
834#endif
835 case SIGWINCH:
836 /* Gloria Gaynor says ... */
837 return 1;
838 default:
839 break;
840 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000841#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000842#ifdef LINUX
843
844 /* This is incredibly costly but it's worth it. */
845 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
846 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
847 doesn't handle real-time signals). */
848 sprintf(sname, "/proc/%d/status", tcp->pid);
849 if ((sfd = open(sname, O_RDONLY)) == -1) {
850 perror(sname);
851 return 1;
852 }
853 i = read(sfd, buf, sizeof(buf));
854 buf[i] = '\0';
855 close(sfd);
856 /*
857 * Skip the extraneous fields. We need to skip
858 * command name has any spaces in it. So be it.
859 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000860 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000861 if (!s)
862 {
863 fprintf(stderr, "/proc/pid/status format error\n");
864 return 1;
865 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000866 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000867
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000868 s = strstr(buf, "SigCgt:\t");
869 if (!s)
870 {
871 fprintf(stderr, "/proc/pid/status format error\n");
872 return 1;
873 }
874 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000875
876#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000877 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
878 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000879#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000880 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000881 return 1;
882#endif /* LINUX */
883
884#ifdef SUNOS4
885 void (*u_signal)();
886
887 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
888 (long *) &u_signal) < 0) {
889 return 0;
890 }
891 if (u_signal != SIG_DFL)
892 return 1;
893#endif /* SUNOS4 */
894
895 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000896}
897
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000898#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899
900int
901sys_sigvec(tcp)
902struct tcb *tcp;
903{
904 struct sigvec sv;
905 long addr;
906
907 if (entering(tcp)) {
908 printsignal(tcp->u_arg[0]);
909 tprintf(", ");
910 addr = tcp->u_arg[1];
911 } else {
912 addr = tcp->u_arg[2];
913 }
914 if (addr == 0)
915 tprintf("NULL");
916 else if (!verbose(tcp))
917 tprintf("%#lx", addr);
918 else if (umove(tcp, addr, &sv) < 0)
919 tprintf("{...}");
920 else {
921 switch ((int) sv.sv_handler) {
922 case (int) SIG_ERR:
923 tprintf("{SIG_ERR}");
924 break;
925 case (int) SIG_DFL:
926 tprintf("{SIG_DFL}");
927 break;
928 case (int) SIG_IGN:
929 if (tcp->u_arg[0] == SIGTRAP) {
930 tcp->flags |= TCB_SIGTRAPPED;
931 kill(tcp->pid, SIGSTOP);
932 }
933 tprintf("{SIG_IGN}");
934 break;
935 case (int) SIG_HOLD:
936 if (tcp->u_arg[0] == SIGTRAP) {
937 tcp->flags |= TCB_SIGTRAPPED;
938 kill(tcp->pid, SIGSTOP);
939 }
940 tprintf("SIG_HOLD");
941 break;
942 default:
943 if (tcp->u_arg[0] == SIGTRAP) {
944 tcp->flags |= TCB_SIGTRAPPED;
945 kill(tcp->pid, SIGSTOP);
946 }
947 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000948 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000949 tprintf(", ");
950 if (!printflags(sigvec_flags, sv.sv_flags))
951 tprintf("0");
952 tprintf("}");
953 }
954 }
955 if (entering(tcp))
956 tprintf(", ");
957 return 0;
958}
959
960int
961sys_sigpause(tcp)
962struct tcb *tcp;
963{
964 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000965 sigset_t sigm;
966 long_to_sigset(tcp->u_arg[0], &sigm);
967 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968 }
969 return 0;
970}
971
972int
973sys_sigstack(tcp)
974struct tcb *tcp;
975{
976 struct sigstack ss;
977 long addr;
978
979 if (entering(tcp))
980 addr = tcp->u_arg[0];
981 else
982 addr = tcp->u_arg[1];
983 if (addr == 0)
984 tprintf("NULL");
985 else if (umove(tcp, addr, &ss) < 0)
986 tprintf("%#lx", addr);
987 else {
988 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
989 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
990 }
991 if (entering(tcp))
992 tprintf(", ");
993 return 0;
994}
995
996int
997sys_sigcleanup(tcp)
998struct tcb *tcp;
999{
1000 return 0;
1001}
1002
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001003#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001004
1005#ifndef SVR4
1006
1007int
1008sys_sigsetmask(tcp)
1009struct tcb *tcp;
1010{
1011 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001013 long_to_sigset(tcp->u_arg[0], &sigm);
1014 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001015#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1017 /* Mark attempt to block SIGTRAP */
1018 tcp->flags |= TCB_SIGTRAPPED;
1019 /* Send unblockable signal */
1020 kill(tcp->pid, SIGSTOP);
1021 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001022#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001023 }
1024 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001025 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001026 long_to_sigset(tcp->u_rval, &sigm);
1027 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001028
1029 return RVAL_HEX | RVAL_STR;
1030 }
1031 return 0;
1032}
1033
1034int
1035sys_sigblock(tcp)
1036struct tcb *tcp;
1037{
1038 return sys_sigsetmask(tcp);
1039}
1040
1041#endif /* !SVR4 */
1042
1043#ifdef HAVE_SIGACTION
1044
1045#ifdef LINUX
1046struct old_sigaction {
1047 __sighandler_t __sa_handler;
1048 unsigned long sa_mask;
1049 unsigned long sa_flags;
1050 void (*sa_restorer)(void);
1051};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001052#define SA_HANDLER __sa_handler
1053#endif /* LINUX */
1054
Roland McGratha39c5a12002-12-17 05:10:37 +00001055#ifndef SA_HANDLER
1056#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001057#endif
1058
1059int
1060sys_sigaction(tcp)
1061struct tcb *tcp;
1062{
1063 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001064#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001065 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001066 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001067#else
1068 struct sigaction sa;
1069#endif
1070
1071
1072 if (entering(tcp)) {
1073 printsignal(tcp->u_arg[0]);
1074 tprintf(", ");
1075 addr = tcp->u_arg[1];
1076 } else
1077 addr = tcp->u_arg[2];
1078 if (addr == 0)
1079 tprintf("NULL");
1080 else if (!verbose(tcp))
1081 tprintf("%#lx", addr);
1082 else if (umove(tcp, addr, &sa) < 0)
1083 tprintf("{...}");
1084 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001085 switch ((long) sa.SA_HANDLER) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001086 case (long) SIG_ERR:
1087 tprintf("{SIG_ERR}");
1088 break;
1089 case (long) SIG_DFL:
1090 tprintf("{SIG_DFL}");
1091 break;
1092 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001093#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094 if (tcp->u_arg[0] == SIGTRAP) {
1095 tcp->flags |= TCB_SIGTRAPPED;
1096 kill(tcp->pid, SIGSTOP);
1097 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001098#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099 tprintf("{SIG_IGN}");
1100 break;
1101 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001102#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001103 if (tcp->u_arg[0] == SIGTRAP) {
1104 tcp->flags |= TCB_SIGTRAPPED;
1105 kill(tcp->pid, SIGSTOP);
1106 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001107#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001108 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001109#ifndef LINUX
1110 printsigmask (&sa.sa_mask, 0);
1111#else
Nate Sammons4a121431999-04-06 01:19:39 +00001112 long_to_sigset(sa.sa_mask, &sigset);
1113 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001114#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001115 tprintf(", ");
1116 if (!printflags(sigact_flags, sa.sa_flags))
1117 tprintf("0");
Roland McGrath2638cb42002-12-15 23:58:41 +00001118#ifdef SA_RESTORER
1119 if (sa.sa_flags & SA_RESTORER)
1120 tprintf(", %p", sa.sa_restorer);
1121#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001122 tprintf("}");
1123 }
1124 }
1125 if (entering(tcp))
1126 tprintf(", ");
1127#ifdef LINUX
1128 else
1129 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1130#endif
1131 return 0;
1132}
1133
1134int
1135sys_signal(tcp)
1136struct tcb *tcp;
1137{
1138 if (entering(tcp)) {
1139 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001140 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001141 switch (tcp->u_arg[1]) {
1142 case (int) SIG_ERR:
1143 tprintf("SIG_ERR");
1144 break;
1145 case (int) SIG_DFL:
1146 tprintf("SIG_DFL");
1147 break;
1148 case (int) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001149#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001150 if (tcp->u_arg[0] == SIGTRAP) {
1151 tcp->flags |= TCB_SIGTRAPPED;
1152 kill(tcp->pid, SIGSTOP);
1153 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001154#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001155 tprintf("SIG_IGN");
1156 break;
1157 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001158#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001159 if (tcp->u_arg[0] == SIGTRAP) {
1160 tcp->flags |= TCB_SIGTRAPPED;
1161 kill(tcp->pid, SIGSTOP);
1162 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001163#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001164 tprintf("%#lx", tcp->u_arg[1]);
1165 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001166 return 0;
1167 }
1168 else {
1169 switch (tcp->u_rval) {
1170 case (int) SIG_ERR:
1171 tcp->auxstr = "SIG_ERR"; break;
1172 case (int) SIG_DFL:
1173 tcp->auxstr = "SIG_DFL"; break;
1174 case (int) SIG_IGN:
1175 tcp->auxstr = "SIG_IGN"; break;
1176 default:
1177 tcp->auxstr = NULL;
1178 }
1179 return RVAL_HEX | RVAL_STR;
1180 }
1181}
1182
1183int
1184sys_sighold(tcp)
1185struct tcb *tcp;
1186{
1187 if (entering(tcp)) {
1188 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001189 }
1190 return 0;
1191}
1192
1193#endif /* HAVE_SIGACTION */
1194
1195#ifdef LINUX
1196
1197int
1198sys_sigreturn(tcp)
1199struct tcb *tcp;
1200{
Roland McGrath0f87c492003-06-03 23:29:04 +00001201#ifdef ARM
1202 struct pt_regs regs;
1203 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001204
Roland McGrath0f87c492003-06-03 23:29:04 +00001205 if (entering(tcp)) {
1206 tcp->u_arg[0] = 0;
1207
1208 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1209 return 0;
1210
1211 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1212 return 0;
1213
1214 tcp->u_arg[0] = 1;
1215 tcp->u_arg[1] = sc.oldmask;
1216 } else {
1217 sigset_t sigm;
1218 long_to_sigset(tcp->u_arg[1], &sigm);
1219 tcp->u_rval = tcp->u_error = 0;
1220 if (tcp->u_arg[0] == 0)
1221 return 0;
1222 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1223 return RVAL_NONE | RVAL_STR;
1224 }
1225 return 0;
1226#elif defined(S390) || defined(S390X)
1227 long usp;
1228 struct sigcontext_struct sc;
1229
1230 if (entering(tcp)) {
1231 tcp->u_arg[0] = 0;
1232 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1233 return 0;
1234 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1235 return 0;
1236 tcp->u_arg[0] = 1;
1237 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1238 } else {
1239 tcp->u_rval = tcp->u_error = 0;
1240 if (tcp->u_arg[0] == 0)
1241 return 0;
1242 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1243 return RVAL_NONE | RVAL_STR;
1244 }
1245 return 0;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001246#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001247#ifdef I386
1248 long esp;
1249 struct sigcontext_struct sc;
1250
1251 if (entering(tcp)) {
1252 tcp->u_arg[0] = 0;
1253 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1254 return 0;
1255 if (umove(tcp, esp, &sc) < 0)
1256 return 0;
1257 tcp->u_arg[0] = 1;
1258 tcp->u_arg[1] = sc.oldmask;
1259 }
1260 else {
1261 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001262 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001263 tcp->u_rval = tcp->u_error = 0;
1264 if (tcp->u_arg[0] == 0)
1265 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001266 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001267 return RVAL_NONE | RVAL_STR;
1268 }
1269 return 0;
1270#else /* !I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001271#ifdef IA64
1272 struct sigcontext sc;
1273 long sp;
1274
1275 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001276 /* offset of sigcontext in the kernel's sigframe structure: */
1277# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001278 tcp->u_arg[0] = 0;
1279 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1280 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001281 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001282 return 0;
1283 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001284 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001285 }
1286 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001287 sigset_t sigm;
1288
1289 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001290 tcp->u_rval = tcp->u_error = 0;
1291 if (tcp->u_arg[0] == 0)
1292 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001293 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001294 return RVAL_NONE | RVAL_STR;
1295 }
1296 return 0;
1297#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298#ifdef POWERPC
Roland McGrath0f87c492003-06-03 23:29:04 +00001299 long esp;
1300 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001301
Roland McGrath0f87c492003-06-03 23:29:04 +00001302 if (entering(tcp)) {
1303 tcp->u_arg[0] = 0;
1304 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1305 return 0;
1306 if (umove(tcp, esp, &sc) < 0)
1307 return 0;
1308 tcp->u_arg[0] = 1;
1309 tcp->u_arg[1] = sc.oldmask;
1310 }
1311 else {
1312 sigset_t sigm;
1313 long_to_sigset(tcp->u_arg[1], &sigm);
1314 tcp->u_rval = tcp->u_error = 0;
1315 if (tcp->u_arg[0] == 0)
1316 return 0;
1317 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1318 return RVAL_NONE | RVAL_STR;
1319 }
1320 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001321#else /* !POWERPC */
1322#ifdef M68K
1323 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001324 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001325
1326 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001327 tcp->u_arg[0] = 0;
1328 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001329 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001330 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001331 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001332 tcp->u_arg[0] = 1;
1333 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334 }
1335 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001336 sigset_t sigm;
1337 long_to_sigset(tcp->u_arg[1], &sigm);
1338 tcp->u_rval = tcp->u_error = 0;
1339 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001340 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001341 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1342 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001343 }
1344 return 0;
1345#else /* !M68K */
1346#ifdef ALPHA
1347 long fp;
1348 struct sigcontext_struct sc;
1349
1350 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001351 tcp->u_arg[0] = 0;
1352 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001353 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001354 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001355 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001356 tcp->u_arg[0] = 1;
1357 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001358 }
1359 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001360 sigset_t sigm;
1361 long_to_sigset(tcp->u_arg[1], &sigm);
1362 tcp->u_rval = tcp->u_error = 0;
1363 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001364 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001365 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1366 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001367 }
1368 return 0;
1369#else
1370#ifdef SPARC
1371 long i1;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001372 struct regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001373 m_siginfo_t si;
1374
1375 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001376 perror("sigreturn: PTRACE_GETREGS ");
1377 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001379 if(entering(tcp)) {
1380 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001381 i1 = regs.r_o1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001382 if(umove(tcp, i1, &si) < 0) {
1383 perror("sigreturn: umove ");
1384 return 0;
1385 }
1386 tcp->u_arg[0] = 1;
1387 tcp->u_arg[1] = si.si_mask;
1388 } else {
1389 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001390 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001391 tcp->u_rval = tcp->u_error = 0;
1392 if(tcp->u_arg[0] == 0)
1393 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001394 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001395 return RVAL_NONE | RVAL_STR;
1396 }
1397 return 0;
Roland McGratha39c5a12002-12-17 05:10:37 +00001398#else
Wichert Akkermanf90da011999-10-31 21:15:38 +00001399#ifdef MIPS
1400 long sp;
1401 struct sigcontext sc;
1402
1403 if(entering(tcp)) {
1404 tcp->u_arg[0] = 0;
1405 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1406 return 0;
1407 if (umove(tcp, sp, &sc) < 0)
1408 return 0;
1409 tcp->u_arg[0] = 1;
1410 tcp->u_arg[1] = sc.sc_sigset;
1411 } else {
1412 tcp->u_rval = tcp->u_error = 0;
1413 if(tcp->u_arg[0] == 0)
1414 return 0;
1415 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1416 return RVAL_NONE | RVAL_STR;
1417 }
1418 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001419#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001420#warning No sys_sigreturn() for this architecture
1421#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001422 return 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001423#endif /* MIPS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424#endif /* SPARC */
1425#endif /* ALPHA */
1426#endif /* !M68K */
1427#endif /* !POWERPC */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001428#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001429#endif /* !I386 */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001430#endif /* S390 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431}
1432
1433int
1434sys_siggetmask(tcp)
1435struct tcb *tcp;
1436{
1437 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001438 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001439 long_to_sigset(tcp->u_rval, &sigm);
1440 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001441 }
1442 return RVAL_HEX | RVAL_STR;
1443}
1444
1445int
1446sys_sigsuspend(tcp)
1447struct tcb *tcp;
1448{
1449 if (entering(tcp)) {
1450 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001451 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001452#if 0
1453 /* first two are not really arguments, but print them anyway */
1454 /* nevermind, they are an anachronism now, too bad... */
1455 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1456#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001457 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001458 }
1459 return 0;
1460}
1461
1462#endif /* LINUX */
1463
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001464#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001465
1466int
1467sys_sigsuspend(tcp)
1468struct tcb *tcp;
1469{
1470 sigset_t sigset;
1471
1472 if (entering(tcp)) {
1473 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1474 tprintf("[?]");
1475 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001476 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001477 }
1478 return 0;
1479}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001480#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001481static struct xlat ucontext_flags[] = {
1482 { UC_SIGMASK, "UC_SIGMASK" },
1483 { UC_STACK, "UC_STACK" },
1484 { UC_CPU, "UC_CPU" },
1485#ifdef UC_FPU
1486 { UC_FPU, "UC_FPU" },
1487#endif
1488#ifdef UC_INTR
1489 { UC_INTR, "UC_INTR" },
1490#endif
1491 { 0, NULL },
1492};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001493#endif /* !FREEBSD */
1494#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001495
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001496#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001497#if defined LINUX && !defined SS_ONSTACK
1498#define SS_ONSTACK 1
1499#define SS_DISABLE 2
1500#if __GLIBC_MINOR__ == 0
1501typedef struct
1502{
1503 __ptr_t ss_sp;
1504 int ss_flags;
1505 size_t ss_size;
1506} stack_t;
1507#endif
1508#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001509#ifdef FREEBSD
1510#define stack_t struct sigaltstack
1511#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001512
1513static struct xlat sigaltstack_flags[] = {
1514 { SS_ONSTACK, "SS_ONSTACK" },
1515 { SS_DISABLE, "SS_DISABLE" },
1516 { 0, NULL },
1517};
1518#endif
1519
1520#ifdef SVR4
1521static void
1522printcontext(tcp, ucp)
1523struct tcb *tcp;
1524ucontext_t *ucp;
1525{
1526 tprintf("{");
1527 if (!abbrev(tcp)) {
1528 tprintf("uc_flags=");
1529 if (!printflags(ucontext_flags, ucp->uc_flags))
1530 tprintf("0");
1531 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1532 }
1533 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001534 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001535 if (!abbrev(tcp)) {
1536 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1537 (unsigned long) ucp->uc_stack.ss_sp,
1538 ucp->uc_stack.ss_size);
1539 if (!printflags(sigaltstack_flags, ucp->uc_stack.ss_flags))
1540 tprintf("0");
1541 tprintf("}");
1542 }
1543 tprintf(", ...}");
1544}
1545
1546int
1547sys_getcontext(tcp)
1548struct tcb *tcp;
1549{
1550 ucontext_t uc;
1551
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001552 if (exiting(tcp)) {
1553 if (tcp->u_error)
1554 tprintf("%#lx", tcp->u_arg[0]);
1555 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001556 tprintf("NULL");
1557 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1558 tprintf("{...}");
1559 else
1560 printcontext(tcp, &uc);
1561 }
1562 return 0;
1563}
1564
1565int
1566sys_setcontext(tcp)
1567struct tcb *tcp;
1568{
1569 ucontext_t uc;
1570
1571 if (entering(tcp)) {
1572 if (!tcp->u_arg[0])
1573 tprintf("NULL");
1574 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1575 tprintf("{...}");
1576 else
1577 printcontext(tcp, &uc);
1578 }
1579 else {
1580 tcp->u_rval = tcp->u_error = 0;
1581 if (tcp->u_arg[0] == 0)
1582 return 0;
1583 return RVAL_NONE;
1584 }
1585 return 0;
1586}
1587
1588#endif /* SVR4 */
1589
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001590#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001591
1592static int
1593print_stack_t(tcp, addr)
1594struct tcb *tcp;
1595unsigned long addr;
1596{
1597 stack_t ss;
1598 if (umove(tcp, addr, &ss) < 0)
1599 return -1;
1600 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1601 if (!printflags(sigaltstack_flags, ss.ss_flags))
1602 tprintf("0");
1603 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1604 return 0;
1605}
1606
1607int
1608sys_sigaltstack(tcp)
1609 struct tcb *tcp;
1610{
1611 if (entering(tcp)) {
1612 if (tcp->u_arg[0] == 0)
1613 tprintf("NULL");
1614 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1615 return -1;
1616 }
1617 else {
1618 tprintf(", ");
1619 if (tcp->u_arg[1] == 0)
1620 tprintf("NULL");
1621 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1622 return -1;
1623 }
1624 return 0;
1625}
1626#endif
1627
1628#ifdef HAVE_SIGACTION
1629
1630int
1631sys_sigprocmask(tcp)
1632struct tcb *tcp;
1633{
1634#ifdef ALPHA
1635 if (entering(tcp)) {
1636 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1637 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001638 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001639 }
1640 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001641 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642 return RVAL_HEX | RVAL_STR;
1643 }
1644#else /* !ALPHA */
1645 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646
1647 if (entering(tcp)) {
1648#ifdef SVR4
1649 if (tcp->u_arg[0] == 0)
1650 tprintf("0");
1651 else
1652#endif /* SVR4 */
1653 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1654 tprintf(", ");
1655 if (!tcp->u_arg[1])
1656 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001657 else if (copy_sigset(tcp, tcp->u_arg[1], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001658 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001659 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001660 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001661 tprintf(", ");
1662 }
1663 }
1664 else {
1665 if (!tcp->u_arg[2])
1666 tprintf("NULL");
1667 else if (syserror(tcp))
1668 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001669 else if (copy_sigset(tcp, tcp->u_arg[2], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001670 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001671 else
Nate Sammons4a121431999-04-06 01:19:39 +00001672 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001673 }
1674#endif /* !ALPHA */
1675 return 0;
1676}
1677
1678#endif /* HAVE_SIGACTION */
1679
1680int
1681sys_kill(tcp)
1682struct tcb *tcp;
1683{
1684 if (entering(tcp)) {
Nate Sammonsce780fc1999-03-29 23:23:13 +00001685 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001686 }
1687 return 0;
1688}
1689
1690int
1691sys_killpg(tcp)
1692struct tcb *tcp;
1693{
1694 return sys_kill(tcp);
1695}
1696
Roland McGrath8ffc3522003-07-09 09:47:49 +00001697#ifdef LINUX
1698int
1699sys_tgkill(tcp)
1700 struct tcb *tcp;
1701{
1702 if (entering(tcp)) {
1703 tprintf("%ld, %ld, %s",
1704 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1705 }
1706 return 0;
1707}
1708#endif
1709
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001710int
1711sys_sigpending(tcp)
1712struct tcb *tcp;
1713{
1714 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001715
1716 if (exiting(tcp)) {
1717 if (syserror(tcp))
1718 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001719 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001720 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001721 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001722 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001723 }
1724 return 0;
1725}
1726
John Hughes42162082001-10-18 14:48:26 +00001727int sys_sigwait(tcp)
1728struct tcb *tcp;
1729{
1730 sigset_t sigset;
1731
1732 if (entering(tcp)) {
1733 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1734 tprintf("[?]");
1735 else
1736 printsigmask(&sigset, 0);
1737 }
1738 else {
1739 if (!syserror(tcp)) {
1740 tcp->auxstr = signalent[tcp->u_rval];
1741 return RVAL_DECIMAL | RVAL_STR;
1742 }
1743 }
1744 return 0;
1745}
1746
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001747#ifdef LINUX
1748
1749 int
1750sys_rt_sigprocmask(tcp)
1751 struct tcb *tcp;
1752{
1753 sigset_t sigset;
1754
Nate Sammons4a121431999-04-06 01:19:39 +00001755 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001756 if (entering(tcp)) {
1757 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1758 tprintf(", ");
1759 if (!tcp->u_arg[1])
1760 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001761 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001762 tprintf("%#lx, ", tcp->u_arg[1]);
1763 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001764 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001765 tprintf(", ");
1766 }
1767 }
1768 else {
1769 if (!tcp->u_arg[2])
1770
1771 tprintf("NULL");
1772 else if (syserror(tcp))
1773 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001774 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001775 tprintf("[?]");
1776 else
Nate Sammons4a121431999-04-06 01:19:39 +00001777 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001778 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001779 }
1780 return 0;
1781}
1782
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001783
1784/* Structure describing the action to be taken when a signal arrives. */
1785struct new_sigaction
1786{
1787 union
1788 {
1789 __sighandler_t __sa_handler;
1790 void (*__sa_sigaction) (int, siginfo_t *, void *);
1791 }
1792 __sigaction_handler;
1793 unsigned long sa_flags;
1794 void (*sa_restorer) (void);
1795 unsigned long int sa_mask[2];
1796};
1797
1798
1799 int
1800sys_rt_sigaction(tcp)
1801 struct tcb *tcp;
1802{
1803 struct new_sigaction sa;
1804 sigset_t sigset;
1805 long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001806
1807 if (entering(tcp)) {
1808 printsignal(tcp->u_arg[0]);
1809 tprintf(", ");
1810 addr = tcp->u_arg[1];
1811 } else
1812 addr = tcp->u_arg[2];
1813 if (addr == 0)
1814 tprintf("NULL");
1815 else if (!verbose(tcp))
1816 tprintf("%#lx", addr);
1817 else if (umove(tcp, addr, &sa) < 0)
1818 tprintf("{...}");
1819 else {
1820 switch ((long) sa.__sigaction_handler.__sa_handler) {
1821 case (long) SIG_ERR:
1822 tprintf("{SIG_ERR}");
1823 break;
1824 case (long) SIG_DFL:
1825 tprintf("{SIG_DFL}");
1826 break;
1827 case (long) SIG_IGN:
1828 tprintf("{SIG_IGN}");
1829 break;
1830 default:
1831 tprintf("{%#lx, ",
1832 (long) sa.__sigaction_handler.__sa_handler);
Nate Sammons4a121431999-04-06 01:19:39 +00001833 sigemptyset(&sigset);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001834#ifdef LINUXSPARC
1835 if (tcp->u_arg[4] <= sizeof(sigset))
1836 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1837#else
Nate Sammons4a121431999-04-06 01:19:39 +00001838 if (tcp->u_arg[3] <= sizeof(sigset))
1839 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001840#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001841 else
1842 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1843 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001844 tprintf(", ");
1845 if (!printflags(sigact_flags, sa.sa_flags))
1846 tprintf("0");
Roland McGrath2638cb42002-12-15 23:58:41 +00001847#ifdef SA_RESTORER
1848 if (sa.sa_flags & SA_RESTORER)
1849 tprintf(", %p", sa.sa_restorer);
1850#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851 tprintf("}");
1852 }
1853 }
1854 if (entering(tcp))
1855 tprintf(", ");
1856 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001857#ifdef LINUXSPARC
1858 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1859#elif defined(ALPHA)
1860 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1861#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001862 tprintf(", %lu", addr = tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001863#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001864 return 0;
1865}
1866
1867 int
1868sys_rt_sigpending(tcp)
1869 struct tcb *tcp;
1870{
1871 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001872
1873 if (exiting(tcp)) {
1874 if (syserror(tcp))
1875 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001876 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1877 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001878 tprintf("[?]");
1879 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001880 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001881 }
1882 return 0;
1883}
1884 int
1885sys_rt_sigsuspend(tcp)
1886 struct tcb *tcp;
1887{
1888 if (entering(tcp)) {
1889 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001890 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1891 tprintf("[?]");
1892 else
1893 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894 }
1895 return 0;
1896}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001897 int
1898sys_rt_sigqueueinfo(tcp)
1899 struct tcb *tcp;
1900{
1901 if (entering(tcp)) {
1902 siginfo_t si;
1903 tprintf("%lu, ", tcp->u_arg[0]);
1904 printsignal(tcp->u_arg[1]);
1905 tprintf(", ");
1906 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1907 tprintf("%#lx", tcp->u_arg[2]);
1908 else
John Hughes58265892001-10-18 15:13:53 +00001909 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910 }
1911 return 0;
1912}
1913
1914int sys_rt_sigtimedwait(tcp)
1915 struct tcb *tcp;
1916{
1917 if (entering(tcp)) {
1918 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001919
Roland McGratha39c5a12002-12-17 05:10:37 +00001920 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00001921 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001922 tprintf("[?]");
1923 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001924 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001925 tprintf(", ");
1926 }
1927 else {
1928 if (syserror(tcp))
1929 tprintf("%#lx", tcp->u_arg[0]);
1930 else {
1931 siginfo_t si;
1932 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1933 tprintf("%#lx", tcp->u_arg[1]);
1934 else
John Hughes58265892001-10-18 15:13:53 +00001935 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001936 /* XXX For now */
1937 tprintf(", %#lx", tcp->u_arg[2]);
1938 tprintf(", %d", (int) tcp->u_arg[3]);
1939 }
1940 }
1941 return 0;
1942};
1943
1944#endif /* LINUX */