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