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 2012 Nexenta Systems, Inc. All rights reserved. 24 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 25 * Copyright (c) 2012, 2014 by Delphix. All rights reserved. 26 * Copyright 2015 Joyent, Inc. 27 */ 28 29 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 30 /* All Rights Reserved */ 31 32 #define _SYSCALL32 33 34 #include <stdio.h> 35 #include <stdlib.h> 36 #include <unistd.h> 37 #include <ctype.h> 38 #include <sys/types.h> 39 #include <sys/mman.h> 40 #include <libproc.h> 41 #include <string.h> 42 #include <limits.h> 43 #include <sys/statfs.h> 44 #include <sys/times.h> 45 #include <sys/timex.h> 46 #include <sys/utssys.h> 47 #include <sys/utsname.h> 48 #include <sys/ipc.h> 49 #include <sys/ipc_impl.h> 50 #include <sys/msg.h> 51 #include <sys/msg_impl.h> 52 #include <sys/sem.h> 53 #include <sys/sem_impl.h> 54 #include <sys/shm.h> 55 #include <sys/shm_impl.h> 56 #include <sys/dirent.h> 57 #include <ustat.h> 58 #include <fcntl.h> 59 #include <time.h> 60 #include <sys/termios.h> 61 #include <sys/termiox.h> 62 #include <sys/termio.h> 63 #include <sys/ttold.h> 64 #include <sys/jioctl.h> 65 #include <sys/filio.h> 66 #include <stropts.h> 67 #include <poll.h> 68 #include <sys/uio.h> 69 #include <sys/resource.h> 70 #include <sys/statvfs.h> 71 #include <sys/time.h> 72 #include <sys/aio.h> 73 #include <sys/socket.h> 74 #include <netinet/in.h> 75 #include <sys/un.h> 76 #include <sys/byteorder.h> 77 #include <arpa/inet.h> 78 #include <sys/audioio.h> 79 #include <sys/cladm.h> 80 #include <sys/synch.h> 81 #include <sys/synch32.h> 82 #include <sys/sysmacros.h> 83 #include <sys/sendfile.h> 84 #include <priv.h> 85 #include <ucred.h> 86 #include <sys/ucred.h> 87 #include <sys/port_impl.h> 88 #include <sys/zone.h> 89 #include <sys/priv_impl.h> 90 #include <sys/priv.h> 91 #include <tsol/label.h> 92 #include <sys/nvpair.h> 93 #include <libnvpair.h> 94 #include <sys/rctl_impl.h> 95 #include <sys/socketvar.h> 96 #include <sys/fs/zfs.h> 97 #include <sys/zfs_ioctl.h> 98 99 #include "ramdata.h" 100 #include "systable.h" 101 #include "proto.h" 102 103 void show_sigset(private_t *, long, const char *); 104 void show_ioctl(private_t *, int, long); 105 void show_zfs_ioc(private_t *, long); 106 107 static void 108 mk_ctime(char *str, size_t maxsize, time_t value) 109 { 110 (void) strftime(str, maxsize, "%b %e %H:%M:%S %Z %Y", 111 localtime(&value)); 112 } 113 114 void 115 prtime(private_t *pri, const char *name, time_t value) 116 { 117 char str[80]; 118 119 mk_ctime(str, sizeof (str), value); 120 (void) printf("%s\t%s%s [ %lu ]\n", 121 pri->pname, 122 name, 123 str, 124 value); 125 } 126 127 void 128 prtimeval(private_t *pri, const char *name, struct timeval *value) 129 { 130 char str[80]; 131 132 mk_ctime(str, sizeof (str), value->tv_sec); 133 (void) printf("%s\t%s%s [ %lu.%6.6lu ]\n", 134 pri->pname, 135 name, 136 str, 137 value->tv_sec, 138 value->tv_usec); 139 } 140 141 void 142 prtimestruc(private_t *pri, const char *name, timestruc_t *value) 143 { 144 char str[80]; 145 146 mk_ctime(str, sizeof (str), value->tv_sec); 147 (void) printf("%s\t%s%s [ %lu.%9.9lu ]\n", 148 pri->pname, 149 name, 150 str, 151 value->tv_sec, 152 value->tv_nsec); 153 } 154 155 static void 156 show_utimens(private_t *pri, long offset) 157 { 158 struct { 159 timespec_t atime; 160 timespec_t mtime; 161 } utimbuf; 162 163 if (offset == 0) 164 return; 165 166 if (data_model == PR_MODEL_NATIVE) { 167 if (Pread(Proc, &utimbuf, sizeof (utimbuf), offset) 168 != sizeof (utimbuf)) 169 return; 170 } else { 171 struct { 172 timespec32_t atime; 173 timespec32_t mtime; 174 } utimbuf32; 175 176 if (Pread(Proc, &utimbuf32, sizeof (utimbuf32), offset) 177 != sizeof (utimbuf32)) 178 return; 179 180 TIMESPEC32_TO_TIMESPEC(&utimbuf.atime, &utimbuf32.atime); 181 TIMESPEC32_TO_TIMESPEC(&utimbuf.mtime, &utimbuf32.mtime); 182 } 183 184 /* print access and modification times */ 185 if (utimbuf.atime.tv_nsec == UTIME_OMIT) 186 (void) printf("%s\tat = UTIME_OMIT\n", pri->pname); 187 else if (utimbuf.atime.tv_nsec == UTIME_NOW) 188 (void) printf("%s\tat = UTIME_NOW\n", pri->pname); 189 else 190 prtimestruc(pri, "at = ", &utimbuf.atime); 191 if (utimbuf.mtime.tv_nsec == UTIME_OMIT) 192 (void) printf("%s\tmt = UTIME_OMIT\n", pri->pname); 193 else if (utimbuf.mtime.tv_nsec == UTIME_NOW) 194 (void) printf("%s\tmt = UTIME_NOW\n", pri->pname); 195 else 196 prtimestruc(pri, "mt = ", &utimbuf.mtime); 197 } 198 199 void 200 show_timeofday(private_t *pri) 201 { 202 struct timeval tod; 203 long offset; 204 205 if (pri->sys_nargs < 1 || (offset = pri->sys_args[0]) == 0) 206 return; 207 208 if (data_model == PR_MODEL_NATIVE) { 209 if (Pread(Proc, &tod, sizeof (tod), offset) 210 != sizeof (tod)) 211 return; 212 } else { 213 struct timeval32 tod32; 214 215 if (Pread(Proc, &tod32, sizeof (tod32), offset) 216 != sizeof (tod32)) 217 return; 218 219 TIMEVAL32_TO_TIMEVAL(&tod, &tod32); 220 } 221 222 prtimeval(pri, "time: ", &tod); 223 } 224 225 void 226 show_itimerval(private_t *pri, long offset, const char *name) 227 { 228 struct itimerval itimerval; 229 230 if (offset == 0) 231 return; 232 233 if (data_model == PR_MODEL_NATIVE) { 234 if (Pread(Proc, &itimerval, sizeof (itimerval), offset) 235 != sizeof (itimerval)) 236 return; 237 } else { 238 struct itimerval32 itimerval32; 239 240 if (Pread(Proc, &itimerval32, sizeof (itimerval32), offset) 241 != sizeof (itimerval32)) 242 return; 243 244 ITIMERVAL32_TO_ITIMERVAL(&itimerval, &itimerval32); 245 } 246 247 (void) printf( 248 "%s\t%s: interval: %4ld.%6.6ld sec value: %4ld.%6.6ld sec\n", 249 pri->pname, 250 name, 251 itimerval.it_interval.tv_sec, 252 itimerval.it_interval.tv_usec, 253 itimerval.it_value.tv_sec, 254 itimerval.it_value.tv_usec); 255 } 256 257 void 258 show_timeval(private_t *pri, long offset, const char *name) 259 { 260 struct timeval timeval; 261 262 if (offset == 0) 263 return; 264 265 if (data_model == PR_MODEL_NATIVE) { 266 if (Pread(Proc, &timeval, sizeof (timeval), offset) 267 != sizeof (timeval)) 268 return; 269 } else { 270 struct timeval32 timeval32; 271 272 if (Pread(Proc, &timeval32, sizeof (timeval32), offset) 273 != sizeof (timeval32)) 274 return; 275 276 TIMEVAL32_TO_TIMEVAL(&timeval, &timeval32); 277 } 278 279 (void) printf( 280 "%s\t%s: %ld.%6.6ld sec\n", 281 pri->pname, 282 name, 283 timeval.tv_sec, 284 timeval.tv_usec); 285 } 286 287 void 288 show_timestruc(private_t *pri, long offset, const char *name) 289 { 290 timestruc_t timestruc; 291 292 if (offset == 0) 293 return; 294 295 if (data_model == PR_MODEL_NATIVE) { 296 if (Pread(Proc, ×truc, sizeof (timestruc), offset) 297 != sizeof (timestruc)) 298 return; 299 } else { 300 timestruc32_t timestruc32; 301 302 if (Pread(Proc, ×truc32, sizeof (timestruc32), offset) 303 != sizeof (timestruc32)) 304 return; 305 306 TIMESPEC32_TO_TIMESPEC(×truc, ×truc32); 307 } 308 309 (void) printf( 310 "%s\t%s: %ld.%9.9ld sec\n", 311 pri->pname, 312 name, 313 timestruc.tv_sec, 314 timestruc.tv_nsec); 315 } 316 317 void 318 show_stime(private_t *pri) 319 { 320 if (pri->sys_nargs >= 1) { 321 /* print new system time */ 322 prtime(pri, "systime = ", (time_t)pri->sys_args[0]); 323 } 324 } 325 326 void 327 show_times(private_t *pri) 328 { 329 long hz = sysconf(_SC_CLK_TCK); 330 long offset; 331 struct tms tms; 332 333 if (pri->sys_nargs < 1 || (offset = pri->sys_args[0]) == 0) 334 return; 335 336 if (data_model == PR_MODEL_NATIVE) { 337 if (Pread(Proc, &tms, sizeof (tms), offset) 338 != sizeof (tms)) 339 return; 340 } else { 341 struct tms32 tms32; 342 343 if (Pread(Proc, &tms32, sizeof (tms32), offset) 344 != sizeof (tms32)) 345 return; 346 347 /* 348 * This looks a bit odd (since the values are actually 349 * signed), but we need to suppress sign extension to 350 * preserve compatibility (we've always printed these 351 * numbers as unsigned quantities). 352 */ 353 tms.tms_utime = (unsigned)tms32.tms_utime; 354 tms.tms_stime = (unsigned)tms32.tms_stime; 355 tms.tms_cutime = (unsigned)tms32.tms_cutime; 356 tms.tms_cstime = (unsigned)tms32.tms_cstime; 357 } 358 359 (void) printf( 360 "%s\tutim=%-6lu stim=%-6lu cutim=%-6lu cstim=%-6lu (HZ=%ld)\n", 361 pri->pname, 362 tms.tms_utime, 363 tms.tms_stime, 364 tms.tms_cutime, 365 tms.tms_cstime, 366 hz); 367 } 368 369 void 370 show_uname(private_t *pri, long offset) 371 { 372 /* 373 * Old utsname buffer (no longer accessible in <sys/utsname.h>). 374 */ 375 struct { 376 char sysname[9]; 377 char nodename[9]; 378 char release[9]; 379 char version[9]; 380 char machine[9]; 381 } ubuf; 382 383 if (offset != 0 && 384 Pread(Proc, &ubuf, sizeof (ubuf), offset) == sizeof (ubuf)) { 385 (void) printf( 386 "%s\tsys=%-9.9snod=%-9.9srel=%-9.9sver=%-9.9smch=%.9s\n", 387 pri->pname, 388 ubuf.sysname, 389 ubuf.nodename, 390 ubuf.release, 391 ubuf.version, 392 ubuf.machine); 393 } 394 } 395 396 /* XX64 -- definition of 'struct ustat' is strange -- check out the defn */ 397 void 398 show_ustat(private_t *pri, long offset) 399 { 400 struct ustat ubuf; 401 402 if (offset != 0 && 403 Pread(Proc, &ubuf, sizeof (ubuf), offset) == sizeof (ubuf)) { 404 (void) printf( 405 "%s\ttfree=%-6ld tinode=%-5lu fname=%-6.6s fpack=%-.6s\n", 406 pri->pname, 407 ubuf.f_tfree, 408 ubuf.f_tinode, 409 ubuf.f_fname, 410 ubuf.f_fpack); 411 } 412 } 413 414 void 415 show_ustat32(private_t *pri, long offset) 416 { 417 struct ustat32 ubuf; 418 419 if (offset != 0 && 420 Pread(Proc, &ubuf, sizeof (ubuf), offset) == sizeof (ubuf)) { 421 (void) printf( 422 "%s\ttfree=%-6d tinode=%-5u fname=%-6.6s fpack=%-.6s\n", 423 pri->pname, 424 ubuf.f_tfree, 425 ubuf.f_tinode, 426 ubuf.f_fname, 427 ubuf.f_fpack); 428 } 429 } 430 431 void 432 show_fusers(private_t *pri, long offset, long nproc) 433 { 434 f_user_t fubuf; 435 int serial = (nproc > 4); 436 437 if (offset == 0) 438 return; 439 440 /* enter region of lengthy output */ 441 if (serial) 442 Eserialize(); 443 444 while (nproc > 0 && 445 Pread(Proc, &fubuf, sizeof (fubuf), offset) == sizeof (fubuf)) { 446 (void) printf("%s\tpid=%-5d uid=%-5u flags=%s\n", 447 pri->pname, 448 (int)fubuf.fu_pid, 449 fubuf.fu_uid, 450 fuflags(pri, fubuf.fu_flags)); 451 nproc--; 452 offset += sizeof (fubuf); 453 } 454 455 /* exit region of lengthy output */ 456 if (serial) 457 Xserialize(); 458 } 459 460 void 461 show_utssys(private_t *pri, long r0) 462 { 463 if (pri->sys_nargs >= 3) { 464 switch (pri->sys_args[2]) { 465 case UTS_UNAME: 466 show_uname(pri, (long)pri->sys_args[0]); 467 break; 468 case UTS_USTAT: 469 show_ustat(pri, (long)pri->sys_args[0]); 470 break; 471 case UTS_FUSERS: 472 show_fusers(pri, (long)pri->sys_args[3], r0); 473 break; 474 } 475 } 476 } 477 478 void 479 show_utssys32(private_t *pri, long r0) 480 { 481 if (pri->sys_nargs >= 3) { 482 switch (pri->sys_args[2]) { 483 case UTS_UNAME: 484 show_uname(pri, (long)pri->sys_args[0]); 485 break; 486 case UTS_USTAT: 487 show_ustat32(pri, (long)pri->sys_args[0]); 488 break; 489 case UTS_FUSERS: 490 show_fusers(pri, (long)pri->sys_args[3], r0); 491 break; 492 } 493 } 494 } 495 496 void 497 show_cladm(private_t *pri, int code, int function, long offset) 498 { 499 int arg; 500 501 switch (code) { 502 case CL_INITIALIZE: 503 switch (function) { 504 case CL_GET_BOOTFLAG: 505 if (Pread(Proc, &arg, sizeof (arg), offset) 506 == sizeof (arg)) { 507 if (arg & CLUSTER_CONFIGURED) 508 (void) printf("%s\tbootflags=" 509 "CLUSTER_CONFIGURED", pri->pname); 510 if (arg & CLUSTER_BOOTED) 511 (void) printf("|CLUSTER_BOOTED\n"); 512 } 513 break; 514 } 515 break; 516 case CL_CONFIG: 517 switch (function) { 518 case CL_NODEID: 519 case CL_HIGHEST_NODEID: 520 if (Pread(Proc, &arg, sizeof (arg), offset) 521 == sizeof (arg)) 522 (void) printf("%s\tnodeid=%d\n", 523 pri->pname, arg); 524 } 525 break; 526 } 527 } 528 529 #define ALL_LOCK_TYPES \ 530 (USYNC_PROCESS | LOCK_ERRORCHECK | LOCK_RECURSIVE | \ 531 LOCK_PRIO_INHERIT | LOCK_PRIO_PROTECT | LOCK_ROBUST | \ 532 USYNC_PROCESS_ROBUST) 533 534 /* return cv and mutex types */ 535 const char * 536 synch_type(private_t *pri, uint_t type) 537 { 538 char *str = pri->code_buf; 539 540 if (type & USYNC_PROCESS) 541 (void) strcpy(str, "USYNC_PROCESS"); 542 else 543 (void) strcpy(str, "USYNC_THREAD"); 544 545 if (type & LOCK_ERRORCHECK) 546 (void) strcat(str, "|LOCK_ERRORCHECK"); 547 if (type & LOCK_RECURSIVE) 548 (void) strcat(str, "|LOCK_RECURSIVE"); 549 if (type & LOCK_PRIO_INHERIT) 550 (void) strcat(str, "|LOCK_PRIO_INHERIT"); 551 if (type & LOCK_PRIO_PROTECT) 552 (void) strcat(str, "|LOCK_PRIO_PROTECT"); 553 if (type & LOCK_ROBUST) 554 (void) strcat(str, "|LOCK_ROBUST"); 555 if (type & USYNC_PROCESS_ROBUST) 556 (void) strcat(str, "|USYNC_PROCESS_ROBUST"); 557 558 if ((type &= ~ALL_LOCK_TYPES) != 0) 559 (void) sprintf(str + strlen(str), "|0x%.4X", type); 560 561 return ((const char *)str); 562 } 563 564 void 565 show_mutex(private_t *pri, long offset) 566 { 567 lwp_mutex_t mutex; 568 569 if (Pread(Proc, &mutex, sizeof (mutex), offset) == sizeof (mutex)) { 570 (void) printf("%s\tmutex type: %s\n", 571 pri->pname, 572 synch_type(pri, mutex.mutex_type)); 573 } 574 } 575 576 void 577 show_condvar(private_t *pri, long offset) 578 { 579 lwp_cond_t condvar; 580 581 if (Pread(Proc, &condvar, sizeof (condvar), offset) 582 == sizeof (condvar)) { 583 (void) printf("%s\tcondvar type: %s\n", 584 pri->pname, 585 synch_type(pri, condvar.cond_type)); 586 } 587 } 588 589 void 590 show_sema(private_t *pri, long offset) 591 { 592 lwp_sema_t sema; 593 594 if (Pread(Proc, &sema, sizeof (sema), offset) == sizeof (sema)) { 595 (void) printf("%s\tsema type: %s count = %u\n", 596 pri->pname, 597 synch_type(pri, sema.sema_type), 598 sema.sema_count); 599 } 600 } 601 602 void 603 show_rwlock(private_t *pri, long offset) 604 { 605 lwp_rwlock_t rwlock; 606 607 if (Pread(Proc, &rwlock, sizeof (rwlock), offset) == sizeof (rwlock)) { 608 (void) printf("%s\trwlock type: %s readers = %d\n", 609 pri->pname, 610 synch_type(pri, rwlock.rwlock_type), 611 rwlock.rwlock_readers); 612 } 613 } 614 615 /* represent character as itself ('c') or octal (012) */ 616 char * 617 show_char(char *buf, int c) 618 { 619 const char *fmt; 620 621 if (c >= ' ' && c < 0177) 622 fmt = "'%c'"; 623 else 624 fmt = "%.3o"; 625 626 (void) sprintf(buf, fmt, c&0xff); 627 return (buf); 628 } 629 630 void 631 show_termio(private_t *pri, long offset) 632 { 633 struct termio termio; 634 char cbuf[8]; 635 int i; 636 637 if (Pread(Proc, &termio, sizeof (termio), offset) == sizeof (termio)) { 638 (void) printf( 639 "%s\tiflag=0%.6o oflag=0%.6o cflag=0%.6o lflag=0%.6o line=%d\n", 640 pri->pname, 641 termio.c_iflag, 642 termio.c_oflag, 643 termio.c_cflag, 644 termio.c_lflag, 645 termio.c_line); 646 (void) printf("%s\t cc: ", pri->pname); 647 for (i = 0; i < NCC; i++) 648 (void) printf(" %s", 649 show_char(cbuf, (int)termio.c_cc[i])); 650 (void) fputc('\n', stdout); 651 } 652 } 653 654 void 655 show_termios(private_t *pri, long offset) 656 { 657 struct termios termios; 658 char cbuf[8]; 659 int i; 660 661 if (Pread(Proc, &termios, sizeof (termios), offset) 662 == sizeof (termios)) { 663 (void) printf( 664 "%s\tiflag=0%.6o oflag=0%.6o cflag=0%.6o lflag=0%.6o\n", 665 pri->pname, 666 termios.c_iflag, 667 termios.c_oflag, 668 termios.c_cflag, 669 termios.c_lflag); 670 (void) printf("%s\t cc: ", pri->pname); 671 for (i = 0; i < NCCS; i++) { 672 if (i == NCC) /* show new chars on new line */ 673 (void) printf("\n%s\t\t", pri->pname); 674 (void) printf(" %s", 675 show_char(cbuf, (int)termios.c_cc[i])); 676 } 677 (void) fputc('\n', stdout); 678 } 679 } 680 681 void 682 show_termiox(private_t *pri, long offset) 683 { 684 struct termiox termiox; 685 int i; 686 687 if (Pread(Proc, &termiox, sizeof (termiox), offset) 688 == sizeof (termiox)) { 689 (void) printf("%s\thflag=0%.3o cflag=0%.3o rflag=0%.3o", 690 pri->pname, 691 termiox.x_hflag, 692 termiox.x_cflag, 693 termiox.x_rflag[0]); 694 for (i = 1; i < NFF; i++) 695 (void) printf(",0%.3o", termiox.x_rflag[i]); 696 (void) printf(" sflag=0%.3o\n", 697 termiox.x_sflag); 698 } 699 } 700 701 void 702 show_sgttyb(private_t *pri, long offset) 703 { 704 struct sgttyb sgttyb; 705 706 if (Pread(Proc, &sgttyb, sizeof (sgttyb), offset) == sizeof (sgttyb)) { 707 char erase[8]; 708 char kill[8]; 709 710 (void) printf( 711 "%s\tispeed=%-2d ospeed=%-2d erase=%s kill=%s flags=0x%.8x\n", 712 pri->pname, 713 sgttyb.sg_ispeed&0xff, 714 sgttyb.sg_ospeed&0xff, 715 show_char(erase, sgttyb.sg_erase), 716 show_char(kill, sgttyb.sg_kill), 717 sgttyb.sg_flags); 718 } 719 } 720 721 void 722 show_ltchars(private_t *pri, long offset) 723 { 724 struct ltchars ltchars; 725 char *p; 726 char cbuf[8]; 727 int i; 728 729 if (Pread(Proc, <chars, sizeof (ltchars), offset) 730 == sizeof (ltchars)) { 731 (void) printf("%s\t cc: ", pri->pname); 732 for (p = (char *)<chars, i = 0; i < sizeof (ltchars); i++) 733 (void) printf(" %s", show_char(cbuf, (int)*p++)); 734 (void) fputc('\n', stdout); 735 } 736 } 737 738 void 739 show_tchars(private_t *pri, long offset) 740 { 741 struct tchars tchars; 742 char *p; 743 char cbuf[8]; 744 int i; 745 746 if (Pread(Proc, &tchars, sizeof (tchars), offset) == sizeof (tchars)) { 747 (void) printf("%s\t cc: ", pri->pname); 748 for (p = (char *)&tchars, i = 0; i < sizeof (tchars); i++) 749 (void) printf(" %s", show_char(cbuf, (int)*p++)); 750 (void) fputc('\n', stdout); 751 } 752 } 753 754 void 755 show_termcb(private_t *pri, long offset) 756 { 757 struct termcb termcb; 758 759 if (Pread(Proc, &termcb, sizeof (termcb), offset) == sizeof (termcb)) { 760 (void) printf( 761 "%s\tflgs=0%.2o termt=%d crow=%d ccol=%d vrow=%d lrow=%d\n", 762 pri->pname, 763 termcb.st_flgs&0xff, 764 termcb.st_termt&0xff, 765 termcb.st_crow&0xff, 766 termcb.st_ccol&0xff, 767 termcb.st_vrow&0xff, 768 termcb.st_lrow&0xff); 769 } 770 } 771 772 /* integer value pointed to by ioctl() arg */ 773 void 774 show_strint(private_t *pri, int code, long offset) 775 { 776 int val; 777 778 if (Pread(Proc, &val, sizeof (val), offset) == sizeof (val)) { 779 const char *s = NULL; 780 781 switch (code) { /* interpret these symbolically */ 782 case I_GRDOPT: 783 s = strrdopt(val); 784 break; 785 case I_GETSIG: 786 s = strevents(pri, val); 787 break; 788 case TIOCFLUSH: 789 s = tiocflush(pri, val); 790 break; 791 } 792 793 if (s == NULL) 794 (void) printf("%s\t0x%.8lX: %d\n", 795 pri->pname, offset, val); 796 else 797 (void) printf("%s\t0x%.8lX: %s\n", 798 pri->pname, offset, s); 799 } 800 } 801 802 void 803 show_strioctl(private_t *pri, long offset) 804 { 805 struct strioctl strioctl; 806 807 if (Pread(Proc, &strioctl, sizeof (strioctl), offset) == 808 sizeof (strioctl)) { 809 (void) printf( 810 "%s\tcmd=%s timout=%d len=%d dp=0x%.8lX\n", 811 pri->pname, 812 ioctlname(pri, strioctl.ic_cmd), 813 strioctl.ic_timout, 814 strioctl.ic_len, 815 (long)strioctl.ic_dp); 816 817 if (pri->recur++ == 0) /* avoid indefinite recursion */ 818 show_ioctl(pri, strioctl.ic_cmd, 819 (long)strioctl.ic_dp); 820 --pri->recur; 821 } 822 } 823 824 void 825 show_strioctl32(private_t *pri, long offset) 826 { 827 struct strioctl32 strioctl; 828 829 if (Pread(Proc, &strioctl, sizeof (strioctl), offset) == 830 sizeof (strioctl)) { 831 (void) printf( 832 "%s\tcmd=%s timout=%d len=%d dp=0x%.8lX\n", 833 pri->pname, 834 ioctlname(pri, strioctl.ic_cmd), 835 strioctl.ic_timout, 836 strioctl.ic_len, 837 (long)strioctl.ic_dp); 838 839 if (pri->recur++ == 0) /* avoid indefinite recursion */ 840 show_ioctl(pri, strioctl.ic_cmd, 841 (long)strioctl.ic_dp); 842 --pri->recur; 843 } 844 } 845 846 void 847 print_strbuf(private_t *pri, struct strbuf *sp, const char *name, int dump) 848 { 849 (void) printf( 850 "%s\t%s: maxlen=%-4d len=%-4d buf=0x%.8lX", 851 pri->pname, 852 name, 853 sp->maxlen, 854 sp->len, 855 (long)sp->buf); 856 /* 857 * Should we show the buffer contents? 858 * Keyed to the '-r fds' and '-w fds' options? 859 */ 860 if (sp->buf == NULL || sp->len <= 0) 861 (void) fputc('\n', stdout); 862 else { 863 int nb = (sp->len > 8)? 8 : sp->len; 864 char buffer[8]; 865 char obuf[40]; 866 867 if (Pread(Proc, buffer, (size_t)nb, (long)sp->buf) == nb) { 868 (void) strcpy(obuf, ": \""); 869 showbytes(buffer, nb, obuf+3); 870 (void) strcat(obuf, 871 (nb == sp->len)? 872 (const char *)"\"" : (const char *)"\".."); 873 (void) fputs(obuf, stdout); 874 } 875 (void) fputc('\n', stdout); 876 if (dump && sp->len > 8) 877 showbuffer(pri, (long)sp->buf, (long)sp->len); 878 } 879 } 880 881 void 882 print_strbuf32(private_t *pri, struct strbuf32 *sp, const char *name, int dump) 883 { 884 (void) printf( 885 "%s\t%s: maxlen=%-4d len=%-4d buf=0x%.8lX", 886 pri->pname, 887 name, 888 sp->maxlen, 889 sp->len, 890 (long)sp->buf); 891 /* 892 * Should we show the buffer contents? 893 * Keyed to the '-r fds' and '-w fds' options? 894 */ 895 if (sp->buf == 0 || sp->len <= 0) 896 (void) fputc('\n', stdout); 897 else { 898 int nb = (sp->len > 8)? 8 : sp->len; 899 char buffer[8]; 900 char obuf[40]; 901 902 if (Pread(Proc, buffer, (size_t)nb, (long)sp->buf) == nb) { 903 (void) strcpy(obuf, ": \""); 904 showbytes(buffer, nb, obuf+3); 905 (void) strcat(obuf, 906 (nb == sp->len)? 907 (const char *)"\"" : (const char *)"\".."); 908 (void) fputs(obuf, stdout); 909 } 910 (void) fputc('\n', stdout); 911 if (dump && sp->len > 8) 912 showbuffer(pri, (long)sp->buf, (long)sp->len); 913 } 914 } 915 916 /* strpeek and strfdinsert flags word */ 917 const char * 918 strflags(private_t *pri, int flags) 919 { 920 const char *s; 921 922 switch (flags) { 923 case 0: 924 s = "0"; 925 break; 926 case RS_HIPRI: 927 s = "RS_HIPRI"; 928 break; 929 default: 930 (void) sprintf(pri->code_buf, "0x%.4X", flags); 931 s = pri->code_buf; 932 } 933 934 return (s); 935 } 936 937 void 938 show_strpeek(private_t *pri, long offset) 939 { 940 struct strpeek strpeek; 941 942 if (Pread(Proc, &strpeek, sizeof (strpeek), offset) 943 == sizeof (strpeek)) { 944 945 print_strbuf(pri, &strpeek.ctlbuf, "ctl", FALSE); 946 print_strbuf(pri, &strpeek.databuf, "dat", FALSE); 947 948 (void) printf("%s\tflags=%s\n", 949 pri->pname, 950 strflags(pri, strpeek.flags)); 951 } 952 } 953 954 void 955 show_strpeek32(private_t *pri, long offset) 956 { 957 struct strpeek32 strpeek; 958 959 if (Pread(Proc, &strpeek, sizeof (strpeek), offset) 960 == sizeof (strpeek)) { 961 962 print_strbuf32(pri, &strpeek.ctlbuf, "ctl", FALSE); 963 print_strbuf32(pri, &strpeek.databuf, "dat", FALSE); 964 965 (void) printf("%s\tflags=%s\n", 966 pri->pname, 967 strflags(pri, strpeek.flags)); 968 } 969 } 970 971 void 972 show_strfdinsert(private_t *pri, long offset) 973 { 974 struct strfdinsert strfdinsert; 975 976 if (Pread(Proc, &strfdinsert, sizeof (strfdinsert), offset) == 977 sizeof (strfdinsert)) { 978 979 print_strbuf(pri, &strfdinsert.ctlbuf, "ctl", FALSE); 980 print_strbuf(pri, &strfdinsert.databuf, "dat", FALSE); 981 982 (void) printf("%s\tflags=%s fildes=%d offset=%d\n", 983 pri->pname, 984 strflags(pri, strfdinsert.flags), 985 strfdinsert.fildes, 986 strfdinsert.offset); 987 } 988 } 989 990 void 991 show_strfdinsert32(private_t *pri, long offset) 992 { 993 struct strfdinsert32 strfdinsert; 994 995 if (Pread(Proc, &strfdinsert, sizeof (strfdinsert), offset) == 996 sizeof (strfdinsert)) { 997 998 print_strbuf32(pri, &strfdinsert.ctlbuf, "ctl", FALSE); 999 print_strbuf32(pri, &strfdinsert.databuf, "dat", FALSE); 1000 1001 (void) printf("%s\tflags=%s fildes=%d offset=%d\n", 1002 pri->pname, 1003 strflags(pri, strfdinsert.flags), 1004 strfdinsert.fildes, 1005 strfdinsert.offset); 1006 } 1007 } 1008 1009 void 1010 show_strrecvfd(private_t *pri, long offset) 1011 { 1012 struct strrecvfd strrecvfd; 1013 1014 if (Pread(Proc, &strrecvfd, sizeof (strrecvfd), offset) == 1015 sizeof (strrecvfd)) { 1016 (void) printf( 1017 "%s\tfd=%-5d uid=%-5u gid=%u\n", 1018 pri->pname, 1019 strrecvfd.fd, 1020 strrecvfd.uid, 1021 strrecvfd.gid); 1022 } 1023 } 1024 1025 void 1026 show_strlist(private_t *pri, long offset) 1027 { 1028 struct str_list strlist; 1029 struct str_mlist list; 1030 int count; 1031 1032 if (Pread(Proc, &strlist, sizeof (strlist), offset) == 1033 sizeof (strlist)) { 1034 (void) printf("%s\tnmods=%d modlist=0x%.8lX\n", 1035 pri->pname, 1036 strlist.sl_nmods, 1037 (long)strlist.sl_modlist); 1038 1039 count = strlist.sl_nmods; 1040 offset = (long)strlist.sl_modlist; 1041 while (!interrupt && --count >= 0) { 1042 if (Pread(Proc, &list, sizeof (list), offset) != 1043 sizeof (list)) 1044 break; 1045 (void) printf("%s\t\t\"%.*s\"\n", 1046 pri->pname, 1047 (int)sizeof (list.l_name), 1048 list.l_name); 1049 offset += sizeof (struct str_mlist); 1050 } 1051 } 1052 } 1053 1054 void 1055 show_strlist32(private_t *pri, long offset) 1056 { 1057 struct str_list32 strlist; 1058 struct str_mlist list; 1059 int count; 1060 1061 if (Pread(Proc, &strlist, sizeof (strlist), offset) == 1062 sizeof (strlist)) { 1063 (void) printf("%s\tnmods=%d modlist=0x%.8lX\n", 1064 pri->pname, 1065 strlist.sl_nmods, 1066 (long)strlist.sl_modlist); 1067 1068 count = strlist.sl_nmods; 1069 offset = (long)strlist.sl_modlist; 1070 while (!interrupt && --count >= 0) { 1071 if (Pread(Proc, &list, sizeof (list), offset) != 1072 sizeof (list)) 1073 break; 1074 (void) printf("%s\t\t\"%.*s\"\n", 1075 pri->pname, 1076 (int)sizeof (list.l_name), 1077 list.l_name); 1078 offset += sizeof (struct str_mlist); 1079 } 1080 } 1081 } 1082 1083 void 1084 show_jwinsize(private_t *pri, long offset) 1085 { 1086 struct jwinsize jwinsize; 1087 1088 if (Pread(Proc, &jwinsize, sizeof (jwinsize), offset) == 1089 sizeof (jwinsize)) { 1090 (void) printf( 1091 "%s\tbytesx=%-3u bytesy=%-3u bitsx=%-3u bitsy=%-3u\n", 1092 pri->pname, 1093 (unsigned)jwinsize.bytesx, 1094 (unsigned)jwinsize.bytesy, 1095 (unsigned)jwinsize.bitsx, 1096 (unsigned)jwinsize.bitsy); 1097 } 1098 } 1099 1100 void 1101 show_winsize(private_t *pri, long offset) 1102 { 1103 struct winsize winsize; 1104 1105 if (Pread(Proc, &winsize, sizeof (winsize), offset) 1106 == sizeof (winsize)) { 1107 (void) printf( 1108 "%s\trow=%-3d col=%-3d xpixel=%-3d ypixel=%-3d\n", 1109 pri->pname, 1110 winsize.ws_row, 1111 winsize.ws_col, 1112 winsize.ws_xpixel, 1113 winsize.ws_ypixel); 1114 } 1115 } 1116 1117 struct audio_stuff { 1118 uint_t bit; 1119 const char *str; 1120 }; 1121 1122 const struct audio_stuff audio_output_ports[] = { 1123 { AUDIO_SPEAKER, "SPEAKER" }, 1124 { AUDIO_HEADPHONE, "HEADPHONE" }, 1125 { AUDIO_LINE_OUT, "LINE_OUT" }, 1126 { AUDIO_SPDIF_OUT, "SPDIF_OUT" }, 1127 { AUDIO_AUX1_OUT, "AUX1_OUT" }, 1128 { AUDIO_AUX2_OUT, "AUX2_OUT" }, 1129 { 0, NULL } 1130 }; 1131 1132 const struct audio_stuff audio_input_ports[] = { 1133 { AUDIO_MICROPHONE, "MICROPHONE" }, 1134 { AUDIO_LINE_IN, "LINE_IN" }, 1135 { AUDIO_CD, "CD" }, 1136 { AUDIO_SPDIF_IN, "SPDIF_IN" }, 1137 { AUDIO_AUX1_IN, "AUX1_IN" }, 1138 { AUDIO_AUX2_IN, "AUX2_IN" }, 1139 { AUDIO_CODEC_LOOPB_IN, "CODEC_LOOPB_IN" }, 1140 { AUDIO_SUNVTS, "SUNVTS" }, 1141 { 0, NULL } 1142 }; 1143 1144 static const struct audio_stuff audio_hw_features[] = { 1145 { AUDIO_HWFEATURE_DUPLEX, "DUPLEX" }, 1146 { AUDIO_HWFEATURE_MSCODEC, "MSCODEC" }, 1147 { AUDIO_HWFEATURE_IN2OUT, "IN2OUT" }, 1148 { AUDIO_HWFEATURE_PLAY, "PLAY" }, 1149 { AUDIO_HWFEATURE_RECORD, "RECORD" }, 1150 { 0, NULL } 1151 }; 1152 1153 static const struct audio_stuff audio_sw_features[] = { 1154 { AUDIO_SWFEATURE_MIXER, "MIXER" }, 1155 { 0, NULL } 1156 }; 1157 1158 void 1159 show_audio_features(const private_t *pri, 1160 const struct audio_stuff *audio_porttab, uint_t features, 1161 const char *name) 1162 { 1163 (void) printf("%s\t%s=", pri->pname, name); 1164 if (features == 0) { 1165 (void) printf("0\n"); 1166 return; 1167 } 1168 1169 for (; audio_porttab->bit != 0; ++audio_porttab) { 1170 if (features & audio_porttab->bit) { 1171 (void) printf(audio_porttab->str); 1172 features &= ~audio_porttab->bit; 1173 if (features) 1174 (void) putchar('|'); 1175 } 1176 } 1177 if (features) 1178 (void) printf("0x%x", features); 1179 (void) putchar('\n'); 1180 } 1181 1182 void 1183 show_audio_ports(private_t *pri, const char *mode, 1184 const char *field, uint_t ports) 1185 { 1186 const struct audio_stuff *audio_porttab; 1187 1188 (void) printf("%s\t%s\t%s=", pri->pname, mode, field); 1189 if (ports == 0) { 1190 (void) printf("0\n"); 1191 return; 1192 } 1193 if (*mode == 'p') 1194 audio_porttab = audio_output_ports; 1195 else 1196 audio_porttab = audio_input_ports; 1197 for (; audio_porttab->bit != 0; ++audio_porttab) { 1198 if (ports & audio_porttab->bit) { 1199 (void) printf(audio_porttab->str); 1200 ports &= ~audio_porttab->bit; 1201 if (ports) 1202 (void) putchar('|'); 1203 } 1204 } 1205 if (ports) 1206 (void) printf("0x%x", ports); 1207 (void) putchar('\n'); 1208 } 1209 1210 void 1211 show_audio_prinfo(private_t *pri, const char *mode, struct audio_prinfo *au_pr) 1212 { 1213 const char *s; 1214 1215 /* 1216 * The following values describe the audio data encoding. 1217 */ 1218 1219 (void) printf("%s\t%s\tsample_rate=%u channels=%u precision=%u\n", 1220 pri->pname, mode, 1221 au_pr->sample_rate, 1222 au_pr->channels, 1223 au_pr->precision); 1224 1225 s = NULL; 1226 switch (au_pr->encoding) { 1227 case AUDIO_ENCODING_NONE: s = "NONE"; break; 1228 case AUDIO_ENCODING_ULAW: s = "ULAW"; break; 1229 case AUDIO_ENCODING_ALAW: s = "ALAW"; break; 1230 case AUDIO_ENCODING_LINEAR: s = "LINEAR"; break; 1231 case AUDIO_ENCODING_DVI: s = "DVI"; break; 1232 case AUDIO_ENCODING_LINEAR8: s = "LINEAR8"; break; 1233 } 1234 if (s) 1235 (void) printf("%s\t%s\tencoding=%s\n", pri->pname, mode, s); 1236 else { 1237 (void) printf("%s\t%s\tencoding=%u\n", 1238 pri->pname, mode, au_pr->encoding); 1239 } 1240 1241 /* 1242 * The following values control audio device configuration 1243 */ 1244 1245 (void) printf( 1246 "%s\t%s\tgain=%u buffer_size=%u\n", 1247 pri->pname, mode, 1248 au_pr->gain, 1249 au_pr->buffer_size); 1250 show_audio_ports(pri, mode, "port", au_pr->port); 1251 show_audio_ports(pri, mode, "avail_ports", au_pr->avail_ports); 1252 show_audio_ports(pri, mode, "mod_ports", au_pr->mod_ports); 1253 1254 /* 1255 * The following values describe driver state 1256 */ 1257 1258 (void) printf("%s\t%s\tsamples=%u eof=%u pause=%u error=%u\n", 1259 pri->pname, mode, 1260 au_pr->samples, 1261 au_pr->eof, 1262 au_pr->pause, 1263 au_pr->error); 1264 (void) printf("%s\t%s\twaiting=%u balance=%u minordev=%u\n", 1265 pri->pname, mode, 1266 au_pr->waiting, 1267 au_pr->balance, 1268 au_pr->minordev); 1269 1270 /* 1271 * The following values are read-only state flags 1272 */ 1273 (void) printf("%s\t%s\topen=%u active=%u\n", 1274 pri->pname, mode, 1275 au_pr->open, 1276 au_pr->active); 1277 } 1278 1279 void 1280 show_audio_info(private_t *pri, long offset) 1281 { 1282 struct audio_info au; 1283 1284 if (Pread(Proc, &au, sizeof (au), offset) == sizeof (au)) { 1285 show_audio_prinfo(pri, "play", &au.play); 1286 show_audio_prinfo(pri, "record", &au.record); 1287 (void) printf("%s\tmonitor_gain=%u output_muted=%u\n", 1288 pri->pname, au.monitor_gain, au.output_muted); 1289 show_audio_features(pri, audio_hw_features, au.hw_features, 1290 "hw_features"); 1291 show_audio_features(pri, audio_sw_features, au.sw_features, 1292 "sw_features"); 1293 show_audio_features(pri, audio_sw_features, 1294 au.sw_features_enabled, "sw_features_enabled"); 1295 } 1296 } 1297 1298 void 1299 show_ioctl(private_t *pri, int code, long offset) 1300 { 1301 int lp64 = (data_model == PR_MODEL_LP64); 1302 int err = pri->Errno; /* don't display output parameters */ 1303 /* for a failed system call */ 1304 if (offset == 0) 1305 return; 1306 1307 switch (code) { 1308 case TCGETA: 1309 if (err) 1310 break; 1311 /*FALLTHROUGH*/ 1312 case TCSETA: 1313 case TCSETAW: 1314 case TCSETAF: 1315 show_termio(pri, offset); 1316 break; 1317 case TCGETS: 1318 if (err) 1319 break; 1320 /*FALLTHROUGH*/ 1321 case TCSETS: 1322 case TCSETSW: 1323 case TCSETSF: 1324 show_termios(pri, offset); 1325 break; 1326 case TCGETX: 1327 if (err) 1328 break; 1329 /*FALLTHROUGH*/ 1330 case TCSETX: 1331 case TCSETXW: 1332 case TCSETXF: 1333 show_termiox(pri, offset); 1334 break; 1335 case TIOCGETP: 1336 if (err) 1337 break; 1338 /*FALLTHROUGH*/ 1339 case TIOCSETN: 1340 case TIOCSETP: 1341 show_sgttyb(pri, offset); 1342 break; 1343 case TIOCGLTC: 1344 if (err) 1345 break; 1346 /*FALLTHROUGH*/ 1347 case TIOCSLTC: 1348 show_ltchars(pri, offset); 1349 break; 1350 case TIOCGETC: 1351 if (err) 1352 break; 1353 /*FALLTHROUGH*/ 1354 case TIOCSETC: 1355 show_tchars(pri, offset); 1356 break; 1357 case LDGETT: 1358 if (err) 1359 break; 1360 /*FALLTHROUGH*/ 1361 case LDSETT: 1362 show_termcb(pri, offset); 1363 break; 1364 /* streams ioctl()s */ 1365 #if 0 1366 /* these are displayed as strings in the arg list */ 1367 /* by prt_ioa(). don't display them again here */ 1368 case I_PUSH: 1369 case I_LOOK: 1370 case I_FIND: 1371 /* these are displayed as decimal in the arg list */ 1372 /* by prt_ioa(). don't display them again here */ 1373 case I_LINK: 1374 case I_UNLINK: 1375 case I_SENDFD: 1376 /* these are displayed symbolically in the arg list */ 1377 /* by prt_ioa(). don't display them again here */ 1378 case I_SRDOPT: 1379 case I_SETSIG: 1380 case I_FLUSH: 1381 break; 1382 /* this one just ignores the argument */ 1383 case I_POP: 1384 break; 1385 #endif 1386 /* these return something in an int pointed to by arg */ 1387 case I_NREAD: 1388 case I_GRDOPT: 1389 case I_GETSIG: 1390 case TIOCGSID: 1391 case TIOCGPGRP: 1392 case TIOCLGET: 1393 case FIONREAD: 1394 case FIORDCHK: 1395 if (err) 1396 break; 1397 /*FALLTHROUGH*/ 1398 /* these pass something in an int pointed to by arg */ 1399 case TIOCSPGRP: 1400 case TIOCFLUSH: 1401 case TIOCLBIS: 1402 case TIOCLBIC: 1403 case TIOCLSET: 1404 show_strint(pri, code, offset); 1405 break; 1406 /* these all point to structures */ 1407 case I_STR: 1408 if (lp64) 1409 show_strioctl(pri, offset); 1410 else 1411 show_strioctl32(pri, offset); 1412 break; 1413 case I_PEEK: 1414 if (lp64) 1415 show_strpeek(pri, offset); 1416 else 1417 show_strpeek32(pri, offset); 1418 break; 1419 case I_FDINSERT: 1420 if (lp64) 1421 show_strfdinsert(pri, offset); 1422 else 1423 show_strfdinsert32(pri, offset); 1424 break; 1425 case I_RECVFD: 1426 if (err) 1427 break; 1428 show_strrecvfd(pri, offset); 1429 break; 1430 case I_LIST: 1431 if (err) 1432 break; 1433 if (lp64) 1434 show_strlist(pri, offset); 1435 else 1436 show_strlist32(pri, offset); 1437 break; 1438 case JWINSIZE: 1439 if (err) 1440 break; 1441 show_jwinsize(pri, offset); 1442 break; 1443 case TIOCGWINSZ: 1444 if (err) 1445 break; 1446 /*FALLTHROUGH*/ 1447 case TIOCSWINSZ: 1448 show_winsize(pri, offset); 1449 break; 1450 case AUDIO_GETINFO: 1451 case (int)AUDIO_SETINFO: 1452 show_audio_info(pri, offset); 1453 break; 1454 1455 default: 1456 if ((code & ~0xff) == ZFS_IOC) { 1457 show_zfs_ioc(pri, offset); 1458 break; 1459 } 1460 1461 if (code & IOC_INOUT) { 1462 const char *str = ioctldatastruct(code); 1463 1464 (void) printf("\t\t%s", 1465 (code & IOC_INOUT) == IOC_INOUT ? "write/read" : 1466 code & IOC_IN ? "write" : "read"); 1467 if (str != NULL) { 1468 (void) printf(" (struct %s)\n", str); 1469 } else { 1470 (void) printf(" %d bytes\n", 1471 (code >> 16) & IOCPARM_MASK); 1472 } 1473 } 1474 } 1475 } 1476 1477 void 1478 show_statvfs(private_t *pri) 1479 { 1480 long offset; 1481 struct statvfs statvfs; 1482 char *cp; 1483 1484 if (pri->sys_nargs > 1 && (offset = pri->sys_args[1]) != 0 && 1485 Pread(Proc, &statvfs, sizeof (statvfs), offset) 1486 == sizeof (statvfs)) { 1487 (void) printf( 1488 "%s\tbsize=%-10lu frsize=%-9lu blocks=%-8llu bfree=%-9llu\n", 1489 pri->pname, 1490 statvfs.f_bsize, 1491 statvfs.f_frsize, 1492 (u_longlong_t)statvfs.f_blocks, 1493 (u_longlong_t)statvfs.f_bfree); 1494 (void) printf( 1495 "%s\tbavail=%-9llu files=%-10llu ffree=%-9llu favail=%-9llu\n", 1496 pri->pname, 1497 (u_longlong_t)statvfs.f_bavail, 1498 (u_longlong_t)statvfs.f_files, 1499 (u_longlong_t)statvfs.f_ffree, 1500 (u_longlong_t)statvfs.f_favail); 1501 (void) printf( 1502 "%s\tfsid=0x%-9.4lX basetype=%-7.16s namemax=%ld\n", 1503 pri->pname, 1504 statvfs.f_fsid, 1505 statvfs.f_basetype, 1506 (long)statvfs.f_namemax); 1507 (void) printf( 1508 "%s\tflag=%s\n", 1509 pri->pname, 1510 svfsflags(pri, (ulong_t)statvfs.f_flag)); 1511 cp = statvfs.f_fstr + strlen(statvfs.f_fstr); 1512 if (cp < statvfs.f_fstr + sizeof (statvfs.f_fstr) - 1 && 1513 *(cp+1) != '\0') 1514 *cp = ' '; 1515 (void) printf("%s\tfstr=\"%.*s\"\n", 1516 pri->pname, 1517 (int)sizeof (statvfs.f_fstr), 1518 statvfs.f_fstr); 1519 } 1520 } 1521 1522 void 1523 show_statvfs32(private_t *pri) 1524 { 1525 long offset; 1526 struct statvfs32 statvfs; 1527 char *cp; 1528 1529 if (pri->sys_nargs > 1 && (offset = pri->sys_args[1]) != 0 && 1530 Pread(Proc, &statvfs, sizeof (statvfs), offset) 1531 == sizeof (statvfs)) { 1532 (void) printf( 1533 "%s\tbsize=%-10u frsize=%-9u blocks=%-8u bfree=%-9u\n", 1534 pri->pname, 1535 statvfs.f_bsize, 1536 statvfs.f_frsize, 1537 statvfs.f_blocks, 1538 statvfs.f_bfree); 1539 (void) printf( 1540 "%s\tbavail=%-9u files=%-10u ffree=%-9u favail=%-9u\n", 1541 pri->pname, 1542 statvfs.f_bavail, 1543 statvfs.f_files, 1544 statvfs.f_ffree, 1545 statvfs.f_favail); 1546 (void) printf( 1547 "%s\tfsid=0x%-9.4X basetype=%-7.16s namemax=%d\n", 1548 pri->pname, 1549 statvfs.f_fsid, 1550 statvfs.f_basetype, 1551 (int)statvfs.f_namemax); 1552 (void) printf( 1553 "%s\tflag=%s\n", 1554 pri->pname, 1555 svfsflags(pri, (ulong_t)statvfs.f_flag)); 1556 cp = statvfs.f_fstr + strlen(statvfs.f_fstr); 1557 if (cp < statvfs.f_fstr + sizeof (statvfs.f_fstr) - 1 && 1558 *(cp+1) != '\0') 1559 *cp = ' '; 1560 (void) printf("%s\tfstr=\"%.*s\"\n", 1561 pri->pname, 1562 (int)sizeof (statvfs.f_fstr), 1563 statvfs.f_fstr); 1564 } 1565 } 1566 1567 void 1568 show_statvfs64(private_t *pri) 1569 { 1570 long offset; 1571 struct statvfs64_32 statvfs; 1572 char *cp; 1573 1574 if (pri->sys_nargs > 1 && (offset = pri->sys_args[1]) != 0 && 1575 Pread(Proc, &statvfs, sizeof (statvfs), offset) 1576 == sizeof (statvfs)) { 1577 (void) printf( 1578 "%s\tbsize=%-10u frsize=%-9u blocks=%-8llu bfree=%-9llu\n", 1579 pri->pname, 1580 statvfs.f_bsize, 1581 statvfs.f_frsize, 1582 (u_longlong_t)statvfs.f_blocks, 1583 (u_longlong_t)statvfs.f_bfree); 1584 (void) printf( 1585 "%s\tbavail=%-9llu files=%-10llu ffree=%-9llu favail=%-9llu\n", 1586 pri->pname, 1587 (u_longlong_t)statvfs.f_bavail, 1588 (u_longlong_t)statvfs.f_files, 1589 (u_longlong_t)statvfs.f_ffree, 1590 (u_longlong_t)statvfs.f_favail); 1591 (void) printf( 1592 "%s\tfsid=0x%-9.4X basetype=%-7.16s namemax=%d\n", 1593 pri->pname, 1594 statvfs.f_fsid, 1595 statvfs.f_basetype, 1596 (int)statvfs.f_namemax); 1597 (void) printf( 1598 "%s\tflag=%s\n", 1599 pri->pname, 1600 svfsflags(pri, (ulong_t)statvfs.f_flag)); 1601 cp = statvfs.f_fstr + strlen(statvfs.f_fstr); 1602 if (cp < statvfs.f_fstr + sizeof (statvfs.f_fstr) - 1 && 1603 *(cp+1) != '\0') 1604 *cp = ' '; 1605 (void) printf("%s\tfstr=\"%.*s\"\n", 1606 pri->pname, 1607 (int)sizeof (statvfs.f_fstr), 1608 statvfs.f_fstr); 1609 } 1610 } 1611 1612 void 1613 show_statfs(private_t *pri) 1614 { 1615 long offset; 1616 struct statfs statfs; 1617 1618 if (pri->sys_nargs >= 2 && (offset = pri->sys_args[1]) != 0 && 1619 Pread(Proc, &statfs, sizeof (statfs), offset) == sizeof (statfs)) { 1620 (void) printf( 1621 "%s\tfty=%d bsz=%ld fsz=%ld blk=%ld bfr=%ld fil=%lu ffr=%lu\n", 1622 pri->pname, 1623 statfs.f_fstyp, 1624 statfs.f_bsize, 1625 statfs.f_frsize, 1626 statfs.f_blocks, 1627 statfs.f_bfree, 1628 statfs.f_files, 1629 statfs.f_ffree); 1630 (void) printf("%s\t fname=%.6s fpack=%.6s\n", 1631 pri->pname, 1632 statfs.f_fname, 1633 statfs.f_fpack); 1634 } 1635 } 1636 1637 void 1638 show_statfs32(private_t *pri) 1639 { 1640 long offset; 1641 struct statfs32 statfs; 1642 1643 if (pri->sys_nargs >= 2 && (offset = pri->sys_args[1]) != 0 && 1644 Pread(Proc, &statfs, sizeof (statfs), offset) == sizeof (statfs)) { 1645 (void) printf( 1646 "%s\tfty=%d bsz=%d fsz=%d blk=%d bfr=%d fil=%u ffr=%u\n", 1647 pri->pname, 1648 statfs.f_fstyp, 1649 statfs.f_bsize, 1650 statfs.f_frsize, 1651 statfs.f_blocks, 1652 statfs.f_bfree, 1653 statfs.f_files, 1654 statfs.f_ffree); 1655 (void) printf("%s\t fname=%.6s fpack=%.6s\n", 1656 pri->pname, 1657 statfs.f_fname, 1658 statfs.f_fpack); 1659 } 1660 } 1661 1662 void 1663 show_flock32(private_t *pri, long offset) 1664 { 1665 struct flock32 flock; 1666 1667 if (Pread(Proc, &flock, sizeof (flock), offset) == sizeof (flock)) { 1668 const char *str = NULL; 1669 1670 (void) printf("%s\ttyp=", pri->pname); 1671 1672 switch (flock.l_type) { 1673 case F_RDLCK: 1674 str = "F_RDLCK"; 1675 break; 1676 case F_WRLCK: 1677 str = "F_WRLCK"; 1678 break; 1679 case F_UNLCK: 1680 str = "F_UNLCK"; 1681 break; 1682 } 1683 if (str != NULL) 1684 (void) printf("%s", str); 1685 else 1686 (void) printf("%-7d", flock.l_type); 1687 1688 str = whencearg(flock.l_whence); 1689 if (str != NULL) 1690 (void) printf(" whence=%s", str); 1691 else 1692 (void) printf(" whence=%-8u", flock.l_whence); 1693 1694 (void) printf( 1695 " start=%-5d len=%-5d sys=%-2u pid=%d\n", 1696 flock.l_start, 1697 flock.l_len, 1698 flock.l_sysid, 1699 flock.l_pid); 1700 } 1701 } 1702 1703 void 1704 show_flock64(private_t *pri, long offset) 1705 { 1706 struct flock64 flock; 1707 1708 if (Pread(Proc, &flock, sizeof (flock), offset) == sizeof (flock)) { 1709 const char *str = NULL; 1710 1711 (void) printf("%s\ttyp=", pri->pname); 1712 1713 switch (flock.l_type) { 1714 case F_RDLCK: 1715 str = "F_RDLCK"; 1716 break; 1717 case F_WRLCK: 1718 str = "F_WRLCK"; 1719 break; 1720 case F_UNLCK: 1721 str = "F_UNLCK"; 1722 break; 1723 } 1724 if (str != NULL) 1725 (void) printf("%s", str); 1726 else 1727 (void) printf("%-7d", flock.l_type); 1728 1729 str = whencearg(flock.l_whence); 1730 if (str != NULL) 1731 (void) printf(" whence=%s", str); 1732 else 1733 (void) printf(" whence=%-8u", flock.l_whence); 1734 1735 (void) printf( 1736 " start=%-5lld len=%-5lld sys=%-2u pid=%d\n", 1737 (long long)flock.l_start, 1738 (long long)flock.l_len, 1739 flock.l_sysid, 1740 (int)flock.l_pid); 1741 } 1742 } 1743 1744 void 1745 show_share(private_t *pri, long offset) 1746 { 1747 struct fshare fshare; 1748 1749 if (Pread(Proc, &fshare, sizeof (fshare), offset) == sizeof (fshare)) { 1750 const char *str = NULL; 1751 int manddny = 0; 1752 1753 (void) printf("%s\taccess=", pri->pname); 1754 1755 switch (fshare.f_access) { 1756 case F_RDACC: 1757 str = "F_RDACC"; 1758 break; 1759 case F_WRACC: 1760 str = "F_WRACC"; 1761 break; 1762 case F_RWACC: 1763 str = "F_RWACC"; 1764 break; 1765 } 1766 if (str != NULL) 1767 (void) printf("%s", str); 1768 else 1769 (void) printf("%-7d", fshare.f_access); 1770 1771 str = NULL; 1772 if (fshare.f_deny & F_MANDDNY) { 1773 fshare.f_deny &= ~F_MANDDNY; 1774 manddny = 1; 1775 } 1776 switch (fshare.f_deny) { 1777 case F_NODNY: 1778 str = "F_NODNY"; 1779 break; 1780 case F_RDDNY: 1781 str = "F_RDDNY"; 1782 break; 1783 case F_WRDNY: 1784 str = "F_WRDNY"; 1785 break; 1786 case F_RWDNY: 1787 str = "F_RWDNY"; 1788 break; 1789 case F_COMPAT: 1790 str = "F_COMPAT"; 1791 break; 1792 } 1793 if (str != NULL) { 1794 if (manddny) 1795 (void) printf(" deny=F_MANDDNY|%s", str); 1796 else 1797 (void) printf(" deny=%s", str); 1798 } else { 1799 (void) printf(" deny=0x%x", manddny? 1800 fshare.f_deny | F_MANDDNY : fshare.f_deny); 1801 } 1802 1803 (void) printf(" id=%x\n", fshare.f_id); 1804 } 1805 } 1806 1807 void 1808 show_ffg(private_t *pri) 1809 { 1810 (void) putchar('\t'); 1811 (void) putchar('\t'); 1812 prt_ffg(pri, 0, pri->Rval1); 1813 (void) puts(pri->sys_string); 1814 } 1815 1816 /* print values in fcntl() pointed-to structure */ 1817 void 1818 show_fcntl(private_t *pri) 1819 { 1820 long offset; 1821 1822 if (pri->sys_nargs >= 2 && pri->sys_args[1] == F_GETFL) { 1823 show_ffg(pri); 1824 return; 1825 } 1826 1827 if (pri->sys_nargs < 3 || (offset = pri->sys_args[2]) == 0) 1828 return; 1829 1830 switch (pri->sys_args[1]) { 1831 case F_GETLK: 1832 case F_SETLK: 1833 case F_SETLKW: 1834 case F_FREESP: 1835 case F_ALLOCSP: 1836 case F_SETLK_NBMAND: 1837 case F_OFD_GETLK: 1838 case F_OFD_SETLK: 1839 case F_OFD_SETLKW: 1840 case F_FLOCK: 1841 case F_FLOCKW: 1842 if (data_model == PR_MODEL_LP64) 1843 show_flock64(pri, offset); 1844 else 1845 show_flock32(pri, offset); 1846 break; 1847 case 33: /* F_GETLK64 */ 1848 case 34: /* F_SETLK64 */ 1849 case 35: /* F_SETLKW64 */ 1850 case 27: /* F_FREESP64 */ 1851 case 28: /* F_ALLOCSP64 */ 1852 case 44: /* F_SETLK64_NBMAND */ 1853 case 50: /* F_OFD_GETLK64 */ 1854 case 51: /* F_OFD_SETLK64 */ 1855 case 52: /* F_OFD_SETLKW64 */ 1856 case 55: /* F_FLOCK64 */ 1857 case 56: /* F_FLOCKW64 */ 1858 show_flock64(pri, offset); 1859 break; 1860 case F_SHARE: 1861 case F_UNSHARE: 1862 show_share(pri, offset); 1863 break; 1864 } 1865 } 1866 1867 void 1868 show_strbuf(private_t *pri, long offset, const char *name, int dump) 1869 { 1870 struct strbuf strbuf; 1871 1872 if (Pread(Proc, &strbuf, sizeof (strbuf), offset) == sizeof (strbuf)) 1873 print_strbuf(pri, &strbuf, name, dump); 1874 } 1875 1876 void 1877 show_strbuf32(private_t *pri, long offset, const char *name, int dump) 1878 { 1879 struct strbuf32 strbuf; 1880 1881 if (Pread(Proc, &strbuf, sizeof (strbuf), offset) == sizeof (strbuf)) 1882 print_strbuf32(pri, &strbuf, name, dump); 1883 } 1884 1885 void 1886 show_gp_msg(private_t *pri, int what) 1887 { 1888 long offset; 1889 int dump = FALSE; 1890 int fdp1 = pri->sys_args[0] + 1; 1891 1892 switch (what) { 1893 case SYS_getmsg: 1894 case SYS_getpmsg: 1895 if (pri->Errno == 0 && prismember(&readfd, fdp1)) 1896 dump = TRUE; 1897 break; 1898 case SYS_putmsg: 1899 case SYS_putpmsg: 1900 if (prismember(&writefd, fdp1)) 1901 dump = TRUE; 1902 break; 1903 } 1904 1905 /* enter region of lengthy output */ 1906 if (dump) 1907 Eserialize(); 1908 1909 if (pri->sys_nargs >= 2 && (offset = pri->sys_args[1]) != 0) { 1910 if (data_model == PR_MODEL_LP64) 1911 show_strbuf(pri, offset, "ctl", dump); 1912 else 1913 show_strbuf32(pri, offset, "ctl", dump); 1914 } 1915 if (pri->sys_nargs >= 3 && (offset = pri->sys_args[2]) != 0) { 1916 if (data_model == PR_MODEL_LP64) 1917 show_strbuf(pri, offset, "dat", dump); 1918 else 1919 show_strbuf32(pri, offset, "dat", dump); 1920 } 1921 1922 /* exit region of lengthy output */ 1923 if (dump) 1924 Xserialize(); 1925 } 1926 1927 void 1928 show_int(private_t *pri, long offset, const char *name) 1929 { 1930 int value; 1931 1932 if (offset != 0 && 1933 Pread(Proc, &value, sizeof (value), offset) == sizeof (value)) 1934 (void) printf("%s\t%s:\t%d\n", 1935 pri->pname, 1936 name, 1937 value); 1938 } 1939 1940 void 1941 show_hhex_int(private_t *pri, long offset, const char *name) 1942 { 1943 int value; 1944 1945 if (Pread(Proc, &value, sizeof (value), offset) == sizeof (value)) 1946 (void) printf("%s\t%s:\t0x%.4X\n", 1947 pri->pname, 1948 name, 1949 value); 1950 } 1951 1952 #define ALL_POLL_FLAGS (POLLIN|POLLPRI|POLLOUT| \ 1953 POLLRDNORM|POLLRDBAND|POLLWRBAND|POLLERR|POLLHUP|POLLNVAL) 1954 1955 const char * 1956 pollevent(private_t *pri, int arg) 1957 { 1958 char *str = pri->code_buf; 1959 1960 if (arg == 0) 1961 return ("0"); 1962 if (arg & ~ALL_POLL_FLAGS) { 1963 (void) sprintf(str, "0x%-5X", arg); 1964 return ((const char *)str); 1965 } 1966 1967 *str = '\0'; 1968 if (arg & POLLIN) 1969 (void) strcat(str, "|POLLIN"); 1970 if (arg & POLLPRI) 1971 (void) strcat(str, "|POLLPRI"); 1972 if (arg & POLLOUT) 1973 (void) strcat(str, "|POLLOUT"); 1974 if (arg & POLLRDNORM) 1975 (void) strcat(str, "|POLLRDNORM"); 1976 if (arg & POLLRDBAND) 1977 (void) strcat(str, "|POLLRDBAND"); 1978 if (arg & POLLWRBAND) 1979 (void) strcat(str, "|POLLWRBAND"); 1980 if (arg & POLLERR) 1981 (void) strcat(str, "|POLLERR"); 1982 if (arg & POLLHUP) 1983 (void) strcat(str, "|POLLHUP"); 1984 if (arg & POLLNVAL) 1985 (void) strcat(str, "|POLLNVAL"); 1986 1987 return ((const char *)(str+1)); 1988 } 1989 1990 static void 1991 show_one_pollfd(private_t *pri, struct pollfd *ppollfd) 1992 { 1993 /* 1994 * can't print both events and revents in same printf. 1995 * pollevent() returns a pointer to a TSD location. 1996 */ 1997 (void) printf("%s\tfd=%-2d ev=%s", 1998 pri->pname, ppollfd->fd, pollevent(pri, ppollfd->events)); 1999 (void) printf(" rev=%s\n", pollevent(pri, ppollfd->revents)); 2000 } 2001 2002 static void 2003 show_all_pollfds(private_t *pri, long offset, int nfds) 2004 { 2005 struct pollfd pollfd[2]; 2006 int skip = -1; 2007 2008 for (; nfds && !interrupt; nfds--, offset += sizeof (struct pollfd)) { 2009 if (Pread(Proc, &pollfd[0], sizeof (struct pollfd), offset) != 2010 sizeof (struct pollfd)) 2011 continue; 2012 2013 if (skip >= 0 && pollfd[0].fd == pollfd[1].fd && 2014 pollfd[0].events == pollfd[1].events && 2015 pollfd[0].revents == pollfd[1].revents) { 2016 skip++; 2017 continue; 2018 } 2019 2020 if (skip > 0) 2021 (void) printf("%s\t...last pollfd structure" 2022 " repeated %d time%s...\n", 2023 pri->pname, skip, (skip == 1 ? "" : "s")); 2024 2025 skip = 0; 2026 show_one_pollfd(pri, &pollfd[0]); 2027 pollfd[1] = pollfd[0]; 2028 } 2029 2030 if (skip > 0) 2031 (void) printf( 2032 "%s\t...last pollfd structure repeated %d time%s...\n", 2033 pri->pname, skip, (skip == 1 ? "" : "s")); 2034 } 2035 2036 void 2037 show_pollsys(private_t *pri) 2038 { 2039 long offset; 2040 int nfds; 2041 int serial = 0; 2042 2043 if (pri->sys_nargs < 2) 2044 return; 2045 2046 offset = pri->sys_args[0]; 2047 nfds = pri->sys_args[1]; 2048 2049 /* enter region of lengthy output */ 2050 if (offset != 0 && nfds > 32) { 2051 Eserialize(); 2052 serial = 1; 2053 } 2054 2055 if (offset != 0 && nfds > 0) 2056 show_all_pollfds(pri, offset, nfds); 2057 2058 if (pri->sys_nargs > 2) 2059 show_timestruc(pri, (long)pri->sys_args[2], "timeout"); 2060 2061 if (pri->sys_nargs > 3) 2062 show_sigset(pri, (long)pri->sys_args[3], "sigmask"); 2063 2064 /* exit region of lengthy output */ 2065 if (serial) 2066 Xserialize(); 2067 } 2068 2069 static void 2070 show_perm64(private_t *pri, struct ipc_perm64 *ip) 2071 { 2072 (void) printf("%s\tu=%-5u g=%-5u cu=%-5u cg=%-5u z=%-5d " 2073 "m=0%.6o key=%d projid=%-5d\n", 2074 pri->pname, 2075 ip->ipcx_uid, 2076 ip->ipcx_gid, 2077 ip->ipcx_cuid, 2078 ip->ipcx_cgid, 2079 (int)ip->ipcx_zoneid, 2080 (unsigned int)ip->ipcx_mode, 2081 ip->ipcx_key, 2082 (int)ip->ipcx_projid); 2083 } 2084 2085 void 2086 show_perm(private_t *pri, struct ipc_perm *ip) 2087 { 2088 (void) printf( 2089 "%s\tu=%-5u g=%-5u cu=%-5u cg=%-5u m=0%.6o seq=%u key=%d\n", 2090 pri->pname, 2091 ip->uid, 2092 ip->gid, 2093 ip->cuid, 2094 ip->cgid, 2095 (int)ip->mode, 2096 ip->seq, 2097 ip->key); 2098 } 2099 2100 void 2101 show_perm32(private_t *pri, struct ipc_perm32 *ip) 2102 { 2103 (void) printf( 2104 "%s\tu=%-5u g=%-5u cu=%-5u cg=%-5u m=0%.6o seq=%u key=%d\n", 2105 pri->pname, 2106 ip->uid, 2107 ip->gid, 2108 ip->cuid, 2109 ip->cgid, 2110 ip->mode, 2111 ip->seq, 2112 ip->key); 2113 } 2114 2115 static void 2116 show_msgctl64(private_t *pri, long offset) 2117 { 2118 struct msqid_ds64 msgq; 2119 2120 if (offset != 0 && 2121 Pread(Proc, &msgq, sizeof (msgq), offset) == sizeof (msgq)) { 2122 show_perm64(pri, &msgq.msgx_perm); 2123 2124 (void) printf("%s\tbytes=%-5llu msgs=%-5llu maxby=%-5llu " 2125 "lspid=%-5d lrpid=%-5d\n", pri->pname, 2126 (unsigned long long)msgq.msgx_cbytes, 2127 (unsigned long long)msgq.msgx_qnum, 2128 (unsigned long long)msgq.msgx_qbytes, 2129 (int)msgq.msgx_lspid, 2130 (int)msgq.msgx_lrpid); 2131 2132 prtime(pri, " st = ", (time_t)msgq.msgx_stime); 2133 prtime(pri, " rt = ", (time_t)msgq.msgx_rtime); 2134 prtime(pri, " ct = ", (time_t)msgq.msgx_ctime); 2135 } 2136 } 2137 2138 void 2139 show_msgctl(private_t *pri, long offset) 2140 { 2141 struct msqid_ds msgq; 2142 2143 if (offset != 0 && 2144 Pread(Proc, &msgq, sizeof (msgq), offset) == sizeof (msgq)) { 2145 show_perm(pri, &msgq.msg_perm); 2146 2147 (void) printf( 2148 "%s\tbytes=%-5lu msgs=%-5lu maxby=%-5lu lspid=%-5u lrpid=%-5u\n", 2149 pri->pname, 2150 msgq.msg_cbytes, 2151 msgq.msg_qnum, 2152 msgq.msg_qbytes, 2153 (int)msgq.msg_lspid, 2154 (int)msgq.msg_lrpid); 2155 2156 prtime(pri, " st = ", msgq.msg_stime); 2157 prtime(pri, " rt = ", msgq.msg_rtime); 2158 prtime(pri, " ct = ", msgq.msg_ctime); 2159 } 2160 } 2161 2162 void 2163 show_msgctl32(private_t *pri, long offset) 2164 { 2165 struct msqid_ds32 msgq; 2166 2167 if (offset != 0 && 2168 Pread(Proc, &msgq, sizeof (msgq), offset) == sizeof (msgq)) { 2169 show_perm32(pri, &msgq.msg_perm); 2170 2171 (void) printf( 2172 "%s\tbytes=%-5u msgs=%-5u maxby=%-5u lspid=%-5u lrpid=%-5u\n", 2173 pri->pname, 2174 msgq.msg_cbytes, 2175 msgq.msg_qnum, 2176 msgq.msg_qbytes, 2177 msgq.msg_lspid, 2178 msgq.msg_lrpid); 2179 2180 prtime(pri, " st = ", msgq.msg_stime); 2181 prtime(pri, " rt = ", msgq.msg_rtime); 2182 prtime(pri, " ct = ", msgq.msg_ctime); 2183 } 2184 } 2185 2186 void 2187 show_msgbuf(private_t *pri, long offset, long msgsz) 2188 { 2189 struct msgbuf msgb; 2190 2191 if (offset != 0 && 2192 Pread(Proc, &msgb, sizeof (msgb.mtype), offset) == 2193 sizeof (msgb.mtype)) { 2194 /* enter region of lengthy output */ 2195 if (msgsz > MYBUFSIZ / 4) 2196 Eserialize(); 2197 2198 (void) printf("%s\tmtype=%lu mtext[]=\n", 2199 pri->pname, 2200 msgb.mtype); 2201 showbuffer(pri, 2202 (long)(offset + sizeof (msgb.mtype)), msgsz); 2203 2204 /* exit region of lengthy output */ 2205 if (msgsz > MYBUFSIZ / 4) 2206 Xserialize(); 2207 } 2208 } 2209 2210 void 2211 show_msgbuf32(private_t *pri, long offset, long msgsz) 2212 { 2213 struct ipcmsgbuf32 msgb; 2214 2215 if (offset != 0 && 2216 Pread(Proc, &msgb, sizeof (msgb.mtype), offset) == 2217 sizeof (msgb.mtype)) { 2218 /* enter region of lengthy output */ 2219 if (msgsz > MYBUFSIZ / 4) 2220 Eserialize(); 2221 2222 (void) printf("%s\tmtype=%u mtext[]=\n", 2223 pri->pname, 2224 msgb.mtype); 2225 showbuffer(pri, 2226 (long)(offset + sizeof (msgb.mtype)), msgsz); 2227 2228 /* exit region of lengthy output */ 2229 if (msgsz > MYBUFSIZ / 4) 2230 Xserialize(); 2231 } 2232 } 2233 2234 void 2235 show_msgsys(private_t *pri, long msgsz) 2236 { 2237 switch (pri->sys_args[0]) { 2238 case 0: /* msgget() */ 2239 break; 2240 case 1: /* msgctl() */ 2241 if (pri->sys_nargs > 3) { 2242 switch (pri->sys_args[2]) { 2243 case IPC_STAT: 2244 if (pri->Errno) 2245 break; 2246 /*FALLTHROUGH*/ 2247 case IPC_SET: 2248 if (data_model == PR_MODEL_LP64) 2249 show_msgctl(pri, 2250 (long)pri->sys_args[3]); 2251 else 2252 show_msgctl32(pri, 2253 (long)pri->sys_args[3]); 2254 break; 2255 case IPC_STAT64: 2256 if (pri->Errno) 2257 break; 2258 /*FALLTHROUGH*/ 2259 case IPC_SET64: 2260 show_msgctl64(pri, (long)pri->sys_args[3]); 2261 break; 2262 } 2263 } 2264 break; 2265 case 2: /* msgrcv() */ 2266 if (!pri->Errno && pri->sys_nargs > 2) { 2267 if (data_model == PR_MODEL_LP64) 2268 show_msgbuf(pri, pri->sys_args[2], msgsz); 2269 else 2270 show_msgbuf32(pri, pri->sys_args[2], msgsz); 2271 } 2272 break; 2273 case 3: /* msgsnd() */ 2274 if (pri->sys_nargs > 3) { 2275 if (data_model == PR_MODEL_LP64) 2276 show_msgbuf(pri, pri->sys_args[2], 2277 pri->sys_args[3]); 2278 else 2279 show_msgbuf32(pri, pri->sys_args[2], 2280 pri->sys_args[3]); 2281 } 2282 break; 2283 case 4: /* msgids() */ 2284 case 5: /* msgsnap() */ 2285 default: /* unexpected subcode */ 2286 break; 2287 } 2288 } 2289 2290 static void 2291 show_semctl64(private_t *pri, long offset) 2292 { 2293 struct semid_ds64 semds; 2294 2295 if (offset != 0 && 2296 Pread(Proc, &semds, sizeof (semds), offset) == sizeof (semds)) { 2297 show_perm64(pri, &semds.semx_perm); 2298 2299 (void) printf("%s\tnsems=%u\n", pri->pname, semds.semx_nsems); 2300 2301 prtime(pri, " ot = ", (time_t)semds.semx_otime); 2302 prtime(pri, " ct = ", (time_t)semds.semx_ctime); 2303 } 2304 } 2305 2306 void 2307 show_semctl(private_t *pri, long offset) 2308 { 2309 struct semid_ds semds; 2310 2311 if (offset != 0 && 2312 Pread(Proc, &semds, sizeof (semds), offset) == sizeof (semds)) { 2313 show_perm(pri, &semds.sem_perm); 2314 2315 (void) printf("%s\tnsems=%u\n", 2316 pri->pname, 2317 semds.sem_nsems); 2318 2319 prtime(pri, " ot = ", semds.sem_otime); 2320 prtime(pri, " ct = ", semds.sem_ctime); 2321 } 2322 } 2323 2324 void 2325 show_semctl32(private_t *pri, long offset) 2326 { 2327 struct semid_ds32 semds; 2328 2329 if (offset != 0 && 2330 Pread(Proc, &semds, sizeof (semds), offset) == sizeof (semds)) { 2331 show_perm32(pri, &semds.sem_perm); 2332 2333 (void) printf("%s\tnsems=%u\n", 2334 pri->pname, 2335 semds.sem_nsems); 2336 2337 prtime(pri, " ot = ", semds.sem_otime); 2338 prtime(pri, " ct = ", semds.sem_ctime); 2339 } 2340 } 2341 2342 void 2343 show_semop(private_t *pri, long offset, long nsops, long timeout) 2344 { 2345 struct sembuf sembuf; 2346 const char *str; 2347 2348 if (offset == 0) 2349 return; 2350 2351 if (nsops > 40) /* let's not be ridiculous */ 2352 nsops = 40; 2353 2354 for (; nsops > 0 && !interrupt; --nsops, offset += sizeof (sembuf)) { 2355 if (Pread(Proc, &sembuf, sizeof (sembuf), offset) != 2356 sizeof (sembuf)) 2357 break; 2358 2359 (void) printf("%s\tsemnum=%-5u semop=%-5d semflg=", 2360 pri->pname, 2361 sembuf.sem_num, 2362 sembuf.sem_op); 2363 2364 if (sembuf.sem_flg == 0) 2365 (void) printf("0\n"); 2366 else if ((str = semflags(pri, sembuf.sem_flg)) != NULL) 2367 (void) printf("%s\n", str); 2368 else 2369 (void) printf("0%.6o\n", sembuf.sem_flg); 2370 } 2371 if (timeout) 2372 show_timestruc(pri, timeout, "timeout"); 2373 } 2374 2375 void 2376 show_semsys(private_t *pri) 2377 { 2378 switch (pri->sys_args[0]) { 2379 case 0: /* semctl() */ 2380 if (pri->sys_nargs > 4) { 2381 switch (pri->sys_args[3]) { 2382 case IPC_STAT: 2383 if (pri->Errno) 2384 break; 2385 /*FALLTHROUGH*/ 2386 case IPC_SET: 2387 if (data_model == PR_MODEL_LP64) 2388 show_semctl(pri, 2389 (long)pri->sys_args[4]); 2390 else 2391 show_semctl32(pri, 2392 (long)pri->sys_args[4]); 2393 break; 2394 case IPC_STAT64: 2395 if (pri->Errno) 2396 break; 2397 /*FALLTHROUGH*/ 2398 case IPC_SET64: 2399 show_semctl64(pri, (long)pri->sys_args[4]); 2400 break; 2401 } 2402 } 2403 break; 2404 case 1: /* semget() */ 2405 break; 2406 case 2: /* semop() */ 2407 if (pri->sys_nargs > 3) 2408 show_semop(pri, (long)pri->sys_args[2], 2409 pri->sys_args[3], 0); 2410 break; 2411 case 3: /* semids() */ 2412 break; 2413 case 4: /* semtimedop() */ 2414 if (pri->sys_nargs > 4) 2415 show_semop(pri, (long)pri->sys_args[2], 2416 pri->sys_args[3], pri->sys_args[4]); 2417 break; 2418 default: /* unexpected subcode */ 2419 break; 2420 } 2421 } 2422 2423 static void 2424 show_shmctl64(private_t *pri, long offset) 2425 { 2426 struct shmid_ds64 shmds; 2427 2428 if (offset != 0 && 2429 Pread(Proc, &shmds, sizeof (shmds), offset) == sizeof (shmds)) { 2430 show_perm64(pri, &shmds.shmx_perm); 2431 2432 (void) printf( 2433 "%s\tsize=%-6llu lpid=%-5d cpid=%-5d na=%-5llu cna=%llu\n", 2434 pri->pname, 2435 (unsigned long long)shmds.shmx_segsz, 2436 (int)shmds.shmx_lpid, 2437 (int)shmds.shmx_cpid, 2438 (unsigned long long)shmds.shmx_nattch, 2439 (unsigned long long)shmds.shmx_cnattch); 2440 2441 prtime(pri, " at = ", (time_t)shmds.shmx_atime); 2442 prtime(pri, " dt = ", (time_t)shmds.shmx_dtime); 2443 prtime(pri, " ct = ", (time_t)shmds.shmx_ctime); 2444 } 2445 } 2446 2447 void 2448 show_shmctl(private_t *pri, long offset) 2449 { 2450 struct shmid_ds shmds; 2451 2452 if (offset != 0 && 2453 Pread(Proc, &shmds, sizeof (shmds), offset) == sizeof (shmds)) { 2454 show_perm(pri, &shmds.shm_perm); 2455 2456 (void) printf( 2457 "%s\tsize=%-6lu lpid=%-5u cpid=%-5u na=%-5lu cna=%lu\n", 2458 pri->pname, 2459 (ulong_t)shmds.shm_segsz, 2460 (int)shmds.shm_lpid, 2461 (int)shmds.shm_cpid, 2462 shmds.shm_nattch, 2463 shmds.shm_cnattch); 2464 2465 prtime(pri, " at = ", shmds.shm_atime); 2466 prtime(pri, " dt = ", shmds.shm_dtime); 2467 prtime(pri, " ct = ", shmds.shm_ctime); 2468 } 2469 } 2470 2471 void 2472 show_shmctl32(private_t *pri, long offset) 2473 { 2474 struct shmid_ds32 shmds; 2475 2476 if (offset != 0 && 2477 Pread(Proc, &shmds, sizeof (shmds), offset) == sizeof (shmds)) { 2478 show_perm32(pri, &shmds.shm_perm); 2479 2480 (void) printf( 2481 "%s\tsize=%-6u lpid=%-5u cpid=%-5u na=%-5u cna=%u\n", 2482 pri->pname, 2483 shmds.shm_segsz, 2484 shmds.shm_lpid, 2485 shmds.shm_cpid, 2486 shmds.shm_nattch, 2487 shmds.shm_cnattch); 2488 2489 prtime(pri, " at = ", shmds.shm_atime); 2490 prtime(pri, " dt = ", shmds.shm_dtime); 2491 prtime(pri, " ct = ", shmds.shm_ctime); 2492 } 2493 } 2494 2495 void 2496 show_shmsys(private_t *pri) 2497 { 2498 switch (pri->sys_args[0]) { 2499 case 0: /* shmat() */ 2500 break; 2501 case 1: /* shmctl() */ 2502 if (pri->sys_nargs > 3) { 2503 switch (pri->sys_args[2]) { 2504 case IPC_STAT: 2505 if (pri->Errno) 2506 break; 2507 /*FALLTHROUGH*/ 2508 case IPC_SET: 2509 if (data_model == PR_MODEL_LP64) 2510 show_shmctl(pri, 2511 (long)pri->sys_args[3]); 2512 else 2513 show_shmctl32(pri, 2514 (long)pri->sys_args[3]); 2515 break; 2516 case IPC_STAT64: 2517 if (pri->Errno) 2518 break; 2519 /*FALLTHROUGH*/ 2520 case IPC_SET64: 2521 show_shmctl64(pri, (long)pri->sys_args[3]); 2522 break; 2523 } 2524 } 2525 break; 2526 case 2: /* shmdt() */ 2527 case 3: /* shmget() */ 2528 case 4: /* shmids() */ 2529 default: /* unexpected subcode */ 2530 break; 2531 } 2532 } 2533 2534 void 2535 show_groups(private_t *pri, long offset, long count) 2536 { 2537 int groups[100]; 2538 2539 if (count > 100) 2540 count = 100; 2541 2542 if (count > 0 && offset != 0 && 2543 Pread(Proc, &groups[0], count*sizeof (int), offset) == 2544 count*sizeof (int)) { 2545 int n; 2546 2547 (void) printf("%s\t", pri->pname); 2548 for (n = 0; !interrupt && n < count; n++) { 2549 if (n != 0 && n%10 == 0) 2550 (void) printf("\n%s\t", pri->pname); 2551 (void) printf(" %5d", groups[n]); 2552 } 2553 (void) fputc('\n', stdout); 2554 } 2555 } 2556 2557 /* 2558 * This assumes that a sigset_t is simply an array of ints. 2559 */ 2560 char * 2561 sigset_string(private_t *pri, sigset_t *sp) 2562 { 2563 char *s = pri->code_buf; 2564 int n = sizeof (*sp) / sizeof (int32_t); 2565 int32_t *lp = (int32_t *)sp; 2566 2567 while (--n >= 0) { 2568 int32_t val = *lp++; 2569 2570 if (val == 0) 2571 s += sprintf(s, " 0"); 2572 else 2573 s += sprintf(s, " 0x%.8X", val); 2574 } 2575 2576 return (pri->code_buf); 2577 } 2578 2579 void 2580 show_sigset(private_t *pri, long offset, const char *name) 2581 { 2582 sigset_t sigset; 2583 2584 if (offset != 0 && 2585 Pread(Proc, &sigset, sizeof (sigset), offset) == sizeof (sigset)) { 2586 (void) printf("%s\t%s =%s\n", 2587 pri->pname, name, sigset_string(pri, &sigset)); 2588 } 2589 } 2590 2591 void 2592 show_sigaltstack32(private_t *pri, long offset, const char *name) 2593 { 2594 struct sigaltstack32 altstack; 2595 2596 if (offset != 0 && 2597 Pread(Proc, &altstack, sizeof (altstack), offset) == 2598 sizeof (altstack)) { 2599 (void) printf("%s\t%s: sp=0x%.8X size=%u flags=0x%.4X\n", 2600 pri->pname, 2601 name, 2602 altstack.ss_sp, 2603 altstack.ss_size, 2604 altstack.ss_flags); 2605 } 2606 } 2607 2608 void 2609 show_sigaltstack(private_t *pri, long offset, const char *name) 2610 { 2611 struct sigaltstack altstack; 2612 2613 if (data_model != PR_MODEL_LP64) { 2614 show_sigaltstack32(pri, offset, name); 2615 return; 2616 } 2617 if (offset != 0 && 2618 Pread(Proc, &altstack, sizeof (altstack), offset) == 2619 sizeof (altstack)) { 2620 (void) printf("%s\t%s: sp=0x%.8lX size=%lu flags=0x%.4X\n", 2621 pri->pname, 2622 name, 2623 (ulong_t)altstack.ss_sp, 2624 (ulong_t)altstack.ss_size, 2625 altstack.ss_flags); 2626 } 2627 } 2628 2629 void 2630 show_sigaction32(private_t *pri, long offset, const char *name, long odisp) 2631 { 2632 struct sigaction32 sigaction; 2633 2634 if (offset != 0 && 2635 Pread(Proc, &sigaction, sizeof (sigaction), offset) == 2636 sizeof (sigaction)) { 2637 /* This is stupid, we shouldn't have to do this */ 2638 if (odisp != 0) 2639 sigaction.sa_handler = (caddr32_t)odisp; 2640 (void) printf( 2641 "%s %s: hand = 0x%.8X mask =%s flags = 0x%.4X\n", 2642 pri->pname, 2643 name, 2644 sigaction.sa_handler, 2645 sigset_string(pri, (sigset_t *)&sigaction.sa_mask), 2646 sigaction.sa_flags); 2647 } 2648 } 2649 2650 void 2651 show_sigaction(private_t *pri, long offset, const char *name, long odisp) 2652 { 2653 struct sigaction sigaction; 2654 2655 if (data_model != PR_MODEL_LP64) { 2656 show_sigaction32(pri, offset, name, odisp); 2657 return; 2658 } 2659 if (offset != 0 && 2660 Pread(Proc, &sigaction, sizeof (sigaction), offset) == 2661 sizeof (sigaction)) { 2662 /* This is stupid, we shouldn't have to do this */ 2663 if (odisp != 0) 2664 sigaction.sa_handler = (void (*)())odisp; 2665 (void) printf( 2666 "%s %s: hand = 0x%.8lX mask =%s flags = 0x%.4X\n", 2667 pri->pname, 2668 name, 2669 (long)sigaction.sa_handler, 2670 sigset_string(pri, &sigaction.sa_mask), 2671 sigaction.sa_flags); 2672 } 2673 } 2674 2675 void 2676 print_siginfo32(private_t *pri, const siginfo32_t *sip) 2677 { 2678 const char *code = NULL; 2679 2680 (void) printf("%s siginfo: %s", pri->pname, 2681 signame(pri, sip->si_signo)); 2682 2683 if (sip->si_signo != 0 && SI_FROMUSER(sip) && sip->si_pid != 0) { 2684 (void) printf(" pid=%d uid=%d", sip->si_pid, sip->si_uid); 2685 if (sip->si_code != 0) 2686 (void) printf(" code=%d", sip->si_code); 2687 (void) fputc('\n', stdout); 2688 return; 2689 } 2690 2691 switch (sip->si_signo) { 2692 default: 2693 (void) fputc('\n', stdout); 2694 return; 2695 case SIGILL: 2696 case SIGTRAP: 2697 case SIGFPE: 2698 case SIGSEGV: 2699 case SIGBUS: 2700 case SIGEMT: 2701 case SIGCLD: 2702 case SIGPOLL: 2703 case SIGXFSZ: 2704 break; 2705 } 2706 2707 switch (sip->si_signo) { 2708 case SIGILL: 2709 switch (sip->si_code) { 2710 case ILL_ILLOPC: code = "ILL_ILLOPC"; break; 2711 case ILL_ILLOPN: code = "ILL_ILLOPN"; break; 2712 case ILL_ILLADR: code = "ILL_ILLADR"; break; 2713 case ILL_ILLTRP: code = "ILL_ILLTRP"; break; 2714 case ILL_PRVOPC: code = "ILL_PRVOPC"; break; 2715 case ILL_PRVREG: code = "ILL_PRVREG"; break; 2716 case ILL_COPROC: code = "ILL_COPROC"; break; 2717 case ILL_BADSTK: code = "ILL_BADSTK"; break; 2718 } 2719 break; 2720 case SIGTRAP: 2721 switch (sip->si_code) { 2722 case TRAP_BRKPT: code = "TRAP_BRKPT"; break; 2723 case TRAP_TRACE: code = "TRAP_TRACE"; break; 2724 case TRAP_RWATCH: code = "TRAP_RWATCH"; break; 2725 case TRAP_WWATCH: code = "TRAP_WWATCH"; break; 2726 case TRAP_XWATCH: code = "TRAP_XWATCH"; break; 2727 case TRAP_DTRACE: code = "TRAP_DTRACE"; break; 2728 } 2729 break; 2730 case SIGFPE: 2731 switch (sip->si_code) { 2732 case FPE_INTDIV: code = "FPE_INTDIV"; break; 2733 case FPE_INTOVF: code = "FPE_INTOVF"; break; 2734 case FPE_FLTDIV: code = "FPE_FLTDIV"; break; 2735 case FPE_FLTOVF: code = "FPE_FLTOVF"; break; 2736 case FPE_FLTUND: code = "FPE_FLTUND"; break; 2737 case FPE_FLTRES: code = "FPE_FLTRES"; break; 2738 case FPE_FLTINV: code = "FPE_FLTINV"; break; 2739 case FPE_FLTSUB: code = "FPE_FLTSUB"; break; 2740 #if defined(FPE_FLTDEN) 2741 case FPE_FLTDEN: code = "FPE_FLTDEN"; break; 2742 #endif 2743 } 2744 break; 2745 case SIGSEGV: 2746 switch (sip->si_code) { 2747 case SEGV_MAPERR: code = "SEGV_MAPERR"; break; 2748 case SEGV_ACCERR: code = "SEGV_ACCERR"; break; 2749 } 2750 break; 2751 case SIGEMT: 2752 switch (sip->si_code) { 2753 #ifdef EMT_TAGOVF 2754 case EMT_TAGOVF: code = "EMT_TAGOVF"; break; 2755 #endif 2756 case EMT_CPCOVF: code = "EMT_CPCOVF"; break; 2757 } 2758 break; 2759 case SIGBUS: 2760 switch (sip->si_code) { 2761 case BUS_ADRALN: code = "BUS_ADRALN"; break; 2762 case BUS_ADRERR: code = "BUS_ADRERR"; break; 2763 case BUS_OBJERR: code = "BUS_OBJERR"; break; 2764 } 2765 break; 2766 case SIGCLD: 2767 switch (sip->si_code) { 2768 case CLD_EXITED: code = "CLD_EXITED"; break; 2769 case CLD_KILLED: code = "CLD_KILLED"; break; 2770 case CLD_DUMPED: code = "CLD_DUMPED"; break; 2771 case CLD_TRAPPED: code = "CLD_TRAPPED"; break; 2772 case CLD_STOPPED: code = "CLD_STOPPED"; break; 2773 case CLD_CONTINUED: code = "CLD_CONTINUED"; break; 2774 } 2775 break; 2776 case SIGPOLL: 2777 switch (sip->si_code) { 2778 case POLL_IN: code = "POLL_IN"; break; 2779 case POLL_OUT: code = "POLL_OUT"; break; 2780 case POLL_MSG: code = "POLL_MSG"; break; 2781 case POLL_ERR: code = "POLL_ERR"; break; 2782 case POLL_PRI: code = "POLL_PRI"; break; 2783 case POLL_HUP: code = "POLL_HUP"; break; 2784 } 2785 break; 2786 } 2787 2788 if (code == NULL) { 2789 (void) sprintf(pri->code_buf, "code=%d", sip->si_code); 2790 code = (const char *)pri->code_buf; 2791 } 2792 2793 switch (sip->si_signo) { 2794 case SIGILL: 2795 case SIGTRAP: 2796 case SIGFPE: 2797 case SIGSEGV: 2798 case SIGBUS: 2799 case SIGEMT: 2800 (void) printf(" %s addr=0x%.8X", 2801 code, 2802 sip->si_addr); 2803 break; 2804 case SIGCLD: 2805 (void) printf(" %s pid=%d status=0x%.4X", 2806 code, 2807 sip->si_pid, 2808 sip->si_status); 2809 break; 2810 case SIGPOLL: 2811 case SIGXFSZ: 2812 (void) printf(" %s fd=%d band=%d", 2813 code, 2814 sip->si_fd, 2815 sip->si_band); 2816 break; 2817 } 2818 2819 if (sip->si_errno != 0) { 2820 const char *ename = errname(sip->si_errno); 2821 2822 (void) printf(" errno=%d", sip->si_errno); 2823 if (ename != NULL) 2824 (void) printf("(%s)", ename); 2825 } 2826 2827 (void) fputc('\n', stdout); 2828 } 2829 2830 void 2831 print_siginfo(private_t *pri, const siginfo_t *sip) 2832 { 2833 const char *code = NULL; 2834 2835 (void) printf("%s siginfo: %s", pri->pname, 2836 signame(pri, sip->si_signo)); 2837 2838 if (sip->si_signo != 0 && SI_FROMUSER(sip) && sip->si_pid != 0) { 2839 (void) printf(" pid=%d uid=%u", 2840 (int)sip->si_pid, 2841 sip->si_uid); 2842 if (sip->si_code != 0) 2843 (void) printf(" code=%d", sip->si_code); 2844 (void) fputc('\n', stdout); 2845 return; 2846 } 2847 2848 switch (sip->si_signo) { 2849 default: 2850 (void) fputc('\n', stdout); 2851 return; 2852 case SIGILL: 2853 case SIGTRAP: 2854 case SIGFPE: 2855 case SIGSEGV: 2856 case SIGBUS: 2857 case SIGEMT: 2858 case SIGCLD: 2859 case SIGPOLL: 2860 case SIGXFSZ: 2861 break; 2862 } 2863 2864 switch (sip->si_signo) { 2865 case SIGILL: 2866 switch (sip->si_code) { 2867 case ILL_ILLOPC: code = "ILL_ILLOPC"; break; 2868 case ILL_ILLOPN: code = "ILL_ILLOPN"; break; 2869 case ILL_ILLADR: code = "ILL_ILLADR"; break; 2870 case ILL_ILLTRP: code = "ILL_ILLTRP"; break; 2871 case ILL_PRVOPC: code = "ILL_PRVOPC"; break; 2872 case ILL_PRVREG: code = "ILL_PRVREG"; break; 2873 case ILL_COPROC: code = "ILL_COPROC"; break; 2874 case ILL_BADSTK: code = "ILL_BADSTK"; break; 2875 } 2876 break; 2877 case SIGTRAP: 2878 switch (sip->si_code) { 2879 case TRAP_BRKPT: code = "TRAP_BRKPT"; break; 2880 case TRAP_TRACE: code = "TRAP_TRACE"; break; 2881 case TRAP_RWATCH: code = "TRAP_RWATCH"; break; 2882 case TRAP_WWATCH: code = "TRAP_WWATCH"; break; 2883 case TRAP_XWATCH: code = "TRAP_XWATCH"; break; 2884 case TRAP_DTRACE: code = "TRAP_DTRACE"; break; 2885 } 2886 break; 2887 case SIGFPE: 2888 switch (sip->si_code) { 2889 case FPE_INTDIV: code = "FPE_INTDIV"; break; 2890 case FPE_INTOVF: code = "FPE_INTOVF"; break; 2891 case FPE_FLTDIV: code = "FPE_FLTDIV"; break; 2892 case FPE_FLTOVF: code = "FPE_FLTOVF"; break; 2893 case FPE_FLTUND: code = "FPE_FLTUND"; break; 2894 case FPE_FLTRES: code = "FPE_FLTRES"; break; 2895 case FPE_FLTINV: code = "FPE_FLTINV"; break; 2896 case FPE_FLTSUB: code = "FPE_FLTSUB"; break; 2897 #if defined(FPE_FLTDEN) 2898 case FPE_FLTDEN: code = "FPE_FLTDEN"; break; 2899 #endif 2900 } 2901 break; 2902 case SIGSEGV: 2903 switch (sip->si_code) { 2904 case SEGV_MAPERR: code = "SEGV_MAPERR"; break; 2905 case SEGV_ACCERR: code = "SEGV_ACCERR"; break; 2906 } 2907 break; 2908 case SIGEMT: 2909 switch (sip->si_code) { 2910 #ifdef EMT_TAGOVF 2911 case EMT_TAGOVF: code = "EMT_TAGOVF"; break; 2912 #endif 2913 case EMT_CPCOVF: code = "EMT_CPCOVF"; break; 2914 } 2915 break; 2916 case SIGBUS: 2917 switch (sip->si_code) { 2918 case BUS_ADRALN: code = "BUS_ADRALN"; break; 2919 case BUS_ADRERR: code = "BUS_ADRERR"; break; 2920 case BUS_OBJERR: code = "BUS_OBJERR"; break; 2921 } 2922 break; 2923 case SIGCLD: 2924 switch (sip->si_code) { 2925 case CLD_EXITED: code = "CLD_EXITED"; break; 2926 case CLD_KILLED: code = "CLD_KILLED"; break; 2927 case CLD_DUMPED: code = "CLD_DUMPED"; break; 2928 case CLD_TRAPPED: code = "CLD_TRAPPED"; break; 2929 case CLD_STOPPED: code = "CLD_STOPPED"; break; 2930 case CLD_CONTINUED: code = "CLD_CONTINUED"; break; 2931 } 2932 break; 2933 case SIGPOLL: 2934 switch (sip->si_code) { 2935 case POLL_IN: code = "POLL_IN"; break; 2936 case POLL_OUT: code = "POLL_OUT"; break; 2937 case POLL_MSG: code = "POLL_MSG"; break; 2938 case POLL_ERR: code = "POLL_ERR"; break; 2939 case POLL_PRI: code = "POLL_PRI"; break; 2940 case POLL_HUP: code = "POLL_HUP"; break; 2941 } 2942 break; 2943 } 2944 2945 if (code == NULL) { 2946 (void) sprintf(pri->code_buf, "code=%d", sip->si_code); 2947 code = (const char *)pri->code_buf; 2948 } 2949 2950 switch (sip->si_signo) { 2951 case SIGILL: 2952 case SIGTRAP: 2953 case SIGFPE: 2954 case SIGSEGV: 2955 case SIGBUS: 2956 case SIGEMT: 2957 (void) printf(" %s addr=0x%.8lX", 2958 code, 2959 (long)sip->si_addr); 2960 break; 2961 case SIGCLD: 2962 (void) printf(" %s pid=%d status=0x%.4X", 2963 code, 2964 (int)sip->si_pid, 2965 sip->si_status); 2966 break; 2967 case SIGPOLL: 2968 case SIGXFSZ: 2969 (void) printf(" %s fd=%d band=%ld", 2970 code, 2971 sip->si_fd, 2972 sip->si_band); 2973 break; 2974 } 2975 2976 if (sip->si_errno != 0) { 2977 const char *ename = errname(sip->si_errno); 2978 2979 (void) printf(" errno=%d", sip->si_errno); 2980 if (ename != NULL) 2981 (void) printf("(%s)", ename); 2982 } 2983 2984 (void) fputc('\n', stdout); 2985 } 2986 2987 void 2988 show_siginfo32(private_t *pri, long offset) 2989 { 2990 struct siginfo32 siginfo; 2991 2992 if (offset != 0 && 2993 Pread(Proc, &siginfo, sizeof (siginfo), offset) == sizeof (siginfo)) 2994 print_siginfo32(pri, &siginfo); 2995 } 2996 2997 void 2998 show_siginfo(private_t *pri, long offset) 2999 { 3000 struct siginfo siginfo; 3001 3002 if (data_model != PR_MODEL_LP64) { 3003 show_siginfo32(pri, offset); 3004 return; 3005 } 3006 if (offset != 0 && 3007 Pread(Proc, &siginfo, sizeof (siginfo), offset) == sizeof (siginfo)) 3008 print_siginfo(pri, &siginfo); 3009 } 3010 3011 void 3012 show_bool(private_t *pri, long offset, int count) 3013 { 3014 int serial = (count > MYBUFSIZ / 4); 3015 3016 /* enter region of lengthy output */ 3017 if (serial) 3018 Eserialize(); 3019 3020 while (count > 0) { 3021 char buf[32]; 3022 int nb = (count < 32)? count : 32; 3023 int i; 3024 3025 if (Pread(Proc, buf, (size_t)nb, offset) != nb) 3026 break; 3027 3028 (void) printf("%s ", pri->pname); 3029 for (i = 0; i < nb; i++) 3030 (void) printf(" %d", buf[i]); 3031 (void) fputc('\n', stdout); 3032 3033 count -= nb; 3034 offset += nb; 3035 } 3036 3037 /* exit region of lengthy output */ 3038 if (serial) 3039 Xserialize(); 3040 } 3041 3042 void 3043 show_iovec32(private_t *pri, long offset, int niov, int showbuf, long count) 3044 { 3045 iovec32_t iovec[16]; 3046 iovec32_t *ip; 3047 long nb; 3048 int serial = (count > MYBUFSIZ / 4 && showbuf); 3049 3050 if (niov > 16) /* is this the real limit? */ 3051 niov = 16; 3052 3053 if (offset != 0 && niov > 0 && 3054 Pread(Proc, &iovec[0], niov*sizeof (iovec32_t), offset) 3055 == niov*sizeof (iovec32_t)) { 3056 /* enter region of lengthy output */ 3057 if (serial) 3058 Eserialize(); 3059 3060 for (ip = &iovec[0]; niov-- && !interrupt; ip++) { 3061 (void) printf("%s\tiov_base = 0x%.8X iov_len = %d\n", 3062 pri->pname, 3063 ip->iov_base, 3064 ip->iov_len); 3065 if ((nb = count) > 0) { 3066 if (nb > ip->iov_len) 3067 nb = ip->iov_len; 3068 if (nb > 0) 3069 count -= nb; 3070 } 3071 if (showbuf && nb > 0) 3072 showbuffer(pri, (long)ip->iov_base, nb); 3073 } 3074 3075 /* exit region of lengthy output */ 3076 if (serial) 3077 Xserialize(); 3078 } 3079 } 3080 3081 void 3082 show_iovec(private_t *pri, long offset, long niov, int showbuf, long count) 3083 { 3084 iovec_t iovec[16]; 3085 iovec_t *ip; 3086 long nb; 3087 int serial = (count > MYBUFSIZ / 4 && showbuf); 3088 3089 if (data_model != PR_MODEL_LP64) { 3090 show_iovec32(pri, offset, niov, showbuf, count); 3091 return; 3092 } 3093 if (niov > 16) /* is this the real limit? */ 3094 niov = 16; 3095 3096 if (offset != 0 && niov > 0 && 3097 Pread(Proc, &iovec[0], niov*sizeof (iovec_t), offset) 3098 == niov*sizeof (iovec_t)) { 3099 /* enter region of lengthy output */ 3100 if (serial) 3101 Eserialize(); 3102 3103 for (ip = &iovec[0]; niov-- && !interrupt; ip++) { 3104 (void) printf("%s\tiov_base = 0x%.8lX iov_len = %lu\n", 3105 pri->pname, 3106 (long)ip->iov_base, 3107 ip->iov_len); 3108 if ((nb = count) > 0) { 3109 if (nb > ip->iov_len) 3110 nb = ip->iov_len; 3111 if (nb > 0) 3112 count -= nb; 3113 } 3114 if (showbuf && nb > 0) 3115 showbuffer(pri, (long)ip->iov_base, nb); 3116 } 3117 3118 /* exit region of lengthy output */ 3119 if (serial) 3120 Xserialize(); 3121 } 3122 } 3123 3124 void 3125 show_dents32(private_t *pri, long offset, long count) 3126 { 3127 long buf[MYBUFSIZ / sizeof (long)]; 3128 struct dirent32 *dp; 3129 int serial = (count > 100); 3130 3131 if (offset == 0) 3132 return; 3133 3134 /* enter region of lengthy output */ 3135 if (serial) 3136 Eserialize(); 3137 3138 while (count > 0 && !interrupt) { 3139 int nb = count < MYBUFSIZ? (int)count : MYBUFSIZ; 3140 3141 if ((nb = Pread(Proc, &buf[0], (size_t)nb, offset)) <= 0) 3142 break; 3143 3144 dp = (struct dirent32 *)&buf[0]; 3145 if (nb < (int)(dp->d_name - (char *)dp)) 3146 break; 3147 if ((unsigned)nb < dp->d_reclen) { 3148 /* getdents() error? */ 3149 (void) printf( 3150 "%s ino=%-5u off=%-4d rlen=%-3d\n", 3151 pri->pname, 3152 dp->d_ino, 3153 dp->d_off, 3154 dp->d_reclen); 3155 break; 3156 } 3157 3158 while (!interrupt && 3159 nb >= (int)(dp->d_name - (char *)dp) && 3160 (unsigned)nb >= dp->d_reclen) { 3161 (void) printf( 3162 "%s ino=%-5u off=%-4d rlen=%-3d \"%.*s\"\n", 3163 pri->pname, 3164 dp->d_ino, 3165 dp->d_off, 3166 dp->d_reclen, 3167 dp->d_reclen - (int)(dp->d_name - (char *)dp), 3168 dp->d_name); 3169 nb -= dp->d_reclen; 3170 count -= dp->d_reclen; 3171 offset += dp->d_reclen; 3172 /* LINTED improper alignment */ 3173 dp = (struct dirent32 *)((char *)dp + dp->d_reclen); 3174 } 3175 } 3176 3177 /* exit region of lengthy output */ 3178 if (serial) 3179 Xserialize(); 3180 } 3181 3182 void 3183 show_dents64(private_t *pri, long offset, long count) 3184 { 3185 long long buf[MYBUFSIZ / sizeof (long long)]; 3186 struct dirent64 *dp; 3187 int serial = (count > 100); 3188 3189 if (offset == 0) 3190 return; 3191 3192 /* enter region of lengthy output */ 3193 if (serial) 3194 Eserialize(); 3195 3196 while (count > 0 && !interrupt) { 3197 int nb = count < MYBUFSIZ? (int)count : MYBUFSIZ; 3198 3199 if ((nb = Pread(Proc, &buf[0], (size_t)nb, offset)) <= 0) 3200 break; 3201 3202 dp = (struct dirent64 *)&buf[0]; 3203 if (nb < (int)(dp->d_name - (char *)dp)) 3204 break; 3205 if ((unsigned)nb < dp->d_reclen) { 3206 /* getdents() error? */ 3207 (void) printf( 3208 "%s ino=%-5llu off=%-4lld rlen=%-3d\n", 3209 pri->pname, 3210 (long long)dp->d_ino, 3211 (long long)dp->d_off, 3212 dp->d_reclen); 3213 break; 3214 } 3215 3216 while (!interrupt && 3217 nb >= (int)(dp->d_name - (char *)dp) && 3218 (unsigned)nb >= dp->d_reclen) { 3219 (void) printf( 3220 "%s ino=%-5llu off=%-4lld rlen=%-3d \"%.*s\"\n", 3221 pri->pname, 3222 (long long)dp->d_ino, 3223 (long long)dp->d_off, 3224 dp->d_reclen, 3225 dp->d_reclen - (int)(dp->d_name - (char *)dp), 3226 dp->d_name); 3227 nb -= dp->d_reclen; 3228 count -= dp->d_reclen; 3229 offset += dp->d_reclen; 3230 /* LINTED improper alignment */ 3231 dp = (struct dirent64 *)((char *)dp + dp->d_reclen); 3232 } 3233 } 3234 3235 /* exit region of lengthy output */ 3236 if (serial) 3237 Xserialize(); 3238 } 3239 3240 void 3241 show_rlimit32(private_t *pri, long offset) 3242 { 3243 struct rlimit32 rlimit; 3244 3245 if (offset != 0 && 3246 Pread(Proc, &rlimit, sizeof (rlimit), offset) == sizeof (rlimit)) { 3247 (void) printf("%s\t", pri->pname); 3248 switch (rlimit.rlim_cur) { 3249 case RLIM32_INFINITY: 3250 (void) fputs("cur = RLIM_INFINITY", stdout); 3251 break; 3252 case RLIM32_SAVED_MAX: 3253 (void) fputs("cur = RLIM_SAVED_MAX", stdout); 3254 break; 3255 case RLIM32_SAVED_CUR: 3256 (void) fputs("cur = RLIM_SAVED_CUR", stdout); 3257 break; 3258 default: 3259 (void) printf("cur = %lu", (long)rlimit.rlim_cur); 3260 break; 3261 } 3262 switch (rlimit.rlim_max) { 3263 case RLIM32_INFINITY: 3264 (void) fputs(" max = RLIM_INFINITY\n", stdout); 3265 break; 3266 case RLIM32_SAVED_MAX: 3267 (void) fputs(" max = RLIM_SAVED_MAX\n", stdout); 3268 break; 3269 case RLIM32_SAVED_CUR: 3270 (void) fputs(" max = RLIM_SAVED_CUR\n", stdout); 3271 break; 3272 default: 3273 (void) printf(" max = %lu\n", (long)rlimit.rlim_max); 3274 break; 3275 } 3276 } 3277 } 3278 3279 void 3280 show_rlimit64(private_t *pri, long offset) 3281 { 3282 struct rlimit64 rlimit; 3283 3284 if (offset != 0 && 3285 Pread(Proc, &rlimit, sizeof (rlimit), offset) == sizeof (rlimit)) { 3286 (void) printf("%s\t", pri->pname); 3287 switch (rlimit.rlim_cur) { 3288 case RLIM64_INFINITY: 3289 (void) fputs("cur = RLIM64_INFINITY", stdout); 3290 break; 3291 case RLIM64_SAVED_MAX: 3292 (void) fputs("cur = RLIM64_SAVED_MAX", stdout); 3293 break; 3294 case RLIM64_SAVED_CUR: 3295 (void) fputs("cur = RLIM64_SAVED_CUR", stdout); 3296 break; 3297 default: 3298 (void) printf("cur = %llu", 3299 (unsigned long long)rlimit.rlim_cur); 3300 break; 3301 } 3302 switch (rlimit.rlim_max) { 3303 case RLIM64_INFINITY: 3304 (void) fputs(" max = RLIM64_INFINITY\n", stdout); 3305 break; 3306 case RLIM64_SAVED_MAX: 3307 (void) fputs(" max = RLIM64_SAVED_MAX\n", stdout); 3308 break; 3309 case RLIM64_SAVED_CUR: 3310 (void) fputs(" max = RLIM64_SAVED_CUR\n", stdout); 3311 break; 3312 default: 3313 (void) printf(" max = %llu\n", 3314 (unsigned long long)rlimit.rlim_max); 3315 break; 3316 } 3317 } 3318 } 3319 3320 void 3321 show_nuname(private_t *pri, long offset) 3322 { 3323 struct utsname ubuf; 3324 3325 if (offset != 0 && 3326 Pread(Proc, &ubuf, sizeof (ubuf), offset) == sizeof (ubuf)) { 3327 (void) printf( 3328 "%s\tsys=%s nod=%s rel=%s ver=%s mch=%s\n", 3329 pri->pname, 3330 ubuf.sysname, 3331 ubuf.nodename, 3332 ubuf.release, 3333 ubuf.version, 3334 ubuf.machine); 3335 } 3336 } 3337 3338 void 3339 show_adjtime(private_t *pri, long off1, long off2) 3340 { 3341 show_timeval(pri, off1, " delta"); 3342 show_timeval(pri, off2, "olddelta"); 3343 } 3344 3345 void 3346 show_sockaddr(private_t *pri, 3347 const char *str, long addroff, long lenoff, long len) 3348 { 3349 /* 3350 * A buffer large enough for PATH_MAX size AF_UNIX address, which is 3351 * also large enough to store a sockaddr_in or a sockaddr_in6. 3352 */ 3353 long buf[(sizeof (short) + PATH_MAX + sizeof (long) - 1) 3354 / sizeof (long)]; 3355 struct sockaddr *sa = (struct sockaddr *)buf; 3356 struct sockaddr_in *sin = (struct sockaddr_in *)buf; 3357 struct sockaddr_un *soun = (struct sockaddr_un *)buf; 3358 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)buf; 3359 char addrbuf[INET6_ADDRSTRLEN]; 3360 3361 if (lenoff != 0) { 3362 uint_t ilen; 3363 if (Pread(Proc, &ilen, sizeof (ilen), lenoff) != sizeof (ilen)) 3364 return; 3365 len = ilen; 3366 } 3367 3368 if (len >= sizeof (buf)) /* protect against ridiculous length */ 3369 len = sizeof (buf) - 1; 3370 if (Pread(Proc, buf, len, addroff) != len) 3371 return; 3372 3373 switch (sa->sa_family) { 3374 case AF_INET6: 3375 (void) printf("%s\tAF_INET6 %s = %s port = %u\n", 3376 pri->pname, str, 3377 inet_ntop(AF_INET6, &sin6->sin6_addr, addrbuf, 3378 sizeof (addrbuf)), 3379 ntohs(sin6->sin6_port)); 3380 (void) printf("%s\tscope id = %u source id = 0x%x\n" 3381 "%s\tflow class = 0x%02x flow label = 0x%05x\n", 3382 pri->pname, ntohl(sin6->sin6_scope_id), 3383 ntohl(sin6->__sin6_src_id), 3384 pri->pname, 3385 ntohl((sin6->sin6_flowinfo & IPV6_FLOWINFO_TCLASS) >> 20), 3386 ntohl(sin6->sin6_flowinfo & IPV6_FLOWINFO_FLOWLABEL)); 3387 break; 3388 case AF_INET: 3389 (void) printf("%s\tAF_%s %s = %s port = %u\n", 3390 pri->pname, "INET", 3391 str, inet_ntop(AF_INET, &sin->sin_addr, addrbuf, 3392 sizeof (addrbuf)), ntohs(sin->sin_port)); 3393 break; 3394 case AF_UNIX: 3395 len -= sizeof (soun->sun_family); 3396 if (len >= 0) { 3397 /* Null terminate */ 3398 soun->sun_path[len] = 0; 3399 (void) printf("%s\tAF_UNIX %s = %s\n", pri->pname, 3400 str, soun->sun_path); 3401 } 3402 break; 3403 } 3404 } 3405 3406 void 3407 show_msghdr(private_t *pri, long offset) 3408 { 3409 const lwpstatus_t *Lsp = pri->lwpstat; 3410 int what = Lsp->pr_what; 3411 int err = pri->Errno; 3412 struct msghdr msg; 3413 int showbuf = FALSE; 3414 int i = pri->sys_args[0]+1; 3415 long nb = (what == SYS_recvmsg)? pri->Rval1 : 32*1024; 3416 3417 if (Pread(Proc, &msg, sizeof (msg), offset) != sizeof (msg)) 3418 return; 3419 3420 if (msg.msg_name != NULL && msg.msg_namelen != 0) 3421 show_sockaddr(pri, "msg_name", 3422 (long)msg.msg_name, 0, (long)msg.msg_namelen); 3423 3424 /* 3425 * Print the iovec if the syscall was successful and the fd is 3426 * part of the set being traced. 3427 */ 3428 if ((what == SYS_recvmsg && !err && 3429 prismember(&readfd, i)) || 3430 (what == SYS_sendmsg && 3431 prismember(&writefd, i))) 3432 showbuf = TRUE; 3433 3434 show_iovec(pri, (long)msg.msg_iov, msg.msg_iovlen, showbuf, nb); 3435 3436 } 3437 3438 void 3439 show_msghdr32(private_t *pri, long offset) 3440 { 3441 struct msghdr32 { 3442 caddr32_t msg_name; 3443 uint32_t msg_namelen; 3444 caddr32_t msg_iov; 3445 int32_t msg_iovlen; 3446 } msg; 3447 const lwpstatus_t *Lsp = pri->lwpstat; 3448 int what = Lsp->pr_what; 3449 int err = pri->Errno; 3450 int showbuf = FALSE; 3451 int i = pri->sys_args[0]+1; 3452 long nb = (what == SYS_recvmsg)? pri->Rval1 : 32*1024; 3453 3454 if (Pread(Proc, &msg, sizeof (msg), offset) != sizeof (msg)) 3455 return; 3456 3457 if (msg.msg_name != 0 && msg.msg_namelen != 0) 3458 show_sockaddr(pri, "msg_name", 3459 (long)msg.msg_name, 0, (long)msg.msg_namelen); 3460 /* 3461 * Print the iovec if the syscall was successful and the fd is 3462 * part of the set being traced. 3463 */ 3464 if ((what == SYS_recvmsg && !err && 3465 prismember(&readfd, i)) || 3466 (what == SYS_sendmsg && 3467 prismember(&writefd, i))) 3468 showbuf = TRUE; 3469 3470 show_iovec32(pri, (long)msg.msg_iov, msg.msg_iovlen, showbuf, nb); 3471 3472 } 3473 3474 static void 3475 show_doorargs(private_t *pri, long offset) 3476 { 3477 door_arg_t args; 3478 3479 if (Pread(Proc, &args, sizeof (args), offset) == sizeof (args)) { 3480 (void) printf("%s\tdata_ptr=0x%lX data_size=%lu\n", 3481 pri->pname, 3482 (ulong_t)args.data_ptr, 3483 (ulong_t)args.data_size); 3484 (void) printf("%s\tdesc_ptr=0x%lX desc_num=%u\n", 3485 pri->pname, 3486 (ulong_t)args.desc_ptr, 3487 args.desc_num); 3488 (void) printf("%s\trbuf=0x%lX rsize=%lu\n", 3489 pri->pname, 3490 (ulong_t)args.rbuf, 3491 (ulong_t)args.rsize); 3492 } 3493 } 3494 3495 static void 3496 show_ucred_privsets(private_t *pri, ucred_t *uc) 3497 { 3498 int i = 0; 3499 const priv_set_t *s; 3500 priv_ptype_t sn; 3501 char *str; 3502 3503 while ((sn = priv_getsetbynum(i++)) != NULL) { 3504 s = ucred_getprivset(uc, sn); 3505 3506 if (s == NULL) 3507 continue; 3508 3509 (void) printf("%s\t%c: %s\n", 3510 pri->pname, 3511 *sn, 3512 str = priv_set_to_str(s, ',', PRIV_STR_SHORT)); 3513 3514 free(str); 3515 } 3516 } 3517 3518 static void 3519 show_ucred(private_t *pri, long offset) 3520 { 3521 ucred_t *uc = _ucred_alloc(); 3522 size_t sz; 3523 3524 if (uc == NULL) 3525 return; 3526 3527 sz = Pread(Proc, uc, uc->uc_size, offset); 3528 3529 /* 3530 * A new uc_size is read, it could be smaller than the previously 3531 * value. We accept short reads that fill the whole header. 3532 */ 3533 if (sz >= sizeof (ucred_t) && sz >= uc->uc_size) { 3534 (void) printf("%s\teuid=%u egid=%u\n", 3535 pri->pname, 3536 ucred_geteuid(uc), 3537 ucred_getegid(uc)); 3538 (void) printf("%s\truid=%u rgid=%u\n", 3539 pri->pname, 3540 ucred_getruid(uc), 3541 ucred_getrgid(uc)); 3542 (void) printf("%s\tpid=%d zoneid=%d\n", 3543 pri->pname, 3544 (int)ucred_getpid(uc), 3545 (int)ucred_getzoneid(uc)); 3546 show_ucred_privsets(pri, uc); 3547 } 3548 ucred_free(uc); 3549 } 3550 3551 static void 3552 show_privset(private_t *pri, long offset, size_t size, char *label) 3553 { 3554 priv_set_t *tmp = priv_allocset(); 3555 size_t sz; 3556 3557 if (tmp == NULL) 3558 return; 3559 3560 sz = Pread(Proc, tmp, size, offset); 3561 3562 if (sz == size) { 3563 char *str = priv_set_to_str(tmp, ',', PRIV_STR_SHORT); 3564 if (str != NULL) { 3565 (void) printf("%s\t%s%s\n", pri->pname, label, str); 3566 free(str); 3567 } 3568 } 3569 priv_freeset(tmp); 3570 } 3571 3572 static void 3573 show_doorinfo(private_t *pri, long offset) 3574 { 3575 door_info_t info; 3576 door_attr_t attr; 3577 3578 if (Pread(Proc, &info, sizeof (info), offset) != sizeof (info)) 3579 return; 3580 (void) printf("%s\ttarget=%d proc=0x%llX data=0x%llX\n", 3581 pri->pname, 3582 (int)info.di_target, 3583 info.di_proc, 3584 info.di_data); 3585 attr = info.di_attributes; 3586 (void) printf("%s\tattributes=%s\n", pri->pname, door_flags(pri, attr)); 3587 (void) printf("%s\tuniquifier=%llu\n", pri->pname, info.di_uniquifier); 3588 } 3589 3590 static void 3591 show_doorparam(private_t *pri, long offset) 3592 { 3593 ulong_t val; 3594 3595 if (Pread(Proc, &val, sizeof (val), offset) == sizeof (val)) { 3596 (void) printf("%s\tvalue=%lu\n", 3597 pri->pname, 3598 val); 3599 } 3600 } 3601 3602 3603 static void 3604 show_doorargs32(private_t *pri, long offset) 3605 { 3606 struct door_arg32 args; 3607 3608 if (Pread(Proc, &args, sizeof (args), offset) == sizeof (args)) { 3609 (void) printf("%s\tdata_ptr=%X data_size=%u\n", 3610 pri->pname, 3611 args.data_ptr, 3612 args.data_size); 3613 (void) printf("%s\tdesc_ptr=0x%X desc_num=%u\n", 3614 pri->pname, 3615 args.desc_ptr, 3616 args.desc_num); 3617 (void) printf("%s\trbuf=0x%X rsize=%u\n", 3618 pri->pname, 3619 args.rbuf, 3620 args.rsize); 3621 } 3622 } 3623 3624 static void 3625 show_doorparam32(private_t *pri, long offset) 3626 { 3627 uint_t val; 3628 3629 if (Pread(Proc, &val, sizeof (val), offset) == sizeof (val)) { 3630 (void) printf("%s\tvalue=%u\n", 3631 pri->pname, 3632 val); 3633 } 3634 } 3635 3636 3637 static void 3638 show_doors(private_t *pri) 3639 { 3640 switch (pri->sys_args[5]) { 3641 case DOOR_CALL: 3642 if (data_model == PR_MODEL_LP64) 3643 show_doorargs(pri, (long)pri->sys_args[1]); 3644 else 3645 show_doorargs32(pri, (long)pri->sys_args[1]); 3646 break; 3647 case DOOR_UCRED: 3648 if (!pri->Errno) 3649 show_ucred(pri, (long)pri->sys_args[0]); 3650 break; 3651 case DOOR_INFO: 3652 if (!pri->Errno) 3653 show_doorinfo(pri, (long)pri->sys_args[1]); 3654 break; 3655 case DOOR_GETPARAM: 3656 if (!pri->Errno) { 3657 if (data_model == PR_MODEL_LP64) 3658 show_doorparam(pri, (long)pri->sys_args[2]); 3659 else 3660 show_doorparam32(pri, (long)pri->sys_args[2]); 3661 } 3662 break; 3663 } 3664 } 3665 3666 static void 3667 show_portargs(private_t *pri, long offset) 3668 { 3669 port_event_t args; 3670 3671 if (Pread(Proc, &args, sizeof (args), offset) == sizeof (args)) { 3672 (void) printf("%s\tevents=0x%x source=%u\n", 3673 pri->pname, 3674 args.portev_events, 3675 args.portev_source); 3676 (void) printf("%s\tobject=0x%p user=0x%p\n", 3677 pri->pname, 3678 (void *)args.portev_object, 3679 (void *)args.portev_user); 3680 } 3681 } 3682 3683 3684 3685 static void 3686 show_portargs32(private_t *pri, long offset) 3687 { 3688 port_event32_t args; 3689 3690 if (Pread(Proc, &args, sizeof (args), offset) == sizeof (args)) { 3691 (void) printf("%s\tevents=0x%x source=%u\n", 3692 pri->pname, 3693 args.portev_events, 3694 args.portev_source); 3695 (void) printf("%s\tobject=0x%x user=0x%x\n", 3696 pri->pname, 3697 args.portev_object, 3698 args.portev_user); 3699 } 3700 } 3701 3702 3703 static void 3704 show_ports(private_t *pri) 3705 { 3706 switch (pri->sys_args[0]) { 3707 case PORT_GET: 3708 if (data_model == PR_MODEL_LP64) 3709 show_portargs(pri, (long)pri->sys_args[2]); 3710 else 3711 show_portargs32(pri, (long)pri->sys_args[2]); 3712 break; 3713 } 3714 } 3715 3716 #define MAX_SNDFL_PRD 16 3717 3718 3719 static void 3720 show_ksendfilevec32(private_t *pri, int fd, 3721 ksendfilevec32_t *sndvec, int sfvcnt) 3722 { 3723 ksendfilevec32_t *snd_ptr, snd[MAX_SNDFL_PRD]; 3724 size_t cpy_rqst; 3725 3726 Eserialize(); 3727 while (sfvcnt > 0) { 3728 cpy_rqst = MIN(sfvcnt, MAX_SNDFL_PRD); 3729 sfvcnt -= cpy_rqst; 3730 cpy_rqst *= sizeof (snd[0]); 3731 3732 if (Pread(Proc, snd, cpy_rqst, (uintptr_t)sndvec) != cpy_rqst) 3733 break; 3734 3735 snd_ptr = &snd[0]; 3736 3737 while (cpy_rqst) { 3738 (void) printf( 3739 "sfv_fd=%d\tsfv_flag=0x%x\t" 3740 "sfv_off=%d\tsfv_len=%u\n", 3741 snd_ptr->sfv_fd, 3742 snd_ptr->sfv_flag, 3743 snd_ptr->sfv_off, 3744 snd_ptr->sfv_len); 3745 3746 if (snd_ptr->sfv_fd == SFV_FD_SELF && 3747 prismember(&writefd, fd)) { 3748 showbuffer(pri, 3749 (long)snd_ptr->sfv_off & 0xffffffff, 3750 (long)snd_ptr->sfv_len); 3751 } 3752 3753 cpy_rqst -= sizeof (snd[0]); 3754 snd_ptr++; 3755 } 3756 3757 sndvec += MAX_SNDFL_PRD; 3758 } 3759 Xserialize(); 3760 } 3761 3762 static void 3763 show_ksendfilevec64(private_t *pri, int fd, 3764 ksendfilevec64_t *sndvec, int sfvcnt) 3765 { 3766 ksendfilevec64_t *snd_ptr, snd[MAX_SNDFL_PRD]; 3767 size_t cpy_rqst; 3768 3769 Eserialize(); 3770 while (sfvcnt > 0) { 3771 cpy_rqst = MIN(sfvcnt, MAX_SNDFL_PRD); 3772 sfvcnt -= cpy_rqst; 3773 cpy_rqst *= sizeof (snd[0]); 3774 3775 if (Pread(Proc, snd, cpy_rqst, (uintptr_t)sndvec) != cpy_rqst) 3776 break; 3777 3778 snd_ptr = &snd[0]; 3779 3780 while (cpy_rqst) { 3781 (void) printf( 3782 "sfv_fd=%d\tsfv_flag=0x%x\t" 3783 "sfv_off=%ld\tsfv_len=%u\n", 3784 snd_ptr->sfv_fd, 3785 snd_ptr->sfv_flag, 3786 snd_ptr->sfv_off, 3787 snd_ptr->sfv_len); 3788 3789 if (snd_ptr->sfv_fd == SFV_FD_SELF && 3790 prismember(&writefd, fd)) { 3791 showbuffer(pri, 3792 (long)snd_ptr->sfv_off & 0xffffffff, 3793 (long)snd_ptr->sfv_len); 3794 } 3795 3796 cpy_rqst -= sizeof (snd[0]); 3797 snd_ptr++; 3798 } 3799 3800 sndvec += MAX_SNDFL_PRD; 3801 } 3802 Xserialize(); 3803 } 3804 3805 3806 /*ARGSUSED*/ 3807 static void 3808 show_sendfilevec(private_t *pri, int fd, sendfilevec_t *sndvec, int sfvcnt) 3809 { 3810 sendfilevec_t *snd_ptr, snd[MAX_SNDFL_PRD]; 3811 size_t cpy_rqst; 3812 3813 if (data_model != PR_MODEL_LP64) { 3814 show_ksendfilevec32(pri, fd, 3815 (ksendfilevec32_t *)sndvec, sfvcnt); 3816 return; 3817 } 3818 Eserialize(); 3819 while (sfvcnt > 0) { 3820 cpy_rqst = MIN(sfvcnt, MAX_SNDFL_PRD); 3821 sfvcnt -= cpy_rqst; 3822 cpy_rqst *= sizeof (snd[0]); 3823 3824 if (Pread(Proc, snd, cpy_rqst, (uintptr_t)sndvec) != cpy_rqst) 3825 break; 3826 3827 snd_ptr = &snd[0]; 3828 3829 while (cpy_rqst) { 3830 (void) printf( 3831 "sfv_fd=%d\tsfv_flag=0x%x\t" 3832 "sfv_off=%ld\tsfv_len=%lu\n", 3833 snd_ptr->sfv_fd, 3834 snd_ptr->sfv_flag, 3835 snd_ptr->sfv_off, 3836 (ulong_t)snd_ptr->sfv_len); 3837 3838 if (snd_ptr->sfv_fd == SFV_FD_SELF && 3839 prismember(&writefd, fd)) { 3840 showbuffer(pri, (long)snd_ptr->sfv_off, 3841 (long)snd_ptr->sfv_len); 3842 } 3843 3844 cpy_rqst -= sizeof (snd[0]); 3845 snd_ptr++; 3846 } 3847 3848 sndvec += MAX_SNDFL_PRD; 3849 } 3850 Xserialize(); 3851 } 3852 3853 /*ARGSUSED*/ 3854 static void 3855 show_sendfilevec64(private_t *pri, int fd, sendfilevec64_t *sndvec, int sfvcnt) 3856 { 3857 sendfilevec64_t *snd_ptr, snd[MAX_SNDFL_PRD]; 3858 size_t cpy_rqst; 3859 3860 if (data_model != PR_MODEL_LP64) { 3861 show_ksendfilevec64(pri, fd, 3862 (ksendfilevec64_t *)sndvec, sfvcnt); 3863 return; 3864 } 3865 3866 Eserialize(); 3867 while (sfvcnt > 0) { 3868 cpy_rqst = MIN(sfvcnt, MAX_SNDFL_PRD); 3869 sfvcnt -= cpy_rqst; 3870 cpy_rqst *= sizeof (snd[0]); 3871 3872 if (Pread(Proc, snd, cpy_rqst, (uintptr_t)sndvec) != cpy_rqst) 3873 break; 3874 3875 snd_ptr = &snd[0]; 3876 3877 while (cpy_rqst) { 3878 (void) printf( 3879 "sfv_fd=%d\tsfv_flag=0x%x\t" 3880 "sfv_off=%ld\tsfv_len=%lu\n", 3881 snd_ptr->sfv_fd, 3882 snd_ptr->sfv_flag, 3883 snd_ptr->sfv_off, 3884 (ulong_t)snd_ptr->sfv_len); 3885 3886 if (snd_ptr->sfv_fd == SFV_FD_SELF && 3887 prismember(&writefd, fd)) { 3888 showbuffer(pri, (long)snd_ptr->sfv_off, 3889 (long)snd_ptr->sfv_len); 3890 } 3891 3892 cpy_rqst -= sizeof (snd[0]); 3893 snd_ptr++; 3894 } 3895 3896 sndvec += MAX_SNDFL_PRD; 3897 } 3898 Xserialize(); 3899 } 3900 3901 static void 3902 show_memcntl_mha(private_t *pri, long offset) 3903 { 3904 struct memcntl_mha mha; 3905 const char *s = NULL; 3906 3907 if (Pread(Proc, &mha, sizeof (mha), offset) == sizeof (mha)) { 3908 switch (mha.mha_cmd) { 3909 case MHA_MAPSIZE_VA: s = "MHA_MAPSIZE_VA"; break; 3910 case MHA_MAPSIZE_BSSBRK: s = "MHA_MAPSIZE_BSSBRK"; break; 3911 case MHA_MAPSIZE_STACK: s = "MHA_MAPSIZE_STACK"; break; 3912 } 3913 if (s) 3914 (void) printf("%s\tmha_cmd=%s mha_flags=0x%x" 3915 " mha_pagesize=%lu\n", 3916 pri->pname, s, mha.mha_flags, 3917 (ulong_t)mha.mha_pagesize); 3918 else 3919 (void) printf("%s\tmha_cmd=0x%.8x mha_flags=0x%x" 3920 " mha_pagesize=%lu\n", 3921 pri->pname, mha.mha_cmd, mha.mha_flags, 3922 (ulong_t)mha.mha_pagesize); 3923 } 3924 } 3925 3926 3927 static void 3928 show_memcntl_mha32(private_t *pri, long offset) 3929 { 3930 struct memcntl_mha32 mha32; 3931 const char *s = NULL; 3932 3933 if (Pread(Proc, &mha32, sizeof (mha32), offset) == 3934 sizeof (mha32)) { 3935 switch (mha32.mha_cmd) { 3936 case MHA_MAPSIZE_VA: s = "MHA_MAPSIZE_VA"; break; 3937 case MHA_MAPSIZE_BSSBRK: s = "MHA_MAPSIZE_BSSBRK"; break; 3938 case MHA_MAPSIZE_STACK: s = "MHA_MAPSIZE_STACK"; break; 3939 } 3940 if (s) 3941 (void) printf("%s\tmha_cmd=%s mha_flags=0x%x" 3942 " mha_pagesize=%u\n", 3943 pri->pname, s, mha32.mha_flags, mha32.mha_pagesize); 3944 else 3945 (void) printf("%s\tmha_cmd=0x%.8x mha_flags=0x%x" 3946 " mha_pagesize=%u\n", 3947 pri->pname, mha32.mha_cmd, mha32.mha_flags, 3948 mha32.mha_pagesize); 3949 } 3950 } 3951 3952 3953 static void 3954 show_memcntl(private_t *pri) 3955 { 3956 3957 if ((int)pri->sys_args[2] != MC_HAT_ADVISE) 3958 return; 3959 if (data_model == PR_MODEL_LP64) 3960 show_memcntl_mha(pri, (long)pri->sys_args[3]); 3961 else 3962 show_memcntl_mha32(pri, (long)pri->sys_args[3]); 3963 } 3964 3965 void 3966 show_ids(private_t *pri, long offset, int count) 3967 { 3968 id_t buf[MYBUFSIZ / sizeof (id_t)]; 3969 id_t *idp; 3970 int serial = (count > MYBUFSIZ / 48); 3971 3972 if (offset == 0) 3973 return; 3974 3975 /* enter region of lengthy output */ 3976 if (serial) 3977 Eserialize(); 3978 3979 while (count > 0 && !interrupt) { 3980 ssize_t nb = (count * sizeof (id_t) < MYBUFSIZ)? 3981 count * sizeof (id_t) : MYBUFSIZ; 3982 3983 if ((nb = Pread(Proc, &buf[0], (size_t)nb, offset)) < 0 || 3984 nb < sizeof (id_t)) 3985 break; 3986 3987 idp = buf; 3988 while (!interrupt && nb >= sizeof (id_t)) { 3989 (void) printf("%s\t%8d\n", pri->pname, (int)*idp); 3990 offset += sizeof (id_t); 3991 nb -= sizeof (id_t); 3992 idp++; 3993 count--; 3994 } 3995 } 3996 3997 /* exit region of lengthy output */ 3998 if (serial) 3999 Xserialize(); 4000 } 4001 4002 void 4003 show_ntp_gettime(private_t *pri) 4004 { 4005 struct ntptimeval ntv; 4006 long offset; 4007 4008 if (pri->sys_nargs < 1 || (offset = pri->sys_args[0]) == 0) 4009 return; 4010 4011 if (data_model == PR_MODEL_NATIVE) { 4012 if (Pread(Proc, &ntv, sizeof (ntv), offset) 4013 != sizeof (ntv)) 4014 return; 4015 } else { 4016 struct ntptimeval32 ntv32; 4017 4018 if (Pread(Proc, &ntv32, sizeof (ntv32), offset) 4019 != sizeof (ntv32)) 4020 return; 4021 4022 TIMEVAL32_TO_TIMEVAL(&ntv.time, &ntv32.time); 4023 ntv.maxerror = ntv32.maxerror; 4024 ntv.esterror = ntv32.esterror; 4025 } 4026 4027 (void) printf("\ttime: %ld.%6.6ld sec\n", 4028 ntv.time.tv_sec, ntv.time.tv_usec); 4029 (void) printf("\tmaxerror: %11d usec\n", ntv.maxerror); 4030 (void) printf("\testerror: %11d usec\n", ntv.esterror); 4031 } 4032 4033 static char * 4034 get_timex_modes(private_t *pri, uint32_t val) 4035 { 4036 char *str = pri->code_buf; 4037 size_t used = 0; 4038 4039 *str = '\0'; 4040 if (val & MOD_OFFSET) 4041 used = strlcat(str, "|MOD_OFFSET", sizeof (pri->code_buf)); 4042 if (val & MOD_FREQUENCY) 4043 used = strlcat(str, "|MOD_FREQUENCY", sizeof (pri->code_buf)); 4044 if (val & MOD_MAXERROR) 4045 used = strlcat(str, "|MOD_MAXERROR", sizeof (pri->code_buf)); 4046 if (val & MOD_ESTERROR) 4047 used = strlcat(str, "|MOD_ESTERROR", sizeof (pri->code_buf)); 4048 if (val & MOD_STATUS) 4049 used = strlcat(str, "|MOD_STATUS", sizeof (pri->code_buf)); 4050 if (val & MOD_TIMECONST) 4051 used = strlcat(str, "|MOD_TIMECONST", sizeof (pri->code_buf)); 4052 if (val & MOD_CLKB) 4053 used = strlcat(str, "|MOD_CLKB", sizeof (pri->code_buf)); 4054 if (val & MOD_CLKA) 4055 used = strlcat(str, "|MOD_CLKA", sizeof (pri->code_buf)); 4056 4057 if (used == 0 || used >= sizeof (pri->code_buf)) 4058 (void) snprintf(str, sizeof (pri->code_buf), " 0x%.4x", val); 4059 4060 return (str + 1); 4061 } 4062 4063 static char * 4064 get_timex_status(private_t *pri, int32_t val) 4065 { 4066 char *str = pri->code_buf; 4067 size_t used = 0; 4068 4069 *str = '\0'; 4070 if (val & STA_PLL) 4071 used = strlcat(str, "|STA_PLL", sizeof (pri->code_buf)); 4072 if (val & STA_PPSFREQ) 4073 used = strlcat(str, "|STA_PPSFREQ", sizeof (pri->code_buf)); 4074 if (val & STA_PPSTIME) 4075 used = strlcat(str, "|STA_PPSTIME", sizeof (pri->code_buf)); 4076 if (val & STA_FLL) 4077 used = strlcat(str, "|STA_FLL", sizeof (pri->code_buf)); 4078 4079 if (val & STA_INS) 4080 used = strlcat(str, "|STA_INS", sizeof (pri->code_buf)); 4081 if (val & STA_DEL) 4082 used = strlcat(str, "|STA_DEL", sizeof (pri->code_buf)); 4083 if (val & STA_UNSYNC) 4084 used = strlcat(str, "|STA_UNSYNC", sizeof (pri->code_buf)); 4085 if (val & STA_FREQHOLD) 4086 used = strlcat(str, "|STA_FREQHOLD", sizeof (pri->code_buf)); 4087 4088 if (val & STA_PPSSIGNAL) 4089 used = strlcat(str, "|STA_PPSSIGNAL", sizeof (pri->code_buf)); 4090 if (val & STA_PPSJITTER) 4091 used = strlcat(str, "|STA_PPSJITTER", sizeof (pri->code_buf)); 4092 if (val & STA_PPSWANDER) 4093 used = strlcat(str, "|STA_PPSWANDER", sizeof (pri->code_buf)); 4094 if (val & STA_PPSERROR) 4095 used = strlcat(str, "|STA_PPSERROR", sizeof (pri->code_buf)); 4096 4097 if (val & STA_CLOCKERR) 4098 used = strlcat(str, "|STA_CLOCKERR", sizeof (pri->code_buf)); 4099 4100 if (used == 0 || used >= sizeof (pri->code_buf)) 4101 (void) snprintf(str, sizeof (pri->code_buf), " 0x%.4x", val); 4102 4103 return (str + 1); 4104 } 4105 4106 void 4107 show_ntp_adjtime(private_t *pri) 4108 { 4109 struct timex timex; 4110 long offset; 4111 4112 if (pri->sys_nargs < 1 || (offset = pri->sys_args[0]) == 0) 4113 return; 4114 4115 if (Pread(Proc, &timex, sizeof (timex), offset) != sizeof (timex)) 4116 return; 4117 4118 (void) printf("\tmodes: %s\n", get_timex_modes(pri, timex.modes)); 4119 (void) printf("\toffset: %11d usec\n", timex.offset); 4120 (void) printf("\tfreq: %11d scaled ppm\n", timex.freq); 4121 (void) printf("\tmaxerror: %11d usec\n", timex.maxerror); 4122 (void) printf("\testerror: %11d usec\n", timex.esterror); 4123 (void) printf("\tstatus: %s\n", get_timex_status(pri, timex.status)); 4124 (void) printf("\tconstant: %11d\n", timex.constant); 4125 (void) printf("\tprecision: %11d usec\n", timex.precision); 4126 (void) printf("\ttolerance: %11d scaled ppm\n", timex.tolerance); 4127 (void) printf("\tppsfreq: %11d scaled ppm\n", timex.ppsfreq); 4128 (void) printf("\tjitter: %11d usec\n", timex.jitter); 4129 (void) printf("\tshift: %11d sec\n", timex.shift); 4130 (void) printf("\tstabil: %11d scaled ppm\n", timex.stabil); 4131 (void) printf("\tjitcnt: %11d\n", timex.jitcnt); 4132 (void) printf("\tcalcnt: %11d\n", timex.calcnt); 4133 (void) printf("\terrcnt: %11d\n", timex.errcnt); 4134 (void) printf("\tstbcnt: %11d\n", timex.stbcnt); 4135 } 4136 4137 void 4138 show_getrusage(long offset) 4139 { 4140 struct rusage r; 4141 if (Pread(Proc, &r, sizeof (r), offset) != sizeof (r)) 4142 return; 4143 (void) printf("\t user time: %ld.%6.6ld sec\n", 4144 r.ru_utime.tv_sec, 4145 r.ru_utime.tv_usec); 4146 (void) printf("\t system time: %ld.%6.6ld sec\n", 4147 r.ru_stime.tv_sec, 4148 r.ru_stime.tv_usec); 4149 (void) printf("\t max rss: <unimpl> %ld\n", 4150 r.ru_maxrss); 4151 (void) printf("\t shared data: <unimpl> %ld\n", 4152 r.ru_ixrss); 4153 (void) printf("\t unshared data: <unimpl> %ld\n", 4154 r.ru_idrss); 4155 (void) printf("\t unshared stack: <unimpl> %ld\n", 4156 r.ru_isrss); 4157 (void) printf("\t minor faults: %ld\n", 4158 r.ru_minflt); 4159 (void) printf("\t major faults: %ld\n", 4160 r.ru_majflt); 4161 (void) printf("\t # of swaps: %ld\n", 4162 r.ru_nswap); 4163 (void) printf("\t blocked inputs: %ld\n", 4164 r.ru_inblock); 4165 (void) printf("\t blocked outputs: %ld\n", 4166 r.ru_oublock); 4167 (void) printf("\t msgs sent: %ld\n", 4168 r.ru_msgsnd); 4169 (void) printf("\t msgs rcv'd: %ld\n", 4170 r.ru_msgrcv); 4171 (void) printf("\t signals rcv'd: %ld\n", 4172 r.ru_nsignals); 4173 (void) printf("\tvol cntxt swtchs: %ld\n", 4174 r.ru_nvcsw); 4175 (void) printf("\tinv cntxt swtchs: %ld\n", 4176 r.ru_nivcsw); 4177 } 4178 4179 void 4180 show_getrusage32(long offset) 4181 { 4182 struct rusage32 r; 4183 if (Pread(Proc, &r, sizeof (r), offset) != sizeof (r)) 4184 return; 4185 (void) printf("\t user time: %d.%6.6d sec\n", 4186 r.ru_utime.tv_sec, 4187 r.ru_utime.tv_usec); 4188 (void) printf("\t system time: %d.%6.6d sec\n", 4189 r.ru_stime.tv_sec, 4190 r.ru_stime.tv_usec); 4191 (void) printf("\t max rss: <unimpl> %d\n", 4192 r.ru_maxrss); 4193 (void) printf("\t shared data: <unimpl> %d\n", 4194 r.ru_ixrss); 4195 (void) printf("\t unshared data: <unimpl> %d\n", 4196 r.ru_idrss); 4197 (void) printf("\t unshared stack: <unimpl> %d\n", 4198 r.ru_isrss); 4199 (void) printf("\t minor faults: %d\n", 4200 r.ru_minflt); 4201 (void) printf("\t major faults: %d\n", 4202 r.ru_majflt); 4203 (void) printf("\t # of swaps: %d\n", 4204 r.ru_nswap); 4205 (void) printf("\t blocked inputs: %d\n", 4206 r.ru_inblock); 4207 (void) printf("\t blocked outputs: %d\n", 4208 r.ru_oublock); 4209 (void) printf("\t msgs sent: %d\n", 4210 r.ru_msgsnd); 4211 (void) printf("\t msgs rcv'd: %d\n", 4212 r.ru_msgrcv); 4213 (void) printf("\t signals rcv'd: %d\n", 4214 r.ru_nsignals); 4215 (void) printf("\tvol cntxt swtchs: %d\n", 4216 r.ru_nvcsw); 4217 (void) printf("\tinv cntxt swtchs: %d\n", 4218 r.ru_nivcsw); 4219 } 4220 4221 /* 4222 * Utility function to print a packed nvlist by unpacking 4223 * and calling the libnvpair pretty printer. Frees all 4224 * allocated memory internally. 4225 */ 4226 static void 4227 show_packed_nvlist(private_t *pri, uintptr_t offset, size_t size) 4228 { 4229 nvlist_t *nvl = NULL; 4230 size_t readsize; 4231 char *buf; 4232 4233 if ((offset == 0) || (size == 0)) { 4234 return; 4235 } 4236 4237 buf = my_malloc(size, "nvlist decode buffer"); 4238 readsize = Pread(Proc, buf, size, offset); 4239 if (readsize != size) { 4240 (void) printf("%s\t<?>", pri->pname); 4241 } else { 4242 int result; 4243 4244 result = nvlist_unpack(buf, size, &nvl, 0); 4245 if (result == 0) { 4246 dump_nvlist(nvl, 8); 4247 nvlist_free(nvl); 4248 } else { 4249 (void) printf("%s\tunpack of nvlist" 4250 " failed: %d\n", pri->pname, result); 4251 } 4252 } 4253 free(buf); 4254 } 4255 4256 static void 4257 show_zone_create_args(private_t *pri, long offset) 4258 { 4259 zone_def args; 4260 char zone_name[ZONENAME_MAX]; 4261 char zone_root[MAXPATHLEN]; 4262 char *zone_zfs = NULL; 4263 4264 if (Pread(Proc, &args, sizeof (args), offset) == sizeof (args)) { 4265 4266 if (Pread_string(Proc, zone_name, sizeof (zone_name), 4267 (uintptr_t)args.zone_name) == -1) 4268 (void) strcpy(zone_name, "<?>"); 4269 4270 if (Pread_string(Proc, zone_root, sizeof (zone_root), 4271 (uintptr_t)args.zone_root) == -1) 4272 (void) strcpy(zone_root, "<?>"); 4273 4274 if (args.zfsbufsz > 0) { 4275 zone_zfs = malloc(MIN(4, args.zfsbufsz)); 4276 if (zone_zfs != NULL) { 4277 if (Pread(Proc, zone_zfs, args.zfsbufsz, 4278 (uintptr_t)args.zfsbuf) == -1) 4279 (void) strcpy(zone_zfs, "<?>"); 4280 } 4281 } else { 4282 zone_zfs = ""; 4283 } 4284 4285 (void) printf("%s\t zone_name: %s\n", pri->pname, 4286 zone_name); 4287 (void) printf("%s\t zone_root: %s\n", pri->pname, 4288 zone_root); 4289 4290 show_privset(pri, (uintptr_t)args.zone_privs, 4291 args.zone_privssz, " zone_privs: "); 4292 4293 (void) printf("%s\t rctlbuf: 0x%p\n", pri->pname, 4294 (void *)args.rctlbuf); 4295 (void) printf("%s\t rctlbufsz: %lu\n", pri->pname, 4296 (ulong_t)args.rctlbufsz); 4297 4298 show_packed_nvlist(pri, (uintptr_t)args.rctlbuf, 4299 args.rctlbufsz); 4300 4301 (void) printf("%s\t zfs: %s\n", pri->pname, zone_zfs); 4302 4303 (void) printf("%s\textended_error: 0x%p\n", pri->pname, 4304 (void *)args.extended_error); 4305 4306 if (is_system_labeled()) { 4307 char *label_str = NULL; 4308 bslabel_t zone_label; 4309 4310 (void) printf("%s\t match: %d\n", pri->pname, 4311 args.match); 4312 (void) printf("%s\t doi: %d\n", pri->pname, 4313 args.doi); 4314 4315 if (Pread_string(Proc, (char *)&zone_label, 4316 sizeof (zone_label), (uintptr_t)args.label) != -1) { 4317 /* show the label as string */ 4318 if (label_to_str(&zone_label, &label_str, 4319 M_LABEL, SHORT_NAMES) != 0) { 4320 /* have to dump label as raw string */ 4321 (void) label_to_str(&zone_label, 4322 &label_str, M_INTERNAL, 4323 SHORT_NAMES); 4324 } 4325 } 4326 4327 (void) printf("%s\t label: %s\n", 4328 pri->pname, label_str != NULL ? label_str : "<?>"); 4329 if (label_str) 4330 free(label_str); 4331 } 4332 4333 if (args.zfsbufsz > 0) 4334 free(zone_zfs); 4335 } 4336 } 4337 4338 4339 4340 static void 4341 show_zone_create_args32(private_t *pri, long offset) 4342 { 4343 zone_def32 args; 4344 char zone_name[ZONENAME_MAX]; 4345 char zone_root[MAXPATHLEN]; 4346 char *zone_zfs = NULL; 4347 4348 if (Pread(Proc, &args, sizeof (args), offset) == sizeof (args)) { 4349 4350 if (Pread_string(Proc, zone_name, sizeof (zone_name), 4351 (uintptr_t)args.zone_name) == -1) 4352 (void) strcpy(zone_name, "<?>"); 4353 4354 if (Pread_string(Proc, zone_root, sizeof (zone_root), 4355 (uintptr_t)args.zone_root) == -1) 4356 (void) strcpy(zone_root, "<?>"); 4357 4358 if (args.zfsbufsz > 0) { 4359 zone_zfs = malloc(MIN(4, args.zfsbufsz)); 4360 if (zone_zfs != NULL) { 4361 if (Pread(Proc, zone_zfs, args.zfsbufsz, 4362 (uintptr_t)args.zfsbuf) == -1) 4363 (void) strcpy(zone_zfs, "<?>"); 4364 } 4365 } else { 4366 zone_zfs = ""; 4367 } 4368 4369 (void) printf("%s\t zone_name: %s\n", pri->pname, 4370 zone_name); 4371 (void) printf("%s\t zone_root: %s\n", pri->pname, 4372 zone_root); 4373 4374 show_privset(pri, (uintptr_t)args.zone_privs, 4375 args.zone_privssz, " zone_privs: "); 4376 4377 (void) printf("%s\t rctlbuf: 0x%x\n", pri->pname, 4378 (caddr32_t)args.rctlbuf); 4379 (void) printf("%s\t rctlbufsz: %lu\n", pri->pname, 4380 (ulong_t)args.rctlbufsz); 4381 4382 show_packed_nvlist(pri, (uintptr_t)args.rctlbuf, 4383 args.rctlbufsz); 4384 4385 (void) printf("%s\t zfs: %s\n", pri->pname, zone_zfs); 4386 4387 (void) printf("%s\textended_error: 0x%x\n", pri->pname, 4388 (caddr32_t)args.extended_error); 4389 4390 if (is_system_labeled()) { 4391 char *label_str = NULL; 4392 bslabel_t zone_label; 4393 4394 (void) printf("%s\t match: %d\n", pri->pname, 4395 args.match); 4396 (void) printf("%s\t doi: %d\n", pri->pname, 4397 args.doi); 4398 4399 if (Pread_string(Proc, (char *)&zone_label, 4400 sizeof (zone_label), (caddr32_t)args.label) != -1) { 4401 /* show the label as string */ 4402 if (label_to_str(&zone_label, &label_str, 4403 M_LABEL, SHORT_NAMES) != 0) { 4404 /* have to dump label as raw string */ 4405 (void) label_to_str(&zone_label, 4406 &label_str, M_INTERNAL, 4407 SHORT_NAMES); 4408 } 4409 } 4410 (void) printf("%s\t label: %s\n", 4411 pri->pname, label_str != NULL ? label_str : "<?>"); 4412 if (label_str) 4413 free(label_str); 4414 } 4415 4416 if (args.zfsbufsz > 0) 4417 free(zone_zfs); 4418 } 4419 } 4420 4421 4422 static void 4423 show_zones(private_t *pri) 4424 { 4425 switch (pri->sys_args[0]) { 4426 case ZONE_CREATE: 4427 if (data_model == PR_MODEL_LP64) 4428 show_zone_create_args(pri, (long)pri->sys_args[1]); 4429 else 4430 show_zone_create_args32(pri, (long)pri->sys_args[1]); 4431 break; 4432 } 4433 } 4434 4435 static void 4436 show_rctlblk(private_t *pri, long _rctlblk) 4437 { 4438 rctlblk_t *blk; 4439 int size = rctlblk_size(); 4440 size_t readsize; 4441 const char *s; 4442 4443 blk = my_malloc(size, "rctlblk decode buffer"); 4444 readsize = Pread(Proc, blk, size, _rctlblk); 4445 if (readsize != size) { 4446 (void) printf("%s\t\t<?>", pri->pname); 4447 } else { 4448 (void) printf("%s\t\t Privilege: 0x%x\n", 4449 pri->pname, 4450 rctlblk_get_privilege(blk)); 4451 (void) printf("%s\t\t Value: %lld\n", 4452 pri->pname, 4453 rctlblk_get_value(blk)); 4454 (void) printf("%s\t\tEnforced Value: %lld\n", 4455 pri->pname, 4456 rctlblk_get_enforced_value(blk)); 4457 4458 { 4459 int sig, act; 4460 act = rctlblk_get_local_action(blk, &sig); 4461 4462 s = rctl_local_action(pri, act); 4463 if (s == NULL) { 4464 (void) printf("%s\t\t Local action: 0x%x\n", 4465 pri->pname, act); 4466 } else { 4467 (void) printf("%s\t\t Local action: %s\n", 4468 pri->pname, s); 4469 } 4470 4471 if (act & RCTL_LOCAL_SIGNAL) { 4472 (void) printf("%s\t\t " 4473 "For signal %s\n", 4474 pri->pname, signame(pri, sig)); 4475 } 4476 } 4477 4478 s = rctl_local_flags(pri, rctlblk_get_local_flags(blk)); 4479 if (s == NULL) { 4480 (void) printf("%s\t\t Local flags: 0x%x\n", 4481 pri->pname, rctlblk_get_local_flags(blk)); 4482 } else { 4483 (void) printf("%s\t\t Local flags: %s\n", 4484 pri->pname, s); 4485 } 4486 4487 (void) printf("%s\t\t Recipient PID: %d\n", 4488 pri->pname, 4489 rctlblk_get_recipient_pid(blk)); 4490 (void) printf("%s\t\t Firing Time: %lld\n", 4491 pri->pname, 4492 rctlblk_get_firing_time(blk)); 4493 } 4494 free(blk); 4495 } 4496 4497 static void 4498 show_rctls(private_t *pri) 4499 { 4500 int entry; 4501 4502 switch (pri->sys_args[0]) { 4503 case 0: /* getrctl */ 4504 case 1: /* setrctl */ 4505 /* 4506 * If these offsets look a little odd, remember that they're 4507 * into the _raw_ system call 4508 */ 4509 (void) printf("%s\tOld rctlblk: 0x%lx\n", pri->pname, 4510 pri->sys_args[2]); 4511 if (pri->sys_args[2] != 0) { 4512 show_rctlblk(pri, pri->sys_args[2]); 4513 } 4514 (void) printf("%s\tNew rctlblk: 0x%lx\n", pri->pname, 4515 pri->sys_args[3]); 4516 if (pri->sys_args[3] != 0) { 4517 show_rctlblk(pri, pri->sys_args[3]); 4518 } 4519 break; 4520 case 4: /* setprojrctl */ 4521 for (entry = 0; entry < pri->sys_args[4]; entry++) { 4522 (void) printf("%s\tNew rctlblk[%d]: 0x%lx\n", 4523 pri->pname, entry, 4524 (long)RCTLBLK_INC(pri->sys_args[3], entry)); 4525 if (RCTLBLK_INC(pri->sys_args[3], entry) != NULL) { 4526 show_rctlblk(pri, 4527 (long)RCTLBLK_INC(pri->sys_args[3], entry)); 4528 } 4529 } 4530 } 4531 } 4532 4533 void 4534 show_utimesys(private_t *pri) 4535 { 4536 switch (pri->sys_args[0]) { 4537 case 0: /* futimens() */ 4538 if (pri->sys_nargs > 2) 4539 show_utimens(pri, (long)pri->sys_args[2]); 4540 break; 4541 case 1: /* utimensat */ 4542 if (pri->sys_nargs > 3) 4543 show_utimens(pri, (long)pri->sys_args[3]); 4544 break; 4545 default: /* unexpected subcode */ 4546 break; 4547 } 4548 } 4549 4550 static void 4551 show_sockconfig_filter_prop32(private_t *pri, long addr) 4552 { 4553 struct sockconfig_filter_props32 props; 4554 const char *s = NULL; 4555 char buf[MAX(FILNAME_MAX, MODMAXNAMELEN)]; 4556 sof_socktuple32_t *tup; 4557 size_t sz; 4558 int i; 4559 4560 if (Pread(Proc, &props, sizeof (props), addr) == sizeof (props)) { 4561 if (Pread_string(Proc, buf, sizeof (buf), 4562 (uintptr_t)props.sfp_modname) == -1) 4563 (void) strcpy(buf, "<?>"); 4564 (void) printf("%s\tmodule name: %s\n", pri->pname, buf); 4565 (void) printf("%s\tattach semantics: %s", pri->pname, 4566 props.sfp_autoattach ? "automatic" : "progammatic"); 4567 if (props.sfp_autoattach) { 4568 buf[0] = '\0'; 4569 switch (props.sfp_hint) { 4570 case SOF_HINT_TOP: s = "top"; break; 4571 case SOF_HINT_BOTTOM: s = "bottom"; break; 4572 case SOF_HINT_BEFORE: 4573 case SOF_HINT_AFTER: 4574 s = (props.sfp_hint == SOF_HINT_BEFORE) ? 4575 "before" : "after"; 4576 if (Pread_string(Proc, buf, sizeof (buf), 4577 (uintptr_t)props.sfp_hintarg) == -1) 4578 (void) strcpy(buf, "<?>"); 4579 } 4580 if (s != NULL) { 4581 (void) printf(", placement: %s %s", s, buf); 4582 } 4583 } 4584 (void) printf("\n"); 4585 (void) printf("%s\tsocket tuples:\n", pri->pname); 4586 if (props.sfp_socktuple_cnt == 0) { 4587 (void) printf("\t\t<empty>\n"); 4588 return; 4589 } 4590 sz = props.sfp_socktuple_cnt * sizeof (*tup); 4591 tup = my_malloc(sz, "socket tuple buffer"); 4592 if (Pread(Proc, tup, sz, (uintptr_t)props.sfp_socktuple) == sz) 4593 for (i = 0; i < props.sfp_socktuple_cnt; i++) { 4594 (void) printf( 4595 "\t\tfamily: %d, type: %d, proto: %d\n", 4596 tup[i].sofst_family, tup[i].sofst_type, 4597 tup[i].sofst_protocol); 4598 } 4599 } 4600 } 4601 static void 4602 show_sockconfig_filter_prop(private_t *pri, long addr) 4603 { 4604 struct sockconfig_filter_props props; 4605 const char *s = NULL; 4606 char buf[MAX(FILNAME_MAX, MODMAXNAMELEN)]; 4607 sof_socktuple_t *tup; 4608 size_t sz; 4609 int i; 4610 4611 if (Pread(Proc, &props, sizeof (props), addr) == sizeof (props)) { 4612 if (Pread_string(Proc, buf, sizeof (buf), 4613 (uintptr_t)props.sfp_modname) == -1) 4614 (void) strcpy(buf, "<?>"); 4615 (void) printf("%s\tmodule name: %s\n", pri->pname, buf); 4616 (void) printf("%s\tattach semantics: %s", pri->pname, 4617 props.sfp_autoattach ? "automatic" : "progammatic"); 4618 if (props.sfp_autoattach) { 4619 buf[0] = '\0'; 4620 switch (props.sfp_hint) { 4621 case SOF_HINT_TOP: s = "top"; break; 4622 case SOF_HINT_BOTTOM: s = "bottom"; break; 4623 case SOF_HINT_BEFORE: 4624 case SOF_HINT_AFTER: 4625 s = (props.sfp_hint == SOF_HINT_BEFORE) ? 4626 "before" : "after"; 4627 if (Pread_string(Proc, buf, sizeof (buf), 4628 (uintptr_t)props.sfp_hintarg) == -1) 4629 (void) strcpy(buf, "<?>"); 4630 } 4631 if (s != NULL) { 4632 (void) printf(", placement: %s", s); 4633 } 4634 } 4635 (void) printf("\n"); 4636 (void) printf("%s\tsocket tuples:\n", pri->pname); 4637 if (props.sfp_socktuple_cnt == 0) { 4638 (void) printf("\t\t<empty>\n"); 4639 return; 4640 } 4641 sz = props.sfp_socktuple_cnt * sizeof (*tup); 4642 tup = my_malloc(sz, "socket tuple buffer"); 4643 if (Pread(Proc, tup, sz, (uintptr_t)props.sfp_socktuple) == sz) 4644 for (i = 0; i < props.sfp_socktuple_cnt; i++) { 4645 (void) printf( 4646 "\t\tfamily: %d, type: %d, proto: %d\n", 4647 tup[i].sofst_family, tup[i].sofst_type, 4648 tup[i].sofst_protocol); 4649 } 4650 } 4651 } 4652 4653 void 4654 show_sockconfig(private_t *pri) 4655 { 4656 switch (pri->sys_args[0]) { 4657 case SOCKCONFIG_ADD_FILTER: 4658 if (data_model == PR_MODEL_LP64) 4659 show_sockconfig_filter_prop(pri, 4660 (long)pri->sys_args[2]); 4661 else 4662 show_sockconfig_filter_prop32(pri, 4663 (long)pri->sys_args[2]); 4664 break; 4665 default: 4666 break; 4667 } 4668 } 4669 4670 void 4671 show_zfs_ioc(private_t *pri, long addr) 4672 { 4673 static const zfs_share_t zero_share = {0}; 4674 static const dmu_objset_stats_t zero_objstats = {0}; 4675 static const struct drr_begin zero_drrbegin = {0}; 4676 static const zinject_record_t zero_injectrec = {0}; 4677 static const zfs_stat_t zero_zstat = {0}; 4678 zfs_cmd_t zc; 4679 4680 if (Pread(Proc, &zc, sizeof (zc), addr) != sizeof (zc)) { 4681 (void) printf(" zfs_ioctl read failed\n"); 4682 return; 4683 } 4684 4685 if (zc.zc_name[0]) 4686 (void) printf(" zc_name=%s\n", zc.zc_name); 4687 if (zc.zc_value[0]) 4688 (void) printf(" zc_value=%s\n", zc.zc_value); 4689 if (zc.zc_string[0]) 4690 (void) printf(" zc_string=%s\n", zc.zc_string); 4691 if (zc.zc_guid != 0) { 4692 (void) printf(" zc_guid=%llu\n", 4693 (u_longlong_t)zc.zc_guid); 4694 } 4695 if (zc.zc_nvlist_conf_size) { 4696 (void) printf(" nvlist_conf:\n"); 4697 show_packed_nvlist(pri, zc.zc_nvlist_conf, 4698 zc.zc_nvlist_conf_size); 4699 } 4700 if (zc.zc_nvlist_src_size) { 4701 (void) printf(" nvlist_src:\n"); 4702 show_packed_nvlist(pri, zc.zc_nvlist_src, 4703 zc.zc_nvlist_src_size); 4704 } 4705 if (zc.zc_nvlist_dst_size) { 4706 (void) printf(" nvlist_dst:\n"); 4707 show_packed_nvlist(pri, zc.zc_nvlist_dst, 4708 zc.zc_nvlist_dst_size); 4709 } 4710 if (zc.zc_cookie != 0) { 4711 (void) printf(" zc_cookie=%llu\n", 4712 (u_longlong_t)zc.zc_cookie); 4713 } 4714 if (zc.zc_objset_type != 0) { 4715 (void) printf(" zc_objset_type=%llu\n", 4716 (u_longlong_t)zc.zc_objset_type); 4717 } 4718 if (zc.zc_perm_action != 0) { 4719 (void) printf(" zc_perm_action=%llu\n", 4720 (u_longlong_t)zc.zc_perm_action); 4721 } 4722 if (zc.zc_history != 0) { 4723 (void) printf(" zc_history=%llu\n", 4724 (u_longlong_t)zc.zc_history); 4725 } 4726 if (zc.zc_obj != 0) { 4727 (void) printf(" zc_obj=%llu\n", 4728 (u_longlong_t)zc.zc_obj); 4729 } 4730 if (zc.zc_iflags != 0) { 4731 (void) printf(" zc_obj=0x%llx\n", 4732 (u_longlong_t)zc.zc_iflags); 4733 } 4734 4735 if (memcmp(&zc.zc_share, &zero_share, sizeof (zc.zc_share))) { 4736 zfs_share_t *z = &zc.zc_share; 4737 (void) printf(" zc_share:\n"); 4738 if (z->z_exportdata) { 4739 (void) printf("\tz_exportdata=0x%llx\n", 4740 (u_longlong_t)z->z_exportdata); 4741 } 4742 if (z->z_sharedata) { 4743 (void) printf("\tz_sharedata=0x%llx\n", 4744 (u_longlong_t)z->z_sharedata); 4745 } 4746 if (z->z_sharetype) { 4747 (void) printf("\tz_sharetype=%llu\n", 4748 (u_longlong_t)z->z_sharetype); 4749 } 4750 if (z->z_sharemax) { 4751 (void) printf("\tz_sharemax=%llu\n", 4752 (u_longlong_t)z->z_sharemax); 4753 } 4754 } 4755 4756 if (memcmp(&zc.zc_objset_stats, &zero_objstats, 4757 sizeof (zc.zc_objset_stats))) { 4758 dmu_objset_stats_t *dds = &zc.zc_objset_stats; 4759 (void) printf(" zc_objset_stats:\n"); 4760 if (dds->dds_num_clones) { 4761 (void) printf("\tdds_num_clones=%llu\n", 4762 (u_longlong_t)dds->dds_num_clones); 4763 } 4764 if (dds->dds_creation_txg) { 4765 (void) printf("\tdds_creation_txg=%llu\n", 4766 (u_longlong_t)dds->dds_creation_txg); 4767 } 4768 if (dds->dds_guid) { 4769 (void) printf("\tdds_guid=%llu\n", 4770 (u_longlong_t)dds->dds_guid); 4771 } 4772 if (dds->dds_type) 4773 (void) printf("\tdds_type=%u\n", dds->dds_type); 4774 if (dds->dds_is_snapshot) { 4775 (void) printf("\tdds_is_snapshot=%u\n", 4776 dds->dds_is_snapshot); 4777 } 4778 if (dds->dds_inconsistent) { 4779 (void) printf("\tdds_inconsitent=%u\n", 4780 dds->dds_inconsistent); 4781 } 4782 if (dds->dds_origin[0]) { 4783 (void) printf("\tdds_origin=%s\n", dds->dds_origin); 4784 } 4785 } 4786 4787 if (memcmp(&zc.zc_begin_record, &zero_drrbegin, 4788 sizeof (zc.zc_begin_record))) { 4789 struct drr_begin *drr = &zc.zc_begin_record.drr_u.drr_begin; 4790 (void) printf(" zc_begin_record:\n"); 4791 if (drr->drr_magic) { 4792 (void) printf("\tdrr_magic=%llu\n", 4793 (u_longlong_t)drr->drr_magic); 4794 } 4795 if (drr->drr_versioninfo) { 4796 (void) printf("\tdrr_versioninfo=%llu\n", 4797 (u_longlong_t)drr->drr_versioninfo); 4798 } 4799 if (drr->drr_creation_time) { 4800 (void) printf("\tdrr_creation_time=%llu\n", 4801 (u_longlong_t)drr->drr_creation_time); 4802 } 4803 if (drr->drr_type) 4804 (void) printf("\tdrr_type=%u\n", drr->drr_type); 4805 if (drr->drr_flags) 4806 (void) printf("\tdrr_flags=0x%x\n", drr->drr_flags); 4807 if (drr->drr_toguid) { 4808 (void) printf("\tdrr_toguid=%llu\n", 4809 (u_longlong_t)drr->drr_toguid); 4810 } 4811 if (drr->drr_fromguid) { 4812 (void) printf("\tdrr_fromguid=%llu\n", 4813 (u_longlong_t)drr->drr_fromguid); 4814 } 4815 if (drr->drr_toname[0]) { 4816 (void) printf("\tdrr_toname=%s\n", drr->drr_toname); 4817 } 4818 } 4819 4820 if (memcmp(&zc.zc_inject_record, &zero_injectrec, 4821 sizeof (zc.zc_inject_record))) { 4822 zinject_record_t *zi = &zc.zc_inject_record; 4823 (void) printf(" zc_inject_record:\n"); 4824 if (zi->zi_objset) { 4825 (void) printf("\tzi_objset=%llu\n", 4826 (u_longlong_t)zi->zi_objset); 4827 } 4828 if (zi->zi_object) { 4829 (void) printf("\tzi_object=%llu\n", 4830 (u_longlong_t)zi->zi_object); 4831 } 4832 if (zi->zi_start) { 4833 (void) printf("\tzi_start=%llu\n", 4834 (u_longlong_t)zi->zi_start); 4835 } 4836 if (zi->zi_end) { 4837 (void) printf("\tzi_end=%llu\n", 4838 (u_longlong_t)zi->zi_end); 4839 } 4840 if (zi->zi_guid) { 4841 (void) printf("\tzi_guid=%llu\n", 4842 (u_longlong_t)zi->zi_guid); 4843 } 4844 if (zi->zi_level) { 4845 (void) printf("\tzi_level=%lu\n", 4846 (ulong_t)zi->zi_level); 4847 } 4848 if (zi->zi_error) { 4849 (void) printf("\tzi_error=%lu\n", 4850 (ulong_t)zi->zi_error); 4851 } 4852 if (zi->zi_type) { 4853 (void) printf("\tzi_type=%llu\n", 4854 (u_longlong_t)zi->zi_type); 4855 } 4856 if (zi->zi_freq) { 4857 (void) printf("\tzi_freq=%lu\n", 4858 (ulong_t)zi->zi_freq); 4859 } 4860 if (zi->zi_failfast) { 4861 (void) printf("\tzi_failfast=%lu\n", 4862 (ulong_t)zi->zi_failfast); 4863 } 4864 if (zi->zi_func[0]) 4865 (void) printf("\tzi_func=%s\n", zi->zi_func); 4866 if (zi->zi_iotype) { 4867 (void) printf("\tzi_iotype=%lu\n", 4868 (ulong_t)zi->zi_iotype); 4869 } 4870 if (zi->zi_duration) { 4871 (void) printf("\tzi_duration=%ld\n", 4872 (long)zi->zi_duration); 4873 } 4874 if (zi->zi_timer) { 4875 (void) printf("\tzi_timer=%llu\n", 4876 (u_longlong_t)zi->zi_timer); 4877 } 4878 } 4879 4880 if (zc.zc_defer_destroy) { 4881 (void) printf(" zc_defer_destroy=%d\n", 4882 (int)zc.zc_defer_destroy); 4883 } 4884 if (zc.zc_flags) { 4885 (void) printf(" zc_flags=0x%x\n", 4886 zc.zc_flags); 4887 } 4888 if (zc.zc_action_handle) { 4889 (void) printf(" zc_action_handle=%llu\n", 4890 (u_longlong_t)zc.zc_action_handle); 4891 } 4892 if (zc.zc_cleanup_fd >= 0) 4893 (void) printf(" zc_cleanup_fd=%d\n", zc.zc_cleanup_fd); 4894 if (zc.zc_sendobj) { 4895 (void) printf(" zc_sendobj=%llu\n", 4896 (u_longlong_t)zc.zc_sendobj); 4897 } 4898 if (zc.zc_fromobj) { 4899 (void) printf(" zc_fromobj=%llu\n", 4900 (u_longlong_t)zc.zc_fromobj); 4901 } 4902 if (zc.zc_createtxg) { 4903 (void) printf(" zc_createtxg=%llu\n", 4904 (u_longlong_t)zc.zc_createtxg); 4905 } 4906 4907 if (memcmp(&zc.zc_stat, &zero_zstat, sizeof (zc.zc_stat))) { 4908 zfs_stat_t *zs = &zc.zc_stat; 4909 (void) printf(" zc_stat:\n"); 4910 if (zs->zs_gen) { 4911 (void) printf("\tzs_gen=%llu\n", 4912 (u_longlong_t)zs->zs_gen); 4913 } 4914 if (zs->zs_mode) { 4915 (void) printf("\tzs_mode=%llu\n", 4916 (u_longlong_t)zs->zs_mode); 4917 } 4918 if (zs->zs_links) { 4919 (void) printf("\tzs_links=%llu\n", 4920 (u_longlong_t)zs->zs_links); 4921 } 4922 if (zs->zs_ctime[0]) { 4923 (void) printf("\tzs_ctime[0]=%llu\n", 4924 (u_longlong_t)zs->zs_ctime[0]); 4925 } 4926 if (zs->zs_ctime[1]) { 4927 (void) printf("\tzs_ctime[1]=%llu\n", 4928 (u_longlong_t)zs->zs_ctime[1]); 4929 } 4930 } 4931 } 4932 4933 /* expound verbosely upon syscall arguments */ 4934 /*ARGSUSED*/ 4935 void 4936 expound(private_t *pri, long r0, int raw) 4937 { 4938 const lwpstatus_t *Lsp = pri->lwpstat; 4939 int lp64 = (data_model == PR_MODEL_LP64); 4940 int what = Lsp->pr_what; 4941 int err = pri->Errno; /* don't display output parameters */ 4942 /* for a failed system call */ 4943 /* for reporting sleeping system calls */ 4944 if (what == 0 && (Lsp->pr_flags & (PR_ASLEEP|PR_VFORKP))) 4945 what = Lsp->pr_syscall; 4946 4947 switch (what) { 4948 case SYS_gettimeofday: 4949 if (!err) 4950 show_timeofday(pri); 4951 break; 4952 case SYS_getitimer: 4953 if (!err && pri->sys_nargs > 1) 4954 show_itimerval(pri, (long)pri->sys_args[1], 4955 " value"); 4956 break; 4957 case SYS_setitimer: 4958 if (pri->sys_nargs > 1) 4959 show_itimerval(pri, (long)pri->sys_args[1], 4960 " value"); 4961 if (!err && pri->sys_nargs > 2) 4962 show_itimerval(pri, (long)pri->sys_args[2], 4963 "ovalue"); 4964 break; 4965 case SYS_stime: 4966 show_stime(pri); 4967 break; 4968 case SYS_times: 4969 if (!err) 4970 show_times(pri); 4971 break; 4972 case SYS_utssys: 4973 if (err) 4974 break; 4975 if (lp64) 4976 show_utssys(pri, r0); 4977 else 4978 show_utssys32(pri, r0); 4979 break; 4980 case SYS_ioctl: 4981 if (pri->sys_nargs >= 3) /* each case must decide for itself */ 4982 show_ioctl(pri, pri->sys_args[1], 4983 (long)pri->sys_args[2]); 4984 break; 4985 case SYS_fstatat: 4986 if (!err && pri->sys_nargs >= 3) 4987 show_stat(pri, (long)pri->sys_args[2]); 4988 break; 4989 case SYS_fstatat64: 4990 if (!err && pri->sys_nargs >= 3) 4991 show_stat64_32(pri, (long)pri->sys_args[2]); 4992 break; 4993 case SYS_stat: 4994 case SYS_fstat: 4995 case SYS_lstat: 4996 if (!err && pri->sys_nargs >= 2) 4997 show_stat(pri, (long)pri->sys_args[1]); 4998 break; 4999 case SYS_stat64: 5000 case SYS_fstat64: 5001 case SYS_lstat64: 5002 if (!err && pri->sys_nargs >= 2) 5003 show_stat64_32(pri, (long)pri->sys_args[1]); 5004 break; 5005 case SYS_statvfs: 5006 case SYS_fstatvfs: 5007 if (err) 5008 break; 5009 if (!lp64) { 5010 show_statvfs32(pri); 5011 break; 5012 } 5013 show_statvfs(pri); 5014 break; 5015 case SYS_statvfs64: 5016 case SYS_fstatvfs64: 5017 if (err) 5018 break; 5019 show_statvfs64(pri); 5020 break; 5021 case SYS_statfs: 5022 case SYS_fstatfs: 5023 if (err) 5024 break; 5025 if (lp64) 5026 show_statfs(pri); 5027 else 5028 show_statfs32(pri); 5029 break; 5030 case SYS_fcntl: 5031 show_fcntl(pri); 5032 break; 5033 case SYS_msgsys: 5034 show_msgsys(pri, r0); /* each case must decide for itself */ 5035 break; 5036 case SYS_semsys: 5037 show_semsys(pri); /* each case must decide for itself */ 5038 break; 5039 case SYS_shmsys: 5040 show_shmsys(pri); /* each case must decide for itself */ 5041 break; 5042 case SYS_getdents: 5043 if (err || pri->sys_nargs <= 1 || r0 <= 0) 5044 break; 5045 if (!lp64) { 5046 show_dents32(pri, (long)pri->sys_args[1], r0); 5047 break; 5048 } 5049 /* FALLTHROUGH */ 5050 case SYS_getdents64: 5051 if (err || pri->sys_nargs <= 1 || r0 <= 0) 5052 break; 5053 show_dents64(pri, (long)pri->sys_args[1], r0); 5054 break; 5055 case SYS_getmsg: 5056 show_gp_msg(pri, what); 5057 if (pri->sys_nargs > 3) 5058 show_hhex_int(pri, (long)pri->sys_args[3], "flags"); 5059 break; 5060 case SYS_getpmsg: 5061 show_gp_msg(pri, what); 5062 if (pri->sys_nargs > 3) 5063 show_hhex_int(pri, (long)pri->sys_args[3], "band"); 5064 if (pri->sys_nargs > 4) 5065 show_hhex_int(pri, (long)pri->sys_args[4], "flags"); 5066 break; 5067 case SYS_putmsg: 5068 case SYS_putpmsg: 5069 show_gp_msg(pri, what); 5070 break; 5071 case SYS_pollsys: 5072 show_pollsys(pri); 5073 break; 5074 case SYS_setgroups: 5075 if (pri->sys_nargs > 1 && (r0 = pri->sys_args[0]) > 0) 5076 show_groups(pri, (long)pri->sys_args[1], r0); 5077 break; 5078 case SYS_getgroups: 5079 if (!err && pri->sys_nargs > 1 && pri->sys_args[0] > 0) 5080 show_groups(pri, (long)pri->sys_args[1], r0); 5081 break; 5082 case SYS_sigprocmask: 5083 if (pri->sys_nargs > 1) 5084 show_sigset(pri, (long)pri->sys_args[1], " set"); 5085 if (!err && pri->sys_nargs > 2) 5086 show_sigset(pri, (long)pri->sys_args[2], "oset"); 5087 break; 5088 case SYS_sigsuspend: 5089 case SYS_sigtimedwait: 5090 if (pri->sys_nargs > 0) 5091 show_sigset(pri, (long)pri->sys_args[0], "sigmask"); 5092 if (!err && pri->sys_nargs > 1) 5093 show_siginfo(pri, (long)pri->sys_args[1]); 5094 if (pri->sys_nargs > 2) 5095 show_timestruc(pri, (long)pri->sys_args[2], "timeout"); 5096 break; 5097 case SYS_sigaltstack: 5098 if (pri->sys_nargs > 0) 5099 show_sigaltstack(pri, (long)pri->sys_args[0], 5100 "new"); 5101 if (!err && pri->sys_nargs > 1) 5102 show_sigaltstack(pri, (long)pri->sys_args[1], 5103 "old"); 5104 break; 5105 case SYS_sigaction: 5106 if (pri->sys_nargs > 1) 5107 show_sigaction(pri, (long)pri->sys_args[1], 5108 "new", 0); 5109 if (!err && pri->sys_nargs > 2) 5110 show_sigaction(pri, (long)pri->sys_args[2], 5111 "old", r0); 5112 break; 5113 case SYS_signotify: 5114 if (pri->sys_nargs > 1) 5115 show_siginfo(pri, (long)pri->sys_args[1]); 5116 break; 5117 case SYS_sigresend: 5118 if (pri->sys_nargs > 1) 5119 show_siginfo(pri, (long)pri->sys_args[1]); 5120 if (pri->sys_nargs > 2) 5121 show_sigset(pri, (long)pri->sys_args[2], "sigmask"); 5122 break; 5123 case SYS_sigpending: 5124 if (!err && pri->sys_nargs > 1) 5125 show_sigset(pri, (long)pri->sys_args[1], "sigmask"); 5126 break; 5127 case SYS_waitid: 5128 if (!err && pri->sys_nargs > 2) 5129 show_siginfo(pri, (long)pri->sys_args[2]); 5130 break; 5131 case SYS_sigsendsys: 5132 if (pri->sys_nargs > 0) 5133 show_procset(pri, (long)pri->sys_args[0]); 5134 break; 5135 case SYS_priocntlsys: 5136 if (pri->sys_nargs > 1) 5137 show_procset(pri, (long)pri->sys_args[1]); 5138 break; 5139 case SYS_mincore: 5140 if (!err && pri->sys_nargs > 2) 5141 show_bool(pri, (long)pri->sys_args[2], 5142 (pri->sys_args[1] + pagesize - 1) / pagesize); 5143 break; 5144 case SYS_readv: 5145 case SYS_writev: 5146 if (pri->sys_nargs > 2) { 5147 int i = pri->sys_args[0]+1; 5148 int showbuf = FALSE; 5149 long nb = (what == SYS_readv)? r0 : 32*1024; 5150 5151 if ((what == SYS_readv && !err && 5152 prismember(&readfd, i)) || 5153 (what == SYS_writev && 5154 prismember(&writefd, i))) 5155 showbuf = TRUE; 5156 show_iovec(pri, (long)pri->sys_args[1], 5157 pri->sys_args[2], showbuf, nb); 5158 } 5159 break; 5160 case SYS_getrlimit: 5161 if (err) 5162 break; 5163 /*FALLTHROUGH*/ 5164 case SYS_setrlimit: 5165 if (pri->sys_nargs <= 1) 5166 break; 5167 if (lp64) 5168 show_rlimit64(pri, (long)pri->sys_args[1]); 5169 else 5170 show_rlimit32(pri, (long)pri->sys_args[1]); 5171 break; 5172 case SYS_getrlimit64: 5173 if (err) 5174 break; 5175 /*FALLTHROUGH*/ 5176 case SYS_setrlimit64: 5177 if (pri->sys_nargs <= 1) 5178 break; 5179 show_rlimit64(pri, (long)pri->sys_args[1]); 5180 break; 5181 case SYS_uname: 5182 if (!err && pri->sys_nargs > 0) 5183 show_nuname(pri, (long)pri->sys_args[0]); 5184 break; 5185 case SYS_adjtime: 5186 if (!err && pri->sys_nargs > 1) 5187 show_adjtime(pri, (long)pri->sys_args[0], 5188 (long)pri->sys_args[1]); 5189 break; 5190 case SYS_lwp_info: 5191 if (!err && pri->sys_nargs > 0) 5192 show_timestruc(pri, (long)pri->sys_args[0], "cpu time"); 5193 break; 5194 case SYS_lwp_wait: 5195 if (!err && pri->sys_nargs > 1) 5196 show_int(pri, (long)pri->sys_args[1], "lwpid"); 5197 break; 5198 case SYS_lwp_mutex_wakeup: 5199 case SYS_lwp_mutex_unlock: 5200 case SYS_lwp_mutex_trylock: 5201 case SYS_lwp_mutex_register: 5202 if (pri->sys_nargs > 0) 5203 show_mutex(pri, (long)pri->sys_args[0]); 5204 break; 5205 case SYS_lwp_mutex_timedlock: 5206 if (pri->sys_nargs > 0) 5207 show_mutex(pri, (long)pri->sys_args[0]); 5208 if (pri->sys_nargs > 1) 5209 show_timestruc(pri, (long)pri->sys_args[1], "timeout"); 5210 break; 5211 case SYS_lwp_cond_wait: 5212 if (pri->sys_nargs > 0) 5213 show_condvar(pri, (long)pri->sys_args[0]); 5214 if (pri->sys_nargs > 1) 5215 show_mutex(pri, (long)pri->sys_args[1]); 5216 if (pri->sys_nargs > 2) 5217 show_timestruc(pri, (long)pri->sys_args[2], "timeout"); 5218 break; 5219 case SYS_lwp_cond_signal: 5220 case SYS_lwp_cond_broadcast: 5221 if (pri->sys_nargs > 0) 5222 show_condvar(pri, (long)pri->sys_args[0]); 5223 break; 5224 case SYS_lwp_sema_trywait: 5225 case SYS_lwp_sema_post: 5226 if (pri->sys_nargs > 0) 5227 show_sema(pri, (long)pri->sys_args[0]); 5228 break; 5229 case SYS_lwp_sema_timedwait: 5230 if (pri->sys_nargs > 0) 5231 show_sema(pri, (long)pri->sys_args[0]); 5232 if (pri->sys_nargs > 1) 5233 show_timestruc(pri, (long)pri->sys_args[1], "timeout"); 5234 break; 5235 case SYS_lwp_rwlock_sys: 5236 if (pri->sys_nargs > 1) 5237 show_rwlock(pri, (long)pri->sys_args[1]); 5238 if (pri->sys_nargs > 2 && 5239 (pri->sys_args[0] == 0 || pri->sys_args[0] == 1)) 5240 show_timestruc(pri, (long)pri->sys_args[2], "timeout"); 5241 break; 5242 case SYS_lwp_create: 5243 /* XXX print some values in ucontext ??? */ 5244 if (!err && pri->sys_nargs > 2) 5245 show_int(pri, (long)pri->sys_args[2], "lwpid"); 5246 break; 5247 case SYS_kaio: 5248 if (pri->sys_args[0] == AIOWAIT && !err && pri->sys_nargs > 1) 5249 show_timeval(pri, (long)pri->sys_args[1], "timeout"); 5250 break; 5251 case SYS_nanosleep: 5252 if (pri->sys_nargs > 0) 5253 show_timestruc(pri, (long)pri->sys_args[0], "tmout"); 5254 if (pri->sys_nargs > 1 && (err == 0 || err == EINTR)) 5255 show_timestruc(pri, (long)pri->sys_args[1], "resid"); 5256 break; 5257 case SYS_privsys: 5258 switch (pri->sys_args[0]) { 5259 case PRIVSYS_SETPPRIV: 5260 case PRIVSYS_GETPPRIV: 5261 if (!err) 5262 show_privset(pri, (long)pri->sys_args[3], 5263 (size_t)pri->sys_args[4], ""); 5264 } 5265 break; 5266 case SYS_ucredsys: 5267 switch (pri->sys_args[0]) { 5268 case UCREDSYS_UCREDGET: 5269 case UCREDSYS_GETPEERUCRED: 5270 if (err == 0) 5271 show_ucred(pri, (long)pri->sys_args[2]); 5272 break; 5273 } 5274 break; 5275 case SYS_bind: 5276 case SYS_connect: 5277 if (pri->sys_nargs > 2) 5278 show_sockaddr(pri, "name", (long)pri->sys_args[1], 5279 0, (long)pri->sys_args[2]); 5280 break; 5281 case SYS_sendto: 5282 if (pri->sys_nargs > 5) 5283 show_sockaddr(pri, "to", (long)pri->sys_args[4], 0, 5284 pri->sys_args[5]); 5285 break; 5286 case SYS_accept: 5287 if (!err && pri->sys_nargs > 2) 5288 show_sockaddr(pri, "name", (long)pri->sys_args[1], 5289 (long)pri->sys_args[2], 0); 5290 break; 5291 case SYS_getsockname: 5292 case SYS_getpeername: 5293 if (!err && pri->sys_nargs > 2) 5294 show_sockaddr(pri, "name", (long)pri->sys_args[1], 5295 (long)pri->sys_args[2], 0); 5296 break; 5297 case SYS_cladm: 5298 if (!err && pri->sys_nargs > 2) 5299 show_cladm(pri, pri->sys_args[0], pri->sys_args[1], 5300 (long)pri->sys_args[2]); 5301 break; 5302 case SYS_recvfrom: 5303 if (!err && pri->sys_nargs > 5) 5304 show_sockaddr(pri, "from", (long)pri->sys_args[4], 5305 (long)pri->sys_args[5], 0); 5306 break; 5307 case SYS_recvmsg: 5308 if (err) 5309 break; 5310 /* FALLTHROUGH */ 5311 case SYS_sendmsg: 5312 if (pri->sys_nargs <= 2) 5313 break; 5314 if (lp64) 5315 show_msghdr(pri, pri->sys_args[1]); 5316 else 5317 show_msghdr32(pri, pri->sys_args[1]); 5318 break; 5319 case SYS_door: 5320 show_doors(pri); 5321 break; 5322 case SYS_sendfilev: 5323 if (pri->sys_nargs != 5) 5324 break; 5325 5326 if (pri->sys_args[0] == SENDFILEV) { 5327 show_sendfilevec(pri, (int)pri->sys_args[1], 5328 (sendfilevec_t *)pri->sys_args[2], 5329 (int)pri->sys_args[3]); 5330 } else if (pri->sys_args[0] == SENDFILEV64) { 5331 show_sendfilevec64(pri, (int)pri->sys_args[1], 5332 (sendfilevec64_t *)pri->sys_args[2], 5333 (int)pri->sys_args[3]); 5334 } 5335 break; 5336 case SYS_memcntl: 5337 show_memcntl(pri); 5338 break; 5339 case SYS_lwp_park: 5340 /* 5341 * subcode 0: lwp_park(timespec_t *, id_t) 5342 * subcode 4: lwp_set_park(timespec_t *, id_t) 5343 */ 5344 if (pri->sys_nargs > 1 && 5345 (pri->sys_args[0] == 0 || pri->sys_args[0] == 4)) 5346 show_timestruc(pri, (long)pri->sys_args[1], "timeout"); 5347 /* subcode 2: lwp_unpark_all(id_t *, int) */ 5348 if (pri->sys_nargs > 2 && pri->sys_args[0] == 2) 5349 show_ids(pri, (long)pri->sys_args[1], 5350 (int)pri->sys_args[2]); 5351 break; 5352 case SYS_ntp_gettime: 5353 if (!err) 5354 show_ntp_gettime(pri); 5355 break; 5356 case SYS_ntp_adjtime: 5357 if (!err) 5358 show_ntp_adjtime(pri); 5359 break; 5360 case SYS_rusagesys: 5361 if (!err) 5362 if (pri->sys_args[0] == _RUSAGESYS_GETRUSAGE) { 5363 if (!lp64) 5364 show_getrusage32(pri->sys_args[1]); 5365 else 5366 show_getrusage(pri->sys_args[1]); 5367 } 5368 break; 5369 case SYS_port: 5370 show_ports(pri); 5371 break; 5372 case SYS_zone: 5373 show_zones(pri); 5374 break; 5375 case SYS_rctlsys: 5376 show_rctls(pri); 5377 break; 5378 case SYS_utimesys: 5379 show_utimesys(pri); 5380 break; 5381 case SYS_sockconfig: 5382 show_sockconfig(pri); 5383 break; 5384 } 5385 } 5386