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