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