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