(root)/
strace-6.5/
src/
signal.c
       1  /*
       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>
       9   * Copyright (c) 1999-2023 The strace developers.
      10   * All rights reserved.
      11   *
      12   * SPDX-License-Identifier: LGPL-2.1-or-later
      13   */
      14  
      15  #include "defs.h"
      16  #include "nsig.h"
      17  #include "xstring.h"
      18  
      19  /* The libc headers do not define this constant since it should only be
      20     used by the implementation.  So we define it here.  */
      21  #ifndef SA_RESTORER
      22  # ifdef ASM_SA_RESTORER
      23  #  define SA_RESTORER ASM_SA_RESTORER
      24  # endif
      25  #endif
      26  
      27  /*
      28   * Some architectures define SA_RESTORER in their headers,
      29   * but do not actually have sa_restorer.
      30   *
      31   * Some architectures, otherwise, do not define SA_RESTORER in their headers,
      32   * but actually have sa_restorer.
      33   */
      34  #ifdef HAVE_ARCH_SA_RESTORER
      35  # define HAVE_SA_RESTORER HAVE_ARCH_SA_RESTORER
      36  #else /* !HAVE_ARCH_SA_RESTORER */
      37  # ifdef SA_RESTORER
      38  #  define HAVE_SA_RESTORER 1
      39  # else
      40  #  define HAVE_SA_RESTORER 0
      41  # endif
      42  #endif /* HAVE_ARCH_SA_RESTORER */
      43  
      44  #include "xlat/sa_handler_values.h"
      45  #include "xlat/sigact_flags.h"
      46  #include "xlat/sigprocmaskcmds.h"
      47  
      48  /* Anonymous realtime signals. */
      49  #ifndef ASM_SIGRTMIN
      50  /* Linux kernel >= 3.18 defines SIGRTMIN to 32 on all architectures. */
      51  # define ASM_SIGRTMIN 32
      52  #endif
      53  #ifndef ASM_SIGRTMAX
      54  /* Under glibc 2.1, SIGRTMAX et al are functions, but __SIGRTMAX is a
      55     constant.  This is what we want.  Otherwise, just use SIGRTMAX. */
      56  # ifdef SIGRTMAX
      57  #  ifndef __SIGRTMAX
      58  #   define __SIGRTMAX SIGRTMAX
      59  #  endif
      60  # endif
      61  # ifdef __SIGRTMAX
      62  #  define ASM_SIGRTMAX __SIGRTMAX
      63  # endif
      64  #endif
      65  
      66  /* Note on the size of sigset_t:
      67   *
      68   * In glibc, sigset_t is an array with space for 1024 bits (!),
      69   * even though all arches supported by Linux have only 64 signals
      70   * except MIPS, which has 128. IOW, it is 128 bytes long.
      71   *
      72   * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long).
      73   * However, some old syscall return only 32 lower bits (one word).
      74   * Example: sys_sigpending vs sys_rt_sigpending.
      75   *
      76   * Be aware of this fact when you try to
      77   *     memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t))
      78   * - sizeof(sigset_t) is much bigger than you think,
      79   * it may overflow tcp->u_arg[] array, and it may try to copy more data
      80   * than is really available in <something>.
      81   * Similarly,
      82   *     umoven(tcp, addr, sizeof(sigset_t), &sigset)
      83   * may be a bad idea: it'll try to read much more data than needed
      84   * to fetch a sigset_t.
      85   * Use NSIG_BYTES as a size instead.
      86   */
      87  
      88  static const char *
      89  get_sa_handler_str(kernel_ulong_t handler)
      90  {
      91  	return xlookup(sa_handler_values, handler);
      92  }
      93  
      94  static void
      95  print_sa_handler(kernel_ulong_t handler)
      96  {
      97  	const char *sa_handler_str = get_sa_handler_str(handler);
      98  
      99  	if (sa_handler_str)
     100  		print_xlat_ex(handler, sa_handler_str, XLAT_STYLE_DEFAULT);
     101  	else
     102  		printaddr(handler);
     103  }
     104  
     105  const char *
     106  signame(const int sig)
     107  {
     108  	if (sig > 0) {
     109  		const unsigned int s = sig;
     110  
     111  		if (s < nsignals)
     112  			return signalent[s];
     113  #ifdef ASM_SIGRTMAX
     114  		if (s >= ASM_SIGRTMIN && s <= (unsigned int) ASM_SIGRTMAX) {
     115  			static char buf[sizeof("SIGRT_%u") + sizeof(s) * 3];
     116  
     117  			xsprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN);
     118  			return buf;
     119  		}
     120  #endif
     121  	}
     122  
     123  	return NULL;
     124  }
     125  
     126  const char *
     127  sprintsigname(const int sig)
     128  {
     129  	const char *str = signame(sig);
     130  
     131  	if (str)
     132  		return str;
     133  
     134  	static char buf[sizeof(sig) * 3 + 2];
     135  
     136  	xsprintf(buf, "%d", sig);
     137  
     138  	return buf;
     139  }
     140  
     141  const char *
     142  sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
     143  {
     144  	/*
     145  	 * The maximum number of signal names to be printed
     146  	 * is NSIG_BYTES * 8 * 2 / 3.
     147  	 * Most of signal names have length 7,
     148  	 * average length of signal names is less than 7.
     149  	 * The length of prefix string does not exceed 16.
     150  	 */
     151  	static char outstr[128 + 8 * (NSIG_BYTES * 8 * 2 / 3)];
     152  
     153  	char *s;
     154  	const uint32_t *mask;
     155  	uint32_t inverted_mask[NSIG_BYTES / 4];
     156  	unsigned int size;
     157  	char sep;
     158  
     159  	s = stpcpy(outstr, prefix);
     160  
     161  	mask = sig_mask;
     162  	/* length of signal mask in 4-byte words */
     163  	size = ROUNDUP_DIV(MIN(bytes, NSIG_BYTES), 4);
     164  
     165  	/* check whether 2/3 or more bits are set */
     166  	if (popcount32(mask, size) >= size * (4 * 8) * 2 / 3) {
     167  		/* show those signals that are NOT in the mask */
     168  		for (unsigned int j = 0; j < size; ++j)
     169  			inverted_mask[j] = ~mask[j];
     170  		mask = inverted_mask;
     171  		*s++ = '~';
     172  	}
     173  
     174  	sep = '[';
     175  	for (int i = 0; (i = next_set_bit(mask, i, size * (4 * 8))) >= 0; ) {
     176  		++i;
     177  		*s++ = sep;
     178  		if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
     179  			s = xappendstr(outstr, s, "%u", i);
     180  		if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
     181  			s = xappendstr(outstr, s, " /* ");
     182  		if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_RAW) {
     183  			if ((unsigned) i < nsignals) {
     184  				s = stpcpy(s, signalent[i] + 3);
     185  			}
     186  #ifdef ASM_SIGRTMAX
     187  			else if (i >= ASM_SIGRTMIN && i <= ASM_SIGRTMAX) {
     188  				s = xappendstr(outstr, s, "RT_%u",
     189  					       i - ASM_SIGRTMIN);
     190  			}
     191  #endif
     192  			else if (xlat_verbose(xlat_verbosity)
     193  				 != XLAT_STYLE_ABBREV) {
     194  				s = xappendstr(outstr, s, "%u", i);
     195  			}
     196  		}
     197  		if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
     198  			s = xappendstr(outstr, s, " */");
     199  		sep = ' ';
     200  	}
     201  	if (sep == '[')
     202  		*s++ = sep;
     203  	*s++ = ']';
     204  	*s = '\0';
     205  	return outstr;
     206  }
     207  
     208  #define sprintsigmask_val(prefix, mask) \
     209  	sprintsigmask_n((prefix), &(mask), sizeof(mask))
     210  
     211  #define tprintsigmask_val(mask) \
     212  	tprints_string(sprintsigmask_n("", &(mask), sizeof(mask)))
     213  
     214  static const char *
     215  sprint_old_sigmask_val(const char *const prefix, const unsigned long mask)
     216  {
     217  #if defined(current_wordsize) || !defined(WORDS_BIGENDIAN)
     218  	return sprintsigmask_n(prefix, &mask, current_wordsize);
     219  #else /* !current_wordsize && WORDS_BIGENDIAN */
     220  	if (current_wordsize == sizeof(mask)) {
     221  		return sprintsigmask_val(prefix, mask);
     222  	} else {
     223  		uint32_t mask32 = mask;
     224  		return sprintsigmask_val(prefix, mask32);
     225  	}
     226  #endif
     227  }
     228  
     229  static void
     230  tprint_old_sigmask_val(const unsigned long mask)
     231  {
     232  	tprints_string(sprint_old_sigmask_val("", mask));
     233  }
     234  
     235  void
     236  printsignal(int nr)
     237  {
     238  	const char *str = signame(nr);
     239  
     240  	if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
     241  		PRINT_VAL_D(nr);
     242  	if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
     243  		return;
     244  	(xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
     245  		? tprints_comment : tprints_string)(str);
     246  }
     247  
     248  static void
     249  print_sigset_addr_len_limit(struct tcb *const tcp, const kernel_ulong_t addr,
     250  			    const kernel_ulong_t len, const unsigned int min_len)
     251  {
     252  	/*
     253  	 * Here len is usually equal to NSIG_BYTES or current_wordsize.
     254  	 * But we code this defensively:
     255  	 */
     256  	if (len < min_len || len > NSIG_BYTES) {
     257  		printaddr(addr);
     258  		return;
     259  	}
     260  	int mask[NSIG_BYTES / sizeof(int)] = {};
     261  	if (umoven_or_printaddr(tcp, addr, len, mask))
     262  		return;
     263  	tprints_string(sprintsigmask_n("", mask, len));
     264  }
     265  
     266  void
     267  print_sigset_addr_len(struct tcb *const tcp, const kernel_ulong_t addr,
     268  		      const kernel_ulong_t len)
     269  {
     270  	print_sigset_addr_len_limit(tcp, addr, len, current_wordsize);
     271  }
     272  
     273  void
     274  print_sigset_addr(struct tcb *const tcp, const kernel_ulong_t addr)
     275  {
     276  	tprint_struct_begin();
     277  	tprints_field_name("mask");
     278  	print_sigset_addr_len_limit(tcp, addr, NSIG_BYTES, NSIG_BYTES);
     279  	tprint_struct_end();
     280  }
     281  
     282  SYS_FUNC(ssetmask)
     283  {
     284  	if (entering(tcp)) {
     285  		tprint_old_sigmask_val((unsigned) tcp->u_arg[0]);
     286  	} else if (!syserror(tcp)) {
     287  		tcp->auxstr = sprint_old_sigmask_val("old mask ",
     288  						     (unsigned) tcp->u_rval);
     289  		return RVAL_HEX | RVAL_STR;
     290  	}
     291  	return 0;
     292  }
     293  
     294  struct old_sigaction {
     295  	/* sa_handler may be a libc #define, need to use other name: */
     296  #if defined MIPS
     297  	unsigned int sa_flags;
     298  	unsigned long sa_handler__;
     299  	unsigned long sa_mask;
     300  #elif defined ALPHA
     301  	unsigned long sa_handler__;
     302  	unsigned long sa_mask;
     303  	unsigned int sa_flags;
     304  #else
     305  	unsigned long sa_handler__;
     306  	unsigned long sa_mask;
     307  	unsigned long sa_flags;
     308  	unsigned long sa_restorer;
     309  #endif
     310  }
     311  #ifdef ALPHA
     312  	ATTRIBUTE_PACKED
     313  #endif
     314  ;
     315  
     316  static void
     317  decode_old_sigaction(struct tcb *const tcp, const kernel_ulong_t addr)
     318  {
     319  	struct old_sigaction sa;
     320  
     321  #ifndef current_wordsize
     322  	if (current_wordsize < sizeof(sa.sa_handler__)) {
     323  		struct old_sigaction32 {
     324  			uint32_t sa_handler__;
     325  			uint32_t sa_mask;
     326  			uint32_t sa_flags;
     327  			uint32_t sa_restorer;
     328  		} sa32;
     329  
     330  		if (umove_or_printaddr(tcp, addr, &sa32))
     331  			return;
     332  
     333  		memset(&sa, 0, sizeof(sa));
     334  		sa.sa_handler__ = sa32.sa_handler__;
     335  		sa.sa_flags = sa32.sa_flags;
     336  		sa.sa_restorer = sa32.sa_restorer;
     337  		sa.sa_mask = sa32.sa_mask;
     338  	} else
     339  #endif
     340  	if (umove_or_printaddr(tcp, addr, &sa))
     341  		return;
     342  
     343  	tprint_struct_begin();
     344  	tprints_field_name("sa_handler");
     345  	print_sa_handler(sa.sa_handler__);
     346  	tprint_struct_next();
     347  	PRINT_FIELD_OBJ_VAL(sa, sa_mask, tprint_old_sigmask_val);
     348  	tprint_struct_next();
     349  	PRINT_FIELD_FLAGS(sa, sa_flags, sigact_flags, "SA_???");
     350  #if !(defined ALPHA || defined MIPS)
     351  	if (sa.sa_flags & 0x04000000U) {
     352  		tprint_struct_next();
     353  		PRINT_FIELD_OBJ_VAL(sa, sa_restorer, printaddr);
     354  	}
     355  #endif
     356  	tprint_struct_end();
     357  }
     358  
     359  SYS_FUNC(sigaction)
     360  {
     361  	if (entering(tcp)) {
     362  		int signo = tcp->u_arg[0];
     363  #if defined SPARC || defined SPARC64
     364  		if (signo < 0) {
     365  			tprints_string("-");
     366  			signo = -signo;
     367  		}
     368  #endif
     369  		/* signum */
     370  		printsignal(signo);
     371  		tprint_arg_next();
     372  
     373  		/* act */
     374  		decode_old_sigaction(tcp, tcp->u_arg[1]);
     375  		tprint_arg_next();
     376  	} else {
     377  		/* oldact */
     378  		decode_old_sigaction(tcp, tcp->u_arg[2]);
     379  	}
     380  	return 0;
     381  }
     382  
     383  SYS_FUNC(signal)
     384  {
     385  	if (entering(tcp)) {
     386  		/* signum */
     387  		printsignal(tcp->u_arg[0]);
     388  		tprint_arg_next();
     389  
     390  		/* handler */
     391  		print_sa_handler(tcp->u_arg[1]);
     392  		return 0;
     393  	} else if (!syserror(tcp)) {
     394  		tcp->auxstr = get_sa_handler_str(tcp->u_rval);
     395  		return RVAL_HEX | RVAL_STR;
     396  	}
     397  	return 0;
     398  }
     399  
     400  SYS_FUNC(sgetmask)
     401  {
     402  	if (exiting(tcp) && !syserror(tcp)) {
     403  		tcp->auxstr = sprint_old_sigmask_val("mask ", tcp->u_rval);
     404  		return RVAL_HEX | RVAL_STR;
     405  	}
     406  	return 0;
     407  }
     408  
     409  SYS_FUNC(sigsuspend)
     410  {
     411  	/* mask */
     412  #ifdef MIPS
     413  	print_sigset_addr_len(tcp, tcp->u_arg[n_args(tcp) - 1],
     414  			      current_wordsize);
     415  #else
     416  	tprint_old_sigmask_val(tcp->u_arg[n_args(tcp) - 1]);
     417  #endif
     418  
     419  	return RVAL_DECODED;
     420  }
     421  
     422  #ifdef ALPHA
     423  /*
     424   * The OSF/1 sigprocmask is different: it doesn't pass in two pointers,
     425   * but rather passes in the new bitmask as an argument and then returns
     426   * the old bitmask.  This "works" because we only have 64 signals to worry
     427   * about.  If you want more, use of the rt_sigprocmask syscall is required.
     428   *
     429   * Alpha:
     430   *	old = osf_sigprocmask(how, new);
     431   * Everyone else:
     432   *	ret = sigprocmask(how, &new, &old, ...);
     433   */
     434  SYS_FUNC(osf_sigprocmask)
     435  {
     436  	if (entering(tcp)) {
     437  		/* how */
     438  		printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
     439  		tprint_arg_next();
     440  
     441  		/* set */
     442  		tprintsigmask_val(tcp->u_arg[1]);
     443  	} else if (!syserror(tcp)) {
     444  		tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
     445  		return RVAL_HEX | RVAL_STR;
     446  	}
     447  	return 0;
     448  }
     449  
     450  #else /* !ALPHA */
     451  
     452  /* "Old" sigprocmask, which operates with word-sized signal masks */
     453  SYS_FUNC(sigprocmask)
     454  {
     455  	if (entering(tcp)) {
     456  		/* how */
     457  		printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
     458  		tprint_arg_next();
     459  
     460  		/* set */
     461  		print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
     462  		tprint_arg_next();
     463  	} else {
     464  		/* oldset */
     465  		print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
     466  	}
     467  	return 0;
     468  }
     469  #endif /* !ALPHA */
     470  
     471  SYS_FUNC(kill)
     472  {
     473  	/* pid */
     474  	printpid_tgid_pgid(tcp, tcp->u_arg[0]);
     475  	tprint_arg_next();
     476  
     477  	/* signum */
     478  	printsignal(tcp->u_arg[1]);
     479  
     480  	return RVAL_DECODED;
     481  }
     482  
     483  SYS_FUNC(tkill)
     484  {
     485  	/* tid */
     486  	printpid(tcp, tcp->u_arg[0], PT_TID);
     487  	tprint_arg_next();
     488  
     489  	/* signum */
     490  	printsignal(tcp->u_arg[1]);
     491  
     492  	return RVAL_DECODED;
     493  }
     494  
     495  SYS_FUNC(tgkill)
     496  {
     497  	/* tgid */
     498  	printpid(tcp, tcp->u_arg[0], PT_TGID);
     499  	tprint_arg_next();
     500  
     501  	/* tid */
     502  	printpid(tcp, tcp->u_arg[1], PT_TID);
     503  	tprint_arg_next();
     504  
     505  	/* signum */
     506  	printsignal(tcp->u_arg[2]);
     507  
     508  	return RVAL_DECODED;
     509  }
     510  
     511  SYS_FUNC(sigpending)
     512  {
     513  	if (exiting(tcp)) {
     514  		/* set */
     515  		print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
     516  	}
     517  	return 0;
     518  }
     519  
     520  SYS_FUNC(rt_sigprocmask)
     521  {
     522  	/* Note: arg[3] is the length of the sigset. Kernel requires NSIG_BYTES */
     523  	if (entering(tcp)) {
     524  		/* how */
     525  		printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
     526  		tprint_arg_next();
     527  
     528  		/* set */
     529  		print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
     530  		tprint_arg_next();
     531  	} else {
     532  		/* oldset */
     533  		print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
     534  		tprint_arg_next();
     535  
     536  		/* sigsetsize */
     537  		PRINT_VAL_U(tcp->u_arg[3]);
     538  	}
     539  	return 0;
     540  }
     541  
     542  /* Structure describing the action to be taken when a signal arrives.  */
     543  struct new_sigaction {
     544  	/* sa_handler may be a libc #define, need to use other name: */
     545  #ifdef MIPS
     546  	unsigned int sa_flags;
     547  	unsigned long sa_handler__;
     548  #else
     549  	unsigned long sa_handler__;
     550  	unsigned long sa_flags;
     551  #endif /* !MIPS */
     552  #if HAVE_SA_RESTORER
     553  	unsigned long sa_restorer;
     554  #endif
     555  	/* Kernel treats sa_mask as an array of longs. */
     556  	unsigned long sa_mask[NSIG / sizeof(long)];
     557  };
     558  /* Same for i386-on-x86_64 and similar cases */
     559  struct new_sigaction32 {
     560  	uint32_t sa_handler__;
     561  	uint32_t sa_flags;
     562  #if HAVE_SA_RESTORER
     563  	uint32_t sa_restorer;
     564  #endif
     565  	uint32_t sa_mask[2 * (NSIG / sizeof(long))];
     566  };
     567  
     568  static void
     569  decode_new_sigaction(struct tcb *const tcp, const kernel_ulong_t addr)
     570  {
     571  	struct new_sigaction sa;
     572  
     573  #ifndef current_wordsize
     574  	if (current_wordsize < sizeof(sa.sa_handler__)) {
     575  		struct new_sigaction32 sa32;
     576  
     577  		if (umove_or_printaddr(tcp, addr, &sa32))
     578  			return;
     579  
     580  		memset(&sa, 0, sizeof(sa));
     581  		sa.sa_handler__ = sa32.sa_handler__;
     582  		sa.sa_flags     = sa32.sa_flags;
     583  # if HAVE_SA_RESTORER && defined SA_RESTORER
     584  		sa.sa_restorer  = sa32.sa_restorer;
     585  # endif
     586  		/* Kernel treats sa_mask as an array of longs.
     587  		 * For 32-bit process, "long" is uint32_t, thus, for example,
     588  		 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
     589  		 * But for (64-bit) kernel, 32th bit in sa_mask is
     590  		 * 32th bit in 0th (64-bit) long!
     591  		 * For little-endian, it's the same.
     592  		 * For big-endian, we swap 32-bit words.
     593  		 */
     594  		sa.sa_mask[0] = ULONG_LONG(sa32.sa_mask[0], sa32.sa_mask[1]);
     595  	} else
     596  #endif
     597  	if (umove_or_printaddr(tcp, addr, &sa))
     598  		return;
     599  
     600  	tprint_struct_begin();
     601  	tprints_field_name("sa_handler");
     602  	print_sa_handler(sa.sa_handler__);
     603  	/*
     604  	 * Sigset size is in tcp->u_arg[4] (SPARC)
     605  	 * or in tcp->u_arg[3] (all other),
     606  	 * but kernel won't handle sys_rt_sigaction
     607  	 * with wrong sigset size (just returns EINVAL instead).
     608  	 * We just fetch the right size, which is NSIG_BYTES.
     609  	 */
     610  	tprint_struct_next();
     611  	tprints_field_name("sa_mask");
     612  	tprintsigmask_val(sa.sa_mask);
     613  	tprint_struct_next();
     614  	PRINT_FIELD_FLAGS(sa, sa_flags, sigact_flags, "SA_???");
     615  #if HAVE_SA_RESTORER && defined SA_RESTORER
     616  	if (sa.sa_flags & SA_RESTORER) {
     617  		tprint_struct_next();
     618  		PRINT_FIELD_OBJ_VAL(sa, sa_restorer, printaddr);
     619  	}
     620  #endif
     621  	tprint_struct_end();
     622  }
     623  
     624  SYS_FUNC(rt_sigaction)
     625  {
     626  	if (entering(tcp)) {
     627  		/* signum */
     628  		printsignal(tcp->u_arg[0]);
     629  		tprint_arg_next();
     630  
     631  		/* act */
     632  		decode_new_sigaction(tcp, tcp->u_arg[1]);
     633  		tprint_arg_next();
     634  	} else {
     635  		/* oldact */
     636  		decode_new_sigaction(tcp, tcp->u_arg[2]);
     637  		tprint_arg_next();
     638  
     639  #if defined(SPARC) || defined(SPARC64)
     640  		/* sa_restorer */
     641  		PRINT_VAL_X(tcp->u_arg[3]);
     642  		tprint_arg_next();
     643  
     644  		/* sigsetsize */
     645  		PRINT_VAL_U(tcp->u_arg[4]);
     646  #elif defined(ALPHA)
     647  		/* sigsetsize */
     648  		PRINT_VAL_U(tcp->u_arg[3]);
     649  		tprint_arg_next();
     650  
     651  		/* sa_restorer */
     652  		PRINT_VAL_X(tcp->u_arg[4]);
     653  #else
     654  		/* sigsetsize */
     655  		PRINT_VAL_U(tcp->u_arg[3]);
     656  #endif
     657  	}
     658  	return 0;
     659  }
     660  
     661  SYS_FUNC(rt_sigpending)
     662  {
     663  	if (exiting(tcp)) {
     664  		/*
     665  		 * One of the few syscalls where sigset size (arg[1])
     666  		 * is allowed to be <= NSIG_BYTES, not strictly ==.
     667  		 * This allows non-rt sigpending() syscall
     668  		 * to reuse rt_sigpending() code in kernel.
     669  		 */
     670  		print_sigset_addr_len_limit(tcp, tcp->u_arg[0],
     671  					    tcp->u_arg[1], 1);
     672  		tprint_arg_next();
     673  
     674  		/* sigsetsize */
     675  		PRINT_VAL_U(tcp->u_arg[1]);
     676  	}
     677  	return 0;
     678  }
     679  
     680  SYS_FUNC(rt_sigsuspend)
     681  {
     682  	/* NB: kernel requires arg[1] == NSIG_BYTES */
     683  	print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
     684  	tprint_arg_next();
     685  
     686  	/* sigsetsize */
     687  	PRINT_VAL_U(tcp->u_arg[1]);
     688  
     689  	return RVAL_DECODED;
     690  }
     691  
     692  static void
     693  print_sigqueueinfo(struct tcb *const tcp, const int sig,
     694  		   const kernel_ulong_t addr)
     695  {
     696  	/* signum */
     697  	printsignal(sig);
     698  	tprint_arg_next();
     699  
     700  	/* info */
     701  	printsiginfo_at(tcp, addr);
     702  }
     703  
     704  SYS_FUNC(rt_sigqueueinfo)
     705  {
     706  	/* tgid */
     707  	printpid(tcp, tcp->u_arg[0], PT_TGID);
     708  	tprint_arg_next();
     709  
     710  	/* int sig, siginfo_t *info */
     711  	print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
     712  
     713  	return RVAL_DECODED;
     714  }
     715  
     716  SYS_FUNC(rt_tgsigqueueinfo)
     717  {
     718  	/* tgid */
     719  	printpid(tcp, tcp->u_arg[0], PT_TGID);
     720  	tprint_arg_next();
     721  
     722  	/* tid */
     723  	printpid(tcp, tcp->u_arg[1], PT_TID);
     724  	tprint_arg_next();
     725  
     726  	/* int sig, siginfo_t *info */
     727  	print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
     728  
     729  	return RVAL_DECODED;
     730  }
     731  
     732  SYS_FUNC(pidfd_send_signal)
     733  {
     734  	/* int pidfd */
     735  	printfd(tcp, tcp->u_arg[0]);
     736  	tprint_arg_next();
     737  
     738  	/* int sig, siginfo_t *info */
     739  	print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
     740  	tprint_arg_next();
     741  
     742  	/* unsigned int flags */
     743  	PRINT_VAL_X((unsigned int) tcp->u_arg[3]);
     744  
     745  	return RVAL_DECODED;
     746  }
     747  
     748  static int
     749  do_rt_sigtimedwait(struct tcb *const tcp, const print_obj_by_addr_fn print_ts,
     750  		   const sprint_obj_by_addr_fn sprint_ts)
     751  {
     752  	/* NB: kernel requires arg[3] == NSIG_BYTES */
     753  	if (entering(tcp)) {
     754  		/* set */
     755  		print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
     756  		tprint_arg_next();
     757  
     758  		if (!(tcp->u_arg[1] && verbose(tcp))) {
     759  			/*
     760  			 * This is the only "return" parameter,
     761  			 * if we are not going to fetch it on exit,
     762  			 * decode all parameters on entry.
     763  			 */
     764  			printaddr(tcp->u_arg[1]);
     765  			tprint_arg_next();
     766  
     767  			/* timeout */
     768  			print_ts(tcp, tcp->u_arg[2]);
     769  			tprint_arg_next();
     770  
     771  			/* sigsetsize */
     772  			PRINT_VAL_U(tcp->u_arg[3]);
     773  		} else {
     774  			char *sts = xstrdup(sprint_ts(tcp, tcp->u_arg[2]));
     775  			set_tcb_priv_data(tcp, sts, free);
     776  		}
     777  	} else {
     778  		if (tcp->u_arg[1] && verbose(tcp)) {
     779  			/* info */
     780  			printsiginfo_at(tcp, tcp->u_arg[1]);
     781  			tprint_arg_next();
     782  
     783  			/* timeout */
     784  			tprints_string(get_tcb_priv_data(tcp));
     785  			tprint_arg_next();
     786  
     787  			/* sigsetsize */
     788  			PRINT_VAL_U(tcp->u_arg[3]);
     789  		}
     790  
     791  		if (!syserror(tcp) && tcp->u_rval) {
     792  			tcp->auxstr = signame(tcp->u_rval);
     793  			return RVAL_STR;
     794  		}
     795  	}
     796  	return 0;
     797  }
     798  
     799  #if HAVE_ARCH_TIME32_SYSCALLS
     800  SYS_FUNC(rt_sigtimedwait_time32)
     801  {
     802  	return do_rt_sigtimedwait(tcp, print_timespec32, sprint_timespec32);
     803  }
     804  #endif
     805  
     806  SYS_FUNC(rt_sigtimedwait_time64)
     807  {
     808  	return do_rt_sigtimedwait(tcp, print_timespec64, sprint_timespec64);
     809  }
     810  
     811  SYS_FUNC(restart_syscall)
     812  {
     813  	tprintf_string("<... resuming interrupted %s ...>",
     814  		tcp->s_prev_ent ? tcp->s_prev_ent->sys_name : "system call");
     815  
     816  	return RVAL_DECODED;
     817  }