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 # ifdef HAVE_STRUCT_IA64_FPREG
57 # define ia64_fpreg XXX_ia64_fpreg
59 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS
60 # define pt_all_user_regs XXX_pt_all_user_regs
62 #include <linux/ptrace.h>
64 # undef pt_all_user_regs
71 # include <asm/ptrace_offsets.h>
75 # if defined (SPARC) || defined (SPARC64)
76 # define fpq kernel_fpq
78 # define fpu kernel_fpu
81 # if defined (SPARC) || defined (SPARC64)
86 #if defined (LINUX) && defined (SPARC64)
88 # undef PTRACE_GETREGS
89 # define PTRACE_GETREGS PTRACE_GETREGS64
90 # undef PTRACE_SETREGS
91 # define PTRACE_SETREGS PTRACE_SETREGS64
92 #endif /* LINUX && SPARC64 */
93 #endif /* HAVE_ASM_REG_H */
95 #if defined (SPARC) || defined (SPARC64)
100 #elif defined HAVE_ASM_SIGCONTEXT_H
101 #if !defined(IA64) && !defined(X86_64)
102 #include <asm/sigcontext.h>
103 #endif /* !IA64 && !X86_64 */
104 #else /* !HAVE_ASM_SIGCONTEXT_H */
106 struct sigcontext_struct {
107 unsigned short gs, __gsh;
108 unsigned short fs, __fsh;
109 unsigned short es, __esh;
110 unsigned short ds, __dsh;
119 unsigned long trapno;
122 unsigned short cs, __csh;
123 unsigned long eflags;
124 unsigned long esp_at_signal;
125 unsigned short ss, __ssh;
127 unsigned long oldmask;
134 unsigned long sc_mask;
135 unsigned long sc_usp;
140 unsigned short sc_sr;
142 unsigned short sc_formatvec;
146 #endif /* !HAVE_ASM_SIGCONTEXT_H */
156 const char *const signalent0[] = {
157 #include "signalent.h"
159 const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
161 #if SUPPORTED_PERSONALITIES >= 2
162 const char *const signalent1[] = {
163 #include "signalent1.h"
165 const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
166 #endif /* SUPPORTED_PERSONALITIES >= 2 */
168 #if SUPPORTED_PERSONALITIES >= 3
169 const char *const signalent2[] = {
170 #include "signalent2.h"
172 const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
173 #endif /* SUPPORTED_PERSONALITIES >= 3 */
175 const char *const *signalent;
178 #if defined(SUNOS4) || defined(FREEBSD)
180 static const struct xlat sigvec_flags[] = {
181 { SV_ONSTACK, "SV_ONSTACK" },
182 { SV_INTERRUPT, "SV_INTERRUPT" },
183 { SV_RESETHAND, "SV_RESETHAND" },
184 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
188 #endif /* SUNOS4 || FREEBSD */
190 #ifdef HAVE_SIGACTION
192 #if defined LINUX && (defined I386 || defined X86_64)
193 /* The libc headers do not define this constant since it should only be
194 used by the implementation. So wwe define it here. */
196 # define SA_RESTORER 0x04000000
200 static const struct xlat sigact_flags[] = {
202 { SA_RESTORER, "SA_RESTORER" },
205 { SA_STACK, "SA_STACK" },
208 { SA_RESTART, "SA_RESTART" },
211 { SA_INTERRUPT, "SA_INTERRUPT" },
214 { SA_NOMASK, "SA_NOMASK" },
217 { SA_ONESHOT, "SA_ONESHOT" },
220 { SA_SIGINFO, "SA_SIGINFO" },
223 { SA_RESETHAND, "SA_RESETHAND" },
226 { SA_ONSTACK, "SA_ONSTACK" },
229 { SA_NODEFER, "SA_NODEFER" },
232 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
235 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
238 { _SA_BSDCALL, "_SA_BSDCALL" },
243 static const struct xlat sigprocmaskcmds[] = {
244 { SIG_BLOCK, "SIG_BLOCK" },
245 { SIG_UNBLOCK, "SIG_UNBLOCK" },
246 { SIG_SETMASK, "SIG_SETMASK" },
248 { SIG_SETMASK32,"SIG_SETMASK32" },
253 #endif /* HAVE_SIGACTION */
255 /* Anonymous realtime signals. */
256 /* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
257 constant. This is what we want. Otherwise, just use SIGRTMIN. */
260 #define __SIGRTMIN SIGRTMIN
261 #define __SIGRTMAX SIGRTMAX /* likewise */
270 if (sig >= 0 && sig < nsignals) {
271 return signalent[sig];
273 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
274 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
276 #endif /* SIGRTMIN */
278 sprintf(buf, "%d", sig);
295 copy_sigset_len(tcp, addr, s, len)
301 if (len > sizeof(*s))
304 if (umoven(tcp, addr, len, (char *)s) < 0)
310 /* Original sigset is unsigned long */
311 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
313 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
317 sprintsigmask(s, mask, rt)
320 int rt; /* set might include realtime sigs */
325 static char outstr[8 * sizeof(sigset_t) * 8];
328 s = outstr + strlen(outstr);
333 maxsigs = __SIGRTMAX; /* instead */
335 for (i = 1; i < maxsigs; i++) {
336 if (sigismember(mask, i) == 1)
339 if (nsigs >= nsignals * 2 / 3) {
341 for (i = 1; i < maxsigs; i++) {
342 switch (sigismember(mask, i)) {
354 for (i = 1; i < maxsigs; i++) {
355 if (sigismember(mask, i) == 1) {
356 /* real-time signals on solaris don't have
360 sprintf(s, format, signalent[i] + 3);
363 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
365 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
366 sprintf(s, format, tsig);
368 #endif /* SIGRTMIN */
371 sprintf(tsig, "%u", i);
372 sprintf(s, format, tsig);
384 printsigmask(mask, rt)
388 tprintf("%s", sprintsigmask("", mask, rt));
395 tprintf(signame(nr));
399 print_sigset(struct tcb *tcp, long addr, int rt)
405 else if (copy_sigset(tcp, addr, &ss) < 0)
406 tprintf("%#lx", addr);
408 printsigmask(&ss, rt);
414 #define ILL_ILLOPC 1 /* illegal opcode */
415 #define ILL_ILLOPN 2 /* illegal operand */
416 #define ILL_ILLADR 3 /* illegal addressing mode */
417 #define ILL_ILLTRP 4 /* illegal trap */
418 #define ILL_PRVOPC 5 /* privileged opcode */
419 #define ILL_PRVREG 6 /* privileged register */
420 #define ILL_COPROC 7 /* coprocessor error */
421 #define ILL_BADSTK 8 /* internal stack error */
422 #define FPE_INTDIV 1 /* integer divide by zero */
423 #define FPE_INTOVF 2 /* integer overflow */
424 #define FPE_FLTDIV 3 /* floating point divide by zero */
425 #define FPE_FLTOVF 4 /* floating point overflow */
426 #define FPE_FLTUND 5 /* floating point underflow */
427 #define FPE_FLTRES 6 /* floating point inexact result */
428 #define FPE_FLTINV 7 /* floating point invalid operation */
429 #define FPE_FLTSUB 8 /* subscript out of range */
430 #define SEGV_MAPERR 1 /* address not mapped to object */
431 #define SEGV_ACCERR 2 /* invalid permissions for mapped object */
432 #define BUS_ADRALN 1 /* invalid address alignment */
433 #define BUS_ADRERR 2 /* non-existant physical address */
434 #define BUS_OBJERR 3 /* object specific hardware error */
435 #define TRAP_BRKPT 1 /* process breakpoint */
436 #define TRAP_TRACE 2 /* process trace trap */
437 #define CLD_EXITED 1 /* child has exited */
438 #define CLD_KILLED 2 /* child was killed */
439 #define CLD_DUMPED 3 /* child terminated abnormally */
440 #define CLD_TRAPPED 4 /* traced child has trapped */
441 #define CLD_STOPPED 5 /* child has stopped */
442 #define CLD_CONTINUED 6 /* stopped child has continued */
443 #define POLL_IN 1 /* data input available */
444 #define POLL_OUT 2 /* output buffers available */
445 #define POLL_MSG 3 /* input message available */
446 #define POLL_ERR 4 /* i/o error */
447 #define POLL_PRI 5 /* high priority input available */
448 #define POLL_HUP 6 /* device disconnected */
449 #define SI_USER 0 /* sent by kill, sigsend, raise */
450 #define SI_QUEUE -1 /* sent by sigqueue */
451 #define SI_TIMER -2 /* sent by timer expiration */
452 #define SI_MESGQ -3 /* sent by real time mesq state change */
453 #define SI_ASYNCIO -4 /* sent by AIO completion */
454 #define SI_SIGIO -5 /* Sent by SIGIO */
455 #define SI_TKILL -6 /* Sent by tkill */
458 #if __GLIBC_MINOR__ < 1
459 /* Type for data associated with a signal. */
466 # define __SI_MAX_SIZE 128
467 # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
469 typedef struct siginfo
471 int si_signo; /* Signal number. */
472 int si_errno; /* If non-zero, an errno value associated with
473 this signal, as defined in <errno.h>. */
474 int si_code; /* Signal code. */
478 int _pad[__SI_PAD_SIZE];
483 __pid_t si_pid; /* Sending process ID. */
484 __uid_t si_uid; /* Real user ID of sending process. */
487 /* POSIX.1b timers. */
490 unsigned int _timer1;
491 unsigned int _timer2;
494 /* POSIX.1b signals. */
497 __pid_t si_pid; /* Sending process ID. */
498 __uid_t si_uid; /* Real user ID of sending process. */
499 sigval_t si_sigval; /* Signal value. */
505 __pid_t si_pid; /* Which child. */
506 int si_status; /* Exit value or signal. */
511 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
514 void *si_addr; /* Faulting insn/memory ref. */
520 int si_band; /* Band event for SIGPOLL. */
526 #define si_pid _sifields._kill.si_pid
527 #define si_uid _sifields._kill.si_uid
528 #define si_status _sifields._sigchld.si_status
529 #define si_utime _sifields._sigchld.si_utime
530 #define si_stime _sifields._sigchld.si_stime
531 #define si_value _sifields._rt.si_sigval
532 #define si_int _sifields._rt.si_sigval.sival_int
533 #define si_ptr _sifields._rt.si_sigval.sival_ptr
534 #define si_addr _sifields._sigfault.si_addr
535 #define si_band _sifields._sigpoll.si_band
536 #define si_fd _sifields._sigpoll.si_fd
542 #if defined (SVR4) || defined (LINUX)
544 static const struct xlat siginfo_codes[] = {
546 { SI_NOINFO, "SI_NOINFO" },
549 { SI_USER, "SI_USER" },
552 { SI_LWP, "SI_LWP" },
555 { SI_QUEUE, "SI_QUEUE" },
558 { SI_TIMER, "SI_TIMER" },
561 { SI_ASYNCIO, "SI_ASYNCIO" },
564 { SI_MESGQ, "SI_MESGQ" },
567 { SI_SIGIO, "SI_SIGIO" },
570 { SI_TKILL, "SI_TKILL" },
575 static const struct xlat sigill_codes[] = {
576 { ILL_ILLOPC, "ILL_ILLOPC" },
577 { ILL_ILLOPN, "ILL_ILLOPN" },
578 { ILL_ILLADR, "ILL_ILLADR" },
579 { ILL_ILLTRP, "ILL_ILLTRP" },
580 { ILL_PRVOPC, "ILL_PRVOPC" },
581 { ILL_PRVREG, "ILL_PRVREG" },
582 { ILL_COPROC, "ILL_COPROC" },
583 { ILL_BADSTK, "ILL_BADSTK" },
587 static const struct xlat sigfpe_codes[] = {
588 { FPE_INTDIV, "FPE_INTDIV" },
589 { FPE_INTOVF, "FPE_INTOVF" },
590 { FPE_FLTDIV, "FPE_FLTDIV" },
591 { FPE_FLTOVF, "FPE_FLTOVF" },
592 { FPE_FLTUND, "FPE_FLTUND" },
593 { FPE_FLTRES, "FPE_FLTRES" },
594 { FPE_FLTINV, "FPE_FLTINV" },
595 { FPE_FLTSUB, "FPE_FLTSUB" },
599 static const struct xlat sigtrap_codes[] = {
600 { TRAP_BRKPT, "TRAP_BRKPT" },
601 { TRAP_TRACE, "TRAP_TRACE" },
605 static const struct xlat sigchld_codes[] = {
606 { CLD_EXITED, "CLD_EXITED" },
607 { CLD_KILLED, "CLD_KILLED" },
608 { CLD_DUMPED, "CLD_DUMPED" },
609 { CLD_TRAPPED, "CLD_TRAPPED" },
610 { CLD_STOPPED, "CLD_STOPPED" },
611 { CLD_CONTINUED,"CLD_CONTINUED" },
615 static const struct xlat sigpoll_codes[] = {
616 { POLL_IN, "POLL_IN" },
617 { POLL_OUT, "POLL_OUT" },
618 { POLL_MSG, "POLL_MSG" },
619 { POLL_ERR, "POLL_ERR" },
620 { POLL_PRI, "POLL_PRI" },
621 { POLL_HUP, "POLL_HUP" },
625 static const struct xlat sigprof_codes[] = {
627 { PROF_SIG, "PROF_SIG" },
633 static const struct xlat sigemt_codes[] = {
635 { EMT_TAGOVF, "EMT_TAGOVF" },
641 static const struct xlat sigsegv_codes[] = {
642 { SEGV_MAPERR, "SEGV_MAPERR" },
643 { SEGV_ACCERR, "SEGV_ACCERR" },
647 static const struct xlat sigbus_codes[] = {
648 { BUS_ADRALN, "BUS_ADRALN" },
649 { BUS_ADRERR, "BUS_ADRERR" },
650 { BUS_OBJERR, "BUS_OBJERR" },
655 printsiginfo(sip, verbose)
661 if (sip->si_signo == 0) {
665 tprintf("{si_signo=");
666 printsignal(sip->si_signo);
667 code = xlookup(siginfo_codes, sip->si_code);
669 switch (sip->si_signo) {
671 code = xlookup(sigtrap_codes, sip->si_code);
674 code = xlookup(sigchld_codes, sip->si_code);
677 code = xlookup(sigpoll_codes, sip->si_code);
680 code = xlookup(sigprof_codes, sip->si_code);
683 code = xlookup(sigill_codes, sip->si_code);
687 code = xlookup(sigemt_codes, sip->si_code);
691 code = xlookup(sigfpe_codes, sip->si_code);
694 code = xlookup(sigsegv_codes, sip->si_code);
697 code = xlookup(sigbus_codes, sip->si_code);
702 tprintf(", si_code=%s", code);
704 tprintf(", si_code=%#x", sip->si_code);
706 if (sip->si_code != SI_NOINFO)
710 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
711 tprintf(", si_errno=%d", sip->si_errno);
713 tprintf(", si_errno=%s",
714 errnoent[sip->si_errno]);
717 if (SI_FROMUSER(sip)) {
718 tprintf(", si_pid=%ld, si_uid=%ld",
719 sip->si_pid, sip->si_uid);
721 switch (sip->si_code) {
725 #endif /* SI_QUEUE */
729 #endif /* SI_MESGQ */
730 tprintf(", si_value=%d",
731 sip->si_value.sival_int);
734 #endif /* SI_QUEUE */
737 #endif /* SI_FROMUSER */
739 switch (sip->si_signo) {
741 tprintf(", si_pid=%ld, si_status=",
743 if (sip->si_code == CLD_EXITED)
744 tprintf("%d", sip->si_status);
746 printsignal(sip->si_status);
751 tprintf(", si_utime=%lu, si_stime=%lu",
756 case SIGILL: case SIGFPE:
757 case SIGSEGV: case SIGBUS:
758 tprintf(", si_addr=%#lx",
759 (unsigned long) sip->si_addr);
762 switch (sip->si_code) {
763 case POLL_IN: case POLL_OUT: case POLL_MSG:
764 tprintf(", si_band=%ld",
765 (long) sip->si_band);
771 tprintf(", si_pid=%lu, si_uid=%lu, ",
772 (unsigned long) sip->si_pid,
773 (unsigned long) sip->si_uid);
777 tprintf("si_value={int=%u, ptr=%#lx}",
779 (unsigned long) sip->si_ptr);
789 #endif /* SVR4 || LINUX */
794 parse_sigset_t (const char *str, sigset_t *set)
802 p = strchr(str, '\n');
804 p = strchr(str, '\0');
805 for (i = 0; p-- > str; i += 4) {
806 if (*p >= '0' && *p <= '9')
808 else if (*p >= 'a' && *p <= 'f')
809 digit = *p - 'a' + 10;
810 else if (*p >= 'A' && *p <= 'F')
811 digit = *p - 'A' + 10;
815 sigaddset(set, i + 1);
817 sigaddset(set, i + 2);
819 sigaddset(set, i + 3);
821 sigaddset(set, i + 4);
828 * Check process TCP for the disposition of signal SIG.
829 * Return 1 if the process would somehow manage to survive signal SIG,
830 * else return 0. This routine will never be called with SIGKILL.
833 sigishandled(tcp, sig)
843 sigset_t ignored, caught;
847 * Since procfs doesn't interfere with wait I think it is safe
848 * to punt on this question. If not, the information is there.
860 #if defined(SIGURG) && SIGURG != SIGIO
864 /* Gloria Gaynor says ... */
872 /* This is incredibly costly but it's worth it. */
873 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
874 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
875 doesn't handle real-time signals). */
876 sprintf(sname, "/proc/%d/status", tcp->pid);
877 if ((sfd = open(sname, O_RDONLY)) == -1) {
881 i = read(sfd, buf, sizeof(buf));
885 * Skip the extraneous fields. We need to skip
886 * command name has any spaces in it. So be it.
888 s = strstr(buf, "SigIgn:\t");
891 fprintf(stderr, "/proc/pid/status format error\n");
894 parse_sigset_t(s + 8, &ignored);
896 s = strstr(buf, "SigCgt:\t");
899 fprintf(stderr, "/proc/pid/status format error\n");
902 parse_sigset_t(s + 8, &caught);
905 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
906 *(long long *) &ignored, *(long long *) &caught, sig);
908 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
915 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
916 (long *) &u_signal) < 0) {
919 if (u_signal != SIG_DFL)
926 #if defined(SUNOS4) || defined(FREEBSD)
936 printsignal(tcp->u_arg[0]);
938 addr = tcp->u_arg[1];
940 addr = tcp->u_arg[2];
944 else if (!verbose(tcp))
945 tprintf("%#lx", addr);
946 else if (umove(tcp, addr, &sv) < 0)
949 switch ((int) sv.sv_handler) {
951 tprintf("{SIG_ERR}");
954 tprintf("{SIG_DFL}");
957 if (tcp->u_arg[0] == SIGTRAP) {
958 tcp->flags |= TCB_SIGTRAPPED;
959 kill(tcp->pid, SIGSTOP);
961 tprintf("{SIG_IGN}");
964 if (tcp->u_arg[0] == SIGTRAP) {
965 tcp->flags |= TCB_SIGTRAPPED;
966 kill(tcp->pid, SIGSTOP);
971 if (tcp->u_arg[0] == SIGTRAP) {
972 tcp->flags |= TCB_SIGTRAPPED;
973 kill(tcp->pid, SIGSTOP);
975 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
976 printsigmask(&sv.sv_mask, 0);
978 printflags(sigvec_flags, sv.sv_flags, "SV_???");
991 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
993 long_to_sigset(tcp->u_arg[0], &sigm);
994 printsigmask(&sigm, 0);
1007 addr = tcp->u_arg[0];
1009 addr = tcp->u_arg[1];
1012 else if (umove(tcp, addr, &ss) < 0)
1013 tprintf("%#lx", addr);
1015 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1016 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1030 #endif /* SUNOS4 || FREEBSD */
1038 if (entering(tcp)) {
1040 long_to_sigset(tcp->u_arg[0], &sigm);
1041 printsigmask(&sigm, 0);
1043 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1044 /* Mark attempt to block SIGTRAP */
1045 tcp->flags |= TCB_SIGTRAPPED;
1046 /* Send unblockable signal */
1047 kill(tcp->pid, SIGSTOP);
1049 #endif /* !USE_PROCFS */
1051 else if (!syserror(tcp)) {
1053 long_to_sigset(tcp->u_rval, &sigm);
1054 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
1056 return RVAL_HEX | RVAL_STR;
1065 return sys_sigsetmask(tcp);
1070 #ifdef HAVE_SIGACTION
1073 struct old_sigaction {
1074 __sighandler_t __sa_handler;
1075 unsigned long sa_mask;
1076 unsigned long sa_flags;
1077 void (*sa_restorer)(void);
1079 #define SA_HANDLER __sa_handler
1083 #define SA_HANDLER sa_handler
1093 struct old_sigaction sa;
1095 struct sigaction sa;
1099 if (entering(tcp)) {
1100 printsignal(tcp->u_arg[0]);
1102 addr = tcp->u_arg[1];
1104 addr = tcp->u_arg[2];
1107 else if (!verbose(tcp))
1108 tprintf("%#lx", addr);
1109 else if (umove(tcp, addr, &sa) < 0)
1112 switch ((long) sa.SA_HANDLER) {
1113 case (long) SIG_ERR:
1114 tprintf("{SIG_ERR}");
1116 case (long) SIG_DFL:
1117 tprintf("{SIG_DFL}");
1119 case (long) SIG_IGN:
1121 if (tcp->u_arg[0] == SIGTRAP) {
1122 tcp->flags |= TCB_SIGTRAPPED;
1123 kill(tcp->pid, SIGSTOP);
1125 #endif /* !USE_PROCFS */
1126 tprintf("{SIG_IGN}");
1130 if (tcp->u_arg[0] == SIGTRAP) {
1131 tcp->flags |= TCB_SIGTRAPPED;
1132 kill(tcp->pid, SIGSTOP);
1134 #endif /* !USE_PROCFS */
1135 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
1137 printsigmask (&sa.sa_mask, 0);
1139 long_to_sigset(sa.sa_mask, &sigset);
1140 printsigmask(&sigset, 0);
1143 printflags(sigact_flags, sa.sa_flags, "SA_???");
1145 if (sa.sa_flags & SA_RESTORER)
1146 tprintf(", %p", sa.sa_restorer);
1155 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1164 if (entering(tcp)) {
1165 printsignal(tcp->u_arg[0]);
1167 switch (tcp->u_arg[1]) {
1176 if (tcp->u_arg[0] == SIGTRAP) {
1177 tcp->flags |= TCB_SIGTRAPPED;
1178 kill(tcp->pid, SIGSTOP);
1180 #endif /* !USE_PROCFS */
1185 if (tcp->u_arg[0] == SIGTRAP) {
1186 tcp->flags |= TCB_SIGTRAPPED;
1187 kill(tcp->pid, SIGSTOP);
1189 #endif /* !USE_PROCFS */
1190 tprintf("%#lx", tcp->u_arg[1]);
1195 switch (tcp->u_rval) {
1197 tcp->auxstr = "SIG_ERR"; break;
1199 tcp->auxstr = "SIG_DFL"; break;
1201 tcp->auxstr = "SIG_IGN"; break;
1205 return RVAL_HEX | RVAL_STR;
1213 if (entering(tcp)) {
1214 printsignal(tcp->u_arg[0]);
1219 #endif /* HAVE_SIGACTION */
1228 struct pt_regs regs;
1229 struct sigcontext_struct sc;
1231 if (entering(tcp)) {
1234 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)®s) == -1)
1237 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1241 tcp->u_arg[1] = sc.oldmask;
1244 long_to_sigset(tcp->u_arg[1], &sigm);
1245 tcp->u_rval = tcp->u_error = 0;
1246 if (tcp->u_arg[0] == 0)
1248 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1249 return RVAL_NONE | RVAL_STR;
1252 #elif defined(S390) || defined(S390X)
1254 struct sigcontext_struct sc;
1256 if (entering(tcp)) {
1258 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1260 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1263 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1265 tcp->u_rval = tcp->u_error = 0;
1266 if (tcp->u_arg[0] == 0)
1268 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1269 return RVAL_NONE | RVAL_STR;
1275 struct sigcontext_struct sc;
1277 if (entering(tcp)) {
1279 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1281 if (umove(tcp, esp, &sc) < 0)
1284 tcp->u_arg[1] = sc.oldmask;
1288 long_to_sigset(tcp->u_arg[1], &sigm);
1289 tcp->u_rval = tcp->u_error = 0;
1290 if (tcp->u_arg[0] == 0)
1292 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1293 return RVAL_NONE | RVAL_STR;
1298 struct sigcontext sc;
1301 if (entering(tcp)) {
1302 /* offset of sigcontext in the kernel's sigframe structure: */
1303 # define SIGFRAME_SC_OFFSET 0x90
1305 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1307 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
1310 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
1315 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
1316 tcp->u_rval = tcp->u_error = 0;
1317 if (tcp->u_arg[0] == 0)
1319 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1320 return RVAL_NONE | RVAL_STR;
1326 struct sigcontext_struct sc;
1328 if (entering(tcp)) {
1330 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1332 if (umove(tcp, esp, &sc) < 0)
1335 tcp->u_arg[1] = sc.oldmask;
1339 long_to_sigset(tcp->u_arg[1], &sigm);
1340 tcp->u_rval = tcp->u_error = 0;
1341 if (tcp->u_arg[0] == 0)
1343 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1344 return RVAL_NONE | RVAL_STR;
1347 #else /* !POWERPC */
1350 struct sigcontext sc;
1352 if (entering(tcp)) {
1354 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
1356 if (umove(tcp, usp, &sc) < 0)
1359 tcp->u_arg[1] = sc.sc_mask;
1363 long_to_sigset(tcp->u_arg[1], &sigm);
1364 tcp->u_rval = tcp->u_error = 0;
1365 if (tcp->u_arg[0] == 0)
1367 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1368 return RVAL_NONE | RVAL_STR;
1374 struct sigcontext_struct sc;
1376 if (entering(tcp)) {
1378 if (upeek(tcp->pid, REG_FP, &fp) < 0)
1380 if (umove(tcp, fp, &sc) < 0)
1383 tcp->u_arg[1] = sc.sc_mask;
1387 long_to_sigset(tcp->u_arg[1], &sigm);
1388 tcp->u_rval = tcp->u_error = 0;
1389 if (tcp->u_arg[0] == 0)
1391 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1392 return RVAL_NONE | RVAL_STR;
1396 #if defined (SPARC) || defined (SPARC64)
1401 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
1402 perror("sigreturn: PTRACE_GETREGS ");
1408 if(umove(tcp, i1, &si) < 0) {
1409 perror("sigreturn: umove ");
1413 tcp->u_arg[1] = si.si_mask;
1416 long_to_sigset(tcp->u_arg[1], &sigm);
1417 tcp->u_rval = tcp->u_error = 0;
1418 if(tcp->u_arg[0] == 0)
1420 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1421 return RVAL_NONE | RVAL_STR;
1427 struct sigcontext sc;
1431 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1433 if (umove(tcp, sp, &sc) < 0)
1436 tcp->u_arg[1] = sc.sc_sigset;
1438 tcp->u_rval = tcp->u_error = 0;
1439 if(tcp->u_arg[0] == 0)
1441 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1442 return RVAL_NONE | RVAL_STR;
1446 #warning No sys_sigreturn() for this architecture
1447 #warning (no problem, just a reminder :-)
1450 #endif /* SPARC || SPARC64 */
1453 #endif /* !POWERPC */
1465 long_to_sigset(tcp->u_rval, &sigm);
1466 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
1468 return RVAL_HEX | RVAL_STR;
1475 if (entering(tcp)) {
1477 long_to_sigset(tcp->u_arg[2], &sigm);
1479 /* first two are not really arguments, but print them anyway */
1480 /* nevermind, they are an anachronism now, too bad... */
1481 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1483 printsigmask(&sigm, 0);
1490 #if defined(SVR4) || defined(FREEBSD)
1498 if (entering(tcp)) {
1499 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1502 printsigmask(&sigset, 0);
1507 static const struct xlat ucontext_flags[] = {
1508 { UC_SIGMASK, "UC_SIGMASK" },
1509 { UC_STACK, "UC_STACK" },
1510 { UC_CPU, "UC_CPU" },
1512 { UC_FPU, "UC_FPU" },
1515 { UC_INTR, "UC_INTR" },
1519 #endif /* !FREEBSD */
1520 #endif /* SVR4 || FREEBSD */
1522 #if defined SVR4 || defined LINUX || defined FREEBSD
1523 #if defined LINUX && !defined SS_ONSTACK
1524 #define SS_ONSTACK 1
1525 #define SS_DISABLE 2
1526 #if __GLIBC_MINOR__ == 0
1536 #define stack_t struct sigaltstack
1539 static const struct xlat sigaltstack_flags[] = {
1540 { SS_ONSTACK, "SS_ONSTACK" },
1541 { SS_DISABLE, "SS_DISABLE" },
1548 printcontext(tcp, ucp)
1554 tprintf("uc_flags=");
1555 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
1556 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1558 tprintf("uc_sigmask=");
1559 printsigmask(&ucp->uc_sigmask, 0);
1561 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1562 (unsigned long) ucp->uc_stack.ss_sp,
1563 ucp->uc_stack.ss_size);
1564 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
1578 tprintf("%#lx", tcp->u_arg[0]);
1579 else if (!tcp->u_arg[0])
1581 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1584 printcontext(tcp, &uc);
1595 if (entering(tcp)) {
1598 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1601 printcontext(tcp, &uc);
1604 tcp->u_rval = tcp->u_error = 0;
1605 if (tcp->u_arg[0] == 0)
1614 #if defined(LINUX) || defined(FREEBSD)
1617 print_stack_t(tcp, addr)
1622 if (umove(tcp, addr, &ss) < 0)
1624 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1625 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1626 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1631 sys_sigaltstack(tcp)
1634 if (entering(tcp)) {
1635 if (tcp->u_arg[0] == 0)
1637 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1642 if (tcp->u_arg[1] == 0)
1644 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1651 #ifdef HAVE_SIGACTION
1654 sys_sigprocmask(tcp)
1658 if (entering(tcp)) {
1659 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1661 printsigmask(tcp->u_arg[1], 0);
1663 else if (!syserror(tcp)) {
1664 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
1665 return RVAL_HEX | RVAL_STR;
1668 if (entering(tcp)) {
1670 if (tcp->u_arg[0] == 0)
1674 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1676 print_sigset(tcp, tcp->u_arg[1], 0);
1682 else if (syserror(tcp))
1683 tprintf("%#lx", tcp->u_arg[2]);
1685 print_sigset(tcp, tcp->u_arg[2], 0);
1691 #endif /* HAVE_SIGACTION */
1697 if (entering(tcp)) {
1698 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
1707 return sys_kill(tcp);
1715 if (entering(tcp)) {
1716 tprintf("%ld, %ld, %s",
1717 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1731 tprintf("%#lx", tcp->u_arg[0]);
1732 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1735 printsigmask(&sigset, 0);
1740 int sys_sigwait(tcp)
1745 if (entering(tcp)) {
1746 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1749 printsigmask(&sigset, 0);
1752 if (!syserror(tcp)) {
1753 tcp->auxstr = signalent[tcp->u_rval];
1754 return RVAL_DECIMAL | RVAL_STR;
1763 sys_rt_sigprocmask(tcp)
1768 /* Note: arg[3] is the length of the sigset. */
1769 if (entering(tcp)) {
1770 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1774 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
1775 tprintf("%#lx, ", tcp->u_arg[1]);
1777 printsigmask(&sigset, 1);
1785 else if (syserror(tcp))
1786 tprintf("%#lx", tcp->u_arg[2]);
1787 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
1790 printsigmask(&sigset, 1);
1791 tprintf(", %lu", tcp->u_arg[3]);
1797 /* Structure describing the action to be taken when a signal arrives. */
1798 struct new_sigaction
1802 __sighandler_t __sa_handler;
1803 void (*__sa_sigaction) (int, siginfo_t *, void *);
1805 __sigaction_handler;
1806 unsigned long sa_flags;
1807 void (*sa_restorer) (void);
1808 unsigned long int sa_mask[2];
1813 sys_rt_sigaction(tcp)
1816 struct new_sigaction sa;
1820 if (entering(tcp)) {
1821 printsignal(tcp->u_arg[0]);
1823 addr = tcp->u_arg[1];
1825 addr = tcp->u_arg[2];
1828 else if (!verbose(tcp))
1829 tprintf("%#lx", addr);
1830 else if (umove(tcp, addr, &sa) < 0)
1833 switch ((long) sa.__sigaction_handler.__sa_handler) {
1834 case (long) SIG_ERR:
1835 tprintf("{SIG_ERR}");
1837 case (long) SIG_DFL:
1838 tprintf("{SIG_DFL}");
1840 case (long) SIG_IGN:
1841 tprintf("{SIG_IGN}");
1845 (long) sa.__sigaction_handler.__sa_handler);
1846 sigemptyset(&sigset);
1848 if (tcp->u_arg[4] <= sizeof(sigset))
1849 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1851 if (tcp->u_arg[3] <= sizeof(sigset))
1852 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1855 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1856 printsigmask(&sigset, 1);
1858 printflags(sigact_flags, sa.sa_flags, "SA_???");
1860 if (sa.sa_flags & SA_RESTORER)
1861 tprintf(", %p", sa.sa_restorer);
1870 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1871 #elif defined(ALPHA)
1872 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1874 tprintf(", %lu", addr = tcp->u_arg[3]);
1880 sys_rt_sigpending(tcp)
1887 tprintf("%#lx", tcp->u_arg[0]);
1888 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1889 &sigset, tcp->u_arg[1]) < 0)
1892 printsigmask(&sigset, 1);
1897 sys_rt_sigsuspend(tcp)
1900 if (entering(tcp)) {
1902 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1905 printsigmask(&sigm, 1);
1910 sys_rt_sigqueueinfo(tcp)
1913 if (entering(tcp)) {
1915 tprintf("%lu, ", tcp->u_arg[0]);
1916 printsignal(tcp->u_arg[1]);
1918 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1919 tprintf("%#lx", tcp->u_arg[2]);
1921 printsiginfo(&si, verbose (tcp));
1926 int sys_rt_sigtimedwait(tcp)
1929 if (entering(tcp)) {
1932 if (copy_sigset_len(tcp, tcp->u_arg[0],
1933 &sigset, tcp->u_arg[3]) < 0)
1936 printsigmask(&sigset, 1);
1941 tprintf("%#lx", tcp->u_arg[0]);
1944 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1945 tprintf("%#lx", tcp->u_arg[1]);
1947 printsiginfo(&si, verbose (tcp));
1949 tprintf(", %#lx", tcp->u_arg[2]);
1950 tprintf(", %d", (int) tcp->u_arg[3]);
1957 sys_restart_syscall(tcp)
1961 tprintf("<... resuming interrupted call ...>");