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.
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.
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]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/types.h>
27 #include <sys/rwlock.h>
28 #include <mdb/mdb_modapi.h>
29 #include <sys/queue.h>
32 #include <sys/hook_impl.h>
37 * List pfhooks hook list information.
41 hooklist(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
45 char hrstr
[MAX_LENGTH
];
47 char buf
[MDB_SYM_NAMLEN
+ 1];
54 if (mdb_vread((void *)&hr
, sizeof (hr
), (uintptr_t)addr
) == -1) {
55 mdb_warn("couldn't read hook register at %p", addr
);
59 mdb_printf("%<u>%?s %8s %20s %4s %24s %24s%</u>\n",
60 "ADDR", "FLAG", "FUNC", "HINT", "NAME", "HINTVALUE");
62 hlp
= TAILQ_FIRST(&hr
.hei_head
);
64 if (mdb_vread((void *)&hl
, sizeof (hl
),
65 (uintptr_t)hlp
) == -1) {
66 mdb_warn("couldn't read hook list at %p",
71 mdb_warn("hook list at %p has null role", h
);
74 if (mdb_readstr((char *)hrstr
, sizeof (hrstr
),
75 (uintptr_t)h
->h_name
) == -1) {
76 mdb_warn("couldn't read list role at %p", h
->h_name
);
82 hintname
= h
->h_hintvalue
?
83 (char *)h
->h_hintvalue
: "";
89 if (mdb_lookup_by_addr((uintptr_t)h
->h_func
,
90 MDB_SYM_EXACT
, buf
, sizeof (buf
), &sym
) == -1)
91 mdb_printf("%0?p %8x %0?p %4d %24s %24s\n",
92 hlp
, h
->h_flags
, h
->h_func
,
93 h
->h_hint
, hrstr
, hintname
);
95 mdb_printf("%0?p %8x %20s %4d %24s %24s\n",
97 h
->h_hint
, hrstr
, hintname
);
98 hlp
= TAILQ_NEXT(&hl
, hi_entry
);
104 * List pfhooks event information.
105 * List the hooks information in verbose mode as well.
109 hookeventlist(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
111 hook_family_int_t hf
;
112 hook_event_int_t hr
, *hrp
;
114 char hprstr
[MAX_LENGTH
];
119 if (mdb_vread((void *)&hf
, sizeof (hf
), (uintptr_t)addr
) == -1) {
120 mdb_warn("couldn't read hook family at %p", addr
);
124 mdb_printf("%<u>%?s %10s %20s%</u>\n", "ADDR", "FLAG", "NAME");
125 hrp
= SLIST_FIRST(&hf
.hfi_head
);
127 if (mdb_vread((void *)&hr
, sizeof (hr
), (uintptr_t)hrp
) == -1) {
128 mdb_warn("couldn't read hook register at %p", hrp
);
132 mdb_warn("hook register at %p has no hook provider",
136 if (mdb_vread((void *)&hp
, sizeof (hp
),
137 (uintptr_t)hr
.hei_event
) == -1) {
138 mdb_warn("hook provider at %p has null role",
143 mdb_warn("hook provider at %p has null role",
147 if (mdb_readstr((char *)hprstr
, sizeof (hprstr
),
148 (uintptr_t)hp
.he_name
) == -1) {
149 mdb_warn("couldn't read provider role at %p",
153 mdb_printf("%0?p %10x %20s\n", hrp
, hp
.he_flags
, hprstr
);
154 hrp
= SLIST_NEXT(&hr
, hei_entry
);
161 * List pfhooks family information.
165 hookrootlist(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
167 struct hook_stack
*hks
;
168 hook_family_int_head_t hfh
;
169 hook_family_int_t hf
, *hfp
;
170 char hrrstr
[MAX_LENGTH
];
175 if (mdb_vread((void *)&hks
, sizeof (hks
),
176 (uintptr_t)(addr
+ OFFSETOF(netstack_t
, netstack_hook
))) == -1) {
177 mdb_warn("couldn't read netstack_hook");
181 if (mdb_vread((void *)&hfh
, sizeof (hfh
), (uintptr_t)((uintptr_t)hks
+
182 OFFSETOF(hook_stack_t
, hks_familylist
))) == -1) {
183 mdb_warn("couldn't read hook family head");
187 mdb_printf("%<u>%?s %10s%</u>\n", "ADDR", "FAMILY");
188 hfp
= SLIST_FIRST(&hfh
);
190 if (mdb_vread((void *)&hf
, sizeof (hf
), (uintptr_t)hfp
) == -1) {
191 mdb_warn("couldn't read hook family at %p", hfp
);
194 if (!hf
.hfi_family
.hf_name
) {
195 mdb_warn("hook root at %p has null role",
199 if (mdb_readstr((char *)hrrstr
, sizeof (hrrstr
),
200 (uintptr_t)hf
.hfi_family
.hf_name
) == -1) {
201 mdb_warn("couldn't read root role at %p",
202 hf
.hfi_family
.hf_name
);
205 mdb_printf("%0?p %10s\n", hfp
, hrrstr
);
206 hfp
= SLIST_NEXT(&hf
, hfi_entry
);
214 hookevent_stack_walk_init(mdb_walk_state_t
*wsp
)
216 hook_family_int_t hf
;
218 if (wsp
->walk_addr
== (uintptr_t)NULL
) {
219 mdb_warn("global walk not supported\n");
223 if (mdb_vread((void *)&hf
, sizeof (hf
),
224 (uintptr_t)wsp
->walk_addr
) == -1) {
225 mdb_warn("couldn't read hook family at %p", wsp
->walk_addr
);
228 wsp
->walk_addr
= (uintptr_t)SLIST_FIRST(&hf
.hfi_head
);
229 return (wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
234 hookevent_stack_walk_step(mdb_walk_state_t
*wsp
)
238 if (mdb_vread((void *)&hr
, sizeof (hr
),
239 (uintptr_t)wsp
->walk_addr
) == -1) {
240 mdb_warn("couldn't read hook event at %p", wsp
->walk_addr
);
243 wsp
->walk_addr
= (uintptr_t)SLIST_NEXT(&hr
, hei_entry
);
244 if (wsp
->walk_addr
== (uintptr_t)NULL
)
246 return (wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
250 static const mdb_dcmd_t dcmds
[] = {
251 { "hookrootlist", "", "display hook family information", hookrootlist
},
252 { "hookeventlist", "", "display hook event information",
253 hookeventlist
, NULL
},
254 { "hooklist", "", "display hooks", hooklist
},
258 static const mdb_walker_t walkers
[] = {
259 { "hookevent_stack", "walk list of hooks",
260 hookevent_stack_walk_init
, hookevent_stack_walk_step
, NULL
},
264 static const mdb_modinfo_t modinfo
= { MDB_API_VERSION
, dcmds
, walkers
};
266 const mdb_modinfo_t
*