Home | History | Annotate | Download | only in strace
      1 /*
      2  * Copyright (c) 1991, 1992 Paul Kranenburg <pk (at) cs.few.eur.nl>
      3  * Copyright (c) 1993 Branko Lankester <branko (at) hacktic.nl>
      4  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs (at) world.std.com>
      5  * Copyright (c) 1996-1999 Wichert Akkerman <wichert (at) cistron.nl>
      6  * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
      7  *                     Linux for s390 port by D.J. Barrow
      8  *                    <barrow_dj (at) mail.yahoo.com,djbarrow (at) 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  *	$Id$
     34  */
     35 
     36 #include "defs.h"
     37 
     38 #include <stdint.h>
     39 #include <signal.h>
     40 #ifndef HAVE_ANDROID_OS
     41 #include <sys/user.h>
     42 #endif
     43 #include <fcntl.h>
     44 
     45 #ifdef HAVE_ANDROID_OS
     46 //FIXME use "sigprocmask" or something
     47 #define sigmask(sig)    (1UL << ((sig) - 1))
     48 #define sigcontext_struct sigcontext
     49 #endif
     50 
     51 #ifdef SVR4
     52 #include <sys/ucontext.h>
     53 #endif /* SVR4 */
     54 
     55 #ifdef HAVE_SYS_REG_H
     56 # include <sys/reg.h>
     57 #ifndef PTRACE_PEEKUSR
     58 # define PTRACE_PEEKUSR PTRACE_PEEKUSER
     59 #endif
     60 #ifndef PTRACE_POKEUSR
     61 # define PTRACE_POKEUSR PTRACE_POKEUSER
     62 #endif
     63 #elif defined(HAVE_LINUX_PTRACE_H)
     64 #undef PTRACE_SYSCALL
     65 # ifdef HAVE_STRUCT_IA64_FPREG
     66 #  define ia64_fpreg XXX_ia64_fpreg
     67 # endif
     68 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS
     69 #  define pt_all_user_regs XXX_pt_all_user_regs
     70 # endif
     71 #include <linux/ptrace.h>
     72 # undef ia64_fpreg
     73 # undef pt_all_user_regs
     74 #endif
     75 
     76 
     77 #ifdef LINUX
     78 
     79 #ifdef IA64
     80 # include <asm/ptrace_offsets.h>
     81 #endif /* !IA64 */
     82 
     83 #if defined (LINUX) && defined (SPARC64)
     84 # undef PTRACE_GETREGS
     85 # define PTRACE_GETREGS PTRACE_GETREGS64
     86 # undef PTRACE_SETREGS
     87 # define PTRACE_SETREGS PTRACE_SETREGS64
     88 #endif /* LINUX && SPARC64 */
     89 
     90 #if defined (SPARC) || defined (SPARC64) || defined (MIPS)
     91 typedef struct {
     92 	struct pt_regs		si_regs;
     93 	int			si_mask;
     94 } m_siginfo_t;
     95 #elif defined HAVE_ASM_SIGCONTEXT_H
     96 #if !defined(IA64) && !defined(X86_64)
     97 #include <asm/sigcontext.h>
     98 #endif /* !IA64 && !X86_64 */
     99 #else /* !HAVE_ASM_SIGCONTEXT_H */
    100 #if defined I386 && !defined HAVE_STRUCT_SIGCONTEXT_STRUCT
    101 struct sigcontext_struct {
    102 	unsigned short gs, __gsh;
    103 	unsigned short fs, __fsh;
    104 	unsigned short es, __esh;
    105 	unsigned short ds, __dsh;
    106 	unsigned long edi;
    107 	unsigned long esi;
    108 	unsigned long ebp;
    109 	unsigned long esp;
    110 	unsigned long ebx;
    111 	unsigned long edx;
    112 	unsigned long ecx;
    113 	unsigned long eax;
    114 	unsigned long trapno;
    115 	unsigned long err;
    116 	unsigned long eip;
    117 	unsigned short cs, __csh;
    118 	unsigned long eflags;
    119 	unsigned long esp_at_signal;
    120 	unsigned short ss, __ssh;
    121 	unsigned long i387;
    122 	unsigned long oldmask;
    123 	unsigned long cr2;
    124 };
    125 #else /* !I386 */
    126 #if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT
    127 struct sigcontext
    128 {
    129 	unsigned long sc_mask;
    130 	unsigned long sc_usp;
    131 	unsigned long sc_d0;
    132 	unsigned long sc_d1;
    133 	unsigned long sc_a0;
    134 	unsigned long sc_a1;
    135 	unsigned short sc_sr;
    136 	unsigned long sc_pc;
    137 	unsigned short sc_formatvec;
    138 };
    139 #endif /* M68K */
    140 #endif /* !I386 */
    141 #endif /* !HAVE_ASM_SIGCONTEXT_H */
    142 #ifndef NSIG
    143 #define NSIG 32
    144 #endif
    145 #ifdef ARM
    146 #undef NSIG
    147 #define NSIG 32
    148 #endif
    149 #endif /* LINUX */
    150 
    151 const char *const signalent0[] = {
    152 #include "signalent.h"
    153 };
    154 const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
    155 
    156 #if SUPPORTED_PERSONALITIES >= 2
    157 const char *const signalent1[] = {
    158 #include "signalent1.h"
    159 };
    160 const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
    161 #endif /* SUPPORTED_PERSONALITIES >= 2 */
    162 
    163 #if SUPPORTED_PERSONALITIES >= 3
    164 const char *const signalent2[] = {
    165 #include "signalent2.h"
    166 };
    167 const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
    168 #endif /* SUPPORTED_PERSONALITIES >= 3 */
    169 
    170 const char *const *signalent;
    171 int nsignals;
    172 
    173 #if defined(SUNOS4) || defined(FREEBSD)
    174 
    175 static const struct xlat sigvec_flags[] = {
    176 	{ SV_ONSTACK,	"SV_ONSTACK"	},
    177 	{ SV_INTERRUPT,	"SV_INTERRUPT"	},
    178 	{ SV_RESETHAND,	"SV_RESETHAND"	},
    179 	{ SA_NOCLDSTOP,	"SA_NOCLDSTOP"	},
    180 	{ 0,		NULL		},
    181 };
    182 
    183 #endif /* SUNOS4 || FREEBSD */
    184 
    185 #ifdef HAVE_SIGACTION
    186 
    187 #if defined LINUX && (defined I386 || defined X86_64)
    188 /* The libc headers do not define this constant since it should only be
    189    used by the implementation.  So wwe define it here.  */
    190 # ifndef SA_RESTORER
    191 #  define SA_RESTORER 0x04000000
    192 # endif
    193 #endif
    194 
    195 static const struct xlat sigact_flags[] = {
    196 #ifdef SA_RESTORER
    197 	{ SA_RESTORER,	"SA_RESTORER"	},
    198 #endif
    199 #ifdef SA_STACK
    200 	{ SA_STACK,	"SA_STACK"	},
    201 #endif
    202 #ifdef SA_RESTART
    203 	{ SA_RESTART,	"SA_RESTART"	},
    204 #endif
    205 #ifdef SA_INTERRUPT
    206 	{ SA_INTERRUPT,	"SA_INTERRUPT"	},
    207 #endif
    208 #ifdef SA_NODEFER
    209 	{ SA_NODEFER,	"SA_NODEFER"	},
    210 #endif
    211 #if defined SA_NOMASK && SA_NODEFER != SA_NOMASK
    212 	{ SA_NOMASK,	"SA_NOMASK"	},
    213 #endif
    214 #ifdef SA_RESETHAND
    215 	{ SA_RESETHAND,	"SA_RESETHAND"	},
    216 #endif
    217 #if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND
    218 	{ SA_ONESHOT,	"SA_ONESHOT"	},
    219 #endif
    220 #ifdef SA_SIGINFO
    221 	{ SA_SIGINFO,	"SA_SIGINFO"	},
    222 #endif
    223 #ifdef SA_RESETHAND
    224 	{ SA_RESETHAND,	"SA_RESETHAND"	},
    225 #endif
    226 #ifdef SA_ONSTACK
    227 	{ SA_ONSTACK,	"SA_ONSTACK"	},
    228 #endif
    229 #ifdef SA_NODEFER
    230 	{ SA_NODEFER,	"SA_NODEFER"	},
    231 #endif
    232 #ifdef SA_NOCLDSTOP
    233 	{ SA_NOCLDSTOP,	"SA_NOCLDSTOP"	},
    234 #endif
    235 #ifdef SA_NOCLDWAIT
    236 	{ SA_NOCLDWAIT,	"SA_NOCLDWAIT"	},
    237 #endif
    238 #ifdef _SA_BSDCALL
    239 	{ _SA_BSDCALL,	"_SA_BSDCALL"	},
    240 #endif
    241 #ifdef SA_NOPTRACE
    242 	{ SA_NOPTRACE,	"SA_NOPTRACE"	},
    243 #endif
    244 	{ 0,		NULL		},
    245 };
    246 
    247 static const struct xlat sigprocmaskcmds[] = {
    248 	{ SIG_BLOCK,	"SIG_BLOCK"	},
    249 	{ SIG_UNBLOCK,	"SIG_UNBLOCK"	},
    250 	{ SIG_SETMASK,	"SIG_SETMASK"	},
    251 #ifdef SIG_SETMASK32
    252 	{ SIG_SETMASK32,"SIG_SETMASK32"	},
    253 #endif
    254 	{ 0,		NULL		},
    255 };
    256 
    257 #endif /* HAVE_SIGACTION */
    258 
    259 /* Anonymous realtime signals. */
    260 /* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
    261    constant.  This is what we want.  Otherwise, just use SIGRTMIN. */
    262 #ifdef SIGRTMIN
    263 #ifndef __SIGRTMIN
    264 #define __SIGRTMIN SIGRTMIN
    265 #define __SIGRTMAX SIGRTMAX /* likewise */
    266 #endif
    267 #endif
    268 
    269 const char *
    270 signame(sig)
    271 int sig;
    272 {
    273 	static char buf[30];
    274 	if (sig >= 0 && sig < nsignals) {
    275 		return signalent[sig];
    276 #ifdef SIGRTMIN
    277 	} else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
    278 		sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN));
    279 		return buf;
    280 #endif /* SIGRTMIN */
    281 	} else {
    282 		sprintf(buf, "%d", sig);
    283 		return buf;
    284 	}
    285 }
    286 
    287 #ifndef UNIXWARE
    288 static void
    289 long_to_sigset(l, s)
    290 long l;
    291 sigset_t *s;
    292 {
    293 	sigemptyset(s);
    294 	*(long *)s = l;
    295 }
    296 #endif
    297 
    298 static int
    299 copy_sigset_len(tcp, addr, s, len)
    300 struct tcb *tcp;
    301 long addr;
    302 sigset_t *s;
    303 int len;
    304 {
    305 	if (len > sizeof(*s))
    306 		len = sizeof(*s);
    307 	sigemptyset(s);
    308 	if (umoven(tcp, addr, len, (char *)s) < 0)
    309 		return -1;
    310 	return 0;
    311 }
    312 
    313 #ifdef LINUX
    314 /* Original sigset is unsigned long */
    315 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
    316 #else
    317 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
    318 #endif
    319 
    320 static const char *
    321 sprintsigmask(const char *str, sigset_t *mask, int rt)
    322 /* set might include realtime sigs */
    323 {
    324 	int i, nsigs;
    325 	int maxsigs;
    326 	const char *format;
    327 	char *s;
    328 	static char outstr[8 * sizeof(sigset_t) * 8];
    329 
    330 	strcpy(outstr, str);
    331 	s = outstr + strlen(outstr);
    332 	nsigs = 0;
    333 	maxsigs = nsignals;
    334 #ifdef __SIGRTMAX
    335 	if (rt)
    336 		maxsigs = __SIGRTMAX; /* instead */
    337 #endif
    338 	for (i = 1; i < maxsigs; i++) {
    339 		if (sigismember(mask, i) == 1)
    340 			nsigs++;
    341 	}
    342 	if (nsigs >= nsignals * 2 / 3) {
    343 		*s++ = '~';
    344 		for (i = 1; i < maxsigs; i++) {
    345 			switch (sigismember(mask, i)) {
    346 			case 1:
    347 				sigdelset(mask, i);
    348 				break;
    349 			case 0:
    350 				sigaddset(mask, i);
    351 				break;
    352 			}
    353 		}
    354 	}
    355 	format = "%s";
    356 	*s++ = '[';
    357 	for (i = 1; i < maxsigs; i++) {
    358 		if (sigismember(mask, i) == 1) {
    359 			/* real-time signals on solaris don't have
    360 			 * signalent entries
    361 			 */
    362 			if (i < nsignals) {
    363 				sprintf(s, format, signalent[i] + 3);
    364 			}
    365 #ifdef SIGRTMIN
    366 			else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
    367 				char tsig[40];
    368 				sprintf(tsig, "RT_%u", i - __SIGRTMIN);
    369 				sprintf(s, format, tsig);
    370 			}
    371 #endif /* SIGRTMIN */
    372 			else {
    373 				char tsig[32];
    374 				sprintf(tsig, "%u", i);
    375 				sprintf(s, format, tsig);
    376 			}
    377 			s += strlen(s);
    378 			format = " %s";
    379 		}
    380 	}
    381 	*s++ = ']';
    382 	*s = '\0';
    383 	return outstr;
    384 }
    385 
    386 static void
    387 printsigmask(mask, rt)
    388 sigset_t *mask;
    389 int rt;
    390 {
    391 	tprintf("%s", sprintsigmask("", mask, rt));
    392 }
    393 
    394 void
    395 printsignal(nr)
    396 int nr;
    397 {
    398 	tprintf("%s", signame(nr));
    399 }
    400 
    401 void
    402 print_sigset(struct tcb *tcp, long addr, int rt)
    403 {
    404 	sigset_t ss;
    405 
    406 	if (!addr)
    407 		tprintf("NULL");
    408 	else if (copy_sigset(tcp, addr, &ss) < 0)
    409 		tprintf("%#lx", addr);
    410 	else
    411 		printsigmask(&ss, rt);
    412 }
    413 
    414 #ifdef LINUX
    415 
    416 #ifndef ILL_ILLOPC
    417 #define ILL_ILLOPC      1       /* illegal opcode */
    418 #define ILL_ILLOPN      2       /* illegal operand */
    419 #define ILL_ILLADR      3       /* illegal addressing mode */
    420 #define ILL_ILLTRP      4       /* illegal trap */
    421 #define ILL_PRVOPC      5       /* privileged opcode */
    422 #define ILL_PRVREG      6       /* privileged register */
    423 #define ILL_COPROC      7       /* coprocessor error */
    424 #define ILL_BADSTK      8       /* internal stack error */
    425 #define FPE_INTDIV      1       /* integer divide by zero */
    426 #define FPE_INTOVF      2       /* integer overflow */
    427 #define FPE_FLTDIV      3       /* floating point divide by zero */
    428 #define FPE_FLTOVF      4       /* floating point overflow */
    429 #define FPE_FLTUND      5       /* floating point underflow */
    430 #define FPE_FLTRES      6       /* floating point inexact result */
    431 #define FPE_FLTINV      7       /* floating point invalid operation */
    432 #define FPE_FLTSUB      8       /* subscript out of range */
    433 #define SEGV_MAPERR     1       /* address not mapped to object */
    434 #define SEGV_ACCERR     2       /* invalid permissions for mapped object */
    435 #define BUS_ADRALN      1       /* invalid address alignment */
    436 #define BUS_ADRERR      2       /* non-existant physical address */
    437 #define BUS_OBJERR      3       /* object specific hardware error */
    438 #define TRAP_BRKPT      1       /* process breakpoint */
    439 #define TRAP_TRACE      2       /* process trace trap */
    440 #define CLD_EXITED      1       /* child has exited */
    441 #define CLD_KILLED      2       /* child was killed */
    442 #define CLD_DUMPED      3       /* child terminated abnormally */
    443 #define CLD_TRAPPED     4       /* traced child has trapped */
    444 #define CLD_STOPPED     5       /* child has stopped */
    445 #define CLD_CONTINUED   6       /* stopped child has continued */
    446 #define POLL_IN         1       /* data input available */
    447 #define POLL_OUT        2       /* output buffers available */
    448 #define POLL_MSG        3       /* input message available */
    449 #define POLL_ERR        4       /* i/o error */
    450 #define POLL_PRI        5       /* high priority input available */
    451 #define POLL_HUP        6       /* device disconnected */
    452 #define SI_KERNEL	0x80	/* sent by kernel */
    453 #define SI_USER         0       /* sent by kill, sigsend, raise */
    454 #define SI_QUEUE        -1      /* sent by sigqueue */
    455 #define SI_TIMER        -2      /* sent by timer expiration */
    456 #define SI_MESGQ        -3      /* sent by real time mesq state change */
    457 #define SI_ASYNCIO      -4      /* sent by AIO completion */
    458 #define SI_SIGIO	-5	/* sent by SIGIO */
    459 #define SI_TKILL	-6	/* sent by tkill */
    460 #define SI_ASYNCNL	-60     /* sent by asynch name lookup completion */
    461 
    462 #define SI_FROMUSER(sip)	((sip)->si_code <= 0)
    463 
    464 #endif /* LINUX */
    465 
    466 #if __GLIBC_MINOR__ < 1 && !defined(HAVE_ANDROID_OS)
    467 /* Type for data associated with a signal.  */
    468 typedef union sigval
    469 {
    470 	int sival_int;
    471 	void *sival_ptr;
    472 } sigval_t;
    473 
    474 # define __SI_MAX_SIZE     128
    475 # define __SI_PAD_SIZE     ((__SI_MAX_SIZE / sizeof (int)) - 3)
    476 
    477 typedef struct siginfo
    478 {
    479 	int si_signo;               /* Signal number.  */
    480 	int si_errno;               /* If non-zero, an errno value associated with
    481 								   this signal, as defined in <errno.h>.  */
    482 	int si_code;                /* Signal code.  */
    483 
    484 	union
    485 	{
    486 		int _pad[__SI_PAD_SIZE];
    487 
    488 		/* kill().  */
    489 		struct
    490 		{
    491 			__pid_t si_pid;     /* Sending process ID.  */
    492 			__uid_t si_uid;     /* Real user ID of sending process.  */
    493 		} _kill;
    494 
    495 		/* POSIX.1b timers.  */
    496 		struct
    497 		{
    498 			unsigned int _timer1;
    499 			unsigned int _timer2;
    500 		} _timer;
    501 
    502 		/* POSIX.1b signals.  */
    503 		struct
    504 		{
    505 			__pid_t si_pid;     /* Sending process ID.  */
    506 			__uid_t si_uid;     /* Real user ID of sending process.  */
    507 			sigval_t si_sigval; /* Signal value.  */
    508 		} _rt;
    509 
    510 		/* SIGCHLD.  */
    511 		struct
    512 		{
    513 			__pid_t si_pid;     /* Which child.  */
    514 			int si_status;      /* Exit value or signal.  */
    515 			__clock_t si_utime;
    516 			__clock_t si_stime;
    517 		} _sigchld;
    518 
    519 		/* SIGILL, SIGFPE, SIGSEGV, SIGBUS.  */
    520 		struct
    521 		{
    522 			void *si_addr;      /* Faulting insn/memory ref.  */
    523 		} _sigfault;
    524 
    525 		/* SIGPOLL.  */
    526 		struct
    527 		{
    528 			int si_band;        /* Band event for SIGPOLL.  */
    529 			int si_fd;
    530 		} _sigpoll;
    531 	} _sifields;
    532 } siginfo_t;
    533 
    534 #define si_pid		_sifields._kill.si_pid
    535 #define si_uid		_sifields._kill.si_uid
    536 #define si_status	_sifields._sigchld.si_status
    537 #define si_utime	_sifields._sigchld.si_utime
    538 #define si_stime	_sifields._sigchld.si_stime
    539 #define si_value	_sifields._rt.si_sigval
    540 #define si_int		_sifields._rt.si_sigval.sival_int
    541 #define si_ptr		_sifields._rt.si_sigval.sival_ptr
    542 #define si_addr		_sifields._sigfault.si_addr
    543 #define si_band		_sifields._sigpoll.si_band
    544 #define si_fd		_sifields._sigpoll.si_fd
    545 
    546 #endif
    547 
    548 #endif
    549 
    550 #if defined (SVR4) || defined (LINUX)
    551 
    552 static const struct xlat siginfo_codes[] = {
    553 #ifdef SI_KERNEL
    554 	{ SI_KERNEL,	"SI_KERNEL"	},
    555 #endif
    556 #ifdef SI_USER
    557 	{ SI_USER,	"SI_USER"	},
    558 #endif
    559 #ifdef SI_QUEUE
    560 	{ SI_QUEUE,	"SI_QUEUE"	},
    561 #endif
    562 #ifdef SI_TIMER
    563 	{ SI_TIMER,	"SI_TIMER"	},
    564 #endif
    565 #ifdef SI_MESGQ
    566 	{ SI_MESGQ,	"SI_MESGQ"	},
    567 #endif
    568 #ifdef SI_ASYNCIO
    569 	{ SI_ASYNCIO,	"SI_ASYNCIO"	},
    570 #endif
    571 #ifdef SI_SIGIO
    572 	{ SI_SIGIO,	"SI_SIGIO"	},
    573 #endif
    574 #ifdef SI_TKILL
    575 	{ SI_TKILL,	"SI_TKILL"	},
    576 #endif
    577 #ifdef SI_ASYNCNL
    578 	{ SI_ASYNCNL,	"SI_ASYNCNL"	},
    579 #endif
    580 #ifdef SI_NOINFO
    581 	{ SI_NOINFO,	"SI_NOINFO"	},
    582 #endif
    583 #ifdef SI_LWP
    584 	{ SI_LWP,	"SI_LWP"	},
    585 #endif
    586 	{ 0,		NULL		},
    587 };
    588 
    589 static const struct xlat sigill_codes[] = {
    590 	{ ILL_ILLOPC,	"ILL_ILLOPC"	},
    591 	{ ILL_ILLOPN,	"ILL_ILLOPN"	},
    592 	{ ILL_ILLADR,	"ILL_ILLADR"	},
    593 	{ ILL_ILLTRP,	"ILL_ILLTRP"	},
    594 	{ ILL_PRVOPC,	"ILL_PRVOPC"	},
    595 	{ ILL_PRVREG,	"ILL_PRVREG"	},
    596 	{ ILL_COPROC,	"ILL_COPROC"	},
    597 	{ ILL_BADSTK,	"ILL_BADSTK"	},
    598 	{ 0,		NULL		},
    599 };
    600 
    601 static const struct xlat sigfpe_codes[] = {
    602 	{ FPE_INTDIV,	"FPE_INTDIV"	},
    603 	{ FPE_INTOVF,	"FPE_INTOVF"	},
    604 	{ FPE_FLTDIV,	"FPE_FLTDIV"	},
    605 	{ FPE_FLTOVF,	"FPE_FLTOVF"	},
    606 	{ FPE_FLTUND,	"FPE_FLTUND"	},
    607 	{ FPE_FLTRES,	"FPE_FLTRES"	},
    608 	{ FPE_FLTINV,	"FPE_FLTINV"	},
    609 	{ FPE_FLTSUB,	"FPE_FLTSUB"	},
    610 	{ 0,		NULL		},
    611 };
    612 
    613 static const struct xlat sigtrap_codes[] = {
    614 	{ TRAP_BRKPT,	"TRAP_BRKPT"	},
    615 	{ TRAP_TRACE,	"TRAP_TRACE"	},
    616 	{ 0,		NULL		},
    617 };
    618 
    619 static const struct xlat sigchld_codes[] = {
    620 	{ CLD_EXITED,	"CLD_EXITED"	},
    621 	{ CLD_KILLED,	"CLD_KILLED"	},
    622 	{ CLD_DUMPED,	"CLD_DUMPED"	},
    623 	{ CLD_TRAPPED,	"CLD_TRAPPED"	},
    624 	{ CLD_STOPPED,	"CLD_STOPPED"	},
    625 	{ CLD_CONTINUED,"CLD_CONTINUED"	},
    626 	{ 0,		NULL		},
    627 };
    628 
    629 static const struct xlat sigpoll_codes[] = {
    630 	{ POLL_IN,	"POLL_IN"	},
    631 	{ POLL_OUT,	"POLL_OUT"	},
    632 	{ POLL_MSG,	"POLL_MSG"	},
    633 	{ POLL_ERR,	"POLL_ERR"	},
    634 	{ POLL_PRI,	"POLL_PRI"	},
    635 	{ POLL_HUP,	"POLL_HUP"	},
    636 	{ 0,		NULL		},
    637 };
    638 
    639 static const struct xlat sigprof_codes[] = {
    640 #ifdef PROF_SIG
    641 	{ PROF_SIG,	"PROF_SIG"	},
    642 #endif
    643 	{ 0,		NULL		},
    644 };
    645 
    646 #ifdef SIGEMT
    647 static const struct xlat sigemt_codes[] = {
    648 #ifdef EMT_TAGOVF
    649 	{ EMT_TAGOVF,	"EMT_TAGOVF"	},
    650 #endif
    651 	{ 0,		NULL		},
    652 };
    653 #endif
    654 
    655 static const struct xlat sigsegv_codes[] = {
    656 	{ SEGV_MAPERR,	"SEGV_MAPERR"	},
    657 	{ SEGV_ACCERR,	"SEGV_ACCERR"	},
    658 	{ 0,		NULL		},
    659 };
    660 
    661 static const struct xlat sigbus_codes[] = {
    662 	{ BUS_ADRALN,	"BUS_ADRALN"	},
    663 	{ BUS_ADRERR,	"BUS_ADRERR"	},
    664 	{ BUS_OBJERR,	"BUS_OBJERR"	},
    665 	{ 0,		NULL		},
    666 };
    667 
    668 void
    669 printsiginfo(siginfo_t *sip, int verbose)
    670 {
    671 	const char *code;
    672 
    673 	if (sip->si_signo == 0) {
    674 		tprintf ("{}");
    675 		return;
    676 	}
    677 	tprintf("{si_signo=");
    678 	printsignal(sip->si_signo);
    679 	code = xlookup(siginfo_codes, sip->si_code);
    680 	if (!code) {
    681 		switch (sip->si_signo) {
    682 		case SIGTRAP:
    683 			code = xlookup(sigtrap_codes, sip->si_code);
    684 			break;
    685 		case SIGCHLD:
    686 			code = xlookup(sigchld_codes, sip->si_code);
    687 			break;
    688 		case SIGPOLL:
    689 			code = xlookup(sigpoll_codes, sip->si_code);
    690 			break;
    691 		case SIGPROF:
    692 			code = xlookup(sigprof_codes, sip->si_code);
    693 			break;
    694 		case SIGILL:
    695 			code = xlookup(sigill_codes, sip->si_code);
    696 			break;
    697 #ifdef SIGEMT
    698 		case SIGEMT:
    699 			code = xlookup(sigemt_codes, sip->si_code);
    700 			break;
    701 #endif
    702 		case SIGFPE:
    703 			code = xlookup(sigfpe_codes, sip->si_code);
    704 			break;
    705 		case SIGSEGV:
    706 			code = xlookup(sigsegv_codes, sip->si_code);
    707 			break;
    708 		case SIGBUS:
    709 			code = xlookup(sigbus_codes, sip->si_code);
    710 			break;
    711 		}
    712 	}
    713 	if (code)
    714 		tprintf(", si_code=%s", code);
    715 	else
    716 		tprintf(", si_code=%#x", sip->si_code);
    717 #ifdef SI_NOINFO
    718 	if (sip->si_code != SI_NOINFO)
    719 #endif
    720 	{
    721 		if (sip->si_errno) {
    722 			if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
    723 				tprintf(", si_errno=%d", sip->si_errno);
    724 			else
    725 				tprintf(", si_errno=%s",
    726 					errnoent[sip->si_errno]);
    727 		}
    728 #ifdef SI_FROMUSER
    729 		if (SI_FROMUSER(sip)) {
    730 			tprintf(", si_pid=%lu, si_uid=%lu",
    731 				(unsigned long) sip->si_pid,
    732 				(unsigned long) sip->si_uid);
    733 			switch (sip->si_code) {
    734 #ifdef SI_USER
    735 			case SI_USER:
    736 				break;
    737 #endif
    738 #ifdef SI_TKILL
    739 			case SI_TKILL:
    740 				break;
    741 #endif
    742 #ifdef SI_TIMER
    743 			case SI_TIMER:
    744 				tprintf(", si_value=%d", sip->si_int);
    745 				break;
    746 #endif
    747 #ifdef LINUX
    748 			default:
    749 				if (!sip->si_ptr)
    750 					break;
    751 				if (!verbose)
    752 					tprintf(", ...");
    753 				else
    754 					tprintf(", si_value={int=%u, ptr=%#lx}",
    755 						sip->si_int,
    756 						(unsigned long) sip->si_ptr);
    757 				break;
    758 #endif
    759 			}
    760 		}
    761 		else
    762 #endif /* SI_FROMUSER */
    763 		{
    764 			switch (sip->si_signo) {
    765 			case SIGCHLD:
    766 				tprintf(", si_pid=%ld, si_status=",
    767 					(long) sip->si_pid);
    768 				if (sip->si_code == CLD_EXITED)
    769 					tprintf("%d", sip->si_status);
    770 				else
    771 					printsignal(sip->si_status);
    772 #if LINUX
    773 				if (!verbose)
    774 					tprintf(", ...");
    775 				else
    776 					tprintf(", si_utime=%lu, si_stime=%lu",
    777 						sip->si_utime,
    778 						sip->si_stime);
    779 #endif
    780 				break;
    781 			case SIGILL: case SIGFPE:
    782 			case SIGSEGV: case SIGBUS:
    783 				tprintf(", si_addr=%#lx",
    784 					(unsigned long) sip->si_addr);
    785 				break;
    786 			case SIGPOLL:
    787 				switch (sip->si_code) {
    788 				case POLL_IN: case POLL_OUT: case POLL_MSG:
    789 					tprintf(", si_band=%ld",
    790 						(long) sip->si_band);
    791 					break;
    792 				}
    793 				break;
    794 #ifdef LINUX
    795 			default:
    796 				if (sip->si_pid || sip->si_uid)
    797 				        tprintf(", si_pid=%lu, si_uid=%lu",
    798 						(unsigned long) sip->si_pid,
    799 						(unsigned long) sip->si_uid);
    800 				if (!sip->si_ptr)
    801 					break;
    802 				if (!verbose)
    803 					tprintf(", ...");
    804 				else {
    805 					tprintf(", si_value={int=%u, ptr=%#lx}",
    806 						sip->si_int,
    807 						(unsigned long) sip->si_ptr);
    808 				}
    809 #endif
    810 
    811 			}
    812 		}
    813 	}
    814 	tprintf("}");
    815 }
    816 
    817 #endif /* SVR4 || LINUX */
    818 
    819 #ifdef LINUX
    820 
    821 static void
    822 parse_sigset_t(const char *str, sigset_t *set)
    823 {
    824 	const char *p;
    825 	unsigned int digit;
    826 	int i;
    827 
    828 	sigemptyset(set);
    829 
    830 	p = strchr(str, '\n');
    831 	if (p == NULL)
    832 		p = strchr(str, '\0');
    833 	for (i = 0; p-- > str; i += 4) {
    834 		if (*p >= '0' && *p <= '9')
    835 			digit = *p - '0';
    836 		else if (*p >= 'a' && *p <= 'f')
    837 			digit = *p - 'a' + 10;
    838 		else if (*p >= 'A' && *p <= 'F')
    839 			digit = *p - 'A' + 10;
    840 		else
    841 			break;
    842 		if (digit & 1)
    843 			sigaddset(set, i + 1);
    844 		if (digit & 2)
    845 			sigaddset(set, i + 2);
    846 		if (digit & 4)
    847 			sigaddset(set, i + 3);
    848 		if (digit & 8)
    849 			sigaddset(set, i + 4);
    850 	}
    851 }
    852 
    853 #endif
    854 
    855 /*
    856  * Check process TCP for the disposition of signal SIG.
    857  * Return 1 if the process would somehow manage to  survive signal SIG,
    858  * else return 0.  This routine will never be called with SIGKILL.
    859  */
    860 int
    861 sigishandled(tcp, sig)
    862 struct tcb *tcp;
    863 int sig;
    864 {
    865 #ifdef LINUX
    866 	int sfd;
    867 	char sname[32];
    868 	char buf[2048];
    869 	const char *s;
    870 	int i;
    871 	sigset_t ignored, caught;
    872 #endif
    873 #ifdef SVR4
    874 	/*
    875 	 * Since procfs doesn't interfere with wait I think it is safe
    876 	 * to punt on this question.  If not, the information is there.
    877 	 */
    878 	return 1;
    879 #else /* !SVR4 */
    880 	switch (sig) {
    881 	case SIGCONT:
    882 	case SIGSTOP:
    883 	case SIGTSTP:
    884 	case SIGTTIN:
    885 	case SIGTTOU:
    886 	case SIGCHLD:
    887 	case SIGIO:
    888 #if defined(SIGURG) && SIGURG != SIGIO
    889 	case SIGURG:
    890 #endif
    891 	case SIGWINCH:
    892 		/* Gloria Gaynor says ... */
    893 		return 1;
    894 	default:
    895 		break;
    896 	}
    897 #endif /* !SVR4 */
    898 #ifdef LINUX
    899 
    900 	/* This is incredibly costly but it's worth it. */
    901 	/* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and
    902 	   SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which
    903 	   doesn't handle real-time signals). */
    904 	sprintf(sname, "/proc/%d/status", tcp->pid);
    905 	if ((sfd = open(sname, O_RDONLY)) == -1) {
    906 		perror(sname);
    907 		return 1;
    908 	}
    909 	i = read(sfd, buf, sizeof(buf));
    910 	buf[i] = '\0';
    911 	close(sfd);
    912 	/*
    913 	 * Skip the extraneous fields. We need to skip
    914 	 * command name has any spaces in it.  So be it.
    915 	 */
    916 	s = strstr(buf, "SigIgn:\t");
    917 	if (!s)
    918 	{
    919 		fprintf(stderr, "/proc/pid/status format error\n");
    920 		return 1;
    921 	}
    922 	parse_sigset_t(s + 8, &ignored);
    923 
    924 	s = strstr(buf, "SigCgt:\t");
    925 	if (!s)
    926 	{
    927 		fprintf(stderr, "/proc/pid/status format error\n");
    928 		return 1;
    929 	}
    930 	parse_sigset_t(s + 8, &caught);
    931 
    932 #ifdef DEBUG
    933 	fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n",
    934 		*(long long *) &ignored, *(long long *) &caught, sig);
    935 #endif
    936 	if (sigismember(&ignored, sig) || sigismember(&caught, sig))
    937 		return 1;
    938 #endif /* LINUX */
    939 
    940 #ifdef SUNOS4
    941 	void (*u_signal)();
    942 
    943 	if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal),
    944 	    (long *) &u_signal) < 0) {
    945 		return 0;
    946 	}
    947 	if (u_signal != SIG_DFL)
    948 		return 1;
    949 #endif /* SUNOS4 */
    950 
    951 	return 0;
    952 }
    953 
    954 #if defined(SUNOS4) || defined(FREEBSD)
    955 
    956 int
    957 sys_sigvec(tcp)
    958 struct tcb *tcp;
    959 {
    960 	struct sigvec sv;
    961 	long addr;
    962 
    963 	if (entering(tcp)) {
    964 		printsignal(tcp->u_arg[0]);
    965 		tprintf(", ");
    966 		addr = tcp->u_arg[1];
    967 	} else {
    968 		addr = tcp->u_arg[2];
    969 	}
    970 	if (addr == 0)
    971 		tprintf("NULL");
    972 	else if (!verbose(tcp))
    973 		tprintf("%#lx", addr);
    974 	else if (umove(tcp, addr, &sv) < 0)
    975 		tprintf("{...}");
    976 	else {
    977 		switch ((int) sv.sv_handler) {
    978 		case (int) SIG_ERR:
    979 			tprintf("{SIG_ERR}");
    980 			break;
    981 		case (int) SIG_DFL:
    982 			tprintf("{SIG_DFL}");
    983 			break;
    984 		case (int) SIG_IGN:
    985 			if (tcp->u_arg[0] == SIGTRAP) {
    986 				tcp->flags |= TCB_SIGTRAPPED;
    987 				kill(tcp->pid, SIGSTOP);
    988 			}
    989 			tprintf("{SIG_IGN}");
    990 			break;
    991 		case (int) SIG_HOLD:
    992 			if (tcp->u_arg[0] == SIGTRAP) {
    993 				tcp->flags |= TCB_SIGTRAPPED;
    994 				kill(tcp->pid, SIGSTOP);
    995 			}
    996 			tprintf("SIG_HOLD");
    997 			break;
    998 		default:
    999 			if (tcp->u_arg[0] == SIGTRAP) {
   1000 				tcp->flags |= TCB_SIGTRAPPED;
   1001 				kill(tcp->pid, SIGSTOP);
   1002 			}
   1003 			tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
   1004 			printsigmask(&sv.sv_mask, 0);
   1005 			tprintf(", ");
   1006 			printflags(sigvec_flags, sv.sv_flags, "SV_???");
   1007 			tprintf("}");
   1008 		}
   1009 	}
   1010 	if (entering(tcp))
   1011 		tprintf(", ");
   1012 	return 0;
   1013 }
   1014 
   1015 int
   1016 sys_sigpause(tcp)
   1017 struct tcb *tcp;
   1018 {
   1019 	if (entering(tcp)) {	/* WTA: UD had a bug here: he forgot the braces */
   1020 		sigset_t sigm;
   1021 		long_to_sigset(tcp->u_arg[0], &sigm);
   1022 		printsigmask(&sigm, 0);
   1023 	}
   1024 	return 0;
   1025 }
   1026 
   1027 int
   1028 sys_sigstack(tcp)
   1029 struct tcb *tcp;
   1030 {
   1031 	struct sigstack ss;
   1032 	long addr;
   1033 
   1034 	if (entering(tcp))
   1035 		addr = tcp->u_arg[0];
   1036 	else
   1037 		addr = tcp->u_arg[1];
   1038 	if (addr == 0)
   1039 		tprintf("NULL");
   1040 	else if (umove(tcp, addr, &ss) < 0)
   1041 		tprintf("%#lx", addr);
   1042 	else {
   1043 		tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
   1044 		tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
   1045 	}
   1046 	if (entering(tcp))
   1047 		tprintf(", ");
   1048 	return 0;
   1049 }
   1050 
   1051 int
   1052 sys_sigcleanup(tcp)
   1053 struct tcb *tcp;
   1054 {
   1055 	return 0;
   1056 }
   1057 
   1058 #endif /* SUNOS4 || FREEBSD */
   1059 
   1060 #ifndef SVR4
   1061 
   1062 int
   1063 sys_sigsetmask(tcp)
   1064 struct tcb *tcp;
   1065 {
   1066 	if (entering(tcp)) {
   1067 		sigset_t sigm;
   1068 		long_to_sigset(tcp->u_arg[0], &sigm);
   1069 		printsigmask(&sigm, 0);
   1070 #ifndef USE_PROCFS
   1071 		if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
   1072 			/* Mark attempt to block SIGTRAP */
   1073 			tcp->flags |= TCB_SIGTRAPPED;
   1074 			/* Send unblockable signal */
   1075 			kill(tcp->pid, SIGSTOP);
   1076 		}
   1077 #endif /* !USE_PROCFS */
   1078 	}
   1079 	else if (!syserror(tcp)) {
   1080 		sigset_t sigm;
   1081 		long_to_sigset(tcp->u_rval, &sigm);
   1082 		tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
   1083 
   1084 		return RVAL_HEX | RVAL_STR;
   1085 	}
   1086 	return 0;
   1087 }
   1088 
   1089 #if defined(SUNOS4) || defined(FREEBSD)
   1090 int
   1091 sys_sigblock(tcp)
   1092 struct tcb *tcp;
   1093 {
   1094 	return sys_sigsetmask(tcp);
   1095 }
   1096 #endif /* SUNOS4 || FREEBSD */
   1097 
   1098 #endif /* !SVR4 */
   1099 
   1100 #ifdef HAVE_SIGACTION
   1101 
   1102 #ifdef LINUX
   1103 struct old_sigaction {
   1104 	__sighandler_t __sa_handler;
   1105 	unsigned long sa_mask;
   1106 	unsigned long sa_flags;
   1107 	void (*sa_restorer)(void);
   1108 };
   1109 #define SA_HANDLER __sa_handler
   1110 #endif /* LINUX */
   1111 
   1112 #ifndef SA_HANDLER
   1113 #define SA_HANDLER sa_handler
   1114 #endif
   1115 
   1116 int
   1117 sys_sigaction(tcp)
   1118 struct tcb *tcp;
   1119 {
   1120 	long addr;
   1121 #ifdef LINUX
   1122 	sigset_t sigset;
   1123 	struct old_sigaction sa;
   1124 #else
   1125 	struct sigaction sa;
   1126 #endif
   1127 
   1128 
   1129 	if (entering(tcp)) {
   1130 		printsignal(tcp->u_arg[0]);
   1131 		tprintf(", ");
   1132 		addr = tcp->u_arg[1];
   1133 	} else
   1134 		addr = tcp->u_arg[2];
   1135 	if (addr == 0)
   1136 		tprintf("NULL");
   1137 	else if (!verbose(tcp))
   1138 		tprintf("%#lx", addr);
   1139 	else if (umove(tcp, addr, &sa) < 0)
   1140 		tprintf("{...}");
   1141 	else {
   1142 		/* Architectures using function pointers, like
   1143 		 * hppa, may need to manipulate the function pointer
   1144 		 * to compute the result of a comparison. However,
   1145 		 * the SA_HANDLER function pointer exists only in
   1146 		 * the address space of the traced process, and can't
   1147 		 * be manipulated by strace. In order to prevent the
   1148 		 * compiler from generating code to manipulate
   1149 		 * SA_HANDLER we cast the function pointers to long. */
   1150 		if ((long)sa.SA_HANDLER == (long)SIG_ERR)
   1151 			tprintf("{SIG_ERR, ");
   1152 		else if ((long)sa.SA_HANDLER == (long)SIG_DFL)
   1153 			tprintf("{SIG_DFL, ");
   1154 		else if ((long)sa.SA_HANDLER == (long)SIG_IGN) {
   1155 #ifndef USE_PROCFS
   1156 			if (tcp->u_arg[0] == SIGTRAP) {
   1157 				tcp->flags |= TCB_SIGTRAPPED;
   1158 				kill(tcp->pid, SIGSTOP);
   1159 			}
   1160 #endif /* !USE_PROCFS */
   1161 			tprintf("{SIG_IGN, ");
   1162 		}
   1163 		else {
   1164 #ifndef USE_PROCFS
   1165 			if (tcp->u_arg[0] == SIGTRAP) {
   1166 				tcp->flags |= TCB_SIGTRAPPED;
   1167 				kill(tcp->pid, SIGSTOP);
   1168 			}
   1169 #endif /* !USE_PROCFS */
   1170 			tprintf("{%#lx, ", (long) sa.SA_HANDLER);
   1171 #ifndef LINUX
   1172 			printsigmask (&sa.sa_mask, 0);
   1173 #else
   1174 			long_to_sigset(sa.sa_mask, &sigset);
   1175 			printsigmask(&sigset, 0);
   1176 #endif
   1177 			tprintf(", ");
   1178 			printflags(sigact_flags, sa.sa_flags, "SA_???");
   1179 #ifdef SA_RESTORER
   1180 			if (sa.sa_flags & SA_RESTORER)
   1181 				tprintf(", %p", sa.sa_restorer);
   1182 #endif
   1183 			tprintf("}");
   1184 		}
   1185 	}
   1186 	if (entering(tcp))
   1187 		tprintf(", ");
   1188 #ifdef LINUX
   1189 	else
   1190 		tprintf(", %#lx", (unsigned long) sa.sa_restorer);
   1191 #endif
   1192 	return 0;
   1193 }
   1194 
   1195 int
   1196 sys_signal(tcp)
   1197 struct tcb *tcp;
   1198 {
   1199 	if (entering(tcp)) {
   1200 		printsignal(tcp->u_arg[0]);
   1201 		tprintf(", ");
   1202 		switch (tcp->u_arg[1]) {
   1203 		case (long) SIG_ERR:
   1204 			tprintf("SIG_ERR");
   1205 			break;
   1206 		case (long) SIG_DFL:
   1207 			tprintf("SIG_DFL");
   1208 			break;
   1209 		case (long) SIG_IGN:
   1210 #ifndef USE_PROCFS
   1211 			if (tcp->u_arg[0] == SIGTRAP) {
   1212 				tcp->flags |= TCB_SIGTRAPPED;
   1213 				kill(tcp->pid, SIGSTOP);
   1214 			}
   1215 #endif /* !USE_PROCFS */
   1216 			tprintf("SIG_IGN");
   1217 			break;
   1218 		default:
   1219 #ifndef USE_PROCFS
   1220 			if (tcp->u_arg[0] == SIGTRAP) {
   1221 				tcp->flags |= TCB_SIGTRAPPED;
   1222 				kill(tcp->pid, SIGSTOP);
   1223 			}
   1224 #endif /* !USE_PROCFS */
   1225 			tprintf("%#lx", tcp->u_arg[1]);
   1226 		}
   1227 		return 0;
   1228 	}
   1229 	else if (!syserror(tcp)) {
   1230 		switch (tcp->u_rval) {
   1231 		    case (long) SIG_ERR:
   1232 			tcp->auxstr = "SIG_ERR"; break;
   1233 		    case (long) SIG_DFL:
   1234 			tcp->auxstr = "SIG_DFL"; break;
   1235 		    case (long) SIG_IGN:
   1236 			tcp->auxstr = "SIG_IGN"; break;
   1237 		    default:
   1238 			tcp->auxstr = NULL;
   1239 		}
   1240 		return RVAL_HEX | RVAL_STR;
   1241 	}
   1242 	return 0;
   1243 }
   1244 
   1245 #ifdef SVR4
   1246 int
   1247 sys_sighold(tcp)
   1248 struct tcb *tcp;
   1249 {
   1250 	if (entering(tcp)) {
   1251 		printsignal(tcp->u_arg[0]);
   1252 	}
   1253 	return 0;
   1254 }
   1255 #endif /* SVR4 */
   1256 
   1257 #endif /* HAVE_SIGACTION */
   1258 
   1259 #ifdef LINUX
   1260 
   1261 int
   1262 sys_sigreturn(struct tcb *tcp)
   1263 {
   1264 #if defined(ARM)
   1265 	struct pt_regs regs;
   1266 	struct sigcontext_struct sc;
   1267 
   1268 	if (entering(tcp)) {
   1269 		tcp->u_arg[0] = 0;
   1270 
   1271 		if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
   1272 			return 0;
   1273 
   1274 		if (umove(tcp, regs.ARM_sp, &sc) < 0)
   1275 			return 0;
   1276 
   1277 		tcp->u_arg[0] = 1;
   1278 		tcp->u_arg[1] = sc.oldmask;
   1279 	} else {
   1280 		sigset_t sigm;
   1281 		long_to_sigset(tcp->u_arg[1], &sigm);
   1282 		tcp->u_rval = tcp->u_error = 0;
   1283 		if (tcp->u_arg[0] == 0)
   1284 			return 0;
   1285 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1286 		return RVAL_NONE | RVAL_STR;
   1287 	}
   1288 	return 0;
   1289 #elif defined(S390) || defined(S390X)
   1290 	long usp;
   1291 	struct sigcontext_struct sc;
   1292 
   1293 	if (entering(tcp)) {
   1294 		tcp->u_arg[0] = 0;
   1295 		if (upeek(tcp,PT_GPR15,&usp)<0)
   1296 			return 0;
   1297 		if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0)
   1298 			return 0;
   1299 		tcp->u_arg[0] = 1;
   1300 		memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t));
   1301 	} else {
   1302 		tcp->u_rval = tcp->u_error = 0;
   1303 		if (tcp->u_arg[0] == 0)
   1304 			return 0;
   1305 		tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
   1306 		return RVAL_NONE | RVAL_STR;
   1307 	}
   1308 	return 0;
   1309 #elif defined(I386)
   1310 	long esp;
   1311 	struct sigcontext_struct sc;
   1312 
   1313 	if (entering(tcp)) {
   1314 		tcp->u_arg[0] = 0;
   1315 		if (upeek(tcp, 4*UESP, &esp) < 0)
   1316 			return 0;
   1317 		if (umove(tcp, esp, &sc) < 0)
   1318 			return 0;
   1319 		tcp->u_arg[0] = 1;
   1320 		tcp->u_arg[1] = sc.oldmask;
   1321 	}
   1322 	else {
   1323 		sigset_t sigm;
   1324 		long_to_sigset(tcp->u_arg[1], &sigm);
   1325 		tcp->u_rval = tcp->u_error = 0;
   1326 		if (tcp->u_arg[0] == 0)
   1327 			return 0;
   1328 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1329 		return RVAL_NONE | RVAL_STR;
   1330 	}
   1331 	return 0;
   1332 #elif defined(IA64)
   1333 	struct sigcontext sc;
   1334 	long sp;
   1335 
   1336 	if (entering(tcp)) {
   1337 		/* offset of sigcontext in the kernel's sigframe structure: */
   1338 #		define SIGFRAME_SC_OFFSET	0x90
   1339 		tcp->u_arg[0] = 0;
   1340 		if (upeek(tcp, PT_R12, &sp) < 0)
   1341 			return 0;
   1342 		if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0)
   1343 			return 0;
   1344 		tcp->u_arg[0] = 1;
   1345 		memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask));
   1346 	}
   1347 	else {
   1348 		sigset_t sigm;
   1349 
   1350 		memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
   1351 		tcp->u_rval = tcp->u_error = 0;
   1352 		if (tcp->u_arg[0] == 0)
   1353 			return 0;
   1354 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1355 		return RVAL_NONE | RVAL_STR;
   1356 	}
   1357 	return 0;
   1358 #elif defined(POWERPC)
   1359 	long esp;
   1360 	struct sigcontext_struct sc;
   1361 
   1362 	if (entering(tcp)) {
   1363 		tcp->u_arg[0] = 0;
   1364 		if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0)
   1365 			return 0;
   1366 		/* Skip dummy stack frame. */
   1367 #ifdef POWERPC64
   1368 		if (current_personality == 0)
   1369 			esp += 128;
   1370 		else
   1371 			esp += 64;
   1372 #else
   1373 		esp += 64;
   1374 #endif
   1375 		if (umove(tcp, esp, &sc) < 0)
   1376 			return 0;
   1377 		tcp->u_arg[0] = 1;
   1378 		tcp->u_arg[1] = sc.oldmask;
   1379 	}
   1380 	else {
   1381 		sigset_t sigm;
   1382 		long_to_sigset(tcp->u_arg[1], &sigm);
   1383 		tcp->u_rval = tcp->u_error = 0;
   1384 		if (tcp->u_arg[0] == 0)
   1385 			return 0;
   1386 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1387 		return RVAL_NONE | RVAL_STR;
   1388 	}
   1389 	return 0;
   1390 #elif defined(M68K)
   1391 	long usp;
   1392 	struct sigcontext sc;
   1393 
   1394 	if (entering(tcp)) {
   1395 		tcp->u_arg[0] = 0;
   1396 		if (upeek(tcp, 4*PT_USP, &usp) < 0)
   1397 			return 0;
   1398 		if (umove(tcp, usp, &sc) < 0)
   1399 			return 0;
   1400 		tcp->u_arg[0] = 1;
   1401 		tcp->u_arg[1] = sc.sc_mask;
   1402 	}
   1403 	else {
   1404 		sigset_t sigm;
   1405 		long_to_sigset(tcp->u_arg[1], &sigm);
   1406 		tcp->u_rval = tcp->u_error = 0;
   1407 		if (tcp->u_arg[0] == 0)
   1408 			return 0;
   1409 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1410 		return RVAL_NONE | RVAL_STR;
   1411 	}
   1412 	return 0;
   1413 #elif defined(ALPHA)
   1414 	long fp;
   1415 	struct sigcontext_struct sc;
   1416 
   1417 	if (entering(tcp)) {
   1418 		tcp->u_arg[0] = 0;
   1419 		if (upeek(tcp, REG_FP, &fp) < 0)
   1420 			return 0;
   1421 		if (umove(tcp, fp, &sc) < 0)
   1422 			return 0;
   1423 		tcp->u_arg[0] = 1;
   1424 		tcp->u_arg[1] = sc.sc_mask;
   1425 	}
   1426 	else {
   1427 		sigset_t sigm;
   1428 		long_to_sigset(tcp->u_arg[1], &sigm);
   1429 		tcp->u_rval = tcp->u_error = 0;
   1430 		if (tcp->u_arg[0] == 0)
   1431 			return 0;
   1432 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1433 		return RVAL_NONE | RVAL_STR;
   1434 	}
   1435 	return 0;
   1436 #elif defined (SPARC) || defined (SPARC64)
   1437 	long i1;
   1438 	struct pt_regs regs;
   1439 	m_siginfo_t si;
   1440 
   1441 	if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
   1442 		perror("sigreturn: PTRACE_GETREGS ");
   1443 		return 0;
   1444 	}
   1445 	if(entering(tcp)) {
   1446 		tcp->u_arg[0] = 0;
   1447 		i1 = regs.u_regs[U_REG_O1];
   1448 		if(umove(tcp, i1, &si) < 0) {
   1449 			perror("sigreturn: umove ");
   1450 			return 0;
   1451 		}
   1452 		tcp->u_arg[0] = 1;
   1453 		tcp->u_arg[1] = si.si_mask;
   1454 	} else {
   1455 		sigset_t sigm;
   1456 		long_to_sigset(tcp->u_arg[1], &sigm);
   1457 		tcp->u_rval = tcp->u_error = 0;
   1458 		if(tcp->u_arg[0] == 0)
   1459 			return 0;
   1460 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1461 		return RVAL_NONE | RVAL_STR;
   1462 	}
   1463 	return 0;
   1464 #elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64)
   1465 	/* This decodes rt_sigreturn.  The 64-bit ABIs do not have
   1466 	   sigreturn.  */
   1467 	long sp;
   1468 	struct ucontext uc;
   1469 
   1470 	if(entering(tcp)) {
   1471 		tcp->u_arg[0] = 0;
   1472 		if (upeek(tcp, REG_SP, &sp) < 0)
   1473 			return 0;
   1474 		/* There are six words followed by a 128-byte siginfo.  */
   1475 		sp = sp + 6 * 4 + 128;
   1476 		if (umove(tcp, sp, &uc) < 0)
   1477 			return 0;
   1478 		tcp->u_arg[0] = 1;
   1479 		tcp->u_arg[1] = *(long *) &uc.uc_sigmask;
   1480 	} else {
   1481 		sigset_t sigm;
   1482 		long_to_sigset(tcp->u_arg[1], &sigm);
   1483 		tcp->u_rval = tcp->u_error = 0;
   1484 		if(tcp->u_arg[0] == 0)
   1485 			return 0;
   1486 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1487 		return RVAL_NONE | RVAL_STR;
   1488 	}
   1489 	return 0;
   1490 #elif defined(MIPS)
   1491 	long sp;
   1492 	struct pt_regs regs;
   1493 	m_siginfo_t si;
   1494 
   1495 	if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
   1496 		perror("sigreturn: PTRACE_GETREGS ");
   1497 		return 0;
   1498 	}
   1499 	if(entering(tcp)) {
   1500 		tcp->u_arg[0] = 0;
   1501 		sp = regs.regs[29];
   1502 		if (umove(tcp, sp, &si) < 0)
   1503 		tcp->u_arg[0] = 1;
   1504 		tcp->u_arg[1] = si.si_mask;
   1505 	} else {
   1506 		sigset_t sigm;
   1507 		long_to_sigset(tcp->u_arg[1], &sigm);
   1508 		tcp->u_rval = tcp->u_error = 0;
   1509 		if(tcp->u_arg[0] == 0)
   1510 			return 0;
   1511 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1512 		return RVAL_NONE | RVAL_STR;
   1513 	}
   1514 	return 0;
   1515 #elif defined(CRISV10) || defined(CRISV32)
   1516 	struct sigcontext sc;
   1517 
   1518 	if (entering(tcp)) {
   1519 		long regs[PT_MAX+1];
   1520 
   1521 		tcp->u_arg[0] = 0;
   1522 
   1523 		if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
   1524 			perror("sigreturn: PTRACE_GETREGS");
   1525 			return 0;
   1526 		}
   1527 		if (umove(tcp, regs[PT_USP], &sc) < 0)
   1528 			return 0;
   1529 		tcp->u_arg[0] = 1;
   1530 		tcp->u_arg[1] = sc.oldmask;
   1531 	} else {
   1532 		sigset_t sigm;
   1533 		long_to_sigset(tcp->u_arg[1], &sigm);
   1534 		tcp->u_rval = tcp->u_error = 0;
   1535 
   1536 		if (tcp->u_arg[0] == 0)
   1537 			return 0;
   1538 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1539 		return RVAL_NONE | RVAL_STR;
   1540 	}
   1541 	return 0;
   1542 #elif defined(TILE)
   1543 	struct ucontext uc;
   1544 	long sp;
   1545 
   1546 	/* offset of ucontext in the kernel's sigframe structure */
   1547 #	define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo)
   1548 
   1549 	if (entering(tcp)) {
   1550 		tcp->u_arg[0] = 0;
   1551 		if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0)
   1552 			return 0;
   1553 		if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0)
   1554 			return 0;
   1555 		tcp->u_arg[0] = 1;
   1556 		memcpy(tcp->u_arg + 1, &uc.uc_sigmask, sizeof(uc.uc_sigmask));
   1557 	}
   1558 	else {
   1559 		sigset_t sigm;
   1560 
   1561 		memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm));
   1562 		tcp->u_rval = tcp->u_error = 0;
   1563 		if (tcp->u_arg[0] == 0)
   1564 			return 0;
   1565 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1566 		return RVAL_NONE | RVAL_STR;
   1567 	}
   1568 	return 0;
   1569 #elif defined(MICROBLAZE)
   1570 	struct sigcontext sc;
   1571 
   1572 	/* TODO: Verify that this is correct...  */
   1573 	if (entering(tcp)) {
   1574 		long sp;
   1575 
   1576 		tcp->u_arg[0] = 0;
   1577 
   1578 		/* Read r1, the stack pointer.  */
   1579 		if (upeek(tcp, 1 * 4, &sp) < 0)
   1580 			return 0;
   1581 		if (umove(tcp, sp, &sc) < 0)
   1582 			return 0;
   1583 		tcp->u_arg[0] = 1;
   1584 		tcp->u_arg[1] = sc.oldmask;
   1585 	} else {
   1586 		sigset_t sigm;
   1587 		long_to_sigset(tcp->u_arg[1], &sigm);
   1588 		tcp->u_rval = tcp->u_error = 0;
   1589 		if (tcp->u_arg[0] == 0)
   1590 			return 0;
   1591 		tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
   1592 		return RVAL_NONE | RVAL_STR;
   1593 	}
   1594 	return 0;
   1595 #else
   1596 #warning No sys_sigreturn() for this architecture
   1597 #warning         (no problem, just a reminder :-)
   1598 	return 0;
   1599 #endif
   1600 }
   1601 
   1602 int
   1603 sys_siggetmask(tcp)
   1604 struct tcb *tcp;
   1605 {
   1606 	if (exiting(tcp)) {
   1607 		sigset_t sigm;
   1608 		long_to_sigset(tcp->u_rval, &sigm);
   1609 		tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
   1610 	}
   1611 	return RVAL_HEX | RVAL_STR;
   1612 }
   1613 
   1614 int
   1615 sys_sigsuspend(struct tcb *tcp)
   1616 {
   1617 	if (entering(tcp)) {
   1618 		sigset_t sigm;
   1619 		long_to_sigset(tcp->u_arg[2], &sigm);
   1620 		printsigmask(&sigm, 0);
   1621 	}
   1622 	return 0;
   1623 }
   1624 
   1625 #endif /* LINUX */
   1626 
   1627 #if defined(SVR4) || defined(FREEBSD)
   1628 
   1629 int
   1630 sys_sigsuspend(tcp)
   1631 struct tcb *tcp;
   1632 {
   1633 	sigset_t sigset;
   1634 
   1635 	if (entering(tcp)) {
   1636 		if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
   1637 			tprintf("[?]");
   1638 		else
   1639 			printsigmask(&sigset, 0);
   1640 	}
   1641 	return 0;
   1642 }
   1643 #ifndef FREEBSD
   1644 static const struct xlat ucontext_flags[] = {
   1645 	{ UC_SIGMASK,	"UC_SIGMASK"	},
   1646 	{ UC_STACK,	"UC_STACK"	},
   1647 	{ UC_CPU,	"UC_CPU"	},
   1648 #ifdef UC_FPU
   1649 	{ UC_FPU,	"UC_FPU"	},
   1650 #endif
   1651 #ifdef UC_INTR
   1652 	{ UC_INTR,	"UC_INTR"	},
   1653 #endif
   1654 	{ 0,		NULL		},
   1655 };
   1656 #endif /* !FREEBSD */
   1657 #endif /* SVR4 || FREEBSD */
   1658 
   1659 #if defined SVR4 || defined LINUX || defined FREEBSD
   1660 #if defined LINUX && !defined SS_ONSTACK
   1661 #define SS_ONSTACK      1
   1662 #define SS_DISABLE      2
   1663 #if __GLIBC_MINOR__ == 0
   1664 typedef struct
   1665 {
   1666 	__ptr_t ss_sp;
   1667 	int ss_flags;
   1668 	size_t ss_size;
   1669 } stack_t;
   1670 #endif
   1671 #endif
   1672 #ifdef FREEBSD
   1673 #define stack_t struct sigaltstack
   1674 #endif
   1675 
   1676 static const struct xlat sigaltstack_flags[] = {
   1677 	{ SS_ONSTACK,	"SS_ONSTACK"	},
   1678 	{ SS_DISABLE,	"SS_DISABLE"	},
   1679 	{ 0,		NULL		},
   1680 };
   1681 #endif
   1682 
   1683 #ifdef SVR4
   1684 static void
   1685 printcontext(tcp, ucp)
   1686 struct tcb *tcp;
   1687 ucontext_t *ucp;
   1688 {
   1689 	tprintf("{");
   1690 	if (!abbrev(tcp)) {
   1691 		tprintf("uc_flags=");
   1692 		printflags(ucontext_flags, ucp->uc_flags, "UC_???");
   1693 		tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
   1694 	}
   1695 	tprintf("uc_sigmask=");
   1696 	printsigmask(&ucp->uc_sigmask, 0);
   1697 	if (!abbrev(tcp)) {
   1698 		tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
   1699 			(unsigned long) ucp->uc_stack.ss_sp,
   1700 			ucp->uc_stack.ss_size);
   1701 		printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
   1702 		tprintf("}");
   1703 	}
   1704 	tprintf(", ...}");
   1705 }
   1706 
   1707 int
   1708 sys_getcontext(tcp)
   1709 struct tcb *tcp;
   1710 {
   1711 	ucontext_t uc;
   1712 
   1713 	if (exiting(tcp)) {
   1714 		if (tcp->u_error)
   1715 			tprintf("%#lx", tcp->u_arg[0]);
   1716 		else if (!tcp->u_arg[0])
   1717 			tprintf("NULL");
   1718 		else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
   1719 			tprintf("{...}");
   1720 		else
   1721 			printcontext(tcp, &uc);
   1722 	}
   1723 	return 0;
   1724 }
   1725 
   1726 int
   1727 sys_setcontext(tcp)
   1728 struct tcb *tcp;
   1729 {
   1730 	ucontext_t uc;
   1731 
   1732 	if (entering(tcp)) {
   1733 		if (!tcp->u_arg[0])
   1734 			tprintf("NULL");
   1735 		else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
   1736 			tprintf("{...}");
   1737 		else
   1738 			printcontext(tcp, &uc);
   1739 	}
   1740 	else {
   1741 		tcp->u_rval = tcp->u_error = 0;
   1742 		if (tcp->u_arg[0] == 0)
   1743 			return 0;
   1744 		return RVAL_NONE;
   1745 	}
   1746 	return 0;
   1747 }
   1748 
   1749 #endif /* SVR4 */
   1750 
   1751 #if defined(LINUX) || defined(FREEBSD)
   1752 
   1753 static int
   1754 print_stack_t(tcp, addr)
   1755 struct tcb *tcp;
   1756 unsigned long addr;
   1757 {
   1758 	stack_t ss;
   1759 	if (umove(tcp, addr, &ss) < 0)
   1760 		return -1;
   1761 	tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
   1762 	printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
   1763 	tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
   1764 	return 0;
   1765 }
   1766 
   1767 int
   1768 sys_sigaltstack(tcp)
   1769 	struct tcb *tcp;
   1770 {
   1771 	if (entering(tcp)) {
   1772 		if (tcp->u_arg[0] == 0)
   1773 			tprintf("NULL");
   1774 		else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
   1775 			return -1;
   1776 	}
   1777 	else {
   1778 		tprintf(", ");
   1779 		if (tcp->u_arg[1] == 0)
   1780 			tprintf("NULL");
   1781 		else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
   1782 			return -1;
   1783 	}
   1784 	return 0;
   1785 }
   1786 #endif
   1787 
   1788 #ifdef HAVE_SIGACTION
   1789 
   1790 int
   1791 sys_sigprocmask(tcp)
   1792 struct tcb *tcp;
   1793 {
   1794 #ifdef ALPHA
   1795 	if (entering(tcp)) {
   1796 		printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
   1797 		tprintf(", ");
   1798 		printsigmask(tcp->u_arg[1], 0);
   1799 	}
   1800 	else if (!syserror(tcp)) {
   1801 		tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
   1802 		return RVAL_HEX | RVAL_STR;
   1803 	}
   1804 #else /* !ALPHA */
   1805 	if (entering(tcp)) {
   1806 #ifdef SVR4
   1807 		if (tcp->u_arg[0] == 0)
   1808 			tprintf("0");
   1809 		else
   1810 #endif /* SVR4 */
   1811 		printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
   1812 		tprintf(", ");
   1813 		print_sigset(tcp, tcp->u_arg[1], 0);
   1814 		tprintf(", ");
   1815 	}
   1816 	else {
   1817 		if (!tcp->u_arg[2])
   1818 			tprintf("NULL");
   1819 		else if (syserror(tcp))
   1820 			tprintf("%#lx", tcp->u_arg[2]);
   1821 		else
   1822 			print_sigset(tcp, tcp->u_arg[2], 0);
   1823 	}
   1824 #endif /* !ALPHA */
   1825 	return 0;
   1826 }
   1827 
   1828 #endif /* HAVE_SIGACTION */
   1829 
   1830 int
   1831 sys_kill(tcp)
   1832 struct tcb *tcp;
   1833 {
   1834 	if (entering(tcp)) {
   1835 		/*
   1836 		 * Sign-extend a 32-bit value when that's what it is.
   1837 		 */
   1838 		long pid = tcp->u_arg[0];
   1839 		if (personality_wordsize[current_personality] < sizeof pid)
   1840 			pid = (long) (int) pid;
   1841 		tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
   1842 	}
   1843 	return 0;
   1844 }
   1845 
   1846 #if defined(FREEBSD) || defined(SUNOS4)
   1847 int
   1848 sys_killpg(tcp)
   1849 struct tcb *tcp;
   1850 {
   1851 	return sys_kill(tcp);
   1852 }
   1853 #endif /* FREEBSD || SUNOS4 */
   1854 
   1855 #ifdef LINUX
   1856 int
   1857 sys_tgkill(tcp)
   1858 	struct tcb *tcp;
   1859 {
   1860 	if (entering(tcp)) {
   1861 		tprintf("%ld, %ld, %s",
   1862 			tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
   1863 	}
   1864 	return 0;
   1865 }
   1866 #endif
   1867 
   1868 int
   1869 sys_sigpending(tcp)
   1870 struct tcb *tcp;
   1871 {
   1872 	sigset_t sigset;
   1873 
   1874 	if (exiting(tcp)) {
   1875 		if (syserror(tcp))
   1876 			tprintf("%#lx", tcp->u_arg[0]);
   1877 		else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
   1878 			tprintf("[?]");
   1879 		else
   1880 			printsigmask(&sigset, 0);
   1881 	}
   1882 	return 0;
   1883 }
   1884 
   1885 #ifdef SVR4
   1886 int sys_sigwait(tcp)
   1887 struct tcb *tcp;
   1888 {
   1889 	sigset_t sigset;
   1890 
   1891 	if (entering(tcp)) {
   1892 		if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
   1893 			tprintf("[?]");
   1894 		else
   1895 			printsigmask(&sigset, 0);
   1896 	}
   1897 	else {
   1898 		if (!syserror(tcp)) {
   1899 			tcp->auxstr = signalent[tcp->u_rval];
   1900 			return RVAL_DECIMAL | RVAL_STR;
   1901 		}
   1902 	}
   1903 	return 0;
   1904 }
   1905 #endif /* SVR4 */
   1906 
   1907 #ifdef LINUX
   1908 
   1909 	int
   1910 sys_rt_sigprocmask(tcp)
   1911 	struct tcb *tcp;
   1912 {
   1913 	sigset_t sigset;
   1914 
   1915 	/* Note: arg[3] is the length of the sigset. */
   1916 	if (entering(tcp)) {
   1917 		printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
   1918 		tprintf(", ");
   1919 		if (!tcp->u_arg[1])
   1920 			tprintf("NULL, ");
   1921 		else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
   1922 			tprintf("%#lx, ", tcp->u_arg[1]);
   1923 		else {
   1924 			printsigmask(&sigset, 1);
   1925 			tprintf(", ");
   1926 		}
   1927 	}
   1928 	else {
   1929 		if (!tcp->u_arg[2])
   1930 
   1931 			tprintf("NULL");
   1932 		else if (syserror(tcp))
   1933 			tprintf("%#lx", tcp->u_arg[2]);
   1934 		else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
   1935 			tprintf("[?]");
   1936 		else
   1937 			printsigmask(&sigset, 1);
   1938 		tprintf(", %lu", tcp->u_arg[3]);
   1939 	}
   1940 	return 0;
   1941 }
   1942 
   1943 
   1944 /* Structure describing the action to be taken when a signal arrives.  */
   1945 struct new_sigaction
   1946 {
   1947 	__sighandler_t __sa_handler;
   1948 	unsigned long sa_flags;
   1949 	void (*sa_restorer) (void);
   1950 	/* Kernel treats sa_mask as an array of longs. */
   1951 	unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1];
   1952 };
   1953 /* Same for i386-on-x86_64 and similar cases */
   1954 struct new_sigaction32
   1955 {
   1956 	uint32_t __sa_handler;
   1957 	uint32_t sa_flags;
   1958 	uint32_t sa_restorer;
   1959 	uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)];
   1960 };
   1961 
   1962 
   1963 int
   1964 sys_rt_sigaction(struct tcb *tcp)
   1965 {
   1966 	struct new_sigaction sa;
   1967 	sigset_t sigset;
   1968 	long addr;
   1969 	int r;
   1970 
   1971 	if (entering(tcp)) {
   1972 		printsignal(tcp->u_arg[0]);
   1973 		tprintf(", ");
   1974 		addr = tcp->u_arg[1];
   1975 	} else
   1976 		addr = tcp->u_arg[2];
   1977 
   1978 	if (addr == 0) {
   1979 		tprintf("NULL");
   1980 		goto after_sa;
   1981 	}
   1982 	if (!verbose(tcp)) {
   1983 		tprintf("%#lx", addr);
   1984 		goto after_sa;
   1985 	}
   1986 #if SUPPORTED_PERSONALITIES > 1
   1987 	if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
   1988 	 && personality_wordsize[current_personality] == 4
   1989 	) {
   1990 		struct new_sigaction32 sa32;
   1991 		r = umove(tcp, addr, &sa32);
   1992 		if (r >= 0) {
   1993 			memset(&sa, 0, sizeof(sa));
   1994 			sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler;
   1995 			sa.sa_flags     = sa32.sa_flags;
   1996 			sa.sa_restorer  = (void*)(unsigned long)sa32.sa_restorer;
   1997 			/* Kernel treats sa_mask as an array of longs.
   1998 			 * For 32-bit process, "long" is uint32_t, thus, for example,
   1999 			 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1].
   2000 			 * But for (64-bit) kernel, 32th bit in sa_mask is
   2001 			 * 32th bit in 0th (64-bit) long!
   2002 			 * For little-endian, it's the same.
   2003 			 * For big-endian, we swap 32-bit words.
   2004 			 */
   2005 			sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32);
   2006 		}
   2007 	} else
   2008 #endif
   2009 	{
   2010 		r = umove(tcp, addr, &sa);
   2011 	}
   2012 	if (r < 0) {
   2013 		tprintf("{...}");
   2014 		goto after_sa;
   2015 	}
   2016 	/* Architectures using function pointers, like
   2017 	 * hppa, may need to manipulate the function pointer
   2018 	 * to compute the result of a comparison. However,
   2019 	 * the SA_HANDLER function pointer exists only in
   2020 	 * the address space of the traced process, and can't
   2021 	 * be manipulated by strace. In order to prevent the
   2022 	 * compiler from generating code to manipulate
   2023 	 * SA_HANDLER we cast the function pointers to long. */
   2024 	if ((long)sa.__sa_handler == (long)SIG_ERR)
   2025 		tprintf("{SIG_ERR, ");
   2026 	else if ((long)sa.__sa_handler == (long)SIG_DFL)
   2027 		tprintf("{SIG_DFL, ");
   2028 	else if ((long)sa.__sa_handler == (long)SIG_IGN)
   2029 		tprintf("{SIG_IGN, ");
   2030 	else
   2031 		tprintf("{%#lx, ", (long) sa.__sa_handler);
   2032 	/* Questionable code below.
   2033 	 * Kernel won't handle sys_rt_sigaction
   2034 	 * with wrong sigset size (just returns EINVAL)
   2035 	 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here,
   2036 	 * and we always use smaller memcpy. */
   2037 	sigemptyset(&sigset);
   2038 #ifdef LINUXSPARC
   2039 	if (tcp->u_arg[4] <= sizeof(sigset))
   2040 		memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]);
   2041 #else
   2042 	if (tcp->u_arg[3] <= sizeof(sigset))
   2043 		memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
   2044 #endif
   2045 	else
   2046 		memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
   2047 	printsigmask(&sigset, 1);
   2048 	tprintf(", ");
   2049 	printflags(sigact_flags, sa.sa_flags, "SA_???");
   2050 #ifdef SA_RESTORER
   2051 	if (sa.sa_flags & SA_RESTORER)
   2052 		tprintf(", %p", sa.sa_restorer);
   2053 #endif
   2054 	tprintf("}");
   2055 
   2056  after_sa:
   2057 	if (entering(tcp))
   2058 		tprintf(", ");
   2059 	else
   2060 #ifdef LINUXSPARC
   2061 		tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
   2062 #elif defined(ALPHA)
   2063 		tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]);
   2064 #else
   2065 		tprintf(", %lu", tcp->u_arg[3]);
   2066 #endif
   2067 	return 0;
   2068 }
   2069 
   2070 int
   2071 sys_rt_sigpending(struct tcb *tcp)
   2072 {
   2073 	sigset_t sigset;
   2074 
   2075 	if (exiting(tcp)) {
   2076 		if (syserror(tcp))
   2077 			tprintf("%#lx", tcp->u_arg[0]);
   2078 		else if (copy_sigset_len(tcp, tcp->u_arg[0],
   2079 					 &sigset, tcp->u_arg[1]) < 0)
   2080 			tprintf("[?]");
   2081 		else
   2082 			printsigmask(&sigset, 1);
   2083 	}
   2084 	return 0;
   2085 }
   2086 
   2087 int
   2088 sys_rt_sigsuspend(struct tcb *tcp)
   2089 {
   2090 	if (entering(tcp)) {
   2091 		sigset_t sigm;
   2092 		if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
   2093 			tprintf("[?]");
   2094 		else
   2095 			printsigmask(&sigm, 1);
   2096 	}
   2097 	return 0;
   2098 }
   2099 
   2100 int
   2101 sys_rt_sigqueueinfo(struct tcb *tcp)
   2102 {
   2103 	if (entering(tcp)) {
   2104 		siginfo_t si;
   2105 		tprintf("%lu, ", tcp->u_arg[0]);
   2106 		printsignal(tcp->u_arg[1]);
   2107 		tprintf(", ");
   2108 		if (umove(tcp, tcp->u_arg[2], &si) < 0)
   2109 			tprintf("%#lx", tcp->u_arg[2]);
   2110 		else
   2111 			printsiginfo(&si, verbose(tcp));
   2112 	}
   2113 	return 0;
   2114 }
   2115 
   2116 int sys_rt_sigtimedwait(struct tcb *tcp)
   2117 {
   2118 	if (entering(tcp)) {
   2119 		sigset_t sigset;
   2120 
   2121 		if (copy_sigset_len(tcp, tcp->u_arg[0],
   2122 				    &sigset, tcp->u_arg[3]) < 0)
   2123 			tprintf("[?]");
   2124 		else
   2125 			printsigmask(&sigset, 1);
   2126 		tprintf(", ");
   2127 		/* This is the only "return" parameter, */
   2128 		if (tcp->u_arg[1] != 0)
   2129 			return 0;
   2130 		/* ... if it's NULL, can decode all on entry */
   2131 		tprintf("NULL, ");
   2132 	}
   2133 	else if (tcp->u_arg[1] != 0) {
   2134 		/* syscall exit, and u_arg[1] wasn't NULL */
   2135 		if (syserror(tcp))
   2136 			tprintf("%#lx, ", tcp->u_arg[1]);
   2137 		else {
   2138 			siginfo_t si;
   2139 			if (umove(tcp, tcp->u_arg[1], &si) < 0)
   2140 				tprintf("%#lx, ", tcp->u_arg[1]);
   2141 			else {
   2142 				printsiginfo(&si, verbose(tcp));
   2143 				tprintf(", ");
   2144 			}
   2145 		}
   2146 	}
   2147 	else {
   2148 		/* syscall exit, and u_arg[1] was NULL */
   2149 		return 0;
   2150 	}
   2151 	print_timespec(tcp, tcp->u_arg[2]);
   2152 	tprintf(", %d", (int) tcp->u_arg[3]);
   2153 	return 0;
   2154 };
   2155 
   2156 int
   2157 sys_restart_syscall(struct tcb *tcp)
   2158 {
   2159 	if (entering(tcp))
   2160 		tprintf("<... resuming interrupted call ...>");
   2161 	return 0;
   2162 }
   2163 
   2164 static int
   2165 do_signalfd(struct tcb *tcp, int flags_arg)
   2166 {
   2167 	if (entering(tcp)) {
   2168 		printfd(tcp, tcp->u_arg[0]);
   2169 		tprintf(", ");
   2170 		print_sigset(tcp, tcp->u_arg[1], 1);
   2171 		tprintf(", %lu", tcp->u_arg[2]);
   2172 		if (flags_arg >= 0) {
   2173 			tprintf(", ");
   2174 			printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
   2175 		}
   2176 	}
   2177 	return 0;
   2178 }
   2179 
   2180 int
   2181 sys_signalfd(struct tcb *tcp)
   2182 {
   2183 	return do_signalfd(tcp, -1);
   2184 }
   2185 
   2186 int
   2187 sys_signalfd4(struct tcb *tcp)
   2188 {
   2189 	return do_signalfd(tcp, 3);
   2190 }
   2191 #endif /* LINUX */
   2192