1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #define	__EXTENSIONS__
31*0Sstevel@tonic-gate #include <string.h>
32*0Sstevel@tonic-gate #undef  __EXTENSIONS__
33*0Sstevel@tonic-gate #include <signal.h>
34*0Sstevel@tonic-gate #include <alloca.h>
35*0Sstevel@tonic-gate #include <errno.h>
36*0Sstevel@tonic-gate #include "libproc.h"
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate static const char *
39*0Sstevel@tonic-gate rawfltname(int flt)
40*0Sstevel@tonic-gate {
41*0Sstevel@tonic-gate 	const char *name;
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate 	switch (flt) {
44*0Sstevel@tonic-gate 	case FLTILL:	name = "FLTILL";	break;
45*0Sstevel@tonic-gate 	case FLTPRIV:	name = "FLTPRIV";	break;
46*0Sstevel@tonic-gate 	case FLTBPT:	name = "FLTBPT";	break;
47*0Sstevel@tonic-gate 	case FLTTRACE:	name = "FLTTRACE";	break;
48*0Sstevel@tonic-gate 	case FLTACCESS:	name = "FLTACCESS";	break;
49*0Sstevel@tonic-gate 	case FLTBOUNDS:	name = "FLTBOUNDS";	break;
50*0Sstevel@tonic-gate 	case FLTIOVF:	name = "FLTIOVF";	break;
51*0Sstevel@tonic-gate 	case FLTIZDIV:	name = "FLTIZDIV";	break;
52*0Sstevel@tonic-gate 	case FLTFPE:	name = "FLTFPE";	break;
53*0Sstevel@tonic-gate 	case FLTSTACK:	name = "FLTSTACK";	break;
54*0Sstevel@tonic-gate 	case FLTPAGE:	name = "FLTPAGE";	break;
55*0Sstevel@tonic-gate 	case FLTWATCH:	name = "FLTWATCH";	break;
56*0Sstevel@tonic-gate 	case FLTCPCOVF:	name = "FLTCPCOVF";	break;
57*0Sstevel@tonic-gate 	default:	name = NULL;		break;
58*0Sstevel@tonic-gate 	}
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate 	return (name);
61*0Sstevel@tonic-gate }
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate /*
64*0Sstevel@tonic-gate  * Return the name of a fault.
65*0Sstevel@tonic-gate  * Manufacture a name for unknown fault.
66*0Sstevel@tonic-gate  */
67*0Sstevel@tonic-gate char *
68*0Sstevel@tonic-gate proc_fltname(int flt, char *buf, size_t bufsz)
69*0Sstevel@tonic-gate {
70*0Sstevel@tonic-gate 	const char *name = rawfltname(flt);
71*0Sstevel@tonic-gate 	size_t len;
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate 	if (bufsz == 0)		/* force a program failure */
74*0Sstevel@tonic-gate 		return (NULL);
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate 	if (name != NULL) {
77*0Sstevel@tonic-gate 		len = strlen(name);
78*0Sstevel@tonic-gate 		(void) strncpy(buf, name, bufsz);
79*0Sstevel@tonic-gate 	} else {
80*0Sstevel@tonic-gate 		len = snprintf(buf, bufsz, "FLT#%d", flt);
81*0Sstevel@tonic-gate 	}
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate 	if (len >= bufsz)	/* ensure null-termination */
84*0Sstevel@tonic-gate 		buf[bufsz-1] = '\0';
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate 	return (buf);
87*0Sstevel@tonic-gate }
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate /*
90*0Sstevel@tonic-gate  * Return the name of a signal.
91*0Sstevel@tonic-gate  * Manufacture a name for unknown signal.
92*0Sstevel@tonic-gate  */
93*0Sstevel@tonic-gate char *
94*0Sstevel@tonic-gate proc_signame(int sig, char *buf, size_t bufsz)
95*0Sstevel@tonic-gate {
96*0Sstevel@tonic-gate 	char name[SIG2STR_MAX+4];
97*0Sstevel@tonic-gate 	size_t len;
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate 	if (bufsz == 0)		/* force a program failure */
100*0Sstevel@tonic-gate 		return (NULL);
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	/* sig2str() omits the leading "SIG" */
103*0Sstevel@tonic-gate 	(void) strcpy(name, "SIG");
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate 	if (sig2str(sig, name+3) == 0) {
106*0Sstevel@tonic-gate 		len = strlen(name);
107*0Sstevel@tonic-gate 		(void) strncpy(buf, name, bufsz);
108*0Sstevel@tonic-gate 	} else {
109*0Sstevel@tonic-gate 		len = snprintf(buf, bufsz, "SIG#%d", sig);
110*0Sstevel@tonic-gate 	}
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate 	if (len >= bufsz)	/* ensure null-termination */
113*0Sstevel@tonic-gate 		buf[bufsz-1] = '\0';
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate 	return (buf);
116*0Sstevel@tonic-gate }
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate static const char *const systable[] = {
119*0Sstevel@tonic-gate 	NULL,			/*  0 */
120*0Sstevel@tonic-gate 	"_exit",		/*  1 */
121*0Sstevel@tonic-gate 	"forkall",		/*  2 */
122*0Sstevel@tonic-gate 	"read",			/*  3 */
123*0Sstevel@tonic-gate 	"write",		/*  4 */
124*0Sstevel@tonic-gate 	"open",			/*  5 */
125*0Sstevel@tonic-gate 	"close",		/*  6 */
126*0Sstevel@tonic-gate 	"wait",			/*  7 */
127*0Sstevel@tonic-gate 	"creat",		/*  8 */
128*0Sstevel@tonic-gate 	"link",			/*  9 */
129*0Sstevel@tonic-gate 	"unlink",		/* 10 */
130*0Sstevel@tonic-gate 	"exec",			/* 11 */
131*0Sstevel@tonic-gate 	"chdir",		/* 12 */
132*0Sstevel@tonic-gate 	"time",			/* 13 */
133*0Sstevel@tonic-gate 	"mknod",		/* 14 */
134*0Sstevel@tonic-gate 	"chmod",		/* 15 */
135*0Sstevel@tonic-gate 	"chown",		/* 16 */
136*0Sstevel@tonic-gate 	"brk",			/* 17 */
137*0Sstevel@tonic-gate 	"stat",			/* 18 */
138*0Sstevel@tonic-gate 	"lseek",		/* 19 */
139*0Sstevel@tonic-gate 	"getpid",		/* 20 */
140*0Sstevel@tonic-gate 	"mount",		/* 21 */
141*0Sstevel@tonic-gate 	"umount",		/* 22 */
142*0Sstevel@tonic-gate 	"setuid",		/* 23 */
143*0Sstevel@tonic-gate 	"getuid",		/* 24 */
144*0Sstevel@tonic-gate 	"stime",		/* 25 */
145*0Sstevel@tonic-gate 	"ptrace",		/* 26 */
146*0Sstevel@tonic-gate 	"alarm",		/* 27 */
147*0Sstevel@tonic-gate 	"fstat",		/* 28 */
148*0Sstevel@tonic-gate 	"pause",		/* 29 */
149*0Sstevel@tonic-gate 	"utime",		/* 30 */
150*0Sstevel@tonic-gate 	"stty",			/* 31 */
151*0Sstevel@tonic-gate 	"gtty",			/* 32 */
152*0Sstevel@tonic-gate 	"access",		/* 33 */
153*0Sstevel@tonic-gate 	"nice",			/* 34 */
154*0Sstevel@tonic-gate 	"statfs",		/* 35 */
155*0Sstevel@tonic-gate 	"sync",			/* 36 */
156*0Sstevel@tonic-gate 	"kill",			/* 37 */
157*0Sstevel@tonic-gate 	"fstatfs",		/* 38 */
158*0Sstevel@tonic-gate 	"pgrpsys",		/* 39 */
159*0Sstevel@tonic-gate 	NULL,			/* 40 was xenix */
160*0Sstevel@tonic-gate 	"dup",			/* 41 */
161*0Sstevel@tonic-gate 	"pipe",			/* 42 */
162*0Sstevel@tonic-gate 	"times",		/* 43 */
163*0Sstevel@tonic-gate 	"profil",		/* 44 */
164*0Sstevel@tonic-gate 	"plock",		/* 45 */
165*0Sstevel@tonic-gate 	"setgid",		/* 46 */
166*0Sstevel@tonic-gate 	"getgid",		/* 47 */
167*0Sstevel@tonic-gate 	"signal",		/* 48 */
168*0Sstevel@tonic-gate 	"msgsys",		/* 49 */
169*0Sstevel@tonic-gate 	"sysi86",		/* 50 */
170*0Sstevel@tonic-gate 	"acct",			/* 51 */
171*0Sstevel@tonic-gate 	"shmsys",		/* 52 */
172*0Sstevel@tonic-gate 	"semsys",		/* 53 */
173*0Sstevel@tonic-gate 	"ioctl",		/* 54 */
174*0Sstevel@tonic-gate 	"uadmin",		/* 55 */
175*0Sstevel@tonic-gate 	NULL,			/* 56 */
176*0Sstevel@tonic-gate 	"utssys",		/* 57 */
177*0Sstevel@tonic-gate 	"fdsync",		/* 58 */
178*0Sstevel@tonic-gate 	"execve",		/* 59 */
179*0Sstevel@tonic-gate 	"umask",		/* 60 */
180*0Sstevel@tonic-gate 	"chroot",		/* 61 */
181*0Sstevel@tonic-gate 	"fcntl",		/* 62 */
182*0Sstevel@tonic-gate 	"ulimit",		/* 63 */
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate 	/* The following 6 entries were reserved for the UNIX PC */
185*0Sstevel@tonic-gate 	NULL,			/* 64 */
186*0Sstevel@tonic-gate 	NULL,			/* 65 */
187*0Sstevel@tonic-gate 	NULL,			/* 66 */
188*0Sstevel@tonic-gate 	NULL,			/* 67 */
189*0Sstevel@tonic-gate 	NULL,			/* 68 */
190*0Sstevel@tonic-gate 	NULL,			/* 69 */
191*0Sstevel@tonic-gate 
192*0Sstevel@tonic-gate 	"tasksys",		/* 70 */
193*0Sstevel@tonic-gate 	"acctctl",		/* 71 */
194*0Sstevel@tonic-gate 	"exacctsys",		/* 72 */
195*0Sstevel@tonic-gate 	"getpagesizes",		/* 73 */
196*0Sstevel@tonic-gate 	"rctlsys",		/* 74 */
197*0Sstevel@tonic-gate 	"issetugid",		/* 75 */
198*0Sstevel@tonic-gate 	"fsat",			/* 76 */
199*0Sstevel@tonic-gate 	"lwp_park",		/* 77 */
200*0Sstevel@tonic-gate 	"sendfilev",		/* 78 */
201*0Sstevel@tonic-gate 	"rmdir",		/* 79 */
202*0Sstevel@tonic-gate 	"mkdir",		/* 80 */
203*0Sstevel@tonic-gate 	"getdents",		/* 81 */
204*0Sstevel@tonic-gate 	"privsys",		/* 82 */
205*0Sstevel@tonic-gate 	"ucredsys",		/* 83 */
206*0Sstevel@tonic-gate 	"sysfs",		/* 84 */
207*0Sstevel@tonic-gate 	"getmsg",		/* 85 */
208*0Sstevel@tonic-gate 	"putmsg",		/* 86 */
209*0Sstevel@tonic-gate 	"poll",			/* 87 */
210*0Sstevel@tonic-gate 	"lstat",		/* 88 */
211*0Sstevel@tonic-gate 	"symlink",		/* 89 */
212*0Sstevel@tonic-gate 	"readlink",		/* 90 */
213*0Sstevel@tonic-gate 	"setgroups",		/* 91 */
214*0Sstevel@tonic-gate 	"getgroups",		/* 92 */
215*0Sstevel@tonic-gate 	"fchmod",		/* 93 */
216*0Sstevel@tonic-gate 	"fchown",		/* 94 */
217*0Sstevel@tonic-gate 	"sigprocmask",		/* 95 */
218*0Sstevel@tonic-gate 	"sigsuspend",		/* 96 */
219*0Sstevel@tonic-gate 	"sigaltstack",		/* 97 */
220*0Sstevel@tonic-gate 	"sigaction",		/* 98 */
221*0Sstevel@tonic-gate 	"sigpending",		/* 99 */
222*0Sstevel@tonic-gate 	"context",		/* 100 */
223*0Sstevel@tonic-gate 	"evsys",		/* 101 */
224*0Sstevel@tonic-gate 	"evtrapret",		/* 102 */
225*0Sstevel@tonic-gate 	"statvfs",		/* 103 */
226*0Sstevel@tonic-gate 	"fstatvfs",		/* 104 */
227*0Sstevel@tonic-gate 	"getloadavg",		/* 105 */
228*0Sstevel@tonic-gate 	"nfssys",		/* 106 */
229*0Sstevel@tonic-gate 	"waitid",		/* 107 */
230*0Sstevel@tonic-gate 	"sigsendsys",		/* 108 */
231*0Sstevel@tonic-gate 	"hrtsys",		/* 109 */
232*0Sstevel@tonic-gate 	"acancel",		/* 110 */
233*0Sstevel@tonic-gate 	"async",		/* 111 */
234*0Sstevel@tonic-gate 	"priocntlsys",		/* 112 */
235*0Sstevel@tonic-gate 	"pathconf",		/* 113 */
236*0Sstevel@tonic-gate 	"mincore",		/* 114 */
237*0Sstevel@tonic-gate 	"mmap",			/* 115 */
238*0Sstevel@tonic-gate 	"mprotect",		/* 116 */
239*0Sstevel@tonic-gate 	"munmap",		/* 117 */
240*0Sstevel@tonic-gate 	"fpathconf",		/* 118 */
241*0Sstevel@tonic-gate 	"vfork",		/* 119 */
242*0Sstevel@tonic-gate 	"fchdir",		/* 120 */
243*0Sstevel@tonic-gate 	"readv",		/* 121 */
244*0Sstevel@tonic-gate 	"writev",		/* 122 */
245*0Sstevel@tonic-gate 	"xstat",		/* 123 */
246*0Sstevel@tonic-gate 	"lxstat",		/* 124 */
247*0Sstevel@tonic-gate 	"fxstat",		/* 125 */
248*0Sstevel@tonic-gate 	"xmknod",		/* 126 */
249*0Sstevel@tonic-gate 	"NULL",			/* 127 */
250*0Sstevel@tonic-gate 	"setrlimit",		/* 128 */
251*0Sstevel@tonic-gate 	"getrlimit",		/* 129 */
252*0Sstevel@tonic-gate 	"lchown",		/* 130 */
253*0Sstevel@tonic-gate 	"memcntl",		/* 131 */
254*0Sstevel@tonic-gate 	"getpmsg",		/* 132 */
255*0Sstevel@tonic-gate 	"putpmsg",		/* 133 */
256*0Sstevel@tonic-gate 	"rename",		/* 134 */
257*0Sstevel@tonic-gate 	"uname",		/* 135 */
258*0Sstevel@tonic-gate 	"setegid",		/* 136 */
259*0Sstevel@tonic-gate 	"sysconfig",		/* 137 */
260*0Sstevel@tonic-gate 	"adjtime",		/* 138 */
261*0Sstevel@tonic-gate 	"systeminfo",		/* 139 */
262*0Sstevel@tonic-gate 	NULL,			/* 140 */
263*0Sstevel@tonic-gate 	"seteuid",		/* 141 */
264*0Sstevel@tonic-gate 	NULL,			/* 142 */
265*0Sstevel@tonic-gate 	"fork1",		/* 143 */
266*0Sstevel@tonic-gate 	"sigtimedwait",		/* 144 */
267*0Sstevel@tonic-gate 	"lwp_info",		/* 145 */
268*0Sstevel@tonic-gate 	"yield",		/* 146 */
269*0Sstevel@tonic-gate 	"lwp_sema_wait",	/* 147 */
270*0Sstevel@tonic-gate 	"lwp_sema_post",	/* 148 */
271*0Sstevel@tonic-gate 	"lwp_sema_trywait",	/* 149 */
272*0Sstevel@tonic-gate 	"lwp_detatch",		/* 150 */
273*0Sstevel@tonic-gate 	"corectl",		/* 151 */
274*0Sstevel@tonic-gate 	"modctl",		/* 152 */
275*0Sstevel@tonic-gate 	"fchroot",		/* 153 */
276*0Sstevel@tonic-gate 	"utimes",		/* 154 */
277*0Sstevel@tonic-gate 	"vhangup",		/* 155 */
278*0Sstevel@tonic-gate 	"gettimeofday",		/* 156 */
279*0Sstevel@tonic-gate 	"getitimer",		/* 157 */
280*0Sstevel@tonic-gate 	"setitimer",		/* 158 */
281*0Sstevel@tonic-gate 	"lwp_create",		/* 159 */
282*0Sstevel@tonic-gate 	"lwp_exit",		/* 160 */
283*0Sstevel@tonic-gate 	"lwp_suspend",		/* 161 */
284*0Sstevel@tonic-gate 	"lwp_continue",		/* 162 */
285*0Sstevel@tonic-gate 	"lwp_kill",		/* 163 */
286*0Sstevel@tonic-gate 	"lwp_self",		/* 164 */
287*0Sstevel@tonic-gate 	"lwp_sigmask",		/* 165 */
288*0Sstevel@tonic-gate 	"lwp_private",		/* 166 */
289*0Sstevel@tonic-gate 	"lwp_wait",		/* 167 */
290*0Sstevel@tonic-gate 	"lwp_mutex_unlock",	/* 168 */
291*0Sstevel@tonic-gate 	"lwp_mutex_lock",	/* 169 */
292*0Sstevel@tonic-gate 	"lwp_cond_wait",	/* 170 */
293*0Sstevel@tonic-gate 	"lwp_cond_signal",	/* 171 */
294*0Sstevel@tonic-gate 	"lwp_cond_broadcast",	/* 172 */
295*0Sstevel@tonic-gate 	"pread",		/* 173 */
296*0Sstevel@tonic-gate 	"pwrite",		/* 174 */
297*0Sstevel@tonic-gate 	"llseek",		/* 175 */
298*0Sstevel@tonic-gate 	"inst_sync",		/* 176 */
299*0Sstevel@tonic-gate 	NULL,			/* 177 */
300*0Sstevel@tonic-gate 	"kaio",			/* 178 */
301*0Sstevel@tonic-gate 	"cpc",			/* 179 */
302*0Sstevel@tonic-gate 	"lgrpsys",		/* 180 */
303*0Sstevel@tonic-gate 	"rusagesys",		/* 181 */
304*0Sstevel@tonic-gate 	"portfs",		/* 182 */
305*0Sstevel@tonic-gate 	"pollsys",		/* 183 */
306*0Sstevel@tonic-gate 	NULL,			/* 184 */
307*0Sstevel@tonic-gate 	"acl",			/* 185 */
308*0Sstevel@tonic-gate 	"auditsys",		/* 186 */
309*0Sstevel@tonic-gate 	"processor_bind",	/* 187 */
310*0Sstevel@tonic-gate 	"processor_info",	/* 188 */
311*0Sstevel@tonic-gate 	"p_online",		/* 189 */
312*0Sstevel@tonic-gate 	"sigqueue",		/* 190 */
313*0Sstevel@tonic-gate 	"clock_gettime",	/* 191 */
314*0Sstevel@tonic-gate 	"clock_settime",	/* 192 */
315*0Sstevel@tonic-gate 	"clock_getres",		/* 193 */
316*0Sstevel@tonic-gate 	"timer_create",		/* 194 */
317*0Sstevel@tonic-gate 	"timer_delete",		/* 195 */
318*0Sstevel@tonic-gate 	"timer_settime",	/* 196 */
319*0Sstevel@tonic-gate 	"timer_gettime",	/* 197 */
320*0Sstevel@tonic-gate 	"timer_getoverrun",	/* 198 */
321*0Sstevel@tonic-gate 	"nanosleep",		/* 199 */
322*0Sstevel@tonic-gate 	"facl",			/* 200 */
323*0Sstevel@tonic-gate 	"door",			/* 201 */
324*0Sstevel@tonic-gate 	"setreuid",		/* 202 */
325*0Sstevel@tonic-gate 	"setregid",		/* 203 */
326*0Sstevel@tonic-gate 	"install_utrap",	/* 204 */
327*0Sstevel@tonic-gate 	"signotify",		/* 205 */
328*0Sstevel@tonic-gate 	"schedctl",		/* 206 */
329*0Sstevel@tonic-gate 	"pset",			/* 207 */
330*0Sstevel@tonic-gate 	"sparc_utrap_install",	/* 208 */
331*0Sstevel@tonic-gate 	"resolvepath",		/* 209 */
332*0Sstevel@tonic-gate 	"lwp_mutex_timedlock",	/* 210 */
333*0Sstevel@tonic-gate 	"lwp_sema_timedwait",	/* 211 */
334*0Sstevel@tonic-gate 	"lwp_rwlock_sys",	/* 212 */
335*0Sstevel@tonic-gate 	"getdents64",		/* 213 */
336*0Sstevel@tonic-gate 	"mmap64",		/* 214 */
337*0Sstevel@tonic-gate 	"stat64",		/* 215 */
338*0Sstevel@tonic-gate 	"lstat64",		/* 216 */
339*0Sstevel@tonic-gate 	"fstat64",		/* 217 */
340*0Sstevel@tonic-gate 	"statvfs64",		/* 218 */
341*0Sstevel@tonic-gate 	"fstatvfs64",		/* 219 */
342*0Sstevel@tonic-gate 	"setrlimit64",		/* 220 */
343*0Sstevel@tonic-gate 	"getrlimit64",		/* 221 */
344*0Sstevel@tonic-gate 	"pread64",		/* 222 */
345*0Sstevel@tonic-gate 	"pwrite64",		/* 223 */
346*0Sstevel@tonic-gate 	"creat64",		/* 224 */
347*0Sstevel@tonic-gate 	"open64",		/* 225 */
348*0Sstevel@tonic-gate 	"rpcmod",		/* 226 */
349*0Sstevel@tonic-gate 	"zone",			/* 227 */
350*0Sstevel@tonic-gate 	"autofssys",		/* 228 */
351*0Sstevel@tonic-gate 	"getcwd",		/* 229 */
352*0Sstevel@tonic-gate 	"so_socket",		/* 230 */
353*0Sstevel@tonic-gate 	"so_socketpair",	/* 231 */
354*0Sstevel@tonic-gate 	"bind",			/* 232 */
355*0Sstevel@tonic-gate 	"listen",		/* 233 */
356*0Sstevel@tonic-gate 	"accept",		/* 234 */
357*0Sstevel@tonic-gate 	"connect",		/* 235 */
358*0Sstevel@tonic-gate 	"shutdown",		/* 236 */
359*0Sstevel@tonic-gate 	"recv",			/* 237 */
360*0Sstevel@tonic-gate 	"recvfrom",		/* 238 */
361*0Sstevel@tonic-gate 	"recvmsg",		/* 239 */
362*0Sstevel@tonic-gate 	"send",			/* 240 */
363*0Sstevel@tonic-gate 	"sendmsg",		/* 241 */
364*0Sstevel@tonic-gate 	"sendto",		/* 242 */
365*0Sstevel@tonic-gate 	"getpeername",		/* 243 */
366*0Sstevel@tonic-gate 	"getsockname",		/* 244 */
367*0Sstevel@tonic-gate 	"getsockopt",		/* 245 */
368*0Sstevel@tonic-gate 	"setsockopt",		/* 246 */
369*0Sstevel@tonic-gate 	"sockconfig",		/* 247 */
370*0Sstevel@tonic-gate 	"ntp_gettime",		/* 248 */
371*0Sstevel@tonic-gate 	"ntp_adjtime",		/* 249 */
372*0Sstevel@tonic-gate 	"lwp_mutex_unlock",	/* 250 */
373*0Sstevel@tonic-gate 	"lwp_mutex_trylock",	/* 251 */
374*0Sstevel@tonic-gate 	"lwp_mutex_init",	/* 252 */
375*0Sstevel@tonic-gate 	"cladm",		/* 253 */
376*0Sstevel@tonic-gate 	NULL,			/* 254 */
377*0Sstevel@tonic-gate 	"umount2"		/* 255 */
378*0Sstevel@tonic-gate };
379*0Sstevel@tonic-gate 
380*0Sstevel@tonic-gate /* SYSEND == max syscall number + 1 */
381*0Sstevel@tonic-gate #define	SYSEND	(sizeof (systable) / sizeof (systable[0]))
382*0Sstevel@tonic-gate 
383*0Sstevel@tonic-gate /*
384*0Sstevel@tonic-gate  * Return the name of a system call.
385*0Sstevel@tonic-gate  * Manufacture a name for unknown system call.
386*0Sstevel@tonic-gate  */
387*0Sstevel@tonic-gate char *
388*0Sstevel@tonic-gate proc_sysname(int sys, char *buf, size_t bufsz)
389*0Sstevel@tonic-gate {
390*0Sstevel@tonic-gate 	const char *name;
391*0Sstevel@tonic-gate 	size_t len;
392*0Sstevel@tonic-gate 
393*0Sstevel@tonic-gate 	if (bufsz == 0)		/* force a program failure */
394*0Sstevel@tonic-gate 		return (NULL);
395*0Sstevel@tonic-gate 
396*0Sstevel@tonic-gate 	if (sys >= 0 && sys < SYSEND)
397*0Sstevel@tonic-gate 		name = systable[sys];
398*0Sstevel@tonic-gate 	else
399*0Sstevel@tonic-gate 		name = NULL;
400*0Sstevel@tonic-gate 
401*0Sstevel@tonic-gate 	if (name != NULL) {
402*0Sstevel@tonic-gate 		len = strlen(name);
403*0Sstevel@tonic-gate 		(void) strncpy(buf, name, bufsz);
404*0Sstevel@tonic-gate 	} else {
405*0Sstevel@tonic-gate 		len = snprintf(buf, bufsz, "SYS#%d", sys);
406*0Sstevel@tonic-gate 	}
407*0Sstevel@tonic-gate 
408*0Sstevel@tonic-gate 	if (len >= bufsz)	/* ensure null-termination */
409*0Sstevel@tonic-gate 		buf[bufsz-1] = '\0';
410*0Sstevel@tonic-gate 
411*0Sstevel@tonic-gate 	return (buf);
412*0Sstevel@tonic-gate }
413*0Sstevel@tonic-gate 
414*0Sstevel@tonic-gate /*
415*0Sstevel@tonic-gate  * Convert a string representation of a fault to the corresponding number.
416*0Sstevel@tonic-gate  */
417*0Sstevel@tonic-gate int
418*0Sstevel@tonic-gate proc_str2flt(const char *str, int *fltnum)
419*0Sstevel@tonic-gate {
420*0Sstevel@tonic-gate 	char *next;
421*0Sstevel@tonic-gate 	int i;
422*0Sstevel@tonic-gate 
423*0Sstevel@tonic-gate 	i = strtol(str, &next, 0);
424*0Sstevel@tonic-gate 	if (i > 0 && i <= PRMAXFAULT && *next == '\0') {
425*0Sstevel@tonic-gate 		*fltnum = i;
426*0Sstevel@tonic-gate 		return (0);
427*0Sstevel@tonic-gate 	}
428*0Sstevel@tonic-gate 
429*0Sstevel@tonic-gate 	for (i = 1; i <= PRMAXFAULT; i++) {
430*0Sstevel@tonic-gate 		const char *s = rawfltname(i);
431*0Sstevel@tonic-gate 
432*0Sstevel@tonic-gate 		if (s && (strcasecmp(s, str) == 0 ||
433*0Sstevel@tonic-gate 		    strcasecmp(s + 3, str) == 0)) {
434*0Sstevel@tonic-gate 			*fltnum = i;
435*0Sstevel@tonic-gate 			return (0);
436*0Sstevel@tonic-gate 		}
437*0Sstevel@tonic-gate 	}
438*0Sstevel@tonic-gate 
439*0Sstevel@tonic-gate 	return (-1);
440*0Sstevel@tonic-gate }
441*0Sstevel@tonic-gate 
442*0Sstevel@tonic-gate /*
443*0Sstevel@tonic-gate  * Convert a string representation of a signal to the signal number.  This
444*0Sstevel@tonic-gate  * functionality is already available in libc, but the interface doesn't
445*0Sstevel@tonic-gate  * optionally accept a "SIG" prefix.  We strip that first, and then call libc.
446*0Sstevel@tonic-gate  */
447*0Sstevel@tonic-gate int
448*0Sstevel@tonic-gate proc_str2sig(const char *str, int *signum)
449*0Sstevel@tonic-gate {
450*0Sstevel@tonic-gate 	if (strncasecmp(str, "SIG", 3) == 0)
451*0Sstevel@tonic-gate 		str += 3; /* skip prefix */
452*0Sstevel@tonic-gate 
453*0Sstevel@tonic-gate 	return (str2sig(str, signum));
454*0Sstevel@tonic-gate }
455*0Sstevel@tonic-gate 
456*0Sstevel@tonic-gate /*
457*0Sstevel@tonic-gate  * Convert a string representation of a system call to the corresponding number.
458*0Sstevel@tonic-gate  * We do this by performing a simple linear search of the table above.
459*0Sstevel@tonic-gate  */
460*0Sstevel@tonic-gate int
461*0Sstevel@tonic-gate proc_str2sys(const char *str, int *sysnum)
462*0Sstevel@tonic-gate {
463*0Sstevel@tonic-gate 	char *next;
464*0Sstevel@tonic-gate 	int i;
465*0Sstevel@tonic-gate 
466*0Sstevel@tonic-gate 	i = strtol(str, &next, 0);
467*0Sstevel@tonic-gate 	if (i > 0 && i <= PRMAXSYS && *next == '\0') {
468*0Sstevel@tonic-gate 		*sysnum = i;
469*0Sstevel@tonic-gate 		return (0);
470*0Sstevel@tonic-gate 	}
471*0Sstevel@tonic-gate 
472*0Sstevel@tonic-gate 	for (i = 1; i < SYSEND; i++) {
473*0Sstevel@tonic-gate 		if (systable[i] != NULL && strcmp(systable[i], str) == 0) {
474*0Sstevel@tonic-gate 			*sysnum = i;
475*0Sstevel@tonic-gate 			return (0);
476*0Sstevel@tonic-gate 		}
477*0Sstevel@tonic-gate 	}
478*0Sstevel@tonic-gate 
479*0Sstevel@tonic-gate 	return (-1);
480*0Sstevel@tonic-gate }
481*0Sstevel@tonic-gate 
482*0Sstevel@tonic-gate /*
483*0Sstevel@tonic-gate  * Convert a fltset_t to a string representation consisting of canonical
484*0Sstevel@tonic-gate  * machine fault names separated by the given delimeter string.  If
485*0Sstevel@tonic-gate  * m is non-zero (TRUE), set members are printed.  If m is zero (FALSE), set
486*0Sstevel@tonic-gate  * non-members are printed.  If the specified buf is too small to hold the
487*0Sstevel@tonic-gate  * complete formatted set, NULL is returned; otherwise buf is returned.
488*0Sstevel@tonic-gate  */
489*0Sstevel@tonic-gate char *
490*0Sstevel@tonic-gate proc_fltset2str(const fltset_t *set, const char *delim, int m,
491*0Sstevel@tonic-gate 	char *buf, size_t len)
492*0Sstevel@tonic-gate {
493*0Sstevel@tonic-gate 	char name[FLT2STR_MAX], *p = buf;
494*0Sstevel@tonic-gate 	size_t n;
495*0Sstevel@tonic-gate 	int i;
496*0Sstevel@tonic-gate 
497*0Sstevel@tonic-gate 	if (buf == NULL || len < 1) {
498*0Sstevel@tonic-gate 		errno = EINVAL;
499*0Sstevel@tonic-gate 		return (NULL);
500*0Sstevel@tonic-gate 	}
501*0Sstevel@tonic-gate 
502*0Sstevel@tonic-gate 	buf[0] = '\0';  /* Set first byte to \0 */
503*0Sstevel@tonic-gate 
504*0Sstevel@tonic-gate 	for (i = 1; i <= PRMAXFAULT; i++) {
505*0Sstevel@tonic-gate 		if ((prismember(set, i) != 0) ^ (m == 0)) {
506*0Sstevel@tonic-gate 			(void) proc_fltname(i, name, sizeof (name));
507*0Sstevel@tonic-gate 
508*0Sstevel@tonic-gate 			if (buf[0] != '\0')
509*0Sstevel@tonic-gate 				n = snprintf(p, len, "%s%s", delim, name);
510*0Sstevel@tonic-gate 			else
511*0Sstevel@tonic-gate 				n = snprintf(p, len, "%s", name);
512*0Sstevel@tonic-gate 
513*0Sstevel@tonic-gate 			if (n != strlen(p)) {
514*0Sstevel@tonic-gate 				errno = ENAMETOOLONG; /* Output was truncated */
515*0Sstevel@tonic-gate 				return (NULL);
516*0Sstevel@tonic-gate 			}
517*0Sstevel@tonic-gate 			len -= n;
518*0Sstevel@tonic-gate 			p += n;
519*0Sstevel@tonic-gate 		}
520*0Sstevel@tonic-gate 	}
521*0Sstevel@tonic-gate 	return (buf);
522*0Sstevel@tonic-gate }
523*0Sstevel@tonic-gate 
524*0Sstevel@tonic-gate /*
525*0Sstevel@tonic-gate  * Convert a sigset_t to a string representation consisting of canonical signal
526*0Sstevel@tonic-gate  * names (without the SIG prefix). Parameters and return values analogous to
527*0Sstevel@tonic-gate  * proc_fltset2str().
528*0Sstevel@tonic-gate  */
529*0Sstevel@tonic-gate char *
530*0Sstevel@tonic-gate proc_sigset2str(const sigset_t *set, const char *delim, int m,
531*0Sstevel@tonic-gate 	char *buf, size_t len)
532*0Sstevel@tonic-gate {
533*0Sstevel@tonic-gate 	char name[SIG2STR_MAX], *p = buf;
534*0Sstevel@tonic-gate 	size_t n;
535*0Sstevel@tonic-gate 	int i;
536*0Sstevel@tonic-gate 
537*0Sstevel@tonic-gate 	if (buf == NULL || len < 1) {
538*0Sstevel@tonic-gate 		errno = EINVAL;
539*0Sstevel@tonic-gate 		return (NULL);
540*0Sstevel@tonic-gate 	}
541*0Sstevel@tonic-gate 
542*0Sstevel@tonic-gate 	m = (m != 0);	/* Make sure m is 0 or 1 */
543*0Sstevel@tonic-gate 	buf[0] = '\0';	/* Set first byte to \0 */
544*0Sstevel@tonic-gate 
545*0Sstevel@tonic-gate 	/*
546*0Sstevel@tonic-gate 	 * Unlike proc_fltset2str() and proc_sysset2str(), we don't loop
547*0Sstevel@tonic-gate 	 * until i <= NSIG here, because sigismember() rejects i == NSIG.
548*0Sstevel@tonic-gate 	 */
549*0Sstevel@tonic-gate 	for (i = 1; i < NSIG; i++) {
550*0Sstevel@tonic-gate 		if (sigismember(set, i) == m) {
551*0Sstevel@tonic-gate 			(void) sig2str(i, name);
552*0Sstevel@tonic-gate 
553*0Sstevel@tonic-gate 			if (buf[0] != '\0')
554*0Sstevel@tonic-gate 				n = snprintf(p, len, "%s%s", delim, name);
555*0Sstevel@tonic-gate 			else
556*0Sstevel@tonic-gate 				n = snprintf(p, len, "%s", name);
557*0Sstevel@tonic-gate 
558*0Sstevel@tonic-gate 			if (n != strlen(p)) {
559*0Sstevel@tonic-gate 				errno = ENAMETOOLONG; /* Output was truncated */
560*0Sstevel@tonic-gate 				return (NULL);
561*0Sstevel@tonic-gate 			}
562*0Sstevel@tonic-gate 
563*0Sstevel@tonic-gate 			len -= n;
564*0Sstevel@tonic-gate 			p += n;
565*0Sstevel@tonic-gate 		}
566*0Sstevel@tonic-gate 	}
567*0Sstevel@tonic-gate 
568*0Sstevel@tonic-gate 	return (buf);
569*0Sstevel@tonic-gate }
570*0Sstevel@tonic-gate 
571*0Sstevel@tonic-gate /*
572*0Sstevel@tonic-gate  * Convert a sysset_t to a string representation consisting of canonical system
573*0Sstevel@tonic-gate  * call names. Parameters and return values analogous to proc_fltset2str().
574*0Sstevel@tonic-gate  */
575*0Sstevel@tonic-gate char *
576*0Sstevel@tonic-gate proc_sysset2str(const sysset_t *set, const char *delim, int m,
577*0Sstevel@tonic-gate 	char *buf, size_t len)
578*0Sstevel@tonic-gate {
579*0Sstevel@tonic-gate 	char name[SYS2STR_MAX], *p = buf;
580*0Sstevel@tonic-gate 	size_t n;
581*0Sstevel@tonic-gate 	int i;
582*0Sstevel@tonic-gate 
583*0Sstevel@tonic-gate 	if (buf == NULL || len < 1) {
584*0Sstevel@tonic-gate 		errno = EINVAL;
585*0Sstevel@tonic-gate 		return (NULL);
586*0Sstevel@tonic-gate 	}
587*0Sstevel@tonic-gate 
588*0Sstevel@tonic-gate 	buf[0] = '\0';  /* Set first byte to \0 */
589*0Sstevel@tonic-gate 
590*0Sstevel@tonic-gate 	for (i = 1; i <= PRMAXSYS; i++) {
591*0Sstevel@tonic-gate 		if ((prismember(set, i) != 0) ^ (m == 0)) {
592*0Sstevel@tonic-gate 			(void) proc_sysname(i, name, sizeof (name));
593*0Sstevel@tonic-gate 
594*0Sstevel@tonic-gate 			if (buf[0] != '\0')
595*0Sstevel@tonic-gate 				n = snprintf(p, len, "%s%s", delim, name);
596*0Sstevel@tonic-gate 			else
597*0Sstevel@tonic-gate 				n = snprintf(p, len, "%s", name);
598*0Sstevel@tonic-gate 
599*0Sstevel@tonic-gate 			if (n != strlen(p)) {
600*0Sstevel@tonic-gate 				errno = ENAMETOOLONG; /* Output was truncated */
601*0Sstevel@tonic-gate 				return (NULL);
602*0Sstevel@tonic-gate 			}
603*0Sstevel@tonic-gate 			len -= n;
604*0Sstevel@tonic-gate 			p += n;
605*0Sstevel@tonic-gate 		}
606*0Sstevel@tonic-gate 	}
607*0Sstevel@tonic-gate 	return (buf);
608*0Sstevel@tonic-gate }
609*0Sstevel@tonic-gate 
610*0Sstevel@tonic-gate /*
611*0Sstevel@tonic-gate  * Convert a string representation of a fault set (names separated by
612*0Sstevel@tonic-gate  * one or more of the given delimeters) to a fltset_t.
613*0Sstevel@tonic-gate  * If m is non-zero (TRUE), members of the string representation are set.
614*0Sstevel@tonic-gate  * If m is zero (FALSE), non-members of the string representation are set.
615*0Sstevel@tonic-gate  * This function returns NULL for success. Otherwise it returns a pointer
616*0Sstevel@tonic-gate  * to the token of the string that couldn't be identified as a string
617*0Sstevel@tonic-gate  * representation of a fault.
618*0Sstevel@tonic-gate  */
619*0Sstevel@tonic-gate char *
620*0Sstevel@tonic-gate proc_str2fltset(const char *s, const char *delim, int m, fltset_t *set)
621*0Sstevel@tonic-gate {
622*0Sstevel@tonic-gate 	char *p, *q, *t = alloca(strlen(s) + 1);
623*0Sstevel@tonic-gate 	int flt;
624*0Sstevel@tonic-gate 
625*0Sstevel@tonic-gate 	if (m) {
626*0Sstevel@tonic-gate 		premptyset(set);
627*0Sstevel@tonic-gate 	} else {
628*0Sstevel@tonic-gate 		prfillset(set);
629*0Sstevel@tonic-gate 	}
630*0Sstevel@tonic-gate 
631*0Sstevel@tonic-gate 	(void) strcpy(t, s);
632*0Sstevel@tonic-gate 
633*0Sstevel@tonic-gate 	for (p = strtok_r(t, delim, &q); p != NULL;
634*0Sstevel@tonic-gate 	    p = strtok_r(NULL, delim, &q)) {
635*0Sstevel@tonic-gate 		if (proc_str2flt(p, &flt) == -1) {
636*0Sstevel@tonic-gate 			errno = EINVAL;
637*0Sstevel@tonic-gate 			return ((char *)s + (p - t));
638*0Sstevel@tonic-gate 		}
639*0Sstevel@tonic-gate 		if (m)
640*0Sstevel@tonic-gate 			praddset(set, flt);
641*0Sstevel@tonic-gate 		else
642*0Sstevel@tonic-gate 			prdelset(set, flt);
643*0Sstevel@tonic-gate 	}
644*0Sstevel@tonic-gate 	return (NULL);
645*0Sstevel@tonic-gate }
646*0Sstevel@tonic-gate 
647*0Sstevel@tonic-gate /*
648*0Sstevel@tonic-gate  * Convert a string representation of a signal set (names with or without the
649*0Sstevel@tonic-gate  * SIG prefix separated by one or more of the given delimeters) to a sigset_t.
650*0Sstevel@tonic-gate  * Parameters and return values analogous to proc_str2fltset().
651*0Sstevel@tonic-gate  */
652*0Sstevel@tonic-gate char *
653*0Sstevel@tonic-gate proc_str2sigset(const char *s, const char *delim, int m, sigset_t *set)
654*0Sstevel@tonic-gate {
655*0Sstevel@tonic-gate 	char *p, *q, *t = alloca(strlen(s) + 1);
656*0Sstevel@tonic-gate 	int sig;
657*0Sstevel@tonic-gate 
658*0Sstevel@tonic-gate 	if (m) {
659*0Sstevel@tonic-gate 		premptyset(set);
660*0Sstevel@tonic-gate 	} else {
661*0Sstevel@tonic-gate 		prfillset(set);
662*0Sstevel@tonic-gate 	}
663*0Sstevel@tonic-gate 
664*0Sstevel@tonic-gate 	(void) strcpy(t, s);
665*0Sstevel@tonic-gate 
666*0Sstevel@tonic-gate 	for (p = strtok_r(t, delim, &q); p != NULL;
667*0Sstevel@tonic-gate 	    p = strtok_r(NULL, delim, &q)) {
668*0Sstevel@tonic-gate 		if (proc_str2sig(p, &sig) == -1) {
669*0Sstevel@tonic-gate 			errno = EINVAL;
670*0Sstevel@tonic-gate 			return ((char *)s + (p - t));
671*0Sstevel@tonic-gate 		}
672*0Sstevel@tonic-gate 		if (m)
673*0Sstevel@tonic-gate 			praddset(set, sig);
674*0Sstevel@tonic-gate 		else
675*0Sstevel@tonic-gate 			prdelset(set, sig);
676*0Sstevel@tonic-gate 	}
677*0Sstevel@tonic-gate 	return (NULL);
678*0Sstevel@tonic-gate }
679*0Sstevel@tonic-gate 
680*0Sstevel@tonic-gate /*
681*0Sstevel@tonic-gate  * Convert a string representation of a system call set (names separated by
682*0Sstevel@tonic-gate  * one or more of the given delimeters) to a sysset_t. Parameters and return
683*0Sstevel@tonic-gate  * values analogous to proc_str2fltset().
684*0Sstevel@tonic-gate  */
685*0Sstevel@tonic-gate char *
686*0Sstevel@tonic-gate proc_str2sysset(const char *s, const char *delim, int m, sysset_t *set)
687*0Sstevel@tonic-gate {
688*0Sstevel@tonic-gate 	char *p, *q, *t = alloca(strlen(s) + 1);
689*0Sstevel@tonic-gate 	int sys;
690*0Sstevel@tonic-gate 
691*0Sstevel@tonic-gate 	if (m) {
692*0Sstevel@tonic-gate 		premptyset(set);
693*0Sstevel@tonic-gate 	} else {
694*0Sstevel@tonic-gate 		prfillset(set);
695*0Sstevel@tonic-gate 	}
696*0Sstevel@tonic-gate 
697*0Sstevel@tonic-gate 	(void) strcpy(t, s);
698*0Sstevel@tonic-gate 
699*0Sstevel@tonic-gate 	for (p = strtok_r(t, delim, &q); p != NULL;
700*0Sstevel@tonic-gate 	    p = strtok_r(NULL, delim, &q)) {
701*0Sstevel@tonic-gate 		if (proc_str2sys(p, &sys) == -1) {
702*0Sstevel@tonic-gate 			errno = EINVAL;
703*0Sstevel@tonic-gate 			return ((char *)s + (p - t));
704*0Sstevel@tonic-gate 		}
705*0Sstevel@tonic-gate 		if (m)
706*0Sstevel@tonic-gate 			praddset(set, sys);
707*0Sstevel@tonic-gate 		else
708*0Sstevel@tonic-gate 			prdelset(set, sys);
709*0Sstevel@tonic-gate 	}
710*0Sstevel@tonic-gate 	return (NULL);
711*0Sstevel@tonic-gate }
712