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 char *signalent0[] = {
157 #include "signalent.h"
159 int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
161 #if SUPPORTED_PERSONALITIES >= 2
162 char *signalent1[] = {
163 #include "signalent1.h"
165 int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
166 #endif /* SUPPORTED_PERSONALITIES >= 2 */
168 #if SUPPORTED_PERSONALITIES >= 3
169 char *signalent2[] = {
170 #include "signalent2.h"
172 int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
173 #endif /* SUPPORTED_PERSONALITIES >= 3 */
178 #if defined(SUNOS4) || defined(FREEBSD)
180 static 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
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 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 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 < 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 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 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 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 struct xlat sigtrap_codes[] = {
587 { TRAP_BRKPT, "TRAP_BRKPT" },
588 { TRAP_TRACE, "TRAP_TRACE" },
592 static 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 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 struct xlat sigprof_codes[] = {
614 { PROF_SIG, "PROF_SIG" },
620 static struct xlat sigemt_codes[] = {
622 { EMT_TAGOVF, "EMT_TAGOVF" },
628 static struct xlat sigsegv_codes[] = {
629 { SEGV_MAPERR, "SEGV_MAPERR" },
630 { SEGV_ACCERR, "SEGV_ACCERR" },
634 static 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 if (!printflags(sigvec_flags, sv.sv_flags))
979 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
981 long_to_sigset(tcp->u_arg[0], &sigm);
982 printsigmask(&sigm, 0);
995 addr = tcp->u_arg[0];
997 addr = tcp->u_arg[1];
1000 else if (umove(tcp, addr, &ss) < 0)
1001 tprintf("%#lx", addr);
1003 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
1004 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1018 #endif /* SUNOS4 || FREEBSD */
1026 if (entering(tcp)) {
1028 long_to_sigset(tcp->u_arg[0], &sigm);
1029 printsigmask(&sigm, 0);
1031 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1032 /* Mark attempt to block SIGTRAP */
1033 tcp->flags |= TCB_SIGTRAPPED;
1034 /* Send unblockable signal */
1035 kill(tcp->pid, SIGSTOP);
1037 #endif /* !USE_PROCFS */
1039 else if (!syserror(tcp)) {
1041 long_to_sigset(tcp->u_rval, &sigm);
1042 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
1044 return RVAL_HEX | RVAL_STR;
1053 return sys_sigsetmask(tcp);
1058 #ifdef HAVE_SIGACTION
1061 struct old_sigaction {
1062 __sighandler_t __sa_handler;
1063 unsigned long sa_mask;
1064 unsigned long sa_flags;
1065 void (*sa_restorer)(void);
1067 #define SA_HANDLER __sa_handler
1071 #define SA_HANDLER sa_handler
1081 struct old_sigaction sa;
1083 struct sigaction sa;
1087 if (entering(tcp)) {
1088 printsignal(tcp->u_arg[0]);
1090 addr = tcp->u_arg[1];
1092 addr = tcp->u_arg[2];
1095 else if (!verbose(tcp))
1096 tprintf("%#lx", addr);
1097 else if (umove(tcp, addr, &sa) < 0)
1100 switch ((long) sa.SA_HANDLER) {
1101 case (long) SIG_ERR:
1102 tprintf("{SIG_ERR}");
1104 case (long) SIG_DFL:
1105 tprintf("{SIG_DFL}");
1107 case (long) SIG_IGN:
1109 if (tcp->u_arg[0] == SIGTRAP) {
1110 tcp->flags |= TCB_SIGTRAPPED;
1111 kill(tcp->pid, SIGSTOP);
1113 #endif /* !USE_PROCFS */
1114 tprintf("{SIG_IGN}");
1118 if (tcp->u_arg[0] == SIGTRAP) {
1119 tcp->flags |= TCB_SIGTRAPPED;
1120 kill(tcp->pid, SIGSTOP);
1122 #endif /* !USE_PROCFS */
1123 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
1125 printsigmask (&sa.sa_mask, 0);
1127 long_to_sigset(sa.sa_mask, &sigset);
1128 printsigmask(&sigset, 0);
1131 if (!printflags(sigact_flags, sa.sa_flags))
1134 if (sa.sa_flags & SA_RESTORER)
1135 tprintf(", %p", sa.sa_restorer);
1144 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1153 if (entering(tcp)) {
1154 printsignal(tcp->u_arg[0]);
1156 switch (tcp->u_arg[1]) {
1165 if (tcp->u_arg[0] == SIGTRAP) {
1166 tcp->flags |= TCB_SIGTRAPPED;
1167 kill(tcp->pid, SIGSTOP);
1169 #endif /* !USE_PROCFS */
1174 if (tcp->u_arg[0] == SIGTRAP) {
1175 tcp->flags |= TCB_SIGTRAPPED;
1176 kill(tcp->pid, SIGSTOP);
1178 #endif /* !USE_PROCFS */
1179 tprintf("%#lx", tcp->u_arg[1]);
1184 switch (tcp->u_rval) {
1186 tcp->auxstr = "SIG_ERR"; break;
1188 tcp->auxstr = "SIG_DFL"; break;
1190 tcp->auxstr = "SIG_IGN"; break;
1194 return RVAL_HEX | RVAL_STR;
1202 if (entering(tcp)) {
1203 printsignal(tcp->u_arg[0]);
1208 #endif /* HAVE_SIGACTION */
1217 struct pt_regs regs;
1218 struct sigcontext_struct sc;
1220 if (entering(tcp)) {
1223 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)®s) == -1)
1226 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1230 tcp->u_arg[1] = sc.oldmask;
1233 long_to_sigset(tcp->u_arg[1], &sigm);
1234 tcp->u_rval = tcp->u_error = 0;
1235 if (tcp->u_arg[0] == 0)
1237 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1238 return RVAL_NONE | RVAL_STR;
1241 #elif defined(S390) || defined(S390X)
1243 struct sigcontext_struct sc;
1245 if (entering(tcp)) {
1247 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1249 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1252 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1254 tcp->u_rval = tcp->u_error = 0;
1255 if (tcp->u_arg[0] == 0)
1257 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1258 return RVAL_NONE | RVAL_STR;
1264 struct sigcontext_struct sc;
1266 if (entering(tcp)) {
1268 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1270 if (umove(tcp, esp, &sc) < 0)
1273 tcp->u_arg[1] = sc.oldmask;
1277 long_to_sigset(tcp->u_arg[1], &sigm);
1278 tcp->u_rval = tcp->u_error = 0;
1279 if (tcp->u_arg[0] == 0)
1281 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1282 return RVAL_NONE | RVAL_STR;
1287 struct sigcontext sc;
1290 if (entering(tcp)) {
1291 /* offset of sigcontext in the kernel's sigframe structure: */
1292 # define SIGFRAME_SC_OFFSET 0x90
1294 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1296 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
1299 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
1304 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
1305 tcp->u_rval = tcp->u_error = 0;
1306 if (tcp->u_arg[0] == 0)
1308 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1309 return RVAL_NONE | RVAL_STR;
1315 struct sigcontext_struct sc;
1317 if (entering(tcp)) {
1319 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1321 if (umove(tcp, esp, &sc) < 0)
1324 tcp->u_arg[1] = sc.oldmask;
1328 long_to_sigset(tcp->u_arg[1], &sigm);
1329 tcp->u_rval = tcp->u_error = 0;
1330 if (tcp->u_arg[0] == 0)
1332 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1333 return RVAL_NONE | RVAL_STR;
1336 #else /* !POWERPC */
1339 struct sigcontext sc;
1341 if (entering(tcp)) {
1343 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
1345 if (umove(tcp, usp, &sc) < 0)
1348 tcp->u_arg[1] = sc.sc_mask;
1352 long_to_sigset(tcp->u_arg[1], &sigm);
1353 tcp->u_rval = tcp->u_error = 0;
1354 if (tcp->u_arg[0] == 0)
1356 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1357 return RVAL_NONE | RVAL_STR;
1363 struct sigcontext_struct sc;
1365 if (entering(tcp)) {
1367 if (upeek(tcp->pid, REG_FP, &fp) < 0)
1369 if (umove(tcp, fp, &sc) < 0)
1372 tcp->u_arg[1] = sc.sc_mask;
1376 long_to_sigset(tcp->u_arg[1], &sigm);
1377 tcp->u_rval = tcp->u_error = 0;
1378 if (tcp->u_arg[0] == 0)
1380 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1381 return RVAL_NONE | RVAL_STR;
1385 #if defined (SPARC) || defined (SPARC64)
1390 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
1391 perror("sigreturn: PTRACE_GETREGS ");
1397 if(umove(tcp, i1, &si) < 0) {
1398 perror("sigreturn: umove ");
1402 tcp->u_arg[1] = si.si_mask;
1405 long_to_sigset(tcp->u_arg[1], &sigm);
1406 tcp->u_rval = tcp->u_error = 0;
1407 if(tcp->u_arg[0] == 0)
1409 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1410 return RVAL_NONE | RVAL_STR;
1416 struct sigcontext sc;
1420 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1422 if (umove(tcp, sp, &sc) < 0)
1425 tcp->u_arg[1] = sc.sc_sigset;
1427 tcp->u_rval = tcp->u_error = 0;
1428 if(tcp->u_arg[0] == 0)
1430 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1431 return RVAL_NONE | RVAL_STR;
1435 #warning No sys_sigreturn() for this architecture
1436 #warning (no problem, just a reminder :-)
1439 #endif /* SPARC || SPARC64 */
1442 #endif /* !POWERPC */
1454 long_to_sigset(tcp->u_rval, &sigm);
1455 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
1457 return RVAL_HEX | RVAL_STR;
1464 if (entering(tcp)) {
1466 long_to_sigset(tcp->u_arg[2], &sigm);
1468 /* first two are not really arguments, but print them anyway */
1469 /* nevermind, they are an anachronism now, too bad... */
1470 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1472 printsigmask(&sigm, 0);
1479 #if defined(SVR4) || defined(FREEBSD)
1487 if (entering(tcp)) {
1488 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1491 printsigmask(&sigset, 0);
1496 static struct xlat ucontext_flags[] = {
1497 { UC_SIGMASK, "UC_SIGMASK" },
1498 { UC_STACK, "UC_STACK" },
1499 { UC_CPU, "UC_CPU" },
1501 { UC_FPU, "UC_FPU" },
1504 { UC_INTR, "UC_INTR" },
1508 #endif /* !FREEBSD */
1509 #endif /* SVR4 || FREEBSD */
1511 #if defined SVR4 || defined LINUX || defined FREEBSD
1512 #if defined LINUX && !defined SS_ONSTACK
1513 #define SS_ONSTACK 1
1514 #define SS_DISABLE 2
1515 #if __GLIBC_MINOR__ == 0
1525 #define stack_t struct sigaltstack
1528 static struct xlat sigaltstack_flags[] = {
1529 { SS_ONSTACK, "SS_ONSTACK" },
1530 { SS_DISABLE, "SS_DISABLE" },
1537 printcontext(tcp, ucp)
1543 tprintf("uc_flags=");
1544 if (!printflags(ucontext_flags, ucp->uc_flags))
1546 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1548 tprintf("uc_sigmask=");
1549 printsigmask(&ucp->uc_sigmask, 0);
1551 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1552 (unsigned long) ucp->uc_stack.ss_sp,
1553 ucp->uc_stack.ss_size);
1554 if (!printflags(sigaltstack_flags, ucp->uc_stack.ss_flags))
1569 tprintf("%#lx", tcp->u_arg[0]);
1570 else if (!tcp->u_arg[0])
1572 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1575 printcontext(tcp, &uc);
1586 if (entering(tcp)) {
1589 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1592 printcontext(tcp, &uc);
1595 tcp->u_rval = tcp->u_error = 0;
1596 if (tcp->u_arg[0] == 0)
1605 #if defined(LINUX) || defined(FREEBSD)
1608 print_stack_t(tcp, addr)
1613 if (umove(tcp, addr, &ss) < 0)
1615 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1616 if (!printflags(sigaltstack_flags, ss.ss_flags))
1618 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1623 sys_sigaltstack(tcp)
1626 if (entering(tcp)) {
1627 if (tcp->u_arg[0] == 0)
1629 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1634 if (tcp->u_arg[1] == 0)
1636 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1643 #ifdef HAVE_SIGACTION
1646 sys_sigprocmask(tcp)
1650 if (entering(tcp)) {
1651 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1653 printsigmask(tcp->u_arg[1], 0);
1655 else if (!syserror(tcp)) {
1656 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
1657 return RVAL_HEX | RVAL_STR;
1662 if (entering(tcp)) {
1664 if (tcp->u_arg[0] == 0)
1668 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1672 else if (copy_sigset(tcp, tcp->u_arg[1], &sigset) < 0)
1673 tprintf("%#lx, ", tcp->u_arg[1]);
1675 printsigmask(&sigset, 0);
1682 else if (syserror(tcp))
1683 tprintf("%#lx", tcp->u_arg[2]);
1684 else if (copy_sigset(tcp, tcp->u_arg[2], &sigset) < 0)
1687 printsigmask(&sigset, 0);
1693 #endif /* HAVE_SIGACTION */
1699 if (entering(tcp)) {
1700 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
1709 return sys_kill(tcp);
1717 if (entering(tcp)) {
1718 tprintf("%ld, %ld, %s",
1719 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1733 tprintf("%#lx", tcp->u_arg[0]);
1734 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1737 printsigmask(&sigset, 0);
1742 int sys_sigwait(tcp)
1747 if (entering(tcp)) {
1748 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1751 printsigmask(&sigset, 0);
1754 if (!syserror(tcp)) {
1755 tcp->auxstr = signalent[tcp->u_rval];
1756 return RVAL_DECIMAL | RVAL_STR;
1765 sys_rt_sigprocmask(tcp)
1770 /* Note: arg[3] is the length of the sigset. */
1771 if (entering(tcp)) {
1772 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1776 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
1777 tprintf("%#lx, ", tcp->u_arg[1]);
1779 printsigmask(&sigset, 1);
1787 else if (syserror(tcp))
1788 tprintf("%#lx", tcp->u_arg[2]);
1789 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
1792 printsigmask(&sigset, 1);
1793 tprintf(", %lu", tcp->u_arg[3]);
1799 /* Structure describing the action to be taken when a signal arrives. */
1800 struct new_sigaction
1804 __sighandler_t __sa_handler;
1805 void (*__sa_sigaction) (int, siginfo_t *, void *);
1807 __sigaction_handler;
1808 unsigned long sa_flags;
1809 void (*sa_restorer) (void);
1810 unsigned long int sa_mask[2];
1815 sys_rt_sigaction(tcp)
1818 struct new_sigaction sa;
1822 if (entering(tcp)) {
1823 printsignal(tcp->u_arg[0]);
1825 addr = tcp->u_arg[1];
1827 addr = tcp->u_arg[2];
1830 else if (!verbose(tcp))
1831 tprintf("%#lx", addr);
1832 else if (umove(tcp, addr, &sa) < 0)
1835 switch ((long) sa.__sigaction_handler.__sa_handler) {
1836 case (long) SIG_ERR:
1837 tprintf("{SIG_ERR}");
1839 case (long) SIG_DFL:
1840 tprintf("{SIG_DFL}");
1842 case (long) SIG_IGN:
1843 tprintf("{SIG_IGN}");
1847 (long) sa.__sigaction_handler.__sa_handler);
1848 sigemptyset(&sigset);
1850 if (tcp->u_arg[4] <= sizeof(sigset))
1851 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1853 if (tcp->u_arg[3] <= sizeof(sigset))
1854 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1857 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1858 printsigmask(&sigset, 1);
1860 if (!printflags(sigact_flags, sa.sa_flags))
1863 if (sa.sa_flags & SA_RESTORER)
1864 tprintf(", %p", sa.sa_restorer);
1873 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1874 #elif defined(ALPHA)
1875 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1877 tprintf(", %lu", addr = tcp->u_arg[3]);
1883 sys_rt_sigpending(tcp)
1890 tprintf("%#lx", tcp->u_arg[0]);
1891 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1892 &sigset, tcp->u_arg[1]) < 0)
1895 printsigmask(&sigset, 1);
1900 sys_rt_sigsuspend(tcp)
1903 if (entering(tcp)) {
1905 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1908 printsigmask(&sigm, 1);
1913 sys_rt_sigqueueinfo(tcp)
1916 if (entering(tcp)) {
1918 tprintf("%lu, ", tcp->u_arg[0]);
1919 printsignal(tcp->u_arg[1]);
1921 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1922 tprintf("%#lx", tcp->u_arg[2]);
1924 printsiginfo(&si, verbose (tcp));
1929 int sys_rt_sigtimedwait(tcp)
1932 if (entering(tcp)) {
1935 if (copy_sigset_len(tcp, tcp->u_arg[0],
1936 &sigset, tcp->u_arg[3]) < 0)
1939 printsigmask(&sigset, 1);
1944 tprintf("%#lx", tcp->u_arg[0]);
1947 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1948 tprintf("%#lx", tcp->u_arg[1]);
1950 printsiginfo(&si, verbose (tcp));
1952 tprintf(", %#lx", tcp->u_arg[2]);
1953 tprintf(", %d", (int) tcp->u_arg[3]);