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