xref: /titanic_50/usr/src/cmd/sgs/liblddbg/common/tls.c (revision 7eea693d6b672899726e75993fddc4e95b52647f)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include	<link.h>
30 #include	<libc_int.h>
31 #include	<rtld.h>
32 #include	<strings.h>
33 #include	<debug.h>
34 #include	"msg.h"
35 #include	"_debug.h"
36 
37 #define	FLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
38 		MSG_TLS_FLAG_STATIC_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
39 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
40 
41 static void
42 Dbg_tls_modent(Lm_list *lml, TLS_modinfo * tmodent)
43 {
44 	static char	flagstr[FLAGSZ];
45 	static Val_desc	vda[] = {
46 		{ TM_FLG_STATICTLS,	MSG_ORIG(MSG_TLS_FLAG_STATIC) },
47 		{ 0,			0 }
48 	};
49 	static CONV_EXPN_FIELD_ARG conv_arg = { flagstr,
50 		sizeof (flagstr), vda };
51 
52 	ulong_t	flags;
53 
54 	if ((flags = tmodent->tm_flags) != 0) {
55 		conv_arg.oflags = conv_arg.rflags = flags;
56 		(void) conv_expn_field(&conv_arg, 0);
57 	} else {
58 		flagstr[0] = '\0';
59 	}
60 
61 	dbg_print(lml, MSG_INTL(MSG_TLS_MODENT1),
62 	    EC_XWORD((uintptr_t)tmodent->tm_tlsblock),
63 	    EC_XWORD(tmodent->tm_stattlsoffset), EC_XWORD(tmodent->tm_flags),
64 	    flagstr);
65 	dbg_print(lml, MSG_INTL(MSG_TLS_MODENT2),
66 	    EC_XWORD(tmodent->tm_filesz), EC_XWORD(tmodent->tm_memsz),
67 	    EC_XWORD(tmodent->tm_modid));
68 }
69 
70 void
71 Dbg_tls_static_block(Lm_list *lml, void *list, ulong_t size, ulong_t resv)
72 {
73 	if (DBG_NOTCLASS(DBG_C_TLS))
74 		return;
75 
76 	Dbg_util_nl(lml, DBG_NL_STD);
77 
78 	if (list) {
79 		ulong_t		ndx;
80 		TLS_modinfo	**tlsmodlist;
81 
82 		tlsmodlist = (TLS_modinfo **)list;
83 
84 		for (ndx = 0; tlsmodlist[ndx]; ndx++) {
85 			dbg_print(lml, MSG_INTL(MSG_TLS_STATBLOCK1), ndx,
86 			    tlsmodlist[ndx]->tm_modname);
87 			Dbg_tls_modent(lml, tlsmodlist[ndx]);
88 			Dbg_util_nl(lml, DBG_NL_STD);
89 		}
90 	}
91 	dbg_print(lml, MSG_INTL(MSG_TLS_STATBLOCK2), EC_XWORD(size),
92 	    EC_XWORD(resv));
93 }
94 
95 void
96 Dbg_tls_static_resv(Rt_map *lmp, ulong_t size, ulong_t resv)
97 {
98 	Lm_list	*lml = LIST(lmp);
99 
100 	if (DBG_NOTCLASS(DBG_C_TLS))
101 		return;
102 
103 	Dbg_util_nl(lml, DBG_NL_STD);
104 	dbg_print(lml, MSG_INTL(MSG_TLS_STATBLOCK3), TLSMODID(lmp), NAME(lmp),
105 	    EC_XWORD(size), EC_XWORD(resv));
106 }
107 
108 void
109 Dbg_tls_modactivity(Lm_list *lml, void *vtlsmodent, uint_t flag)
110 {
111 	const char	*str;
112 	TLS_modinfo	*tlsmodent;
113 
114 	if (DBG_NOTCLASS(DBG_C_TLS))
115 		return;
116 
117 	if (flag == TM_FLG_MODADD)
118 		str = MSG_INTL(MSG_TLS_ADD);
119 	else
120 		str = MSG_INTL(MSG_TLS_REMOVE);
121 
122 	tlsmodent = (TLS_modinfo *)vtlsmodent;
123 	Dbg_util_nl(lml, DBG_NL_STD);
124 	dbg_print(lml, MSG_INTL(MSG_TLS_MODACT), str, tlsmodent->tm_modname);
125 	Dbg_tls_modent(lml, tlsmodent);
126 }
127