xref: /onnv-gate/usr/src/cmd/ptools/psig/psig.c (revision 1914:8a8c5f225b1b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1914Scasper  * Common Development and Distribution License (the "License").
6*1914Scasper  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*1914Scasper  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <stdio.h>
29*1914Scasper #include <stdio_ext.h>
300Sstevel@tonic-gate #include <stdlib.h>
310Sstevel@tonic-gate #include <unistd.h>
320Sstevel@tonic-gate #include <ctype.h>
330Sstevel@tonic-gate #include <fcntl.h>
340Sstevel@tonic-gate #include <string.h>
350Sstevel@tonic-gate #include <signal.h>
360Sstevel@tonic-gate #include <stddef.h>
370Sstevel@tonic-gate #include <sys/types.h>
380Sstevel@tonic-gate #include <sys/stat.h>
390Sstevel@tonic-gate #include <libproc.h>
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /* evil knowledge of libc internals */
420Sstevel@tonic-gate #include "../../../lib/libc/inc/thr_uberdata.h"
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #define	MAX_SYMNAMLEN	1024	/* Recommended max symbol name length */
450Sstevel@tonic-gate 
460Sstevel@tonic-gate static	char	*sigflags(int, int);
470Sstevel@tonic-gate static	int	look(char *);
480Sstevel@tonic-gate static	void	perr(char *);
490Sstevel@tonic-gate static	int	usage(void);
500Sstevel@tonic-gate static	uintptr_t deinterpose(int, void *, psinfo_t *, struct sigaction *);
510Sstevel@tonic-gate 
520Sstevel@tonic-gate static	char	*command;
530Sstevel@tonic-gate static	char	*procname;
540Sstevel@tonic-gate static	int	all_flag = 0;
550Sstevel@tonic-gate static	int	lookuphandlers_flag = 1;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate int
main(int argc,char ** argv)580Sstevel@tonic-gate main(int argc, char **argv)
590Sstevel@tonic-gate {
600Sstevel@tonic-gate 	int rc = 0;
610Sstevel@tonic-gate 	int c;
620Sstevel@tonic-gate 	struct rlimit rlim;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	if ((command = strrchr(argv[0], '/')) != NULL)
650Sstevel@tonic-gate 		command++;
660Sstevel@tonic-gate 	else
670Sstevel@tonic-gate 		command = argv[0];
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "an")) != EOF) {
700Sstevel@tonic-gate 		switch (c) {
710Sstevel@tonic-gate 		case 'a':
720Sstevel@tonic-gate 			all_flag = 1;
730Sstevel@tonic-gate 			break;
740Sstevel@tonic-gate 		case 'n':
750Sstevel@tonic-gate 			lookuphandlers_flag = 0;
760Sstevel@tonic-gate 			break;
770Sstevel@tonic-gate 		default:
780Sstevel@tonic-gate 			return (usage());
790Sstevel@tonic-gate 		}
800Sstevel@tonic-gate 	}
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	if (argc - optind < 1) {
830Sstevel@tonic-gate 		return (usage());
840Sstevel@tonic-gate 	}
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 	/*
870Sstevel@tonic-gate 	 * Make sure we'll have enough file descriptors to handle a target
880Sstevel@tonic-gate 	 * that has many many mappings.
890Sstevel@tonic-gate 	 */
900Sstevel@tonic-gate 	if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
910Sstevel@tonic-gate 		rlim.rlim_cur = rlim.rlim_max;
920Sstevel@tonic-gate 		(void) setrlimit(RLIMIT_NOFILE, &rlim);
93*1914Scasper 		(void) enable_extended_FILE_stdio(-1, -1);
940Sstevel@tonic-gate 	}
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	for (; optind != argc; optind++) {
970Sstevel@tonic-gate 		rc += look(argv[optind]);
980Sstevel@tonic-gate 	}
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	return (rc);
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate static int
usage(void)1040Sstevel@tonic-gate usage(void)
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate 	(void) fprintf(stderr, "usage:\t%s [-n] pid ...\n", command);
1070Sstevel@tonic-gate 	(void) fprintf(stderr, "  (report process signal actions)\n");
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 	return (2);
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate static uintptr_t
uberdata_addr(struct ps_prochandle * Pr,char dmodel)1130Sstevel@tonic-gate uberdata_addr(struct ps_prochandle *Pr, char dmodel)
1140Sstevel@tonic-gate {
1150Sstevel@tonic-gate 	GElf_Sym sym;
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 	if (Plookup_by_name(Pr, "libc.so", "_tdb_bootstrap", &sym) < 0)
1180Sstevel@tonic-gate 		return (NULL);
1190Sstevel@tonic-gate #ifdef _LP64
1200Sstevel@tonic-gate 	if (dmodel != PR_MODEL_NATIVE) {
1210Sstevel@tonic-gate 		caddr32_t uaddr;
1220Sstevel@tonic-gate 		caddr32_t addr;
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 		if (Pread(Pr, &addr, sizeof (addr), sym.st_value)
1250Sstevel@tonic-gate 		    == sizeof (addr) &&
1260Sstevel@tonic-gate 		    addr != 0 &&
1270Sstevel@tonic-gate 		    Pread(Pr, &uaddr, sizeof (uaddr), (uintptr_t)addr)
1280Sstevel@tonic-gate 		    == sizeof (uaddr) &&
1290Sstevel@tonic-gate 		    uaddr != 0)
1300Sstevel@tonic-gate 			return ((uintptr_t)uaddr);
1310Sstevel@tonic-gate 	}
1320Sstevel@tonic-gate #endif
1330Sstevel@tonic-gate 	if (dmodel == PR_MODEL_NATIVE) {
1340Sstevel@tonic-gate 		uintptr_t uaddr;
1350Sstevel@tonic-gate 		uintptr_t addr;
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 		if (Pread(Pr, &addr, sizeof (addr), sym.st_value)
1380Sstevel@tonic-gate 		    == sizeof (addr) &&
1390Sstevel@tonic-gate 		    addr != 0 &&
1400Sstevel@tonic-gate 		    Pread(Pr, &uaddr, sizeof (uaddr), addr)
1410Sstevel@tonic-gate 		    == sizeof (uaddr) &&
1420Sstevel@tonic-gate 		    uaddr != 0)
1430Sstevel@tonic-gate 			return (uaddr);
1440Sstevel@tonic-gate 	}
1450Sstevel@tonic-gate 	if (Plookup_by_name(Pr, "libc.so", "_uberdata", &sym) < 0)
1460Sstevel@tonic-gate 		return (0);
1470Sstevel@tonic-gate 	return (sym.st_value);
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate /*
1510Sstevel@tonic-gate  * Iterator function used to generate the process sigmask
1520Sstevel@tonic-gate  * from the individual lwp sigmasks.
1530Sstevel@tonic-gate  */
1540Sstevel@tonic-gate static int
lwp_iter(void * cd,const lwpstatus_t * lwpstatus)1550Sstevel@tonic-gate lwp_iter(void *cd, const lwpstatus_t *lwpstatus)
1560Sstevel@tonic-gate {
1570Sstevel@tonic-gate 	sigset_t *ssp = cd;
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	ssp->__sigbits[0] &= lwpstatus->pr_lwphold.__sigbits[0];
1600Sstevel@tonic-gate 	ssp->__sigbits[1] &= lwpstatus->pr_lwphold.__sigbits[1];
1610Sstevel@tonic-gate 	ssp->__sigbits[2] &= lwpstatus->pr_lwphold.__sigbits[2];
1620Sstevel@tonic-gate 	ssp->__sigbits[3] &= lwpstatus->pr_lwphold.__sigbits[3];
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	/*
1650Sstevel@tonic-gate 	 * Return non-zero to terminate the iteration
1660Sstevel@tonic-gate 	 * if the sigmask has become all zeros.
1670Sstevel@tonic-gate 	 */
1680Sstevel@tonic-gate 	return ((ssp->__sigbits[0] | ssp->__sigbits[1] |
1690Sstevel@tonic-gate 	    ssp->__sigbits[2] | ssp->__sigbits[3]) == 0);
1700Sstevel@tonic-gate }
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate static int
look(char * arg)1730Sstevel@tonic-gate look(char *arg)
1740Sstevel@tonic-gate {
1750Sstevel@tonic-gate 	char pathname[100];
1760Sstevel@tonic-gate 	struct stat statb;
1770Sstevel@tonic-gate 	int fd = -1;
1780Sstevel@tonic-gate 	int sig, gcode;
1790Sstevel@tonic-gate 	sigset_t holdmask;
1800Sstevel@tonic-gate 	int maxsig;
1810Sstevel@tonic-gate 	struct sigaction *action = NULL;
1820Sstevel@tonic-gate 	psinfo_t psinfo;
1830Sstevel@tonic-gate 	const psinfo_t *psinfop;
1840Sstevel@tonic-gate 	struct ps_prochandle *Pr = NULL;
1850Sstevel@tonic-gate 	uintptr_t uberaddr;
1860Sstevel@tonic-gate 	uintptr_t aharraddr;
1870Sstevel@tonic-gate 	uintptr_t intfnaddr;
1880Sstevel@tonic-gate 	size_t aharrlen;
1890Sstevel@tonic-gate 	void *aharr = NULL;
1900Sstevel@tonic-gate 	int error = 1;
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 	procname = arg;		/* for perr() */
1930Sstevel@tonic-gate 	if ((Pr = proc_arg_grab(arg, PR_ARG_PIDS, PGRAB_RDONLY|PGRAB_FORCE,
1940Sstevel@tonic-gate 	    &gcode)) == NULL || (psinfop = Ppsinfo(Pr)) == NULL) {
1950Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: cannot examine %s: %s\n",
1960Sstevel@tonic-gate 		    command, arg, Pgrab_error(gcode));
1970Sstevel@tonic-gate 		goto look_error;
1980Sstevel@tonic-gate 	}
1990Sstevel@tonic-gate 	(void) memcpy(&psinfo, psinfop, sizeof (psinfo_t));
2000Sstevel@tonic-gate 	proc_unctrl_psinfo(&psinfo);
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate 	(void) sprintf(pathname, "/proc/%d/sigact", (int)psinfo.pr_pid);
2030Sstevel@tonic-gate 	if ((fd = open(pathname, O_RDONLY)) < 0) {
2040Sstevel@tonic-gate 		perr("open sigact");
2050Sstevel@tonic-gate 		goto look_error;
2060Sstevel@tonic-gate 	}
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate 	if (fstat(fd, &statb) != 0) {
2090Sstevel@tonic-gate 		perr("fstat sigact");
2100Sstevel@tonic-gate 		goto look_error;
2110Sstevel@tonic-gate 	}
2120Sstevel@tonic-gate 	maxsig = statb.st_size / sizeof (struct sigaction);
2130Sstevel@tonic-gate 	action = malloc(maxsig * sizeof (struct sigaction));
2140Sstevel@tonic-gate 	if (action == NULL) {
2150Sstevel@tonic-gate 		(void) fprintf(stderr,
2160Sstevel@tonic-gate 		"%s: cannot malloc() space for %d sigaction structures\n",
2170Sstevel@tonic-gate 			command, maxsig);
2180Sstevel@tonic-gate 		goto look_error;
2190Sstevel@tonic-gate 	}
2200Sstevel@tonic-gate 	if (read(fd, (char *)action, maxsig * sizeof (struct sigaction)) !=
2210Sstevel@tonic-gate 	    maxsig * sizeof (struct sigaction)) {
2220Sstevel@tonic-gate 		perr("read sigact");
2230Sstevel@tonic-gate 		goto look_error;
2240Sstevel@tonic-gate 	}
2250Sstevel@tonic-gate 	(void) close(fd);
2260Sstevel@tonic-gate 	fd = -1;
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 	(void) printf("%d:\t%.70s\n", (int)psinfo.pr_pid, psinfo.pr_psargs);
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate 	(void) sigfillset(&holdmask);
2310Sstevel@tonic-gate 	(void) Plwp_iter(Pr, lwp_iter, &holdmask);
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 	if ((uberaddr = uberdata_addr(Pr, psinfo.pr_dmodel)) == 0) {
2340Sstevel@tonic-gate 		aharraddr = 0;
2350Sstevel@tonic-gate 		aharrlen = 0;
2360Sstevel@tonic-gate 		intfnaddr = 0;
2370Sstevel@tonic-gate 	} else {
2380Sstevel@tonic-gate #ifdef _LP64
2390Sstevel@tonic-gate 		if (psinfo.pr_dmodel != PR_MODEL_NATIVE) {
2400Sstevel@tonic-gate 			caddr32_t addr;
2410Sstevel@tonic-gate 			aharraddr = uberaddr +
2420Sstevel@tonic-gate 				offsetof(uberdata32_t, siguaction);
2430Sstevel@tonic-gate 			aharrlen = sizeof (siguaction32_t) * NSIG;
2440Sstevel@tonic-gate 			(void) Pread(Pr, &addr, sizeof (addr),
2450Sstevel@tonic-gate 			    uberaddr + offsetof(uberdata32_t, sigacthandler));
2460Sstevel@tonic-gate 			intfnaddr = (uintptr_t)addr;
2470Sstevel@tonic-gate 		} else
2480Sstevel@tonic-gate #endif
2490Sstevel@tonic-gate 		{
2500Sstevel@tonic-gate 			aharraddr = uberaddr +
2510Sstevel@tonic-gate 				offsetof(uberdata_t, siguaction);
2520Sstevel@tonic-gate 			aharrlen = sizeof (siguaction_t) * NSIG;
2530Sstevel@tonic-gate 			(void) Pread(Pr, &intfnaddr, sizeof (intfnaddr),
2540Sstevel@tonic-gate 			    uberaddr + offsetof(uberdata_t, sigacthandler));
2550Sstevel@tonic-gate 		}
2560Sstevel@tonic-gate 	}
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate 	if (aharraddr) {
2590Sstevel@tonic-gate 		aharr = malloc(aharrlen);
2600Sstevel@tonic-gate 		if (aharr == NULL) {
2610Sstevel@tonic-gate 			(void) fprintf(stderr,
2620Sstevel@tonic-gate 			"%s: cannot malloc() space for actual handler array\n",
2630Sstevel@tonic-gate 			    command);
2640Sstevel@tonic-gate 			goto look_error;
2650Sstevel@tonic-gate 		}
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 		if (Pread(Pr, aharr, aharrlen, aharraddr) != aharrlen) {
2680Sstevel@tonic-gate 			(void) fprintf(stderr,
2690Sstevel@tonic-gate 			    "%s: signal handler data at %p cannot be read.\n",
2700Sstevel@tonic-gate 			    command, (void *)aharraddr);
2710Sstevel@tonic-gate 			free(aharr);
2720Sstevel@tonic-gate 			aharr = NULL;
2730Sstevel@tonic-gate 		}
2740Sstevel@tonic-gate 	}
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate 	for (sig = 1; sig <= maxsig; sig++) {
2770Sstevel@tonic-gate 		struct sigaction *sp = &action[sig - 1];
2780Sstevel@tonic-gate 		int caught = 0;
2790Sstevel@tonic-gate 		char buf[SIG2STR_MAX];
2800Sstevel@tonic-gate 		char *s;
2810Sstevel@tonic-gate 
2820Sstevel@tonic-gate 		/* proc_signame() returns "SIG..."; skip the "SIG" part */
2830Sstevel@tonic-gate 		(void) printf("%s\t", proc_signame(sig, buf, sizeof (buf)) + 3);
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate 		if (prismember(&holdmask, sig))
2860Sstevel@tonic-gate 			(void) printf("blocked,");
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 		if (sp->sa_handler == SIG_DFL)
2890Sstevel@tonic-gate 			(void) printf("default");
2900Sstevel@tonic-gate 		else if (sp->sa_handler == SIG_IGN)
2910Sstevel@tonic-gate 			(void) printf("ignored");
2920Sstevel@tonic-gate 		else
2930Sstevel@tonic-gate 			caught = 1;
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 		if (caught || all_flag) {
2960Sstevel@tonic-gate 			uintptr_t haddr;
2970Sstevel@tonic-gate 			GElf_Sym hsym;
2980Sstevel@tonic-gate 			char hname[MAX_SYMNAMLEN];
2990Sstevel@tonic-gate 			char buf[PRSIGBUFSZ];
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 			haddr = (uintptr_t)sp->sa_handler;
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate 			if (aharr && intfnaddr && haddr == intfnaddr)
3040Sstevel@tonic-gate 				haddr = deinterpose(sig, aharr, &psinfo, sp);
3050Sstevel@tonic-gate 
3060Sstevel@tonic-gate 			if (haddr == (uintptr_t)SIG_DFL) {
3070Sstevel@tonic-gate 				if (caught)
3080Sstevel@tonic-gate 					(void) printf("default");
3090Sstevel@tonic-gate 				caught = 0;
3100Sstevel@tonic-gate 			} else if (haddr == (uintptr_t)SIG_IGN) {
3110Sstevel@tonic-gate 				if (caught)
3120Sstevel@tonic-gate 					(void) printf("ignored");
3130Sstevel@tonic-gate 				caught = 0;
3140Sstevel@tonic-gate 			} else {
3150Sstevel@tonic-gate 				if (caught)
3160Sstevel@tonic-gate 					(void) printf("caught");
3170Sstevel@tonic-gate 			}
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 			if (caught || all_flag) {
3200Sstevel@tonic-gate 				if (lookuphandlers_flag && haddr > 1 &&
3210Sstevel@tonic-gate 				    Plookup_by_addr(Pr, haddr, hname,
3220Sstevel@tonic-gate 				    sizeof (hname), &hsym) == 0)
3230Sstevel@tonic-gate 					(void) printf("\t%-8s", hname);
3240Sstevel@tonic-gate 				else
3250Sstevel@tonic-gate 					(void) printf("\t0x%-8lx",
3260Sstevel@tonic-gate 						(ulong_t)haddr);
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 				s = sigflags(sig, sp->sa_flags);
3290Sstevel@tonic-gate 				(void) printf("%s", (*s != '\0')? s : "\t0");
3300Sstevel@tonic-gate 				(void) proc_sigset2str(&sp->sa_mask, ",", 1,
3310Sstevel@tonic-gate 				    buf, sizeof (buf));
3320Sstevel@tonic-gate 				if (buf[0] != '\0')
3330Sstevel@tonic-gate 					(void) printf("\t%s", buf);
3340Sstevel@tonic-gate 			}
3350Sstevel@tonic-gate 		} else if (sig == SIGCLD) {
3360Sstevel@tonic-gate 			s = sigflags(sig,
3370Sstevel@tonic-gate 				sp->sa_flags & (SA_NOCLDWAIT|SA_NOCLDSTOP));
3380Sstevel@tonic-gate 			if (*s != '\0')
3390Sstevel@tonic-gate 				(void) printf("\t\t%s", s);
3400Sstevel@tonic-gate 		}
3410Sstevel@tonic-gate 		(void) printf("\n");
3420Sstevel@tonic-gate 	}
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate 	error = 0;
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate look_error:
3470Sstevel@tonic-gate 	if (fd >= 0)
3480Sstevel@tonic-gate 		(void) close(fd);
3490Sstevel@tonic-gate 	if (aharr)
3500Sstevel@tonic-gate 		free(aharr);
3510Sstevel@tonic-gate 	if (action)
3520Sstevel@tonic-gate 		free(action);
3530Sstevel@tonic-gate 	if (Pr)
3540Sstevel@tonic-gate 		Prelease(Pr, 0);
3550Sstevel@tonic-gate 	return (error);
3560Sstevel@tonic-gate }
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate static void
perr(char * s)3590Sstevel@tonic-gate perr(char *s)
3600Sstevel@tonic-gate {
3610Sstevel@tonic-gate 	if (s)
3620Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: ", procname);
3630Sstevel@tonic-gate 	else
3640Sstevel@tonic-gate 		s = procname;
3650Sstevel@tonic-gate 	perror(s);
3660Sstevel@tonic-gate }
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate static char *
sigflags(int sig,int flags)3690Sstevel@tonic-gate sigflags(int sig, int flags)
3700Sstevel@tonic-gate {
3710Sstevel@tonic-gate 	static char code_buf[100];
3720Sstevel@tonic-gate 	char *str = code_buf;
3730Sstevel@tonic-gate 	int flagmask =
3740Sstevel@tonic-gate 		(SA_ONSTACK|SA_RESETHAND|SA_RESTART|SA_SIGINFO|SA_NODEFER);
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate 	if (sig == SIGCLD)
3770Sstevel@tonic-gate 		flagmask |= (SA_NOCLDSTOP|SA_NOCLDWAIT);
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 	*str = '\0';
3800Sstevel@tonic-gate 	if (flags & ~flagmask)
3810Sstevel@tonic-gate 		(void) sprintf(str, ",0x%x,", flags & ~flagmask);
3820Sstevel@tonic-gate 	else if (flags == 0)
3830Sstevel@tonic-gate 		return (str);
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate 	if (flags & SA_RESTART)
3860Sstevel@tonic-gate 		(void) strcat(str, ",RESTART");
3870Sstevel@tonic-gate 	if (flags & SA_RESETHAND)
3880Sstevel@tonic-gate 		(void) strcat(str, ",RESETHAND");
3890Sstevel@tonic-gate 	if (flags & SA_ONSTACK)
3900Sstevel@tonic-gate 		(void) strcat(str, ",ONSTACK");
3910Sstevel@tonic-gate 	if (flags & SA_SIGINFO)
3920Sstevel@tonic-gate 		(void) strcat(str, ",SIGINFO");
3930Sstevel@tonic-gate 	if (flags & SA_NODEFER)
3940Sstevel@tonic-gate 		(void) strcat(str, ",NODEFER");
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate 	if (sig == SIGCLD) {
3970Sstevel@tonic-gate 		if (flags & SA_NOCLDWAIT)
3980Sstevel@tonic-gate 			(void) strcat(str, ",NOCLDWAIT");
3990Sstevel@tonic-gate 		if (flags & SA_NOCLDSTOP)
4000Sstevel@tonic-gate 			(void) strcat(str, ",NOCLDSTOP");
4010Sstevel@tonic-gate 	}
4020Sstevel@tonic-gate 
4030Sstevel@tonic-gate 	*str = '\t';
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate 	return (str);
4060Sstevel@tonic-gate }
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate /*ARGSUSED2*/
4090Sstevel@tonic-gate static uintptr_t
deinterpose(int sig,void * aharr,psinfo_t * psinfo,struct sigaction * sp)4100Sstevel@tonic-gate deinterpose(int sig, void *aharr, psinfo_t *psinfo, struct sigaction *sp)
4110Sstevel@tonic-gate {
4120Sstevel@tonic-gate 	if (sp->sa_handler == SIG_DFL || sp->sa_handler == SIG_IGN)
4130Sstevel@tonic-gate 		return ((uintptr_t)sp->sa_handler);
4140Sstevel@tonic-gate #ifdef _LP64
4150Sstevel@tonic-gate 	if (psinfo->pr_dmodel != PR_MODEL_NATIVE) {
4160Sstevel@tonic-gate 		struct sigaction32 *sa32 = (struct sigaction32 *)
4170Sstevel@tonic-gate 			((uintptr_t)aharr + sig * sizeof (siguaction32_t) +
4180Sstevel@tonic-gate 			offsetof(siguaction32_t, sig_uaction));
4190Sstevel@tonic-gate 
4200Sstevel@tonic-gate 		sp->sa_flags = sa32->sa_flags;
4210Sstevel@tonic-gate 		sp->sa_handler = (void (*)())(uintptr_t)sa32->sa_handler;
4220Sstevel@tonic-gate 		(void) memcpy(&sp->sa_mask, &sa32->sa_mask,
4230Sstevel@tonic-gate 			sizeof (sp->sa_mask));
4240Sstevel@tonic-gate 	} else
4250Sstevel@tonic-gate #endif
4260Sstevel@tonic-gate 	{
4270Sstevel@tonic-gate 		struct sigaction *sa = (struct sigaction *)
4280Sstevel@tonic-gate 			((uintptr_t)aharr + sig * sizeof (siguaction_t) +
4290Sstevel@tonic-gate 			offsetof(siguaction_t, sig_uaction));
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate 		sp->sa_flags = sa->sa_flags;
4320Sstevel@tonic-gate 		sp->sa_handler = sa->sa_handler;
4330Sstevel@tonic-gate 		sp->sa_mask = sa->sa_mask;
4340Sstevel@tonic-gate 	}
4350Sstevel@tonic-gate 	return ((uintptr_t)sp->sa_handler);
4360Sstevel@tonic-gate }
437