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));
401 #define ILL_ILLOPC 1 /* illegal opcode */
402 #define ILL_ILLOPN 2 /* illegal operand */
403 #define ILL_ILLADR 3 /* illegal addressing mode */
404 #define ILL_ILLTRP 4 /* illegal trap */
405 #define ILL_PRVOPC 5 /* privileged opcode */
406 #define ILL_PRVREG 6 /* privileged register */
407 #define ILL_COPROC 7 /* coprocessor error */
408 #define ILL_BADSTK 8 /* internal stack error */
409 #define FPE_INTDIV 1 /* integer divide by zero */
410 #define FPE_INTOVF 2 /* integer overflow */
411 #define FPE_FLTDIV 3 /* floating point divide by zero */
412 #define FPE_FLTOVF 4 /* floating point overflow */
413 #define FPE_FLTUND 5 /* floating point underflow */
414 #define FPE_FLTRES 6 /* floating point inexact result */
415 #define FPE_FLTINV 7 /* floating point invalid operation */
416 #define FPE_FLTSUB 8 /* subscript out of range */
417 #define SEGV_MAPERR 1 /* address not mapped to object */
418 #define SEGV_ACCERR 2 /* invalid permissions for mapped object */
419 #define BUS_ADRALN 1 /* invalid address alignment */
420 #define BUS_ADRERR 2 /* non-existant physical address */
421 #define BUS_OBJERR 3 /* object specific hardware error */
422 #define TRAP_BRKPT 1 /* process breakpoint */
423 #define TRAP_TRACE 2 /* process trace trap */
424 #define CLD_EXITED 1 /* child has exited */
425 #define CLD_KILLED 2 /* child was killed */
426 #define CLD_DUMPED 3 /* child terminated abnormally */
427 #define CLD_TRAPPED 4 /* traced child has trapped */
428 #define CLD_STOPPED 5 /* child has stopped */
429 #define CLD_CONTINUED 6 /* stopped child has continued */
430 #define POLL_IN 1 /* data input available */
431 #define POLL_OUT 2 /* output buffers available */
432 #define POLL_MSG 3 /* input message available */
433 #define POLL_ERR 4 /* i/o error */
434 #define POLL_PRI 5 /* high priority input available */
435 #define POLL_HUP 6 /* device disconnected */
436 #define SI_USER 0 /* sent by kill, sigsend, raise */
437 #define SI_QUEUE -1 /* sent by sigqueue */
438 #define SI_TIMER -2 /* sent by timer expiration */
439 #define SI_MESGQ -3 /* sent by real time mesq state change */
440 #define SI_ASYNCIO -4 /* sent by AIO completion */
441 #define SI_SIGIO -5 /* Sent by SIGIO */
442 #define SI_TKILL -6 /* Sent by tkill */
445 #if __GLIBC_MINOR__ < 1
446 /* Type for data associated with a signal. */
453 # define __SI_MAX_SIZE 128
454 # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
456 typedef struct siginfo
458 int si_signo; /* Signal number. */
459 int si_errno; /* If non-zero, an errno value associated with
460 this signal, as defined in <errno.h>. */
461 int si_code; /* Signal code. */
465 int _pad[__SI_PAD_SIZE];
470 __pid_t si_pid; /* Sending process ID. */
471 __uid_t si_uid; /* Real user ID of sending process. */
474 /* POSIX.1b timers. */
477 unsigned int _timer1;
478 unsigned int _timer2;
481 /* POSIX.1b signals. */
484 __pid_t si_pid; /* Sending process ID. */
485 __uid_t si_uid; /* Real user ID of sending process. */
486 sigval_t si_sigval; /* Signal value. */
492 __pid_t si_pid; /* Which child. */
493 int si_status; /* Exit value or signal. */
498 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
501 void *si_addr; /* Faulting insn/memory ref. */
507 int si_band; /* Band event for SIGPOLL. */
513 #define si_pid _sifields._kill.si_pid
514 #define si_uid _sifields._kill.si_uid
515 #define si_status _sifields._sigchld.si_status
516 #define si_utime _sifields._sigchld.si_utime
517 #define si_stime _sifields._sigchld.si_stime
518 #define si_value _sifields._rt.si_sigval
519 #define si_int _sifields._rt.si_sigval.sival_int
520 #define si_ptr _sifields._rt.si_sigval.sival_ptr
521 #define si_addr _sifields._sigfault.si_addr
522 #define si_band _sifields._sigpoll.si_band
523 #define si_fd _sifields._sigpoll.si_fd
529 #if defined (SVR4) || defined (LINUX)
531 static const struct xlat siginfo_codes[] = {
533 { SI_NOINFO, "SI_NOINFO" },
536 { SI_USER, "SI_USER" },
539 { SI_LWP, "SI_LWP" },
542 { SI_QUEUE, "SI_QUEUE" },
545 { SI_TIMER, "SI_TIMER" },
548 { SI_ASYNCIO, "SI_ASYNCIO" },
551 { SI_MESGQ, "SI_MESGQ" },
554 { SI_SIGIO, "SI_SIGIO" },
557 { SI_TKILL, "SI_TKILL" },
562 static const struct xlat sigill_codes[] = {
563 { ILL_ILLOPC, "ILL_ILLOPC" },
564 { ILL_ILLOPN, "ILL_ILLOPN" },
565 { ILL_ILLADR, "ILL_ILLADR" },
566 { ILL_ILLTRP, "ILL_ILLTRP" },
567 { ILL_PRVOPC, "ILL_PRVOPC" },
568 { ILL_PRVREG, "ILL_PRVREG" },
569 { ILL_COPROC, "ILL_COPROC" },
570 { ILL_BADSTK, "ILL_BADSTK" },
574 static const struct xlat sigfpe_codes[] = {
575 { FPE_INTDIV, "FPE_INTDIV" },
576 { FPE_INTOVF, "FPE_INTOVF" },
577 { FPE_FLTDIV, "FPE_FLTDIV" },
578 { FPE_FLTOVF, "FPE_FLTOVF" },
579 { FPE_FLTUND, "FPE_FLTUND" },
580 { FPE_FLTRES, "FPE_FLTRES" },
581 { FPE_FLTINV, "FPE_FLTINV" },
582 { FPE_FLTSUB, "FPE_FLTSUB" },
586 static const struct xlat sigtrap_codes[] = {
587 { TRAP_BRKPT, "TRAP_BRKPT" },
588 { TRAP_TRACE, "TRAP_TRACE" },
592 static const struct xlat sigchld_codes[] = {
593 { CLD_EXITED, "CLD_EXITED" },
594 { CLD_KILLED, "CLD_KILLED" },
595 { CLD_DUMPED, "CLD_DUMPED" },
596 { CLD_TRAPPED, "CLD_TRAPPED" },
597 { CLD_STOPPED, "CLD_STOPPED" },
598 { CLD_CONTINUED,"CLD_CONTINUED" },
602 static const struct xlat sigpoll_codes[] = {
603 { POLL_IN, "POLL_IN" },
604 { POLL_OUT, "POLL_OUT" },
605 { POLL_MSG, "POLL_MSG" },
606 { POLL_ERR, "POLL_ERR" },
607 { POLL_PRI, "POLL_PRI" },
608 { POLL_HUP, "POLL_HUP" },
612 static const struct xlat sigprof_codes[] = {
614 { PROF_SIG, "PROF_SIG" },
620 static const struct xlat sigemt_codes[] = {
622 { EMT_TAGOVF, "EMT_TAGOVF" },
628 static const struct xlat sigsegv_codes[] = {
629 { SEGV_MAPERR, "SEGV_MAPERR" },
630 { SEGV_ACCERR, "SEGV_ACCERR" },
634 static const struct xlat sigbus_codes[] = {
635 { BUS_ADRALN, "BUS_ADRALN" },
636 { BUS_ADRERR, "BUS_ADRERR" },
637 { BUS_OBJERR, "BUS_OBJERR" },
642 printsiginfo(sip, verbose)
648 if (sip->si_signo == 0) {
652 tprintf("{si_signo=");
653 printsignal(sip->si_signo);
654 code = xlookup(siginfo_codes, sip->si_code);
656 switch (sip->si_signo) {
658 code = xlookup(sigtrap_codes, sip->si_code);
661 code = xlookup(sigchld_codes, sip->si_code);
664 code = xlookup(sigpoll_codes, sip->si_code);
667 code = xlookup(sigprof_codes, sip->si_code);
670 code = xlookup(sigill_codes, sip->si_code);
674 code = xlookup(sigemt_codes, sip->si_code);
678 code = xlookup(sigfpe_codes, sip->si_code);
681 code = xlookup(sigsegv_codes, sip->si_code);
684 code = xlookup(sigbus_codes, sip->si_code);
689 tprintf(", si_code=%s", code);
691 tprintf(", si_code=%#x", sip->si_code);
693 if (sip->si_code != SI_NOINFO)
697 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
698 tprintf(", si_errno=%d", sip->si_errno);
700 tprintf(", si_errno=%s",
701 errnoent[sip->si_errno]);
704 if (SI_FROMUSER(sip)) {
705 tprintf(", si_pid=%ld, si_uid=%ld",
706 sip->si_pid, sip->si_uid);
708 switch (sip->si_code) {
712 #endif /* SI_QUEUE */
716 #endif /* SI_MESGQ */
717 tprintf(", si_value=%d",
718 sip->si_value.sival_int);
721 #endif /* SI_QUEUE */
724 #endif /* SI_FROMUSER */
726 switch (sip->si_signo) {
728 tprintf(", si_pid=%ld, si_status=",
730 if (sip->si_code == CLD_EXITED)
731 tprintf("%d", sip->si_status);
733 printsignal(sip->si_status);
738 tprintf(", si_utime=%lu, si_stime=%lu",
743 case SIGILL: case SIGFPE:
744 case SIGSEGV: case SIGBUS:
745 tprintf(", si_addr=%#lx",
746 (unsigned long) sip->si_addr);
749 switch (sip->si_code) {
750 case POLL_IN: case POLL_OUT: case POLL_MSG:
751 tprintf(", si_band=%ld",
752 (long) sip->si_band);
758 tprintf(", si_pid=%lu, si_uid=%lu, ",
759 (unsigned long) sip->si_pid,
760 (unsigned long) sip->si_uid);
764 tprintf("si_value={int=%u, ptr=%#lx}",
766 (unsigned long) sip->si_ptr);
776 #endif /* SVR4 || LINUX */
781 parse_sigset_t (const char *str, sigset_t *set)
789 p = strchr(str, '\n');
791 p = strchr(str, '\0');
792 for (i = 0; p-- > str; i += 4) {
793 if (*p >= '0' && *p <= '9')
795 else if (*p >= 'a' && *p <= 'f')
796 digit = *p - 'a' + 10;
797 else if (*p >= 'A' && *p <= 'F')
798 digit = *p - 'A' + 10;
802 sigaddset(set, i + 1);
804 sigaddset(set, i + 2);
806 sigaddset(set, i + 3);
808 sigaddset(set, i + 4);
815 * Check process TCP for the disposition of signal SIG.
816 * Return 1 if the process would somehow manage to survive signal SIG,
817 * else return 0. This routine will never be called with SIGKILL.
820 sigishandled(tcp, sig)
830 sigset_t ignored, caught;
834 * Since procfs doesn't interfere with wait I think it is safe
835 * to punt on this question. If not, the information is there.
847 #if defined(SIGURG) && SIGURG != SIGIO
851 /* Gloria Gaynor says ... */
859 /* This is incredibly costly but it's worth it. */
860 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
861 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
862 doesn't handle real-time signals). */
863 sprintf(sname, "/proc/%d/status", tcp->pid);
864 if ((sfd = open(sname, O_RDONLY)) == -1) {
868 i = read(sfd, buf, sizeof(buf));
872 * Skip the extraneous fields. We need to skip
873 * command name has any spaces in it. So be it.
875 s = strstr(buf, "SigIgn:\t");
878 fprintf(stderr, "/proc/pid/status format error\n");
881 parse_sigset_t(s + 8, &ignored);
883 s = strstr(buf, "SigCgt:\t");
886 fprintf(stderr, "/proc/pid/status format error\n");
889 parse_sigset_t(s + 8, &caught);
892 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
893 *(long long *) &ignored, *(long long *) &caught, sig);
895 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
902 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
903 (long *) &u_signal) < 0) {
906 if (u_signal != SIG_DFL)
913 #if defined(SUNOS4) || defined(FREEBSD)
923 printsignal(tcp->u_arg[0]);
925 addr = tcp->u_arg[1];
927 addr = tcp->u_arg[2];
931 else if (!verbose(tcp))
932 tprintf("%#lx", addr);
933 else if (umove(tcp, addr, &sv) < 0)
936 switch ((int) sv.sv_handler) {
938 tprintf("{SIG_ERR}");
941 tprintf("{SIG_DFL}");
944 if (tcp->u_arg[0] == SIGTRAP) {
945 tcp->flags |= TCB_SIGTRAPPED;
946 kill(tcp->pid, SIGSTOP);
948 tprintf("{SIG_IGN}");
951 if (tcp->u_arg[0] == SIGTRAP) {
952 tcp->flags |= TCB_SIGTRAPPED;
953 kill(tcp->pid, SIGSTOP);
958 if (tcp->u_arg[0] == SIGTRAP) {
959 tcp->flags |= TCB_SIGTRAPPED;
960 kill(tcp->pid, SIGSTOP);
962 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
963 printsigmask(&sv.sv_mask, 0);
965 printflags(sigvec_flags, sv.sv_flags, "SV_???");
978 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
980 long_to_sigset(tcp->u_arg[0], &sigm);
981 printsigmask(&sigm, 0);
994 addr = tcp->u_arg[0];
996 addr = tcp->u_arg[1];
999 else if (umove(tcp, addr, &ss) < 0)
1000 tprintf("%#lx", addr);
1002 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1003 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1017 #endif /* SUNOS4 || FREEBSD */
1025 if (entering(tcp)) {
1027 long_to_sigset(tcp->u_arg[0], &sigm);
1028 printsigmask(&sigm, 0);
1030 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1031 /* Mark attempt to block SIGTRAP */
1032 tcp->flags |= TCB_SIGTRAPPED;
1033 /* Send unblockable signal */
1034 kill(tcp->pid, SIGSTOP);
1036 #endif /* !USE_PROCFS */
1038 else if (!syserror(tcp)) {
1040 long_to_sigset(tcp->u_rval, &sigm);
1041 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
1043 return RVAL_HEX | RVAL_STR;
1052 return sys_sigsetmask(tcp);
1057 #ifdef HAVE_SIGACTION
1060 struct old_sigaction {
1061 __sighandler_t __sa_handler;
1062 unsigned long sa_mask;
1063 unsigned long sa_flags;
1064 void (*sa_restorer)(void);
1066 #define SA_HANDLER __sa_handler
1070 #define SA_HANDLER sa_handler
1080 struct old_sigaction sa;
1082 struct sigaction sa;
1086 if (entering(tcp)) {
1087 printsignal(tcp->u_arg[0]);
1089 addr = tcp->u_arg[1];
1091 addr = tcp->u_arg[2];
1094 else if (!verbose(tcp))
1095 tprintf("%#lx", addr);
1096 else if (umove(tcp, addr, &sa) < 0)
1099 switch ((long) sa.SA_HANDLER) {
1100 case (long) SIG_ERR:
1101 tprintf("{SIG_ERR}");
1103 case (long) SIG_DFL:
1104 tprintf("{SIG_DFL}");
1106 case (long) SIG_IGN:
1108 if (tcp->u_arg[0] == SIGTRAP) {
1109 tcp->flags |= TCB_SIGTRAPPED;
1110 kill(tcp->pid, SIGSTOP);
1112 #endif /* !USE_PROCFS */
1113 tprintf("{SIG_IGN}");
1117 if (tcp->u_arg[0] == SIGTRAP) {
1118 tcp->flags |= TCB_SIGTRAPPED;
1119 kill(tcp->pid, SIGSTOP);
1121 #endif /* !USE_PROCFS */
1122 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
1124 printsigmask (&sa.sa_mask, 0);
1126 long_to_sigset(sa.sa_mask, &sigset);
1127 printsigmask(&sigset, 0);
1130 printflags(sigact_flags, sa.sa_flags, "SA_???");
1132 if (sa.sa_flags & SA_RESTORER)
1133 tprintf(", %p", sa.sa_restorer);
1142 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1151 if (entering(tcp)) {
1152 printsignal(tcp->u_arg[0]);
1154 switch (tcp->u_arg[1]) {
1163 if (tcp->u_arg[0] == SIGTRAP) {
1164 tcp->flags |= TCB_SIGTRAPPED;
1165 kill(tcp->pid, SIGSTOP);
1167 #endif /* !USE_PROCFS */
1172 if (tcp->u_arg[0] == SIGTRAP) {
1173 tcp->flags |= TCB_SIGTRAPPED;
1174 kill(tcp->pid, SIGSTOP);
1176 #endif /* !USE_PROCFS */
1177 tprintf("%#lx", tcp->u_arg[1]);
1182 switch (tcp->u_rval) {
1184 tcp->auxstr = "SIG_ERR"; break;
1186 tcp->auxstr = "SIG_DFL"; break;
1188 tcp->auxstr = "SIG_IGN"; break;
1192 return RVAL_HEX | RVAL_STR;
1200 if (entering(tcp)) {
1201 printsignal(tcp->u_arg[0]);
1206 #endif /* HAVE_SIGACTION */
1215 struct pt_regs regs;
1216 struct sigcontext_struct sc;
1218 if (entering(tcp)) {
1221 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)®s) == -1)
1224 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1228 tcp->u_arg[1] = sc.oldmask;
1231 long_to_sigset(tcp->u_arg[1], &sigm);
1232 tcp->u_rval = tcp->u_error = 0;
1233 if (tcp->u_arg[0] == 0)
1235 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1236 return RVAL_NONE | RVAL_STR;
1239 #elif defined(S390) || defined(S390X)
1241 struct sigcontext_struct sc;
1243 if (entering(tcp)) {
1245 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1247 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1250 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1252 tcp->u_rval = tcp->u_error = 0;
1253 if (tcp->u_arg[0] == 0)
1255 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1256 return RVAL_NONE | RVAL_STR;
1262 struct sigcontext_struct sc;
1264 if (entering(tcp)) {
1266 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1268 if (umove(tcp, esp, &sc) < 0)
1271 tcp->u_arg[1] = sc.oldmask;
1275 long_to_sigset(tcp->u_arg[1], &sigm);
1276 tcp->u_rval = tcp->u_error = 0;
1277 if (tcp->u_arg[0] == 0)
1279 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1280 return RVAL_NONE | RVAL_STR;
1285 struct sigcontext sc;
1288 if (entering(tcp)) {
1289 /* offset of sigcontext in the kernel's sigframe structure: */
1290 # define SIGFRAME_SC_OFFSET 0x90
1292 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1294 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
1297 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
1302 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
1303 tcp->u_rval = tcp->u_error = 0;
1304 if (tcp->u_arg[0] == 0)
1306 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1307 return RVAL_NONE | RVAL_STR;
1313 struct sigcontext_struct sc;
1315 if (entering(tcp)) {
1317 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1319 if (umove(tcp, esp, &sc) < 0)
1322 tcp->u_arg[1] = sc.oldmask;
1326 long_to_sigset(tcp->u_arg[1], &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;
1334 #else /* !POWERPC */
1337 struct sigcontext sc;
1339 if (entering(tcp)) {
1341 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
1343 if (umove(tcp, usp, &sc) < 0)
1346 tcp->u_arg[1] = sc.sc_mask;
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;
1361 struct sigcontext_struct sc;
1363 if (entering(tcp)) {
1365 if (upeek(tcp->pid, REG_FP, &fp) < 0)
1367 if (umove(tcp, fp, &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;
1383 #if defined (SPARC) || defined (SPARC64)
1388 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
1389 perror("sigreturn: PTRACE_GETREGS ");
1395 if(umove(tcp, i1, &si) < 0) {
1396 perror("sigreturn: umove ");
1400 tcp->u_arg[1] = si.si_mask;
1403 long_to_sigset(tcp->u_arg[1], &sigm);
1404 tcp->u_rval = tcp->u_error = 0;
1405 if(tcp->u_arg[0] == 0)
1407 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1408 return RVAL_NONE | RVAL_STR;
1414 struct sigcontext sc;
1418 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1420 if (umove(tcp, sp, &sc) < 0)
1423 tcp->u_arg[1] = sc.sc_sigset;
1425 tcp->u_rval = tcp->u_error = 0;
1426 if(tcp->u_arg[0] == 0)
1428 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1429 return RVAL_NONE | RVAL_STR;
1433 #warning No sys_sigreturn() for this architecture
1434 #warning (no problem, just a reminder :-)
1437 #endif /* SPARC || SPARC64 */
1440 #endif /* !POWERPC */
1452 long_to_sigset(tcp->u_rval, &sigm);
1453 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
1455 return RVAL_HEX | RVAL_STR;
1462 if (entering(tcp)) {
1464 long_to_sigset(tcp->u_arg[2], &sigm);
1466 /* first two are not really arguments, but print them anyway */
1467 /* nevermind, they are an anachronism now, too bad... */
1468 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1470 printsigmask(&sigm, 0);
1477 #if defined(SVR4) || defined(FREEBSD)
1485 if (entering(tcp)) {
1486 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1489 printsigmask(&sigset, 0);
1494 static const struct xlat ucontext_flags[] = {
1495 { UC_SIGMASK, "UC_SIGMASK" },
1496 { UC_STACK, "UC_STACK" },
1497 { UC_CPU, "UC_CPU" },
1499 { UC_FPU, "UC_FPU" },
1502 { UC_INTR, "UC_INTR" },
1506 #endif /* !FREEBSD */
1507 #endif /* SVR4 || FREEBSD */
1509 #if defined SVR4 || defined LINUX || defined FREEBSD
1510 #if defined LINUX && !defined SS_ONSTACK
1511 #define SS_ONSTACK 1
1512 #define SS_DISABLE 2
1513 #if __GLIBC_MINOR__ == 0
1523 #define stack_t struct sigaltstack
1526 static const struct xlat sigaltstack_flags[] = {
1527 { SS_ONSTACK, "SS_ONSTACK" },
1528 { SS_DISABLE, "SS_DISABLE" },
1535 printcontext(tcp, ucp)
1541 tprintf("uc_flags=");
1542 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
1543 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1545 tprintf("uc_sigmask=");
1546 printsigmask(&ucp->uc_sigmask, 0);
1548 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1549 (unsigned long) ucp->uc_stack.ss_sp,
1550 ucp->uc_stack.ss_size);
1551 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
1565 tprintf("%#lx", tcp->u_arg[0]);
1566 else if (!tcp->u_arg[0])
1568 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1571 printcontext(tcp, &uc);
1582 if (entering(tcp)) {
1585 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1588 printcontext(tcp, &uc);
1591 tcp->u_rval = tcp->u_error = 0;
1592 if (tcp->u_arg[0] == 0)
1601 #if defined(LINUX) || defined(FREEBSD)
1604 print_stack_t(tcp, addr)
1609 if (umove(tcp, addr, &ss) < 0)
1611 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1612 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1613 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1618 sys_sigaltstack(tcp)
1621 if (entering(tcp)) {
1622 if (tcp->u_arg[0] == 0)
1624 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1629 if (tcp->u_arg[1] == 0)
1631 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1638 #ifdef HAVE_SIGACTION
1641 sys_sigprocmask(tcp)
1645 if (entering(tcp)) {
1646 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1648 printsigmask(tcp->u_arg[1], 0);
1650 else if (!syserror(tcp)) {
1651 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
1652 return RVAL_HEX | RVAL_STR;
1657 if (entering(tcp)) {
1659 if (tcp->u_arg[0] == 0)
1663 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1667 else if (copy_sigset(tcp, tcp->u_arg[1], &sigset) < 0)
1668 tprintf("%#lx, ", tcp->u_arg[1]);
1670 printsigmask(&sigset, 0);
1677 else if (syserror(tcp))
1678 tprintf("%#lx", tcp->u_arg[2]);
1679 else if (copy_sigset(tcp, tcp->u_arg[2], &sigset) < 0)
1682 printsigmask(&sigset, 0);
1688 #endif /* HAVE_SIGACTION */
1694 if (entering(tcp)) {
1695 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
1704 return sys_kill(tcp);
1712 if (entering(tcp)) {
1713 tprintf("%ld, %ld, %s",
1714 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1728 tprintf("%#lx", tcp->u_arg[0]);
1729 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1732 printsigmask(&sigset, 0);
1737 int sys_sigwait(tcp)
1742 if (entering(tcp)) {
1743 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1746 printsigmask(&sigset, 0);
1749 if (!syserror(tcp)) {
1750 tcp->auxstr = signalent[tcp->u_rval];
1751 return RVAL_DECIMAL | RVAL_STR;
1760 sys_rt_sigprocmask(tcp)
1765 /* Note: arg[3] is the length of the sigset. */
1766 if (entering(tcp)) {
1767 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1771 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
1772 tprintf("%#lx, ", tcp->u_arg[1]);
1774 printsigmask(&sigset, 1);
1782 else if (syserror(tcp))
1783 tprintf("%#lx", tcp->u_arg[2]);
1784 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
1787 printsigmask(&sigset, 1);
1788 tprintf(", %lu", tcp->u_arg[3]);
1794 /* Structure describing the action to be taken when a signal arrives. */
1795 struct new_sigaction
1799 __sighandler_t __sa_handler;
1800 void (*__sa_sigaction) (int, siginfo_t *, void *);
1802 __sigaction_handler;
1803 unsigned long sa_flags;
1804 void (*sa_restorer) (void);
1805 unsigned long int sa_mask[2];
1810 sys_rt_sigaction(tcp)
1813 struct new_sigaction sa;
1817 if (entering(tcp)) {
1818 printsignal(tcp->u_arg[0]);
1820 addr = tcp->u_arg[1];
1822 addr = tcp->u_arg[2];
1825 else if (!verbose(tcp))
1826 tprintf("%#lx", addr);
1827 else if (umove(tcp, addr, &sa) < 0)
1830 switch ((long) sa.__sigaction_handler.__sa_handler) {
1831 case (long) SIG_ERR:
1832 tprintf("{SIG_ERR}");
1834 case (long) SIG_DFL:
1835 tprintf("{SIG_DFL}");
1837 case (long) SIG_IGN:
1838 tprintf("{SIG_IGN}");
1842 (long) sa.__sigaction_handler.__sa_handler);
1843 sigemptyset(&sigset);
1845 if (tcp->u_arg[4] <= sizeof(sigset))
1846 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1848 if (tcp->u_arg[3] <= sizeof(sigset))
1849 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1852 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1853 printsigmask(&sigset, 1);
1855 printflags(sigact_flags, sa.sa_flags, "SA_???");
1857 if (sa.sa_flags & SA_RESTORER)
1858 tprintf(", %p", sa.sa_restorer);
1867 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1868 #elif defined(ALPHA)
1869 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1871 tprintf(", %lu", addr = tcp->u_arg[3]);
1877 sys_rt_sigpending(tcp)
1884 tprintf("%#lx", tcp->u_arg[0]);
1885 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1886 &sigset, tcp->u_arg[1]) < 0)
1889 printsigmask(&sigset, 1);
1894 sys_rt_sigsuspend(tcp)
1897 if (entering(tcp)) {
1899 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1902 printsigmask(&sigm, 1);
1907 sys_rt_sigqueueinfo(tcp)
1910 if (entering(tcp)) {
1912 tprintf("%lu, ", tcp->u_arg[0]);
1913 printsignal(tcp->u_arg[1]);
1915 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1916 tprintf("%#lx", tcp->u_arg[2]);
1918 printsiginfo(&si, verbose (tcp));
1923 int sys_rt_sigtimedwait(tcp)
1926 if (entering(tcp)) {
1929 if (copy_sigset_len(tcp, tcp->u_arg[0],
1930 &sigset, tcp->u_arg[3]) < 0)
1933 printsigmask(&sigset, 1);
1938 tprintf("%#lx", tcp->u_arg[0]);
1941 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1942 tprintf("%#lx", tcp->u_arg[1]);
1944 printsiginfo(&si, verbose (tcp));
1946 tprintf(", %#lx", tcp->u_arg[2]);
1947 tprintf(", %d", (int) tcp->u_arg[3]);
1954 sys_restart_syscall(tcp)
1958 tprintf("<... resuming interrupted call ...>");