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.
44 #include <sys/ucontext.h>
49 #ifndef PTRACE_PEEKUSR
50 # define PTRACE_PEEKUSR PTRACE_PEEKUSER
52 #ifndef PTRACE_POKEUSR
53 # define PTRACE_POKEUSR PTRACE_POKEUSER
55 #elif defined(HAVE_LINUX_PTRACE_H)
57 # ifdef HAVE_STRUCT_IA64_FPREG
58 # define ia64_fpreg XXX_ia64_fpreg
60 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS
61 # define pt_all_user_regs XXX_pt_all_user_regs
63 #include <linux/ptrace.h>
65 # undef pt_all_user_regs
72 # include <asm/ptrace_offsets.h>
75 #if defined (LINUX) && defined (SPARC64)
76 # undef PTRACE_GETREGS
77 # define PTRACE_GETREGS PTRACE_GETREGS64
78 # undef PTRACE_SETREGS
79 # define PTRACE_SETREGS PTRACE_SETREGS64
80 #endif /* LINUX && SPARC64 */
82 #if defined (SPARC) || defined (SPARC64) || defined (MIPS)
84 struct pt_regs si_regs;
87 #elif defined HAVE_ASM_SIGCONTEXT_H
88 #if !defined(IA64) && !defined(X86_64)
89 #include <asm/sigcontext.h>
90 #endif /* !IA64 && !X86_64 */
91 #else /* !HAVE_ASM_SIGCONTEXT_H */
92 #if defined I386 && !defined HAVE_STRUCT_SIGCONTEXT_STRUCT
93 struct sigcontext_struct {
94 unsigned short gs, __gsh;
95 unsigned short fs, __fsh;
96 unsigned short es, __esh;
97 unsigned short ds, __dsh;
106 unsigned long trapno;
109 unsigned short cs, __csh;
110 unsigned long eflags;
111 unsigned long esp_at_signal;
112 unsigned short ss, __ssh;
114 unsigned long oldmask;
118 #if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
121 unsigned long sc_mask;
122 unsigned long sc_usp;
127 unsigned short sc_sr;
129 unsigned short sc_formatvec;
133 #endif /* !HAVE_ASM_SIGCONTEXT_H */
136 #warning: NSIG is not defined, using 32
140 /* Ugh. Is this really correct? ARM has no RT signals?! */
147 #if defined(SUNOS4) || defined(FREEBSD)
149 static const struct xlat sigvec_flags[] = {
150 { SV_ONSTACK, "SV_ONSTACK" },
151 { SV_INTERRUPT, "SV_INTERRUPT" },
152 { SV_RESETHAND, "SV_RESETHAND" },
153 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
157 #endif /* SUNOS4 || FREEBSD */
159 #ifdef HAVE_SIGACTION
161 #if defined LINUX && (defined I386 || defined X86_64)
162 /* The libc headers do not define this constant since it should only be
163 used by the implementation. So we define it here. */
165 # define SA_RESTORER 0x04000000
169 static const struct xlat sigact_flags[] = {
171 { SA_RESTORER, "SA_RESTORER" },
174 { SA_STACK, "SA_STACK" },
177 { SA_RESTART, "SA_RESTART" },
180 { SA_INTERRUPT, "SA_INTERRUPT" },
183 { SA_NODEFER, "SA_NODEFER" },
185 #if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
186 { SA_NOMASK, "SA_NOMASK" },
189 { SA_RESETHAND, "SA_RESETHAND" },
191 #if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
192 { SA_ONESHOT, "SA_ONESHOT" },
195 { SA_SIGINFO, "SA_SIGINFO" },
198 { SA_RESETHAND, "SA_RESETHAND" },
201 { SA_ONSTACK, "SA_ONSTACK" },
204 { SA_NODEFER, "SA_NODEFER" },
207 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
210 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
213 { _SA_BSDCALL, "_SA_BSDCALL" },
216 { SA_NOPTRACE, "SA_NOPTRACE" },
221 static const struct xlat sigprocmaskcmds[] = {
222 { SIG_BLOCK, "SIG_BLOCK" },
223 { SIG_UNBLOCK, "SIG_UNBLOCK" },
224 { SIG_SETMASK, "SIG_SETMASK" },
226 { SIG_SETMASK32,"SIG_SETMASK32" },
231 #endif /* HAVE_SIGACTION */
233 /* Anonymous realtime signals. */
234 /* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
235 constant. This is what we want. Otherwise, just use SIGRTMIN. */
238 #define __SIGRTMIN SIGRTMIN
239 #define __SIGRTMAX SIGRTMAX /* likewise */
243 /* Note on the size of sigset_t:
245 * In glibc, sigset_t is an array with space for 1024 bits (!),
246 * even though all arches supported by Linux have only 64 signals
247 * except MIPS, which has 128. IOW, it is 128 bytes long.
249 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
250 * However, some old syscall return only 32 lower bits (one word).
251 * Example: sys_sigpending vs sys_rt_sigpending.
253 * Be aware of this fact when you try to
254 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
255 * - sizeof(sigset_t) is much bigger than you think,
256 * it may overflow tcp->u_arg[] array, and it may try to copy more data
257 * than is really available in <something>.
259 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
260 * may be a bad idea: it'll try to read much more data than needed
261 * to fetch a sigset_t.
262 * Use (NSIG / 8) as a size instead.
268 static char buf[sizeof("SIGRT_%d") + sizeof(int)*3];
270 if (sig >= 0 && sig < nsignals)
271 return signalent[sig];
273 if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
274 sprintf(buf, "SIGRT_%d", (int)(sig - __SIGRTMIN));
278 sprintf(buf, "%d", sig);
284 long_to_sigset(long l, sigset_t *s)
292 copy_sigset_len(struct tcb *tcp, long addr, sigset_t *s, int 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(const char *str, sigset_t *mask, int rt)
311 /* set might include realtime sigs */
313 /* Was [8 * sizeof(sigset_t) * 8], but
314 * glibc sigset_t is huge (1024 bits = 128 *bytes*),
315 * and we were ending up with 8k (!) buffer here.
317 * No Unix system can have sig > 255
318 * (waitpid API won't be able to indicate death from one)
319 * and sig 0 doesn't exist either.
320 * Therefore max possible no of sigs is 255: 1..255
322 static char outstr[8 * (255 * 2 / 3)];
333 maxsigs = __SIGRTMAX; /* instead */
335 s = stpcpy(outstr, str);
337 for (i = 1; i < maxsigs; i++) {
338 if (sigismember(mask, i) == 1)
342 /* 1: show mask members, 0: show those which are NOT in mask */
343 show_members = (nsigs < nsignals * 2 / 3);
348 for (i = 1; i < maxsigs; i++) {
349 if (sigismember(mask, i) == show_members) {
350 /* real-time signals on solaris don't have
356 s = stpcpy(s, signalent[i] + 3);
359 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
360 sprintf(tsig, "RT_%u", i - __SIGRTMIN);
363 #endif /* SIGRTMIN */
365 sprintf(tsig, "%u", i);
379 printsigmask(sigset_t *mask, int rt)
381 tprints(sprintsigmask("", mask, rt));
387 tprints(signame(nr));
391 print_sigset(struct tcb *tcp, long addr, int rt)
397 else if (copy_sigset(tcp, addr, &ss) < 0)
398 tprintf("%#lx", addr);
400 printsigmask(&ss, rt);
406 #define ILL_ILLOPC 1 /* illegal opcode */
407 #define ILL_ILLOPN 2 /* illegal operand */
408 #define ILL_ILLADR 3 /* illegal addressing mode */
409 #define ILL_ILLTRP 4 /* illegal trap */
410 #define ILL_PRVOPC 5 /* privileged opcode */
411 #define ILL_PRVREG 6 /* privileged register */
412 #define ILL_COPROC 7 /* coprocessor error */
413 #define ILL_BADSTK 8 /* internal stack error */
414 #define FPE_INTDIV 1 /* integer divide by zero */
415 #define FPE_INTOVF 2 /* integer overflow */
416 #define FPE_FLTDIV 3 /* floating point divide by zero */
417 #define FPE_FLTOVF 4 /* floating point overflow */
418 #define FPE_FLTUND 5 /* floating point underflow */
419 #define FPE_FLTRES 6 /* floating point inexact result */
420 #define FPE_FLTINV 7 /* floating point invalid operation */
421 #define FPE_FLTSUB 8 /* subscript out of range */
422 #define SEGV_MAPERR 1 /* address not mapped to object */
423 #define SEGV_ACCERR 2 /* invalid permissions for mapped object */
424 #define BUS_ADRALN 1 /* invalid address alignment */
425 #define BUS_ADRERR 2 /* non-existant physical address */
426 #define BUS_OBJERR 3 /* object specific hardware error */
427 #define TRAP_BRKPT 1 /* process breakpoint */
428 #define TRAP_TRACE 2 /* process trace trap */
429 #define CLD_EXITED 1 /* child has exited */
430 #define CLD_KILLED 2 /* child was killed */
431 #define CLD_DUMPED 3 /* child terminated abnormally */
432 #define CLD_TRAPPED 4 /* traced child has trapped */
433 #define CLD_STOPPED 5 /* child has stopped */
434 #define CLD_CONTINUED 6 /* stopped child has continued */
435 #define POLL_IN 1 /* data input available */
436 #define POLL_OUT 2 /* output buffers available */
437 #define POLL_MSG 3 /* input message available */
438 #define POLL_ERR 4 /* i/o error */
439 #define POLL_PRI 5 /* high priority input available */
440 #define POLL_HUP 6 /* device disconnected */
441 #define SI_KERNEL 0x80 /* sent by kernel */
442 #define SI_USER 0 /* sent by kill, sigsend, raise */
443 #define SI_QUEUE -1 /* sent by sigqueue */
444 #define SI_TIMER -2 /* sent by timer expiration */
445 #define SI_MESGQ -3 /* sent by real time mesq state change */
446 #define SI_ASYNCIO -4 /* sent by AIO completion */
447 #define SI_SIGIO -5 /* sent by SIGIO */
448 #define SI_TKILL -6 /* sent by tkill */
449 #define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
451 #define SI_FROMUSER(sip) ((sip)->si_code <= 0)
455 #if __GLIBC_MINOR__ < 1
456 /* Type for data associated with a signal. */
463 # define __SI_MAX_SIZE 128
464 # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof(int)) - 3)
466 typedef struct siginfo
468 int si_signo; /* Signal number. */
469 int si_errno; /* If non-zero, an errno value associated with
470 this signal, as defined in <errno.h>. */
471 int si_code; /* Signal code. */
475 int _pad[__SI_PAD_SIZE];
480 __pid_t si_pid; /* Sending process ID. */
481 __uid_t si_uid; /* Real user ID of sending process. */
484 /* POSIX.1b timers. */
487 unsigned int _timer1;
488 unsigned int _timer2;
491 /* POSIX.1b signals. */
494 __pid_t si_pid; /* Sending process ID. */
495 __uid_t si_uid; /* Real user ID of sending process. */
496 sigval_t si_sigval; /* Signal value. */
502 __pid_t si_pid; /* Which child. */
503 int si_status; /* Exit value or signal. */
508 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
511 void *si_addr; /* Faulting insn/memory ref. */
517 int si_band; /* Band event for SIGPOLL. */
523 #define si_pid _sifields._kill.si_pid
524 #define si_uid _sifields._kill.si_uid
525 #define si_status _sifields._sigchld.si_status
526 #define si_utime _sifields._sigchld.si_utime
527 #define si_stime _sifields._sigchld.si_stime
528 #define si_value _sifields._rt.si_sigval
529 #define si_int _sifields._rt.si_sigval.sival_int
530 #define si_ptr _sifields._rt.si_sigval.sival_ptr
531 #define si_addr _sifields._sigfault.si_addr
532 #define si_band _sifields._sigpoll.si_band
533 #define si_fd _sifields._sigpoll.si_fd
539 #if defined (SVR4) || defined (LINUX)
541 static const struct xlat siginfo_codes[] = {
543 { SI_KERNEL, "SI_KERNEL" },
546 { SI_USER, "SI_USER" },
549 { SI_QUEUE, "SI_QUEUE" },
552 { SI_TIMER, "SI_TIMER" },
555 { SI_MESGQ, "SI_MESGQ" },
558 { SI_ASYNCIO, "SI_ASYNCIO" },
561 { SI_SIGIO, "SI_SIGIO" },
564 { SI_TKILL, "SI_TKILL" },
567 { SI_ASYNCNL, "SI_ASYNCNL" },
570 { SI_NOINFO, "SI_NOINFO" },
573 { SI_LWP, "SI_LWP" },
578 static const struct xlat sigill_codes[] = {
579 { ILL_ILLOPC, "ILL_ILLOPC" },
580 { ILL_ILLOPN, "ILL_ILLOPN" },
581 { ILL_ILLADR, "ILL_ILLADR" },
582 { ILL_ILLTRP, "ILL_ILLTRP" },
583 { ILL_PRVOPC, "ILL_PRVOPC" },
584 { ILL_PRVREG, "ILL_PRVREG" },
585 { ILL_COPROC, "ILL_COPROC" },
586 { ILL_BADSTK, "ILL_BADSTK" },
590 static const struct xlat sigfpe_codes[] = {
591 { FPE_INTDIV, "FPE_INTDIV" },
592 { FPE_INTOVF, "FPE_INTOVF" },
593 { FPE_FLTDIV, "FPE_FLTDIV" },
594 { FPE_FLTOVF, "FPE_FLTOVF" },
595 { FPE_FLTUND, "FPE_FLTUND" },
596 { FPE_FLTRES, "FPE_FLTRES" },
597 { FPE_FLTINV, "FPE_FLTINV" },
598 { FPE_FLTSUB, "FPE_FLTSUB" },
602 static const struct xlat sigtrap_codes[] = {
603 { TRAP_BRKPT, "TRAP_BRKPT" },
604 { TRAP_TRACE, "TRAP_TRACE" },
608 static const struct xlat sigchld_codes[] = {
609 { CLD_EXITED, "CLD_EXITED" },
610 { CLD_KILLED, "CLD_KILLED" },
611 { CLD_DUMPED, "CLD_DUMPED" },
612 { CLD_TRAPPED, "CLD_TRAPPED" },
613 { CLD_STOPPED, "CLD_STOPPED" },
614 { CLD_CONTINUED,"CLD_CONTINUED" },
618 static const struct xlat sigpoll_codes[] = {
619 { POLL_IN, "POLL_IN" },
620 { POLL_OUT, "POLL_OUT" },
621 { POLL_MSG, "POLL_MSG" },
622 { POLL_ERR, "POLL_ERR" },
623 { POLL_PRI, "POLL_PRI" },
624 { POLL_HUP, "POLL_HUP" },
628 static const struct xlat sigprof_codes[] = {
630 { PROF_SIG, "PROF_SIG" },
636 static const struct xlat sigemt_codes[] = {
638 { EMT_TAGOVF, "EMT_TAGOVF" },
644 static const struct xlat sigsegv_codes[] = {
645 { SEGV_MAPERR, "SEGV_MAPERR" },
646 { SEGV_ACCERR, "SEGV_ACCERR" },
650 static const struct xlat sigbus_codes[] = {
651 { BUS_ADRALN, "BUS_ADRALN" },
652 { BUS_ADRERR, "BUS_ADRERR" },
653 { BUS_OBJERR, "BUS_OBJERR" },
658 printsiginfo(siginfo_t *sip, int verbose)
662 if (sip->si_signo == 0) {
666 tprints("{si_signo=");
667 printsignal(sip->si_signo);
668 code = xlookup(siginfo_codes, sip->si_code);
670 switch (sip->si_signo) {
672 code = xlookup(sigtrap_codes, sip->si_code);
675 code = xlookup(sigchld_codes, sip->si_code);
678 code = xlookup(sigpoll_codes, sip->si_code);
681 code = xlookup(sigprof_codes, sip->si_code);
684 code = xlookup(sigill_codes, sip->si_code);
688 code = xlookup(sigemt_codes, sip->si_code);
692 code = xlookup(sigfpe_codes, sip->si_code);
695 code = xlookup(sigsegv_codes, sip->si_code);
698 code = xlookup(sigbus_codes, sip->si_code);
703 tprintf(", si_code=%s", code);
705 tprintf(", si_code=%#x", sip->si_code);
707 if (sip->si_code != SI_NOINFO)
711 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
712 tprintf(", si_errno=%d", sip->si_errno);
714 tprintf(", si_errno=%s",
715 errnoent[sip->si_errno]);
718 if (SI_FROMUSER(sip)) {
719 tprintf(", si_pid=%lu, si_uid=%lu",
720 (unsigned long) sip->si_pid,
721 (unsigned long) sip->si_uid);
722 switch (sip->si_code) {
733 tprintf(", si_value=%d", sip->si_int);
743 tprintf(", si_value={int=%u, ptr=%#lx}",
745 (unsigned long) sip->si_ptr);
751 #endif /* SI_FROMUSER */
753 switch (sip->si_signo) {
755 tprintf(", si_pid=%ld, si_status=",
757 if (sip->si_code == CLD_EXITED)
758 tprintf("%d", sip->si_status);
760 printsignal(sip->si_status);
765 tprintf(", si_utime=%lu, si_stime=%lu",
770 case SIGILL: case SIGFPE:
771 case SIGSEGV: case SIGBUS:
772 tprintf(", si_addr=%#lx",
773 (unsigned long) sip->si_addr);
776 switch (sip->si_code) {
777 case POLL_IN: case POLL_OUT: case POLL_MSG:
778 tprintf(", si_band=%ld",
779 (long) sip->si_band);
785 if (sip->si_pid || sip->si_uid)
786 tprintf(", si_pid=%lu, si_uid=%lu",
787 (unsigned long) sip->si_pid,
788 (unsigned long) sip->si_uid);
794 tprintf(", si_value={int=%u, ptr=%#lx}",
796 (unsigned long) sip->si_ptr);
806 #endif /* SVR4 || LINUX */
808 #if defined(SUNOS4) || defined(FREEBSD)
811 sys_sigvec(struct tcb *tcp)
817 printsignal(tcp->u_arg[0]);
819 addr = tcp->u_arg[1];
821 addr = tcp->u_arg[2];
825 else if (!verbose(tcp))
826 tprintf("%#lx", addr);
827 else if (umove(tcp, addr, &sv) < 0)
830 switch ((int) sv.sv_handler) {
832 tprints("{SIG_ERR}");
835 tprints("{SIG_DFL}");
838 tprints("{SIG_IGN}");
841 tprints("{SIG_HOLD}");
844 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
845 printsigmask(&sv.sv_mask, 0);
847 printflags(sigvec_flags, sv.sv_flags, "SV_???");
857 sys_sigpause(struct tcb *tcp)
859 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
861 long_to_sigset(tcp->u_arg[0], &sigm);
862 printsigmask(&sigm, 0);
868 sys_sigstack(struct tcb *tcp)
874 addr = tcp->u_arg[0];
876 addr = tcp->u_arg[1];
879 else if (umove(tcp, addr, &ss) < 0)
880 tprintf("%#lx", addr);
882 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
883 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
891 sys_sigcleanup(struct tcb *tcp)
896 #endif /* SUNOS4 || FREEBSD */
901 sys_sigsetmask(struct tcb *tcp)
905 long_to_sigset(tcp->u_arg[0], &sigm);
906 printsigmask(&sigm, 0);
908 else if (!syserror(tcp)) {
910 long_to_sigset(tcp->u_rval, &sigm);
911 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
913 return RVAL_HEX | RVAL_STR;
918 #if defined(SUNOS4) || defined(FREEBSD)
920 sys_sigblock(struct tcb *tcp)
922 return sys_sigsetmask(tcp);
924 #endif /* SUNOS4 || FREEBSD */
928 #ifdef HAVE_SIGACTION
931 struct old_sigaction {
932 __sighandler_t __sa_handler;
933 unsigned long sa_mask;
934 unsigned long sa_flags;
935 void (*sa_restorer)(void);
937 #define SA_HANDLER __sa_handler
941 #define SA_HANDLER sa_handler
945 sys_sigaction(struct tcb *tcp)
950 struct old_sigaction sa;
957 printsignal(tcp->u_arg[0]);
959 addr = tcp->u_arg[1];
961 addr = tcp->u_arg[2];
964 else if (!verbose(tcp))
965 tprintf("%#lx", addr);
966 else if (umove(tcp, addr, &sa) < 0)
969 /* Architectures using function pointers, like
970 * hppa, may need to manipulate the function pointer
971 * to compute the result of a comparison. However,
972 * the SA_HANDLER function pointer exists only in
973 * the address space of the traced process, and can't
974 * be manipulated by strace. In order to prevent the
975 * compiler from generating code to manipulate
976 * SA_HANDLER we cast the function pointers to long. */
977 if ((long)sa.SA_HANDLER == (long)SIG_ERR)
978 tprints("{SIG_ERR, ");
979 else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
980 tprints("{SIG_DFL, ");
981 else if ((long)sa.SA_HANDLER == (long)SIG_IGN)
982 tprints("{SIG_IGN, ");
984 tprintf("{%#lx, ", (long) sa.SA_HANDLER);
986 printsigmask(&sa.sa_mask, 0);
988 long_to_sigset(sa.sa_mask, &sigset);
989 printsigmask(&sigset, 0);
992 printflags(sigact_flags, sa.sa_flags, "SA_???");
994 if (sa.sa_flags & SA_RESTORER)
995 tprintf(", %p", sa.sa_restorer);
1003 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
1009 sys_signal(struct tcb *tcp)
1011 if (entering(tcp)) {
1012 printsignal(tcp->u_arg[0]);
1014 switch (tcp->u_arg[1]) {
1015 case (long) SIG_ERR:
1018 case (long) SIG_DFL:
1021 case (long) SIG_IGN:
1025 tprintf("%#lx", tcp->u_arg[1]);
1029 else if (!syserror(tcp)) {
1030 switch (tcp->u_rval) {
1031 case (long) SIG_ERR:
1032 tcp->auxstr = "SIG_ERR"; break;
1033 case (long) SIG_DFL:
1034 tcp->auxstr = "SIG_DFL"; break;
1035 case (long) SIG_IGN:
1036 tcp->auxstr = "SIG_IGN"; break;
1040 return RVAL_HEX | RVAL_STR;
1047 sys_sighold(struct tcb *tcp)
1049 if (entering(tcp)) {
1050 printsignal(tcp->u_arg[0]);
1056 #endif /* HAVE_SIGACTION */
1061 sys_sigreturn(struct tcb *tcp)
1064 if (entering(tcp)) {
1065 struct pt_regs regs;
1066 struct sigcontext_struct sc;
1068 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)®s) == -1)
1070 if (umove(tcp, regs.ARM_sp, &sc) < 0)
1072 long_to_sigset(sc.oldmask, &sigm);
1073 tprints(sprintsigmask(") (mask ", &sigm, 0));
1076 #elif defined(S390) || defined(S390X)
1077 if (entering(tcp)) {
1079 struct sigcontext_struct sc;
1080 if (upeek(tcp, PT_GPR15, &usp) < 0)
1082 if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &sc) < 0)
1084 tprints(sprintsigmask(") (mask ", (sigset_t *)&sc.oldmask[0], 0));
1088 if (entering(tcp)) {
1089 struct sigcontext_struct sc;
1090 /* Note: on i386, sc is followed on stack by struct fpstate
1091 * and after it an additional u32 extramask[1] which holds
1092 * upper half of the mask. We can fetch it there
1093 * if/when we'd want to display the full mask...
1096 if (umove(tcp, i386_regs.esp, &sc) < 0)
1098 long_to_sigset(sc.oldmask, &sigm);
1099 tprints(sprintsigmask(") (mask ", &sigm, 0));
1103 if (entering(tcp)) {
1104 struct sigcontext sc;
1107 /* offset of sigcontext in the kernel's sigframe structure: */
1108 # define SIGFRAME_SC_OFFSET 0x90
1109 if (upeek(tcp, PT_R12, &sp) < 0)
1111 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
1114 memcpy(&sigm, &sc.sc_mask, NSIG / 8);
1115 tprints(sprintsigmask(") (mask ", &sigm, 0));
1118 #elif defined(POWERPC)
1119 if (entering(tcp)) {
1121 struct sigcontext_struct sc;
1123 if (upeek(tcp, sizeof(unsigned long) * PT_R1, &esp) < 0)
1125 /* Skip dummy stack frame. */
1127 if (current_personality == 0)
1134 if (umove(tcp, esp, &sc) < 0)
1136 long_to_sigset(sc.oldmask, &sigm);
1137 tprints(sprintsigmask(") (mask ", &sigm, 0));
1141 if (entering(tcp)) {
1143 struct sigcontext sc;
1145 if (upeek(tcp, 4*PT_USP, &usp) < 0)
1147 if (umove(tcp, usp, &sc) < 0)
1149 long_to_sigset(sc.sc_mask, &sigm);
1150 tprints(sprintsigmask(") (mask ", &sigm, 0));
1153 #elif defined(ALPHA)
1154 if (entering(tcp)) {
1156 struct sigcontext_struct sc;
1158 if (upeek(tcp, REG_FP, &fp) < 0)
1160 if (umove(tcp, fp, &sc) < 0)
1162 long_to_sigset(sc.sc_mask, &sigm);
1163 tprints(sprintsigmask(") (mask ", &sigm, 0));
1166 #elif defined (SPARC) || defined (SPARC64)
1167 if (entering(tcp)) {
1169 struct pt_regs regs;
1172 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
1173 perror("sigreturn: PTRACE_GETREGS");
1176 i1 = regs.u_regs[U_REG_O1];
1177 if (umove(tcp, i1, &si) < 0) {
1178 perror("sigreturn: umove");
1181 long_to_sigset(si.si_mask, &sigm);
1182 tprints(sprintsigmask(") (mask ", &sigm, 0));
1185 #elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
1186 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1188 if (entering(tcp)) {
1192 if (upeek(tcp, REG_SP, &sp) < 0)
1194 /* There are six words followed by a 128-byte siginfo. */
1195 sp = sp + 6 * 4 + 128;
1196 if (umove(tcp, sp, &uc) < 0)
1198 long_to_sigset(*(long *) &uc.uc_sigmask, &sigm);
1199 tprints(sprintsigmask(") (mask ", &sigm, 0));
1203 if (entering(tcp)) {
1205 struct pt_regs regs;
1208 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
1209 perror("sigreturn: PTRACE_GETREGS");
1213 if (umove(tcp, sp, &si) < 0)
1215 long_to_sigset(si.si_mask, &sigm);
1216 tprints(sprintsigmask(") (mask ", &sigm, 0));
1219 #elif defined(CRISV10) || defined(CRISV32)
1220 if (entering(tcp)) {
1221 struct sigcontext sc;
1222 long regs[PT_MAX+1];
1224 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1225 perror("sigreturn: PTRACE_GETREGS");
1228 if (umove(tcp, regs[PT_USP], &sc) < 0)
1230 long_to_sigset(sc.oldmask, &sigm);
1231 tprints(sprintsigmask(") (mask ", &sigm, 0));
1235 if (entering(tcp)) {
1240 /* offset of ucontext in the kernel's sigframe structure */
1241 # define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo)
1242 if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0)
1244 if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1247 memcpy(&sigm, &uc.uc_sigmask, NSIG / 8);
1248 tprints(sprintsigmask(") (mask ", &sigm, 0));
1251 #elif defined(MICROBLAZE)
1252 /* TODO: Verify that this is correct... */
1253 if (entering(tcp)) {
1254 struct sigcontext sc;
1257 /* Read r1, the stack pointer. */
1258 if (upeek(tcp, 1 * 4, &sp) < 0)
1260 if (umove(tcp, sp, &sc) < 0)
1262 long_to_sigset(sc.oldmask, &sigm);
1263 tprints(sprintsigmask(") (mask ", &sigm, 0));
1267 #warning No sys_sigreturn() for this architecture
1268 #warning (no problem, just a reminder :-)
1274 sys_siggetmask(struct tcb *tcp)
1278 long_to_sigset(tcp->u_rval, &sigm);
1279 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
1281 return RVAL_HEX | RVAL_STR;
1285 sys_sigsuspend(struct tcb *tcp)
1287 if (entering(tcp)) {
1289 long_to_sigset(tcp->u_arg[2], &sigm);
1290 printsigmask(&sigm, 0);
1297 #if defined(SVR4) || defined(FREEBSD)
1300 sys_sigsuspend(struct tcb *tcp)
1304 if (entering(tcp)) {
1305 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
1308 printsigmask(&sigset, 0);
1313 static const struct xlat ucontext_flags[] = {
1314 { UC_SIGMASK, "UC_SIGMASK" },
1315 { UC_STACK, "UC_STACK" },
1316 { UC_CPU, "UC_CPU" },
1318 { UC_FPU, "UC_FPU" },
1321 { UC_INTR, "UC_INTR" },
1325 #endif /* !FREEBSD */
1326 #endif /* SVR4 || FREEBSD */
1328 #if defined SVR4 || defined LINUX || defined FREEBSD
1329 #if defined LINUX && !defined SS_ONSTACK
1330 #define SS_ONSTACK 1
1331 #define SS_DISABLE 2
1332 #if __GLIBC_MINOR__ == 0
1342 #define stack_t struct sigaltstack
1345 static const struct xlat sigaltstack_flags[] = {
1346 { SS_ONSTACK, "SS_ONSTACK" },
1347 { SS_DISABLE, "SS_DISABLE" },
1354 printcontext(struct tcb *tcp, ucontext_t *ucp)
1358 tprints("uc_flags=");
1359 printflags(ucontext_flags, ucp->uc_flags, "UC_???");
1360 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
1362 tprints("uc_sigmask=");
1363 printsigmask(&ucp->uc_sigmask, 0);
1365 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
1366 (unsigned long) ucp->uc_stack.ss_sp,
1367 ucp->uc_stack.ss_size);
1368 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
1375 sys_getcontext(struct tcb *tcp)
1381 tprintf("%#lx", tcp->u_arg[0]);
1382 else if (!tcp->u_arg[0])
1384 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1387 printcontext(tcp, &uc);
1393 sys_setcontext(struct tcb *tcp)
1397 if (entering(tcp)) {
1400 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
1403 printcontext(tcp, &uc);
1406 tcp->u_rval = tcp->u_error = 0;
1407 if (tcp->u_arg[0] == 0)
1416 #if defined(LINUX) || defined(FREEBSD)
1419 print_stack_t(struct tcb *tcp, unsigned long addr)
1422 if (umove(tcp, addr, &ss) < 0)
1424 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1425 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1426 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1431 sys_sigaltstack(struct tcb *tcp)
1433 if (entering(tcp)) {
1434 if (tcp->u_arg[0] == 0)
1436 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
1441 if (tcp->u_arg[1] == 0)
1443 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
1450 #ifdef HAVE_SIGACTION
1453 sys_sigprocmask(struct tcb *tcp)
1456 if (entering(tcp)) {
1457 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1459 printsigmask(tcp->u_arg[1], 0);
1461 else if (!syserror(tcp)) {
1462 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
1463 return RVAL_HEX | RVAL_STR;
1466 if (entering(tcp)) {
1468 if (tcp->u_arg[0] == 0)
1472 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1474 print_sigset(tcp, tcp->u_arg[1], 0);
1480 else if (syserror(tcp))
1481 tprintf("%#lx", tcp->u_arg[2]);
1483 print_sigset(tcp, tcp->u_arg[2], 0);
1489 #endif /* HAVE_SIGACTION */
1492 sys_kill(struct tcb *tcp)
1494 if (entering(tcp)) {
1495 long pid = tcp->u_arg[0];
1496 #if SUPPORTED_PERSONALITIES > 1
1497 /* Sign-extend a 32-bit value when that's what it is. */
1498 if (personality_wordsize[current_personality] < sizeof pid)
1499 pid = (long) (int) pid;
1501 tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
1506 #if defined(FREEBSD) || defined(SUNOS4)
1508 sys_killpg(struct tcb *tcp)
1510 return sys_kill(tcp);
1512 #endif /* FREEBSD || SUNOS4 */
1516 sys_tgkill(struct tcb *tcp)
1518 if (entering(tcp)) {
1519 tprintf("%ld, %ld, %s",
1520 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
1527 sys_sigpending(struct tcb *tcp)
1533 tprintf("%#lx", tcp->u_arg[0]);
1534 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1537 printsigmask(&sigset, 0);
1543 int sys_sigwait(struct tcb *tcp)
1547 if (entering(tcp)) {
1548 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
1551 printsigmask(&sigset, 0);
1554 if (!syserror(tcp)) {
1555 tcp->auxstr = signalent[tcp->u_rval];
1556 return RVAL_DECIMAL | RVAL_STR;
1566 sys_rt_sigprocmask(struct tcb *tcp)
1570 /* Note: arg[3] is the length of the sigset. */
1571 if (entering(tcp)) {
1572 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1576 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
1577 tprintf("%#lx, ", tcp->u_arg[1]);
1579 printsigmask(&sigset, 1);
1586 else if (syserror(tcp))
1587 tprintf("%#lx", tcp->u_arg[2]);
1588 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
1591 printsigmask(&sigset, 1);
1592 tprintf(", %lu", tcp->u_arg[3]);
1598 /* Structure describing the action to be taken when a signal arrives. */
1599 struct new_sigaction
1601 __sighandler_t __sa_handler;
1602 unsigned long sa_flags;
1603 void (*sa_restorer) (void);
1604 /* Kernel treats sa_mask as an array of longs. */
1605 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1607 /* Same for i386-on-x86_64 and similar cases */
1608 struct new_sigaction32
1610 uint32_t __sa_handler;
1612 uint32_t sa_restorer;
1613 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
1618 sys_rt_sigaction(struct tcb *tcp)
1620 struct new_sigaction sa;
1625 if (entering(tcp)) {
1626 printsignal(tcp->u_arg[0]);
1628 addr = tcp->u_arg[1];
1630 addr = tcp->u_arg[2];
1636 if (!verbose(tcp)) {
1637 tprintf("%#lx", addr);
1640 #if SUPPORTED_PERSONALITIES > 1
1641 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
1642 && personality_wordsize[current_personality] == 4
1644 struct new_sigaction32 sa32;
1645 r = umove(tcp, addr, &sa32);
1647 memset(&sa, 0, sizeof(sa));
1648 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1649 sa.sa_flags = sa32.sa_flags;
1650 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1651 /* Kernel treats sa_mask as an array of longs.
1652 * For 32-bit process, "long" is uint32_t, thus, for example,
1653 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1654 * But for (64-bit) kernel, 32th bit in sa_mask is
1655 * 32th bit in 0th (64-bit) long!
1656 * For little-endian, it's the same.
1657 * For big-endian, we swap 32-bit words.
1659 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1664 r = umove(tcp, addr, &sa);
1670 /* Architectures using function pointers, like
1671 * hppa, may need to manipulate the function pointer
1672 * to compute the result of a comparison. However,
1673 * the SA_HANDLER function pointer exists only in
1674 * the address space of the traced process, and can't
1675 * be manipulated by strace. In order to prevent the
1676 * compiler from generating code to manipulate
1677 * SA_HANDLER we cast the function pointers to long. */
1678 if ((long)sa.__sa_handler == (long)SIG_ERR)
1679 tprints("{SIG_ERR, ");
1680 else if ((long)sa.__sa_handler == (long)SIG_DFL)
1681 tprints("{SIG_DFL, ");
1682 else if ((long)sa.__sa_handler == (long)SIG_IGN)
1683 tprints("{SIG_IGN, ");
1685 tprintf("{%#lx, ", (long) sa.__sa_handler);
1686 /* Questionable code below.
1687 * Kernel won't handle sys_rt_sigaction
1688 * with wrong sigset size (just returns EINVAL)
1689 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
1690 * and we always use smaller memcpy. */
1691 sigemptyset(&sigset);
1693 if (tcp->u_arg[4] <= sizeof(sigset))
1694 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
1696 if (tcp->u_arg[3] <= sizeof(sigset))
1697 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1700 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1701 printsigmask(&sigset, 1);
1703 printflags(sigact_flags, sa.sa_flags, "SA_???");
1705 if (sa.sa_flags & SA_RESTORER)
1706 tprintf(", %p", sa.sa_restorer);
1715 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1716 #elif defined(ALPHA)
1717 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1719 tprintf(", %lu", tcp->u_arg[3]);
1725 sys_rt_sigpending(struct tcb *tcp)
1731 tprintf("%#lx", tcp->u_arg[0]);
1732 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1733 &sigset, tcp->u_arg[1]) < 0)
1736 printsigmask(&sigset, 1);
1742 sys_rt_sigsuspend(struct tcb *tcp)
1744 if (entering(tcp)) {
1746 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1749 printsigmask(&sigm, 1);
1755 sys_rt_sigqueueinfo(struct tcb *tcp)
1757 if (entering(tcp)) {
1759 tprintf("%lu, ", tcp->u_arg[0]);
1760 printsignal(tcp->u_arg[1]);
1762 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1763 tprintf("%#lx", tcp->u_arg[2]);
1765 printsiginfo(&si, verbose(tcp));
1770 int sys_rt_sigtimedwait(struct tcb *tcp)
1772 if (entering(tcp)) {
1775 if (copy_sigset_len(tcp, tcp->u_arg[0],
1776 &sigset, tcp->u_arg[3]) < 0)
1779 printsigmask(&sigset, 1);
1781 /* This is the only "return" parameter, */
1782 if (tcp->u_arg[1] != 0)
1784 /* ... if it's NULL, can decode all on entry */
1787 else if (tcp->u_arg[1] != 0) {
1788 /* syscall exit, and u_arg[1] wasn't NULL */
1790 tprintf("%#lx, ", tcp->u_arg[1]);
1793 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1794 tprintf("%#lx, ", tcp->u_arg[1]);
1796 printsiginfo(&si, verbose(tcp));
1802 /* syscall exit, and u_arg[1] was NULL */
1805 print_timespec(tcp, tcp->u_arg[2]);
1806 tprintf(", %d", (int) tcp->u_arg[3]);
1811 sys_restart_syscall(struct tcb *tcp)
1814 tprints("<... resuming interrupted call ...>");
1819 do_signalfd(struct tcb *tcp, int flags_arg)
1821 if (entering(tcp)) {
1822 printfd(tcp, tcp->u_arg[0]);
1824 print_sigset(tcp, tcp->u_arg[1], 1);
1825 tprintf(", %lu", tcp->u_arg[2]);
1826 if (flags_arg >= 0) {
1828 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1835 sys_signalfd(struct tcb *tcp)
1837 return do_signalfd(tcp, -1);
1841 sys_signalfd4(struct tcb *tcp)
1843 return do_signalfd(tcp, 3);