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>
76 # define fpq kernel_fpq
78 # define fpu kernel_fpu
86 #endif /* HAVE_ASM_REG_H */
93 #elif defined HAVE_ASM_SIGCONTEXT_H
94 #if !defined(IA64) && !defined(X86_64)
95 #include <asm/sigcontext.h>
96 #endif /* !IA64 && !X86_64 */
97 #else /* !HAVE_ASM_SIGCONTEXT_H */
99 struct sigcontext_struct {
100 unsigned short gs, __gsh;
101 unsigned short fs, __fsh;
102 unsigned short es, __esh;
103 unsigned short ds, __dsh;
112 unsigned long trapno;
115 unsigned short cs, __csh;
116 unsigned long eflags;
117 unsigned long esp_at_signal;
118 unsigned short ss, __ssh;
120 unsigned long oldmask;
127 unsigned long sc_mask;
128 unsigned long sc_usp;
133 unsigned short sc_sr;
135 unsigned short sc_formatvec;
139 #endif /* !HAVE_ASM_SIGCONTEXT_H */
149 char *signalent0[] = {
150 #include "signalent.h"
152 int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
154 #if SUPPORTED_PERSONALITIES >= 2
155 char *signalent1[] = {
156 #include "signalent1.h"
158 int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
159 #endif /* SUPPORTED_PERSONALITIES >= 2 */
161 #if SUPPORTED_PERSONALITIES >= 3
162 char *signalent2[] = {
163 #include "signalent2.h"
165 int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
166 #endif /* SUPPORTED_PERSONALITIES >= 3 */
171 #if defined(SUNOS4) || defined(FREEBSD)
173 static struct xlat sigvec_flags[] = {
174 { SV_ONSTACK, "SV_ONSTACK" },
175 { SV_INTERRUPT, "SV_INTERRUPT" },
176 { SV_RESETHAND, "SV_RESETHAND" },
177 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
181 #endif /* SUNOS4 || FREEBSD */
183 #ifdef HAVE_SIGACTION
185 #if defined LINUX && defined I386
186 /* The libc headers do not define this constant since it should only be
187 used by the implementation. So wwe define it here. */
189 # define SA_RESTORER 0x04000000
193 static struct xlat sigact_flags[] = {
195 { SA_RESTORER, "SA_RESTORER" },
198 { SA_STACK, "SA_STACK" },
201 { SA_RESTART, "SA_RESTART" },
204 { SA_INTERRUPT, "SA_INTERRUPT" },
207 { SA_NOMASK, "SA_NOMASK" },
210 { SA_ONESHOT, "SA_ONESHOT" },
213 { SA_SIGINFO, "SA_SIGINFO" },
216 { SA_RESETHAND, "SA_RESETHAND" },
219 { SA_ONSTACK, "SA_ONSTACK" },
222 { SA_NODEFER, "SA_NODEFER" },
225 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
228 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
231 { _SA_BSDCALL, "_SA_BSDCALL" },
236 static struct xlat sigprocmaskcmds[] = {
237 { SIG_BLOCK, "SIG_BLOCK" },
238 { SIG_UNBLOCK, "SIG_UNBLOCK" },
239 { SIG_SETMASK, "SIG_SETMASK" },
241 { SIG_SETMASK32,"SIG_SETMASK32" },
246 #endif /* HAVE_SIGACTION */
248 /* Anonymous realtime signals. */
249 /* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
250 constant. This is what we want. Otherwise, just use SIGRTMIN. */
253 #define __SIGRTMIN SIGRTMIN
254 #define __SIGRTMAX SIGRTMAX /* likewise */
263 if (sig < nsignals) {
264 return signalent[sig];
266 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
267 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
269 #endif /* SIGRTMIN */
271 sprintf(buf, "%d", sig);
288 copy_sigset_len(tcp, addr, s, len)
294 if (len > sizeof(*s))
297 if (umoven(tcp, addr, len, (char *)s) < 0)
303 /* Original sigset is unsigned long */
304 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
306 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
310 sprintsigmask(s, mask, rt)
313 int rt; /* set might include realtime sigs */
318 static char outstr[8 * sizeof(sigset_t) * 8];
321 s = outstr + strlen(outstr);
326 maxsigs = __SIGRTMAX; /* instead */
328 for (i = 1; i < maxsigs; i++) {
329 if (sigismember(mask, i) == 1)
332 if (nsigs >= nsignals * 2 / 3) {
334 for (i = 1; i < maxsigs; i++) {
335 switch (sigismember(mask, i)) {
347 for (i = 1; i < maxsigs; i++) {
348 if (sigismember(mask, i) == 1) {
349 /* real-time signals on solaris don't have
353 sprintf(s, format, signalent[i] + 3);
356 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
358 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
359 sprintf(s, format, tsig);
361 #endif /* SIGRTMIN */
364 sprintf(tsig, "%u", i);
365 sprintf(s, format, tsig);
377 printsigmask(mask, rt)
381 tprintf("%s", sprintsigmask("", mask, rt));
388 tprintf(signame(nr));
394 #define ILL_ILLOPC 1 /* illegal opcode */
395 #define ILL_ILLOPN 2 /* illegal operand */
396 #define ILL_ILLADR 3 /* illegal addressing mode */
397 #define ILL_ILLTRP 4 /* illegal trap */
398 #define ILL_PRVOPC 5 /* privileged opcode */
399 #define ILL_PRVREG 6 /* privileged register */
400 #define ILL_COPROC 7 /* coprocessor error */
401 #define ILL_BADSTK 8 /* internal stack error */
402 #define FPE_INTDIV 1 /* integer divide by zero */
403 #define FPE_INTOVF 2 /* integer overflow */
404 #define FPE_FLTDIV 3 /* floating point divide by zero */
405 #define FPE_FLTOVF 4 /* floating point overflow */
406 #define FPE_FLTUND 5 /* floating point underflow */
407 #define FPE_FLTRES 6 /* floating point inexact result */
408 #define FPE_FLTINV 7 /* floating point invalid operation */
409 #define FPE_FLTSUB 8 /* subscript out of range */
410 #define SEGV_MAPERR 1 /* address not mapped to object */
411 #define SEGV_ACCERR 2 /* invalid permissions for mapped object */
412 #define BUS_ADRALN 1 /* invalid address alignment */
413 #define BUS_ADRERR 2 /* non-existant physical address */
414 #define BUS_OBJERR 3 /* object specific hardware error */
415 #define TRAP_BRKPT 1 /* process breakpoint */
416 #define TRAP_TRACE 2 /* process trace trap */
417 #define CLD_EXITED 1 /* child has exited */
418 #define CLD_KILLED 2 /* child was killed */
419 #define CLD_DUMPED 3 /* child terminated abnormally */
420 #define CLD_TRAPPED 4 /* traced child has trapped */
421 #define CLD_STOPPED 5 /* child has stopped */
422 #define CLD_CONTINUED 6 /* stopped child has continued */
423 #define POLL_IN 1 /* data input available */
424 #define POLL_OUT 2 /* output buffers available */
425 #define POLL_MSG 3 /* input message available */
426 #define POLL_ERR 4 /* i/o error */
427 #define POLL_PRI 5 /* high priority input available */
428 #define POLL_HUP 6 /* device disconnected */
429 #define SI_USER 0 /* sent by kill, sigsend, raise */
430 #define SI_QUEUE -1 /* sent by sigqueue */
431 #define SI_TIMER -2 /* sent by timer expiration */
432 #define SI_MESGQ -3 /* sent by real time mesq state change */
433 #define SI_ASYNCIO -4 /* sent by AIO completion */
434 #define SI_SIGIO -5 /* Sent by SIGIO */
435 #define SI_TKILL -6 /* Sent by tkill */
438 #if __GLIBC_MINOR__ < 1
439 /* Type for data associated with a signal. */
446 # define __SI_MAX_SIZE 128
447 # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
449 typedef struct siginfo
451 int si_signo; /* Signal number. */
452 int si_errno; /* If non-zero, an errno value associated with
453 this signal, as defined in <errno.h>. */
454 int si_code; /* Signal code. */
458 int _pad[__SI_PAD_SIZE];
463 __pid_t si_pid; /* Sending process ID. */
464 __uid_t si_uid; /* Real user ID of sending process. */
467 /* POSIX.1b timers. */
470 unsigned int _timer1;
471 unsigned int _timer2;
474 /* POSIX.1b signals. */
477 __pid_t si_pid; /* Sending process ID. */
478 __uid_t si_uid; /* Real user ID of sending process. */
479 sigval_t si_sigval; /* Signal value. */
485 __pid_t si_pid; /* Which child. */
486 int si_status; /* Exit value or signal. */
491 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
494 void *si_addr; /* Faulting insn/memory ref. */
500 int si_band; /* Band event for SIGPOLL. */
506 #define si_pid _sifields._kill.si_pid
507 #define si_uid _sifields._kill.si_uid
508 #define si_status _sifields._sigchld.si_status
509 #define si_utime _sifields._sigchld.si_utime
510 #define si_stime _sifields._sigchld.si_stime
511 #define si_value _sifields._rt.si_sigval
512 #define si_int _sifields._rt.si_sigval.sival_int
513 #define si_ptr _sifields._rt.si_sigval.sival_ptr
514 #define si_addr _sifields._sigfault.si_addr
515 #define si_band _sifields._sigpoll.si_band
516 #define si_fd _sifields._sigpoll.si_fd
522 #if defined (SVR4) || defined (LINUX)
524 static struct xlat siginfo_codes[] = {
526 { SI_NOINFO, "SI_NOINFO" },
529 { SI_USER, "SI_USER" },
532 { SI_LWP, "SI_LWP" },
535 { SI_QUEUE, "SI_QUEUE" },
538 { SI_TIMER, "SI_TIMER" },
541 { SI_ASYNCIO, "SI_ASYNCIO" },
544 { SI_MESGQ, "SI_MESGQ" },
547 { SI_SIGIO, "SI_SIGIO" },
550 { SI_TKILL, "SI_TKILL" },
555 static struct xlat sigill_codes[] = {
556 { ILL_ILLOPC, "ILL_ILLOPC" },
557 { ILL_ILLOPN, "ILL_ILLOPN" },
558 { ILL_ILLADR, "ILL_ILLADR" },
559 { ILL_ILLTRP, "ILL_ILLTRP" },
560 { ILL_PRVOPC, "ILL_PRVOPC" },
561 { ILL_PRVREG, "ILL_PRVREG" },
562 { ILL_COPROC, "ILL_COPROC" },
563 { ILL_BADSTK, "ILL_BADSTK" },
567 static struct xlat sigfpe_codes[] = {
568 { FPE_INTDIV, "FPE_INTDIV" },
569 { FPE_INTOVF, "FPE_INTOVF" },
570 { FPE_FLTDIV, "FPE_FLTDIV" },
571 { FPE_FLTOVF, "FPE_FLTOVF" },
572 { FPE_FLTUND, "FPE_FLTUND" },
573 { FPE_FLTRES, "FPE_FLTRES" },
574 { FPE_FLTINV, "FPE_FLTINV" },
575 { FPE_FLTSUB, "FPE_FLTSUB" },
579 static struct xlat sigtrap_codes[] = {
580 { TRAP_BRKPT, "TRAP_BRKPT" },
581 { TRAP_TRACE, "TRAP_TRACE" },
585 static struct xlat sigchld_codes[] = {
586 { CLD_EXITED, "CLD_EXITED" },
587 { CLD_KILLED, "CLD_KILLED" },
588 { CLD_DUMPED, "CLD_DUMPED" },
589 { CLD_TRAPPED, "CLD_TRAPPED" },
590 { CLD_STOPPED, "CLD_STOPPED" },
591 { CLD_CONTINUED,"CLD_CONTINUED" },
595 static struct xlat sigpoll_codes[] = {
596 { POLL_IN, "POLL_IN" },
597 { POLL_OUT, "POLL_OUT" },
598 { POLL_MSG, "POLL_MSG" },
599 { POLL_ERR, "POLL_ERR" },
600 { POLL_PRI, "POLL_PRI" },
601 { POLL_HUP, "POLL_HUP" },
605 static struct xlat sigprof_codes[] = {
607 { PROF_SIG, "PROF_SIG" },
613 static struct xlat sigemt_codes[] = {
615 { EMT_TAGOVF, "EMT_TAGOVF" },
621 static struct xlat sigsegv_codes[] = {
622 { SEGV_MAPERR, "SEGV_MAPERR" },
623 { SEGV_ACCERR, "SEGV_ACCERR" },
627 static struct xlat sigbus_codes[] = {
628 { BUS_ADRALN, "BUS_ADRALN" },
629 { BUS_ADRERR, "BUS_ADRERR" },
630 { BUS_OBJERR, "BUS_OBJERR" },
635 printsiginfo(sip, verbose)
641 if (sip->si_signo == 0) {
645 tprintf("{si_signo=");
646 printsignal(sip->si_signo);
647 code = xlookup(siginfo_codes, sip->si_code);
649 switch (sip->si_signo) {
651 code = xlookup(sigtrap_codes, sip->si_code);
654 code = xlookup(sigchld_codes, sip->si_code);
657 code = xlookup(sigpoll_codes, sip->si_code);
660 code = xlookup(sigprof_codes, sip->si_code);
663 code = xlookup(sigill_codes, sip->si_code);
667 code = xlookup(sigemt_codes, sip->si_code);
671 code = xlookup(sigfpe_codes, sip->si_code);
674 code = xlookup(sigsegv_codes, sip->si_code);
677 code = xlookup(sigbus_codes, sip->si_code);
682 tprintf(", si_code=%s", code);
684 tprintf(", si_code=%#x", sip->si_code);
686 if (sip->si_code != SI_NOINFO)
690 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
691 tprintf(", si_errno=%d", sip->si_errno);
693 tprintf(", si_errno=%s",
694 errnoent[sip->si_errno]);
697 if (SI_FROMUSER(sip)) {
698 tprintf(", si_pid=%ld, si_uid=%ld",
699 sip->si_pid, sip->si_uid);
701 switch (sip->si_code) {
705 #endif /* SI_QUEUE */
709 #endif /* SI_MESGQ */
710 tprintf(", si_value=%d",
711 sip->si_value.sival_int);
714 #endif /* SI_QUEUE */
717 #endif /* SI_FROMUSER */
719 switch (sip->si_signo) {
721 tprintf(", si_pid=%ld, si_status=",
723 if (sip->si_code == CLD_EXITED)
724 tprintf("%d", sip->si_status);
726 printsignal(sip->si_status);
731 tprintf(", si_utime=%lu, si_stime=%lu",
736 case SIGILL: case SIGFPE:
737 case SIGSEGV: case SIGBUS:
738 tprintf(", si_addr=%#lx",
739 (unsigned long) sip->si_addr);
742 switch (sip->si_code) {
743 case POLL_IN: case POLL_OUT: case POLL_MSG:
744 tprintf(", si_band=%ld",
745 (long) sip->si_band);
751 tprintf(", si_pid=%lu, si_uid=%lu, ",
752 (unsigned long) sip->si_pid,
753 (unsigned long) sip->si_uid);
757 tprintf("si_value={int=%u, ptr=%#lx}",
759 (unsigned long) sip->si_ptr);
769 #endif /* SVR4 || LINUX */
774 parse_sigset_t (const char *str, sigset_t *set)
782 p = strchr(str, '\n');
784 p = strchr(str, '\0');
785 for (i = 0; p-- > str; i += 4) {
786 if (*p >= '0' && *p <= '9')
788 else if (*p >= 'a' && *p <= 'f')
790 else if (*p >= 'A' && *p <= 'F')
795 sigaddset(set, i + 1);
797 sigaddset(set, i + 2);
799 sigaddset(set, i + 3);
801 sigaddset(set, i + 4);
808 * Check process TCP for the disposition of signal SIG.
809 * Return 1 if the process would somehow manage to survive signal SIG,
810 * else return 0. This routine will never be called with SIGKILL.
813 sigishandled(tcp, sig)
823 sigset_t ignored, caught;
827 * Since procfs doesn't interfere with wait I think it is safe
828 * to punt on this question. If not, the information is there.
840 #if defined(SIGURG) && SIGURG != SIGIO
844 /* Gloria Gaynor says ... */
852 /* This is incredibly costly but it's worth it. */
853 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
854 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
855 doesn't handle real-time signals). */
856 sprintf(sname, "/proc/%d/status", tcp->pid);
857 if ((sfd = open(sname, O_RDONLY)) == -1) {
861 i = read(sfd, buf, sizeof(buf));
865 * Skip the extraneous fields. We need to skip
866 * command name has any spaces in it. So be it.
868 s = strstr(buf, "SigIgn:\t");
871 fprintf(stderr, "/proc/pid/status format error\n");
874 parse_sigset_t(s + 8, &ignored);
876 s = strstr(buf, "SigCgt:\t");
879 fprintf(stderr, "/proc/pid/status format error\n");
882 parse_sigset_t(s + 8, &caught);
885 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
886 *(long long *) &ignored, *(long long *) &caught, sig);
888 if (sigismember(&ignored, sig) || sigismember(&caught, sig))
895 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
896 (long *) &u_signal) < 0) {
899 if (u_signal != SIG_DFL)
906 #if defined(SUNOS4) || defined(FREEBSD)
916 printsignal(tcp->u_arg[0]);
918 addr = tcp->u_arg[1];
920 addr = tcp->u_arg[2];
924 else if (!verbose(tcp))
925 tprintf("%#lx", addr);
926 else if (umove(tcp, addr, &sv) < 0)
929 switch ((int) sv.sv_handler) {
931 tprintf("{SIG_ERR}");
934 tprintf("{SIG_DFL}");
937 if (tcp->u_arg[0] == SIGTRAP) {
938 tcp->flags |= TCB_SIGTRAPPED;
939 kill(tcp->pid, SIGSTOP);
941 tprintf("{SIG_IGN}");
944 if (tcp->u_arg[0] == SIGTRAP) {
945 tcp->flags |= TCB_SIGTRAPPED;
946 kill(tcp->pid, SIGSTOP);
951 if (tcp->u_arg[0] == SIGTRAP) {
952 tcp->flags |= TCB_SIGTRAPPED;
953 kill(tcp->pid, SIGSTOP);
955 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
956 printsigmask(&sv.sv_mask, 0);
958 if (!printflags(sigvec_flags, sv.sv_flags))
972 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
974 long_to_sigset(tcp->u_arg[0], &sigm);
975 printsigmask(&sigm, 0);
988 addr = tcp->u_arg[0];
990 addr = tcp->u_arg[1];
993 else if (umove(tcp, addr, &ss) < 0)
994 tprintf("%#lx", addr);
996 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
997 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
1011 #endif /* SUNOS4 || FREEBSD */
1019 if (entering(tcp)) {
1021 long_to_sigset(tcp->u_arg[0], &sigm);
1022 printsigmask(&sigm, 0);
1024 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
1025 /* Mark attempt to block SIGTRAP */
1026 tcp->flags |= TCB_SIGTRAPPED;
1027 /* Send unblockable signal */
1028 kill(tcp->pid, SIGSTOP);
1030 #endif /* !USE_PROCFS */
1032 else if (!syserror(tcp)) {
1034 long_to_sigset(tcp->u_rval, &sigm);
1035 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
1037 return RVAL_HEX | RVAL_STR;
1046 return sys_sigsetmask(tcp);
1051 #ifdef HAVE_SIGACTION
1054 struct old_sigaction {
1055 __sighandler_t __sa_handler;
1056 unsigned long sa_mask;
1057 unsigned long sa_flags;
1058 void (*sa_restorer)(void);
1060 #define SA_HANDLER __sa_handler
1064 #define SA_HANDLER sa_handler
1074 struct old_sigaction sa;
1076 struct sigaction sa;
1080 if (entering(tcp)) {
1081 printsignal(tcp->u_arg[0]);
1083 addr = tcp->u_arg[1];
1085 addr = tcp->u_arg[2];
1088 else if (!verbose(tcp))
1089 tprintf("%#lx", addr);
1090 else if (umove(tcp, addr, &sa) < 0)
1093 switch ((long) sa.SA_HANDLER) {
1094 case (long) SIG_ERR:
1095 tprintf("{SIG_ERR}");
1097 case (long) SIG_DFL:
1098 tprintf("{SIG_DFL}");
1100 case (long) SIG_IGN:
1102 if (tcp->u_arg[0] == SIGTRAP) {
1103 tcp->flags |= TCB_SIGTRAPPED;
1104 kill(tcp->pid, SIGSTOP);
1106 #endif /* !USE_PROCFS */
1107 tprintf("{SIG_IGN}");
1111 if (tcp->u_arg[0] == SIGTRAP) {
1112 tcp->flags |= TCB_SIGTRAPPED;
1113 kill(tcp->pid, SIGSTOP);
1115 #endif /* !USE_PROCFS */
1116 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
1118 printsigmask (&sa.sa_mask, 0);
1120 long_to_sigset(sa.sa_mask, &sigset);
1121 printsigmask(&sigset, 0);
1124 if (!printflags(sigact_flags, sa.sa_flags))
1127 if (sa.sa_flags & SA_RESTORER)
1128 tprintf(", %p", sa.sa_restorer);
1137 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1146 if (entering(tcp)) {
1147 printsignal(tcp->u_arg[0]);
1149 switch (tcp->u_arg[1]) {
1158 if (tcp->u_arg[0] == SIGTRAP) {
1159 tcp->flags |= TCB_SIGTRAPPED;
1160 kill(tcp->pid, SIGSTOP);
1162 #endif /* !USE_PROCFS */
1167 if (tcp->u_arg[0] == SIGTRAP) {
1168 tcp->flags |= TCB_SIGTRAPPED;
1169 kill(tcp->pid, SIGSTOP);
1171 #endif /* !USE_PROCFS */
1172 tprintf("%#lx", tcp->u_arg[1]);
1177 switch (tcp->u_rval) {
1179 tcp->auxstr = "SIG_ERR"; break;
1181 tcp->auxstr = "SIG_DFL"; break;
1183 tcp->auxstr = "SIG_IGN"; break;
1187 return RVAL_HEX | RVAL_STR;
1195 if (entering(tcp)) {
1196 printsignal(tcp->u_arg[0]);
1201 #endif /* HAVE_SIGACTION */
1210 struct pt_regs regs;
1211 struct sigcontext_struct sc;
1213 if (entering(tcp)) {
1216 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)®s) == -1)
1219 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1223 tcp->u_arg[1] = sc.oldmask;
1226 long_to_sigset(tcp->u_arg[1], &sigm);
1227 tcp->u_rval = tcp->u_error = 0;
1228 if (tcp->u_arg[0] == 0)
1230 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1231 return RVAL_NONE | RVAL_STR;
1234 #elif defined(S390) || defined(S390X)
1236 struct sigcontext_struct sc;
1238 if (entering(tcp)) {
1240 if (upeek(tcp->pid,PT_GPR15,&usp)<0)
1242 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
1245 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
1247 tcp->u_rval = tcp->u_error = 0;
1248 if (tcp->u_arg[0] == 0)
1250 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
1251 return RVAL_NONE | RVAL_STR;
1257 struct sigcontext_struct sc;
1259 if (entering(tcp)) {
1261 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
1263 if (umove(tcp, esp, &sc) < 0)
1266 tcp->u_arg[1] = sc.oldmask;
1270 long_to_sigset(tcp->u_arg[1], &sigm);
1271 tcp->u_rval = tcp->u_error = 0;
1272 if (tcp->u_arg[0] == 0)
1274 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1275 return RVAL_NONE | RVAL_STR;
1280 struct sigcontext sc;
1283 if (entering(tcp)) {
1284 /* offset of sigcontext in the kernel's sigframe structure: */
1285 # define SIGFRAME_SC_OFFSET 0x90
1287 if (upeek(tcp->pid, PT_R12, &sp) < 0)
1289 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
1292 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
1297 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
1298 tcp->u_rval = tcp->u_error = 0;
1299 if (tcp->u_arg[0] == 0)
1301 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1302 return RVAL_NONE | RVAL_STR;
1308 struct sigcontext_struct sc;
1310 if (entering(tcp)) {
1312 if (upeek(tcp->pid, sizeof(unsigned long)*PT_R1, &esp) < 0)
1314 if (umove(tcp, esp, &sc) < 0)
1317 tcp->u_arg[1] = sc.oldmask;
1321 long_to_sigset(tcp->u_arg[1], &sigm);
1322 tcp->u_rval = tcp->u_error = 0;
1323 if (tcp->u_arg[0] == 0)
1325 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1326 return RVAL_NONE | RVAL_STR;
1329 #else /* !POWERPC */
1332 struct sigcontext sc;
1334 if (entering(tcp)) {
1336 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
1338 if (umove(tcp, usp, &sc) < 0)
1341 tcp->u_arg[1] = sc.sc_mask;
1345 long_to_sigset(tcp->u_arg[1], &sigm);
1346 tcp->u_rval = tcp->u_error = 0;
1347 if (tcp->u_arg[0] == 0)
1349 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1350 return RVAL_NONE | RVAL_STR;
1356 struct sigcontext_struct sc;
1358 if (entering(tcp)) {
1360 if (upeek(tcp->pid, REG_FP, &fp) < 0)
1362 if (umove(tcp, fp, &sc) < 0)
1365 tcp->u_arg[1] = sc.sc_mask;
1369 long_to_sigset(tcp->u_arg[1], &sigm);
1370 tcp->u_rval = tcp->u_error = 0;
1371 if (tcp->u_arg[0] == 0)
1373 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
1374 return RVAL_NONE | RVAL_STR;
1383 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
1384 perror("sigreturn: PTRACE_GETREGS ");
1390 if(umove(tcp, i1, &si) < 0) {
1391 perror("sigreturn: umove ");
1395 tcp->u_arg[1] = si.si_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;
1409 struct sigcontext sc;
1413 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1415 if (umove(tcp, sp, &sc) < 0)
1418 tcp->u_arg[1] = sc.sc_sigset;
1420 tcp->u_rval = tcp->u_error = 0;
1421 if(tcp->u_arg[0] == 0)
1423 tcp->auxstr = sprintsigmask("mask now ", tcp->u_arg[1]);
1424 return RVAL_NONE | RVAL_STR;
1428 #warning No sys_sigreturn() for this architecture
1429 #warning (no problem, just a reminder :-)
1435 #endif /* !POWERPC */
1447 long_to_sigset(tcp->u_rval, &sigm);
1448 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
1450 return RVAL_HEX | RVAL_STR;
1457 if (entering(tcp)) {
1459 long_to_sigset(tcp->u_arg[2], &sigm);
1461 /* first two are not really arguments, but print them anyway */
1462 /* nevermind, they are an anachronism now, too bad... */
1463 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
1465 printsigmask(&sigm, 0);
1472 #if defined(SVR4) || defined(FREEBSD)
1480 if (entering(tcp)) {
1481 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1484 printsigmask(&sigset, 0);
1489 static struct xlat ucontext_flags[] = {
1490 { UC_SIGMASK, "UC_SIGMASK" },
1491 { UC_STACK, "UC_STACK" },
1492 { UC_CPU, "UC_CPU" },
1494 { UC_FPU, "UC_FPU" },
1497 { UC_INTR, "UC_INTR" },
1501 #endif /* !FREEBSD */
1502 #endif /* SVR4 || FREEBSD */
1504 #if defined SVR4 || defined LINUX || defined FREEBSD
1505 #if defined LINUX && !defined SS_ONSTACK
1506 #define SS_ONSTACK 1
1507 #define SS_DISABLE 2
1508 #if __GLIBC_MINOR__ == 0
1518 #define stack_t struct sigaltstack
1521 static struct xlat sigaltstack_flags[] = {
1522 { SS_ONSTACK, "SS_ONSTACK" },
1523 { SS_DISABLE, "SS_DISABLE" },
1530 printcontext(tcp, ucp)
1536 tprintf("uc_flags=");
1537 if (!printflags(ucontext_flags, ucp->uc_flags))
1539 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1541 tprintf("uc_sigmask=");
1542 printsigmask(&ucp->uc_sigmask, 0);
1544 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1545 (unsigned long) ucp->uc_stack.ss_sp,
1546 ucp->uc_stack.ss_size);
1547 if (!printflags(sigaltstack_flags, ucp->uc_stack.ss_flags))
1562 tprintf("%#lx", tcp->u_arg[0]);
1563 else if (!tcp->u_arg[0])
1565 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1568 printcontext(tcp, &uc);
1579 if (entering(tcp)) {
1582 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1585 printcontext(tcp, &uc);
1588 tcp->u_rval = tcp->u_error = 0;
1589 if (tcp->u_arg[0] == 0)
1598 #if defined(LINUX) || defined(FREEBSD)
1601 print_stack_t(tcp, addr)
1606 if (umove(tcp, addr, &ss) < 0)
1608 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1609 if (!printflags(sigaltstack_flags, ss.ss_flags))
1611 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1616 sys_sigaltstack(tcp)
1619 if (entering(tcp)) {
1620 if (tcp->u_arg[0] == 0)
1622 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1627 if (tcp->u_arg[1] == 0)
1629 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1636 #ifdef HAVE_SIGACTION
1639 sys_sigprocmask(tcp)
1643 if (entering(tcp)) {
1644 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1646 printsigmask(tcp->u_arg[1], 0);
1648 else if (!syserror(tcp)) {
1649 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
1650 return RVAL_HEX | RVAL_STR;
1655 if (entering(tcp)) {
1657 if (tcp->u_arg[0] == 0)
1661 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1665 else if (copy_sigset(tcp, tcp->u_arg[1], &sigset) < 0)
1666 tprintf("%#lx, ", tcp->u_arg[1]);
1668 printsigmask(&sigset, 0);
1675 else if (syserror(tcp))
1676 tprintf("%#lx", tcp->u_arg[2]);
1677 else if (copy_sigset(tcp, tcp->u_arg[2], &sigset) < 0)
1680 printsigmask(&sigset, 0);
1686 #endif /* HAVE_SIGACTION */
1692 if (entering(tcp)) {
1693 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
1702 return sys_kill(tcp);
1710 if (entering(tcp)) {
1711 tprintf("%ld, %ld, %s",
1712 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1726 tprintf("%#lx", tcp->u_arg[0]);
1727 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1730 printsigmask(&sigset, 0);
1735 int sys_sigwait(tcp)
1740 if (entering(tcp)) {
1741 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1744 printsigmask(&sigset, 0);
1747 if (!syserror(tcp)) {
1748 tcp->auxstr = signalent[tcp->u_rval];
1749 return RVAL_DECIMAL | RVAL_STR;
1758 sys_rt_sigprocmask(tcp)
1763 /* Note: arg[3] is the length of the sigset. */
1764 if (entering(tcp)) {
1765 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1769 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
1770 tprintf("%#lx, ", tcp->u_arg[1]);
1772 printsigmask(&sigset, 1);
1780 else if (syserror(tcp))
1781 tprintf("%#lx", tcp->u_arg[2]);
1782 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
1785 printsigmask(&sigset, 1);
1786 tprintf(", %lu", tcp->u_arg[3]);
1792 /* Structure describing the action to be taken when a signal arrives. */
1793 struct new_sigaction
1797 __sighandler_t __sa_handler;
1798 void (*__sa_sigaction) (int, siginfo_t *, void *);
1800 __sigaction_handler;
1801 unsigned long sa_flags;
1802 void (*sa_restorer) (void);
1803 unsigned long int sa_mask[2];
1808 sys_rt_sigaction(tcp)
1811 struct new_sigaction sa;
1815 if (entering(tcp)) {
1816 printsignal(tcp->u_arg[0]);
1818 addr = tcp->u_arg[1];
1820 addr = tcp->u_arg[2];
1823 else if (!verbose(tcp))
1824 tprintf("%#lx", addr);
1825 else if (umove(tcp, addr, &sa) < 0)
1828 switch ((long) sa.__sigaction_handler.__sa_handler) {
1829 case (long) SIG_ERR:
1830 tprintf("{SIG_ERR}");
1832 case (long) SIG_DFL:
1833 tprintf("{SIG_DFL}");
1835 case (long) SIG_IGN:
1836 tprintf("{SIG_IGN}");
1840 (long) sa.__sigaction_handler.__sa_handler);
1841 sigemptyset(&sigset);
1843 if (tcp->u_arg[4] <= sizeof(sigset))
1844 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1846 if (tcp->u_arg[3] <= sizeof(sigset))
1847 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1850 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1851 printsigmask(&sigset, 1);
1853 if (!printflags(sigact_flags, sa.sa_flags))
1856 if (sa.sa_flags & SA_RESTORER)
1857 tprintf(", %p", sa.sa_restorer);
1866 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1867 #elif defined(ALPHA)
1868 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1870 tprintf(", %lu", addr = tcp->u_arg[3]);
1876 sys_rt_sigpending(tcp)
1883 tprintf("%#lx", tcp->u_arg[0]);
1884 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1885 &sigset, tcp->u_arg[1]) < 0)
1888 printsigmask(&sigset, 1);
1893 sys_rt_sigsuspend(tcp)
1896 if (entering(tcp)) {
1898 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1901 printsigmask(&sigm, 1);
1906 sys_rt_sigqueueinfo(tcp)
1909 if (entering(tcp)) {
1911 tprintf("%lu, ", tcp->u_arg[0]);
1912 printsignal(tcp->u_arg[1]);
1914 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1915 tprintf("%#lx", tcp->u_arg[2]);
1917 printsiginfo(&si, verbose (tcp));
1922 int sys_rt_sigtimedwait(tcp)
1925 if (entering(tcp)) {
1928 if (copy_sigset_len(tcp, tcp->u_arg[0],
1929 &sigset, tcp->u_arg[3]) < 0)
1932 printsigmask(&sigset, 1);
1937 tprintf("%#lx", tcp->u_arg[0]);
1940 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1941 tprintf("%#lx", tcp->u_arg[1]);
1943 printsiginfo(&si, verbose (tcp));
1945 tprintf(", %#lx", tcp->u_arg[2]);
1946 tprintf(", %d", (int) tcp->u_arg[3]);