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.
37 # warning NSIG is not defined, using 32
43 /* The libc headers do not define this constant since it should only be
44 used by the implementation. So we define it here. */
46 # ifdef ASM_SA_RESTORER
47 # define SA_RESTORER ASM_SA_RESTORER
52 * Some architectures define SA_RESTORER in their headers,
53 * but do not actually have sa_restorer.
55 * Some architectures, otherwise, do not define SA_RESTORER in their headers,
56 * but actually have sa_restorer.
59 # if defined HPPA || defined IA64
60 # define HAVE_SA_RESTORER 0
62 # define HAVE_SA_RESTORER 1
64 #else /* !SA_RESTORER */
65 # if defined SPARC || defined SPARC64 || defined M68K
66 # define HAVE_SA_RESTORER 1
68 # define HAVE_SA_RESTORER 0
72 #include "xlat/sigact_flags.h"
73 #include "xlat/sigprocmaskcmds.h"
75 /* Anonymous realtime signals. */
77 /* Linux kernel >= 3.18 defines SIGRTMIN to 32 on all architectures. */
78 # define ASM_SIGRTMIN 32
81 /* Under glibc 2.1, SIGRTMAX et al are functions, but __SIGRTMAX is a
82 constant. This is what we want. Otherwise, just use SIGRTMAX. */
85 # define __SIGRTMAX SIGRTMAX
89 # define ASM_SIGRTMAX __SIGRTMAX
93 /* Note on the size of sigset_t:
95 * In glibc, sigset_t is an array with space for 1024 bits (!),
96 * even though all arches supported by Linux have only 64 signals
97 * except MIPS, which has 128. IOW, it is 128 bytes long.
99 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
100 * However, some old syscall return only 32 lower bits (one word).
101 * Example: sys_sigpending vs sys_rt_sigpending.
103 * Be aware of this fact when you try to
104 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
105 * - sizeof(sigset_t) is much bigger than you think,
106 * it may overflow tcp->u_arg[] array, and it may try to copy more data
107 * than is really available in <something>.
109 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
110 * may be a bad idea: it'll try to read much more data than needed
111 * to fetch a sigset_t.
112 * Use (NSIG / 8) as a size instead.
116 signame(const int sig)
118 static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
121 const unsigned int s = sig;
126 if (s >= ASM_SIGRTMIN && s <= ASM_SIGRTMAX) {
127 sprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN);
132 sprintf(buf, "%d", sig);
137 popcount32(const uint32_t *a, unsigned int size)
139 unsigned int count = 0;
141 for (; size; ++a, --size) {
144 #ifdef HAVE___BUILTIN_POPCOUNT
145 count += __builtin_popcount(x);
156 sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
159 * The maximum number of signal names to be printed is NSIG * 2 / 3.
160 * Most of signal names have length 7,
161 * average length of signal names is less than 7.
162 * The length of prefix string does not exceed 16.
164 static char outstr[128 + 8 * (NSIG * 2 / 3)];
167 const uint32_t *mask;
168 uint32_t inverted_mask[NSIG / 32];
173 s = stpcpy(outstr, prefix);
176 /* length of signal mask in 4-byte words */
177 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
179 /* check whether 2/3 or more bits are set */
180 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
181 /* show those signals that are NOT in the mask */
183 for (j = 0; j < size; ++j)
184 inverted_mask[j] = ~mask[j];
185 mask = inverted_mask;
190 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
193 if ((unsigned) i < nsignals) {
194 s = stpcpy(s, signalent[i] + 3);
197 else if (i >= ASM_SIGRTMIN && i <= ASM_SIGRTMAX) {
198 s += sprintf(s, "RT_%u", i - ASM_SIGRTMIN);
202 s += sprintf(s, "%u", i);
213 #define sprintsigmask_val(prefix, mask) \
214 sprintsigmask_n((prefix), &(mask), sizeof(mask))
216 #define tprintsigmask_val(prefix, mask) \
217 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
222 tprints(signame(nr));
226 print_sigset_addr_len(struct tcb *tcp, long addr, long len)
234 /* Here len is usually equals NSIG / 8 or current_wordsize.
235 * But we code this defensively:
239 tprintf("%#lx", addr);
245 len = (len + 3) & ~3;
247 if (umoven(tcp, addr, len, mask) < 0)
249 tprints(sprintsigmask_n("", mask, len));
253 sys_sigsetmask(struct tcb *tcp)
256 tprintsigmask_val("", tcp->u_arg[0]);
258 else if (!syserror(tcp)) {
259 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
260 return RVAL_HEX | RVAL_STR;
265 #ifdef HAVE_SIGACTION
267 struct old_sigaction {
268 /* sa_handler may be a libc #define, need to use other name: */
270 unsigned int sa_flags;
271 void (*__sa_handler)(int);
272 /* Kernel treats sa_mask as an array of longs. */
273 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
275 void (*__sa_handler)(int);
276 unsigned long sa_mask;
277 unsigned long sa_flags;
280 void (*sa_restorer)(void);
284 struct old_sigaction32 {
285 /* sa_handler may be a libc #define, need to use other name: */
286 uint32_t __sa_handler;
290 uint32_t sa_restorer;
295 decode_old_sigaction(struct tcb *tcp, long addr)
297 struct old_sigaction sa;
304 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
305 tprintf("%#lx", addr);
309 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
310 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
311 struct old_sigaction32 sa32;
312 r = umove(tcp, addr, &sa32);
314 memset(&sa, 0, sizeof(sa));
315 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
316 sa.sa_flags = sa32.sa_flags;
317 #if HAVE_SA_RESTORER && defined SA_RESTORER
318 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
320 sa.sa_mask = sa32.sa_mask;
325 r = umove(tcp, addr, &sa);
332 /* Architectures using function pointers, like
333 * hppa, may need to manipulate the function pointer
334 * to compute the result of a comparison. However,
335 * the __sa_handler function pointer exists only in
336 * the address space of the traced process, and can't
337 * be manipulated by strace. In order to prevent the
338 * compiler from generating code to manipulate
339 * __sa_handler we cast the function pointers to long. */
340 if ((long)sa.__sa_handler == (long)SIG_ERR)
341 tprints("{SIG_ERR, ");
342 else if ((long)sa.__sa_handler == (long)SIG_DFL)
343 tprints("{SIG_DFL, ");
344 else if ((long)sa.__sa_handler == (long)SIG_IGN)
345 tprints("{SIG_IGN, ");
347 tprintf("{%#lx, ", (long) sa.__sa_handler);
349 tprintsigmask_addr("", sa.sa_mask);
351 tprintsigmask_val("", sa.sa_mask);
354 printflags(sigact_flags, sa.sa_flags, "SA_???");
355 #if HAVE_SA_RESTORER && defined SA_RESTORER
356 if (sa.sa_flags & SA_RESTORER)
357 tprintf(", %p", sa.sa_restorer);
363 sys_sigaction(struct tcb *tcp)
366 printsignal(tcp->u_arg[0]);
368 decode_old_sigaction(tcp, tcp->u_arg[1]);
371 decode_old_sigaction(tcp, tcp->u_arg[2]);
376 sys_signal(struct tcb *tcp)
379 printsignal(tcp->u_arg[0]);
381 switch (tcp->u_arg[1]) {
392 tprintf("%#lx", tcp->u_arg[1]);
396 else if (!syserror(tcp)) {
397 switch (tcp->u_rval) {
399 tcp->auxstr = "SIG_ERR"; break;
401 tcp->auxstr = "SIG_DFL"; break;
403 tcp->auxstr = "SIG_IGN"; break;
407 return RVAL_HEX | RVAL_STR;
412 #endif /* HAVE_SIGACTION */
415 sys_siggetmask(struct tcb *tcp)
418 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
420 return RVAL_HEX | RVAL_STR;
424 sys_sigsuspend(struct tcb *tcp)
427 tprintsigmask_val("", tcp->u_arg[2]);
432 #ifdef HAVE_SIGACTION
434 /* "Old" sigprocmask, which operates with word-sized signal masks */
436 sys_sigprocmask(struct tcb *tcp)
441 * Alpha/OSF is different: it doesn't pass in two pointers,
442 * but rather passes in the new bitmask as an argument and
443 * then returns the old bitmask. This "works" because we
444 * only have 64 signals to worry about. If you want more,
445 * use of the rt_sigprocmask syscall is required.
447 * old = osf_sigprocmask(how, new);
449 * ret = sigprocmask(how, &new, &old, ...);
451 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
452 tprintsigmask_val(", ", tcp->u_arg[1]);
454 else if (!syserror(tcp)) {
455 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
456 return RVAL_HEX | RVAL_STR;
460 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
462 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
467 tprintf("%#lx", tcp->u_arg[2]);
469 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
475 #endif /* HAVE_SIGACTION */
478 sys_kill(struct tcb *tcp)
482 widen_to_long(tcp->u_arg[0]),
483 signame(tcp->u_arg[1])
490 sys_tgkill(struct tcb *tcp)
493 tprintf("%ld, %ld, %s",
494 widen_to_long(tcp->u_arg[0]),
495 widen_to_long(tcp->u_arg[1]),
496 signame(tcp->u_arg[2])
503 sys_sigpending(struct tcb *tcp)
507 tprintf("%#lx", tcp->u_arg[0]);
509 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
515 sys_rt_sigprocmask(struct tcb *tcp)
517 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
519 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
521 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
526 tprintf("%#lx", tcp->u_arg[2]);
528 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
529 tprintf(", %lu", tcp->u_arg[3]);
534 /* Structure describing the action to be taken when a signal arrives. */
537 /* sa_handler may be a libc #define, need to use other name: */
539 unsigned int sa_flags;
540 void (*__sa_handler)(int);
542 void (*__sa_handler)(int);
543 unsigned long sa_flags;
546 void (*sa_restorer)(void);
548 /* Kernel treats sa_mask as an array of longs. */
549 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
551 /* Same for i386-on-x86_64 and similar cases */
552 struct new_sigaction32
554 uint32_t __sa_handler;
557 uint32_t sa_restorer;
559 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
563 decode_new_sigaction(struct tcb *tcp, long addr)
565 struct new_sigaction sa;
572 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
573 tprintf("%#lx", addr);
576 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
577 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
578 struct new_sigaction32 sa32;
579 r = umove(tcp, addr, &sa32);
581 memset(&sa, 0, sizeof(sa));
582 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
583 sa.sa_flags = sa32.sa_flags;
584 #if HAVE_SA_RESTORER && defined SA_RESTORER
585 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
587 /* Kernel treats sa_mask as an array of longs.
588 * For 32-bit process, "long" is uint32_t, thus, for example,
589 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
590 * But for (64-bit) kernel, 32th bit in sa_mask is
591 * 32th bit in 0th (64-bit) long!
592 * For little-endian, it's the same.
593 * For big-endian, we swap 32-bit words.
595 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
600 r = umove(tcp, addr, &sa);
606 /* Architectures using function pointers, like
607 * hppa, may need to manipulate the function pointer
608 * to compute the result of a comparison. However,
609 * the __sa_handler function pointer exists only in
610 * the address space of the traced process, and can't
611 * be manipulated by strace. In order to prevent the
612 * compiler from generating code to manipulate
613 * __sa_handler we cast the function pointers to long. */
614 if ((long)sa.__sa_handler == (long)SIG_ERR)
615 tprints("{SIG_ERR, ");
616 else if ((long)sa.__sa_handler == (long)SIG_DFL)
617 tprints("{SIG_DFL, ");
618 else if ((long)sa.__sa_handler == (long)SIG_IGN)
619 tprints("{SIG_IGN, ");
621 tprintf("{%#lx, ", (long) sa.__sa_handler);
623 * Sigset size is in tcp->u_arg[4] (SPARC)
624 * or in tcp->u_arg[3] (all other),
625 * but kernel won't handle sys_rt_sigaction
626 * with wrong sigset size (just returns EINVAL instead).
627 * We just fetch the right size, which is NSIG / 8.
629 tprintsigmask_val("", sa.sa_mask);
632 printflags(sigact_flags, sa.sa_flags, "SA_???");
633 #if HAVE_SA_RESTORER && defined SA_RESTORER
634 if (sa.sa_flags & SA_RESTORER)
635 tprintf(", %p", sa.sa_restorer);
641 sys_rt_sigaction(struct tcb *tcp)
644 printsignal(tcp->u_arg[0]);
646 decode_new_sigaction(tcp, tcp->u_arg[1]);
649 decode_new_sigaction(tcp, tcp->u_arg[2]);
650 #if defined(SPARC) || defined(SPARC64)
651 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
653 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
655 tprintf(", %lu", tcp->u_arg[3]);
662 sys_rt_sigpending(struct tcb *tcp)
666 * One of the few syscalls where sigset size (arg[1])
667 * is allowed to be <= NSIG / 8, not strictly ==.
668 * This allows non-rt sigpending() syscall
669 * to reuse rt_sigpending() code in kernel.
672 tprintf("%#lx", tcp->u_arg[0]);
674 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
675 tprintf(", %lu", tcp->u_arg[1]);
681 sys_rt_sigsuspend(struct tcb *tcp)
684 /* NB: kernel requires arg[1] == NSIG / 8 */
685 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
686 tprintf(", %lu", tcp->u_arg[1]);
692 print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
696 printsiginfo_at(tcp, uinfo);
700 sys_rt_sigqueueinfo(struct tcb *tcp)
703 tprintf("%lu, ", tcp->u_arg[0]);
704 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
710 sys_rt_tgsigqueueinfo(struct tcb *tcp)
713 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
714 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
719 int sys_rt_sigtimedwait(struct tcb *tcp)
721 /* NB: kernel requires arg[3] == NSIG / 8 */
723 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
725 /* This is the only "return" parameter, */
726 if (tcp->u_arg[1] != 0)
728 /* ... if it's NULL, can decode all on entry */
731 else if (tcp->u_arg[1] != 0) {
732 /* syscall exit, and u_arg[1] wasn't NULL */
733 printsiginfo_at(tcp, tcp->u_arg[1]);
737 /* syscall exit, and u_arg[1] was NULL */
740 print_timespec(tcp, tcp->u_arg[2]);
741 tprintf(", %lu", tcp->u_arg[3]);
746 sys_restart_syscall(struct tcb *tcp)
749 tprintf("<... resuming interrupted %s ...>",
751 ? tcp->s_prev_ent->sys_name
759 do_signalfd(struct tcb *tcp, int flags_arg)
761 /* NB: kernel requires arg[2] == NSIG / 8 */
763 printfd(tcp, tcp->u_arg[0]);
765 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
766 tprintf(", %lu", tcp->u_arg[2]);
767 if (flags_arg >= 0) {
769 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
776 sys_signalfd(struct tcb *tcp)
778 return do_signalfd(tcp, -1);
782 sys_signalfd4(struct tcb *tcp)
784 return do_signalfd(tcp, 3);