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 /* The libc headers do not define this constant since it should only be
38 used by the implementation. So we define it here. */
40 # ifdef ASM_SA_RESTORER
41 # define SA_RESTORER ASM_SA_RESTORER
46 * Some architectures define SA_RESTORER in their headers,
47 * but do not actually have sa_restorer.
49 * Some architectures, otherwise, do not define SA_RESTORER in their headers,
50 * but actually have sa_restorer.
53 # if defined HPPA || defined IA64
54 # define HAVE_SA_RESTORER 0
56 # define HAVE_SA_RESTORER 1
58 #else /* !SA_RESTORER */
59 # if defined SPARC || defined SPARC64 || defined M68K
60 # define HAVE_SA_RESTORER 1
62 # define HAVE_SA_RESTORER 0
66 #include "xlat/sa_handler_values.h"
67 #include "xlat/sigact_flags.h"
68 #include "xlat/sigprocmaskcmds.h"
70 /* Anonymous realtime signals. */
72 /* Linux kernel >= 3.18 defines SIGRTMIN to 32 on all architectures. */
73 # define ASM_SIGRTMIN 32
76 /* Under glibc 2.1, SIGRTMAX et al are functions, but __SIGRTMAX is a
77 constant. This is what we want. Otherwise, just use SIGRTMAX. */
80 # define __SIGRTMAX SIGRTMAX
84 # define ASM_SIGRTMAX __SIGRTMAX
88 /* Note on the size of sigset_t:
90 * In glibc, sigset_t is an array with space for 1024 bits (!),
91 * even though all arches supported by Linux have only 64 signals
92 * except MIPS, which has 128. IOW, it is 128 bytes long.
94 * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
95 * However, some old syscall return only 32 lower bits (one word).
96 * Example: sys_sigpending vs sys_rt_sigpending.
98 * Be aware of this fact when you try to
99 * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
100 * - sizeof(sigset_t) is much bigger than you think,
101 * it may overflow tcp->u_arg[] array, and it may try to copy more data
102 * than is really available in <something>.
104 * umoven(tcp, addr, sizeof(sigset_t), &sigset)
105 * may be a bad idea: it'll try to read much more data than needed
106 * to fetch a sigset_t.
107 * Use NSIG_BYTES as a size instead.
111 get_sa_handler_str(kernel_ulong_t handler)
113 return xlookup(sa_handler_values, handler);
117 print_sa_handler(kernel_ulong_t handler)
119 const char *sa_handler_str = get_sa_handler_str(handler);
122 tprints(sa_handler_str);
128 signame(const int sig)
130 static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
133 const unsigned int s = sig;
138 if (s >= ASM_SIGRTMIN && s <= (unsigned int) ASM_SIGRTMAX) {
139 sprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN);
144 sprintf(buf, "%d", sig);
149 popcount32(const uint32_t *a, unsigned int size)
151 unsigned int count = 0;
153 for (; size; ++a, --size) {
156 #ifdef HAVE___BUILTIN_POPCOUNT
157 count += __builtin_popcount(x);
168 sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
171 * The maximum number of signal names to be printed
172 * is NSIG_BYTES * 8 * 2 / 3.
173 * Most of signal names have length 7,
174 * average length of signal names is less than 7.
175 * The length of prefix string does not exceed 16.
177 static char outstr[128 + 8 * (NSIG_BYTES * 8 * 2 / 3)];
180 const uint32_t *mask;
181 uint32_t inverted_mask[NSIG_BYTES / 4];
186 s = stpcpy(outstr, prefix);
189 /* length of signal mask in 4-byte words */
190 size = (bytes >= NSIG_BYTES) ? NSIG_BYTES / 4 : (bytes + 3) / 4;
192 /* check whether 2/3 or more bits are set */
193 if (popcount32(mask, size) >= size * (4 * 8) * 2 / 3) {
194 /* show those signals that are NOT in the mask */
196 for (j = 0; j < size; ++j)
197 inverted_mask[j] = ~mask[j];
198 mask = inverted_mask;
203 for (i = 0; (i = next_set_bit(mask, i, size * (4 * 8))) >= 0; ) {
206 if ((unsigned) i < nsignals) {
207 s = stpcpy(s, signalent[i] + 3);
210 else if (i >= ASM_SIGRTMIN && i <= ASM_SIGRTMAX) {
211 s += sprintf(s, "RT_%u", i - ASM_SIGRTMIN);
215 s += sprintf(s, "%u", i);
226 #define sprintsigmask_val(prefix, mask) \
227 sprintsigmask_n((prefix), &(mask), sizeof(mask))
229 #define tprintsigmask_val(prefix, mask) \
230 tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
235 tprints(signame(nr));
239 print_sigset_addr_len_limit(struct tcb *const tcp, const kernel_ulong_t addr,
240 const kernel_ulong_t len, const unsigned int min_len)
243 * Here len is usually equal to NSIG_BYTES or current_wordsize.
244 * But we code this defensively:
246 if (len < min_len || len > NSIG_BYTES) {
250 int mask[NSIG_BYTES / sizeof(int)] = {};
251 if (umoven_or_printaddr(tcp, addr, len, mask))
253 tprints(sprintsigmask_n("", mask, len));
257 print_sigset_addr_len(struct tcb *const tcp, const kernel_ulong_t addr,
258 const kernel_ulong_t len)
260 print_sigset_addr_len_limit(tcp, addr, len, current_wordsize);
266 tprintsigmask_val("", tcp->u_arg[0]);
268 else if (!syserror(tcp)) {
269 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
270 return RVAL_HEX | RVAL_STR;
275 struct old_sigaction {
276 /* sa_handler may be a libc #define, need to use other name: */
278 unsigned int sa_flags;
279 unsigned long sa_handler__;
280 /* Kernel treats sa_mask as an array of longs. */
281 unsigned long sa_mask[NSIG / sizeof(long)];
283 unsigned long sa_handler__;
284 unsigned long sa_mask;
285 unsigned long sa_flags;
288 unsigned long sa_restorer;
292 struct old_sigaction32 {
293 /* sa_handler may be a libc #define, need to use other name: */
294 uint32_t sa_handler__;
298 uint32_t sa_restorer;
303 decode_old_sigaction(struct tcb *const tcp, const kernel_ulong_t addr)
305 struct old_sigaction sa;
307 #ifndef current_wordsize
308 if (current_wordsize < sizeof(sa.sa_handler__)) {
309 struct old_sigaction32 sa32;
311 if (umove_or_printaddr(tcp, addr, &sa32))
314 memset(&sa, 0, sizeof(sa));
315 sa.sa_handler__ = sa32.sa_handler__;
316 sa.sa_flags = sa32.sa_flags;
317 #if HAVE_SA_RESTORER && defined SA_RESTORER
318 sa.sa_restorer = sa32.sa_restorer;
320 sa.sa_mask = sa32.sa_mask;
323 if (umove_or_printaddr(tcp, addr, &sa))
326 tprints("{sa_handler=");
327 print_sa_handler(sa.sa_handler__);
328 tprints(", sa_mask=");
330 tprintsigmask_addr("", sa.sa_mask);
332 tprintsigmask_val("", sa.sa_mask);
334 tprints(", sa_flags=");
335 printflags(sigact_flags, sa.sa_flags, "SA_???");
336 #if HAVE_SA_RESTORER && defined SA_RESTORER
337 if (sa.sa_flags & SA_RESTORER) {
338 tprints(", sa_restorer=");
339 printaddr(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 print_sa_handler(tcp->u_arg[1]);
364 } else if (!syserror(tcp)) {
365 tcp->auxstr = get_sa_handler_str(tcp->u_rval);
366 return RVAL_HEX | RVAL_STR;
374 tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
376 return RVAL_HEX | RVAL_STR;
381 tprintsigmask_val("", tcp->u_arg[2]);
386 /* "Old" sigprocmask, which operates with word-sized signal masks */
387 SYS_FUNC(sigprocmask)
392 * Alpha/OSF is different: it doesn't pass in two pointers,
393 * but rather passes in the new bitmask as an argument and
394 * then returns the old bitmask. This "works" because we
395 * only have 64 signals to worry about. If you want more,
396 * use of the rt_sigprocmask syscall is required.
398 * old = osf_sigprocmask(how, new);
400 * ret = sigprocmask(how, &new, &old, ...);
402 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
403 tprintsigmask_val(", ", tcp->u_arg[1]);
405 else if (!syserror(tcp)) {
406 tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
407 return RVAL_HEX | RVAL_STR;
411 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
413 print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
417 print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
427 signame(tcp->u_arg[1]));
434 tprintf("%d, %d, %s",
437 signame(tcp->u_arg[2]));
445 print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
449 SYS_FUNC(rt_sigprocmask)
451 /* Note: arg[3] is the length of the sigset. Kernel requires NSIG_BYTES */
453 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
455 print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
459 print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
460 tprintf(", %" PRI_klu, tcp->u_arg[3]);
465 /* Structure describing the action to be taken when a signal arrives. */
468 /* sa_handler may be a libc #define, need to use other name: */
470 unsigned int sa_flags;
471 unsigned long sa_handler__;
473 unsigned long sa_handler__;
474 unsigned long sa_flags;
477 unsigned long sa_restorer;
479 /* Kernel treats sa_mask as an array of longs. */
480 unsigned long sa_mask[NSIG / sizeof(long)];
482 /* Same for i386-on-x86_64 and similar cases */
483 struct new_sigaction32
485 uint32_t sa_handler__;
488 uint32_t sa_restorer;
490 uint32_t sa_mask[2 * (NSIG / sizeof(long))];
494 decode_new_sigaction(struct tcb *const tcp, const kernel_ulong_t addr)
496 struct new_sigaction sa;
498 #ifndef current_wordsize
499 if (current_wordsize < sizeof(sa.sa_handler__)) {
500 struct new_sigaction32 sa32;
502 if (umove_or_printaddr(tcp, addr, &sa32))
505 memset(&sa, 0, sizeof(sa));
506 sa.sa_handler__ = sa32.sa_handler__;
507 sa.sa_flags = sa32.sa_flags;
508 #if HAVE_SA_RESTORER && defined SA_RESTORER
509 sa.sa_restorer = sa32.sa_restorer;
511 /* Kernel treats sa_mask as an array of longs.
512 * For 32-bit process, "long" is uint32_t, thus, for example,
513 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
514 * But for (64-bit) kernel, 32th bit in sa_mask is
515 * 32th bit in 0th (64-bit) long!
516 * For little-endian, it's the same.
517 * For big-endian, we swap 32-bit words.
519 sa.sa_mask[0] = ULONG_LONG(sa32.sa_mask[0], sa32.sa_mask[1]);
522 if (umove_or_printaddr(tcp, addr, &sa))
525 tprints("{sa_handler=");
526 print_sa_handler(sa.sa_handler__);
527 tprints(", sa_mask=");
529 * Sigset size is in tcp->u_arg[4] (SPARC)
530 * or in tcp->u_arg[3] (all other),
531 * but kernel won't handle sys_rt_sigaction
532 * with wrong sigset size (just returns EINVAL instead).
533 * We just fetch the right size, which is NSIG_BYTES.
535 tprintsigmask_val("", sa.sa_mask);
536 tprints(", sa_flags=");
538 printflags(sigact_flags, sa.sa_flags, "SA_???");
539 #if HAVE_SA_RESTORER && defined SA_RESTORER
540 if (sa.sa_flags & SA_RESTORER) {
541 tprints(", sa_restorer=");
542 printaddr(sa.sa_restorer);
548 SYS_FUNC(rt_sigaction)
551 printsignal(tcp->u_arg[0]);
553 decode_new_sigaction(tcp, tcp->u_arg[1]);
556 decode_new_sigaction(tcp, tcp->u_arg[2]);
557 #if defined(SPARC) || defined(SPARC64)
558 tprintf(", %#" PRI_klx ", %" PRI_klu, tcp->u_arg[3], tcp->u_arg[4]);
560 tprintf(", %" PRI_klu ", %#" PRI_klx, tcp->u_arg[3], tcp->u_arg[4]);
562 tprintf(", %" PRI_klu, tcp->u_arg[3]);
568 SYS_FUNC(rt_sigpending)
572 * One of the few syscalls where sigset size (arg[1])
573 * is allowed to be <= NSIG_BYTES, not strictly ==.
574 * This allows non-rt sigpending() syscall
575 * to reuse rt_sigpending() code in kernel.
577 print_sigset_addr_len_limit(tcp, tcp->u_arg[0],
579 tprintf(", %" PRI_klu, tcp->u_arg[1]);
584 SYS_FUNC(rt_sigsuspend)
586 /* NB: kernel requires arg[1] == NSIG_BYTES */
587 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
588 tprintf(", %" PRI_klu, tcp->u_arg[1]);
594 print_sigqueueinfo(struct tcb *const tcp, const int sig,
595 const kernel_ulong_t addr)
599 printsiginfo_at(tcp, addr);
602 SYS_FUNC(rt_sigqueueinfo)
604 tprintf("%d, ", (int) tcp->u_arg[0]);
605 print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
610 SYS_FUNC(rt_tgsigqueueinfo)
612 tprintf("%d, %d, ", (int) tcp->u_arg[0], (int) tcp->u_arg[1]);
613 print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
618 SYS_FUNC(rt_sigtimedwait)
620 /* NB: kernel requires arg[3] == NSIG_BYTES */
622 print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
624 if (!(tcp->u_arg[1] && verbose(tcp))) {
626 * This is the only "return" parameter,
627 * if we are not going to fetch it on exit,
628 * decode all parameters on entry.
630 printaddr(tcp->u_arg[1]);
632 print_timespec(tcp, tcp->u_arg[2]);
633 tprintf(", %" PRI_klu, tcp->u_arg[3]);
635 char *sts = xstrdup(sprint_timespec(tcp, tcp->u_arg[2]));
636 set_tcb_priv_data(tcp, sts, free);
639 if (tcp->u_arg[1] && verbose(tcp)) {
640 printsiginfo_at(tcp, tcp->u_arg[1]);
642 tprints(get_tcb_priv_data(tcp));
643 tprintf(", %" PRI_klu, tcp->u_arg[3]);
646 if (!syserror(tcp) && tcp->u_rval) {
647 tcp->auxstr = signame(tcp->u_rval);
654 SYS_FUNC(restart_syscall)
656 tprintf("<... resuming interrupted %s ...>",
657 tcp->s_prev_ent ? tcp->s_prev_ent->sys_name : "system call");