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.
40 #if defined(SPARC) || defined(SPARC64) || defined(MIPS)
42 struct pt_regs si_regs;
45 #elif defined HAVE_ASM_SIGCONTEXT_H
46 # if !defined(IA64) && !defined(X86_64) && !defined(X32)
47 # include <asm/sigcontext.h>
49 #else /* !HAVE_ASM_SIGCONTEXT_H */
50 # if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
52 unsigned long sc_mask;
60 unsigned short sc_formatvec;
63 #endif /* !HAVE_ASM_SIGCONTEXT_H */
66 # warning: NSIG is not defined, using 32
72 /* The libc headers do not define this constant since it should only be
73 used by the implementation. So we define it here. */
75 # ifdef ASM_SA_RESTORER
76 # define SA_RESTORER ASM_SA_RESTORER
81 * Some architectures define SA_RESTORER in their headers,
82 * but do not actually have sa_restorer.
84 * Some architectures, otherwise, do not define SA_RESTORER in their headers,
85 * but actually have sa_restorer.
88 # if defined HPPA || defined IA64
89 # define HAVE_SA_RESTORER 0
91 # define HAVE_SA_RESTORER 1
93 #else /* !SA_RESTORER */
94 # if defined SPARC || defined SPARC64
95 # define HAVE_SA_RESTORER 1
97 # define HAVE_SA_RESTORER 0
101 #include "xlat/sigact_flags.h"
102 #include "xlat/sigprocmaskcmds.h"
104 /* Anonymous realtime signals. */
105 /* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
106 constant. This is what we want. Otherwise, just use SIGRTMIN. */
109 #define __SIGRTMIN SIGRTMIN
110 #define __SIGRTMAX SIGRTMAX /* likewise */
114 /* Note on the size of sigset_t:
116 * In glibc, sigset_t is an array with space for 1024 bits (!),
117 * even though all arches supported by Linux have only 64 signals
118 * except MIPS, which has 128. IOW, it is 128 bytes long.
120 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
121 * However, some old syscall return only 32 lower bits (one word).
122 * Example: sys_sigpending vs sys_rt_sigpending.
124 * Be aware of this fact when you try to
125 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
126 * - sizeof(sigset_t) is much bigger than you think,
127 * it may overflow tcp->u_arg[] array, and it may try to copy more data
128 * than is really available in <something>.
130 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
131 * may be a bad idea: it'll try to read much more data than needed
132 * to fetch a sigset_t.
133 * Use (NSIG / 8) as a size instead.
137 signame(const int sig)
139 static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
142 const unsigned int s = sig;
147 if (s >= __SIGRTMIN && s <= __SIGRTMAX) {
148 sprintf(buf, "SIGRT_%u", s - __SIGRTMIN);
153 sprintf(buf, "%d", sig);
158 popcount32(const uint32_t *a, unsigned int size)
160 unsigned int count = 0;
162 for (; size; ++a, --size) {
165 #ifdef HAVE___BUILTIN_POPCOUNT
166 count += __builtin_popcount(x);
177 sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
180 * The maximum number of signal names to be printed is NSIG * 2 / 3.
181 * Most of signal names have length 7,
182 * average length of signal names is less than 7.
183 * The length of prefix string does not exceed 16.
185 static char outstr[128 + 8 * (NSIG * 2 / 3)];
188 const uint32_t *mask;
189 uint32_t inverted_mask[NSIG / 32];
194 s = stpcpy(outstr, prefix);
197 /* length of signal mask in 4-byte words */
198 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
200 /* check whether 2/3 or more bits are set */
201 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
202 /* show those signals that are NOT in the mask */
204 for (j = 0; j < size; ++j)
205 inverted_mask[j] = ~mask[j];
206 mask = inverted_mask;
211 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
214 if ((unsigned) i < nsignals) {
215 s = stpcpy(s, signalent[i] + 3);
218 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
219 s += sprintf(s, "RT_%u", i - __SIGRTMIN);
223 s += sprintf(s, "%u", i);
234 #define tprintsigmask_addr(prefix, mask) \
235 tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
237 #define sprintsigmask_val(prefix, mask) \
238 sprintsigmask_n((prefix), &(mask), sizeof(mask))
240 #define tprintsigmask_val(prefix, mask) \
241 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
246 tprints(signame(nr));
250 print_sigset_addr_len(struct tcb *tcp, long addr, long len)
258 /* Here len is usually equals NSIG / 8 or current_wordsize.
259 * But we code this defensively:
263 tprintf("%#lx", addr);
269 len = (len + 3) & ~3;
271 if (umoven(tcp, addr, len, mask) < 0)
273 tprints(sprintsigmask_n("", mask, len));
277 #define ILL_ILLOPC 1 /* illegal opcode */
278 #define ILL_ILLOPN 2 /* illegal operand */
279 #define ILL_ILLADR 3 /* illegal addressing mode */
280 #define ILL_ILLTRP 4 /* illegal trap */
281 #define ILL_PRVOPC 5 /* privileged opcode */
282 #define ILL_PRVREG 6 /* privileged register */
283 #define ILL_COPROC 7 /* coprocessor error */
284 #define ILL_BADSTK 8 /* internal stack error */
285 #define FPE_INTDIV 1 /* integer divide by zero */
286 #define FPE_INTOVF 2 /* integer overflow */
287 #define FPE_FLTDIV 3 /* floating point divide by zero */
288 #define FPE_FLTOVF 4 /* floating point overflow */
289 #define FPE_FLTUND 5 /* floating point underflow */
290 #define FPE_FLTRES 6 /* floating point inexact result */
291 #define FPE_FLTINV 7 /* floating point invalid operation */
292 #define FPE_FLTSUB 8 /* subscript out of range */
293 #define SEGV_MAPERR 1 /* address not mapped to object */
294 #define SEGV_ACCERR 2 /* invalid permissions for mapped object */
295 #define BUS_ADRALN 1 /* invalid address alignment */
296 #define BUS_ADRERR 2 /* non-existant physical address */
297 #define BUS_OBJERR 3 /* object specific hardware error */
298 #define SYS_SECCOMP 1 /* seccomp triggered */
299 #define TRAP_BRKPT 1 /* process breakpoint */
300 #define TRAP_TRACE 2 /* process trace trap */
301 #define CLD_EXITED 1 /* child has exited */
302 #define CLD_KILLED 2 /* child was killed */
303 #define CLD_DUMPED 3 /* child terminated abnormally */
304 #define CLD_TRAPPED 4 /* traced child has trapped */
305 #define CLD_STOPPED 5 /* child has stopped */
306 #define CLD_CONTINUED 6 /* stopped child has continued */
307 #define POLL_IN 1 /* data input available */
308 #define POLL_OUT 2 /* output buffers available */
309 #define POLL_MSG 3 /* input message available */
310 #define POLL_ERR 4 /* i/o error */
311 #define POLL_PRI 5 /* high priority input available */
312 #define POLL_HUP 6 /* device disconnected */
313 #define SI_KERNEL 0x80 /* sent by kernel */
314 #define SI_USER 0 /* sent by kill, sigsend, raise */
315 #define SI_QUEUE -1 /* sent by sigqueue */
316 #define SI_TIMER -2 /* sent by timer expiration */
317 #define SI_MESGQ -3 /* sent by real time mesq state change */
318 #define SI_ASYNCIO -4 /* sent by AIO completion */
319 #define SI_SIGIO -5 /* sent by SIGIO */
320 #define SI_TKILL -6 /* sent by tkill */
321 #define SI_DETHREAD -7 /* sent by execve killing subsidiary threads */
322 #define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
326 # define SI_FROMUSER(sip) ((sip)->si_code <= 0)
329 #include "xlat/siginfo_codes.h"
330 #include "xlat/sigill_codes.h"
331 #include "xlat/sigfpe_codes.h"
332 #include "xlat/sigtrap_codes.h"
333 #include "xlat/sigchld_codes.h"
334 #include "xlat/sigpoll_codes.h"
335 #include "xlat/sigprof_codes.h"
338 #include "xlat/sigemt_codes.h"
341 #include "xlat/sigsegv_codes.h"
342 #include "xlat/sigbus_codes.h"
345 # define SYS_SECCOMP 1
347 #include "xlat/sigsys_codes.h"
350 printsigsource(const siginfo_t *sip)
352 tprintf(", si_pid=%lu, si_uid=%lu",
353 (unsigned long) sip->si_pid,
354 (unsigned long) sip->si_uid);
358 printsigval(const siginfo_t *sip, int verbose)
363 tprintf(", si_value={int=%u, ptr=%#lx}",
365 (unsigned long) sip->si_ptr);
369 printsiginfo(const siginfo_t *sip, int verbose)
373 if (sip->si_signo == 0) {
377 tprints("{si_signo=");
378 printsignal(sip->si_signo);
379 code = xlookup(siginfo_codes, sip->si_code);
381 switch (sip->si_signo) {
383 code = xlookup(sigtrap_codes, sip->si_code);
386 code = xlookup(sigchld_codes, sip->si_code);
389 code = xlookup(sigpoll_codes, sip->si_code);
392 code = xlookup(sigprof_codes, sip->si_code);
395 code = xlookup(sigill_codes, sip->si_code);
399 code = xlookup(sigemt_codes, sip->si_code);
403 code = xlookup(sigfpe_codes, sip->si_code);
406 code = xlookup(sigsegv_codes, sip->si_code);
409 code = xlookup(sigbus_codes, sip->si_code);
412 code = xlookup(sigsys_codes, sip->si_code);
417 tprintf(", si_code=%s", code);
419 tprintf(", si_code=%#x", sip->si_code);
421 if (sip->si_code != SI_NOINFO)
425 tprints(", si_errno=");
426 if ((unsigned) sip->si_errno < nerrnos
427 && errnoent[sip->si_errno])
428 tprints(errnoent[sip->si_errno]);
430 tprintf("%d", sip->si_errno);
433 if (SI_FROMUSER(sip)) {
434 switch (sip->si_code) {
445 #if defined SI_TIMER \
446 && defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
448 tprintf(", si_timerid=%#x, si_overrun=%d",
449 sip->si_timerid, sip->si_overrun);
450 printsigval(sip, verbose);
456 printsigval(sip, verbose);
461 #endif /* SI_FROMUSER */
463 switch (sip->si_signo) {
466 tprints(", si_status=");
467 if (sip->si_code == CLD_EXITED)
468 tprintf("%d", sip->si_status);
470 printsignal(sip->si_status);
474 tprintf(", si_utime=%llu, si_stime=%llu",
475 (unsigned long long) sip->si_utime,
476 (unsigned long long) sip->si_stime);
478 case SIGILL: case SIGFPE:
479 case SIGSEGV: case SIGBUS:
480 tprintf(", si_addr=%#lx",
481 (unsigned long) sip->si_addr);
484 switch (sip->si_code) {
485 case POLL_IN: case POLL_OUT: case POLL_MSG:
486 tprintf(", si_band=%ld",
487 (long) sip->si_band);
491 #ifdef HAVE_SIGINFO_T_SI_SYSCALL
493 tprintf(", si_call_addr=%#lx, si_syscall=%d, si_arch=%u",
494 (unsigned long) sip->si_call_addr,
495 sip->si_syscall, sip->si_arch);
499 if (sip->si_pid || sip->si_uid)
502 printsigval(sip, verbose);
510 printsiginfo_at(struct tcb *tcp, long addr)
518 tprintf("%#lx", addr);
521 if (umove(tcp, addr, &si) < 0) {
525 printsiginfo(&si, verbose(tcp));
529 sys_sigsetmask(struct tcb *tcp)
532 tprintsigmask_val("", tcp->u_arg[0]);
534 else if (!syserror(tcp)) {
535 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
536 return RVAL_HEX | RVAL_STR;
541 #ifdef HAVE_SIGACTION
543 struct old_sigaction {
544 /* sa_handler may be a libc #define, need to use other name: */
546 unsigned int sa_flags;
547 void (*__sa_handler)(int);
548 /* Kernel treats sa_mask as an array of longs. */
549 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
551 void (*__sa_handler)(int);
552 unsigned long sa_mask;
553 unsigned long sa_flags;
556 void (*sa_restorer)(void);
560 struct old_sigaction32 {
561 /* sa_handler may be a libc #define, need to use other name: */
562 uint32_t __sa_handler;
566 uint32_t sa_restorer;
571 decode_old_sigaction(struct tcb *tcp, long addr)
573 struct old_sigaction sa;
580 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
581 tprintf("%#lx", addr);
585 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
586 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
587 struct old_sigaction32 sa32;
588 r = umove(tcp, addr, &sa32);
590 memset(&sa, 0, sizeof(sa));
591 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
592 sa.sa_flags = sa32.sa_flags;
593 #if HAVE_SA_RESTORER && defined SA_RESTORER
594 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
596 sa.sa_mask = sa32.sa_mask;
601 r = umove(tcp, addr, &sa);
608 /* Architectures using function pointers, like
609 * hppa, may need to manipulate the function pointer
610 * to compute the result of a comparison. However,
611 * the __sa_handler function pointer exists only in
612 * the address space of the traced process, and can't
613 * be manipulated by strace. In order to prevent the
614 * compiler from generating code to manipulate
615 * __sa_handler we cast the function pointers to long. */
616 if ((long)sa.__sa_handler == (long)SIG_ERR)
617 tprints("{SIG_ERR, ");
618 else if ((long)sa.__sa_handler == (long)SIG_DFL)
619 tprints("{SIG_DFL, ");
620 else if ((long)sa.__sa_handler == (long)SIG_IGN)
621 tprints("{SIG_IGN, ");
623 tprintf("{%#lx, ", (long) sa.__sa_handler);
625 tprintsigmask_addr("", sa.sa_mask);
627 tprintsigmask_val("", sa.sa_mask);
630 printflags(sigact_flags, sa.sa_flags, "SA_???");
631 #if HAVE_SA_RESTORER && defined SA_RESTORER
632 if (sa.sa_flags & SA_RESTORER)
633 tprintf(", %p", sa.sa_restorer);
639 sys_sigaction(struct tcb *tcp)
642 printsignal(tcp->u_arg[0]);
644 decode_old_sigaction(tcp, tcp->u_arg[1]);
647 decode_old_sigaction(tcp, tcp->u_arg[2]);
652 sys_signal(struct tcb *tcp)
655 printsignal(tcp->u_arg[0]);
657 switch (tcp->u_arg[1]) {
668 tprintf("%#lx", tcp->u_arg[1]);
672 else if (!syserror(tcp)) {
673 switch (tcp->u_rval) {
675 tcp->auxstr = "SIG_ERR"; break;
677 tcp->auxstr = "SIG_DFL"; break;
679 tcp->auxstr = "SIG_IGN"; break;
683 return RVAL_HEX | RVAL_STR;
688 #endif /* HAVE_SIGACTION */
691 sys_sigreturn(struct tcb *tcp)
695 struct arm_sigcontext {
696 unsigned long trap_no;
697 unsigned long error_code;
698 unsigned long oldmask;
699 unsigned long arm_r0;
700 unsigned long arm_r1;
701 unsigned long arm_r2;
702 unsigned long arm_r3;
703 unsigned long arm_r4;
704 unsigned long arm_r5;
705 unsigned long arm_r6;
706 unsigned long arm_r7;
707 unsigned long arm_r8;
708 unsigned long arm_r9;
709 unsigned long arm_r10;
710 unsigned long arm_fp;
711 unsigned long arm_ip;
712 unsigned long arm_sp;
713 unsigned long arm_lr;
714 unsigned long arm_pc;
715 unsigned long arm_cpsr;
716 unsigned long fault_address;
718 struct arm_ucontext {
719 unsigned long uc_flags;
720 unsigned long uc_link; /* struct ucontext* */
721 /* The next three members comprise stack_t struct: */
722 unsigned long ss_sp; /* void* */
723 unsigned long ss_flags; /* int */
724 unsigned long ss_size; /* size_t */
725 struct arm_sigcontext sc;
726 /* These two members are sigset_t: */
727 unsigned long uc_sigmask[2];
728 /* more fields follow, which we aren't interested in */
730 struct arm_ucontext uc;
731 if (umove(tcp, arm_regs.ARM_sp, &uc) < 0)
734 * Kernel fills out uc.sc.oldmask too when it sets up signal stack,
735 * but for sigmask restore, sigreturn syscall uses uc.uc_sigmask instead.
737 tprintsigmask_addr(") (mask ", uc.uc_sigmask);
739 #elif defined(S390) || defined(S390X)
742 long mask[NSIG / 8 / sizeof(long)];
743 if (upeek(tcp->pid, PT_GPR15, &usp) < 0)
745 if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &mask) < 0)
752 tprintsigmask_addr(") (mask ", mask);
754 #elif defined I386 || defined X86_64 || defined X32
757 if (current_personality != 1) {
758 const unsigned long addr =
759 (unsigned long) *x86_64_rsp_ptr +
760 offsetof(struct ucontext, uc_sigmask);
762 print_sigset_addr_len(tcp, addr, NSIG / 8);
766 struct i386_sigcontext_struct {
784 uint32_t esp_at_signal;
790 struct i386_fpstate {
798 uint8_t st[8][10]; /* 8*10 bytes: FP regs */
801 uint32_t fxsr_env[6];
804 uint8_t stx[8][16]; /* 8*16 bytes: FP regs, each padded to 16 bytes */
805 uint8_t xmm[8][16]; /* 8 XMM regs */
806 uint32_t padding1[44];
807 uint32_t padding2[12]; /* union with struct _fpx_sw_bytes */
810 struct i386_sigcontext_struct sc;
811 struct i386_fpstate fp;
812 uint32_t extramask[1];
814 /* On i386, sc is followed on stack by struct fpstate
815 * and after it an additional u32 extramask[1] which holds
816 * upper half of the mask.
819 if (umove(tcp, *i386_esp_ptr, &signal_stack) < 0)
821 sigmask[0] = signal_stack.sc.oldmask;
822 sigmask[1] = signal_stack.extramask[0];
823 tprintsigmask_addr(") (mask ", sigmask);
828 if (upeek(tcp->pid, PT_R12, &addr) < 0)
830 /* offsetof(struct sigframe, sc) */
831 # define OFFSETOF_STRUCT_SIGFRAME_SC 0xA0
832 addr += 16 + OFFSETOF_STRUCT_SIGFRAME_SC +
833 offsetof(struct sigcontext, sc_mask);
835 print_sigset_addr_len(tcp, addr, NSIG / 8);
837 #elif defined(POWERPC)
839 long esp = ppc_regs.gpr[1];
840 struct sigcontext sc;
842 /* Skip dummy stack frame. */
844 if (current_personality == 0)
851 if (umove(tcp, esp, &sc) < 0) {
852 tprintf("%#lx", esp);
854 unsigned long mask[NSIG / 8 / sizeof(long)];
856 if (current_personality == 0)
857 mask[0] = sc.oldmask | (sc._unused[3] << 32);
861 mask[0] = sc.oldmask;
862 mask[1] = sc._unused[3];
864 tprintsigmask_val("", mask);
870 struct sigcontext sc;
871 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
873 if (umove(tcp, usp, &sc) < 0)
875 tprintsigmask_val(") (mask ", sc.sc_mask);
880 struct sigcontext sc;
881 if (upeek(tcp->pid, REG_FP, &fp) < 0)
883 if (umove(tcp, fp, &sc) < 0)
885 tprintsigmask_val(") (mask ", sc.sc_mask);
887 #elif defined(SPARC) || defined(SPARC64)
889 long fp = sparc_regs.u_regs[U_REG_FP] + sizeof(struct sparc_stackf);
893 long insns[2] __attribute__ ((aligned (8)));
894 unsigned int extramask[NSIG / 8 / sizeof(int) - 1];
898 if (umove(tcp, fp, &frame) < 0) {
901 unsigned int mask[NSIG / 8 / sizeof(int)];
903 mask[0] = frame.si.si_mask;
904 memcpy(mask + 1, frame.extramask, sizeof(frame.extramask));
905 tprintsigmask_val("", mask);
910 # if defined LINUX_MIPSO32
912 * offsetof(struct sigframe, sf_mask) ==
913 * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct sigcontext)
915 const long addr = mips_REG_SP + 6 * 4 +
916 sizeof(struct sigcontext);
919 * This decodes rt_sigreturn.
920 * The 64-bit ABIs do not have sigreturn.
922 * offsetof(struct rt_sigframe, rs_uc) ==
923 * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct siginfo)
925 const long addr = mips_REG_SP + 6 * 4 + 128 +
926 offsetof(struct ucontext, uc_sigmask);
929 print_sigset_addr_len(tcp, addr, NSIG / 8);
931 #elif defined(CRISV10) || defined(CRISV32)
933 struct sigcontext sc;
935 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
936 perror_msg("sigreturn: PTRACE_GETREGS");
939 if (umove(tcp, regs[PT_USP], &sc) < 0)
941 tprintsigmask_val(") (mask ", sc.oldmask);
947 /* offset of ucontext in the kernel's sigframe structure */
948 # define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
949 if (umove(tcp, tile_regs.sp + SIGFRAME_UC_OFFSET, &uc) < 0)
951 tprintsigmask_val(") (mask ", uc.uc_sigmask);
953 #elif defined(MICROBLAZE)
954 /* TODO: Verify that this is correct... */
956 struct sigcontext sc;
958 /* Read r1, the stack pointer. */
959 if (upeek(tcp->pid, 1 * 4, &sp) < 0)
961 if (umove(tcp, sp, &sc) < 0)
963 tprintsigmask_val(") (mask ", sc.oldmask);
966 # warning sigreturn/rt_sigreturn signal mask decoding is not implemented for this architecture
972 sys_siggetmask(struct tcb *tcp)
975 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
977 return RVAL_HEX | RVAL_STR;
981 sys_sigsuspend(struct tcb *tcp)
984 tprintsigmask_val("", tcp->u_arg[2]);
989 #if !defined SS_ONSTACK
994 #include "xlat/sigaltstack_flags.h"
997 print_stack_t(struct tcb *tcp, unsigned long addr)
1007 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1008 if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
1014 r = umove(tcp, addr, &ss32);
1016 memset(&ss, 0, sizeof(ss));
1017 ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
1018 ss.ss_flags = ss32.ss_flags;
1019 ss.ss_size = (unsigned long) ss32.ss_size;
1024 r = umove(tcp, addr, &ss);
1027 tprintf("%#lx", addr);
1029 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1030 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1031 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1036 sys_sigaltstack(struct tcb *tcp)
1038 if (entering(tcp)) {
1039 print_stack_t(tcp, tcp->u_arg[0]);
1043 print_stack_t(tcp, tcp->u_arg[1]);
1048 #ifdef HAVE_SIGACTION
1050 /* "Old" sigprocmask, which operates with word-sized signal masks */
1052 sys_sigprocmask(struct tcb *tcp)
1055 if (entering(tcp)) {
1057 * Alpha/OSF is different: it doesn't pass in two pointers,
1058 * but rather passes in the new bitmask as an argument and
1059 * then returns the old bitmask. This "works" because we
1060 * only have 64 signals to worry about. If you want more,
1061 * use of the rt_sigprocmask syscall is required.
1063 * old = osf_sigprocmask(how, new);
1065 * ret = sigprocmask(how, &new, &old, ...);
1067 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1068 tprintsigmask_val(", ", tcp->u_arg[1]);
1070 else if (!syserror(tcp)) {
1071 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
1072 return RVAL_HEX | RVAL_STR;
1075 if (entering(tcp)) {
1076 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1078 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
1083 tprintf("%#lx", tcp->u_arg[2]);
1085 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
1087 # endif /* !ALPHA */
1091 #endif /* HAVE_SIGACTION */
1094 sys_kill(struct tcb *tcp)
1096 if (entering(tcp)) {
1098 widen_to_long(tcp->u_arg[0]),
1099 signame(tcp->u_arg[1])
1106 sys_tgkill(struct tcb *tcp)
1108 if (entering(tcp)) {
1109 tprintf("%ld, %ld, %s",
1110 widen_to_long(tcp->u_arg[0]),
1111 widen_to_long(tcp->u_arg[1]),
1112 signame(tcp->u_arg[2])
1119 sys_sigpending(struct tcb *tcp)
1123 tprintf("%#lx", tcp->u_arg[0]);
1125 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
1131 sys_rt_sigprocmask(struct tcb *tcp)
1133 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
1134 if (entering(tcp)) {
1135 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1137 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1142 tprintf("%#lx", tcp->u_arg[2]);
1144 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
1145 tprintf(", %lu", tcp->u_arg[3]);
1150 /* Structure describing the action to be taken when a signal arrives. */
1151 struct new_sigaction
1153 /* sa_handler may be a libc #define, need to use other name: */
1155 unsigned int sa_flags;
1156 void (*__sa_handler)(int);
1158 void (*__sa_handler)(int);
1159 unsigned long sa_flags;
1161 #if HAVE_SA_RESTORER
1162 void (*sa_restorer)(void);
1164 /* Kernel treats sa_mask as an array of longs. */
1165 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1167 /* Same for i386-on-x86_64 and similar cases */
1168 struct new_sigaction32
1170 uint32_t __sa_handler;
1172 #if HAVE_SA_RESTORER
1173 uint32_t sa_restorer;
1175 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
1179 decode_new_sigaction(struct tcb *tcp, long addr)
1181 struct new_sigaction sa;
1188 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
1189 tprintf("%#lx", addr);
1192 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1193 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
1194 struct new_sigaction32 sa32;
1195 r = umove(tcp, addr, &sa32);
1197 memset(&sa, 0, sizeof(sa));
1198 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1199 sa.sa_flags = sa32.sa_flags;
1200 #if HAVE_SA_RESTORER && defined SA_RESTORER
1201 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1203 /* Kernel treats sa_mask as an array of longs.
1204 * For 32-bit process, "long" is uint32_t, thus, for example,
1205 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1206 * But for (64-bit) kernel, 32th bit in sa_mask is
1207 * 32th bit in 0th (64-bit) long!
1208 * For little-endian, it's the same.
1209 * For big-endian, we swap 32-bit words.
1211 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1216 r = umove(tcp, addr, &sa);
1222 /* Architectures using function pointers, like
1223 * hppa, may need to manipulate the function pointer
1224 * to compute the result of a comparison. However,
1225 * the __sa_handler function pointer exists only in
1226 * the address space of the traced process, and can't
1227 * be manipulated by strace. In order to prevent the
1228 * compiler from generating code to manipulate
1229 * __sa_handler we cast the function pointers to long. */
1230 if ((long)sa.__sa_handler == (long)SIG_ERR)
1231 tprints("{SIG_ERR, ");
1232 else if ((long)sa.__sa_handler == (long)SIG_DFL)
1233 tprints("{SIG_DFL, ");
1234 else if ((long)sa.__sa_handler == (long)SIG_IGN)
1235 tprints("{SIG_IGN, ");
1237 tprintf("{%#lx, ", (long) sa.__sa_handler);
1239 * Sigset size is in tcp->u_arg[4] (SPARC)
1240 * or in tcp->u_arg[3] (all other),
1241 * but kernel won't handle sys_rt_sigaction
1242 * with wrong sigset size (just returns EINVAL instead).
1243 * We just fetch the right size, which is NSIG / 8.
1245 tprintsigmask_val("", sa.sa_mask);
1248 printflags(sigact_flags, sa.sa_flags, "SA_???");
1249 #if HAVE_SA_RESTORER && defined SA_RESTORER
1250 if (sa.sa_flags & SA_RESTORER)
1251 tprintf(", %p", sa.sa_restorer);
1257 sys_rt_sigaction(struct tcb *tcp)
1259 if (entering(tcp)) {
1260 printsignal(tcp->u_arg[0]);
1262 decode_new_sigaction(tcp, tcp->u_arg[1]);
1265 decode_new_sigaction(tcp, tcp->u_arg[2]);
1266 #if defined(SPARC) || defined(SPARC64)
1267 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1268 #elif defined(ALPHA)
1269 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1271 tprintf(", %lu", tcp->u_arg[3]);
1278 sys_rt_sigpending(struct tcb *tcp)
1282 * One of the few syscalls where sigset size (arg[1])
1283 * is allowed to be <= NSIG / 8, not strictly ==.
1284 * This allows non-rt sigpending() syscall
1285 * to reuse rt_sigpending() code in kernel.
1288 tprintf("%#lx", tcp->u_arg[0]);
1290 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1291 tprintf(", %lu", tcp->u_arg[1]);
1297 sys_rt_sigsuspend(struct tcb *tcp)
1299 if (entering(tcp)) {
1300 /* NB: kernel requires arg[1] == NSIG / 8 */
1301 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1302 tprintf(", %lu", tcp->u_arg[1]);
1308 print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1312 printsiginfo_at(tcp, uinfo);
1316 sys_rt_sigqueueinfo(struct tcb *tcp)
1318 if (entering(tcp)) {
1319 tprintf("%lu, ", tcp->u_arg[0]);
1320 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1326 sys_rt_tgsigqueueinfo(struct tcb *tcp)
1328 if (entering(tcp)) {
1329 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1330 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
1335 int sys_rt_sigtimedwait(struct tcb *tcp)
1337 /* NB: kernel requires arg[3] == NSIG / 8 */
1338 if (entering(tcp)) {
1339 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
1341 /* This is the only "return" parameter, */
1342 if (tcp->u_arg[1] != 0)
1344 /* ... if it's NULL, can decode all on entry */
1347 else if (tcp->u_arg[1] != 0) {
1348 /* syscall exit, and u_arg[1] wasn't NULL */
1349 printsiginfo_at(tcp, tcp->u_arg[1]);
1353 /* syscall exit, and u_arg[1] was NULL */
1356 print_timespec(tcp, tcp->u_arg[2]);
1357 tprintf(", %lu", tcp->u_arg[3]);
1362 sys_restart_syscall(struct tcb *tcp)
1365 tprints("<... resuming interrupted call ...>");
1370 do_signalfd(struct tcb *tcp, int flags_arg)
1372 /* NB: kernel requires arg[2] == NSIG / 8 */
1373 if (entering(tcp)) {
1374 printfd(tcp, tcp->u_arg[0]);
1376 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1377 tprintf(", %lu", tcp->u_arg[2]);
1378 if (flags_arg >= 0) {
1380 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1387 sys_signalfd(struct tcb *tcp)
1389 return do_signalfd(tcp, -1);
1393 sys_signalfd4(struct tcb *tcp)
1395 return do_signalfd(tcp, 3);