1 /* $NetBSD: misc.c,v 1.6 2009/07/13 21:43:24 christos Exp $ */
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: misc.c,v 1.6 2009/07/13 21:43:24 christos Exp $");
37 #include <sys/param.h>
38 #include <sys/types.h>
41 #include <sys/condvar.h>
42 #include <sys/selinfo.h>
43 #include <sys/filedesc.h>
45 #include <sys/mqueue.h>
46 #include <sys/eventvar.h>
52 #include <sys/vnode.h>
53 #include <sys/mount.h>
55 #include <net/bpfdesc.h>
61 static struct nlist nl
[] = {
63 { .n_name
= "kqueueops" },
65 { .n_name
= "mqops" },
67 { .n_name
= "pipeops" },
69 { .n_name
= "socketops" },
71 { .n_name
= "vnops" },
73 { .n_name
= "cryptofops" },
75 { .n_name
= "bpf_fileops", },
77 { .n_name
= "tap_fileops", },
90 if (!KVM_READ(f
->f_data
, &bpf
, sizeof (bpf
))) {
91 dprintf("can't read bpf at %p for pid %d", f
->f_data
, Pid
);
94 (void)printf("* bpf rec=%lu, dr=%lu, cap=%lu, pid=%lu",
95 bpf
.bd_rcount
, bpf
.bd_dcount
, bpf
.bd_ccount
,
96 (unsigned long)bpf
.bd_pid
);
98 (void)printf(", promisc");
100 (void)printf(", immed");
102 (void)printf(", seesent");
104 (void)printf(", asyncgrp=%lu", (unsigned long)bpf
.bd_pgid
);
105 if (bpf
.bd_state
== BPF_IDLE
)
106 (void)printf(", idle");
107 else if (bpf
.bd_state
== BPF_WAITING
)
108 (void)printf(", waiting");
109 else if (bpf
.bd_state
== BPF_TIMED_OUT
)
110 (void)printf(", timeout");
116 p_mqueue(struct file
*f
)
120 if (!KVM_READ(f
->f_data
, &mq
, sizeof (mq
))) {
121 dprintf("can't read mqueue at %p for pid %d", f
->f_data
, Pid
);
124 (void)printf("* mqueue \"%s\"\n", mq
.mq_name
);
129 p_kqueue(struct file
*f
)
133 if (!KVM_READ(f
->f_data
, &kq
, sizeof (kq
))) {
134 dprintf("can't read kqueue at %p for pid %d", f
->f_data
, Pid
);
137 (void)printf("* kqueue pending %d\n", kq
.kq_count
);
142 pmisc(struct file
*f
, const char *name
)
145 if (nl
[0].n_value
== 0) {
147 if ((n
= KVM_NLIST(nl
)) == -1)
148 errx(1, "Cannot list kernel symbols (%s)",
150 else if (n
!= 0 && vflg
)
151 warnx("Could not find %d symbols", n
);
153 for (i
= 0; i
< NL_MAX
; i
++)
154 if ((uintptr_t)f
->f_ops
== nl
[i
].n_value
)
164 printf("* tap %lu\n", (unsigned long)(intptr_t)f
->f_data
);
167 printf("* crypto %p\n", f
->f_data
);
170 printf("* %s %p\n", name
, f
->f_data
);