xref: /titanic_51/usr/src/cmd/sgs/libconv/common/syminfo.c (revision 613a2f6ba31e891e3d947a356daf5e563d43c1ce)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * String conversion routines for syminfo attributes.
29  */
30 #include	<stdio.h>
31 #include	<_machelf.h>
32 #include	"_conv.h"
33 #include	"syminfo_msg.h"
34 
35 
36 
37 static const Val_desc *
38 conv_syminfo_flags_strings(Conv_fmt_flags_t fmt_flags)
39 {
40 #define	FLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
41 	MSG_SYMINFO_FLG_DIRECT_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
42 	MSG_SYMINFO_FLG_FILTER_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
43 	MSG_SYMINFO_FLG_COPY_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
44 	MSG_SYMINFO_FLG_LAZYLOAD_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
45 	MSG_SYMINFO_FLG_DIRECTBIND_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
46 	MSG_SYMINFO_FLG_NOEXTDIRECT_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
47 	MSG_SYMINFO_FLG_AUXILIARY_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
48 	MSG_SYMINFO_FLG_INTERPOSE_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
49 	CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
50 
51 	/*
52 	 * Ensure that Conv_syminfo_flags_buf_t is large enough:
53 	 *
54 	 * FLAGSZ is the real minimum size of the buffer required by
55 	 * conv_syminfo_flags(). However, Conv_syminfo_flags_buf_t uses
56 	 * CONV_SYMINFO_FLAGS_BUFSIZE to set the buffer size. We do things
57 	 * this way because the definition of FLAGSZ uses information that
58 	 * is not available in the environment of other programs that include
59 	 * the conv.h header file.
60 	 */
61 #if (CONV_SYMINFO_FLAGS_BUFSIZE != FLAGSZ) && !defined(__lint)
62 #define	REPORT_BUFSIZE FLAGSZ
63 #include "report_bufsize.h"
64 #error "CONV_SYMINFO_FLAGS_BUFSIZE does not match FLAGSZ"
65 #endif
66 
67 	static const Val_desc vda_cf[] = {
68 		{ SYMINFO_FLG_DIRECT,	MSG_SYMINFO_FLG_DIRECT_CF },
69 		{ SYMINFO_FLG_FILTER,	MSG_SYMINFO_FLG_FILTER_CF },
70 		{ SYMINFO_FLG_COPY,	MSG_SYMINFO_FLG_COPY_CF },
71 		{ SYMINFO_FLG_LAZYLOAD,	MSG_SYMINFO_FLG_LAZYLOAD_CF },
72 		{ SYMINFO_FLG_DIRECTBIND, MSG_SYMINFO_FLG_DIRECTBIND_CF },
73 		{ SYMINFO_FLG_NOEXTDIRECT, MSG_SYMINFO_FLG_NOEXTDIRECT_CF },
74 		{ SYMINFO_FLG_AUXILIARY, MSG_SYMINFO_FLG_AUXILIARY_CF },
75 		{ SYMINFO_FLG_INTERPOSE, MSG_SYMINFO_FLG_INTERPOSE_CF },
76 		{ 0 }
77 	};
78 	static const Val_desc vda_cfnp[] = {
79 		{ SYMINFO_FLG_DIRECT,	MSG_SYMINFO_FLG_DIRECT_CFNP },
80 		{ SYMINFO_FLG_FILTER,	MSG_SYMINFO_FLG_FILTER_CFNP },
81 		{ SYMINFO_FLG_COPY,	MSG_SYMINFO_FLG_COPY_CFNP },
82 		{ SYMINFO_FLG_LAZYLOAD,	MSG_SYMINFO_FLG_LAZYLOAD_CFNP },
83 		{ SYMINFO_FLG_DIRECTBIND, MSG_SYMINFO_FLG_DIRECTBIND_CFNP },
84 		{ SYMINFO_FLG_NOEXTDIRECT, MSG_SYMINFO_FLG_NOEXTDIRECT_CFNP },
85 		{ SYMINFO_FLG_AUXILIARY, MSG_SYMINFO_FLG_AUXILIARY_CFNP },
86 		{ SYMINFO_FLG_INTERPOSE, MSG_SYMINFO_FLG_INTERPOSE_CFNP },
87 		{ 0 }
88 	};
89 	static const Val_desc vda_nf[] = {
90 		{ SYMINFO_FLG_DIRECT,	MSG_SYMINFO_FLG_DIRECT_NF },
91 		{ SYMINFO_FLG_FILTER,	MSG_SYMINFO_FLG_FILTER_NF },
92 		{ SYMINFO_FLG_COPY,	MSG_SYMINFO_FLG_COPY_NF },
93 		{ SYMINFO_FLG_LAZYLOAD,	MSG_SYMINFO_FLG_LAZYLOAD_NF },
94 		{ SYMINFO_FLG_DIRECTBIND, MSG_SYMINFO_FLG_DIRECTBIND_NF },
95 		{ SYMINFO_FLG_NOEXTDIRECT, MSG_SYMINFO_FLG_NOEXTDIRECT_NF },
96 		{ SYMINFO_FLG_AUXILIARY, MSG_SYMINFO_FLG_AUXILIARY_NF },
97 		{ SYMINFO_FLG_INTERPOSE, MSG_SYMINFO_FLG_INTERPOSE_NF },
98 		{ 0 }
99 	};
100 
101 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
102 	case CONV_FMT_ALT_CF:
103 		return (vda_cf);
104 	case CONV_FMT_ALT_NF:
105 		return (vda_nf);
106 	}
107 
108 	return (vda_cfnp);
109 }
110 
111 
112 const char *
113 conv_syminfo_flags(Half flags, Conv_fmt_flags_t fmt_flags,
114     Conv_syminfo_flags_buf_t *syminfo_flags_buf)
115 {
116 	static CONV_EXPN_FIELD_ARG conv_arg = {
117 	    NULL, sizeof (syminfo_flags_buf->buf) };
118 
119 	if (flags == 0)
120 		return (MSG_ORIG(MSG_GBL_ZERO));
121 
122 	conv_arg.buf = syminfo_flags_buf->buf;
123 	conv_arg.oflags = conv_arg.rflags = flags;
124 	conv_arg.prefix = conv_arg.suffix = NULL;
125 	(void) conv_expn_field(&conv_arg,
126 	    conv_syminfo_flags_strings(fmt_flags), fmt_flags);
127 
128 	return ((const char *)syminfo_flags_buf->buf);
129 }
130 
131 conv_iter_ret_t
132 conv_iter_syminfo_flags(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
133     void *uvalue)
134 {
135 	return (conv_iter_vd(conv_syminfo_flags_strings(fmt_flags),
136 	    func, uvalue));
137 }
138 
139 
140 static const conv_ds_t **
141 conv_syminfo_boundto_strings(Conv_fmt_flags_t fmt_flags)
142 {
143 	static const Msg	boundto_cf[] = {
144 		MSG_SYMINFO_BT_EXTERN_CF,	MSG_SYMINFO_BT_NONE_CF,
145 		MSG_SYMINFO_BT_PARENT_CF,	MSG_SYMINFO_BT_SELF_CF
146 	};
147 	static const Msg	boundto_cfnp[] = {
148 		MSG_SYMINFO_BT_EXTERN_CFNP,	MSG_SYMINFO_BT_NONE_CFNP,
149 		MSG_SYMINFO_BT_PARENT_CFNP,	MSG_SYMINFO_BT_SELF_CFNP
150 	};
151 	static const Msg	boundto_nf[] = {
152 		MSG_SYMINFO_BT_EXTERN_NF,	MSG_SYMINFO_BT_NONE_NF,
153 		MSG_SYMINFO_BT_PARENT_NF,	MSG_SYMINFO_BT_SELF_NF
154 	};
155 	static const conv_ds_msg_t ds_boundto_cf = {
156 	    CONV_DS_MSG_INIT(SYMINFO_BT_EXTERN, boundto_cf) };
157 	static const conv_ds_msg_t ds_boundto_cfnp = {
158 	    CONV_DS_MSG_INIT(SYMINFO_BT_EXTERN, boundto_cfnp) };
159 	static const conv_ds_msg_t ds_boundto_nf = {
160 	    CONV_DS_MSG_INIT(SYMINFO_BT_EXTERN, boundto_nf) };
161 
162 	/* Build NULL terminated return arrays for each string style */
163 	static const const conv_ds_t	*ds_cf[] = {
164 		CONV_DS_ADDR(ds_boundto_cf), NULL };
165 	static const const conv_ds_t	*ds_cfnp[] = {
166 		CONV_DS_ADDR(ds_boundto_cfnp), NULL };
167 	static const const conv_ds_t	*ds_nf[] = {
168 		CONV_DS_ADDR(ds_boundto_nf), NULL };
169 
170 	/* Select the strings to use */
171 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
172 	case CONV_FMT_ALT_CF:
173 		return (ds_cf);
174 	case CONV_FMT_ALT_NF:
175 		return (ds_nf);
176 	}
177 
178 	return (ds_cfnp);
179 }
180 
181 const char *
182 conv_syminfo_boundto(Half value, Conv_fmt_flags_t fmt_flags,
183     Conv_inv_buf_t *inv_buf)
184 {
185 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, value,
186 	    conv_syminfo_boundto_strings(fmt_flags), fmt_flags, inv_buf));
187 }
188 
189 conv_iter_ret_t
190 conv_iter_syminfo_boundto(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
191     void *uvalue)
192 {
193 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
194 	    conv_syminfo_boundto_strings(fmt_flags), func, uvalue));
195 }
196