xref: /illumos-gate/usr/src/cmd/truss/expound.c (revision 27aa4812)
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
mk_ctime(char * str,size_t maxsize,time_t value)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
prtime(private_t * pri,const char * name,time_t value)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
prtimeval(private_t * pri,const char * name,struct timeval * value)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
prtimestruc(private_t * pri,const char * name,timestruc_t * value)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
show_utimens(private_t * pri,long offset)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
show_timeofday(private_t * pri)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
show_itimerval(private_t * pri,long offset,const char * name)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
show_timeval(private_t * pri,long offset,const char * name)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
show_timestruc(private_t * pri,long offset,const char * name)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, &timestruc, sizeof (timestruc), offset)
297 		    != sizeof (timestruc))
298 			return;
299 	} else {
300 		timestruc32_t timestruc32;
301 
302 		if (Pread(Proc, &timestruc32, sizeof (timestruc32), offset)
303 		    != sizeof (timestruc32))
304 			return;
305 
306 		TIMESPEC32_TO_TIMESPEC(&timestruc, &timestruc32);
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
show_stime(private_t * pri)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
show_times(private_t * pri)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
show_uname(private_t * pri,long offset)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
show_ustat(private_t * pri,long offset)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 #ifdef _LP64
415 void
show_ustat32(private_t * pri,long offset)416 show_ustat32(private_t *pri, long offset)
417 {
418 	struct ustat32 ubuf;
419 
420 	if (offset != 0 &&
421 	    Pread(Proc, &ubuf, sizeof (ubuf), offset) == sizeof (ubuf)) {
422 		(void) printf(
423 		    "%s\ttfree=%-6d tinode=%-5u fname=%-6.6s fpack=%-.6s\n",
424 		    pri->pname,
425 		    ubuf.f_tfree,
426 		    ubuf.f_tinode,
427 		    ubuf.f_fname,
428 		    ubuf.f_fpack);
429 	}
430 }
431 #endif	/* _LP64 */
432 
433 void
show_fusers(private_t * pri,long offset,long nproc)434 show_fusers(private_t *pri, long offset, long nproc)
435 {
436 	f_user_t fubuf;
437 	int serial = (nproc > 4);
438 
439 	if (offset == 0)
440 		return;
441 
442 	/* enter region of lengthy output */
443 	if (serial)
444 		Eserialize();
445 
446 	while (nproc > 0 &&
447 	    Pread(Proc, &fubuf, sizeof (fubuf), offset) == sizeof (fubuf)) {
448 		(void) printf("%s\tpid=%-5d uid=%-5u flags=%s\n",
449 		    pri->pname,
450 		    (int)fubuf.fu_pid,
451 		    fubuf.fu_uid,
452 		    fuflags(pri, fubuf.fu_flags));
453 		nproc--;
454 		offset += sizeof (fubuf);
455 	}
456 
457 	/* exit region of lengthy output */
458 	if (serial)
459 		Xserialize();
460 }
461 
462 void
show_utssys(private_t * pri,long r0)463 show_utssys(private_t *pri, long r0)
464 {
465 	if (pri->sys_nargs >= 3) {
466 		switch (pri->sys_args[2]) {
467 		case UTS_UNAME:
468 			show_uname(pri, (long)pri->sys_args[0]);
469 			break;
470 		case UTS_USTAT:
471 			show_ustat(pri, (long)pri->sys_args[0]);
472 			break;
473 		case UTS_FUSERS:
474 			show_fusers(pri, (long)pri->sys_args[3], r0);
475 			break;
476 		}
477 	}
478 }
479 
480 #ifdef _LP64
481 void
show_utssys32(private_t * pri,long r0)482 show_utssys32(private_t *pri, long r0)
483 {
484 	if (pri->sys_nargs >= 3) {
485 		switch (pri->sys_args[2]) {
486 		case UTS_UNAME:
487 			show_uname(pri, (long)pri->sys_args[0]);
488 			break;
489 		case UTS_USTAT:
490 			show_ustat32(pri, (long)pri->sys_args[0]);
491 			break;
492 		case UTS_FUSERS:
493 			show_fusers(pri, (long)pri->sys_args[3], r0);
494 			break;
495 		}
496 	}
497 }
498 #endif	/* _LP64 */
499 
500 void
show_cladm(private_t * pri,int code,int function,long offset)501 show_cladm(private_t *pri, int code, int function, long offset)
502 {
503 	int	arg;
504 
505 	switch (code) {
506 	case CL_INITIALIZE:
507 		switch (function) {
508 		case CL_GET_BOOTFLAG:
509 			if (Pread(Proc, &arg, sizeof (arg), offset)
510 			    == sizeof (arg)) {
511 				if (arg & CLUSTER_CONFIGURED)
512 					(void) printf("%s\tbootflags="
513 					    "CLUSTER_CONFIGURED", pri->pname);
514 				if (arg & CLUSTER_BOOTED)
515 					(void) printf("|CLUSTER_BOOTED\n");
516 			}
517 			break;
518 		}
519 		break;
520 	case CL_CONFIG:
521 		switch (function) {
522 		case CL_NODEID:
523 		case CL_HIGHEST_NODEID:
524 			if (Pread(Proc, &arg, sizeof (arg), offset)
525 			    == sizeof (arg))
526 				(void) printf("%s\tnodeid=%d\n",
527 				    pri->pname, arg);
528 		}
529 		break;
530 	}
531 }
532 
533 #define	ALL_LOCK_TYPES						\
534 	(USYNC_PROCESS | LOCK_ERRORCHECK | LOCK_RECURSIVE |	\
535 	LOCK_PRIO_INHERIT | LOCK_PRIO_PROTECT | LOCK_ROBUST |	\
536 	USYNC_PROCESS_ROBUST)
537 
538 /* return cv and mutex types */
539 const char *
synch_type(private_t * pri,uint_t type)540 synch_type(private_t *pri, uint_t type)
541 {
542 	char *str = pri->code_buf;
543 
544 	if (type & USYNC_PROCESS)
545 		(void) strcpy(str, "USYNC_PROCESS");
546 	else
547 		(void) strcpy(str, "USYNC_THREAD");
548 
549 	if (type & LOCK_ERRORCHECK)
550 		(void) strcat(str, "|LOCK_ERRORCHECK");
551 	if (type & LOCK_RECURSIVE)
552 		(void) strcat(str, "|LOCK_RECURSIVE");
553 	if (type & LOCK_PRIO_INHERIT)
554 		(void) strcat(str, "|LOCK_PRIO_INHERIT");
555 	if (type & LOCK_PRIO_PROTECT)
556 		(void) strcat(str, "|LOCK_PRIO_PROTECT");
557 	if (type & LOCK_ROBUST)
558 		(void) strcat(str, "|LOCK_ROBUST");
559 	if (type & USYNC_PROCESS_ROBUST)
560 		(void) strcat(str, "|USYNC_PROCESS_ROBUST");
561 
562 	if ((type &= ~ALL_LOCK_TYPES) != 0)
563 		(void) sprintf(str + strlen(str), "|0x%.4X", type);
564 
565 	return ((const char *)str);
566 }
567 
568 void
show_mutex(private_t * pri,long offset)569 show_mutex(private_t *pri, long offset)
570 {
571 	lwp_mutex_t mutex;
572 
573 	if (Pread(Proc, &mutex, sizeof (mutex), offset) == sizeof (mutex)) {
574 		(void) printf("%s\tmutex type: %s\n",
575 		    pri->pname,
576 		    synch_type(pri, mutex.mutex_type));
577 	}
578 }
579 
580 void
show_condvar(private_t * pri,long offset)581 show_condvar(private_t *pri, long offset)
582 {
583 	lwp_cond_t condvar;
584 
585 	if (Pread(Proc, &condvar, sizeof (condvar), offset)
586 	    == sizeof (condvar)) {
587 		(void) printf("%s\tcondvar type: %s\n",
588 		    pri->pname,
589 		    synch_type(pri, condvar.cond_type));
590 	}
591 }
592 
593 void
show_sema(private_t * pri,long offset)594 show_sema(private_t *pri, long offset)
595 {
596 	lwp_sema_t sema;
597 
598 	if (Pread(Proc, &sema, sizeof (sema), offset) == sizeof (sema)) {
599 		(void) printf("%s\tsema type: %s  count = %u\n",
600 		    pri->pname,
601 		    synch_type(pri, sema.sema_type),
602 		    sema.sema_count);
603 	}
604 }
605 
606 void
show_rwlock(private_t * pri,long offset)607 show_rwlock(private_t *pri, long offset)
608 {
609 	lwp_rwlock_t rwlock;
610 
611 	if (Pread(Proc, &rwlock, sizeof (rwlock), offset) == sizeof (rwlock)) {
612 		(void) printf("%s\trwlock type: %s  readers = %d\n",
613 		    pri->pname,
614 		    synch_type(pri, rwlock.rwlock_type),
615 		    rwlock.rwlock_readers);
616 	}
617 }
618 
619 /* represent character as itself ('c') or octal (012) */
620 char *
show_char(char * buf,int c)621 show_char(char *buf, int c)
622 {
623 	const char *fmt;
624 
625 	if (c >= ' ' && c < 0177)
626 		fmt = "'%c'";
627 	else
628 		fmt = "%.3o";
629 
630 	(void) sprintf(buf, fmt, c&0xff);
631 	return (buf);
632 }
633 
634 void
show_termio(private_t * pri,long offset)635 show_termio(private_t *pri, long offset)
636 {
637 	struct termio termio;
638 	char cbuf[8];
639 	int i;
640 
641 	if (Pread(Proc, &termio, sizeof (termio), offset) == sizeof (termio)) {
642 		(void) printf(
643 		"%s\tiflag=0%.6o oflag=0%.6o cflag=0%.6o lflag=0%.6o line=%d\n",
644 		    pri->pname,
645 		    termio.c_iflag,
646 		    termio.c_oflag,
647 		    termio.c_cflag,
648 		    termio.c_lflag,
649 		    termio.c_line);
650 		(void) printf("%s\t    cc: ", pri->pname);
651 		for (i = 0; i < NCC; i++)
652 			(void) printf(" %s",
653 			    show_char(cbuf, (int)termio.c_cc[i]));
654 		(void) fputc('\n', stdout);
655 	}
656 }
657 
658 void
show_termios(private_t * pri,long offset)659 show_termios(private_t *pri, long offset)
660 {
661 	struct termios termios;
662 	char cbuf[8];
663 	int i;
664 
665 	if (Pread(Proc, &termios, sizeof (termios), offset)
666 	    == sizeof (termios)) {
667 		(void) printf(
668 		    "%s\tiflag=0%.6o oflag=0%.6o cflag=0%.6o lflag=0%.6o\n",
669 		    pri->pname,
670 		    termios.c_iflag,
671 		    termios.c_oflag,
672 		    termios.c_cflag,
673 		    termios.c_lflag);
674 		(void) printf("%s\t    cc: ", pri->pname);
675 		for (i = 0; i < NCCS; i++) {
676 			if (i == NCC)	/* show new chars on new line */
677 				(void) printf("\n%s\t\t", pri->pname);
678 			(void) printf(" %s",
679 			    show_char(cbuf, (int)termios.c_cc[i]));
680 		}
681 		(void) fputc('\n', stdout);
682 	}
683 }
684 
685 void
show_termiox(private_t * pri,long offset)686 show_termiox(private_t *pri, long offset)
687 {
688 	struct termiox termiox;
689 	int i;
690 
691 	if (Pread(Proc, &termiox, sizeof (termiox), offset)
692 	    == sizeof (termiox)) {
693 		(void) printf("%s\thflag=0%.3o cflag=0%.3o rflag=0%.3o",
694 		    pri->pname,
695 		    termiox.x_hflag,
696 		    termiox.x_cflag,
697 		    termiox.x_rflag[0]);
698 		for (i = 1; i < NFF; i++)
699 			(void) printf(",0%.3o", termiox.x_rflag[i]);
700 		(void) printf(" sflag=0%.3o\n",
701 		    termiox.x_sflag);
702 	}
703 }
704 
705 void
show_sgttyb(private_t * pri,long offset)706 show_sgttyb(private_t *pri, long offset)
707 {
708 	struct sgttyb sgttyb;
709 
710 	if (Pread(Proc, &sgttyb, sizeof (sgttyb), offset) == sizeof (sgttyb)) {
711 		char erase[8];
712 		char kill[8];
713 
714 		(void) printf(
715 		"%s\tispeed=%-2d ospeed=%-2d erase=%s kill=%s flags=0x%.8x\n",
716 		    pri->pname,
717 		    sgttyb.sg_ispeed&0xff,
718 		    sgttyb.sg_ospeed&0xff,
719 		    show_char(erase, sgttyb.sg_erase),
720 		    show_char(kill, sgttyb.sg_kill),
721 		    sgttyb.sg_flags);
722 	}
723 }
724 
725 void
show_ltchars(private_t * pri,long offset)726 show_ltchars(private_t *pri, long offset)
727 {
728 	struct ltchars ltchars;
729 	char *p;
730 	char cbuf[8];
731 	int i;
732 
733 	if (Pread(Proc, &ltchars, sizeof (ltchars), offset)
734 	    == sizeof (ltchars)) {
735 		(void) printf("%s\t    cc: ", pri->pname);
736 		for (p = (char *)&ltchars, i = 0; i < sizeof (ltchars); i++)
737 			(void) printf(" %s", show_char(cbuf, (int)*p++));
738 		(void) fputc('\n', stdout);
739 	}
740 }
741 
742 void
show_tchars(private_t * pri,long offset)743 show_tchars(private_t *pri, long offset)
744 {
745 	struct tchars tchars;
746 	char *p;
747 	char cbuf[8];
748 	int i;
749 
750 	if (Pread(Proc, &tchars, sizeof (tchars), offset) == sizeof (tchars)) {
751 		(void) printf("%s\t    cc: ", pri->pname);
752 		for (p = (char *)&tchars, i = 0; i < sizeof (tchars); i++)
753 			(void) printf(" %s", show_char(cbuf, (int)*p++));
754 		(void) fputc('\n', stdout);
755 	}
756 }
757 
758 void
show_termcb(private_t * pri,long offset)759 show_termcb(private_t *pri, long offset)
760 {
761 	struct termcb termcb;
762 
763 	if (Pread(Proc, &termcb, sizeof (termcb), offset) == sizeof (termcb)) {
764 		(void) printf(
765 		    "%s\tflgs=0%.2o termt=%d crow=%d ccol=%d vrow=%d lrow=%d\n",
766 		    pri->pname,
767 		    termcb.st_flgs&0xff,
768 		    termcb.st_termt&0xff,
769 		    termcb.st_crow&0xff,
770 		    termcb.st_ccol&0xff,
771 		    termcb.st_vrow&0xff,
772 		    termcb.st_lrow&0xff);
773 	}
774 }
775 
776 /* integer value pointed to by ioctl() arg */
777 void
show_strint(private_t * pri,int code,long offset)778 show_strint(private_t *pri, int code, long offset)
779 {
780 	int val;
781 
782 	if (Pread(Proc, &val, sizeof (val), offset) == sizeof (val)) {
783 		const char *s = NULL;
784 
785 		switch (code) {		/* interpret these symbolically */
786 		case I_GRDOPT:
787 			s = strrdopt(val);
788 			break;
789 		case I_GETSIG:
790 			s = strevents(pri, val);
791 			break;
792 		case TIOCFLUSH:
793 			s = tiocflush(pri, val);
794 			break;
795 		}
796 
797 		if (s == NULL)
798 			(void) printf("%s\t0x%.8lX: %d\n",
799 			    pri->pname, offset, val);
800 		else
801 			(void) printf("%s\t0x%.8lX: %s\n",
802 			    pri->pname, offset, s);
803 	}
804 }
805 
806 void
show_strioctl(private_t * pri,long offset)807 show_strioctl(private_t *pri, long offset)
808 {
809 	struct strioctl strioctl;
810 
811 	if (Pread(Proc, &strioctl, sizeof (strioctl), offset) ==
812 	    sizeof (strioctl)) {
813 		(void) printf(
814 		    "%s\tcmd=%s timout=%d len=%d dp=0x%.8lX\n",
815 		    pri->pname,
816 		    ioctlname(pri, strioctl.ic_cmd),
817 		    strioctl.ic_timout,
818 		    strioctl.ic_len,
819 		    (long)strioctl.ic_dp);
820 
821 		if (pri->recur++ == 0)	/* avoid indefinite recursion */
822 			show_ioctl(pri, strioctl.ic_cmd,
823 			    (long)strioctl.ic_dp);
824 		--pri->recur;
825 	}
826 }
827 
828 #ifdef _LP64
829 void
show_strioctl32(private_t * pri,long offset)830 show_strioctl32(private_t *pri, long offset)
831 {
832 	struct strioctl32 strioctl;
833 
834 	if (Pread(Proc, &strioctl, sizeof (strioctl), offset) ==
835 	    sizeof (strioctl)) {
836 		(void) printf(
837 		    "%s\tcmd=%s timout=%d len=%d dp=0x%.8lX\n",
838 		    pri->pname,
839 		    ioctlname(pri, strioctl.ic_cmd),
840 		    strioctl.ic_timout,
841 		    strioctl.ic_len,
842 		    (long)strioctl.ic_dp);
843 
844 		if (pri->recur++ == 0)	/* avoid indefinite recursion */
845 			show_ioctl(pri, strioctl.ic_cmd,
846 			    (long)strioctl.ic_dp);
847 		--pri->recur;
848 	}
849 }
850 #endif	/* _LP64 */
851 
852 void
print_strbuf(private_t * pri,struct strbuf * sp,const char * name,int dump)853 print_strbuf(private_t *pri, struct strbuf *sp, const char *name, int dump)
854 {
855 	(void) printf(
856 	    "%s\t%s:  maxlen=%-4d len=%-4d buf=0x%.8lX",
857 	    pri->pname,
858 	    name,
859 	    sp->maxlen,
860 	    sp->len,
861 	    (long)sp->buf);
862 	/*
863 	 * Should we show the buffer contents?
864 	 * Keyed to the '-r fds' and '-w fds' options?
865 	 */
866 	if (sp->buf == NULL || sp->len <= 0)
867 		(void) fputc('\n', stdout);
868 	else {
869 		int nb = (sp->len > 8)? 8 : sp->len;
870 		char buffer[8];
871 		char obuf[40];
872 
873 		if (Pread(Proc, buffer, (size_t)nb, (long)sp->buf) == nb) {
874 			(void) strcpy(obuf, ": \"");
875 			showbytes(buffer, nb, obuf+3);
876 			(void) strcat(obuf,
877 			    (nb == sp->len)?
878 			    (const char *)"\"" : (const char *)"\"..");
879 			(void) fputs(obuf, stdout);
880 		}
881 		(void) fputc('\n', stdout);
882 		if (dump && sp->len > 8)
883 			showbuffer(pri, (long)sp->buf, (long)sp->len);
884 	}
885 }
886 
887 #ifdef _LP64
888 void
print_strbuf32(private_t * pri,struct strbuf32 * sp,const char * name,int dump)889 print_strbuf32(private_t *pri, struct strbuf32 *sp, const char *name, int dump)
890 {
891 	(void) printf(
892 	    "%s\t%s:  maxlen=%-4d len=%-4d buf=0x%.8lX",
893 	    pri->pname,
894 	    name,
895 	    sp->maxlen,
896 	    sp->len,
897 	    (long)sp->buf);
898 	/*
899 	 * Should we show the buffer contents?
900 	 * Keyed to the '-r fds' and '-w fds' options?
901 	 */
902 	if (sp->buf == 0 || sp->len <= 0)
903 		(void) fputc('\n', stdout);
904 	else {
905 		int nb = (sp->len > 8)? 8 : sp->len;
906 		char buffer[8];
907 		char obuf[40];
908 
909 		if (Pread(Proc, buffer, (size_t)nb, (long)sp->buf) == nb) {
910 			(void) strcpy(obuf, ": \"");
911 			showbytes(buffer, nb, obuf+3);
912 			(void) strcat(obuf,
913 			    (nb == sp->len)?
914 			    (const char *)"\"" : (const char *)"\"..");
915 			(void) fputs(obuf, stdout);
916 		}
917 		(void) fputc('\n', stdout);
918 		if (dump && sp->len > 8)
919 			showbuffer(pri, (long)sp->buf, (long)sp->len);
920 	}
921 }
922 #endif	/* _LP64 */
923 
924 /* strpeek and strfdinsert flags word */
925 const char *
strflags(private_t * pri,int flags)926 strflags(private_t *pri, int flags)
927 {
928 	const char *s;
929 
930 	switch (flags) {
931 	case 0:
932 		s = "0";
933 		break;
934 	case RS_HIPRI:
935 		s = "RS_HIPRI";
936 		break;
937 	default:
938 		(void) sprintf(pri->code_buf, "0x%.4X", flags);
939 		s = pri->code_buf;
940 	}
941 
942 	return (s);
943 }
944 
945 void
show_strpeek(private_t * pri,long offset)946 show_strpeek(private_t *pri, long offset)
947 {
948 	struct strpeek strpeek;
949 
950 	if (Pread(Proc, &strpeek, sizeof (strpeek), offset)
951 	    == sizeof (strpeek)) {
952 
953 		print_strbuf(pri, &strpeek.ctlbuf, "ctl", FALSE);
954 		print_strbuf(pri, &strpeek.databuf, "dat", FALSE);
955 
956 		(void) printf("%s\tflags=%s\n",
957 		    pri->pname,
958 		    strflags(pri, strpeek.flags));
959 	}
960 }
961 
962 #ifdef _LP64
963 void
show_strpeek32(private_t * pri,long offset)964 show_strpeek32(private_t *pri, long offset)
965 {
966 	struct strpeek32 strpeek;
967 
968 	if (Pread(Proc, &strpeek, sizeof (strpeek), offset)
969 	    == sizeof (strpeek)) {
970 
971 		print_strbuf32(pri, &strpeek.ctlbuf, "ctl", FALSE);
972 		print_strbuf32(pri, &strpeek.databuf, "dat", FALSE);
973 
974 		(void) printf("%s\tflags=%s\n",
975 		    pri->pname,
976 		    strflags(pri, strpeek.flags));
977 	}
978 }
979 #endif	/* _LP64 */
980 
981 void
show_strfdinsert(private_t * pri,long offset)982 show_strfdinsert(private_t *pri, long offset)
983 {
984 	struct strfdinsert strfdinsert;
985 
986 	if (Pread(Proc, &strfdinsert, sizeof (strfdinsert), offset) ==
987 	    sizeof (strfdinsert)) {
988 
989 		print_strbuf(pri, &strfdinsert.ctlbuf, "ctl", FALSE);
990 		print_strbuf(pri, &strfdinsert.databuf, "dat", FALSE);
991 
992 		(void) printf("%s\tflags=%s fildes=%d offset=%d\n",
993 		    pri->pname,
994 		    strflags(pri, strfdinsert.flags),
995 		    strfdinsert.fildes,
996 		    strfdinsert.offset);
997 	}
998 }
999 
1000 #ifdef _LP64
1001 void
show_strfdinsert32(private_t * pri,long offset)1002 show_strfdinsert32(private_t *pri, long offset)
1003 {
1004 	struct strfdinsert32 strfdinsert;
1005 
1006 	if (Pread(Proc, &strfdinsert, sizeof (strfdinsert), offset) ==
1007 	    sizeof (strfdinsert)) {
1008 
1009 		print_strbuf32(pri, &strfdinsert.ctlbuf, "ctl", FALSE);
1010 		print_strbuf32(pri, &strfdinsert.databuf, "dat", FALSE);
1011 
1012 		(void) printf("%s\tflags=%s fildes=%d offset=%d\n",
1013 		    pri->pname,
1014 		    strflags(pri, strfdinsert.flags),
1015 		    strfdinsert.fildes,
1016 		    strfdinsert.offset);
1017 	}
1018 }
1019 #endif	/* _LP64 */
1020 
1021 void
show_strrecvfd(private_t * pri,long offset)1022 show_strrecvfd(private_t *pri, long offset)
1023 {
1024 	struct strrecvfd strrecvfd;
1025 
1026 	if (Pread(Proc, &strrecvfd, sizeof (strrecvfd), offset) ==
1027 	    sizeof (strrecvfd)) {
1028 		(void) printf(
1029 		    "%s\tfd=%-5d uid=%-5u gid=%u\n",
1030 		    pri->pname,
1031 		    strrecvfd.fd,
1032 		    strrecvfd.uid,
1033 		    strrecvfd.gid);
1034 	}
1035 }
1036 
1037 void
show_strlist(private_t * pri,long offset)1038 show_strlist(private_t *pri, long offset)
1039 {
1040 	struct str_list strlist;
1041 	struct str_mlist list;
1042 	int count;
1043 
1044 	if (Pread(Proc, &strlist, sizeof (strlist), offset) ==
1045 	    sizeof (strlist)) {
1046 		(void) printf("%s\tnmods=%d  modlist=0x%.8lX\n",
1047 		    pri->pname,
1048 		    strlist.sl_nmods,
1049 		    (long)strlist.sl_modlist);
1050 
1051 		count = strlist.sl_nmods;
1052 		offset = (long)strlist.sl_modlist;
1053 		while (!interrupt && --count >= 0) {
1054 			if (Pread(Proc, &list, sizeof (list), offset) !=
1055 			    sizeof (list))
1056 				break;
1057 			(void) printf("%s\t\t\"%.*s\"\n",
1058 			    pri->pname,
1059 			    (int)sizeof (list.l_name),
1060 			    list.l_name);
1061 			offset += sizeof (struct str_mlist);
1062 		}
1063 	}
1064 }
1065 
1066 #ifdef _LP64
1067 void
show_strlist32(private_t * pri,long offset)1068 show_strlist32(private_t *pri, long offset)
1069 {
1070 	struct str_list32 strlist;
1071 	struct str_mlist list;
1072 	int count;
1073 
1074 	if (Pread(Proc, &strlist, sizeof (strlist), offset) ==
1075 	    sizeof (strlist)) {
1076 		(void) printf("%s\tnmods=%d  modlist=0x%.8lX\n",
1077 		    pri->pname,
1078 		    strlist.sl_nmods,
1079 		    (long)strlist.sl_modlist);
1080 
1081 		count = strlist.sl_nmods;
1082 		offset = (long)strlist.sl_modlist;
1083 		while (!interrupt && --count >= 0) {
1084 			if (Pread(Proc, &list, sizeof (list), offset) !=
1085 			    sizeof (list))
1086 				break;
1087 			(void) printf("%s\t\t\"%.*s\"\n",
1088 			    pri->pname,
1089 			    (int)sizeof (list.l_name),
1090 			    list.l_name);
1091 			offset += sizeof (struct str_mlist);
1092 		}
1093 	}
1094 }
1095 #endif	/* _LP64 */
1096 
1097 void
show_jwinsize(private_t * pri,long offset)1098 show_jwinsize(private_t *pri, long offset)
1099 {
1100 	struct jwinsize jwinsize;
1101 
1102 	if (Pread(Proc, &jwinsize, sizeof (jwinsize), offset) ==
1103 	    sizeof (jwinsize)) {
1104 		(void) printf(
1105 		    "%s\tbytesx=%-3u bytesy=%-3u bitsx=%-3u bitsy=%-3u\n",
1106 		    pri->pname,
1107 		    (unsigned)jwinsize.bytesx,
1108 		    (unsigned)jwinsize.bytesy,
1109 		    (unsigned)jwinsize.bitsx,
1110 		    (unsigned)jwinsize.bitsy);
1111 	}
1112 }
1113 
1114 void
show_winsize(private_t * pri,long offset)1115 show_winsize(private_t *pri, long offset)
1116 {
1117 	struct winsize winsize;
1118 
1119 	if (Pread(Proc, &winsize, sizeof (winsize), offset)
1120 	    == sizeof (winsize)) {
1121 		(void) printf(
1122 		    "%s\trow=%-3d col=%-3d xpixel=%-3d ypixel=%-3d\n",
1123 		    pri->pname,
1124 		    winsize.ws_row,
1125 		    winsize.ws_col,
1126 		    winsize.ws_xpixel,
1127 		    winsize.ws_ypixel);
1128 	}
1129 }
1130 
1131 struct audio_stuff {
1132 	uint_t	bit;
1133 	const char *str;
1134 };
1135 
1136 const struct audio_stuff audio_output_ports[] = {
1137 	{ AUDIO_SPEAKER, "SPEAKER" },
1138 	{ AUDIO_HEADPHONE, "HEADPHONE" },
1139 	{ AUDIO_LINE_OUT, "LINE_OUT" },
1140 	{ AUDIO_SPDIF_OUT, "SPDIF_OUT" },
1141 	{ AUDIO_AUX1_OUT, "AUX1_OUT" },
1142 	{ AUDIO_AUX2_OUT, "AUX2_OUT" },
1143 	{ 0, NULL }
1144 };
1145 
1146 const struct audio_stuff audio_input_ports[] = {
1147 	{ AUDIO_MICROPHONE, "MICROPHONE" },
1148 	{ AUDIO_LINE_IN, "LINE_IN" },
1149 	{ AUDIO_CD, "CD" },
1150 	{ AUDIO_SPDIF_IN, "SPDIF_IN" },
1151 	{ AUDIO_AUX1_IN, "AUX1_IN" },
1152 	{ AUDIO_AUX2_IN, "AUX2_IN" },
1153 	{ AUDIO_CODEC_LOOPB_IN, "CODEC_LOOPB_IN" },
1154 	{ AUDIO_SUNVTS, "SUNVTS" },
1155 	{ 0, NULL }
1156 };
1157 
1158 static const struct audio_stuff audio_hw_features[] = {
1159 	{ AUDIO_HWFEATURE_DUPLEX, "DUPLEX" },
1160 	{ AUDIO_HWFEATURE_MSCODEC, "MSCODEC" },
1161 	{ AUDIO_HWFEATURE_IN2OUT, "IN2OUT" },
1162 	{ AUDIO_HWFEATURE_PLAY, "PLAY" },
1163 	{ AUDIO_HWFEATURE_RECORD, "RECORD" },
1164 	{ 0, NULL }
1165 };
1166 
1167 static const struct audio_stuff audio_sw_features[] = {
1168 	{ AUDIO_SWFEATURE_MIXER, "MIXER" },
1169 	{ 0, NULL }
1170 };
1171 
1172 void
show_audio_features(const private_t * pri,const struct audio_stuff * audio_porttab,uint_t features,const char * name)1173 show_audio_features(const private_t *pri,
1174     const struct audio_stuff *audio_porttab, uint_t features,
1175     const char *name)
1176 {
1177 	(void) printf("%s\t%s=", pri->pname, name);
1178 	if (features == 0) {
1179 		(void) printf("0\n");
1180 		return;
1181 	}
1182 
1183 	for (; audio_porttab->bit != 0; ++audio_porttab) {
1184 		if (features & audio_porttab->bit) {
1185 			(void) printf(audio_porttab->str);
1186 			features &= ~audio_porttab->bit;
1187 			if (features)
1188 				(void) putchar('|');
1189 		}
1190 	}
1191 	if (features)
1192 		(void) printf("0x%x", features);
1193 	(void) putchar('\n');
1194 }
1195 
1196 void
show_audio_ports(private_t * pri,const char * mode,const char * field,uint_t ports)1197 show_audio_ports(private_t *pri, const char *mode,
1198     const char *field, uint_t ports)
1199 {
1200 	const struct audio_stuff *audio_porttab;
1201 
1202 	(void) printf("%s\t%s\t%s=", pri->pname, mode, field);
1203 	if (ports == 0) {
1204 		(void) printf("0\n");
1205 		return;
1206 	}
1207 	if (*mode == 'p')
1208 		audio_porttab = audio_output_ports;
1209 	else
1210 		audio_porttab = audio_input_ports;
1211 	for (; audio_porttab->bit != 0; ++audio_porttab) {
1212 		if (ports & audio_porttab->bit) {
1213 			(void) printf(audio_porttab->str);
1214 			ports &= ~audio_porttab->bit;
1215 			if (ports)
1216 				(void) putchar('|');
1217 		}
1218 	}
1219 	if (ports)
1220 		(void) printf("0x%x", ports);
1221 	(void) putchar('\n');
1222 }
1223 
1224 void
show_audio_prinfo(private_t * pri,const char * mode,struct audio_prinfo * au_pr)1225 show_audio_prinfo(private_t *pri, const char *mode, struct audio_prinfo *au_pr)
1226 {
1227 	const char *s;
1228 
1229 	/*
1230 	 * The following values describe the audio data encoding.
1231 	 */
1232 
1233 	(void) printf("%s\t%s\tsample_rate=%u channels=%u precision=%u\n",
1234 	    pri->pname, mode,
1235 	    au_pr->sample_rate,
1236 	    au_pr->channels,
1237 	    au_pr->precision);
1238 
1239 	s = NULL;
1240 	switch (au_pr->encoding) {
1241 	case AUDIO_ENCODING_NONE:	s = "NONE";	break;
1242 	case AUDIO_ENCODING_ULAW:	s = "ULAW";	break;
1243 	case AUDIO_ENCODING_ALAW:	s = "ALAW";	break;
1244 	case AUDIO_ENCODING_LINEAR:	s = "LINEAR";	break;
1245 	case AUDIO_ENCODING_DVI:	s = "DVI";	break;
1246 	case AUDIO_ENCODING_LINEAR8:	s = "LINEAR8";	break;
1247 	}
1248 	if (s)
1249 		(void) printf("%s\t%s\tencoding=%s\n", pri->pname, mode, s);
1250 	else {
1251 		(void) printf("%s\t%s\tencoding=%u\n",
1252 		    pri->pname, mode, au_pr->encoding);
1253 	}
1254 
1255 	/*
1256 	 * The following values control audio device configuration
1257 	 */
1258 
1259 	(void) printf(
1260 	    "%s\t%s\tgain=%u buffer_size=%u\n",
1261 	    pri->pname, mode,
1262 	    au_pr->gain,
1263 	    au_pr->buffer_size);
1264 	show_audio_ports(pri, mode, "port", au_pr->port);
1265 	show_audio_ports(pri, mode, "avail_ports", au_pr->avail_ports);
1266 	show_audio_ports(pri, mode, "mod_ports", au_pr->mod_ports);
1267 
1268 	/*
1269 	 * The following values describe driver state
1270 	 */
1271 
1272 	(void) printf("%s\t%s\tsamples=%u eof=%u pause=%u error=%u\n",
1273 	    pri->pname, mode,
1274 	    au_pr->samples,
1275 	    au_pr->eof,
1276 	    au_pr->pause,
1277 	    au_pr->error);
1278 	(void) printf("%s\t%s\twaiting=%u balance=%u minordev=%u\n",
1279 	    pri->pname, mode,
1280 	    au_pr->waiting,
1281 	    au_pr->balance,
1282 	    au_pr->minordev);
1283 
1284 	/*
1285 	 * The following values are read-only state flags
1286 	 */
1287 	(void) printf("%s\t%s\topen=%u active=%u\n",
1288 	    pri->pname, mode,
1289 	    au_pr->open,
1290 	    au_pr->active);
1291 }
1292 
1293 void
show_audio_info(private_t * pri,long offset)1294 show_audio_info(private_t *pri, long offset)
1295 {
1296 	struct audio_info au;
1297 
1298 	if (Pread(Proc, &au, sizeof (au), offset) == sizeof (au)) {
1299 		show_audio_prinfo(pri, "play", &au.play);
1300 		show_audio_prinfo(pri, "record", &au.record);
1301 		(void) printf("%s\tmonitor_gain=%u output_muted=%u\n",
1302 		    pri->pname, au.monitor_gain, au.output_muted);
1303 		show_audio_features(pri, audio_hw_features, au.hw_features,
1304 		    "hw_features");
1305 		show_audio_features(pri, audio_sw_features, au.sw_features,
1306 		    "sw_features");
1307 		show_audio_features(pri, audio_sw_features,
1308 		    au.sw_features_enabled, "sw_features_enabled");
1309 	}
1310 }
1311 
1312 void
show_ioctl(private_t * pri,int code,long offset)1313 show_ioctl(private_t *pri, int code, long offset)
1314 {
1315 	int lp64 = (data_model == PR_MODEL_LP64);
1316 	int err = pri->Errno;	/* don't display output parameters */
1317 				/* for a failed system call */
1318 #ifndef _LP64
1319 	if (lp64)
1320 		return;
1321 #endif
1322 	if (offset == 0)
1323 		return;
1324 
1325 	switch (code) {
1326 	case TCGETA:
1327 		if (err)
1328 			break;
1329 		/*FALLTHROUGH*/
1330 	case TCSETA:
1331 	case TCSETAW:
1332 	case TCSETAF:
1333 		show_termio(pri, offset);
1334 		break;
1335 	case TCGETS:
1336 		if (err)
1337 			break;
1338 		/*FALLTHROUGH*/
1339 	case TCSETS:
1340 	case TCSETSW:
1341 	case TCSETSF:
1342 		show_termios(pri, offset);
1343 		break;
1344 	case TCGETX:
1345 		if (err)
1346 			break;
1347 		/*FALLTHROUGH*/
1348 	case TCSETX:
1349 	case TCSETXW:
1350 	case TCSETXF:
1351 		show_termiox(pri, offset);
1352 		break;
1353 	case TIOCGETP:
1354 		if (err)
1355 			break;
1356 		/*FALLTHROUGH*/
1357 	case TIOCSETN:
1358 	case TIOCSETP:
1359 		show_sgttyb(pri, offset);
1360 		break;
1361 	case TIOCGLTC:
1362 		if (err)
1363 			break;
1364 		/*FALLTHROUGH*/
1365 	case TIOCSLTC:
1366 		show_ltchars(pri, offset);
1367 		break;
1368 	case TIOCGETC:
1369 		if (err)
1370 			break;
1371 		/*FALLTHROUGH*/
1372 	case TIOCSETC:
1373 		show_tchars(pri, offset);
1374 		break;
1375 	case LDGETT:
1376 		if (err)
1377 			break;
1378 		/*FALLTHROUGH*/
1379 	case LDSETT:
1380 		show_termcb(pri, offset);
1381 		break;
1382 	/* streams ioctl()s */
1383 #if 0
1384 		/* these are displayed as strings in the arg list */
1385 		/* by prt_ioa().  don't display them again here */
1386 	case I_PUSH:
1387 	case I_LOOK:
1388 	case I_FIND:
1389 		/* these are displayed as decimal in the arg list */
1390 		/* by prt_ioa().  don't display them again here */
1391 	case I_LINK:
1392 	case I_UNLINK:
1393 	case I_SENDFD:
1394 		/* these are displayed symbolically in the arg list */
1395 		/* by prt_ioa().  don't display them again here */
1396 	case I_SRDOPT:
1397 	case I_SETSIG:
1398 	case I_FLUSH:
1399 		break;
1400 		/* this one just ignores the argument */
1401 	case I_POP:
1402 		break;
1403 #endif
1404 		/* these return something in an int pointed to by arg */
1405 	case I_NREAD:
1406 	case I_GRDOPT:
1407 	case I_GETSIG:
1408 	case TIOCGSID:
1409 	case TIOCGPGRP:
1410 	case TIOCLGET:
1411 	case FIONREAD:
1412 	case FIORDCHK:
1413 		if (err)
1414 			break;
1415 		/*FALLTHROUGH*/
1416 		/* these pass something in an int pointed to by arg */
1417 	case TIOCSPGRP:
1418 	case TIOCFLUSH:
1419 	case TIOCLBIS:
1420 	case TIOCLBIC:
1421 	case TIOCLSET:
1422 		show_strint(pri, code, offset);
1423 		break;
1424 		/* these all point to structures */
1425 	case I_STR:
1426 #ifdef _LP64
1427 		if (lp64)
1428 			show_strioctl(pri, offset);
1429 		else
1430 			show_strioctl32(pri, offset);
1431 #else
1432 		show_strioctl(pri, offset);
1433 #endif
1434 		break;
1435 	case I_PEEK:
1436 #ifdef _LP64
1437 		if (lp64)
1438 			show_strpeek(pri, offset);
1439 		else
1440 			show_strpeek32(pri, offset);
1441 #else
1442 		show_strpeek(pri, offset);
1443 #endif
1444 		break;
1445 	case I_FDINSERT:
1446 #ifdef _LP64
1447 		if (lp64)
1448 			show_strfdinsert(pri, offset);
1449 		else
1450 			show_strfdinsert32(pri, offset);
1451 #else
1452 		show_strfdinsert(pri, offset);
1453 #endif
1454 		break;
1455 	case I_RECVFD:
1456 		if (err)
1457 			break;
1458 		show_strrecvfd(pri, offset);
1459 		break;
1460 	case I_LIST:
1461 		if (err)
1462 			break;
1463 #ifdef _LP64
1464 		if (lp64)
1465 			show_strlist(pri, offset);
1466 		else
1467 			show_strlist32(pri, offset);
1468 #else
1469 		show_strlist(pri, offset);
1470 #endif
1471 		break;
1472 	case JWINSIZE:
1473 		if (err)
1474 			break;
1475 		show_jwinsize(pri, offset);
1476 		break;
1477 	case TIOCGWINSZ:
1478 		if (err)
1479 			break;
1480 		/*FALLTHROUGH*/
1481 	case TIOCSWINSZ:
1482 		show_winsize(pri, offset);
1483 		break;
1484 	case AUDIO_GETINFO:
1485 	case (int)AUDIO_SETINFO:
1486 		show_audio_info(pri, offset);
1487 		break;
1488 
1489 	default:
1490 		if ((code & ~0xff) == ZFS_IOC) {
1491 			show_zfs_ioc(pri, offset);
1492 			break;
1493 		}
1494 
1495 		if (code & IOC_INOUT) {
1496 			const char *str = ioctldatastruct(code);
1497 
1498 			(void) printf("\t\t%s",
1499 			    (code & IOC_INOUT) == IOC_INOUT ? "write/read" :
1500 			    code & IOC_IN ? "write" : "read");
1501 			if (str != NULL) {
1502 				(void) printf(" (struct %s)\n", str);
1503 			} else {
1504 				(void) printf(" %d bytes\n",
1505 				    (code >> 16) & IOCPARM_MASK);
1506 			}
1507 		}
1508 	}
1509 }
1510 
1511 void
show_statvfs(private_t * pri)1512 show_statvfs(private_t *pri)
1513 {
1514 	long offset;
1515 	struct statvfs statvfs;
1516 	char *cp;
1517 
1518 	if (pri->sys_nargs > 1 && (offset = pri->sys_args[1]) != 0 &&
1519 	    Pread(Proc, &statvfs, sizeof (statvfs), offset)
1520 	    == sizeof (statvfs)) {
1521 		(void) printf(
1522 		"%s\tbsize=%-10lu frsize=%-9lu blocks=%-8llu bfree=%-9llu\n",
1523 		    pri->pname,
1524 		    statvfs.f_bsize,
1525 		    statvfs.f_frsize,
1526 		    (u_longlong_t)statvfs.f_blocks,
1527 		    (u_longlong_t)statvfs.f_bfree);
1528 		(void) printf(
1529 		"%s\tbavail=%-9llu files=%-10llu ffree=%-9llu favail=%-9llu\n",
1530 		    pri->pname,
1531 		    (u_longlong_t)statvfs.f_bavail,
1532 		    (u_longlong_t)statvfs.f_files,
1533 		    (u_longlong_t)statvfs.f_ffree,
1534 		    (u_longlong_t)statvfs.f_favail);
1535 		(void) printf(
1536 		    "%s\tfsid=0x%-9.4lX basetype=%-7.16s namemax=%ld\n",
1537 		    pri->pname,
1538 		    statvfs.f_fsid,
1539 		    statvfs.f_basetype,
1540 		    (long)statvfs.f_namemax);
1541 		(void) printf(
1542 		    "%s\tflag=%s\n",
1543 		    pri->pname,
1544 		    svfsflags(pri, (ulong_t)statvfs.f_flag));
1545 		cp = statvfs.f_fstr + strlen(statvfs.f_fstr);
1546 		if (cp < statvfs.f_fstr + sizeof (statvfs.f_fstr) - 1 &&
1547 		    *(cp+1) != '\0')
1548 			*cp = ' ';
1549 		(void) printf("%s\tfstr=\"%.*s\"\n",
1550 		    pri->pname,
1551 		    (int)sizeof (statvfs.f_fstr),
1552 		    statvfs.f_fstr);
1553 	}
1554 }
1555 
1556 #ifdef _LP64
1557 void
show_statvfs32(private_t * pri)1558 show_statvfs32(private_t *pri)
1559 {
1560 	long offset;
1561 	struct statvfs32 statvfs;
1562 	char *cp;
1563 
1564 	if (pri->sys_nargs > 1 && (offset = pri->sys_args[1]) != 0 &&
1565 	    Pread(Proc, &statvfs, sizeof (statvfs), offset)
1566 	    == sizeof (statvfs)) {
1567 		(void) printf(
1568 		    "%s\tbsize=%-10u frsize=%-9u blocks=%-8u bfree=%-9u\n",
1569 		    pri->pname,
1570 		    statvfs.f_bsize,
1571 		    statvfs.f_frsize,
1572 		    statvfs.f_blocks,
1573 		    statvfs.f_bfree);
1574 		(void) printf(
1575 		    "%s\tbavail=%-9u files=%-10u ffree=%-9u favail=%-9u\n",
1576 		    pri->pname,
1577 		    statvfs.f_bavail,
1578 		    statvfs.f_files,
1579 		    statvfs.f_ffree,
1580 		    statvfs.f_favail);
1581 		(void) printf(
1582 		    "%s\tfsid=0x%-9.4X basetype=%-7.16s namemax=%d\n",
1583 		    pri->pname,
1584 		    statvfs.f_fsid,
1585 		    statvfs.f_basetype,
1586 		    (int)statvfs.f_namemax);
1587 		(void) printf(
1588 		    "%s\tflag=%s\n",
1589 		    pri->pname,
1590 		    svfsflags(pri, (ulong_t)statvfs.f_flag));
1591 		cp = statvfs.f_fstr + strlen(statvfs.f_fstr);
1592 		if (cp < statvfs.f_fstr + sizeof (statvfs.f_fstr) - 1 &&
1593 		    *(cp+1) != '\0')
1594 			*cp = ' ';
1595 		(void) printf("%s\tfstr=\"%.*s\"\n",
1596 		    pri->pname,
1597 		    (int)sizeof (statvfs.f_fstr),
1598 		    statvfs.f_fstr);
1599 	}
1600 }
1601 #endif	/* _LP64 */
1602 
1603 void
show_statvfs64(private_t * pri)1604 show_statvfs64(private_t *pri)
1605 {
1606 	long offset;
1607 	struct statvfs64_32 statvfs;
1608 	char *cp;
1609 
1610 	if (pri->sys_nargs > 1 && (offset = pri->sys_args[1]) != 0 &&
1611 	    Pread(Proc, &statvfs, sizeof (statvfs), offset)
1612 	    == sizeof (statvfs)) {
1613 		(void) printf(
1614 		    "%s\tbsize=%-10u frsize=%-9u blocks=%-8llu bfree=%-9llu\n",
1615 		    pri->pname,
1616 		    statvfs.f_bsize,
1617 		    statvfs.f_frsize,
1618 		    (u_longlong_t)statvfs.f_blocks,
1619 		    (u_longlong_t)statvfs.f_bfree);
1620 		(void) printf(
1621 		"%s\tbavail=%-9llu files=%-10llu ffree=%-9llu favail=%-9llu\n",
1622 		    pri->pname,
1623 		    (u_longlong_t)statvfs.f_bavail,
1624 		    (u_longlong_t)statvfs.f_files,
1625 		    (u_longlong_t)statvfs.f_ffree,
1626 		    (u_longlong_t)statvfs.f_favail);
1627 		(void) printf(
1628 		    "%s\tfsid=0x%-9.4X basetype=%-7.16s namemax=%d\n",
1629 		    pri->pname,
1630 		    statvfs.f_fsid,
1631 		    statvfs.f_basetype,
1632 		    (int)statvfs.f_namemax);
1633 		(void) printf(
1634 		    "%s\tflag=%s\n",
1635 		    pri->pname,
1636 		    svfsflags(pri, (ulong_t)statvfs.f_flag));
1637 		cp = statvfs.f_fstr + strlen(statvfs.f_fstr);
1638 		if (cp < statvfs.f_fstr + sizeof (statvfs.f_fstr) - 1 &&
1639 		    *(cp+1) != '\0')
1640 			*cp = ' ';
1641 		(void) printf("%s\tfstr=\"%.*s\"\n",
1642 		    pri->pname,
1643 		    (int)sizeof (statvfs.f_fstr),
1644 		    statvfs.f_fstr);
1645 	}
1646 }
1647 
1648 void
show_statfs(private_t * pri)1649 show_statfs(private_t *pri)
1650 {
1651 	long offset;
1652 	struct statfs statfs;
1653 
1654 	if (pri->sys_nargs >= 2 && (offset = pri->sys_args[1]) != 0 &&
1655 	    Pread(Proc, &statfs, sizeof (statfs), offset) == sizeof (statfs)) {
1656 		(void) printf(
1657 		"%s\tfty=%d bsz=%ld fsz=%ld blk=%ld bfr=%ld fil=%lu ffr=%lu\n",
1658 		    pri->pname,
1659 		    statfs.f_fstyp,
1660 		    statfs.f_bsize,
1661 		    statfs.f_frsize,
1662 		    statfs.f_blocks,
1663 		    statfs.f_bfree,
1664 		    statfs.f_files,
1665 		    statfs.f_ffree);
1666 		(void) printf("%s\t    fname=%.6s fpack=%.6s\n",
1667 		    pri->pname,
1668 		    statfs.f_fname,
1669 		    statfs.f_fpack);
1670 	}
1671 }
1672 
1673 #ifdef _LP64
1674 void
show_statfs32(private_t * pri)1675 show_statfs32(private_t *pri)
1676 {
1677 	long offset;
1678 	struct statfs32 statfs;
1679 
1680 	if (pri->sys_nargs >= 2 && (offset = pri->sys_args[1]) != 0 &&
1681 	    Pread(Proc, &statfs, sizeof (statfs), offset) == sizeof (statfs)) {
1682 		(void) printf(
1683 		    "%s\tfty=%d bsz=%d fsz=%d blk=%d bfr=%d fil=%u ffr=%u\n",
1684 		    pri->pname,
1685 		    statfs.f_fstyp,
1686 		    statfs.f_bsize,
1687 		    statfs.f_frsize,
1688 		    statfs.f_blocks,
1689 		    statfs.f_bfree,
1690 		    statfs.f_files,
1691 		    statfs.f_ffree);
1692 		(void) printf("%s\t    fname=%.6s fpack=%.6s\n",
1693 		    pri->pname,
1694 		    statfs.f_fname,
1695 		    statfs.f_fpack);
1696 	}
1697 }
1698 #endif	/* _LP64 */
1699 
1700 void
show_flock32(private_t * pri,long offset)1701 show_flock32(private_t *pri, long offset)
1702 {
1703 	struct flock32 flock;
1704 
1705 	if (Pread(Proc, &flock, sizeof (flock), offset) == sizeof (flock)) {
1706 		const char *str = NULL;
1707 
1708 		(void) printf("%s\ttyp=", pri->pname);
1709 
1710 		switch (flock.l_type) {
1711 		case F_RDLCK:
1712 			str = "F_RDLCK";
1713 			break;
1714 		case F_WRLCK:
1715 			str = "F_WRLCK";
1716 			break;
1717 		case F_UNLCK:
1718 			str = "F_UNLCK";
1719 			break;
1720 		}
1721 		if (str != NULL)
1722 			(void) printf("%s", str);
1723 		else
1724 			(void) printf("%-7d", flock.l_type);
1725 
1726 		str = whencearg(flock.l_whence);
1727 		if (str != NULL)
1728 			(void) printf("  whence=%s", str);
1729 		else
1730 			(void) printf("  whence=%-8u", flock.l_whence);
1731 
1732 		(void) printf(
1733 		    " start=%-5d len=%-5d sys=%-2u pid=%d\n",
1734 		    flock.l_start,
1735 		    flock.l_len,
1736 		    flock.l_sysid,
1737 		    flock.l_pid);
1738 	}
1739 }
1740 
1741 void
show_flock64(private_t * pri,long offset)1742 show_flock64(private_t *pri, long offset)
1743 {
1744 	struct flock64 flock;
1745 
1746 	if (Pread(Proc, &flock, sizeof (flock), offset) == sizeof (flock)) {
1747 		const char *str = NULL;
1748 
1749 		(void) printf("%s\ttyp=", pri->pname);
1750 
1751 		switch (flock.l_type) {
1752 		case F_RDLCK:
1753 			str = "F_RDLCK";
1754 			break;
1755 		case F_WRLCK:
1756 			str = "F_WRLCK";
1757 			break;
1758 		case F_UNLCK:
1759 			str = "F_UNLCK";
1760 			break;
1761 		}
1762 		if (str != NULL)
1763 			(void) printf("%s", str);
1764 		else
1765 			(void) printf("%-7d", flock.l_type);
1766 
1767 		str = whencearg(flock.l_whence);
1768 		if (str != NULL)
1769 			(void) printf("  whence=%s", str);
1770 		else
1771 			(void) printf("  whence=%-8u", flock.l_whence);
1772 
1773 		(void) printf(
1774 		    " start=%-5lld len=%-5lld sys=%-2u pid=%d\n",
1775 		    (long long)flock.l_start,
1776 		    (long long)flock.l_len,
1777 		    flock.l_sysid,
1778 		    (int)flock.l_pid);
1779 	}
1780 }
1781 
1782 void
show_share(private_t * pri,long offset)1783 show_share(private_t *pri, long offset)
1784 {
1785 	struct fshare fshare;
1786 
1787 	if (Pread(Proc, &fshare, sizeof (fshare), offset) == sizeof (fshare)) {
1788 		const char *str = NULL;
1789 		int manddny = 0;
1790 
1791 		(void) printf("%s\taccess=", pri->pname);
1792 
1793 		switch (fshare.f_access) {
1794 		case F_RDACC:
1795 			str = "F_RDACC";
1796 			break;
1797 		case F_WRACC:
1798 			str = "F_WRACC";
1799 			break;
1800 		case F_RWACC:
1801 			str = "F_RWACC";
1802 			break;
1803 		}
1804 		if (str != NULL)
1805 			(void) printf("%s", str);
1806 		else
1807 			(void) printf("%-7d", fshare.f_access);
1808 
1809 		str = NULL;
1810 		if (fshare.f_deny & F_MANDDNY) {
1811 			fshare.f_deny &= ~F_MANDDNY;
1812 			manddny = 1;
1813 		}
1814 		switch (fshare.f_deny) {
1815 		case F_NODNY:
1816 			str = "F_NODNY";
1817 			break;
1818 		case F_RDDNY:
1819 			str = "F_RDDNY";
1820 			break;
1821 		case F_WRDNY:
1822 			str = "F_WRDNY";
1823 			break;
1824 		case F_RWDNY:
1825 			str = "F_RWDNY";
1826 			break;
1827 		case F_COMPAT:
1828 			str = "F_COMPAT";
1829 			break;
1830 		}
1831 		if (str != NULL) {
1832 			if (manddny)
1833 				(void) printf("  deny=F_MANDDNY|%s", str);
1834 			else
1835 				(void) printf("  deny=%s", str);
1836 		} else {
1837 			(void) printf("  deny=0x%x", manddny?
1838 			    fshare.f_deny | F_MANDDNY : fshare.f_deny);
1839 		}
1840 
1841 		(void) printf("  id=%x\n", fshare.f_id);
1842 	}
1843 }
1844 
1845 void
show_ffg(private_t * pri)1846 show_ffg(private_t *pri)
1847 {
1848 	(void) putchar('\t');
1849 	(void) putchar('\t');
1850 	prt_ffg(pri, 0, pri->Rval1);
1851 	(void) puts(pri->sys_string);
1852 }
1853 
1854 /* print values in fcntl() pointed-to structure */
1855 void
show_fcntl(private_t * pri)1856 show_fcntl(private_t *pri)
1857 {
1858 	long offset;
1859 
1860 	if (pri->sys_nargs >= 2 && pri->sys_args[1] == F_GETFL) {
1861 		show_ffg(pri);
1862 		return;
1863 	}
1864 
1865 	if (pri->sys_nargs < 3 || (offset = pri->sys_args[2]) == 0)
1866 		return;
1867 
1868 	switch (pri->sys_args[1]) {
1869 #ifdef _LP64
1870 	case F_GETLK:
1871 	case F_SETLK:
1872 	case F_SETLKW:
1873 	case F_FREESP:
1874 	case F_ALLOCSP:
1875 	case F_SETLK_NBMAND:
1876 	case F_OFD_GETLK:
1877 	case F_OFD_SETLK:
1878 	case F_OFD_SETLKW:
1879 	case F_FLOCK:
1880 	case F_FLOCKW:
1881 		if (data_model == PR_MODEL_LP64)
1882 			show_flock64(pri, offset);
1883 		else
1884 			show_flock32(pri, offset);
1885 		break;
1886 	case 33:	/* F_GETLK64 */
1887 	case 34:	/* F_SETLK64 */
1888 	case 35:	/* F_SETLKW64 */
1889 	case 27:	/* F_FREESP64 */
1890 	case 28:	/* F_ALLOCSP64 */
1891 	case 44:	/* F_SETLK64_NBMAND */
1892 	case 50:	/* F_OFD_GETLK64 */
1893 	case 51:	/* F_OFD_SETLK64 */
1894 	case 52:	/* F_OFD_SETLKW64 */
1895 	case 55:	/* F_FLOCK64 */
1896 	case 56:	/* F_FLOCKW64 */
1897 		show_flock64(pri, offset);
1898 		break;
1899 #else	/* _LP64 */
1900 	case F_GETLK:
1901 	case F_SETLK:
1902 	case F_SETLKW:
1903 	case F_FREESP:
1904 	case F_ALLOCSP:
1905 	case F_SETLK_NBMAND:
1906 		show_flock32(pri, offset);
1907 		break;
1908 	case F_GETLK64:
1909 	case F_SETLK64:
1910 	case F_SETLKW64:
1911 	case F_FREESP64:
1912 	case F_ALLOCSP64:
1913 	case F_SETLK64_NBMAND:
1914 	case F_OFD_GETLK64:
1915 	case F_OFD_SETLK64:
1916 	case F_OFD_SETLKW64:
1917 	case F_FLOCK64:
1918 	case F_FLOCKW64:
1919 		show_flock64(pri, offset);
1920 		break;
1921 #endif	/* _LP64 */
1922 	case F_SHARE:
1923 	case F_UNSHARE:
1924 		show_share(pri, offset);
1925 		break;
1926 	}
1927 }
1928 
1929 void
show_strbuf(private_t * pri,long offset,const char * name,int dump)1930 show_strbuf(private_t *pri, long offset, const char *name, int dump)
1931 {
1932 	struct strbuf strbuf;
1933 
1934 	if (Pread(Proc, &strbuf, sizeof (strbuf), offset) == sizeof (strbuf))
1935 		print_strbuf(pri, &strbuf, name, dump);
1936 }
1937 
1938 #ifdef _LP64
1939 void
show_strbuf32(private_t * pri,long offset,const char * name,int dump)1940 show_strbuf32(private_t *pri, long offset, const char *name, int dump)
1941 {
1942 	struct strbuf32 strbuf;
1943 
1944 	if (Pread(Proc, &strbuf, sizeof (strbuf), offset) == sizeof (strbuf))
1945 		print_strbuf32(pri, &strbuf, name, dump);
1946 }
1947 #endif	/* _LP64 */
1948 
1949 void
show_gp_msg(private_t * pri,int what)1950 show_gp_msg(private_t *pri, int what)
1951 {
1952 	long offset;
1953 	int dump = FALSE;
1954 	int fdp1 = pri->sys_args[0] + 1;
1955 
1956 	switch (what) {
1957 	case SYS_getmsg:
1958 	case SYS_getpmsg:
1959 		if (pri->Errno == 0 && prismember(&readfd, fdp1))
1960 			dump = TRUE;
1961 		break;
1962 	case SYS_putmsg:
1963 	case SYS_putpmsg:
1964 		if (prismember(&writefd, fdp1))
1965 			dump = TRUE;
1966 		break;
1967 	}
1968 
1969 	/* enter region of lengthy output */
1970 	if (dump)
1971 		Eserialize();
1972 
1973 #ifdef _LP64
1974 	if (pri->sys_nargs >= 2 && (offset = pri->sys_args[1]) != 0) {
1975 		if (data_model == PR_MODEL_LP64)
1976 			show_strbuf(pri, offset, "ctl", dump);
1977 		else
1978 			show_strbuf32(pri, offset, "ctl", dump);
1979 	}
1980 	if (pri->sys_nargs >= 3 && (offset = pri->sys_args[2]) != 0) {
1981 		if (data_model == PR_MODEL_LP64)
1982 			show_strbuf(pri, offset, "dat", dump);
1983 		else
1984 			show_strbuf32(pri, offset, "dat", dump);
1985 	}
1986 #else	/* _LP64 */
1987 	if (pri->sys_nargs >= 2 && (offset = pri->sys_args[1]) != 0)
1988 		show_strbuf(pri, offset, "ctl", dump);
1989 	if (pri->sys_nargs >= 3 && (offset = pri->sys_args[2]) != 0)
1990 		show_strbuf(pri, offset, "dat", dump);
1991 #endif	/* _LP64 */
1992 
1993 	/* exit region of lengthy output */
1994 	if (dump)
1995 		Xserialize();
1996 }
1997 
1998 void
show_int(private_t * pri,long offset,const char * name)1999 show_int(private_t *pri, long offset, const char *name)
2000 {
2001 	int value;
2002 
2003 	if (offset != 0 &&
2004 	    Pread(Proc, &value, sizeof (value), offset) == sizeof (value))
2005 		(void) printf("%s\t%s:\t%d\n",
2006 		    pri->pname,
2007 		    name,
2008 		    value);
2009 }
2010 
2011 void
show_hhex_int(private_t * pri,long offset,const char * name)2012 show_hhex_int(private_t *pri, long offset, const char *name)
2013 {
2014 	int value;
2015 
2016 	if (Pread(Proc, &value, sizeof (value), offset) == sizeof (value))
2017 		(void) printf("%s\t%s:\t0x%.4X\n",
2018 		    pri->pname,
2019 		    name,
2020 		    value);
2021 }
2022 
2023 #define	ALL_POLL_FLAGS	(POLLIN|POLLPRI|POLLOUT| \
2024 	POLLRDNORM|POLLRDBAND|POLLWRBAND|POLLERR|POLLHUP|POLLNVAL)
2025 
2026 const char *
pollevent(private_t * pri,int arg)2027 pollevent(private_t *pri, int arg)
2028 {
2029 	char *str = pri->code_buf;
2030 
2031 	if (arg == 0)
2032 		return ("0");
2033 	if (arg & ~ALL_POLL_FLAGS) {
2034 		(void) sprintf(str, "0x%-5X", arg);
2035 		return ((const char *)str);
2036 	}
2037 
2038 	*str = '\0';
2039 	if (arg & POLLIN)
2040 		(void) strcat(str, "|POLLIN");
2041 	if (arg & POLLPRI)
2042 		(void) strcat(str, "|POLLPRI");
2043 	if (arg & POLLOUT)
2044 		(void) strcat(str, "|POLLOUT");
2045 	if (arg & POLLRDNORM)
2046 		(void) strcat(str, "|POLLRDNORM");
2047 	if (arg & POLLRDBAND)
2048 		(void) strcat(str, "|POLLRDBAND");
2049 	if (arg & POLLWRBAND)
2050 		(void) strcat(str, "|POLLWRBAND");
2051 	if (arg & POLLERR)
2052 		(void) strcat(str, "|POLLERR");
2053 	if (arg & POLLHUP)
2054 		(void) strcat(str, "|POLLHUP");
2055 	if (arg & POLLNVAL)
2056 		(void) strcat(str, "|POLLNVAL");
2057 
2058 	return ((const char *)(str+1));
2059 }
2060 
2061 static void
show_one_pollfd(private_t * pri,struct pollfd * ppollfd)2062 show_one_pollfd(private_t *pri, struct pollfd *ppollfd)
2063 {
2064 	/*
2065 	 * can't print both events and revents in same printf.
2066 	 * pollevent() returns a pointer to a TSD location.
2067 	 */
2068 	(void) printf("%s\tfd=%-2d ev=%s",
2069 	    pri->pname, ppollfd->fd, pollevent(pri, ppollfd->events));
2070 	(void) printf(" rev=%s\n", pollevent(pri, ppollfd->revents));
2071 }
2072 
2073 static void
show_all_pollfds(private_t * pri,long offset,int nfds)2074 show_all_pollfds(private_t *pri, long offset, int nfds)
2075 {
2076 	struct pollfd pollfd[2];
2077 	int skip = -1;
2078 
2079 	for (; nfds && !interrupt; nfds--, offset += sizeof (struct pollfd)) {
2080 		if (Pread(Proc, &pollfd[0], sizeof (struct pollfd), offset) !=
2081 		    sizeof (struct pollfd))
2082 			continue;
2083 
2084 		if (skip >= 0 && pollfd[0].fd == pollfd[1].fd &&
2085 		    pollfd[0].events == pollfd[1].events &&
2086 		    pollfd[0].revents == pollfd[1].revents) {
2087 			skip++;
2088 			continue;
2089 		}
2090 
2091 		if (skip > 0)
2092 			(void) printf("%s\t...last pollfd structure"
2093 			    " repeated %d time%s...\n",
2094 			    pri->pname, skip, (skip == 1 ? "" : "s"));
2095 
2096 		skip = 0;
2097 		show_one_pollfd(pri, &pollfd[0]);
2098 		pollfd[1] = pollfd[0];
2099 	}
2100 
2101 	if (skip > 0)
2102 		(void) printf(
2103 		    "%s\t...last pollfd structure repeated %d time%s...\n",
2104 		    pri->pname, skip, (skip == 1 ? "" : "s"));
2105 }
2106 
2107 void
show_pollsys(private_t * pri)2108 show_pollsys(private_t *pri)
2109 {
2110 	long offset;
2111 	int nfds;
2112 	int serial = 0;
2113 
2114 	if (pri->sys_nargs < 2)
2115 		return;
2116 
2117 	offset = pri->sys_args[0];
2118 	nfds = pri->sys_args[1];
2119 
2120 	/* enter region of lengthy output */
2121 	if (offset != 0 && nfds > 32) {
2122 		Eserialize();
2123 		serial = 1;
2124 	}
2125 
2126 	if (offset != 0 && nfds > 0)
2127 		show_all_pollfds(pri, offset, nfds);
2128 
2129 	if (pri->sys_nargs > 2)
2130 		show_timestruc(pri, (long)pri->sys_args[2], "timeout");
2131 
2132 	if (pri->sys_nargs > 3)
2133 		show_sigset(pri, (long)pri->sys_args[3], "sigmask");
2134 
2135 	/* exit region of lengthy output */
2136 	if (serial)
2137 		Xserialize();
2138 }
2139 
2140 static void
show_perm64(private_t * pri,struct ipc_perm64 * ip)2141 show_perm64(private_t *pri, struct ipc_perm64 *ip)
2142 {
2143 	(void) printf("%s\tu=%-5u g=%-5u cu=%-5u cg=%-5u z=%-5d "
2144 	    "m=0%.6o key=%d projid=%-5d\n",
2145 	    pri->pname,
2146 	    ip->ipcx_uid,
2147 	    ip->ipcx_gid,
2148 	    ip->ipcx_cuid,
2149 	    ip->ipcx_cgid,
2150 	    (int)ip->ipcx_zoneid,
2151 	    (unsigned int)ip->ipcx_mode,
2152 	    ip->ipcx_key,
2153 	    (int)ip->ipcx_projid);
2154 }
2155 
2156 void
show_perm(private_t * pri,struct ipc_perm * ip)2157 show_perm(private_t *pri, struct ipc_perm *ip)
2158 {
2159 	(void) printf(
2160 	    "%s\tu=%-5u g=%-5u cu=%-5u cg=%-5u m=0%.6o seq=%u key=%d\n",
2161 	    pri->pname,
2162 	    ip->uid,
2163 	    ip->gid,
2164 	    ip->cuid,
2165 	    ip->cgid,
2166 	    (int)ip->mode,
2167 	    ip->seq,
2168 	    ip->key);
2169 }
2170 
2171 #ifdef _LP64
2172 void
show_perm32(private_t * pri,struct ipc_perm32 * ip)2173 show_perm32(private_t *pri, struct ipc_perm32 *ip)
2174 {
2175 	(void) printf(
2176 	    "%s\tu=%-5u g=%-5u cu=%-5u cg=%-5u m=0%.6o seq=%u key=%d\n",
2177 	    pri->pname,
2178 	    ip->uid,
2179 	    ip->gid,
2180 	    ip->cuid,
2181 	    ip->cgid,
2182 	    ip->mode,
2183 	    ip->seq,
2184 	    ip->key);
2185 }
2186 #endif	/* _LP64 */
2187 
2188 static void
show_msgctl64(private_t * pri,long offset)2189 show_msgctl64(private_t *pri, long offset)
2190 {
2191 	struct msqid_ds64 msgq;
2192 
2193 	if (offset != 0 &&
2194 	    Pread(Proc, &msgq, sizeof (msgq), offset) == sizeof (msgq)) {
2195 		show_perm64(pri, &msgq.msgx_perm);
2196 
2197 		(void) printf("%s\tbytes=%-5llu msgs=%-5llu maxby=%-5llu "
2198 		    "lspid=%-5d lrpid=%-5d\n", pri->pname,
2199 		    (unsigned long long)msgq.msgx_cbytes,
2200 		    (unsigned long long)msgq.msgx_qnum,
2201 		    (unsigned long long)msgq.msgx_qbytes,
2202 		    (int)msgq.msgx_lspid,
2203 		    (int)msgq.msgx_lrpid);
2204 
2205 		prtime(pri, "    st = ", (time_t)msgq.msgx_stime);
2206 		prtime(pri, "    rt = ", (time_t)msgq.msgx_rtime);
2207 		prtime(pri, "    ct = ", (time_t)msgq.msgx_ctime);
2208 	}
2209 }
2210 
2211 void
show_msgctl(private_t * pri,long offset)2212 show_msgctl(private_t *pri, long offset)
2213 {
2214 	struct msqid_ds msgq;
2215 
2216 	if (offset != 0 &&
2217 	    Pread(Proc, &msgq, sizeof (msgq), offset) == sizeof (msgq)) {
2218 		show_perm(pri, &msgq.msg_perm);
2219 
2220 		(void) printf(
2221 	"%s\tbytes=%-5lu msgs=%-5lu maxby=%-5lu lspid=%-5u lrpid=%-5u\n",
2222 		    pri->pname,
2223 		    msgq.msg_cbytes,
2224 		    msgq.msg_qnum,
2225 		    msgq.msg_qbytes,
2226 		    (int)msgq.msg_lspid,
2227 		    (int)msgq.msg_lrpid);
2228 
2229 		prtime(pri, "    st = ", msgq.msg_stime);
2230 		prtime(pri, "    rt = ", msgq.msg_rtime);
2231 		prtime(pri, "    ct = ", msgq.msg_ctime);
2232 	}
2233 }
2234 
2235 #ifdef _LP64
2236 void
show_msgctl32(private_t * pri,long offset)2237 show_msgctl32(private_t *pri, long offset)
2238 {
2239 	struct msqid_ds32 msgq;
2240 
2241 	if (offset != 0 &&
2242 	    Pread(Proc, &msgq, sizeof (msgq), offset) == sizeof (msgq)) {
2243 		show_perm32(pri, &msgq.msg_perm);
2244 
2245 		(void) printf(
2246 	"%s\tbytes=%-5u msgs=%-5u maxby=%-5u lspid=%-5u lrpid=%-5u\n",
2247 		    pri->pname,
2248 		    msgq.msg_cbytes,
2249 		    msgq.msg_qnum,
2250 		    msgq.msg_qbytes,
2251 		    msgq.msg_lspid,
2252 		    msgq.msg_lrpid);
2253 
2254 		prtime(pri, "    st = ", msgq.msg_stime);
2255 		prtime(pri, "    rt = ", msgq.msg_rtime);
2256 		prtime(pri, "    ct = ", msgq.msg_ctime);
2257 	}
2258 }
2259 #endif	/* _LP64 */
2260 
2261 void
show_msgbuf(private_t * pri,long offset,long msgsz)2262 show_msgbuf(private_t *pri, long offset, long msgsz)
2263 {
2264 	struct msgbuf msgb;
2265 
2266 	if (offset != 0 &&
2267 	    Pread(Proc, &msgb, sizeof (msgb.mtype), offset) ==
2268 	    sizeof (msgb.mtype)) {
2269 		/* enter region of lengthy output */
2270 		if (msgsz > MYBUFSIZ / 4)
2271 			Eserialize();
2272 
2273 		(void) printf("%s\tmtype=%lu  mtext[]=\n",
2274 		    pri->pname,
2275 		    msgb.mtype);
2276 		showbuffer(pri,
2277 		    (long)(offset + sizeof (msgb.mtype)), msgsz);
2278 
2279 		/* exit region of lengthy output */
2280 		if (msgsz > MYBUFSIZ / 4)
2281 			Xserialize();
2282 	}
2283 }
2284 
2285 #ifdef _LP64
2286 void
show_msgbuf32(private_t * pri,long offset,long msgsz)2287 show_msgbuf32(private_t *pri, long offset, long msgsz)
2288 {
2289 	struct ipcmsgbuf32 msgb;
2290 
2291 	if (offset != 0 &&
2292 	    Pread(Proc, &msgb, sizeof (msgb.mtype), offset) ==
2293 	    sizeof (msgb.mtype)) {
2294 		/* enter region of lengthy output */
2295 		if (msgsz > MYBUFSIZ / 4)
2296 			Eserialize();
2297 
2298 		(void) printf("%s\tmtype=%u  mtext[]=\n",
2299 		    pri->pname,
2300 		    msgb.mtype);
2301 		showbuffer(pri,
2302 		    (long)(offset + sizeof (msgb.mtype)), msgsz);
2303 
2304 		/* exit region of lengthy output */
2305 		if (msgsz > MYBUFSIZ / 4)
2306 			Xserialize();
2307 	}
2308 }
2309 #endif	/* _LP64 */
2310 
2311 #ifdef _LP64
2312 void
show_msgsys(private_t * pri,long msgsz)2313 show_msgsys(private_t *pri, long msgsz)
2314 {
2315 	switch (pri->sys_args[0]) {
2316 	case 0:			/* msgget() */
2317 		break;
2318 	case 1:			/* msgctl() */
2319 		if (pri->sys_nargs > 3) {
2320 			switch (pri->sys_args[2]) {
2321 			case IPC_STAT:
2322 				if (pri->Errno)
2323 					break;
2324 				/*FALLTHROUGH*/
2325 			case IPC_SET:
2326 				if (data_model == PR_MODEL_LP64)
2327 					show_msgctl(pri,
2328 					    (long)pri->sys_args[3]);
2329 				else
2330 					show_msgctl32(pri,
2331 					    (long)pri->sys_args[3]);
2332 				break;
2333 			case IPC_STAT64:
2334 				if (pri->Errno)
2335 					break;
2336 				/*FALLTHROUGH*/
2337 			case IPC_SET64:
2338 				show_msgctl64(pri, (long)pri->sys_args[3]);
2339 				break;
2340 			}
2341 		}
2342 		break;
2343 	case 2:			/* msgrcv() */
2344 		if (!pri->Errno && pri->sys_nargs > 2) {
2345 			if (data_model == PR_MODEL_LP64)
2346 				show_msgbuf(pri, pri->sys_args[2], msgsz);
2347 			else
2348 				show_msgbuf32(pri, pri->sys_args[2], msgsz);
2349 		}
2350 		break;
2351 	case 3:			/* msgsnd() */
2352 		if (pri->sys_nargs > 3) {
2353 			if (data_model == PR_MODEL_LP64)
2354 				show_msgbuf(pri, pri->sys_args[2],
2355 				    pri->sys_args[3]);
2356 			else
2357 				show_msgbuf32(pri, pri->sys_args[2],
2358 				    pri->sys_args[3]);
2359 		}
2360 		break;
2361 	case 4:			/* msgids() */
2362 	case 5:			/* msgsnap() */
2363 	default:		/* unexpected subcode */
2364 		break;
2365 	}
2366 }
2367 #else	/* _LP64 */
2368 void
show_msgsys(private_t * pri,long msgsz)2369 show_msgsys(private_t *pri, long msgsz)
2370 {
2371 	switch (pri->sys_args[0]) {
2372 	case 0:			/* msgget() */
2373 		break;
2374 	case 1:			/* msgctl() */
2375 		if (pri->sys_nargs > 3) {
2376 			switch (pri->sys_args[2]) {
2377 			case IPC_STAT:
2378 				if (pri->Errno)
2379 					break;
2380 				/*FALLTHROUGH*/
2381 			case IPC_SET:
2382 				show_msgctl(pri, (long)pri->sys_args[3]);
2383 				break;
2384 			case IPC_STAT64:
2385 				if (pri->Errno)
2386 					break;
2387 				/*FALLTHROUGH*/
2388 			case IPC_SET64:
2389 				show_msgctl64(pri, (long)pri->sys_args[3]);
2390 				break;
2391 			}
2392 		}
2393 		break;
2394 	case 2:			/* msgrcv() */
2395 		if (!pri->Errno && pri->sys_nargs > 2)
2396 			show_msgbuf(pri, pri->sys_args[2], msgsz);
2397 		break;
2398 	case 3:			/* msgsnd() */
2399 		if (pri->sys_nargs > 3)
2400 			show_msgbuf(pri, pri->sys_args[2],
2401 			    pri->sys_args[3]);
2402 		break;
2403 	case 4:			/* msgids() */
2404 	case 5:			/* msgsnap() */
2405 	default:		/* unexpected subcode */
2406 		break;
2407 	}
2408 }
2409 #endif	/* _LP64 */
2410 
2411 static void
show_semctl64(private_t * pri,long offset)2412 show_semctl64(private_t *pri, long offset)
2413 {
2414 	struct semid_ds64 semds;
2415 
2416 	if (offset != 0 &&
2417 	    Pread(Proc, &semds, sizeof (semds), offset) == sizeof (semds)) {
2418 		show_perm64(pri, &semds.semx_perm);
2419 
2420 		(void) printf("%s\tnsems=%u\n", pri->pname, semds.semx_nsems);
2421 
2422 		prtime(pri, "    ot = ", (time_t)semds.semx_otime);
2423 		prtime(pri, "    ct = ", (time_t)semds.semx_ctime);
2424 	}
2425 }
2426 
2427 void
show_semctl(private_t * pri,long offset)2428 show_semctl(private_t *pri, long offset)
2429 {
2430 	struct semid_ds semds;
2431 
2432 	if (offset != 0 &&
2433 	    Pread(Proc, &semds, sizeof (semds), offset) == sizeof (semds)) {
2434 		show_perm(pri, &semds.sem_perm);
2435 
2436 		(void) printf("%s\tnsems=%u\n",
2437 		    pri->pname,
2438 		    semds.sem_nsems);
2439 
2440 		prtime(pri, "    ot = ", semds.sem_otime);
2441 		prtime(pri, "    ct = ", semds.sem_ctime);
2442 	}
2443 }
2444 
2445 #ifdef _LP64
2446 void
show_semctl32(private_t * pri,long offset)2447 show_semctl32(private_t *pri, long offset)
2448 {
2449 	struct semid_ds32 semds;
2450 
2451 	if (offset != 0 &&
2452 	    Pread(Proc, &semds, sizeof (semds), offset) == sizeof (semds)) {
2453 		show_perm32(pri, &semds.sem_perm);
2454 
2455 		(void) printf("%s\tnsems=%u\n",
2456 		    pri->pname,
2457 		    semds.sem_nsems);
2458 
2459 		prtime(pri, "    ot = ", semds.sem_otime);
2460 		prtime(pri, "    ct = ", semds.sem_ctime);
2461 	}
2462 }
2463 #endif	/* _LP64 */
2464 
2465 void
show_semop(private_t * pri,long offset,long nsops,long timeout)2466 show_semop(private_t *pri, long offset, long nsops, long timeout)
2467 {
2468 	struct sembuf sembuf;
2469 	const char *str;
2470 
2471 	if (offset == 0)
2472 		return;
2473 
2474 	if (nsops > 40)		/* let's not be ridiculous */
2475 		nsops = 40;
2476 
2477 	for (; nsops > 0 && !interrupt; --nsops, offset += sizeof (sembuf)) {
2478 		if (Pread(Proc, &sembuf, sizeof (sembuf), offset) !=
2479 		    sizeof (sembuf))
2480 			break;
2481 
2482 		(void) printf("%s\tsemnum=%-5u semop=%-5d semflg=",
2483 		    pri->pname,
2484 		    sembuf.sem_num,
2485 		    sembuf.sem_op);
2486 
2487 		if (sembuf.sem_flg == 0)
2488 			(void) printf("0\n");
2489 		else if ((str = semflags(pri, sembuf.sem_flg)) != NULL)
2490 			(void) printf("%s\n", str);
2491 		else
2492 			(void) printf("0%.6o\n", sembuf.sem_flg);
2493 	}
2494 	if (timeout)
2495 		show_timestruc(pri, timeout, "timeout");
2496 }
2497 
2498 void
show_semsys(private_t * pri)2499 show_semsys(private_t *pri)
2500 {
2501 	switch (pri->sys_args[0]) {
2502 	case 0:			/* semctl() */
2503 		if (pri->sys_nargs > 4) {
2504 			switch (pri->sys_args[3]) {
2505 			case IPC_STAT:
2506 				if (pri->Errno)
2507 					break;
2508 				/*FALLTHROUGH*/
2509 			case IPC_SET:
2510 #ifdef _LP64
2511 				if (data_model == PR_MODEL_LP64)
2512 					show_semctl(pri,
2513 					    (long)pri->sys_args[4]);
2514 				else
2515 					show_semctl32(pri,
2516 					    (long)pri->sys_args[4]);
2517 #else
2518 				show_semctl(pri, (long)pri->sys_args[4]);
2519 #endif
2520 				break;
2521 			case IPC_STAT64:
2522 				if (pri->Errno)
2523 					break;
2524 				/*FALLTHROUGH*/
2525 			case IPC_SET64:
2526 				show_semctl64(pri, (long)pri->sys_args[4]);
2527 				break;
2528 			}
2529 		}
2530 		break;
2531 	case 1:			/* semget() */
2532 		break;
2533 	case 2:			/* semop() */
2534 		if (pri->sys_nargs > 3)
2535 			show_semop(pri, (long)pri->sys_args[2],
2536 			    pri->sys_args[3], 0);
2537 		break;
2538 	case 3:			/* semids() */
2539 		break;
2540 	case 4:			/* semtimedop() */
2541 		if (pri->sys_nargs > 4)
2542 			show_semop(pri, (long)pri->sys_args[2],
2543 			    pri->sys_args[3], pri->sys_args[4]);
2544 		break;
2545 	default:		/* unexpected subcode */
2546 		break;
2547 	}
2548 }
2549 
2550 static void
show_shmctl64(private_t * pri,long offset)2551 show_shmctl64(private_t *pri, long offset)
2552 {
2553 	struct shmid_ds64 shmds;
2554 
2555 	if (offset != 0 &&
2556 	    Pread(Proc, &shmds, sizeof (shmds), offset) == sizeof (shmds)) {
2557 		show_perm64(pri, &shmds.shmx_perm);
2558 
2559 		(void) printf(
2560 		    "%s\tsize=%-6llu lpid=%-5d cpid=%-5d na=%-5llu cna=%llu\n",
2561 		    pri->pname,
2562 		    (unsigned long long)shmds.shmx_segsz,
2563 		    (int)shmds.shmx_lpid,
2564 		    (int)shmds.shmx_cpid,
2565 		    (unsigned long long)shmds.shmx_nattch,
2566 		    (unsigned long long)shmds.shmx_cnattch);
2567 
2568 		prtime(pri, "    at = ", (time_t)shmds.shmx_atime);
2569 		prtime(pri, "    dt = ", (time_t)shmds.shmx_dtime);
2570 		prtime(pri, "    ct = ", (time_t)shmds.shmx_ctime);
2571 	}
2572 }
2573 
2574 void
show_shmctl(private_t * pri,long offset)2575 show_shmctl(private_t *pri, long offset)
2576 {
2577 	struct shmid_ds shmds;
2578 
2579 	if (offset != 0 &&
2580 	    Pread(Proc, &shmds, sizeof (shmds), offset) == sizeof (shmds)) {
2581 		show_perm(pri, &shmds.shm_perm);
2582 
2583 		(void) printf(
2584 		    "%s\tsize=%-6lu lpid=%-5u cpid=%-5u na=%-5lu cna=%lu\n",
2585 		    pri->pname,
2586 		    (ulong_t)shmds.shm_segsz,
2587 		    (int)shmds.shm_lpid,
2588 		    (int)shmds.shm_cpid,
2589 		    shmds.shm_nattch,
2590 		    shmds.shm_cnattch);
2591 
2592 		prtime(pri, "    at = ", shmds.shm_atime);
2593 		prtime(pri, "    dt = ", shmds.shm_dtime);
2594 		prtime(pri, "    ct = ", shmds.shm_ctime);
2595 	}
2596 }
2597 
2598 #ifdef _LP64
2599 void
show_shmctl32(private_t * pri,long offset)2600 show_shmctl32(private_t *pri, long offset)
2601 {
2602 	struct shmid_ds32 shmds;
2603 
2604 	if (offset != 0 &&
2605 	    Pread(Proc, &shmds, sizeof (shmds), offset) == sizeof (shmds)) {
2606 		show_perm32(pri, &shmds.shm_perm);
2607 
2608 		(void) printf(
2609 		    "%s\tsize=%-6u lpid=%-5u cpid=%-5u na=%-5u cna=%u\n",
2610 		    pri->pname,
2611 		    shmds.shm_segsz,
2612 		    shmds.shm_lpid,
2613 		    shmds.shm_cpid,
2614 		    shmds.shm_nattch,
2615 		    shmds.shm_cnattch);
2616 
2617 		prtime(pri, "    at = ", shmds.shm_atime);
2618 		prtime(pri, "    dt = ", shmds.shm_dtime);
2619 		prtime(pri, "    ct = ", shmds.shm_ctime);
2620 	}
2621 }
2622 #endif	/* _LP64 */
2623 
2624 void
show_shmsys(private_t * pri)2625 show_shmsys(private_t *pri)
2626 {
2627 	switch (pri->sys_args[0]) {
2628 	case 0:			/* shmat() */
2629 		break;
2630 	case 1:			/* shmctl() */
2631 		if (pri->sys_nargs > 3) {
2632 			switch (pri->sys_args[2]) {
2633 			case IPC_STAT:
2634 				if (pri->Errno)
2635 					break;
2636 				/*FALLTHROUGH*/
2637 			case IPC_SET:
2638 #ifdef _LP64
2639 				if (data_model == PR_MODEL_LP64)
2640 					show_shmctl(pri,
2641 					    (long)pri->sys_args[3]);
2642 				else
2643 					show_shmctl32(pri,
2644 					    (long)pri->sys_args[3]);
2645 #else
2646 				show_shmctl(pri, (long)pri->sys_args[3]);
2647 #endif
2648 				break;
2649 			case IPC_STAT64:
2650 				if (pri->Errno)
2651 					break;
2652 				/*FALLTHROUGH*/
2653 			case IPC_SET64:
2654 				show_shmctl64(pri, (long)pri->sys_args[3]);
2655 				break;
2656 			}
2657 		}
2658 		break;
2659 	case 2:			/* shmdt() */
2660 	case 3:			/* shmget() */
2661 	case 4:			/* shmids() */
2662 	default:		/* unexpected subcode */
2663 		break;
2664 	}
2665 }
2666 
2667 void
show_groups(private_t * pri,long offset,long count)2668 show_groups(private_t *pri, long offset, long count)
2669 {
2670 	int groups[100];
2671 
2672 	if (count > 100)
2673 		count = 100;
2674 
2675 	if (count > 0 && offset != 0 &&
2676 	    Pread(Proc, &groups[0], count*sizeof (int), offset) ==
2677 	    count*sizeof (int)) {
2678 		int n;
2679 
2680 		(void) printf("%s\t", pri->pname);
2681 		for (n = 0; !interrupt && n < count; n++) {
2682 			if (n != 0 && n%10 == 0)
2683 				(void) printf("\n%s\t", pri->pname);
2684 			(void) printf(" %5d", groups[n]);
2685 		}
2686 		(void) fputc('\n', stdout);
2687 	}
2688 }
2689 
2690 /*
2691  * This assumes that a sigset_t is simply an array of ints.
2692  */
2693 char *
sigset_string(private_t * pri,sigset_t * sp)2694 sigset_string(private_t *pri, sigset_t *sp)
2695 {
2696 	char *s = pri->code_buf;
2697 	int n = sizeof (*sp) / sizeof (int32_t);
2698 	int32_t *lp = (int32_t *)sp;
2699 
2700 	while (--n >= 0) {
2701 		int32_t val = *lp++;
2702 
2703 		if (val == 0)
2704 			s += sprintf(s, " 0");
2705 		else
2706 			s += sprintf(s, " 0x%.8X", val);
2707 	}
2708 
2709 	return (pri->code_buf);
2710 }
2711 
2712 void
show_sigset(private_t * pri,long offset,const char * name)2713 show_sigset(private_t *pri, long offset, const char *name)
2714 {
2715 	sigset_t sigset;
2716 
2717 	if (offset != 0 &&
2718 	    Pread(Proc, &sigset, sizeof (sigset), offset) == sizeof (sigset)) {
2719 		(void) printf("%s\t%s =%s\n",
2720 		    pri->pname, name, sigset_string(pri, &sigset));
2721 	}
2722 }
2723 
2724 #ifdef _LP64
2725 void
show_sigaltstack32(private_t * pri,long offset,const char * name)2726 show_sigaltstack32(private_t *pri, long offset, const char *name)
2727 {
2728 	struct sigaltstack32 altstack;
2729 
2730 	if (offset != 0 &&
2731 	    Pread(Proc, &altstack, sizeof (altstack), offset) ==
2732 	    sizeof (altstack)) {
2733 		(void) printf("%s\t%s: sp=0x%.8X size=%u flags=0x%.4X\n",
2734 		    pri->pname,
2735 		    name,
2736 		    altstack.ss_sp,
2737 		    altstack.ss_size,
2738 		    altstack.ss_flags);
2739 	}
2740 }
2741 #endif	/* _LP64 */
2742 
2743 void
show_sigaltstack(private_t * pri,long offset,const char * name)2744 show_sigaltstack(private_t *pri, long offset, const char *name)
2745 {
2746 	struct sigaltstack altstack;
2747 
2748 #ifdef _LP64
2749 	if (data_model != PR_MODEL_LP64) {
2750 		show_sigaltstack32(pri, offset, name);
2751 		return;
2752 	}
2753 #endif
2754 	if (offset != 0 &&
2755 	    Pread(Proc, &altstack, sizeof (altstack), offset) ==
2756 	    sizeof (altstack)) {
2757 		(void) printf("%s\t%s: sp=0x%.8lX size=%lu flags=0x%.4X\n",
2758 		    pri->pname,
2759 		    name,
2760 		    (ulong_t)altstack.ss_sp,
2761 		    (ulong_t)altstack.ss_size,
2762 		    altstack.ss_flags);
2763 	}
2764 }
2765 
2766 #ifdef _LP64
2767 void
show_sigaction32(private_t * pri,long offset,const char * name,long odisp)2768 show_sigaction32(private_t *pri, long offset, const char *name, long odisp)
2769 {
2770 	struct sigaction32 sigaction;
2771 
2772 	if (offset != 0 &&
2773 	    Pread(Proc, &sigaction, sizeof (sigaction), offset) ==
2774 	    sizeof (sigaction)) {
2775 		/* This is stupid, we shouldn't have to do this */
2776 		if (odisp != 0)
2777 			sigaction.sa_handler = (caddr32_t)odisp;
2778 		(void) printf(
2779 		    "%s    %s: hand = 0x%.8X mask =%s flags = 0x%.4X\n",
2780 		    pri->pname,
2781 		    name,
2782 		    sigaction.sa_handler,
2783 		    sigset_string(pri, (sigset_t *)&sigaction.sa_mask),
2784 		    sigaction.sa_flags);
2785 	}
2786 }
2787 #endif	/* _LP64 */
2788 
2789 void
show_sigaction(private_t * pri,long offset,const char * name,long odisp)2790 show_sigaction(private_t *pri, long offset, const char *name, long odisp)
2791 {
2792 	struct sigaction sigaction;
2793 
2794 #ifdef _LP64
2795 	if (data_model != PR_MODEL_LP64) {
2796 		show_sigaction32(pri, offset, name, odisp);
2797 		return;
2798 	}
2799 #endif
2800 	if (offset != 0 &&
2801 	    Pread(Proc, &sigaction, sizeof (sigaction), offset) ==
2802 	    sizeof (sigaction)) {
2803 		/* This is stupid, we shouldn't have to do this */
2804 		if (odisp != 0)
2805 			sigaction.sa_handler = (void (*)())odisp;
2806 		(void) printf(
2807 		    "%s    %s: hand = 0x%.8lX mask =%s flags = 0x%.4X\n",
2808 		    pri->pname,
2809 		    name,
2810 		    (long)sigaction.sa_handler,
2811 		    sigset_string(pri, &sigaction.sa_mask),
2812 		    sigaction.sa_flags);
2813 	}
2814 }
2815 
2816 #ifdef _LP64
2817 void
print_siginfo32(private_t * pri,const siginfo32_t * sip)2818 print_siginfo32(private_t *pri, const siginfo32_t *sip)
2819 {
2820 	const char *code = NULL;
2821 
2822 	(void) printf("%s      siginfo: %s", pri->pname,
2823 	    signame(pri, sip->si_signo));
2824 
2825 	if (sip->si_signo != 0 && SI_FROMUSER(sip) && sip->si_pid != 0) {
2826 		(void) printf(" pid=%d uid=%d", sip->si_pid, sip->si_uid);
2827 		if (sip->si_code != 0)
2828 			(void) printf(" code=%d", sip->si_code);
2829 		(void) fputc('\n', stdout);
2830 		return;
2831 	}
2832 
2833 	switch (sip->si_signo) {
2834 	default:
2835 		(void) fputc('\n', stdout);
2836 		return;
2837 	case SIGILL:
2838 	case SIGTRAP:
2839 	case SIGFPE:
2840 	case SIGSEGV:
2841 	case SIGBUS:
2842 	case SIGEMT:
2843 	case SIGCLD:
2844 	case SIGPOLL:
2845 	case SIGXFSZ:
2846 		break;
2847 	}
2848 
2849 	switch (sip->si_signo) {
2850 	case SIGILL:
2851 		switch (sip->si_code) {
2852 		case ILL_ILLOPC:	code = "ILL_ILLOPC";	break;
2853 		case ILL_ILLOPN:	code = "ILL_ILLOPN";	break;
2854 		case ILL_ILLADR:	code = "ILL_ILLADR";	break;
2855 		case ILL_ILLTRP:	code = "ILL_ILLTRP";	break;
2856 		case ILL_PRVOPC:	code = "ILL_PRVOPC";	break;
2857 		case ILL_PRVREG:	code = "ILL_PRVREG";	break;
2858 		case ILL_COPROC:	code = "ILL_COPROC";	break;
2859 		case ILL_BADSTK:	code = "ILL_BADSTK";	break;
2860 		}
2861 		break;
2862 	case SIGTRAP:
2863 		switch (sip->si_code) {
2864 		case TRAP_BRKPT:	code = "TRAP_BRKPT";	break;
2865 		case TRAP_TRACE:	code = "TRAP_TRACE";	break;
2866 		case TRAP_RWATCH:	code = "TRAP_RWATCH";	break;
2867 		case TRAP_WWATCH:	code = "TRAP_WWATCH";	break;
2868 		case TRAP_XWATCH:	code = "TRAP_XWATCH";	break;
2869 		case TRAP_DTRACE:	code = "TRAP_DTRACE";	break;
2870 		}
2871 		break;
2872 	case SIGFPE:
2873 		switch (sip->si_code) {
2874 		case FPE_INTDIV:	code = "FPE_INTDIV";	break;
2875 		case FPE_INTOVF:	code = "FPE_INTOVF";	break;
2876 		case FPE_FLTDIV:	code = "FPE_FLTDIV";	break;
2877 		case FPE_FLTOVF:	code = "FPE_FLTOVF";	break;
2878 		case FPE_FLTUND:	code = "FPE_FLTUND";	break;
2879 		case FPE_FLTRES:	code = "FPE_FLTRES";	break;
2880 		case FPE_FLTINV:	code = "FPE_FLTINV";	break;
2881 		case FPE_FLTSUB:	code = "FPE_FLTSUB";	break;
2882 #if defined(FPE_FLTDEN)
2883 		case FPE_FLTDEN:	code = "FPE_FLTDEN";	break;
2884 #endif
2885 		}
2886 		break;
2887 	case SIGSEGV:
2888 		switch (sip->si_code) {
2889 		case SEGV_MAPERR:	code = "SEGV_MAPERR";	break;
2890 		case SEGV_ACCERR:	code = "SEGV_ACCERR";	break;
2891 		}
2892 		break;
2893 	case SIGEMT:
2894 		switch (sip->si_code) {
2895 #ifdef EMT_TAGOVF
2896 		case EMT_TAGOVF:	code = "EMT_TAGOVF";	break;
2897 #endif
2898 		case EMT_CPCOVF:	code = "EMT_CPCOVF";	break;
2899 		}
2900 		break;
2901 	case SIGBUS:
2902 		switch (sip->si_code) {
2903 		case BUS_ADRALN:	code = "BUS_ADRALN";	break;
2904 		case BUS_ADRERR:	code = "BUS_ADRERR";	break;
2905 		case BUS_OBJERR:	code = "BUS_OBJERR";	break;
2906 		}
2907 		break;
2908 	case SIGCLD:
2909 		switch (sip->si_code) {
2910 		case CLD_EXITED:	code = "CLD_EXITED";	break;
2911 		case CLD_KILLED:	code = "CLD_KILLED";	break;
2912 		case CLD_DUMPED:	code = "CLD_DUMPED";	break;
2913 		case CLD_TRAPPED:	code = "CLD_TRAPPED";	break;
2914 		case CLD_STOPPED:	code = "CLD_STOPPED";	break;
2915 		case CLD_CONTINUED:	code = "CLD_CONTINUED";	break;
2916 		}
2917 		break;
2918 	case SIGPOLL:
2919 		switch (sip->si_code) {
2920 		case POLL_IN:		code = "POLL_IN";	break;
2921 		case POLL_OUT:		code = "POLL_OUT";	break;
2922 		case POLL_MSG:		code = "POLL_MSG";	break;
2923 		case POLL_ERR:		code = "POLL_ERR";	break;
2924 		case POLL_PRI:		code = "POLL_PRI";	break;
2925 		case POLL_HUP:		code = "POLL_HUP";	break;
2926 		}
2927 		break;
2928 	}
2929 
2930 	if (code == NULL) {
2931 		(void) sprintf(pri->code_buf, "code=%d", sip->si_code);
2932 		code = (const char *)pri->code_buf;
2933 	}
2934 
2935 	switch (sip->si_signo) {
2936 	case SIGILL:
2937 	case SIGTRAP:
2938 	case SIGFPE:
2939 	case SIGSEGV:
2940 	case SIGBUS:
2941 	case SIGEMT:
2942 		(void) printf(" %s addr=0x%.8X",
2943 		    code,
2944 		    sip->si_addr);
2945 		break;
2946 	case SIGCLD:
2947 		(void) printf(" %s pid=%d status=0x%.4X",
2948 		    code,
2949 		    sip->si_pid,
2950 		    sip->si_status);
2951 		break;
2952 	case SIGPOLL:
2953 	case SIGXFSZ:
2954 		(void) printf(" %s fd=%d band=%d",
2955 		    code,
2956 		    sip->si_fd,
2957 		    sip->si_band);
2958 		break;
2959 	}
2960 
2961 	if (sip->si_errno != 0) {
2962 		const char *ename = errname(sip->si_errno);
2963 
2964 		(void) printf(" errno=%d", sip->si_errno);
2965 		if (ename != NULL)
2966 			(void) printf("(%s)", ename);
2967 	}
2968 
2969 	(void) fputc('\n', stdout);
2970 }
2971 #endif	/* _LP64 */
2972 
2973 void
print_siginfo(private_t * pri,const siginfo_t * sip)2974 print_siginfo(private_t *pri, const siginfo_t *sip)
2975 {
2976 	const char *code = NULL;
2977 
2978 	(void) printf("%s      siginfo: %s", pri->pname,
2979 	    signame(pri, sip->si_signo));
2980 
2981 	if (sip->si_signo != 0 && SI_FROMUSER(sip) && sip->si_pid != 0) {
2982 		(void) printf(" pid=%d uid=%u",
2983 		    (int)sip->si_pid,
2984 		    sip->si_uid);
2985 		if (sip->si_code != 0)
2986 			(void) printf(" code=%d", sip->si_code);
2987 		(void) fputc('\n', stdout);
2988 		return;
2989 	}
2990 
2991 	switch (sip->si_signo) {
2992 	default:
2993 		(void) fputc('\n', stdout);
2994 		return;
2995 	case SIGILL:
2996 	case SIGTRAP:
2997 	case SIGFPE:
2998 	case SIGSEGV:
2999 	case SIGBUS:
3000 	case SIGEMT:
3001 	case SIGCLD:
3002 	case SIGPOLL:
3003 	case SIGXFSZ:
3004 		break;
3005 	}
3006 
3007 	switch (sip->si_signo) {
3008 	case SIGILL:
3009 		switch (sip->si_code) {
3010 		case ILL_ILLOPC:	code = "ILL_ILLOPC";	break;
3011 		case ILL_ILLOPN:	code = "ILL_ILLOPN";	break;
3012 		case ILL_ILLADR:	code = "ILL_ILLADR";	break;
3013 		case ILL_ILLTRP:	code = "ILL_ILLTRP";	break;
3014 		case ILL_PRVOPC:	code = "ILL_PRVOPC";	break;
3015 		case ILL_PRVREG:	code = "ILL_PRVREG";	break;
3016 		case ILL_COPROC:	code = "ILL_COPROC";	break;
3017 		case ILL_BADSTK:	code = "ILL_BADSTK";	break;
3018 		}
3019 		break;
3020 	case SIGTRAP:
3021 		switch (sip->si_code) {
3022 		case TRAP_BRKPT:	code = "TRAP_BRKPT";	break;
3023 		case TRAP_TRACE:	code = "TRAP_TRACE";	break;
3024 		case TRAP_RWATCH:	code = "TRAP_RWATCH";	break;
3025 		case TRAP_WWATCH:	code = "TRAP_WWATCH";	break;
3026 		case TRAP_XWATCH:	code = "TRAP_XWATCH";	break;
3027 		case TRAP_DTRACE:	code = "TRAP_DTRACE";	break;
3028 		}
3029 		break;
3030 	case SIGFPE:
3031 		switch (sip->si_code) {
3032 		case FPE_INTDIV:	code = "FPE_INTDIV";	break;
3033 		case FPE_INTOVF:	code = "FPE_INTOVF";	break;
3034 		case FPE_FLTDIV:	code = "FPE_FLTDIV";	break;
3035 		case FPE_FLTOVF:	code = "FPE_FLTOVF";	break;
3036 		case FPE_FLTUND:	code = "FPE_FLTUND";	break;
3037 		case FPE_FLTRES:	code = "FPE_FLTRES";	break;
3038 		case FPE_FLTINV:	code = "FPE_FLTINV";	break;
3039 		case FPE_FLTSUB:	code = "FPE_FLTSUB";	break;
3040 #if defined(FPE_FLTDEN)
3041 		case FPE_FLTDEN:	code = "FPE_FLTDEN";	break;
3042 #endif
3043 		}
3044 		break;
3045 	case SIGSEGV:
3046 		switch (sip->si_code) {
3047 		case SEGV_MAPERR:	code = "SEGV_MAPERR";	break;
3048 		case SEGV_ACCERR:	code = "SEGV_ACCERR";	break;
3049 		}
3050 		break;
3051 	case SIGEMT:
3052 		switch (sip->si_code) {
3053 #ifdef EMT_TAGOVF
3054 		case EMT_TAGOVF:	code = "EMT_TAGOVF";	break;
3055 #endif
3056 		case EMT_CPCOVF:	code = "EMT_CPCOVF";	break;
3057 		}
3058 		break;
3059 	case SIGBUS:
3060 		switch (sip->si_code) {
3061 		case BUS_ADRALN:	code = "BUS_ADRALN";	break;
3062 		case BUS_ADRERR:	code = "BUS_ADRERR";	break;
3063 		case BUS_OBJERR:	code = "BUS_OBJERR";	break;
3064 		}
3065 		break;
3066 	case SIGCLD:
3067 		switch (sip->si_code) {
3068 		case CLD_EXITED:	code = "CLD_EXITED";	break;
3069 		case CLD_KILLED:	code = "CLD_KILLED";	break;
3070 		case CLD_DUMPED:	code = "CLD_DUMPED";	break;
3071 		case CLD_TRAPPED:	code = "CLD_TRAPPED";	break;
3072 		case CLD_STOPPED:	code = "CLD_STOPPED";	break;
3073 		case CLD_CONTINUED:	code = "CLD_CONTINUED";	break;
3074 		}
3075 		break;
3076 	case SIGPOLL:
3077 		switch (sip->si_code) {
3078 		case POLL_IN:		code = "POLL_IN";	break;
3079 		case POLL_OUT:		code = "POLL_OUT";	break;
3080 		case POLL_MSG:		code = "POLL_MSG";	break;
3081 		case POLL_ERR:		code = "POLL_ERR";	break;
3082 		case POLL_PRI:		code = "POLL_PRI";	break;
3083 		case POLL_HUP:		code = "POLL_HUP";	break;
3084 		}
3085 		break;
3086 	}
3087 
3088 	if (code == NULL) {
3089 		(void) sprintf(pri->code_buf, "code=%d", sip->si_code);
3090 		code = (const char *)pri->code_buf;
3091 	}
3092 
3093 	switch (sip->si_signo) {
3094 	case SIGILL:
3095 	case SIGTRAP:
3096 	case SIGFPE:
3097 	case SIGSEGV:
3098 	case SIGBUS:
3099 	case SIGEMT:
3100 		(void) printf(" %s addr=0x%.8lX",
3101 		    code,
3102 		    (long)sip->si_addr);
3103 		break;
3104 	case SIGCLD:
3105 		(void) printf(" %s pid=%d status=0x%.4X",
3106 		    code,
3107 		    (int)sip->si_pid,
3108 		    sip->si_status);
3109 		break;
3110 	case SIGPOLL:
3111 	case SIGXFSZ:
3112 		(void) printf(" %s fd=%d band=%ld",
3113 		    code,
3114 		    sip->si_fd,
3115 		    sip->si_band);
3116 		break;
3117 	}
3118 
3119 	if (sip->si_errno != 0) {
3120 		const char *ename = errname(sip->si_errno);
3121 
3122 		(void) printf(" errno=%d", sip->si_errno);
3123 		if (ename != NULL)
3124 			(void) printf("(%s)", ename);
3125 	}
3126 
3127 	(void) fputc('\n', stdout);
3128 }
3129 
3130 #ifdef _LP64
3131 void
show_siginfo32(private_t * pri,long offset)3132 show_siginfo32(private_t *pri, long offset)
3133 {
3134 	struct siginfo32 siginfo;
3135 
3136 	if (offset != 0 &&
3137 	    Pread(Proc, &siginfo, sizeof (siginfo), offset) == sizeof (siginfo))
3138 		print_siginfo32(pri, &siginfo);
3139 }
3140 #endif	/* _LP64 */
3141 
3142 void
show_siginfo(private_t * pri,long offset)3143 show_siginfo(private_t *pri, long offset)
3144 {
3145 	struct siginfo siginfo;
3146 
3147 #ifdef _LP64
3148 	if (data_model != PR_MODEL_LP64) {
3149 		show_siginfo32(pri, offset);
3150 		return;
3151 	}
3152 #endif
3153 	if (offset != 0 &&
3154 	    Pread(Proc, &siginfo, sizeof (siginfo), offset) == sizeof (siginfo))
3155 		print_siginfo(pri, &siginfo);
3156 }
3157 
3158 void
show_bool(private_t * pri,long offset,int count)3159 show_bool(private_t *pri, long offset, int count)
3160 {
3161 	int serial = (count > MYBUFSIZ / 4);
3162 
3163 	/* enter region of lengthy output */
3164 	if (serial)
3165 		Eserialize();
3166 
3167 	while (count > 0) {
3168 		char buf[32];
3169 		int nb = (count < 32)? count : 32;
3170 		int i;
3171 
3172 		if (Pread(Proc, buf, (size_t)nb, offset) != nb)
3173 			break;
3174 
3175 		(void) printf("%s   ", pri->pname);
3176 		for (i = 0; i < nb; i++)
3177 			(void) printf(" %d", buf[i]);
3178 		(void) fputc('\n', stdout);
3179 
3180 		count -= nb;
3181 		offset += nb;
3182 	}
3183 
3184 	/* exit region of lengthy output */
3185 	if (serial)
3186 		Xserialize();
3187 }
3188 
3189 #ifdef _LP64
3190 void
show_iovec32(private_t * pri,long offset,int niov,int showbuf,long count)3191 show_iovec32(private_t *pri, long offset, int niov, int showbuf, long count)
3192 {
3193 	iovec32_t iovec[16];
3194 	iovec32_t *ip;
3195 	long nb;
3196 	int serial = (count > MYBUFSIZ / 4 && showbuf);
3197 
3198 	if (niov > 16)		/* is this the real limit? */
3199 		niov = 16;
3200 
3201 	if (offset != 0 && niov > 0 &&
3202 	    Pread(Proc, &iovec[0], niov*sizeof (iovec32_t), offset)
3203 	    == niov*sizeof (iovec32_t)) {
3204 		/* enter region of lengthy output */
3205 		if (serial)
3206 			Eserialize();
3207 
3208 		for (ip = &iovec[0]; niov-- && !interrupt; ip++) {
3209 			(void) printf("%s\tiov_base = 0x%.8X  iov_len = %d\n",
3210 			    pri->pname,
3211 			    ip->iov_base,
3212 			    ip->iov_len);
3213 			if ((nb = count) > 0) {
3214 				if (nb > ip->iov_len)
3215 					nb = ip->iov_len;
3216 				if (nb > 0)
3217 					count -= nb;
3218 			}
3219 			if (showbuf && nb > 0)
3220 				showbuffer(pri, (long)ip->iov_base, nb);
3221 		}
3222 
3223 		/* exit region of lengthy output */
3224 		if (serial)
3225 			Xserialize();
3226 	}
3227 }
3228 #endif	/* _LP64 */
3229 
3230 void
show_iovec(private_t * pri,long offset,long niov,int showbuf,long count)3231 show_iovec(private_t *pri, long offset, long niov, int showbuf, long count)
3232 {
3233 	iovec_t iovec[16];
3234 	iovec_t *ip;
3235 	long nb;
3236 	int serial = (count > MYBUFSIZ / 4 && showbuf);
3237 
3238 #ifdef _LP64
3239 	if (data_model != PR_MODEL_LP64) {
3240 		show_iovec32(pri, offset, niov, showbuf, count);
3241 		return;
3242 	}
3243 #endif
3244 	if (niov > 16)		/* is this the real limit? */
3245 		niov = 16;
3246 
3247 	if (offset != 0 && niov > 0 &&
3248 	    Pread(Proc, &iovec[0], niov*sizeof (iovec_t), offset)
3249 	    == niov*sizeof (iovec_t)) {
3250 		/* enter region of lengthy output */
3251 		if (serial)
3252 			Eserialize();
3253 
3254 		for (ip = &iovec[0]; niov-- && !interrupt; ip++) {
3255 			(void) printf("%s\tiov_base = 0x%.8lX  iov_len = %lu\n",
3256 			    pri->pname,
3257 			    (long)ip->iov_base,
3258 			    ip->iov_len);
3259 			if ((nb = count) > 0) {
3260 				if (nb > ip->iov_len)
3261 					nb = ip->iov_len;
3262 				if (nb > 0)
3263 					count -= nb;
3264 			}
3265 			if (showbuf && nb > 0)
3266 				showbuffer(pri, (long)ip->iov_base, nb);
3267 		}
3268 
3269 		/* exit region of lengthy output */
3270 		if (serial)
3271 			Xserialize();
3272 	}
3273 }
3274 
3275 void
show_dents32(private_t * pri,long offset,long count)3276 show_dents32(private_t *pri, long offset, long count)
3277 {
3278 	long buf[MYBUFSIZ / sizeof (long)];
3279 	struct dirent32 *dp;
3280 	int serial = (count > 100);
3281 
3282 	if (offset == 0)
3283 		return;
3284 
3285 	/* enter region of lengthy output */
3286 	if (serial)
3287 		Eserialize();
3288 
3289 	while (count > 0 && !interrupt) {
3290 		int nb = count < MYBUFSIZ? (int)count : MYBUFSIZ;
3291 
3292 		if ((nb = Pread(Proc, &buf[0], (size_t)nb, offset)) <= 0)
3293 			break;
3294 
3295 		dp = (struct dirent32 *)&buf[0];
3296 		if (nb < (int)(dp->d_name - (char *)dp))
3297 			break;
3298 		if ((unsigned)nb < dp->d_reclen) {
3299 			/* getdents() error? */
3300 			(void) printf(
3301 			    "%s    ino=%-5u off=%-4d rlen=%-3d\n",
3302 			    pri->pname,
3303 			    dp->d_ino,
3304 			    dp->d_off,
3305 			    dp->d_reclen);
3306 			break;
3307 		}
3308 
3309 		while (!interrupt &&
3310 		    nb >= (int)(dp->d_name - (char *)dp) &&
3311 		    (unsigned)nb >= dp->d_reclen) {
3312 			(void) printf(
3313 			    "%s    ino=%-5u off=%-4d rlen=%-3d \"%.*s\"\n",
3314 			    pri->pname,
3315 			    dp->d_ino,
3316 			    dp->d_off,
3317 			    dp->d_reclen,
3318 			    dp->d_reclen - (int)(dp->d_name - (char *)dp),
3319 			    dp->d_name);
3320 			nb -= dp->d_reclen;
3321 			count -= dp->d_reclen;
3322 			offset += dp->d_reclen;
3323 			/* LINTED improper alignment */
3324 			dp = (struct dirent32 *)((char *)dp + dp->d_reclen);
3325 		}
3326 	}
3327 
3328 	/* exit region of lengthy output */
3329 	if (serial)
3330 		Xserialize();
3331 }
3332 
3333 void
show_dents64(private_t * pri,long offset,long count)3334 show_dents64(private_t *pri, long offset, long count)
3335 {
3336 	long long buf[MYBUFSIZ / sizeof (long long)];
3337 	struct dirent64 *dp;
3338 	int serial = (count > 100);
3339 
3340 	if (offset == 0)
3341 		return;
3342 
3343 	/* enter region of lengthy output */
3344 	if (serial)
3345 		Eserialize();
3346 
3347 	while (count > 0 && !interrupt) {
3348 		int nb = count < MYBUFSIZ? (int)count : MYBUFSIZ;
3349 
3350 		if ((nb = Pread(Proc, &buf[0], (size_t)nb, offset)) <= 0)
3351 			break;
3352 
3353 		dp = (struct dirent64 *)&buf[0];
3354 		if (nb < (int)(dp->d_name - (char *)dp))
3355 			break;
3356 		if ((unsigned)nb < dp->d_reclen) {
3357 			/* getdents() error? */
3358 			(void) printf(
3359 			    "%s    ino=%-5llu off=%-4lld rlen=%-3d\n",
3360 			    pri->pname,
3361 			    (long long)dp->d_ino,
3362 			    (long long)dp->d_off,
3363 			    dp->d_reclen);
3364 			break;
3365 		}
3366 
3367 		while (!interrupt &&
3368 		    nb >= (int)(dp->d_name - (char *)dp) &&
3369 		    (unsigned)nb >= dp->d_reclen) {
3370 			(void) printf(
3371 			    "%s    ino=%-5llu off=%-4lld rlen=%-3d \"%.*s\"\n",
3372 			    pri->pname,
3373 			    (long long)dp->d_ino,
3374 			    (long long)dp->d_off,
3375 			    dp->d_reclen,
3376 			    dp->d_reclen - (int)(dp->d_name - (char *)dp),
3377 			    dp->d_name);
3378 			nb -= dp->d_reclen;
3379 			count -= dp->d_reclen;
3380 			offset += dp->d_reclen;
3381 			/* LINTED improper alignment */
3382 			dp = (struct dirent64 *)((char *)dp + dp->d_reclen);
3383 		}
3384 	}
3385 
3386 	/* exit region of lengthy output */
33