xref: /titanic_44/usr/src/cmd/sgs/libconv/common/llib-lconv (revision a4aeef46cda1835da2b19f8f62b4526de6521e6c)
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 2010 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26/* LINTLIBRARY */
27/* PROTOLIB1 */
28
29#include	<stdlib.h>
30#include	<libelf.h>
31#include	<_machelf.h>
32#include	<sgs.h>
33#include	<libld.h>
34#include	<conv.h>
35
36/*
37 * Generic miscellaneous interfaces
38 */
39uchar_t		conv_check_native(char **, char **);
40const char	*conv_lddstub(int);
41int		conv_sys_eclass(void);
42int		conv_strproc_isspace(int);
43char		*conv_strproc_trim(char *);
44Boolean		conv_strproc_extract_value(char *, size_t, int, const char **);
45
46
47/*
48 * Generic core formatting and iteration functionality
49 */
50conv_iter_ret_t	_conv_iter_ds(conv_iter_osabi_t, Half, const conv_ds_t **,
51		    conv_iter_cb_t, void *, const char *);
52conv_iter_ret_t	_conv_iter_ds_msg(const conv_ds_msg_t *, conv_iter_cb_t,
53		    void *, const char *);
54conv_iter_ret_t	_conv_iter_msgarr(Conv_elfvalue_t, const Msg *, size_t,
55		    conv_iter_cb_t, void *, const char *);
56conv_iter_ret_t	_conv_iter_vd(const Val_desc *, conv_iter_cb_t,
57		    void *, const char *);
58conv_iter_ret_t	_conv_iter_vd2(conv_iter_osabi_t, Half, const Val_desc2 *,
59		    conv_iter_cb_t, void *, const char *);
60int		conv_iter_strtol_init(const char *, conv_strtol_uvalue_t *);
61conv_iter_ret_t	conv_iter_strtol(const char *, Conv_elfvalue_t, void *);
62const char	*_conv_map2str(Conv_inv_buf_t *, Conv_elfvalue_t,
63		    Conv_fmt_flags_t, size_t, const Msg *, const char *);
64const char	*_conv_map_ds(uchar_t, Half, Conv_elfvalue_t,
65		    const conv_ds_t **, Conv_fmt_flags_t, Conv_inv_buf_t *,
66		    const char *);
67const char	*_conv_map_vd2str(Conv_inv_buf_t *, Conv_elfvalue_t,
68		    Conv_fmt_flags_t, const Val_desc *, const char *);
69const char	*_conv_map_vd22str(Conv_inv_buf_t *, uchar_t, Half,
70		    Conv_elfvalue_t, Conv_fmt_flags_t, const Val_desc2 *,
71		    const char *);
72
73/*
74 * Generic formatting interfaces.
75 */
76const char	*conv_bnd_obj(uint_t, Conv_bnd_obj_buf_t *);
77const char	*conv_bnd_type(uint_t, Conv_bnd_type_buf_t *);
78const char	*conv_config_feat(int, Conv_config_feat_buf_t *);
79const char	*conv_config_obj(ushort_t, Conv_config_obj_buf_t *);
80const char	*conv_config_upm(const char *, const char *,
81		    const char *, size_t);
82const char	*conv_cnote_auxv_af(Word, Conv_fmt_flags_t,
83		    Conv_cnote_auxv_af_buf_t *);
84const char	*conv_cnote_auxv_type(Word, Conv_fmt_flags_t, Conv_inv_buf_t *);
85const char	*conv_cnote_cc_content(Lword, Conv_fmt_flags_t,
86		    Conv_cnote_cc_content_buf_t *);
87const char	*conv_cnote_errno(int, Conv_fmt_flags_t, Conv_inv_buf_t *);
88const char	*conv_cnote_fault(Word, Conv_fmt_flags_t, Conv_inv_buf_t *);
89const char	*conv_cnote_fltset(uint32_t *, int, Conv_fmt_flags_t,
90		    Conv_cnote_fltset_buf_t *);
91const char	*conv_cnote_old_pr_flags(int, Conv_fmt_flags_t,
92		    Conv_cnote_old_pr_flags_buf_t *);
93const char	*conv_cnote_pr_dmodel(Word, Conv_fmt_flags_t, Conv_inv_buf_t *);
94const char	*conv_cnote_pr_flags(int, Conv_fmt_flags_t,
95		    Conv_cnote_pr_flags_buf_t *);
96const char	*conv_cnote_proc_flag(int, Conv_fmt_flags_t,
97		    Conv_cnote_proc_flag_buf_t *);
98const char	*conv_cnote_pr_regname(Half, int, Conv_fmt_flags_t,
99		    Conv_inv_buf_t *inv_buf);
100const char	*conv_cnote_pr_stype(Word, Conv_fmt_flags_t, Conv_inv_buf_t *);
101const char	*conv_cnote_pr_what(short, short, Conv_fmt_flags_t,
102		    Conv_inv_buf_t *);
103const char	*conv_cnote_pr_why(short, Conv_fmt_flags_t, Conv_inv_buf_t *);
104const char	*conv_cnote_priv(int, Conv_fmt_flags_t, Conv_inv_buf_t *);
105const char	*conv_cnote_psetid(int, Conv_fmt_flags_t, Conv_inv_buf_t *);
106const char	*conv_cnote_sa_flags(int, Conv_fmt_flags_t,
107		    Conv_cnote_sa_flags_buf_t *);
108const char	*conv_cnote_signal(Word, Conv_fmt_flags_t, Conv_inv_buf_t *);
109const char	*conv_cnote_si_code(Half, int, int, Conv_fmt_flags_t,
110		    Conv_inv_buf_t *);
111const char	*conv_cnote_sigset(uint32_t *, int, Conv_fmt_flags_t,
112		    Conv_cnote_sigset_buf_t *);
113const char	*conv_cnote_ss_flags(int, Conv_fmt_flags_t,
114		    Conv_cnote_ss_flags_buf_t *);
115const char	*conv_cnote_syscall(Word, Conv_fmt_flags_t, Conv_inv_buf_t *);
116const char	*conv_cnote_sysset(uint32_t *, int, Conv_fmt_flags_t,
117		    Conv_cnote_sysset_buf_t *);
118const char	*conv_cnote_type(Word, Conv_fmt_flags_t, Conv_inv_buf_t *);
119const char	*conv_def_tag(Symref, Conv_inv_buf_t *);
120const char	*conv_demangle_name(const char *);
121const char	*conv_dl_flag(int, Conv_fmt_flags_t, Conv_dl_flag_buf_t *);
122const char	*conv_dl_mode(int, int, Conv_dl_mode_buf_t *);
123const char	*conv_dwarf_cfa(uchar_t, Conv_fmt_flags_t, Conv_inv_buf_t *);
124const char	*conv_dwarf_ehe(uint_t, Conv_dwarf_ehe_buf_t *);
125const char	*conv_dwarf_regname(Half, Word, Conv_fmt_flags_t,
126		    int *, Conv_inv_buf_t *);
127const char	*conv_ehdr_abivers(uchar_t, Word, Conv_fmt_flags_t,
128		    Conv_inv_buf_t *);
129const char	*conv_ehdr_class(uchar_t, Conv_fmt_flags_t, Conv_inv_buf_t *);
130const char	*conv_ehdr_data(uchar_t, Conv_fmt_flags_t, Conv_inv_buf_t *);
131const char	*conv_ehdr_flags(Half, Word, Conv_fmt_flags_t,
132		    Conv_ehdr_flags_buf_t *);
133const char	*conv_ehdr_mach(Half, Conv_fmt_flags_t, Conv_inv_buf_t *);
134const char	*conv_ehdr_osabi(uchar_t, Conv_fmt_flags_t, Conv_inv_buf_t *);
135const char	*conv_ehdr_type(uchar_t, Half, Conv_fmt_flags_t,
136		    Conv_inv_buf_t *);
137const char	*conv_ehdr_vers(Word, Conv_fmt_flags_t, Conv_inv_buf_t *);
138const char	*conv_elfdata_type(Elf_Type, Conv_inv_buf_t *);
139const char	*conv_ent_flags(ec_flags_t, Conv_ent_flags_buf_t *);
140const char	*conv_ent_filcmp(Word, Conv_fmt_flags_t, Conv_inv_buf_t *);
141const char	*conv_grphdl_flags(uint_t, Conv_grphdl_flags_buf_t *);
142const char	*conv_grpdesc_flags(uint_t, Conv_grpdesc_flags_buf_t *);
143Isa_desc	*conv_isalist(void);
144const char	*conv_mapfile_version(Word, Conv_fmt_flags_t,
145		    Conv_inv_buf_t *);
146const char	*conv_phdr_flags(uchar_t, Word, Conv_fmt_flags_t,
147		    Conv_phdr_flags_buf_t *);
148const char	*conv_phdr_type(uchar_t, Half, Word, Conv_fmt_flags_t,
149		    Conv_inv_buf_t *);
150const char	*conv_reject_desc(Rej_desc *, Conv_reject_desc_buf_t *,
151		    Half mach);
152const char	*conv_reloc_type(Half, Word, Conv_fmt_flags_t,
153		    Conv_inv_buf_t *);
154const char	*conv_reloc_type_static(Half, Word, Conv_fmt_flags_t);
155const char	*conv_reloc_386_type(Word, Conv_fmt_flags_t, Conv_inv_buf_t *);
156const char	*conv_reloc_amd64_type(Word, Conv_fmt_flags_t,
157		    Conv_inv_buf_t *);
158const char	*conv_reloc_SPARC_type(Word, Conv_fmt_flags_t,
159		    Conv_inv_buf_t *);
160const char	*conv_sec_type(uchar_t, Half, Word, Conv_fmt_flags_t,
161		    Conv_inv_buf_t *);
162const char	*conv_seg_flags(Half, Conv_seg_flags_buf_t *);
163void		conv_str_to_c_literal(const char *buf, size_t n,
164		    Conv_str_to_c_literal_func_t *cb_func, void *uvalue);
165const char	*conv_sym_info_bind(uchar_t, Conv_fmt_flags_t,
166		    Conv_inv_buf_t *);
167const char	*conv_sym_info_type(Half, uchar_t, Conv_fmt_flags_t,
168		    Conv_inv_buf_t *);
169const char	*conv_sym_shndx(uchar_t, Half, Half, Conv_fmt_flags_t,
170		    Conv_inv_buf_t *);
171const char	*conv_sym_other(uchar_t, Conv_inv_buf_t *);
172const char	*conv_sym_other_vis(uchar_t, Conv_fmt_flags_t,
173		    Conv_inv_buf_t *);
174const char	*conv_syminfo_boundto(Half, Conv_fmt_flags_t, Conv_inv_buf_t *);
175const char	*conv_syminfo_flags(Half, Conv_fmt_flags_t,
176		    Conv_syminfo_flags_buf_t *);
177const char	*conv_time(struct timeval *, struct timeval *,
178		    Conv_time_buf_t *);
179Uts_desc	*conv_uts(void);
180const char	*conv_ver_flags(Half, Conv_fmt_flags_t, Conv_ver_flags_buf_t *);
181const char	*conv_ver_index(Versym, int, Conv_inv_buf_t *);
182
183
184/*
185 * Generic iteration interfaces.
186 */
187conv_iter_ret_t	conv_iter_cap_tags(Conv_fmt_flags_t, conv_iter_cb_t, void *);
188conv_iter_ret_t	conv_iter_cap_val_hw1(Half, Conv_fmt_flags_t,
189		    conv_iter_cb_t, void *);
190conv_iter_ret_t	conv_iter_cap_val_sf1(Conv_fmt_flags_t, conv_iter_cb_t, void *);
191
192conv_iter_ret_t	conv_iter_dyn_feature1(Conv_fmt_flags_t,
193		    conv_iter_cb_t, void *);
194conv_iter_ret_t	conv_iter_dyn_flag(Conv_fmt_flags_t, conv_iter_cb_t, void *);
195conv_iter_ret_t	conv_iter_dyn_flag1(Conv_fmt_flags_t, conv_iter_cb_t, void *);
196conv_iter_ret_t	conv_iter_dyn_posflag1(Conv_fmt_flags_t,
197		    conv_iter_cb_t, void *);
198conv_iter_ret_t	conv_iter_dyn_tag(conv_iter_osabi_t, Half,
199		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
200
201conv_iter_ret_t	conv_iter_ehdr_abivers(conv_iter_osabi_t,
202		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
203conv_iter_ret_t	conv_iter_ehdr_class(Conv_fmt_flags_t, conv_iter_cb_t, void *);
204conv_iter_ret_t	conv_iter_ehdr_data(Conv_fmt_flags_t, conv_iter_cb_t, void *);
205conv_iter_ret_t	conv_iter_ehdr_eident(Conv_fmt_flags_t, conv_iter_cb_t, void *);
206conv_iter_ret_t	conv_iter_ehdr_flags(Half, Conv_fmt_flags_t,
207		    conv_iter_cb_t, void *);
208conv_iter_ret_t	conv_iter_ehdr_mach(Conv_fmt_flags_t, conv_iter_cb_t, void *);
209conv_iter_ret_t	conv_iter_ehdr_osabi(Conv_fmt_flags_t, conv_iter_cb_t, void *);
210conv_iter_ret_t	conv_iter_ehdr_type(conv_iter_osabi_t, Conv_fmt_flags_t,
211		    conv_iter_cb_t, void *);
212conv_iter_ret_t	conv_iter_ehdr_vers(Conv_fmt_flags_t, conv_iter_cb_t, void *);
213
214conv_iter_ret_t	conv_iter_phdr_flags(conv_iter_osabi_t,
215		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
216conv_iter_ret_t	conv_iter_phdr_type(conv_iter_osabi_t, Conv_fmt_flags_t,
217		    conv_iter_cb_t, void *);
218
219conv_iter_ret_t	conv_iter_sec_flags(conv_iter_osabi_t, Half,
220		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
221conv_iter_ret_t	conv_iter_sec_symtab(conv_iter_osabi_t,
222		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
223conv_iter_ret_t	conv_iter_sec_type(conv_iter_osabi_t, Half,
224		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
225
226conv_iter_ret_t	conv_iter_sym_info_bind(Conv_fmt_flags_t,
227		    conv_iter_cb_t, void *);
228conv_iter_ret_t	conv_iter_sym_other_vis(Conv_fmt_flags_t,
229		    conv_iter_cb_t, void *);
230conv_iter_ret_t	conv_iter_sym_shndx(conv_iter_osabi_t, Half,
231		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
232conv_iter_ret_t	conv_iter_sym_info_type(Half, Conv_fmt_flags_t,
233		    conv_iter_cb_t, void *);
234
235conv_iter_ret_t	conv_iter_syminfo_boundto(Conv_fmt_flags_t,
236		    conv_iter_cb_t, void *);
237conv_iter_ret_t	conv_iter_syminfo_flags(Conv_fmt_flags_t,
238			    conv_iter_cb_t, void *);
239
240
241/*
242 * ELFCLASS-specific core formatting functionality
243 */
244int		_conv_expn_field(CONV_EXPN_FIELD_ARG *,
245		    const Val_desc *, Conv_fmt_flags_t, const char *);
246int		_conv_expn_field2(CONV_EXPN_FIELD_ARG *, uchar_t,
247		    Half, const Val_desc2 *, Conv_fmt_flags_t, const char *);
248const char	*conv_invalid_val(Conv_inv_buf_t *, Xword, Conv_fmt_flags_t);
249
250
251/*
252 * Define all class specific routines.
253 */
254const char	*conv32_cap_tag(Elf32_Word, Conv_fmt_flags_t,
255		    Conv_inv_buf_t *);
256const char	*conv64_cap_tag(Elf64_Xword, Conv_fmt_flags_t,
257		    Conv_inv_buf_t *);
258const char	*conv32_cap_val(Elf32_Word, Elf32_Word, Half,
259		    Conv_cap_val_buf_t *);
260const char	*conv64_cap_val(Elf64_Xword, Elf64_Xword, Half,
261		    Conv_cap_val_buf_t *);
262const char	*conv32_cap_val_hw1(Elf32_Word, Half, Conv_fmt_flags_t,
263		    Conv_cap_val_hw1_buf_t *);
264const char	*conv64_cap_val_hw1(Elf64_Xword, Half, Conv_fmt_flags_t,
265		    Conv_cap_val_hw1_buf_t *);
266const char	*conv32_cap_val_sf1(Elf32_Word, Half, Conv_fmt_flags_t,
267		    Conv_cap_val_sf1_buf_t *);
268const char	*conv64_cap_val_sf1(Elf64_Xword, Half, Conv_fmt_flags_t,
269		    Conv_cap_val_sf1_buf_t *);
270const char	*conv32_dyn_flag1(Elf32_Word, Conv_fmt_flags_t,
271		    Conv_dyn_flag1_buf_t *);
272const char	*conv64_dyn_flag1(Elf64_Xword, Conv_fmt_flags_t,
273		    Conv_dyn_flag1_buf_t *);
274const char	*conv32_dyn_flag(Elf32_Word, int, Conv_dyn_flag_buf_t *);
275const char	*conv64_dyn_flag(Elf64_Xword, int, Conv_dyn_flag_buf_t *);
276const char	*conv32_dyn_posflag1(Elf32_Word, int,
277		    Conv_dyn_posflag1_buf_t *);
278const char	*conv64_dyn_posflag1(Elf64_Xword, int,
279		    Conv_dyn_posflag1_buf_t *);
280const char	*conv32_dyn_tag(Elf32_Word, uchar_t, Elf32_Half,
281		    Conv_fmt_flags_t, Conv_inv_buf_t *);
282const char	*conv64_dyn_tag(Elf64_Xword, uchar_t, Elf64_Half,
283		    Conv_fmt_flags_t, Conv_inv_buf_t *);
284const char	*conv32_dyn_feature1(Elf32_Word, int,
285		    Conv_dyn_feature1_buf_t *);
286const char	*conv64_dyn_feature1(Elf64_Xword, int,
287		    Conv_dyn_feature1_buf_t *);
288const char	*conv32_sec_flags(uchar_t, Half, Elf32_Word, Conv_fmt_flags_t,
289		    Conv_sec_flags_buf_t *);
290const char	*conv64_sec_flags(uchar_t, Half, Elf64_Xword, Conv_fmt_flags_t,
291		    Conv_sec_flags_buf_t *);
292const char	*conv32_sec_linkinfo(Elf32_Word, Elf32_Word,
293		    Conv_inv_buf_t *);
294const char	*conv64_sec_linkinfo(Elf64_Word, Elf64_Xword,
295		    Conv_inv_buf_t *);
296const char	*conv32_sym_value(Elf32_Half, uchar_t, Elf32_Addr,
297		    Conv_inv_buf_t *);
298const char	*conv64_sym_value(Elf64_Half, uchar_t, Elf64_Addr,
299		    Conv_inv_buf_t *);
300const char	*conv32_sym_SPARC_value(Elf32_Addr, int, Conv_inv_buf_t *);
301const char	*conv64_sym_SPARC_value(Elf64_Addr, int, Conv_inv_buf_t *);
302