blob: 75f757e6a24d761e2cf159e06dfe87ce600261cb [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 }
347 else {
348 char tsig[32];
349 sprintf(tsig, "%u", i);
350 sprintf(s, format, tsig);
351 }
352 s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000353 format = " %s";
354 }
355 }
356 *s++ = ']';
357 *s = '\0';
358 return outstr;
359}
360
361static void
Nate Sammons4a121431999-04-06 01:19:39 +0000362printsigmask(mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000363sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000364int rt;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000365{
Nate Sammons4a121431999-04-06 01:19:39 +0000366 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000367}
368
369void
370printsignal(nr)
371int nr;
372{
Nate Sammonsce780fc1999-03-29 23:23:13 +0000373 tprintf(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374}
375
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000376#ifdef LINUX
377
John Hughes58265892001-10-18 15:13:53 +0000378#ifndef ILL_ILLOPC
379#define ILL_ILLOPC 1 /* illegal opcode */
380#define ILL_ILLOPN 2 /* illegal operand */
381#define ILL_ILLADR 3 /* illegal addressing mode */
382#define ILL_ILLTRP 4 /* illegal trap */
383#define ILL_PRVOPC 5 /* privileged opcode */
384#define ILL_PRVREG 6 /* privileged register */
385#define ILL_COPROC 7 /* coprocessor error */
386#define ILL_BADSTK 8 /* internal stack error */
387#define FPE_INTDIV 1 /* integer divide by zero */
388#define FPE_INTOVF 2 /* integer overflow */
389#define FPE_FLTDIV 3 /* floating point divide by zero */
390#define FPE_FLTOVF 4 /* floating point overflow */
391#define FPE_FLTUND 5 /* floating point underflow */
392#define FPE_FLTRES 6 /* floating point inexact result */
393#define FPE_FLTINV 7 /* floating point invalid operation */
394#define FPE_FLTSUB 8 /* subscript out of range */
395#define SEGV_MAPERR 1 /* address not mapped to object */
396#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
397#define BUS_ADRALN 1 /* invalid address alignment */
398#define BUS_ADRERR 2 /* non-existant physical address */
399#define BUS_OBJERR 3 /* object specific hardware error */
400#define TRAP_BRKPT 1 /* process breakpoint */
401#define TRAP_TRACE 2 /* process trace trap */
402#define CLD_EXITED 1 /* child has exited */
403#define CLD_KILLED 2 /* child was killed */
404#define CLD_DUMPED 3 /* child terminated abnormally */
405#define CLD_TRAPPED 4 /* traced child has trapped */
406#define CLD_STOPPED 5 /* child has stopped */
407#define CLD_CONTINUED 6 /* stopped child has continued */
408#define POLL_IN 1 /* data input available */
409#define POLL_OUT 2 /* output buffers available */
410#define POLL_MSG 3 /* input message available */
411#define POLL_ERR 4 /* i/o error */
412#define POLL_PRI 5 /* high priority input available */
413#define POLL_HUP 6 /* device disconnected */
414#define SI_USER 0 /* sent by kill, sigsend, raise */
415#define SI_QUEUE -1 /* sent by sigqueue */
416#define SI_TIMER -2 /* sent by timer expiration */
417#define SI_MESGQ -3 /* sent by real time mesq state change */
418#define SI_ASYNCIO -4 /* sent by AIO completion */
Roland McGrath941b7402003-05-23 00:29:02 +0000419#define SI_SIGIO -5 /* Sent by SIGIO */
420#define SI_TKILL -6 /* Sent by tkill */
John Hughes58265892001-10-18 15:13:53 +0000421#endif
422
423#if __GLIBC_MINOR__ < 1
424/* Type for data associated with a signal. */
425typedef union sigval
426{
427 int sival_int;
428 void *sival_ptr;
429} sigval_t;
430
431# define __SI_MAX_SIZE 128
432# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
433
434typedef struct siginfo
435{
436 int si_signo; /* Signal number. */
437 int si_errno; /* If non-zero, an errno value associated with
438 this signal, as defined in <errno.h>. */
439 int si_code; /* Signal code. */
440
441 union
442 {
443 int _pad[__SI_PAD_SIZE];
444
445 /* kill(). */
446 struct
447 {
448 __pid_t si_pid; /* Sending process ID. */
449 __uid_t si_uid; /* Real user ID of sending process. */
450 } _kill;
451
452 /* POSIX.1b timers. */
453 struct
454 {
455 unsigned int _timer1;
456 unsigned int _timer2;
457 } _timer;
458
459 /* POSIX.1b signals. */
460 struct
461 {
462 __pid_t si_pid; /* Sending process ID. */
463 __uid_t si_uid; /* Real user ID of sending process. */
464 sigval_t si_sigval; /* Signal value. */
465 } _rt;
466
467 /* SIGCHLD. */
468 struct
469 {
470 __pid_t si_pid; /* Which child. */
471 int si_status; /* Exit value or signal. */
472 __clock_t si_utime;
473 __clock_t si_stime;
474 } _sigchld;
475
476 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
477 struct
478 {
479 void *si_addr; /* Faulting insn/memory ref. */
480 } _sigfault;
481
482 /* SIGPOLL. */
483 struct
484 {
485 int si_band; /* Band event for SIGPOLL. */
486 int si_fd;
487 } _sigpoll;
488 } _sifields;
489} siginfo_t;
490
491#define si_pid _sifields._kill.si_pid
492#define si_uid _sifields._kill.si_uid
493#define si_status _sifields._sigchld.si_status
494#define si_utime _sifields._sigchld.si_utime
495#define si_stime _sifields._sigchld.si_stime
496#define si_value _sifields._rt.si_sigval
497#define si_int _sifields._rt.si_sigval.sival_int
498#define si_ptr _sifields._rt.si_sigval.sival_ptr
499#define si_addr _sifields._sigfault.si_addr
500#define si_band _sifields._sigpoll.si_band
501#define si_fd _sifields._sigpoll.si_fd
502
503#endif
504
505#endif
506
507#if defined (SVR4) || defined (LINUX)
508
509static struct xlat siginfo_codes[] = {
510#ifdef SI_NOINFO
511 { SI_NOINFO, "SI_NOINFO" },
512#endif
513#ifdef SI_USER
514 { SI_USER, "SI_USER" },
515#endif
516#ifdef SI_LWP
517 { SI_LWP, "SI_LWP" },
518#endif
519#ifdef SI_QUEUE
520 { SI_QUEUE, "SI_QUEUE" },
521#endif
522#ifdef SI_TIMER
523 { SI_TIMER, "SI_TIMER" },
524#endif
525#ifdef SI_ASYNCIO
526 { SI_ASYNCIO, "SI_ASYNCIO" },
527#endif
528#ifdef SI_MESGQ
529 { SI_MESGQ, "SI_MESGQ" },
530#endif
Roland McGrath941b7402003-05-23 00:29:02 +0000531#ifdef SI_SIGIO
532 { SI_SIGIO, "SI_SIGIO" },
533#endif
534#ifdef SI_TKILL
535 { SI_TKILL, "SI_TKILL" },
536#endif
John Hughes58265892001-10-18 15:13:53 +0000537 { 0, NULL },
538};
539
540static struct xlat sigill_codes[] = {
541 { ILL_ILLOPC, "ILL_ILLOPC" },
542 { ILL_ILLOPN, "ILL_ILLOPN" },
543 { ILL_ILLADR, "ILL_ILLADR" },
544 { ILL_ILLTRP, "ILL_ILLTRP" },
545 { ILL_PRVOPC, "ILL_PRVOPC" },
546 { ILL_PRVREG, "ILL_PRVREG" },
547 { ILL_COPROC, "ILL_COPROC" },
548 { ILL_BADSTK, "ILL_BADSTK" },
549 { 0, NULL },
550};
551
552static struct xlat sigfpe_codes[] = {
553 { FPE_INTDIV, "FPE_INTDIV" },
554 { FPE_INTOVF, "FPE_INTOVF" },
555 { FPE_FLTDIV, "FPE_FLTDIV" },
556 { FPE_FLTOVF, "FPE_FLTOVF" },
557 { FPE_FLTUND, "FPE_FLTUND" },
558 { FPE_FLTRES, "FPE_FLTRES" },
559 { FPE_FLTINV, "FPE_FLTINV" },
560 { FPE_FLTSUB, "FPE_FLTSUB" },
561 { 0, NULL },
562};
563
564static struct xlat sigtrap_codes[] = {
565 { TRAP_BRKPT, "TRAP_BRKPT" },
566 { TRAP_TRACE, "TRAP_TRACE" },
567 { 0, NULL },
568};
569
570static struct xlat sigchld_codes[] = {
571 { CLD_EXITED, "CLD_EXITED" },
572 { CLD_KILLED, "CLD_KILLED" },
573 { CLD_DUMPED, "CLD_DUMPED" },
574 { CLD_TRAPPED, "CLD_TRAPPED" },
575 { CLD_STOPPED, "CLD_STOPPED" },
576 { CLD_CONTINUED,"CLD_CONTINUED" },
577 { 0, NULL },
578};
579
580static struct xlat sigpoll_codes[] = {
581 { POLL_IN, "POLL_IN" },
582 { POLL_OUT, "POLL_OUT" },
583 { POLL_MSG, "POLL_MSG" },
584 { POLL_ERR, "POLL_ERR" },
585 { POLL_PRI, "POLL_PRI" },
586 { POLL_HUP, "POLL_HUP" },
587 { 0, NULL },
588};
589
590static struct xlat sigprof_codes[] = {
591#ifdef PROF_SIG
592 { PROF_SIG, "PROF_SIG" },
593#endif
594 { 0, NULL },
595};
596
597#ifdef SIGEMT
598static struct xlat sigemt_codes[] = {
599#ifdef EMT_TAGOVF
600 { EMT_TAGOVF, "EMT_TAGOVF" },
601#endif
602 { 0, NULL },
603};
604#endif
605
606static struct xlat sigsegv_codes[] = {
607 { SEGV_MAPERR, "SEGV_MAPERR" },
608 { SEGV_ACCERR, "SEGV_ACCERR" },
609 { 0, NULL },
610};
611
612static struct xlat sigbus_codes[] = {
613 { BUS_ADRALN, "BUS_ADRALN" },
614 { BUS_ADRERR, "BUS_ADRERR" },
615 { BUS_OBJERR, "BUS_OBJERR" },
616 { 0, NULL },
617};
618
619void
620printsiginfo(sip, verbose)
621siginfo_t *sip;
622int verbose;
623{
624 char *code;
625
626 if (sip->si_signo == 0) {
627 tprintf ("{}");
628 return;
629 }
630 tprintf("{si_signo=");
631 printsignal(sip->si_signo);
632 code = xlookup(siginfo_codes, sip->si_code);
633 if (!code) {
634 switch (sip->si_signo) {
635 case SIGTRAP:
636 code = xlookup(sigtrap_codes, sip->si_code);
637 break;
638 case SIGCHLD:
639 code = xlookup(sigchld_codes, sip->si_code);
640 break;
641 case SIGPOLL:
642 code = xlookup(sigpoll_codes, sip->si_code);
643 break;
644 case SIGPROF:
645 code = xlookup(sigprof_codes, sip->si_code);
646 break;
647 case SIGILL:
648 code = xlookup(sigill_codes, sip->si_code);
649 break;
650#ifdef SIGEMT
651 case SIGEMT:
652 code = xlookup(sigemt_codes, sip->si_code);
653 break;
654#endif
655 case SIGFPE:
656 code = xlookup(sigfpe_codes, sip->si_code);
657 break;
658 case SIGSEGV:
659 code = xlookup(sigsegv_codes, sip->si_code);
660 break;
661 case SIGBUS:
662 code = xlookup(sigbus_codes, sip->si_code);
663 break;
664 }
665 }
666 if (code)
667 tprintf(", si_code=%s", code);
668 else
669 tprintf(", si_code=%#x", sip->si_code);
670#ifdef SI_NOINFO
671 if (sip->si_code != SI_NOINFO)
672#endif
673 {
674 if (sip->si_errno) {
675 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
676 tprintf(", si_errno=%d", sip->si_errno);
677 else
678 tprintf(", si_errno=%s",
679 errnoent[sip->si_errno]);
680 }
681#ifdef SI_FROMUSER
682 if (SI_FROMUSER(sip)) {
683 tprintf(", si_pid=%ld, si_uid=%ld",
684 sip->si_pid, sip->si_uid);
685#ifdef SI_QUEUE
686 switch (sip->si_code) {
687 case SI_QUEUE:
688#ifdef SI_TIMER
689 case SI_TIMER:
690#endif /* SI_QUEUE */
691 case SI_ASYNCIO:
692#ifdef SI_MESGQ
693 case SI_MESGQ:
694#endif /* SI_MESGQ */
695 tprintf(", si_value=%d",
696 sip->si_value.sival_int);
697 break;
698 }
699#endif /* SI_QUEUE */
700 }
701 else
702#endif /* SI_FROMUSER */
703 {
704 switch (sip->si_signo) {
705 case SIGCHLD:
706 tprintf(", si_pid=%ld, si_status=",
707 (long) sip->si_pid);
708 if (sip->si_code == CLD_EXITED)
709 tprintf("%d", sip->si_status);
710 else
711 printsignal(sip->si_status);
712#if LINUX
713 if (!verbose)
714 tprintf(", ...");
715 else
716 tprintf(", si_utime=%lu, si_stime=%lu",
717 sip->si_utime,
718 sip->si_stime);
719#endif
720 break;
721 case SIGILL: case SIGFPE:
722 case SIGSEGV: case SIGBUS:
723 tprintf(", si_addr=%#lx",
724 (unsigned long) sip->si_addr);
725 break;
726 case SIGPOLL:
727 switch (sip->si_code) {
728 case POLL_IN: case POLL_OUT: case POLL_MSG:
729 tprintf(", si_band=%ld",
730 (long) sip->si_band);
731 break;
732 }
733 break;
734#ifdef LINUX
735 default:
736 tprintf(", si_pid=%lu, si_uid=%lu, ",
737 (unsigned long) sip->si_pid,
738 (unsigned long) sip->si_uid);
739 if (!verbose)
740 tprintf("...");
741 else {
742 tprintf("si_value={int=%u, ptr=%#lx}",
743 sip->si_int,
744 (unsigned long) sip->si_ptr);
745 }
746#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000747
John Hughes58265892001-10-18 15:13:53 +0000748 }
749 }
750 }
751 tprintf("}");
752}
753
754#endif /* SVR4 || LINUX */
755
756#ifdef LINUX
757
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000758static void
759parse_sigset_t (const char *str, sigset_t *set)
760{
761 unsigned int digit;
762 int i;
763
764 sigemptyset(set);
765
766 for (i = _NSIG - 4; i >= 0; i -= 4, ++str) {
767 if (*str >= 'a')
768 digit = (*str - 'a') + 10;
769 else
770 digit = *str - '0';
771 if (digit & 1)
772 sigaddset(set, i + 1);
773 if (digit & 2)
774 sigaddset(set, i + 2);
775 if (digit & 4)
776 sigaddset(set, i + 3);
777 if (digit & 8)
778 sigaddset(set, i + 4);
779 }
780}
781
782#endif
783
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000784/*
785 * Check process TCP for the disposition of signal SIG.
786 * Return 1 if the process would somehow manage to survive signal SIG,
787 * else return 0. This routine will never be called with SIGKILL.
788 */
789int
790sigishandled(tcp, sig)
791struct tcb *tcp;
792int sig;
793{
794#ifdef LINUX
795 int sfd;
796 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000797 char buf[2048];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000798 char *s;
799 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000800 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000801#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000802#ifdef SVR4
803 /*
804 * Since procfs doesn't interfere with wait I think it is safe
805 * to punt on this question. If not, the information is there.
806 */
807 return 1;
808#else /* !SVR4 */
809 switch (sig) {
810 case SIGCONT:
811 case SIGSTOP:
812 case SIGTSTP:
813 case SIGTTIN:
814 case SIGTTOU:
815 case SIGCHLD:
816 case SIGIO:
817#if defined(SIGURG) && SIGURG != SIGIO
818 case SIGURG:
819#endif
820 case SIGWINCH:
821 /* Gloria Gaynor says ... */
822 return 1;
823 default:
824 break;
825 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000826#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000827#ifdef LINUX
828
829 /* This is incredibly costly but it's worth it. */
830 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
831 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
832 doesn't handle real-time signals). */
833 sprintf(sname, "/proc/%d/status", tcp->pid);
834 if ((sfd = open(sname, O_RDONLY)) == -1) {
835 perror(sname);
836 return 1;
837 }
838 i = read(sfd, buf, sizeof(buf));
839 buf[i] = '\0';
840 close(sfd);
841 /*
842 * Skip the extraneous fields. We need to skip
843 * command name has any spaces in it. So be it.
844 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000845 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000846 if (!s)
847 {
848 fprintf(stderr, "/proc/pid/status format error\n");
849 return 1;
850 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000851 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000852
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000853 s = strstr(buf, "SigCgt:\t");
854 if (!s)
855 {
856 fprintf(stderr, "/proc/pid/status format error\n");
857 return 1;
858 }
859 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000860
861#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000862 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
863 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000864#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000865 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000866 return 1;
867#endif /* LINUX */
868
869#ifdef SUNOS4
870 void (*u_signal)();
871
872 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
873 (long *) &u_signal) < 0) {
874 return 0;
875 }
876 if (u_signal != SIG_DFL)
877 return 1;
878#endif /* SUNOS4 */
879
880 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000881}
882
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000883#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000884
885int
886sys_sigvec(tcp)
887struct tcb *tcp;
888{
889 struct sigvec sv;
890 long addr;
891
892 if (entering(tcp)) {
893 printsignal(tcp->u_arg[0]);
894 tprintf(", ");
895 addr = tcp->u_arg[1];
896 } else {
897 addr = tcp->u_arg[2];
898 }
899 if (addr == 0)
900 tprintf("NULL");
901 else if (!verbose(tcp))
902 tprintf("%#lx", addr);
903 else if (umove(tcp, addr, &sv) < 0)
904 tprintf("{...}");
905 else {
906 switch ((int) sv.sv_handler) {
907 case (int) SIG_ERR:
908 tprintf("{SIG_ERR}");
909 break;
910 case (int) SIG_DFL:
911 tprintf("{SIG_DFL}");
912 break;
913 case (int) SIG_IGN:
914 if (tcp->u_arg[0] == SIGTRAP) {
915 tcp->flags |= TCB_SIGTRAPPED;
916 kill(tcp->pid, SIGSTOP);
917 }
918 tprintf("{SIG_IGN}");
919 break;
920 case (int) SIG_HOLD:
921 if (tcp->u_arg[0] == SIGTRAP) {
922 tcp->flags |= TCB_SIGTRAPPED;
923 kill(tcp->pid, SIGSTOP);
924 }
925 tprintf("SIG_HOLD");
926 break;
927 default:
928 if (tcp->u_arg[0] == SIGTRAP) {
929 tcp->flags |= TCB_SIGTRAPPED;
930 kill(tcp->pid, SIGSTOP);
931 }
932 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000933 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000934 tprintf(", ");
935 if (!printflags(sigvec_flags, sv.sv_flags))
936 tprintf("0");
937 tprintf("}");
938 }
939 }
940 if (entering(tcp))
941 tprintf(", ");
942 return 0;
943}
944
945int
946sys_sigpause(tcp)
947struct tcb *tcp;
948{
949 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000950 sigset_t sigm;
951 long_to_sigset(tcp->u_arg[0], &sigm);
952 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953 }
954 return 0;
955}
956
957int
958sys_sigstack(tcp)
959struct tcb *tcp;
960{
961 struct sigstack ss;
962 long addr;
963
964 if (entering(tcp))
965 addr = tcp->u_arg[0];
966 else
967 addr = tcp->u_arg[1];
968 if (addr == 0)
969 tprintf("NULL");
970 else if (umove(tcp, addr, &ss) < 0)
971 tprintf("%#lx", addr);
972 else {
973 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
974 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
975 }
976 if (entering(tcp))
977 tprintf(", ");
978 return 0;
979}
980
981int
982sys_sigcleanup(tcp)
983struct tcb *tcp;
984{
985 return 0;
986}
987
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000988#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000989
990#ifndef SVR4
991
992int
993sys_sigsetmask(tcp)
994struct tcb *tcp;
995{
996 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000997 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000998 long_to_sigset(tcp->u_arg[0], &sigm);
999 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001000#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001001 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1002 /* Mark attempt to block SIGTRAP */
1003 tcp->flags |= TCB_SIGTRAPPED;
1004 /* Send unblockable signal */
1005 kill(tcp->pid, SIGSTOP);
1006 }
Roland McGratha39c5a12002-12-17 05:10:37 +00001007#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008 }
1009 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001010 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001011 long_to_sigset(tcp->u_rval, &sigm);
1012 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001013
1014 return RVAL_HEX | RVAL_STR;
1015 }
1016 return 0;
1017}
1018
1019int
1020sys_sigblock(tcp)
1021struct tcb *tcp;
1022{
1023 return sys_sigsetmask(tcp);
1024}
1025
1026#endif /* !SVR4 */
1027
1028#ifdef HAVE_SIGACTION
1029
1030#ifdef LINUX
1031struct old_sigaction {
1032 __sighandler_t __sa_handler;
1033 unsigned long sa_mask;
1034 unsigned long sa_flags;
1035 void (*sa_restorer)(void);
1036};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001037#define SA_HANDLER __sa_handler
1038#endif /* LINUX */
1039
Roland McGratha39c5a12002-12-17 05:10:37 +00001040#ifndef SA_HANDLER
1041#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001042#endif
1043
1044int
1045sys_sigaction(tcp)
1046struct tcb *tcp;
1047{
1048 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001049#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001050 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001051 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052#else
1053 struct sigaction sa;
1054#endif
1055
1056
1057 if (entering(tcp)) {
1058 printsignal(tcp->u_arg[0]);
1059 tprintf(", ");
1060 addr = tcp->u_arg[1];
1061 } else
1062 addr = tcp->u_arg[2];
1063 if (addr == 0)
1064 tprintf("NULL");
1065 else if (!verbose(tcp))
1066 tprintf("%#lx", addr);
1067 else if (umove(tcp, addr, &sa) < 0)
1068 tprintf("{...}");
1069 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001070 switch ((long) sa.SA_HANDLER) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071 case (long) SIG_ERR:
1072 tprintf("{SIG_ERR}");
1073 break;
1074 case (long) SIG_DFL:
1075 tprintf("{SIG_DFL}");
1076 break;
1077 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001078#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001079 if (tcp->u_arg[0] == SIGTRAP) {
1080 tcp->flags |= TCB_SIGTRAPPED;
1081 kill(tcp->pid, SIGSTOP);
1082 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001083#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001084 tprintf("{SIG_IGN}");
1085 break;
1086 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001087#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001088 if (tcp->u_arg[0] == SIGTRAP) {
1089 tcp->flags |= TCB_SIGTRAPPED;
1090 kill(tcp->pid, SIGSTOP);
1091 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001092#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001093 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001094#ifndef LINUX
1095 printsigmask (&sa.sa_mask, 0);
1096#else
Nate Sammons4a121431999-04-06 01:19:39 +00001097 long_to_sigset(sa.sa_mask, &sigset);
1098 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001099#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001100 tprintf(", ");
1101 if (!printflags(sigact_flags, sa.sa_flags))
1102 tprintf("0");
Roland McGrath2638cb42002-12-15 23:58:41 +00001103#ifdef SA_RESTORER
1104 if (sa.sa_flags & SA_RESTORER)
1105 tprintf(", %p", sa.sa_restorer);
1106#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001107 tprintf("}");
1108 }
1109 }
1110 if (entering(tcp))
1111 tprintf(", ");
1112#ifdef LINUX
1113 else
1114 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1115#endif
1116 return 0;
1117}
1118
1119int
1120sys_signal(tcp)
1121struct tcb *tcp;
1122{
1123 if (entering(tcp)) {
1124 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001125 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126 switch (tcp->u_arg[1]) {
1127 case (int) SIG_ERR:
1128 tprintf("SIG_ERR");
1129 break;
1130 case (int) SIG_DFL:
1131 tprintf("SIG_DFL");
1132 break;
1133 case (int) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001134#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001135 if (tcp->u_arg[0] == SIGTRAP) {
1136 tcp->flags |= TCB_SIGTRAPPED;
1137 kill(tcp->pid, SIGSTOP);
1138 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001139#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001140 tprintf("SIG_IGN");
1141 break;
1142 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001143#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001144 if (tcp->u_arg[0] == SIGTRAP) {
1145 tcp->flags |= TCB_SIGTRAPPED;
1146 kill(tcp->pid, SIGSTOP);
1147 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001148#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001149 tprintf("%#lx", tcp->u_arg[1]);
1150 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001151 return 0;
1152 }
1153 else {
1154 switch (tcp->u_rval) {
1155 case (int) SIG_ERR:
1156 tcp->auxstr = "SIG_ERR"; break;
1157 case (int) SIG_DFL:
1158 tcp->auxstr = "SIG_DFL"; break;
1159 case (int) SIG_IGN:
1160 tcp->auxstr = "SIG_IGN"; break;
1161 default:
1162 tcp->auxstr = NULL;
1163 }
1164 return RVAL_HEX | RVAL_STR;
1165 }
1166}
1167
1168int
1169sys_sighold(tcp)
1170struct tcb *tcp;
1171{
1172 if (entering(tcp)) {
1173 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001174 }
1175 return 0;
1176}
1177
1178#endif /* HAVE_SIGACTION */
1179
1180#ifdef LINUX
1181
1182int
1183sys_sigreturn(tcp)
1184struct tcb *tcp;
1185{
Roland McGrath0f87c492003-06-03 23:29:04 +00001186#ifdef ARM
1187 struct pt_regs regs;
1188 struct sigcontext_struct sc;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001189
Roland McGrath0f87c492003-06-03 23:29:04 +00001190 if (entering(tcp)) {
1191 tcp->u_arg[0] = 0;
1192
1193 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1194 return 0;
1195
1196 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1197 return 0;
1198
1199 tcp->u_arg[0] = 1;
1200 tcp->u_arg[1] = sc.oldmask;
1201 } else {
1202 sigset_t sigm;
1203 long_to_sigset(tcp->u_arg[1], &sigm);
1204 tcp->u_rval = tcp->u_error = 0;
1205 if (tcp->u_arg[0] == 0)
1206 return 0;
1207 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1208 return RVAL_NONE | RVAL_STR;
1209 }
1210 return 0;
1211#elif defined(S390) || defined(S390X)
1212 long usp;
1213 struct sigcontext_struct sc;
1214
1215 if (entering(tcp)) {
1216 tcp->u_arg[0] = 0;
1217 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1218 return 0;
1219 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1220 return 0;
1221 tcp->u_arg[0] = 1;
1222 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1223 } else {
1224 tcp->u_rval = tcp->u_error = 0;
1225 if (tcp->u_arg[0] == 0)
1226 return 0;
1227 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1228 return RVAL_NONE | RVAL_STR;
1229 }
1230 return 0;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001231#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001232#ifdef I386
1233 long esp;
1234 struct sigcontext_struct sc;
1235
1236 if (entering(tcp)) {
1237 tcp->u_arg[0] = 0;
1238 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1239 return 0;
1240 if (umove(tcp, esp, &sc) < 0)
1241 return 0;
1242 tcp->u_arg[0] = 1;
1243 tcp->u_arg[1] = sc.oldmask;
1244 }
1245 else {
1246 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001247 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248 tcp->u_rval = tcp->u_error = 0;
1249 if (tcp->u_arg[0] == 0)
1250 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001251 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001252 return RVAL_NONE | RVAL_STR;
1253 }
1254 return 0;
1255#else /* !I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001256#ifdef IA64
1257 struct sigcontext sc;
1258 long sp;
1259
1260 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001261 /* offset of sigcontext in the kernel's sigframe structure: */
1262# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001263 tcp->u_arg[0] = 0;
1264 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1265 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001266 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001267 return 0;
1268 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001269 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001270 }
1271 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001272 sigset_t sigm;
1273
1274 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001275 tcp->u_rval = tcp->u_error = 0;
1276 if (tcp->u_arg[0] == 0)
1277 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001278 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001279 return RVAL_NONE | RVAL_STR;
1280 }
1281 return 0;
1282#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001283#ifdef POWERPC
Roland McGrath0f87c492003-06-03 23:29:04 +00001284 long esp;
1285 struct sigcontext_struct sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001286
Roland McGrath0f87c492003-06-03 23:29:04 +00001287 if (entering(tcp)) {
1288 tcp->u_arg[0] = 0;
1289 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1290 return 0;
1291 if (umove(tcp, esp, &sc) < 0)
1292 return 0;
1293 tcp->u_arg[0] = 1;
1294 tcp->u_arg[1] = sc.oldmask;
1295 }
1296 else {
1297 sigset_t sigm;
1298 long_to_sigset(tcp->u_arg[1], &sigm);
1299 tcp->u_rval = tcp->u_error = 0;
1300 if (tcp->u_arg[0] == 0)
1301 return 0;
1302 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1303 return RVAL_NONE | RVAL_STR;
1304 }
1305 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001306#else /* !POWERPC */
1307#ifdef M68K
1308 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001309 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001310
1311 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001312 tcp->u_arg[0] = 0;
1313 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001315 if (umove(tcp, usp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001316 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001317 tcp->u_arg[0] = 1;
1318 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001319 }
1320 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001321 sigset_t sigm;
1322 long_to_sigset(tcp->u_arg[1], &sigm);
1323 tcp->u_rval = tcp->u_error = 0;
1324 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001325 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001326 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1327 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001328 }
1329 return 0;
1330#else /* !M68K */
1331#ifdef ALPHA
1332 long fp;
1333 struct sigcontext_struct sc;
1334
1335 if (entering(tcp)) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001336 tcp->u_arg[0] = 0;
1337 if (upeek(tcp->pid, REG_FP, &fp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001338 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001339 if (umove(tcp, fp, &sc) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001340 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001341 tcp->u_arg[0] = 1;
1342 tcp->u_arg[1] = sc.sc_mask;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001343 }
1344 else {
Roland McGrath0f87c492003-06-03 23:29:04 +00001345 sigset_t sigm;
1346 long_to_sigset(tcp->u_arg[1], &sigm);
1347 tcp->u_rval = tcp->u_error = 0;
1348 if (tcp->u_arg[0] == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001349 return 0;
Roland McGrath0f87c492003-06-03 23:29:04 +00001350 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1351 return RVAL_NONE | RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001352 }
1353 return 0;
1354#else
1355#ifdef SPARC
1356 long i1;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001357 struct regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001358 m_siginfo_t si;
1359
1360 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
Roland McGrath0f87c492003-06-03 23:29:04 +00001361 perror("sigreturn: PTRACE_GETREGS ");
1362 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001363 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001364 if(entering(tcp)) {
1365 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001366 i1 = regs.r_o1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001367 if(umove(tcp, i1, &si) < 0) {
1368 perror("sigreturn: umove ");
1369 return 0;
1370 }
1371 tcp->u_arg[0] = 1;
1372 tcp->u_arg[1] = si.si_mask;
1373 } else {
1374 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001375 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001376 tcp->u_rval = tcp->u_error = 0;
1377 if(tcp->u_arg[0] == 0)
1378 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001379 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001380 return RVAL_NONE | RVAL_STR;
1381 }
1382 return 0;
Roland McGratha39c5a12002-12-17 05:10:37 +00001383#else
Wichert Akkermanf90da011999-10-31 21:15:38 +00001384#ifdef MIPS
1385 long sp;
1386 struct sigcontext sc;
1387
1388 if(entering(tcp)) {
1389 tcp->u_arg[0] = 0;
1390 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1391 return 0;
1392 if (umove(tcp, sp, &sc) < 0)
1393 return 0;
1394 tcp->u_arg[0] = 1;
1395 tcp->u_arg[1] = sc.sc_sigset;
1396 } else {
1397 tcp->u_rval = tcp->u_error = 0;
1398 if(tcp->u_arg[0] == 0)
1399 return 0;
1400 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1401 return RVAL_NONE | RVAL_STR;
1402 }
1403 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001404#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001405#warning No sys_sigreturn() for this architecture
1406#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001407 return 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001408#endif /* MIPS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409#endif /* SPARC */
1410#endif /* ALPHA */
1411#endif /* !M68K */
1412#endif /* !POWERPC */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001413#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001414#endif /* !I386 */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001415#endif /* S390 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001416}
1417
1418int
1419sys_siggetmask(tcp)
1420struct tcb *tcp;
1421{
1422 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001423 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001424 long_to_sigset(tcp->u_rval, &sigm);
1425 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001426 }
1427 return RVAL_HEX | RVAL_STR;
1428}
1429
1430int
1431sys_sigsuspend(tcp)
1432struct tcb *tcp;
1433{
1434 if (entering(tcp)) {
1435 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001436 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001437#if 0
1438 /* first two are not really arguments, but print them anyway */
1439 /* nevermind, they are an anachronism now, too bad... */
1440 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1441#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001442 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001443 }
1444 return 0;
1445}
1446
1447#endif /* LINUX */
1448
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001449#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001450
1451int
1452sys_sigsuspend(tcp)
1453struct tcb *tcp;
1454{
1455 sigset_t sigset;
1456
1457 if (entering(tcp)) {
1458 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1459 tprintf("[?]");
1460 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001461 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001462 }
1463 return 0;
1464}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001465#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001466static struct xlat ucontext_flags[] = {
1467 { UC_SIGMASK, "UC_SIGMASK" },
1468 { UC_STACK, "UC_STACK" },
1469 { UC_CPU, "UC_CPU" },
1470#ifdef UC_FPU
1471 { UC_FPU, "UC_FPU" },
1472#endif
1473#ifdef UC_INTR
1474 { UC_INTR, "UC_INTR" },
1475#endif
1476 { 0, NULL },
1477};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001478#endif /* !FREEBSD */
1479#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001480
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001481#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001482#if defined LINUX && !defined SS_ONSTACK
1483#define SS_ONSTACK 1
1484#define SS_DISABLE 2
1485#if __GLIBC_MINOR__ == 0
1486typedef struct
1487{
1488 __ptr_t ss_sp;
1489 int ss_flags;
1490 size_t ss_size;
1491} stack_t;
1492#endif
1493#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001494#ifdef FREEBSD
1495#define stack_t struct sigaltstack
1496#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001497
1498static struct xlat sigaltstack_flags[] = {
1499 { SS_ONSTACK, "SS_ONSTACK" },
1500 { SS_DISABLE, "SS_DISABLE" },
1501 { 0, NULL },
1502};
1503#endif
1504
1505#ifdef SVR4
1506static void
1507printcontext(tcp, ucp)
1508struct tcb *tcp;
1509ucontext_t *ucp;
1510{
1511 tprintf("{");
1512 if (!abbrev(tcp)) {
1513 tprintf("uc_flags=");
1514 if (!printflags(ucontext_flags, ucp->uc_flags))
1515 tprintf("0");
1516 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1517 }
1518 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001519 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001520 if (!abbrev(tcp)) {
1521 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1522 (unsigned long) ucp->uc_stack.ss_sp,
1523 ucp->uc_stack.ss_size);
1524 if (!printflags(sigaltstack_flags, ucp->uc_stack.ss_flags))
1525 tprintf("0");
1526 tprintf("}");
1527 }
1528 tprintf(", ...}");
1529}
1530
1531int
1532sys_getcontext(tcp)
1533struct tcb *tcp;
1534{
1535 ucontext_t uc;
1536
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001537 if (exiting(tcp)) {
1538 if (tcp->u_error)
1539 tprintf("%#lx", tcp->u_arg[0]);
1540 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001541 tprintf("NULL");
1542 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1543 tprintf("{...}");
1544 else
1545 printcontext(tcp, &uc);
1546 }
1547 return 0;
1548}
1549
1550int
1551sys_setcontext(tcp)
1552struct tcb *tcp;
1553{
1554 ucontext_t uc;
1555
1556 if (entering(tcp)) {
1557 if (!tcp->u_arg[0])
1558 tprintf("NULL");
1559 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1560 tprintf("{...}");
1561 else
1562 printcontext(tcp, &uc);
1563 }
1564 else {
1565 tcp->u_rval = tcp->u_error = 0;
1566 if (tcp->u_arg[0] == 0)
1567 return 0;
1568 return RVAL_NONE;
1569 }
1570 return 0;
1571}
1572
1573#endif /* SVR4 */
1574
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001575#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576
1577static int
1578print_stack_t(tcp, addr)
1579struct tcb *tcp;
1580unsigned long addr;
1581{
1582 stack_t ss;
1583 if (umove(tcp, addr, &ss) < 0)
1584 return -1;
1585 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1586 if (!printflags(sigaltstack_flags, ss.ss_flags))
1587 tprintf("0");
1588 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1589 return 0;
1590}
1591
1592int
1593sys_sigaltstack(tcp)
1594 struct tcb *tcp;
1595{
1596 if (entering(tcp)) {
1597 if (tcp->u_arg[0] == 0)
1598 tprintf("NULL");
1599 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1600 return -1;
1601 }
1602 else {
1603 tprintf(", ");
1604 if (tcp->u_arg[1] == 0)
1605 tprintf("NULL");
1606 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1607 return -1;
1608 }
1609 return 0;
1610}
1611#endif
1612
1613#ifdef HAVE_SIGACTION
1614
1615int
1616sys_sigprocmask(tcp)
1617struct tcb *tcp;
1618{
1619#ifdef ALPHA
1620 if (entering(tcp)) {
1621 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1622 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001623 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001624 }
1625 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001626 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001627 return RVAL_HEX | RVAL_STR;
1628 }
1629#else /* !ALPHA */
1630 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631
1632 if (entering(tcp)) {
1633#ifdef SVR4
1634 if (tcp->u_arg[0] == 0)
1635 tprintf("0");
1636 else
1637#endif /* SVR4 */
1638 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1639 tprintf(", ");
1640 if (!tcp->u_arg[1])
1641 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001642 else if (copy_sigset(tcp, tcp->u_arg[1], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001643 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001644 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001645 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646 tprintf(", ");
1647 }
1648 }
1649 else {
1650 if (!tcp->u_arg[2])
1651 tprintf("NULL");
1652 else if (syserror(tcp))
1653 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001654 else if (copy_sigset(tcp, tcp->u_arg[2], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001655 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001656 else
Nate Sammons4a121431999-04-06 01:19:39 +00001657 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001658 }
1659#endif /* !ALPHA */
1660 return 0;
1661}
1662
1663#endif /* HAVE_SIGACTION */
1664
1665int
1666sys_kill(tcp)
1667struct tcb *tcp;
1668{
1669 if (entering(tcp)) {
Nate Sammonsce780fc1999-03-29 23:23:13 +00001670 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001671 }
1672 return 0;
1673}
1674
1675int
1676sys_killpg(tcp)
1677struct tcb *tcp;
1678{
1679 return sys_kill(tcp);
1680}
1681
Roland McGrath8ffc3522003-07-09 09:47:49 +00001682#ifdef LINUX
1683int
1684sys_tgkill(tcp)
1685 struct tcb *tcp;
1686{
1687 if (entering(tcp)) {
1688 tprintf("%ld, %ld, %s",
1689 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1690 }
1691 return 0;
1692}
1693#endif
1694
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001695int
1696sys_sigpending(tcp)
1697struct tcb *tcp;
1698{
1699 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001700
1701 if (exiting(tcp)) {
1702 if (syserror(tcp))
1703 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001704 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001705 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001706 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001707 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001708 }
1709 return 0;
1710}
1711
John Hughes42162082001-10-18 14:48:26 +00001712int sys_sigwait(tcp)
1713struct tcb *tcp;
1714{
1715 sigset_t sigset;
1716
1717 if (entering(tcp)) {
1718 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1719 tprintf("[?]");
1720 else
1721 printsigmask(&sigset, 0);
1722 }
1723 else {
1724 if (!syserror(tcp)) {
1725 tcp->auxstr = signalent[tcp->u_rval];
1726 return RVAL_DECIMAL | RVAL_STR;
1727 }
1728 }
1729 return 0;
1730}
1731
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001732#ifdef LINUX
1733
1734 int
1735sys_rt_sigprocmask(tcp)
1736 struct tcb *tcp;
1737{
1738 sigset_t sigset;
1739
Nate Sammons4a121431999-04-06 01:19:39 +00001740 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001741 if (entering(tcp)) {
1742 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1743 tprintf(", ");
1744 if (!tcp->u_arg[1])
1745 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001746 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001747 tprintf("%#lx, ", tcp->u_arg[1]);
1748 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001749 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001750 tprintf(", ");
1751 }
1752 }
1753 else {
1754 if (!tcp->u_arg[2])
1755
1756 tprintf("NULL");
1757 else if (syserror(tcp))
1758 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001759 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760 tprintf("[?]");
1761 else
Nate Sammons4a121431999-04-06 01:19:39 +00001762 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001763 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001764 }
1765 return 0;
1766}
1767
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001768
1769/* Structure describing the action to be taken when a signal arrives. */
1770struct new_sigaction
1771{
1772 union
1773 {
1774 __sighandler_t __sa_handler;
1775 void (*__sa_sigaction) (int, siginfo_t *, void *);
1776 }
1777 __sigaction_handler;
1778 unsigned long sa_flags;
1779 void (*sa_restorer) (void);
1780 unsigned long int sa_mask[2];
1781};
1782
1783
1784 int
1785sys_rt_sigaction(tcp)
1786 struct tcb *tcp;
1787{
1788 struct new_sigaction sa;
1789 sigset_t sigset;
1790 long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791
1792 if (entering(tcp)) {
1793 printsignal(tcp->u_arg[0]);
1794 tprintf(", ");
1795 addr = tcp->u_arg[1];
1796 } else
1797 addr = tcp->u_arg[2];
1798 if (addr == 0)
1799 tprintf("NULL");
1800 else if (!verbose(tcp))
1801 tprintf("%#lx", addr);
1802 else if (umove(tcp, addr, &sa) < 0)
1803 tprintf("{...}");
1804 else {
1805 switch ((long) sa.__sigaction_handler.__sa_handler) {
1806 case (long) SIG_ERR:
1807 tprintf("{SIG_ERR}");
1808 break;
1809 case (long) SIG_DFL:
1810 tprintf("{SIG_DFL}");
1811 break;
1812 case (long) SIG_IGN:
1813 tprintf("{SIG_IGN}");
1814 break;
1815 default:
1816 tprintf("{%#lx, ",
1817 (long) sa.__sigaction_handler.__sa_handler);
Nate Sammons4a121431999-04-06 01:19:39 +00001818 sigemptyset(&sigset);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001819#ifdef LINUXSPARC
1820 if (tcp->u_arg[4] <= sizeof(sigset))
1821 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1822#else
Nate Sammons4a121431999-04-06 01:19:39 +00001823 if (tcp->u_arg[3] <= sizeof(sigset))
1824 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001825#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001826 else
1827 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1828 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001829 tprintf(", ");
1830 if (!printflags(sigact_flags, sa.sa_flags))
1831 tprintf("0");
Roland McGrath2638cb42002-12-15 23:58:41 +00001832#ifdef SA_RESTORER
1833 if (sa.sa_flags & SA_RESTORER)
1834 tprintf(", %p", sa.sa_restorer);
1835#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001836 tprintf("}");
1837 }
1838 }
1839 if (entering(tcp))
1840 tprintf(", ");
1841 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001842#ifdef LINUXSPARC
1843 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1844#elif defined(ALPHA)
1845 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1846#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001847 tprintf(", %lu", addr = tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001848#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849 return 0;
1850}
1851
1852 int
1853sys_rt_sigpending(tcp)
1854 struct tcb *tcp;
1855{
1856 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001857
1858 if (exiting(tcp)) {
1859 if (syserror(tcp))
1860 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001861 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1862 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001863 tprintf("[?]");
1864 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001865 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866 }
1867 return 0;
1868}
1869 int
1870sys_rt_sigsuspend(tcp)
1871 struct tcb *tcp;
1872{
1873 if (entering(tcp)) {
1874 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001875 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1876 tprintf("[?]");
1877 else
1878 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001879 }
1880 return 0;
1881}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001882 int
1883sys_rt_sigqueueinfo(tcp)
1884 struct tcb *tcp;
1885{
1886 if (entering(tcp)) {
1887 siginfo_t si;
1888 tprintf("%lu, ", tcp->u_arg[0]);
1889 printsignal(tcp->u_arg[1]);
1890 tprintf(", ");
1891 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1892 tprintf("%#lx", tcp->u_arg[2]);
1893 else
John Hughes58265892001-10-18 15:13:53 +00001894 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001895 }
1896 return 0;
1897}
1898
1899int sys_rt_sigtimedwait(tcp)
1900 struct tcb *tcp;
1901{
1902 if (entering(tcp)) {
1903 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001904
Roland McGratha39c5a12002-12-17 05:10:37 +00001905 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00001906 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001907 tprintf("[?]");
1908 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001909 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910 tprintf(", ");
1911 }
1912 else {
1913 if (syserror(tcp))
1914 tprintf("%#lx", tcp->u_arg[0]);
1915 else {
1916 siginfo_t si;
1917 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1918 tprintf("%#lx", tcp->u_arg[1]);
1919 else
John Hughes58265892001-10-18 15:13:53 +00001920 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001921 /* XXX For now */
1922 tprintf(", %#lx", tcp->u_arg[2]);
1923 tprintf(", %d", (int) tcp->u_arg[3]);
1924 }
1925 }
1926 return 0;
1927};
1928
1929#endif /* LINUX */