xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/tls.c (revision 4f680cc6)
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
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
215aefb655Srie 
227c478bd9Sstevel@tonic-gate /*
23*4f680cc6SAli Bahrami  * Copyright 2009 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	<link.h>
287c478bd9Sstevel@tonic-gate #include	<libc_int.h>
297c478bd9Sstevel@tonic-gate #include	<rtld.h>
30d326b23bSrie #include	<strings.h>
315aefb655Srie #include	<debug.h>
327c478bd9Sstevel@tonic-gate #include	"msg.h"
337c478bd9Sstevel@tonic-gate #include	"_debug.h"
347c478bd9Sstevel@tonic-gate 
35ba4e3c84Sab #define	FLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
36ba4e3c84Sab 		MSG_TLS_FLAG_STATIC_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
37de777a60Sab 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
38d326b23bSrie 
397c478bd9Sstevel@tonic-gate static void
Dbg_tls_modent(Lm_list * lml,TLS_modinfo * tmodent)405aefb655Srie Dbg_tls_modent(Lm_list *lml, TLS_modinfo * tmodent)
417c478bd9Sstevel@tonic-gate {
42*4f680cc6SAli Bahrami 	/*
43*4f680cc6SAli Bahrami 	 * MSG_ORIG(MSG_TLS_FLAG_STATIC)
44*4f680cc6SAli Bahrami 	 */
45ba4e3c84Sab 	static char	flagstr[FLAGSZ];
46d326b23bSrie 	static Val_desc	vda[] = {
47*4f680cc6SAli Bahrami 		{ TM_FLG_STATICTLS,	MSG_TLS_FLAG_STATIC },
48d326b23bSrie 		{ 0,			0 }
49d326b23bSrie 	};
50*4f680cc6SAli Bahrami 	static CONV_EXPN_FIELD_ARG conv_arg = { flagstr, sizeof (flagstr) };
51ba4e3c84Sab 
52d326b23bSrie 	ulong_t	flags;
53d326b23bSrie 
54d326b23bSrie 	if ((flags = tmodent->tm_flags) != 0) {
55ba4e3c84Sab 		conv_arg.oflags = conv_arg.rflags = flags;
56*4f680cc6SAli Bahrami 		(void) conv_expn_field(&conv_arg, vda, 0);
57ba4e3c84Sab 	} else {
58d326b23bSrie 		flagstr[0] = '\0';
59ba4e3c84Sab 	}
60d326b23bSrie 
61d326b23bSrie 	dbg_print(lml, MSG_INTL(MSG_TLS_MODENT1),
625aefb655Srie 	    EC_XWORD((uintptr_t)tmodent->tm_tlsblock),
63d326b23bSrie 	    EC_XWORD(tmodent->tm_stattlsoffset), EC_XWORD(tmodent->tm_flags),
64d326b23bSrie 	    flagstr);
65d326b23bSrie 	dbg_print(lml, MSG_INTL(MSG_TLS_MODENT2),
665aefb655Srie 	    EC_XWORD(tmodent->tm_filesz), EC_XWORD(tmodent->tm_memsz),
675aefb655Srie 	    EC_XWORD(tmodent->tm_modid));
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate void
Dbg_tls_static_block(Lm_list * lml,void * list,ulong_t size,ulong_t resv)71d326b23bSrie Dbg_tls_static_block(Lm_list *lml, void *list, ulong_t size, ulong_t resv)
727c478bd9Sstevel@tonic-gate {
735aefb655Srie 	if (DBG_NOTCLASS(DBG_C_TLS))
747c478bd9Sstevel@tonic-gate 		return;
755aefb655Srie 
765aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
775aefb655Srie 
78d326b23bSrie 	if (list) {
79d326b23bSrie 		ulong_t		ndx;
80d326b23bSrie 		TLS_modinfo	**tlsmodlist;
81d326b23bSrie 
82d326b23bSrie 		tlsmodlist = (TLS_modinfo **)list;
83d326b23bSrie 
84d326b23bSrie 		for (ndx = 0; tlsmodlist[ndx]; ndx++) {
85d326b23bSrie 			dbg_print(lml, MSG_INTL(MSG_TLS_STATBLOCK1), ndx,
86d326b23bSrie 			    tlsmodlist[ndx]->tm_modname);
87d326b23bSrie 			Dbg_tls_modent(lml, tlsmodlist[ndx]);
88d326b23bSrie 			Dbg_util_nl(lml, DBG_NL_STD);
89d326b23bSrie 		}
907c478bd9Sstevel@tonic-gate 	}
91d326b23bSrie 	dbg_print(lml, MSG_INTL(MSG_TLS_STATBLOCK2), EC_XWORD(size),
92d326b23bSrie 	    EC_XWORD(resv));
93d326b23bSrie }
94d326b23bSrie 
95d326b23bSrie void
Dbg_tls_static_resv(Rt_map * lmp,ulong_t size,ulong_t resv)96d326b23bSrie Dbg_tls_static_resv(Rt_map *lmp, ulong_t size, ulong_t resv)
97d326b23bSrie {
98d326b23bSrie 	Lm_list	*lml = LIST(lmp);
99d326b23bSrie 
100d326b23bSrie 	if (DBG_NOTCLASS(DBG_C_TLS))
101d326b23bSrie 		return;
102d326b23bSrie 
103d326b23bSrie 	Dbg_util_nl(lml, DBG_NL_STD);
104d326b23bSrie 	dbg_print(lml, MSG_INTL(MSG_TLS_STATBLOCK3), TLSMODID(lmp), NAME(lmp),
105d326b23bSrie 	    EC_XWORD(size), EC_XWORD(resv));
1067c478bd9Sstevel@tonic-gate }
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate void
Dbg_tls_modactivity(Lm_list * lml,void * vtlsmodent,uint_t flag)1095aefb655Srie Dbg_tls_modactivity(Lm_list *lml, void *vtlsmodent, uint_t flag)
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate 	const char	*str;
1127c478bd9Sstevel@tonic-gate 	TLS_modinfo	*tlsmodent;
1135aefb655Srie 
1145aefb655Srie 	if (DBG_NOTCLASS(DBG_C_TLS))
1157c478bd9Sstevel@tonic-gate 		return;
1165aefb655Srie 
1177c478bd9Sstevel@tonic-gate 	if (flag == TM_FLG_MODADD)
1187c478bd9Sstevel@tonic-gate 		str = MSG_INTL(MSG_TLS_ADD);
1197c478bd9Sstevel@tonic-gate 	else
1207c478bd9Sstevel@tonic-gate 		str = MSG_INTL(MSG_TLS_REMOVE);
1215aefb655Srie 
1227c478bd9Sstevel@tonic-gate 	tlsmodent = (TLS_modinfo *)vtlsmodent;
1235aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1245aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_TLS_MODACT), str, tlsmodent->tm_modname);
1255aefb655Srie 	Dbg_tls_modent(lml, tlsmodent);
1267c478bd9Sstevel@tonic-gate }
127