xref: /titanic_41/usr/src/cmd/sgs/libconv/common/syminfo.c (revision 430b4c467020edf2445feb0c21db01c88b86243a)
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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 /*
27  * String conversion routines for syminfo attributes.
28  */
29 #include	<stdio.h>
30 #include	<_machelf.h>
31 #include	"_conv.h"
32 #include	"syminfo_msg.h"
33 
34 
35 
36 static const Val_desc *
37 conv_syminfo_flags_strings(Conv_fmt_flags_t fmt_flags)
38 {
39 #define	FLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
40 	MSG_SYMINFO_FLG_DIRECT_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
41 	MSG_SYMINFO_FLG_FILTER_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
42 	MSG_SYMINFO_FLG_COPY_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
43 	MSG_SYMINFO_FLG_LAZYLOAD_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
44 	MSG_SYMINFO_FLG_DIRECTBIND_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
45 	MSG_SYMINFO_FLG_NOEXTDIRECT_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
46 	MSG_SYMINFO_FLG_AUXILIARY_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
47 	MSG_SYMINFO_FLG_INTERPOSE_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
48 	MSG_SYMINFO_FLG_CAP_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
49 	MSG_SYMINFO_FLG_DEFERRED_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
50 	CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
51 
52 	/*
53 	 * Ensure that Conv_syminfo_flags_buf_t is large enough:
54 	 *
55 	 * FLAGSZ is the real minimum size of the buffer required by
56 	 * conv_syminfo_flags(). However, Conv_syminfo_flags_buf_t uses
57 	 * CONV_SYMINFO_FLAGS_BUFSIZE to set the buffer size. We do things
58 	 * this way because the definition of FLAGSZ uses information that
59 	 * is not available in the environment of other programs that include
60 	 * the conv.h header file.
61 	 */
62 #if (CONV_SYMINFO_FLAGS_BUFSIZE != FLAGSZ) && !defined(__lint)
63 #define	REPORT_BUFSIZE FLAGSZ
64 #include "report_bufsize.h"
65 #error "CONV_SYMINFO_FLAGS_BUFSIZE does not match FLAGSZ"
66 #endif
67 
68 	static const Val_desc vda_cf[] = {
69 		{ SYMINFO_FLG_DIRECT,	MSG_SYMINFO_FLG_DIRECT_CF },
70 		{ SYMINFO_FLG_FILTER,	MSG_SYMINFO_FLG_FILTER_CF },
71 		{ SYMINFO_FLG_COPY,	MSG_SYMINFO_FLG_COPY_CF },
72 		{ SYMINFO_FLG_LAZYLOAD,	MSG_SYMINFO_FLG_LAZYLOAD_CF },
73 		{ SYMINFO_FLG_DIRECTBIND, MSG_SYMINFO_FLG_DIRECTBIND_CF },
74 		{ SYMINFO_FLG_NOEXTDIRECT, MSG_SYMINFO_FLG_NOEXTDIRECT_CF },
75 		{ SYMINFO_FLG_AUXILIARY, MSG_SYMINFO_FLG_AUXILIARY_CF },
76 		{ SYMINFO_FLG_INTERPOSE, MSG_SYMINFO_FLG_INTERPOSE_CF },
77 		{ SYMINFO_FLG_CAP,	MSG_SYMINFO_FLG_CAP_CF },
78 		{ SYMINFO_FLG_DEFERRED,	MSG_SYMINFO_FLG_DEFERRED_CF },
79 		{ 0 }
80 	};
81 	static const Val_desc vda_cfnp[] = {
82 		{ SYMINFO_FLG_DIRECT,	MSG_SYMINFO_FLG_DIRECT_CFNP },
83 		{ SYMINFO_FLG_FILTER,	MSG_SYMINFO_FLG_FILTER_CFNP },
84 		{ SYMINFO_FLG_COPY,	MSG_SYMINFO_FLG_COPY_CFNP },
85 		{ SYMINFO_FLG_LAZYLOAD,	MSG_SYMINFO_FLG_LAZYLOAD_CFNP },
86 		{ SYMINFO_FLG_DIRECTBIND, MSG_SYMINFO_FLG_DIRECTBIND_CFNP },
87 		{ SYMINFO_FLG_NOEXTDIRECT, MSG_SYMINFO_FLG_NOEXTDIRECT_CFNP },
88 		{ SYMINFO_FLG_AUXILIARY, MSG_SYMINFO_FLG_AUXILIARY_CFNP },
89 		{ SYMINFO_FLG_INTERPOSE, MSG_SYMINFO_FLG_INTERPOSE_CFNP },
90 		{ SYMINFO_FLG_CAP,	MSG_SYMINFO_FLG_CAP_CFNP },
91 		{ SYMINFO_FLG_DEFERRED,	MSG_SYMINFO_FLG_DEFERRED_CFNP },
92 		{ 0 }
93 	};
94 	static const Val_desc vda_nf[] = {
95 		{ SYMINFO_FLG_DIRECT,	MSG_SYMINFO_FLG_DIRECT_NF },
96 		{ SYMINFO_FLG_FILTER,	MSG_SYMINFO_FLG_FILTER_NF },
97 		{ SYMINFO_FLG_COPY,	MSG_SYMINFO_FLG_COPY_NF },
98 		{ SYMINFO_FLG_LAZYLOAD,	MSG_SYMINFO_FLG_LAZYLOAD_NF },
99 		{ SYMINFO_FLG_DIRECTBIND, MSG_SYMINFO_FLG_DIRECTBIND_NF },
100 		{ SYMINFO_FLG_NOEXTDIRECT, MSG_SYMINFO_FLG_NOEXTDIRECT_NF },
101 		{ SYMINFO_FLG_AUXILIARY, MSG_SYMINFO_FLG_AUXILIARY_NF },
102 		{ SYMINFO_FLG_INTERPOSE, MSG_SYMINFO_FLG_INTERPOSE_NF },
103 		{ SYMINFO_FLG_CAP,	MSG_SYMINFO_FLG_CAP_NF },
104 		{ SYMINFO_FLG_DEFERRED,	MSG_SYMINFO_FLG_DEFERRED_NF },
105 		{ 0 }
106 	};
107 
108 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
109 	case CONV_FMT_ALT_CF:
110 		return (vda_cf);
111 	case CONV_FMT_ALT_NF:
112 		return (vda_nf);
113 	}
114 
115 	return (vda_cfnp);
116 }
117 
118 
119 const char *
120 conv_syminfo_flags(Half flags, Conv_fmt_flags_t fmt_flags,
121     Conv_syminfo_flags_buf_t *syminfo_flags_buf)
122 {
123 	static CONV_EXPN_FIELD_ARG conv_arg = {
124 	    NULL, sizeof (syminfo_flags_buf->buf) };
125 
126 	if (flags == 0)
127 		return (MSG_ORIG(MSG_GBL_ZERO));
128 
129 	conv_arg.buf = syminfo_flags_buf->buf;
130 	conv_arg.oflags = conv_arg.rflags = flags;
131 	conv_arg.prefix = conv_arg.suffix = NULL;
132 	(void) conv_expn_field(&conv_arg,
133 	    conv_syminfo_flags_strings(fmt_flags), fmt_flags);
134 
135 	return ((const char *)syminfo_flags_buf->buf);
136 }
137 
138 conv_iter_ret_t
139 conv_iter_syminfo_flags(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
140     void *uvalue)
141 {
142 	return (conv_iter_vd(conv_syminfo_flags_strings(fmt_flags),
143 	    func, uvalue));
144 }
145 
146 
147 static const conv_ds_t **
148 conv_syminfo_boundto_strings(Conv_fmt_flags_t fmt_flags)
149 {
150 	static const Msg	boundto_cf[] = {
151 		MSG_SYMINFO_BT_EXTERN_CF,	MSG_SYMINFO_BT_NONE_CF,
152 		MSG_SYMINFO_BT_PARENT_CF,	MSG_SYMINFO_BT_SELF_CF
153 	};
154 	static const Msg	boundto_cfnp[] = {
155 		MSG_SYMINFO_BT_EXTERN_CFNP,	MSG_SYMINFO_BT_NONE_CFNP,
156 		MSG_SYMINFO_BT_PARENT_CFNP,	MSG_SYMINFO_BT_SELF_CFNP
157 	};
158 	static const Msg	boundto_nf[] = {
159 		MSG_SYMINFO_BT_EXTERN_NF,	MSG_SYMINFO_BT_NONE_NF,
160 		MSG_SYMINFO_BT_PARENT_NF,	MSG_SYMINFO_BT_SELF_NF
161 	};
162 	static const conv_ds_msg_t ds_boundto_cf = {
163 	    CONV_DS_MSG_INIT(SYMINFO_BT_EXTERN, boundto_cf) };
164 	static const conv_ds_msg_t ds_boundto_cfnp = {
165 	    CONV_DS_MSG_INIT(SYMINFO_BT_EXTERN, boundto_cfnp) };
166 	static const conv_ds_msg_t ds_boundto_nf = {
167 	    CONV_DS_MSG_INIT(SYMINFO_BT_EXTERN, boundto_nf) };
168 
169 	/* Build NULL terminated return arrays for each string style */
170 	static const const conv_ds_t	*ds_cf[] = {
171 		CONV_DS_ADDR(ds_boundto_cf), NULL };
172 	static const const conv_ds_t	*ds_cfnp[] = {
173 		CONV_DS_ADDR(ds_boundto_cfnp), NULL };
174 	static const const conv_ds_t	*ds_nf[] = {
175 		CONV_DS_ADDR(ds_boundto_nf), NULL };
176 
177 	/* Select the strings to use */
178 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
179 	case CONV_FMT_ALT_CF:
180 		return (ds_cf);
181 	case CONV_FMT_ALT_NF:
182 		return (ds_nf);
183 	}
184 
185 	return (ds_cfnp);
186 }
187 
188 const char *
189 conv_syminfo_boundto(Half value, Conv_fmt_flags_t fmt_flags,
190     Conv_inv_buf_t *inv_buf)
191 {
192 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, value,
193 	    conv_syminfo_boundto_strings(fmt_flags), fmt_flags, inv_buf));
194 }
195 
196 conv_iter_ret_t
197 conv_iter_syminfo_boundto(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
198     void *uvalue)
199 {
200 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
201 	    conv_syminfo_boundto_strings(fmt_flags), func, uvalue));
202 }
203