xref: /titanic_41/usr/src/cmd/sgs/liblddbg/common/tls.c (revision 2fb876ae0cefcbd01f8d8490242aa4501caddbc3)
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 2006 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	MSG_TLS_FLAG_START_SIZE + \
38 		MSG_TLS_FLAG_STATIC_SIZE + \
39 		CONV_INV_STRSIZE + MSG_TLS_FLAG_END_SIZE
40 
41 static void
42 Dbg_tls_modent(Lm_list *lml, TLS_modinfo * tmodent)
43 {
44 	static Val_desc	vda[] = {
45 		{ TM_FLG_STATICTLS,	MSG_ORIG(MSG_TLS_FLAG_STATIC) },
46 		{ 0,			0 }
47 	};
48 	char	flagstr[FLAGSZ];
49 	ulong_t	flags;
50 
51 	if ((flags = tmodent->tm_flags) != 0) {
52 		(void) strlcpy(flagstr, MSG_ORIG(MSG_TLS_FLAG_START), FLAGSZ);
53 
54 		if (conv_expn_field(flagstr, FLAGSZ, vda, flags, flags,
55 		    MSG_ORIG(MSG_TLS_FLAG_SEP), 0))
56 			(void) strcat(flagstr, MSG_ORIG(MSG_TLS_FLAG_END));
57 	} else
58 		flagstr[0] = '\0';
59 
60 	dbg_print(lml, MSG_INTL(MSG_TLS_MODENT1),
61 	    EC_XWORD((uintptr_t)tmodent->tm_tlsblock),
62 	    EC_XWORD(tmodent->tm_stattlsoffset), EC_XWORD(tmodent->tm_flags),
63 	    flagstr);
64 	dbg_print(lml, MSG_INTL(MSG_TLS_MODENT2),
65 	    EC_XWORD(tmodent->tm_filesz), EC_XWORD(tmodent->tm_memsz),
66 	    EC_XWORD(tmodent->tm_modid));
67 }
68 
69 void
70 Dbg_tls_static_block(Lm_list *lml, void *list, ulong_t size, ulong_t resv)
71 {
72 	if (DBG_NOTCLASS(DBG_C_TLS))
73 		return;
74 
75 	Dbg_util_nl(lml, DBG_NL_STD);
76 
77 	if (list) {
78 		ulong_t		ndx;
79 		TLS_modinfo	**tlsmodlist;
80 
81 		tlsmodlist = (TLS_modinfo **)list;
82 
83 		for (ndx = 0; tlsmodlist[ndx]; ndx++) {
84 			dbg_print(lml, MSG_INTL(MSG_TLS_STATBLOCK1), ndx,
85 			    tlsmodlist[ndx]->tm_modname);
86 			Dbg_tls_modent(lml, tlsmodlist[ndx]);
87 			Dbg_util_nl(lml, DBG_NL_STD);
88 		}
89 	}
90 	dbg_print(lml, MSG_INTL(MSG_TLS_STATBLOCK2), EC_XWORD(size),
91 	    EC_XWORD(resv));
92 }
93 
94 void
95 Dbg_tls_static_resv(Rt_map *lmp, ulong_t size, ulong_t resv)
96 {
97 	Lm_list	*lml = LIST(lmp);
98 
99 	if (DBG_NOTCLASS(DBG_C_TLS))
100 		return;
101 
102 	Dbg_util_nl(lml, DBG_NL_STD);
103 	dbg_print(lml, MSG_INTL(MSG_TLS_STATBLOCK3), TLSMODID(lmp), NAME(lmp),
104 	    EC_XWORD(size), EC_XWORD(resv));
105 }
106 
107 void
108 Dbg_tls_modactivity(Lm_list *lml, void *vtlsmodent, uint_t flag)
109 {
110 	const char	*str;
111 	TLS_modinfo	*tlsmodent;
112 
113 	if (DBG_NOTCLASS(DBG_C_TLS))
114 		return;
115 
116 	if (flag == TM_FLG_MODADD)
117 		str = MSG_INTL(MSG_TLS_ADD);
118 	else
119 		str = MSG_INTL(MSG_TLS_REMOVE);
120 
121 	tlsmodent = (TLS_modinfo *)vtlsmodent;
122 	Dbg_util_nl(lml, DBG_NL_STD);
123 	dbg_print(lml, MSG_INTL(MSG_TLS_MODACT), str, tlsmodent->tm_modname);
124 	Dbg_tls_modent(lml, tlsmodent);
125 }
126