xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/dl.c (revision 12449:a87750d92895)
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*12449SRod.Evans@Sun.COM  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include	<string.h>
270Sstevel@tonic-gate #include	"_conv.h"
280Sstevel@tonic-gate #include	"dl_msg.h"
290Sstevel@tonic-gate 
302352Sab196087 #define	MODESZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
312352Sab196087 		MSG_RTLD_LAZY_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
322352Sab196087 		MSG_RTLD_GLOBAL_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
332352Sab196087 		MSG_RTLD_NOLOAD_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
342352Sab196087 		MSG_RTLD_PARENT_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
352352Sab196087 		MSG_RTLD_GROUP_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
362352Sab196087 		MSG_RTLD_WORLD_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
372352Sab196087 		MSG_RTLD_NODELETE_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
382352Sab196087 		MSG_RTLD_FIRST_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
392352Sab196087 		MSG_RTLD_CONFGEN_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
404734Sab196087 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
414734Sab196087 
421618Srie 
434734Sab196087 /*
444734Sab196087  * Ensure that Conv_dl_mode_buf_t is large enough:
454734Sab196087  *
464734Sab196087  * MODESZ is the real minimum size of the buffer required by conv_dl_mode().
474734Sab196087  * However, Conv_dl_mode_buf_t uses CONV_DL_MODE_BUFSIZE to set the
484734Sab196087  * buffer size. We do things this way because the definition of MODESZ uses
494734Sab196087  * information that is not available in the environment of other programs
504734Sab196087  * that include the conv.h header file.
514734Sab196087  */
525152Sab196087 #if (CONV_DL_MODE_BUFSIZE != MODESZ) && !defined(__lint)
535152Sab196087 #define	REPORT_BUFSIZE MODESZ
545152Sab196087 #include "report_bufsize.h"
555152Sab196087 #error "CONV_DL_MODE_BUFSIZE does not match MODESZ"
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 *
conv_dl_mode(int mode,int fabricate,Conv_dl_mode_buf_t * dl_mode_buf)624734Sab196087 conv_dl_mode(int mode, int fabricate, Conv_dl_mode_buf_t *dl_mode_buf)
630Sstevel@tonic-gate {
649273SAli.Bahrami@Sun.COM 	static const Val_desc vda[] = {
659273SAli.Bahrami@Sun.COM 		{ RTLD_NOLOAD,		MSG_RTLD_NOLOAD },
669273SAli.Bahrami@Sun.COM 		{ RTLD_PARENT,		MSG_RTLD_PARENT },
679273SAli.Bahrami@Sun.COM 		{ RTLD_GROUP,		MSG_RTLD_GROUP },
689273SAli.Bahrami@Sun.COM 		{ RTLD_WORLD,		MSG_RTLD_WORLD },
699273SAli.Bahrami@Sun.COM 		{ RTLD_NODELETE,	MSG_RTLD_NODELETE },
709273SAli.Bahrami@Sun.COM 		{ RTLD_FIRST,		MSG_RTLD_FIRST },
719273SAli.Bahrami@Sun.COM 		{ RTLD_CONFGEN,		MSG_RTLD_CONFGEN },
721618Srie 		{ 0,			0 }
731618Srie 	};
742352Sab196087 	static const char *leading_str_arr[3];
754734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
769273SAli.Bahrami@Sun.COM 	    NULL, sizeof (dl_mode_buf->buf), 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);
868140SAli.Bahrami@Sun.COM 	} else if ((mode & RTLD_LAZY) || 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 
989273SAli.Bahrami@Sun.COM 	(void) conv_expn_field(&conv_arg, vda, 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  */
1325152Sab196087 #if (CONV_DL_FLAG_BUFSIZE != FLAGSZ) && !defined(__lint)
1335152Sab196087 #define	REPORT_BUFSIZE FLAGSZ
1345152Sab196087 #include "report_bufsize.h"
1355152Sab196087 #error "CONV_DL_FLAG_BUFSIZE does not match FLAGSZ"
1364734Sab196087 #endif
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate /*
1390Sstevel@tonic-gate  * String conversion routine for dldump() flags.
1400Sstevel@tonic-gate  * crle(1) uses this routine to generate update information, and in this case
1410Sstevel@tonic-gate  * we build a "|" separated string.
1420Sstevel@tonic-gate  */
1430Sstevel@tonic-gate const char *
conv_dl_flag(int flags,Conv_fmt_flags_t fmt_flags,Conv_dl_flag_buf_t * dl_flag_buf)1445088Sab196087 conv_dl_flag(int flags, Conv_fmt_flags_t fmt_flags,
1455088Sab196087     Conv_dl_flag_buf_t *dl_flag_buf)
1460Sstevel@tonic-gate {
1479273SAli.Bahrami@Sun.COM 	static const Val_desc vda[] = {
1489273SAli.Bahrami@Sun.COM 		{ RTLD_REL_RELATIVE,	MSG_RTLD_REL_RELATIVE },
1499273SAli.Bahrami@Sun.COM 		{ RTLD_REL_EXEC,	MSG_RTLD_REL_EXEC },
1509273SAli.Bahrami@Sun.COM 		{ RTLD_REL_DEPENDS,	MSG_RTLD_REL_DEPENDS },
1519273SAli.Bahrami@Sun.COM 		{ RTLD_REL_PRELOAD,	MSG_RTLD_REL_PRELOAD },
1529273SAli.Bahrami@Sun.COM 		{ RTLD_REL_SELF,	MSG_RTLD_REL_SELF },
1539273SAli.Bahrami@Sun.COM 		{ RTLD_REL_WEAK,	MSG_RTLD_REL_WEAK },
1549273SAli.Bahrami@Sun.COM 		{ RTLD_MEMORY,		MSG_RTLD_MEMORY },
1559273SAli.Bahrami@Sun.COM 		{ RTLD_STRIP,		MSG_RTLD_STRIP },
1569273SAli.Bahrami@Sun.COM 		{ RTLD_NOHEAP,		MSG_RTLD_NOHEAP },
1579273SAli.Bahrami@Sun.COM 		{ RTLD_CONFSET,		MSG_RTLD_CONFSET },
1581618Srie 		{ 0,			0 }
1591618Srie 	};
1602352Sab196087 	static const char *leading_str_arr[2];
1614734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
1629273SAli.Bahrami@Sun.COM 	    NULL, sizeof (dl_flag_buf->buf), leading_str_arr };
1632352Sab196087 
1642352Sab196087 	const char **lstr = leading_str_arr;
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	if (flags == 0)
1670Sstevel@tonic-gate 		return (MSG_ORIG(MSG_GBL_ZERO));
1680Sstevel@tonic-gate 
1694734Sab196087 	conv_arg.buf = dl_flag_buf->buf;
1705088Sab196087 	if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_CRLE) {
1712352Sab196087 		conv_arg.prefix = conv_arg.suffix = MSG_ORIG(MSG_GBL_QUOTE);
1722352Sab196087 		conv_arg.sep = MSG_ORIG(MSG_GBL_SEP);
1732352Sab196087 	} else {		/* Use default delimiters */
1744734Sab196087 		conv_arg.prefix = conv_arg.suffix = conv_arg.sep = NULL;
1752352Sab196087 	}
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 	if ((flags & RTLD_REL_ALL) == RTLD_REL_ALL) {
1782352Sab196087 		*lstr++ = MSG_ORIG(MSG_RTLD_REL_ALL);
1794734Sab196087 		flags &= ~RTLD_REL_ALL;
1800Sstevel@tonic-gate 	}
1812352Sab196087 	*lstr = NULL;
1822352Sab196087 	conv_arg.oflags = conv_arg.rflags = flags;
1830Sstevel@tonic-gate 
1849273SAli.Bahrami@Sun.COM 	(void) conv_expn_field(&conv_arg, vda, fmt_flags);
1850Sstevel@tonic-gate 
1864734Sab196087 	return ((const char *)dl_flag_buf->buf);
1870Sstevel@tonic-gate }
18812029SRod.Evans@Sun.COM 
18912029SRod.Evans@Sun.COM const char *
conv_dl_info(int request)19012029SRod.Evans@Sun.COM conv_dl_info(int request)
19112029SRod.Evans@Sun.COM {
19212029SRod.Evans@Sun.COM 	static const Msg	requests[RTLD_DI_MAX] = {
19312029SRod.Evans@Sun.COM 		MSG_RTLD_DI_LMID,	/* MSG_ORIG(MSG_RTLD_DI_LMID) */
19412029SRod.Evans@Sun.COM 		MSG_RTLD_DI_LINKMAP,	/* MSG_ORIG(MSG_RTLD_DI_LINKMAP) */
19512029SRod.Evans@Sun.COM 		MSG_RTLD_DI_CONFIGADDR,	/* MSG_ORIG(MSG_RTLD_DI_CONFIGADDR) */
19612029SRod.Evans@Sun.COM 		MSG_RTLD_DI_SERINFO,	/* MSG_ORIG(MSG_RTLD_DI_SERINFO) */
19712029SRod.Evans@Sun.COM 		MSG_RTLD_DI_SERINFOSIZE, /* MSG_ORIG(MSG_RTLD_DI_SERINFOSIZE) */
19812029SRod.Evans@Sun.COM 		MSG_RTLD_DI_ORIGIN,	/* MSG_ORIG(MSG_RTLD_DI_ORIGIN) */
19912029SRod.Evans@Sun.COM 		MSG_RTLD_DI_PROFILENAME, /* MSG_ORIG(MSG_RTLD_DI_PROFILENAME) */
20012029SRod.Evans@Sun.COM 		MSG_RTLD_DI_PROFILEOUT,	/* MSG_ORIG(MSG_RTLD_DI_PROFILEOUT) */
20112029SRod.Evans@Sun.COM 		MSG_RTLD_DI_GETSIGNAL,	/* MSG_ORIG(MSG_RTLD_DI_GETSIGNAL) */
20212029SRod.Evans@Sun.COM 		MSG_RTLD_DI_SETSIGNAL,	/* MSG_ORIG(MSG_RTLD_DI_SETSIGNAL) */
20312029SRod.Evans@Sun.COM 		MSG_RTLD_DI_ARGSINFO,	/* MSG_ORIG(MSG_RTLD_DI_ARGSINFO) */
20412029SRod.Evans@Sun.COM 		MSG_RTLD_DI_MMAPS,	/* MSG_ORIG(MSG_RTLD_DI_MMAPS) */
205*12449SRod.Evans@Sun.COM 		MSG_RTLD_DI_MMAPCNT,	/* MSG_ORIG(MSG_RTLD_DI_MMAPCNT) */
206*12449SRod.Evans@Sun.COM 		MSG_RTLD_DI_DEFERRED,	/* MSG_ORIG(MSG_RTLD_DI_DEFERRED) */
207*12449SRod.Evans@Sun.COM 		MSG_RTLD_DI_DEFERRED_SYM
208*12449SRod.Evans@Sun.COM 					/* MSG_ORIG(MSG_RTLD_DI_DEFERRED_SYM) */
20912029SRod.Evans@Sun.COM 	};
21012029SRod.Evans@Sun.COM 	static Conv_inv_buf_t	inv_buf;
21112029SRod.Evans@Sun.COM 
212*12449SRod.Evans@Sun.COM #if	(RTLD_DI_MAX != RTLD_DI_DEFERRED_SYM)
21312029SRod.Evans@Sun.COM #error	"RTLD_DI_MAX has grown"
21412029SRod.Evans@Sun.COM #endif
21512029SRod.Evans@Sun.COM 	if (request && (request <= RTLD_DI_MAX))
21612029SRod.Evans@Sun.COM 		return (MSG_ORIG(requests[request - 1]));
21712029SRod.Evans@Sun.COM 
21812029SRod.Evans@Sun.COM 	(void) conv_invalid_val(&inv_buf, EC_NATPTR(request), 0);
21912029SRod.Evans@Sun.COM 	return (inv_buf.buf);
22012029SRod.Evans@Sun.COM }
221