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  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
21  *
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.
32  */
33 
34 #include "defs.h"
35 
36 #ifndef NSIG
37 # warning NSIG is not defined, using 32
38 # define NSIG 32
39 #elif NSIG < 32
40 # error NSIG < 32
41 #endif
42 
43 /* The libc headers do not define this constant since it should only be
44    used by the implementation.  So we define it here.  */
45 #ifndef SA_RESTORER
46 # ifdef ASM_SA_RESTORER
47 #  define SA_RESTORER ASM_SA_RESTORER
48 # endif
49 #endif
50 
51 /*
52  * Some architectures define SA_RESTORER in their headers,
53  * but do not actually have sa_restorer.
54  *
55  * Some architectures, otherwise, do not define SA_RESTORER in their headers,
56  * but actually have sa_restorer.
57  */
58 #ifdef SA_RESTORER
59 # if defined HPPA || defined IA64
60 #  define HAVE_SA_RESTORER 0
61 # else
62 #  define HAVE_SA_RESTORER 1
63 # endif
64 #else /* !SA_RESTORER */
65 # if defined SPARC || defined SPARC64 || defined M68K
66 #  define HAVE_SA_RESTORER 1
67 # else
68 #  define HAVE_SA_RESTORER 0
69 # endif
70 #endif
71 
72 #include "xlat/sigact_flags.h"
73 #include "xlat/sigprocmaskcmds.h"
74 
75 /* Anonymous realtime signals. */
76 #ifndef ASM_SIGRTMIN
77 /* Linux kernel >= 3.18 defines SIGRTMIN to 32 on all architectures. */
78 # define ASM_SIGRTMIN 32
79 #endif
80 #ifndef ASM_SIGRTMAX
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. */
83 # ifdef SIGRTMAX
84 #  ifndef __SIGRTMAX
85 #   define __SIGRTMAX SIGRTMAX
86 #  endif
87 # endif
88 # ifdef __SIGRTMAX
89 #  define ASM_SIGRTMAX __SIGRTMAX
90 # endif
91 #endif
92 
93 /* Note on the size of sigset_t:
94  *
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.
98  *
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.
102  *
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>.
108  * Similarly,
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.
113  */
114 
115 const char *
signame(const int sig)116 signame(const int sig)
117 {
118 	static char buf[sizeof("SIGRT_%u") + sizeof(int)*3];
119 
120 	if (sig >= 0) {
121 		const unsigned int s = sig;
122 
123 		if (s < nsignals)
124 			return signalent[s];
125 #ifdef ASM_SIGRTMAX
126 		if (s >= ASM_SIGRTMIN && s <= ASM_SIGRTMAX) {
127 			sprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN);
128 			return buf;
129 		}
130 #endif
131 	}
132 	sprintf(buf, "%d", sig);
133 	return buf;
134 }
135 
136 static unsigned int
popcount32(const uint32_t * a,unsigned int size)137 popcount32(const uint32_t *a, unsigned int size)
138 {
139 	unsigned int count = 0;
140 
141 	for (; size; ++a, --size) {
142 		uint32_t x = *a;
143 
144 #ifdef HAVE___BUILTIN_POPCOUNT
145 		count += __builtin_popcount(x);
146 #else
147 		for (; x; ++count)
148 			x &= x - 1;
149 #endif
150 	}
151 
152 	return count;
153 }
154 
155 const char *
sprintsigmask_n(const char * prefix,const void * sig_mask,unsigned int bytes)156 sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
157 {
158 	/*
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.
163 	 */
164 	static char outstr[128 + 8 * (NSIG * 2 / 3)];
165 
166 	char *s;
167 	const uint32_t *mask;
168 	uint32_t inverted_mask[NSIG / 32];
169 	unsigned int size;
170 	int i;
171 	char sep;
172 
173 	s = stpcpy(outstr, prefix);
174 
175 	mask = sig_mask;
176 	/* length of signal mask in 4-byte words */
177 	size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4;
178 
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 */
182 		unsigned int j;
183 		for (j = 0; j < size; ++j)
184 			inverted_mask[j] = ~mask[j];
185 		mask = inverted_mask;
186 		*s++ = '~';
187 	}
188 
189 	sep = '[';
190 	for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) {
191 		++i;
192 		*s++ = sep;
193 		if ((unsigned) i < nsignals) {
194 			s = stpcpy(s, signalent[i] + 3);
195 		}
196 #ifdef ASM_SIGRTMAX
197 		else if (i >= ASM_SIGRTMIN && i <= ASM_SIGRTMAX) {
198 			s += sprintf(s, "RT_%u", i - ASM_SIGRTMIN);
199 		}
200 #endif
201 		else {
202 			s += sprintf(s, "%u", i);
203 		}
204 		sep = ' ';
205 	}
206 	if (sep == '[')
207 		*s++ = sep;
208 	*s++ = ']';
209 	*s = '\0';
210 	return outstr;
211 }
212 
213 #define sprintsigmask_val(prefix, mask) \
214 	sprintsigmask_n((prefix), &(mask), sizeof(mask))
215 
216 #define tprintsigmask_val(prefix, mask) \
217 	tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask)))
218 
219 void
printsignal(int nr)220 printsignal(int nr)
221 {
222 	tprints(signame(nr));
223 }
224 
225 void
print_sigset_addr_len(struct tcb * tcp,long addr,long len)226 print_sigset_addr_len(struct tcb *tcp, long addr, long len)
227 {
228 	char mask[NSIG / 8];
229 
230 	if (!addr) {
231 		tprints("NULL");
232 		return;
233 	}
234 	/* Here len is usually equals NSIG / 8 or current_wordsize.
235 	 * But we code this defensively:
236 	 */
237 	if (len < 0) {
238  bad:
239 		tprintf("%#lx", addr);
240 		return;
241 	}
242 	if (len >= NSIG / 8)
243 		len = NSIG / 8;
244 	else
245 		len = (len + 3) & ~3;
246 
247 	if (umoven(tcp, addr, len, mask) < 0)
248 		goto bad;
249 	tprints(sprintsigmask_n("", mask, len));
250 }
251 
SYS_FUNC(sigsetmask)252 SYS_FUNC(sigsetmask)
253 {
254 	if (entering(tcp)) {
255 		tprintsigmask_val("", tcp->u_arg[0]);
256 	}
257 	else if (!syserror(tcp)) {
258 		tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
259 		return RVAL_HEX | RVAL_STR;
260 	}
261 	return 0;
262 }
263 
264 #ifdef HAVE_SIGACTION
265 
266 struct old_sigaction {
267 	/* sa_handler may be a libc #define, need to use other name: */
268 #ifdef MIPS
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];
273 #else
274 	void (*__sa_handler)(int);
275 	unsigned long sa_mask;
276 	unsigned long sa_flags;
277 #endif /* !MIPS */
278 #if HAVE_SA_RESTORER
279 	void (*sa_restorer)(void);
280 #endif
281 };
282 
283 struct old_sigaction32 {
284 	/* sa_handler may be a libc #define, need to use other name: */
285 	uint32_t __sa_handler;
286 	uint32_t sa_mask;
287 	uint32_t sa_flags;
288 #if HAVE_SA_RESTORER
289 	uint32_t sa_restorer;
290 #endif
291 };
292 
293 static void
decode_old_sigaction(struct tcb * tcp,long addr)294 decode_old_sigaction(struct tcb *tcp, long addr)
295 {
296 	struct old_sigaction sa;
297 	int r;
298 
299 	if (!addr) {
300 		tprints("NULL");
301 		return;
302 	}
303 	if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
304 		tprintf("%#lx", addr);
305 		return;
306 	}
307 
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);
312 		if (r >= 0) {
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;
318 #endif
319 			sa.sa_mask = sa32.sa_mask;
320 		}
321 	} else
322 #endif
323 	{
324 		r = umove(tcp, addr, &sa);
325 	}
326 	if (r < 0) {
327 		tprints("{...}");
328 		return;
329 	}
330 
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, ");
345 	else
346 		tprintf("{%#lx, ", (long) sa.__sa_handler);
347 #ifdef MIPS
348 	tprintsigmask_addr("", sa.sa_mask);
349 #else
350 	tprintsigmask_val("", sa.sa_mask);
351 #endif
352 	tprints(", ");
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);
357 #endif
358 	tprints("}");
359 }
360 
SYS_FUNC(sigaction)361 SYS_FUNC(sigaction)
362 {
363 	if (entering(tcp)) {
364 		printsignal(tcp->u_arg[0]);
365 		tprints(", ");
366 		decode_old_sigaction(tcp, tcp->u_arg[1]);
367 		tprints(", ");
368 	} else
369 		decode_old_sigaction(tcp, tcp->u_arg[2]);
370 	return 0;
371 }
372 
SYS_FUNC(signal)373 SYS_FUNC(signal)
374 {
375 	if (entering(tcp)) {
376 		printsignal(tcp->u_arg[0]);
377 		tprints(", ");
378 		switch (tcp->u_arg[1]) {
379 		case (long) SIG_ERR:
380 			tprints("SIG_ERR");
381 			break;
382 		case (long) SIG_DFL:
383 			tprints("SIG_DFL");
384 			break;
385 		case (long) SIG_IGN:
386 			tprints("SIG_IGN");
387 			break;
388 		default:
389 			tprintf("%#lx", tcp->u_arg[1]);
390 		}
391 		return 0;
392 	}
393 	else if (!syserror(tcp)) {
394 		switch (tcp->u_rval) {
395 		case (long) SIG_ERR:
396 			tcp->auxstr = "SIG_ERR"; break;
397 		case (long) SIG_DFL:
398 			tcp->auxstr = "SIG_DFL"; break;
399 		case (long) SIG_IGN:
400 			tcp->auxstr = "SIG_IGN"; break;
401 		default:
402 			tcp->auxstr = NULL;
403 		}
404 		return RVAL_HEX | RVAL_STR;
405 	}
406 	return 0;
407 }
408 
409 #endif /* HAVE_SIGACTION */
410 
SYS_FUNC(siggetmask)411 SYS_FUNC(siggetmask)
412 {
413 	if (exiting(tcp)) {
414 		tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval);
415 	}
416 	return RVAL_HEX | RVAL_STR;
417 }
418 
SYS_FUNC(sigsuspend)419 SYS_FUNC(sigsuspend)
420 {
421 	if (entering(tcp)) {
422 		tprintsigmask_val("", tcp->u_arg[2]);
423 	}
424 	return 0;
425 }
426 
427 #ifdef HAVE_SIGACTION
428 
429 /* "Old" sigprocmask, which operates with word-sized signal masks */
SYS_FUNC(sigprocmask)430 SYS_FUNC(sigprocmask)
431 {
432 # ifdef ALPHA
433 	if (entering(tcp)) {
434 		/*
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.
440 		 * Alpha:
441 		 *	old = osf_sigprocmask(how, new);
442 		 * Everyone else:
443 		 *	ret = sigprocmask(how, &new, &old, ...);
444 		 */
445 		printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
446 		tprintsigmask_val(", ", tcp->u_arg[1]);
447 	}
448 	else if (!syserror(tcp)) {
449 		tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval);
450 		return RVAL_HEX | RVAL_STR;
451 	}
452 # else /* !ALPHA */
453 	if (entering(tcp)) {
454 		printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
455 		tprints(", ");
456 		print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize);
457 		tprints(", ");
458 	}
459 	else {
460 		if (syserror(tcp))
461 			tprintf("%#lx", tcp->u_arg[2]);
462 		else
463 			print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize);
464 	}
465 # endif /* !ALPHA */
466 	return 0;
467 }
468 
469 #endif /* HAVE_SIGACTION */
470 
SYS_FUNC(kill)471 SYS_FUNC(kill)
472 {
473 	if (entering(tcp)) {
474 		tprintf("%ld, %s",
475 			widen_to_long(tcp->u_arg[0]),
476 			signame(tcp->u_arg[1])
477 		);
478 	}
479 	return 0;
480 }
481 
SYS_FUNC(tgkill)482 SYS_FUNC(tgkill)
483 {
484 	if (entering(tcp)) {
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])
489 		);
490 	}
491 	return 0;
492 }
493 
SYS_FUNC(sigpending)494 SYS_FUNC(sigpending)
495 {
496 	if (exiting(tcp)) {
497 		if (syserror(tcp))
498 			tprintf("%#lx", tcp->u_arg[0]);
499 		else
500 			print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize);
501 	}
502 	return 0;
503 }
504 
SYS_FUNC(rt_sigprocmask)505 SYS_FUNC(rt_sigprocmask)
506 {
507 	/* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */
508 	if (entering(tcp)) {
509 		printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
510 		tprints(", ");
511 		print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]);
512 		tprints(", ");
513 	}
514 	else {
515 		if (syserror(tcp))
516 			tprintf("%#lx", tcp->u_arg[2]);
517 		else
518 			print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]);
519 		tprintf(", %lu", tcp->u_arg[3]);
520 	}
521 	return 0;
522 }
523 
524 /* Structure describing the action to be taken when a signal arrives.  */
525 struct new_sigaction
526 {
527 	/* sa_handler may be a libc #define, need to use other name: */
528 #ifdef MIPS
529 	unsigned int sa_flags;
530 	void (*__sa_handler)(int);
531 #else
532 	void (*__sa_handler)(int);
533 	unsigned long sa_flags;
534 #endif /* !MIPS */
535 #if HAVE_SA_RESTORER
536 	void (*sa_restorer)(void);
537 #endif
538 	/* Kernel treats sa_mask as an array of longs. */
539 	unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
540 };
541 /* Same for i386-on-x86_64 and similar cases */
542 struct new_sigaction32
543 {
544 	uint32_t __sa_handler;
545 	uint32_t sa_flags;
546 #if HAVE_SA_RESTORER
547 	uint32_t sa_restorer;
548 #endif
549 	uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
550 };
551 
552 static void
decode_new_sigaction(struct tcb * tcp,long addr)553 decode_new_sigaction(struct tcb *tcp, long addr)
554 {
555 	struct new_sigaction sa;
556 	int r;
557 
558 	if (!addr) {
559 		tprints("NULL");
560 		return;
561 	}
562 	if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) {
563 		tprintf("%#lx", addr);
564 		return;
565 	}
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);
570 		if (r >= 0) {
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;
576 #endif
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.
584 			 */
585 			sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
586 		}
587 	} else
588 #endif
589 	{
590 		r = umove(tcp, addr, &sa);
591 	}
592 	if (r < 0) {
593 		tprints("{...}");
594 		return;
595 	}
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, ");
610 	else
611 		tprintf("{%#lx, ", (long) sa.__sa_handler);
612 	/*
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.
618 	 */
619 	tprintsigmask_val("", sa.sa_mask);
620 	tprints(", ");
621 
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);
626 #endif
627 	tprints("}");
628 }
629 
SYS_FUNC(rt_sigaction)630 SYS_FUNC(rt_sigaction)
631 {
632 	if (entering(tcp)) {
633 		printsignal(tcp->u_arg[0]);
634 		tprints(", ");
635 		decode_new_sigaction(tcp, tcp->u_arg[1]);
636 		tprints(", ");
637 	} else {
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]);
641 #elif defined(ALPHA)
642 		tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
643 #else
644 		tprintf(", %lu", tcp->u_arg[3]);
645 #endif
646 	}
647 	return 0;
648 }
649 
SYS_FUNC(rt_sigpending)650 SYS_FUNC(rt_sigpending)
651 {
652 	if (exiting(tcp)) {
653 		/*
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.
658 		 */
659 		if (syserror(tcp))
660 			tprintf("%#lx", tcp->u_arg[0]);
661 		else
662 			print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]);
663 		tprintf(", %lu", tcp->u_arg[1]);
664 	}
665 	return 0;
666 }
667 
SYS_FUNC(rt_sigsuspend)668 SYS_FUNC(rt_sigsuspend)
669 {
670 	if (entering(tcp)) {
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]);
674 	}
675 	return 0;
676 }
677 
678 static void
print_sigqueueinfo(struct tcb * tcp,int sig,unsigned long uinfo)679 print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo)
680 {
681 	printsignal(sig);
682 	tprints(", ");
683 	printsiginfo_at(tcp, uinfo);
684 }
685 
SYS_FUNC(rt_sigqueueinfo)686 SYS_FUNC(rt_sigqueueinfo)
687 {
688 	if (entering(tcp)) {
689 		tprintf("%lu, ", tcp->u_arg[0]);
690 		print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]);
691 	}
692 	return 0;
693 }
694 
SYS_FUNC(rt_tgsigqueueinfo)695 SYS_FUNC(rt_tgsigqueueinfo)
696 {
697 	if (entering(tcp)) {
698 		tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
699 		print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]);
700 	}
701 	return 0;
702 }
703 
SYS_FUNC(rt_sigtimedwait)704 SYS_FUNC(rt_sigtimedwait)
705 {
706 	/* NB: kernel requires arg[3] == NSIG / 8 */
707 	if (entering(tcp)) {
708 		print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]);
709 		tprints(", ");
710 		/* This is the only "return" parameter, */
711 		if (tcp->u_arg[1] != 0)
712 			return 0;
713 		/* ... if it's NULL, can decode all on entry */
714 		tprints("NULL, ");
715 	}
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]);
719 		tprints(", ");
720 	}
721 	else {
722 		/* syscall exit, and u_arg[1] was NULL */
723 		return 0;
724 	}
725 	print_timespec(tcp, tcp->u_arg[2]);
726 	tprintf(", %lu", tcp->u_arg[3]);
727 	return 0;
728 };
729 
SYS_FUNC(restart_syscall)730 SYS_FUNC(restart_syscall)
731 {
732 	if (entering(tcp)) {
733 		tprintf("<... resuming interrupted %s ...>",
734 			tcp->s_prev_ent
735 			? tcp->s_prev_ent->sys_name
736 			: "system call"
737 		);
738 	}
739 	return 0;
740 }
741 
742 static int
do_signalfd(struct tcb * tcp,int flags_arg)743 do_signalfd(struct tcb *tcp, int flags_arg)
744 {
745 	/* NB: kernel requires arg[2] == NSIG / 8 */
746 	if (entering(tcp)) {
747 		printfd(tcp, tcp->u_arg[0]);
748 		tprints(", ");
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) {
752 			tprints(", ");
753 			printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
754 		}
755 	}
756 	return 0;
757 }
758 
SYS_FUNC(signalfd)759 SYS_FUNC(signalfd)
760 {
761 	return do_signalfd(tcp, -1);
762 }
763 
SYS_FUNC(signalfd4)764 SYS_FUNC(signalfd4)
765 {
766 	return do_signalfd(tcp, 3);
767 }
768