xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/dl.c (revision 8140:5932af7fc25c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211618Srie 
220Sstevel@tonic-gate /*
23*8140SAli.Bahrami@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
241618Srie  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #include	<string.h>
280Sstevel@tonic-gate #include	"_conv.h"
290Sstevel@tonic-gate #include	"dl_msg.h"
300Sstevel@tonic-gate 
312352Sab196087 #define	MODESZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
322352Sab196087 		MSG_RTLD_LAZY_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
332352Sab196087 		MSG_RTLD_GLOBAL_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
342352Sab196087 		MSG_RTLD_NOLOAD_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
352352Sab196087 		MSG_RTLD_PARENT_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
362352Sab196087 		MSG_RTLD_GROUP_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
372352Sab196087 		MSG_RTLD_WORLD_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
382352Sab196087 		MSG_RTLD_NODELETE_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
392352Sab196087 		MSG_RTLD_FIRST_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
402352Sab196087 		MSG_RTLD_CONFGEN_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
414734Sab196087 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
424734Sab196087 
431618Srie 
444734Sab196087 /*
454734Sab196087  * Ensure that Conv_dl_mode_buf_t is large enough:
464734Sab196087  *
474734Sab196087  * MODESZ is the real minimum size of the buffer required by conv_dl_mode().
484734Sab196087  * However, Conv_dl_mode_buf_t uses CONV_DL_MODE_BUFSIZE to set the
494734Sab196087  * buffer size. We do things this way because the definition of MODESZ uses
504734Sab196087  * information that is not available in the environment of other programs
514734Sab196087  * that include the conv.h header file.
524734Sab196087  */
535152Sab196087 #if (CONV_DL_MODE_BUFSIZE != MODESZ) && !defined(__lint)
545152Sab196087 #define	REPORT_BUFSIZE MODESZ
555152Sab196087 #include "report_bufsize.h"
565152Sab196087 #error "CONV_DL_MODE_BUFSIZE does not match MODESZ"
574734Sab196087 #endif
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /*
600Sstevel@tonic-gate  * String conversion routine for dlopen() attributes.
610Sstevel@tonic-gate  */
620Sstevel@tonic-gate const char *
634734Sab196087 conv_dl_mode(int mode, int fabricate, Conv_dl_mode_buf_t *dl_mode_buf)
640Sstevel@tonic-gate {
651618Srie 	static Val_desc vda[] = {
661618Srie 		{ RTLD_NOLOAD,		MSG_ORIG(MSG_RTLD_NOLOAD) },
671618Srie 		{ RTLD_PARENT,		MSG_ORIG(MSG_RTLD_PARENT) },
681618Srie 		{ RTLD_GROUP,		MSG_ORIG(MSG_RTLD_GROUP) },
691618Srie 		{ RTLD_WORLD,		MSG_ORIG(MSG_RTLD_WORLD) },
701618Srie 		{ RTLD_NODELETE,	MSG_ORIG(MSG_RTLD_NODELETE) },
711618Srie 		{ RTLD_FIRST,		MSG_ORIG(MSG_RTLD_FIRST) },
721618Srie 		{ RTLD_CONFGEN,		MSG_ORIG(MSG_RTLD_CONFGEN) },
731618Srie 		{ 0,			0 }
741618Srie 	};
752352Sab196087 	static const char *leading_str_arr[3];
764734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
774734Sab196087 	    NULL, sizeof (dl_mode_buf->buf), vda, leading_str_arr };
780Sstevel@tonic-gate 
792352Sab196087 	const char **lstr = leading_str_arr;
802352Sab196087 
814734Sab196087 	conv_arg.buf = dl_mode_buf->buf;
822352Sab196087 	conv_arg.oflags = conv_arg.rflags = mode;
832352Sab196087 
840Sstevel@tonic-gate 
851618Srie 	if (mode & RTLD_NOW) {
862352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_NOW);
87*8140SAli.Bahrami@Sun.COM 	} else if ((mode & RTLD_LAZY) || fabricate) {
882352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_LAZY);
891618Srie 	}
901618Srie 	if (mode & RTLD_GLOBAL) {
912352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_GLOBAL);
921618Srie 	} else if (fabricate) {
932352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_LOCAL);
941618Srie 	}
952352Sab196087 	*lstr = NULL;
962352Sab196087 	conv_arg.oflags = mode;
972352Sab196087 	conv_arg.rflags = mode & ~(RTLD_LAZY | RTLD_NOW | RTLD_GLOBAL);
980Sstevel@tonic-gate 
995088Sab196087 	(void) conv_expn_field(&conv_arg, 0);
1000Sstevel@tonic-gate 
1014734Sab196087 	return ((const char *)dl_mode_buf->buf);
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate 
1042352Sab196087 /*
1052352Sab196087  * Note: We can use two different sets of prefix/separator/suffix
1062352Sab196087  * strings in conv_dl_flag(), depending on the value of the separator
1072352Sab196087  * argument. To size the buffer, I use the default prefix and suffix
1082352Sab196087  * sizes, and the alternate separator size, because they are larger.
1092352Sab196087  */
1102352Sab196087 
1112352Sab196087 #define	FLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
1121618Srie 		MSG_RTLD_REL_RELATIVE_SIZE +	MSG_GBL_SEP_SIZE + \
1131618Srie 		MSG_RTLD_REL_EXEC_SIZE +	MSG_GBL_SEP_SIZE + \
1141618Srie 		MSG_RTLD_REL_DEPENDS_SIZE +	MSG_GBL_SEP_SIZE + \
1151618Srie 		MSG_RTLD_REL_PRELOAD_SIZE +	MSG_GBL_SEP_SIZE + \
1161618Srie 		MSG_RTLD_REL_SELF_SIZE +	MSG_GBL_SEP_SIZE + \
1171618Srie 		MSG_RTLD_REL_WEAK_SIZE +	MSG_GBL_SEP_SIZE + \
1181618Srie 		MSG_RTLD_MEMORY_SIZE +		MSG_GBL_SEP_SIZE + \
1191618Srie 		MSG_RTLD_STRIP_SIZE +		MSG_GBL_SEP_SIZE + \
1201618Srie 		MSG_RTLD_NOHEAP_SIZE +		MSG_GBL_SEP_SIZE + \
1210Sstevel@tonic-gate 		MSG_RTLD_CONFSET_SIZE + \
1224734Sab196087 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
1234734Sab196087 
1244734Sab196087 /*
1254734Sab196087  * Ensure that Conv_dl_flag_buf_t is large enough:
1264734Sab196087  *
1274734Sab196087  * FLAGSZ is the real minimum size of the buffer required by conv_dl_flag().
1284734Sab196087  * However, Conv_dl_flag_buf_t uses CONV_DL_FLAG_BUFSIZE to set the
1294734Sab196087  * buffer size. We do things this way because the definition of FLAGSZ uses
1304734Sab196087  * information that is not available in the environment of other programs
1314734Sab196087  * that include the conv.h header file.
1324734Sab196087  */
1335152Sab196087 #if (CONV_DL_FLAG_BUFSIZE != FLAGSZ) && !defined(__lint)
1345152Sab196087 #define	REPORT_BUFSIZE FLAGSZ
1355152Sab196087 #include "report_bufsize.h"
1365152Sab196087 #error "CONV_DL_FLAG_BUFSIZE does not match FLAGSZ"
1374734Sab196087 #endif
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate  * String conversion routine for dldump() flags.
1410Sstevel@tonic-gate  * crle(1) uses this routine to generate update information, and in this case
1420Sstevel@tonic-gate  * we build a "|" separated string.
1430Sstevel@tonic-gate  */
1440Sstevel@tonic-gate const char *
1455088Sab196087 conv_dl_flag(int flags, Conv_fmt_flags_t fmt_flags,
1465088Sab196087     Conv_dl_flag_buf_t *dl_flag_buf)
1470Sstevel@tonic-gate {
1481618Srie 	static Val_desc vda[] = {
1491618Srie 		{ RTLD_REL_RELATIVE,	MSG_ORIG(MSG_RTLD_REL_RELATIVE) },
1501618Srie 		{ RTLD_REL_EXEC,	MSG_ORIG(MSG_RTLD_REL_EXEC) },
1511618Srie 		{ RTLD_REL_DEPENDS,	MSG_ORIG(MSG_RTLD_REL_DEPENDS) },
1521618Srie 		{ RTLD_REL_PRELOAD,	MSG_ORIG(MSG_RTLD_REL_PRELOAD) },
1531618Srie 		{ RTLD_REL_SELF,	MSG_ORIG(MSG_RTLD_REL_SELF) },
1541618Srie 		{ RTLD_REL_WEAK,	MSG_ORIG(MSG_RTLD_REL_WEAK) },
1551618Srie 		{ RTLD_MEMORY,		MSG_ORIG(MSG_RTLD_MEMORY) },
1561618Srie 		{ RTLD_STRIP,		MSG_ORIG(MSG_RTLD_STRIP) },
1571618Srie 		{ RTLD_NOHEAP,		MSG_ORIG(MSG_RTLD_NOHEAP) },
1581618Srie 		{ RTLD_CONFSET,		MSG_ORIG(MSG_RTLD_CONFSET) },
1591618Srie 		{ 0,			0 }
1601618Srie 	};
1612352Sab196087 	static const char *leading_str_arr[2];
1624734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
1634734Sab196087 	    NULL, sizeof (dl_flag_buf->buf), vda, leading_str_arr };
1642352Sab196087 
1652352Sab196087 	const char **lstr = leading_str_arr;
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate 	if (flags == 0)
1680Sstevel@tonic-gate 		return (MSG_ORIG(MSG_GBL_ZERO));
1690Sstevel@tonic-gate 
1704734Sab196087 	conv_arg.buf = dl_flag_buf->buf;
1715088Sab196087 	if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_CRLE) {
1722352Sab196087 		conv_arg.prefix = conv_arg.suffix = MSG_ORIG(MSG_GBL_QUOTE);
1732352Sab196087 		conv_arg.sep = MSG_ORIG(MSG_GBL_SEP);
1742352Sab196087 	} else {		/* Use default delimiters */
1754734Sab196087 		conv_arg.prefix = conv_arg.suffix = conv_arg.sep = NULL;
1762352Sab196087 	}
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 	if ((flags & RTLD_REL_ALL) == RTLD_REL_ALL) {
1792352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_REL_ALL);
1804734Sab196087 		flags &= ~RTLD_REL_ALL;
1810Sstevel@tonic-gate 	}
1822352Sab196087 	*lstr = NULL;
1832352Sab196087 	conv_arg.oflags = conv_arg.rflags = flags;
1840Sstevel@tonic-gate 
1855088Sab196087 	(void) conv_expn_field(&conv_arg, fmt_flags);
1860Sstevel@tonic-gate 
1874734Sab196087 	return ((const char *)dl_flag_buf->buf);
1880Sstevel@tonic-gate }
189