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