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 /*
237c478bd9Sstevel@tonic-gate  * Copyright 2002 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 "sysevent.h"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate int
sysevent_buf(uintptr_t addr,uint_t flags,uint_t opt_flags)307c478bd9Sstevel@tonic-gate sysevent_buf(uintptr_t addr, uint_t flags, uint_t opt_flags)
317c478bd9Sstevel@tonic-gate {
327c478bd9Sstevel@tonic-gate 	sysevent_hdr_t evh;
337c478bd9Sstevel@tonic-gate 	sysevent_impl_t *ev;
347c478bd9Sstevel@tonic-gate 	int size;
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
377c478bd9Sstevel@tonic-gate 		if ((opt_flags & SYSEVENT_VERBOSE) == 0) {
387c478bd9Sstevel@tonic-gate 			mdb_printf("%<u>%-?s %-16s %-9s %-10s "
397c478bd9Sstevel@tonic-gate 			    "%-?s%</u>\n", "ADDRESS", "SEQUENCE ID",
407c478bd9Sstevel@tonic-gate 			    "CLASS", "SUBCLASS", "NVPAIR BUF ADDR");
417c478bd9Sstevel@tonic-gate 		}
427c478bd9Sstevel@tonic-gate 	}
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate 	/*
457c478bd9Sstevel@tonic-gate 	 * Read in the sysevent buffer header first.  After extracting
467c478bd9Sstevel@tonic-gate 	 * the size of the buffer, re-read the buffer in its entirety.
477c478bd9Sstevel@tonic-gate 	 */
487c478bd9Sstevel@tonic-gate 	if (mdb_vread(&evh, sizeof (sysevent_hdr_t), addr) == -1) {
497c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read event header at %p", addr);
507c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
517c478bd9Sstevel@tonic-gate 	}
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	size = SE_SIZE((sysevent_impl_t *)&evh);
547c478bd9Sstevel@tonic-gate 	ev = mdb_alloc(size, UM_SLEEP | UM_GC);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 	if (mdb_vread(ev, size, addr) == -1) {
577c478bd9Sstevel@tonic-gate 		mdb_warn("can not read sysevent at %p", addr);
587c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
597c478bd9Sstevel@tonic-gate 	}
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 	if ((opt_flags & SYSEVENT_VERBOSE) == 0) {
627c478bd9Sstevel@tonic-gate 		char ev_class[CLASS_FIELD_MAX];
637c478bd9Sstevel@tonic-gate 		char ev_subclass[SUBCLASS_FIELD_MAX];
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 		if (mdb_snprintf(ev_class, CLASS_FIELD_MAX, "%s",
667c478bd9Sstevel@tonic-gate 		    SE_CLASS_NAME(ev)) >= CLASS_FIELD_MAX - 1)
677c478bd9Sstevel@tonic-gate 			(void) strcpy(&ev_class[CLASS_FIELD_MAX - 4], "...");
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 		if (mdb_snprintf(ev_subclass, SUBCLASS_FIELD_MAX, "%s",
707c478bd9Sstevel@tonic-gate 		    SE_SUBCLASS_NAME(ev)) >= SUBCLASS_FIELD_MAX - 1)
717c478bd9Sstevel@tonic-gate 			(void) strcpy(&ev_subclass[SUBCLASS_FIELD_MAX - 4],
727c478bd9Sstevel@tonic-gate 			    "...");
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 		mdb_printf("%-?p %-16llu %-9s %-10s %-?p%\n",
757c478bd9Sstevel@tonic-gate 			addr, SE_SEQ(ev), ev_class, ev_subclass,
767c478bd9Sstevel@tonic-gate 			addr + SE_ATTR_OFF(ev));
777c478bd9Sstevel@tonic-gate 	} else {
787c478bd9Sstevel@tonic-gate 		mdb_printf("%<b>Sequence ID\t : %llu%</b>\n", SE_SEQ(ev));
797c478bd9Sstevel@tonic-gate 		mdb_printf("%16s : %s\n", "publisher", SE_PUB_NAME(ev));
807c478bd9Sstevel@tonic-gate 		mdb_printf("%16s : %p\n", "event address", (caddr_t)addr);
817c478bd9Sstevel@tonic-gate 		mdb_printf("%16s : %s\n", "class", SE_CLASS_NAME(ev));
827c478bd9Sstevel@tonic-gate 		mdb_printf("%16s : %s\n", "subclass", SE_SUBCLASS_NAME(ev));
837c478bd9Sstevel@tonic-gate 		mdb_printf("%16s : %llu\n", "time stamp", SE_TIME(ev));
847c478bd9Sstevel@tonic-gate 		mdb_printf("%16s : %p\n", "nvpair buf addr",
857c478bd9Sstevel@tonic-gate 		    addr + SE_ATTR_OFF(ev));
867c478bd9Sstevel@tonic-gate 	}
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate int
sysevent_subclass_list(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)927c478bd9Sstevel@tonic-gate sysevent_subclass_list(uintptr_t addr, uint_t flags, int argc,
937c478bd9Sstevel@tonic-gate     const mdb_arg_t *argv)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate 	int subclass_name_sz;
967c478bd9Sstevel@tonic-gate 	char subclass_name[CLASS_LIST_FIELD_MAX];
977c478bd9Sstevel@tonic-gate 	subclass_lst_t sclist;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
1007c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_LOOP) == 0) {
1037c478bd9Sstevel@tonic-gate 		if (mdb_pwalk_dcmd("sysevent_subclass_list",
1047c478bd9Sstevel@tonic-gate 		    "sysevent_subclass_list", argc, argv, addr) == -1) {
1057c478bd9Sstevel@tonic-gate 			mdb_warn("can't walk sysevent subclass list");
1067c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
1077c478bd9Sstevel@tonic-gate 		}
1087c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
1097c478bd9Sstevel@tonic-gate 	}
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
1127c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%-?s %-24s %-?s%</u>\n",
1137c478bd9Sstevel@tonic-gate 		    "ADDR", "NAME", "SUBSCRIBER DATA ADDR");
1147c478bd9Sstevel@tonic-gate 	}
1157c478bd9Sstevel@tonic-gate 	if (mdb_vread(&sclist, sizeof (sclist), (uintptr_t)addr) == -1) {
1167c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read subclass list at %p", addr);
1177c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1187c478bd9Sstevel@tonic-gate 	}
1197c478bd9Sstevel@tonic-gate 	if ((subclass_name_sz = mdb_readstr(subclass_name, CLASS_LIST_FIELD_MAX,
1207c478bd9Sstevel@tonic-gate 	    (uintptr_t)sclist.sl_name)) == -1) {
1217c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read class name at %p",
1227c478bd9Sstevel@tonic-gate 		    sclist.sl_name);
1237c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1247c478bd9Sstevel@tonic-gate 	}
1257c478bd9Sstevel@tonic-gate 	if (subclass_name_sz >= CLASS_LIST_FIELD_MAX - 1)
1267c478bd9Sstevel@tonic-gate 		(void) strcpy(&subclass_name[CLASS_LIST_FIELD_MAX - 4], "...");
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	mdb_printf("%-?p %-24s %-?p\n", addr, subclass_name,
1297c478bd9Sstevel@tonic-gate 	    addr + offsetof(subclass_lst_t, sl_num));
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate int
sysevent_class_list(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1367c478bd9Sstevel@tonic-gate sysevent_class_list(uintptr_t addr, uint_t flags, int argc,
1377c478bd9Sstevel@tonic-gate     const mdb_arg_t *argv)
1387c478bd9Sstevel@tonic-gate {
1397c478bd9Sstevel@tonic-gate 	int class_name_sz;
1407c478bd9Sstevel@tonic-gate 	char class_name[CLASS_LIST_FIELD_MAX];
1417c478bd9Sstevel@tonic-gate 	class_lst_t clist;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
1447c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_LOOP) == 0) {
1477c478bd9Sstevel@tonic-gate 		if (mdb_pwalk_dcmd("sysevent_class_list", "sysevent_class_list",
1487c478bd9Sstevel@tonic-gate 		    argc, argv, addr) == -1) {
1497c478bd9Sstevel@tonic-gate 			mdb_warn("can't walk sysevent class list");
1507c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
1517c478bd9Sstevel@tonic-gate 		}
1527c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
1537c478bd9Sstevel@tonic-gate 	}
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
1567c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%-?s %-24s %-?s%</u>\n",
1577c478bd9Sstevel@tonic-gate 		    "ADDR", "NAME", "SUBCLASS LIST ADDR");
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	if (mdb_vread(&clist, sizeof (clist),
1607c478bd9Sstevel@tonic-gate 	    (uintptr_t)addr) == -1) {
1617c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read class clist at %p", addr);
1627c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1637c478bd9Sstevel@tonic-gate 	}
1647c478bd9Sstevel@tonic-gate 	if ((class_name_sz = mdb_readstr(class_name, CLASS_LIST_FIELD_MAX,
1657c478bd9Sstevel@tonic-gate 	    (uintptr_t)clist.cl_name)) == -1) {
1667c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read class name at %p",
1677c478bd9Sstevel@tonic-gate 		    clist.cl_name);
1687c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1697c478bd9Sstevel@tonic-gate 	}
1707c478bd9Sstevel@tonic-gate 	if (class_name_sz >= CLASS_LIST_FIELD_MAX - 1)
1717c478bd9Sstevel@tonic-gate 		(void) strcpy(&class_name[CLASS_LIST_FIELD_MAX - 4], "...");
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	mdb_printf("%-?p %-24s %-?p\n", addr, class_name,
1747c478bd9Sstevel@tonic-gate 	    clist.cl_subclass_list);
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate int
sysevent_subclass_list_walk_init(mdb_walk_state_t * wsp)1807c478bd9Sstevel@tonic-gate sysevent_subclass_list_walk_init(mdb_walk_state_t *wsp)
1817c478bd9Sstevel@tonic-gate {
182*892ad162SToomas Soome 	if (wsp->walk_addr == 0) {
1837c478bd9Sstevel@tonic-gate 		mdb_warn("sysevent_subclass_list does not support global "
1847c478bd9Sstevel@tonic-gate 		    "walks");
1857c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
1867c478bd9Sstevel@tonic-gate 	}
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	wsp->walk_data = mdb_alloc(sizeof (subclass_lst_t), UM_SLEEP);
1897c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate int
sysevent_subclass_list_walk_step(mdb_walk_state_t * wsp)1937c478bd9Sstevel@tonic-gate sysevent_subclass_list_walk_step(mdb_walk_state_t *wsp)
1947c478bd9Sstevel@tonic-gate {
1957c478bd9Sstevel@tonic-gate 	int status;
1967c478bd9Sstevel@tonic-gate 
197*892ad162SToomas Soome 	if (wsp->walk_addr == 0)
1987c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	if (mdb_vread(wsp->walk_data, sizeof (subclass_lst_t),
2017c478bd9Sstevel@tonic-gate 	    wsp->walk_addr) == -1) {
2027c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read class list at %p", wsp->walk_addr);
2037c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
2077c478bd9Sstevel@tonic-gate 	    wsp->walk_cbdata);
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 	wsp->walk_addr =
2107c478bd9Sstevel@tonic-gate 	    (uintptr_t)(((subclass_lst_t *)wsp->walk_data)->sl_next);
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	return (status);
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate void
sysevent_subclass_list_walk_fini(mdb_walk_state_t * wsp)2167c478bd9Sstevel@tonic-gate sysevent_subclass_list_walk_fini(mdb_walk_state_t *wsp)
2177c478bd9Sstevel@tonic-gate {
2187c478bd9Sstevel@tonic-gate 	mdb_free(wsp->walk_data, sizeof (subclass_lst_t));
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate typedef struct class_walk_data {
2227c478bd9Sstevel@tonic-gate 	int	hash_index;
2237c478bd9Sstevel@tonic-gate 	class_lst_t *hash_tbl[CLASS_HASH_SZ + 1];
2247c478bd9Sstevel@tonic-gate } class_walk_data_t;
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate int
sysevent_class_list_walk_init(mdb_walk_state_t * wsp)2277c478bd9Sstevel@tonic-gate sysevent_class_list_walk_init(mdb_walk_state_t *wsp)
2287c478bd9Sstevel@tonic-gate {
2297c478bd9Sstevel@tonic-gate 	class_walk_data_t *cl_walker;
2307c478bd9Sstevel@tonic-gate 
231*892ad162SToomas Soome 	if (wsp->walk_addr == 0) {
2327c478bd9Sstevel@tonic-gate 		mdb_warn("sysevent_class_list does not support global walks");
2337c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
2347c478bd9Sstevel@tonic-gate 	}
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	cl_walker = mdb_zalloc(sizeof (class_walk_data_t), UM_SLEEP);
2377c478bd9Sstevel@tonic-gate 	if (mdb_vread(cl_walker->hash_tbl,
2387c478bd9Sstevel@tonic-gate 	    sizeof (cl_walker->hash_tbl), wsp->walk_addr) == -1) {
2397c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read class hash table at %p",
2407c478bd9Sstevel@tonic-gate 		    wsp->walk_addr);
2417c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
2427c478bd9Sstevel@tonic-gate 	}
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)cl_walker->hash_tbl[0];
2457c478bd9Sstevel@tonic-gate 	wsp->walk_data = cl_walker;
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate int
sysevent_class_list_walk_step(mdb_walk_state_t * wsp)2517c478bd9Sstevel@tonic-gate sysevent_class_list_walk_step(mdb_walk_state_t *wsp)
2527c478bd9Sstevel@tonic-gate {
2537c478bd9Sstevel@tonic-gate 	int status = WALK_NEXT;
2547c478bd9Sstevel@tonic-gate 	class_walk_data_t *cl_walker;
2557c478bd9Sstevel@tonic-gate 	class_lst_t clist;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	cl_walker = (class_walk_data_t *)wsp->walk_data;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	/* Skip over empty class table entries */
260*892ad162SToomas Soome 	if (wsp->walk_addr != 0) {
2617c478bd9Sstevel@tonic-gate 		if (mdb_vread(&clist, sizeof (class_lst_t),
2627c478bd9Sstevel@tonic-gate 		    wsp->walk_addr) == -1) {
2637c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read class list at %p",
2647c478bd9Sstevel@tonic-gate 			    wsp->walk_addr);
2657c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
2667c478bd9Sstevel@tonic-gate 		}
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 		status = wsp->walk_callback(wsp->walk_addr, NULL,
2697c478bd9Sstevel@tonic-gate 		    wsp->walk_cbdata);
2707c478bd9Sstevel@tonic-gate 		wsp->walk_addr = (uintptr_t)clist.cl_next;
2717c478bd9Sstevel@tonic-gate 	} else {
2727c478bd9Sstevel@tonic-gate 		if (cl_walker->hash_index > CLASS_HASH_SZ) {
2737c478bd9Sstevel@tonic-gate 			return (WALK_DONE);
2747c478bd9Sstevel@tonic-gate 		} else {
2757c478bd9Sstevel@tonic-gate 			wsp->walk_addr = (uintptr_t)
2767c478bd9Sstevel@tonic-gate 			    cl_walker->hash_tbl[cl_walker->hash_index];
2777c478bd9Sstevel@tonic-gate 			cl_walker->hash_index++;
2787c478bd9Sstevel@tonic-gate 		}
2797c478bd9Sstevel@tonic-gate 	}
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	return (status);
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate void
sysevent_class_list_walk_fini(mdb_walk_state_t * wsp)2867c478bd9Sstevel@tonic-gate sysevent_class_list_walk_fini(mdb_walk_state_t *wsp)
2877c478bd9Sstevel@tonic-gate {
2887c478bd9Sstevel@tonic-gate 	class_walk_data_t *cl_walker = wsp->walk_data;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	mdb_free(cl_walker, sizeof (cl_walker));
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate #ifdef _KERNEL
2947c478bd9Sstevel@tonic-gate int
sysevent(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)2957c478bd9Sstevel@tonic-gate sysevent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate 	uint_t sys_flags = FALSE;
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
3007c478bd9Sstevel@tonic-gate 	    's', MDB_OPT_SETBITS, SYSEVENT_SENTQ, &sys_flags,
3017c478bd9Sstevel@tonic-gate 	    'v', MDB_OPT_SETBITS, SYSEVENT_VERBOSE, &sys_flags, NULL) != argc)
3027c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
3057c478bd9Sstevel@tonic-gate 		if (sys_flags & SYSEVENT_SENTQ) {
3067c478bd9Sstevel@tonic-gate 			if (mdb_walk_dcmd("sysevent_sent", "sysevent", argc,
3077c478bd9Sstevel@tonic-gate 			    argv) == -1) {
3087c478bd9Sstevel@tonic-gate 				mdb_warn("can not walk sent queue");
3097c478bd9Sstevel@tonic-gate 				return (DCMD_ERR);
3107c478bd9Sstevel@tonic-gate 			}
3117c478bd9Sstevel@tonic-gate 		} else {
3127c478bd9Sstevel@tonic-gate 			if (mdb_walk_dcmd("sysevent_pend", "sysevent", argc,
3137c478bd9Sstevel@tonic-gate 			    argv) == -1) {
3147c478bd9Sstevel@tonic-gate 				mdb_warn("can not walk pending queue");
3157c478bd9Sstevel@tonic-gate 				return (DCMD_ERR);
3167c478bd9Sstevel@tonic-gate 			}
3177c478bd9Sstevel@tonic-gate 		}
3187c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
3197c478bd9Sstevel@tonic-gate 	}
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	return (sysevent_buf(addr, flags, sys_flags));
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate int
sysevent_channel(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)3257c478bd9Sstevel@tonic-gate sysevent_channel(uintptr_t addr, uint_t flags, int argc,
3267c478bd9Sstevel@tonic-gate     const mdb_arg_t *argv)
3277c478bd9Sstevel@tonic-gate {
3287c478bd9Sstevel@tonic-gate 	ssize_t channel_name_sz;
3297c478bd9Sstevel@tonic-gate 	char channel_name[CHAN_FIELD_MAX];
3307c478bd9Sstevel@tonic-gate 	sysevent_channel_descriptor_t chan_tbl;
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	if (argc != 0)
3337c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
3367c478bd9Sstevel@tonic-gate 		if (mdb_walk_dcmd("sysevent_channel", "sysevent_channel",
3377c478bd9Sstevel@tonic-gate 		    argc, argv) == -1) {
3387c478bd9Sstevel@tonic-gate 			mdb_warn("can't walk sysevent channel");
3397c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
3407c478bd9Sstevel@tonic-gate 		}
3417c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
3427c478bd9Sstevel@tonic-gate 	}
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
3467c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%-?s %-16s %-8s %-?s%</u>\n",
3477c478bd9Sstevel@tonic-gate 		    "ADDR", "NAME", "REF CNT", "CLASS LST ADDR");
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	if (mdb_vread(&chan_tbl, sizeof (chan_tbl),
3507c478bd9Sstevel@tonic-gate 	    (uintptr_t)addr) == -1) {
3517c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read channel table at %p", addr);
3527c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
3537c478bd9Sstevel@tonic-gate 	}
3547c478bd9Sstevel@tonic-gate 	if ((channel_name_sz = mdb_readstr(channel_name, CHAN_FIELD_MAX,
3557c478bd9Sstevel@tonic-gate 	    (uintptr_t)chan_tbl.scd_channel_name)) == -1) {
3567c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read channel name at %p",
3577c478bd9Sstevel@tonic-gate 		    chan_tbl.scd_channel_name);
3587c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
3597c478bd9Sstevel@tonic-gate 	}
3607c478bd9Sstevel@tonic-gate 	if (channel_name_sz >= CHAN_FIELD_MAX - 1)
3617c478bd9Sstevel@tonic-gate 		(void) strcpy(&channel_name[CHAN_FIELD_MAX - 4], "...");
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	mdb_printf("%-?p %-16s %-8lu %-?p\n",
3647c478bd9Sstevel@tonic-gate 	    addr, channel_name, chan_tbl.scd_ref_cnt,
3657c478bd9Sstevel@tonic-gate 	    addr + offsetof(sysevent_channel_descriptor_t,
3667c478bd9Sstevel@tonic-gate 	    scd_class_list_tbl));
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate typedef struct channel_walk_data {
3727c478bd9Sstevel@tonic-gate 	int hash_index;
3737c478bd9Sstevel@tonic-gate 	sysevent_channel_descriptor_t *hash_tbl[CHAN_HASH_SZ];
3747c478bd9Sstevel@tonic-gate } channel_walk_data_t;
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate int
sysevent_channel_walk_init(mdb_walk_state_t * wsp)3777c478bd9Sstevel@tonic-gate sysevent_channel_walk_init(mdb_walk_state_t *wsp)
3787c478bd9Sstevel@tonic-gate {
3797c478bd9Sstevel@tonic-gate 	channel_walk_data_t *ch_walker;
3807c478bd9Sstevel@tonic-gate 
381*892ad162SToomas Soome 	if (wsp->walk_addr != 0) {
3827c478bd9Sstevel@tonic-gate 		mdb_warn("sysevent_channel supports only global walks");
3837c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
3847c478bd9Sstevel@tonic-gate 	}
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	ch_walker = mdb_zalloc(sizeof (channel_walk_data_t), UM_SLEEP);
3877c478bd9Sstevel@tonic-gate 	if (mdb_readvar(ch_walker->hash_tbl, "registered_channels")
3887c478bd9Sstevel@tonic-gate 	    == -1) {
3897c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'registered_channels'");
3907c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
3917c478bd9Sstevel@tonic-gate 	}
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)ch_walker->hash_tbl[0];
3947c478bd9Sstevel@tonic-gate 	wsp->walk_data = ch_walker;
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate int
sysevent_channel_walk_step(mdb_walk_state_t * wsp)4007c478bd9Sstevel@tonic-gate sysevent_channel_walk_step(mdb_walk_state_t *wsp)
4017c478bd9Sstevel@tonic-gate {
4027c478bd9Sstevel@tonic-gate 	int status = WALK_NEXT;
4037c478bd9Sstevel@tonic-gate 	channel_walk_data_t *ch_walker;
4047c478bd9Sstevel@tonic-gate 	sysevent_channel_descriptor_t scd;
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 	ch_walker = (channel_walk_data_t *)wsp->walk_data;
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate 	/* Skip over empty hash table entries */
409*892ad162SToomas Soome 	if (wsp->walk_addr != 0) {
4107c478bd9Sstevel@tonic-gate 		if (mdb_vread(&scd, sizeof (sysevent_channel_descriptor_t),
4117c478bd9Sstevel@tonic-gate 		    wsp->walk_addr) == -1) {
4127c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read channel at %p",
4137c478bd9Sstevel@tonic-gate 			    wsp->walk_addr);
4147c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
4157c478bd9Sstevel@tonic-gate 		}
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate 		status = wsp->walk_callback(wsp->walk_addr, NULL,
4187c478bd9Sstevel@tonic-gate 		    wsp->walk_cbdata);
4197c478bd9Sstevel@tonic-gate 		wsp->walk_addr = (uintptr_t)scd.scd_next;
4207c478bd9Sstevel@tonic-gate 	} else {
4217c478bd9Sstevel@tonic-gate 		if (ch_walker->hash_index == CHAN_HASH_SZ) {
4227c478bd9Sstevel@tonic-gate 			return (WALK_DONE);
4237c478bd9Sstevel@tonic-gate 		} else {
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate 			wsp->walk_addr = (uintptr_t)
4267c478bd9Sstevel@tonic-gate 			    ch_walker->hash_tbl[ch_walker->hash_index];
4277c478bd9Sstevel@tonic-gate 			ch_walker->hash_index++;
4287c478bd9Sstevel@tonic-gate 		}
4297c478bd9Sstevel@tonic-gate 	}
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	return (status);
4327c478bd9Sstevel@tonic-gate }
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate void
sysevent_channel_walk_fini(mdb_walk_state_t * wsp)4357c478bd9Sstevel@tonic-gate sysevent_channel_walk_fini(mdb_walk_state_t *wsp)
4367c478bd9Sstevel@tonic-gate {
4377c478bd9Sstevel@tonic-gate 	channel_walk_data_t *ch_walker = wsp->walk_data;
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 	mdb_free(ch_walker, sizeof (ch_walker));
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate int
sysevent_pend_walk_init(mdb_walk_state_t * wsp)4437c478bd9Sstevel@tonic-gate sysevent_pend_walk_init(mdb_walk_state_t *wsp)
4447c478bd9Sstevel@tonic-gate {
445*892ad162SToomas Soome 	if (wsp->walk_addr == 0) {
4467c478bd9Sstevel@tonic-gate 		if (mdb_readvar(&wsp->walk_addr, "log_eventq_head") == -1) {
4477c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read 'log_eventq_head'");
4487c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
4497c478bd9Sstevel@tonic-gate 		}
4507c478bd9Sstevel@tonic-gate 	}
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate 	wsp->walk_data = mdb_alloc(sizeof (log_eventq_t), UM_SLEEP);
4537c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate int
sysevent_walk_step(mdb_walk_state_t * wsp)4577c478bd9Sstevel@tonic-gate sysevent_walk_step(mdb_walk_state_t *wsp)
4587c478bd9Sstevel@tonic-gate {
4597c478bd9Sstevel@tonic-gate 	int status;
4607c478bd9Sstevel@tonic-gate 	uintptr_t ev_arg_addr;
4617c478bd9Sstevel@tonic-gate 
462*892ad162SToomas Soome 	if (wsp->walk_addr == 0)
4637c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	if (mdb_vread(wsp->walk_data, sizeof (log_eventq_t),
4667c478bd9Sstevel@tonic-gate 	    wsp->walk_addr) == -1) {
4677c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read event queue at %p", wsp->walk_addr);
4687c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
4697c478bd9Sstevel@tonic-gate 	}
4707c478bd9Sstevel@tonic-gate 	ev_arg_addr = wsp->walk_addr + offsetof(log_eventq_t, arg.buf);
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback(ev_arg_addr, wsp->walk_data,
4737c478bd9Sstevel@tonic-gate 	    wsp->walk_cbdata);
4747c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)(((log_eventq_t *)wsp->walk_data)->next);
4757c478bd9Sstevel@tonic-gate 	return (status);
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate int
sysevent_sent_walk_init(mdb_walk_state_t * wsp)4797c478bd9Sstevel@tonic-gate sysevent_sent_walk_init(mdb_walk_state_t *wsp)
4807c478bd9Sstevel@tonic-gate {
481*892ad162SToomas Soome 	if (wsp->walk_addr == 0) {
4827c478bd9Sstevel@tonic-gate 		if (mdb_readvar(&wsp->walk_addr, "log_eventq_sent") == -1) {
4837c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read 'log_eventq_sent'");
4847c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
4857c478bd9Sstevel@tonic-gate 		}
4867c478bd9Sstevel@tonic-gate 	}
4877c478bd9Sstevel@tonic-gate 	wsp->walk_data = mdb_alloc(sizeof (log_eventq_t), UM_SLEEP);
4887c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
4897c478bd9Sstevel@tonic-gate }
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate void
sysevent_walk_fini(mdb_walk_state_t * wsp)4927c478bd9Sstevel@tonic-gate sysevent_walk_fini(mdb_walk_state_t *wsp)
4937c478bd9Sstevel@tonic-gate {
4947c478bd9Sstevel@tonic-gate 	mdb_free(wsp->walk_data, sizeof (log_eventq_t));
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate #endif
498