blob: 148cad06366ff8b3ac8603860ded3d2ae9e1545f [file] [log] [blame]
preludedrewbac65502010-12-30 20:27:30 -07001/*
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>
5 * 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>
9 * 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: signal.c,v 1.54 2005/06/01 19:02:37 roland Exp $
34 */
35
36#include "defs.h"
37
38#include <signal.h>
39#ifdef HAVE_ANDROID_OS
40#else
41#include <sys/user.h>
42#endif
43#include <fcntl.h>
44
45#ifdef SVR4
46#include <sys/ucontext.h>
47#endif /* SVR4 */
48
49#ifdef HAVE_SYS_REG_H
50# include <sys/reg.h>
51#ifndef PTRACE_PEEKUSR
52# define PTRACE_PEEKUSR PTRACE_PEEKUSER
53#endif
54#ifndef PTRACE_POKEUSR
55# define PTRACE_POKEUSR PTRACE_POKEUSER
56#endif
57#elif defined(HAVE_LINUX_PTRACE_H)
58#undef PTRACE_SYSCALL
59# ifdef HAVE_STRUCT_IA64_FPREG
60# define ia64_fpreg XXX_ia64_fpreg
61# endif
62# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
63# define pt_all_user_regs XXX_pt_all_user_regs
64# endif
65#include <linux/ptrace.h>
66# undef ia64_fpreg
67# undef pt_all_user_regs
68#endif
69
70
71#ifdef LINUX
72
73#ifdef IA64
74# include <asm/ptrace_offsets.h>
75#endif /* !IA64 */
76
77#if HAVE_ASM_REG_H
78# if defined (SPARC) || defined (SPARC64)
79# define fpq kernel_fpq
80# define fq kernel_fq
81# define fpu kernel_fpu
82# endif
83# include <asm/reg.h>
84# if defined (SPARC) || defined (SPARC64)
85# undef fpq
86# undef fq
87# undef fpu
88# endif
89#if defined (LINUX) && defined (SPARC64)
90# define r_pc r_tpc
91# undef PTRACE_GETREGS
92# define PTRACE_GETREGS PTRACE_GETREGS64
93# undef PTRACE_SETREGS
94# define PTRACE_SETREGS PTRACE_SETREGS64
95#endif /* LINUX && SPARC64 */
96#endif /* HAVE_ASM_REG_H */
97
98#if defined (SPARC) || defined (SPARC64)
99typedef struct {
100 struct regs si_regs;
101 int si_mask;
102} m_siginfo_t;
103#elif defined HAVE_ASM_SIGCONTEXT_H
104#if !defined(IA64) && !defined(X86_64)
105#include <asm/sigcontext.h>
106#endif /* !IA64 && !X86_64 */
107#else /* !HAVE_ASM_SIGCONTEXT_H */
108#ifdef I386
109struct sigcontext_struct {
110 unsigned short gs, __gsh;
111 unsigned short fs, __fsh;
112 unsigned short es, __esh;
113 unsigned short ds, __dsh;
114 unsigned long edi;
115 unsigned long esi;
116 unsigned long ebp;
117 unsigned long esp;
118 unsigned long ebx;
119 unsigned long edx;
120 unsigned long ecx;
121 unsigned long eax;
122 unsigned long trapno;
123 unsigned long err;
124 unsigned long eip;
125 unsigned short cs, __csh;
126 unsigned long eflags;
127 unsigned long esp_at_signal;
128 unsigned short ss, __ssh;
129 unsigned long i387;
130 unsigned long oldmask;
131 unsigned long cr2;
132};
133#else /* !I386 */
134#ifdef M68K
135struct sigcontext
136{
137 unsigned long sc_mask;
138 unsigned long sc_usp;
139 unsigned long sc_d0;
140 unsigned long sc_d1;
141 unsigned long sc_a0;
142 unsigned long sc_a1;
143 unsigned short sc_sr;
144 unsigned long sc_pc;
145 unsigned short sc_formatvec;
146};
147#endif /* M68K */
148#endif /* !I386 */
149#endif /* !HAVE_ASM_SIGCONTEXT_H */
150#ifndef NSIG
151#define NSIG 32
152#endif
153#ifdef ARM
154#undef NSIG
155#define NSIG 32
156#endif
157#endif /* LINUX */
158
159const char *const signalent0[] = {
160#include "signalent.h"
161};
162const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
163
164#if SUPPORTED_PERSONALITIES >= 2
165const char *const signalent1[] = {
166#include "signalent1.h"
167};
168const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
169#endif /* SUPPORTED_PERSONALITIES >= 2 */
170
171#if SUPPORTED_PERSONALITIES >= 3
172const char *const signalent2[] = {
173#include "signalent2.h"
174};
175const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
176#endif /* SUPPORTED_PERSONALITIES >= 3 */
177
178const char *const *signalent;
179int nsignals;
180
181#if defined(SUNOS4) || defined(FREEBSD)
182
183static const struct xlat sigvec_flags[] = {
184 { SV_ONSTACK, "SV_ONSTACK" },
185 { SV_INTERRUPT, "SV_INTERRUPT" },
186 { SV_RESETHAND, "SV_RESETHAND" },
187 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
188 { 0, NULL },
189};
190
191#endif /* SUNOS4 || FREEBSD */
192
193#ifdef HAVE_SIGACTION
194
195#if defined LINUX && (defined I386 || defined X86_64)
196/* The libc headers do not define this constant since it should only be
197 used by the implementation. So wwe define it here. */
198# ifndef SA_RESTORER
199# define SA_RESTORER 0x04000000
200# endif
201#endif
202
203static const struct xlat sigact_flags[] = {
204#ifdef SA_RESTORER
205 { SA_RESTORER, "SA_RESTORER" },
206#endif
207#ifdef SA_STACK
208 { SA_STACK, "SA_STACK" },
209#endif
210#ifdef SA_RESTART
211 { SA_RESTART, "SA_RESTART" },
212#endif
213#ifdef SA_INTERRUPT
214 { SA_INTERRUPT, "SA_INTERRUPT" },
215#endif
216#ifdef SA_NOMASK
217 { SA_NOMASK, "SA_NOMASK" },
218#endif
219#ifdef SA_ONESHOT
220 { SA_ONESHOT, "SA_ONESHOT" },
221#endif
222#ifdef SA_SIGINFO
223 { SA_SIGINFO, "SA_SIGINFO" },
224#endif
225#ifdef SA_RESETHAND
226 { SA_RESETHAND, "SA_RESETHAND" },
227#endif
228#ifdef SA_ONSTACK
229 { SA_ONSTACK, "SA_ONSTACK" },
230#endif
231#ifdef SA_NODEFER
232 { SA_NODEFER, "SA_NODEFER" },
233#endif
234#ifdef SA_NOCLDSTOP
235 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
236#endif
237#ifdef SA_NOCLDWAIT
238 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
239#endif
240#ifdef _SA_BSDCALL
241 { _SA_BSDCALL, "_SA_BSDCALL" },
242#endif
243 { 0, NULL },
244};
245
246static const struct xlat sigprocmaskcmds[] = {
247 { SIG_BLOCK, "SIG_BLOCK" },
248 { SIG_UNBLOCK, "SIG_UNBLOCK" },
249 { SIG_SETMASK, "SIG_SETMASK" },
250#ifdef SIG_SETMASK32
251 { SIG_SETMASK32,"SIG_SETMASK32" },
252#endif
253 { 0, NULL },
254};
255
256#endif /* HAVE_SIGACTION */
257
258/* Anonymous realtime signals. */
259/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
260 constant. This is what we want. Otherwise, just use SIGRTMIN. */
261#ifdef SIGRTMIN
262#ifndef __SIGRTMIN
263#define __SIGRTMIN SIGRTMIN
264#define __SIGRTMAX SIGRTMAX /* likewise */
265#endif
266#endif
267
268const char *
269signame(sig)
270int sig;
271{
272 static char buf[30];
273 if (sig >= 0 && sig < nsignals) {
274 return signalent[sig];
275#ifdef SIGRTMIN
276 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
277 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
278 return buf;
279#endif /* SIGRTMIN */
280 } else {
281 sprintf(buf, "%d", sig);
282 return buf;
283 }
284}
285
286#ifndef UNIXWARE
287static void
288long_to_sigset(l, s)
289long l;
290sigset_t *s;
291{
292 sigemptyset(s);
293 *(long *)s = l;
294}
295#endif
296
297static int
298copy_sigset_len(tcp, addr, s, len)
299struct tcb *tcp;
300long addr;
301sigset_t *s;
302int len;
303{
304 if (len > sizeof(*s))
305 len = sizeof(*s);
306 sigemptyset(s);
307 if (umoven(tcp, addr, len, (char *)s) < 0)
308 return -1;
309 return 0;
310}
311
312#ifdef LINUX
313/* Original sigset is unsigned long */
314#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
315#else
316#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
317#endif
318
319static char *
320sprintsigmask(s, mask, rt)
321char *s;
322sigset_t *mask;
323int rt; /* set might include realtime sigs */
324{
325 int i, nsigs;
326 int maxsigs;
327 char *format;
328 static char outstr[8 * sizeof(sigset_t) * 8];
329
330 strcpy(outstr, s);
331 s = outstr + strlen(outstr);
332 nsigs = 0;
333 maxsigs = nsignals;
334#ifdef __SIGRTMAX
335 if (rt)
336 maxsigs = __SIGRTMAX; /* instead */
337#endif
338 for (i = 1; i < maxsigs; i++) {
339 if (sigismember(mask, i) == 1)
340 nsigs++;
341 }
342 if (nsigs >= nsignals * 2 / 3) {
343 *s++ = '~';
344 for (i = 1; i < maxsigs; i++) {
345 switch (sigismember(mask, i)) {
346 case 1:
347 sigdelset(mask, i);
348 break;
349 case 0:
350 sigaddset(mask, i);
351 break;
352 }
353 }
354 }
355 format = "%s";
356 *s++ = '[';
357 for (i = 1; i < maxsigs; i++) {
358 if (sigismember(mask, i) == 1) {
359 /* real-time signals on solaris don't have
360 * signalent entries
361 */
362 if (i < nsignals) {
363 sprintf(s, format, signalent[i] + 3);
364 }
365#ifdef SIGRTMIN
366 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
367 char tsig[40];
368 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
369 sprintf(s, format, tsig);
370 }
371#endif /* SIGRTMIN */
372 else {
373 char tsig[32];
374 sprintf(tsig, "%u", i);
375 sprintf(s, format, tsig);
376 }
377 s += strlen(s);
378 format = " %s";
379 }
380 }
381 *s++ = ']';
382 *s = '\0';
383 return outstr;
384}
385
386static void
387printsigmask(mask, rt)
388sigset_t *mask;
389int rt;
390{
391 tprintf("%s", sprintsigmask("", mask, rt));
392}
393
394void
395printsignal(nr)
396int nr;
397{
398 tprintf("%s", signame(nr));
399}
400
401void
402print_sigset(struct tcb *tcp, long addr, int rt)
403{
404 sigset_t ss;
405
406 if (!addr)
407 tprintf("NULL");
408 else if (copy_sigset(tcp, addr, &ss) < 0)
409 tprintf("%#lx", addr);
410 else
411 printsigmask(&ss, rt);
412}
413
414#ifdef LINUX
415
416#ifndef ILL_ILLOPC
417#define ILL_ILLOPC 1 /* illegal opcode */
418#define ILL_ILLOPN 2 /* illegal operand */
419#define ILL_ILLADR 3 /* illegal addressing mode */
420#define ILL_ILLTRP 4 /* illegal trap */
421#define ILL_PRVOPC 5 /* privileged opcode */
422#define ILL_PRVREG 6 /* privileged register */
423#define ILL_COPROC 7 /* coprocessor error */
424#define ILL_BADSTK 8 /* internal stack error */
425#define FPE_INTDIV 1 /* integer divide by zero */
426#define FPE_INTOVF 2 /* integer overflow */
427#define FPE_FLTDIV 3 /* floating point divide by zero */
428#define FPE_FLTOVF 4 /* floating point overflow */
429#define FPE_FLTUND 5 /* floating point underflow */
430#define FPE_FLTRES 6 /* floating point inexact result */
431#define FPE_FLTINV 7 /* floating point invalid operation */
432#define FPE_FLTSUB 8 /* subscript out of range */
433#define SEGV_MAPERR 1 /* address not mapped to object */
434#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
435#define BUS_ADRALN 1 /* invalid address alignment */
436#define BUS_ADRERR 2 /* non-existant physical address */
437#define BUS_OBJERR 3 /* object specific hardware error */
438#define TRAP_BRKPT 1 /* process breakpoint */
439#define TRAP_TRACE 2 /* process trace trap */
440#define CLD_EXITED 1 /* child has exited */
441#define CLD_KILLED 2 /* child was killed */
442#define CLD_DUMPED 3 /* child terminated abnormally */
443#define CLD_TRAPPED 4 /* traced child has trapped */
444#define CLD_STOPPED 5 /* child has stopped */
445#define CLD_CONTINUED 6 /* stopped child has continued */
446#define POLL_IN 1 /* data input available */
447#define POLL_OUT 2 /* output buffers available */
448#define POLL_MSG 3 /* input message available */
449#define POLL_ERR 4 /* i/o error */
450#define POLL_PRI 5 /* high priority input available */
451#define POLL_HUP 6 /* device disconnected */
452#define SI_USER 0 /* sent by kill, sigsend, raise */
453#define SI_QUEUE -1 /* sent by sigqueue */
454#define SI_TIMER -2 /* sent by timer expiration */
455#define SI_MESGQ -3 /* sent by real time mesq state change */
456#define SI_ASYNCIO -4 /* sent by AIO completion */
457#define SI_SIGIO -5 /* Sent by SIGIO */
458#define SI_TKILL -6 /* Sent by tkill */
459#endif
460
461#if __GLIBC_MINOR__ < 1 && !defined(HAVE_ANDROID_OS)
462/* Type for data associated with a signal. */
463typedef union sigval
464{
465 int sival_int;
466 void *sival_ptr;
467} sigval_t;
468
469# define __SI_MAX_SIZE 128
470# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
471
472typedef struct siginfo
473{
474 int si_signo; /* Signal number. */
475 int si_errno; /* If non-zero, an errno value associated with
476 this signal, as defined in <errno.h>. */
477 int si_code; /* Signal code. */
478
479 union
480 {
481 int _pad[__SI_PAD_SIZE];
482
483 /* kill(). */
484 struct
485 {
486 __pid_t si_pid; /* Sending process ID. */
487 __uid_t si_uid; /* Real user ID of sending process. */
488 } _kill;
489
490 /* POSIX.1b timers. */
491 struct
492 {
493 unsigned int _timer1;
494 unsigned int _timer2;
495 } _timer;
496
497 /* POSIX.1b signals. */
498 struct
499 {
500 __pid_t si_pid; /* Sending process ID. */
501 __uid_t si_uid; /* Real user ID of sending process. */
502 sigval_t si_sigval; /* Signal value. */
503 } _rt;
504
505 /* SIGCHLD. */
506 struct
507 {
508 __pid_t si_pid; /* Which child. */
509 int si_status; /* Exit value or signal. */
510 __clock_t si_utime;
511 __clock_t si_stime;
512 } _sigchld;
513
514 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
515 struct
516 {
517 void *si_addr; /* Faulting insn/memory ref. */
518 } _sigfault;
519
520 /* SIGPOLL. */
521 struct
522 {
523 int si_band; /* Band event for SIGPOLL. */
524 int si_fd;
525 } _sigpoll;
526 } _sifields;
527} siginfo_t;
528
529#define si_pid _sifields._kill.si_pid
530#define si_uid _sifields._kill.si_uid
531#define si_status _sifields._sigchld.si_status
532#define si_utime _sifields._sigchld.si_utime
533#define si_stime _sifields._sigchld.si_stime
534#define si_value _sifields._rt.si_sigval
535#define si_int _sifields._rt.si_sigval.sival_int
536#define si_ptr _sifields._rt.si_sigval.sival_ptr
537#define si_addr _sifields._sigfault.si_addr
538#define si_band _sifields._sigpoll.si_band
539#define si_fd _sifields._sigpoll.si_fd
540
541#endif
542
543#endif
544
545#if defined (SVR4) || defined (LINUX)
546
547static const struct xlat siginfo_codes[] = {
548#ifdef SI_NOINFO
549 { SI_NOINFO, "SI_NOINFO" },
550#endif
551#ifdef SI_USER
552 { SI_USER, "SI_USER" },
553#endif
554#ifdef SI_LWP
555 { SI_LWP, "SI_LWP" },
556#endif
557#ifdef SI_QUEUE
558 { SI_QUEUE, "SI_QUEUE" },
559#endif
560#ifdef SI_TIMER
561 { SI_TIMER, "SI_TIMER" },
562#endif
563#ifdef SI_ASYNCIO
564 { SI_ASYNCIO, "SI_ASYNCIO" },
565#endif
566#ifdef SI_MESGQ
567 { SI_MESGQ, "SI_MESGQ" },
568#endif
569#ifdef SI_SIGIO
570 { SI_SIGIO, "SI_SIGIO" },
571#endif
572#ifdef SI_TKILL
573 { SI_TKILL, "SI_TKILL" },
574#endif
575 { 0, NULL },
576};
577
578static const struct xlat sigill_codes[] = {
579 { ILL_ILLOPC, "ILL_ILLOPC" },
580 { ILL_ILLOPN, "ILL_ILLOPN" },
581 { ILL_ILLADR, "ILL_ILLADR" },
582 { ILL_ILLTRP, "ILL_ILLTRP" },
583 { ILL_PRVOPC, "ILL_PRVOPC" },
584 { ILL_PRVREG, "ILL_PRVREG" },
585 { ILL_COPROC, "ILL_COPROC" },
586 { ILL_BADSTK, "ILL_BADSTK" },
587 { 0, NULL },
588};
589
590static const struct xlat sigfpe_codes[] = {
591 { FPE_INTDIV, "FPE_INTDIV" },
592 { FPE_INTOVF, "FPE_INTOVF" },
593 { FPE_FLTDIV, "FPE_FLTDIV" },
594 { FPE_FLTOVF, "FPE_FLTOVF" },
595 { FPE_FLTUND, "FPE_FLTUND" },
596 { FPE_FLTRES, "FPE_FLTRES" },
597 { FPE_FLTINV, "FPE_FLTINV" },
598 { FPE_FLTSUB, "FPE_FLTSUB" },
599 { 0, NULL },
600};
601
602static const struct xlat sigtrap_codes[] = {
603 { TRAP_BRKPT, "TRAP_BRKPT" },
604 { TRAP_TRACE, "TRAP_TRACE" },
605 { 0, NULL },
606};
607
608static const struct xlat sigchld_codes[] = {
609 { CLD_EXITED, "CLD_EXITED" },
610 { CLD_KILLED, "CLD_KILLED" },
611 { CLD_DUMPED, "CLD_DUMPED" },
612 { CLD_TRAPPED, "CLD_TRAPPED" },
613 { CLD_STOPPED, "CLD_STOPPED" },
614 { CLD_CONTINUED,"CLD_CONTINUED" },
615 { 0, NULL },
616};
617
618static const struct xlat sigpoll_codes[] = {
619 { POLL_IN, "POLL_IN" },
620 { POLL_OUT, "POLL_OUT" },
621 { POLL_MSG, "POLL_MSG" },
622 { POLL_ERR, "POLL_ERR" },
623 { POLL_PRI, "POLL_PRI" },
624 { POLL_HUP, "POLL_HUP" },
625 { 0, NULL },
626};
627
628static const struct xlat sigprof_codes[] = {
629#ifdef PROF_SIG
630 { PROF_SIG, "PROF_SIG" },
631#endif
632 { 0, NULL },
633};
634
635#ifdef SIGEMT
636static const struct xlat sigemt_codes[] = {
637#ifdef EMT_TAGOVF
638 { EMT_TAGOVF, "EMT_TAGOVF" },
639#endif
640 { 0, NULL },
641};
642#endif
643
644static const struct xlat sigsegv_codes[] = {
645 { SEGV_MAPERR, "SEGV_MAPERR" },
646 { SEGV_ACCERR, "SEGV_ACCERR" },
647 { 0, NULL },
648};
649
650static const struct xlat sigbus_codes[] = {
651 { BUS_ADRALN, "BUS_ADRALN" },
652 { BUS_ADRERR, "BUS_ADRERR" },
653 { BUS_OBJERR, "BUS_OBJERR" },
654 { 0, NULL },
655};
656
657void
658printsiginfo(sip, verbose)
659siginfo_t *sip;
660int verbose;
661{
662 const char *code;
663
664 if (sip->si_signo == 0) {
665 tprintf ("{}");
666 return;
667 }
668 tprintf("{si_signo=");
669 printsignal(sip->si_signo);
670 code = xlookup(siginfo_codes, sip->si_code);
671 if (!code) {
672 switch (sip->si_signo) {
673 case SIGTRAP:
674 code = xlookup(sigtrap_codes, sip->si_code);
675 break;
676 case SIGCHLD:
677 code = xlookup(sigchld_codes, sip->si_code);
678 break;
679 case SIGPOLL:
680 code = xlookup(sigpoll_codes, sip->si_code);
681 break;
682 case SIGPROF:
683 code = xlookup(sigprof_codes, sip->si_code);
684 break;
685 case SIGILL:
686 code = xlookup(sigill_codes, sip->si_code);
687 break;
688#ifdef SIGEMT
689 case SIGEMT:
690 code = xlookup(sigemt_codes, sip->si_code);
691 break;
692#endif
693 case SIGFPE:
694 code = xlookup(sigfpe_codes, sip->si_code);
695 break;
696 case SIGSEGV:
697 code = xlookup(sigsegv_codes, sip->si_code);
698 break;
699 case SIGBUS:
700 code = xlookup(sigbus_codes, sip->si_code);
701 break;
702 }
703 }
704 if (code)
705 tprintf(", si_code=%s", code);
706 else
707 tprintf(", si_code=%#x", sip->si_code);
708#ifdef SI_NOINFO
709 if (sip->si_code != SI_NOINFO)
710#endif
711 {
712 if (sip->si_errno) {
713 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
714 tprintf(", si_errno=%d", sip->si_errno);
715 else
716 tprintf(", si_errno=%s",
717 errnoent[sip->si_errno]);
718 }
719#ifdef SI_FROMUSER
720 if (SI_FROMUSER(sip)) {
721 tprintf(", si_pid=%ld, si_uid=%ld",
722 sip->si_pid, sip->si_uid);
723#ifdef SI_QUEUE
724 switch (sip->si_code) {
725 case SI_QUEUE:
726#ifdef SI_TIMER
727 case SI_TIMER:
728#endif /* SI_QUEUE */
729 case SI_ASYNCIO:
730#ifdef SI_MESGQ
731 case SI_MESGQ:
732#endif /* SI_MESGQ */
733 tprintf(", si_value=%d",
734 sip->si_value.sival_int);
735 break;
736 }
737#endif /* SI_QUEUE */
738 }
739 else
740#endif /* SI_FROMUSER */
741 {
742 switch (sip->si_signo) {
743 case SIGCHLD:
744 tprintf(", si_pid=%ld, si_status=",
745 (long) sip->si_pid);
746 if (sip->si_code == CLD_EXITED)
747 tprintf("%d", sip->si_status);
748 else
749 printsignal(sip->si_status);
750#if LINUX
751 if (!verbose)
752 tprintf(", ...");
753 else
754 tprintf(", si_utime=%lu, si_stime=%lu",
755 sip->si_utime,
756 sip->si_stime);
757#endif
758 break;
759 case SIGILL: case SIGFPE:
760 case SIGSEGV: case SIGBUS:
761 tprintf(", si_addr=%#lx",
762 (unsigned long) sip->si_addr);
763 break;
764 case SIGPOLL:
765 switch (sip->si_code) {
766 case POLL_IN: case POLL_OUT: case POLL_MSG:
767 tprintf(", si_band=%ld",
768 (long) sip->si_band);
769 break;
770 }
771 break;
772#ifdef LINUX
773 default:
774 tprintf(", si_pid=%lu, si_uid=%lu, ",
775 (unsigned long) sip->si_pid,
776 (unsigned long) sip->si_uid);
777 if (!verbose)
778 tprintf("...");
779 else {
780 tprintf("si_value={int=%u, ptr=%#lx}",
781 sip->si_int,
782 (unsigned long) sip->si_ptr);
783 }
784#endif
785
786 }
787 }
788 }
789 tprintf("}");
790}
791
792#endif /* SVR4 || LINUX */
793
794#ifdef LINUX
795
796static void
797parse_sigset_t (const char *str, sigset_t *set)
798{
799 const char *p;
800 unsigned int digit;
801 int i;
802
803 sigemptyset(set);
804
805 p = strchr(str, '\n');
806 if (p == NULL)
807 p = strchr(str, '\0');
808 for (i = 0; p-- > str; i += 4) {
809 if (*p >= '0' && *p <= '9')
810 digit = *p - '0';
811 else if (*p >= 'a' && *p <= 'f')
812 digit = *p - 'a' + 10;
813 else if (*p >= 'A' && *p <= 'F')
814 digit = *p - 'A' + 10;
815 else
816 break;
817 if (digit & 1)
818 sigaddset(set, i + 1);
819 if (digit & 2)
820 sigaddset(set, i + 2);
821 if (digit & 4)
822 sigaddset(set, i + 3);
823 if (digit & 8)
824 sigaddset(set, i + 4);
825 }
826}
827
828#endif
829
830/*
831 * Check process TCP for the disposition of signal SIG.
832 * Return 1 if the process would somehow manage to survive signal SIG,
833 * else return 0. This routine will never be called with SIGKILL.
834 */
835int
836sigishandled(tcp, sig)
837struct tcb *tcp;
838int sig;
839{
840#ifdef LINUX
841 int sfd;
842 char sname[32];
843 char buf[2048];
844 char *s;
845 int i;
846 sigset_t ignored, caught;
847#endif
848#ifdef SVR4
849 /*
850 * Since procfs doesn't interfere with wait I think it is safe
851 * to punt on this question. If not, the information is there.
852 */
853 return 1;
854#else /* !SVR4 */
855 switch (sig) {
856 case SIGCONT:
857 case SIGSTOP:
858 case SIGTSTP:
859 case SIGTTIN:
860 case SIGTTOU:
861 case SIGCHLD:
862 case SIGIO:
863#if defined(SIGURG) && SIGURG != SIGIO
864 case SIGURG:
865#endif
866 case SIGWINCH:
867 /* Gloria Gaynor says ... */
868 return 1;
869 default:
870 break;
871 }
872#endif /* !SVR4 */
873#ifdef LINUX
874
875 /* This is incredibly costly but it's worth it. */
876 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
877 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
878 doesn't handle real-time signals). */
879 sprintf(sname, "/proc/%d/status", tcp->pid);
880 if ((sfd = open(sname, O_RDONLY)) == -1) {
881 perror(sname);
882 return 1;
883 }
884 i = read(sfd, buf, sizeof(buf));
885 buf[i] = '\0';
886 close(sfd);
887 /*
888 * Skip the extraneous fields. We need to skip
889 * command name has any spaces in it. So be it.
890 */
891 s = strstr(buf, "SigIgn:\t");
892 if (!s)
893 {
894 fprintf(stderr, "/proc/pid/status format error\n");
895 return 1;
896 }
897 parse_sigset_t(s + 8, &ignored);
898
899 s = strstr(buf, "SigCgt:\t");
900 if (!s)
901 {
902 fprintf(stderr, "/proc/pid/status format error\n");
903 return 1;
904 }
905 parse_sigset_t(s + 8, &caught);
906
907#ifdef DEBUG
908 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
909 *(long long *) &ignored, *(long long *) &caught, sig);
910#endif
911 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
912 return 1;
913#endif /* LINUX */
914
915#ifdef SUNOS4
916 void (*u_signal)();
917
918 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
919 (long *) &u_signal) < 0) {
920 return 0;
921 }
922 if (u_signal != SIG_DFL)
923 return 1;
924#endif /* SUNOS4 */
925
926 return 0;
927}
928
929#if defined(SUNOS4) || defined(FREEBSD)
930
931int
932sys_sigvec(tcp)
933struct tcb *tcp;
934{
935 struct sigvec sv;
936 long addr;
937
938 if (entering(tcp)) {
939 printsignal(tcp->u_arg[0]);
940 tprintf(", ");
941 addr = tcp->u_arg[1];
942 } else {
943 addr = tcp->u_arg[2];
944 }
945 if (addr == 0)
946 tprintf("NULL");
947 else if (!verbose(tcp))
948 tprintf("%#lx", addr);
949 else if (umove(tcp, addr, &sv) < 0)
950 tprintf("{...}");
951 else {
952 switch ((int) sv.sv_handler) {
953 case (int) SIG_ERR:
954 tprintf("{SIG_ERR}");
955 break;
956 case (int) SIG_DFL:
957 tprintf("{SIG_DFL}");
958 break;
959 case (int) SIG_IGN:
960 if (tcp->u_arg[0] == SIGTRAP) {
961 tcp->flags |= TCB_SIGTRAPPED;
962 kill(tcp->pid, SIGSTOP);
963 }
964 tprintf("{SIG_IGN}");
965 break;
966 case (int) SIG_HOLD:
967 if (tcp->u_arg[0] == SIGTRAP) {
968 tcp->flags |= TCB_SIGTRAPPED;
969 kill(tcp->pid, SIGSTOP);
970 }
971 tprintf("SIG_HOLD");
972 break;
973 default:
974 if (tcp->u_arg[0] == SIGTRAP) {
975 tcp->flags |= TCB_SIGTRAPPED;
976 kill(tcp->pid, SIGSTOP);
977 }
978 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
979 printsigmask(&sv.sv_mask, 0);
980 tprintf(", ");
981 printflags(sigvec_flags, sv.sv_flags, "SV_???");
982 tprintf("}");
983 }
984 }
985 if (entering(tcp))
986 tprintf(", ");
987 return 0;
988}
989
990int
991sys_sigpause(tcp)
992struct tcb *tcp;
993{
994 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
995 sigset_t sigm;
996 long_to_sigset(tcp->u_arg[0], &sigm);
997 printsigmask(&sigm, 0);
998 }
999 return 0;
1000}
1001
1002int
1003sys_sigstack(tcp)
1004struct tcb *tcp;
1005{
1006 struct sigstack ss;
1007 long addr;
1008
1009 if (entering(tcp))
1010 addr = tcp->u_arg[0];
1011 else
1012 addr = tcp->u_arg[1];
1013 if (addr == 0)
1014 tprintf("NULL");
1015 else if (umove(tcp, addr, &ss) < 0)
1016 tprintf("%#lx", addr);
1017 else {
1018 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1019 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1020 }
1021 if (entering(tcp))
1022 tprintf(", ");
1023 return 0;
1024}
1025
1026int
1027sys_sigcleanup(tcp)
1028struct tcb *tcp;
1029{
1030 return 0;
1031}
1032
1033#endif /* SUNOS4 || FREEBSD */
1034
1035#ifndef SVR4
1036
1037int
1038sys_sigsetmask(tcp)
1039struct tcb *tcp;
1040{
1041 if (entering(tcp)) {
1042 sigset_t sigm;
1043 long_to_sigset(tcp->u_arg[0], &sigm);
1044 printsigmask(&sigm, 0);
1045#ifndef USE_PROCFS
1046#ifdef HAVE_ANDROID_OS
1047//FIXME use "sigprocmask" or something
1048#define sigmask(sig) (1UL << ((sig) - 1))
1049#endif
1050
1051 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1052 /* Mark attempt to block SIGTRAP */
1053 tcp->flags |= TCB_SIGTRAPPED;
1054 /* Send unblockable signal */
1055 kill(tcp->pid, SIGSTOP);
1056 }
1057#endif /* !USE_PROCFS */
1058 }
1059 else if (!syserror(tcp)) {
1060 sigset_t sigm;
1061 long_to_sigset(tcp->u_rval, &sigm);
1062 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
1063
1064 return RVAL_HEX | RVAL_STR;
1065 }
1066 return 0;
1067}
1068
1069int
1070sys_sigblock(tcp)
1071struct tcb *tcp;
1072{
1073 return sys_sigsetmask(tcp);
1074}
1075
1076#endif /* !SVR4 */
1077
1078#ifdef HAVE_SIGACTION
1079
1080#ifdef LINUX
1081struct old_sigaction {
1082 __sighandler_t __sa_handler;
1083 unsigned long sa_mask;
1084 unsigned long sa_flags;
1085 void (*sa_restorer)(void);
1086};
1087#define SA_HANDLER __sa_handler
1088#endif /* LINUX */
1089
1090#ifndef SA_HANDLER
1091#define SA_HANDLER sa_handler
1092#endif
1093
1094int
1095sys_sigaction(tcp)
1096struct tcb *tcp;
1097{
1098 long addr;
1099#ifdef LINUX
1100 sigset_t sigset;
1101 struct old_sigaction sa;
1102#else
1103 struct sigaction sa;
1104#endif
1105
1106
1107 if (entering(tcp)) {
1108 printsignal(tcp->u_arg[0]);
1109 tprintf(", ");
1110 addr = tcp->u_arg[1];
1111 } else
1112 addr = tcp->u_arg[2];
1113 if (addr == 0)
1114 tprintf("NULL");
1115 else if (!verbose(tcp))
1116 tprintf("%#lx", addr);
1117 else if (umove(tcp, addr, &sa) < 0)
1118 tprintf("{...}");
1119 else {
1120 switch ((long) sa.SA_HANDLER) {
1121 case (long) SIG_ERR:
1122 tprintf("{SIG_ERR}");
1123 break;
1124 case (long) SIG_DFL:
1125 tprintf("{SIG_DFL}");
1126 break;
1127 case (long) SIG_IGN:
1128#ifndef USE_PROCFS
1129 if (tcp->u_arg[0] == SIGTRAP) {
1130 tcp->flags |= TCB_SIGTRAPPED;
1131 kill(tcp->pid, SIGSTOP);
1132 }
1133#endif /* !USE_PROCFS */
1134 tprintf("{SIG_IGN}");
1135 break;
1136 default:
1137#ifndef USE_PROCFS
1138 if (tcp->u_arg[0] == SIGTRAP) {
1139 tcp->flags |= TCB_SIGTRAPPED;
1140 kill(tcp->pid, SIGSTOP);
1141 }
1142#endif /* !USE_PROCFS */
1143 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
1144#ifndef LINUX
1145 printsigmask (&sa.sa_mask, 0);
1146#else
1147 long_to_sigset(sa.sa_mask, &sigset);
1148 printsigmask(&sigset, 0);
1149#endif
1150 tprintf(", ");
1151 printflags(sigact_flags, sa.sa_flags, "SA_???");
1152#ifdef SA_RESTORER
1153 if (sa.sa_flags & SA_RESTORER)
1154 tprintf(", %p", sa.sa_restorer);
1155#endif
1156 tprintf("}");
1157 }
1158 }
1159 if (entering(tcp))
1160 tprintf(", ");
1161#ifdef LINUX
1162 else
1163 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1164#endif
1165 return 0;
1166}
1167
1168int
1169sys_signal(tcp)
1170struct tcb *tcp;
1171{
1172 if (entering(tcp)) {
1173 printsignal(tcp->u_arg[0]);
1174 tprintf(", ");
1175 switch (tcp->u_arg[1]) {
1176 case (int) SIG_ERR:
1177 tprintf("SIG_ERR");
1178 break;
1179 case (int) SIG_DFL:
1180 tprintf("SIG_DFL");
1181 break;
1182 case (int) SIG_IGN:
1183#ifndef USE_PROCFS
1184 if (tcp->u_arg[0] == SIGTRAP) {
1185 tcp->flags |= TCB_SIGTRAPPED;
1186 kill(tcp->pid, SIGSTOP);
1187 }
1188#endif /* !USE_PROCFS */
1189 tprintf("SIG_IGN");
1190 break;
1191 default:
1192#ifndef USE_PROCFS
1193 if (tcp->u_arg[0] == SIGTRAP) {
1194 tcp->flags |= TCB_SIGTRAPPED;
1195 kill(tcp->pid, SIGSTOP);
1196 }
1197#endif /* !USE_PROCFS */
1198 tprintf("%#lx", tcp->u_arg[1]);
1199 }
1200 return 0;
1201 }
1202 else {
1203 switch (tcp->u_rval) {
1204 case (int) SIG_ERR:
1205 tcp->auxstr = "SIG_ERR"; break;
1206 case (int) SIG_DFL:
1207 tcp->auxstr = "SIG_DFL"; break;
1208 case (int) SIG_IGN:
1209 tcp->auxstr = "SIG_IGN"; break;
1210 default:
1211 tcp->auxstr = NULL;
1212 }
1213 return RVAL_HEX | RVAL_STR;
1214 }
1215}
1216
1217int
1218sys_sighold(tcp)
1219struct tcb *tcp;
1220{
1221 if (entering(tcp)) {
1222 printsignal(tcp->u_arg[0]);
1223 }
1224 return 0;
1225}
1226
1227#endif /* HAVE_SIGACTION */
1228
1229#ifdef HAVE_ANDROID_OS
1230#define sigcontext_struct sigcontext
1231#endif
1232//#ifndef HAVE_ANDROID_OS
1233#ifdef LINUX
1234
1235int
1236sys_sigreturn(tcp)
1237struct tcb *tcp;
1238{
1239#ifdef ARM
1240 struct pt_regs regs;
1241 struct sigcontext_struct sc;
1242
1243 if (entering(tcp)) {
1244 tcp->u_arg[0] = 0;
1245
1246 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
1247 return 0;
1248
1249 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1250 return 0;
1251
1252 tcp->u_arg[0] = 1;
1253 tcp->u_arg[1] = sc.oldmask;
1254 } else {
1255 sigset_t sigm;
1256 long_to_sigset(tcp->u_arg[1], &sigm);
1257 tcp->u_rval = tcp->u_error = 0;
1258 if (tcp->u_arg[0] == 0)
1259 return 0;
1260 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1261 return RVAL_NONE | RVAL_STR;
1262 }
1263 return 0;
1264#elif defined(S390) || defined(S390X)
1265 long usp;
1266 struct sigcontext_struct sc;
1267
1268 if (entering(tcp)) {
1269 tcp->u_arg[0] = 0;
1270 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1271 return 0;
1272 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1273 return 0;
1274 tcp->u_arg[0] = 1;
1275 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1276 } else {
1277 tcp->u_rval = tcp->u_error = 0;
1278 if (tcp->u_arg[0] == 0)
1279 return 0;
1280 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1281 return RVAL_NONE | RVAL_STR;
1282 }
1283 return 0;
1284#else
1285#ifdef I386
1286 long esp;
1287 struct sigcontext_struct sc;
1288
1289 if (entering(tcp)) {
1290 tcp->u_arg[0] = 0;
1291 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1292 return 0;
1293 if (umove(tcp, esp, &sc) < 0)
1294 return 0;
1295 tcp->u_arg[0] = 1;
1296 tcp->u_arg[1] = sc.oldmask;
1297 }
1298 else {
1299 sigset_t sigm;
1300 long_to_sigset(tcp->u_arg[1], &sigm);
1301 tcp->u_rval = tcp->u_error = 0;
1302 if (tcp->u_arg[0] == 0)
1303 return 0;
1304 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1305 return RVAL_NONE | RVAL_STR;
1306 }
1307 return 0;
1308#else /* !I386 */
1309#ifdef IA64
1310 struct sigcontext sc;
1311 long sp;
1312
1313 if (entering(tcp)) {
1314 /* offset of sigcontext in the kernel's sigframe structure: */
1315# define SIGFRAME_SC_OFFSET 0x90
1316 tcp->u_arg[0] = 0;
1317 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1318 return 0;
1319 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
1320 return 0;
1321 tcp->u_arg[0] = 1;
1322 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
1323 }
1324 else {
1325 sigset_t sigm;
1326
1327 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
1328 tcp->u_rval = tcp->u_error = 0;
1329 if (tcp->u_arg[0] == 0)
1330 return 0;
1331 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1332 return RVAL_NONE | RVAL_STR;
1333 }
1334 return 0;
1335#else /* !IA64 */
1336#ifdef POWERPC
1337 long esp;
1338 struct sigcontext_struct sc;
1339
1340 if (entering(tcp)) {
1341 tcp->u_arg[0] = 0;
1342 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1343 return 0;
1344 if (umove(tcp, esp, &sc) < 0)
1345 return 0;
1346 tcp->u_arg[0] = 1;
1347 tcp->u_arg[1] = sc.oldmask;
1348 }
1349 else {
1350 sigset_t sigm;
1351 long_to_sigset(tcp->u_arg[1], &sigm);
1352 tcp->u_rval = tcp->u_error = 0;
1353 if (tcp->u_arg[0] == 0)
1354 return 0;
1355 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1356 return RVAL_NONE | RVAL_STR;
1357 }
1358 return 0;
1359#else /* !POWERPC */
1360#ifdef M68K
1361 long usp;
1362 struct sigcontext sc;
1363
1364 if (entering(tcp)) {
1365 tcp->u_arg[0] = 0;
1366 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
1367 return 0;
1368 if (umove(tcp, usp, &sc) < 0)
1369 return 0;
1370 tcp->u_arg[0] = 1;
1371 tcp->u_arg[1] = sc.sc_mask;
1372 }
1373 else {
1374 sigset_t sigm;
1375 long_to_sigset(tcp->u_arg[1], &sigm);
1376 tcp->u_rval = tcp->u_error = 0;
1377 if (tcp->u_arg[0] == 0)
1378 return 0;
1379 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1380 return RVAL_NONE | RVAL_STR;
1381 }
1382 return 0;
1383#else /* !M68K */
1384#ifdef ALPHA
1385 long fp;
1386 struct sigcontext_struct sc;
1387
1388 if (entering(tcp)) {
1389 tcp->u_arg[0] = 0;
1390 if (upeek(tcp->pid, REG_FP, &fp) < 0)
1391 return 0;
1392 if (umove(tcp, fp, &sc) < 0)
1393 return 0;
1394 tcp->u_arg[0] = 1;
1395 tcp->u_arg[1] = sc.sc_mask;
1396 }
1397 else {
1398 sigset_t sigm;
1399 long_to_sigset(tcp->u_arg[1], &sigm);
1400 tcp->u_rval = tcp->u_error = 0;
1401 if (tcp->u_arg[0] == 0)
1402 return 0;
1403 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1404 return RVAL_NONE | RVAL_STR;
1405 }
1406 return 0;
1407#else
1408#if defined (SPARC) || defined (SPARC64)
1409 long i1;
1410 struct regs regs;
1411 m_siginfo_t si;
1412
1413 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
1414 perror("sigreturn: PTRACE_GETREGS ");
1415 return 0;
1416 }
1417 if(entering(tcp)) {
1418 tcp->u_arg[0] = 0;
1419 i1 = regs.r_o1;
1420 if(umove(tcp, i1, &si) < 0) {
1421 perror("sigreturn: umove ");
1422 return 0;
1423 }
1424 tcp->u_arg[0] = 1;
1425 tcp->u_arg[1] = si.si_mask;
1426 } else {
1427 sigset_t sigm;
1428 long_to_sigset(tcp->u_arg[1], &sigm);
1429 tcp->u_rval = tcp->u_error = 0;
1430 if(tcp->u_arg[0] == 0)
1431 return 0;
1432 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1433 return RVAL_NONE | RVAL_STR;
1434 }
1435 return 0;
1436#else
1437#ifdef MIPS
1438 long sp;
1439 struct sigcontext sc;
1440
1441 if(entering(tcp)) {
1442 tcp->u_arg[0] = 0;
1443 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1444 return 0;
1445 if (umove(tcp, sp, &sc) < 0)
1446 return 0;
1447 tcp->u_arg[0] = 1;
1448 tcp->u_arg[1] = sc.sc_sigset;
1449 } else {
1450 tcp->u_rval = tcp->u_error = 0;
1451 if(tcp->u_arg[0] == 0)
1452 return 0;
1453 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1454 return RVAL_NONE | RVAL_STR;
1455 }
1456 return 0;
1457#else
1458#warning No sys_sigreturn() for this architecture
1459#warning (no problem, just a reminder :-)
1460 return 0;
1461#endif /* MIPS */
1462#endif /* SPARC || SPARC64 */
1463#endif /* ALPHA */
1464#endif /* !M68K */
1465#endif /* !POWERPC */
1466#endif /* !IA64 */
1467#endif /* !I386 */
1468#endif /* S390 */
1469}
1470
1471int
1472sys_siggetmask(tcp)
1473struct tcb *tcp;
1474{
1475 if (exiting(tcp)) {
1476 sigset_t sigm;
1477 long_to_sigset(tcp->u_rval, &sigm);
1478 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
1479 }
1480 return RVAL_HEX | RVAL_STR;
1481}
1482
1483int
1484sys_sigsuspend(tcp)
1485struct tcb *tcp;
1486{
1487 if (entering(tcp)) {
1488 sigset_t sigm;
1489 long_to_sigset(tcp->u_arg[2], &sigm);
1490#if 0
1491 /* first two are not really arguments, but print them anyway */
1492 /* nevermind, they are an anachronism now, too bad... */
1493 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1494#endif
1495 printsigmask(&sigm, 0);
1496 }
1497 return 0;
1498}
1499
1500#endif /* LINUX */
1501//#endif /* HAVE_ANDROID_OS */
1502
1503#if defined(SVR4) || defined(FREEBSD)
1504
1505int
1506sys_sigsuspend(tcp)
1507struct tcb *tcp;
1508{
1509 sigset_t sigset;
1510
1511 if (entering(tcp)) {
1512 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1513 tprintf("[?]");
1514 else
1515 printsigmask(&sigset, 0);
1516 }
1517 return 0;
1518}
1519#ifndef FREEBSD
1520static const struct xlat ucontext_flags[] = {
1521 { UC_SIGMASK, "UC_SIGMASK" },
1522 { UC_STACK, "UC_STACK" },
1523 { UC_CPU, "UC_CPU" },
1524#ifdef UC_FPU
1525 { UC_FPU, "UC_FPU" },
1526#endif
1527#ifdef UC_INTR
1528 { UC_INTR, "UC_INTR" },
1529#endif
1530 { 0, NULL },
1531};
1532#endif /* !FREEBSD */
1533#endif /* SVR4 || FREEBSD */
1534
1535#if defined SVR4 || defined LINUX || defined FREEBSD
1536#if defined LINUX && !defined SS_ONSTACK
1537#define SS_ONSTACK 1
1538#define SS_DISABLE 2
1539#if __GLIBC_MINOR__ == 0
1540typedef struct
1541{
1542 __ptr_t ss_sp;
1543 int ss_flags;
1544 size_t ss_size;
1545} stack_t;
1546#endif
1547#endif
1548#ifdef FREEBSD
1549#define stack_t struct sigaltstack
1550#endif
1551
1552static const struct xlat sigaltstack_flags[] = {
1553 { SS_ONSTACK, "SS_ONSTACK" },
1554 { SS_DISABLE, "SS_DISABLE" },
1555 { 0, NULL },
1556};
1557#endif
1558
1559#ifdef SVR4
1560static void
1561printcontext(tcp, ucp)
1562struct tcb *tcp;
1563ucontext_t *ucp;
1564{
1565 tprintf("{");
1566 if (!abbrev(tcp)) {
1567 tprintf("uc_flags=");
1568 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
1569 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1570 }
1571 tprintf("uc_sigmask=");
1572 printsigmask(&ucp->uc_sigmask, 0);
1573 if (!abbrev(tcp)) {
1574 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1575 (unsigned long) ucp->uc_stack.ss_sp,
1576 ucp->uc_stack.ss_size);
1577 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
1578 tprintf("}");
1579 }
1580 tprintf(", ...}");
1581}
1582
1583int
1584sys_getcontext(tcp)
1585struct tcb *tcp;
1586{
1587 ucontext_t uc;
1588
1589 if (exiting(tcp)) {
1590 if (tcp->u_error)
1591 tprintf("%#lx", tcp->u_arg[0]);
1592 else if (!tcp->u_arg[0])
1593 tprintf("NULL");
1594 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1595 tprintf("{...}");
1596 else
1597 printcontext(tcp, &uc);
1598 }
1599 return 0;
1600}
1601
1602int
1603sys_setcontext(tcp)
1604struct tcb *tcp;
1605{
1606 ucontext_t uc;
1607
1608 if (entering(tcp)) {
1609 if (!tcp->u_arg[0])
1610 tprintf("NULL");
1611 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1612 tprintf("{...}");
1613 else
1614 printcontext(tcp, &uc);
1615 }
1616 else {
1617 tcp->u_rval = tcp->u_error = 0;
1618 if (tcp->u_arg[0] == 0)
1619 return 0;
1620 return RVAL_NONE;
1621 }
1622 return 0;
1623}
1624
1625#endif /* SVR4 */
1626
1627#if defined(LINUX) || defined(FREEBSD)
1628
1629static int
1630print_stack_t(tcp, addr)
1631struct tcb *tcp;
1632unsigned long addr;
1633{
1634 stack_t ss;
1635 if (umove(tcp, addr, &ss) < 0)
1636 return -1;
1637 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1638 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1639 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1640 return 0;
1641}
1642
1643int
1644sys_sigaltstack(tcp)
1645 struct tcb *tcp;
1646{
1647 if (entering(tcp)) {
1648 if (tcp->u_arg[0] == 0)
1649 tprintf("NULL");
1650 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1651 return -1;
1652 }
1653 else {
1654 tprintf(", ");
1655 if (tcp->u_arg[1] == 0)
1656 tprintf("NULL");
1657 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1658 return -1;
1659 }
1660 return 0;
1661}
1662#endif
1663
1664#ifdef HAVE_SIGACTION
1665
1666int
1667sys_sigprocmask(tcp)
1668struct tcb *tcp;
1669{
1670#ifdef ALPHA
1671 if (entering(tcp)) {
1672 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1673 tprintf(", ");
1674 printsigmask(tcp->u_arg[1], 0);
1675 }
1676 else if (!syserror(tcp)) {
1677 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
1678 return RVAL_HEX | RVAL_STR;
1679 }
1680#else /* !ALPHA */
1681 if (entering(tcp)) {
1682#ifdef SVR4
1683 if (tcp->u_arg[0] == 0)
1684 tprintf("0");
1685 else
1686#endif /* SVR4 */
1687 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1688 tprintf(", ");
1689 print_sigset(tcp, tcp->u_arg[1], 0);
1690 tprintf(", ");
1691 }
1692 else {
1693 if (!tcp->u_arg[2])
1694 tprintf("NULL");
1695 else if (syserror(tcp))
1696 tprintf("%#lx", tcp->u_arg[2]);
1697 else
1698 print_sigset(tcp, tcp->u_arg[2], 0);
1699 }
1700#endif /* !ALPHA */
1701 return 0;
1702}
1703
1704#endif /* HAVE_SIGACTION */
1705
1706int
1707sys_kill(tcp)
1708struct tcb *tcp;
1709{
1710 if (entering(tcp)) {
1711 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
1712 }
1713 return 0;
1714}
1715
1716int
1717sys_killpg(tcp)
1718struct tcb *tcp;
1719{
1720 return sys_kill(tcp);
1721}
1722
1723#ifdef LINUX
1724int
1725sys_tgkill(tcp)
1726 struct tcb *tcp;
1727{
1728 if (entering(tcp)) {
1729 tprintf("%ld, %ld, %s",
1730 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1731 }
1732 return 0;
1733}
1734#endif
1735
1736int
1737sys_sigpending(tcp)
1738struct tcb *tcp;
1739{
1740 sigset_t sigset;
1741
1742 if (exiting(tcp)) {
1743 if (syserror(tcp))
1744 tprintf("%#lx", tcp->u_arg[0]);
1745 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1746 tprintf("[?]");
1747 else
1748 printsigmask(&sigset, 0);
1749 }
1750 return 0;
1751}
1752
1753int sys_sigwait(tcp)
1754struct tcb *tcp;
1755{
1756 sigset_t sigset;
1757
1758 if (entering(tcp)) {
1759 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1760 tprintf("[?]");
1761 else
1762 printsigmask(&sigset, 0);
1763 }
1764 else {
1765 if (!syserror(tcp)) {
1766 tcp->auxstr = signalent[tcp->u_rval];
1767 return RVAL_DECIMAL | RVAL_STR;
1768 }
1769 }
1770 return 0;
1771}
1772
1773#ifdef LINUX
1774
1775 int
1776sys_rt_sigprocmask(tcp)
1777 struct tcb *tcp;
1778{
1779 sigset_t sigset;
1780
1781 /* Note: arg[3] is the length of the sigset. */
1782 if (entering(tcp)) {
1783 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1784 tprintf(", ");
1785 if (!tcp->u_arg[1])
1786 tprintf("NULL, ");
1787 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
1788 tprintf("%#lx, ", tcp->u_arg[1]);
1789 else {
1790 printsigmask(&sigset, 1);
1791 tprintf(", ");
1792 }
1793 }
1794 else {
1795 if (!tcp->u_arg[2])
1796
1797 tprintf("NULL");
1798 else if (syserror(tcp))
1799 tprintf("%#lx", tcp->u_arg[2]);
1800 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
1801 tprintf("[?]");
1802 else
1803 printsigmask(&sigset, 1);
1804 tprintf(", %lu", tcp->u_arg[3]);
1805 }
1806 return 0;
1807}
1808
1809
1810/* Structure describing the action to be taken when a signal arrives. */
1811struct new_sigaction
1812{
1813 union
1814 {
1815 __sighandler_t __sa_handler;
1816 void (*__sa_sigaction) (int, siginfo_t *, void *);
1817 }
1818 __sigaction_handler;
1819 unsigned long sa_flags;
1820 void (*sa_restorer) (void);
1821 unsigned long int sa_mask[2];
1822};
1823
1824
1825 int
1826sys_rt_sigaction(tcp)
1827 struct tcb *tcp;
1828{
1829 struct new_sigaction sa;
1830 sigset_t sigset;
1831 long addr;
1832
1833 if (entering(tcp)) {
1834 printsignal(tcp->u_arg[0]);
1835 tprintf(", ");
1836 addr = tcp->u_arg[1];
1837 } else
1838 addr = tcp->u_arg[2];
1839 if (addr == 0)
1840 tprintf("NULL");
1841 else if (!verbose(tcp))
1842 tprintf("%#lx", addr);
1843 else if (umove(tcp, addr, &sa) < 0)
1844 tprintf("{...}");
1845 else {
1846 switch ((long) sa.__sigaction_handler.__sa_handler) {
1847 case (long) SIG_ERR:
1848 tprintf("{SIG_ERR}");
1849 break;
1850 case (long) SIG_DFL:
1851 tprintf("{SIG_DFL}");
1852 break;
1853 case (long) SIG_IGN:
1854 tprintf("{SIG_IGN}");
1855 break;
1856 default:
1857 tprintf("{%#lx, ",
1858 (long) sa.__sigaction_handler.__sa_handler);
1859 sigemptyset(&sigset);
1860#ifdef LINUXSPARC
1861 if (tcp->u_arg[4] <= sizeof(sigset))
1862 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1863#else
1864 if (tcp->u_arg[3] <= sizeof(sigset))
1865 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1866#endif
1867 else
1868 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1869 printsigmask(&sigset, 1);
1870 tprintf(", ");
1871 printflags(sigact_flags, sa.sa_flags, "SA_???");
1872#ifdef SA_RESTORER
1873 if (sa.sa_flags & SA_RESTORER)
1874 tprintf(", %p", sa.sa_restorer);
1875#endif
1876 tprintf("}");
1877 }
1878 }
1879 if (entering(tcp))
1880 tprintf(", ");
1881 else
1882#ifdef LINUXSPARC
1883 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1884#elif defined(ALPHA)
1885 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1886#else
1887 tprintf(", %lu", addr = tcp->u_arg[3]);
1888#endif
1889 return 0;
1890}
1891
1892 int
1893sys_rt_sigpending(tcp)
1894 struct tcb *tcp;
1895{
1896 sigset_t sigset;
1897
1898 if (exiting(tcp)) {
1899 if (syserror(tcp))
1900 tprintf("%#lx", tcp->u_arg[0]);
1901 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1902 &sigset, tcp->u_arg[1]) < 0)
1903 tprintf("[?]");
1904 else
1905 printsigmask(&sigset, 1);
1906 }
1907 return 0;
1908}
1909 int
1910sys_rt_sigsuspend(tcp)
1911 struct tcb *tcp;
1912{
1913 if (entering(tcp)) {
1914 sigset_t sigm;
1915 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1916 tprintf("[?]");
1917 else
1918 printsigmask(&sigm, 1);
1919 }
1920 return 0;
1921}
1922 int
1923sys_rt_sigqueueinfo(tcp)
1924 struct tcb *tcp;
1925{
1926 if (entering(tcp)) {
1927 siginfo_t si;
1928 tprintf("%lu, ", tcp->u_arg[0]);
1929 printsignal(tcp->u_arg[1]);
1930 tprintf(", ");
1931 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1932 tprintf("%#lx", tcp->u_arg[2]);
1933 else
1934 printsiginfo(&si, verbose (tcp));
1935 }
1936 return 0;
1937}
1938
1939int sys_rt_sigtimedwait(tcp)
1940 struct tcb *tcp;
1941{
1942 if (entering(tcp)) {
1943 sigset_t sigset;
1944
1945 if (copy_sigset_len(tcp, tcp->u_arg[0],
1946 &sigset, tcp->u_arg[3]) < 0)
1947 tprintf("[?]");
1948 else
1949 printsigmask(&sigset, 1);
1950 tprintf(", ");
1951 }
1952 else {
1953 if (syserror(tcp))
1954 tprintf("%#lx", tcp->u_arg[0]);
1955 else {
1956 siginfo_t si;
1957 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1958 tprintf("%#lx", tcp->u_arg[1]);
1959 else
1960 printsiginfo(&si, verbose (tcp));
1961 /* XXX For now */
1962 tprintf(", %#lx", tcp->u_arg[2]);
1963 tprintf(", %d", (int) tcp->u_arg[3]);
1964 }
1965 }
1966 return 0;
1967};
1968
1969#endif /* LINUX */