dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / truss / print.c
blobc5b835543cf6d07c95be82ecadb7bddf4ebfec64
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2015, Joyent, Inc. All rights reserved.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
32 #define _SYSCALL32 /* make 32-bit compat headers visible */
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 <fcntl.h>
43 #include <ctype.h>
44 #include <sys/types.h>
45 #include <sys/mman.h>
46 #include <sys/resource.h>
47 #include <sys/ulimit.h>
48 #include <sys/utsname.h>
49 #include <sys/kstat.h>
50 #include <sys/modctl.h>
51 #include <sys/acl.h>
52 #include <stropts.h>
53 #include <sys/isa_defs.h>
54 #include <sys/systeminfo.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 <sys/proc.h>
70 #include <netdb.h>
71 #include <nss_dbdefs.h>
72 #include <sys/socketvar.h>
73 #include <netinet/in.h>
74 #include <netinet/tcp.h>
75 #include <netinet/udp.h>
76 #include <netinet/sctp.h>
77 #include <net/route.h>
78 #include <sys/utrap.h>
79 #include <sys/lgrp_user.h>
80 #include <sys/door.h>
81 #include <sys/rctl.h>
82 #include <sys/rctl_impl.h>
83 #include <sys/fork.h>
84 #include <sys/task.h>
85 #include <sys/random.h>
86 #include "ramdata.h"
87 #include "print.h"
88 #include "proto.h"
89 #include "systable.h"
91 void grow(private_t *, int nbyte);
93 #define GROW(nb) if (pri->sys_leng + (nb) >= pri->sys_ssize) grow(pri, (nb))
96 /*ARGSUSED*/
97 void
98 prt_nov(private_t *pri, int raw, long val) /* print nothing */
102 /*ARGSUSED*/
103 void
104 prt_dec(private_t *pri, int raw, long val) /* print as decimal */
106 GROW(24);
107 if (data_model == PR_MODEL_ILP32)
108 pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
109 "%d", (int)val);
110 else
111 pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
112 "%ld", val);
115 /*ARGSUSED*/
116 void
117 prt_uns(private_t *pri, int raw, long val) /* print as unsigned decimal */
119 GROW(24);
120 if (data_model == PR_MODEL_ILP32)
121 pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
122 "%u", (int)val);
123 else
124 pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
125 "%lu", val);
128 /* print as unsigned decimal, except for -1 */
129 void
130 prt_un1(private_t *pri, int raw, long val)
132 if ((int)val == -1)
133 prt_dec(pri, raw, val);
134 else
135 prt_uns(pri, raw, val);
138 /*ARGSUSED*/
139 void
140 prt_oct(private_t *pri, int raw, long val) /* print as octal */
142 GROW(24);
143 if (data_model == PR_MODEL_ILP32)
144 pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
145 "%#o", (int)val);
146 else
147 pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
148 "%#lo", val);
151 /*ARGSUSED*/
152 void
153 prt_hex(private_t *pri, int raw, long val) /* print as hexadecimal */
155 GROW(20);
156 if (data_model == PR_MODEL_ILP32)
157 pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
158 "0x%.8X", (int)val);
159 else
160 pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
161 "0x%.8lX", val);
164 /* print as hexadecimal (half size) */
165 /*ARGSUSED*/
166 void
167 prt_hhx(private_t *pri, int raw, long val)
169 GROW(20);
170 if (data_model == PR_MODEL_ILP32)
171 pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
172 "0x%.4X", (int)val);
173 else
174 pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
175 "0x%.4lX", val);
178 /* print as decimal if small, else hexadecimal */
179 /*ARGSUSED*/
180 void
181 prt_dex(private_t *pri, int raw, long val)
183 if (val & 0xff000000)
184 prt_hex(pri, 0, val);
185 else
186 prt_dec(pri, 0, val);
189 /* print long long offset */
190 /*ARGSUSED*/
191 void
192 prt_llo(private_t *pri, int raw, long val1, long val2)
194 int hival;
195 int loval;
197 #ifdef _LONG_LONG_LTOH
198 hival = (int)val2;
199 loval = (int)val1;
200 #else
201 hival = (int)val1;
202 loval = (int)val2;
203 #endif
205 if (hival == 0) {
206 prt_dex(pri, 0, loval);
207 } else {
208 GROW(18);
209 pri->sys_leng +=
210 sprintf(pri->sys_string + pri->sys_leng, "0x%.8X%.8X",
211 hival, loval);
215 void
216 escape_string(private_t *pri, const char *s)
219 * We want to avoid outputting unprintable characters that may
220 * destroy the user's terminal. So we do one pass to find any
221 * unprintable characters, size the array appropriately, and
222 * then walk each character by hand. Those that are unprintable
223 * are replaced by a hex escape (\xNN). We also escape quotes for
224 * completeness.
226 int i, unprintable, quotes;
227 size_t len = strlen(s);
228 for (i = 0, unprintable = 0, quotes = 0; i < len; i++) {
229 if (!isprint(s[i]))
230 unprintable++;
231 if (s[i] == '"')
232 quotes++;
235 GROW(len + 3 * unprintable + quotes + 2);
237 pri->sys_string[pri->sys_leng++] = '"';
238 for (i = 0; i < len; i++) {
239 if (s[i] == '"')
240 pri->sys_string[pri->sys_leng++] = '\\';
242 if (isprint(s[i])) {
243 pri->sys_string[pri->sys_leng++] = s[i];
244 } else {
245 pri->sys_leng += sprintf(pri->sys_string +
246 pri->sys_leng, "\\x%02x", (uint8_t)s[i]);
249 pri->sys_string[pri->sys_leng++] = '"';
252 void
253 prt_stg(private_t *pri, int raw, long val) /* print as string */
255 char *s = raw? NULL : fetchstring(pri, (long)val, PATH_MAX);
257 if (s == NULL)
258 prt_hex(pri, 0, val);
259 else
260 escape_string(pri, s);
263 /* print as string returned from syscall */
264 void
265 prt_rst(private_t *pri, int raw, long val)
267 char *s = (raw || pri->Errno)? NULL :
268 fetchstring(pri, (long)val, PATH_MAX);
270 if (s == NULL)
271 prt_hex(pri, 0, val);
272 else {
273 GROW((int)strlen(s) + 2);
274 pri->sys_leng += snprintf(pri->sys_string + pri->sys_leng,
275 pri->sys_ssize - pri->sys_leng, "\"%s\"", s);
279 /* print contents of readlink() buffer */
280 void
281 prt_rlk(private_t *pri, int raw, long val)
283 char *s = (raw || pri->Errno || pri->Rval1 <= 0)? NULL :
284 fetchstring(pri, (long)val,
285 (pri->Rval1 > PATH_MAX)? PATH_MAX : (int)pri->Rval1);
287 if (s == NULL)
288 prt_hex(pri, 0, val);
289 else {
290 GROW((int)strlen(s) + 2);
291 pri->sys_leng += snprintf(pri->sys_string + pri->sys_leng,
292 pri->sys_ssize - pri->sys_leng, "\"%s\"", s);
296 void
297 prt_ioc(private_t *pri, int raw, long val) /* print ioctl code */
299 const char *s = raw? NULL : ioctlname(pri, (int)val);
301 if (s == NULL)
302 prt_hex(pri, 0, val);
303 else
304 outstring(pri, s);
307 void
308 prt_ioa(private_t *pri, int raw, long val) /* print ioctl argument */
310 const char *s;
312 /* cheating -- look at the ioctl() code */
313 switch (pri->sys_args[1]) {
315 /* kstat ioctl()s */
316 case KSTAT_IOC_READ:
317 case KSTAT_IOC_WRITE:
318 #ifdef _LP64
319 if (data_model == PR_MODEL_ILP32)
320 prt_stg(pri, raw,
321 val + offsetof(kstat32_t, ks_name[0]));
322 else
323 #endif
324 prt_stg(pri, raw,
325 val + offsetof(kstat_t, ks_name[0]));
326 break;
328 /* streams ioctl()s */
329 case I_LOOK:
330 prt_rst(pri, raw, val);
331 break;
332 case I_PUSH:
333 case I_FIND:
334 prt_stg(pri, raw, val);
335 break;
336 case I_LINK:
337 case I_UNLINK:
338 case I_SENDFD:
339 prt_dec(pri, 0, val);
340 break;
341 case I_SRDOPT:
342 if (raw || (s = strrdopt(val)) == NULL)
343 prt_dec(pri, 0, val);
344 else
345 outstring(pri, s);
346 break;
347 case I_SETSIG:
348 if (raw || (s = strevents(pri, val)) == NULL)
349 prt_hex(pri, 0, val);
350 else
351 outstring(pri, s);
352 break;
353 case I_FLUSH:
354 if (raw || (s = strflush(val)) == NULL)
355 prt_dec(pri, 0, val);
356 else
357 outstring(pri, s);
358 break;
360 /* tty ioctl()s */
361 case TCSBRK:
362 case TCXONC:
363 case TCFLSH:
364 case TCDSET:
365 prt_dec(pri, 0, val);
366 break;
368 default:
369 prt_hex(pri, 0, val);
370 break;
374 void
375 prt_pip(private_t *pri, int raw, long val) /* print pipe code */
377 const char *s = NULL;
379 if (!raw) {
380 switch (val) {
381 case O_CLOEXEC:
382 s = "O_CLOEXEC";
383 break;
384 case O_NONBLOCK:
385 s = "O_NONBLOCK";
386 break;
387 case O_CLOEXEC|O_NONBLOCK:
388 s = "O_CLOEXEC|O_NONBLOCK";
389 break;
393 if (s == NULL)
394 prt_dex(pri, 0, val);
395 else
396 outstring(pri, s);
399 void
400 prt_pfd(private_t *pri, int raw, long val) /* print pipe code */
402 int fds[2];
403 char str[32];
405 /* the fds only have meaning if the return value is 0 */
406 if (!raw &&
407 pri->Rval1 >= 0 &&
408 Pread(Proc, fds, sizeof (fds), (long)val) == sizeof (fds)) {
409 (void) snprintf(str, sizeof (str), "[%d,%d]", fds[0], fds[1]);
410 outstring(pri, str);
411 } else {
412 prt_hex(pri, 0, val);
416 void
417 prt_fcn(private_t *pri, int raw, long val) /* print fcntl code */
419 const char *s = raw? NULL : fcntlname(val);
421 if (s == NULL)
422 prt_dec(pri, 0, val);
423 else
424 outstring(pri, s);
427 void
428 prt_s86(private_t *pri, int raw, long val) /* print sysi86 code */
431 const char *s = raw? NULL : si86name(val);
433 if (s == NULL)
434 prt_dec(pri, 0, val);
435 else
436 outstring(pri, s);
439 void
440 prt_uts(private_t *pri, int raw, long val) /* print utssys code */
442 const char *s = raw? NULL : utscode(val);
444 if (s == NULL)
445 prt_dec(pri, 0, val);
446 else
447 outstring(pri, s);
450 void
451 prt_msc(private_t *pri, int raw, long val) /* print msgsys command */
453 const char *s = raw? NULL : msgcmd(val);
455 if (s == NULL)
456 prt_dec(pri, 0, val);
457 else
458 outstring(pri, s);
461 void
462 prt_msf(private_t *pri, int raw, long val) /* print msgsys flags */
464 const char *s = raw? NULL : msgflags(pri, (int)val);
466 if (s == NULL)
467 prt_oct(pri, 0, val);
468 else
469 outstring(pri, s);
472 void
473 prt_smc(private_t *pri, int raw, long val) /* print semsys command */
475 const char *s = raw? NULL : semcmd(val);
477 if (s == NULL)
478 prt_dec(pri, 0, val);
479 else
480 outstring(pri, s);
483 void
484 prt_sef(private_t *pri, int raw, long val) /* print semsys flags */
486 const char *s = raw? NULL : semflags(pri, (int)val);
488 if (s == NULL)
489 prt_oct(pri, 0, val);
490 else
491 outstring(pri, s);
494 void
495 prt_shc(private_t *pri, int raw, long val) /* print shmsys command */
497 const char *s = raw? NULL : shmcmd(val);
499 if (s == NULL)
500 prt_dec(pri, 0, val);
501 else
502 outstring(pri, s);
505 void
506 prt_shf(private_t *pri, int raw, long val) /* print shmsys flags */
508 const char *s = raw? NULL : shmflags(pri, (int)val);
510 if (s == NULL)
511 prt_oct(pri, 0, val);
512 else
513 outstring(pri, s);
516 void
517 prt_sfs(private_t *pri, int raw, long val) /* print sysfs code */
519 const char *s = raw? NULL : sfsname(val);
521 if (s == NULL)
522 prt_dec(pri, 0, val);
523 else
524 outstring(pri, s);
527 void
528 prt_opn(private_t *pri, int raw, long val) /* print open code */
530 const char *s = raw? NULL : openarg(pri, val);
532 if (s == NULL)
533 prt_oct(pri, 0, val);
534 else
535 outstring(pri, s);
538 void
539 prt_sig(private_t *pri, int raw, long val) /* print signal name */
541 const char *s = raw? NULL : signame(pri, (int)val);
543 if (s == NULL)
544 prt_hex(pri, 0, val);
545 else
546 outstring(pri, s);
549 void
550 prt_smf(private_t *pri, int raw, long val) /* print streams message flags */
552 switch (val) {
553 case 0:
554 prt_dec(pri, 0, val);
555 break;
556 case RS_HIPRI:
557 if (raw)
558 prt_hhx(pri, 0, val);
559 else
560 outstring(pri, "RS_HIPRI");
561 break;
562 default:
563 prt_hhx(pri, 0, val);
564 break;
568 void
569 prt_mtf(private_t *pri, int raw, long val) /* print mount flags */
571 const char *s = raw? NULL : mountflags(pri, val);
573 if (s == NULL)
574 prt_hex(pri, 0, val);
575 else
576 outstring(pri, s);
579 void
580 prt_mft(private_t *pri, int raw, long val) /* print mount file system type */
582 if (val >= 0 && val < 256)
583 prt_dec(pri, 0, val);
584 else if (raw)
585 prt_hex(pri, 0, val);
586 else
587 prt_stg(pri, raw, val);
590 #define ISREAD(code) \
591 ((code) == SYS_read || (code) == SYS_pread || (code) == SYS_pread64 || \
592 (code) == SYS_recv || (code) == SYS_recvfrom)
593 #define ISWRITE(code) \
594 ((code) == SYS_write || (code) == SYS_pwrite || \
595 (code) == SYS_pwrite64 || (code) == SYS_send || (code) == SYS_sendto)
597 /* print contents of read() or write() I/O buffer */
598 void
599 prt_iob(private_t *pri, int raw, long val)
601 const lwpstatus_t *Lsp = pri->lwpstat;
602 int syscall = Lsp->pr_what;
603 int fdp1 = pri->sys_args[0] + 1;
604 ssize_t nbyte = ISWRITE(syscall)? pri->sys_args[2] :
605 (pri->Errno? 0 : pri->Rval1);
606 int elsewhere = FALSE; /* TRUE iff dumped elsewhere */
607 char buffer[IOBSIZE];
609 pri->iob_buf[0] = '\0';
611 if (Lsp->pr_why == PR_SYSEXIT && nbyte > IOBSIZE) {
612 if (ISREAD(syscall))
613 elsewhere = prismember(&readfd, fdp1);
614 else
615 elsewhere = prismember(&writefd, fdp1);
618 if (nbyte <= 0 || elsewhere)
619 prt_hex(pri, 0, val);
620 else {
621 int nb = nbyte > IOBSIZE? IOBSIZE : (int)nbyte;
623 if (Pread(Proc, buffer, (size_t)nb, (long)val) != nb)
624 prt_hex(pri, 0, val);
625 else {
626 pri->iob_buf[0] = '"';
627 showbytes(buffer, nb, pri->iob_buf + 1);
628 (void) strlcat(pri->iob_buf,
629 (nb == nbyte)?
630 (const char *)"\"" : (const char *)"\"..",
631 sizeof (pri->iob_buf));
632 if (raw)
633 prt_hex(pri, 0, val);
634 else
635 outstring(pri, pri->iob_buf);
639 #undef ISREAD
640 #undef ISWRITE
642 void
643 prt_idt(private_t *pri, int raw, long val) /* print idtype_t, waitid() arg */
645 const char *s = raw? NULL : idtype_enum(pri, val);
647 if (s == NULL)
648 prt_dec(pri, 0, val);
649 else
650 outstring(pri, s);
653 void
654 prt_wop(private_t *pri, int raw, long val) /* print waitid() options */
656 const char *s = raw? NULL : woptions(pri, (int)val);
658 if (s == NULL)
659 prt_oct(pri, 0, val);
660 else
661 outstring(pri, s);
664 void
665 prt_whn(private_t *pri, int raw, long val) /* print lseek() whence argument */
667 const char *s = raw? NULL : whencearg(val);
669 if (s == NULL)
670 prt_dec(pri, 0, val);
671 else
672 outstring(pri, s);
675 /*ARGSUSED*/
676 void
677 prt_spm(private_t *pri, int raw, long val) /* print sigprocmask argument */
679 const char *s = NULL;
681 if (!raw) {
682 switch (val) {
683 case SIG_BLOCK: s = "SIG_BLOCK"; break;
684 case SIG_UNBLOCK: s = "SIG_UNBLOCK"; break;
685 case SIG_SETMASK: s = "SIG_SETMASK"; break;
689 if (s == NULL)
690 prt_dec(pri, 0, val);
691 else
692 outstring(pri, s);
695 const char *
696 mmap_protect(private_t *pri, long arg)
698 char *str = pri->code_buf;
700 if (arg & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
701 return (NULL);
703 if (arg == PROT_NONE)
704 return ("PROT_NONE");
706 *str = '\0';
707 if (arg & PROT_READ)
708 (void) strlcat(str, "|PROT_READ", sizeof (pri->code_buf));
709 if (arg & PROT_WRITE)
710 (void) strlcat(str, "|PROT_WRITE", sizeof (pri->code_buf));
711 if (arg & PROT_EXEC)
712 (void) strlcat(str, "|PROT_EXEC", sizeof (pri->code_buf));
713 return ((const char *)(str + 1));
716 const char *
717 mmap_type(private_t *pri, long arg)
719 char *str = pri->code_buf;
720 size_t used;
722 #define CBSIZE sizeof (pri->code_buf)
723 switch (arg & MAP_TYPE) {
724 case MAP_SHARED:
725 used = strlcpy(str, "MAP_SHARED", CBSIZE);
726 break;
727 case MAP_PRIVATE:
728 used = strlcpy(str, "MAP_PRIVATE", CBSIZE);
729 break;
730 default:
731 used = snprintf(str, CBSIZE, "%ld", arg&MAP_TYPE);
732 break;
735 arg &= ~MAP_TYPE;
737 if (arg & ~(MAP_FIXED|MAP_RENAME|MAP_NORESERVE|MAP_ANON|MAP_ALIGN|
738 MAP_TEXT|MAP_INITDATA|MAP_32BIT))
739 (void) snprintf(str + used, sizeof (pri->code_buf) - used,
740 "|0x%lX", arg);
741 else {
742 if (arg & MAP_FIXED)
743 (void) strlcat(str, "|MAP_FIXED", CBSIZE);
744 if (arg & MAP_RENAME)
745 (void) strlcat(str, "|MAP_RENAME", CBSIZE);
746 if (arg & MAP_NORESERVE)
747 (void) strlcat(str, "|MAP_NORESERVE", CBSIZE);
748 if (arg & MAP_ANON)
749 (void) strlcat(str, "|MAP_ANON", CBSIZE);
750 if (arg & MAP_ALIGN)
751 (void) strlcat(str, "|MAP_ALIGN", CBSIZE);
752 if (arg & MAP_TEXT)
753 (void) strlcat(str, "|MAP_TEXT", CBSIZE);
754 if (arg & MAP_INITDATA)
755 (void) strlcat(str, "|MAP_INITDATA", CBSIZE);
756 if (arg & MAP_32BIT)
757 (void) strlcat(str, "|MAP_32BIT", CBSIZE);
760 return ((const char *)str);
761 #undef CBSIZE
764 void
765 prt_mpr(private_t *pri, int raw, long val) /* print mmap()/mprotect() flags */
767 const char *s = raw? NULL : mmap_protect(pri, val);
769 if (s == NULL)
770 prt_hhx(pri, 0, val);
771 else
772 outstring(pri, s);
775 void
776 prt_mty(private_t *pri, int raw, long val) /* print mmap() mapping type flags */
778 const char *s = raw? NULL : mmap_type(pri, val);
780 if (s == NULL)
781 prt_hhx(pri, 0, val);
782 else
783 outstring(pri, s);
786 void
787 prt_mob(private_t *pri, int raw, long val) /* print mmapobj() flags */
789 if (val == 0) {
790 prt_dec(pri, 0, val);
791 } else if (raw || (val & ~(MMOBJ_ALL_FLAGS)) != 0) {
792 prt_hhx(pri, 0, val);
793 } else {
794 #define CBSIZE sizeof (pri->code_buf)
795 char *s = pri->code_buf;
797 *s = '\0';
798 if (val & MMOBJ_PADDING)
799 (void) strlcat(s, "|MMOBJ_PADDING", CBSIZE);
800 if (val & MMOBJ_INTERPRET)
801 (void) strlcat(s, "|MMOBJ_INTERPRET", CBSIZE);
802 if (val & MMOBJ_PRIMARY)
803 (void) strlcat(s, "|MMOBJ_PRIMARY", CBSIZE);
804 outstring(pri, s + 1);
805 #undef CBSIZE
809 /*ARGSUSED*/
810 void
811 prt_mcf(private_t *pri, int raw, long val) /* print memcntl() function */
813 const char *s = NULL;
815 if (!raw) {
816 switch (val) {
817 case MC_SYNC: s = "MC_SYNC"; break;
818 case MC_LOCK: s = "MC_LOCK"; break;
819 case MC_UNLOCK: s = "MC_UNLOCK"; break;
820 case MC_ADVISE: s = "MC_ADVISE"; break;
821 case MC_LOCKAS: s = "MC_LOCKAS"; break;
822 case MC_UNLOCKAS: s = "MC_UNLOCKAS"; break;
823 case MC_HAT_ADVISE: s = "MC_HAT_ADVISE"; break;
827 if (s == NULL)
828 prt_dec(pri, 0, val);
829 else
830 outstring(pri, s);
833 void
834 prt_mad(private_t *pri, int raw, long val) /* print madvise() argument */
836 const char *s = NULL;
838 if (!raw) {
839 switch (val) {
840 case MADV_NORMAL: s = "MADV_NORMAL"; break;
841 case MADV_RANDOM: s = "MADV_RANDOM"; break;
842 case MADV_SEQUENTIAL: s = "MADV_SEQUENTIAL"; break;
843 case MADV_WILLNEED: s = "MADV_WILLNEED"; break;
844 case MADV_DONTNEED: s = "MADV_DONTNEED"; break;
845 case MADV_FREE: s = "MADV_FREE"; break;
846 case MADV_ACCESS_DEFAULT: s = "MADV_ACCESS_DEFAULT"; break;
847 case MADV_ACCESS_LWP: s = "MADV_ACCESS_LWP"; break;
848 case MADV_ACCESS_MANY: s = "MADV_ACCESS_MANY"; break;
849 case MADV_PURGE: s = "MADV_PURGE"; break;
853 if (s == NULL)
854 prt_dec(pri, 0, val);
855 else
856 outstring(pri, s);
859 void
860 prt_mc4(private_t *pri, int raw, long val) /* print memcntl() (4th) argument */
862 if (val == 0)
863 prt_dec(pri, 0, val);
864 else if (raw)
865 prt_hhx(pri, 0, val);
866 else {
867 char *s = NULL;
869 #define CBSIZE sizeof (pri->code_buf)
870 /* cheating -- look at memcntl func */
871 switch (pri->sys_args[2]) {
872 case MC_ADVISE:
873 prt_mad(pri, 0, val);
874 return;
876 case MC_SYNC:
877 if ((val & ~(MS_SYNC|MS_ASYNC|MS_INVALIDATE)) == 0) {
878 *(s = pri->code_buf) = '\0';
879 if (val & MS_SYNC)
880 (void) strlcat(s, "|MS_SYNC", CBSIZE);
881 if (val & MS_ASYNC)
882 (void) strlcat(s, "|MS_ASYNC", CBSIZE);
883 if (val & MS_INVALIDATE)
884 (void) strlcat(s, "|MS_INVALIDATE",
885 CBSIZE);
887 break;
889 case MC_LOCKAS:
890 case MC_UNLOCKAS:
891 if ((val & ~(MCL_CURRENT|MCL_FUTURE)) == 0) {
892 *(s = pri->code_buf) = '\0';
893 if (val & MCL_CURRENT)
894 (void) strlcat(s, "|MCL_CURRENT",
895 CBSIZE);
896 if (val & MCL_FUTURE)
897 (void) strlcat(s, "|MCL_FUTURE",
898 CBSIZE);
900 break;
902 #undef CBSIZE
904 if (s == NULL || *s == '\0')
905 prt_hhx(pri, 0, val);
906 else
907 outstring(pri, ++s);
911 void
912 prt_mc5(private_t *pri, int raw, long val) /* print memcntl() (5th) argument */
914 char *s;
916 #define CBSIZE sizeof (pri->code_buf)
917 if (val == 0)
918 prt_dec(pri, 0, val);
919 else if (raw || (val & ~VALID_ATTR))
920 prt_hhx(pri, 0, val);
921 else {
922 s = pri->code_buf;
923 *s = '\0';
924 if (val & SHARED)
925 (void) strlcat(s, "|SHARED", CBSIZE);
926 if (val & PRIVATE)
927 (void) strlcat(s, "|PRIVATE", CBSIZE);
928 if (val & PROT_READ)
929 (void) strlcat(s, "|PROT_READ", CBSIZE);
930 if (val & PROT_WRITE)
931 (void) strlcat(s, "|PROT_WRITE", CBSIZE);
932 if (val & PROT_EXEC)
933 (void) strlcat(s, "|PROT_EXEC", CBSIZE);
934 if (*s == '\0')
935 prt_hhx(pri, 0, val);
936 else
937 outstring(pri, ++s);
939 #undef CBSIZE
942 void
943 prt_ulm(private_t *pri, int raw, long val) /* print ulimit() argument */
945 const char *s = NULL;
947 if (!raw) {
948 switch (val) {
949 case UL_GFILLIM: s = "UL_GFILLIM"; break;
950 case UL_SFILLIM: s = "UL_SFILLIM"; break;
951 case UL_GMEMLIM: s = "UL_GMEMLIM"; break;
952 case UL_GDESLIM: s = "UL_GDESLIM"; break;
956 if (s == NULL)
957 prt_dec(pri, 0, val);
958 else
959 outstring(pri, s);
962 void
963 prt_rlm(private_t *pri, int raw, long val) /* print get/setrlimit() argument */
965 const char *s = NULL;
967 if (!raw) {
968 switch (val) {
969 case RLIMIT_CPU: s = "RLIMIT_CPU"; break;
970 case RLIMIT_FSIZE: s = "RLIMIT_FSIZE"; break;
971 case RLIMIT_DATA: s = "RLIMIT_DATA"; break;
972 case RLIMIT_STACK: s = "RLIMIT_STACK"; break;
973 case RLIMIT_CORE: s = "RLIMIT_CORE"; break;
974 case RLIMIT_NOFILE: s = "RLIMIT_NOFILE"; break;
975 case RLIMIT_VMEM: s = "RLIMIT_VMEM"; break;
979 if (s == NULL)
980 prt_dec(pri, 0, val);
981 else
982 outstring(pri, s);
985 void
986 prt_cnf(private_t *pri, int raw, long val) /* print sysconfig code */
988 const char *s = raw? NULL : sconfname(val);
990 if (s == NULL)
991 prt_dec(pri, 0, val);
992 else
993 outstring(pri, s);
996 void
997 prt_inf(private_t *pri, int raw, long val) /* print sysinfo code */
999 const char *s = NULL;
1001 if (!raw) {
1002 switch (val) {
1003 case SI_SYSNAME: s = "SI_SYSNAME"; break;
1004 case SI_HOSTNAME: s = "SI_HOSTNAME"; break;
1005 case SI_RELEASE: s = "SI_RELEASE"; break;
1006 case SI_VERSION: s = "SI_VERSION"; break;
1007 case SI_MACHINE: s = "SI_MACHINE"; break;
1008 case SI_ARCHITECTURE: s = "SI_ARCHITECTURE"; break;
1009 case SI_ARCHITECTURE_32:s = "SI_ARCHITECTURE_32"; break;
1010 case SI_ARCHITECTURE_64:s = "SI_ARCHITECTURE_64"; break;
1011 case SI_ARCHITECTURE_K: s = "SI_ARCHITECTURE_K"; break;
1012 case SI_HW_SERIAL: s = "SI_HW_SERIAL"; break;
1013 case SI_HW_PROVIDER: s = "SI_HW_PROVIDER"; break;
1014 case SI_SRPC_DOMAIN: s = "SI_SRPC_DOMAIN"; break;
1015 case SI_SET_HOSTNAME: s = "SI_SET_HOSTNAME"; break;
1016 case SI_SET_SRPC_DOMAIN: s = "SI_SET_SRPC_DOMAIN"; break;
1017 case SI_PLATFORM: s = "SI_PLATFORM"; break;
1018 case SI_ISALIST: s = "SI_ISALIST"; break;
1019 case SI_DHCP_CACHE: s = "SI_DHCP_CACHE"; break;
1023 if (s == NULL)
1024 prt_dec(pri, 0, val);
1025 else
1026 outstring(pri, s);
1029 void
1030 prt_ptc(private_t *pri, int raw, long val) /* print pathconf code */
1032 const char *s = raw? NULL : pathconfname(val);
1034 if (s == NULL)
1035 prt_dec(pri, 0, val);
1036 else
1037 outstring(pri, s);
1040 void
1041 prt_fui(private_t *pri, int raw, long val) /* print fusers() input argument */
1043 const char *s = raw? NULL : fuiname(val);
1045 if (s == NULL)
1046 prt_hhx(pri, 0, val);
1047 else
1048 outstring(pri, s);
1051 void
1052 prt_lwf(private_t *pri, int raw, long val) /* print lwp_create() flags */
1054 char *s;
1056 if (val == 0)
1057 prt_dec(pri, 0, val);
1058 else if (raw ||
1059 (val & ~(LWP_DAEMON|LWP_DETACHED|LWP_SUSPENDED)))
1060 prt_hhx(pri, 0, val);
1061 else {
1062 #define CBSIZE sizeof (pri->code_buf)
1063 s = pri->code_buf;
1064 *s = '\0';
1065 if (val & LWP_DAEMON)
1066 (void) strlcat(s, "|LWP_DAEMON", CBSIZE);
1067 if (val & LWP_DETACHED)
1068 (void) strlcat(s, "|LWP_DETACHED", CBSIZE);
1069 if (val & LWP_SUSPENDED)
1070 (void) strlcat(s, "|LWP_SUSPENDED", CBSIZE);
1071 outstring(pri, ++s);
1072 #undef CBSIZE
1076 void
1077 prt_itm(private_t *pri, int raw, long val) /* print [get|set]itimer() arg */
1079 const char *s = NULL;
1081 if (!raw) {
1082 switch (val) {
1083 case ITIMER_REAL: s = "ITIMER_REAL"; break;
1084 case ITIMER_VIRTUAL: s = "ITIMER_VIRTUAL"; break;
1085 case ITIMER_PROF: s = "ITIMER_PROF"; break;
1086 #ifdef ITIMER_REALPROF
1087 case ITIMER_REALPROF: s = "ITIMER_REALPROF"; break;
1088 #endif
1092 if (s == NULL)
1093 prt_dec(pri, 0, val);
1094 else
1095 outstring(pri, s);
1098 void
1099 prt_mod(private_t *pri, int raw, long val) /* print modctl() code */
1101 const char *s = NULL;
1103 if (!raw) {
1104 switch (val) {
1105 case MODLOAD: s = "MODLOAD"; break;
1106 case MODUNLOAD: s = "MODUNLOAD"; break;
1107 case MODINFO: s = "MODINFO"; break;
1108 case MODRESERVED: s = "MODRESERVED"; break;
1109 case MODSETMINIROOT: s = "MODSETMINIROOT"; break;
1110 case MODADDMAJBIND: s = "MODADDMAJBIND"; break;
1111 case MODGETPATH: s = "MODGETPATH"; break;
1112 case MODGETPATHLEN: s = "MODGETPATHLEN"; break;
1113 case MODREADSYSBIND: s = "MODREADSYSBIND"; break;
1114 case MODGETMAJBIND: s = "MODGETMAJBIND"; break;
1115 case MODGETNAME: s = "MODGETNAME"; break;
1116 case MODSIZEOF_DEVID: s = "MODSIZEOF_DEVID"; break;
1117 case MODGETDEVID: s = "MODGETDEVID"; break;
1118 case MODSIZEOF_MINORNAME: s = "MODSIZEOF_MINORNAME"; break;
1119 case MODGETMINORNAME: s = "MODGETMINORNAME"; break;
1120 case MODGETFBNAME: s = "MODGETFBNAME"; break;
1121 case MODEVENTS: s = "MODEVENTS"; break;
1122 case MODREREADDACF: s = "MODREREADDACF"; break;
1123 case MODLOADDRVCONF: s = "MODLOADDRVCONF"; break;
1124 case MODUNLOADDRVCONF: s = "MODUNLOADDRVCONF"; break;
1125 case MODREMMAJBIND: s = "MODREMMAJBIND"; break;
1126 case MODDEVT2INSTANCE: s = "MODDEVT2INSTANCE"; break;
1127 case MODGETDEVFSPATH_LEN: s = "MODGETDEVFSPATH_LEN"; break;
1128 case MODGETDEVFSPATH: s = "MODGETDEVFSPATH"; break;
1129 case MODDEVID2PATHS: s = "MODDEVID2PATHS"; break;
1130 case MODSETDEVPOLICY: s = "MODSETDEVPOLICY"; break;
1131 case MODGETDEVPOLICY: s = "MODGETDEVPOLICY"; break;
1132 case MODALLOCPRIV: s = "MODALLOCPRIV"; break;
1133 case MODGETDEVPOLICYBYNAME:
1134 s = "MODGETDEVPOLICYBYNAME"; break;
1135 case MODLOADMINORPERM: s = "MODLOADMINORPERM"; break;
1136 case MODADDMINORPERM: s = "MODADDMINORPERM"; break;
1137 case MODREMMINORPERM: s = "MODREMMINORPERM"; break;
1138 case MODREMDRVCLEANUP: s = "MODREMDRVCLEANUP"; break;
1139 case MODDEVEXISTS: s = "MODDEVEXISTS"; break;
1140 case MODDEVREADDIR: s = "MODDEVREADDIR"; break;
1141 case MODDEVEMPTYDIR: s = "MODDEVEMPTYDIR"; break;
1142 case MODDEVNAME: s = "MODDEVNAME"; break;
1143 case MODGETDEVFSPATH_MI_LEN:
1144 s = "MODGETDEVFSPATH_MI_LEN"; break;
1145 case MODGETDEVFSPATH_MI:
1146 s = "MODGETDEVFSPATH_MI"; break;
1147 case MODREMDRVALIAS: s = "MODREMDRVALIAS"; break;
1148 case MODHPOPS: s = "MODHPOPS"; break;
1152 if (s == NULL)
1153 prt_dec(pri, 0, val);
1154 else
1155 outstring(pri, s);
1158 void
1159 prt_acl(private_t *pri, int raw, long val) /* print acl() code */
1161 const char *s = NULL;
1163 if (!raw) {
1164 switch (val) {
1165 case GETACL: s = "GETACL"; break;
1166 case SETACL: s = "SETACL"; break;
1167 case GETACLCNT: s = "GETACLCNT"; break;
1168 case ACE_GETACL: s = "ACE_GETACL"; break;
1169 case ACE_SETACL: s = "ACE_SETACL"; break;
1170 case ACE_GETACLCNT: s = "ACE_GETACLCNT"; break;
1174 if (s == NULL)
1175 prt_dec(pri, 0, val);
1176 else
1177 outstring(pri, s);
1180 void
1181 prt_aio(private_t *pri, int raw, long val) /* print kaio() code */
1183 const char *s = NULL;
1184 char buf[32];
1186 if (!raw) {
1187 switch (val & ~AIO_POLL_BIT) {
1188 case AIOREAD: s = "AIOREAD"; break;
1189 case AIOWRITE: s = "AIOWRITE"; break;
1190 case AIOWAIT: s = "AIOWAIT"; break;
1191 case AIOCANCEL: s = "AIOCANCEL"; break;
1192 case AIONOTIFY: s = "AIONOTIFY"; break;
1193 case AIOINIT: s = "AIOINIT"; break;
1194 case AIOSTART: s = "AIOSTART"; break;
1195 case AIOLIO: s = "AIOLIO"; break;
1196 case AIOSUSPEND: s = "AIOSUSPEND"; break;
1197 case AIOERROR: s = "AIOERROR"; break;
1198 case AIOLIOWAIT: s = "AIOLIOWAIT"; break;
1199 case AIOAREAD: s = "AIOAREAD"; break;
1200 case AIOAWRITE: s = "AIOAWRITE"; break;
1202 * We have to hardcode the values for the 64-bit versions of
1203 * these calls, because <sys/aio.h> defines them to be identical
1204 * when compiled 64-bit. If our target is 32-bit, we still need
1205 * to decode them correctly.
1207 case 13: s = "AIOLIO64"; break;
1208 case 14: s = "AIOSUSPEND64"; break;
1209 case 15: s = "AUIOERROR64"; break;
1210 case 16: s = "AIOLIOWAIT64"; break;
1211 case 17: s = "AIOAREAD64"; break;
1212 case 18: s = "AIOAWRITE64"; break;
1213 case 19: s = "AIOCANCEL64"; break;
1216 * AIOFSYNC doesn't correspond to a syscall.
1218 case AIOWAITN: s = "AIOWAITN"; break;
1220 if (s != NULL && (val & AIO_POLL_BIT)) {
1221 (void) strlcpy(buf, s, sizeof (buf));
1222 (void) strlcat(buf, "|AIO_POLL_BIT", sizeof (buf));
1223 s = (const char *)buf;
1227 if (s == NULL)
1228 prt_dec(pri, 0, val);
1229 else
1230 outstring(pri, s);
1233 void
1234 prt_aud(private_t *pri, int raw, long val) /* print auditsys() code */
1236 const char *s = NULL;
1238 if (!raw) {
1239 switch (val) {
1240 case BSM_GETAUID: s = "BSM_GETAUID"; break;
1241 case BSM_SETAUID: s = "BSM_SETAUID"; break;
1242 case BSM_GETAUDIT: s = "BSM_GETAUDIT"; break;
1243 case BSM_SETAUDIT: s = "BSM_SETAUDIT"; break;
1244 case BSM_AUDIT: s = "BSM_AUDIT"; break;
1245 case BSM_AUDITCTL: s = "BSM_AUDITCTL"; break;
1246 case BSM_GETAUDIT_ADDR: s = "BSM_GETAUDIT_ADDR"; break;
1247 case BSM_SETAUDIT_ADDR: s = "BSM_SETAUDIT_ADDR"; break;
1251 if (s == NULL)
1252 prt_dec(pri, 0, val);
1253 else
1254 outstring(pri, s);
1257 void
1258 prt_cor(private_t *pri, int raw, long val) /* print corectl() subcode */
1260 const char *s = NULL;
1262 if (!raw) {
1263 switch (val) {
1264 case CC_SET_OPTIONS:
1265 s = "CC_SET_OPTIONS"; break;
1266 case CC_GET_OPTIONS:
1267 s = "CC_GET_OPTIONS"; break;
1268 case CC_SET_GLOBAL_PATH:
1269 s = "CC_SET_GLOBAL_PATH"; break;
1270 case CC_GET_GLOBAL_PATH:
1271 s = "CC_GET_GLOBAL_PATH"; break;
1272 case CC_SET_PROCESS_PATH:
1273 s = "CC_SET_PROCESS_PATH"; break;
1274 case CC_GET_PROCESS_PATH:
1275 s = "CC_GET_PROCESS_PATH"; break;
1276 case CC_SET_GLOBAL_CONTENT:
1277 s = "CC_SET_GLOBAL_CONTENT"; break;
1278 case CC_GET_GLOBAL_CONTENT:
1279 s = "CC_GET_GLOBAL_CONTENT"; break;
1280 case CC_SET_PROCESS_CONTENT:
1281 s = "CC_SET_PROCESS_CONTENT"; break;
1282 case CC_GET_PROCESS_CONTENT:
1283 s = "CC_GET_PROCESS_CONTENT"; break;
1284 case CC_SET_DEFAULT_PATH:
1285 s = "CC_SET_DEFAULT_PATH"; break;
1286 case CC_GET_DEFAULT_PATH:
1287 s = "CC_GET_DEFAULT_PATH"; break;
1288 case CC_SET_DEFAULT_CONTENT:
1289 s = "CC_SET_DEFAULT_CONTENT"; break;
1290 case CC_GET_DEFAULT_CONTENT:
1291 s = "CC_GET_DEFAULT_CONTENT"; break;
1295 if (s == NULL)
1296 prt_dec(pri, 0, val);
1297 else
1298 outstring(pri, s);
1301 void
1302 prt_cco(private_t *pri, int raw, long val) /* print corectl() options */
1304 char *s;
1306 if (val == 0)
1307 prt_dec(pri, 0, val);
1308 else if (raw || (val & ~CC_OPTIONS))
1309 prt_hhx(pri, 0, val);
1310 else {
1311 #define CBSIZE sizeof (pri->code_buf)
1312 s = pri->code_buf;
1313 *s = '\0';
1314 if (val & CC_GLOBAL_PATH)
1315 (void) strlcat(s, "|CC_GLOBAL_PATH", CBSIZE);
1316 if (val & CC_PROCESS_PATH)
1317 (void) strlcat(s, "|CC_PROCESS_PATH", CBSIZE);
1318 if (val & CC_GLOBAL_SETID)
1319 (void) strlcat(s, "|CC_GLOBAL_SETID", CBSIZE);
1320 if (val & CC_PROCESS_SETID)
1321 (void) strlcat(s, "|CC_PROCESS_SETID", CBSIZE);
1322 if (val & CC_GLOBAL_LOG)
1323 (void) strlcat(s, "|CC_GLOBAL_LOG", CBSIZE);
1324 if (*s == '\0')
1325 prt_hhx(pri, 0, val);
1326 else
1327 outstring(pri, ++s);
1328 #undef CBSIZE
1332 void
1333 prt_ccc(private_t *pri, int raw, long val) /* print corectl() content */
1335 core_content_t ccc;
1337 if (Pread(Proc, &ccc, sizeof (ccc), val) != sizeof (ccc))
1338 prt_hex(pri, 0, val);
1339 else if (!raw && proc_content2str(ccc, pri->code_buf,
1340 sizeof (pri->code_buf)) >= 0)
1341 outstring(pri, pri->code_buf);
1342 else
1343 prt_hhx(pri, 0, (long)ccc);
1346 void
1347 prt_rcc(private_t *pri, int raw, long val) /* print corectl() ret. cont. */
1349 core_content_t ccc;
1351 if (pri->Errno || Pread(Proc, &ccc, sizeof (ccc), val) != sizeof (ccc))
1352 prt_hex(pri, 0, val);
1353 else if (!raw && proc_content2str(ccc, pri->code_buf,
1354 sizeof (pri->code_buf)) >= 0)
1355 outstring(pri, pri->code_buf);
1356 else
1357 prt_hhx(pri, 0, (long)ccc);
1360 void
1361 prt_cpc(private_t *pri, int raw, long val) /* print cpc() subcode */
1363 const char *s = NULL;
1365 if (!raw) {
1366 switch (val) {
1367 case CPC_BIND: s = "CPC_BIND"; break;
1368 case CPC_SAMPLE: s = "CPC_SAMPLE"; break;
1369 case CPC_INVALIDATE: s = "CPC_INVALIDATE"; break;
1370 case CPC_RELE: s = "CPC_RELE"; break;
1371 case CPC_EVLIST_SIZE: s = "CPC_EVLIST_SIZE"; break;
1372 case CPC_LIST_EVENTS: s = "CPC_LIST_EVENTS"; break;
1373 case CPC_ATTRLIST_SIZE: s = "CPC_ATTRLIST_SIZE"; break;
1374 case CPC_LIST_ATTRS: s = "CPC_LIST_ATTRS"; break;
1375 case CPC_IMPL_NAME: s = "CPC_IMPL_NAME"; break;
1376 case CPC_CPUREF: s = "CPC_CPUREF"; break;
1377 case CPC_USR_EVENTS: s = "CPC_USR_EVENTS"; break;
1378 case CPC_SYS_EVENTS: s = "CPC_SYS_EVENTS"; break;
1379 case CPC_NPIC: s = "CPC_NPIC"; break;
1380 case CPC_CAPS: s = "CPC_CAPS"; break;
1381 case CPC_ENABLE: s = "CPC_ENABLE"; break;
1382 case CPC_DISABLE: s = "CPC_DISABLE"; break;
1386 if (s == NULL)
1387 prt_dec(pri, 0, val);
1388 else
1389 outstring(pri, s);
1392 void
1393 outstring(private_t *pri, const char *s)
1395 int len = strlen(s);
1397 GROW(len);
1398 (void) strcpy(pri->sys_string + pri->sys_leng, s);
1399 pri->sys_leng += len;
1402 void
1403 grow(private_t *pri, int nbyte) /* reallocate format buffer if necessary */
1405 while (pri->sys_leng + nbyte >= pri->sys_ssize)
1406 pri->sys_string = my_realloc(pri->sys_string,
1407 pri->sys_ssize *= 2, "format buffer");
1410 void
1411 prt_sqc(private_t *pri, int raw, long val) /* print sigqueue() si_code */
1413 const char *s = NULL;
1415 if (!raw) {
1416 switch ((int)val) {
1417 case SI_QUEUE: s = "SI_QUEUE"; break;
1418 case SI_TIMER: s = "SI_TIMER"; break;
1419 case SI_ASYNCIO: s = "SI_ASYNCIO"; break;
1420 case SI_MESGQ: s = "SI_MESGQ"; break;
1424 if (s == NULL)
1425 prt_dec(pri, 0, val);
1426 else
1427 outstring(pri, s);
1431 * print priocntlsys() (key, value) pair key.
1433 void
1434 print_pck(private_t *pri, int raw, long val)
1436 const char *s = NULL;
1437 char clname[PC_CLNMSZ];
1439 if ((pri->sys_args[2] != PC_GETXPARMS &&
1440 pri->sys_args[2] != PC_SETXPARMS) || val == 0 || raw) {
1441 prt_dec(pri, 0, val);
1442 return;
1445 if (pri->sys_args[3] == 0) {
1446 if (val == PC_KY_CLNAME) {
1447 s = "PC_KY_CLNAME";
1448 outstring(pri, s);
1449 } else
1450 prt_dec(pri, 0, val);
1451 return;
1454 if (Pread(Proc, &clname, PC_CLNMSZ, pri->sys_args[3]) != PC_CLNMSZ) {
1455 prt_dec(pri, 0, val);
1456 return;
1459 if (strcmp(clname, "TS") == 0) {
1460 switch (val) {
1461 case TS_KY_UPRILIM: s = "TS_KY_UPRILIM"; break;
1462 case TS_KY_UPRI: s = "TS_KY_UPRI"; break;
1463 default: break;
1465 } else if (strcmp(clname, "IA") == 0) {
1466 switch (val) {
1467 case IA_KY_UPRILIM: s = "IA_KY_UPRILIM"; break;
1468 case IA_KY_UPRI: s = "IA_KY_UPRI"; break;
1469 case IA_KY_MODE: s = "IA_KY_MODE"; break;
1470 default: break;
1472 } else if (strcmp(clname, "RT") == 0) {
1473 switch (val) {
1474 case RT_KY_PRI: s = "RT_KY_PRI"; break;
1475 case RT_KY_TQSECS: s = "RT_KY_TQSECS"; break;
1476 case RT_KY_TQNSECS: s = "RT_KY_TQNSECS"; break;
1477 case RT_KY_TQSIG: s = "RT_KY_TQSIG"; break;
1478 default: break;
1480 } else if (strcmp(clname, "FSS") == 0) {
1481 switch (val) {
1482 case FSS_KY_UPRILIM: s = "FSS_KY_UPRILIM"; break;
1483 case FSS_KY_UPRI: s = "FSS_KY_UPRI"; break;
1484 default: break;
1486 } else if (strcmp(clname, "FX") == 0) {
1487 switch (val) {
1488 case FX_KY_UPRILIM: s = "FX_KY_UPRILIM"; break;
1489 case FX_KY_UPRI: s = "FX_KY_UPRI"; break;
1490 case FX_KY_TQSECS: s = "FX_KY_TQSECS"; break;
1491 case FX_KY_TQNSECS: s = "FX_KY_TQNSECS"; break;
1492 default: break;
1496 if (s == NULL)
1497 prt_dec(pri, 0, val);
1498 else
1499 outstring(pri, s);
1503 * print priocntlsys() fourth argument.
1505 /*ARGSUSED*/
1506 void
1507 prt_pc4(private_t *pri, int raw, long val)
1509 /* look at pricntlsys function */
1510 if ((pri->sys_args[2] != PC_GETXPARMS &&
1511 pri->sys_args[2] != PC_SETXPARMS))
1512 prt_hex(pri, 0, val);
1513 else if (val)
1514 prt_stg(pri, 0, val);
1515 else
1516 prt_dec(pri, 0, val);
1520 * print priocntlsys() (key, value) pairs (5th argument).
1522 /*ARGSUSED*/
1523 void
1524 prt_pc5(private_t *pri, int raw, long val)
1526 pc_vaparms_t prms;
1527 pc_vaparm_t *vpp = &prms.pc_parms[0];
1528 uint_t cnt;
1531 /* look at pricntlsys function */
1532 if ((pri->sys_args[2] != PC_GETXPARMS &&
1533 pri->sys_args[2] != PC_SETXPARMS) || val == 0) {
1534 prt_dec(pri, 0, 0);
1535 return;
1538 if (Pread(Proc, &prms, sizeof (prms), val) != sizeof (prms)) {
1539 prt_hex(pri, 0, val);
1540 return;
1543 if ((cnt = prms.pc_vaparmscnt) > PC_VAPARMCNT)
1544 return;
1546 for (; cnt--; vpp++) {
1547 print_pck(pri, 0, vpp->pc_key);
1548 outstring(pri, ", ");
1549 prt_hex(pri, 0, (long)vpp->pc_parm);
1550 outstring(pri, ", ");
1553 prt_dec(pri, 0, PC_KY_NULL);
1557 void
1558 prt_psflags(private_t *pri, secflagset_t val)
1560 char str[1024];
1562 if (val == 0) {
1563 outstring(pri, "0x0");
1564 return;
1567 *str = '\0';
1568 if (secflag_isset(val, PROC_SEC_ASLR)) {
1569 (void) strlcat(str, "|PROC_SEC_ASLR", sizeof (str));
1570 secflag_clear(&val, PROC_SEC_ASLR);
1572 if (secflag_isset(val, PROC_SEC_FORBIDNULLMAP)) {
1573 (void) strlcat(str, "|PROC_SEC_FORBIDNULLMAP",
1574 sizeof (str));
1575 secflag_clear(&val, PROC_SEC_FORBIDNULLMAP);
1577 if (secflag_isset(val, PROC_SEC_NOEXECSTACK)) {
1578 (void) strlcat(str, "|PROC_SEC_NOEXECSTACK",
1579 sizeof (str));
1580 secflag_clear(&val, PROC_SEC_NOEXECSTACK);
1583 if (val != 0)
1584 (void) snprintf(str, sizeof (str), "%s|%#x", str, val);
1586 outstring(pri, str + 1);
1590 * Print a psecflags(2) delta
1592 void
1593 prt_psdelta(private_t *pri, int raw, long value)
1595 secflagdelta_t psd;
1597 if ((raw != 0) ||
1598 (Pread(Proc, &psd, sizeof (psd), value) != sizeof (psd))) {
1599 prt_hex(pri, 0, value);
1600 return;
1602 outstring(pri, "{ ");
1603 prt_psflags(pri, psd.psd_add);
1604 outstring(pri, ", ");
1605 prt_psflags(pri, psd.psd_rem);
1606 outstring(pri, ", ");
1607 prt_psflags(pri, psd.psd_assign);
1608 outstring(pri, ", ");
1609 outstring(pri, psd.psd_ass_active ? "B_TRUE" : "B_FALSE");
1610 outstring(pri, " }");
1614 * Print a psecflagswhich_t
1616 void
1617 prt_psfw(private_t *pri, int raw, long value)
1619 psecflagwhich_t which = (psecflagwhich_t)value;
1620 char *s;
1622 if (raw != 0) {
1623 prt_dec(pri, 0, value);
1624 return;
1627 switch (which) {
1628 case PSF_EFFECTIVE:
1629 s = "PSF_EFFECTIVE";
1630 break;
1631 case PSF_INHERIT:
1632 s = "PSF_INHERIT";
1633 break;
1634 case PSF_LOWER:
1635 s = "PSF_LOWER";
1636 break;
1637 case PSF_UPPER:
1638 s = "PSF_UPPER";
1639 break;
1642 if (s == NULL)
1643 prt_dec(pri, 0, value);
1644 else
1645 outstring(pri, s);
1649 * Print processor set id, including logical expansion of "special" ids.
1651 void
1652 prt_pst(private_t *pri, int raw, long val)
1654 const char *s = NULL;
1656 if (!raw) {
1657 switch ((psetid_t)val) {
1658 case PS_NONE: s = "PS_NONE"; break;
1659 case PS_QUERY: s = "PS_QUERY"; break;
1660 case PS_MYID: s = "PS_MYID"; break;
1664 if (s == NULL)
1665 prt_dec(pri, 0, val);
1666 else
1667 outstring(pri, s);
1671 * Print meminfo() argument.
1673 /*ARGSUSED*/
1674 void
1675 prt_mif(private_t *pri, int raw, long val)
1677 struct meminfo minfo;
1679 #ifdef _LP64
1680 if (data_model == PR_MODEL_ILP32) {
1681 struct meminfo32 minfo32;
1683 if (Pread(Proc, &minfo32, sizeof (struct meminfo32), val) !=
1684 sizeof (struct meminfo32)) {
1685 prt_dec(pri, 0, pri->sys_args[1]); /* addr_count */
1686 outstring(pri, ", ");
1687 prt_hex(pri, 0, val);
1688 return;
1691 * arrange the arguments in the order that user calls with
1693 prt_hex(pri, 0, minfo32.mi_inaddr);
1694 outstring(pri, ", ");
1695 prt_dec(pri, 0, pri->sys_args[1]); /* addr_count */
1696 outstring(pri, ", ");
1697 prt_hex(pri, 0, minfo32.mi_info_req);
1698 outstring(pri, ", ");
1699 prt_dec(pri, 0, minfo32.mi_info_count);
1700 outstring(pri, ", ");
1701 prt_hex(pri, 0, minfo32.mi_outdata);
1702 outstring(pri, ", ");
1703 prt_hex(pri, 0, minfo32.mi_validity);
1704 return;
1706 #endif
1707 if (Pread(Proc, &minfo, sizeof (struct meminfo), val) !=
1708 sizeof (struct meminfo)) {
1709 prt_dec(pri, 0, pri->sys_args[1]); /* addr_count */
1710 outstring(pri, ", ");
1711 prt_hex(pri, 0, val);
1712 return;
1715 * arrange the arguments in the order that user calls with
1717 prt_hex(pri, 0, (long)minfo.mi_inaddr);
1718 outstring(pri, ", ");
1719 prt_dec(pri, 0, pri->sys_args[1]); /* addr_count */
1720 outstring(pri, ", ");
1721 prt_hex(pri, 0, (long)minfo.mi_info_req);
1722 outstring(pri, ", ");
1723 prt_dec(pri, 0, minfo.mi_info_count);
1724 outstring(pri, ", ");
1725 prt_hex(pri, 0, (long)minfo.mi_outdata);
1726 outstring(pri, ", ");
1727 prt_hex(pri, 0, (long)minfo.mi_validity);
1732 * Print so_socket() 1st argument.
1734 /*ARGSUSED*/
1735 void
1736 prt_pfm(private_t *pri, int raw, long val)
1738 /* Protocol Families have same names as Address Families */
1739 if ((ulong_t)val < MAX_AFCODES) {
1740 outstring(pri, "PF_");
1741 outstring(pri, afcodes[val]);
1742 } else {
1743 prt_dec(pri, 0, val);
1748 * Print sockconfig() subcode.
1750 /*ARGSUSED*/
1751 void
1752 prt_skc(private_t *pri, int raw, long val)
1754 const char *s = NULL;
1756 if (!raw) {
1757 switch (val) {
1758 case SOCKCONFIG_ADD_SOCK:
1759 s = "SOCKCONFIG_ADD_SOCK"; break;
1760 case SOCKCONFIG_REMOVE_SOCK:
1761 s = "SOCKCONFIG_REMOVE_SOCK"; break;
1762 case SOCKCONFIG_ADD_FILTER:
1763 s = "SOCKCONFIG_ADD_FILTER"; break;
1764 case SOCKCONFIG_REMOVE_FILTER:
1765 s = "SOCKCONFIG_REMOVE_FILTER"; break;
1768 if (s == NULL)
1769 prt_dec(pri, 0, val);
1770 else
1771 outstring(pri, s);
1774 * Print so_socket() 2nd argument.
1776 /*ARGSUSED*/
1777 void
1778 prt_skt(private_t *pri, int raw, long val)
1780 const char *s;
1781 long type = val & SOCK_TYPE_MASK;
1783 if ((ulong_t)type <= MAX_SOCKTYPES &&
1784 (s = socktype_codes[type]) != NULL) {
1785 outstring(pri, s);
1786 if ((val & SOCK_CLOEXEC) != 0) {
1787 outstring(pri, "|SOCK_CLOEXEC");
1789 } else {
1790 prt_dec(pri, 0, val);
1796 * Print so_socket() 3rd argument.
1798 /*ARGSUSED*/
1799 void
1800 prt_skp(private_t *pri, int raw, long val)
1802 const char *s;
1804 /* cheating -- look at the protocol-family */
1805 switch (pri->sys_args[0]) {
1806 case PF_INET6:
1807 case PF_INET: if ((s = ipprotos((int)val)) != NULL) {
1808 outstring(pri, s);
1809 break;
1811 /* FALLTHROUGH */
1812 default: prt_dec(pri, 0, val);
1813 break;
1819 * Print accept4() flags argument.
1821 void
1822 prt_acf(private_t *pri, int raw, long val)
1824 int first = 1;
1825 if (raw || !val ||
1826 (val & ~(SOCK_CLOEXEC|SOCK_NDELAY|SOCK_NONBLOCK))) {
1827 prt_dex(pri, 0, val);
1828 return;
1831 if (val & SOCK_CLOEXEC) {
1832 outstring(pri, "|SOCK_CLOEXEC" + first);
1833 first = 0;
1835 if (val & SOCK_NDELAY) {
1836 outstring(pri, "|SOCK_NDELAY" + first);
1837 first = 0;
1839 if (val & SOCK_NONBLOCK) {
1840 outstring(pri, "|SOCK_NONBLOCK" + first);
1846 * Print setsockopt()/getsockopt() 2nd argument.
1848 /*ARGSUSED*/
1849 void
1850 prt_sol(private_t *pri, int raw, long val)
1852 if (val == SOL_SOCKET) {
1853 outstring(pri, "SOL_SOCKET");
1854 } else if (val == SOL_ROUTE) {
1855 outstring(pri, "SOL_ROUTE");
1856 } else {
1857 const struct protoent *p;
1858 struct protoent res;
1859 char buf[NSS_BUFLEN_PROTOCOLS];
1861 if ((p = getprotobynumber_r(val, &res,
1862 (char *)buf, sizeof (buf))) != NULL)
1863 outstring(pri, p->p_name);
1864 else
1865 prt_dec(pri, 0, val);
1870 const char *
1871 sol_optname(private_t *pri, long val)
1873 #define CBSIZE sizeof (pri->code_buf)
1874 if (val >= SO_SNDBUF) {
1875 switch (val) {
1876 case SO_SNDBUF: return ("SO_SNDBUF");
1877 case SO_RCVBUF: return ("SO_RCVBUF");
1878 case SO_SNDLOWAT: return ("SO_SNDLOWAT");
1879 case SO_RCVLOWAT: return ("SO_RCVLOWAT");
1880 case SO_SNDTIMEO: return ("SO_SNDTIMEO");
1881 case SO_RCVTIMEO: return ("SO_RCVTIMEO");
1882 case SO_ERROR: return ("SO_ERROR");
1883 case SO_TYPE: return ("SO_TYPE");
1884 case SO_PROTOTYPE: return ("SO_PROTOTYPE");
1885 case SO_ALLZONES: return ("SO_ALLZONES");
1886 case SO_VRRP: return ("SO_VRRP");
1887 case SO_EXCLBIND: return ("SO_EXCLBIND");
1888 case SO_DOMAIN: return ("SO_DOMAIN");
1890 default: (void) snprintf(pri->code_buf, CBSIZE,
1891 "0x%lx", val);
1892 return (pri->code_buf);
1894 } else {
1895 char *s = pri->code_buf;
1896 size_t used = 1;
1897 long val2;
1899 *s = '\0';
1900 val2 = val & ~(SO_DEBUG|SO_ACCEPTCONN|SO_REUSEADDR|SO_KEEPALIVE|
1901 SO_DONTROUTE|SO_BROADCAST|SO_USELOOPBACK|SO_LINGER|
1902 SO_OOBINLINE|SO_DGRAM_ERRIND|SO_RECVUCRED);
1903 if (val2)
1904 used = snprintf(s, CBSIZE, "|0x%lx", val2);
1905 if (val & SO_DEBUG)
1906 used = strlcat(s, "|SO_DEBUG", CBSIZE);
1907 if (val & SO_ACCEPTCONN)
1908 used = strlcat(s, "|SO_ACCEPTCONN", CBSIZE);
1909 if (val & SO_REUSEADDR)
1910 used = strlcat(s, "|SO_REUSEADDR", CBSIZE);
1911 if (val & SO_KEEPALIVE)
1912 used = strlcat(s, "|SO_KEEPALIVE", CBSIZE);
1913 if (val & SO_DONTROUTE)
1914 used = strlcat(s, "|SO_DONTROUTE", CBSIZE);
1915 if (val & SO_BROADCAST)
1916 used = strlcat(s, "|SO_BROADCAST", CBSIZE);
1917 if (val & SO_USELOOPBACK)
1918 used = strlcat(s, "|SO_USELOOPBACK", CBSIZE);
1919 if (val & SO_LINGER)
1920 used = strlcat(s, "|SO_LINGER", CBSIZE);
1921 if (val & SO_OOBINLINE)
1922 used = strlcat(s, "|SO_OOBINLINE", CBSIZE);
1923 if (val & SO_DGRAM_ERRIND)
1924 used = strlcat(s, "|SO_DGRAM_ERRIND", CBSIZE);
1925 if (val & SO_RECVUCRED)
1926 used = strlcat(s, "|SO_RECVUCRED", CBSIZE);
1927 if (used >= CBSIZE || val == 0)
1928 (void) snprintf(s + 1, CBSIZE-1, "0x%lx", val);
1929 return ((const char *)(s + 1));
1931 #undef CBSIZE
1934 const char *
1935 route_optname(private_t *pri, long val)
1937 switch (val) {
1938 case RT_AWARE:
1939 return ("RT_AWARE");
1940 default:
1941 (void) snprintf(pri->code_buf, sizeof (pri->code_buf),
1942 "0x%lx", val);
1943 return (pri->code_buf);
1947 const char *
1948 tcp_optname(private_t *pri, long val)
1950 switch (val) {
1951 case TCP_NODELAY: return ("TCP_NODELAY");
1952 case TCP_MAXSEG: return ("TCP_MAXSEG");
1953 case TCP_KEEPALIVE: return ("TCP_KEEPALIVE");
1954 case TCP_NOTIFY_THRESHOLD: return ("TCP_NOTIFY_THRESHOLD");
1955 case TCP_ABORT_THRESHOLD: return ("TCP_ABORT_THRESHOLD");
1956 case TCP_CONN_NOTIFY_THRESHOLD: return ("TCP_CONN_NOTIFY_THRESHOLD");
1957 case TCP_CONN_ABORT_THRESHOLD: return ("TCP_CONN_ABORT_THRESHOLD");
1958 case TCP_RECVDSTADDR: return ("TCP_RECVDSTADDR");
1959 case TCP_ANONPRIVBIND: return ("TCP_ANONPRIVBIND");
1960 case TCP_EXCLBIND: return ("TCP_EXCLBIND");
1961 case TCP_INIT_CWND: return ("TCP_INIT_CWND");
1962 case TCP_KEEPALIVE_THRESHOLD: return ("TCP_KEEPALIVE_THRESHOLD");
1963 case TCP_KEEPALIVE_ABORT_THRESHOLD:
1964 return ("TCP_KEEPALIVE_ABORT_THRESHOLD");
1965 case TCP_CORK: return ("TCP_CORK");
1966 case TCP_RTO_INITIAL: return ("TCP_RTO_INITIAL");
1967 case TCP_RTO_MIN: return ("TCP_RTO_MIN");
1968 case TCP_RTO_MAX: return ("TCP_RTO_MAX");
1969 case TCP_LINGER2: return ("TCP_LINGER2");
1970 case TCP_KEEPIDLE: return ("TCP_KEEPIDLE");
1971 case TCP_KEEPCNT: return ("TCP_KEEPCNT");
1972 case TCP_KEEPINTVL: return ("TCP_KEEPINTVL");
1974 default: (void) snprintf(pri->code_buf,
1975 sizeof (pri->code_buf),
1976 "0x%lx", val);
1977 return (pri->code_buf);
1982 const char *
1983 sctp_optname(private_t *pri, long val)
1985 switch (val) {
1986 case SCTP_RTOINFO: return ("SCTP_RTOINFO");
1987 case SCTP_ASSOCINFO: return ("SCTP_ASSOCINFO");
1988 case SCTP_INITMSG: return ("SCTP_INITMSG");
1989 case SCTP_NODELAY: return ("SCTP_NODELAY");
1990 case SCTP_AUTOCLOSE: return ("SCTP_AUTOCLOSE");
1991 case SCTP_SET_PEER_PRIMARY_ADDR:
1992 return ("SCTP_SET_PEER_PRIMARY_ADDR");
1993 case SCTP_PRIMARY_ADDR: return ("SCTP_PRIMARY_ADDR");
1994 case SCTP_ADAPTATION_LAYER: return ("SCTP_ADAPTATION_LAYER");
1995 case SCTP_DISABLE_FRAGMENTS: return ("SCTP_DISABLE_FRAGMENTS");
1996 case SCTP_PEER_ADDR_PARAMS: return ("SCTP_PEER_ADDR_PARAMS");
1997 case SCTP_DEFAULT_SEND_PARAM: return ("SCTP_DEFAULT_SEND_PARAM");
1998 case SCTP_EVENTS: return ("SCTP_EVENTS");
1999 case SCTP_I_WANT_MAPPED_V4_ADDR:
2000 return ("SCTP_I_WANT_MAPPED_V4_ADDR");
2001 case SCTP_MAXSEG: return ("SCTP_MAXSEG");
2002 case SCTP_STATUS: return ("SCTP_STATUS");
2003 case SCTP_GET_PEER_ADDR_INFO: return ("SCTP_GET_PEER_ADDR_INFO");
2005 case SCTP_ADD_ADDR: return ("SCTP_ADD_ADDR");
2006 case SCTP_REM_ADDR: return ("SCTP_REM_ADDR");
2008 default: (void) snprintf(pri->code_buf,
2009 sizeof (pri->code_buf),
2010 "0x%lx", val);
2011 return (pri->code_buf);
2016 const char *
2017 udp_optname(private_t *pri, long val)
2019 switch (val) {
2020 case UDP_CHECKSUM: return ("UDP_CHECKSUM");
2021 case UDP_ANONPRIVBIND: return ("UDP_ANONPRIVBIND");
2022 case UDP_EXCLBIND: return ("UDP_EXCLBIND");
2023 case UDP_RCVHDR: return ("UDP_RCVHDR");
2024 case UDP_NAT_T_ENDPOINT: return ("UDP_NAT_T_ENDPOINT");
2026 default: (void) snprintf(pri->code_buf,
2027 sizeof (pri->code_buf), "0x%lx",
2028 val);
2029 return (pri->code_buf);
2035 * Print setsockopt()/getsockopt() 3rd argument.
2037 /*ARGSUSED*/
2038 void
2039 prt_son(private_t *pri, int raw, long val)
2041 /* cheating -- look at the level */
2042 switch (pri->sys_args[1]) {
2043 case SOL_SOCKET: outstring(pri, sol_optname(pri, val));
2044 break;
2045 case SOL_ROUTE: outstring(pri, route_optname(pri, val));
2046 break;
2047 case IPPROTO_TCP: outstring(pri, tcp_optname(pri, val));
2048 break;
2049 case IPPROTO_UDP: outstring(pri, udp_optname(pri, val));
2050 break;
2051 case IPPROTO_SCTP: outstring(pri, sctp_optname(pri, val));
2052 break;
2053 default: prt_dec(pri, 0, val);
2054 break;
2060 * Print utrap type
2062 /*ARGSUSED*/
2063 void
2064 prt_utt(private_t *pri, int raw, long val)
2066 const char *s = NULL;
2069 if (s == NULL)
2070 prt_dec(pri, 0, val);
2071 else
2072 outstring(pri, s);
2077 * Print utrap handler
2079 void
2080 prt_uth(private_t *pri, int raw, long val)
2082 const char *s = NULL;
2084 if (!raw) {
2085 switch (val) {
2086 case (long)UTH_NOCHANGE: s = "UTH_NOCHANGE"; break;
2090 if (s == NULL)
2091 prt_hex(pri, 0, val);
2092 else
2093 outstring(pri, s);
2096 const char *
2097 access_flags(private_t *pri, long arg)
2099 #define E_OK 010
2100 char *str = pri->code_buf;
2102 if (arg & ~(R_OK|W_OK|X_OK|E_OK))
2103 return (NULL);
2105 /* NB: F_OK == 0 */
2106 if (arg == F_OK)
2107 return ("F_OK");
2108 if (arg == E_OK)
2109 return ("F_OK|E_OK");
2111 *str = '\0';
2112 if (arg & R_OK)
2113 (void) strlcat(str, "|R_OK", sizeof (pri->code_buf));
2114 if (arg & W_OK)
2115 (void) strlcat(str, "|W_OK", sizeof (pri->code_buf));
2116 if (arg & X_OK)
2117 (void) strlcat(str, "|X_OK", sizeof (pri->code_buf));
2118 if (arg & E_OK)
2119 (void) strlcat(str, "|E_OK", sizeof (pri->code_buf));
2120 return ((const char *)(str + 1));
2121 #undef E_OK
2125 * Print access() flags.
2127 void
2128 prt_acc(private_t *pri, int raw, long val)
2130 const char *s = raw? NULL : access_flags(pri, val);
2132 if (s == NULL)
2133 prt_dex(pri, 0, val);
2134 else
2135 outstring(pri, s);
2139 * Print shutdown() "how" (2nd) argument
2141 void
2142 prt_sht(private_t *pri, int raw, long val)
2144 if (raw) {
2145 prt_dex(pri, 0, val);
2146 return;
2148 switch (val) {
2149 case SHUT_RD: outstring(pri, "SHUT_RD"); break;
2150 case SHUT_WR: outstring(pri, "SHUT_WR"); break;
2151 case SHUT_RDWR: outstring(pri, "SHUT_RDWR"); break;
2152 default: prt_dec(pri, 0, val); break;
2157 * Print fcntl() F_SETFL flags (3rd) argument or fdsync flag (2nd arg)
2159 static struct fcntl_flags {
2160 long val;
2161 const char *name;
2162 } fcntl_flags[] = {
2163 #define FC_FL(flag) { (long)flag, "|" # flag }
2164 FC_FL(FREVOKED),
2165 FC_FL(FREAD),
2166 FC_FL(FWRITE),
2167 FC_FL(FNDELAY),
2168 FC_FL(FAPPEND),
2169 FC_FL(FSYNC),
2170 FC_FL(FDSYNC),
2171 FC_FL(FRSYNC),
2172 FC_FL(FOFFMAX),
2173 FC_FL(FNONBLOCK),
2174 FC_FL(FCREAT),
2175 FC_FL(FTRUNC),
2176 FC_FL(FEXCL),
2177 FC_FL(FNOCTTY),
2178 FC_FL(FXATTR),
2179 FC_FL(FASYNC),
2180 FC_FL(FNODSYNC)
2181 #undef FC_FL
2184 void
2185 prt_ffg(private_t *pri, int raw, long val)
2187 #define CBSIZE sizeof (pri->code_buf)
2188 char *s = pri->code_buf;
2189 size_t used = 1;
2190 struct fcntl_flags *fp;
2192 if (raw) {
2193 (void) snprintf(s, CBSIZE, "0x%lx", val);
2194 outstring(pri, s);
2195 return;
2197 if (val == 0) {
2198 outstring(pri, "(no flags)");
2199 return;
2202 *s = '\0';
2203 for (fp = fcntl_flags;
2204 fp < &fcntl_flags[sizeof (fcntl_flags) / sizeof (*fp)]; fp++) {
2205 if (val & fp->val) {
2206 used = strlcat(s, fp->name, CBSIZE);
2207 val &= ~fp->val;
2211 if (val != 0 && used <= CBSIZE)
2212 used += snprintf(s + used, CBSIZE - used, "|0x%lx", val);
2214 if (used >= CBSIZE)
2215 (void) snprintf(s + 1, CBSIZE-1, "0x%lx", val);
2216 outstring(pri, s + 1);
2217 #undef CBSIZE
2220 void
2221 prt_prs(private_t *pri, int raw, long val)
2223 static size_t setsize;
2224 priv_set_t *set = priv_allocset();
2226 if (setsize == 0) {
2227 const priv_impl_info_t *info = getprivimplinfo();
2228 if (info != NULL)
2229 setsize = info->priv_setsize * sizeof (priv_chunk_t);
2232 if (setsize != 0 && !raw && set != NULL &&
2233 Pread(Proc, set, setsize, val) == setsize) {
2234 int i;
2236 outstring(pri, "{");
2237 for (i = 0; i < setsize / sizeof (priv_chunk_t); i++) {
2238 char buf[9]; /* 8 hex digits + '\0' */
2239 (void) snprintf(buf, sizeof (buf), "%08x",
2240 ((priv_chunk_t *)set)[i]);
2241 outstring(pri, buf);
2244 outstring(pri, "}");
2245 } else {
2246 prt_hex(pri, 0, val);
2249 if (set != NULL)
2250 priv_freeset(set);
2254 * Print privilege set operation.
2256 void
2257 prt_pro(private_t *pri, int raw, long val)
2259 const char *s = NULL;
2261 if (!raw) {
2262 switch ((priv_op_t)val) {
2263 case PRIV_ON: s = "PRIV_ON"; break;
2264 case PRIV_OFF: s = "PRIV_OFF"; break;
2265 case PRIV_SET: s = "PRIV_SET"; break;
2269 if (s == NULL)
2270 prt_dec(pri, 0, val);
2271 else
2272 outstring(pri, s);
2276 * Print privilege set name
2278 void
2279 prt_prn(private_t *pri, int raw, long val)
2281 const char *s = NULL;
2283 if (!raw)
2284 s = priv_getsetbynum((int)val);
2286 if (s == NULL)
2287 prt_dec(pri, 0, val);
2288 else {
2289 char *dup = strdup(s);
2290 char *q;
2292 /* Do the best we can in this case */
2293 if (dup == NULL) {
2294 outstring(pri, s);
2295 return;
2298 outstring(pri, "PRIV_");
2300 q = dup;
2302 while (*q != '\0') {
2303 *q = toupper(*q);
2304 q++;
2306 outstring(pri, dup);
2307 free(dup);
2312 * Print process flag names.
2314 void
2315 prt_pfl(private_t *pri, int raw, long val)
2317 const char *s = NULL;
2319 if (!raw) {
2320 switch ((int)val) {
2321 case PRIV_DEBUG: s = "PRIV_DEBUG"; break;
2322 case PRIV_AWARE: s = "PRIV_AWARE"; break;
2323 case PRIV_XPOLICY: s = "PRIV_XPOLICY"; break;
2324 case PRIV_AWARE_RESET: s = "PRIV_AWARE_RESET"; break;
2325 case PRIV_PFEXEC: s = "PRIV_PFEXEC"; break;
2329 if (s == NULL)
2330 prt_dec(pri, 0, val);
2331 else
2332 outstring(pri, s);
2336 * Print lgrp_affinity_{get,set}() arguments.
2338 /*ARGSUSED*/
2339 void
2340 prt_laf(private_t *pri, int raw, long val)
2342 lgrp_affinity_args_t laff;
2344 if (Pread(Proc, &laff, sizeof (lgrp_affinity_args_t), val) !=
2345 sizeof (lgrp_affinity_args_t)) {
2346 prt_hex(pri, 0, val);
2347 return;
2350 * arrange the arguments in the order that user calls with
2352 prt_dec(pri, 0, laff.idtype);
2353 outstring(pri, ", ");
2354 prt_dec(pri, 0, laff.id);
2355 outstring(pri, ", ");
2356 prt_dec(pri, 0, laff.lgrp);
2357 outstring(pri, ", ");
2358 if (pri->sys_args[0] == LGRP_SYS_AFFINITY_SET)
2359 prt_dec(pri, 0, laff.aff);
2363 * Print a key_t as IPC_PRIVATE if it is 0.
2365 void
2366 prt_key(private_t *pri, int raw, long val)
2368 if (!raw && val == 0)
2369 outstring(pri, "IPC_PRIVATE");
2370 else
2371 prt_dec(pri, 0, val);
2376 * Print zone_getattr() attribute types.
2378 void
2379 prt_zga(private_t *pri, int raw, long val)
2381 const char *s = NULL;
2383 if (!raw) {
2384 switch ((int)val) {
2385 case ZONE_ATTR_NAME: s = "ZONE_ATTR_NAME"; break;
2386 case ZONE_ATTR_ROOT: s = "ZONE_ATTR_ROOT"; break;
2387 case ZONE_ATTR_STATUS: s = "ZONE_ATTR_STATUS"; break;
2388 case ZONE_ATTR_PRIVSET: s = "ZONE_ATTR_PRIVSET"; break;
2389 case ZONE_ATTR_UNIQID: s = "ZONE_ATTR_UNIQID"; break;
2390 case ZONE_ATTR_POOLID: s = "ZONE_ATTR_POOLID"; break;
2391 case ZONE_ATTR_INITPID: s = "ZONE_ATTR_INITPID"; break;
2392 case ZONE_ATTR_INITNAME: s = "ZONE_ATTR_INITNAME"; break;
2393 case ZONE_ATTR_BOOTARGS: s = "ZONE_ATTR_BOOTARGS"; break;
2394 case ZONE_ATTR_BRAND: s = "ZONE_ATTR_BRAND"; break;
2395 case ZONE_ATTR_FLAGS: s = "ZONE_ATTR_FLAGS"; break;
2396 case ZONE_ATTR_PHYS_MCAP: s = "ZONE_ATTR_PHYS_MCAP"; break;
2400 if (s == NULL)
2401 prt_dec(pri, 0, val);
2402 else
2403 outstring(pri, s);
2407 * Print a file descriptor as AT_FDCWD if necessary
2409 void
2410 prt_atc(private_t *pri, int raw, long val)
2412 if ((int)val == AT_FDCWD) {
2413 if (raw)
2414 prt_hex(pri, 0, (uint_t)AT_FDCWD);
2415 else
2416 outstring(pri, "AT_FDCWD");
2417 } else {
2418 prt_dec(pri, 0, val);
2423 * Print LIO_XX flags
2425 void
2426 prt_lio(private_t *pri, int raw, long val)
2428 if (raw)
2429 prt_dec(pri, 0, val);
2430 else if (val == LIO_WAIT)
2431 outstring(pri, "LIO_WAIT");
2432 else if (val == LIO_NOWAIT)
2433 outstring(pri, "LIO_NOWAIT");
2434 else
2435 prt_dec(pri, 0, val);
2438 const char *
2439 door_flags(private_t *pri, long val)
2441 door_attr_t attr = (door_attr_t)val;
2442 char *str = pri->code_buf;
2444 *str = '\0';
2445 #define PROCESS_FLAG(flg) \
2446 if (attr & flg) { \
2447 (void) strlcat(str, "|" #flg, sizeof (pri->code_buf)); \
2448 attr &= ~flg; \
2451 PROCESS_FLAG(DOOR_UNREF);
2452 PROCESS_FLAG(DOOR_UNREF_MULTI);
2453 PROCESS_FLAG(DOOR_PRIVATE);
2454 PROCESS_FLAG(DOOR_REFUSE_DESC);
2455 PROCESS_FLAG(DOOR_NO_CANCEL);
2456 PROCESS_FLAG(DOOR_LOCAL);
2457 PROCESS_FLAG(DOOR_REVOKED);
2458 PROCESS_FLAG(DOOR_IS_UNREF);
2459 #undef PROCESS_FLAG
2461 if (attr != 0 || *str == '\0') {
2462 size_t len = strlen(str);
2463 (void) snprintf(str + len, sizeof (pri->code_buf) - len,
2464 "|0x%X", attr);
2467 return (str + 1);
2471 * Print door_create() flags
2473 void
2474 prt_dfl(private_t *pri, int raw, long val)
2476 if (raw)
2477 prt_hex(pri, 0, val);
2478 else
2479 outstring(pri, door_flags(pri, val));
2483 * Print door_*param() param argument
2485 void
2486 prt_dpm(private_t *pri, int raw, long val)
2488 if (raw)
2489 prt_hex(pri, 0, val);
2490 else if (val == DOOR_PARAM_DESC_MAX)
2491 outstring(pri, "DOOR_PARAM_DESC_MAX");
2492 else if (val == DOOR_PARAM_DATA_MIN)
2493 outstring(pri, "DOOR_PARAM_DATA_MIN");
2494 else if (val == DOOR_PARAM_DATA_MAX)
2495 outstring(pri, "DOOR_PARAM_DATA_MAX");
2496 else
2497 prt_hex(pri, 0, val);
2501 * Print rctlsys subcodes
2503 void
2504 prt_rsc(private_t *pri, int raw, long val) /* print utssys code */
2506 const char *s = raw? NULL : rctlsyscode(val);
2508 if (s == NULL)
2509 prt_dec(pri, 0, val);
2510 else
2511 outstring(pri, s);
2515 * Print getrctl flags
2517 void
2518 prt_rgf(private_t *pri, int raw, long val)
2520 long action = val & (~RCTLSYS_ACTION_MASK);
2522 if (raw)
2523 prt_hex(pri, 0, val);
2524 else if (action == RCTL_FIRST)
2525 outstring(pri, "RCTL_FIRST");
2526 else if (action == RCTL_NEXT)
2527 outstring(pri, "RCTL_NEXT");
2528 else if (action == RCTL_USAGE)
2529 outstring(pri, "RCTL_USAGE");
2530 else
2531 prt_hex(pri, 0, val);
2535 * Print setrctl flags
2537 void
2538 prt_rsf(private_t *pri, int raw, long val)
2540 long action = val & (~RCTLSYS_ACTION_MASK);
2541 long pval = val & RCTL_LOCAL_ACTION_MASK;
2542 char *s = pri->code_buf;
2544 if (raw) {
2545 prt_hex(pri, 0, val);
2546 return;
2547 } else if (action == RCTL_INSERT)
2548 (void) strcpy(s, "RCTL_INSERT");
2549 else if (action == RCTL_DELETE)
2550 (void) strcpy(s, "RCTL_DELETE");
2551 else if (action == RCTL_REPLACE)
2552 (void) strcpy(s, "RCTL_REPLACE");
2553 else {
2554 prt_hex(pri, 0, val);
2555 return;
2558 if (pval & RCTL_USE_RECIPIENT_PID) {
2559 pval ^= RCTL_USE_RECIPIENT_PID;
2560 (void) strlcat(s, "|RCTL_USE_RECIPIENT_PID",
2561 sizeof (pri->code_buf));
2564 if ((pval & RCTLSYS_ACTION_MASK) != 0)
2565 prt_hex(pri, 0, val);
2566 else if (*s != '\0')
2567 outstring(pri, s);
2568 else
2569 prt_hex(pri, 0, val);
2573 * Print rctlctl flags
2575 void
2576 prt_rcf(private_t *pri, int raw, long val)
2578 long action = val & (~RCTLSYS_ACTION_MASK);
2580 if (raw)
2581 prt_hex(pri, 0, val);
2582 else if (action == RCTLCTL_GET)
2583 outstring(pri, "RCTLCTL_GET");
2584 else if (action == RCTLCTL_SET)
2585 outstring(pri, "RCTLCTL_SET");
2586 else
2587 prt_hex(pri, 0, val);
2591 * Print setprojrctl flags
2593 void
2594 prt_spf(private_t *pri, int raw, long val)
2596 long action = val & TASK_PROJ_MASK;
2598 if (!raw && (action == TASK_PROJ_PURGE))
2599 outstring(pri, "TASK_PROJ_PURGE");
2600 else
2601 prt_hex(pri, 0, val);
2605 * Print forkx() flags
2607 void
2608 prt_fxf(private_t *pri, int raw, long val)
2610 char *str;
2612 if (val == 0)
2613 outstring(pri, "0");
2614 else if (raw || (val & ~(FORK_NOSIGCHLD | FORK_WAITPID)))
2615 prt_hhx(pri, 0, val);
2616 else {
2617 str = pri->code_buf;
2618 *str = '\0';
2619 if (val & FORK_NOSIGCHLD)
2620 (void) strlcat(str, "|FORK_NOSIGCHLD",
2621 sizeof (pri->code_buf));
2622 if (val & FORK_WAITPID)
2623 (void) strlcat(str, "|FORK_WAITPID",
2624 sizeof (pri->code_buf));
2625 outstring(pri, str + 1);
2630 * Print faccessat() flag
2632 void
2633 prt_fat(private_t *pri, int raw, long val)
2635 if (val == 0)
2636 outstring(pri, "0");
2637 else if (!raw && val == AT_EACCESS)
2638 outstring(pri, "AT_EACCESS");
2639 else
2640 prt_hex(pri, 0, val);
2644 * Print unlinkat() flag
2646 void
2647 prt_uat(private_t *pri, int raw, long val)
2649 if (val == 0)
2650 outstring(pri, "0");
2651 else if (!raw && val == AT_REMOVEDIR)
2652 outstring(pri, "AT_REMOVEDIR");
2653 else
2654 prt_hex(pri, 0, val);
2658 * Print AT_SYMLINK_NOFOLLOW / AT_SYMLINK_FOLLOW flag
2660 void
2661 prt_snf(private_t *pri, int raw, long val)
2663 if (val == 0)
2664 outstring(pri, "0");
2665 else if (!raw && val == AT_SYMLINK_NOFOLLOW)
2666 outstring(pri, "AT_SYMLINK_NOFOLLOW");
2667 else if (!raw && val == AT_SYMLINK_FOLLOW)
2668 outstring(pri, "AT_SYMLINK_FOLLOW");
2669 else
2670 prt_hex(pri, 0, val);
2673 void
2674 prt_grf(private_t *pri, int raw, long val)
2676 int first = 1;
2678 if (raw != 0 || val == 0 ||
2679 (val & ~(GRND_NONBLOCK | GRND_RANDOM)) != 0) {
2680 outstring(pri, "0");
2681 return;
2684 if (val & GRND_NONBLOCK) {
2685 outstring(pri, "|GRND_NONBLOCK" + first);
2686 first = 0;
2688 if (val & GRND_RANDOM) {
2689 outstring(pri, "|GRND_RANDOM" + first);
2690 first = 0;
2695 * Array of pointers to print functions, one for each format.
2697 void (* const Print[])() = {
2698 prt_nov, /* NOV -- no value */
2699 prt_dec, /* DEC -- print value in decimal */
2700 prt_oct, /* OCT -- print value in octal */
2701 prt_hex, /* HEX -- print value in hexadecimal */
2702 prt_dex, /* DEX -- print value in hexadecimal if big enough */
2703 prt_stg, /* STG -- print value as string */
2704 prt_ioc, /* IOC -- print ioctl code */
2705 prt_fcn, /* FCN -- print fcntl code */
2706 prt_s86, /* S86 -- print sysi86 code */
2707 prt_uts, /* UTS -- print utssys code */
2708 prt_opn, /* OPN -- print open code */
2709 prt_sig, /* SIG -- print signal name plus flags */
2710 prt_uat, /* UAT -- print unlinkat() flag */
2711 prt_msc, /* MSC -- print msgsys command */
2712 prt_msf, /* MSF -- print msgsys flags */
2713 prt_smc, /* SMC -- print semsys command */
2714 prt_sef, /* SEF -- print semsys flags */
2715 prt_shc, /* SHC -- print shmsys command */
2716 prt_shf, /* SHF -- print shmsys flags */
2717 prt_fat, /* FAT -- print faccessat( flag */
2718 prt_sfs, /* SFS -- print sysfs code */
2719 prt_rst, /* RST -- print string returned by syscall */
2720 prt_smf, /* SMF -- print streams message flags */
2721 prt_ioa, /* IOA -- print ioctl argument */
2722 prt_pip, /* PIP -- print pipe flags */
2723 prt_mtf, /* MTF -- print mount flags */
2724 prt_mft, /* MFT -- print mount file system type */
2725 prt_iob, /* IOB -- print contents of I/O buffer */
2726 prt_hhx, /* HHX -- print value in hexadecimal (half size) */
2727 prt_wop, /* WOP -- print waitsys() options */
2728 prt_spm, /* SPM -- print sigprocmask argument */
2729 prt_rlk, /* RLK -- print readlink buffer */
2730 prt_mpr, /* MPR -- print mmap()/mprotect() flags */
2731 prt_mty, /* MTY -- print mmap() mapping type flags */
2732 prt_mcf, /* MCF -- print memcntl() function */
2733 prt_mc4, /* MC4 -- print memcntl() (fourth) argument */
2734 prt_mc5, /* MC5 -- print memcntl() (fifth) argument */
2735 prt_mad, /* MAD -- print madvise() argument */
2736 prt_ulm, /* ULM -- print ulimit() argument */
2737 prt_rlm, /* RLM -- print get/setrlimit() argument */
2738 prt_cnf, /* CNF -- print sysconfig() argument */
2739 prt_inf, /* INF -- print sysinfo() argument */
2740 prt_ptc, /* PTC -- print pathconf/fpathconf() argument */
2741 prt_fui, /* FUI -- print fusers() input argument */
2742 prt_idt, /* IDT -- print idtype_t, waitid() argument */
2743 prt_lwf, /* LWF -- print lwp_create() flags */
2744 prt_itm, /* ITM -- print [get|set]itimer() arg */
2745 prt_llo, /* LLO -- print long long offset arg */
2746 prt_mod, /* MOD -- print modctl() subcode */
2747 prt_whn, /* WHN -- print lseek() whence arguiment */
2748 prt_acl, /* ACL -- print acl() code */
2749 prt_aio, /* AIO -- print kaio() code */
2750 prt_aud, /* AUD -- print auditsys() code */
2751 prt_uns, /* DEC -- print value in unsigned decimal */
2752 prt_cor, /* COR -- print corectl() subcode */
2753 prt_cco, /* CCO -- print corectl() options */
2754 prt_ccc, /* CCC -- print corectl() content */
2755 prt_rcc, /* RCC -- print corectl() returned content */
2756 prt_cpc, /* CPC -- print cpc() subcode */
2757 prt_sqc, /* SQC -- print sigqueue() si_code argument */
2758 prt_pc4, /* PC4 -- print priocntlsys() (fourth) argument */
2759 prt_pc5, /* PC5 -- print priocntlsys() (key, value) pairs */
2760 prt_pst, /* PST -- print processor set id */
2761 prt_mif, /* MIF -- print meminfo() arguments */
2762 prt_pfm, /* PFM -- print so_socket() proto-family (1st) arg */
2763 prt_skt, /* SKT -- print so_socket() socket-type (2nd) arg */
2764 prt_skp, /* SKP -- print so_socket() protocol (3rd) arg */
2765 prt_sol, /* SOL -- print [sg]etsockopt() level (2nd) arg */
2766 prt_son, /* SON -- print [sg]etsockopt() opt-name (3rd) arg */
2767 prt_utt, /* UTT -- print utrap type */
2768 prt_uth, /* UTH -- print utrap handler */
2769 prt_acc, /* ACC -- print access() flags */
2770 prt_sht, /* SHT -- print shutdown() how (2nd) argument */
2771 prt_ffg, /* FFG -- print fcntl() flags (3rd) argument */
2772 prt_prs, /* PRS -- print privilege set */
2773 prt_pro, /* PRO -- print privilege set operation */
2774 prt_prn, /* PRN -- print privilege set name */
2775 prt_pfl, /* PFL -- print privilege/process flag name */
2776 prt_laf, /* LAF -- print lgrp_affinity arguments */
2777 prt_key, /* KEY -- print key_t 0 as IPC_PRIVATE */
2778 prt_zga, /* ZGA -- print zone_getattr attribute types */
2779 prt_atc, /* ATC -- print AT_FDCWD or file descriptor */
2780 prt_lio, /* LIO -- print LIO_XX flags */
2781 prt_dfl, /* DFL -- print door_create() flags */
2782 prt_dpm, /* DPM -- print DOOR_PARAM_XX flags */
2783 prt_rsc, /* RSC -- print rctlsys() subcodes */
2784 prt_rgf, /* RGF -- print getrctl() flags */
2785 prt_rsf, /* RSF -- print setrctl() flags */
2786 prt_rcf, /* RCF -- print rctlsys_ctl() flags */
2787 prt_fxf, /* FXF -- print forkx() flags */
2788 prt_spf, /* SPF -- print rctlsys_projset() flags */
2789 prt_un1, /* UN1 -- as prt_uns except for -1 */
2790 prt_mob, /* MOB -- print mmapobj() flags */
2791 prt_snf, /* SNF -- print AT_SYMLINK_[NO]FOLLOW flag */
2792 prt_skc, /* SKC -- print sockconfig() subcode */
2793 prt_acf, /* ACF -- print accept4 flags */
2794 prt_pfd, /* PFD -- print pipe fds */
2795 prt_grf, /* GRF -- print getrandom flags */
2796 prt_psdelta, /* PSDLT -- print psecflags(2) delta */
2797 prt_psfw, /* PSFW -- print psecflags(2) set */
2798 prt_dec, /* HID -- hidden argument, make this the last one */