xref: /illumos-gate/usr/src/cmd/truss/print.c (revision 2974b68dd4245e041051c854ef990e47c8271e71)
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))
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 	}
756 
757 	return ((const char *)str);
758 #undef CBSIZE
759 }
760 
761 void
762 prt_mpr(private_t *pri, int raw, long val) /* print mmap()/mprotect() flags */
763 {
764 	const char *s = raw? NULL : mmap_protect(pri, val);
765 
766 	if (s == NULL)
767 		prt_hhx(pri, 0, val);
768 	else
769 		outstring(pri, s);
770 }
771 
772 void
773 prt_mty(private_t *pri, int raw, long val) /* print mmap() mapping type flags */
774 {
775 	const char *s = raw? NULL : mmap_type(pri, val);
776 
777 	if (s == NULL)
778 		prt_hhx(pri, 0, val);
779 	else
780 		outstring(pri, s);
781 }
782 
783 void
784 prt_mob(private_t *pri, int raw, long val) /* print mmapobj() flags */
785 {
786 	if (val == 0)
787 		prt_dec(pri, 0, val);
788 	else if (raw || (val & ~(MMOBJ_PADDING|MMOBJ_INTERPRET)) != 0)
789 		prt_hhx(pri, 0, val);
790 	else {
791 #define	CBSIZE	sizeof (pri->code_buf)
792 		char *s = pri->code_buf;
793 
794 		*s = '\0';
795 		if (val & MMOBJ_PADDING)
796 			(void) strlcat(s, "|MMOBJ_PADDING", CBSIZE);
797 		if (val & MMOBJ_INTERPRET)
798 			(void) strlcat(s, "|MMOBJ_INTERPRET", CBSIZE);
799 		outstring(pri, s + 1);
800 #undef CBSIZE
801 	}
802 }
803 
804 /*ARGSUSED*/
805 void
806 prt_mcf(private_t *pri, int raw, long val)	/* print memcntl() function */
807 {
808 	const char *s = NULL;
809 
810 	if (!raw) {
811 		switch (val) {
812 		case MC_SYNC:		s = "MC_SYNC";		break;
813 		case MC_LOCK:		s = "MC_LOCK";		break;
814 		case MC_UNLOCK:		s = "MC_UNLOCK";	break;
815 		case MC_ADVISE:		s = "MC_ADVISE";	break;
816 		case MC_LOCKAS:		s = "MC_LOCKAS";	break;
817 		case MC_UNLOCKAS:	s = "MC_UNLOCKAS";	break;
818 		case MC_HAT_ADVISE:	s = "MC_HAT_ADVISE";	break;
819 		}
820 	}
821 
822 	if (s == NULL)
823 		prt_dec(pri, 0, val);
824 	else
825 		outstring(pri, s);
826 }
827 
828 void
829 prt_mad(private_t *pri, int raw, long val)	/* print madvise() argument */
830 {
831 	const char *s = NULL;
832 
833 	if (!raw) {
834 		switch (val) {
835 		case MADV_NORMAL:	s = "MADV_NORMAL";	break;
836 		case MADV_RANDOM:	s = "MADV_RANDOM";	break;
837 		case MADV_SEQUENTIAL:	s = "MADV_SEQUENTIAL";	break;
838 		case MADV_WILLNEED:	s = "MADV_WILLNEED";	break;
839 		case MADV_DONTNEED:	s = "MADV_DONTNEED";	break;
840 		case MADV_FREE:		s = "MADV_FREE";	break;
841 		case MADV_ACCESS_DEFAULT: s = "MADV_ACCESS_DEFAULT";	break;
842 		case MADV_ACCESS_LWP:	s = "MADV_ACCESS_LWP";	break;
843 		case MADV_ACCESS_MANY:	s = "MADV_ACCESS_MANY";	break;
844 		}
845 	}
846 
847 	if (s == NULL)
848 		prt_dec(pri, 0, val);
849 	else
850 		outstring(pri, s);
851 }
852 
853 void
854 prt_mc4(private_t *pri, int raw, long val) /* print memcntl() (4th) argument */
855 {
856 	if (val == 0)
857 		prt_dec(pri, 0, val);
858 	else if (raw)
859 		prt_hhx(pri, 0, val);
860 	else {
861 		char *s = NULL;
862 
863 #define	CBSIZE	sizeof (pri->code_buf)
864 		/* cheating -- look at memcntl func */
865 		switch (pri->sys_args[2]) {
866 		case MC_ADVISE:
867 			prt_mad(pri, 0, val);
868 			return;
869 
870 		case MC_SYNC:
871 			if ((val & ~(MS_SYNC|MS_ASYNC|MS_INVALIDATE)) == 0) {
872 				*(s = pri->code_buf) = '\0';
873 				if (val & MS_SYNC)
874 					(void) strlcat(s, "|MS_SYNC", CBSIZE);
875 				if (val & MS_ASYNC)
876 					(void) strlcat(s, "|MS_ASYNC", CBSIZE);
877 				if (val & MS_INVALIDATE)
878 					(void) strlcat(s, "|MS_INVALIDATE",
879 					    CBSIZE);
880 			}
881 			break;
882 
883 		case MC_LOCKAS:
884 		case MC_UNLOCKAS:
885 			if ((val & ~(MCL_CURRENT|MCL_FUTURE)) == 0) {
886 				*(s = pri->code_buf) = '\0';
887 				if (val & MCL_CURRENT)
888 					(void) strlcat(s, "|MCL_CURRENT",
889 					    CBSIZE);
890 				if (val & MCL_FUTURE)
891 					(void) strlcat(s, "|MCL_FUTURE",
892 					    CBSIZE);
893 			}
894 			break;
895 		}
896 #undef CBSIZE
897 
898 		if (s == NULL || *s == '\0')
899 			prt_hhx(pri, 0, val);
900 		else
901 			outstring(pri, ++s);
902 	}
903 }
904 
905 void
906 prt_mc5(private_t *pri, int raw, long val) /* print memcntl() (5th) argument */
907 {
908 	char *s;
909 
910 #define	CBSIZE	sizeof (pri->code_buf)
911 	if (val == 0)
912 		prt_dec(pri, 0, val);
913 	else if (raw || (val & ~VALID_ATTR))
914 		prt_hhx(pri, 0, val);
915 	else {
916 		s = pri->code_buf;
917 		*s = '\0';
918 		if (val & SHARED)
919 			(void) strlcat(s, "|SHARED", CBSIZE);
920 		if (val & PRIVATE)
921 			(void) strlcat(s, "|PRIVATE", CBSIZE);
922 		if (val & PROT_READ)
923 			(void) strlcat(s, "|PROT_READ", CBSIZE);
924 		if (val & PROT_WRITE)
925 			(void) strlcat(s, "|PROT_WRITE", CBSIZE);
926 		if (val & PROT_EXEC)
927 			(void) strlcat(s, "|PROT_EXEC", CBSIZE);
928 		if (*s == '\0')
929 			prt_hhx(pri, 0, val);
930 		else
931 			outstring(pri, ++s);
932 	}
933 #undef CBSIZE
934 }
935 
936 void
937 prt_ulm(private_t *pri, int raw, long val)	/* print ulimit() argument */
938 {
939 	const char *s = NULL;
940 
941 	if (!raw) {
942 		switch (val) {
943 		case UL_GFILLIM:	s = "UL_GFILLIM";	break;
944 		case UL_SFILLIM:	s = "UL_SFILLIM";	break;
945 		case UL_GMEMLIM:	s = "UL_GMEMLIM";	break;
946 		case UL_GDESLIM:	s = "UL_GDESLIM";	break;
947 		}
948 	}
949 
950 	if (s == NULL)
951 		prt_dec(pri, 0, val);
952 	else
953 		outstring(pri, s);
954 }
955 
956 void
957 prt_rlm(private_t *pri, int raw, long val) /* print get/setrlimit() argument */
958 {
959 	const char *s = NULL;
960 
961 	if (!raw) {
962 		switch (val) {
963 		case RLIMIT_CPU:	s = "RLIMIT_CPU";	break;
964 		case RLIMIT_FSIZE:	s = "RLIMIT_FSIZE";	break;
965 		case RLIMIT_DATA:	s = "RLIMIT_DATA";	break;
966 		case RLIMIT_STACK:	s = "RLIMIT_STACK";	break;
967 		case RLIMIT_CORE:	s = "RLIMIT_CORE";	break;
968 		case RLIMIT_NOFILE:	s = "RLIMIT_NOFILE";	break;
969 		case RLIMIT_VMEM:	s = "RLIMIT_VMEM";	break;
970 		}
971 	}
972 
973 	if (s == NULL)
974 		prt_dec(pri, 0, val);
975 	else
976 		outstring(pri, s);
977 }
978 
979 void
980 prt_cnf(private_t *pri, int raw, long val)	/* print sysconfig code */
981 {
982 	const char *s = raw? NULL : sconfname(val);
983 
984 	if (s == NULL)
985 		prt_dec(pri, 0, val);
986 	else
987 		outstring(pri, s);
988 }
989 
990 void
991 prt_inf(private_t *pri, int raw, long val)	/* print sysinfo code */
992 {
993 	const char *s = NULL;
994 
995 	if (!raw) {
996 		switch (val) {
997 		case SI_SYSNAME:	s = "SI_SYSNAME";	break;
998 		case SI_HOSTNAME:	s = "SI_HOSTNAME";	break;
999 		case SI_RELEASE:	s = "SI_RELEASE";	break;
1000 		case SI_VERSION:	s = "SI_VERSION";	break;
1001 		case SI_MACHINE:	s = "SI_MACHINE";	break;
1002 		case SI_ARCHITECTURE:	s = "SI_ARCHITECTURE";	break;
1003 		case SI_ARCHITECTURE_32:s = "SI_ARCHITECTURE_32"; break;
1004 		case SI_ARCHITECTURE_64:s = "SI_ARCHITECTURE_64"; break;
1005 		case SI_ARCHITECTURE_K:	s = "SI_ARCHITECTURE_K"; break;
1006 		case SI_HW_SERIAL:	s = "SI_HW_SERIAL";	break;
1007 		case SI_HW_PROVIDER:	s = "SI_HW_PROVIDER";	break;
1008 		case SI_SRPC_DOMAIN:	s = "SI_SRPC_DOMAIN";	break;
1009 		case SI_SET_HOSTNAME:	s = "SI_SET_HOSTNAME";	break;
1010 		case SI_SET_SRPC_DOMAIN: s = "SI_SET_SRPC_DOMAIN"; break;
1011 		case SI_PLATFORM:	s = "SI_PLATFORM";	break;
1012 		case SI_ISALIST:	s = "SI_ISALIST";	break;
1013 		case SI_DHCP_CACHE:	s = "SI_DHCP_CACHE";	break;
1014 		}
1015 	}
1016 
1017 	if (s == NULL)
1018 		prt_dec(pri, 0, val);
1019 	else
1020 		outstring(pri, s);
1021 }
1022 
1023 void
1024 prt_ptc(private_t *pri, int raw, long val)	/* print pathconf code */
1025 {
1026 	const char *s = raw? NULL : pathconfname(val);
1027 
1028 	if (s == NULL)
1029 		prt_dec(pri, 0, val);
1030 	else
1031 		outstring(pri, s);
1032 }
1033 
1034 void
1035 prt_fui(private_t *pri, int raw, long val) /* print fusers() input argument */
1036 {
1037 	const char *s = raw? NULL : fuiname(val);
1038 
1039 	if (s == NULL)
1040 		prt_hhx(pri, 0, val);
1041 	else
1042 		outstring(pri, s);
1043 }
1044 
1045 void
1046 prt_lwf(private_t *pri, int raw, long val)	/* print lwp_create() flags */
1047 {
1048 	char *s;
1049 
1050 	if (val == 0)
1051 		prt_dec(pri, 0, val);
1052 	else if (raw ||
1053 	    (val & ~(LWP_DAEMON|LWP_DETACHED|LWP_SUSPENDED)))
1054 		prt_hhx(pri, 0, val);
1055 	else {
1056 #define	CBSIZE	sizeof (pri->code_buf)
1057 		s = pri->code_buf;
1058 		*s = '\0';
1059 		if (val & LWP_DAEMON)
1060 			(void) strlcat(s, "|LWP_DAEMON", CBSIZE);
1061 		if (val & LWP_DETACHED)
1062 			(void) strlcat(s, "|LWP_DETACHED", CBSIZE);
1063 		if (val & LWP_SUSPENDED)
1064 			(void) strlcat(s, "|LWP_SUSPENDED", CBSIZE);
1065 		outstring(pri, ++s);
1066 #undef CBSIZE
1067 	}
1068 }
1069 
1070 void
1071 prt_itm(private_t *pri, int raw, long val) /* print [get|set]itimer() arg */
1072 {
1073 	const char *s = NULL;
1074 
1075 	if (!raw) {
1076 		switch (val) {
1077 		case ITIMER_REAL:	s = "ITIMER_REAL";	break;
1078 		case ITIMER_VIRTUAL:	s = "ITIMER_VIRTUAL";	break;
1079 		case ITIMER_PROF:	s = "ITIMER_PROF";	break;
1080 #ifdef ITIMER_REALPROF
1081 		case ITIMER_REALPROF:	s = "ITIMER_REALPROF";	break;
1082 #endif
1083 		}
1084 	}
1085 
1086 	if (s == NULL)
1087 		prt_dec(pri, 0, val);
1088 	else
1089 		outstring(pri, s);
1090 }
1091 
1092 void
1093 prt_mod(private_t *pri, int raw, long val)	/* print modctl() code */
1094 {
1095 	const char *s = NULL;
1096 
1097 	if (!raw) {
1098 		switch (val) {
1099 		case MODLOAD:		s = "MODLOAD";		break;
1100 		case MODUNLOAD:		s = "MODUNLOAD";	break;
1101 		case MODINFO:		s = "MODINFO";		break;
1102 		case MODRESERVED:	s = "MODRESERVED";	break;
1103 		case MODSETMINIROOT:	s = "MODSETMINIROOT";	break;
1104 		case MODADDMAJBIND:	s = "MODADDMAJBIND";	break;
1105 		case MODGETPATH:	s = "MODGETPATH";	break;
1106 		case MODGETPATHLEN:	s = "MODGETPATHLEN";	break;
1107 		case MODREADSYSBIND:	s = "MODREADSYSBIND";	break;
1108 		case MODGETMAJBIND:	s = "MODGETMAJBIND";	break;
1109 		case MODGETNAME:	s = "MODGETNAME";	break;
1110 		case MODSIZEOF_DEVID:	s = "MODSIZEOF_DEVID";	break;
1111 		case MODGETDEVID:	s = "MODGETDEVID";	break;
1112 		case MODSIZEOF_MINORNAME: s = "MODSIZEOF_MINORNAME"; break;
1113 		case MODGETMINORNAME:	s = "MODGETMINORNAME";	break;
1114 		case MODGETFBNAME:	s = "MODGETFBNAME";	break;
1115 		case MODEVENTS:		s = "MODEVENTS";	break;
1116 		case MODREREADDACF:	s = "MODREREADDACF";	break;
1117 		case MODLOADDRVCONF:	s = "MODLOADDRVCONF";	break;
1118 		case MODUNLOADDRVCONF:	s = "MODUNLOADDRVCONF";	break;
1119 		case MODREMMAJBIND:	s = "MODREMMAJBIND";	break;
1120 		case MODDEVT2INSTANCE:	s = "MODDEVT2INSTANCE";	break;
1121 		case MODGETDEVFSPATH_LEN: s = "MODGETDEVFSPATH_LEN"; break;
1122 		case MODGETDEVFSPATH:	s = "MODGETDEVFSPATH";	break;
1123 		case MODDEVID2PATHS:	s = "MODDEVID2PATHS";	break;
1124 		case MODSETDEVPOLICY:	s = "MODSETDEVPOLICY";	break;
1125 		case MODGETDEVPOLICY:	s = "MODGETDEVPOLICY";	break;
1126 		case MODALLOCPRIV:	s = "MODALLOCPRIV";	break;
1127 		case MODGETDEVPOLICYBYNAME:
1128 					s = "MODGETDEVPOLICYBYNAME"; break;
1129 		case MODLOADMINORPERM:	s = "MODLOADMINORPERM"; break;
1130 		case MODADDMINORPERM:	s = "MODADDMINORPERM"; break;
1131 		case MODREMMINORPERM:	s = "MODREMMINORPERM"; break;
1132 		case MODREMDRVCLEANUP:	s = "MODREMDRVCLEANUP"; break;
1133 		case MODDEVEXISTS:	s = "MODDEVEXISTS"; break;
1134 		case MODDEVREADDIR:	s = "MODDEVREADDIR"; break;
1135 		case MODDEVEMPTYDIR:	s = "MODDEVEMPTYDIR"; break;
1136 		case MODDEVNAME:	s = "MODDEVNAME"; break;
1137 		case MODGETDEVFSPATH_MI_LEN:
1138 					s = "MODGETDEVFSPATH_MI_LEN"; break;
1139 		case MODGETDEVFSPATH_MI:
1140 					s = "MODGETDEVFSPATH_MI"; break;
1141 		case MODREMDRVALIAS:	s = "MODREMDRVALIAS"; break;
1142 		case MODHPOPS:	s = "MODHPOPS"; break;
1143 		}
1144 	}
1145 
1146 	if (s == NULL)
1147 		prt_dec(pri, 0, val);
1148 	else
1149 		outstring(pri, s);
1150 }
1151 
1152 void
1153 prt_acl(private_t *pri, int raw, long val)	/* print acl() code */
1154 {
1155 	const char *s = NULL;
1156 
1157 	if (!raw) {
1158 		switch (val) {
1159 		case GETACL:		s = "GETACL";		break;
1160 		case SETACL:		s = "SETACL";		break;
1161 		case GETACLCNT:		s = "GETACLCNT";	break;
1162 		case ACE_GETACL:	s = "ACE_GETACL";	break;
1163 		case ACE_SETACL:	s = "ACE_SETACL";	break;
1164 		case ACE_GETACLCNT:	s = "ACE_GETACLCNT";	break;
1165 		}
1166 	}
1167 
1168 	if (s == NULL)
1169 		prt_dec(pri, 0, val);
1170 	else
1171 		outstring(pri, s);
1172 }
1173 
1174 void
1175 prt_aio(private_t *pri, int raw, long val)	/* print kaio() code */
1176 {
1177 	const char *s = NULL;
1178 	char buf[32];
1179 
1180 	if (!raw) {
1181 		switch (val & ~AIO_POLL_BIT) {
1182 		case AIOREAD:		s = "AIOREAD";		break;
1183 		case AIOWRITE:		s = "AIOWRITE";		break;
1184 		case AIOWAIT:		s = "AIOWAIT";		break;
1185 		case AIOCANCEL:		s = "AIOCANCEL";	break;
1186 		case AIONOTIFY:		s = "AIONOTIFY";	break;
1187 		case AIOINIT:		s = "AIOINIT";		break;
1188 		case AIOSTART:		s = "AIOSTART";		break;
1189 		case AIOLIO:		s = "AIOLIO";		break;
1190 		case AIOSUSPEND:	s = "AIOSUSPEND";	break;
1191 		case AIOERROR:		s = "AIOERROR";		break;
1192 		case AIOLIOWAIT:	s = "AIOLIOWAIT";	break;
1193 		case AIOAREAD:		s = "AIOAREAD";		break;
1194 		case AIOAWRITE:		s = "AIOAWRITE";	break;
1195 		/*
1196 		 * We have to hardcode the values for the 64-bit versions of
1197 		 * these calls, because <sys/aio.h> defines them to be identical
1198 		 * when compiled 64-bit.  If our target is 32-bit, we still need
1199 		 * to decode them correctly.
1200 		 */
1201 		case 13:		s = "AIOLIO64";		break;
1202 		case 14:		s = "AIOSUSPEND64";	break;
1203 		case 15:		s = "AUIOERROR64";	break;
1204 		case 16:		s = "AIOLIOWAIT64";	break;
1205 		case 17:		s = "AIOAREAD64";	break;
1206 		case 18:		s = "AIOAWRITE64";	break;
1207 		case 19:		s = "AIOCANCEL64";	break;
1208 
1209 		/*
1210 		 * AIOFSYNC doesn't correspond to a syscall.
1211 		 */
1212 		case AIOWAITN:		s = "AIOWAITN";		break;
1213 		}
1214 		if (s != NULL && (val & AIO_POLL_BIT)) {
1215 			(void) strlcpy(buf, s, sizeof (buf));
1216 			(void) strlcat(buf, "|AIO_POLL_BIT", sizeof (buf));
1217 			s = (const char *)buf;
1218 		}
1219 	}
1220 
1221 	if (s == NULL)
1222 		prt_dec(pri, 0, val);
1223 	else
1224 		outstring(pri, s);
1225 }
1226 
1227 void
1228 prt_aud(private_t *pri, int raw, long val)	/* print auditsys() code */
1229 {
1230 	const char *s = NULL;
1231 
1232 	if (!raw) {
1233 		switch (val) {
1234 		case BSM_GETAUID:	s = "BSM_GETAUID";	break;
1235 		case BSM_SETAUID:	s = "BSM_SETAUID";	break;
1236 		case BSM_GETAUDIT:	s = "BSM_GETAUDIT";	break;
1237 		case BSM_SETAUDIT:	s = "BSM_SETAUDIT";	break;
1238 		case BSM_AUDIT:		s = "BSM_AUDIT";	break;
1239 		case BSM_AUDITCTL:	s = "BSM_AUDITCTL";	break;
1240 		case BSM_GETAUDIT_ADDR:	s = "BSM_GETAUDIT_ADDR"; break;
1241 		case BSM_SETAUDIT_ADDR:	s = "BSM_SETAUDIT_ADDR"; break;
1242 		}
1243 	}
1244 
1245 	if (s == NULL)
1246 		prt_dec(pri, 0, val);
1247 	else
1248 		outstring(pri, s);
1249 }
1250 
1251 void
1252 prt_cor(private_t *pri, int raw, long val)	/* print corectl() subcode */
1253 {
1254 	const char *s = NULL;
1255 
1256 	if (!raw) {
1257 		switch (val) {
1258 		case CC_SET_OPTIONS:
1259 			s = "CC_SET_OPTIONS";		break;
1260 		case CC_GET_OPTIONS:
1261 			s = "CC_GET_OPTIONS";		break;
1262 		case CC_SET_GLOBAL_PATH:
1263 			s = "CC_SET_GLOBAL_PATH";	break;
1264 		case CC_GET_GLOBAL_PATH:
1265 			s = "CC_GET_GLOBAL_PATH";	break;
1266 		case CC_SET_PROCESS_PATH:
1267 			s = "CC_SET_PROCESS_PATH";	break;
1268 		case CC_GET_PROCESS_PATH:
1269 			s = "CC_GET_PROCESS_PATH";	break;
1270 		case CC_SET_GLOBAL_CONTENT:
1271 			s = "CC_SET_GLOBAL_CONTENT";	break;
1272 		case CC_GET_GLOBAL_CONTENT:
1273 			s = "CC_GET_GLOBAL_CONTENT";	break;
1274 		case CC_SET_PROCESS_CONTENT:
1275 			s = "CC_SET_PROCESS_CONTENT";	break;
1276 		case CC_GET_PROCESS_CONTENT:
1277 			s = "CC_GET_PROCESS_CONTENT";	break;
1278 		case CC_SET_DEFAULT_PATH:
1279 			s = "CC_SET_DEFAULT_PATH";	break;
1280 		case CC_GET_DEFAULT_PATH:
1281 			s = "CC_GET_DEFAULT_PATH";	break;
1282 		case CC_SET_DEFAULT_CONTENT:
1283 			s = "CC_SET_DEFAULT_CONTENT";	break;
1284 		case CC_GET_DEFAULT_CONTENT:
1285 			s = "CC_GET_DEFAULT_CONTENT";	break;
1286 		}
1287 	}
1288 
1289 	if (s == NULL)
1290 		prt_dec(pri, 0, val);
1291 	else
1292 		outstring(pri, s);
1293 }
1294 
1295 void
1296 prt_cco(private_t *pri, int raw, long val)	/* print corectl() options */
1297 {
1298 	char *s;
1299 
1300 	if (val == 0)
1301 		prt_dec(pri, 0, val);
1302 	else if (raw || (val & ~CC_OPTIONS))
1303 		prt_hhx(pri, 0, val);
1304 	else {
1305 #define	CBSIZE	sizeof (pri->code_buf)
1306 		s = pri->code_buf;
1307 		*s = '\0';
1308 		if (val & CC_GLOBAL_PATH)
1309 			(void) strlcat(s, "|CC_GLOBAL_PATH", CBSIZE);
1310 		if (val & CC_PROCESS_PATH)
1311 			(void) strlcat(s, "|CC_PROCESS_PATH", CBSIZE);
1312 		if (val & CC_GLOBAL_SETID)
1313 			(void) strlcat(s, "|CC_GLOBAL_SETID", CBSIZE);
1314 		if (val & CC_PROCESS_SETID)
1315 			(void) strlcat(s, "|CC_PROCESS_SETID", CBSIZE);
1316 		if (val & CC_GLOBAL_LOG)
1317 			(void) strlcat(s, "|CC_GLOBAL_LOG", CBSIZE);
1318 		if (*s == '\0')
1319 			prt_hhx(pri, 0, val);
1320 		else
1321 			outstring(pri, ++s);
1322 #undef CBSIZE
1323 	}
1324 }
1325 
1326 void
1327 prt_ccc(private_t *pri, int raw, long val)	/* print corectl() content */
1328 {
1329 	core_content_t ccc;
1330 
1331 	if (Pread(Proc, &ccc, sizeof (ccc), val) != sizeof (ccc))
1332 		prt_hex(pri, 0, val);
1333 	else if (!raw && proc_content2str(ccc, pri->code_buf,
1334 	    sizeof (pri->code_buf)) >= 0)
1335 		outstring(pri, pri->code_buf);
1336 	else
1337 		prt_hhx(pri, 0, (long)ccc);
1338 }
1339 
1340 void
1341 prt_rcc(private_t *pri, int raw, long val)	/* print corectl() ret. cont. */
1342 {
1343 	core_content_t ccc;
1344 
1345 	if (pri->Errno || Pread(Proc, &ccc, sizeof (ccc), val) != sizeof (ccc))
1346 		prt_hex(pri, 0, val);
1347 	else if (!raw && proc_content2str(ccc, pri->code_buf,
1348 	    sizeof (pri->code_buf)) >= 0)
1349 		outstring(pri, pri->code_buf);
1350 	else
1351 		prt_hhx(pri, 0, (long)ccc);
1352 }
1353 
1354 void
1355 prt_cpc(private_t *pri, int raw, long val)	/* print cpc() subcode */
1356 {
1357 	const char *s = NULL;
1358 
1359 	if (!raw) {
1360 		switch (val) {
1361 		case CPC_BIND:		s = "CPC_BIND";		break;
1362 		case CPC_SAMPLE:	s = "CPC_SAMPLE";	break;
1363 		case CPC_INVALIDATE:	s = "CPC_INVALIDATE";	break;
1364 		case CPC_RELE:		s = "CPC_RELE";		break;
1365 		case CPC_EVLIST_SIZE:	s = "CPC_EVLIST_SIZE";	break;
1366 		case CPC_LIST_EVENTS:	s = "CPC_LIST_EVENTS";	break;
1367 		case CPC_ATTRLIST_SIZE:	s = "CPC_ATTRLIST_SIZE"; break;
1368 		case CPC_LIST_ATTRS:	s = "CPC_LIST_ATTRS";	break;
1369 		case CPC_IMPL_NAME:	s = "CPC_IMPL_NAME";	break;
1370 		case CPC_CPUREF:	s = "CPC_CPUREF";	break;
1371 		case CPC_USR_EVENTS:	s = "CPC_USR_EVENTS";	break;
1372 		case CPC_SYS_EVENTS:	s = "CPC_SYS_EVENTS";	break;
1373 		case CPC_NPIC:		s = "CPC_NPIC";		break;
1374 		case CPC_CAPS:		s = "CPC_CAPS";		break;
1375 		case CPC_ENABLE:	s = "CPC_ENABLE";	break;
1376 		case CPC_DISABLE:	s = "CPC_DISABLE";	break;
1377 		}
1378 	}
1379 
1380 	if (s == NULL)
1381 		prt_dec(pri, 0, val);
1382 	else
1383 		outstring(pri, s);
1384 }
1385 
1386 void
1387 outstring(private_t *pri, const char *s)
1388 {
1389 	int len = strlen(s);
1390 
1391 	GROW(len);
1392 	(void) strcpy(pri->sys_string + pri->sys_leng, s);
1393 	pri->sys_leng += len;
1394 }
1395 
1396 void
1397 grow(private_t *pri, int nbyte)	/* reallocate format buffer if necessary */
1398 {
1399 	while (pri->sys_leng + nbyte >= pri->sys_ssize)
1400 		pri->sys_string = my_realloc(pri->sys_string,
1401 		    pri->sys_ssize *= 2, "format buffer");
1402 }
1403 
1404 void
1405 prt_clc(private_t *pri, int raw, long val)
1406 {
1407 	const char *s = NULL;
1408 
1409 	if (!raw) {
1410 		switch (val) {
1411 		case CL_INITIALIZE:	s = "CL_INITIALIZE";	break;
1412 		case CL_CONFIG:		s = "CL_CONFIG";	break;
1413 		}
1414 	}
1415 
1416 	if (s == NULL)
1417 		prt_dec(pri, 0, val);
1418 	else
1419 		outstring(pri, s);
1420 }
1421 
1422 void
1423 prt_clf(private_t *pri, int raw, long val)
1424 {
1425 	const char *s = NULL;
1426 
1427 	if (!raw) {
1428 		switch (pri->sys_args[0]) {
1429 		case CL_CONFIG:
1430 			switch (pri->sys_args[1]) {
1431 			case CL_NODEID:
1432 				s = "CL_NODEID";		break;
1433 			case CL_HIGHEST_NODEID:
1434 				s = "CL_HIGHEST_NODEID";	break;
1435 			}
1436 			break;
1437 		case CL_INITIALIZE:
1438 			switch (pri->sys_args[1]) {
1439 			case CL_GET_BOOTFLAG:
1440 				s = "CL_GET_BOOTFLAG";		break;
1441 			}
1442 			break;
1443 		}
1444 	}
1445 
1446 	if (s == NULL)
1447 		prt_dec(pri, 0, val);
1448 	else
1449 		outstring(pri, s);
1450 }
1451 
1452 void
1453 prt_sqc(private_t *pri, int raw, long val)	/* print sigqueue() si_code */
1454 {
1455 	const char *s = NULL;
1456 
1457 	if (!raw) {
1458 		switch ((int)val) {
1459 		case SI_QUEUE:		s = "SI_QUEUE";		break;
1460 		case SI_TIMER:		s = "SI_TIMER";		break;
1461 		case SI_ASYNCIO:	s = "SI_ASYNCIO";	break;
1462 		case SI_MESGQ:		s = "SI_MESGQ";		break;
1463 		}
1464 	}
1465 
1466 	if (s == NULL)
1467 		prt_dec(pri, 0, val);
1468 	else
1469 		outstring(pri, s);
1470 }
1471 
1472 /*
1473  * print priocntlsys() (key, value) pair key.
1474  */
1475 void
1476 print_pck(private_t *pri, int raw, long val)
1477 {
1478 	const char	*s = NULL;
1479 	char		clname[PC_CLNMSZ];
1480 
1481 	if ((pri->sys_args[2] != PC_GETXPARMS &&
1482 	    pri->sys_args[2] != PC_SETXPARMS) || val == 0 || raw) {
1483 		prt_dec(pri, 0, val);
1484 		return;
1485 	}
1486 
1487 	if (pri->sys_args[3] == NULL) {
1488 		if (val == PC_KY_CLNAME) {
1489 			s = "PC_KY_CLNAME";
1490 			outstring(pri, s);
1491 		} else
1492 			prt_dec(pri, 0, val);
1493 		return;
1494 	}
1495 
1496 	if (Pread(Proc, &clname, PC_CLNMSZ, pri->sys_args[3]) != PC_CLNMSZ) {
1497 		prt_dec(pri, 0, val);
1498 		return;
1499 	}
1500 
1501 	if (strcmp(clname, "TS") == 0) {
1502 		switch (val) {
1503 		case TS_KY_UPRILIM: 	s = "TS_KY_UPRILIM";	break;
1504 		case TS_KY_UPRI:	s = "TS_KY_UPRI";	break;
1505 		default:					break;
1506 		}
1507 	} else if (strcmp(clname, "IA") == 0) {
1508 		switch (val) {
1509 		case IA_KY_UPRILIM: 	s = "IA_KY_UPRILIM";	break;
1510 		case IA_KY_UPRI:	s = "IA_KY_UPRI";	break;
1511 		case IA_KY_MODE:	s = "IA_KY_MODE";	break;
1512 		default:					break;
1513 		}
1514 	} else if (strcmp(clname, "RT") == 0) {
1515 		switch (val) {
1516 		case RT_KY_PRI: 	s = "RT_KY_PRI";	break;
1517 		case RT_KY_TQSECS:	s = "RT_KY_TQSECS";	break;
1518 		case RT_KY_TQNSECS:	s = "RT_KY_TQNSECS";	break;
1519 		case RT_KY_TQSIG:	s = "RT_KY_TQSIG";	break;
1520 		default:					break;
1521 		}
1522 	} else if (strcmp(clname, "FSS") == 0) {
1523 		switch (val) {
1524 		case FSS_KY_UPRILIM: 	s = "FSS_KY_UPRILIM";	break;
1525 		case FSS_KY_UPRI:	s = "FSS_KY_UPRI";	break;
1526 		default:					break;
1527 		}
1528 	} else if (strcmp(clname, "FX") == 0) {
1529 		switch (val) {
1530 		case FX_KY_UPRILIM: 	s = "FX_KY_UPRILIM";	break;
1531 		case FX_KY_UPRI:	s = "FX_KY_UPRI";	break;
1532 		case FX_KY_TQSECS:	s = "FX_KY_TQSECS";	break;
1533 		case FX_KY_TQNSECS:	s = "FX_KY_TQNSECS";	break;
1534 		default:					break;
1535 		}
1536 	}
1537 
1538 	if (s == NULL)
1539 		prt_dec(pri, 0, val);
1540 	else
1541 		outstring(pri, s);
1542 }
1543 
1544 /*
1545  * print priocntlsys() fourth argument.
1546  */
1547 /*ARGSUSED*/
1548 void
1549 prt_pc4(private_t *pri, int raw, long val)
1550 {
1551 	/* look at pricntlsys function */
1552 	if ((pri->sys_args[2] != PC_GETXPARMS &&
1553 	    pri->sys_args[2] != PC_SETXPARMS))
1554 		prt_hex(pri, 0, val);
1555 	else if (val)
1556 		prt_stg(pri, 0, val);
1557 	else
1558 		prt_dec(pri, 0, val);
1559 }
1560 
1561 /*
1562  * print priocntlsys() (key, value) pairs (5th argument).
1563  */
1564 /*ARGSUSED*/
1565 void
1566 prt_pc5(private_t *pri, int raw, long val)
1567 {
1568 	pc_vaparms_t	prms;
1569 	pc_vaparm_t	*vpp = &prms.pc_parms[0];
1570 	uint_t		cnt;
1571 
1572 
1573 	/* look at pricntlsys function */
1574 	if ((pri->sys_args[2] != PC_GETXPARMS &&
1575 	    pri->sys_args[2] != PC_SETXPARMS) || val == 0) {
1576 		prt_dec(pri, 0, 0);
1577 		return;
1578 	}
1579 
1580 	if (Pread(Proc, &prms, sizeof (prms), val) != sizeof (prms)) {
1581 		prt_hex(pri, 0, val);
1582 		return;
1583 	}
1584 
1585 	if ((cnt = prms.pc_vaparmscnt) > PC_VAPARMCNT)
1586 		return;
1587 
1588 	for (; cnt--; vpp++) {
1589 		print_pck(pri, 0, vpp->pc_key);
1590 		outstring(pri, ", ");
1591 		prt_hex(pri, 0, (long)vpp->pc_parm);
1592 		outstring(pri, ", ");
1593 	}
1594 
1595 	prt_dec(pri, 0, PC_KY_NULL);
1596 }
1597 
1598 /*
1599  * Print processor set id, including logical expansion of "special" ids.
1600  */
1601 void
1602 prt_pst(private_t *pri, int raw, long val)
1603 {
1604 	const char *s = NULL;
1605 
1606 	if (!raw) {
1607 		switch ((psetid_t)val) {
1608 		case PS_NONE:		s = "PS_NONE";		break;
1609 		case PS_QUERY:		s = "PS_QUERY";		break;
1610 		case PS_MYID:		s = "PS_MYID";		break;
1611 		}
1612 	}
1613 
1614 	if (s == NULL)
1615 		prt_dec(pri, 0, val);
1616 	else
1617 		outstring(pri, s);
1618 }
1619 
1620 /*
1621  * Print meminfo() argument.
1622  */
1623 /*ARGSUSED*/
1624 void
1625 prt_mif(private_t *pri, int raw, long val)
1626 {
1627 	struct meminfo	minfo;
1628 
1629 #ifdef _LP64
1630 	if (data_model == PR_MODEL_ILP32) {
1631 		struct meminfo32 minfo32;
1632 
1633 		if (Pread(Proc, &minfo32, sizeof (struct meminfo32), val) !=
1634 			sizeof (struct meminfo32)) {
1635 			prt_dec(pri, 0, pri->sys_args[1]);	/* addr_count */
1636 			outstring(pri, ", ");
1637 			prt_hex(pri, 0, val);
1638 			return;
1639 		}
1640 		/*
1641 		 * arrange the arguments in the order that user calls with
1642 		 */
1643 		prt_hex(pri, 0, minfo32.mi_inaddr);
1644 		outstring(pri, ", ");
1645 		prt_dec(pri, 0, pri->sys_args[1]);	/* addr_count */
1646 		outstring(pri, ", ");
1647 		prt_hex(pri, 0, minfo32.mi_info_req);
1648 		outstring(pri, ", ");
1649 		prt_dec(pri, 0, minfo32.mi_info_count);
1650 		outstring(pri, ", ");
1651 		prt_hex(pri, 0, minfo32.mi_outdata);
1652 		outstring(pri, ", ");
1653 		prt_hex(pri, 0, minfo32.mi_validity);
1654 		return;
1655 	}
1656 #endif
1657 	if (Pread(Proc, &minfo, sizeof (struct meminfo), val) !=
1658 		sizeof (struct meminfo)) {
1659 		prt_dec(pri, 0, pri->sys_args[1]);	/* addr_count */
1660 		outstring(pri, ", ");
1661 		prt_hex(pri, 0, val);
1662 		return;
1663 	}
1664 	/*
1665 	 * arrange the arguments in the order that user calls with
1666 	 */
1667 	prt_hex(pri, 0, (long)minfo.mi_inaddr);
1668 	outstring(pri, ", ");
1669 	prt_dec(pri, 0, pri->sys_args[1]);	/* addr_count */
1670 	outstring(pri, ", ");
1671 	prt_hex(pri, 0, (long)minfo.mi_info_req);
1672 	outstring(pri, ", ");
1673 	prt_dec(pri, 0, minfo.mi_info_count);
1674 	outstring(pri, ", ");
1675 	prt_hex(pri, 0, (long)minfo.mi_outdata);
1676 	outstring(pri, ", ");
1677 	prt_hex(pri, 0, (long)minfo.mi_validity);
1678 }
1679 
1680 
1681 /*
1682  * Print so_socket() 1st argument.
1683  */
1684 /*ARGSUSED*/
1685 void
1686 prt_pfm(private_t *pri, int raw, long val)
1687 {
1688 	/* Protocol Families have same names as Address Families */
1689 	if ((ulong_t)val < MAX_AFCODES) {
1690 		outstring(pri, "PF_");
1691 		outstring(pri, afcodes[val]);
1692 	} else {
1693 		prt_dec(pri, 0, val);
1694 	}
1695 }
1696 
1697 /*
1698  * Print sockconfig() subcode.
1699  */
1700 /*ARGSUSED*/
1701 void
1702 prt_skc(private_t *pri, int raw, long val)
1703 {
1704 	const char *s = NULL;
1705 
1706 	if (!raw) {
1707 		switch (val) {
1708 		case SOCKCONFIG_ADD_SOCK:
1709 			s = "SOCKCONFIG_ADD_SOCK"; break;
1710 		case SOCKCONFIG_REMOVE_SOCK:
1711 			s = "SOCKCONFIG_REMOVE_SOCK"; break;
1712 		case SOCKCONFIG_ADD_FILTER:
1713 			s = "SOCKCONFIG_ADD_FILTER"; break;
1714 		case SOCKCONFIG_REMOVE_FILTER:
1715 			s = "SOCKCONFIG_REMOVE_FILTER"; break;
1716 		}
1717 	}
1718 	if (s == NULL)
1719 		prt_dec(pri, 0, val);
1720 	else
1721 		outstring(pri, s);
1722 }
1723 /*
1724  * Print so_socket() 2nd argument.
1725  */
1726 /*ARGSUSED*/
1727 void
1728 prt_skt(private_t *pri, int raw, long val)
1729 {
1730 	const char *s;
1731 	long type = val & SOCK_TYPE_MASK;
1732 
1733 	if ((ulong_t)type <= MAX_SOCKTYPES &&
1734 	    (s = socktype_codes[type]) != NULL) {
1735 		outstring(pri, s);
1736 		if ((val & SOCK_CLOEXEC) != 0) {
1737 			outstring(pri, "|SOCK_CLOEXEC");
1738 		}
1739 	} else {
1740 		prt_dec(pri, 0, val);
1741 	}
1742 }
1743 
1744 
1745 /*
1746  * Print so_socket() 3rd argument.
1747  */
1748 /*ARGSUSED*/
1749 void
1750 prt_skp(private_t *pri, int raw, long val)
1751 {
1752 	const char *s;
1753 
1754 	/* cheating -- look at the protocol-family */
1755 	switch (pri->sys_args[0]) {
1756 	case PF_INET6:
1757 	case PF_INET:
1758 	case PF_NCA:	if ((s = ipprotos((int)val)) != NULL) {
1759 				outstring(pri, s);
1760 				break;
1761 			}
1762 			/* FALLTHROUGH */
1763 	default:	prt_dec(pri, 0, val);
1764 			break;
1765 	}
1766 }
1767 
1768 
1769 /*
1770  * Print so_socket() 5th argument.
1771  */
1772 /*ARGSUSED*/
1773 void
1774 prt_skv(private_t *pri, int raw, long val)
1775 {
1776 	switch (val) {
1777 	case SOV_STREAM:	outstring(pri, "SOV_STREAM");	break;
1778 	case SOV_DEFAULT:	outstring(pri, "SOV_DEFAULT");	break;
1779 	case SOV_SOCKSTREAM:	outstring(pri, "SOV_SOCKSTREAM");	break;
1780 	case SOV_SOCKBSD:	outstring(pri, "SOV_SOCKBSD");	break;
1781 	case SOV_XPG4_2:	outstring(pri, "SOV_XPG4_2");	break;
1782 	default:		prt_dec(pri, 0, val);		break;
1783 	}
1784 }
1785 
1786 /*
1787  * Print accept4() flags argument.
1788  */
1789 void
1790 prt_acf(private_t *pri, int raw, long val)
1791 {
1792 	int first = 1;
1793 	if (raw || !val ||
1794 	    (val & ~(SOCK_CLOEXEC|SOCK_NDELAY|SOCK_NONBLOCK))) {
1795 		prt_dex(pri, 0, val);
1796 		return;
1797 	}
1798 
1799 	if (val & SOCK_CLOEXEC) {
1800 		outstring(pri, "|SOCK_CLOEXEC" + first);
1801 		first = 0;
1802 	}
1803 	if (val & SOCK_NDELAY) {
1804 		outstring(pri, "|SOCK_NDELAY" + first);
1805 		first = 0;
1806 	}
1807 	if (val & SOCK_NONBLOCK) {
1808 		outstring(pri, "|SOCK_NONBLOCK" + first);
1809 	}
1810 }
1811 
1812 
1813 /*
1814  * Print setsockopt()/getsockopt() 2nd argument.
1815  */
1816 /*ARGSUSED*/
1817 void
1818 prt_sol(private_t *pri, int raw, long val)
1819 {
1820 	if (val == SOL_SOCKET) {
1821 		outstring(pri, "SOL_SOCKET");
1822 	} else if (val == SOL_ROUTE) {
1823 		outstring(pri, "SOL_ROUTE");
1824 	} else {
1825 		const struct protoent *p;
1826 		struct protoent res;
1827 		char buf[NSS_BUFLEN_PROTOCOLS];
1828 
1829 		if ((p = getprotobynumber_r(val, &res,
1830 		    (char *)buf, sizeof (buf))) != NULL)
1831 			outstring(pri, p->p_name);
1832 		else
1833 			prt_dec(pri, 0, val);
1834 	}
1835 }
1836 
1837 
1838 const char *
1839 sol_optname(private_t *pri, long val)
1840 {
1841 #define	CBSIZE	sizeof (pri->code_buf)
1842 	if (val >= SO_SNDBUF) {
1843 		switch (val) {
1844 		case SO_SNDBUF:		return ("SO_SNDBUF");
1845 		case SO_RCVBUF:		return ("SO_RCVBUF");
1846 		case SO_SNDLOWAT:	return ("SO_SNDLOWAT");
1847 		case SO_RCVLOWAT:	return ("SO_RCVLOWAT");
1848 		case SO_SNDTIMEO:	return ("SO_SNDTIMEO");
1849 		case SO_RCVTIMEO:	return ("SO_RCVTIMEO");
1850 		case SO_ERROR:		return ("SO_ERROR");
1851 		case SO_TYPE:		return ("SO_TYPE");
1852 		case SO_PROTOTYPE:	return ("SO_PROTOTYPE");
1853 		case SO_ANON_MLP:	return ("SO_ANON_MLP");
1854 		case SO_MAC_EXEMPT:	return ("SO_MAC_EXEMPT");
1855 		case SO_ALLZONES:	return ("SO_ALLZONES");
1856 		case SO_MAC_IMPLICIT:	return ("SO_MAC_IMPLICIT");
1857 		case SO_VRRP:		return ("SO_VRRP");
1858 		case SO_EXCLBIND:	return ("SO_EXCLBIND");
1859 		case SO_DOMAIN:		return ("SO_DOMAIN");
1860 
1861 		default:		(void) snprintf(pri->code_buf, CBSIZE,
1862 					    "0x%lx", val);
1863 					return (pri->code_buf);
1864 		}
1865 	} else {
1866 		char *s = pri->code_buf;
1867 		size_t used = 1;
1868 		long val2;
1869 
1870 		*s = '\0';
1871 		val2 = val & ~(SO_DEBUG|SO_ACCEPTCONN|SO_REUSEADDR|SO_KEEPALIVE|
1872 		    SO_DONTROUTE|SO_BROADCAST|SO_USELOOPBACK|SO_LINGER|
1873 		    SO_OOBINLINE|SO_DGRAM_ERRIND|SO_RECVUCRED);
1874 		if (val2)
1875 			used = snprintf(s, CBSIZE, "|0x%lx", val2);
1876 		if (val & SO_DEBUG)
1877 			used = strlcat(s, "|SO_DEBUG", CBSIZE);
1878 		if (val & SO_ACCEPTCONN)
1879 			used = strlcat(s, "|SO_ACCEPTCONN", CBSIZE);
1880 		if (val & SO_REUSEADDR)
1881 			used = strlcat(s, "|SO_REUSEADDR", CBSIZE);
1882 		if (val & SO_KEEPALIVE)
1883 			used = strlcat(s, "|SO_KEEPALIVE", CBSIZE);
1884 		if (val & SO_DONTROUTE)
1885 			used = strlcat(s, "|SO_DONTROUTE", CBSIZE);
1886 		if (val & SO_BROADCAST)
1887 			used = strlcat(s, "|SO_BROADCAST", CBSIZE);
1888 		if (val & SO_USELOOPBACK)
1889 			used = strlcat(s, "|SO_USELOOPBACK", CBSIZE);
1890 		if (val & SO_LINGER)
1891 			used = strlcat(s, "|SO_LINGER", CBSIZE);
1892 		if (val & SO_OOBINLINE)
1893 			used = strlcat(s, "|SO_OOBINLINE", CBSIZE);
1894 		if (val & SO_DGRAM_ERRIND)
1895 			used = strlcat(s, "|SO_DGRAM_ERRIND", CBSIZE);
1896 		if (val & SO_RECVUCRED)
1897 			used = strlcat(s, "|SO_RECVUCRED", CBSIZE);
1898 		if (used >= CBSIZE || val == 0)
1899 			(void) snprintf(s + 1, CBSIZE-1, "0x%lx", val);
1900 		return ((const char *)(s + 1));
1901 	}
1902 #undef CBSIZE
1903 }
1904 
1905 const char *
1906 route_optname(private_t *pri, long val)
1907 {
1908 	switch (val) {
1909 	case RT_AWARE:
1910 		return ("RT_AWARE");
1911 	default:
1912 		(void) snprintf(pri->code_buf, sizeof (pri->code_buf),
1913 		    "0x%lx", val);
1914 		return (pri->code_buf);
1915 	}
1916 }
1917 
1918 const char *
1919 tcp_optname(private_t *pri, long val)
1920 {
1921 	switch (val) {
1922 	case TCP_NODELAY:		return ("TCP_NODELAY");
1923 	case TCP_MAXSEG:		return ("TCP_MAXSEG");
1924 	case TCP_KEEPALIVE:		return ("TCP_KEEPALIVE");
1925 	case TCP_NOTIFY_THRESHOLD:	return ("TCP_NOTIFY_THRESHOLD");
1926 	case TCP_ABORT_THRESHOLD:	return ("TCP_ABORT_THRESHOLD");
1927 	case TCP_CONN_NOTIFY_THRESHOLD:	return ("TCP_CONN_NOTIFY_THRESHOLD");
1928 	case TCP_CONN_ABORT_THRESHOLD:	return ("TCP_CONN_ABORT_THRESHOLD");
1929 	case TCP_RECVDSTADDR:		return ("TCP_RECVDSTADDR");
1930 	case TCP_ANONPRIVBIND:		return ("TCP_ANONPRIVBIND");
1931 	case TCP_EXCLBIND:		return ("TCP_EXCLBIND");
1932 	case TCP_INIT_CWND:		return ("TCP_INIT_CWND");
1933 	case TCP_KEEPALIVE_THRESHOLD:	return ("TCP_KEEPALIVE_THRESHOLD");
1934 	case TCP_KEEPALIVE_ABORT_THRESHOLD:
1935 		return ("TCP_KEEPALIVE_ABORT_THRESHOLD");
1936 	case TCP_CORK:			return ("TCP_CORK");
1937 	case TCP_RTO_INITIAL:		return ("TCP_RTO_INITIAL");
1938 	case TCP_RTO_MIN:		return ("TCP_RTO_MIN");
1939 	case TCP_RTO_MAX:		return ("TCP_RTO_MAX");
1940 	case TCP_LINGER2:		return ("TCP_LINGER2");
1941 
1942 	default:			(void) snprintf(pri->code_buf,
1943 					    sizeof (pri->code_buf),
1944 					    "0x%lx", val);
1945 					return (pri->code_buf);
1946 	}
1947 }
1948 
1949 
1950 const char *
1951 sctp_optname(private_t *pri, long val)
1952 {
1953 	switch (val) {
1954 	case SCTP_RTOINFO:		return ("SCTP_RTOINFO");
1955 	case SCTP_ASSOCINFO:		return ("SCTP_ASSOCINFO");
1956 	case SCTP_INITMSG:		return ("SCTP_INITMSG");
1957 	case SCTP_NODELAY:		return ("SCTP_NODELAY");
1958 	case SCTP_AUTOCLOSE:		return ("SCTP_AUTOCLOSE");
1959 	case SCTP_SET_PEER_PRIMARY_ADDR:
1960 		return ("SCTP_SET_PEER_PRIMARY_ADDR");
1961 	case SCTP_PRIMARY_ADDR:		return ("SCTP_PRIMARY_ADDR");
1962 	case SCTP_ADAPTATION_LAYER:	return ("SCTP_ADAPTATION_LAYER");
1963 	case SCTP_DISABLE_FRAGMENTS:	return ("SCTP_DISABLE_FRAGMENTS");
1964 	case SCTP_PEER_ADDR_PARAMS:	return ("SCTP_PEER_ADDR_PARAMS");
1965 	case SCTP_DEFAULT_SEND_PARAM:	return ("SCTP_DEFAULT_SEND_PARAM");
1966 	case SCTP_EVENTS:		return ("SCTP_EVENTS");
1967 	case SCTP_I_WANT_MAPPED_V4_ADDR:
1968 		return ("SCTP_I_WANT_MAPPED_V4_ADDR");
1969 	case SCTP_MAXSEG:		return ("SCTP_MAXSEG");
1970 	case SCTP_STATUS:		return ("SCTP_STATUS");
1971 	case SCTP_GET_PEER_ADDR_INFO:	return ("SCTP_GET_PEER_ADDR_INFO");
1972 
1973 	case SCTP_ADD_ADDR:		return ("SCTP_ADD_ADDR");
1974 	case SCTP_REM_ADDR:		return ("SCTP_REM_ADDR");
1975 
1976 	default:			(void) snprintf(pri->code_buf,
1977 					    sizeof (pri->code_buf),
1978 					    "0x%lx", val);
1979 					return (pri->code_buf);
1980 	}
1981 }
1982 
1983 
1984 const char *
1985 udp_optname(private_t *pri, long val)
1986 {
1987 	switch (val) {
1988 	case UDP_CHECKSUM:		return ("UDP_CHECKSUM");
1989 	case UDP_ANONPRIVBIND:		return ("UDP_ANONPRIVBIND");
1990 	case UDP_EXCLBIND:		return ("UDP_EXCLBIND");
1991 	case UDP_RCVHDR:		return ("UDP_RCVHDR");
1992 	case UDP_NAT_T_ENDPOINT:	return ("UDP_NAT_T_ENDPOINT");
1993 
1994 	default:			(void) snprintf(pri->code_buf,
1995 					    sizeof (pri->code_buf), "0x%lx",
1996 					    val);
1997 					return (pri->code_buf);
1998 	}
1999 }
2000 
2001 
2002 /*
2003  * Print setsockopt()/getsockopt() 3rd argument.
2004  */
2005 /*ARGSUSED*/
2006 void
2007 prt_son(private_t *pri, int raw, long val)
2008 {
2009 	/* cheating -- look at the level */
2010 	switch (pri->sys_args[1]) {
2011 	case SOL_SOCKET:	outstring(pri, sol_optname(pri, val));
2012 				break;
2013 	case SOL_ROUTE:		outstring(pri, route_optname(pri, val));
2014 				break;
2015 	case IPPROTO_TCP:	outstring(pri, tcp_optname(pri, val));
2016 				break;
2017 	case IPPROTO_UDP:	outstring(pri, udp_optname(pri, val));
2018 				break;
2019 	case IPPROTO_SCTP:	outstring(pri, sctp_optname(pri, val));
2020 				break;
2021 	default:		prt_dec(pri, 0, val);
2022 				break;
2023 	}
2024 }
2025 
2026 
2027 /*
2028  * Print utrap type
2029  */
2030 /*ARGSUSED*/
2031 void
2032 prt_utt(private_t *pri, int raw, long val)
2033 {
2034 	const char *s = NULL;
2035 
2036 #ifdef __sparc
2037 	if (!raw) {
2038 		switch (val) {
2039 		case UT_INSTRUCTION_DISABLED:
2040 			s = "UT_INSTRUCTION_DISABLED"; break;
2041 		case UT_INSTRUCTION_ERROR:
2042 			s = "UT_INSTRUCTION_ERROR"; break;
2043 		case UT_INSTRUCTION_PROTECTION:
2044 			s = "UT_INSTRUCTION_PROTECTION"; break;
2045 		case UT_ILLTRAP_INSTRUCTION:
2046 			s = "UT_ILLTRAP_INSTRUCTION"; break;
2047 		case UT_ILLEGAL_INSTRUCTION:
2048 			s = "UT_ILLEGAL_INSTRUCTION"; break;
2049 		case UT_PRIVILEGED_OPCODE:
2050 			s = "UT_PRIVILEGED_OPCODE"; break;
2051 		case UT_FP_DISABLED:
2052 			s = "UT_FP_DISABLED"; break;
2053 		case UT_FP_EXCEPTION_IEEE_754:
2054 			s = "UT_FP_EXCEPTION_IEEE_754"; break;
2055 		case UT_FP_EXCEPTION_OTHER:
2056 			s = "UT_FP_EXCEPTION_OTHER"; break;
2057 		case UT_TAG_OVERFLOW:
2058 			s = "UT_TAG_OVERFLOW"; break;
2059 		case UT_DIVISION_BY_ZERO:
2060 			s = "UT_DIVISION_BY_ZERO"; break;
2061 		case UT_DATA_EXCEPTION:
2062 			s = "UT_DATA_EXCEPTION"; break;
2063 		case UT_DATA_ERROR:
2064 			s = "UT_DATA_ERROR"; break;
2065 		case UT_DATA_PROTECTION:
2066 			s = "UT_DATA_PROTECTION"; break;
2067 		case UT_MEM_ADDRESS_NOT_ALIGNED:
2068 			s = "UT_MEM_ADDRESS_NOT_ALIGNED"; break;
2069 		case UT_PRIVILEGED_ACTION:
2070 			s = "UT_PRIVILEGED_ACTION"; break;
2071 		case UT_ASYNC_DATA_ERROR:
2072 			s = "UT_ASYNC_DATA_ERROR"; break;
2073 		case UT_TRAP_INSTRUCTION_16:
2074 			s = "UT_TRAP_INSTRUCTION_16"; break;
2075 		case UT_TRAP_INSTRUCTION_17:
2076 			s = "UT_TRAP_INSTRUCTION_17"; break;
2077 		case UT_TRAP_INSTRUCTION_18:
2078 			s = "UT_TRAP_INSTRUCTION_18"; break;
2079 		case UT_TRAP_INSTRUCTION_19:
2080 			s = "UT_TRAP_INSTRUCTION_19"; break;
2081 		case UT_TRAP_INSTRUCTION_20:
2082 			s = "UT_TRAP_INSTRUCTION_20"; break;
2083 		case UT_TRAP_INSTRUCTION_21:
2084 			s = "UT_TRAP_INSTRUCTION_21"; break;
2085 		case UT_TRAP_INSTRUCTION_22:
2086 			s = "UT_TRAP_INSTRUCTION_22"; break;
2087 		case UT_TRAP_INSTRUCTION_23:
2088 			s = "UT_TRAP_INSTRUCTION_23"; break;
2089 		case UT_TRAP_INSTRUCTION_24:
2090 			s = "UT_TRAP_INSTRUCTION_24"; break;
2091 		case UT_TRAP_INSTRUCTION_25:
2092 			s = "UT_TRAP_INSTRUCTION_25"; break;
2093 		case UT_TRAP_INSTRUCTION_26:
2094 			s = "UT_TRAP_INSTRUCTION_26"; break;
2095 		case UT_TRAP_INSTRUCTION_27:
2096 			s = "UT_TRAP_INSTRUCTION_27"; break;
2097 		case UT_TRAP_INSTRUCTION_28:
2098 			s = "UT_TRAP_INSTRUCTION_28"; break;
2099 		case UT_TRAP_INSTRUCTION_29:
2100 			s = "UT_TRAP_INSTRUCTION_29"; break;
2101 		case UT_TRAP_INSTRUCTION_30:
2102 			s = "UT_TRAP_INSTRUCTION_30"; break;
2103 		case UT_TRAP_INSTRUCTION_31:
2104 			s = "UT_TRAP_INSTRUCTION_31"; break;
2105 		}
2106 	}
2107 #endif /* __sparc */
2108 
2109 	if (s == NULL)
2110 		prt_dec(pri, 0, val);
2111 	else
2112 		outstring(pri, s);
2113 }
2114 
2115 
2116 /*
2117  * Print utrap handler
2118  */
2119 void
2120 prt_uth(private_t *pri, int raw, long val)
2121 {
2122 	const char *s = NULL;
2123 
2124 	if (!raw) {
2125 		switch (val) {
2126 		case (long)UTH_NOCHANGE:	s = "UTH_NOCHANGE"; break;
2127 		}
2128 	}
2129 
2130 	if (s == NULL)
2131 		prt_hex(pri, 0, val);
2132 	else
2133 		outstring(pri, s);
2134 }
2135 
2136 const char *
2137 access_flags(private_t *pri, long arg)
2138 {
2139 #define	E_OK 010
2140 	char *str = pri->code_buf;
2141 
2142 	if (arg & ~(R_OK|W_OK|X_OK|E_OK))
2143 		return (NULL);
2144 
2145 	/* NB: F_OK == 0 */
2146 	if (arg == F_OK)
2147 		return ("F_OK");
2148 	if (arg == E_OK)
2149 		return ("F_OK|E_OK");
2150 
2151 	*str = '\0';
2152 	if (arg & R_OK)
2153 		(void) strlcat(str, "|R_OK", sizeof (pri->code_buf));
2154 	if (arg & W_OK)
2155 		(void) strlcat(str, "|W_OK", sizeof (pri->code_buf));
2156 	if (arg & X_OK)
2157 		(void) strlcat(str, "|X_OK", sizeof (pri->code_buf));
2158 	if (arg & E_OK)
2159 		(void) strlcat(str, "|E_OK", sizeof (pri->code_buf));
2160 	return ((const char *)(str + 1));
2161 #undef E_OK
2162 }
2163 
2164 /*
2165  * Print access() flags.
2166  */
2167 void
2168 prt_acc(private_t *pri, int raw, long val)
2169 {
2170 	const char *s = raw? NULL : access_flags(pri, val);
2171 
2172 	if (s == NULL)
2173 		prt_dex(pri, 0, val);
2174 	else
2175 		outstring(pri, s);
2176 }
2177 
2178 /*
2179  * Print shutdown() "how" (2nd) argument
2180  */
2181 void
2182 prt_sht(private_t *pri, int raw, long val)
2183 {
2184 	if (raw) {
2185 		prt_dex(pri, 0, val);
2186 		return;
2187 	}
2188 	switch (val) {
2189 	case SHUT_RD:	outstring(pri, "SHUT_RD");	break;
2190 	case SHUT_WR:	outstring(pri, "SHUT_WR");	break;
2191 	case SHUT_RDWR:	outstring(pri, "SHUT_RDWR");	break;
2192 	default:	prt_dec(pri, 0, val);		break;
2193 	}
2194 }
2195 
2196 /*
2197  * Print fcntl() F_SETFL flags (3rd) argument or fdsync flag (2nd arg)
2198  */
2199 static struct fcntl_flags {
2200 	long		val;
2201 	const char	*name;
2202 } fcntl_flags[] = {
2203 #define	FC_FL(flag)	{ (long)flag, "|" # flag }
2204 	FC_FL(FREVOKED),
2205 	FC_FL(FREAD),
2206 	FC_FL(FWRITE),
2207 	FC_FL(FNDELAY),
2208 	FC_FL(FAPPEND),
2209 	FC_FL(FSYNC),
2210 	FC_FL(FDSYNC),
2211 	FC_FL(FRSYNC),
2212 	FC_FL(FOFFMAX),
2213 	FC_FL(FNONBLOCK),
2214 	FC_FL(FCREAT),
2215 	FC_FL(FTRUNC),
2216 	FC_FL(FEXCL),
2217 	FC_FL(FNOCTTY),
2218 	FC_FL(FXATTR),
2219 	FC_FL(FASYNC),
2220 	FC_FL(FNODSYNC)
2221 #undef FC_FL
2222 };
2223 
2224 void
2225 prt_ffg(private_t *pri, int raw, long val)
2226 {
2227 #define	CBSIZE	sizeof (pri->code_buf)
2228 	char *s = pri->code_buf;
2229 	size_t used = 1;
2230 	struct fcntl_flags *fp;
2231 
2232 	if (raw) {
2233 		(void) snprintf(s, CBSIZE, "0x%lx", val);
2234 		outstring(pri, s);
2235 		return;
2236 	}
2237 	if (val == 0) {
2238 		outstring(pri, "(no flags)");
2239 		return;
2240 	}
2241 
2242 	*s = '\0';
2243 	for (fp = fcntl_flags;
2244 	    fp < &fcntl_flags[sizeof (fcntl_flags) / sizeof (*fp)]; fp++) {
2245 		if (val & fp->val) {
2246 			used = strlcat(s, fp->name, CBSIZE);
2247 			val &= ~fp->val;
2248 		}
2249 	}
2250 
2251 	if (val != 0 && used <= CBSIZE)
2252 		used += snprintf(s + used, CBSIZE - used, "|0x%lx", val);
2253 
2254 	if (used >= CBSIZE)
2255 		(void) snprintf(s + 1, CBSIZE-1, "0x%lx", val);
2256 	outstring(pri, s + 1);
2257 #undef CBSIZE
2258 }
2259 
2260 void
2261 prt_prs(private_t *pri, int raw, long val)
2262 {
2263 	static size_t setsize;
2264 	priv_set_t *set = priv_allocset();
2265 
2266 	if (setsize == 0) {
2267 		const priv_impl_info_t *info = getprivimplinfo();
2268 		if (info != NULL)
2269 			setsize = info->priv_setsize * sizeof (priv_chunk_t);
2270 	}
2271 
2272 	if (setsize != 0 && !raw && set != NULL &&
2273 	    Pread(Proc, set, setsize, val) == setsize) {
2274 		int i;
2275 
2276 		outstring(pri, "{");
2277 		for (i = 0; i < setsize / sizeof (priv_chunk_t); i++) {
2278 			char buf[9];	/* 8 hex digits + '\0' */
2279 			(void) snprintf(buf, sizeof (buf), "%08x",
2280 			    ((priv_chunk_t *)set)[i]);
2281 			outstring(pri, buf);
2282 		}
2283 
2284 		outstring(pri, "}");
2285 	} else {
2286 		prt_hex(pri, 0, val);
2287 	}
2288 
2289 	if (set != NULL)
2290 		priv_freeset(set);
2291 }
2292 
2293 /*
2294  * Print privilege set operation.
2295  */
2296 void
2297 prt_pro(private_t *pri, int raw, long val)
2298 {
2299 	const char *s = NULL;
2300 
2301 	if (!raw) {
2302 		switch ((priv_op_t)val) {
2303 		case PRIV_ON:		s = "PRIV_ON";		break;
2304 		case PRIV_OFF:		s = "PRIV_OFF";		break;
2305 		case PRIV_SET:		s = "PRIV_SET";		break;
2306 		}
2307 	}
2308 
2309 	if (s == NULL)
2310 		prt_dec(pri, 0, val);
2311 	else
2312 		outstring(pri, s);
2313 }
2314 
2315 /*
2316  * Print privilege set name
2317  */
2318 void
2319 prt_prn(private_t *pri, int raw, long val)
2320 {
2321 	const char *s = NULL;
2322 
2323 	if (!raw)
2324 		s = priv_getsetbynum((int)val);
2325 
2326 	if (s == NULL)
2327 		prt_dec(pri, 0, val);
2328 	else {
2329 		char *dup = strdup(s);
2330 		char *q;
2331 
2332 		/* Do the best we can in this case */
2333 		if (dup == NULL) {
2334 			outstring(pri, s);
2335 			return;
2336 		}
2337 
2338 		outstring(pri, "PRIV_");
2339 
2340 		q = dup;
2341 
2342 		while (*q != '\0') {
2343 			*q = toupper(*q);
2344 			q++;
2345 		}
2346 		outstring(pri, dup);
2347 		free(dup);
2348 	}
2349 }
2350 
2351 /*
2352  * Print process flag names.
2353  */
2354 void
2355 prt_pfl(private_t *pri, int raw, long val)
2356 {
2357 	const char *s = NULL;
2358 
2359 	if (!raw) {
2360 		switch ((int)val) {
2361 		case PRIV_DEBUG:	s = "PRIV_DEBUG";	break;
2362 		case PRIV_AWARE:	s = "PRIV_AWARE";	break;
2363 		case PRIV_XPOLICY:	s = "PRIV_XPOLICY";	break;
2364 		case PRIV_AWARE_RESET:  s = "PRIV_AWARE_RESET"; break;
2365 		case PRIV_PFEXEC:	s = "PRIV_PFEXEC";	break;
2366 		case NET_MAC_AWARE:	s =  "NET_MAC_AWARE";	break;
2367 		case NET_MAC_AWARE_INHERIT:
2368 			s = "NET_MAC_AWARE_INHERIT";
2369 			break;
2370 		}
2371 	}
2372 
2373 	if (s == NULL)
2374 		prt_dec(pri, 0, val);
2375 	else
2376 		outstring(pri, s);
2377 }
2378 
2379 /*
2380  * Print lgrp_affinity_{get,set}() arguments.
2381  */
2382 /*ARGSUSED*/
2383 void
2384 prt_laf(private_t *pri, int raw, long val)
2385 {
2386 	lgrp_affinity_args_t	laff;
2387 
2388 	if (Pread(Proc, &laff, sizeof (lgrp_affinity_args_t), val) !=
2389 	    sizeof (lgrp_affinity_args_t)) {
2390 		prt_hex(pri, 0, val);
2391 		return;
2392 	}
2393 	/*
2394 	 * arrange the arguments in the order that user calls with
2395 	 */
2396 	prt_dec(pri, 0, laff.idtype);
2397 	outstring(pri, ", ");
2398 	prt_dec(pri, 0, laff.id);
2399 	outstring(pri, ", ");
2400 	prt_dec(pri, 0, laff.lgrp);
2401 	outstring(pri, ", ");
2402 	if (pri->sys_args[0] == LGRP_SYS_AFFINITY_SET)
2403 		prt_dec(pri, 0, laff.aff);
2404 }
2405 
2406 /*
2407  * Print a key_t as IPC_PRIVATE if it is 0.
2408  */
2409 void
2410 prt_key(private_t *pri, int raw, long val)
2411 {
2412 	if (!raw && val == 0)
2413 		outstring(pri, "IPC_PRIVATE");
2414 	else
2415 		prt_dec(pri, 0, val);
2416 }
2417 
2418 
2419 /*
2420  * Print zone_getattr() attribute types.
2421  */
2422 void
2423 prt_zga(private_t *pri, int raw, long val)
2424 {
2425 	const char *s = NULL;
2426 
2427 	if (!raw) {
2428 		switch ((int)val) {
2429 		case ZONE_ATTR_NAME:	s = "ZONE_ATTR_NAME";	break;
2430 		case ZONE_ATTR_ROOT:	s = "ZONE_ATTR_ROOT";	break;
2431 		case ZONE_ATTR_STATUS:	s = "ZONE_ATTR_STATUS";	break;
2432 		case ZONE_ATTR_PRIVSET:	s = "ZONE_ATTR_PRIVSET"; break;
2433 		case ZONE_ATTR_UNIQID:	s = "ZONE_ATTR_UNIQID"; break;
2434 		case ZONE_ATTR_POOLID:	s = "ZONE_ATTR_POOLID"; break;
2435 		case ZONE_ATTR_INITPID:	s = "ZONE_ATTR_INITPID"; break;
2436 		case ZONE_ATTR_SLBL:	s = "ZONE_ATTR_SLBL"; break;
2437 		case ZONE_ATTR_INITNAME:	s = "ZONE_ATTR_INITNAME"; break;
2438 		case ZONE_ATTR_BOOTARGS:	s = "ZONE_ATTR_BOOTARGS"; break;
2439 		case ZONE_ATTR_BRAND:	s = "ZONE_ATTR_BRAND"; break;
2440 		case ZONE_ATTR_FLAGS:	s = "ZONE_ATTR_FLAGS"; break;
2441 		case ZONE_ATTR_PHYS_MCAP: s = "ZONE_ATTR_PHYS_MCAP"; break;
2442 		}
2443 	}
2444 
2445 	if (s == NULL)
2446 		prt_dec(pri, 0, val);
2447 	else
2448 		outstring(pri, s);
2449 }
2450 
2451 /*
2452  * Print a file descriptor as AT_FDCWD if necessary
2453  */
2454 void
2455 prt_atc(private_t *pri, int raw, long val)
2456 {
2457 	if ((int)val == AT_FDCWD) {
2458 		if (raw)
2459 			prt_hex(pri, 0, (uint_t)AT_FDCWD);
2460 		else
2461 			outstring(pri, "AT_FDCWD");
2462 	} else {
2463 		prt_dec(pri, 0, val);
2464 	}
2465 }
2466 
2467 /*
2468  * Print Trusted Networking database operation codes (labelsys; tn*)
2469  */
2470 static void
2471 prt_tnd(private_t *pri, int raw, long val)
2472 {
2473 	const char *s = NULL;
2474 
2475 	if (!raw) {
2476 		switch ((tsol_dbops_t)val) {
2477 		case TNDB_NOOP:		s = "TNDB_NOOP";	break;
2478 		case TNDB_LOAD:		s = "TNDB_LOAD";	break;
2479 		case TNDB_DELETE:	s = "TNDB_DELETE";	break;
2480 		case TNDB_FLUSH:	s = "TNDB_FLUSH";	break;
2481 		case TNDB_GET:		s = "TNDB_GET";		break;
2482 		}
2483 	}
2484 
2485 	if (s == NULL)
2486 		prt_dec(pri, 0, val);
2487 	else
2488 		outstring(pri, s);
2489 }
2490 
2491 /*
2492  * Print LIO_XX flags
2493  */
2494 void
2495 prt_lio(private_t *pri, int raw, long val)
2496 {
2497 	if (raw)
2498 		prt_dec(pri, 0, val);
2499 	else if (val == LIO_WAIT)
2500 		outstring(pri, "LIO_WAIT");
2501 	else if (val == LIO_NOWAIT)
2502 		outstring(pri, "LIO_NOWAIT");
2503 	else
2504 		prt_dec(pri, 0, val);
2505 }
2506 
2507 const char *
2508 door_flags(private_t *pri, long val)
2509 {
2510 	door_attr_t attr = (door_attr_t)val;
2511 	char *str = pri->code_buf;
2512 
2513 	*str = '\0';
2514 #define	PROCESS_FLAG(flg)						\
2515 	if (attr & flg) {						\
2516 		(void) strlcat(str, "|" #flg, sizeof (pri->code_buf));	\
2517 		attr &= ~flg;						\
2518 	}
2519 
2520 	PROCESS_FLAG(DOOR_UNREF);
2521 	PROCESS_FLAG(DOOR_UNREF_MULTI);
2522 	PROCESS_FLAG(DOOR_PRIVATE);
2523 	PROCESS_FLAG(DOOR_REFUSE_DESC);
2524 	PROCESS_FLAG(DOOR_NO_CANCEL);
2525 	PROCESS_FLAG(DOOR_LOCAL);
2526 	PROCESS_FLAG(DOOR_REVOKED);
2527 	PROCESS_FLAG(DOOR_IS_UNREF);
2528 #undef PROCESS_FLAG
2529 
2530 	if (attr != 0 || *str == '\0') {
2531 		size_t len = strlen(str);
2532 		(void) snprintf(str + len, sizeof (pri->code_buf) - len,
2533 		    "|0x%X", attr);
2534 	}
2535 
2536 	return (str + 1);
2537 }
2538 
2539 /*
2540  * Print door_create() flags
2541  */
2542 void
2543 prt_dfl(private_t *pri, int raw, long val)
2544 {
2545 	if (raw)
2546 		prt_hex(pri, 0, val);
2547 	else
2548 		outstring(pri, door_flags(pri, val));
2549 }
2550 
2551 /*
2552  * Print door_*param() param argument
2553  */
2554 void
2555 prt_dpm(private_t *pri, int raw, long val)
2556 {
2557 	if (raw)
2558 		prt_hex(pri, 0, val);
2559 	else if (val == DOOR_PARAM_DESC_MAX)
2560 		outstring(pri, "DOOR_PARAM_DESC_MAX");
2561 	else if (val == DOOR_PARAM_DATA_MIN)
2562 		outstring(pri, "DOOR_PARAM_DATA_MIN");
2563 	else if (val == DOOR_PARAM_DATA_MAX)
2564 		outstring(pri, "DOOR_PARAM_DATA_MAX");
2565 	else
2566 		prt_hex(pri, 0, val);
2567 }
2568 
2569 /*
2570  * Print rctlsys subcodes
2571  */
2572 void
2573 prt_rsc(private_t *pri, int raw, long val)	/* print utssys code */
2574 {
2575 	const char *s = raw? NULL : rctlsyscode(val);
2576 
2577 	if (s == NULL)
2578 		prt_dec(pri, 0, val);
2579 	else
2580 		outstring(pri, s);
2581 }
2582 
2583 /*
2584  * Print getrctl flags
2585  */
2586 void
2587 prt_rgf(private_t *pri, int raw, long val)
2588 {
2589 	long action = val & (~RCTLSYS_ACTION_MASK);
2590 
2591 	if (raw)
2592 		prt_hex(pri, 0, val);
2593 	else if (action == RCTL_FIRST)
2594 		outstring(pri, "RCTL_FIRST");
2595 	else if (action == RCTL_NEXT)
2596 		outstring(pri, "RCTL_NEXT");
2597 	else if (action == RCTL_USAGE)
2598 		outstring(pri, "RCTL_USAGE");
2599 	else
2600 		prt_hex(pri, 0, val);
2601 }
2602 
2603 /*
2604  * Print setrctl flags
2605  */
2606 void
2607 prt_rsf(private_t *pri, int raw, long val)
2608 {
2609 	long action = val & (~RCTLSYS_ACTION_MASK);
2610 	long pval = val & RCTL_LOCAL_ACTION_MASK;
2611 	char *s = pri->code_buf;
2612 
2613 	if (raw) {
2614 		prt_hex(pri, 0, val);
2615 		return;
2616 	} else if (action == RCTL_INSERT)
2617 		(void) strcpy(s, "RCTL_INSERT");
2618 	else if (action == RCTL_DELETE)
2619 		(void) strcpy(s, "RCTL_DELETE");
2620 	else if (action == RCTL_REPLACE)
2621 		(void) strcpy(s, "RCTL_REPLACE");
2622 	else {
2623 		prt_hex(pri, 0, val);
2624 		return;
2625 	}
2626 
2627 	if (pval & RCTL_USE_RECIPIENT_PID) {
2628 		pval ^= RCTL_USE_RECIPIENT_PID;
2629 		(void) strlcat(s, "|RCTL_USE_RECIPIENT_PID",
2630 		    sizeof (pri->code_buf));
2631 	}
2632 
2633 	if ((pval & RCTLSYS_ACTION_MASK) != 0)
2634 		prt_hex(pri, 0, val);
2635 	else if (*s != '\0')
2636 		outstring(pri, s);
2637 	else
2638 		prt_hex(pri, 0, val);
2639 }
2640 
2641 /*
2642  * Print rctlctl flags
2643  */
2644 void
2645 prt_rcf(private_t *pri, int raw, long val)
2646 {
2647 	long action = val & (~RCTLSYS_ACTION_MASK);
2648 
2649 	if (raw)
2650 		prt_hex(pri, 0, val);
2651 	else if (action == RCTLCTL_GET)
2652 		outstring(pri, "RCTLCTL_GET");
2653 	else if (action == RCTLCTL_SET)
2654 		outstring(pri, "RCTLCTL_SET");
2655 	else
2656 		prt_hex(pri, 0, val);
2657 }
2658 
2659 /*
2660  * Print setprojrctl flags
2661  */
2662 void
2663 prt_spf(private_t *pri, int raw, long val)
2664 {
2665 	long action = val & TASK_PROJ_MASK;
2666 
2667 	if (!raw && (action == TASK_PROJ_PURGE))
2668 		outstring(pri, "TASK_PROJ_PURGE");
2669 	else
2670 		prt_hex(pri, 0, val);
2671 }
2672 
2673 /*
2674  * Print forkx() flags
2675  */
2676 void
2677 prt_fxf(private_t *pri, int raw, long val)
2678 {
2679 	char *str;
2680 
2681 	if (val == 0)
2682 		outstring(pri, "0");
2683 	else if (raw || (val & ~(FORK_NOSIGCHLD | FORK_WAITPID)))
2684 		prt_hhx(pri, 0, val);
2685 	else {
2686 		str = pri->code_buf;
2687 		*str = '\0';
2688 		if (val & FORK_NOSIGCHLD)
2689 			(void) strlcat(str, "|FORK_NOSIGCHLD",
2690 			    sizeof (pri->code_buf));
2691 		if (val & FORK_WAITPID)
2692 			(void) strlcat(str, "|FORK_WAITPID",
2693 			    sizeof (pri->code_buf));
2694 		outstring(pri, str + 1);
2695 	}
2696 }
2697 
2698 /*
2699  * Print faccessat() flag
2700  */
2701 void
2702 prt_fat(private_t *pri, int raw, long val)
2703 {
2704 	if (val == 0)
2705 		outstring(pri, "0");
2706 	else if (!raw && val == AT_EACCESS)
2707 		outstring(pri, "AT_EACCESS");
2708 	else
2709 		prt_hex(pri, 0, val);
2710 }
2711 
2712 /*
2713  * Print unlinkat() flag
2714  */
2715 void
2716 prt_uat(private_t *pri, int raw, long val)
2717 {
2718 	if (val == 0)
2719 		outstring(pri, "0");
2720 	else if (!raw && val == AT_REMOVEDIR)
2721 		outstring(pri, "AT_REMOVEDIR");
2722 	else
2723 		prt_hex(pri, 0, val);
2724 }
2725 
2726 /*
2727  * Print AT_SYMLINK_NOFOLLOW / AT_SYMLINK_FOLLOW flag
2728  */
2729 void
2730 prt_snf(private_t *pri, int raw, long val)
2731 {
2732 	if (val == 0)
2733 		outstring(pri, "0");
2734 	else if (!raw && val == AT_SYMLINK_NOFOLLOW)
2735 		outstring(pri, "AT_SYMLINK_NOFOLLOW");
2736 	else if (!raw && val == AT_SYMLINK_FOLLOW)
2737 		outstring(pri, "AT_SYMLINK_FOLLOW");
2738 	else
2739 		prt_hex(pri, 0, val);
2740 }
2741 
2742 /*
2743  * Array of pointers to print functions, one for each format.
2744  */
2745 void (* const Print[])() = {
2746 	prt_nov,	/* NOV -- no value */
2747 	prt_dec,	/* DEC -- print value in decimal */
2748 	prt_oct,	/* OCT -- print value in octal */
2749 	prt_hex,	/* HEX -- print value in hexadecimal */
2750 	prt_dex,	/* DEX -- print value in hexadecimal if big enough */
2751 	prt_stg,	/* STG -- print value as string */
2752 	prt_ioc,	/* IOC -- print ioctl code */
2753 	prt_fcn,	/* FCN -- print fcntl code */
2754 	prt_s86,	/* S86 -- print sysi86 code */
2755 	prt_uts,	/* UTS -- print utssys code */
2756 	prt_opn,	/* OPN -- print open code */
2757 	prt_sig,	/* SIG -- print signal name plus flags */
2758 	prt_uat,	/* UAT -- print unlinkat() flag */
2759 	prt_msc,	/* MSC -- print msgsys command */
2760 	prt_msf,	/* MSF -- print msgsys flags */
2761 	prt_smc,	/* SMC -- print semsys command */
2762 	prt_sef,	/* SEF -- print semsys flags */
2763 	prt_shc,	/* SHC -- print shmsys command */
2764 	prt_shf,	/* SHF -- print shmsys flags */
2765 	prt_fat,	/* FAT -- print faccessat( flag */
2766 	prt_sfs,	/* SFS -- print sysfs code */
2767 	prt_rst,	/* RST -- print string returned by syscall */
2768 	prt_smf,	/* SMF -- print streams message flags */
2769 	prt_ioa,	/* IOA -- print ioctl argument */
2770 	prt_pip,	/* PIP -- print pipe flags */
2771 	prt_mtf,	/* MTF -- print mount flags */
2772 	prt_mft,	/* MFT -- print mount file system type */
2773 	prt_iob,	/* IOB -- print contents of I/O buffer */
2774 	prt_hhx,	/* HHX -- print value in hexadecimal (half size) */
2775 	prt_wop,	/* WOP -- print waitsys() options */
2776 	prt_spm,	/* SPM -- print sigprocmask argument */
2777 	prt_rlk,	/* RLK -- print readlink buffer */
2778 	prt_mpr,	/* MPR -- print mmap()/mprotect() flags */
2779 	prt_mty,	/* MTY -- print mmap() mapping type flags */
2780 	prt_mcf,	/* MCF -- print memcntl() function */
2781 	prt_mc4,	/* MC4 -- print memcntl() (fourth) argument */
2782 	prt_mc5,	/* MC5 -- print memcntl() (fifth) argument */
2783 	prt_mad,	/* MAD -- print madvise() argument */
2784 	prt_ulm,	/* ULM -- print ulimit() argument */
2785 	prt_rlm,	/* RLM -- print get/setrlimit() argument */
2786 	prt_cnf,	/* CNF -- print sysconfig() argument */
2787 	prt_inf,	/* INF -- print sysinfo() argument */
2788 	prt_ptc,	/* PTC -- print pathconf/fpathconf() argument */
2789 	prt_fui,	/* FUI -- print fusers() input argument */
2790 	prt_idt,	/* IDT -- print idtype_t, waitid() argument */
2791 	prt_lwf,	/* LWF -- print lwp_create() flags */
2792 	prt_itm,	/* ITM -- print [get|set]itimer() arg */
2793 	prt_llo,	/* LLO -- print long long offset arg */
2794 	prt_mod,	/* MOD -- print modctl() subcode */
2795 	prt_whn,	/* WHN -- print lseek() whence arguiment */
2796 	prt_acl,	/* ACL -- print acl() code */
2797 	prt_aio,	/* AIO -- print kaio() code */
2798 	prt_aud,	/* AUD -- print auditsys() code */
2799 	prt_uns,	/* DEC -- print value in unsigned decimal */
2800 	prt_clc,	/* CLC -- print cladm command argument */
2801 	prt_clf,	/* CLF -- print cladm flag argument */
2802 	prt_cor,	/* COR -- print corectl() subcode */
2803 	prt_cco,	/* CCO -- print corectl() options */
2804 	prt_ccc,	/* CCC -- print corectl() content */
2805 	prt_rcc,	/* RCC -- print corectl() returned content */
2806 	prt_cpc,	/* CPC -- print cpc() subcode */
2807 	prt_sqc,	/* SQC -- print sigqueue() si_code argument */
2808 	prt_pc4,	/* PC4 -- print priocntlsys() (fourth) argument */
2809 	prt_pc5,	/* PC5 -- print priocntlsys() (key, value) pairs */
2810 	prt_pst,	/* PST -- print processor set id */
2811 	prt_mif,	/* MIF -- print meminfo() arguments */
2812 	prt_pfm,	/* PFM -- print so_socket() proto-family (1st) arg */
2813 	prt_skt,	/* SKT -- print so_socket() socket-type (2nd) arg */
2814 	prt_skp,	/* SKP -- print so_socket() protocol (3rd) arg */
2815 	prt_skv,	/* SKV -- print socket version arg */
2816 	prt_sol,	/* SOL -- print [sg]etsockopt() level (2nd) arg */
2817 	prt_son,	/* SON -- print [sg]etsockopt() opt-name (3rd) arg */
2818 	prt_utt,	/* UTT -- print utrap type */
2819 	prt_uth,	/* UTH -- print utrap handler */
2820 	prt_acc,	/* ACC -- print access() flags */
2821 	prt_sht,	/* SHT -- print shutdown() how (2nd) argument */
2822 	prt_ffg,	/* FFG -- print fcntl() flags (3rd) argument */
2823 	prt_prs,	/* PRS -- print privilege set */
2824 	prt_pro,	/* PRO -- print privilege set operation */
2825 	prt_prn,	/* PRN -- print privilege set name */
2826 	prt_pfl,	/* PFL -- print privilege/process flag name */
2827 	prt_laf,	/* LAF -- print lgrp_affinity arguments */
2828 	prt_key,	/* KEY -- print key_t 0 as IPC_PRIVATE */
2829 	prt_zga,	/* ZGA -- print zone_getattr attribute types */
2830 	prt_atc,	/* ATC -- print AT_FDCWD or file descriptor */
2831 	prt_lio,	/* LIO -- print LIO_XX flags */
2832 	prt_dfl,	/* DFL -- print door_create() flags */
2833 	prt_dpm,	/* DPM -- print DOOR_PARAM_XX flags */
2834 	prt_tnd,	/* TND -- print trusted network data base opcode */
2835 	prt_rsc,	/* RSC -- print rctlsys() subcodes */
2836 	prt_rgf,	/* RGF -- print getrctl() flags */
2837 	prt_rsf,	/* RSF -- print setrctl() flags */
2838 	prt_rcf,	/* RCF -- print rctlsys_ctl() flags */
2839 	prt_fxf,	/* FXF -- print forkx() flags */
2840 	prt_spf,	/* SPF -- print rctlsys_projset() flags */
2841 	prt_un1,	/* UN1 -- as prt_uns except for -1 */
2842 	prt_mob,	/* MOB -- print mmapobj() flags */
2843 	prt_snf,	/* SNF -- print AT_SYMLINK_[NO]FOLLOW flag */
2844 	prt_skc,	/* SKC -- print sockconfig() subcode */
2845 	prt_acf,	/* ACF -- print accept4 flags */
2846 	prt_pfd,	/* PFD -- print pipe fds */
2847 	prt_dec,	/* HID -- hidden argument, make this the last one */
2848 };
2849