xref: /illumos-gate/usr/src/cmd/truss/print.c (revision 4763305e3243687c189d755d737d52205b2614ed)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2020 Joyent, Inc.
25  * Copyright 2022 Garrett D'Amore
26  * Copyright 2024 Oxide Computer Company
27  */
28 
29 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
30 /*	  All Rights Reserved	*/
31 
32 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
33 
34 #define	_SYSCALL32	/* make 32-bit compat headers visible */
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <string.h>
40 #include <signal.h>
41 #include <termio.h>
42 #include <stddef.h>
43 #include <limits.h>
44 #include <fcntl.h>
45 #include <ctype.h>
46 #include <sys/types.h>
47 #include <sys/mman.h>
48 #include <sys/resource.h>
49 #include <sys/ulimit.h>
50 #include <sys/utsname.h>
51 #include <sys/kstat.h>
52 #include <sys/modctl.h>
53 #include <sys/acl.h>
54 #include <stropts.h>
55 #include <sys/isa_defs.h>
56 #include <sys/systeminfo.h>
57 #include <sys/cladm.h>
58 #include <sys/lwp.h>
59 #include <bsm/audit.h>
60 #include <libproc.h>
61 #include <priv.h>
62 #include <sys/aio.h>
63 #include <sys/aiocb.h>
64 #include <sys/corectl.h>
65 #include <sys/cpc_impl.h>
66 #include <sys/execx.h>
67 #include <sys/priocntl.h>
68 #include <sys/tspriocntl.h>
69 #include <sys/iapriocntl.h>
70 #include <sys/rtpriocntl.h>
71 #include <sys/fsspriocntl.h>
72 #include <sys/fxpriocntl.h>
73 #include <sys/proc.h>
74 #include <netdb.h>
75 #include <nss_dbdefs.h>
76 #include <sys/socketvar.h>
77 #include <netinet/in.h>
78 #include <netinet/tcp.h>
79 #include <netinet/udp.h>
80 #include <netinet/sctp.h>
81 #include <netinet/ip_mroute.h>
82 #include <netinet/icmp6.h>
83 #include <net/route.h>
84 #include <sys/utrap.h>
85 #include <sys/lgrp_user.h>
86 #include <sys/door.h>
87 #include <sys/tsol/tndb.h>
88 #include <sys/rctl.h>
89 #include <sys/rctl_impl.h>
90 #include <sys/fork.h>
91 #include <sys/task.h>
92 #include <sys/random.h>
93 #include <sys/sysmacros.h>
94 #include <sys/fdsync.h>
95 #include "ramdata.h"
96 #include "print.h"
97 #include "proto.h"
98 #include "systable.h"
99 
100 void grow(private_t *, int nbyte);
101 
102 #define	GROW(nb) if (pri->sys_leng + (nb) >= pri->sys_ssize) grow(pri, (nb))
103 
104 
105 /*ARGSUSED*/
106 void
prt_nov(private_t * pri,int raw,long val)107 prt_nov(private_t *pri, int raw, long val)	/* print nothing */
108 {
109 }
110 
111 /*ARGSUSED*/
112 void
prt_dec(private_t * pri,int raw,long val)113 prt_dec(private_t *pri, int raw, long val)	/* print as decimal */
114 {
115 	GROW(24);
116 	if (data_model == PR_MODEL_ILP32)
117 		pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
118 		    "%d", (int)val);
119 	else
120 		pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
121 		    "%ld", val);
122 }
123 
124 /*ARGSUSED*/
125 void
prt_uns(private_t * pri,int raw,long val)126 prt_uns(private_t *pri, int raw, long val)	/* print as unsigned decimal */
127 {
128 	GROW(24);
129 	if (data_model == PR_MODEL_ILP32)
130 		pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
131 		    "%u", (int)val);
132 	else
133 		pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
134 		    "%lu", val);
135 }
136 
137 /* print as unsigned decimal, except for -1 */
138 void
prt_un1(private_t * pri,int raw,long val)139 prt_un1(private_t *pri, int raw, long val)
140 {
141 	if ((int)val == -1)
142 		prt_dec(pri, raw, val);
143 	else
144 		prt_uns(pri, raw, val);
145 }
146 
147 /*ARGSUSED*/
148 void
prt_oct(private_t * pri,int raw,long val)149 prt_oct(private_t *pri, int raw, long val)	/* print as octal */
150 {
151 	GROW(24);
152 	if (data_model == PR_MODEL_ILP32)
153 		pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
154 		    "%#o", (int)val);
155 	else
156 		pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
157 		    "%#lo", val);
158 }
159 
160 /*ARGSUSED*/
161 void
prt_hex(private_t * pri,int raw,long val)162 prt_hex(private_t *pri, int raw, long val)	/* print as hexadecimal */
163 {
164 	GROW(20);
165 	if (data_model == PR_MODEL_ILP32)
166 		pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
167 		    "0x%.8X", (int)val);
168 	else
169 		pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
170 		    "0x%.8lX", val);
171 }
172 
173 /* print as hexadecimal (half size) */
174 /*ARGSUSED*/
175 void
prt_hhx(private_t * pri,int raw,long val)176 prt_hhx(private_t *pri, int raw, long val)
177 {
178 	GROW(20);
179 	if (data_model == PR_MODEL_ILP32)
180 		pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
181 		    "0x%.4X", (int)val);
182 	else
183 		pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
184 		    "0x%.4lX", val);
185 }
186 
187 /* print as decimal if small, else hexadecimal */
188 /*ARGSUSED*/
189 void
prt_dex(private_t * pri,int raw,long val)190 prt_dex(private_t *pri, int raw, long val)
191 {
192 	if (val & 0xff000000)
193 		prt_hex(pri, 0, val);
194 	else
195 		prt_dec(pri, 0, val);
196 }
197 
198 /* print long long offset */
199 /*ARGSUSED*/
200 void
prt_llo(private_t * pri,int raw,long val1,long val2)201 prt_llo(private_t *pri, int raw, long val1, long val2)
202 {
203 	int hival;
204 	int loval;
205 
206 #ifdef	_LONG_LONG_LTOH
207 	hival = (int)val2;
208 	loval = (int)val1;
209 #else
210 	hival = (int)val1;
211 	loval = (int)val2;
212 #endif
213 
214 	if (hival == 0) {
215 		prt_dex(pri, 0, loval);
216 	} else {
217 		GROW(18);
218 		pri->sys_leng +=
219 		    sprintf(pri->sys_string + pri->sys_leng, "0x%.8X%.8X",
220 		    hival, loval);
221 	}
222 }
223 
224 void
escape_string(private_t * pri,const char * s)225 escape_string(private_t *pri, const char *s)
226 {
227 	/*
228 	 * We want to avoid outputting unprintable characters that may
229 	 * destroy the user's terminal.  So we do one pass to find any
230 	 * unprintable characters, size the array appropriately, and
231 	 * then walk each character by hand.  Those that are unprintable
232 	 * are replaced by a hex escape (\xNN).  We also escape quotes for
233 	 * completeness.
234 	 */
235 	int i, unprintable, quotes;
236 	size_t len = strlen(s);
237 	for (i = 0, unprintable = 0, quotes = 0; i < len; i++) {
238 		if (!isprint(s[i]))
239 			unprintable++;
240 		if (s[i] == '"')
241 			quotes++;
242 	}
243 
244 	GROW(len + 3 * unprintable + quotes + 2);
245 
246 	pri->sys_string[pri->sys_leng++] = '"';
247 	for (i = 0; i < len; i++) {
248 		if (s[i] == '"')
249 			pri->sys_string[pri->sys_leng++] = '\\';
250 
251 		if (isprint(s[i])) {
252 			pri->sys_string[pri->sys_leng++] = s[i];
253 		} else {
254 			pri->sys_leng += sprintf(pri->sys_string +
255 			    pri->sys_leng, "\\x%02x", (uint8_t)s[i]);
256 		}
257 	}
258 	pri->sys_string[pri->sys_leng++] = '"';
259 }
260 
261 void
prt_stg(private_t * pri,int raw,long val)262 prt_stg(private_t *pri, int raw, long val)	/* print as string */
263 {
264 	char *s = raw? NULL : fetchstring(pri, (long)val, PATH_MAX);
265 
266 	if (s == NULL)
267 		prt_hex(pri, 0, val);
268 	else
269 		escape_string(pri, s);
270 }
271 
272 /* print as string returned from syscall */
273 void
prt_rst(private_t * pri,int raw,long val)274 prt_rst(private_t *pri, int raw, long val)
275 {
276 	char *s = (raw || pri->Errno)? NULL :
277 	    fetchstring(pri, (long)val, PATH_MAX);
278 
279 	if (s == NULL)
280 		prt_hex(pri, 0, val);
281 	else {
282 		GROW((int)strlen(s) + 2);
283 		pri->sys_leng += snprintf(pri->sys_string + pri->sys_leng,
284 		    pri->sys_ssize - pri->sys_leng, "\"%s\"", s);
285 	}
286 }
287 
288 /* print contents of readlink() buffer */
289 void
prt_rlk(private_t * pri,int raw,long val)290 prt_rlk(private_t *pri, int raw, long val)
291 {
292 	char *s = (raw || pri->Errno || pri->Rval1 <= 0)? NULL :
293 	    fetchstring(pri, (long)val,
294 	    (pri->Rval1 > PATH_MAX)? PATH_MAX : (int)pri->Rval1);
295 
296 	if (s == NULL)
297 		prt_hex(pri, 0, val);
298 	else {
299 		GROW((int)strlen(s) + 2);
300 		pri->sys_leng += snprintf(pri->sys_string + pri->sys_leng,
301 		    pri->sys_ssize - pri->sys_leng, "\"%s\"", s);
302 	}
303 }
304 
305 void
prt_ioc(private_t * pri,int raw,long val)306 prt_ioc(private_t *pri, int raw, long val)	/* print ioctl code */
307 {
308 	const char *s = raw? NULL : ioctlname(pri, (int)val);
309 
310 	if (s == NULL)
311 		prt_hex(pri, 0, val);
312 	else
313 		outstring(pri, s);
314 }
315 
316 void
prt_ioa(private_t * pri,int raw,long val)317 prt_ioa(private_t *pri, int raw, long val)	/* print ioctl argument */
318 {
319 	const char *s;
320 
321 	/* cheating -- look at the ioctl() code */
322 	switch (pri->sys_args[1]) {
323 
324 	/* kstat ioctl()s */
325 	case KSTAT_IOC_READ:
326 	case KSTAT_IOC_WRITE:
327 		if (data_model == PR_MODEL_ILP32)
328 			prt_stg(pri, raw,
329 			    val + offsetof(kstat32_t, ks_name[0]));
330 		else
331 			prt_stg(pri, raw,
332 			    val + offsetof(kstat_t, ks_name[0]));
333 		break;
334 
335 	/* streams ioctl()s */
336 	case I_LOOK:
337 		prt_rst(pri, raw, val);
338 		break;
339 	case I_PUSH:
340 	case I_FIND:
341 		prt_stg(pri, raw, val);
342 		break;
343 	case I_LINK:
344 	case I_UNLINK:
345 	case I_SENDFD:
346 		prt_dec(pri, 0, val);
347 		break;
348 	case I_SRDOPT:
349 		if (raw || (s = strrdopt(val)) == NULL)
350 			prt_dec(pri, 0, val);
351 		else
352 			outstring(pri, s);
353 		break;
354 	case I_SETSIG:
355 		if (raw || (s = strevents(pri, val)) == NULL)
356 			prt_hex(pri, 0, val);
357 		else
358 			outstring(pri, s);
359 		break;
360 	case I_FLUSH:
361 		if (raw || (s = strflush(val)) == NULL)
362 			prt_dec(pri, 0, val);
363 		else
364 			outstring(pri, s);
365 		break;
366 
367 	/* tty ioctl()s */
368 	case TCSBRK:
369 	case TCXONC:
370 	case TCFLSH:
371 	case TCDSET:
372 		prt_dec(pri, 0, val);
373 		break;
374 
375 	default:
376 		prt_hex(pri, 0, val);
377 		break;
378 	}
379 }
380 
381 void
prt_pip(private_t * pri,int raw,long val)382 prt_pip(private_t *pri, int raw, long val)	/* print pipe code */
383 {
384 	int first = 1;
385 	long flags = ~(O_CLOEXEC | O_CLOFORK | O_NONBLOCK);
386 
387 	if (raw != 0 || val == 0 || (val & flags) != 0) {
388 		prt_dex(pri, 0, val);
389 		return;
390 	}
391 
392 	if (val & O_CLOEXEC) {
393 		outstring(pri, "|O_CLOEXEC" + first);
394 		first = 0;
395 	}
396 	if (val & O_CLOFORK) {
397 		outstring(pri, "|O_CLOFORK" + first);
398 		first = 0;
399 	}
400 	if (val & O_NONBLOCK) {
401 		outstring(pri, "|O_NONBLOCK" + first);
402 	}
403 }
404 
405 void
prt_pfd(private_t * pri,int raw,long val)406 prt_pfd(private_t *pri, int raw, long val)	/* print pipe code */
407 {
408 	int fds[2];
409 	char str[32];
410 
411 	/* the fds only have meaning if the return value is 0 */
412 	if (!raw &&
413 	    pri->Rval1 >= 0 &&
414 	    Pread(Proc, fds, sizeof (fds), (long)val) == sizeof (fds)) {
415 		(void) snprintf(str, sizeof (str), "[%d,%d]", fds[0], fds[1]);
416 		outstring(pri, str);
417 	} else {
418 		prt_hex(pri, 0, val);
419 	}
420 }
421 
422 void
prt_fcn(private_t * pri,int raw,long val)423 prt_fcn(private_t *pri, int raw, long val)	/* print fcntl code */
424 {
425 	const char *s = raw? NULL : fcntlname(val);
426 
427 	if (s == NULL)
428 		prt_dec(pri, 0, val);
429 	else
430 		outstring(pri, s);
431 }
432 
433 void
prt_s86(private_t * pri,int raw,long val)434 prt_s86(private_t *pri, int raw, long val)	/* print sysi86 code */
435 {
436 
437 	const char *s = raw? NULL : si86name(val);
438 
439 	if (s == NULL)
440 		prt_dec(pri, 0, val);
441 	else
442 		outstring(pri, s);
443 }
444 
445 void
prt_uts(private_t * pri,int raw,long val)446 prt_uts(private_t *pri, int raw, long val)	/* print utssys code */
447 {
448 	const char *s = raw? NULL : utscode(val);
449 
450 	if (s == NULL)
451 		prt_dec(pri, 0, val);
452 	else
453 		outstring(pri, s);
454 }
455 
456 void
prt_msc(private_t * pri,int raw,long val)457 prt_msc(private_t *pri, int raw, long val)	/* print msgsys command */
458 {
459 	const char *s = raw? NULL : msgcmd(val);
460 
461 	if (s == NULL)
462 		prt_dec(pri, 0, val);
463 	else
464 		outstring(pri, s);
465 }
466 
467 void
prt_msf(private_t * pri,int raw,long val)468 prt_msf(private_t *pri, int raw, long val)	/* print msgsys flags */
469 {
470 	const char *s = raw? NULL : msgflags(pri, (int)val);
471 
472 	if (s == NULL)
473 		prt_oct(pri, 0, val);
474 	else
475 		outstring(pri, s);
476 }
477 
478 void
prt_smc(private_t * pri,int raw,long val)479 prt_smc(private_t *pri, int raw, long val)	/* print semsys command */
480 {
481 	const char *s = raw? NULL : semcmd(val);
482 
483 	if (s == NULL)
484 		prt_dec(pri, 0, val);
485 	else
486 		outstring(pri, s);
487 }
488 
489 void
prt_sef(private_t * pri,int raw,long val)490 prt_sef(private_t *pri, int raw, long val)	/* print semsys flags */
491 {
492 	const char *s = raw? NULL : semflags(pri, (int)val);
493 
494 	if (s == NULL)
495 		prt_oct(pri, 0, val);
496 	else
497 		outstring(pri, s);
498 }
499 
500 void
prt_shc(private_t * pri,int raw,long val)501 prt_shc(private_t *pri, int raw, long val)	/* print shmsys command */
502 {
503 	const char *s = raw? NULL : shmcmd(val);
504 
505 	if (s == NULL)
506 		prt_dec(pri, 0, val);
507 	else
508 		outstring(pri, s);
509 }
510 
511 void
prt_shf(private_t * pri,int raw,long val)512 prt_shf(private_t *pri, int raw, long val)	/* print shmsys flags */
513 {
514 	const char *s = raw? NULL : shmflags(pri, (int)val);
515 
516 	if (s == NULL)
517 		prt_oct(pri, 0, val);
518 	else
519 		outstring(pri, s);
520 }
521 
522 void
prt_sfs(private_t * pri,int raw,long val)523 prt_sfs(private_t *pri, int raw, long val)	/* print sysfs code */
524 {
525 	const char *s = raw? NULL : sfsname(val);
526 
527 	if (s == NULL)
528 		prt_dec(pri, 0, val);
529 	else
530 		outstring(pri, s);
531 }
532 
533 void
prt_opn(private_t * pri,int raw,long val)534 prt_opn(private_t *pri, int raw, long val)	/* print open code */
535 {
536 	const char *s = raw? NULL : openarg(pri, val);
537 
538 	if (s == NULL)
539 		prt_oct(pri, 0, val);
540 	else
541 		outstring(pri, s);
542 }
543 
544 void
prt_sig(private_t * pri,int raw,long val)545 prt_sig(private_t *pri, int raw, long val)	/* print signal name */
546 {
547 	const char *s = raw? NULL : signame(pri, (int)val);
548 
549 	if (s == NULL)
550 		prt_hex(pri, 0, val);
551 	else
552 		outstring(pri, s);
553 }
554 
555 void
prt_smf(private_t * pri,int raw,long val)556 prt_smf(private_t *pri, int raw, long val) /* print streams message flags */
557 {
558 	switch (val) {
559 	case 0:
560 		prt_dec(pri, 0, val);
561 		break;
562 	case RS_HIPRI:
563 		if (raw)
564 			prt_hhx(pri, 0, val);
565 		else
566 			outstring(pri, "RS_HIPRI");
567 		break;
568 	default:
569 		prt_hhx(pri, 0, val);
570 		break;
571 	}
572 }
573 
574 void
prt_mtf(private_t * pri,int raw,long val)575 prt_mtf(private_t *pri, int raw, long val)	/* print mount flags */
576 {
577 	const char *s = raw? NULL : mountflags(pri, val);
578 
579 	if (s == NULL)
580 		prt_hex(pri, 0, val);
581 	else
582 		outstring(pri, s);
583 }
584 
585 void
prt_mft(private_t * pri,int raw,long val)586 prt_mft(private_t *pri, int raw, long val) /* print mount file system type */
587 {
588 	if (val >= 0 && val < 256)
589 		prt_dec(pri, 0, val);
590 	else if (raw)
591 		prt_hex(pri, 0, val);
592 	else
593 		prt_stg(pri, raw, val);
594 }
595 
596 #define	ISREAD(code) \
597 	((code) == SYS_read || (code) == SYS_pread || (code) == SYS_pread64 || \
598 	(code) == SYS_recv || (code) == SYS_recvfrom)
599 #define	ISWRITE(code) \
600 	((code) == SYS_write || (code) == SYS_pwrite || \
601 	(code) == SYS_pwrite64 || (code) == SYS_send || (code) == SYS_sendto)
602 
603 /* print contents of read() or write() I/O buffer */
604 void
prt_iob(private_t * pri,int raw,long val)605 prt_iob(private_t *pri, int raw, long val)
606 {
607 	const lwpstatus_t *Lsp = pri->lwpstat;
608 	int syscall = Lsp->pr_what;
609 	int fdp1 = pri->sys_args[0] + 1;
610 	ssize_t nbyte = ISWRITE(syscall)? pri->sys_args[2] :
611 	    (pri->Errno? 0 : pri->Rval1);
612 	int elsewhere = FALSE;		/* TRUE iff dumped elsewhere */
613 	char buffer[IOBSIZE];
614 
615 	pri->iob_buf[0] = '\0';
616 
617 	if (Lsp->pr_why == PR_SYSEXIT && nbyte > IOBSIZE) {
618 		if (ISREAD(syscall))
619 			elsewhere = prismember(&readfd, fdp1);
620 		else
621 			elsewhere = prismember(&writefd, fdp1);
622 	}
623 
624 	if (nbyte <= 0 || elsewhere)
625 		prt_hex(pri, 0, val);
626 	else {
627 		int nb = nbyte > IOBSIZE? IOBSIZE : (int)nbyte;
628 
629 		if (Pread(Proc, buffer, (size_t)nb, (long)val) != nb)
630 			prt_hex(pri, 0, val);
631 		else {
632 			pri->iob_buf[0] = '"';
633 			showbytes(buffer, nb, pri->iob_buf + 1);
634 			(void) strlcat(pri->iob_buf,
635 			    (nb == nbyte)?
636 			    (const char *)"\"" : (const char *)"\"..",
637 			    sizeof (pri->iob_buf));
638 			if (raw)
639 				prt_hex(pri, 0, val);
640 			else
641 				outstring(pri, pri->iob_buf);
642 		}
643 	}
644 }
645 #undef	ISREAD
646 #undef	ISWRITE
647 
648 void
prt_idt(private_t * pri,int raw,long val)649 prt_idt(private_t *pri, int raw, long val) /* print idtype_t, waitid() arg */
650 {
651 	const char *s = raw? NULL : idtype_enum(pri, val);
652 
653 	if (s == NULL)
654 		prt_dec(pri, 0, val);
655 	else
656 		outstring(pri, s);
657 }
658 
659 void
prt_wop(private_t * pri,int raw,long val)660 prt_wop(private_t *pri, int raw, long val)	/* print waitid() options */
661 {
662 	const char *s = raw? NULL : woptions(pri, (int)val);
663 
664 	if (s == NULL)
665 		prt_oct(pri, 0, val);
666 	else
667 		outstring(pri, s);
668 }
669 
670 void
prt_whn(private_t * pri,int raw,long val)671 prt_whn(private_t *pri, int raw, long val) /* print lseek() whence argument */
672 {
673 	const char *s = raw? NULL : whencearg(val);
674 
675 	if (s == NULL)
676 		prt_dec(pri, 0, val);
677 	else
678 		outstring(pri, s);
679 }
680 
681 /*ARGSUSED*/
682 void
prt_spm(private_t * pri,int raw,long val)683 prt_spm(private_t *pri, int raw, long val)	/* print sigprocmask argument */
684 {
685 	const char *s = NULL;
686 
687 	if (!raw) {
688 		switch (val) {
689 		case SIG_BLOCK:		s = "SIG_BLOCK";	break;
690 		case SIG_UNBLOCK:	s = "SIG_UNBLOCK";	break;
691 		case SIG_SETMASK:	s = "SIG_SETMASK";	break;
692 		}
693 	}
694 
695 	if (s == NULL)
696 		prt_dec(pri, 0, val);
697 	else
698 		outstring(pri, s);
699 }
700 
701 const char *
mmap_protect(private_t * pri,long arg)702 mmap_protect(private_t *pri, long arg)
703 {
704 	char *str = pri->code_buf;
705 
706 	if (arg & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
707 		return ((char *)NULL);
708 
709 	if (arg == PROT_NONE)
710 		return ("PROT_NONE");
711 
712 	*str = '\0';
713 	if (arg & PROT_READ)
714 		(void) strlcat(str, "|PROT_READ", sizeof (pri->code_buf));
715 	if (arg & PROT_WRITE)
716 		(void) strlcat(str, "|PROT_WRITE", sizeof (pri->code_buf));
717 	if (arg & PROT_EXEC)
718 		(void) strlcat(str, "|PROT_EXEC", sizeof (pri->code_buf));
719 	return ((const char *)(str + 1));
720 }
721 
722 const char *
mmap_type(private_t * pri,long arg)723 mmap_type(private_t *pri, long arg)
724 {
725 	char *str = pri->code_buf;
726 	size_t used;
727 
728 #define	CBSIZE	sizeof (pri->code_buf)
729 	switch (arg & MAP_TYPE) {
730 	case MAP_SHARED:
731 		used = strlcpy(str, "MAP_SHARED", CBSIZE);
732 		break;
733 	case MAP_PRIVATE:
734 		used = strlcpy(str, "MAP_PRIVATE", CBSIZE);
735 		break;
736 	default:
737 		used = snprintf(str, CBSIZE, "%ld", arg&MAP_TYPE);
738 		break;
739 	}
740 
741 	arg &= ~(_MAP_NEW|MAP_TYPE);
742 
743 	if (arg & ~(MAP_FIXED|MAP_RENAME|MAP_NORESERVE|MAP_ANON|MAP_ALIGN|
744 	    MAP_TEXT|MAP_INITDATA|MAP_32BIT))
745 		(void) snprintf(str + used, sizeof (pri->code_buf) - used,
746 		    "|0x%lX", arg);
747 	else {
748 		if (arg & MAP_FIXED)
749 			(void) strlcat(str, "|MAP_FIXED", CBSIZE);
750 		if (arg & MAP_RENAME)
751 			(void) strlcat(str, "|MAP_RENAME", CBSIZE);
752 		if (arg & MAP_NORESERVE)
753 			(void) strlcat(str, "|MAP_NORESERVE", CBSIZE);
754 		if (arg & MAP_ANON)
755 			(void) strlcat(str, "|MAP_ANON", CBSIZE);
756 		if (arg & MAP_ALIGN)
757 			(void) strlcat(str, "|MAP_ALIGN", CBSIZE);
758 		if (arg & MAP_TEXT)
759 			(void) strlcat(str, "|MAP_TEXT", CBSIZE);
760 		if (arg & MAP_INITDATA)
761 			(void) strlcat(str, "|MAP_INITDATA", CBSIZE);
762 		if (arg & MAP_32BIT)
763 			(void) strlcat(str, "|MAP_32BIT", CBSIZE);
764 	}
765 
766 	return ((const char *)str);
767 #undef CBSIZE
768 }
769 
770 void
prt_mpr(private_t * pri,int raw,long val)771 prt_mpr(private_t *pri, int raw, long val) /* print mmap()/mprotect() flags */
772 {
773 	const char *s = raw? NULL : mmap_protect(pri, val);
774 
775 	if (s == NULL)
776 		prt_hhx(pri, 0, val);
777 	else
778 		outstring(pri, s);
779 }
780 
781 void
prt_mty(private_t * pri,int raw,long val)782 prt_mty(private_t *pri, int raw, long val) /* print mmap() mapping type flags */
783 {
784 	const char *s = raw? NULL : mmap_type(pri, val);
785 
786 	if (s == NULL)
787 		prt_hhx(pri, 0, val);
788 	else
789 		outstring(pri, s);
790 }
791 
792 void
prt_mob(private_t * pri,int raw,long val)793 prt_mob(private_t *pri, int raw, long val) /* print mmapobj() flags */
794 {
795 	if (val == 0)
796 		prt_dec(pri, 0, val);
797 	else if (raw || (val & ~(MMOBJ_PADDING|MMOBJ_INTERPRET)) != 0)
798 		prt_hhx(pri, 0, val);
799 	else {
800 #define	CBSIZE	sizeof (pri->code_buf)
801 		char *s = pri->code_buf;
802 
803 		*s = '\0';
804 		if (val & MMOBJ_PADDING)
805 			(void) strlcat(s, "|MMOBJ_PADDING", CBSIZE);
806 		if (val & MMOBJ_INTERPRET)
807 			(void) strlcat(s, "|MMOBJ_INTERPRET", CBSIZE);
808 		outstring(pri, s + 1);
809 #undef CBSIZE
810 	}
811 }
812 
813 /*ARGSUSED*/
814 void
prt_mcf(private_t * pri,int raw,long val)815 prt_mcf(private_t *pri, int raw, long val)	/* print memcntl() function */
816 {
817 	const char *s = NULL;
818 
819 	if (!raw) {
820 		switch (val) {
821 		case MC_SYNC:		s = "MC_SYNC";		break;
822 		case MC_LOCK:		s = "MC_LOCK";		break;
823 		case MC_UNLOCK:		s = "MC_UNLOCK";	break;
824 		case MC_ADVISE:		s = "MC_ADVISE";	break;
825 		case MC_LOCKAS:		s = "MC_LOCKAS";	break;
826 		case MC_UNLOCKAS:	s = "MC_UNLOCKAS";	break;
827 		case MC_HAT_ADVISE:	s = "MC_HAT_ADVISE";	break;
828 		}
829 	}
830 
831 	if (s == NULL)
832 		prt_dec(pri, 0, val);
833 	else
834 		outstring(pri, s);
835 }
836 
837 void
prt_mad(private_t * pri,int raw,long val)838 prt_mad(private_t *pri, int raw, long val)	/* print madvise() argument */
839 {
840 	const char *s = NULL;
841 
842 	if (!raw) {
843 		switch (val) {
844 		case MADV_NORMAL:	s = "MADV_NORMAL";	break;
845 		case MADV_RANDOM:	s = "MADV_RANDOM";	break;
846 		case MADV_SEQUENTIAL:	s = "MADV_SEQUENTIAL";	break;
847 		case MADV_WILLNEED:	s = "MADV_WILLNEED";	break;
848 		case MADV_DONTNEED:	s = "MADV_DONTNEED";	break;
849 		case MADV_FREE:		s = "MADV_FREE";	break;
850 		case MADV_ACCESS_DEFAULT: s = "MADV_ACCESS_DEFAULT";	break;
851 		case MADV_ACCESS_LWP:	s = "MADV_ACCESS_LWP";	break;
852 		case MADV_ACCESS_MANY:	s = "MADV_ACCESS_MANY";	break;
853 		case MADV_PURGE:	s = "MADV_PURGE";	break;
854 		}
855 	}
856 
857 	if (s == NULL)
858 		prt_dec(pri, 0, val);
859 	else
860 		outstring(pri, s);
861 }
862 
863 void
prt_mc4(private_t * pri,int raw,long val)864 prt_mc4(private_t *pri, int raw, long val) /* print memcntl() (4th) argument */
865 {
866 	if (val == 0)
867 		prt_dec(pri, 0, val);
868 	else if (raw)
869 		prt_hhx(pri, 0, val);
870 	else {
871 		char *s = NULL;
872 
873 #define	CBSIZE	sizeof (pri->code_buf)
874 		/* cheating -- look at memcntl func */
875 		switch (pri->sys_args[2]) {
876 		case MC_ADVISE:
877 			prt_mad(pri, 0, val);
878 			return;
879 
880 		case MC_SYNC:
881 			if ((val & ~(MS_SYNC|MS_ASYNC|MS_INVALIDATE)) == 0) {
882 				*(s = pri->code_buf) = '\0';
883 				if (val & MS_SYNC)
884 					(void) strlcat(s, "|MS_SYNC", CBSIZE);
885 				if (val & MS_ASYNC)
886 					(void) strlcat(s, "|MS_ASYNC", CBSIZE);
887 				if (val & MS_INVALIDATE)
888 					(void) strlcat(s, "|MS_INVALIDATE",
889 					    CBSIZE);
890 			}
891 			break;
892 
893 		case MC_LOCKAS:
894 		case MC_UNLOCKAS:
895 			if ((val & ~(MCL_CURRENT|MCL_FUTURE)) == 0) {
896 				*(s = pri->code_buf) = '\0';
897 				if (val & MCL_CURRENT)
898 					(void) strlcat(s, "|MCL_CURRENT",
899 					    CBSIZE);
900 				if (val & MCL_FUTURE)
901 					(void) strlcat(s, "|MCL_FUTURE",
902 					    CBSIZE);
903 			}
904 			break;
905 		}
906 #undef CBSIZE
907 
908 		if (s == NULL || *s == '\0')
909 			prt_hhx(pri, 0, val);
910 		else
911 			outstring(pri, ++s);
912 	}
913 }
914 
915 void
prt_mc5(private_t * pri,int raw,long val)916 prt_mc5(private_t *pri, int raw, long val) /* print memcntl() (5th) argument */
917 {
918 	char *s;
919 
920 #define	CBSIZE	sizeof (pri->code_buf)
921 	if (val == 0)
922 		prt_dec(pri, 0, val);
923 	else if (raw || (val & ~VALID_ATTR))
924 		prt_hhx(pri, 0, val);
925 	else {
926 		s = pri->code_buf;
927 		*s = '\0';
928 		if (val & SHARED)
929 			(void) strlcat(s, "|SHARED", CBSIZE);
930 		if (val & PRIVATE)
931 			(void) strlcat(s, "|PRIVATE", CBSIZE);
932 		if (val & PROT_READ)
933 			(void) strlcat(s, "|PROT_READ", CBSIZE);
934 		if (val & PROT_WRITE)
935 			(void) strlcat(s, "|PROT_WRITE", CBSIZE);
936 		if (val & PROT_EXEC)
937 			(void) strlcat(s, "|PROT_EXEC", CBSIZE);
938 		if (*s == '\0')
939 			prt_hhx(pri, 0, val);
940 		else
941 			outstring(pri, ++s);
942 	}
943 #undef CBSIZE
944 }
945 
946 void
prt_ulm(private_t * pri,int raw,long val)947 prt_ulm(private_t *pri, int raw, long val)	/* print ulimit() argument */
948 {
949 	const char *s = NULL;
950 
951 	if (!raw) {
952 		switch (val) {
953 		case UL_GFILLIM:	s = "UL_GFILLIM";	break;
954 		case UL_SFILLIM:	s = "UL_SFILLIM";	break;
955 		case UL_GMEMLIM:	s = "UL_GMEMLIM";	break;
956 		case UL_GDESLIM:	s = "UL_GDESLIM";	break;
957 		}
958 	}
959 
960 	if (s == NULL)
961 		prt_dec(pri, 0, val);
962 	else
963 		outstring(pri, s);
964 }
965 
966 void
prt_rlm(private_t * pri,int raw,long val)967 prt_rlm(private_t *pri, int raw, long val) /* print get/setrlimit() argument */
968 {
969 	const char *s = NULL;
970 
971 	if (!raw) {
972 		switch (val) {
973 		case RLIMIT_CPU:	s = "RLIMIT_CPU";	break;
974 		case RLIMIT_FSIZE:	s = "RLIMIT_FSIZE";	break;
975 		case RLIMIT_DATA:	s = "RLIMIT_DATA";	break;
976 		case RLIMIT_STACK:	s = "RLIMIT_STACK";	break;
977 		case RLIMIT_CORE:	s = "RLIMIT_CORE";	break;
978 		case RLIMIT_NOFILE:	s = "RLIMIT_NOFILE";	break;
979 		case RLIMIT_VMEM:	s = "RLIMIT_VMEM";	break;
980 		}
981 	}
982 
983 	if (s == NULL)
984 		prt_dec(pri, 0, val);
985 	else
986 		outstring(pri, s);
987 }
988 
989 void
prt_cnf(private_t * pri,int raw,long val)990 prt_cnf(private_t *pri, int raw, long val)	/* print sysconfig code */
991 {
992 	const char *s = raw? NULL : sconfname(val);
993 
994 	if (s == NULL)
995 		prt_dec(pri, 0, val);
996 	else
997 		outstring(pri, s);
998 }
999 
1000 void
prt_inf(private_t * pri,int raw,long val)1001 prt_inf(private_t *pri, int raw, long val)	/* print sysinfo code */
1002 {
1003 	const char *s = NULL;
1004 
1005 	if (!raw) {
1006 		switch (val) {
1007 		case SI_SYSNAME:	s = "SI_SYSNAME";	break;
1008 		case SI_HOSTNAME:	s = "SI_HOSTNAME";	break;
1009 		case SI_RELEASE:	s = "SI_RELEASE";	break;
1010 		case SI_VERSION:	s = "SI_VERSION";	break;
1011 		case SI_MACHINE:	s = "SI_MACHINE";	break;
1012 		case SI_ARCHITECTURE:	s = "SI_ARCHITECTURE";	break;
1013 		case SI_ARCHITECTURE_32:s = "SI_ARCHITECTURE_32"; break;
1014 		case SI_ARCHITECTURE_64:s = "SI_ARCHITECTURE_64"; break;
1015 		case SI_ARCHITECTURE_K:	s = "SI_ARCHITECTURE_K"; break;
1016 		case SI_HW_SERIAL:	s = "SI_HW_SERIAL";	break;
1017 		case SI_HW_PROVIDER:	s = "SI_HW_PROVIDER";	break;
1018 		case SI_SRPC_DOMAIN:	s = "SI_SRPC_DOMAIN";	break;
1019 		case SI_SET_HOSTNAME:	s = "SI_SET_HOSTNAME";	break;
1020 		case SI_SET_SRPC_DOMAIN: s = "SI_SET_SRPC_DOMAIN"; break;
1021 		case SI_PLATFORM:	s = "SI_PLATFORM";	break;
1022 		case SI_ISALIST:	s = "SI_ISALIST";	break;
1023 		case SI_DHCP_CACHE:	s = "SI_DHCP_CACHE";	break;
1024 		}
1025 	}
1026 
1027 	if (s == NULL)
1028 		prt_dec(pri, 0, val);
1029 	else
1030 		outstring(pri, s);
1031 }
1032 
1033 void
prt_ptc(private_t * pri,int raw,long val)1034 prt_ptc(private_t *pri, int raw, long val)	/* print pathconf code */
1035 {
1036 	const char *s = raw? NULL : pathconfname(val);
1037 
1038 	if (s == NULL)
1039 		prt_dec(pri, 0, val);
1040 	else
1041 		outstring(pri, s);
1042 }
1043 
1044 void
prt_fui(private_t * pri,int raw,long val)1045 prt_fui(private_t *pri, int raw, long val) /* print fusers() input argument */
1046 {
1047 	const char *s = raw? NULL : fuiname(val);
1048 
1049 	if (s == NULL)
1050 		prt_hhx(pri, 0, val);
1051 	else
1052 		outstring(pri, s);
1053 }
1054 
1055 void
prt_lwf(private_t * pri,int raw,long val)1056 prt_lwf(private_t *pri, int raw, long val)	/* print lwp_create() flags */
1057 {
1058 	char *s;
1059 
1060 	if (val == 0)
1061 		prt_dec(pri, 0, val);
1062 	else if (raw ||
1063 	    (val & ~(LWP_DAEMON|LWP_DETACHED|LWP_SUSPENDED)))
1064 		prt_hhx(pri, 0, val);
1065 	else {
1066 #define	CBSIZE	sizeof (pri->code_buf)
1067 		s = pri->code_buf;
1068 		*s = '\0';
1069 		if (val & LWP_DAEMON)
1070 			(void) strlcat(s, "|LWP_DAEMON", CBSIZE);
1071 		if (val & LWP_DETACHED)
1072 			(void) strlcat(s, "|LWP_DETACHED", CBSIZE);
1073 		if (val & LWP_SUSPENDED)
1074 			(void) strlcat(s, "|LWP_SUSPENDED", CBSIZE);
1075 		outstring(pri, ++s);
1076 #undef CBSIZE
1077 	}
1078 }
1079 
1080 void
prt_itm(private_t * pri,int raw,long val)1081 prt_itm(private_t *pri, int raw, long val) /* print [get|set]itimer() arg */
1082 {
1083 	const char *s = NULL;
1084 
1085 	if (!raw) {
1086 		switch (val) {
1087 		case ITIMER_REAL:	s = "ITIMER_REAL";	break;
1088 		case ITIMER_VIRTUAL:	s = "ITIMER_VIRTUAL";	break;
1089 		case ITIMER_PROF:	s = "ITIMER_PROF";	break;
1090 #ifdef ITIMER_REALPROF
1091 		case ITIMER_REALPROF:	s = "ITIMER_REALPROF";	break;
1092 #endif
1093 		}
1094 	}
1095 
1096 	if (s == NULL)
1097 		prt_dec(pri, 0, val);
1098 	else
1099 		outstring(pri, s);
1100 }
1101 
1102 void
prt_mod(private_t * pri,int raw,long val)1103 prt_mod(private_t *pri, int raw, long val)	/* print modctl() code */
1104 {
1105 	const char *s = NULL;
1106 
1107 	if (!raw) {
1108 		switch (val) {
1109 		case MODLOAD:		s = "MODLOAD";		break;
1110 		case MODUNLOAD:		s = "MODUNLOAD";	break;
1111 		case MODINFO:		s = "MODINFO";		break;
1112 		case MODRESERVED:	s = "MODRESERVED";	break;
1113 		case MODSETMINIROOT:	s = "MODSETMINIROOT";	break;
1114 		case MODADDMAJBIND:	s = "MODADDMAJBIND";	break;
1115 		case MODGETPATH:	s = "MODGETPATH";	break;
1116 		case MODGETPATHLEN:	s = "MODGETPATHLEN";	break;
1117 		case MODREADSYSBIND:	s = "MODREADSYSBIND";	break;
1118 		case MODGETMAJBIND:	s = "MODGETMAJBIND";	break;
1119 		case MODGETNAME:	s = "MODGETNAME";	break;
1120 		case MODSIZEOF_DEVID:	s = "MODSIZEOF_DEVID";	break;
1121 		case MODGETDEVID:	s = "MODGETDEVID";	break;
1122 		case MODSIZEOF_MINORNAME: s = "MODSIZEOF_MINORNAME"; break;
1123 		case MODGETMINORNAME:	s = "MODGETMINORNAME";	break;
1124 		case MODGETFBNAME:	s = "MODGETFBNAME";	break;
1125 		case MODEVENTS:		s = "MODEVENTS";	break;
1126 		case MODREREADDACF:	s = "MODREREADDACF";	break;
1127 		case MODLOADDRVCONF:	s = "MODLOADDRVCONF";	break;
1128 		case MODUNLOADDRVCONF:	s = "MODUNLOADDRVCONF";	break;
1129 		case MODREMMAJBIND:	s = "MODREMMAJBIND";	break;
1130 		case MODDEVT2INSTANCE:	s = "MODDEVT2INSTANCE";	break;
1131 		case MODGETDEVFSPATH_LEN: s = "MODGETDEVFSPATH_LEN"; break;
1132 		case MODGETDEVFSPATH:	s = "MODGETDEVFSPATH";	break;
1133 		case MODDEVID2PATHS:	s = "MODDEVID2PATHS";	break;
1134 		case MODSETDEVPOLICY:	s = "MODSETDEVPOLICY";	break;
1135 		case MODGETDEVPOLICY:	s = "MODGETDEVPOLICY";	break;
1136 		case MODALLOCPRIV:	s = "MODALLOCPRIV";	break;
1137 		case MODGETDEVPOLICYBYNAME:
1138 					s = "MODGETDEVPOLICYBYNAME"; break;
1139 		case MODLOADMINORPERM:	s = "MODLOADMINORPERM"; break;
1140 		case MODADDMINORPERM:	s = "MODADDMINORPERM"; break;
1141 		case MODREMMINORPERM:	s = "MODREMMINORPERM"; break;
1142 		case MODREMDRVCLEANUP:	s = "MODREMDRVCLEANUP"; break;
1143 		case MODDEVEXISTS:	s = "MODDEVEXISTS"; break;
1144 		case MODDEVREADDIR:	s = "MODDEVREADDIR"; break;
1145 		case MODDEVEMPTYDIR:	s = "MODDEVEMPTYDIR"; break;
1146 		case MODDEVNAME:	s = "MODDEVNAME"; break;
1147 		case MODGETDEVFSPATH_MI_LEN:
1148 					s = "MODGETDEVFSPATH_MI_LEN"; break;
1149 		case MODGETDEVFSPATH_MI:
1150 					s = "MODGETDEVFSPATH_MI"; break;
1151 		case MODREMDRVALIAS:	s = "MODREMDRVALIAS"; break;
1152 		case MODHPOPS:	s = "MODHPOPS"; break;
1153 		}
1154 	}
1155 
1156 	if (s == NULL)
1157 		prt_dec(pri, 0, val);
1158 	else
1159 		outstring(pri, s);
1160 }
1161 
1162 void
prt_acl(private_t * pri,int raw,long val)1163 prt_acl(private_t *pri, int raw, long val)	/* print acl() code */
1164 {
1165 	const char *s = NULL;
1166 
1167 	if (!raw) {
1168 		switch (val) {
1169 		case GETACL:		s = "GETACL";		break;
1170 		case SETACL:		s = "SETACL";		break;
1171 		case GETACLCNT:		s = "GETACLCNT";	break;
1172 		case ACE_GETACL:	s = "ACE_GETACL";	break;
1173 		case ACE_SETACL:	s = "ACE_SETACL";	break;
1174 		case ACE_GETACLCNT:	s = "ACE_GETACLCNT";	break;
1175 		}
1176 	}
1177 
1178 	if (s == NULL)
1179 		prt_dec(pri, 0, val);
1180 	else
1181 		outstring(pri, s);
1182 }
1183 
1184 void
prt_aio(private_t * pri,int raw,long val)1185 prt_aio(private_t *pri, int raw, long val)	/* print kaio() code */
1186 {
1187 	const char *s = NULL;
1188 	char buf[32];
1189 
1190 	if (!raw) {
1191 		switch (val & ~AIO_POLL_BIT) {
1192 		case AIOREAD:		s = "AIOREAD";		break;
1193 		case AIOWRITE:		s = "AIOWRITE";		break;
1194 		case AIOWAIT:		s = "AIOWAIT";		break;
1195 		case AIOCANCEL:		s = "AIOCANCEL";	break;
1196 		case AIONOTIFY:		s = "AIONOTIFY";	break;
1197 		case AIOINIT:		s = "AIOINIT";		break;
1198 		case AIOSTART:		s = "AIOSTART";		break;
1199 		case AIOLIO:		s = "AIOLIO";		break;
1200 		case AIOSUSPEND:	s = "AIOSUSPEND";	break;
1201 		case AIOERROR:		s = "AIOERROR";		break;
1202 		case AIOLIOWAIT:	s = "AIOLIOWAIT";	break;
1203 		case AIOAREAD:		s = "AIOAREAD";		break;
1204 		case AIOAWRITE:		s = "AIOAWRITE";	break;
1205 		/*
1206 		 * We have to hardcode the values for the 64-bit versions of
1207 		 * these calls, because <sys/aio.h> defines them to be identical
1208 		 * when compiled 64-bit.  If our target is 32-bit, we still need
1209 		 * to decode them correctly.
1210 		 */
1211 		case 13:		s = "AIOLIO64";		break;
1212 		case 14:		s = "AIOSUSPEND64";	break;
1213 		case 15:		s = "AUIOERROR64";	break;
1214 		case 16:		s = "AIOLIOWAIT64";	break;
1215 		case 17:		s = "AIOAREAD64";	break;
1216 		case 18:		s = "AIOAWRITE64";	break;
1217 		case 19:		s = "AIOCANCEL64";	break;
1218 
1219 		/*
1220 		 * AIOFSYNC doesn't correspond to a syscall.
1221 		 */
1222 		case AIOWAITN:		s = "AIOWAITN";		break;
1223 		}
1224 		if (s != NULL && (val & AIO_POLL_BIT)) {
1225 			(void) strlcpy(buf, s, sizeof (buf));
1226 			(void) strlcat(buf, "|AIO_POLL_BIT", sizeof (buf));
1227 			s = (const char *)buf;
1228 		}
1229 	}
1230 
1231 	if (s == NULL)
1232 		prt_dec(pri, 0, val);
1233 	else
1234 		outstring(pri, s);
1235 }
1236 
1237 void
prt_aud(private_t * pri,int raw,long val)1238 prt_aud(private_t *pri, int raw, long val)	/* print auditsys() code */
1239 {
1240 	const char *s = NULL;
1241 
1242 	if (!raw) {
1243 		switch (val) {
1244 		case BSM_GETAUID:	s = "BSM_GETAUID";	break;
1245 		case BSM_SETAUID:	s = "BSM_SETAUID";	break;
1246 		case BSM_GETAUDIT:	s = "BSM_GETAUDIT";	break;
1247 		case BSM_SETAUDIT:	s = "BSM_SETAUDIT";	break;
1248 		case BSM_AUDIT:		s = "BSM_AUDIT";	break;
1249 		case BSM_AUDITCTL:	s = "BSM_AUDITCTL";	break;
1250 		case BSM_GETAUDIT_ADDR:	s = "BSM_GETAUDIT_ADDR"; break;
1251 		case BSM_SETAUDIT_ADDR:	s = "BSM_SETAUDIT_ADDR"; break;
1252 		}
1253 	}
1254 
1255 	if (s == NULL)
1256 		prt_dec(pri, 0, val);
1257 	else
1258 		outstring(pri, s);
1259 }
1260 
1261 void
prt_cor(private_t * pri,int raw,long val)1262 prt_cor(private_t *pri, int raw, long val)	/* print corectl() subcode */
1263 {
1264 	const char *s = NULL;
1265 
1266 	if (!raw) {
1267 		switch (val) {
1268 		case CC_SET_OPTIONS:
1269 			s = "CC_SET_OPTIONS";		break;
1270 		case CC_GET_OPTIONS:
1271 			s = "CC_GET_OPTIONS";		break;
1272 		case CC_SET_GLOBAL_PATH:
1273 			s = "CC_SET_GLOBAL_PATH";	break;
1274 		case CC_GET_GLOBAL_PATH:
1275 			s = "CC_GET_GLOBAL_PATH";	break;
1276 		case CC_SET_PROCESS_PATH:
1277 			s = "CC_SET_PROCESS_PATH";	break;
1278 		case CC_GET_PROCESS_PATH:
1279 			s = "CC_GET_PROCESS_PATH";	break;
1280 		case CC_SET_GLOBAL_CONTENT:
1281 			s = "CC_SET_GLOBAL_CONTENT";	break;
1282 		case CC_GET_GLOBAL_CONTENT:
1283 			s = "CC_GET_GLOBAL_CONTENT";	break;
1284 		case CC_SET_PROCESS_CONTENT:
1285 			s = "CC_SET_PROCESS_CONTENT";	break;
1286 		case CC_GET_PROCESS_CONTENT:
1287 			s = "CC_GET_PROCESS_CONTENT";	break;
1288 		case CC_SET_DEFAULT_PATH:
1289 			s = "CC_SET_DEFAULT_PATH";	break;
1290 		case CC_GET_DEFAULT_PATH:
1291 			s = "CC_GET_DEFAULT_PATH";	break;
1292 		case CC_SET_DEFAULT_CONTENT:
1293 			s = "CC_SET_DEFAULT_CONTENT";	break;
1294 		case CC_GET_DEFAULT_CONTENT:
1295 			s = "CC_GET_DEFAULT_CONTENT";	break;
1296 		}
1297 	}
1298 
1299 	if (s == NULL)
1300 		prt_dec(pri, 0, val);
1301 	else
1302 		outstring(pri, s);
1303 }
1304 
1305 void
prt_cco(private_t * pri,int raw,long val)1306 prt_cco(private_t *pri, int raw, long val)	/* print corectl() options */
1307 {
1308 	char *s;
1309 
1310 	if (val == 0)
1311 		prt_dec(pri, 0, val);
1312 	else if (raw || (val & ~CC_OPTIONS))
1313 		prt_hhx(pri, 0, val);
1314 	else {
1315 #define	CBSIZE	sizeof (pri->code_buf)
1316 		s = pri->code_buf;
1317 		*s = '\0';
1318 		if (val & CC_GLOBAL_PATH)
1319 			(void) strlcat(s, "|CC_GLOBAL_PATH", CBSIZE);
1320 		if (val & CC_PROCESS_PATH)
1321 			(void) strlcat(s, "|CC_PROCESS_PATH", CBSIZE);
1322 		if (val & CC_GLOBAL_SETID)
1323 			(void) strlcat(s, "|CC_GLOBAL_SETID", CBSIZE);
1324 		if (val & CC_PROCESS_SETID)
1325 			(void) strlcat(s, "|CC_PROCESS_SETID", CBSIZE);
1326 		if (val & CC_GLOBAL_LOG)
1327 			(void) strlcat(s, "|CC_GLOBAL_LOG", CBSIZE);
1328 		if (*s == '\0')
1329 			prt_hhx(pri, 0, val);
1330 		else
1331 			outstring(pri, ++s);
1332 #undef CBSIZE
1333 	}
1334 }
1335 
1336 void
prt_ccc(private_t * pri,int raw,long val)1337 prt_ccc(private_t *pri, int raw, long val)	/* print corectl() content */
1338 {
1339 	core_content_t ccc;
1340 
1341 	if (Pread(Proc, &ccc, sizeof (ccc), val) != sizeof (ccc))
1342 		prt_hex(pri, 0, val);
1343 	else if (!raw && proc_content2str(ccc, pri->code_buf,
1344 	    sizeof (pri->code_buf)) >= 0)
1345 		outstring(pri, pri->code_buf);
1346 	else
1347 		prt_hhx(pri, 0, (long)ccc);
1348 }
1349 
1350 void
prt_rcc(private_t * pri,int raw,long val)1351 prt_rcc(private_t *pri, int raw, long val)	/* print corectl() ret. cont. */
1352 {
1353 	core_content_t ccc;
1354 
1355 	if (pri->Errno || Pread(Proc, &ccc, sizeof (ccc), val) != sizeof (ccc))
1356 		prt_hex(pri, 0, val);
1357 	else if (!raw && proc_content2str(ccc, pri->code_buf,
1358 	    sizeof (pri->code_buf)) >= 0)
1359 		outstring(pri, pri->code_buf);
1360 	else
1361 		prt_hhx(pri, 0, (long)ccc);
1362 }
1363 
1364 void
prt_cpc(private_t * pri,int raw,long val)1365 prt_cpc(private_t *pri, int raw, long val)	/* print cpc() subcode */
1366 {
1367 	const char *s = NULL;
1368 
1369 	if (!raw) {
1370 		switch (val) {
1371 		case CPC_BIND:		s = "CPC_BIND";		break;
1372 		case CPC_SAMPLE:	s = "CPC_SAMPLE";	break;
1373 		case CPC_INVALIDATE:	s = "CPC_INVALIDATE";	break;
1374 		case CPC_RELE:		s = "CPC_RELE";		break;
1375 		case CPC_EVLIST_SIZE:	s = "CPC_EVLIST_SIZE";	break;
1376 		case CPC_LIST_EVENTS:	s = "CPC_LIST_EVENTS";	break;
1377 		case CPC_ATTRLIST_SIZE:	s = "CPC_ATTRLIST_SIZE"; break;
1378 		case CPC_LIST_ATTRS:	s = "CPC_LIST_ATTRS";	break;
1379 		case CPC_IMPL_NAME:	s = "CPC_IMPL_NAME";	break;
1380 		case CPC_CPUREF:	s = "CPC_CPUREF";	break;
1381 		case CPC_USR_EVENTS:	s = "CPC_USR_EVENTS";	break;
1382 		case CPC_SYS_EVENTS:	s = "CPC_SYS_EVENTS";	break;
1383 		case CPC_NPIC:		s = "CPC_NPIC";		break;
1384 		case CPC_CAPS:		s = "CPC_CAPS";		break;
1385 		case CPC_ENABLE:	s = "CPC_ENABLE";	break;
1386 		case CPC_DISABLE:	s = "CPC_DISABLE";	break;
1387 		}
1388 	}
1389 
1390 	if (s == NULL)
1391 		prt_dec(pri, 0, val);
1392 	else
1393 		outstring(pri, s);
1394 }
1395 
1396 void
outstring(private_t * pri,const char * s)1397 outstring(private_t *pri, const char *s)
1398 {
1399 	int len = strlen(s);
1400 
1401 	GROW(len);
1402 	(void) strcpy(pri->sys_string + pri->sys_leng, s);
1403 	pri->sys_leng += len;
1404 }
1405 
1406 void
grow(private_t * pri,int nbyte)1407 grow(private_t *pri, int nbyte)	/* reallocate format buffer if necessary */
1408 {
1409 	while (pri->sys_leng + nbyte >= pri->sys_ssize)
1410 		pri->sys_string = my_realloc(pri->sys_string,
1411 		    pri->sys_ssize *= 2, "format buffer");
1412 }
1413 
1414 void
prt_clc(private_t * pri,int raw,long val)1415 prt_clc(private_t *pri, int raw, long val)
1416 {
1417 	const char *s = NULL;
1418 
1419 	if (!raw) {
1420 		switch (val) {
1421 		case CL_INITIALIZE:	s = "CL_INITIALIZE";	break;
1422 		case CL_CONFIG:		s = "CL_CONFIG";	break;
1423 		}
1424 	}
1425 
1426 	if (s == NULL)
1427 		prt_dec(pri, 0, val);
1428 	else
1429 		outstring(pri, s);
1430 }
1431 
1432 void
prt_clf(private_t * pri,int raw,long val)1433 prt_clf(private_t *pri, int raw, long val)
1434 {
1435 	const char *s = NULL;
1436 
1437 	if (!raw) {
1438 		switch (pri->sys_args[0]) {
1439 		case CL_CONFIG:
1440 			switch (pri->sys_args[1]) {
1441 			case CL_NODEID:
1442 				s = "CL_NODEID";		break;
1443 			case CL_HIGHEST_NODEID:
1444 				s = "CL_HIGHEST_NODEID";	break;
1445 			}
1446 			break;
1447 		case CL_INITIALIZE:
1448 			switch (pri->sys_args[1]) {
1449 			case CL_GET_BOOTFLAG:
1450 				s = "CL_GET_BOOTFLAG";		break;
1451 			}
1452 			break;
1453 		}
1454 	}
1455 
1456 	if (s == NULL)
1457 		prt_dec(pri, 0, val);
1458 	else
1459 		outstring(pri, s);
1460 }
1461 
1462 void
prt_sqc(private_t * pri,int raw,long val)1463 prt_sqc(private_t *pri, int raw, long val)	/* print sigqueue() si_code */
1464 {
1465 	const char *s = NULL;
1466 
1467 	if (!raw) {
1468 		switch ((int)val) {
1469 		case SI_QUEUE:		s = "SI_QUEUE";		break;
1470 		case SI_TIMER:		s = "SI_TIMER";		break;
1471 		case SI_ASYNCIO:	s = "SI_ASYNCIO";	break;
1472 		case SI_MESGQ:		s = "SI_MESGQ";		break;
1473 		}
1474 	}
1475 
1476 	if (s == NULL)
1477 		prt_dec(pri, 0, val);
1478 	else
1479 		outstring(pri, s);
1480 }
1481 
1482 /*
1483  * print priocntlsys() (key, value) pair key.
1484  */
1485 void
print_pck(private_t * pri,int raw,long val)1486 print_pck(private_t *pri, int raw, long val)
1487 {
1488 	const char	*s = NULL;
1489 	char		clname[PC_CLNMSZ];
1490 
1491 	if ((pri->sys_args[2] != PC_GETXPARMS &&
1492 	    pri->sys_args[2] != PC_SETXPARMS) || val == 0 || raw) {
1493 		prt_dec(pri, 0, val);
1494 		return;
1495 	}
1496 
1497 	if (pri->sys_args[3] == 0) {
1498 		if (val == PC_KY_CLNAME) {
1499 			s = "PC_KY_CLNAME";
1500 			outstring(pri, s);
1501 		} else
1502 			prt_dec(pri, 0, val);
1503 		return;
1504 	}
1505 
1506 	if (Pread(Proc, &clname, PC_CLNMSZ, pri->sys_args[3]) != PC_CLNMSZ) {
1507 		prt_dec(pri, 0, val);
1508 		return;
1509 	}
1510 
1511 	if (strcmp(clname, "TS") == 0) {
1512 		switch (val) {
1513 		case TS_KY_UPRILIM:	s = "TS_KY_UPRILIM";	break;
1514 		case TS_KY_UPRI:	s = "TS_KY_UPRI";	break;
1515 		default:					break;
1516 		}
1517 	} else if (strcmp(clname, "IA") == 0) {
1518 		switch (val) {
1519 		case IA_KY_UPRILIM:	s = "IA_KY_UPRILIM";	break;
1520 		case IA_KY_UPRI:	s = "IA_KY_UPRI";	break;
1521 		case IA_KY_MODE:	s = "IA_KY_MODE";	break;
1522 		default:					break;
1523 		}
1524 	} else if (strcmp(clname, "RT") == 0) {
1525 		switch (val) {
1526 		case RT_KY_PRI:		s = "RT_KY_PRI";	break;
1527 		case RT_KY_TQSECS:	s = "RT_KY_TQSECS";	break;
1528 		case RT_KY_TQNSECS:	s = "RT_KY_TQNSECS";	break;
1529 		case RT_KY_TQSIG:	s = "RT_KY_TQSIG";	break;
1530 		default:					break;
1531 		}
1532 	} else if (strcmp(clname, "FSS") == 0) {
1533 		switch (val) {
1534 		case FSS_KY_UPRILIM:	s = "FSS_KY_UPRILIM";	break;
1535 		case FSS_KY_UPRI:	s = "FSS_KY_UPRI";	break;
1536 		default:					break;
1537 		}
1538 	} else if (strcmp(clname, "FX") == 0) {
1539 		switch (val) {
1540 		case FX_KY_UPRILIM:	s = "FX_KY_UPRILIM";	break;
1541 		case FX_KY_UPRI:	s = "FX_KY_UPRI";	break;
1542 		case FX_KY_TQSECS:	s = "FX_KY_TQSECS";	break;
1543 		case FX_KY_TQNSECS:	s = "FX_KY_TQNSECS";	break;
1544 		default:					break;
1545 		}
1546 	}
1547 
1548 	if (s == NULL)
1549 		prt_dec(pri, 0, val);
1550 	else
1551 		outstring(pri, s);
1552 }
1553 
1554 /*
1555  * print priocntlsys() fourth argument.
1556  */
1557 /*ARGSUSED*/
1558 void
prt_pc4(private_t * pri,int raw,long val)1559 prt_pc4(private_t *pri, int raw, long val)
1560 {
1561 	/* look at pricntlsys function */
1562 	if ((pri->sys_args[2] != PC_GETXPARMS &&
1563 	    pri->sys_args[2] != PC_SETXPARMS))
1564 		prt_hex(pri, 0, val);
1565 	else if (val)
1566 		prt_stg(pri, 0, val);
1567 	else
1568 		prt_dec(pri, 0, val);
1569 }
1570 
1571 /*
1572  * print priocntlsys() (key, value) pairs (5th argument).
1573  */
1574 /*ARGSUSED*/
1575 void
prt_pc5(private_t * pri,int raw,long val)1576 prt_pc5(private_t *pri, int raw, long val)
1577 {
1578 	pc_vaparms_t	prms;
1579 	pc_vaparm_t	*vpp = &prms.pc_parms[0];
1580 	uint_t		cnt;
1581 
1582 
1583 	/* look at pricntlsys function */
1584 	if ((pri->sys_args[2] != PC_GETXPARMS &&
1585 	    pri->sys_args[2] != PC_SETXPARMS) || val == 0) {
1586 		prt_dec(pri, 0, 0);
1587 		return;
1588 	}
1589 
1590 	if (Pread(Proc, &prms, sizeof (prms), val) != sizeof (prms)) {
1591 		prt_hex(pri, 0, val);
1592 		return;
1593 	}
1594 
1595 	if ((cnt = prms.pc_vaparmscnt) > PC_VAPARMCNT)
1596 		return;
1597 
1598 	for (; cnt--; vpp++) {
1599 		print_pck(pri, 0, vpp->pc_key);
1600 		outstring(pri, ", ");
1601 		prt_hex(pri, 0, (long)vpp->pc_parm);
1602 		outstring(pri, ", ");
1603 	}
1604 
1605 	prt_dec(pri, 0, PC_KY_NULL);
1606 }
1607 
1608 
1609 void
prt_psflags(private_t * pri,secflagset_t val)1610 prt_psflags(private_t *pri, secflagset_t val)
1611 {
1612 	size_t len;
1613 	char *ptr;
1614 	char str[1024];
1615 
1616 	if (val == 0) {
1617 		outstring(pri, "0x0");
1618 		return;
1619 	}
1620 
1621 	*str = '\0';
1622 	if (secflag_isset(val, PROC_SEC_ASLR)) {
1623 		(void) strlcat(str, "|PROC_SEC_ASLR", sizeof (str));
1624 		secflag_clear(&val, PROC_SEC_ASLR);
1625 	}
1626 	if (secflag_isset(val, PROC_SEC_FORBIDNULLMAP)) {
1627 		(void) strlcat(str, "|PROC_SEC_FORBIDNULLMAP",
1628 		    sizeof (str));
1629 		secflag_clear(&val, PROC_SEC_FORBIDNULLMAP);
1630 	}
1631 	if (secflag_isset(val, PROC_SEC_NOEXECSTACK)) {
1632 		(void) strlcat(str, "|PROC_SEC_NOEXECSTACK",
1633 		    sizeof (str));
1634 		secflag_clear(&val, PROC_SEC_NOEXECSTACK);
1635 	}
1636 
1637 	if (val != 0) {
1638 		len = strlen(str);
1639 		ptr = str + len;
1640 		(void) snprintf(ptr, sizeof (str) - len, "|%#x", val);
1641 	}
1642 
1643 	outstring(pri, str + 1);
1644 }
1645 
1646 /*
1647  * Print a psecflags(2) delta
1648  */
1649 void
prt_psdelta(private_t * pri,int raw,long value)1650 prt_psdelta(private_t *pri, int raw, long value)
1651 {
1652 	secflagdelta_t psd;
1653 
1654 	if ((raw != 0) ||
1655 	    (Pread(Proc, &psd, sizeof (psd), value) != sizeof (psd))) {
1656 		prt_hex(pri, 0, value);
1657 		return;
1658 	}
1659 	outstring(pri, "{ ");
1660 	prt_psflags(pri, psd.psd_add);
1661 	outstring(pri, ", ");
1662 	prt_psflags(pri, psd.psd_rem);
1663 	outstring(pri, ", ");
1664 	prt_psflags(pri, psd.psd_assign);
1665 	outstring(pri, ", ");
1666 	outstring(pri, psd.psd_ass_active ? "B_TRUE" : "B_FALSE");
1667 	outstring(pri, " }");
1668 }
1669 
1670 /*
1671  * Print a psecflagswhich_t
1672  */
1673 void
prt_psfw(private_t * pri,int raw,long value)1674 prt_psfw(private_t *pri, int raw, long value)
1675 {
1676 	psecflagwhich_t which = (psecflagwhich_t)value;
1677 	char *s;
1678 
1679 	if (raw != 0) {
1680 		prt_dec(pri, 0, value);
1681 		return;
1682 	}
1683 
1684 	switch (which) {
1685 	case PSF_EFFECTIVE:
1686 		s = "PSF_EFFECTIVE";
1687 		break;
1688 	case PSF_INHERIT:
1689 		s = "PSF_INHERIT";
1690 		break;
1691 	case PSF_LOWER:
1692 		s = "PSF_LOWER";
1693 		break;
1694 	case PSF_UPPER:
1695 		s = "PSF_UPPER";
1696 		break;
1697 	}
1698 
1699 	if (s == NULL)
1700 		prt_dec(pri, 0, value);
1701 	else
1702 		outstring(pri, s);
1703 }
1704 
1705 /*
1706  * Print processor set id, including logical expansion of "special" ids.
1707  */
1708 void
prt_pst(private_t * pri,int raw,long val)1709 prt_pst(private_t *pri, int raw, long val)
1710 {
1711 	const char *s = NULL;
1712 
1713 	if (!raw) {
1714 		switch ((psetid_t)val) {
1715 		case PS_NONE:		s = "PS_NONE";		break;
1716 		case PS_QUERY:		s = "PS_QUERY";		break;
1717 		case PS_MYID:		s = "PS_MYID";		break;
1718 		}
1719 	}
1720 
1721 	if (s == NULL)
1722 		prt_dec(pri, 0, val);
1723 	else
1724 		outstring(pri, s);
1725 }
1726 
1727 /*
1728  * Print meminfo() argument.
1729  */
1730 /*ARGSUSED*/
1731 void
prt_mif(private_t * pri,int raw,long val)1732 prt_mif(private_t *pri, int raw, long val)
1733 {
1734 	struct meminfo	minfo;
1735 
1736 	if (data_model == PR_MODEL_ILP32) {
1737 		struct meminfo32 minfo32;
1738 
1739 		if (Pread(Proc, &minfo32, sizeof (struct meminfo32), val) !=
1740 			sizeof (struct meminfo32)) {
1741 			prt_dec(pri, 0, pri->sys_args[1]);	/* addr_count */
1742 			outstring(pri, ", ");
1743 			prt_hex(pri, 0, val);
1744 			return;
1745 		}
1746 		/*
1747 		 * arrange the arguments in the order that user calls with
1748 		 */
1749 		prt_hex(pri, 0, minfo32.mi_inaddr);
1750 		outstring(pri, ", ");
1751 		prt_dec(pri, 0, pri->sys_args[1]);	/* addr_count */
1752 		outstring(pri, ", ");
1753 		prt_hex(pri, 0, minfo32.mi_info_req);
1754 		outstring(pri, ", ");
1755 		prt_dec(pri, 0, minfo32.mi_info_count);
1756 		outstring(pri, ", ");
1757 		prt_hex(pri, 0, minfo32.mi_outdata);
1758 		outstring(pri, ", ");
1759 		prt_hex(pri, 0, minfo32.mi_validity);
1760 		return;
1761 	}
1762 	if (Pread(Proc, &minfo, sizeof (struct meminfo), val) !=
1763 		sizeof (struct meminfo)) {
1764 		prt_dec(pri, 0, pri->sys_args[1]);	/* addr_count */
1765 		outstring(pri, ", ");
1766 		prt_hex(pri, 0, val);
1767 		return;
1768 	}
1769 	/*
1770 	 * arrange the arguments in the order that user calls with
1771 	 */
1772 	prt_hex(pri, 0, (long)minfo.mi_inaddr);
1773 	outstring(pri, ", ");
1774 	prt_dec(pri, 0, pri->sys_args[1]);	/* addr_count */
1775 	outstring(pri, ", ");
1776 	prt_hex(pri, 0, (long)minfo.mi_info_req);
1777 	outstring(pri, ", ");
1778 	prt_dec(pri, 0, minfo.mi_info_count);
1779 	outstring(pri, ", ");
1780 	prt_hex(pri, 0, (long)minfo.mi_outdata);
1781 	outstring(pri, ", ");
1782 	prt_hex(pri, 0, (long)minfo.mi_validity);
1783 }
1784 
1785 
1786 /*
1787  * Print so_socket() 1st argument.
1788  */
1789 /*ARGSUSED*/
1790 void
prt_pfm(private_t * pri,int raw,long val)1791 prt_pfm(private_t *pri, int raw, long val)
1792 {
1793 	/* Protocol Families have same names as Address Families */
1794 	if ((ulong_t)val < MAX_AFCODES) {
1795 		outstring(pri, "PF_");
1796 		outstring(pri, afcodes[val]);
1797 	} else {
1798 		prt_dec(pri, 0, val);
1799 	}
1800 }
1801 
1802 /*
1803  * Print sockconfig() subcode.
1804  */
1805 /*ARGSUSED*/
1806 void
prt_skc(private_t * pri,int raw,long val)1807 prt_skc(private_t *pri, int raw, long val)
1808 {
1809 	const char *s = NULL;
1810 
1811 	if (!raw) {
1812 		switch (val) {
1813 		case SOCKCONFIG_ADD_SOCK:
1814 			s = "SOCKCONFIG_ADD_SOCK"; break;
1815 		case SOCKCONFIG_REMOVE_SOCK:
1816 			s = "SOCKCONFIG_REMOVE_SOCK"; break;
1817 		case SOCKCONFIG_ADD_FILTER:
1818 			s = "SOCKCONFIG_ADD_FILTER"; break;
1819 		case SOCKCONFIG_REMOVE_FILTER:
1820 			s = "SOCKCONFIG_REMOVE_FILTER"; break;
1821 		}
1822 	}
1823 	if (s == NULL)
1824 		prt_dec(pri, 0, val);
1825 	else
1826 		outstring(pri, s);
1827 }
1828 /*
1829  * Print so_socket() 2nd argument.
1830  */
1831 /*ARGSUSED*/
1832 void
prt_skt(private_t * pri,int raw,long val)1833 prt_skt(private_t *pri, int raw, long val)
1834 {
1835 	const char *s;
1836 	long type = val & SOCK_TYPE_MASK;
1837 
1838 	if ((ulong_t)type <= MAX_SOCKTYPES &&
1839 	    (s = socktype_codes[type]) != NULL) {
1840 		outstring(pri, s);
1841 		if ((val & SOCK_CLOEXEC) != 0) {
1842 			outstring(pri, "|SOCK_CLOEXEC");
1843 		}
1844 		if ((val & SOCK_CLOFORK) != 0) {
1845 			outstring(pri, "|SOCK_CLOFORK");
1846 		}
1847 		if ((val & SOCK_NDELAY) != 0) {
1848 			outstring(pri, "|SOCK_NDELAY");
1849 		}
1850 		if ((val & SOCK_NONBLOCK) != 0) {
1851 			outstring(pri, "|SOCK_NONBLOCK");
1852 		}
1853 	} else {
1854 		prt_dec(pri, 0, val);
1855 	}
1856 }
1857 
1858 
1859 /*
1860  * Print so_socket() 3rd argument.
1861  */
1862 /*ARGSUSED*/
1863 void
prt_skp(private_t * pri,int raw,long val)1864 prt_skp(private_t *pri, int raw, long val)
1865 {
1866 	const char *s;
1867 
1868 	/* cheating -- look at the protocol-family */
1869 	switch (pri->sys_args[0]) {
1870 	case PF_INET6:
1871 	case PF_INET:
1872 		if ((s = ipprotos((int)val)) != NULL) {
1873 			outstring(pri, s);
1874 			break;
1875 		}
1876 		/* FALLTHROUGH */
1877 	default:
1878 		prt_dec(pri, 0, val);
1879 		break;
1880 	}
1881 }
1882 
1883 
1884 /*
1885  * Print so_socket() 5th argument.
1886  */
1887 /*ARGSUSED*/
1888 void
prt_skv(private_t * pri,int raw,long val)1889 prt_skv(private_t *pri, int raw, long val)
1890 {
1891 	switch (val) {
1892 	case SOV_STREAM:	outstring(pri, "SOV_STREAM");	break;
1893 	case SOV_DEFAULT:	outstring(pri, "SOV_DEFAULT");	break;
1894 	case SOV_SOCKSTREAM:	outstring(pri, "SOV_SOCKSTREAM");	break;
1895 	case SOV_SOCKBSD:	outstring(pri, "SOV_SOCKBSD");	break;
1896 	case SOV_XPG4_2:	outstring(pri, "SOV_XPG4_2");	break;
1897 	default:		prt_dec(pri, 0, val);		break;
1898 	}
1899 }
1900 
1901 /*
1902  * Print accept4() flags argument.
1903  */
1904 void
prt_acf(private_t * pri,int raw,long val)1905 prt_acf(private_t *pri, int raw, long val)
1906 {
1907 	int first = 1;
1908 	if (raw || !val ||
1909 	    (val & ~(SOCK_CLOEXEC|SOCK_NDELAY|SOCK_NONBLOCK|SOCK_CLOFORK))) {
1910 		prt_dex(pri, 0, val);
1911 		return;
1912 	}
1913 
1914 	if (val & SOCK_CLOEXEC) {
1915 		outstring(pri, "|SOCK_CLOEXEC" + first);
1916 		first = 0;
1917 	}
1918 	if (val & SOCK_CLOFORK) {
1919 		outstring(pri, "|SOCK_CLOFORK" + first);
1920 		first = 0;
1921 	}
1922 	if (val & SOCK_NDELAY) {
1923 		outstring(pri, "|SOCK_NDELAY" + first);
1924 		first = 0;
1925 	}
1926 	if (val & SOCK_NONBLOCK) {
1927 		outstring(pri, "|SOCK_NONBLOCK" + first);
1928 	}
1929 }
1930 
1931 
1932 /*
1933  * Print setsockopt()/getsockopt() 2nd argument.
1934  */
1935 /*ARGSUSED*/
1936 void
prt_sol(private_t * pri,int raw,long val)1937 prt_sol(private_t *pri, int raw, long val)
1938 {
1939 	if (val == SOL_SOCKET) {
1940 		outstring(pri, "SOL_SOCKET");
1941 	} else if (val == SOL_ROUTE) {
1942 		outstring(pri, "SOL_ROUTE");
1943 	} else {
1944 		const struct protoent *p;
1945 		struct protoent res;
1946 		char buf[NSS_BUFLEN_PROTOCOLS];
1947 
1948 		if ((p = getprotobynumber_r(val, &res,
1949 		    (char *)buf, sizeof (buf))) != NULL)
1950 			outstring(pri, p->p_name);
1951 		else
1952 			prt_dec(pri, 0, val);
1953 	}
1954 }
1955 
1956 
1957 const char *
sol_optname(private_t * pri,long val)1958 sol_optname(private_t *pri, long val)
1959 {
1960 #define	CBSIZE	sizeof (pri->code_buf)
1961 	if (val >= SO_SNDBUF) {
1962 		switch (val) {
1963 		case SO_SNDBUF:		return ("SO_SNDBUF");
1964 		case SO_RCVBUF:		return ("SO_RCVBUF");
1965 		case SO_SNDLOWAT:	return ("SO_SNDLOWAT");
1966 		case SO_RCVLOWAT:	return ("SO_RCVLOWAT");
1967 		case SO_SNDTIMEO:	return ("SO_SNDTIMEO");
1968 		case SO_RCVTIMEO:	return ("SO_RCVTIMEO");
1969 		case SO_ERROR:		return ("SO_ERROR");
1970 		case SO_TYPE:		return ("SO_TYPE");
1971 		case SO_PROTOTYPE:	return ("SO_PROTOTYPE");
1972 		case SO_ANON_MLP:	return ("SO_ANON_MLP");
1973 		case SO_MAC_EXEMPT:	return ("SO_MAC_EXEMPT");
1974 		case SO_ALLZONES:	return ("SO_ALLZONES");
1975 		case SO_MAC_IMPLICIT:	return ("SO_MAC_IMPLICIT");
1976 		case SO_VRRP:		return ("SO_VRRP");
1977 		case SO_EXCLBIND:	return ("SO_EXCLBIND");
1978 		case SO_DOMAIN:		return ("SO_DOMAIN");
1979 
1980 		default:		(void) snprintf(pri->code_buf, CBSIZE,
1981 					    "0x%lx", val);
1982 					return (pri->code_buf);
1983 		}
1984 	} else {
1985 		char *s = pri->code_buf;
1986 		size_t used = 1;
1987 		long val2;
1988 
1989 		*s = '\0';
1990 		val2 = val & ~(SO_DEBUG|SO_ACCEPTCONN|SO_REUSEADDR|SO_KEEPALIVE|
1991 		    SO_DONTROUTE|SO_BROADCAST|SO_USELOOPBACK|SO_LINGER|
1992 		    SO_OOBINLINE|SO_DGRAM_ERRIND|SO_RECVUCRED);
1993 		if (val2)
1994 			used = snprintf(s, CBSIZE, "|0x%lx", val2);
1995 		if (val & SO_DEBUG)
1996 			used = strlcat(s, "|SO_DEBUG", CBSIZE);
1997 		if (val & SO_ACCEPTCONN)
1998 			used = strlcat(s, "|SO_ACCEPTCONN", CBSIZE);
1999 		if (val & SO_REUSEADDR)
2000 			used = strlcat(s, "|SO_REUSEADDR", CBSIZE);
2001 		if (val & SO_KEEPALIVE)
2002 			used = strlcat(s, "|SO_KEEPALIVE", CBSIZE);
2003 		if (val & SO_DONTROUTE)
2004 			used = strlcat(s, "|SO_DONTROUTE", CBSIZE);
2005 		if (val & SO_BROADCAST)
2006 			used = strlcat(s, "|SO_BROADCAST", CBSIZE);
2007 		if (val & SO_USELOOPBACK)
2008 			used = strlcat(s, "|SO_USELOOPBACK", CBSIZE);
2009 		if (val & SO_LINGER)
2010 			used = strlcat(s, "|SO_LINGER", CBSIZE);
2011 		if (val & SO_OOBINLINE)
2012 			used = strlcat(s, "|SO_OOBINLINE", CBSIZE);
2013 		if (val & SO_DGRAM_ERRIND)
2014 			used = strlcat(s, "|SO_DGRAM_ERRIND", CBSIZE);
2015 		if (val & SO_RECVUCRED)
2016 			used = strlcat(s, "|SO_RECVUCRED", CBSIZE);
2017 		if (used >= CBSIZE || val == 0)
2018 			(void) snprintf(s + 1, CBSIZE-1, "0x%lx", val);
2019 		return ((const char *)(s + 1));
2020 	}
2021 #undef CBSIZE
2022 }
2023 
2024 const char *
route_optname(private_t * pri,long val)2025 route_optname(private_t *pri, long val)
2026 {
2027 	switch (val) {
2028 	case RT_AWARE:
2029 		return ("RT_AWARE");
2030 	default:
2031 		(void) snprintf(pri->code_buf, sizeof (pri->code_buf),
2032 		    "0x%lx", val);
2033 		return (pri->code_buf);
2034 	}
2035 }
2036 
2037 const char *
tcp_optname(private_t * pri,long val)2038 tcp_optname(private_t *pri, long val)
2039 {
2040 	switch (val) {
2041 	case TCP_NODELAY:		return ("TCP_NODELAY");
2042 	case TCP_MAXSEG:		return ("TCP_MAXSEG");
2043 	case TCP_KEEPALIVE:		return ("TCP_KEEPALIVE");
2044 	case TCP_NOTIFY_THRESHOLD:	return ("TCP_NOTIFY_THRESHOLD");
2045 	case TCP_ABORT_THRESHOLD:	return ("TCP_ABORT_THRESHOLD");
2046 	case TCP_CONN_NOTIFY_THRESHOLD:	return ("TCP_CONN_NOTIFY_THRESHOLD");
2047 	case TCP_CONN_ABORT_THRESHOLD:	return ("TCP_CONN_ABORT_THRESHOLD");
2048 	case TCP_RECVDSTADDR:		return ("TCP_RECVDSTADDR");
2049 	case TCP_ANONPRIVBIND:		return ("TCP_ANONPRIVBIND");
2050 	case TCP_EXCLBIND:		return ("TCP_EXCLBIND");
2051 	case TCP_INIT_CWND:		return ("TCP_INIT_CWND");
2052 	case TCP_KEEPALIVE_THRESHOLD:	return ("TCP_KEEPALIVE_THRESHOLD");
2053 	case TCP_KEEPALIVE_ABORT_THRESHOLD:
2054 		return ("TCP_KEEPALIVE_ABORT_THRESHOLD");
2055 	case TCP_CORK:			return ("TCP_CORK");
2056 	case TCP_RTO_INITIAL:		return ("TCP_RTO_INITIAL");
2057 	case TCP_RTO_MIN:		return ("TCP_RTO_MIN");
2058 	case TCP_RTO_MAX:		return ("TCP_RTO_MAX");
2059 	case TCP_LINGER2:		return ("TCP_LINGER2");
2060 	case TCP_KEEPIDLE:		return ("TCP_KEEPIDLE");
2061 	case TCP_KEEPCNT:		return ("TCP_KEEPCNT");
2062 	case TCP_KEEPINTVL:		return ("TCP_KEEPINTVL");
2063 	case TCP_CONGESTION:		return ("TCP_CONGESTION");
2064 	case TCP_QUICKACK:		return ("TCP_QUICKACK");
2065 	case TCP_MD5SIG:		return ("TCP_MD5SIG");
2066 
2067 	default:			(void) snprintf(pri->code_buf,
2068 					    sizeof (pri->code_buf),
2069 					    "0x%lx", val);
2070 					return (pri->code_buf);
2071 	}
2072 }
2073 
2074 
2075 const char *
sctp_optname(private_t * pri,long val)2076 sctp_optname(private_t *pri, long val)
2077 {
2078 	switch (val) {
2079 	case SCTP_RTOINFO:		return ("SCTP_RTOINFO");
2080 	case SCTP_ASSOCINFO:		return ("SCTP_ASSOCINFO");
2081 	case SCTP_INITMSG:		return ("SCTP_INITMSG");
2082 	case SCTP_NODELAY:		return ("SCTP_NODELAY");
2083 	case SCTP_AUTOCLOSE:		return ("SCTP_AUTOCLOSE");
2084 	case SCTP_SET_PEER_PRIMARY_ADDR:
2085 		return ("SCTP_SET_PEER_PRIMARY_ADDR");
2086 	case SCTP_PRIMARY_ADDR:		return ("SCTP_PRIMARY_ADDR");
2087 	case SCTP_ADAPTATION_LAYER:	return ("SCTP_ADAPTATION_LAYER");
2088 	case SCTP_DISABLE_FRAGMENTS:	return ("SCTP_DISABLE_FRAGMENTS");
2089 	case SCTP_PEER_ADDR_PARAMS:	return ("SCTP_PEER_ADDR_PARAMS");
2090 	case SCTP_DEFAULT_SEND_PARAM:	return ("SCTP_DEFAULT_SEND_PARAM");
2091 	case SCTP_EVENTS:		return ("SCTP_EVENTS");
2092 	case SCTP_I_WANT_MAPPED_V4_ADDR:
2093 		return ("SCTP_I_WANT_MAPPED_V4_ADDR");
2094 	case SCTP_MAXSEG:		return ("SCTP_MAXSEG");
2095 	case SCTP_STATUS:		return ("SCTP_STATUS");
2096 	case SCTP_GET_PEER_ADDR_INFO:	return ("SCTP_GET_PEER_ADDR_INFO");
2097 
2098 	case SCTP_ADD_ADDR:		return ("SCTP_ADD_ADDR");
2099 	case SCTP_REM_ADDR:		return ("SCTP_REM_ADDR");
2100 
2101 	default:			(void) snprintf(pri->code_buf,
2102 					    sizeof (pri->code_buf),
2103 					    "0x%lx", val);
2104 					return (pri->code_buf);
2105 	}
2106 }
2107 
2108 
2109 const char *
udp_optname(private_t * pri,long val)2110 udp_optname(private_t *pri, long val)
2111 {
2112 	switch (val) {
2113 	case UDP_CHECKSUM:		return ("UDP_CHECKSUM");
2114 	case UDP_ANONPRIVBIND:		return ("UDP_ANONPRIVBIND");
2115 	case UDP_EXCLBIND:		return ("UDP_EXCLBIND");
2116 	case UDP_RCVHDR:		return ("UDP_RCVHDR");
2117 	case UDP_NAT_T_ENDPOINT:	return ("UDP_NAT_T_ENDPOINT");
2118 	case UDP_SRCPORT_HASH:		return ("UDP_SRCPORT_HASH");
2119 
2120 	default:			(void) snprintf(pri->code_buf,
2121 					    sizeof (pri->code_buf), "0x%lx",
2122 					    val);
2123 					return (pri->code_buf);
2124 	}
2125 }
2126 
2127 
2128 const char *
ip_optname(private_t * pri,long val)2129 ip_optname(private_t *pri, long val)
2130 {
2131 	switch (val) {
2132 	case IP_OPTIONS:		return ("IP_OPTIONS");
2133 	case IP_HDRINCL:		return ("IP_HDRINCL");
2134 	case IP_TOS:			return ("IP_TOS");
2135 	case IP_TTL:			return ("IP_TTL");
2136 	case IP_RECVOPTS:		return ("IP_RECVOPTS");
2137 	case IP_RECVRETOPTS:		return ("IP_RECVRETOPTS");
2138 	case IP_RECVDSTADDR:		return ("IP_RECVDSTADDR");
2139 	case IP_RETOPTS:		return ("IP_RETOPTS");
2140 	case IP_RECVIF:			return ("IP_RECVIF");
2141 	case IP_RECVSLLA:		return ("IP_RECVSLLA");
2142 	case IP_RECVTTL:		return ("IP_RECVTTL");
2143 	case IP_RECVTOS:		return ("IP_RECVTOS");
2144 	case IP_MULTICAST_IF:		return ("IP_MULTICAST_IF");
2145 	case IP_MULTICAST_TTL:		return ("IP_MULTICAST_TTL");
2146 	case IP_MULTICAST_LOOP:		return ("IP_MULTICAST_LOOP");
2147 	case IP_ADD_MEMBERSHIP:		return ("IP_ADD_MEMBERSHIP");
2148 	case IP_DROP_MEMBERSHIP:	return ("IP_DROP_MEMBERSHIP");
2149 	case IP_BLOCK_SOURCE:		return ("IP_BLOCK_SOURCE");
2150 	case IP_UNBLOCK_SOURCE:		return ("IP_UNBLOCK_SOURCE");
2151 	case IP_ADD_SOURCE_MEMBERSHIP:	return ("IP_ADD_SOURCE_MEMBERSHIP");
2152 	case IP_DROP_SOURCE_MEMBERSHIP:	return ("IP_DROP_SOURCE_MEMBERSHIP");
2153 	case IP_NEXTHOP:		return ("IP_NEXTHOP");
2154 	/* IP_PKTINFO and IP_RECVPKTINFO share the same code */
2155 	case IP_PKTINFO:		return ("IP_PKTINFO/IP_RECVPKTINFO");
2156 	case IP_DONTFRAG:		return ("IP_DONTFRAG");
2157 	case IP_MINTTL:			return ("IP_MINTTL");
2158 	case IP_SEC_OPT:		return ("IP_SEC_OPT");
2159 	case MCAST_JOIN_GROUP:		return ("MCAST_JOIN_GROUP");
2160 	case MCAST_LEAVE_GROUP:		return ("MCAST_LEAVE_GROUP");
2161 	case MCAST_BLOCK_SOURCE:	return ("MCAST_BLOCK_SOURCE");
2162 	case MCAST_UNBLOCK_SOURCE:	return ("MCAST_UNBLOCK_SOURCE");
2163 	case MCAST_JOIN_SOURCE_GROUP:	return ("MCAST_JOIN_SOURCE_GROUP");
2164 	case MCAST_LEAVE_SOURCE_GROUP:	return ("MCAST_LEAVE_SOURCE_GROUP");
2165 	case MRT_INIT:			return ("MRT_INIT");
2166 	case MRT_DONE:			return ("MRT_DONE");
2167 	case MRT_ADD_VIF:		return ("MRT_ADD_VIF");
2168 	case MRT_DEL_VIF:		return ("MRT_DEL_VIF");
2169 	case MRT_ADD_MFC:		return ("MRT_ADD_MFC");
2170 	case MRT_DEL_MFC:		return ("MRT_DEL_MFC");
2171 	case MRT_VERSION:		return ("MRT_VERSION");
2172 	case MRT_ASSERT:		return ("MRT_ASSERT");
2173 	case IP_BOUND_IF:		return ("IP_BOUND_IF");
2174 	case IP_UNSPEC_SRC:		return ("IP_UNSPEC_SRC");
2175 	case IP_BROADCAST_TTL:		return ("IP_BROADCAST_TTL");
2176 	case IP_DHCPINIT_IF:		return ("IP_DHCPINIT_IF");
2177 	case IP_REUSEADDR:		return ("IP_REUSEADDR");
2178 	case IP_DONTROUTE:		return ("IP_DONTROUTE");
2179 	case IP_BROADCAST:		return ("IP_BROADCAST");
2180 
2181 	default:			(void) snprintf(pri->code_buf,
2182 					    sizeof (pri->code_buf), "0x%lx",
2183 					    val);
2184 					return (pri->code_buf);
2185 	}
2186 }
2187 
2188 const char *
ipv6_optname(private_t * pri,long val)2189 ipv6_optname(private_t *pri, long val)
2190 {
2191 	switch (val) {
2192 	case IPV6_UNICAST_HOPS:		return ("IPV6_UNICAST_HOPS");
2193 	case IPV6_MULTICAST_IF:		return ("IPV6_MULTICAST_IF");
2194 	case IPV6_MULTICAST_HOPS:	return ("IPV6_MULTICAST_HOPS");
2195 	case IPV6_MULTICAST_LOOP:	return ("IPV6_MULTICAST_LOOP");
2196 	case IPV6_JOIN_GROUP:		return ("IPV6_JOIN_GROUP");
2197 	case IPV6_LEAVE_GROUP:		return ("IPV6_LEAVE_GROUP");
2198 	case IPV6_PKTINFO:		return ("IPV6_PKTINFO");
2199 	case IPV6_HOPLIMIT:		return ("IPV6_HOPLIMIT");
2200 	case IPV6_NEXTHOP:		return ("IPV6_NEXTHOP");
2201 	case IPV6_HOPOPTS:		return ("IPV6_HOPOPTS");
2202 	case IPV6_DSTOPTS:		return ("IPV6_DSTOPTS");
2203 	case IPV6_RTHDR:		return ("IPV6_RTHDR");
2204 	case IPV6_RTHDRDSTOPTS:		return ("IPV6_RTHDRDSTOPTS");
2205 	case IPV6_RECVPKTINFO:		return ("IPV6_RECVPKTINFO");
2206 	case IPV6_RECVHOPLIMIT:		return ("IPV6_RECVHOPLIMIT");
2207 	case IPV6_RECVHOPOPTS:		return ("IPV6_RECVHOPOPTS");
2208 	case _OLD_IPV6_RECVDSTOPTS:	return ("_OLD_IPV6_RECVDSTOPTS");
2209 	case IPV6_RECVRTHDR:		return ("IPV6_RECVRTHDR");
2210 	case IPV6_RECVRTHDRDSTOPTS:	return ("IPV6_RECVRTHDRDSTOPTS");
2211 	case IPV6_CHECKSUM:		return ("IPV6_CHECKSUM");
2212 	case IPV6_RECVTCLASS:		return ("IPV6_RECVTCLASS");
2213 	case IPV6_USE_MIN_MTU:		return ("IPV6_USE_MIN_MTU");
2214 	case IPV6_DONTFRAG:		return ("IPV6_DONTFRAG");
2215 	case IPV6_SEC_OPT:		return ("IPV6_SEC_OPT");
2216 	case IPV6_SRC_PREFERENCES:	return ("IPV6_SRC_PREFERENCES");
2217 	case IPV6_RECVPATHMTU:		return ("IPV6_RECVPATHMTU");
2218 	case IPV6_PATHMTU:		return ("IPV6_PATHMTU");
2219 	case IPV6_TCLASS:		return ("IPV6_TCLASS");
2220 	case IPV6_V6ONLY:		return ("IPV6_V6ONLY");
2221 	case IPV6_RECVDSTOPTS:		return ("IPV6_RECVDSTOPTS");
2222 	case MCAST_JOIN_GROUP:		return ("MCAST_JOIN_GROUP");
2223 	case MCAST_LEAVE_GROUP:		return ("MCAST_LEAVE_GROUP");
2224 	case MCAST_BLOCK_SOURCE:	return ("MCAST_BLOCK_SOURCE");
2225 	case MCAST_UNBLOCK_SOURCE:	return ("MCAST_UNBLOCK_SOURCE");
2226 	case MCAST_JOIN_SOURCE_GROUP:	return ("MCAST_JOIN_SOURCE_GROUP");
2227 	case MCAST_LEAVE_SOURCE_GROUP:	return ("MCAST_LEAVE_SOURCE_GROUP");
2228 	case IPV6_MINHOPCOUNT:		return ("IPV6_MINHOPCOUNT");
2229 
2230 	default:			(void) snprintf(pri->code_buf,
2231 					    sizeof (pri->code_buf), "0x%lx",
2232 					    val);
2233 					return (pri->code_buf);
2234 	}
2235 }
2236 
2237 
2238 const char *
icmpv6_optname(private_t * pri,long val)2239 icmpv6_optname(private_t *pri, long val)
2240 {
2241 	switch (val) {
2242 	case ICMP6_FILTER:		return ("ICMP6_FILTER");
2243 	default:			(void) snprintf(pri->code_buf,
2244 					    sizeof (pri->code_buf), "0x%lx",
2245 					    val);
2246 					return (pri->code_buf);
2247 	}
2248 }
2249 
2250 
2251 /*
2252  * Print setsockopt()/getsockopt() 3rd argument.
2253  */
2254 /*ARGSUSED*/
2255 void
prt_son(private_t * pri,int raw,long val)2256 prt_son(private_t *pri, int raw, long val)
2257 {
2258 	/* cheating -- look at the level */
2259 	switch (pri->sys_args[1]) {
2260 	case SOL_SOCKET:	outstring(pri, sol_optname(pri, val));
2261 				break;
2262 	case SOL_ROUTE:		outstring(pri, route_optname(pri, val));
2263 				break;
2264 	case IPPROTO_IP:	outstring(pri, ip_optname(pri, val));
2265 				break;
2266 	case IPPROTO_IPV6:	outstring(pri, ipv6_optname(pri, val));
2267 				break;
2268 	case IPPROTO_ICMPV6:	outstring(pri, icmpv6_optname(pri, val));
2269 				break;
2270 	case IPPROTO_TCP:	outstring(pri, tcp_optname(pri, val));
2271 				break;
2272 	case IPPROTO_UDP:	outstring(pri, udp_optname(pri, val));
2273 				break;
2274 	case IPPROTO_SCTP:	outstring(pri, sctp_optname(pri, val));
2275 				break;
2276 	default:		prt_dec(pri, 0, val);
2277 				break;
2278 	}
2279 }
2280 
2281 
2282 /*
2283  * Print utrap type
2284  */
2285 /*ARGSUSED*/
2286 void
prt_utt(private_t * pri,int raw,long val)2287 prt_utt(private_t *pri, int raw, long val)
2288 {
2289 	const char *s = NULL;
2290 
2291 #ifdef __sparc
2292 	if (!raw) {
2293 		switch (val) {
2294 		case UT_INSTRUCTION_DISABLED:
2295 			s = "UT_INSTRUCTION_DISABLED"; break;
2296 		case UT_INSTRUCTION_ERROR:
2297 			s = "UT_INSTRUCTION_ERROR"; break;
2298 		case UT_INSTRUCTION_PROTECTION:
2299 			s = "UT_INSTRUCTION_PROTECTION"; break;
2300 		case UT_ILLTRAP_INSTRUCTION:
2301 			s = "UT_ILLTRAP_INSTRUCTION"; break;
2302 		case UT_ILLEGAL_INSTRUCTION:
2303 			s = "UT_ILLEGAL_INSTRUCTION"; break;
2304 		case UT_PRIVILEGED_OPCODE:
2305 			s = "UT_PRIVILEGED_OPCODE"; break;
2306 		case UT_FP_DISABLED:
2307 			s = "UT_FP_DISABLED"; break;
2308 		case UT_FP_EXCEPTION_IEEE_754:
2309 			s = "UT_FP_EXCEPTION_IEEE_754"; break;
2310 		case UT_FP_EXCEPTION_OTHER:
2311 			s = "UT_FP_EXCEPTION_OTHER"; break;
2312 		case UT_TAG_OVERFLOW:
2313 			s = "UT_TAG_OVERFLOW"; break;
2314 		case UT_DIVISION_BY_ZERO:
2315 			s = "UT_DIVISION_BY_ZERO"; break;
2316 		case UT_DATA_EXCEPTION:
2317 			s = "UT_DATA_EXCEPTION"; break;
2318 		case UT_DATA_ERROR:
2319 			s = "UT_DATA_ERROR"; break;
2320 		case UT_DATA_PROTECTION:
2321 			s = "UT_DATA_PROTECTION"; break;
2322 		case UT_MEM_ADDRESS_NOT_ALIGNED:
2323 			s = "UT_MEM_ADDRESS_NOT_ALIGNED"; break;
2324 		case UT_PRIVILEGED_ACTION:
2325 			s = "UT_PRIVILEGED_ACTION"; break;
2326 		case UT_ASYNC_DATA_ERROR:
2327 			s = "UT_ASYNC_DATA_ERROR"; break;
2328 		case UT_TRAP_INSTRUCTION_16:
2329 			s = "UT_TRAP_INSTRUCTION_16"; break;
2330 		case UT_TRAP_INSTRUCTION_17:
2331 			s = "UT_TRAP_INSTRUCTION_17"; break;
2332 		case UT_TRAP_INSTRUCTION_18:
2333 			s = "UT_TRAP_INSTRUCTION_18"; break;
2334 		case UT_TRAP_INSTRUCTION_19:
2335 			s = "UT_TRAP_INSTRUCTION_19"; break;
2336 		case UT_TRAP_INSTRUCTION_20:
2337 			s = "UT_TRAP_INSTRUCTION_20"; break;
2338 		case UT_TRAP_INSTRUCTION_21:
2339 			s = "UT_TRAP_INSTRUCTION_21"; break;
2340 		case UT_TRAP_INSTRUCTION_22:
2341 			s = "UT_TRAP_INSTRUCTION_22"; break;
2342 		case UT_TRAP_INSTRUCTION_23:
2343 			s = "UT_TRAP_INSTRUCTION_23"; break;
2344 		case UT_TRAP_INSTRUCTION_24:
2345 			s = "UT_TRAP_INSTRUCTION_24"; break;
2346 		case UT_TRAP_INSTRUCTION_25:
2347 			s = "UT_TRAP_INSTRUCTION_25"; break;
2348 		case UT_TRAP_INSTRUCTION_26:
2349 			s = "UT_TRAP_INSTRUCTION_26"; break;
2350 		case UT_TRAP_INSTRUCTION_27:
2351 			s = "UT_TRAP_INSTRUCTION_27"; break;
2352 		case UT_TRAP_INSTRUCTION_28:
2353 			s = "UT_TRAP_INSTRUCTION_28"; break;
2354 		case UT_TRAP_INSTRUCTION_29:
2355 			s = "UT_TRAP_INSTRUCTION_29"; break;
2356 		case UT_TRAP_INSTRUCTION_30:
2357 			s = "UT_TRAP_INSTRUCTION_30"; break;
2358 		case UT_TRAP_INSTRUCTION_31:
2359 			s = "UT_TRAP_INSTRUCTION_31"; break;
2360 		}
2361 	}
2362 #endif /* __sparc */
2363 
2364 	if (s == NULL)
2365 		prt_dec(pri, 0, val);
2366 	else
2367 		outstring(pri, s);
2368 }
2369 
2370 
2371 /*
2372  * Print utrap handler
2373  */
2374 void
prt_uth(private_t * pri,int raw,long val)2375 prt_uth(private_t *pri, int raw, long val)
2376 {
2377 	const char *s = NULL;
2378 
2379 	if (!raw) {
2380 		switch (val) {
2381 		case (long)UTH_NOCHANGE:	s = "UTH_NOCHANGE"; break;
2382 		}
2383 	}
2384 
2385 	if (s == NULL)
2386 		prt_hex(pri, 0, val);
2387 	else
2388 		outstring(pri, s);
2389 }
2390 
2391 const char *
access_flags(private_t * pri,long arg)2392 access_flags(private_t *pri, long arg)
2393 {
2394 #define	E_OK 010
2395 	char *str = pri->code_buf;
2396 
2397 	if (arg & ~(R_OK|W_OK|X_OK|E_OK))
2398 		return (NULL);
2399 
2400 	/* NB: F_OK == 0 */
2401 	if (arg == F_OK)
2402 		return ("F_OK");
2403 	if (arg == E_OK)
2404 		return ("F_OK|E_OK");
2405 
2406 	*str = '\0';
2407 	if (arg & R_OK)
2408 		(void) strlcat(str, "|R_OK", sizeof (pri->code_buf));
2409 	if (arg & W_OK)
2410 		(void) strlcat(str, "|W_OK", sizeof (pri->code_buf));
2411 	if (arg & X_OK)
2412 		(void) strlcat(str, "|X_OK", sizeof (pri->code_buf));
2413 	if (arg & E_OK)
2414 		(void) strlcat(str, "|E_OK", sizeof (pri->code_buf));
2415 	return ((const char *)(str + 1));
2416 #undef E_OK
2417 }
2418 
2419 /*
2420  * Print access() flags.
2421  */
2422 void
prt_acc(private_t * pri,int raw,long val)2423 prt_acc(private_t *pri, int raw, long val)
2424 {
2425 	const char *s = raw? NULL : access_flags(pri, val);
2426 
2427 	if (s == NULL)
2428 		prt_dex(pri, 0, val);
2429 	else
2430 		outstring(pri, s);
2431 }
2432 
2433 /*
2434  * Print shutdown() "how" (2nd) argument
2435  */
2436 void
prt_sht(private_t * pri,int raw,long val)2437 prt_sht(private_t *pri, int raw, long val)
2438 {
2439 	if (raw) {
2440 		prt_dex(pri, 0, val);
2441 		return;
2442 	}
2443 	switch (val) {
2444 	case SHUT_RD:	outstring(pri, "SHUT_RD");	break;
2445 	case SHUT_WR:	outstring(pri, "SHUT_WR");	break;
2446 	case SHUT_RDWR:	outstring(pri, "SHUT_RDWR");	break;
2447 	default:	prt_dec(pri, 0, val);		break;
2448 	}
2449 }
2450 
2451 /*
2452  * Print fcntl() F_SETFL flags (3rd) argument or fdsync flag (2nd arg)
2453  */
2454 static struct fcntl_flags {
2455 	long		val;
2456 	const char	*name;
2457 } fcntl_flags[] = {
2458 #define	FC_FL(flag)	{ (long)flag, "|" # flag }
2459 	FC_FL(FREVOKED),
2460 	FC_FL(FREAD),
2461 	FC_FL(FWRITE),
2462 	FC_FL(FNDELAY),
2463 	FC_FL(FAPPEND),
2464 	FC_FL(FSYNC),
2465 	FC_FL(FDSYNC),
2466 	FC_FL(FRSYNC),
2467 	FC_FL(FOFFMAX),
2468 	FC_FL(FNONBLOCK),
2469 	FC_FL(FCREAT),
2470 	FC_FL(FTRUNC),
2471 	FC_FL(FEXCL),
2472 	FC_FL(FNOCTTY),
2473 	FC_FL(FXATTR),
2474 	FC_FL(FASYNC),
2475 	FC_FL(FNODSYNC)
2476 #undef FC_FL
2477 };
2478 
2479 void
prt_ffg(private_t * pri,int raw,long val)2480 prt_ffg(private_t *pri, int raw, long val)
2481 {
2482 #define	CBSIZE	sizeof (pri->code_buf)
2483 	char *s = pri->code_buf;
2484 	size_t used = 1;
2485 
2486 	if (raw) {
2487 		(void) snprintf(s, CBSIZE, "0x%lx", val);
2488 		outstring(pri, s);
2489 		return;
2490 	}
2491 	if (val == 0) {
2492 		outstring(pri, "(no flags)");
2493 		return;
2494 	}
2495 
2496 	*s = '\0';
2497 	for (size_t i = 0; i < ARRAY_SIZE(fcntl_flags); i++) {
2498 		struct fcntl_flags *fp = &fcntl_flags[i];
2499 		if (val & fp->val) {
2500 			used = strlcat(s, fp->name, CBSIZE);
2501 			val &= ~fp->val;
2502 		}
2503 	}
2504 
2505 	if (val != 0 && used <= CBSIZE)
2506 		used += snprintf(s + used, CBSIZE - used, "|0x%lx", val);
2507 
2508 	if (used >= CBSIZE)
2509 		(void) snprintf(s + 1, CBSIZE-1, "0x%lx", val);
2510 	outstring(pri, s + 1);
2511 #undef CBSIZE
2512 }
2513 
2514 /*
2515  * Print fcntl() F_GETFD/F_SETFD values
2516  */
2517 static struct fcntl_fdflags {
2518 	long		val;
2519 	const char	*name;
2520 } fcntl_fdflags[] = {
2521 	{ FD_CLOEXEC, "|FD_CLOEXEC" },
2522 	{ FD_CLOFORK, "|FD_CLOFORK" }
2523 };
2524 
2525 void
prt_ffd(private_t * pri,int raw,long val)2526 prt_ffd(private_t *pri, int raw, long val)
2527 {
2528 #define	CBSIZE	sizeof (pri->code_buf)
2529 	char *s = pri->code_buf;
2530 	size_t used = 1;
2531 
2532 	if (raw) {
2533 		(void) snprintf(s, CBSIZE, "0x%lx", val);
2534 		outstring(pri, s);
2535 		return;
2536 	}
2537 	if (val == 0) {
2538 		outstring(pri, "(no flags)");
2539 		return;
2540 	}
2541 
2542 	*s = '\0';
2543 	for (size_t i = 0; i < ARRAY_SIZE(fcntl_fdflags); i++) {
2544 		struct fcntl_fdflags *fp = &fcntl_fdflags[i];
2545 		if (val & fp->val) {
2546 			used = strlcat(s, fp->name, CBSIZE);
2547 			val &= ~fp->val;
2548 		}
2549 	}
2550 
2551 	if (val != 0 && used <= CBSIZE)
2552 		used += snprintf(s + used, CBSIZE - used, "|0x%lx", val);
2553 
2554 	if (used >= CBSIZE)
2555 		(void) snprintf(s + 1, CBSIZE-1, "0x%lx", val);
2556 	outstring(pri, s + 1);
2557 #undef CBSIZE
2558 }
2559 
2560 void
prt_prs(private_t * pri,int raw,long val)2561 prt_prs(private_t *pri, int raw, long val)
2562 {
2563 	static size_t setsize;
2564 	priv_set_t *set = priv_allocset();
2565 
2566 	if (setsize == 0) {
2567 		const priv_impl_info_t *info = getprivimplinfo();
2568 		if (info != NULL)
2569 			setsize = info->priv_setsize * sizeof (priv_chunk_t);
2570 	}
2571 
2572 	if (setsize != 0 && !raw && set != NULL &&
2573 	    Pread(Proc, set, setsize, val) == setsize) {
2574 		int i;
2575 
2576 		outstring(pri, "{");
2577 		for (i = 0; i < setsize / sizeof (priv_chunk_t); i++) {
2578 			char buf[9];	/* 8 hex digits + '\0' */
2579 			(void) snprintf(buf, sizeof (buf), "%08x",
2580 			    ((priv_chunk_t *)set)[i]);
2581 			outstring(pri, buf);
2582 		}
2583 
2584 		outstring(pri, "}");
2585 	} else {
2586 		prt_hex(pri, 0, val);
2587 	}
2588 
2589 	if (set != NULL)
2590 		priv_freeset(set);
2591 }
2592 
2593 /*
2594  * Print privilege set operation.
2595  */
2596 void
prt_pro(private_t * pri,int raw,long val)2597 prt_pro(private_t *pri, int raw, long val)
2598 {
2599 	const char *s = NULL;
2600 
2601 	if (!raw) {
2602 		switch ((priv_op_t)val) {
2603 		case PRIV_ON:		s = "PRIV_ON";		break;
2604 		case PRIV_OFF:		s = "PRIV_OFF";		break;
2605 		case PRIV_SET:		s = "PRIV_SET";		break;
2606 		}
2607 	}
2608 
2609 	if (s == NULL)
2610 		prt_dec(pri, 0, val);
2611 	else
2612 		outstring(pri, s);
2613 }
2614 
2615 /*
2616  * Print privilege set name
2617  */
2618 void
prt_prn(private_t * pri,int raw,long val)2619 prt_prn(private_t *pri, int raw, long val)
2620 {
2621 	const char *s = NULL;
2622 
2623 	if (!raw)
2624 		s = priv_getsetbynum((int)val);
2625 
2626 	if (s == NULL)
2627 		prt_dec(pri, 0, val);
2628 	else {
2629 		char *dup = strdup(s);
2630 		char *q;
2631 
2632 		/* Do the best we can in this case */
2633 		if (dup == NULL) {
2634 			outstring(pri, s);
2635 			return;
2636 		}
2637 
2638 		outstring(pri, "PRIV_");
2639 
2640 		q = dup;
2641 
2642 		while (*q != '\0') {
2643 			*q = toupper(*q);
2644 			q++;
2645 		}
2646 		outstring(pri, dup);
2647 		free(dup);
2648 	}
2649 }
2650 
2651 /*
2652  * Print process flag names.
2653  */
2654 void
prt_pfl(private_t * pri,int raw,long val)2655 prt_pfl(private_t *pri, int raw, long val)
2656 {
2657 	const char *s = NULL;
2658 
2659 	if (!raw) {
2660 		switch ((int)val) {
2661 		case PRIV_DEBUG:	s = "PRIV_DEBUG";	break;
2662 		case PRIV_AWARE:	s = "PRIV_AWARE";	break;
2663 		case PRIV_XPOLICY:	s = "PRIV_XPOLICY";	break;
2664 		case PRIV_AWARE_RESET:  s = "PRIV_AWARE_RESET"; break;
2665 		case PRIV_PFEXEC:	s = "PRIV_PFEXEC";	break;
2666 		case NET_MAC_AWARE:	s =  "NET_MAC_AWARE";	break;
2667 		case NET_MAC_AWARE_INHERIT:
2668 			s = "NET_MAC_AWARE_INHERIT";
2669 			break;
2670 		}
2671 	}
2672 
2673 	if (s == NULL)
2674 		prt_dec(pri, 0, val);
2675 	else
2676 		outstring(pri, s);
2677 }
2678 
2679 /*
2680  * Print lgrp_affinity_{get,set}() arguments.
2681  */
2682 /*ARGSUSED*/
2683 void
prt_laf(private_t * pri,int raw,long val)2684 prt_laf(private_t *pri, int raw, long val)
2685 {
2686 	lgrp_affinity_args_t	laff;
2687 
2688 	if (Pread(Proc, &laff, sizeof (lgrp_affinity_args_t), val) !=
2689 	    sizeof (lgrp_affinity_args_t)) {
2690 		prt_hex(pri, 0, val);
2691 		return;
2692 	}
2693 	/*
2694 	 * arrange the arguments in the order that user calls with
2695 	 */
2696 	prt_dec(pri, 0, laff.idtype);
2697 	outstring(pri, ", ");
2698 	prt_dec(pri, 0, laff.id);
2699 	outstring(pri, ", ");
2700 	prt_dec(pri, 0, laff.lgrp);
2701 	outstring(pri, ", ");
2702 	if (pri->sys_args[0] == LGRP_SYS_AFFINITY_SET)
2703 		prt_dec(pri, 0, laff.aff);
2704 }
2705 
2706 /*
2707  * Print a key_t as IPC_PRIVATE if it is 0.
2708  */
2709 void
prt_key(private_t * pri,int raw,long val)2710 prt_key(private_t *pri, int raw, long val)
2711 {
2712 	if (!raw && val == 0)
2713 		outstring(pri, "IPC_PRIVATE");
2714 	else
2715 		prt_dec(pri, 0, val);
2716 }
2717 
2718 
2719 /*
2720  * Print zone_getattr() attribute types.
2721  */
2722 void
prt_zga(private_t * pri,int raw,long val)2723 prt_zga(private_t *pri, int raw, long val)
2724 {
2725 	const char *s = NULL;
2726 
2727 	if (!raw) {
2728 		switch ((int)val) {
2729 		case ZONE_ATTR_NAME:	s = "ZONE_ATTR_NAME";	break;
2730 		case ZONE_ATTR_ROOT:	s = "ZONE_ATTR_ROOT";	break;
2731 		case ZONE_ATTR_STATUS:	s = "ZONE_ATTR_STATUS";	break;
2732 		case ZONE_ATTR_PRIVSET:	s = "ZONE_ATTR_PRIVSET"; break;
2733 		case ZONE_ATTR_UNIQID:	s = "ZONE_ATTR_UNIQID"; break;
2734 		case ZONE_ATTR_POOLID:	s = "ZONE_ATTR_POOLID"; break;
2735 		case ZONE_ATTR_INITPID:	s = "ZONE_ATTR_INITPID"; break;
2736 		case ZONE_ATTR_SLBL:	s = "ZONE_ATTR_SLBL"; break;
2737 		case ZONE_ATTR_INITNAME:	s = "ZONE_ATTR_INITNAME"; break;
2738 		case ZONE_ATTR_BOOTARGS:	s = "ZONE_ATTR_BOOTARGS"; break;
2739 		case ZONE_ATTR_BRAND:	s = "ZONE_ATTR_BRAND"; break;
2740 		case ZONE_ATTR_FLAGS:	s = "ZONE_ATTR_FLAGS"; break;
2741 		case ZONE_ATTR_PHYS_MCAP: s = "ZONE_ATTR_PHYS_MCAP"; break;
2742 		}
2743 	}
2744 
2745 	if (s == NULL)
2746 		prt_dec(pri, 0, val);
2747 	else
2748 		outstring(pri, s);
2749 }
2750 
2751 /*
2752  * Print a file descriptor as AT_FDCWD if necessary
2753  */
2754 void
prt_atc(private_t * pri,int raw,long val)2755 prt_atc(private_t *pri, int raw, long val)
2756 {
2757 	if ((int)val == AT_FDCWD) {
2758 		if (raw)
2759 			prt_hex(pri, 0, (uint_t)AT_FDCWD);
2760 		else
2761 			outstring(pri, "AT_FDCWD");
2762 	} else {
2763 		prt_dec(pri, 0, val);
2764 	}
2765 }
2766 
2767 /*
2768  * Print Trusted Networking database operation codes (labelsys; tn*)
2769  */
2770 static void
prt_tnd(private_t * pri,int raw,long val)2771 prt_tnd(private_t *pri, int raw, long val)
2772 {
2773 	const char *s = NULL;
2774 
2775 	if (!raw) {
2776 		switch ((tsol_dbops_t)val) {
2777 		case TNDB_NOOP:		s = "TNDB_NOOP";	break;
2778 		case TNDB_LOAD:		s = "TNDB_LOAD";	break;
2779 		case TNDB_DELETE:	s = "TNDB_DELETE";	break;
2780 		case TNDB_FLUSH:	s = "TNDB_FLUSH";	break;
2781 		case TNDB_GET:		s = "TNDB_GET";		break;
2782 		}
2783 	}
2784 
2785 	if (s == NULL)
2786 		prt_dec(pri, 0, val);
2787 	else
2788 		outstring(pri, s);
2789 }
2790 
2791 /*
2792  * Print LIO_XX flags
2793  */
2794 void
prt_lio(private_t * pri,int raw,long val)2795 prt_lio(private_t *pri, int raw, long val)
2796 {
2797 	if (raw)
2798 		prt_dec(pri, 0, val);
2799 	else if (val == LIO_WAIT)
2800 		outstring(pri, "LIO_WAIT");
2801 	else if (val == LIO_NOWAIT)
2802 		outstring(pri, "LIO_NOWAIT");
2803 	else
2804 		prt_dec(pri, 0, val);
2805 }
2806 
2807 const char *
door_flags(private_t * pri,long val)2808 door_flags(private_t *pri, long val)
2809 {
2810 	door_attr_t attr = (door_attr_t)val;
2811 	char *str = pri->code_buf;
2812 
2813 	*str = '\0';
2814 #define	PROCESS_FLAG(flg)						\
2815 	if (attr & flg) {						\
2816 		(void) strlcat(str, "|" #flg, sizeof (pri->code_buf));	\
2817 		attr &= ~flg;						\
2818 	}
2819 
2820 	PROCESS_FLAG(DOOR_UNREF);
2821 	PROCESS_FLAG(DOOR_UNREF_MULTI);
2822 	PROCESS_FLAG(DOOR_PRIVATE);
2823 	PROCESS_FLAG(DOOR_REFUSE_DESC);
2824 	PROCESS_FLAG(DOOR_NO_CANCEL);
2825 	PROCESS_FLAG(DOOR_LOCAL);
2826 	PROCESS_FLAG(DOOR_REVOKED);
2827 	PROCESS_FLAG(DOOR_IS_UNREF);
2828 #undef PROCESS_FLAG
2829 
2830 	if (attr != 0 || *str == '\0') {
2831 		size_t len = strlen(str);
2832 		(void) snprintf(str + len, sizeof (pri->code_buf) - len,
2833 		    "|0x%X", attr);
2834 	}
2835 
2836 	return (str + 1);
2837 }
2838 
2839 /*
2840  * Print door_create() flags
2841  */
2842 void
prt_dfl(private_t * pri,int raw,long val)2843 prt_dfl(private_t *pri, int raw, long val)
2844 {
2845 	if (raw)
2846 		prt_hex(pri, 0, val);
2847 	else
2848 		outstring(pri, door_flags(pri, val));
2849 }
2850 
2851 /*
2852  * Print door_*param() param argument
2853  */
2854 void
prt_dpm(private_t * pri,int raw,long val)2855 prt_dpm(private_t *pri, int raw, long val)
2856 {
2857 	if (raw)
2858 		prt_hex(pri, 0, val);
2859 	else if (val == DOOR_PARAM_DESC_MAX)
2860 		outstring(pri, "DOOR_PARAM_DESC_MAX");
2861 	else if (val == DOOR_PARAM_DATA_MIN)
2862 		outstring(pri, "DOOR_PARAM_DATA_MIN");
2863 	else if (val == DOOR_PARAM_DATA_MAX)
2864 		outstring(pri, "DOOR_PARAM_DATA_MAX");
2865 	else
2866 		prt_hex(pri, 0, val);
2867 }
2868 
2869 /*
2870  * Print rctlsys subcodes
2871  */
2872 void
prt_rsc(private_t * pri,int raw,long val)2873 prt_rsc(private_t *pri, int raw, long val)	/* print utssys code */
2874 {
2875 	const char *s = raw? NULL : rctlsyscode(val);
2876 
2877 	if (s == NULL)
2878 		prt_dec(pri, 0, val);
2879 	else
2880 		outstring(pri, s);
2881 }
2882 
2883 /*
2884  * Print getrctl flags
2885  */
2886 void
prt_rgf(private_t * pri,int raw,long val)2887 prt_rgf(private_t *pri, int raw, long val)
2888 {
2889 	long action = val & (~RCTLSYS_ACTION_MASK);
2890 
2891 	if (raw)
2892 		prt_hex(pri, 0, val);
2893 	else if (action == RCTL_FIRST)
2894 		outstring(pri, "RCTL_FIRST");
2895 	else if (action == RCTL_NEXT)
2896 		outstring(pri, "RCTL_NEXT");
2897 	else if (action == RCTL_USAGE)
2898 		outstring(pri, "RCTL_USAGE");
2899 	else
2900 		prt_hex(pri, 0, val);
2901 }
2902 
2903 /*
2904  * Print setrctl flags
2905  */
2906 void
prt_rsf(private_t * pri,int raw,long val)2907 prt_rsf(private_t *pri, int raw, long val)
2908 {
2909 	long action = val & (~RCTLSYS_ACTION_MASK);
2910 	long pval = val & RCTL_LOCAL_ACTION_MASK;
2911 	char *s = pri->code_buf;
2912 
2913 	if (raw) {
2914 		prt_hex(pri, 0, val);
2915 		return;
2916 	} else if (action == RCTL_INSERT)
2917 		(void) strcpy(s, "RCTL_INSERT");
2918 	else if (action == RCTL_DELETE)
2919 		(void) strcpy(s, "RCTL_DELETE");
2920 	else if (action == RCTL_REPLACE)
2921 		(void) strcpy(s, "RCTL_REPLACE");
2922 	else {
2923 		prt_hex(pri, 0, val);
2924 		return;
2925 	}
2926 
2927 	if (pval & RCTL_USE_RECIPIENT_PID) {
2928 		pval ^= RCTL_USE_RECIPIENT_PID;
2929 		(void) strlcat(s, "|RCTL_USE_RECIPIENT_PID",
2930 		    sizeof (pri->code_buf));
2931 	}
2932 
2933 	if ((pval & RCTLSYS_ACTION_MASK) != 0)
2934 		prt_hex(pri, 0, val);
2935 	else if (*s != '\0')
2936 		outstring(pri, s);
2937 	else
2938 		prt_hex(pri, 0, val);
2939 }
2940 
2941 /*
2942  * Print rctlctl flags
2943  */
2944 void
prt_rcf(private_t * pri,int raw,long val)2945 prt_rcf(private_t *pri, int raw, long val)
2946 {
2947 	long action = val & (~RCTLSYS_ACTION_MASK);
2948 
2949 	if (raw)
2950 		prt_hex(pri, 0, val);
2951 	else if (action == RCTLCTL_GET)
2952 		outstring(pri, "RCTLCTL_GET");
2953 	else if (action == RCTLCTL_SET)
2954 		outstring(pri, "RCTLCTL_SET");
2955 	else
2956 		prt_hex(pri, 0, val);
2957 }
2958 
2959 /*
2960  * Print setprojrctl flags
2961  */
2962 void
prt_spf(private_t * pri,int raw,long val)2963 prt_spf(private_t *pri, int raw, long val)
2964 {
2965 	long action = val & TASK_PROJ_MASK;
2966 
2967 	if (!raw && (action == TASK_PROJ_PURGE))
2968 		outstring(pri, "TASK_PROJ_PURGE");
2969 	else
2970 		prt_hex(pri, 0, val);
2971 }
2972 
2973 /*
2974  * Print forkx() flags
2975  */
2976 void
prt_fxf(private_t * pri,int raw,long val)2977 prt_fxf(private_t *pri, int raw, long val)
2978 {
2979 	char *str;
2980 
2981 	if (val == 0)
2982 		outstring(pri, "0");
2983 	else if (raw || (val & ~(FORK_NOSIGCHLD | FORK_WAITPID)))
2984 		prt_hhx(pri, 0, val);
2985 	else {
2986 		str = pri->code_buf;
2987 		*str = '\0';
2988 		if (val & FORK_NOSIGCHLD)
2989 			(void) strlcat(str, "|FORK_NOSIGCHLD",
2990 			    sizeof (pri->code_buf));
2991 		if (val & FORK_WAITPID)
2992 			(void) strlcat(str, "|FORK_WAITPID",
2993 			    sizeof (pri->code_buf));
2994 		outstring(pri, str + 1);
2995 	}
2996 }
2997 
2998 /*
2999  * Print faccessat() flag
3000  */
3001 void
prt_fat(private_t * pri,int raw,long val)3002 prt_fat(private_t *pri, int raw, long val)
3003 {
3004 	if (val == 0)
3005 		outstring(pri, "0");
3006 	else if (!raw && val == AT_EACCESS)
3007 		outstring(pri, "AT_EACCESS");
3008 	else
3009 		prt_hex(pri, 0, val);
3010 }
3011 
3012 /*
3013  * Print unlinkat() flag
3014  */
3015 void
prt_uat(private_t * pri,int raw,long val)3016 prt_uat(private_t *pri, int raw, long val)
3017 {
3018 	if (val == 0)
3019 		outstring(pri, "0");
3020 	else if (!raw && val == AT_REMOVEDIR)
3021 		outstring(pri, "AT_REMOVEDIR");
3022 	else
3023 		prt_hex(pri, 0, val);
3024 }
3025 
3026 /*
3027  * Print AT_SYMLINK_NOFOLLOW / AT_SYMLINK_FOLLOW flag
3028  */
3029 void
prt_snf(private_t * pri,int raw,long val)3030 prt_snf(private_t *pri, int raw, long val)
3031 {
3032 	if (val == 0)
3033 		outstring(pri, "0");
3034 	else if (!raw && val == AT_SYMLINK_NOFOLLOW)
3035 		outstring(pri, "AT_SYMLINK_NOFOLLOW");
3036 	else if (!raw && val == AT_SYMLINK_FOLLOW)
3037 		outstring(pri, "AT_SYMLINK_FOLLOW");
3038 	else
3039 		prt_hex(pri, 0, val);
3040 }
3041 
3042 void
prt_grf(private_t * pri,int raw,long val)3043 prt_grf(private_t *pri, int raw, long val)
3044 {
3045 	int first = 1;
3046 
3047 	if (raw != 0 || val == 0 ||
3048 	    (val & ~(GRND_NONBLOCK | GRND_RANDOM)) != 0) {
3049 		outstring(pri, "0");
3050 		return;
3051 	}
3052 
3053 	if (val & GRND_NONBLOCK) {
3054 		outstring(pri, "|GRND_NONBLOCK" + first);
3055 		first = 0;
3056 	}
3057 	if (val & GRND_RANDOM) {
3058 		outstring(pri, "|GRND_RANDOM" + first);
3059 		first = 0;
3060 	}
3061 }
3062 
3063 void
prt_exc(private_t * pri,int raw,long val)3064 prt_exc(private_t *pri, int raw, long val)
3065 {
3066 #define	CBSIZE	sizeof (pri->code_buf)
3067 	char *str = pri->code_buf;
3068 	size_t used = 0;
3069 
3070 	if (raw) {
3071 		prt_hex(pri, 0, val);
3072 		return;
3073 	}
3074 	if (val == 0) {
3075 		outstring(pri, "0");
3076 		return;
3077 	}
3078 
3079 	*str = '\0';
3080 	if (val & EXEC_DESCRIPTOR) {
3081 		used = strlcat(str, "|EXEC_DESCRIPTOR", CBSIZE);
3082 		val &= ~EXEC_DESCRIPTOR;
3083 	}
3084 
3085 	if (val != 0 && used <= CBSIZE)
3086 		used += snprintf(str + used, CBSIZE - used, "|0x%lx", val);
3087 
3088 	if (used >= CBSIZE)
3089 		(void) snprintf(str + 1, CBSIZE - 1, "0x%lx", val);
3090 
3091 	outstring(pri, str + 1);
3092 #undef CBSIZE
3093 }
3094 
3095 /*
3096  * Print recv*(), send*() flags. This includes all the msg_flags data as well as
3097  * they're the same namespace.
3098  */
3099 static struct sendrecv_flags {
3100 	long		val;
3101 	const char	*name;
3102 } sendrecv_flags[] = {
3103 	{ MSG_OOB, "|MSG_OOB" },
3104 	{ MSG_PEEK, "|MSG_PEEK" },
3105 	{ MSG_DONTROUTE, "|MSG_DONTROUTE" },
3106 	{ MSG_CTRUNC, "|MSG_CTRUNC" },
3107 	{ MSG_TRUNC, "|MSG_TRUNC" },
3108 	{ MSG_WAITALL, "|MSG_WAITALL" },
3109 	{ MSG_DONTWAIT, "|MSG_DONTWAIT" },
3110 	{ MSG_NOTIFICATION, "|MSG_NOTIFICATION" },
3111 	{ MSG_NOSIGNAL, "|MSG_NOSIGNAL" },
3112 	{ MSG_DUPCTRL, "|MSG_DUPCTRL" },
3113 	{ MSG_CMSG_CLOEXEC, "|MSG_CMSG_CLOEXEC" },
3114 	{ MSG_CMSG_CLOFORK, "|MSG_CMSG_CLOFORK" },
3115 	{ MSG_XPG4_2, "|MSG_XPG4_2" }
3116 };
3117 
3118 void
prt_srf(private_t * pri,int raw,long val)3119 prt_srf(private_t *pri, int raw, long val)
3120 {
3121 #define	CBSIZE	sizeof (pri->code_buf)
3122 	char *s = pri->code_buf;
3123 	size_t used = 1;
3124 
3125 	if (raw) {
3126 		(void) snprintf(s, CBSIZE, "0x%lx", val);
3127 		outstring(pri, s);
3128 		return;
3129 	}
3130 	if (val == 0) {
3131 		outstring(pri, "(no flags)");
3132 		return;
3133 	}
3134 
3135 	*s = '\0';
3136 	for (size_t i = 0; i < ARRAY_SIZE(sendrecv_flags); i++) {
3137 		struct sendrecv_flags *fp = &sendrecv_flags[i];
3138 		if (val & fp->val) {
3139 			used = strlcat(s, fp->name, CBSIZE);
3140 			val &= ~fp->val;
3141 		}
3142 	}
3143 
3144 	if (val != 0 && used <= CBSIZE)
3145 		used += snprintf(s + used, CBSIZE - used, "|0x%lx", val);
3146 
3147 	if (used >= CBSIZE)
3148 		(void) snprintf(s + 1, CBSIZE-1, "0x%lx", val);
3149 	outstring(pri, s + 1);
3150 #undef CBSIZE
3151 }
3152 
3153 /*
3154  * Print fdsync() internal argument.
3155  */
3156 void
prt_fds(private_t * pri,int raw,long val)3157 prt_fds(private_t *pri, int raw, long val)
3158 {
3159 	if (raw) {
3160 		prt_hex(pri, 0, val);
3161 		return;
3162 	}
3163 
3164 	switch (val) {
3165 	case FDSYNC_FS:
3166 		outstring(pri, "FDSYNC_FS");
3167 		break;
3168 	case FDSYNC_FILE:
3169 		outstring(pri, "FDSYNC_FILE");
3170 		break;
3171 	case FDSYNC_DATA:
3172 		outstring(pri, "FDSYNC_DATA");
3173 		break;
3174 	default:
3175 		prt_hex(pri, 0, val);
3176 		break;
3177 	}
3178 }
3179 
3180 /*
3181  * Array of pointers to print functions, one for each format.
3182  */
3183 void (* const Print[])() = {
3184 	prt_nov,	/* NOV -- no value */
3185 	prt_dec,	/* DEC -- print value in decimal */
3186 	prt_oct,	/* OCT -- print value in octal */
3187 	prt_hex,	/* HEX -- print value in hexadecimal */
3188 	prt_dex,	/* DEX -- print value in hexadecimal if big enough */
3189 	prt_stg,	/* STG -- print value as string */
3190 	prt_ioc,	/* IOC -- print ioctl code */
3191 	prt_fcn,	/* FCN -- print fcntl code */
3192 	prt_s86,	/* S86 -- print sysi86 code */
3193 	prt_uts,	/* UTS -- print utssys code */
3194 	prt_opn,	/* OPN -- print open code */
3195 	prt_sig,	/* SIG -- print signal name plus flags */
3196 	prt_uat,	/* UAT -- print unlinkat() flag */
3197 	prt_msc,	/* MSC -- print msgsys command */
3198 	prt_msf,	/* MSF -- print msgsys flags */
3199 	prt_smc,	/* SMC -- print semsys command */
3200 	prt_sef,	/* SEF -- print semsys flags */
3201 	prt_shc,	/* SHC -- print shmsys command */
3202 	prt_shf,	/* SHF -- print shmsys flags */
3203 	prt_fat,	/* FAT -- print faccessat( flag */
3204 	prt_sfs,	/* SFS -- print sysfs code */
3205 	prt_rst,	/* RST -- print string returned by syscall */
3206 	prt_smf,	/* SMF -- print streams message flags */
3207 	prt_ioa,	/* IOA -- print ioctl argument */
3208 	prt_pip,	/* PIP -- print pipe flags */
3209 	prt_mtf,	/* MTF -- print mount flags */
3210 	prt_mft,	/* MFT -- print mount file system type */
3211 	prt_iob,	/* IOB -- print contents of I/O buffer */
3212 	prt_hhx,	/* HHX -- print value in hexadecimal (half size) */
3213 	prt_wop,	/* WOP -- print waitsys() options */
3214 	prt_spm,	/* SPM -- print sigprocmask argument */
3215 	prt_rlk,	/* RLK -- print readlink buffer */
3216 	prt_mpr,	/* MPR -- print mmap()/mprotect() flags */
3217 	prt_mty,	/* MTY -- print mmap() mapping type flags */
3218 	prt_mcf,	/* MCF -- print memcntl() function */
3219 	prt_mc4,	/* MC4 -- print memcntl() (fourth) argument */
3220 	prt_mc5,	/* MC5 -- print memcntl() (fifth) argument */
3221 	prt_mad,	/* MAD -- print madvise() argument */
3222 	prt_ulm,	/* ULM -- print ulimit() argument */
3223 	prt_rlm,	/* RLM -- print get/setrlimit() argument */
3224 	prt_cnf,	/* CNF -- print sysconfig() argument */
3225 	prt_inf,	/* INF -- print sysinfo() argument */
3226 	prt_ptc,	/* PTC -- print pathconf/fpathconf() argument */
3227 	prt_fui,	/* FUI -- print fusers() input argument */
3228 	prt_idt,	/* IDT -- print idtype_t, waitid() argument */
3229 	prt_lwf,	/* LWF -- print lwp_create() flags */
3230 	prt_itm,	/* ITM -- print [get|set]itimer() arg */
3231 	prt_llo,	/* LLO -- print long long offset arg */
3232 	prt_mod,	/* MOD -- print modctl() subcode */
3233 	prt_whn,	/* WHN -- print lseek() whence arguiment */
3234 	prt_acl,	/* ACL -- print acl() code */
3235 	prt_aio,	/* AIO -- print kaio() code */
3236 	prt_aud,	/* AUD -- print auditsys() code */
3237 	prt_uns,	/* DEC -- print value in unsigned decimal */
3238 	prt_clc,	/* CLC -- print cladm command argument */
3239 	prt_clf,	/* CLF -- print cladm flag argument */
3240 	prt_cor,	/* COR -- print corectl() subcode */
3241 	prt_cco,	/* CCO -- print corectl() options */
3242 	prt_ccc,	/* CCC -- print corectl() content */
3243 	prt_rcc,	/* RCC -- print corectl() returned content */
3244 	prt_cpc,	/* CPC -- print cpc() subcode */
3245 	prt_sqc,	/* SQC -- print sigqueue() si_code argument */
3246 	prt_pc4,	/* PC4 -- print priocntlsys() (fourth) argument */
3247 	prt_pc5,	/* PC5 -- print priocntlsys() (key, value) pairs */
3248 	prt_pst,	/* PST -- print processor set id */
3249 	prt_mif,	/* MIF -- print meminfo() arguments */
3250 	prt_pfm,	/* PFM -- print so_socket() proto-family (1st) arg */
3251 	prt_skt,	/* SKT -- print so_socket() socket-type (2nd) arg */
3252 	prt_skp,	/* SKP -- print so_socket() protocol (3rd) arg */
3253 	prt_skv,	/* SKV -- print socket version arg */
3254 	prt_sol,	/* SOL -- print [sg]etsockopt() level (2nd) arg */
3255 	prt_son,	/* SON -- print [sg]etsockopt() opt-name (3rd) arg */
3256 	prt_utt,	/* UTT -- print utrap type */
3257 	prt_uth,	/* UTH -- print utrap handler */
3258 	prt_acc,	/* ACC -- print access() flags */
3259 	prt_sht,	/* SHT -- print shutdown() how (2nd) argument */
3260 	prt_ffg,	/* FFG -- print fcntl() flags (3rd) argument */
3261 	prt_prs,	/* PRS -- print privilege set */
3262 	prt_pro,	/* PRO -- print privilege set operation */
3263 	prt_prn,	/* PRN -- print privilege set name */
3264 	prt_pfl,	/* PFL -- print privilege/process flag name */
3265 	prt_laf,	/* LAF -- print lgrp_affinity arguments */
3266 	prt_key,	/* KEY -- print key_t 0 as IPC_PRIVATE */
3267 	prt_zga,	/* ZGA -- print zone_getattr attribute types */
3268 	prt_atc,	/* ATC -- print AT_FDCWD or file descriptor */
3269 	prt_lio,	/* LIO -- print LIO_XX flags */
3270 	prt_dfl,	/* DFL -- print door_create() flags */
3271 	prt_dpm,	/* DPM -- print DOOR_PARAM_XX flags */
3272 	prt_tnd,	/* TND -- print trusted network data base opcode */
3273 	prt_rsc,	/* RSC -- print rctlsys() subcodes */
3274 	prt_rgf,	/* RGF -- print getrctl() flags */
3275 	prt_rsf,	/* RSF -- print setrctl() flags */
3276 	prt_rcf,	/* RCF -- print rctlsys_ctl() flags */
3277 	prt_fxf,	/* FXF -- print forkx() flags */
3278 	prt_spf,	/* SPF -- print rctlsys_projset() flags */
3279 	prt_un1,	/* UN1 -- as prt_uns except for -1 */
3280 	prt_mob,	/* MOB -- print mmapobj() flags */
3281 	prt_snf,	/* SNF -- print AT_SYMLINK_[NO]FOLLOW flag */
3282 	prt_skc,	/* SKC -- print sockconfig() subcode */
3283 	prt_acf,	/* ACF -- print accept4 flags */
3284 	prt_pfd,	/* PFD -- print pipe fds */
3285 	prt_grf,	/* GRF -- print getrandom flags */
3286 	prt_psdelta,	/* PSDLT -- print psecflags(2) delta */
3287 	prt_psfw,	/* PSFW -- print psecflags(2) set */
3288 	prt_exc,	/* EXC -- print execvex() flags */
3289 	prt_ffd,	/* FFD -- print fcntl() F_SETFD flags */
3290 	prt_srf,	/* SRF -- print send*()/recv*() flags */
3291 	prt_fds,	/* FDS -- print fdsync() flags */
3292 	prt_dec,	/* HID -- hidden argument, make this the last one */
3293 };
3294