xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/dl.c (revision 5088:26c540f30cd3)
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 /*
234734Sab196087  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
241618Srie  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include	<string.h>
290Sstevel@tonic-gate #include	"_conv.h"
300Sstevel@tonic-gate #include	"dl_msg.h"
310Sstevel@tonic-gate 
322352Sab196087 #define	MODESZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
332352Sab196087 		MSG_RTLD_LAZY_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
342352Sab196087 		MSG_RTLD_GLOBAL_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
352352Sab196087 		MSG_RTLD_NOLOAD_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
362352Sab196087 		MSG_RTLD_PARENT_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
372352Sab196087 		MSG_RTLD_GROUP_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
382352Sab196087 		MSG_RTLD_WORLD_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
392352Sab196087 		MSG_RTLD_NODELETE_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
402352Sab196087 		MSG_RTLD_FIRST_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
412352Sab196087 		MSG_RTLD_CONFGEN_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
424734Sab196087 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
434734Sab196087 
441618Srie 
454734Sab196087 /*
464734Sab196087  * Ensure that Conv_dl_mode_buf_t is large enough:
474734Sab196087  *
484734Sab196087  * MODESZ is the real minimum size of the buffer required by conv_dl_mode().
494734Sab196087  * However, Conv_dl_mode_buf_t uses CONV_DL_MODE_BUFSIZE to set the
504734Sab196087  * buffer size. We do things this way because the definition of MODESZ uses
514734Sab196087  * information that is not available in the environment of other programs
524734Sab196087  * that include the conv.h header file.
534734Sab196087  */
544734Sab196087 #if (CONV_DL_MODE_BUFSIZE < MODESZ) && !defined(__lint)
554734Sab196087 #error "CONV_DL_MODE_BUFSIZE is not large enough"
564734Sab196087 #endif
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate  * String conversion routine for dlopen() attributes.
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate const char *
624734Sab196087 conv_dl_mode(int mode, int fabricate, Conv_dl_mode_buf_t *dl_mode_buf)
630Sstevel@tonic-gate {
641618Srie 	static Val_desc vda[] = {
651618Srie 		{ RTLD_NOLOAD,		MSG_ORIG(MSG_RTLD_NOLOAD) },
661618Srie 		{ RTLD_PARENT,		MSG_ORIG(MSG_RTLD_PARENT) },
671618Srie 		{ RTLD_GROUP,		MSG_ORIG(MSG_RTLD_GROUP) },
681618Srie 		{ RTLD_WORLD,		MSG_ORIG(MSG_RTLD_WORLD) },
691618Srie 		{ RTLD_NODELETE,	MSG_ORIG(MSG_RTLD_NODELETE) },
701618Srie 		{ RTLD_FIRST,		MSG_ORIG(MSG_RTLD_FIRST) },
711618Srie 		{ RTLD_CONFGEN,		MSG_ORIG(MSG_RTLD_CONFGEN) },
721618Srie 		{ 0,			0 }
731618Srie 	};
742352Sab196087 	static const char *leading_str_arr[3];
754734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
764734Sab196087 	    NULL, sizeof (dl_mode_buf->buf), vda, leading_str_arr };
770Sstevel@tonic-gate 
782352Sab196087 	const char **lstr = leading_str_arr;
792352Sab196087 
804734Sab196087 	conv_arg.buf = dl_mode_buf->buf;
812352Sab196087 	conv_arg.oflags = conv_arg.rflags = mode;
822352Sab196087 
830Sstevel@tonic-gate 
841618Srie 	if (mode & RTLD_NOW) {
852352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_NOW);
861618Srie 	} else if (fabricate) {
872352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_LAZY);
881618Srie 	}
891618Srie 	if (mode & RTLD_GLOBAL) {
902352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_GLOBAL);
911618Srie 	} else if (fabricate) {
922352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_LOCAL);
931618Srie 	}
942352Sab196087 	*lstr = NULL;
952352Sab196087 	conv_arg.oflags = mode;
962352Sab196087 	conv_arg.rflags = mode & ~(RTLD_LAZY | RTLD_NOW | RTLD_GLOBAL);
970Sstevel@tonic-gate 
98*5088Sab196087 	(void) conv_expn_field(&conv_arg, 0);
990Sstevel@tonic-gate 
1004734Sab196087 	return ((const char *)dl_mode_buf->buf);
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate 
1032352Sab196087 /*
1042352Sab196087  * Note: We can use two different sets of prefix/separator/suffix
1052352Sab196087  * strings in conv_dl_flag(), depending on the value of the separator
1062352Sab196087  * argument. To size the buffer, I use the default prefix and suffix
1072352Sab196087  * sizes, and the alternate separator size, because they are larger.
1082352Sab196087  */
1092352Sab196087 
1102352Sab196087 #define	FLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
1111618Srie 		MSG_RTLD_REL_RELATIVE_SIZE +	MSG_GBL_SEP_SIZE + \
1121618Srie 		MSG_RTLD_REL_EXEC_SIZE +	MSG_GBL_SEP_SIZE + \
1131618Srie 		MSG_RTLD_REL_DEPENDS_SIZE +	MSG_GBL_SEP_SIZE + \
1141618Srie 		MSG_RTLD_REL_PRELOAD_SIZE +	MSG_GBL_SEP_SIZE + \
1151618Srie 		MSG_RTLD_REL_SELF_SIZE +	MSG_GBL_SEP_SIZE + \
1161618Srie 		MSG_RTLD_REL_WEAK_SIZE +	MSG_GBL_SEP_SIZE + \
1171618Srie 		MSG_RTLD_MEMORY_SIZE +		MSG_GBL_SEP_SIZE + \
1181618Srie 		MSG_RTLD_STRIP_SIZE +		MSG_GBL_SEP_SIZE + \
1191618Srie 		MSG_RTLD_NOHEAP_SIZE +		MSG_GBL_SEP_SIZE + \
1200Sstevel@tonic-gate 		MSG_RTLD_CONFSET_SIZE + \
1214734Sab196087 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
1224734Sab196087 
1234734Sab196087 /*
1244734Sab196087  * Ensure that Conv_dl_flag_buf_t is large enough:
1254734Sab196087  *
1264734Sab196087  * FLAGSZ is the real minimum size of the buffer required by conv_dl_flag().
1274734Sab196087  * However, Conv_dl_flag_buf_t uses CONV_DL_FLAG_BUFSIZE to set the
1284734Sab196087  * buffer size. We do things this way because the definition of FLAGSZ uses
1294734Sab196087  * information that is not available in the environment of other programs
1304734Sab196087  * that include the conv.h header file.
1314734Sab196087  */
1324734Sab196087 #if (CONV_DL_FLAG_BUFSIZE < FLAGSZ) && !defined(__lint)
1334734Sab196087 #error "CONV_DL_FLAG_BUFSIZE is not large enough"
1344734Sab196087 #endif
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate /*
1370Sstevel@tonic-gate  * String conversion routine for dldump() flags.
1380Sstevel@tonic-gate  * crle(1) uses this routine to generate update information, and in this case
1390Sstevel@tonic-gate  * we build a "|" separated string.
1400Sstevel@tonic-gate  */
1410Sstevel@tonic-gate const char *
142*5088Sab196087 conv_dl_flag(int flags, Conv_fmt_flags_t fmt_flags,
143*5088Sab196087     Conv_dl_flag_buf_t *dl_flag_buf)
1440Sstevel@tonic-gate {
1451618Srie 	static Val_desc vda[] = {
1461618Srie 		{ RTLD_REL_RELATIVE,	MSG_ORIG(MSG_RTLD_REL_RELATIVE) },
1471618Srie 		{ RTLD_REL_EXEC,	MSG_ORIG(MSG_RTLD_REL_EXEC) },
1481618Srie 		{ RTLD_REL_DEPENDS,	MSG_ORIG(MSG_RTLD_REL_DEPENDS) },
1491618Srie 		{ RTLD_REL_PRELOAD,	MSG_ORIG(MSG_RTLD_REL_PRELOAD) },
1501618Srie 		{ RTLD_REL_SELF,	MSG_ORIG(MSG_RTLD_REL_SELF) },
1511618Srie 		{ RTLD_REL_WEAK,	MSG_ORIG(MSG_RTLD_REL_WEAK) },
1521618Srie 		{ RTLD_MEMORY,		MSG_ORIG(MSG_RTLD_MEMORY) },
1531618Srie 		{ RTLD_STRIP,		MSG_ORIG(MSG_RTLD_STRIP) },
1541618Srie 		{ RTLD_NOHEAP,		MSG_ORIG(MSG_RTLD_NOHEAP) },
1551618Srie 		{ RTLD_CONFSET,		MSG_ORIG(MSG_RTLD_CONFSET) },
1561618Srie 		{ 0,			0 }
1571618Srie 	};
1582352Sab196087 	static const char *leading_str_arr[2];
1594734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
1604734Sab196087 	    NULL, sizeof (dl_flag_buf->buf), vda, leading_str_arr };
1612352Sab196087 
1622352Sab196087 	const char **lstr = leading_str_arr;
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	if (flags == 0)
1650Sstevel@tonic-gate 		return (MSG_ORIG(MSG_GBL_ZERO));
1660Sstevel@tonic-gate 
1674734Sab196087 	conv_arg.buf = dl_flag_buf->buf;
168*5088Sab196087 	if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_CRLE) {
1692352Sab196087 		conv_arg.prefix = conv_arg.suffix = MSG_ORIG(MSG_GBL_QUOTE);
1702352Sab196087 		conv_arg.sep = MSG_ORIG(MSG_GBL_SEP);
1712352Sab196087 	} else {		/* Use default delimiters */
1724734Sab196087 		conv_arg.prefix = conv_arg.suffix = conv_arg.sep = NULL;
1732352Sab196087 	}
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 	if ((flags & RTLD_REL_ALL) == RTLD_REL_ALL) {
1762352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_REL_ALL);
1774734Sab196087 		flags &= ~RTLD_REL_ALL;
1780Sstevel@tonic-gate 	}
1792352Sab196087 	*lstr = NULL;
1802352Sab196087 	conv_arg.oflags = conv_arg.rflags = flags;
1810Sstevel@tonic-gate 
182*5088Sab196087 	(void) conv_expn_field(&conv_arg, fmt_flags);
1830Sstevel@tonic-gate 
1844734Sab196087 	return ((const char *)dl_flag_buf->buf);
1850Sstevel@tonic-gate }
186