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 #elif defined(HAVE_LINUX_PTRACE_H)
41 # undef PTRACE_SYSCALL
42 # ifdef HAVE_STRUCT_IA64_FPREG
43 # define ia64_fpreg XXX_ia64_fpreg
45 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS
46 # define pt_all_user_regs XXX_pt_all_user_regs
48 # ifdef HAVE_STRUCT_PTRACE_PEEKSIGINFO_ARGS
49 # define ptrace_peeksiginfo_args XXX_ptrace_peeksiginfo_args
51 # include <linux/ptrace.h>
52 # undef ptrace_peeksiginfo_args
54 # undef pt_all_user_regs
58 # include <asm/ptrace_offsets.h>
61 #if defined(SPARC) || defined(SPARC64) || defined(MIPS)
63 struct pt_regs si_regs;
66 #elif defined HAVE_ASM_SIGCONTEXT_H
67 # if !defined(IA64) && !defined(X86_64) && !defined(X32)
68 # include <asm/sigcontext.h>
70 #else /* !HAVE_ASM_SIGCONTEXT_H */
71 # if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
73 unsigned long sc_mask;
81 unsigned short sc_formatvec;
84 #endif /* !HAVE_ASM_SIGCONTEXT_H */
87 # warning: NSIG is not defined, using 32
95 /* The libc headers do not define this constant since it should only be
96 used by the implementation. So we define it here. */
98 # ifdef ASM_SA_RESTORER
99 # define SA_RESTORER ASM_SA_RESTORER
103 static const struct xlat sigact_flags[] = {
119 #if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
125 #if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
155 static const struct xlat sigprocmaskcmds[] = {
165 #endif /* HAVE_SIGACTION */
167 /* Anonymous realtime signals. */
168 /* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
169 constant. This is what we want. Otherwise, just use SIGRTMIN. */
172 #define __SIGRTMIN SIGRTMIN
173 #define __SIGRTMAX SIGRTMAX /* likewise */
177 /* Note on the size of sigset_t:
179 * In glibc, sigset_t is an array with space for 1024 bits (!),
180 * even though all arches supported by Linux have only 64 signals
181 * except MIPS, which has 128. IOW, it is 128 bytes long.
183 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
184 * However, some old syscall return only 32 lower bits (one word).
185 * Example: sys_sigpending vs sys_rt_sigpending.
187 * Be aware of this fact when you try to
188 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
189 * - sizeof(sigset_t) is much bigger than you think,
190 * it may overflow tcp->u_arg[] array, and it may try to copy more data
191 * than is really available in <something>.
193 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
194 * may be a bad idea: it'll try to read much more data than needed
195 * to fetch a sigset_t.
196 * Use (NSIG / 8) as a size instead.
202 static char buf[sizeof("SIGRT_%d") + sizeof(int)*3];
204 if (sig >= 0 && sig < nsignals)
205 return signalent[sig];
207 if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
208 sprintf(buf, "SIGRT_%d", (int)(sig - __SIGRTMIN));
212 sprintf(buf, "%d", sig);
217 popcount32(const uint32_t *a, unsigned int size)
219 unsigned int count = 0;
221 for (; size; ++a, --size) {
224 #ifdef HAVE___BUILTIN_POPCOUNT
225 count += __builtin_popcount(x);
236 sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
239 * The maximum number of signal names to be printed is NSIG * 2 / 3.
240 * Most of signal names have length 7,
241 * average length of signal names is less than 7.
242 * The length of prefix string does not exceed 16.
244 static char outstr[128 + 8 * (NSIG * 2 / 3)];
247 const uint32_t *mask;
248 uint32_t inverted_mask[NSIG / 32];
253 s = stpcpy(outstr, prefix);
256 /* length of signal mask in 4-byte words */
257 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
259 /* check whether 2/3 or more bits are set */
260 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
261 /* show those signals that are NOT in the mask */
263 for (j = 0; j < size; ++j)
264 inverted_mask[j] = ~mask[j];
265 mask = inverted_mask;
270 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
274 s = stpcpy(s, signalent[i] + 3);
277 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
278 s += sprintf(s, "RT_%u", i - __SIGRTMIN);
282 s += sprintf(s, "%u", i);
293 #define tprintsigmask_addr(prefix, mask) \
294 tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
296 #define sprintsigmask_val(prefix, mask) \
297 sprintsigmask_n((prefix), &(mask), sizeof(mask))
299 #define tprintsigmask_val(prefix, mask) \
300 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
305 tprints(signame(nr));
309 print_sigset_addr_len(struct tcb *tcp, long addr, long len)
317 /* Here len is usually equals NSIG / 8 or current_wordsize.
318 * But we code this defensively:
322 tprintf("%#lx", addr);
328 len = (len + 3) & ~3;
330 if (umoven(tcp, addr, len, mask) < 0)
332 tprints(sprintsigmask_n("", mask, len));
336 #define ILL_ILLOPC 1 /* illegal opcode */
337 #define ILL_ILLOPN 2 /* illegal operand */
338 #define ILL_ILLADR 3 /* illegal addressing mode */
339 #define ILL_ILLTRP 4 /* illegal trap */
340 #define ILL_PRVOPC 5 /* privileged opcode */
341 #define ILL_PRVREG 6 /* privileged register */
342 #define ILL_COPROC 7 /* coprocessor error */
343 #define ILL_BADSTK 8 /* internal stack error */
344 #define FPE_INTDIV 1 /* integer divide by zero */
345 #define FPE_INTOVF 2 /* integer overflow */
346 #define FPE_FLTDIV 3 /* floating point divide by zero */
347 #define FPE_FLTOVF 4 /* floating point overflow */
348 #define FPE_FLTUND 5 /* floating point underflow */
349 #define FPE_FLTRES 6 /* floating point inexact result */
350 #define FPE_FLTINV 7 /* floating point invalid operation */
351 #define FPE_FLTSUB 8 /* subscript out of range */
352 #define SEGV_MAPERR 1 /* address not mapped to object */
353 #define SEGV_ACCERR 2 /* invalid permissions for mapped object */
354 #define BUS_ADRALN 1 /* invalid address alignment */
355 #define BUS_ADRERR 2 /* non-existant physical address */
356 #define BUS_OBJERR 3 /* object specific hardware error */
357 #define TRAP_BRKPT 1 /* process breakpoint */
358 #define TRAP_TRACE 2 /* process trace trap */
359 #define CLD_EXITED 1 /* child has exited */
360 #define CLD_KILLED 2 /* child was killed */
361 #define CLD_DUMPED 3 /* child terminated abnormally */
362 #define CLD_TRAPPED 4 /* traced child has trapped */
363 #define CLD_STOPPED 5 /* child has stopped */
364 #define CLD_CONTINUED 6 /* stopped child has continued */
365 #define POLL_IN 1 /* data input available */
366 #define POLL_OUT 2 /* output buffers available */
367 #define POLL_MSG 3 /* input message available */
368 #define POLL_ERR 4 /* i/o error */
369 #define POLL_PRI 5 /* high priority input available */
370 #define POLL_HUP 6 /* device disconnected */
371 #define SI_KERNEL 0x80 /* sent by kernel */
372 #define SI_USER 0 /* sent by kill, sigsend, raise */
373 #define SI_QUEUE -1 /* sent by sigqueue */
374 #define SI_TIMER -2 /* sent by timer expiration */
375 #define SI_MESGQ -3 /* sent by real time mesq state change */
376 #define SI_ASYNCIO -4 /* sent by AIO completion */
377 #define SI_SIGIO -5 /* sent by SIGIO */
378 #define SI_TKILL -6 /* sent by tkill */
379 #define SI_DETHREAD -7 /* sent by execve killing subsidiary threads */
380 #define SI_ASYNCNL -60 /* sent by asynch name lookup completion */
384 # define SI_FROMUSER(sip) ((sip)->si_code <= 0)
387 static const struct xlat siginfo_codes[] = {
427 static const struct xlat sigill_codes[] = {
439 static const struct xlat sigfpe_codes[] = {
451 static const struct xlat sigtrap_codes[] = {
457 static const struct xlat sigchld_codes[] = {
467 static const struct xlat sigpoll_codes[] = {
477 static const struct xlat sigprof_codes[] = {
485 static const struct xlat sigemt_codes[] = {
493 static const struct xlat sigsegv_codes[] = {
499 static const struct xlat sigbus_codes[] = {
507 printsigsource(const siginfo_t *sip)
509 tprintf(", si_pid=%lu, si_uid=%lu",
510 (unsigned long) sip->si_pid,
511 (unsigned long) sip->si_uid);
515 printsigval(const siginfo_t *sip, int verbose)
520 tprintf(", si_value={int=%u, ptr=%#lx}",
522 (unsigned long) sip->si_ptr);
526 printsiginfo(siginfo_t *sip, int verbose)
530 if (sip->si_signo == 0) {
534 tprints("{si_signo=");
535 printsignal(sip->si_signo);
536 code = xlookup(siginfo_codes, sip->si_code);
538 switch (sip->si_signo) {
540 code = xlookup(sigtrap_codes, sip->si_code);
543 code = xlookup(sigchld_codes, sip->si_code);
546 code = xlookup(sigpoll_codes, sip->si_code);
549 code = xlookup(sigprof_codes, sip->si_code);
552 code = xlookup(sigill_codes, sip->si_code);
556 code = xlookup(sigemt_codes, sip->si_code);
560 code = xlookup(sigfpe_codes, sip->si_code);
563 code = xlookup(sigsegv_codes, sip->si_code);
566 code = xlookup(sigbus_codes, sip->si_code);
571 tprintf(", si_code=%s", code);
573 tprintf(", si_code=%#x", sip->si_code);
575 if (sip->si_code != SI_NOINFO)
579 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
580 tprintf(", si_errno=%d", sip->si_errno);
582 tprintf(", si_errno=%s",
583 errnoent[sip->si_errno]);
586 if (SI_FROMUSER(sip)) {
587 switch (sip->si_code) {
600 tprintf(", si_timerid=%#x, si_overrun=%d",
601 sip->si_timerid, sip->si_overrun);
602 printsigval(sip, verbose);
608 printsigval(sip, verbose);
613 #endif /* SI_FROMUSER */
615 switch (sip->si_signo) {
618 tprints(", si_status=");
619 if (sip->si_code == CLD_EXITED)
620 tprintf("%d", sip->si_status);
622 printsignal(sip->si_status);
626 tprintf(", si_utime=%llu, si_stime=%llu",
627 (unsigned long long) sip->si_utime,
628 (unsigned long long) sip->si_stime);
630 case SIGILL: case SIGFPE:
631 case SIGSEGV: case SIGBUS:
632 tprintf(", si_addr=%#lx",
633 (unsigned long) sip->si_addr);
636 switch (sip->si_code) {
637 case POLL_IN: case POLL_OUT: case POLL_MSG:
638 tprintf(", si_band=%ld",
639 (long) sip->si_band);
644 if (sip->si_pid || sip->si_uid)
647 printsigval(sip, verbose);
655 printsiginfo_at(struct tcb *tcp, long addr)
663 tprintf("%#lx", addr);
666 if (umove(tcp, addr, &si) < 0) {
670 printsiginfo(&si, verbose(tcp));
674 sys_sigsetmask(struct tcb *tcp)
677 tprintsigmask_val("", tcp->u_arg[0]);
679 else if (!syserror(tcp)) {
680 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
681 return RVAL_HEX | RVAL_STR;
686 #ifdef HAVE_SIGACTION
688 struct old_sigaction {
689 /* sa_handler may be a libc #define, need to use other name: */
691 unsigned int sa_flags;
692 void (*__sa_handler)(int);
693 /* Kernel treats sa_mask as an array of longs. */
694 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
696 void (*__sa_handler)(int);
697 unsigned long sa_mask;
698 unsigned long sa_flags;
699 void (*sa_restorer)(void);
703 struct old_sigaction32 {
704 /* sa_handler may be a libc #define, need to use other name: */
705 uint32_t __sa_handler;
708 uint32_t sa_restorer;
712 decode_old_sigaction(struct tcb *tcp, long addr)
714 struct old_sigaction sa;
721 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
722 tprintf("%#lx", addr);
726 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
727 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
728 struct old_sigaction32 sa32;
729 r = umove(tcp, addr, &sa32);
731 memset(&sa, 0, sizeof(sa));
732 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
733 sa.sa_flags = sa32.sa_flags;
734 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
735 sa.sa_mask = sa32.sa_mask;
740 r = umove(tcp, addr, &sa);
747 /* Architectures using function pointers, like
748 * hppa, may need to manipulate the function pointer
749 * to compute the result of a comparison. However,
750 * the __sa_handler function pointer exists only in
751 * the address space of the traced process, and can't
752 * be manipulated by strace. In order to prevent the
753 * compiler from generating code to manipulate
754 * __sa_handler we cast the function pointers to long. */
755 if ((long)sa.__sa_handler == (long)SIG_ERR)
756 tprints("{SIG_ERR, ");
757 else if ((long)sa.__sa_handler == (long)SIG_DFL)
758 tprints("{SIG_DFL, ");
759 else if ((long)sa.__sa_handler == (long)SIG_IGN)
760 tprints("{SIG_IGN, ");
762 tprintf("{%#lx, ", (long) sa.__sa_handler);
764 tprintsigmask_addr("", sa.sa_mask);
766 tprintsigmask_val("", sa.sa_mask);
769 printflags(sigact_flags, sa.sa_flags, "SA_???");
771 if (sa.sa_flags & SA_RESTORER)
772 tprintf(", %p", sa.sa_restorer);
778 sys_sigaction(struct tcb *tcp)
781 printsignal(tcp->u_arg[0]);
783 decode_old_sigaction(tcp, tcp->u_arg[1]);
786 decode_old_sigaction(tcp, tcp->u_arg[2]);
791 sys_signal(struct tcb *tcp)
794 printsignal(tcp->u_arg[0]);
796 switch (tcp->u_arg[1]) {
807 tprintf("%#lx", tcp->u_arg[1]);
811 else if (!syserror(tcp)) {
812 switch (tcp->u_rval) {
814 tcp->auxstr = "SIG_ERR"; break;
816 tcp->auxstr = "SIG_DFL"; break;
818 tcp->auxstr = "SIG_IGN"; break;
822 return RVAL_HEX | RVAL_STR;
827 #endif /* HAVE_SIGACTION */
830 sys_sigreturn(struct tcb *tcp)
834 struct arm_sigcontext {
835 unsigned long trap_no;
836 unsigned long error_code;
837 unsigned long oldmask;
838 unsigned long arm_r0;
839 unsigned long arm_r1;
840 unsigned long arm_r2;
841 unsigned long arm_r3;
842 unsigned long arm_r4;
843 unsigned long arm_r5;
844 unsigned long arm_r6;
845 unsigned long arm_r7;
846 unsigned long arm_r8;
847 unsigned long arm_r9;
848 unsigned long arm_r10;
849 unsigned long arm_fp;
850 unsigned long arm_ip;
851 unsigned long arm_sp;
852 unsigned long arm_lr;
853 unsigned long arm_pc;
854 unsigned long arm_cpsr;
855 unsigned long fault_address;
857 struct arm_ucontext {
858 unsigned long uc_flags;
859 unsigned long uc_link; /* struct ucontext* */
860 /* The next three members comprise stack_t struct: */
861 unsigned long ss_sp; /* void* */
862 unsigned long ss_flags; /* int */
863 unsigned long ss_size; /* size_t */
864 struct arm_sigcontext sc;
865 /* These two members are sigset_t: */
866 unsigned long uc_sigmask[2];
867 /* more fields follow, which we aren't interested in */
869 struct arm_ucontext uc;
870 if (umove(tcp, arm_regs.ARM_sp, &uc) < 0)
873 * Kernel fills out uc.sc.oldmask too when it sets up signal stack,
874 * but for sigmask restore, sigreturn syscall uses uc.uc_sigmask instead.
876 tprintsigmask_addr(") (mask ", uc.uc_sigmask);
878 #elif defined(S390) || defined(S390X)
881 struct sigcontext sc;
882 if (upeek(tcp->pid, PT_GPR15, &usp) < 0)
884 if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &sc) < 0)
886 tprintsigmask_addr(") (mask ", sc.oldmask);
888 #elif defined(I386) || defined(X86_64)
890 if (current_personality == 0) /* 64-bit */
894 struct i386_sigcontext_struct {
912 uint32_t esp_at_signal;
918 struct i386_fpstate {
926 uint8_t st[8][10]; /* 8*10 bytes: FP regs */
929 uint32_t fxsr_env[6];
932 uint8_t stx[8][16]; /* 8*16 bytes: FP regs, each padded to 16 bytes */
933 uint8_t xmm[8][16]; /* 8 XMM regs */
934 uint32_t padding1[44];
935 uint32_t padding2[12]; /* union with struct _fpx_sw_bytes */
938 struct i386_sigcontext_struct sc;
939 struct i386_fpstate fp;
940 uint32_t extramask[1];
942 /* On i386, sc is followed on stack by struct fpstate
943 * and after it an additional u32 extramask[1] which holds
944 * upper half of the mask.
947 if (umove(tcp, *i386_esp_ptr, &signal_stack) < 0)
949 sigmask[0] = signal_stack.sc.oldmask;
950 sigmask[1] = signal_stack.extramask[0];
951 tprintsigmask_addr(") (mask ", sigmask);
955 struct sigcontext sc;
957 /* offset of sigcontext in the kernel's sigframe structure: */
958 # define SIGFRAME_SC_OFFSET 0x90
959 if (upeek(tcp->pid, PT_R12, &sp) < 0)
961 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
963 tprintsigmask_val(") (mask ", sc.sc_mask);
965 #elif defined(POWERPC)
968 struct sigcontext sc;
970 esp = ppc_regs.gpr[1];
972 /* Skip dummy stack frame. */
974 if (current_personality == 0)
981 if (umove(tcp, esp, &sc) < 0)
983 tprintsigmask_val(") (mask ", sc.oldmask);
988 struct sigcontext sc;
989 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
991 if (umove(tcp, usp, &sc) < 0)
993 tprintsigmask_val(") (mask ", sc.sc_mask);
998 struct sigcontext sc;
999 if (upeek(tcp->pid, REG_FP, &fp) < 0)
1001 if (umove(tcp, fp, &sc) < 0)
1003 tprintsigmask_val(") (mask ", sc.sc_mask);
1005 #elif defined(SPARC) || defined(SPARC64)
1006 if (entering(tcp)) {
1009 i1 = sparc_regs.u_regs[U_REG_O1];
1010 if (umove(tcp, i1, &si) < 0) {
1011 perror_msg("sigreturn: umove");
1014 tprintsigmask_val(") (mask ", si.si_mask);
1016 #elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
1017 /* This decodes rt_sigreturn. The 64-bit ABIs do not have
1019 if (entering(tcp)) {
1022 if (upeek(tcp->pid, REG_SP, &sp) < 0)
1024 /* There are six words followed by a 128-byte siginfo. */
1025 sp = sp + 6 * 4 + 128;
1026 if (umove(tcp, sp, &uc) < 0)
1028 tprintsigmask_val(") (mask ", uc.uc_sigmask);
1031 if (entering(tcp)) {
1033 struct pt_regs regs;
1035 if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
1036 perror_msg("sigreturn: PTRACE_GETREGS");
1040 if (umove(tcp, sp, &si) < 0)
1042 tprintsigmask_val(") (mask ", si.si_mask);
1044 #elif defined(CRISV10) || defined(CRISV32)
1045 if (entering(tcp)) {
1046 struct sigcontext sc;
1047 long regs[PT_MAX+1];
1048 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
1049 perror_msg("sigreturn: PTRACE_GETREGS");
1052 if (umove(tcp, regs[PT_USP], &sc) < 0)
1054 tprintsigmask_val(") (mask ", sc.oldmask);
1057 if (entering(tcp)) {
1060 /* offset of ucontext in the kernel's sigframe structure */
1061 # define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
1062 if (umove(tcp, tile_regs.sp + SIGFRAME_UC_OFFSET, &uc) < 0)
1064 tprintsigmask_val(") (mask ", uc.uc_sigmask);
1066 #elif defined(MICROBLAZE)
1067 /* TODO: Verify that this is correct... */
1068 if (entering(tcp)) {
1069 struct sigcontext sc;
1071 /* Read r1, the stack pointer. */
1072 if (upeek(tcp->pid, 1 * 4, &sp) < 0)
1074 if (umove(tcp, sp, &sc) < 0)
1076 tprintsigmask_val(") (mask ", sc.oldmask);
1078 #elif defined(XTENSA)
1079 /* Xtensa only has rt_sys_sigreturn */
1081 /* ARC syscall ABI only supports rt_sys_sigreturn */
1083 # warning No sys_sigreturn() for this architecture
1084 # warning (no problem, just a reminder :-)
1090 sys_siggetmask(struct tcb *tcp)
1093 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
1095 return RVAL_HEX | RVAL_STR;
1099 sys_sigsuspend(struct tcb *tcp)
1101 if (entering(tcp)) {
1102 tprintsigmask_val("", tcp->u_arg[2]);
1107 #if !defined SS_ONSTACK
1108 #define SS_ONSTACK 1
1109 #define SS_DISABLE 2
1112 static const struct xlat sigaltstack_flags[] = {
1119 print_stack_t(struct tcb *tcp, unsigned long addr)
1129 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1130 if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) {
1136 r = umove(tcp, addr, &ss32);
1138 memset(&ss, 0, sizeof(ss));
1139 ss.ss_sp = (void*)(unsigned long) ss32.ss_sp;
1140 ss.ss_flags = ss32.ss_flags;
1141 ss.ss_size = (unsigned long) ss32.ss_size;
1146 r = umove(tcp, addr, &ss);
1149 tprintf("%#lx", addr);
1151 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
1152 printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
1153 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
1158 sys_sigaltstack(struct tcb *tcp)
1160 if (entering(tcp)) {
1161 print_stack_t(tcp, tcp->u_arg[0]);
1165 print_stack_t(tcp, tcp->u_arg[1]);
1170 #ifdef HAVE_SIGACTION
1172 /* "Old" sigprocmask, which operates with word-sized signal masks */
1174 sys_sigprocmask(struct tcb *tcp)
1177 if (entering(tcp)) {
1179 * Alpha/OSF is different: it doesn't pass in two pointers,
1180 * but rather passes in the new bitmask as an argument and
1181 * then returns the old bitmask. This "works" because we
1182 * only have 64 signals to worry about. If you want more,
1183 * use of the rt_sigprocmask syscall is required.
1185 * old = osf_sigprocmask(how, new);
1187 * ret = sigprocmask(how, &new, &old, ...);
1189 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1190 tprintsigmask_val(", ", tcp->u_arg[1]);
1192 else if (!syserror(tcp)) {
1193 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
1194 return RVAL_HEX | RVAL_STR;
1197 if (entering(tcp)) {
1198 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1200 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
1205 tprintf("%#lx", tcp->u_arg[2]);
1207 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
1209 # endif /* !ALPHA */
1213 #endif /* HAVE_SIGACTION */
1216 sys_kill(struct tcb *tcp)
1218 if (entering(tcp)) {
1220 widen_to_long(tcp->u_arg[0]),
1221 signame(tcp->u_arg[1])
1228 sys_tgkill(struct tcb *tcp)
1230 if (entering(tcp)) {
1231 tprintf("%ld, %ld, %s",
1232 widen_to_long(tcp->u_arg[0]),
1233 widen_to_long(tcp->u_arg[1]),
1234 signame(tcp->u_arg[2])
1241 sys_sigpending(struct tcb *tcp)
1245 tprintf("%#lx", tcp->u_arg[0]);
1247 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
1253 sys_rt_sigprocmask(struct tcb *tcp)
1255 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
1256 if (entering(tcp)) {
1257 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1259 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
1264 tprintf("%#lx", tcp->u_arg[2]);
1266 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
1267 tprintf(", %lu", tcp->u_arg[3]);
1272 /* Structure describing the action to be taken when a signal arrives. */
1273 struct new_sigaction
1275 /* sa_handler may be a libc #define, need to use other name: */
1277 unsigned int sa_flags;
1278 void (*__sa_handler)(int);
1280 void (*__sa_handler)(int);
1281 unsigned long sa_flags;
1282 void (*sa_restorer)(void);
1284 /* Kernel treats sa_mask as an array of longs. */
1285 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
1287 /* Same for i386-on-x86_64 and similar cases */
1288 struct new_sigaction32
1290 uint32_t __sa_handler;
1292 uint32_t sa_restorer;
1293 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
1297 decode_new_sigaction(struct tcb *tcp, long addr)
1299 struct new_sigaction sa;
1306 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
1307 tprintf("%#lx", addr);
1310 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1311 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
1312 struct new_sigaction32 sa32;
1313 r = umove(tcp, addr, &sa32);
1315 memset(&sa, 0, sizeof(sa));
1316 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
1317 sa.sa_flags = sa32.sa_flags;
1318 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
1319 /* Kernel treats sa_mask as an array of longs.
1320 * For 32-bit process, "long" is uint32_t, thus, for example,
1321 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
1322 * But for (64-bit) kernel, 32th bit in sa_mask is
1323 * 32th bit in 0th (64-bit) long!
1324 * For little-endian, it's the same.
1325 * For big-endian, we swap 32-bit words.
1327 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
1332 r = umove(tcp, addr, &sa);
1338 /* Architectures using function pointers, like
1339 * hppa, may need to manipulate the function pointer
1340 * to compute the result of a comparison. However,
1341 * the __sa_handler function pointer exists only in
1342 * the address space of the traced process, and can't
1343 * be manipulated by strace. In order to prevent the
1344 * compiler from generating code to manipulate
1345 * __sa_handler we cast the function pointers to long. */
1346 if ((long)sa.__sa_handler == (long)SIG_ERR)
1347 tprints("{SIG_ERR, ");
1348 else if ((long)sa.__sa_handler == (long)SIG_DFL)
1349 tprints("{SIG_DFL, ");
1350 else if ((long)sa.__sa_handler == (long)SIG_IGN)
1351 tprints("{SIG_IGN, ");
1353 tprintf("{%#lx, ", (long) sa.__sa_handler);
1355 * Sigset size is in tcp->u_arg[4] (SPARC)
1356 * or in tcp->u_arg[3] (all other),
1357 * but kernel won't handle sys_rt_sigaction
1358 * with wrong sigset size (just returns EINVAL instead).
1359 * We just fetch the right size, which is NSIG / 8.
1361 tprintsigmask_val("", sa.sa_mask);
1364 printflags(sigact_flags, sa.sa_flags, "SA_???");
1366 if (sa.sa_flags & SA_RESTORER)
1367 tprintf(", %p", sa.sa_restorer);
1373 sys_rt_sigaction(struct tcb *tcp)
1375 if (entering(tcp)) {
1376 printsignal(tcp->u_arg[0]);
1378 decode_new_sigaction(tcp, tcp->u_arg[1]);
1381 decode_new_sigaction(tcp, tcp->u_arg[2]);
1382 #if defined(SPARC) || defined(SPARC64)
1383 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
1384 #elif defined(ALPHA)
1385 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
1387 tprintf(", %lu", tcp->u_arg[3]);
1394 sys_rt_sigpending(struct tcb *tcp)
1398 * One of the few syscalls where sigset size (arg[1])
1399 * is allowed to be <= NSIG / 8, not strictly ==.
1400 * This allows non-rt sigpending() syscall
1401 * to reuse rt_sigpending() code in kernel.
1404 tprintf("%#lx", tcp->u_arg[0]);
1406 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1407 tprintf(", %lu", tcp->u_arg[1]);
1413 sys_rt_sigsuspend(struct tcb *tcp)
1415 if (entering(tcp)) {
1416 /* NB: kernel requires arg[1] == NSIG / 8 */
1417 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1418 tprintf(", %lu", tcp->u_arg[1]);
1424 print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
1428 printsiginfo_at(tcp, uinfo);
1432 sys_rt_sigqueueinfo(struct tcb *tcp)
1434 if (entering(tcp)) {
1435 tprintf("%lu, ", tcp->u_arg[0]);
1436 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1442 sys_rt_tgsigqueueinfo(struct tcb *tcp)
1444 if (entering(tcp)) {
1445 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1446 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
1451 int sys_rt_sigtimedwait(struct tcb *tcp)
1453 /* NB: kernel requires arg[3] == NSIG / 8 */
1454 if (entering(tcp)) {
1455 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
1457 /* This is the only "return" parameter, */
1458 if (tcp->u_arg[1] != 0)
1460 /* ... if it's NULL, can decode all on entry */
1463 else if (tcp->u_arg[1] != 0) {
1464 /* syscall exit, and u_arg[1] wasn't NULL */
1465 printsiginfo_at(tcp, tcp->u_arg[1]);
1469 /* syscall exit, and u_arg[1] was NULL */
1472 print_timespec(tcp, tcp->u_arg[2]);
1473 tprintf(", %lu", tcp->u_arg[3]);
1478 sys_restart_syscall(struct tcb *tcp)
1481 tprints("<... resuming interrupted call ...>");
1486 do_signalfd(struct tcb *tcp, int flags_arg)
1488 /* NB: kernel requires arg[2] == NSIG / 8 */
1489 if (entering(tcp)) {
1490 printfd(tcp, tcp->u_arg[0]);
1492 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1493 tprintf(", %lu", tcp->u_arg[2]);
1494 if (flags_arg >= 0) {
1496 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1503 sys_signalfd(struct tcb *tcp)
1505 return do_signalfd(tcp, -1);
1509 sys_signalfd4(struct tcb *tcp)
1511 return do_signalfd(tcp, 3);