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)
102 struct pt_regs si_regs;
105 #elif defined HAVE_ASM_SIGCONTEXT_H
106 #if !defined(IA64) && !defined(X86_64)
107 #include <asm/sigcontext.h>
108 #endif /* !IA64 && !X86_64 */
109 #else /* !HAVE_ASM_SIGCONTEXT_H */
110 #if defined I386 && !defined HAVE_STRUCT_SIGCONTEXT_STRUCT
111 struct sigcontext_struct {
112 unsigned short gs, __gsh;
113 unsigned short fs, __fsh;
114 unsigned short es, __esh;
115 unsigned short ds, __dsh;
124 unsigned long trapno;
127 unsigned short cs, __csh;
128 unsigned long eflags;
129 unsigned long esp_at_signal;
130 unsigned short ss, __ssh;
132 unsigned long oldmask;
139 unsigned long sc_mask;
140 unsigned long sc_usp;
145 unsigned short sc_sr;
147 unsigned short sc_formatvec;
151 #endif /* !HAVE_ASM_SIGCONTEXT_H */
161 const char *const signalent0[] = {
162 #include "signalent.h"
164 const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
166 #if SUPPORTED_PERSONALITIES >= 2
167 const char *const signalent1[] = {
168 #include "signalent1.h"
170 const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
171 #endif /* SUPPORTED_PERSONALITIES >= 2 */
173 #if SUPPORTED_PERSONALITIES >= 3
174 const char *const signalent2[] = {
175 #include "signalent2.h"
177 const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
178 #endif /* SUPPORTED_PERSONALITIES >= 3 */
180 const char *const *signalent;
183 #if defined(SUNOS4) || defined(FREEBSD)
185 static const struct xlat sigvec_flags[] = {
186 { SV_ONSTACK, "SV_ONSTACK" },
187 { SV_INTERRUPT, "SV_INTERRUPT" },
188 { SV_RESETHAND, "SV_RESETHAND" },
189 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
193 #endif /* SUNOS4 || FREEBSD */
195 #ifdef HAVE_SIGACTION
197 #if defined LINUX && (defined I386 || defined X86_64)
198 /* The libc headers do not define this constant since it should only be
199 used by the implementation. So wwe define it here. */
201 # define SA_RESTORER 0x04000000
205 static const struct xlat sigact_flags[] = {
207 { SA_RESTORER, "SA_RESTORER" },
210 { SA_STACK, "SA_STACK" },
213 { SA_RESTART, "SA_RESTART" },
216 { SA_INTERRUPT, "SA_INTERRUPT" },
219 { SA_NODEFER, "SA_NODEFER" },
221 #if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
222 { SA_NOMASK, "SA_NOMASK" },
225 { SA_RESETHAND, "SA_RESETHAND" },
227 #if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
228 { SA_ONESHOT, "SA_ONESHOT" },
231 { SA_SIGINFO, "SA_SIGINFO" },
234 { SA_RESETHAND, "SA_RESETHAND" },
237 { SA_ONSTACK, "SA_ONSTACK" },
240 { SA_NODEFER, "SA_NODEFER" },
243 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
246 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
249 { _SA_BSDCALL, "_SA_BSDCALL" },
254 static const struct xlat sigprocmaskcmds[] = {
255 { SIG_BLOCK, "SIG_BLOCK" },
256 { SIG_UNBLOCK, "SIG_UNBLOCK" },
257 { SIG_SETMASK, "SIG_SETMASK" },
259 { SIG_SETMASK32,"SIG_SETMASK32" },
264 #endif /* HAVE_SIGACTION */
266 /* Anonymous realtime signals. */
267 /* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
268 constant. This is what we want. Otherwise, just use SIGRTMIN. */
271 #define __SIGRTMIN SIGRTMIN
272 #define __SIGRTMAX SIGRTMAX /* likewise */
281 if (sig >= 0 && sig < nsignals) {
282 return signalent[sig];
284 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
285 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
287 #endif /* SIGRTMIN */
289 sprintf(buf, "%d", sig);
306 copy_sigset_len(tcp, addr, s, len)
312 if (len > sizeof(*s))
315 if (umoven(tcp, addr, len, (char *)s) < 0)
321 /* Original sigset is unsigned long */
322 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
324 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
328 sprintsigmask(const char *str, sigset_t *mask, int rt)
329 /* set might include realtime sigs */
334 static char outstr[8 * sizeof(sigset_t) * 8];
337 s = outstr + strlen(outstr);
342 maxsigs = __SIGRTMAX; /* instead */
344 for (i = 1; i < maxsigs; i++) {
345 if (sigismember(mask, i) == 1)
348 if (nsigs >= nsignals * 2 / 3) {
350 for (i = 1; i < maxsigs; i++) {
351 switch (sigismember(mask, i)) {
363 for (i = 1; i < maxsigs; i++) {
364 if (sigismember(mask, i) == 1) {
365 /* real-time signals on solaris don't have
369 sprintf(s, format, signalent[i] + 3);
372 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
374 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
375 sprintf(s, format, tsig);
377 #endif /* SIGRTMIN */
380 sprintf(tsig, "%u", i);
381 sprintf(s, format, tsig);
393 printsigmask(mask, rt)
397 tprintf("%s", sprintsigmask("", mask, rt));
404 tprintf(signame(nr));
408 print_sigset(struct tcb *tcp, long addr, int rt)
414 else if (copy_sigset(tcp, addr, &ss) < 0)
415 tprintf("%#lx", addr);
417 printsigmask(&ss, rt);
423 #define ILL_ILLOPC 1 /* illegal opcode */
424 #define ILL_ILLOPN 2 /* illegal operand */
425 #define ILL_ILLADR 3 /* illegal addressing mode */
426 #define ILL_ILLTRP 4 /* illegal trap */
427 #define ILL_PRVOPC 5 /* privileged opcode */
428 #define ILL_PRVREG 6 /* privileged register */
429 #define ILL_COPROC 7 /* coprocessor error */
430 #define ILL_BADSTK 8 /* internal stack error */
431 #define FPE_INTDIV 1 /* integer divide by zero */
432 #define FPE_INTOVF 2 /* integer overflow */
433 #define FPE_FLTDIV 3 /* floating point divide by zero */
434 #define FPE_FLTOVF 4 /* floating point overflow */
435 #define FPE_FLTUND 5 /* floating point underflow */
436 #define FPE_FLTRES 6 /* floating point inexact result */
437 #define FPE_FLTINV 7 /* floating point invalid operation */
438 #define FPE_FLTSUB 8 /* subscript out of range */
439 #define SEGV_MAPERR 1 /* address not mapped to object */
440 #define SEGV_ACCERR 2 /* invalid permissions for mapped object */
441 #define BUS_ADRALN 1 /* invalid address alignment */
442 #define BUS_ADRERR 2 /* non-existant physical address */
443 #define BUS_OBJERR 3 /* object specific hardware error */
444 #define TRAP_BRKPT 1 /* process breakpoint */
445 #define TRAP_TRACE 2 /* process trace trap */
446 #define CLD_EXITED 1 /* child has exited */
447 #define CLD_KILLED 2 /* child was killed */
448 #define CLD_DUMPED 3 /* child terminated abnormally */
449 #define CLD_TRAPPED 4 /* traced child has trapped */
450 #define CLD_STOPPED 5 /* child has stopped */
451 #define CLD_CONTINUED 6 /* stopped child has continued */
452 #define POLL_IN 1 /* data input available */
453 #define POLL_OUT 2 /* output buffers available */
454 #define POLL_MSG 3 /* input message available */
455 #define POLL_ERR 4 /* i/o error */
456 #define POLL_PRI 5 /* high priority input available */
457 #define POLL_HUP 6 /* device disconnected */
458 #define SI_USER 0 /* sent by kill, sigsend, raise */
459 #define SI_QUEUE -1 /* sent by sigqueue */
460 #define SI_TIMER -2 /* sent by timer expiration */
461 #define SI_MESGQ -3 /* sent by real time mesq state change */
462 #define SI_ASYNCIO -4 /* sent by AIO completion */
463 #define SI_SIGIO -5 /* Sent by SIGIO */
464 #define SI_TKILL -6 /* Sent by tkill */
467 #if __GLIBC_MINOR__ < 1
468 /* Type for data associated with a signal. */
475 # define __SI_MAX_SIZE 128
476 # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
478 typedef struct siginfo
480 int si_signo; /* Signal number. */
481 int si_errno; /* If non-zero, an errno value associated with
482 this signal, as defined in <errno.h>. */
483 int si_code; /* Signal code. */
487 int _pad[__SI_PAD_SIZE];
492 __pid_t si_pid; /* Sending process ID. */
493 __uid_t si_uid; /* Real user ID of sending process. */
496 /* POSIX.1b timers. */
499 unsigned int _timer1;
500 unsigned int _timer2;
503 /* POSIX.1b signals. */
506 __pid_t si_pid; /* Sending process ID. */
507 __uid_t si_uid; /* Real user ID of sending process. */
508 sigval_t si_sigval; /* Signal value. */
514 __pid_t si_pid; /* Which child. */
515 int si_status; /* Exit value or signal. */
520 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
523 void *si_addr; /* Faulting insn/memory ref. */
529 int si_band; /* Band event for SIGPOLL. */
535 #define si_pid _sifields._kill.si_pid
536 #define si_uid _sifields._kill.si_uid
537 #define si_status _sifields._sigchld.si_status
538 #define si_utime _sifields._sigchld.si_utime
539 #define si_stime _sifields._sigchld.si_stime
540 #define si_value _sifields._rt.si_sigval
541 #define si_int _sifields._rt.si_sigval.sival_int
542 #define si_ptr _sifields._rt.si_sigval.sival_ptr
543 #define si_addr _sifields._sigfault.si_addr
544 #define si_band _sifields._sigpoll.si_band
545 #define si_fd _sifields._sigpoll.si_fd
551 #if defined (SVR4) || defined (LINUX)
553 static const struct xlat siginfo_codes[] = {
555 { SI_NOINFO, "SI_NOINFO" },
558 { SI_USER, "SI_USER" },
561 { SI_LWP, "SI_LWP" },
564 { SI_QUEUE, "SI_QUEUE" },
567 { SI_TIMER, "SI_TIMER" },
570 { SI_ASYNCIO, "SI_ASYNCIO" },
573 { SI_MESGQ, "SI_MESGQ" },
576 { SI_SIGIO, "SI_SIGIO" },
579 { SI_TKILL, "SI_TKILL" },
584 static const struct xlat sigill_codes[] = {
585 { ILL_ILLOPC, "ILL_ILLOPC" },
586 { ILL_ILLOPN, "ILL_ILLOPN" },
587 { ILL_ILLADR, "ILL_ILLADR" },
588 { ILL_ILLTRP, "ILL_ILLTRP" },
589 { ILL_PRVOPC, "ILL_PRVOPC" },
590 { ILL_PRVREG, "ILL_PRVREG" },
591 { ILL_COPROC, "ILL_COPROC" },
592 { ILL_BADSTK, "ILL_BADSTK" },
596 static const struct xlat sigfpe_codes[] = {
597 { FPE_INTDIV, "FPE_INTDIV" },
598 { FPE_INTOVF, "FPE_INTOVF" },
599 { FPE_FLTDIV, "FPE_FLTDIV" },
600 { FPE_FLTOVF, "FPE_FLTOVF" },
601 { FPE_FLTUND, "FPE_FLTUND" },
602 { FPE_FLTRES, "FPE_FLTRES" },
603 { FPE_FLTINV, "FPE_FLTINV" },
604 { FPE_FLTSUB, "FPE_FLTSUB" },
608 static const struct xlat sigtrap_codes[] = {
609 { TRAP_BRKPT, "TRAP_BRKPT" },
610 { TRAP_TRACE, "TRAP_TRACE" },
614 static const struct xlat sigchld_codes[] = {
615 { CLD_EXITED, "CLD_EXITED" },
616 { CLD_KILLED, "CLD_KILLED" },
617 { CLD_DUMPED, "CLD_DUMPED" },
618 { CLD_TRAPPED, "CLD_TRAPPED" },
619 { CLD_STOPPED, "CLD_STOPPED" },
620 { CLD_CONTINUED,"CLD_CONTINUED" },
624 static const struct xlat sigpoll_codes[] = {
625 { POLL_IN, "POLL_IN" },
626 { POLL_OUT, "POLL_OUT" },
627 { POLL_MSG, "POLL_MSG" },
628 { POLL_ERR, "POLL_ERR" },
629 { POLL_PRI, "POLL_PRI" },
630 { POLL_HUP, "POLL_HUP" },
634 static const struct xlat sigprof_codes[] = {
636 { PROF_SIG, "PROF_SIG" },
642 static const struct xlat sigemt_codes[] = {
644 { EMT_TAGOVF, "EMT_TAGOVF" },
650 static const struct xlat sigsegv_codes[] = {
651 { SEGV_MAPERR, "SEGV_MAPERR" },
652 { SEGV_ACCERR, "SEGV_ACCERR" },
656 static const struct xlat sigbus_codes[] = {
657 { BUS_ADRALN, "BUS_ADRALN" },
658 { BUS_ADRERR, "BUS_ADRERR" },
659 { BUS_OBJERR, "BUS_OBJERR" },
664 printsiginfo(sip, verbose)
670 if (sip->si_signo == 0) {
674 tprintf("{si_signo=");
675 printsignal(sip->si_signo);
676 code = xlookup(siginfo_codes, sip->si_code);
678 switch (sip->si_signo) {
680 code = xlookup(sigtrap_codes, sip->si_code);
683 code = xlookup(sigchld_codes, sip->si_code);
686 code = xlookup(sigpoll_codes, sip->si_code);
689 code = xlookup(sigprof_codes, sip->si_code);
692 code = xlookup(sigill_codes, sip->si_code);
696 code = xlookup(sigemt_codes, sip->si_code);
700 code = xlookup(sigfpe_codes, sip->si_code);
703 code = xlookup(sigsegv_codes, sip->si_code);
706 code = xlookup(sigbus_codes, sip->si_code);
711 tprintf(", si_code=%s", code);
713 tprintf(", si_code=%#x", sip->si_code);
715 if (sip->si_code != SI_NOINFO)
719 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
720 tprintf(", si_errno=%d", sip->si_errno);
722 tprintf(", si_errno=%s",
723 errnoent[sip->si_errno]);
726 if (SI_FROMUSER(sip)) {
727 tprintf(", si_pid=%ld, si_uid=%ld",
728 sip->si_pid, sip->si_uid);
730 switch (sip->si_code) {
734 #endif /* SI_QUEUE */
738 #endif /* SI_MESGQ */
739 tprintf(", si_value=%d",
740 sip->si_value.sival_int);
743 #endif /* SI_QUEUE */
746 #endif /* SI_FROMUSER */
748 switch (sip->si_signo) {
750 tprintf(", si_pid=%ld, si_status=",
752 if (sip->si_code == CLD_EXITED)
753 tprintf("%d", sip->si_status);
755 printsignal(sip->si_status);
760 tprintf(", si_utime=%lu, si_stime=%lu",
765 case SIGILL: case SIGFPE:
766 case SIGSEGV: case SIGBUS:
767 tprintf(", si_addr=%#lx",
768 (unsigned long) sip->si_addr);
771 switch (sip->si_code) {
772 case POLL_IN: case POLL_OUT: case POLL_MSG:
773 tprintf(", si_band=%ld",
774 (long) sip->si_band);
780 tprintf(", si_pid=%lu, si_uid=%lu, ",
781 (unsigned long) sip->si_pid,
782 (unsigned long) sip->si_uid);
786 tprintf("si_value={int=%u, ptr=%#lx}",
788 (unsigned long) sip->si_ptr);
798 #endif /* SVR4 || LINUX */
803 parse_sigset_t (const char *str, sigset_t *set)
811 p = strchr(str, '\n');
813 p = strchr(str, '\0');
814 for (i = 0; p-- > str; i += 4) {
815 if (*p >= '0' && *p <= '9')
817 else if (*p >= 'a' && *p <= 'f')
818 digit = *p - 'a' + 10;
819 else if (*p >= 'A' && *p <= 'F')
820 digit = *p - 'A' + 10;
824 sigaddset(set, i + 1);
826 sigaddset(set, i + 2);
828 sigaddset(set, i + 3);
830 sigaddset(set, i + 4);
837 * Check process TCP for the disposition of signal SIG.
838 * Return 1 if the process would somehow manage to survive signal SIG,
839 * else return 0. This routine will never be called with SIGKILL.
842 sigishandled(tcp, sig)
852 sigset_t ignored, caught;
856 * Since procfs doesn't interfere with wait I think it is safe
857 * to punt on this question. If not, the information is there.
869 #if defined(SIGURG) && SIGURG != SIGIO
873 /* Gloria Gaynor says ... */
881 /* This is incredibly costly but it's worth it. */
882 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
883 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
884 doesn't handle real-time signals). */
885 sprintf(sname, "/proc/%d/status", tcp->pid);
886 if ((sfd = open(sname, O_RDONLY)) == -1) {
890 i = read(sfd, buf, sizeof(buf));
894 * Skip the extraneous fields. We need to skip
895 * command name has any spaces in it. So be it.
897 s = strstr(buf, "SigIgn:\t");
900 fprintf(stderr, "/proc/pid/status format error\n");
903 parse_sigset_t(s + 8, &ignored);
905 s = strstr(buf, "SigCgt:\t");
908 fprintf(stderr, "/proc/pid/status format error\n");
911 parse_sigset_t(s + 8, &caught);
914 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
915 *(long long *) &ignored, *(long long *) &caught, sig);
917 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
924 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
925 (long *) &u_signal) < 0) {
928 if (u_signal != SIG_DFL)
935 #if defined(SUNOS4) || defined(FREEBSD)
945 printsignal(tcp->u_arg[0]);
947 addr = tcp->u_arg[1];
949 addr = tcp->u_arg[2];
953 else if (!verbose(tcp))
954 tprintf("%#lx", addr);
955 else if (umove(tcp, addr, &sv) < 0)
958 switch ((int) sv.sv_handler) {
960 tprintf("{SIG_ERR}");
963 tprintf("{SIG_DFL}");
966 if (tcp->u_arg[0] == SIGTRAP) {
967 tcp->flags |= TCB_SIGTRAPPED;
968 kill(tcp->pid, SIGSTOP);
970 tprintf("{SIG_IGN}");
973 if (tcp->u_arg[0] == SIGTRAP) {
974 tcp->flags |= TCB_SIGTRAPPED;
975 kill(tcp->pid, SIGSTOP);
980 if (tcp->u_arg[0] == SIGTRAP) {
981 tcp->flags |= TCB_SIGTRAPPED;
982 kill(tcp->pid, SIGSTOP);
984 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
985 printsigmask(&sv.sv_mask, 0);
987 printflags(sigvec_flags, sv.sv_flags, "SV_???");
1000 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
1002 long_to_sigset(tcp->u_arg[0], &sigm);
1003 printsigmask(&sigm, 0);
1016 addr = tcp->u_arg[0];
1018 addr = tcp->u_arg[1];
1021 else if (umove(tcp, addr, &ss) < 0)
1022 tprintf("%#lx", addr);
1024 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1025 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1039 #endif /* SUNOS4 || FREEBSD */
1047 if (entering(tcp)) {
1049 long_to_sigset(tcp->u_arg[0], &sigm);
1050 printsigmask(&sigm, 0);
1052 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1053 /* Mark attempt to block SIGTRAP */
1054 tcp->flags |= TCB_SIGTRAPPED;
1055 /* Send unblockable signal */
1056 kill(tcp->pid, SIGSTOP);
1058 #endif /* !USE_PROCFS */
1060 else if (!syserror(tcp)) {
1062 long_to_sigset(tcp->u_rval, &sigm);
1063 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
1065 return RVAL_HEX | RVAL_STR;
1070 #if defined(SUNOS4) || defined(FREEBSD)
1075 return sys_sigsetmask(tcp);
1077 #endif /* SUNOS4 || FREEBSD */
1081 #ifdef HAVE_SIGACTION
1084 struct old_sigaction {
1085 __sighandler_t __sa_handler;
1086 unsigned long sa_mask;
1087 unsigned long sa_flags;
1088 void (*sa_restorer)(void);
1090 #define SA_HANDLER __sa_handler
1094 #define SA_HANDLER sa_handler
1104 struct old_sigaction sa;
1106 struct sigaction sa;
1110 if (entering(tcp)) {
1111 printsignal(tcp->u_arg[0]);
1113 addr = tcp->u_arg[1];
1115 addr = tcp->u_arg[2];
1118 else if (!verbose(tcp))
1119 tprintf("%#lx", addr);
1120 else if (umove(tcp, addr, &sa) < 0)
1123 if (sa.SA_HANDLER == SIG_ERR)
1124 tprintf("{SIG_ERR, ");
1125 else if (sa.SA_HANDLER == SIG_DFL)
1126 tprintf("{SIG_DFL, ");
1127 else if (sa.SA_HANDLER == SIG_DFL) {
1129 if (tcp->u_arg[0] == SIGTRAP) {
1130 tcp->flags |= TCB_SIGTRAPPED;
1131 kill(tcp->pid, SIGSTOP);
1133 #endif /* !USE_PROCFS */
1134 tprintf("{SIG_IGN, ");
1138 if (tcp->u_arg[0] == SIGTRAP) {
1139 tcp->flags |= TCB_SIGTRAPPED;
1140 kill(tcp->pid, SIGSTOP);
1142 #endif /* !USE_PROCFS */
1143 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
1145 printsigmask (&sa.sa_mask, 0);
1147 long_to_sigset(sa.sa_mask, &sigset);
1148 printsigmask(&sigset, 0);
1151 printflags(sigact_flags, sa.sa_flags, "SA_???");
1153 if (sa.sa_flags & SA_RESTORER)
1154 tprintf(", %p", sa.sa_restorer);
1163 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1172 if (entering(tcp)) {
1173 printsignal(tcp->u_arg[0]);
1175 switch (tcp->u_arg[1]) {
1176 case (long) SIG_ERR:
1179 case (long) SIG_DFL:
1182 case (long) SIG_IGN:
1184 if (tcp->u_arg[0] == SIGTRAP) {
1185 tcp->flags |= TCB_SIGTRAPPED;
1186 kill(tcp->pid, SIGSTOP);
1188 #endif /* !USE_PROCFS */
1193 if (tcp->u_arg[0] == SIGTRAP) {
1194 tcp->flags |= TCB_SIGTRAPPED;
1195 kill(tcp->pid, SIGSTOP);
1197 #endif /* !USE_PROCFS */
1198 tprintf("%#lx", tcp->u_arg[1]);
1202 else if (!syserror(tcp)) {
1203 switch (tcp->u_rval) {
1204 case (long) SIG_ERR:
1205 tcp->auxstr = "SIG_ERR"; break;
1206 case (long) SIG_DFL:
1207 tcp->auxstr = "SIG_DFL"; break;
1208 case (long) SIG_IGN:
1209 tcp->auxstr = "SIG_IGN"; break;
1213 return RVAL_HEX | RVAL_STR;
1223 if (entering(tcp)) {
1224 printsignal(tcp->u_arg[0]);
1230 #endif /* HAVE_SIGACTION */
1239 struct pt_regs regs;
1240 struct sigcontext_struct sc;
1242 if (entering(tcp)) {
1245 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)®s) == -1)
1248 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1252 tcp->u_arg[1] = sc.oldmask;
1255 long_to_sigset(tcp->u_arg[1], &sigm);
1256 tcp->u_rval = tcp->u_error = 0;
1257 if (tcp->u_arg[0] == 0)
1259 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1260 return RVAL_NONE | RVAL_STR;
1263 #elif defined(S390) || defined(S390X)
1265 struct sigcontext_struct sc;
1267 if (entering(tcp)) {
1269 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1271 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1274 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1276 tcp->u_rval = tcp->u_error = 0;
1277 if (tcp->u_arg[0] == 0)
1279 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1280 return RVAL_NONE | RVAL_STR;
1286 struct sigcontext_struct sc;
1288 if (entering(tcp)) {
1290 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1292 if (umove(tcp, esp, &sc) < 0)
1295 tcp->u_arg[1] = sc.oldmask;
1299 long_to_sigset(tcp->u_arg[1], &sigm);
1300 tcp->u_rval = tcp->u_error = 0;
1301 if (tcp->u_arg[0] == 0)
1303 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1304 return RVAL_NONE | RVAL_STR;
1309 struct sigcontext sc;
1312 if (entering(tcp)) {
1313 /* offset of sigcontext in the kernel's sigframe structure: */
1314 # define SIGFRAME_SC_OFFSET 0x90
1316 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1318 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
1321 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
1326 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
1327 tcp->u_rval = tcp->u_error = 0;
1328 if (tcp->u_arg[0] == 0)
1330 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1331 return RVAL_NONE | RVAL_STR;
1337 struct sigcontext_struct sc;
1339 if (entering(tcp)) {
1341 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1343 if (umove(tcp, esp, &sc) < 0)
1346 tcp->u_arg[1] = sc.oldmask;
1350 long_to_sigset(tcp->u_arg[1], &sigm);
1351 tcp->u_rval = tcp->u_error = 0;
1352 if (tcp->u_arg[0] == 0)
1354 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1355 return RVAL_NONE | RVAL_STR;
1358 #else /* !POWERPC */
1361 struct sigcontext sc;
1363 if (entering(tcp)) {
1365 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
1367 if (umove(tcp, usp, &sc) < 0)
1370 tcp->u_arg[1] = sc.sc_mask;
1374 long_to_sigset(tcp->u_arg[1], &sigm);
1375 tcp->u_rval = tcp->u_error = 0;
1376 if (tcp->u_arg[0] == 0)
1378 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1379 return RVAL_NONE | RVAL_STR;
1385 struct sigcontext_struct sc;
1387 if (entering(tcp)) {
1389 if (upeek(tcp->pid, REG_FP, &fp) < 0)
1391 if (umove(tcp, fp, &sc) < 0)
1394 tcp->u_arg[1] = sc.sc_mask;
1398 long_to_sigset(tcp->u_arg[1], &sigm);
1399 tcp->u_rval = tcp->u_error = 0;
1400 if (tcp->u_arg[0] == 0)
1402 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1403 return RVAL_NONE | RVAL_STR;
1407 #if defined (SPARC) || defined (SPARC64)
1412 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
1413 perror("sigreturn: PTRACE_GETREGS ");
1419 if(umove(tcp, i1, &si) < 0) {
1420 perror("sigreturn: umove ");
1424 tcp->u_arg[1] = si.si_mask;
1427 long_to_sigset(tcp->u_arg[1], &sigm);
1428 tcp->u_rval = tcp->u_error = 0;
1429 if(tcp->u_arg[0] == 0)
1431 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1432 return RVAL_NONE | RVAL_STR;
1436 #if defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
1437 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1444 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1446 /* There are six words followed by a 128-byte siginfo. */
1447 sp = sp + 6 * 4 + 128;
1448 if (umove(tcp, sp, &uc) < 0)
1451 tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
1454 long_to_sigset(tcp->u_arg[1], &sigm);
1455 tcp->u_rval = tcp->u_error = 0;
1456 if(tcp->u_arg[0] == 0)
1458 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1459 return RVAL_NONE | RVAL_STR;
1465 struct pt_regs regs;
1468 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
1469 perror("sigreturn: PTRACE_GETREGS ");
1475 if (umove(tcp, sp, &si) < 0)
1477 tcp->u_arg[1] = si.si_mask;
1480 long_to_sigset(tcp->u_arg[1], &sigm);
1481 tcp->u_rval = tcp->u_error = 0;
1482 if(tcp->u_arg[0] == 0)
1484 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1485 return RVAL_NONE | RVAL_STR;
1489 #warning No sys_sigreturn() for this architecture
1490 #warning (no problem, just a reminder :-)
1493 #endif /* LINUX_MIPSN32 || LINUX_MIPSN64 */
1494 #endif /* SPARC || SPARC64 */
1497 #endif /* !POWERPC */
1509 long_to_sigset(tcp->u_rval, &sigm);
1510 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
1512 return RVAL_HEX | RVAL_STR;
1519 if (entering(tcp)) {
1521 long_to_sigset(tcp->u_arg[2], &sigm);
1523 /* first two are not really arguments, but print them anyway */
1524 /* nevermind, they are an anachronism now, too bad... */
1525 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1527 printsigmask(&sigm, 0);
1534 #if defined(SVR4) || defined(FREEBSD)
1542 if (entering(tcp)) {
1543 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1546 printsigmask(&sigset, 0);
1551 static const struct xlat ucontext_flags[] = {
1552 { UC_SIGMASK, "UC_SIGMASK" },
1553 { UC_STACK, "UC_STACK" },
1554 { UC_CPU, "UC_CPU" },
1556 { UC_FPU, "UC_FPU" },
1559 { UC_INTR, "UC_INTR" },
1563 #endif /* !FREEBSD */
1564 #endif /* SVR4 || FREEBSD */
1566 #if defined SVR4 || defined LINUX || defined FREEBSD
1567 #if defined LINUX && !defined SS_ONSTACK
1568 #define SS_ONSTACK 1
1569 #define SS_DISABLE 2
1570 #if __GLIBC_MINOR__ == 0
1580 #define stack_t struct sigaltstack
1583 static const struct xlat sigaltstack_flags[] = {
1584 { SS_ONSTACK, "SS_ONSTACK" },
1585 { SS_DISABLE, "SS_DISABLE" },
1592 printcontext(tcp, ucp)
1598 tprintf("uc_flags=");
1599 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
1600 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1602 tprintf("uc_sigmask=");
1603 printsigmask(&ucp->uc_sigmask, 0);
1605 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1606 (unsigned long) ucp->uc_stack.ss_sp,
1607 ucp->uc_stack.ss_size);
1608 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
1622 tprintf("%#lx", tcp->u_arg[0]);
1623 else if (!tcp->u_arg[0])
1625 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1628 printcontext(tcp, &uc);
1639 if (entering(tcp)) {
1642 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1645 printcontext(tcp, &uc);
1648 tcp->u_rval = tcp->u_error = 0;
1649 if (tcp->u_arg[0] == 0)
1658 #if defined(LINUX) || defined(FREEBSD)
1661 print_stack_t(tcp, addr)
1666 if (umove(tcp, addr, &ss) < 0)
1668 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1669 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1670 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1675 sys_sigaltstack(tcp)
1678 if (entering(tcp)) {
1679 if (tcp->u_arg[0] == 0)
1681 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1686 if (tcp->u_arg[1] == 0)
1688 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1695 #ifdef HAVE_SIGACTION
1698 sys_sigprocmask(tcp)
1702 if (entering(tcp)) {
1703 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1705 printsigmask(tcp->u_arg[1], 0);
1707 else if (!syserror(tcp)) {
1708 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
1709 return RVAL_HEX | RVAL_STR;
1712 if (entering(tcp)) {
1714 if (tcp->u_arg[0] == 0)
1718 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1720 print_sigset(tcp, tcp->u_arg[1], 0);
1726 else if (syserror(tcp))
1727 tprintf("%#lx", tcp->u_arg[2]);
1729 print_sigset(tcp, tcp->u_arg[2], 0);
1735 #endif /* HAVE_SIGACTION */
1741 if (entering(tcp)) {
1743 * Sign-extend a 32-bit value when that's what it is.
1745 long pid = tcp->u_arg[0];
1746 if (personality_wordsize[current_personality] < sizeof pid)
1747 pid = (long) (int) pid;
1748 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
1753 #if defined(FREEBSD) || defined(SUNOS4)
1758 return sys_kill(tcp);
1760 #endif /* FREEBSD || SUNOS4 */
1767 if (entering(tcp)) {
1768 tprintf("%ld, %ld, %s",
1769 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1783 tprintf("%#lx", tcp->u_arg[0]);
1784 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1787 printsigmask(&sigset, 0);
1793 int sys_sigwait(tcp)
1798 if (entering(tcp)) {
1799 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1802 printsigmask(&sigset, 0);
1805 if (!syserror(tcp)) {
1806 tcp->auxstr = signalent[tcp->u_rval];
1807 return RVAL_DECIMAL | RVAL_STR;
1817 sys_rt_sigprocmask(tcp)
1822 /* Note: arg[3] is the length of the sigset. */
1823 if (entering(tcp)) {
1824 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1828 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
1829 tprintf("%#lx, ", tcp->u_arg[1]);
1831 printsigmask(&sigset, 1);
1839 else if (syserror(tcp))
1840 tprintf("%#lx", tcp->u_arg[2]);
1841 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
1844 printsigmask(&sigset, 1);
1845 tprintf(", %lu", tcp->u_arg[3]);
1851 /* Structure describing the action to be taken when a signal arrives. */
1852 struct new_sigaction
1856 __sighandler_t __sa_handler;
1857 void (*__sa_sigaction) (int, siginfo_t *, void *);
1859 __sigaction_handler;
1860 unsigned long sa_flags;
1861 void (*sa_restorer) (void);
1862 unsigned long int sa_mask[2];
1867 sys_rt_sigaction(tcp)
1870 struct new_sigaction sa;
1874 if (entering(tcp)) {
1875 printsignal(tcp->u_arg[0]);
1877 addr = tcp->u_arg[1];
1879 addr = tcp->u_arg[2];
1882 else if (!verbose(tcp))
1883 tprintf("%#lx", addr);
1884 else if (umove(tcp, addr, &sa) < 0)
1887 if (sa.__sigaction_handler.__sa_handler == SIG_ERR)
1888 tprintf("{SIG_ERR, ");
1889 else if (sa.__sigaction_handler.__sa_handler == SIG_DFL)
1890 tprintf("{SIG_DFL, ");
1891 else if (sa.__sigaction_handler.__sa_handler == SIG_DFL)
1892 tprintf("{SIG_IGN, ");
1895 (long) sa.__sigaction_handler.__sa_handler);
1896 sigemptyset(&sigset);
1898 if (tcp->u_arg[4] <= sizeof(sigset))
1899 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1901 if (tcp->u_arg[3] <= sizeof(sigset))
1902 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1905 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1906 printsigmask(&sigset, 1);
1908 printflags(sigact_flags, sa.sa_flags, "SA_???");
1910 if (sa.sa_flags & SA_RESTORER)
1911 tprintf(", %p", sa.sa_restorer);
1919 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1920 #elif defined(ALPHA)
1921 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1923 tprintf(", %lu", addr = tcp->u_arg[3]);
1929 sys_rt_sigpending(tcp)
1936 tprintf("%#lx", tcp->u_arg[0]);
1937 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1938 &sigset, tcp->u_arg[1]) < 0)
1941 printsigmask(&sigset, 1);
1946 sys_rt_sigsuspend(tcp)
1949 if (entering(tcp)) {
1951 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1954 printsigmask(&sigm, 1);
1959 sys_rt_sigqueueinfo(tcp)
1962 if (entering(tcp)) {
1964 tprintf("%lu, ", tcp->u_arg[0]);
1965 printsignal(tcp->u_arg[1]);
1967 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1968 tprintf("%#lx", tcp->u_arg[2]);
1970 printsiginfo(&si, verbose (tcp));
1975 int sys_rt_sigtimedwait(tcp)
1978 if (entering(tcp)) {
1981 if (copy_sigset_len(tcp, tcp->u_arg[0],
1982 &sigset, tcp->u_arg[3]) < 0)
1985 printsigmask(&sigset, 1);
1990 tprintf("%#lx", tcp->u_arg[0]);
1993 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1994 tprintf("%#lx", tcp->u_arg[1]);
1996 printsiginfo(&si, verbose (tcp));
1998 tprintf(", %#lx", tcp->u_arg[2]);
1999 tprintf(", %d", (int) tcp->u_arg[3]);
2006 sys_restart_syscall(tcp)
2010 tprintf("<... resuming interrupted call ...>");
2014 extern const struct xlat open_mode_flags[];
2017 do_signalfd(struct tcb *tcp, int flags_arg)
2019 if (entering(tcp)) {
2020 tprintf("%ld, ", tcp->u_arg[0]);
2021 print_sigset(tcp, tcp->u_arg[1], 1);
2022 tprintf("%lu", tcp->u_arg[2]);
2023 if (flags_arg >= 0) {
2025 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
2032 sys_signalfd(struct tcb *tcp)
2034 return do_signalfd(tcp, -1);
2038 sys_signalfd4(struct tcb *tcp)
2040 return do_signalfd(tcp, 3);