xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/dl.c (revision 4734:a4708faa3e85)
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*4734Sab196087  * 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 + \
42*4734Sab196087 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
43*4734Sab196087 
441618Srie 
45*4734Sab196087 /*
46*4734Sab196087  * Ensure that Conv_dl_mode_buf_t is large enough:
47*4734Sab196087  *
48*4734Sab196087  * MODESZ is the real minimum size of the buffer required by conv_dl_mode().
49*4734Sab196087  * However, Conv_dl_mode_buf_t uses CONV_DL_MODE_BUFSIZE to set the
50*4734Sab196087  * buffer size. We do things this way because the definition of MODESZ uses
51*4734Sab196087  * information that is not available in the environment of other programs
52*4734Sab196087  * that include the conv.h header file.
53*4734Sab196087  */
54*4734Sab196087 #if (CONV_DL_MODE_BUFSIZE < MODESZ) && !defined(__lint)
55*4734Sab196087 #error "CONV_DL_MODE_BUFSIZE is not large enough"
56*4734Sab196087 #endif
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate  * String conversion routine for dlopen() attributes.
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate const char *
62*4734Sab196087 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];
75*4734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
76*4734Sab196087 	    NULL, sizeof (dl_mode_buf->buf), vda, leading_str_arr };
770Sstevel@tonic-gate 
782352Sab196087 	const char **lstr = leading_str_arr;
792352Sab196087 
80*4734Sab196087 	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 
982352Sab196087 	(void) conv_expn_field(&conv_arg);
990Sstevel@tonic-gate 
100*4734Sab196087 	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 + \
121*4734Sab196087 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
122*4734Sab196087 
123*4734Sab196087 /*
124*4734Sab196087  * Ensure that Conv_dl_flag_buf_t is large enough:
125*4734Sab196087  *
126*4734Sab196087  * FLAGSZ is the real minimum size of the buffer required by conv_dl_flag().
127*4734Sab196087  * However, Conv_dl_flag_buf_t uses CONV_DL_FLAG_BUFSIZE to set the
128*4734Sab196087  * buffer size. We do things this way because the definition of FLAGSZ uses
129*4734Sab196087  * information that is not available in the environment of other programs
130*4734Sab196087  * that include the conv.h header file.
131*4734Sab196087  */
132*4734Sab196087 #if (CONV_DL_FLAG_BUFSIZE < FLAGSZ) && !defined(__lint)
133*4734Sab196087 #error "CONV_DL_FLAG_BUFSIZE is not large enough"
134*4734Sab196087 #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*4734Sab196087 conv_dl_flag(int flags, int fmt_flags, Conv_dl_flag_buf_t *dl_flag_buf)
1430Sstevel@tonic-gate {
1441618Srie 	static Val_desc vda[] = {
1451618Srie 		{ RTLD_REL_RELATIVE,	MSG_ORIG(MSG_RTLD_REL_RELATIVE) },
1461618Srie 		{ RTLD_REL_EXEC,	MSG_ORIG(MSG_RTLD_REL_EXEC) },
1471618Srie 		{ RTLD_REL_DEPENDS,	MSG_ORIG(MSG_RTLD_REL_DEPENDS) },
1481618Srie 		{ RTLD_REL_PRELOAD,	MSG_ORIG(MSG_RTLD_REL_PRELOAD) },
1491618Srie 		{ RTLD_REL_SELF,	MSG_ORIG(MSG_RTLD_REL_SELF) },
1501618Srie 		{ RTLD_REL_WEAK,	MSG_ORIG(MSG_RTLD_REL_WEAK) },
1511618Srie 		{ RTLD_MEMORY,		MSG_ORIG(MSG_RTLD_MEMORY) },
1521618Srie 		{ RTLD_STRIP,		MSG_ORIG(MSG_RTLD_STRIP) },
1531618Srie 		{ RTLD_NOHEAP,		MSG_ORIG(MSG_RTLD_NOHEAP) },
1541618Srie 		{ RTLD_CONFSET,		MSG_ORIG(MSG_RTLD_CONFSET) },
1551618Srie 		{ 0,			0 }
1561618Srie 	};
1572352Sab196087 	static const char *leading_str_arr[2];
158*4734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
159*4734Sab196087 	    NULL, sizeof (dl_flag_buf->buf), vda, leading_str_arr };
1602352Sab196087 
1612352Sab196087 	const char **lstr = leading_str_arr;
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	if (flags == 0)
1640Sstevel@tonic-gate 		return (MSG_ORIG(MSG_GBL_ZERO));
1650Sstevel@tonic-gate 
166*4734Sab196087 	conv_arg.buf = dl_flag_buf->buf;
1672352Sab196087 	if (fmt_flags & CONV_FMT_ALTCRLE) {
1682352Sab196087 		conv_arg.prefix = conv_arg.suffix = MSG_ORIG(MSG_GBL_QUOTE);
1692352Sab196087 		conv_arg.sep = MSG_ORIG(MSG_GBL_SEP);
1702352Sab196087 	} else {		/* Use default delimiters */
171*4734Sab196087 		conv_arg.prefix = conv_arg.suffix = conv_arg.sep = NULL;
1722352Sab196087 	}
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 	if ((flags & RTLD_REL_ALL) == RTLD_REL_ALL) {
1752352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_REL_ALL);
176*4734Sab196087 		flags &= ~RTLD_REL_ALL;
1770Sstevel@tonic-gate 	}
1782352Sab196087 	*lstr = NULL;
1792352Sab196087 	conv_arg.oflags = conv_arg.rflags = flags;
1800Sstevel@tonic-gate 
1812352Sab196087 	(void) conv_expn_field(&conv_arg);
1820Sstevel@tonic-gate 
183*4734Sab196087 	return ((const char *)dl_flag_buf->buf);
1840Sstevel@tonic-gate }
185