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.
38 # warning NSIG is not defined, using 32
44 /* The libc headers do not define this constant since it should only be
45 used by the implementation. So we define it here. */
47 # ifdef ASM_SA_RESTORER
48 # define SA_RESTORER ASM_SA_RESTORER
53 * Some architectures define SA_RESTORER in their headers,
54 * but do not actually have sa_restorer.
56 * Some architectures, otherwise, do not define SA_RESTORER in their headers,
57 * but actually have sa_restorer.
60 # if defined HPPA || defined IA64
61 # define HAVE_SA_RESTORER 0
63 # define HAVE_SA_RESTORER 1
65 #else /* !SA_RESTORER */
66 # if defined SPARC || defined SPARC64 || defined M68K
67 # define HAVE_SA_RESTORER 1
69 # define HAVE_SA_RESTORER 0
73 #include "xlat/sigact_flags.h"
74 #include "xlat/sigprocmaskcmds.h"
76 /* Anonymous realtime signals. */
78 /* Linux kernel >= 3.18 defines SIGRTMIN to 32 on all architectures. */
79 # define ASM_SIGRTMIN 32
82 /* Under glibc 2.1, SIGRTMAX et al are functions, but __SIGRTMAX is a
83 constant. This is what we want. Otherwise, just use SIGRTMAX. */
86 # define __SIGRTMAX SIGRTMAX
90 # define ASM_SIGRTMAX __SIGRTMAX
94 /* Note on the size of sigset_t:
96 * In glibc, sigset_t is an array with space for 1024 bits (!),
97 * even though all arches supported by Linux have only 64 signals
98 * except MIPS, which has 128. IOW, it is 128 bytes long.
100 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
101 * However, some old syscall return only 32 lower bits (one word).
102 * Example: sys_sigpending vs sys_rt_sigpending.
104 * Be aware of this fact when you try to
105 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
106 * - sizeof(sigset_t) is much bigger than you think,
107 * it may overflow tcp->u_arg[] array, and it may try to copy more data
108 * than is really available in <something>.
110 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
111 * may be a bad idea: it'll try to read much more data than needed
112 * to fetch a sigset_t.
113 * Use (NSIG / 8) as a size instead.
117 signame(const int sig)
119 static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
122 const unsigned int s = sig;
127 if (s >= ASM_SIGRTMIN && s <= ASM_SIGRTMAX) {
128 sprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN);
133 sprintf(buf, "%d", sig);
138 popcount32(const uint32_t *a, unsigned int size)
140 unsigned int count = 0;
142 for (; size; ++a, --size) {
145 #ifdef HAVE___BUILTIN_POPCOUNT
146 count += __builtin_popcount(x);
157 sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
160 * The maximum number of signal names to be printed is NSIG * 2 / 3.
161 * Most of signal names have length 7,
162 * average length of signal names is less than 7.
163 * The length of prefix string does not exceed 16.
165 static char outstr[128 + 8 * (NSIG * 2 / 3)];
168 const uint32_t *mask;
169 uint32_t inverted_mask[NSIG / 32];
174 s = stpcpy(outstr, prefix);
177 /* length of signal mask in 4-byte words */
178 size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
180 /* check whether 2/3 or more bits are set */
181 if (popcount32(mask, size) >= size * 32 * 2 / 3) {
182 /* show those signals that are NOT in the mask */
184 for (j = 0; j < size; ++j)
185 inverted_mask[j] = ~mask[j];
186 mask = inverted_mask;
191 for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
194 if ((unsigned) i < nsignals) {
195 s = stpcpy(s, signalent[i] + 3);
198 else if (i >= ASM_SIGRTMIN && i <= ASM_SIGRTMAX) {
199 s += sprintf(s, "RT_%u", i - ASM_SIGRTMIN);
203 s += sprintf(s, "%u", i);
214 #define sprintsigmask_val(prefix, mask) \
215 sprintsigmask_n((prefix), &(mask), sizeof(mask))
217 #define tprintsigmask_val(prefix, mask) \
218 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
223 tprints(signame(nr));
227 print_sigset_addr_len(struct tcb *tcp, long addr, long len)
231 /* Here len is usually equals NSIG / 8 or current_wordsize.
232 * But we code this defensively:
241 len = (len + 3) & ~3;
243 if (umoven_or_printaddr(tcp, addr, len, mask))
245 tprints(sprintsigmask_n("", mask, len));
251 tprintsigmask_val("", tcp->u_arg[0]);
253 else if (!syserror(tcp)) {
254 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
255 return RVAL_HEX | RVAL_STR;
260 #ifdef HAVE_SIGACTION
262 struct old_sigaction {
263 /* sa_handler may be a libc #define, need to use other name: */
265 unsigned int sa_flags;
266 void (*__sa_handler)(int);
267 /* Kernel treats sa_mask as an array of longs. */
268 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
270 void (*__sa_handler)(int);
271 unsigned long sa_mask;
272 unsigned long sa_flags;
275 void (*sa_restorer)(void);
279 struct old_sigaction32 {
280 /* sa_handler may be a libc #define, need to use other name: */
281 uint32_t __sa_handler;
285 uint32_t sa_restorer;
290 decode_old_sigaction(struct tcb *tcp, long addr)
292 struct old_sigaction sa;
294 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
295 if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) {
296 struct old_sigaction32 sa32;
298 if (umove_or_printaddr(tcp, addr, &sa32))
301 memset(&sa, 0, sizeof(sa));
302 sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler;
303 sa.sa_flags = sa32.sa_flags;
304 #if HAVE_SA_RESTORER && defined SA_RESTORER
305 sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer;
307 sa.sa_mask = sa32.sa_mask;
310 if (umove_or_printaddr(tcp, addr, &sa))
313 /* Architectures using function pointers, like
314 * hppa, may need to manipulate the function pointer
315 * to compute the result of a comparison. However,
316 * the __sa_handler function pointer exists only in
317 * the address space of the traced process, and can't
318 * be manipulated by strace. In order to prevent the
319 * compiler from generating code to manipulate
320 * __sa_handler we cast the function pointers to long. */
322 if ((long)sa.__sa_handler == (long)SIG_ERR)
324 else if ((long)sa.__sa_handler == (long)SIG_DFL)
326 else if ((long)sa.__sa_handler == (long)SIG_IGN)
329 printaddr((long) sa.__sa_handler);
332 tprintsigmask_addr("", sa.sa_mask);
334 tprintsigmask_val("", sa.sa_mask);
337 printflags(sigact_flags, sa.sa_flags, "SA_???");
338 #if HAVE_SA_RESTORER && defined SA_RESTORER
339 if (sa.sa_flags & SA_RESTORER)
340 tprintf(", %p", sa.sa_restorer);
348 printsignal(tcp->u_arg[0]);
350 decode_old_sigaction(tcp, tcp->u_arg[1]);
353 decode_old_sigaction(tcp, tcp->u_arg[2]);
360 printsignal(tcp->u_arg[0]);
362 switch (tcp->u_arg[1]) {
373 printaddr(tcp->u_arg[1]);
377 else if (!syserror(tcp)) {
378 switch (tcp->u_rval) {
380 tcp->auxstr = "SIG_ERR"; break;
382 tcp->auxstr = "SIG_DFL"; break;
384 tcp->auxstr = "SIG_IGN"; break;
388 return RVAL_HEX | RVAL_STR;
393 #endif /* HAVE_SIGACTION */
398 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
400 return RVAL_HEX | RVAL_STR;
405 tprintsigmask_val("", tcp->u_arg[2]);
410 #ifdef HAVE_SIGACTION
412 /* "Old" sigprocmask, which operates with word-sized signal masks */
413 SYS_FUNC(sigprocmask)
418 * Alpha/OSF is different: it doesn't pass in two pointers,
419 * but rather passes in the new bitmask as an argument and
420 * then returns the old bitmask. This "works" because we
421 * only have 64 signals to worry about. If you want more,
422 * use of the rt_sigprocmask syscall is required.
424 * old = osf_sigprocmask(how, new);
426 * ret = sigprocmask(how, &new, &old, ...);
428 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
429 tprintsigmask_val(", ", tcp->u_arg[1]);
431 else if (!syserror(tcp)) {
432 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
433 return RVAL_HEX | RVAL_STR;
437 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
439 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
443 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
449 #endif /* HAVE_SIGACTION */
454 widen_to_long(tcp->u_arg[0]),
455 signame(tcp->u_arg[1]));
462 tprintf("%ld, %ld, %s",
463 widen_to_long(tcp->u_arg[0]),
464 widen_to_long(tcp->u_arg[1]),
465 signame(tcp->u_arg[2]));
473 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
477 SYS_FUNC(rt_sigprocmask)
479 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
481 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
483 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
487 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
488 tprintf(", %lu", tcp->u_arg[3]);
493 /* Structure describing the action to be taken when a signal arrives. */
496 /* sa_handler may be a libc #define, need to use other name: */
498 unsigned int sa_flags;
499 void (*__sa_handler)(int);
501 void (*__sa_handler)(int);
502 unsigned long sa_flags;
505 void (*sa_restorer)(void);
507 /* Kernel treats sa_mask as an array of longs. */
508 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
510 /* Same for i386-on-x86_64 and similar cases */
511 struct new_sigaction32
513 uint32_t __sa_handler;
516 uint32_t sa_restorer;
518 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
522 decode_new_sigaction(struct tcb *tcp, long addr)
524 struct new_sigaction sa;
526 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
527 if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
528 struct new_sigaction32 sa32;
530 if (umove_or_printaddr(tcp, addr, &sa32))
533 memset(&sa, 0, sizeof(sa));
534 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
535 sa.sa_flags = sa32.sa_flags;
536 #if HAVE_SA_RESTORER && defined SA_RESTORER
537 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer;
539 /* Kernel treats sa_mask as an array of longs.
540 * For 32-bit process, "long" is uint32_t, thus, for example,
541 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
542 * But for (64-bit) kernel, 32th bit in sa_mask is
543 * 32th bit in 0th (64-bit) long!
544 * For little-endian, it's the same.
545 * For big-endian, we swap 32-bit words.
547 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
550 if (umove_or_printaddr(tcp, addr, &sa))
553 /* Architectures using function pointers, like
554 * hppa, may need to manipulate the function pointer
555 * to compute the result of a comparison. However,
556 * the __sa_handler function pointer exists only in
557 * the address space of the traced process, and can't
558 * be manipulated by strace. In order to prevent the
559 * compiler from generating code to manipulate
560 * __sa_handler we cast the function pointers to long. */
561 if ((long)sa.__sa_handler == (long)SIG_ERR)
562 tprints("{SIG_ERR, ");
563 else if ((long)sa.__sa_handler == (long)SIG_DFL)
564 tprints("{SIG_DFL, ");
565 else if ((long)sa.__sa_handler == (long)SIG_IGN)
566 tprints("{SIG_IGN, ");
568 tprintf("{%#lx, ", (long) sa.__sa_handler);
570 * Sigset size is in tcp->u_arg[4] (SPARC)
571 * or in tcp->u_arg[3] (all other),
572 * but kernel won't handle sys_rt_sigaction
573 * with wrong sigset size (just returns EINVAL instead).
574 * We just fetch the right size, which is NSIG / 8.
576 tprintsigmask_val("", sa.sa_mask);
579 printflags(sigact_flags, sa.sa_flags, "SA_???");
580 #if HAVE_SA_RESTORER && defined SA_RESTORER
581 if (sa.sa_flags & SA_RESTORER)
582 tprintf(", %p", sa.sa_restorer);
587 SYS_FUNC(rt_sigaction)
590 printsignal(tcp->u_arg[0]);
592 decode_new_sigaction(tcp, tcp->u_arg[1]);
595 decode_new_sigaction(tcp, tcp->u_arg[2]);
596 #if defined(SPARC) || defined(SPARC64)
597 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
599 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
601 tprintf(", %lu", tcp->u_arg[3]);
607 SYS_FUNC(rt_sigpending)
611 * One of the few syscalls where sigset size (arg[1])
612 * is allowed to be <= NSIG / 8, not strictly ==.
613 * This allows non-rt sigpending() syscall
614 * to reuse rt_sigpending() code in kernel.
616 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
617 tprintf(", %lu", tcp->u_arg[1]);
622 SYS_FUNC(rt_sigsuspend)
624 /* NB: kernel requires arg[1] == NSIG / 8 */
625 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
626 tprintf(", %lu", tcp->u_arg[1]);
632 print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
636 printsiginfo_at(tcp, uinfo);
639 SYS_FUNC(rt_sigqueueinfo)
641 tprintf("%lu, ", tcp->u_arg[0]);
642 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
647 SYS_FUNC(rt_tgsigqueueinfo)
649 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
650 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
655 SYS_FUNC(rt_sigtimedwait)
657 /* NB: kernel requires arg[3] == NSIG / 8 */
659 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
661 /* This is the only "return" parameter, */
662 if (tcp->u_arg[1] != 0)
664 /* ... if it's NULL, can decode all on entry */
667 else if (tcp->u_arg[1] != 0) {
668 /* syscall exit, and u_arg[1] wasn't NULL */
669 printsiginfo_at(tcp, tcp->u_arg[1]);
673 /* syscall exit, and u_arg[1] was NULL */
676 print_timespec(tcp, tcp->u_arg[2]);
677 tprintf(", %lu", tcp->u_arg[3]);
681 SYS_FUNC(restart_syscall)
683 tprintf("<... resuming interrupted %s ...>",
684 tcp->s_prev_ent ? tcp->s_prev_ent->sys_name : "system call");