xref: /titanic_50/usr/src/cmd/sgs/libconv/common/dl.c (revision 554ff184129088135ad2643c1c9832174a17be88)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  *	Use is subject to license terms.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include	<string.h>
29 #include	"_conv.h"
30 #include	"dl_msg.h"
31 
32 #define	MODESZ	MSG_GBL_OSQBRKT_SIZE + \
33 		MSG_RTLD_LAZY_SIZE + \
34 		MSG_RTLD_NOLOAD_SIZE + \
35 		MSG_RTLD_GLOBAL_SIZE + \
36 		MSG_RTLD_PARENT_SIZE + \
37 		MSG_RTLD_GROUP_SIZE + \
38 		MSG_RTLD_WORLD_SIZE + \
39 		MSG_RTLD_NODELETE_SIZE + \
40 		MSG_RTLD_FIRST_SIZE + \
41 		MSG_RTLD_CONFGEN_SIZE + \
42 		MSG_GBL_CSQBRKT_SIZE
43 
44 /*
45  * String conversion routine for dlopen() attributes.
46  */
47 const char *
48 conv_dlmode_str(int mode, int fabricate)
49 {
50 	static	char	string[MODESZ] = { '\0' };
51 
52 	(void) strcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT));
53 
54 	if (mode & RTLD_NOW)
55 		(void) strcat(string, MSG_ORIG(MSG_RTLD_NOW));
56 	else if (fabricate)
57 		(void) strcat(string, MSG_ORIG(MSG_RTLD_LAZY));
58 
59 	if (mode & RTLD_NOLOAD)
60 		(void) strcat(string, MSG_ORIG(MSG_RTLD_NOLOAD));
61 
62 	if (mode & RTLD_GLOBAL)
63 		(void) strcat(string, MSG_ORIG(MSG_RTLD_GLOBAL));
64 	else if (fabricate)
65 		(void) strcat(string, MSG_ORIG(MSG_RTLD_LOCAL));
66 
67 	if (mode & RTLD_PARENT)
68 		(void) strcat(string, MSG_ORIG(MSG_RTLD_PARENT));
69 	if (mode & RTLD_GROUP)
70 		(void) strcat(string, MSG_ORIG(MSG_RTLD_GROUP));
71 	if (mode & RTLD_WORLD)
72 		(void) strcat(string, MSG_ORIG(MSG_RTLD_WORLD));
73 	if (mode & RTLD_NODELETE)
74 		(void) strcat(string, MSG_ORIG(MSG_RTLD_NODELETE));
75 	if (mode & RTLD_FIRST)
76 		(void) strcat(string, MSG_ORIG(MSG_RTLD_FIRST));
77 	if (mode & RTLD_CONFGEN)
78 		(void) strcat(string, MSG_ORIG(MSG_RTLD_CONFGEN));
79 
80 	(void) strcat(string, MSG_ORIG(MSG_GBL_CSQBRKT));
81 
82 	return ((const char *)string);
83 }
84 
85 #define	FLAGSZ	MSG_GBL_OSQBRKT_SIZE + \
86 		MSG_RTLD_REL_RELATIVE_SIZE + \
87 		MSG_GBL_SEP_SIZE + \
88 		MSG_RTLD_REL_EXEC_SIZE + \
89 		MSG_GBL_SEP_SIZE + \
90 		MSG_RTLD_REL_DEPENDS_SIZE + \
91 		MSG_GBL_SEP_SIZE + \
92 		MSG_RTLD_REL_PRELOAD_SIZE + \
93 		MSG_GBL_SEP_SIZE + \
94 		MSG_RTLD_REL_SELF_SIZE + \
95 		MSG_GBL_SEP_SIZE + \
96 		MSG_RTLD_REL_WEAK_SIZE + \
97 		MSG_GBL_SEP_SIZE + \
98 		MSG_RTLD_MEMORY_SIZE + \
99 		MSG_GBL_SEP_SIZE + \
100 		MSG_RTLD_STRIP_SIZE + \
101 		MSG_GBL_SEP_SIZE + \
102 		MSG_RTLD_NOHEAP_SIZE + \
103 		MSG_GBL_SEP_SIZE + \
104 		MSG_RTLD_CONFSET_SIZE + \
105 		MSG_GBL_CSQBRKT_SIZE
106 
107 /*
108  * String conversion routine for dldump() flags.
109  * crle(1) uses this routine to generate update information, and in this case
110  * we build a "|" separated string.
111  */
112 const char *
113 conv_dlflag_str(int flags, int separator)
114 {
115 	static	char	string[FLAGSZ] = { '\0' };
116 	int		element = 0;
117 
118 	if (flags == 0)
119 		return (MSG_ORIG(MSG_GBL_ZERO));
120 
121 	if (separator)
122 		(void) strcpy(string, MSG_ORIG(MSG_GBL_QUOTE));
123 	else
124 		(void) strcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT));
125 
126 	if ((flags & RTLD_REL_ALL) == RTLD_REL_ALL) {
127 		(void) strcat(string, MSG_ORIG(MSG_RTLD_REL_ALL));
128 		element++;
129 	} else {
130 		if (flags & RTLD_REL_RELATIVE) {
131 			(void) strcat(string, MSG_ORIG(MSG_RTLD_REL_RELATIVE));
132 			element++;
133 		}
134 		if (flags & RTLD_REL_EXEC) {
135 			if (separator && element++)
136 				(void) strcat(string, MSG_ORIG(MSG_GBL_SEP));
137 			(void) strcat(string, MSG_ORIG(MSG_RTLD_REL_EXEC));
138 		}
139 		if (flags & RTLD_REL_DEPENDS) {
140 			if (separator && element++)
141 				(void) strcat(string, MSG_ORIG(MSG_GBL_SEP));
142 			(void) strcat(string, MSG_ORIG(MSG_RTLD_REL_DEPENDS));
143 		}
144 		if (flags & RTLD_REL_PRELOAD) {
145 			if (separator && element++)
146 				(void) strcat(string, MSG_ORIG(MSG_GBL_SEP));
147 			(void) strcat(string, MSG_ORIG(MSG_RTLD_REL_PRELOAD));
148 		}
149 		if (flags & RTLD_REL_SELF) {
150 			if (separator && element++)
151 				(void) strcat(string, MSG_ORIG(MSG_GBL_SEP));
152 			(void) strcat(string, MSG_ORIG(MSG_RTLD_REL_SELF));
153 		}
154 		if (flags & RTLD_REL_WEAK) {
155 			if (separator && element++)
156 				(void) strcat(string, MSG_ORIG(MSG_GBL_SEP));
157 			(void) strcat(string, MSG_ORIG(MSG_RTLD_REL_WEAK));
158 		}
159 	}
160 
161 	if (flags & RTLD_MEMORY) {
162 		if (separator && element++)
163 			(void) strcat(string, MSG_ORIG(MSG_GBL_SEP));
164 		(void) strcat(string, MSG_ORIG(MSG_RTLD_MEMORY));
165 	}
166 	if (flags & RTLD_STRIP) {
167 		if (separator && element++)
168 			(void) strcat(string, MSG_ORIG(MSG_GBL_SEP));
169 		(void) strcat(string, MSG_ORIG(MSG_RTLD_STRIP));
170 	}
171 	if (flags & RTLD_NOHEAP) {
172 		if (separator && element++)
173 			(void) strcat(string, MSG_ORIG(MSG_GBL_SEP));
174 		(void) strcat(string, MSG_ORIG(MSG_RTLD_NOHEAP));
175 	}
176 	if (flags & RTLD_CONFSET) {
177 		if (separator && element++)
178 			(void) strcat(string, MSG_ORIG(MSG_GBL_SEP));
179 		(void) strcat(string, MSG_ORIG(MSG_RTLD_CONFSET));
180 	}
181 
182 	if (separator)
183 		(void) strcat(string, MSG_ORIG(MSG_GBL_QUOTE));
184 	else
185 		(void) strcat(string, MSG_ORIG(MSG_GBL_CSQBRKT));
186 
187 	return ((const char *)string);
188 }
189