xref: /titanic_50/usr/src/cmd/sgs/libconv/common/llib-lconv (revision 636423db672c14451a65835f534789270ebd4dc9)
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);
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_grphdl_flags(uint_t, Conv_grphdl_flags_buf_t *);
140const char	*conv_grpdesc_flags(uint_t, Conv_grpdesc_flags_buf_t *);
141Isa_desc	*conv_isalist(void);
142const char	*conv_phdr_flags(uchar_t, Word, Conv_fmt_flags_t,
143		    Conv_phdr_flags_buf_t *);
144const char	*conv_phdr_type(uchar_t, Half, Word, Conv_fmt_flags_t,
145		    Conv_inv_buf_t *);
146const char	*conv_reject_desc(Rej_desc *, Conv_reject_desc_buf_t *,
147		    Half mach);
148const char	*conv_reloc_type(Half, Word, Conv_fmt_flags_t,
149		    Conv_inv_buf_t *);
150const char	*conv_reloc_type_static(Half, Word, Conv_fmt_flags_t);
151const char	*conv_reloc_386_type(Word, Conv_fmt_flags_t, Conv_inv_buf_t *);
152const char	*conv_reloc_amd64_type(Word, Conv_fmt_flags_t,
153		    Conv_inv_buf_t *);
154const char	*conv_reloc_SPARC_type(Word, Conv_fmt_flags_t,
155		    Conv_inv_buf_t *);
156const char	*conv_sec_type(uchar_t, Half, Word, Conv_fmt_flags_t,
157		    Conv_inv_buf_t *);
158const char	*conv_seg_flags(Half, Conv_seg_flags_buf_t *);
159void		conv_str_to_c_literal(const char *buf, size_t n,
160		    Conv_str_to_c_literal_func_t *cb_func, void *uvalue);
161const char	*conv_sym_info_bind(uchar_t, Conv_fmt_flags_t,
162		    Conv_inv_buf_t *);
163const char	*conv_sym_info_type(Half, uchar_t, Conv_fmt_flags_t,
164		    Conv_inv_buf_t *);
165const char	*conv_sym_shndx(uchar_t, Half, Half, Conv_fmt_flags_t,
166		    Conv_inv_buf_t *);
167const char	*conv_sym_other(uchar_t, Conv_inv_buf_t *);
168const char	*conv_sym_other_vis(uchar_t, Conv_fmt_flags_t,
169		    Conv_inv_buf_t *);
170const char	*conv_syminfo_boundto(Half, Conv_fmt_flags_t, Conv_inv_buf_t *);
171const char	*conv_syminfo_flags(Half, Conv_fmt_flags_t,
172		    Conv_syminfo_flags_buf_t *);
173const char	*conv_time(struct timeval *, struct timeval *,
174		    Conv_time_buf_t *);
175Uts_desc	*conv_uts(void);
176const char	*conv_ver_flags(Half, Conv_fmt_flags_t, Conv_ver_flags_buf_t *);
177const char	*conv_ver_index(Versym, int, Conv_inv_buf_t *);
178
179
180/*
181 * Generic iteration interfaces.
182 */
183conv_iter_ret_t	conv_iter_cap_tags(Conv_fmt_flags_t, conv_iter_cb_t, void *);
184conv_iter_ret_t	conv_iter_cap_val_hw1(Half, Conv_fmt_flags_t,
185		    conv_iter_cb_t, void *);
186conv_iter_ret_t	conv_iter_cap_val_sf1(Conv_fmt_flags_t, conv_iter_cb_t, void *);
187
188conv_iter_ret_t	conv_iter_dyn_feature1(Conv_fmt_flags_t,
189		    conv_iter_cb_t, void *);
190conv_iter_ret_t	conv_iter_dyn_flag(Conv_fmt_flags_t, conv_iter_cb_t, void *);
191conv_iter_ret_t	conv_iter_dyn_flag1(Conv_fmt_flags_t, conv_iter_cb_t, void *);
192conv_iter_ret_t	conv_iter_dyn_posflag1(Conv_fmt_flags_t,
193		    conv_iter_cb_t, void *);
194conv_iter_ret_t	conv_iter_dyn_tag(conv_iter_osabi_t, Half,
195		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
196
197conv_iter_ret_t	conv_iter_ehdr_abivers(conv_iter_osabi_t,
198		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
199conv_iter_ret_t	conv_iter_ehdr_class(Conv_fmt_flags_t, conv_iter_cb_t, void *);
200conv_iter_ret_t	conv_iter_ehdr_data(Conv_fmt_flags_t, conv_iter_cb_t, void *);
201conv_iter_ret_t	conv_iter_ehdr_eident(Conv_fmt_flags_t, conv_iter_cb_t, void *);
202conv_iter_ret_t	conv_iter_ehdr_flags(Half, Conv_fmt_flags_t,
203		    conv_iter_cb_t, void *);
204conv_iter_ret_t	conv_iter_ehdr_mach(Conv_fmt_flags_t, conv_iter_cb_t, void *);
205conv_iter_ret_t	conv_iter_ehdr_osabi(Conv_fmt_flags_t, conv_iter_cb_t, void *);
206conv_iter_ret_t	conv_iter_ehdr_type(conv_iter_osabi_t, Conv_fmt_flags_t,
207		    conv_iter_cb_t, void *);
208conv_iter_ret_t	conv_iter_ehdr_vers(Conv_fmt_flags_t, conv_iter_cb_t, void *);
209
210conv_iter_ret_t	conv_iter_phdr_flags(conv_iter_osabi_t,
211		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
212conv_iter_ret_t	conv_iter_phdr_type(conv_iter_osabi_t, Conv_fmt_flags_t,
213		    conv_iter_cb_t, void *);
214
215conv_iter_ret_t	conv_iter_sec_flags(conv_iter_osabi_t, Half,
216		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
217conv_iter_ret_t	conv_iter_sec_symtab(conv_iter_osabi_t,
218		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
219conv_iter_ret_t	conv_iter_sec_type(conv_iter_osabi_t, Half,
220		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
221
222conv_iter_ret_t	conv_iter_sym_info_bind(Conv_fmt_flags_t,
223		    conv_iter_cb_t, void *);
224conv_iter_ret_t	conv_iter_sym_other_vis(Conv_fmt_flags_t,
225		    conv_iter_cb_t, void *);
226conv_iter_ret_t	conv_iter_sym_shndx(conv_iter_osabi_t, Half,
227		    Conv_fmt_flags_t, conv_iter_cb_t, void *);
228conv_iter_ret_t	conv_iter_sym_info_type(Half, Conv_fmt_flags_t,
229		    conv_iter_cb_t, void *);
230
231conv_iter_ret_t	conv_iter_syminfo_boundto(Conv_fmt_flags_t,
232		    conv_iter_cb_t, void *);
233conv_iter_ret_t	conv_iter_syminfo_flags(Conv_fmt_flags_t,
234			    conv_iter_cb_t, void *);
235
236
237/*
238 * ELFCLASS-specific core formatting functionality
239 */
240int		_conv_expn_field(CONV_EXPN_FIELD_ARG *,
241		    const Val_desc *, Conv_fmt_flags_t, const char *);
242int		_conv_expn_field2(CONV_EXPN_FIELD_ARG *, uchar_t,
243		    Half, const Val_desc2 *, Conv_fmt_flags_t, const char *);
244const char	*conv_invalid_val(Conv_inv_buf_t *, Xword, Conv_fmt_flags_t);
245
246
247/*
248 * Define all class specific routines.
249 */
250const char	*conv32_cap_tag(Elf32_Word, Conv_fmt_flags_t,
251		    Conv_inv_buf_t *);
252const char	*conv64_cap_tag(Elf64_Xword, Conv_fmt_flags_t,
253		    Conv_inv_buf_t *);
254const char	*conv32_cap_val(Elf32_Word, Elf32_Word, Half,
255		    Conv_cap_val_buf_t *);
256const char	*conv64_cap_val(Elf64_Xword, Elf64_Xword, Half,
257		    Conv_cap_val_buf_t *);
258const char	*conv32_cap_val_hw1(Elf32_Word, Half, Conv_fmt_flags_t,
259		    Conv_cap_val_hw1_buf_t *);
260const char	*conv64_cap_val_hw1(Elf64_Xword, Half, Conv_fmt_flags_t,
261		    Conv_cap_val_hw1_buf_t *);
262const char	*conv32_cap_val_sf1(Elf32_Word, Half, Conv_fmt_flags_t,
263		    Conv_cap_val_sf1_buf_t *);
264const char	*conv64_cap_val_sf1(Elf64_Xword, Half, Conv_fmt_flags_t,
265		    Conv_cap_val_sf1_buf_t *);
266const char	*conv32_dyn_flag1(Elf32_Word, Conv_fmt_flags_t,
267		    Conv_dyn_flag1_buf_t *);
268const char	*conv64_dyn_flag1(Elf64_Xword, Conv_fmt_flags_t,
269		    Conv_dyn_flag1_buf_t *);
270const char	*conv32_dyn_flag(Elf32_Word, int, Conv_dyn_flag_buf_t *);
271const char	*conv64_dyn_flag(Elf64_Xword, int, Conv_dyn_flag_buf_t *);
272const char	*conv32_dyn_posflag1(Elf32_Word, int,
273		    Conv_dyn_posflag1_buf_t *);
274const char	*conv64_dyn_posflag1(Elf64_Xword, int,
275		    Conv_dyn_posflag1_buf_t *);
276const char	*conv32_dyn_tag(Elf32_Word, uchar_t, Elf32_Half,
277		    Conv_fmt_flags_t, Conv_inv_buf_t *);
278const char	*conv64_dyn_tag(Elf64_Xword, uchar_t, Elf64_Half,
279		    Conv_fmt_flags_t, Conv_inv_buf_t *);
280const char	*conv32_dyn_feature1(Elf32_Word, int,
281		    Conv_dyn_feature1_buf_t *);
282const char	*conv64_dyn_feature1(Elf64_Xword, int,
283		    Conv_dyn_feature1_buf_t *);
284const char	*conv32_sec_flags(uchar_t, Half, Elf32_Word, Conv_fmt_flags_t,
285		    Conv_sec_flags_buf_t *);
286const char	*conv64_sec_flags(uchar_t, Half, Elf64_Xword, Conv_fmt_flags_t,
287		    Conv_sec_flags_buf_t *);
288const char	*conv32_sec_linkinfo(Elf32_Word, Elf32_Word,
289		    Conv_inv_buf_t *);
290const char	*conv64_sec_linkinfo(Elf64_Word, Elf64_Xword,
291		    Conv_inv_buf_t *);
292const char	*conv32_sym_value(Elf32_Half, uchar_t, Elf32_Addr,
293		    Conv_inv_buf_t *);
294const char	*conv64_sym_value(Elf64_Half, uchar_t, Elf64_Addr,
295		    Conv_inv_buf_t *);
296const char	*conv32_sym_SPARC_value(Elf32_Addr, int, Conv_inv_buf_t *);
297const char	*conv64_sym_SPARC_value(Elf64_Addr, int, Conv_inv_buf_t *);
298