Annotation of src/usr.bin/kdump/kdump.c, Revision 1.91
1.91 ! guenther 1: /* $OpenBSD: kdump.c,v 1.90 2014/10/08 04:02:46 doug Exp $ */
1.4 deraadt 2:
1.1 deraadt 3: /*-
4: * Copyright (c) 1988, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
1.21 millert 15: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 16: * may be used to endorse or promote products derived from this software
17: * without specific prior written permission.
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29: * SUCH DAMAGE.
30: */
31:
32: #include <sys/param.h>
33: #include <sys/time.h>
34: #include <sys/uio.h>
35: #include <sys/ktrace.h>
36: #include <sys/ioctl.h>
1.62 otto 37: #include <sys/malloc.h>
38: #include <sys/namei.h>
1.1 deraadt 39: #include <sys/ptrace.h>
1.62 otto 40: #include <sys/sem.h>
41: #include <sys/shm.h>
1.51 otto 42: #include <sys/socket.h>
1.28 deraadt 43: #include <sys/sysctl.h>
1.63 deraadt 44: #include <sys/siginfo.h>
1.62 otto 45: #include <sys/vmmeter.h>
46: #include <sys/tty.h>
1.82 guenther 47: #include <sys/wait.h>
1.1 deraadt 48: #define _KERNEL
1.84 guenther 49: #include <errno.h>
1.1 deraadt 50: #undef _KERNEL
1.62 otto 51: #include <ddb/db_var.h>
52: #include <machine/cpu.h>
1.1 deraadt 53:
1.33 tedu 54: #include <ctype.h>
1.1 deraadt 55: #include <err.h>
1.61 matthew 56: #include <fcntl.h>
1.64 guenther 57: #include <limits.h>
1.77 guenther 58: #include <poll.h>
1.1 deraadt 59: #include <signal.h>
60: #include <stdio.h>
61: #include <stdlib.h>
1.55 otto 62: #include <stdint.h>
1.1 deraadt 63: #include <string.h>
64: #include <unistd.h>
65: #include <vis.h>
66:
67: #include "ktrace.h"
1.22 deraadt 68: #include "kdump.h"
1.51 otto 69: #include "kdump_subr.h"
1.12 espie 70: #include "extern.h"
1.1 deraadt 71:
1.67 mikeb 72: int timestamp, decimal, iohex, fancy = 1, maxdata = INT_MAX;
73: int needtid, resolv, tail;
1.1 deraadt 74: char *tracefile = DEF_TRACEFILE;
75: struct ktr_header ktr_header;
1.85 guenther 76: pid_t pid_opt = -1;
1.1 deraadt 77:
78: #define eqs(s1, s2) (strcmp((s1), (s2)) == 0)
79:
80: #include <sys/syscall.h>
81:
1.25 mickey 82: #include <compat/linux/linux_syscall.h>
1.1 deraadt 83:
84: #define KTRACE
1.19 mickey 85: #define PTRACE
1.7 deraadt 86: #define NFSCLIENT
87: #define NFSSERVER
88: #define SYSVSEM
89: #define SYSVMSG
90: #define SYSVSHM
91: #define LFS
1.25 mickey 92: #include <kern/syscalls.c>
1.1 deraadt 93:
1.25 mickey 94: #include <compat/linux/linux_syscalls.c>
1.1 deraadt 95: #undef KTRACE
1.19 mickey 96: #undef PTRACE
1.7 deraadt 97: #undef NFSCLIENT
98: #undef NFSSERVER
99: #undef SYSVSEM
100: #undef SYSVMSG
101: #undef SYSVSHM
102: #undef LFS
1.1 deraadt 103:
104: struct emulation {
105: char *name; /* Emulation name */
106: char **sysnames; /* Array of system call names */
107: int nsysnames; /* Number of */
108: };
109:
110: static struct emulation emulations[] = {
1.9 deraadt 111: { "native", syscallnames, SYS_MAXSYSCALL },
112: { "linux", linux_syscallnames, LINUX_SYS_MAXSYSCALL },
1.49 miod 113: { NULL, NULL, 0 }
1.1 deraadt 114: };
115:
1.59 otto 116: static struct emulation *current;
1.60 otto 117: static struct emulation *def_emul;
1.59 otto 118:
119: struct pid_emul {
120: struct emulation *e;
121: pid_t p;
122: };
123:
124: static struct pid_emul *pe_table;
125: static size_t pe_size;
1.1 deraadt 126:
127:
128: static char *ptrace_ops[] = {
129: "PT_TRACE_ME", "PT_READ_I", "PT_READ_D", "PT_READ_U",
130: "PT_WRITE_I", "PT_WRITE_D", "PT_WRITE_U", "PT_CONTINUE",
1.15 art 131: "PT_KILL", "PT_ATTACH", "PT_DETACH", "PT_IO",
1.64 guenther 132: "PT_SET_EVENT_MASK", "PT_GET_EVENT_MASK", "PT_GET_PROCESS_STATE",
1.71 guenther 133: "PT_GET_THREAD_FIRST", "PT_GET_THREAD_NEXT",
1.1 deraadt 134: };
135:
1.52 otto 136: static int narg;
137: static register_t *ap;
138: static char sep;
139:
1.59 otto 140: static void mappidtoemul(pid_t, struct emulation *);
141: static struct emulation * findemul(pid_t);
1.37 tedu 142: static int fread_tail(void *, size_t, size_t);
1.13 millert 143: static void dumpheader(struct ktr_header *);
144: static void ktrcsw(struct ktr_csw *);
1.37 tedu 145: static void ktremul(char *, size_t);
146: static void ktrgenio(struct ktr_genio *, size_t);
147: static void ktrnamei(const char *, size_t);
1.13 millert 148: static void ktrpsig(struct ktr_psig *);
149: static void ktrsyscall(struct ktr_syscall *);
1.62 otto 150: static const char *kresolvsysctl(int, int *, int);
1.13 millert 151: static void ktrsysret(struct ktr_sysret *);
1.81 miod 152: static void ktruser(struct ktr_user *, size_t);
1.13 millert 153: static void setemul(const char *);
154: static void usage(void);
1.61 matthew 155: static void atfd(int);
1.77 guenther 156: static void polltimeout(int);
1.82 guenther 157: static void pgid(int);
158: static void wait4pid(int);
1.83 guenther 159: static void signame(int);
160: static void semctlname(int);
161: static void shmctlname(int);
162: static void semgetname(int);
163: static void flagsandmodename(int, int);
164: static void clockname(int);
165: static void sockoptlevelname(int);
1.88 guenther 166: static void ktraceopname(int);
1.12 espie 167:
1.1 deraadt 168: int
1.17 deraadt 169: main(int argc, char *argv[])
1.1 deraadt 170: {
1.37 tedu 171: int ch, silent;
172: size_t ktrlen, size;
1.17 deraadt 173: int trpoints = ALL_POINTS;
1.12 espie 174: void *m;
1.1 deraadt 175:
1.60 otto 176: def_emul = current = &emulations[0]; /* native */
1.1 deraadt 177:
1.67 mikeb 178: while ((ch = getopt(argc, argv, "e:f:dHlm:nrRp:Tt:xX")) != -1)
1.1 deraadt 179: switch (ch) {
180: case 'e':
181: setemul(optarg);
1.60 otto 182: def_emul = current;
1.1 deraadt 183: break;
184: case 'f':
185: tracefile = optarg;
186: break;
187: case 'd':
188: decimal = 1;
189: break;
1.67 mikeb 190: case 'H':
191: needtid = 1;
192: break;
1.1 deraadt 193: case 'l':
194: tail = 1;
195: break;
196: case 'm':
197: maxdata = atoi(optarg);
198: break;
199: case 'n':
200: fancy = 0;
201: break;
1.17 deraadt 202: case 'p':
1.85 guenther 203: pid_opt = atoi(optarg);
1.17 deraadt 204: break;
1.55 otto 205: case 'r':
206: resolv = 1;
207: break;
1.1 deraadt 208: case 'R':
209: timestamp = 2; /* relative timestamp */
210: break;
211: case 'T':
212: timestamp = 1;
213: break;
214: case 't':
215: trpoints = getpoints(optarg);
216: if (trpoints < 0)
217: errx(1, "unknown trace point in %s", optarg);
218: break;
1.31 tedu 219: case 'x':
220: iohex = 1;
221: break;
222: case 'X':
223: iohex = 2;
224: break;
1.1 deraadt 225: default:
226: usage();
227: }
1.5 deraadt 228: if (argc > optind)
1.1 deraadt 229: usage();
230:
1.37 tedu 231: m = malloc(size = 1025);
1.1 deraadt 232: if (m == NULL)
1.37 tedu 233: err(1, NULL);
1.1 deraadt 234: if (!freopen(tracefile, "r", stdin))
235: err(1, "%s", tracefile);
1.67 mikeb 236: if (fread_tail(&ktr_header, sizeof(struct ktr_header), 1) == 0 ||
237: ktr_header.ktr_type != htobe32(KTR_START))
238: errx(1, "%s: not a dump", tracefile);
1.1 deraadt 239: while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) {
1.17 deraadt 240: silent = 0;
1.59 otto 241: if (pe_size == 0)
242: mappidtoemul(ktr_header.ktr_pid, current);
1.85 guenther 243: if (pid_opt != -1 && pid_opt != ktr_header.ktr_pid)
1.17 deraadt 244: silent = 1;
245: if (silent == 0 && trpoints & (1<<ktr_header.ktr_type))
1.1 deraadt 246: dumpheader(&ktr_header);
1.37 tedu 247: ktrlen = ktr_header.ktr_len;
1.1 deraadt 248: if (ktrlen > size) {
1.23 tedu 249: void *newm;
250:
1.64 guenther 251: if (ktrlen == SIZE_MAX)
252: errx(1, "data too long");
1.23 tedu 253: newm = realloc(m, ktrlen+1);
254: if (newm == NULL)
1.66 deraadt 255: err(1, "realloc");
1.23 tedu 256: m = newm;
1.1 deraadt 257: size = ktrlen;
258: }
259: if (ktrlen && fread_tail(m, ktrlen, 1) == 0)
260: errx(1, "data too short");
1.17 deraadt 261: if (silent)
262: continue;
1.1 deraadt 263: if ((trpoints & (1<<ktr_header.ktr_type)) == 0)
264: continue;
1.59 otto 265: current = findemul(ktr_header.ktr_pid);
1.1 deraadt 266: switch (ktr_header.ktr_type) {
267: case KTR_SYSCALL:
268: ktrsyscall((struct ktr_syscall *)m);
269: break;
270: case KTR_SYSRET:
271: ktrsysret((struct ktr_sysret *)m);
272: break;
273: case KTR_NAMEI:
274: ktrnamei(m, ktrlen);
275: break;
276: case KTR_GENIO:
277: ktrgenio((struct ktr_genio *)m, ktrlen);
278: break;
279: case KTR_PSIG:
280: ktrpsig((struct ktr_psig *)m);
281: break;
282: case KTR_CSW:
283: ktrcsw((struct ktr_csw *)m);
284: break;
285: case KTR_EMUL:
286: ktremul(m, ktrlen);
1.59 otto 287: mappidtoemul(ktr_header.ktr_pid, current);
1.1 deraadt 288: break;
1.55 otto 289: case KTR_STRUCT:
290: ktrstruct(m, ktrlen);
291: break;
1.81 miod 292: case KTR_USER:
293: ktruser(m, ktrlen);
294: break;
1.1 deraadt 295: }
296: if (tail)
297: (void)fflush(stdout);
298: }
1.12 espie 299: exit(0);
1.1 deraadt 300: }
301:
1.59 otto 302: static void
303: mappidtoemul(pid_t pid, struct emulation *emul)
304: {
305: size_t i;
306: struct pid_emul *tmp;
307:
308: for (i = 0; i < pe_size; i++) {
309: if (pe_table[i].p == pid) {
310: pe_table[i].e = emul;
311: return;
312: }
313: }
1.90 doug 314: tmp = reallocarray(pe_table, pe_size + 1, sizeof(*pe_table));
1.59 otto 315: if (tmp == NULL)
316: err(1, NULL);
317: pe_table = tmp;
318: pe_table[pe_size].p = pid;
319: pe_table[pe_size].e = emul;
320: pe_size++;
321: }
322:
323: static struct emulation*
324: findemul(pid_t pid)
325: {
326: size_t i;
327:
328: for (i = 0; i < pe_size; i++)
329: if (pe_table[i].p == pid)
330: return pe_table[i].e;
1.60 otto 331: return def_emul;
1.59 otto 332: }
333:
1.12 espie 334: static int
1.37 tedu 335: fread_tail(void *buf, size_t size, size_t num)
1.1 deraadt 336: {
337: int i;
338:
339: while ((i = fread(buf, size, num, stdin)) == 0 && tail) {
340: (void)sleep(1);
341: clearerr(stdin);
342: }
343: return (i);
344: }
345:
1.12 espie 346: static void
1.17 deraadt 347: dumpheader(struct ktr_header *kth)
1.1 deraadt 348: {
1.67 mikeb 349: static struct timespec prevtime;
1.1 deraadt 350: char unknown[64], *type;
1.67 mikeb 351: struct timespec temp;
1.1 deraadt 352:
353: switch (kth->ktr_type) {
354: case KTR_SYSCALL:
355: type = "CALL";
356: break;
357: case KTR_SYSRET:
358: type = "RET ";
359: break;
360: case KTR_NAMEI:
361: type = "NAMI";
362: break;
363: case KTR_GENIO:
364: type = "GIO ";
365: break;
366: case KTR_PSIG:
367: type = "PSIG";
368: break;
369: case KTR_CSW:
370: type = "CSW";
371: break;
372: case KTR_EMUL:
373: type = "EMUL";
374: break;
1.55 otto 375: case KTR_STRUCT:
376: type = "STRU";
377: break;
1.81 miod 378: case KTR_USER:
379: type = "USER";
380: break;
1.1 deraadt 381: default:
1.17 deraadt 382: (void)snprintf(unknown, sizeof unknown, "UNKNOWN(%d)",
383: kth->ktr_type);
1.1 deraadt 384: type = unknown;
385: }
386:
1.67 mikeb 387: (void)printf("%6ld", (long)kth->ktr_pid);
388: if (needtid)
1.69 mikeb 389: (void)printf("/%-7ld", (long)kth->ktr_tid);
1.67 mikeb 390: (void)printf(" %-8.*s ", MAXCOMLEN, kth->ktr_comm);
1.1 deraadt 391: if (timestamp) {
392: if (timestamp == 2) {
1.67 mikeb 393: timespecsub(&kth->ktr_time, &prevtime, &temp);
1.1 deraadt 394: prevtime = kth->ktr_time;
395: } else
396: temp = kth->ktr_time;
1.79 deraadt 397: printf("%lld.%06ld ", (long long)temp.tv_sec,
398: temp.tv_nsec / 1000);
1.1 deraadt 399: }
400: (void)printf("%s ", type);
401: }
402:
1.12 espie 403: static void
1.17 deraadt 404: ioctldecode(u_long cmd)
1.2 deraadt 405: {
406: char dirbuf[4], *dir = dirbuf;
407:
1.6 deraadt 408: if (cmd & IOC_IN)
409: *dir++ = 'W';
1.2 deraadt 410: if (cmd & IOC_OUT)
411: *dir++ = 'R';
412: *dir = '\0';
413:
1.33 tedu 414: printf(decimal ? ",_IO%s('%c',%lu" : ",_IO%s('%c',%#lx",
415: dirbuf, (int)((cmd >> 8) & 0xff), cmd & 0xff);
1.2 deraadt 416: if ((cmd & IOC_VOID) == 0)
1.34 tedu 417: printf(decimal ? ",%lu)" : ",%#lx)", (cmd >> 16) & 0xff);
1.2 deraadt 418: else
419: printf(")");
420: }
1.1 deraadt 421:
1.52 otto 422: static void
423: ptracedecode(void)
424: {
425: if (*ap >= 0 && *ap <
426: sizeof(ptrace_ops) / sizeof(ptrace_ops[0]))
427: (void)printf("%s", ptrace_ops[*ap]);
428: else switch(*ap) {
429: #ifdef PT_GETFPREGS
430: case PT_GETFPREGS:
431: (void)printf("PT_GETFPREGS");
432: break;
433: #endif
434: case PT_GETREGS:
435: (void)printf("PT_GETREGS");
436: break;
1.75 guenther 437: #ifdef PT_GETXMMREGS
438: case PT_GETXMMREGS:
439: (void)printf("PT_GETXMMREGS");
440: break;
441: #endif
1.52 otto 442: #ifdef PT_SETFPREGS
443: case PT_SETFPREGS:
444: (void)printf("PT_SETFPREGS");
445: break;
446: #endif
447: case PT_SETREGS:
448: (void)printf("PT_SETREGS");
449: break;
1.75 guenther 450: #ifdef PT_SETXMMREGS
451: case PT_SETXMMREGS:
452: (void)printf("PT_SETXMMREGS");
453: break;
454: #endif
1.52 otto 455: #ifdef PT_STEP
456: case PT_STEP:
457: (void)printf("PT_STEP");
458: break;
459: #endif
460: #ifdef PT_WCOOKIE
461: case PT_WCOOKIE:
462: (void)printf("PT_WCOOKIE");
463: break;
464: #endif
465: default:
466: (void)printf("%ld", (long)*ap);
467: break;
468: }
469: sep = ',';
470: ap++;
471: narg--;
472: }
473:
474: static void
475: pn(void (*f)(int))
476: {
477: if (sep)
478: (void)putchar(sep);
479: if (fancy && f != NULL)
480: f((int)*ap);
481: else if (decimal)
482: (void)printf("%ld", (long)*ap);
483: else
484: (void)printf("%#lx", (long)*ap);
485: ap++;
486: narg--;
487: sep = ',';
488: }
489:
490: #ifdef __LP64__
491: #define plln() pn(NULL)
492: #elif _BYTE_ORDER == _LITTLE_ENDIAN
493: static void
494: plln(void)
495: {
496: long long val = ((long long)*ap) & 0xffffffff;
497: ap++;
498: val |= ((long long)*ap) << 32;
499: ap++;
500: narg -= 2;
501: if (sep)
502: (void)putchar(sep);
503: if (decimal)
504: (void)printf("%lld", val);
505: else
506: (void)printf("%#llx", val);
507: sep = ',';
508: }
509: #else
510: static void
511: plln(void)
512: {
513: long long val = ((long long)*ap) << 32;
514: ap++;
515: val |= ((long long)*ap) & 0xffffffff;
516: ap++;
517: narg -= 2;
518: if (sep)
519: (void)putchar(sep);
520: if (decimal)
521: (void)printf("%lld", val);
522: else
523: (void)printf("%#llx", val);
524: sep = ',';
525: }
526: #endif
1.51 otto 527:
1.12 espie 528: static void
1.17 deraadt 529: ktrsyscall(struct ktr_syscall *ktr)
1.1 deraadt 530: {
1.52 otto 531: narg = ktr->ktr_argsize / sizeof(register_t);
532: sep = '\0';
1.1 deraadt 533:
534: if (ktr->ktr_code >= current->nsysnames || ktr->ktr_code < 0)
535: (void)printf("[%d]", ktr->ktr_code);
536: else
537: (void)printf("%s", current->sysnames[ktr->ktr_code]);
538: ap = (register_t *)((char *)ktr + sizeof(struct ktr_syscall));
1.27 mickey 539: (void)putchar('(');
1.52 otto 540:
1.54 otto 541: if (current != &emulations[0])
542: goto nonnative;
543:
1.52 otto 544: switch (ktr->ktr_code) {
545: case SYS_ioctl: {
546: const char *cp;
547:
548: pn(NULL);
549: if (!fancy)
550: break;
551: if ((cp = ioctlname(*ap)) != NULL)
552: (void)printf(",%s", cp);
553: else
554: ioctldecode(*ap);
555: ap++;
556: narg--;
557: break;
558: }
559: case SYS___sysctl: {
1.62 otto 560: const char *s;
561: int *np, n, i, *top;
1.52 otto 562:
563: if (!fancy)
564: break;
565: n = ap[1];
566: if (n > CTL_MAXNAME)
567: n = CTL_MAXNAME;
1.62 otto 568: np = top = (int *)(ap + 6);
569: for (i = 0; n--; np++, i++) {
1.52 otto 570: if (sep)
571: putchar(sep);
1.62 otto 572: if (resolv && (s = kresolvsysctl(i, top, *np)) != NULL)
573: printf("%s", s);
574: else
575: printf("%d", *np);
1.52 otto 576: sep = '.';
1.1 deraadt 577: }
1.52 otto 578:
579: sep = ',';
580: ap += 2;
581: narg -= 2;
582: break;
583: }
584: case SYS_ptrace:
585: if (!fancy)
586: break;
587: ptracedecode();
588: break;
1.89 guenther 589: case SYS_accept4:
590: pn(NULL);
591: pn(NULL);
592: pn(NULL);
593: pn(sockflagsname);
594: break;
1.52 otto 595: case SYS_access:
596: pn(NULL);
597: pn(accessmodename);
598: break;
599: case SYS_chmod:
600: case SYS_fchmod:
1.87 guenther 601: case SYS_mkdir:
602: case SYS_mkfifo:
603: case SYS_mknod:
1.61 matthew 604: pn(NULL);
1.87 guenther 605: pn(modename);
606: break;
607: case SYS_umask:
1.52 otto 608: pn(modename);
609: break;
1.89 guenther 610: case SYS_dup3:
611: pn(NULL);
612: pn(NULL);
613: pn(flagsname);
614: break;
1.52 otto 615: case SYS_fcntl: {
616: int cmd;
617: int arg;
618: pn(NULL);
619: if (!fancy)
620: break;
621: cmd = ap[0];
622: arg = ap[1];
623: (void)putchar(',');
624: fcntlcmdname(cmd, arg);
625: ap += 2;
626: narg -= 2;
627: break;
628: }
629: case SYS_flock:
630: pn(NULL);
631: pn(flockname);
632: break;
633: case SYS_getrlimit:
634: case SYS_setrlimit:
635: pn(rlimitname);
636: break;
637: case SYS_getsockopt:
638: case SYS_setsockopt: {
639: int level;
640:
641: pn(NULL);
642: level = *ap;
643: pn(sockoptlevelname);
644: if (level == SOL_SOCKET)
645: pn(sockoptname);
646: break;
647: }
648: case SYS_kill:
1.82 guenther 649: pn(pgid);
1.52 otto 650: pn(signame);
651: break;
652: case SYS_lseek:
653: pn(NULL);
654: /* skip padding */
655: ap++;
656: narg--;
657: plln();
658: pn(whencename);
659: break;
660: case SYS_madvise:
661: pn(NULL);
662: pn(NULL);
663: pn(madvisebehavname);
664: break;
665: case SYS_minherit:
666: pn(NULL);
667: pn(NULL);
668: pn(minheritname);
669: break;
670: case SYS_mlockall:
671: pn(mlockallname);
672: break;
673: case SYS_mmap:
1.88 guenther 674: case SYS_mquery:
1.52 otto 675: pn(NULL);
676: pn(NULL);
677: pn(mmapprotname);
678: pn(mmapflagsname);
679: pn(NULL);
680: /* skip padding */
681: ap++;
682: narg--;
683: plln();
684: break;
685: case SYS_mprotect:
686: pn(NULL);
687: pn(NULL);
688: pn(mmapprotname);
689: break;
690: case SYS_msync:
691: pn(NULL);
692: pn(NULL);
693: pn(msyncflagsname);
694: break;
695: case SYS_msgctl:
696: pn(NULL);
697: pn(shmctlname);
698: break;
699: case SYS_open: {
700: int flags;
701: int mode;
702:
703: pn(NULL);
704: if (!fancy)
705: break;
706: flags = ap[0];
707: mode = ap[1];
708: (void)putchar(',');
709: flagsandmodename(flags, mode);
710: ap += 2;
711: narg -= 2;
712: break;
713: }
1.89 guenther 714: case SYS_pipe2:
715: pn(NULL);
716: pn(flagsname);
717: break;
1.52 otto 718: case SYS_pread:
719: case SYS_preadv:
720: case SYS_pwrite:
721: case SYS_pwritev:
722: pn(NULL);
723: pn(NULL);
724: pn(NULL);
725: /* skip padding */
726: ap++;
727: narg--;
728: plln();
729: break;
730: case SYS_recvmsg:
731: case SYS_sendmsg:
732: pn(NULL);
733: pn(NULL);
734: pn(sendrecvflagsname);
735: break;
736: case SYS_recvfrom:
737: case SYS_sendto:
738: pn(NULL);
739: pn(NULL);
740: pn(NULL);
741: pn(sendrecvflagsname);
742: break;
1.77 guenther 743: case SYS_shutdown:
744: pn(NULL);
745: pn(shutdownhowname);
746: break;
1.52 otto 747: case SYS___semctl:
748: pn(NULL);
749: pn(NULL);
750: pn(semctlname);
751: break;
752: case SYS_semget:
753: pn(NULL);
754: pn(NULL);
755: pn(semgetname);
756: break;
757: case SYS_shmat:
758: pn(NULL);
759: pn(NULL);
760: pn(shmatname);
761: break;
762: case SYS_shmctl:
763: pn(NULL);
764: pn(shmctlname);
765: break;
1.64 guenther 766: case SYS_clock_gettime:
767: case SYS_clock_settime:
768: case SYS_clock_getres:
769: pn(clockname);
770: break;
1.77 guenther 771: case SYS_poll:
772: pn(NULL);
773: pn(NULL);
774: pn(polltimeout);
775: break;
1.52 otto 776: case SYS_sigaction:
777: pn(signame);
778: break;
779: case SYS_sigprocmask:
780: pn(sigprocmaskhowname);
1.64 guenther 781: pn(sigset);
782: break;
783: case SYS_sigsuspend:
784: pn(sigset);
1.52 otto 785: break;
786: case SYS_socket: {
787: int sockdomain = *ap;
788:
789: pn(sockdomainname);
790: pn(socktypename);
791: if (sockdomain == PF_INET || sockdomain == PF_INET6)
792: pn(sockipprotoname);
793: break;
794: }
795: case SYS_socketpair:
796: pn(sockdomainname);
797: pn(socktypename);
798: break;
799: case SYS_truncate:
800: case SYS_ftruncate:
801: pn(NULL);
802: /* skip padding */
803: ap++;
804: narg--;
805: plln();
806: break;
807: case SYS_wait4:
1.82 guenther 808: pn(wait4pid);
1.52 otto 809: pn(NULL);
810: pn(wait4optname);
811: break;
1.77 guenther 812: case SYS_getrusage:
813: pn(rusagewho);
814: break;
1.64 guenther 815: case SYS___thrsleep:
816: pn(NULL);
817: pn(clockname);
818: break;
819: case SYS___thrsigdivert:
820: pn(sigset);
821: break;
1.61 matthew 822: case SYS_faccessat:
823: pn(atfd);
824: pn(NULL);
825: pn(accessmodename);
826: pn(atflagsname);
827: break;
828: case SYS_fchmodat:
829: pn(atfd);
830: pn(NULL);
831: pn(modename);
832: pn(atflagsname);
833: break;
834: case SYS_fchownat:
835: pn(atfd);
836: pn(NULL);
837: pn(NULL);
838: pn(NULL);
839: pn(atflagsname);
840: break;
841: case SYS_fstatat:
842: pn(atfd);
843: pn(NULL);
844: pn(NULL);
845: pn(atflagsname);
846: break;
847: case SYS_linkat:
848: pn(atfd);
849: pn(NULL);
850: pn(atfd);
851: pn(NULL);
852: pn(atflagsname);
853: break;
854: case SYS_mkdirat:
855: case SYS_mkfifoat:
856: case SYS_mknodat:
857: pn(atfd);
858: pn(NULL);
859: pn(modename);
860: break;
861: case SYS_openat: {
862: int flags;
863: int mode;
864:
865: pn(atfd);
866: pn(NULL);
867: if (!fancy)
868: break;
869: flags = ap[0];
870: mode = ap[1];
871: (void)putchar(',');
872: flagsandmodename(flags, mode);
873: ap += 2;
874: narg -= 2;
875: break;
876: }
877: case SYS_readlinkat:
878: pn(atfd);
879: break;
880: case SYS_renameat:
881: pn(atfd);
882: pn(NULL);
883: pn(atfd);
884: break;
885: case SYS_symlinkat:
886: pn(NULL);
887: pn(atfd);
888: break;
889: case SYS_unlinkat:
890: pn(atfd);
891: pn(NULL);
892: pn(atflagsname);
893: break;
894: case SYS_utimensat:
895: pn(atfd);
896: pn(NULL);
897: pn(NULL);
898: pn(atflagsname);
899: break;
1.77 guenther 900: case SYS_pathconf:
901: case SYS_fpathconf:
902: pn(NULL);
903: pn(pathconfname);
1.86 guenther 904: break;
905: case SYS_ktrace:
906: pn(NULL);
1.88 guenther 907: pn(ktraceopname);
1.86 guenther 908: pn(ktracefacname);
909: pn(pgid);
910: break;
911: case SYS_setitimer:
912: case SYS_getitimer:
913: pn(itimername);
1.91 ! guenther 914: break;
! 915: case SYS_quotactl:
! 916: pn(NULL);
! 917: pn(quotactlcmdname);
1.77 guenther 918: break;
1.52 otto 919: }
920:
1.54 otto 921: nonnative:
1.52 otto 922: while (narg) {
923: if (sep)
924: putchar(sep);
925: if (decimal)
926: (void)printf("%ld", (long)*ap);
927: else
928: (void)printf("%#lx", (long)*ap);
929: sep = ',';
930: ap++;
931: narg--;
1.1 deraadt 932: }
1.27 mickey 933: (void)printf(")\n");
1.62 otto 934: }
935:
936: static struct ctlname topname[] = CTL_NAMES;
937: static struct ctlname kernname[] = CTL_KERN_NAMES;
938: static struct ctlname vmname[] = CTL_VM_NAMES;
939: static struct ctlname fsname[] = CTL_FS_NAMES;
940: static struct ctlname netname[] = CTL_NET_NAMES;
941: static struct ctlname hwname[] = CTL_HW_NAMES;
942: static struct ctlname debugname[CTL_DEBUG_MAXID];
943: static struct ctlname kernmallocname[] = CTL_KERN_MALLOC_NAMES;
944: static struct ctlname forkstatname[] = CTL_KERN_FORKSTAT_NAMES;
945: static struct ctlname nchstatsname[] = CTL_KERN_NCHSTATS_NAMES;
1.88 guenther 946: static struct ctlname kernprocname[] = {
1.64 guenther 947: { NULL },
948: { "all" },
949: { "pid" },
950: { "pgrp" },
951: { "session" },
952: { "tty" },
953: { "uid" },
954: { "ruid" },
1.77 guenther 955: { "kthread" },
1.64 guenther 956: };
1.62 otto 957: static struct ctlname ttysname[] = CTL_KERN_TTY_NAMES;
958: static struct ctlname semname[] = CTL_KERN_SEMINFO_NAMES;
959: static struct ctlname shmname[] = CTL_KERN_SHMINFO_NAMES;
960: static struct ctlname watchdogname[] = CTL_KERN_WATCHDOG_NAMES;
961: static struct ctlname tcname[] = CTL_KERN_TIMECOUNTER_NAMES;
962: #ifdef CTL_MACHDEP_NAMES
963: static struct ctlname machdepname[] = CTL_MACHDEP_NAMES;
964: #endif
965: static struct ctlname ddbname[] = CTL_DDB_NAMES;
966:
967: #ifndef nitems
968: #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
969: #endif
970:
971: #define SETNAME(name) do { names = (name); limit = nitems(name); } while (0)
972:
973: static const char *
974: kresolvsysctl(int depth, int *top, int idx)
975: {
976: struct ctlname *names;
977: size_t limit;
978:
979: names = NULL;
980:
981: switch (depth) {
982: case 0:
983: SETNAME(topname);
984: break;
985: case 1:
986: switch (top[0]) {
987: case CTL_KERN:
988: SETNAME(kernname);
989: break;
990: case CTL_VM:
991: SETNAME(vmname);
992: break;
993: case CTL_FS:
994: SETNAME(fsname);
995: break;
996: case CTL_NET:
997: SETNAME(netname);
998: break;
999: case CTL_DEBUG:
1000: SETNAME(debugname);
1001: break;
1002: case CTL_HW:
1003: SETNAME(hwname);
1004: break;
1005: #ifdef CTL_MACHDEP_NAMES
1006: case CTL_MACHDEP:
1007: SETNAME(machdepname);
1008: break;
1009: #endif
1010: case CTL_DDB:
1011: SETNAME(ddbname);
1012: break;
1013: }
1014: break;
1015: case 2:
1016: switch (top[0]) {
1017: case CTL_KERN:
1018: switch (top[1]) {
1019: case KERN_MALLOCSTATS:
1020: SETNAME(kernmallocname);
1021: break;
1022: case KERN_FORKSTAT:
1023: SETNAME(forkstatname);
1024: break;
1025: case KERN_NCHSTATS:
1026: SETNAME(nchstatsname);
1027: break;
1028: case KERN_TTY:
1029: SETNAME(ttysname);
1030: break;
1031: case KERN_SEMINFO:
1032: SETNAME(semname);
1033: break;
1034: case KERN_SHMINFO:
1035: SETNAME(shmname);
1036: break;
1037: case KERN_WATCHDOG:
1038: SETNAME(watchdogname);
1039: break;
1.64 guenther 1040: case KERN_PROC:
1041: idx++; /* zero is valid at this level */
1042: SETNAME(kernprocname);
1043: break;
1.62 otto 1044: case KERN_TIMECOUNTER:
1045: SETNAME(tcname);
1046: break;
1047: }
1048: }
1049: break;
1050: }
1051: if (names != NULL && idx > 0 && idx < limit)
1052: return (names[idx].ctl_name);
1053: return (NULL);
1.1 deraadt 1054: }
1055:
1.12 espie 1056: static void
1.17 deraadt 1057: ktrsysret(struct ktr_sysret *ktr)
1.1 deraadt 1058: {
1.50 deraadt 1059: register_t ret = ktr->ktr_retval;
1.12 espie 1060: int error = ktr->ktr_error;
1061: int code = ktr->ktr_code;
1.1 deraadt 1062:
1063: if (code >= current->nsysnames || code < 0)
1064: (void)printf("[%d] ", code);
1.59 otto 1065: else {
1.1 deraadt 1066: (void)printf("%s ", current->sysnames[code]);
1.59 otto 1067: if (ret > 0 && (strcmp(current->sysnames[code], "fork") == 0 ||
1068: strcmp(current->sysnames[code], "vfork") == 0 ||
1.64 guenther 1069: strcmp(current->sysnames[code], "__tfork") == 0 ||
1.59 otto 1070: strcmp(current->sysnames[code], "clone") == 0))
1071: mappidtoemul(ret, current);
1072: }
1.1 deraadt 1073:
1074: if (error == 0) {
1075: if (fancy) {
1.64 guenther 1076: switch (current == &emulations[0] ? code : -1) {
1077: case SYS_sigprocmask:
1.73 guenther 1078: case SYS_sigpending:
1.64 guenther 1079: sigset(ret);
1080: break;
1081: case SYS___thrsigdivert:
1082: signame(ret);
1083: break;
1084: case -1: /* non-default emulation */
1085: default:
1086: (void)printf("%ld", (long)ret);
1087: if (ret < 0 || ret > 9)
1088: (void)printf("/%#lx", (long)ret);
1089: }
1.1 deraadt 1090: } else {
1091: if (decimal)
1.50 deraadt 1092: (void)printf("%ld", (long)ret);
1.1 deraadt 1093: else
1.50 deraadt 1094: (void)printf("%#lx", (long)ret);
1.1 deraadt 1095: }
1096: } else if (error == ERESTART)
1097: (void)printf("RESTART");
1098: else if (error == EJUSTRETURN)
1099: (void)printf("JUSTRETURN");
1100: else {
1101: (void)printf("-1 errno %d", ktr->ktr_error);
1102: if (fancy)
1103: (void)printf(" %s", strerror(ktr->ktr_error));
1104: }
1105: (void)putchar('\n');
1106: }
1107:
1.12 espie 1108: static void
1.37 tedu 1109: ktrnamei(const char *cp, size_t len)
1.1 deraadt 1110: {
1.37 tedu 1111: (void)printf("\"%.*s\"\n", (int)len, cp);
1.1 deraadt 1112: }
1113:
1.12 espie 1114: static void
1.37 tedu 1115: ktremul(char *cp, size_t len)
1.1 deraadt 1116: {
1117: char name[1024];
1118:
1119: if (len >= sizeof(name))
1120: errx(1, "Emulation name too long");
1121:
1122: strncpy(name, cp, len);
1123: name[len] = '\0';
1124: (void)printf("\"%s\"\n", name);
1125:
1126: setemul(name);
1127: }
1128:
1.12 espie 1129: static void
1.81 miod 1130: showbuf(unsigned char *dp, size_t datalen)
1.1 deraadt 1131: {
1.37 tedu 1132: int i, j;
1.81 miod 1133: static int screenwidth;
1.31 tedu 1134: int col = 0, width, bpl;
1.32 tedu 1135: unsigned char visbuf[5], *cp, c;
1.1 deraadt 1136:
1137: if (screenwidth == 0) {
1138: struct winsize ws;
1139:
1140: if (fancy && ioctl(fileno(stderr), TIOCGWINSZ, &ws) != -1 &&
1141: ws.ws_col > 8)
1142: screenwidth = ws.ws_col;
1143: else
1144: screenwidth = 80;
1145: }
1.31 tedu 1146: if (iohex == 1) {
1147: putchar('\t');
1148: col = 8;
1149: for (i = 0; i < datalen; i++) {
1.35 tedu 1150: printf("%02x", dp[i]);
1.31 tedu 1151: col += 3;
1152: if (i < datalen - 1) {
1153: if (col + 3 > screenwidth) {
1154: printf("\n\t");
1155: col = 8;
1156: } else
1157: putchar(' ');
1158: }
1159: }
1160: putchar('\n');
1161: return;
1162: }
1163: if (iohex == 2) {
1164: bpl = (screenwidth - 13)/4;
1165: if (bpl <= 0)
1166: bpl = 1;
1167: for (i = 0; i < datalen; i += bpl) {
1168: printf(" %04x: ", i);
1169: for (j = 0; j < bpl; j++) {
1170: if (i+j >= datalen)
1171: printf(" ");
1172: else
1.35 tedu 1173: printf("%02x ", dp[i+j]);
1.31 tedu 1174: }
1175: putchar(' ');
1176: for (j = 0; j < bpl; j++) {
1177: if (i+j >= datalen)
1178: break;
1179: c = dp[i+j];
1180: if (!isprint(c))
1181: c = '.';
1182: putchar(c);
1183: }
1184: putchar('\n');
1185: }
1186: return;
1187: }
1.1 deraadt 1188: (void)printf(" \"");
1189: col = 8;
1190: for (; datalen > 0; datalen--, dp++) {
1.31 tedu 1191: (void)vis(visbuf, *dp, VIS_CSTYLE, *(dp+1));
1.1 deraadt 1192: cp = visbuf;
1.17 deraadt 1193:
1.1 deraadt 1194: /*
1195: * Keep track of printables and
1196: * space chars (like fold(1)).
1197: */
1198: if (col == 0) {
1199: (void)putchar('\t');
1200: col = 8;
1201: }
1.17 deraadt 1202: switch (*cp) {
1.1 deraadt 1203: case '\n':
1204: col = 0;
1205: (void)putchar('\n');
1206: continue;
1207: case '\t':
1208: width = 8 - (col&07);
1209: break;
1210: default:
1211: width = strlen(cp);
1212: }
1213: if (col + width > (screenwidth-2)) {
1214: (void)printf("\\\n\t");
1215: col = 8;
1216: }
1217: col += width;
1218: do {
1219: (void)putchar(*cp++);
1220: } while (*cp);
1221: }
1222: if (col == 0)
1223: (void)printf(" ");
1224: (void)printf("\"\n");
1225: }
1226:
1.12 espie 1227: static void
1.81 miod 1228: ktrgenio(struct ktr_genio *ktr, size_t len)
1229: {
1230: unsigned char *dp = (unsigned char *)ktr + sizeof(struct ktr_genio);
1231: size_t datalen = len - sizeof(struct ktr_genio);
1232:
1233: printf("fd %d %s %zu bytes\n", ktr->ktr_fd,
1234: ktr->ktr_rw == UIO_READ ? "read" : "wrote", datalen);
1235: if (maxdata == 0)
1236: return;
1237: if (datalen > maxdata)
1238: datalen = maxdata;
1239: if (iohex && !datalen)
1240: return;
1241: showbuf(dp, datalen);
1242: }
1243:
1244: static void
1.17 deraadt 1245: ktrpsig(struct ktr_psig *psig)
1.1 deraadt 1246: {
1247: (void)printf("SIG%s ", sys_signame[psig->signo]);
1248: if (psig->action == SIG_DFL)
1.63 deraadt 1249: (void)printf("SIG_DFL");
1.64 guenther 1250: else {
1251: (void)printf("caught handler=0x%lx mask=",
1252: (u_long)psig->action);
1253: sigset(psig->mask);
1254: }
1.63 deraadt 1255: if (psig->code) {
1256: printf(" code ");
1257: if (fancy) {
1258: switch (psig->signo) {
1259: case SIGILL:
1260: sigill_name(psig->code);
1261: break;
1262: case SIGTRAP:
1263: sigtrap_name(psig->code);
1264: break;
1265: case SIGEMT:
1266: sigemt_name(psig->code);
1267: break;
1268: case SIGFPE:
1269: sigfpe_name(psig->code);
1270: break;
1271: case SIGBUS:
1272: sigbus_name(psig->code);
1273: break;
1274: case SIGSEGV:
1275: sigsegv_name(psig->code);
1276: break;
1277: case SIGCHLD:
1278: sigchld_name(psig->code);
1279: break;
1280: }
1281: }
1282: printf("<%d>", psig->code);
1283: }
1284:
1.14 deraadt 1285: switch (psig->signo) {
1286: case SIGSEGV:
1287: case SIGILL:
1288: case SIGBUS:
1289: case SIGFPE:
1290: printf(" addr=%p trapno=%d", psig->si.si_addr,
1291: psig->si.si_trapno);
1292: break;
1293: default:
1294: break;
1295: }
1296: printf("\n");
1.1 deraadt 1297: }
1298:
1.12 espie 1299: static void
1.17 deraadt 1300: ktrcsw(struct ktr_csw *cs)
1.1 deraadt 1301: {
1302: (void)printf("%s %s\n", cs->out ? "stop" : "resume",
1303: cs->user ? "user" : "kernel");
1304: }
1305:
1.64 guenther 1306: static void
1.81 miod 1307: ktruser(struct ktr_user *usr, size_t len)
1308: {
1309: len -= sizeof(struct ktr_user);
1310: printf("%.*s:", KTR_USER_MAXIDLEN, usr->ktr_id);
1311: printf(" %zu bytes\n", len);
1312: showbuf((unsigned char *)(usr + 1), len);
1313: }
1314:
1315: static void
1.17 deraadt 1316: usage(void)
1.1 deraadt 1317: {
1318:
1.19 mickey 1319: extern char *__progname;
1320: fprintf(stderr, "usage: %s "
1.68 jmc 1321: "[-dHlnRrTXx] [-e emulation] [-f file] [-m maxdata] [-p pid]\n"
1.81 miod 1322: "%*s[-t [ceinstuw]]\n",
1.51 otto 1323: __progname, (int)(sizeof("usage: ") + strlen(__progname)), "");
1.1 deraadt 1324: exit(1);
1325: }
1326:
1.12 espie 1327: static void
1.17 deraadt 1328: setemul(const char *name)
1.1 deraadt 1329: {
1330: int i;
1.17 deraadt 1331:
1.1 deraadt 1332: for (i = 0; emulations[i].name != NULL; i++)
1333: if (strcmp(emulations[i].name, name) == 0) {
1334: current = &emulations[i];
1335: return;
1336: }
1337: warnx("Emulation `%s' unknown", name);
1.61 matthew 1338: }
1339:
1340: static void
1341: atfd(int fd)
1342: {
1343: if (fd == AT_FDCWD)
1344: (void)printf("AT_FDCWD");
1345: else if (decimal)
1346: (void)printf("%d", fd);
1347: else
1348: (void)printf("%#x", fd);
1.77 guenther 1349: }
1350:
1351: static void
1352: polltimeout(int timeout)
1353: {
1354: if (timeout == INFTIM)
1355: (void)printf("INFTIM");
1356: else if (decimal)
1357: (void)printf("%d", timeout);
1358: else
1359: (void)printf("%#x", timeout);
1.82 guenther 1360: }
1361:
1362: static void
1363: pgid(int pid)
1364: {
1365: (void)printf("%d", pid);
1366: }
1367:
1368: static void
1369: wait4pid(int pid)
1370: {
1371: if (pid == WAIT_ANY)
1372: (void)printf("WAIT_ANY");
1373: else if (pid == WAIT_MYPGRP)
1374: (void)printf("WAIT_MYPGRP");
1375: else
1376: pgid(pid);
1.1 deraadt 1377: }
1.83 guenther 1378:
1379: static void
1380: signame(int sig)
1381: {
1382: if (sig > 0 && sig < NSIG)
1383: (void)printf("SIG%s", sys_signame[sig]);
1384: else
1385: (void)printf("SIG %d", sig);
1386: }
1387:
1.84 guenther 1388: void
1.83 guenther 1389: sigset(int ss)
1390: {
1391: int or = 0;
1392: int cnt = 0;
1393: int i;
1394:
1395: for (i = 1; i < NSIG; i++)
1396: if (sigismember(&ss, i))
1397: cnt++;
1398: if (cnt > (NSIG-1)/2) {
1399: ss = ~ss;
1400: putchar('~');
1401: }
1402:
1403: if (ss == 0) {
1404: (void)printf("0<>");
1405: return;
1406: }
1407:
1408: printf("%#x<", ss);
1409: for (i = 1; i < NSIG; i++)
1410: if (sigismember(&ss, i)) {
1411: if (or) putchar('|'); else or=1;
1412: signame(i);
1413: }
1414: printf(">");
1415: }
1416:
1417: static void
1418: semctlname(int cmd)
1419: {
1420: switch (cmd) {
1421: case GETNCNT:
1422: (void)printf("GETNCNT");
1423: break;
1424: case GETPID:
1425: (void)printf("GETPID");
1426: break;
1427: case GETVAL:
1428: (void)printf("GETVAL");
1429: break;
1430: case GETALL:
1431: (void)printf("GETALL");
1432: break;
1433: case GETZCNT:
1434: (void)printf("GETZCNT");
1435: break;
1436: case SETVAL:
1437: (void)printf("SETVAL");
1438: break;
1439: case SETALL:
1440: (void)printf("SETALL");
1441: break;
1442: case IPC_RMID:
1443: (void)printf("IPC_RMID");
1444: break;
1445: case IPC_SET:
1446: (void)printf("IPC_SET");
1447: break;
1448: case IPC_STAT:
1449: (void)printf("IPC_STAT");
1450: break;
1451: default: /* Should not reach */
1452: (void)printf("<invalid=%ld>", (long)cmd);
1453: }
1454: }
1455:
1456: static void
1.88 guenther 1457: shmctlname(int cmd)
1458: {
1.83 guenther 1459: switch (cmd) {
1460: case IPC_RMID:
1461: (void)printf("IPC_RMID");
1462: break;
1463: case IPC_SET:
1464: (void)printf("IPC_SET");
1465: break;
1466: case IPC_STAT:
1467: (void)printf("IPC_STAT");
1468: break;
1469: default: /* Should not reach */
1470: (void)printf("<invalid=%ld>", (long)cmd);
1471: }
1472: }
1473:
1474:
1475: static void
1.88 guenther 1476: semgetname(int flag)
1477: {
1.83 guenther 1478: int or = 0;
1479: if_print_or(flag, IPC_CREAT, or);
1480: if_print_or(flag, IPC_EXCL, or);
1481: if_print_or(flag, SEM_R, or);
1482: if_print_or(flag, SEM_A, or);
1483: if_print_or(flag, (SEM_R>>3), or);
1484: if_print_or(flag, (SEM_A>>3), or);
1485: if_print_or(flag, (SEM_R>>6), or);
1486: if_print_or(flag, (SEM_A>>6), or);
1487: }
1488:
1489:
1490: /*
1491: * Only used by SYS_open. Unless O_CREAT is set in flags, the
1492: * mode argument is unused (and often bogus and misleading).
1493: */
1494: static void
1.88 guenther 1495: flagsandmodename(int flags, int mode)
1496: {
1.89 guenther 1497: doflagsname(flags, 1);
1.83 guenther 1498: if ((flags & O_CREAT) == O_CREAT) {
1499: (void)putchar(',');
1500: modename (mode);
1501: } else if (!fancy) {
1502: (void)putchar(',');
1503: if (decimal) {
1504: (void)printf("<unused>%ld", (long)mode);
1505: } else {
1506: (void)printf("<unused>%#lx", (long)mode);
1507: }
1508: }
1509: }
1510:
1511: static void
1512: clockname(int clockid)
1513: {
1514: clocktypename(__CLOCK_TYPE(clockid));
1515: if (__CLOCK_PTID(clockid) != 0)
1516: printf("(%d)", __CLOCK_PTID(clockid));
1517: }
1518:
1519: /*
1520: * [g|s]etsockopt's level argument can either be SOL_SOCKET or a value
1521: * referring to a line in /etc/protocols . It might be appropriate
1522: * to use getprotoent(3) here.
1523: */
1524: static void
1525: sockoptlevelname(int level)
1526: {
1527: if (level == SOL_SOCKET) {
1528: (void)printf("SOL_SOCKET");
1529: } else {
1530: if (decimal) {
1531: (void)printf("%ld", (long)level);
1532: } else {
1533: (void)printf("%#lx", (long)level);
1534: }
1535: }
1536: }
1537:
1.88 guenther 1538: static void
1539: ktraceopname(int ops)
1540: {
1541: int invalid = 0;
1542:
1543: printf("%#x<", ops);
1544: switch (KTROP(ops)) {
1545: case KTROP_SET:
1546: printf("KTROP_SET");
1547: break;
1548: case KTROP_CLEAR:
1549: printf("KTROP_CLEAR");
1550: break;
1551: case KTROP_CLEARFILE:
1552: printf("KTROP_CLEARFILE");
1553: break;
1554: default:
1555: printf("KTROP(%d)", KTROP(ops));
1556: invalid = 1;
1557: break;
1558: }
1559: if (ops & KTRFLAG_DESCEND) printf ("|%s", "KTRFLAG_DESCEND");
1560: printf(">");
1561: if (invalid || (ops & ~(KTROP((unsigned)-1) | KTRFLAG_DESCEND)))
1562: (void)printf("<invalid>%ld", (long)ops);
1563: }