xref: /illumos-gate/usr/src/cmd/mdb/common/modules/logindmux/logindmux.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <mdb/mdb_modapi.h>
28 #include <mdb/mdb_ks.h>
29 #include <sys/logindmux_impl.h>
30 
31 /*
32  * Print our peer's upper queue pointer, and our lower queue pointer.
33  */
34 void
35 logdmux_uqinfo(const queue_t *q, char *buf, size_t nbytes)
36 {
37 	struct tmx tmx;
38 	uintptr_t peer, lower;
39 	queue_t lq;
40 
41 	/*
42 	 * First, get the pointer to our lower write queue.
43 	 */
44 	(void) mdb_vread(&tmx, sizeof (tmx), (uintptr_t)q->q_ptr);
45 	lower = (uintptr_t)tmx.muxq;
46 
47 	/*
48 	 * Now read in the lower's peer, and follow that to up to our peer.
49 	 */
50 	(void) mdb_vread(&lq, sizeof (lq), (uintptr_t)tmx.peerq);
51 	(void) mdb_vread(&tmx, sizeof (tmx), (uintptr_t)lq.q_ptr);
52 	peer = (uintptr_t)tmx.rdq;
53 
54 	(void) mdb_snprintf(buf, nbytes, "peer rq    : %p\nlower wq   : %p",
55 	    peer, lower);
56 }
57 
58 /*
59  * Print our peer's lower queue pointer, and our upper queue pointer.
60  */
61 void
62 logdmux_lqinfo(const queue_t *q, char *buf, size_t nbytes)
63 {
64 	struct tmx tmx;
65 
66 	(void) mdb_vread(&tmx, sizeof (tmx), (uintptr_t)q->q_ptr);
67 	(void) mdb_snprintf(buf, nbytes, "peer wq    : %p\nupper rq   : %p",
68 	    (uintptr_t)tmx.peerq, (uintptr_t)tmx.rdq);
69 }
70 
71 uintptr_t
72 logdmux_lrnext(const queue_t *q)
73 {
74 	struct tmx tmx;
75 
76 	(void) mdb_vread(&tmx, sizeof (tmx), (uintptr_t)q->q_ptr);
77 	return ((uintptr_t)tmx.rdq);
78 }
79 
80 uintptr_t
81 logdmux_uwnext(const queue_t *q)
82 {
83 	struct tmx tmx;
84 
85 	(void) mdb_vread(&tmx, sizeof (tmx), (uintptr_t)q->q_ptr);
86 	return ((uintptr_t)tmx.muxq);
87 }
88 
89 static const mdb_qops_t logdmux_uqops = {
90 	logdmux_uqinfo, mdb_qrnext_default, logdmux_uwnext
91 };
92 
93 static const mdb_qops_t logdmux_lqops = {
94 	logdmux_lqinfo, logdmux_lrnext, mdb_qwnext_default
95 };
96 
97 static const mdb_modinfo_t modinfo = { MDB_API_VERSION };
98 
99 const mdb_modinfo_t *
100 _mdb_init(void)
101 {
102 	GElf_Sym sym;
103 
104 	if (mdb_lookup_by_obj("logindmux", "logdmuxuwinit", &sym) == 0)
105 		mdb_qops_install(&logdmux_uqops, (uintptr_t)sym.st_value);
106 	if (mdb_lookup_by_obj("logindmux", "logdmuxlwinit", &sym) == 0)
107 		mdb_qops_install(&logdmux_lqops, (uintptr_t)sym.st_value);
108 
109 	return (&modinfo);
110 }
111 
112 void
113 _mdb_fini(void)
114 {
115 	GElf_Sym sym;
116 
117 	if (mdb_lookup_by_obj("logindmux", "logdmuxuwinit", &sym) == 0)
118 		mdb_qops_remove(&logdmux_uqops, (uintptr_t)sym.st_value);
119 	if (mdb_lookup_by_obj("logindmux", "logdmuxlwinit", &sym) == 0)
120 		mdb_qops_remove(&logdmux_lqops, (uintptr_t)sym.st_value);
121 }
122