xref: /illumos-gate/usr/src/cmd/mdb/common/modules/libuutil/libuutil.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*8918dff3Sjwadams  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <pthread.h>
307c478bd9Sstevel@tonic-gate #include <stddef.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <libuutil.h>
337c478bd9Sstevel@tonic-gate #include <libuutil_impl.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*ARGSUSED*/
367c478bd9Sstevel@tonic-gate static int
uutil_status(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)377c478bd9Sstevel@tonic-gate uutil_status(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
387c478bd9Sstevel@tonic-gate {
397c478bd9Sstevel@tonic-gate 	pthread_t uu_panic_thread = 0;
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) || argc != 0)
427c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&uu_panic_thread, "uu_panic_thread") == -1) {
457c478bd9Sstevel@tonic-gate 		mdb_warn("unable to read uu_panic_thread");
467c478bd9Sstevel@tonic-gate 	}
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate 	if (uu_panic_thread != 0) {
497c478bd9Sstevel@tonic-gate 		mdb_printf("thread %d uu_panicked\n", uu_panic_thread);
507c478bd9Sstevel@tonic-gate 	}
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
537c478bd9Sstevel@tonic-gate }
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*ARGSUSED*/
567c478bd9Sstevel@tonic-gate static int
uutil_listpool(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)577c478bd9Sstevel@tonic-gate uutil_listpool(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
587c478bd9Sstevel@tonic-gate {
597c478bd9Sstevel@tonic-gate 	uu_list_pool_t ulp;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
627c478bd9Sstevel@tonic-gate 		if (mdb_walk_dcmd("uu_list_pool", "uu_list_pool", argc,
637c478bd9Sstevel@tonic-gate 		    argv) == -1) {
647c478bd9Sstevel@tonic-gate 			mdb_warn("can't walk uu_list_pool");
657c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
667c478bd9Sstevel@tonic-gate 		}
677c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
687c478bd9Sstevel@tonic-gate 	}
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	if (argc != 0)
717c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
747c478bd9Sstevel@tonic-gate 		mdb_printf("%-?s %-30s %?s %5s\n",
757c478bd9Sstevel@tonic-gate 		    "ADDR", "NAME", "COMPARE", "FLAGS");
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	if (mdb_vread(&ulp, sizeof (uu_list_pool_t), addr) == -1) {
787c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read uu_list_pool\n");
797c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
807c478bd9Sstevel@tonic-gate 	}
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	mdb_printf("%0?p %-30s %08x     %c\n", addr, ulp.ulp_name, ulp.ulp_cmp,
837c478bd9Sstevel@tonic-gate 	    ulp.ulp_debug ? 'D' : ' ');
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*ARGSUSED*/
897c478bd9Sstevel@tonic-gate static int
uutil_list(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)907c478bd9Sstevel@tonic-gate uutil_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
917c478bd9Sstevel@tonic-gate {
927c478bd9Sstevel@tonic-gate 	uu_list_t ul;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC) || argc != 0)
957c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	if (mdb_vread(&ul, sizeof (uu_list_t), addr) == -1) {
987c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read uu_list\n");
997c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1007c478bd9Sstevel@tonic-gate 	}
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
1037c478bd9Sstevel@tonic-gate 		mdb_printf("%-?s %-?s %-?s %6s %5s\n",
1047c478bd9Sstevel@tonic-gate 		    "ADDR", "POOL", "PARENT", "NODES", "FLAGS");
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	mdb_printf("%0?p %0?p %0?p %6u    %c%c\n",
107*8918dff3Sjwadams 	    addr, ul.ul_pool, UU_PTR_DECODE(ul.ul_parent_enc),
108*8918dff3Sjwadams 	    ul.ul_numnodes, ul.ul_sorted ? 'S' : ' ', ul.ul_debug? 'D' : ' ');
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate typedef struct uutil_listpool_walk {
1147c478bd9Sstevel@tonic-gate 	uintptr_t ulpw_final;
1157c478bd9Sstevel@tonic-gate 	uintptr_t ulpw_current;
1167c478bd9Sstevel@tonic-gate } uutil_listpool_walk_t;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate int
uutil_listpool_walk_init(mdb_walk_state_t * wsp)1197c478bd9Sstevel@tonic-gate uutil_listpool_walk_init(mdb_walk_state_t *wsp)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate 	uu_list_pool_t null_lpool;
1227c478bd9Sstevel@tonic-gate 	uutil_listpool_walk_t *ulpw;
1237c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	bzero(&null_lpool, sizeof (uu_list_pool_t));
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_obj("libuutil.so.1", "uu_null_lpool", &sym) ==
1287c478bd9Sstevel@tonic-gate 	    -1) {
1297c478bd9Sstevel@tonic-gate 		mdb_warn("failed to find 'uu_null_lpool'\n");
1307c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
1317c478bd9Sstevel@tonic-gate 	}
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	if (mdb_vread(&null_lpool, sym.st_size, (uintptr_t)sym.st_value) ==
1347c478bd9Sstevel@tonic-gate 	    -1) {
1357c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read data from 'uu_null_lpool' address\n");
1367c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
1377c478bd9Sstevel@tonic-gate 	}
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	ulpw = mdb_alloc(sizeof (uutil_listpool_walk_t), UM_SLEEP);
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 	ulpw->ulpw_final = (uintptr_t)null_lpool.ulp_prev;
1427c478bd9Sstevel@tonic-gate 	ulpw->ulpw_current = (uintptr_t)null_lpool.ulp_next;
1437c478bd9Sstevel@tonic-gate 	wsp->walk_data = ulpw;
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate int
uutil_listpool_walk_step(mdb_walk_state_t * wsp)1497c478bd9Sstevel@tonic-gate uutil_listpool_walk_step(mdb_walk_state_t *wsp)
1507c478bd9Sstevel@tonic-gate {
1517c478bd9Sstevel@tonic-gate 	uu_list_pool_t ulp;
1527c478bd9Sstevel@tonic-gate 	uutil_listpool_walk_t *ulpw = wsp->walk_data;
1537c478bd9Sstevel@tonic-gate 	int status;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	if (mdb_vread(&ulp, sizeof (uu_list_pool_t),
1567c478bd9Sstevel@tonic-gate 	    ulpw->ulpw_current) == -1) {
1577c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read uu_list_pool %x", ulpw->ulpw_current);
1587c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
1597c478bd9Sstevel@tonic-gate 	}
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback(ulpw->ulpw_current, &ulp, wsp->walk_cbdata);
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	if (ulpw->ulpw_current == ulpw->ulpw_final)
1647c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	ulpw->ulpw_current = (uintptr_t)ulp.ulp_next;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	return (status);
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate void
uutil_listpool_walk_fini(mdb_walk_state_t * wsp)1727c478bd9Sstevel@tonic-gate uutil_listpool_walk_fini(mdb_walk_state_t *wsp)
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate 	uutil_listpool_walk_t *ulpw = wsp->walk_data;
1757c478bd9Sstevel@tonic-gate 	mdb_free(ulpw, sizeof (uutil_listpool_walk_t));
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate typedef struct uutil_list_walk {
1797c478bd9Sstevel@tonic-gate 	uintptr_t ulw_final;
1807c478bd9Sstevel@tonic-gate 	uintptr_t ulw_current;
1817c478bd9Sstevel@tonic-gate } uutil_list_walk_t;
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate int
uutil_list_walk_init(mdb_walk_state_t * wsp)1847c478bd9Sstevel@tonic-gate uutil_list_walk_init(mdb_walk_state_t *wsp)
1857c478bd9Sstevel@tonic-gate {
1867c478bd9Sstevel@tonic-gate 	uutil_list_walk_t *ulw;
1877c478bd9Sstevel@tonic-gate 	uu_list_pool_t ulp;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	if (mdb_vread(&ulp, sizeof (uu_list_pool_t), wsp->walk_addr) == -1) {
1907c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read uu_list_pool_t at given address\n");
1917c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
1927c478bd9Sstevel@tonic-gate 	}
1937c478bd9Sstevel@tonic-gate 
194*8918dff3Sjwadams 	if (UU_LIST_PTR(ulp.ulp_null_list.ul_next_enc) ==
195*8918dff3Sjwadams 	    &((uu_list_pool_t *)wsp->walk_addr)->ulp_null_list)
196*8918dff3Sjwadams 		return (WALK_DONE);
197*8918dff3Sjwadams 
1987c478bd9Sstevel@tonic-gate 	ulw = mdb_alloc(sizeof (uutil_list_walk_t), UM_SLEEP);
1997c478bd9Sstevel@tonic-gate 
200*8918dff3Sjwadams 	ulw->ulw_final = (uintptr_t)UU_LIST_PTR(ulp.ulp_null_list.ul_prev_enc);
201*8918dff3Sjwadams 	ulw->ulw_current =
202*8918dff3Sjwadams 	    (uintptr_t)UU_LIST_PTR(ulp.ulp_null_list.ul_next_enc);
2037c478bd9Sstevel@tonic-gate 	wsp->walk_data = ulw;
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate int
uutil_list_walk_step(mdb_walk_state_t * wsp)2097c478bd9Sstevel@tonic-gate uutil_list_walk_step(mdb_walk_state_t *wsp)
2107c478bd9Sstevel@tonic-gate {
2117c478bd9Sstevel@tonic-gate 	uu_list_t ul;
2127c478bd9Sstevel@tonic-gate 	uutil_list_walk_t *ulw = wsp->walk_data;
2137c478bd9Sstevel@tonic-gate 	int status;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	if (mdb_vread(&ul, sizeof (uu_list_t), ulw->ulw_current) == -1) {
2167c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read uu_list %x", ulw->ulw_current);
2177c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
2187c478bd9Sstevel@tonic-gate 	}
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback(ulw->ulw_current, &ul, wsp->walk_cbdata);
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	if (ulw->ulw_current == ulw->ulw_final)
2237c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
2247c478bd9Sstevel@tonic-gate 
225*8918dff3Sjwadams 	ulw->ulw_current = (uintptr_t)UU_LIST_PTR(ul.ul_next_enc);
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	return (status);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate void
uutil_list_walk_fini(mdb_walk_state_t * wsp)2317c478bd9Sstevel@tonic-gate uutil_list_walk_fini(mdb_walk_state_t *wsp)
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate 	uutil_list_walk_t *ulw = wsp->walk_data;
2347c478bd9Sstevel@tonic-gate 	mdb_free(ulw, sizeof (uutil_list_walk_t));
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate typedef struct uutil_list_node_walk {
2387c478bd9Sstevel@tonic-gate 	size_t ulnw_offset;
2397c478bd9Sstevel@tonic-gate 	uintptr_t ulnw_final;
2407c478bd9Sstevel@tonic-gate 	uintptr_t ulnw_current;
2417c478bd9Sstevel@tonic-gate 	void *ulnw_buf;
2427c478bd9Sstevel@tonic-gate 	size_t ulnw_bufsz;
2437c478bd9Sstevel@tonic-gate } uutil_list_node_walk_t;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate int
uutil_list_node_walk_init(mdb_walk_state_t * wsp)2467c478bd9Sstevel@tonic-gate uutil_list_node_walk_init(mdb_walk_state_t *wsp)
2477c478bd9Sstevel@tonic-gate {
2487c478bd9Sstevel@tonic-gate 	uutil_list_node_walk_t *ulnw;
2497c478bd9Sstevel@tonic-gate 	uu_list_t ul;
2507c478bd9Sstevel@tonic-gate 	uu_list_pool_t ulp;
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	if (mdb_vread(&ul, sizeof (uu_list_t), wsp->walk_addr) == -1) {
2537c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read uu_list_t at given address\n");
2547c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
2557c478bd9Sstevel@tonic-gate 	}
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	if (mdb_vread(&ulp, sizeof (uu_list_pool_t), (uintptr_t)ul.ul_pool) ==
2587c478bd9Sstevel@tonic-gate 	    -1) {
2597c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read supporting uu_list_pool_t\n");
2607c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
2617c478bd9Sstevel@tonic-gate 	}
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	ulnw = mdb_alloc(sizeof (uutil_list_node_walk_t), UM_SLEEP);
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 	ulnw->ulnw_offset = ul.ul_offset;
2667c478bd9Sstevel@tonic-gate 	ulnw->ulnw_final = wsp->walk_addr + offsetof(uu_list_t, ul_null_node);
2677c478bd9Sstevel@tonic-gate 	ulnw->ulnw_current = (uintptr_t)ul.ul_null_node.uln_next;
2687c478bd9Sstevel@tonic-gate 	ulnw->ulnw_buf = mdb_alloc(ulp.ulp_objsize, UM_SLEEP);
2697c478bd9Sstevel@tonic-gate 	ulnw->ulnw_bufsz = ulp.ulp_objsize;
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 	wsp->walk_data = ulnw;
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate int
uutil_list_node_walk_step(mdb_walk_state_t * wsp)2777c478bd9Sstevel@tonic-gate uutil_list_node_walk_step(mdb_walk_state_t *wsp)
2787c478bd9Sstevel@tonic-gate {
2797c478bd9Sstevel@tonic-gate 	uu_list_node_impl_t uln;
2807c478bd9Sstevel@tonic-gate 	uutil_list_node_walk_t *ulnw = wsp->walk_data;
2817c478bd9Sstevel@tonic-gate 	int status;
2827c478bd9Sstevel@tonic-gate 	uintptr_t diff;
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	if (ulnw->ulnw_current == ulnw->ulnw_final)
2857c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	if (mdb_vread(&uln, sizeof (uu_list_node_impl_t), ulnw->ulnw_current) ==
2887c478bd9Sstevel@tonic-gate 	    -1) {
2897c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read uu_list_node %x", ulnw->ulnw_current);
2907c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
2917c478bd9Sstevel@tonic-gate 	}
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 	diff = ulnw->ulnw_current - ulnw->ulnw_offset;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	if (mdb_vread(ulnw->ulnw_buf, ulnw->ulnw_bufsz, diff) == -1) {
2967c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read enclosing structure %x", diff);
2977c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
2987c478bd9Sstevel@tonic-gate 	}
2997c478bd9Sstevel@tonic-gate 	/*
3007c478bd9Sstevel@tonic-gate 	 * Correct for offset; we return the address of the included structure.
3017c478bd9Sstevel@tonic-gate 	 */
3027c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback(diff, ulnw->ulnw_buf, wsp->walk_cbdata);
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	ulnw->ulnw_current = (uintptr_t)uln.uln_next;
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	return (status);
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate void
uutil_list_node_walk_fini(mdb_walk_state_t * wsp)3107c478bd9Sstevel@tonic-gate uutil_list_node_walk_fini(mdb_walk_state_t *wsp)
3117c478bd9Sstevel@tonic-gate {
3127c478bd9Sstevel@tonic-gate 	uutil_list_node_walk_t *ulnw = wsp->walk_data;
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	mdb_free(ulnw->ulnw_buf, ulnw->ulnw_bufsz);
3157c478bd9Sstevel@tonic-gate 	mdb_free(ulnw, sizeof (uutil_list_node_walk_t));
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
3197c478bd9Sstevel@tonic-gate 	{ "uutil_status", NULL, "libuutil status summary", uutil_status },
3207c478bd9Sstevel@tonic-gate 	{ "uu_list_pool", NULL, "display uu_list_pool information",
3217c478bd9Sstevel@tonic-gate 		uutil_listpool },
3227c478bd9Sstevel@tonic-gate 	{ "uu_list", NULL, "display uu_list information",
3237c478bd9Sstevel@tonic-gate 		uutil_list },
3247c478bd9Sstevel@tonic-gate 	{ NULL }
3257c478bd9Sstevel@tonic-gate };
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
3287c478bd9Sstevel@tonic-gate 	{ "uu_list_pool", "walk uu_list_pools",
3297c478bd9Sstevel@tonic-gate 		uutil_listpool_walk_init, uutil_listpool_walk_step,
3307c478bd9Sstevel@tonic-gate 		uutil_listpool_walk_fini },
3317c478bd9Sstevel@tonic-gate 	{ "uu_list", "given a uu_list_pool, walk its uu_lists",
3327c478bd9Sstevel@tonic-gate 		uutil_list_walk_init, uutil_list_walk_step,
3337c478bd9Sstevel@tonic-gate 		uutil_list_walk_fini },
3347c478bd9Sstevel@tonic-gate 	{ "uu_list_node",
3357c478bd9Sstevel@tonic-gate 		"given a uu_list, walk its nodes, returning container addr",
3367c478bd9Sstevel@tonic-gate 		uutil_list_node_walk_init, uutil_list_node_walk_step,
3377c478bd9Sstevel@tonic-gate 		uutil_list_node_walk_fini },
3387c478bd9Sstevel@tonic-gate 	{ NULL }
3397c478bd9Sstevel@tonic-gate };
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = {
3427c478bd9Sstevel@tonic-gate 	MDB_API_VERSION, dcmds, walkers
3437c478bd9Sstevel@tonic-gate };
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)3467c478bd9Sstevel@tonic-gate _mdb_init(void)
3477c478bd9Sstevel@tonic-gate {
3487c478bd9Sstevel@tonic-gate 	return (&modinfo);
3497c478bd9Sstevel@tonic-gate }
350