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