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>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
43 #include <sys/ucontext.h>
48 #ifndef PTRACE_PEEKUSR
49 # define PTRACE_PEEKUSR PTRACE_PEEKUSER
51 #ifndef PTRACE_POKEUSR
52 # define PTRACE_POKEUSR PTRACE_POKEUSER
54 #elif defined(HAVE_LINUX_PTRACE_H)
56 #include <linux/ptrace.h>
63 # include <asm/ptrace_offsets.h>
68 # define fpq kernel_fpq
70 # define fpu kernel_fpu
79 #endif /* HAVE_ASM_REG_H */
80 #ifdef HAVE_ASM_SIGCONTEXT_H
86 #elif !defined(IA64) && !defined(X86_64)
87 #include <asm/sigcontext.h>
89 #else /* !HAVE_ASM_SIGCONTEXT_H */
91 struct sigcontext_struct {
92 unsigned short gs, __gsh;
93 unsigned short fs, __fsh;
94 unsigned short es, __esh;
95 unsigned short ds, __dsh;
104 unsigned long trapno;
107 unsigned short cs, __csh;
108 unsigned long eflags;
109 unsigned long esp_at_signal;
110 unsigned short ss, __ssh;
112 unsigned long oldmask;
119 unsigned long sc_mask;
120 unsigned long sc_usp;
125 unsigned short sc_sr;
127 unsigned short sc_formatvec;
131 #endif /* !HAVE_ASM_SIGCONTEXT_H */
141 char *signalent0[] = {
142 #include "signalent.h"
144 int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
146 #if SUPPORTED_PERSONALITIES >= 2
147 char *signalent1[] = {
148 #include "signalent1.h"
150 int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
151 #endif /* SUPPORTED_PERSONALITIES >= 2 */
153 #if SUPPORTED_PERSONALITIES >= 3
154 char *signalent2[] = {
155 #include "signalent2.h"
157 int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
158 #endif /* SUPPORTED_PERSONALITIES >= 3 */
163 #if defined(SUNOS4) || defined(FREEBSD)
165 static struct xlat sigvec_flags[] = {
166 { SV_ONSTACK, "SV_ONSTACK" },
167 { SV_INTERRUPT, "SV_INTERRUPT" },
168 { SV_RESETHAND, "SV_RESETHAND" },
169 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
173 #endif /* SUNOS4 || FREEBSD */
175 #ifdef HAVE_SIGACTION
177 #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. */
181 # define SA_RESTORER 0x04000000
185 static struct xlat sigact_flags[] = {
187 { SA_RESTORER, "SA_RESTORER" },
190 { SA_STACK, "SA_STACK" },
193 { SA_RESTART, "SA_RESTART" },
196 { SA_INTERRUPT, "SA_INTERRUPT" },
199 { SA_NOMASK, "SA_NOMASK" },
202 { SA_ONESHOT, "SA_ONESHOT" },
205 { SA_SIGINFO, "SA_SIGINFO" },
208 { SA_RESETHAND, "SA_RESETHAND" },
211 { SA_ONSTACK, "SA_ONSTACK" },
214 { SA_NODEFER, "SA_NODEFER" },
217 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
220 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
223 { _SA_BSDCALL, "_SA_BSDCALL" },
228 static struct xlat sigprocmaskcmds[] = {
229 { SIG_BLOCK, "SIG_BLOCK" },
230 { SIG_UNBLOCK, "SIG_UNBLOCK" },
231 { SIG_SETMASK, "SIG_SETMASK" },
233 { SIG_SETMASK32,"SIG_SETMASK32" },
238 #endif /* HAVE_SIGACTION */
240 /* 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. */
245 #define __SIGRTMIN SIGRTMIN
246 #define __SIGRTMAX SIGRTMAX /* likewise */
255 if (sig < nsignals) {
256 return signalent[sig];
258 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
259 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
261 #endif /* SIGRTMIN */
263 sprintf(buf, "%d", sig);
280 copy_sigset_len(tcp, addr, s, len)
286 if (len > sizeof(*s))
289 if (umoven(tcp, addr, len, (char *)s) < 0)
295 /* Original sigset is unsigned long */
296 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
298 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
302 sprintsigmask(s, mask, rt)
305 int rt; /* set might include realtime sigs */
310 static char outstr[256];
313 s = outstr + strlen(outstr);
318 maxsigs = __SIGRTMAX; /* instead */
320 for (i = 1; i < maxsigs; i++) {
321 if (sigismember(mask, i) == 1)
324 if (nsigs >= nsignals * 2 / 3) {
326 for (i = 1; i < maxsigs; i++) {
327 switch (sigismember(mask, i)) {
339 for (i = 1; i < maxsigs; i++) {
340 if (sigismember(mask, i) == 1) {
341 /* real-time signals on solaris don't have
345 sprintf(s, format, signalent[i] + 3);
349 sprintf(tsig, "%u", i);
350 sprintf(s, format, tsig);
362 printsigmask(mask, rt)
366 tprintf("%s", sprintsigmask("", mask, rt));
373 tprintf(signame(nr));
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 */
421 #if __GLIBC_MINOR__ < 1
422 /* Type for data associated with a signal. */
429 # define __SI_MAX_SIZE 128
430 # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
432 typedef struct siginfo
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. */
441 int _pad[__SI_PAD_SIZE];
446 __pid_t si_pid; /* Sending process ID. */
447 __uid_t si_uid; /* Real user ID of sending process. */
450 /* POSIX.1b timers. */
453 unsigned int _timer1;
454 unsigned int _timer2;
457 /* POSIX.1b signals. */
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. */
468 __pid_t si_pid; /* Which child. */
469 int si_status; /* Exit value or signal. */
474 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
477 void *si_addr; /* Faulting insn/memory ref. */
483 int si_band; /* Band event for SIGPOLL. */
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
505 #if defined (SVR4) || defined (LINUX)
507 static struct xlat siginfo_codes[] = {
509 { SI_NOINFO, "SI_NOINFO" },
512 { SI_USER, "SI_USER" },
515 { SI_LWP, "SI_LWP" },
518 { SI_QUEUE, "SI_QUEUE" },
521 { SI_TIMER, "SI_TIMER" },
524 { SI_ASYNCIO, "SI_ASYNCIO" },
527 { SI_MESGQ, "SI_MESGQ" },
532 static 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" },
544 static 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" },
556 static struct xlat sigtrap_codes[] = {
557 { TRAP_BRKPT, "TRAP_BRKPT" },
558 { TRAP_TRACE, "TRAP_TRACE" },
562 static 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" },
572 static 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" },
582 static struct xlat sigprof_codes[] = {
584 { PROF_SIG, "PROF_SIG" },
590 static struct xlat sigemt_codes[] = {
592 { EMT_TAGOVF, "EMT_TAGOVF" },
598 static struct xlat sigsegv_codes[] = {
599 { SEGV_MAPERR, "SEGV_MAPERR" },
600 { SEGV_ACCERR, "SEGV_ACCERR" },
604 static struct xlat sigbus_codes[] = {
605 { BUS_ADRALN, "BUS_ADRALN" },
606 { BUS_ADRERR, "BUS_ADRERR" },
607 { BUS_OBJERR, "BUS_OBJERR" },
612 printsiginfo(sip, verbose)
618 if (sip->si_signo == 0) {
622 tprintf("{si_signo=");
623 printsignal(sip->si_signo);
624 code = xlookup(siginfo_codes, sip->si_code);
626 switch (sip->si_signo) {
628 code = xlookup(sigtrap_codes, sip->si_code);
631 code = xlookup(sigchld_codes, sip->si_code);
634 code = xlookup(sigpoll_codes, sip->si_code);
637 code = xlookup(sigprof_codes, sip->si_code);
640 code = xlookup(sigill_codes, sip->si_code);
644 code = xlookup(sigemt_codes, sip->si_code);
648 code = xlookup(sigfpe_codes, sip->si_code);
651 code = xlookup(sigsegv_codes, sip->si_code);
654 code = xlookup(sigbus_codes, sip->si_code);
659 tprintf(", si_code=%s", code);
661 tprintf(", si_code=%#x", sip->si_code);
663 if (sip->si_code != SI_NOINFO)
667 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
668 tprintf(", si_errno=%d", sip->si_errno);
670 tprintf(", si_errno=%s",
671 errnoent[sip->si_errno]);
674 if (SI_FROMUSER(sip)) {
675 tprintf(", si_pid=%ld, si_uid=%ld",
676 sip->si_pid, sip->si_uid);
678 switch (sip->si_code) {
682 #endif /* SI_QUEUE */
686 #endif /* SI_MESGQ */
687 tprintf(", si_value=%d",
688 sip->si_value.sival_int);
691 #endif /* SI_QUEUE */
694 #endif /* SI_FROMUSER */
696 switch (sip->si_signo) {
698 tprintf(", si_pid=%ld, si_status=",
700 if (sip->si_code == CLD_EXITED)
701 tprintf("%d", sip->si_status);
703 printsignal(sip->si_status);
708 tprintf(", si_utime=%lu, si_stime=%lu",
713 case SIGILL: case SIGFPE:
714 case SIGSEGV: case SIGBUS:
715 tprintf(", si_addr=%#lx",
716 (unsigned long) sip->si_addr);
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);
728 tprintf(", si_pid=%lu, si_uid=%lu, ",
729 (unsigned long) sip->si_pid,
730 (unsigned long) sip->si_uid);
734 tprintf("si_value={int=%u, ptr=%#lx}",
736 (unsigned long) sip->si_ptr);
746 #endif /* SVR4 || LINUX */
751 parse_sigset_t (const char *str, sigset_t *set)
758 for (i = _NSIG - 4; i >= 0; i -= 4, ++str) {
760 digit = (*str - 'a') + 10;
764 sigaddset(set, i + 1);
766 sigaddset(set, i + 2);
768 sigaddset(set, i + 3);
770 sigaddset(set, i + 4);
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.
782 sigishandled(tcp, sig)
792 sigset_t ignored, caught;
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.
809 #if defined(SIGURG) && SIGURG != SIGIO
813 /* Gloria Gaynor says ... */
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) {
830 i = read(sfd, buf, sizeof(buf));
834 * Skip the extraneous fields. We need to skip
835 * command name has any spaces in it. So be it.
837 s = strstr(buf, "SigIgn:\t");
840 fprintf(stderr, "/proc/pid/status format error\n");
843 parse_sigset_t(s + 8, &ignored);
845 s = strstr(buf, "SigCgt:\t");
848 fprintf(stderr, "/proc/pid/status format error\n");
851 parse_sigset_t(s + 8, &caught);
854 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
855 *(long long *) &ignored, *(long long *) &caught, sig);
857 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
864 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
865 (long *) &u_signal) < 0) {
868 if (u_signal != SIG_DFL)
875 #if defined(SUNOS4) || defined(FREEBSD)
885 printsignal(tcp->u_arg[0]);
887 addr = tcp->u_arg[1];
889 addr = tcp->u_arg[2];
893 else if (!verbose(tcp))
894 tprintf("%#lx", addr);
895 else if (umove(tcp, addr, &sv) < 0)
898 switch ((int) sv.sv_handler) {
900 tprintf("{SIG_ERR}");
903 tprintf("{SIG_DFL}");
906 if (tcp->u_arg[0] == SIGTRAP) {
907 tcp->flags |= TCB_SIGTRAPPED;
908 kill(tcp->pid, SIGSTOP);
910 tprintf("{SIG_IGN}");
913 if (tcp->u_arg[0] == SIGTRAP) {
914 tcp->flags |= TCB_SIGTRAPPED;
915 kill(tcp->pid, SIGSTOP);
920 if (tcp->u_arg[0] == SIGTRAP) {
921 tcp->flags |= TCB_SIGTRAPPED;
922 kill(tcp->pid, SIGSTOP);
924 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
925 printsigmask(&sv.sv_mask, 0);
927 if (!printflags(sigvec_flags, sv.sv_flags))
941 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
943 long_to_sigset(tcp->u_arg[0], &sigm);
944 printsigmask(&sigm, 0);
957 addr = tcp->u_arg[0];
959 addr = tcp->u_arg[1];
962 else if (umove(tcp, addr, &ss) < 0)
963 tprintf("%#lx", addr);
965 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
966 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
980 #endif /* SUNOS4 || FREEBSD */
990 long_to_sigset(tcp->u_arg[0], &sigm);
991 printsigmask(&sigm, 0);
993 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);
999 #endif /* !USE_PROCFS */
1001 else if (!syserror(tcp)) {
1003 long_to_sigset(tcp->u_rval, &sigm);
1004 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
1006 return RVAL_HEX | RVAL_STR;
1015 return sys_sigsetmask(tcp);
1020 #ifdef HAVE_SIGACTION
1023 struct old_sigaction {
1024 __sighandler_t __sa_handler;
1025 unsigned long sa_mask;
1026 unsigned long sa_flags;
1027 void (*sa_restorer)(void);
1029 #define SA_HANDLER __sa_handler
1033 #define SA_HANDLER sa_handler
1043 struct old_sigaction sa;
1045 struct sigaction sa;
1049 if (entering(tcp)) {
1050 printsignal(tcp->u_arg[0]);
1052 addr = tcp->u_arg[1];
1054 addr = tcp->u_arg[2];
1057 else if (!verbose(tcp))
1058 tprintf("%#lx", addr);
1059 else if (umove(tcp, addr, &sa) < 0)
1062 switch ((long) sa.SA_HANDLER) {
1063 case (long) SIG_ERR:
1064 tprintf("{SIG_ERR}");
1066 case (long) SIG_DFL:
1067 tprintf("{SIG_DFL}");
1069 case (long) SIG_IGN:
1071 if (tcp->u_arg[0] == SIGTRAP) {
1072 tcp->flags |= TCB_SIGTRAPPED;
1073 kill(tcp->pid, SIGSTOP);
1075 #endif /* !USE_PROCFS */
1076 tprintf("{SIG_IGN}");
1080 if (tcp->u_arg[0] == SIGTRAP) {
1081 tcp->flags |= TCB_SIGTRAPPED;
1082 kill(tcp->pid, SIGSTOP);
1084 #endif /* !USE_PROCFS */
1085 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
1087 printsigmask (&sa.sa_mask, 0);
1089 long_to_sigset(sa.sa_mask, &sigset);
1090 printsigmask(&sigset, 0);
1093 if (!printflags(sigact_flags, sa.sa_flags))
1096 if (sa.sa_flags & SA_RESTORER)
1097 tprintf(", %p", sa.sa_restorer);
1106 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1115 if (entering(tcp)) {
1116 printsignal(tcp->u_arg[0]);
1118 switch (tcp->u_arg[1]) {
1127 if (tcp->u_arg[0] == SIGTRAP) {
1128 tcp->flags |= TCB_SIGTRAPPED;
1129 kill(tcp->pid, SIGSTOP);
1131 #endif /* !USE_PROCFS */
1136 if (tcp->u_arg[0] == SIGTRAP) {
1137 tcp->flags |= TCB_SIGTRAPPED;
1138 kill(tcp->pid, SIGSTOP);
1140 #endif /* !USE_PROCFS */
1141 tprintf("%#lx", tcp->u_arg[1]);
1146 switch (tcp->u_rval) {
1148 tcp->auxstr = "SIG_ERR"; break;
1150 tcp->auxstr = "SIG_DFL"; break;
1152 tcp->auxstr = "SIG_IGN"; break;
1156 return RVAL_HEX | RVAL_STR;
1164 if (entering(tcp)) {
1165 printsignal(tcp->u_arg[0]);
1170 #endif /* HAVE_SIGACTION */
1178 #if defined(S390) || defined(S390X)
1180 struct sigcontext_struct sc;
1182 if (entering(tcp)) {
1184 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1186 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1189 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1191 tcp->u_rval = tcp->u_error = 0;
1192 if (tcp->u_arg[0] == 0)
1194 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1195 return RVAL_NONE | RVAL_STR;
1201 struct sigcontext_struct sc;
1203 if (entering(tcp)) {
1205 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1207 if (umove(tcp, esp, &sc) < 0)
1210 tcp->u_arg[1] = sc.oldmask;
1214 long_to_sigset(tcp->u_arg[1], &sigm);
1215 tcp->u_rval = tcp->u_error = 0;
1216 if (tcp->u_arg[0] == 0)
1218 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1219 return RVAL_NONE | RVAL_STR;
1224 struct sigcontext sc;
1227 if (entering(tcp)) {
1228 /* offset of sigcontext in the kernel's sigframe structure: */
1229 # define SIGFRAME_SC_OFFSET 0x90
1231 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1233 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
1236 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
1241 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
1242 tcp->u_rval = tcp->u_error = 0;
1243 if (tcp->u_arg[0] == 0)
1245 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1246 return RVAL_NONE | RVAL_STR;
1252 struct sigcontext_struct sc;
1254 if (entering(tcp)) {
1256 if (upeek(tcp->pid, 4*PT_R1, &esp) < 0)
1258 if (umove(tcp, esp, &sc) < 0)
1261 tcp->u_arg[1] = sc.oldmask;
1265 long_to_sigset(tcp->u_arg[1], &sigm);
1266 tcp->u_rval = tcp->u_error = 0;
1267 if (tcp->u_arg[0] == 0)
1269 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1270 return RVAL_NONE | RVAL_STR;
1273 #else /* !POWERPC */
1276 struct sigcontext sc;
1278 if (entering(tcp)) {
1280 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
1282 if (umove(tcp, usp, &sc) < 0)
1285 tcp->u_arg[1] = sc.sc_mask;
1289 long_to_sigset(tcp->u_arg[1], &sigm);
1290 tcp->u_rval = tcp->u_error = 0;
1291 if (tcp->u_arg[0] == 0)
1293 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1294 return RVAL_NONE | RVAL_STR;
1300 struct sigcontext_struct sc;
1302 if (entering(tcp)) {
1304 if (upeek(tcp->pid, REG_FP, &fp) < 0)
1306 if (umove(tcp, fp, &sc) < 0)
1309 tcp->u_arg[1] = sc.sc_mask;
1313 long_to_sigset(tcp->u_arg[1], &sigm);
1314 tcp->u_rval = tcp->u_error = 0;
1315 if (tcp->u_arg[0] == 0)
1317 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1318 return RVAL_NONE | RVAL_STR;
1327 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
1328 perror("sigreturn: PTRACE_GETREGS ");
1334 if(umove(tcp, i1, &si) < 0) {
1335 perror("sigreturn: umove ");
1339 tcp->u_arg[1] = si.si_mask;
1342 long_to_sigset(tcp->u_arg[1], &sigm);
1343 tcp->u_rval = tcp->u_error = 0;
1344 if(tcp->u_arg[0] == 0)
1346 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1347 return RVAL_NONE | RVAL_STR;
1353 struct sigcontext sc;
1357 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1359 if (umove(tcp, sp, &sc) < 0)
1362 tcp->u_arg[1] = sc.sc_sigset;
1364 tcp->u_rval = tcp->u_error = 0;
1365 if(tcp->u_arg[0] == 0)
1367 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1368 return RVAL_NONE | RVAL_STR;
1372 #warning No sys_sigreturn() for this architecture
1373 #warning (no problem, just a reminder :-)
1379 #endif /* !POWERPC */
1391 long_to_sigset(tcp->u_rval, &sigm);
1392 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
1394 return RVAL_HEX | RVAL_STR;
1401 if (entering(tcp)) {
1403 long_to_sigset(tcp->u_arg[2], &sigm);
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]);
1409 printsigmask(&sigm, 0);
1416 #if defined(SVR4) || defined(FREEBSD)
1424 if (entering(tcp)) {
1425 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1428 printsigmask(&sigset, 0);
1433 static struct xlat ucontext_flags[] = {
1434 { UC_SIGMASK, "UC_SIGMASK" },
1435 { UC_STACK, "UC_STACK" },
1436 { UC_CPU, "UC_CPU" },
1438 { UC_FPU, "UC_FPU" },
1441 { UC_INTR, "UC_INTR" },
1445 #endif /* !FREEBSD */
1446 #endif /* SVR4 || FREEBSD */
1448 #if defined SVR4 || defined LINUX || defined FREEBSD
1449 #if defined LINUX && !defined SS_ONSTACK
1450 #define SS_ONSTACK 1
1451 #define SS_DISABLE 2
1452 #if __GLIBC_MINOR__ == 0
1462 #define stack_t struct sigaltstack
1465 static struct xlat sigaltstack_flags[] = {
1466 { SS_ONSTACK, "SS_ONSTACK" },
1467 { SS_DISABLE, "SS_DISABLE" },
1474 printcontext(tcp, ucp)
1480 tprintf("uc_flags=");
1481 if (!printflags(ucontext_flags, ucp->uc_flags))
1483 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1485 tprintf("uc_sigmask=");
1486 printsigmask(&ucp->uc_sigmask, 0);
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))
1506 tprintf("%#lx", tcp->u_arg[0]);
1507 else if (!tcp->u_arg[0])
1509 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1512 printcontext(tcp, &uc);
1523 if (entering(tcp)) {
1526 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1529 printcontext(tcp, &uc);
1532 tcp->u_rval = tcp->u_error = 0;
1533 if (tcp->u_arg[0] == 0)
1542 #if defined(LINUX) || defined(FREEBSD)
1545 print_stack_t(tcp, addr)
1550 if (umove(tcp, addr, &ss) < 0)
1552 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1553 if (!printflags(sigaltstack_flags, ss.ss_flags))
1555 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1560 sys_sigaltstack(tcp)
1563 if (entering(tcp)) {
1564 if (tcp->u_arg[0] == 0)
1566 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1571 if (tcp->u_arg[1] == 0)
1573 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1580 #ifdef HAVE_SIGACTION
1583 sys_sigprocmask(tcp)
1587 if (entering(tcp)) {
1588 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1590 printsigmask(tcp->u_arg[1], 0);
1592 else if (!syserror(tcp)) {
1593 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
1594 return RVAL_HEX | RVAL_STR;
1599 if (entering(tcp)) {
1601 if (tcp->u_arg[0] == 0)
1605 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1609 else if (copy_sigset(tcp, tcp->u_arg[1], &sigset) < 0)
1610 tprintf("%#lx, ", tcp->u_arg[1]);
1612 printsigmask(&sigset, 0);
1619 else if (syserror(tcp))
1620 tprintf("%#lx", tcp->u_arg[2]);
1621 else if (copy_sigset(tcp, tcp->u_arg[2], &sigset) < 0)
1624 printsigmask(&sigset, 0);
1630 #endif /* HAVE_SIGACTION */
1636 if (entering(tcp)) {
1637 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
1646 return sys_kill(tcp);
1657 tprintf("%#lx", tcp->u_arg[0]);
1658 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1661 printsigmask(&sigset, 0);
1666 int sys_sigwait(tcp)
1671 if (entering(tcp)) {
1672 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1675 printsigmask(&sigset, 0);
1678 if (!syserror(tcp)) {
1679 tcp->auxstr = signalent[tcp->u_rval];
1680 return RVAL_DECIMAL | RVAL_STR;
1689 sys_rt_sigprocmask(tcp)
1694 /* Note: arg[3] is the length of the sigset. */
1695 if (entering(tcp)) {
1696 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1700 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
1701 tprintf("%#lx, ", tcp->u_arg[1]);
1703 printsigmask(&sigset, 1);
1711 else if (syserror(tcp))
1712 tprintf("%#lx", tcp->u_arg[2]);
1713 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
1716 printsigmask(&sigset, 1);
1717 tprintf(", %lu", tcp->u_arg[3]);
1723 /* Structure describing the action to be taken when a signal arrives. */
1724 struct new_sigaction
1728 __sighandler_t __sa_handler;
1729 void (*__sa_sigaction) (int, siginfo_t *, void *);
1731 __sigaction_handler;
1732 unsigned long sa_flags;
1733 void (*sa_restorer) (void);
1734 unsigned long int sa_mask[2];
1739 sys_rt_sigaction(tcp)
1742 struct new_sigaction sa;
1746 if (entering(tcp)) {
1747 printsignal(tcp->u_arg[0]);
1749 addr = tcp->u_arg[1];
1751 addr = tcp->u_arg[2];
1754 else if (!verbose(tcp))
1755 tprintf("%#lx", addr);
1756 else if (umove(tcp, addr, &sa) < 0)
1759 switch ((long) sa.__sigaction_handler.__sa_handler) {
1760 case (long) SIG_ERR:
1761 tprintf("{SIG_ERR}");
1763 case (long) SIG_DFL:
1764 tprintf("{SIG_DFL}");
1766 case (long) SIG_IGN:
1767 tprintf("{SIG_IGN}");
1771 (long) sa.__sigaction_handler.__sa_handler);
1772 sigemptyset(&sigset);
1774 if (tcp->u_arg[4] <= sizeof(sigset))
1775 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1777 if (tcp->u_arg[3] <= sizeof(sigset))
1778 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1781 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1782 printsigmask(&sigset, 1);
1784 if (!printflags(sigact_flags, sa.sa_flags))
1787 if (sa.sa_flags & SA_RESTORER)
1788 tprintf(", %p", sa.sa_restorer);
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]);
1801 tprintf(", %lu", addr = tcp->u_arg[3]);
1807 sys_rt_sigpending(tcp)
1814 tprintf("%#lx", tcp->u_arg[0]);
1815 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1816 &sigset, tcp->u_arg[1]) < 0)
1819 printsigmask(&sigset, 1);
1824 sys_rt_sigsuspend(tcp)
1827 if (entering(tcp)) {
1829 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1832 printsigmask(&sigm, 1);
1837 sys_rt_sigqueueinfo(tcp)
1840 if (entering(tcp)) {
1842 tprintf("%lu, ", tcp->u_arg[0]);
1843 printsignal(tcp->u_arg[1]);
1845 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1846 tprintf("%#lx", tcp->u_arg[2]);
1848 printsiginfo(&si, verbose (tcp));
1853 int sys_rt_sigtimedwait(tcp)
1856 if (entering(tcp)) {
1859 if (copy_sigset_len(tcp, tcp->u_arg[0],
1860 &sigset, tcp->u_arg[3]) < 0)
1863 printsigmask(&sigset, 1);
1868 tprintf("%#lx", tcp->u_arg[0]);
1871 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1872 tprintf("%#lx", tcp->u_arg[1]);
1874 printsiginfo(&si, verbose (tcp));
1876 tprintf(", %#lx", tcp->u_arg[2]);
1877 tprintf(", %d", (int) tcp->u_arg[3]);