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