blob: 64b15682b289606b1a327adc276245b4b46ccf5e [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 */
419#endif
420
421#if __GLIBC_MINOR__ < 1
422/* Type for data associated with a signal. */
423typedef union sigval
424{
425 int sival_int;
426 void *sival_ptr;
427} sigval_t;
428
429# define __SI_MAX_SIZE 128
430# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
431
432typedef struct siginfo
433{
434 int si_signo; /* Signal number. */
435 int si_errno; /* If non-zero, an errno value associated with
436 this signal, as defined in <errno.h>. */
437 int si_code; /* Signal code. */
438
439 union
440 {
441 int _pad[__SI_PAD_SIZE];
442
443 /* kill(). */
444 struct
445 {
446 __pid_t si_pid; /* Sending process ID. */
447 __uid_t si_uid; /* Real user ID of sending process. */
448 } _kill;
449
450 /* POSIX.1b timers. */
451 struct
452 {
453 unsigned int _timer1;
454 unsigned int _timer2;
455 } _timer;
456
457 /* POSIX.1b signals. */
458 struct
459 {
460 __pid_t si_pid; /* Sending process ID. */
461 __uid_t si_uid; /* Real user ID of sending process. */
462 sigval_t si_sigval; /* Signal value. */
463 } _rt;
464
465 /* SIGCHLD. */
466 struct
467 {
468 __pid_t si_pid; /* Which child. */
469 int si_status; /* Exit value or signal. */
470 __clock_t si_utime;
471 __clock_t si_stime;
472 } _sigchld;
473
474 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
475 struct
476 {
477 void *si_addr; /* Faulting insn/memory ref. */
478 } _sigfault;
479
480 /* SIGPOLL. */
481 struct
482 {
483 int si_band; /* Band event for SIGPOLL. */
484 int si_fd;
485 } _sigpoll;
486 } _sifields;
487} siginfo_t;
488
489#define si_pid _sifields._kill.si_pid
490#define si_uid _sifields._kill.si_uid
491#define si_status _sifields._sigchld.si_status
492#define si_utime _sifields._sigchld.si_utime
493#define si_stime _sifields._sigchld.si_stime
494#define si_value _sifields._rt.si_sigval
495#define si_int _sifields._rt.si_sigval.sival_int
496#define si_ptr _sifields._rt.si_sigval.sival_ptr
497#define si_addr _sifields._sigfault.si_addr
498#define si_band _sifields._sigpoll.si_band
499#define si_fd _sifields._sigpoll.si_fd
500
501#endif
502
503#endif
504
505#if defined (SVR4) || defined (LINUX)
506
507static struct xlat siginfo_codes[] = {
508#ifdef SI_NOINFO
509 { SI_NOINFO, "SI_NOINFO" },
510#endif
511#ifdef SI_USER
512 { SI_USER, "SI_USER" },
513#endif
514#ifdef SI_LWP
515 { SI_LWP, "SI_LWP" },
516#endif
517#ifdef SI_QUEUE
518 { SI_QUEUE, "SI_QUEUE" },
519#endif
520#ifdef SI_TIMER
521 { SI_TIMER, "SI_TIMER" },
522#endif
523#ifdef SI_ASYNCIO
524 { SI_ASYNCIO, "SI_ASYNCIO" },
525#endif
526#ifdef SI_MESGQ
527 { SI_MESGQ, "SI_MESGQ" },
528#endif
529 { 0, NULL },
530};
531
532static struct xlat sigill_codes[] = {
533 { ILL_ILLOPC, "ILL_ILLOPC" },
534 { ILL_ILLOPN, "ILL_ILLOPN" },
535 { ILL_ILLADR, "ILL_ILLADR" },
536 { ILL_ILLTRP, "ILL_ILLTRP" },
537 { ILL_PRVOPC, "ILL_PRVOPC" },
538 { ILL_PRVREG, "ILL_PRVREG" },
539 { ILL_COPROC, "ILL_COPROC" },
540 { ILL_BADSTK, "ILL_BADSTK" },
541 { 0, NULL },
542};
543
544static struct xlat sigfpe_codes[] = {
545 { FPE_INTDIV, "FPE_INTDIV" },
546 { FPE_INTOVF, "FPE_INTOVF" },
547 { FPE_FLTDIV, "FPE_FLTDIV" },
548 { FPE_FLTOVF, "FPE_FLTOVF" },
549 { FPE_FLTUND, "FPE_FLTUND" },
550 { FPE_FLTRES, "FPE_FLTRES" },
551 { FPE_FLTINV, "FPE_FLTINV" },
552 { FPE_FLTSUB, "FPE_FLTSUB" },
553 { 0, NULL },
554};
555
556static struct xlat sigtrap_codes[] = {
557 { TRAP_BRKPT, "TRAP_BRKPT" },
558 { TRAP_TRACE, "TRAP_TRACE" },
559 { 0, NULL },
560};
561
562static struct xlat sigchld_codes[] = {
563 { CLD_EXITED, "CLD_EXITED" },
564 { CLD_KILLED, "CLD_KILLED" },
565 { CLD_DUMPED, "CLD_DUMPED" },
566 { CLD_TRAPPED, "CLD_TRAPPED" },
567 { CLD_STOPPED, "CLD_STOPPED" },
568 { CLD_CONTINUED,"CLD_CONTINUED" },
569 { 0, NULL },
570};
571
572static struct xlat sigpoll_codes[] = {
573 { POLL_IN, "POLL_IN" },
574 { POLL_OUT, "POLL_OUT" },
575 { POLL_MSG, "POLL_MSG" },
576 { POLL_ERR, "POLL_ERR" },
577 { POLL_PRI, "POLL_PRI" },
578 { POLL_HUP, "POLL_HUP" },
579 { 0, NULL },
580};
581
582static struct xlat sigprof_codes[] = {
583#ifdef PROF_SIG
584 { PROF_SIG, "PROF_SIG" },
585#endif
586 { 0, NULL },
587};
588
589#ifdef SIGEMT
590static struct xlat sigemt_codes[] = {
591#ifdef EMT_TAGOVF
592 { EMT_TAGOVF, "EMT_TAGOVF" },
593#endif
594 { 0, NULL },
595};
596#endif
597
598static struct xlat sigsegv_codes[] = {
599 { SEGV_MAPERR, "SEGV_MAPERR" },
600 { SEGV_ACCERR, "SEGV_ACCERR" },
601 { 0, NULL },
602};
603
604static struct xlat sigbus_codes[] = {
605 { BUS_ADRALN, "BUS_ADRALN" },
606 { BUS_ADRERR, "BUS_ADRERR" },
607 { BUS_OBJERR, "BUS_OBJERR" },
608 { 0, NULL },
609};
610
611void
612printsiginfo(sip, verbose)
613siginfo_t *sip;
614int verbose;
615{
616 char *code;
617
618 if (sip->si_signo == 0) {
619 tprintf ("{}");
620 return;
621 }
622 tprintf("{si_signo=");
623 printsignal(sip->si_signo);
624 code = xlookup(siginfo_codes, sip->si_code);
625 if (!code) {
626 switch (sip->si_signo) {
627 case SIGTRAP:
628 code = xlookup(sigtrap_codes, sip->si_code);
629 break;
630 case SIGCHLD:
631 code = xlookup(sigchld_codes, sip->si_code);
632 break;
633 case SIGPOLL:
634 code = xlookup(sigpoll_codes, sip->si_code);
635 break;
636 case SIGPROF:
637 code = xlookup(sigprof_codes, sip->si_code);
638 break;
639 case SIGILL:
640 code = xlookup(sigill_codes, sip->si_code);
641 break;
642#ifdef SIGEMT
643 case SIGEMT:
644 code = xlookup(sigemt_codes, sip->si_code);
645 break;
646#endif
647 case SIGFPE:
648 code = xlookup(sigfpe_codes, sip->si_code);
649 break;
650 case SIGSEGV:
651 code = xlookup(sigsegv_codes, sip->si_code);
652 break;
653 case SIGBUS:
654 code = xlookup(sigbus_codes, sip->si_code);
655 break;
656 }
657 }
658 if (code)
659 tprintf(", si_code=%s", code);
660 else
661 tprintf(", si_code=%#x", sip->si_code);
662#ifdef SI_NOINFO
663 if (sip->si_code != SI_NOINFO)
664#endif
665 {
666 if (sip->si_errno) {
667 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
668 tprintf(", si_errno=%d", sip->si_errno);
669 else
670 tprintf(", si_errno=%s",
671 errnoent[sip->si_errno]);
672 }
673#ifdef SI_FROMUSER
674 if (SI_FROMUSER(sip)) {
675 tprintf(", si_pid=%ld, si_uid=%ld",
676 sip->si_pid, sip->si_uid);
677#ifdef SI_QUEUE
678 switch (sip->si_code) {
679 case SI_QUEUE:
680#ifdef SI_TIMER
681 case SI_TIMER:
682#endif /* SI_QUEUE */
683 case SI_ASYNCIO:
684#ifdef SI_MESGQ
685 case SI_MESGQ:
686#endif /* SI_MESGQ */
687 tprintf(", si_value=%d",
688 sip->si_value.sival_int);
689 break;
690 }
691#endif /* SI_QUEUE */
692 }
693 else
694#endif /* SI_FROMUSER */
695 {
696 switch (sip->si_signo) {
697 case SIGCHLD:
698 tprintf(", si_pid=%ld, si_status=",
699 (long) sip->si_pid);
700 if (sip->si_code == CLD_EXITED)
701 tprintf("%d", sip->si_status);
702 else
703 printsignal(sip->si_status);
704#if LINUX
705 if (!verbose)
706 tprintf(", ...");
707 else
708 tprintf(", si_utime=%lu, si_stime=%lu",
709 sip->si_utime,
710 sip->si_stime);
711#endif
712 break;
713 case SIGILL: case SIGFPE:
714 case SIGSEGV: case SIGBUS:
715 tprintf(", si_addr=%#lx",
716 (unsigned long) sip->si_addr);
717 break;
718 case SIGPOLL:
719 switch (sip->si_code) {
720 case POLL_IN: case POLL_OUT: case POLL_MSG:
721 tprintf(", si_band=%ld",
722 (long) sip->si_band);
723 break;
724 }
725 break;
726#ifdef LINUX
727 default:
728 tprintf(", si_pid=%lu, si_uid=%lu, ",
729 (unsigned long) sip->si_pid,
730 (unsigned long) sip->si_uid);
731 if (!verbose)
732 tprintf("...");
733 else {
734 tprintf("si_value={int=%u, ptr=%#lx}",
735 sip->si_int,
736 (unsigned long) sip->si_ptr);
737 }
738#endif
Roland McGratha39c5a12002-12-17 05:10:37 +0000739
John Hughes58265892001-10-18 15:13:53 +0000740 }
741 }
742 }
743 tprintf("}");
744}
745
746#endif /* SVR4 || LINUX */
747
748#ifdef LINUX
749
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000750static void
751parse_sigset_t (const char *str, sigset_t *set)
752{
753 unsigned int digit;
754 int i;
755
756 sigemptyset(set);
757
758 for (i = _NSIG - 4; i >= 0; i -= 4, ++str) {
759 if (*str >= 'a')
760 digit = (*str - 'a') + 10;
761 else
762 digit = *str - '0';
763 if (digit & 1)
764 sigaddset(set, i + 1);
765 if (digit & 2)
766 sigaddset(set, i + 2);
767 if (digit & 4)
768 sigaddset(set, i + 3);
769 if (digit & 8)
770 sigaddset(set, i + 4);
771 }
772}
773
774#endif
775
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776/*
777 * Check process TCP for the disposition of signal SIG.
778 * Return 1 if the process would somehow manage to survive signal SIG,
779 * else return 0. This routine will never be called with SIGKILL.
780 */
781int
782sigishandled(tcp, sig)
783struct tcb *tcp;
784int sig;
785{
786#ifdef LINUX
787 int sfd;
788 char sname[32];
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000789 char buf[2048];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000790 char *s;
791 int i;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000792 sigset_t ignored, caught;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000793#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000794#ifdef SVR4
795 /*
796 * Since procfs doesn't interfere with wait I think it is safe
797 * to punt on this question. If not, the information is there.
798 */
799 return 1;
800#else /* !SVR4 */
801 switch (sig) {
802 case SIGCONT:
803 case SIGSTOP:
804 case SIGTSTP:
805 case SIGTTIN:
806 case SIGTTOU:
807 case SIGCHLD:
808 case SIGIO:
809#if defined(SIGURG) && SIGURG != SIGIO
810 case SIGURG:
811#endif
812 case SIGWINCH:
813 /* Gloria Gaynor says ... */
814 return 1;
815 default:
816 break;
817 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000818#endif /* !SVR4 */
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000819#ifdef LINUX
820
821 /* This is incredibly costly but it's worth it. */
822 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
823 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
824 doesn't handle real-time signals). */
825 sprintf(sname, "/proc/%d/status", tcp->pid);
826 if ((sfd = open(sname, O_RDONLY)) == -1) {
827 perror(sname);
828 return 1;
829 }
830 i = read(sfd, buf, sizeof(buf));
831 buf[i] = '\0';
832 close(sfd);
833 /*
834 * Skip the extraneous fields. We need to skip
835 * command name has any spaces in it. So be it.
836 */
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000837 s = strstr(buf, "SigIgn:\t");
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000838 if (!s)
839 {
840 fprintf(stderr, "/proc/pid/status format error\n");
841 return 1;
842 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000843 parse_sigset_t(s + 8, &ignored);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000844
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000845 s = strstr(buf, "SigCgt:\t");
846 if (!s)
847 {
848 fprintf(stderr, "/proc/pid/status format error\n");
849 return 1;
850 }
851 parse_sigset_t(s + 8, &caught);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000852
853#ifdef DEBUG
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000854 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
855 *(long long *) &ignored, *(long long *) &caught, sig);
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000856#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000857 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
Wichert Akkermand5c2dae2001-04-12 09:10:24 +0000858 return 1;
859#endif /* LINUX */
860
861#ifdef SUNOS4
862 void (*u_signal)();
863
864 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
865 (long *) &u_signal) < 0) {
866 return 0;
867 }
868 if (u_signal != SIG_DFL)
869 return 1;
870#endif /* SUNOS4 */
871
872 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000873}
874
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000875#if defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000876
877int
878sys_sigvec(tcp)
879struct tcb *tcp;
880{
881 struct sigvec sv;
882 long addr;
883
884 if (entering(tcp)) {
885 printsignal(tcp->u_arg[0]);
886 tprintf(", ");
887 addr = tcp->u_arg[1];
888 } else {
889 addr = tcp->u_arg[2];
890 }
891 if (addr == 0)
892 tprintf("NULL");
893 else if (!verbose(tcp))
894 tprintf("%#lx", addr);
895 else if (umove(tcp, addr, &sv) < 0)
896 tprintf("{...}");
897 else {
898 switch ((int) sv.sv_handler) {
899 case (int) SIG_ERR:
900 tprintf("{SIG_ERR}");
901 break;
902 case (int) SIG_DFL:
903 tprintf("{SIG_DFL}");
904 break;
905 case (int) SIG_IGN:
906 if (tcp->u_arg[0] == SIGTRAP) {
907 tcp->flags |= TCB_SIGTRAPPED;
908 kill(tcp->pid, SIGSTOP);
909 }
910 tprintf("{SIG_IGN}");
911 break;
912 case (int) SIG_HOLD:
913 if (tcp->u_arg[0] == SIGTRAP) {
914 tcp->flags |= TCB_SIGTRAPPED;
915 kill(tcp->pid, SIGSTOP);
916 }
917 tprintf("SIG_HOLD");
918 break;
919 default:
920 if (tcp->u_arg[0] == SIGTRAP) {
921 tcp->flags |= TCB_SIGTRAPPED;
922 kill(tcp->pid, SIGSTOP);
923 }
924 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000925 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000926 tprintf(", ");
927 if (!printflags(sigvec_flags, sv.sv_flags))
928 tprintf("0");
929 tprintf("}");
930 }
931 }
932 if (entering(tcp))
933 tprintf(", ");
934 return 0;
935}
936
937int
938sys_sigpause(tcp)
939struct tcb *tcp;
940{
941 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000942 sigset_t sigm;
943 long_to_sigset(tcp->u_arg[0], &sigm);
944 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000945 }
946 return 0;
947}
948
949int
950sys_sigstack(tcp)
951struct tcb *tcp;
952{
953 struct sigstack ss;
954 long addr;
955
956 if (entering(tcp))
957 addr = tcp->u_arg[0];
958 else
959 addr = tcp->u_arg[1];
960 if (addr == 0)
961 tprintf("NULL");
962 else if (umove(tcp, addr, &ss) < 0)
963 tprintf("%#lx", addr);
964 else {
965 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
966 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
967 }
968 if (entering(tcp))
969 tprintf(", ");
970 return 0;
971}
972
973int
974sys_sigcleanup(tcp)
975struct tcb *tcp;
976{
977 return 0;
978}
979
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000980#endif /* SUNOS4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000981
982#ifndef SVR4
983
984int
985sys_sigsetmask(tcp)
986struct tcb *tcp;
987{
988 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000989 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000990 long_to_sigset(tcp->u_arg[0], &sigm);
991 printsigmask(&sigm, 0);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000992#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000993 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
994 /* Mark attempt to block SIGTRAP */
995 tcp->flags |= TCB_SIGTRAPPED;
996 /* Send unblockable signal */
997 kill(tcp->pid, SIGSTOP);
998 }
Roland McGratha39c5a12002-12-17 05:10:37 +0000999#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001000 }
1001 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001002 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001003 long_to_sigset(tcp->u_rval, &sigm);
1004 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005
1006 return RVAL_HEX | RVAL_STR;
1007 }
1008 return 0;
1009}
1010
1011int
1012sys_sigblock(tcp)
1013struct tcb *tcp;
1014{
1015 return sys_sigsetmask(tcp);
1016}
1017
1018#endif /* !SVR4 */
1019
1020#ifdef HAVE_SIGACTION
1021
1022#ifdef LINUX
1023struct old_sigaction {
1024 __sighandler_t __sa_handler;
1025 unsigned long sa_mask;
1026 unsigned long sa_flags;
1027 void (*sa_restorer)(void);
1028};
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001029#define SA_HANDLER __sa_handler
1030#endif /* LINUX */
1031
Roland McGratha39c5a12002-12-17 05:10:37 +00001032#ifndef SA_HANDLER
1033#define SA_HANDLER sa_handler
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034#endif
1035
1036int
1037sys_sigaction(tcp)
1038struct tcb *tcp;
1039{
1040 long addr;
Nate Sammons4a121431999-04-06 01:19:39 +00001041#ifdef LINUX
John Hughes1e4cb342001-03-06 09:25:46 +00001042 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001044#else
1045 struct sigaction sa;
1046#endif
1047
1048
1049 if (entering(tcp)) {
1050 printsignal(tcp->u_arg[0]);
1051 tprintf(", ");
1052 addr = tcp->u_arg[1];
1053 } else
1054 addr = tcp->u_arg[2];
1055 if (addr == 0)
1056 tprintf("NULL");
1057 else if (!verbose(tcp))
1058 tprintf("%#lx", addr);
1059 else if (umove(tcp, addr, &sa) < 0)
1060 tprintf("{...}");
1061 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001062 switch ((long) sa.SA_HANDLER) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063 case (long) SIG_ERR:
1064 tprintf("{SIG_ERR}");
1065 break;
1066 case (long) SIG_DFL:
1067 tprintf("{SIG_DFL}");
1068 break;
1069 case (long) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001070#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071 if (tcp->u_arg[0] == SIGTRAP) {
1072 tcp->flags |= TCB_SIGTRAPPED;
1073 kill(tcp->pid, SIGSTOP);
1074 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001075#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001076 tprintf("{SIG_IGN}");
1077 break;
1078 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001079#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001080 if (tcp->u_arg[0] == SIGTRAP) {
1081 tcp->flags |= TCB_SIGTRAPPED;
1082 kill(tcp->pid, SIGSTOP);
1083 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001084#endif /* !USE_PROCFS */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001085 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001086#ifndef LINUX
1087 printsigmask (&sa.sa_mask, 0);
1088#else
Nate Sammons4a121431999-04-06 01:19:39 +00001089 long_to_sigset(sa.sa_mask, &sigset);
1090 printsigmask(&sigset, 0);
Wichert Akkerman48214be1999-11-26 09:55:42 +00001091#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001092 tprintf(", ");
1093 if (!printflags(sigact_flags, sa.sa_flags))
1094 tprintf("0");
Roland McGrath2638cb42002-12-15 23:58:41 +00001095#ifdef SA_RESTORER
1096 if (sa.sa_flags & SA_RESTORER)
1097 tprintf(", %p", sa.sa_restorer);
1098#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099 tprintf("}");
1100 }
1101 }
1102 if (entering(tcp))
1103 tprintf(", ");
1104#ifdef LINUX
1105 else
1106 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1107#endif
1108 return 0;
1109}
1110
1111int
1112sys_signal(tcp)
1113struct tcb *tcp;
1114{
1115 if (entering(tcp)) {
1116 printsignal(tcp->u_arg[0]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001117 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001118 switch (tcp->u_arg[1]) {
1119 case (int) SIG_ERR:
1120 tprintf("SIG_ERR");
1121 break;
1122 case (int) SIG_DFL:
1123 tprintf("SIG_DFL");
1124 break;
1125 case (int) SIG_IGN:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001126#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001127 if (tcp->u_arg[0] == SIGTRAP) {
1128 tcp->flags |= TCB_SIGTRAPPED;
1129 kill(tcp->pid, SIGSTOP);
1130 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001131#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001132 tprintf("SIG_IGN");
1133 break;
1134 default:
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001135#ifndef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001136 if (tcp->u_arg[0] == SIGTRAP) {
1137 tcp->flags |= TCB_SIGTRAPPED;
1138 kill(tcp->pid, SIGSTOP);
1139 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001140#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001141 tprintf("%#lx", tcp->u_arg[1]);
1142 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001143 return 0;
1144 }
1145 else {
1146 switch (tcp->u_rval) {
1147 case (int) SIG_ERR:
1148 tcp->auxstr = "SIG_ERR"; break;
1149 case (int) SIG_DFL:
1150 tcp->auxstr = "SIG_DFL"; break;
1151 case (int) SIG_IGN:
1152 tcp->auxstr = "SIG_IGN"; break;
1153 default:
1154 tcp->auxstr = NULL;
1155 }
1156 return RVAL_HEX | RVAL_STR;
1157 }
1158}
1159
1160int
1161sys_sighold(tcp)
1162struct tcb *tcp;
1163{
1164 if (entering(tcp)) {
1165 printsignal(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001166 }
1167 return 0;
1168}
1169
1170#endif /* HAVE_SIGACTION */
1171
1172#ifdef LINUX
1173
1174int
1175sys_sigreturn(tcp)
1176struct tcb *tcp;
1177{
Michal Ludvig10a88d02002-10-07 14:31:00 +00001178#if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001179 long usp;
1180 struct sigcontext_struct sc;
1181
1182 if (entering(tcp)) {
1183 tcp->u_arg[0] = 0;
1184 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1185 return 0;
1186 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1187 return 0;
1188 tcp->u_arg[0] = 1;
1189 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1190 } else {
1191 tcp->u_rval = tcp->u_error = 0;
1192 if (tcp->u_arg[0] == 0)
1193 return 0;
Michal Ludvig10a88d02002-10-07 14:31:00 +00001194 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001195 return RVAL_NONE | RVAL_STR;
1196 }
1197 return 0;
1198#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001199#ifdef I386
1200 long esp;
1201 struct sigcontext_struct sc;
1202
1203 if (entering(tcp)) {
1204 tcp->u_arg[0] = 0;
1205 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1206 return 0;
1207 if (umove(tcp, esp, &sc) < 0)
1208 return 0;
1209 tcp->u_arg[0] = 1;
1210 tcp->u_arg[1] = sc.oldmask;
1211 }
1212 else {
1213 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001214 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001215 tcp->u_rval = tcp->u_error = 0;
1216 if (tcp->u_arg[0] == 0)
1217 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001218 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001219 return RVAL_NONE | RVAL_STR;
1220 }
1221 return 0;
1222#else /* !I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001223#ifdef IA64
1224 struct sigcontext sc;
1225 long sp;
1226
1227 if (entering(tcp)) {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001228 /* offset of sigcontext in the kernel's sigframe structure: */
1229# define SIGFRAME_SC_OFFSET 0x90
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001230 tcp->u_arg[0] = 0;
1231 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1232 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001233 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001234 return 0;
1235 tcp->u_arg[0] = 1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001236 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001237 }
1238 else {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001239 sigset_t sigm;
1240
1241 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001242 tcp->u_rval = tcp->u_error = 0;
1243 if (tcp->u_arg[0] == 0)
1244 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +00001245 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001246 return RVAL_NONE | RVAL_STR;
1247 }
1248 return 0;
1249#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001250#ifdef POWERPC
1251 long esp;
1252 struct sigcontext_struct sc;
1253
1254 if (entering(tcp)) {
1255 tcp->u_arg[0] = 0;
Roland McGratheb285352003-01-14 09:59:00 +00001256 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001257 return 0;
1258 if (umove(tcp, esp, &sc) < 0)
1259 return 0;
1260 tcp->u_arg[0] = 1;
1261 tcp->u_arg[1] = sc.oldmask;
1262 }
1263 else {
1264 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001265 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001266 tcp->u_rval = tcp->u_error = 0;
1267 if (tcp->u_arg[0] == 0)
1268 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001269 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001270 return RVAL_NONE | RVAL_STR;
1271 }
1272 return 0;
1273#else /* !POWERPC */
1274#ifdef M68K
1275 long usp;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001276 struct sigcontext sc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001277
1278 if (entering(tcp)) {
1279 tcp->u_arg[0] = 0;
1280 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
1281 return 0;
1282 if (umove(tcp, usp, &sc) < 0)
1283 return 0;
1284 tcp->u_arg[0] = 1;
1285 tcp->u_arg[1] = sc.sc_mask;
1286 }
1287 else {
1288 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001289 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290 tcp->u_rval = tcp->u_error = 0;
1291 if (tcp->u_arg[0] == 0)
1292 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001293 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294 return RVAL_NONE | RVAL_STR;
1295 }
1296 return 0;
1297#else /* !M68K */
1298#ifdef ALPHA
1299 long fp;
1300 struct sigcontext_struct sc;
1301
1302 if (entering(tcp)) {
1303 tcp->u_arg[0] = 0;
1304 if (upeek(tcp->pid, REG_FP, &fp) < 0)
1305 return 0;
1306 if (umove(tcp, fp, &sc) < 0)
1307 return 0;
1308 tcp->u_arg[0] = 1;
1309 tcp->u_arg[1] = sc.sc_mask;
1310 }
1311 else {
1312 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001313 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314 tcp->u_rval = tcp->u_error = 0;
1315 if (tcp->u_arg[0] == 0)
1316 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001317 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001318 return RVAL_NONE | RVAL_STR;
1319 }
1320 return 0;
1321#else
1322#ifdef SPARC
1323 long i1;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001324 struct regs regs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001325 m_siginfo_t si;
1326
1327 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1328 perror("sigreturn: PTRACE_GETREGS ");
1329 return 0;
1330 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001331 if(entering(tcp)) {
1332 tcp->u_arg[0] = 0;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001333 i1 = regs.r_o1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334 if(umove(tcp, i1, &si) < 0) {
1335 perror("sigreturn: umove ");
1336 return 0;
1337 }
1338 tcp->u_arg[0] = 1;
1339 tcp->u_arg[1] = si.si_mask;
1340 } else {
1341 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001342 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001343 tcp->u_rval = tcp->u_error = 0;
1344 if(tcp->u_arg[0] == 0)
1345 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +00001346 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001347 return RVAL_NONE | RVAL_STR;
1348 }
1349 return 0;
Roland McGratha39c5a12002-12-17 05:10:37 +00001350#else
Wichert Akkermanf90da011999-10-31 21:15:38 +00001351#ifdef MIPS
1352 long sp;
1353 struct sigcontext sc;
1354
1355 if(entering(tcp)) {
1356 tcp->u_arg[0] = 0;
1357 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1358 return 0;
1359 if (umove(tcp, sp, &sc) < 0)
1360 return 0;
1361 tcp->u_arg[0] = 1;
1362 tcp->u_arg[1] = sc.sc_sigset;
1363 } else {
1364 tcp->u_rval = tcp->u_error = 0;
1365 if(tcp->u_arg[0] == 0)
1366 return 0;
1367 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1368 return RVAL_NONE | RVAL_STR;
1369 }
1370 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001371#else
Michal Ludvig0e035502002-09-23 15:41:01 +00001372#warning No sys_sigreturn() for this architecture
1373#warning (no problem, just a reminder :-)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001374 return 0;
Wichert Akkermanf90da011999-10-31 21:15:38 +00001375#endif /* MIPS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001376#endif /* SPARC */
1377#endif /* ALPHA */
1378#endif /* !M68K */
1379#endif /* !POWERPC */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001380#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001381#endif /* !I386 */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001382#endif /* S390 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001383}
1384
1385int
1386sys_siggetmask(tcp)
1387struct tcb *tcp;
1388{
1389 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001390 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001391 long_to_sigset(tcp->u_rval, &sigm);
1392 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 }
1394 return RVAL_HEX | RVAL_STR;
1395}
1396
1397int
1398sys_sigsuspend(tcp)
1399struct tcb *tcp;
1400{
1401 if (entering(tcp)) {
1402 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001403 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001404#if 0
1405 /* first two are not really arguments, but print them anyway */
1406 /* nevermind, they are an anachronism now, too bad... */
1407 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1408#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001409 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001410 }
1411 return 0;
1412}
1413
1414#endif /* LINUX */
1415
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001416#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001417
1418int
1419sys_sigsuspend(tcp)
1420struct tcb *tcp;
1421{
1422 sigset_t sigset;
1423
1424 if (entering(tcp)) {
1425 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1426 tprintf("[?]");
1427 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001428 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001429 }
1430 return 0;
1431}
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001432#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433static struct xlat ucontext_flags[] = {
1434 { UC_SIGMASK, "UC_SIGMASK" },
1435 { UC_STACK, "UC_STACK" },
1436 { UC_CPU, "UC_CPU" },
1437#ifdef UC_FPU
1438 { UC_FPU, "UC_FPU" },
1439#endif
1440#ifdef UC_INTR
1441 { UC_INTR, "UC_INTR" },
1442#endif
1443 { 0, NULL },
1444};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001445#endif /* !FREEBSD */
1446#endif /* SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001447
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001448#if defined SVR4 || defined LINUX || defined FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001449#if defined LINUX && !defined SS_ONSTACK
1450#define SS_ONSTACK 1
1451#define SS_DISABLE 2
1452#if __GLIBC_MINOR__ == 0
1453typedef struct
1454{
1455 __ptr_t ss_sp;
1456 int ss_flags;
1457 size_t ss_size;
1458} stack_t;
1459#endif
1460#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001461#ifdef FREEBSD
1462#define stack_t struct sigaltstack
1463#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001464
1465static struct xlat sigaltstack_flags[] = {
1466 { SS_ONSTACK, "SS_ONSTACK" },
1467 { SS_DISABLE, "SS_DISABLE" },
1468 { 0, NULL },
1469};
1470#endif
1471
1472#ifdef SVR4
1473static void
1474printcontext(tcp, ucp)
1475struct tcb *tcp;
1476ucontext_t *ucp;
1477{
1478 tprintf("{");
1479 if (!abbrev(tcp)) {
1480 tprintf("uc_flags=");
1481 if (!printflags(ucontext_flags, ucp->uc_flags))
1482 tprintf("0");
1483 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1484 }
1485 tprintf("uc_sigmask=");
John Hughes70c5e7a2001-05-15 15:09:14 +00001486 printsigmask(&ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001487 if (!abbrev(tcp)) {
1488 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1489 (unsigned long) ucp->uc_stack.ss_sp,
1490 ucp->uc_stack.ss_size);
1491 if (!printflags(sigaltstack_flags, ucp->uc_stack.ss_flags))
1492 tprintf("0");
1493 tprintf("}");
1494 }
1495 tprintf(", ...}");
1496}
1497
1498int
1499sys_getcontext(tcp)
1500struct tcb *tcp;
1501{
1502 ucontext_t uc;
1503
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001504 if (exiting(tcp)) {
1505 if (tcp->u_error)
1506 tprintf("%#lx", tcp->u_arg[0]);
1507 else if (!tcp->u_arg[0])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001508 tprintf("NULL");
1509 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1510 tprintf("{...}");
1511 else
1512 printcontext(tcp, &uc);
1513 }
1514 return 0;
1515}
1516
1517int
1518sys_setcontext(tcp)
1519struct tcb *tcp;
1520{
1521 ucontext_t uc;
1522
1523 if (entering(tcp)) {
1524 if (!tcp->u_arg[0])
1525 tprintf("NULL");
1526 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1527 tprintf("{...}");
1528 else
1529 printcontext(tcp, &uc);
1530 }
1531 else {
1532 tcp->u_rval = tcp->u_error = 0;
1533 if (tcp->u_arg[0] == 0)
1534 return 0;
1535 return RVAL_NONE;
1536 }
1537 return 0;
1538}
1539
1540#endif /* SVR4 */
1541
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001542#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001543
1544static int
1545print_stack_t(tcp, addr)
1546struct tcb *tcp;
1547unsigned long addr;
1548{
1549 stack_t ss;
1550 if (umove(tcp, addr, &ss) < 0)
1551 return -1;
1552 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1553 if (!printflags(sigaltstack_flags, ss.ss_flags))
1554 tprintf("0");
1555 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1556 return 0;
1557}
1558
1559int
1560sys_sigaltstack(tcp)
1561 struct tcb *tcp;
1562{
1563 if (entering(tcp)) {
1564 if (tcp->u_arg[0] == 0)
1565 tprintf("NULL");
1566 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1567 return -1;
1568 }
1569 else {
1570 tprintf(", ");
1571 if (tcp->u_arg[1] == 0)
1572 tprintf("NULL");
1573 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1574 return -1;
1575 }
1576 return 0;
1577}
1578#endif
1579
1580#ifdef HAVE_SIGACTION
1581
1582int
1583sys_sigprocmask(tcp)
1584struct tcb *tcp;
1585{
1586#ifdef ALPHA
1587 if (entering(tcp)) {
1588 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1589 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001590 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001591 }
1592 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001593 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001594 return RVAL_HEX | RVAL_STR;
1595 }
1596#else /* !ALPHA */
1597 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001598
1599 if (entering(tcp)) {
1600#ifdef SVR4
1601 if (tcp->u_arg[0] == 0)
1602 tprintf("0");
1603 else
1604#endif /* SVR4 */
1605 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1606 tprintf(", ");
1607 if (!tcp->u_arg[1])
1608 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001609 else if (copy_sigset(tcp, tcp->u_arg[1], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001610 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001611 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001612 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001613 tprintf(", ");
1614 }
1615 }
1616 else {
1617 if (!tcp->u_arg[2])
1618 tprintf("NULL");
1619 else if (syserror(tcp))
1620 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001621 else if (copy_sigset(tcp, tcp->u_arg[2], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001622 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001623 else
Nate Sammons4a121431999-04-06 01:19:39 +00001624 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625 }
1626#endif /* !ALPHA */
1627 return 0;
1628}
1629
1630#endif /* HAVE_SIGACTION */
1631
1632int
1633sys_kill(tcp)
1634struct tcb *tcp;
1635{
1636 if (entering(tcp)) {
Nate Sammonsce780fc1999-03-29 23:23:13 +00001637 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001638 }
1639 return 0;
1640}
1641
1642int
1643sys_killpg(tcp)
1644struct tcb *tcp;
1645{
1646 return sys_kill(tcp);
1647}
1648
1649int
1650sys_sigpending(tcp)
1651struct tcb *tcp;
1652{
1653 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001654
1655 if (exiting(tcp)) {
1656 if (syserror(tcp))
1657 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001658 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001659 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001660 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001661 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001662 }
1663 return 0;
1664}
1665
John Hughes42162082001-10-18 14:48:26 +00001666int sys_sigwait(tcp)
1667struct tcb *tcp;
1668{
1669 sigset_t sigset;
1670
1671 if (entering(tcp)) {
1672 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1673 tprintf("[?]");
1674 else
1675 printsigmask(&sigset, 0);
1676 }
1677 else {
1678 if (!syserror(tcp)) {
1679 tcp->auxstr = signalent[tcp->u_rval];
1680 return RVAL_DECIMAL | RVAL_STR;
1681 }
1682 }
1683 return 0;
1684}
1685
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001686#ifdef LINUX
1687
1688 int
1689sys_rt_sigprocmask(tcp)
1690 struct tcb *tcp;
1691{
1692 sigset_t sigset;
1693
Nate Sammons4a121431999-04-06 01:19:39 +00001694 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001695 if (entering(tcp)) {
1696 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1697 tprintf(", ");
1698 if (!tcp->u_arg[1])
1699 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001700 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001701 tprintf("%#lx, ", tcp->u_arg[1]);
1702 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001703 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001704 tprintf(", ");
1705 }
1706 }
1707 else {
1708 if (!tcp->u_arg[2])
1709
1710 tprintf("NULL");
1711 else if (syserror(tcp))
1712 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001713 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001714 tprintf("[?]");
1715 else
Nate Sammons4a121431999-04-06 01:19:39 +00001716 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001717 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001718 }
1719 return 0;
1720}
1721
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001722
1723/* Structure describing the action to be taken when a signal arrives. */
1724struct new_sigaction
1725{
1726 union
1727 {
1728 __sighandler_t __sa_handler;
1729 void (*__sa_sigaction) (int, siginfo_t *, void *);
1730 }
1731 __sigaction_handler;
1732 unsigned long sa_flags;
1733 void (*sa_restorer) (void);
1734 unsigned long int sa_mask[2];
1735};
1736
1737
1738 int
1739sys_rt_sigaction(tcp)
1740 struct tcb *tcp;
1741{
1742 struct new_sigaction sa;
1743 sigset_t sigset;
1744 long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001745
1746 if (entering(tcp)) {
1747 printsignal(tcp->u_arg[0]);
1748 tprintf(", ");
1749 addr = tcp->u_arg[1];
1750 } else
1751 addr = tcp->u_arg[2];
1752 if (addr == 0)
1753 tprintf("NULL");
1754 else if (!verbose(tcp))
1755 tprintf("%#lx", addr);
1756 else if (umove(tcp, addr, &sa) < 0)
1757 tprintf("{...}");
1758 else {
1759 switch ((long) sa.__sigaction_handler.__sa_handler) {
1760 case (long) SIG_ERR:
1761 tprintf("{SIG_ERR}");
1762 break;
1763 case (long) SIG_DFL:
1764 tprintf("{SIG_DFL}");
1765 break;
1766 case (long) SIG_IGN:
1767 tprintf("{SIG_IGN}");
1768 break;
1769 default:
1770 tprintf("{%#lx, ",
1771 (long) sa.__sigaction_handler.__sa_handler);
Nate Sammons4a121431999-04-06 01:19:39 +00001772 sigemptyset(&sigset);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001773#ifdef LINUXSPARC
1774 if (tcp->u_arg[4] <= sizeof(sigset))
1775 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1776#else
Nate Sammons4a121431999-04-06 01:19:39 +00001777 if (tcp->u_arg[3] <= sizeof(sigset))
1778 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001779#endif
Nate Sammons4a121431999-04-06 01:19:39 +00001780 else
1781 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1782 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001783 tprintf(", ");
1784 if (!printflags(sigact_flags, sa.sa_flags))
1785 tprintf("0");
Roland McGrath2638cb42002-12-15 23:58:41 +00001786#ifdef SA_RESTORER
1787 if (sa.sa_flags & SA_RESTORER)
1788 tprintf(", %p", sa.sa_restorer);
1789#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001790 tprintf("}");
1791 }
1792 }
1793 if (entering(tcp))
1794 tprintf(", ");
1795 else
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001796#ifdef LINUXSPARC
1797 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1798#elif defined(ALPHA)
1799 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1800#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001801 tprintf(", %lu", addr = tcp->u_arg[3]);
Wichert Akkermandacfb6e1999-06-03 14:21:07 +00001802#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001803 return 0;
1804}
1805
1806 int
1807sys_rt_sigpending(tcp)
1808 struct tcb *tcp;
1809{
1810 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001811
1812 if (exiting(tcp)) {
1813 if (syserror(tcp))
1814 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001815 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1816 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001817 tprintf("[?]");
1818 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001819 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001820 }
1821 return 0;
1822}
1823 int
1824sys_rt_sigsuspend(tcp)
1825 struct tcb *tcp;
1826{
1827 if (entering(tcp)) {
1828 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001829 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1830 tprintf("[?]");
1831 else
1832 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001833 }
1834 return 0;
1835}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001836 int
1837sys_rt_sigqueueinfo(tcp)
1838 struct tcb *tcp;
1839{
1840 if (entering(tcp)) {
1841 siginfo_t si;
1842 tprintf("%lu, ", tcp->u_arg[0]);
1843 printsignal(tcp->u_arg[1]);
1844 tprintf(", ");
1845 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1846 tprintf("%#lx", tcp->u_arg[2]);
1847 else
John Hughes58265892001-10-18 15:13:53 +00001848 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849 }
1850 return 0;
1851}
1852
1853int sys_rt_sigtimedwait(tcp)
1854 struct tcb *tcp;
1855{
1856 if (entering(tcp)) {
1857 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001858
Roland McGratha39c5a12002-12-17 05:10:37 +00001859 if (copy_sigset_len(tcp, tcp->u_arg[0],
Nate Sammons4a121431999-04-06 01:19:39 +00001860 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001861 tprintf("[?]");
1862 else
Wichert Akkerman46956571999-11-26 10:12:59 +00001863 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001864 tprintf(", ");
1865 }
1866 else {
1867 if (syserror(tcp))
1868 tprintf("%#lx", tcp->u_arg[0]);
1869 else {
1870 siginfo_t si;
1871 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1872 tprintf("%#lx", tcp->u_arg[1]);
1873 else
John Hughes58265892001-10-18 15:13:53 +00001874 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001875 /* XXX For now */
1876 tprintf(", %#lx", tcp->u_arg[2]);
1877 tprintf(", %d", (int) tcp->u_arg[3]);
1878 }
1879 }
1880 return 0;
1881};
1882
1883#endif /* LINUX */