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));
255 tprintsigmask_val("", tcp->u_arg[0]);
257 else if (!syserror(tcp)) {
258 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
259 return RVAL_HEX | RVAL_STR;
264 #ifdef HAVE_SIGACTION
266 struct old_sigaction {
267 /* sa_handler may be a libc #define, need to use other name: */
269 unsigned int sa_flags;
270 void (*__sa_handler)(int);
271 /* Kernel treats sa_mask as an array of longs. */
272 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
274 void (*__sa_handler)(int);
275 unsigned long sa_mask;
276 unsigned long sa_flags;
279 void (*sa_restorer)(void);
283 struct old_sigaction32 {
284 /* sa_handler may be a libc #define, need to use other name: */
285 uint32_t __sa_handler;
289 uint32_t sa_restorer;
294 decode_old_sigaction(struct tcb *tcp, long addr)
296 struct old_sigaction sa;
303 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
304 tprintf("%#lx", addr);
308 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
309 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
310 struct old_sigaction32 sa32;
311 r = umove(tcp, addr, &sa32);
313 memset(&sa, 0, sizeof(sa));
314 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
315 sa.sa_flags = sa32.sa_flags;
316 #if HAVE_SA_RESTORER && defined SA_RESTORER
317 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
319 sa.sa_mask = sa32.sa_mask;
324 r = umove(tcp, addr, &sa);
331 /* Architectures using function pointers, like
332 * hppa, may need to manipulate the function pointer
333 * to compute the result of a comparison. However,
334 * the __sa_handler function pointer exists only in
335 * the address space of the traced process, and can't
336 * be manipulated by strace. In order to prevent the
337 * compiler from generating code to manipulate
338 * __sa_handler we cast the function pointers to long. */
339 if ((long)sa.__sa_handler == (long)SIG_ERR)
340 tprints("{SIG_ERR, ");
341 else if ((long)sa.__sa_handler == (long)SIG_DFL)
342 tprints("{SIG_DFL, ");
343 else if ((long)sa.__sa_handler == (long)SIG_IGN)
344 tprints("{SIG_IGN, ");
346 tprintf("{%#lx, ", (long) sa.__sa_handler);
348 tprintsigmask_addr("", sa.sa_mask);
350 tprintsigmask_val("", sa.sa_mask);
353 printflags(sigact_flags, sa.sa_flags, "SA_???");
354 #if HAVE_SA_RESTORER && defined SA_RESTORER
355 if (sa.sa_flags & SA_RESTORER)
356 tprintf(", %p", sa.sa_restorer);
364 printsignal(tcp->u_arg[0]);
366 decode_old_sigaction(tcp, tcp->u_arg[1]);
369 decode_old_sigaction(tcp, tcp->u_arg[2]);
376 printsignal(tcp->u_arg[0]);
378 switch (tcp->u_arg[1]) {
389 tprintf("%#lx", tcp->u_arg[1]);
393 else if (!syserror(tcp)) {
394 switch (tcp->u_rval) {
396 tcp->auxstr = "SIG_ERR"; break;
398 tcp->auxstr = "SIG_DFL"; break;
400 tcp->auxstr = "SIG_IGN"; break;
404 return RVAL_HEX | RVAL_STR;
409 #endif /* HAVE_SIGACTION */
414 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
416 return RVAL_HEX | RVAL_STR;
422 tprintsigmask_val("", tcp->u_arg[2]);
427 #ifdef HAVE_SIGACTION
429 /* "Old" sigprocmask, which operates with word-sized signal masks */
430 SYS_FUNC(sigprocmask)
435 * Alpha/OSF is different: it doesn't pass in two pointers,
436 * but rather passes in the new bitmask as an argument and
437 * then returns the old bitmask. This "works" because we
438 * only have 64 signals to worry about. If you want more,
439 * use of the rt_sigprocmask syscall is required.
441 * old = osf_sigprocmask(how, new);
443 * ret = sigprocmask(how, &new, &old, ...);
445 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
446 tprintsigmask_val(", ", tcp->u_arg[1]);
448 else if (!syserror(tcp)) {
449 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
450 return RVAL_HEX | RVAL_STR;
454 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
456 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
461 tprintf("%#lx", tcp->u_arg[2]);
463 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
469 #endif /* HAVE_SIGACTION */
475 widen_to_long(tcp->u_arg[0]),
476 signame(tcp->u_arg[1])
485 tprintf("%ld, %ld, %s",
486 widen_to_long(tcp->u_arg[0]),
487 widen_to_long(tcp->u_arg[1]),
488 signame(tcp->u_arg[2])
498 tprintf("%#lx", tcp->u_arg[0]);
500 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
505 SYS_FUNC(rt_sigprocmask)
507 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
509 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
511 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
516 tprintf("%#lx", tcp->u_arg[2]);
518 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
519 tprintf(", %lu", tcp->u_arg[3]);
524 /* Structure describing the action to be taken when a signal arrives. */
527 /* sa_handler may be a libc #define, need to use other name: */
529 unsigned int sa_flags;
530 void (*__sa_handler)(int);
532 void (*__sa_handler)(int);
533 unsigned long sa_flags;
536 void (*sa_restorer)(void);
538 /* Kernel treats sa_mask as an array of longs. */
539 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
541 /* Same for i386-on-x86_64 and similar cases */
542 struct new_sigaction32
544 uint32_t __sa_handler;
547 uint32_t sa_restorer;
549 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
553 decode_new_sigaction(struct tcb *tcp, long addr)
555 struct new_sigaction sa;
562 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
563 tprintf("%#lx", addr);
566 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
567 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
568 struct new_sigaction32 sa32;
569 r = umove(tcp, addr, &sa32);
571 memset(&sa, 0, sizeof(sa));
572 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
573 sa.sa_flags = sa32.sa_flags;
574 #if HAVE_SA_RESTORER && defined SA_RESTORER
575 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
577 /* Kernel treats sa_mask as an array of longs.
578 * For 32-bit process, "long" is uint32_t, thus, for example,
579 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
580 * But for (64-bit) kernel, 32th bit in sa_mask is
581 * 32th bit in 0th (64-bit) long!
582 * For little-endian, it's the same.
583 * For big-endian, we swap 32-bit words.
585 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
590 r = umove(tcp, addr, &sa);
596 /* Architectures using function pointers, like
597 * hppa, may need to manipulate the function pointer
598 * to compute the result of a comparison. However,
599 * the __sa_handler function pointer exists only in
600 * the address space of the traced process, and can't
601 * be manipulated by strace. In order to prevent the
602 * compiler from generating code to manipulate
603 * __sa_handler we cast the function pointers to long. */
604 if ((long)sa.__sa_handler == (long)SIG_ERR)
605 tprints("{SIG_ERR, ");
606 else if ((long)sa.__sa_handler == (long)SIG_DFL)
607 tprints("{SIG_DFL, ");
608 else if ((long)sa.__sa_handler == (long)SIG_IGN)
609 tprints("{SIG_IGN, ");
611 tprintf("{%#lx, ", (long) sa.__sa_handler);
613 * Sigset size is in tcp->u_arg[4] (SPARC)
614 * or in tcp->u_arg[3] (all other),
615 * but kernel won't handle sys_rt_sigaction
616 * with wrong sigset size (just returns EINVAL instead).
617 * We just fetch the right size, which is NSIG / 8.
619 tprintsigmask_val("", sa.sa_mask);
622 printflags(sigact_flags, sa.sa_flags, "SA_???");
623 #if HAVE_SA_RESTORER && defined SA_RESTORER
624 if (sa.sa_flags & SA_RESTORER)
625 tprintf(", %p", sa.sa_restorer);
630 SYS_FUNC(rt_sigaction)
633 printsignal(tcp->u_arg[0]);
635 decode_new_sigaction(tcp, tcp->u_arg[1]);
638 decode_new_sigaction(tcp, tcp->u_arg[2]);
639 #if defined(SPARC) || defined(SPARC64)
640 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
642 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
644 tprintf(", %lu", tcp->u_arg[3]);
650 SYS_FUNC(rt_sigpending)
654 * One of the few syscalls where sigset size (arg[1])
655 * is allowed to be <= NSIG / 8, not strictly ==.
656 * This allows non-rt sigpending() syscall
657 * to reuse rt_sigpending() code in kernel.
660 tprintf("%#lx", tcp->u_arg[0]);
662 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
663 tprintf(", %lu", tcp->u_arg[1]);
668 SYS_FUNC(rt_sigsuspend)
671 /* NB: kernel requires arg[1] == NSIG / 8 */
672 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
673 tprintf(", %lu", tcp->u_arg[1]);
679 print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
683 printsiginfo_at(tcp, uinfo);
686 SYS_FUNC(rt_sigqueueinfo)
689 tprintf("%lu, ", tcp->u_arg[0]);
690 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
695 SYS_FUNC(rt_tgsigqueueinfo)
698 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
699 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
704 SYS_FUNC(rt_sigtimedwait)
706 /* NB: kernel requires arg[3] == NSIG / 8 */
708 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
710 /* This is the only "return" parameter, */
711 if (tcp->u_arg[1] != 0)
713 /* ... if it's NULL, can decode all on entry */
716 else if (tcp->u_arg[1] != 0) {
717 /* syscall exit, and u_arg[1] wasn't NULL */
718 printsiginfo_at(tcp, tcp->u_arg[1]);
722 /* syscall exit, and u_arg[1] was NULL */
725 print_timespec(tcp, tcp->u_arg[2]);
726 tprintf(", %lu", tcp->u_arg[3]);
730 SYS_FUNC(restart_syscall)
733 tprintf("<... resuming interrupted %s ...>",
735 ? tcp->s_prev_ent->sys_name
743 do_signalfd(struct tcb *tcp, int flags_arg)
745 /* NB: kernel requires arg[2] == NSIG / 8 */
747 printfd(tcp, tcp->u_arg[0]);
749 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]);
750 tprintf(", %lu", tcp->u_arg[2]);
751 if (flags_arg >= 0) {
753 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
761 return do_signalfd(tcp, -1);
766 return do_signalfd(tcp, 3);