conv.h revision 3850:71162a8a771b
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) 1988 AT&T 24 * All Rights Reserved 25 * 26 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 27 * Use is subject to license terms. 28 */ 29 30#ifndef _CONV_H 31#define _CONV_H 32 33#pragma ident "%Z%%M% %I% %E% SMI" 34 35/* 36 * Global include file for conversion library. 37 */ 38 39#include <stdlib.h> 40#include <libelf.h> 41#include <dlfcn.h> 42#include <libld.h> 43#include <sgs.h> 44#include <machdep.h> 45 46#ifdef __cplusplus 47extern "C" { 48#endif 49 50/* 51 * Configuration features available - maintained here (instead of debug.h) 52 * to save libconv from having to include debug.h which results in numerous 53 * "declared but not used or defined" lint errors. 54 */ 55#define CONF_EDLIBPATH 0x000100 /* ELF default library path */ 56#define CONF_ESLIBPATH 0x000200 /* ELF secure library path */ 57#define CONF_ADLIBPATH 0x000400 /* AOUT default library path */ 58#define CONF_ASLIBPATH 0x000800 /* AOUT secure library path */ 59#define CONF_DIRCFG 0x001000 /* directory configuration available */ 60#define CONF_OBJALT 0x002000 /* object alternatives available */ 61#define CONF_MEMRESV 0x004000 /* memory reservation required */ 62#define CONF_ENVS 0x008000 /* environment variables available */ 63#define CONF_FLTR 0x010000 /* filter information available */ 64#define CONF_FEATMSK 0xffff00 65 66/* 67 * Various values that can't be matched to a symbolic definition are converted 68 * to a numeric string. Each function that may require this fallback maintains 69 * its own static string buffer, as many conversion routines may be called for 70 * one final diagnostic. See conv_invalid_val(). 71 * 72 * The string size reflects the largest possible decimal number plus a trailing 73 * null. Typically however, values are hex with a leading "0x". 74 */ 75#if defined(_ELF64) 76#define CONV_INV_STRSIZE 22 77#else 78#define CONV_INV_STRSIZE 12 79#endif 80 81/* 82 * Some libconv routines require the caller to supply the buffer used by 83 * conv_invalid_val(). 84 */ 85typedef char Conv_inv_buf_t[CONV_INV_STRSIZE]; 86 87/* 88 * Flags that alter standard formatting for conversion routines. 89 */ 90#define CONV_FMT_DECIMAL 0x01 /* conv_invalid_val() should print */ 91 /* integer print as decimal */ 92 /* (default is hex) */ 93#define CONV_FMT_SPACE 0x02 /* conv_invalid_val() should append */ 94 /* a space after the number. */ 95#define CONV_FMT_ALTDUMP 0x04 /* Output strings using the versions */ 96 /* used by the dump program. */ 97#define CONV_FMT_ALTFILE 0x08 /* Output strings in the form used */ 98 /* by the file(1) command */ 99#define CONV_FMT_ALTCRLE 0x10 /* Output strings in the form used */ 100 /* by the crle(1) command */ 101 102/* 103 * Mask of CONV_FMT bits that reflect a desire to use alternate strings. 104 */ 105#define CONV_FMTALTMASK (CONV_FMT_ALTDUMP | CONV_FMT_ALTFILE) 106 107/* 108 * The expansion of bit-field data items is driven from a value descriptor and 109 * the conv_expn_field() routine. 110 */ 111typedef struct { 112 Xword v_val; /* expansion value */ 113 const char *v_msg; /* associated message string */ 114} Val_desc; 115 116/* 117 * conv_expn_field() is willing to supply default strings for the 118 * prefix, separator, and suffix arguments, if they are passed as NULL. 119 * The caller needs to know how much room to allow for these items. 120 * These values supply those sizes. 121 */ 122#define CONV_EXPN_FIELD_DEF_PREFIX_SIZE 2 /* Default is "[ " */ 123#define CONV_EXPN_FIELD_DEF_SEP_SIZE 1 /* Default is " " */ 124#define CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 2 /* Default is " ]" */ 125 126/* 127 * conv_expn_field() requires a large number of inputs, many of which 128 * can be NULL to accept default behavior. An argument of the following 129 * type is used to supply them. 130 */ 131typedef struct { 132 char *buf; /* Buffer to receive generated string */ 133 size_t bufsize; /* sizeof(buf) */ 134 const Val_desc *vdp; /* Array of value descriptors, giving the */ 135 /* possible bit values, and their */ 136 /* corresponding strings. Note that the */ 137 /* final element must contain only NULL */ 138 /* values. This terminates the list. */ 139 const char **lead_str; /* NULL, or array of pointers to strings to */ 140 /* be output at the head of the list. */ 141 /* Last entry must be NULL. */ 142 Xword oflags; /* Bits for which output strings are desired */ 143 Xword rflags; /* Bits for which a numeric value should be */ 144 /* output if vdp does not provide str. */ 145 /* Must be a proper subset of oflags */ 146 const char *prefix; /* NULL, or string to prefix output with */ 147 /* If NULL, "[ " is used. */ 148 const char *sep; /* NULL, or string to separate output items */ 149 /* with. If NULL, " " is used. */ 150 const char *suffix; /* NULL, or string to suffix output with */ 151 /* If NULL, " ]" is used. */ 152} CONV_EXPN_FIELD_ARG; 153 154/* 155 * Define all generic interfaces. 156 */ 157extern uchar_t conv_check_native(char **, char **); 158extern const char *conv_config_feat(int); 159extern const char *conv_config_obj(ushort_t); 160extern const char *conv_config_upm(const char *, const char *, 161 const char *, size_t); 162extern const char *conv_def_tag(Symref); 163extern const char *conv_demangle_name(const char *); 164extern const char *conv_dl_flag(int, int); 165extern const char *conv_dl_mode(int, int); 166extern const char *conv_dwarf_ehe(uint_t); 167extern const char *conv_elfdata_type(Elf_Type); 168extern const char *conv_grphdl_flags(uint_t); 169extern const char *conv_grpdesc_flags(uint_t); 170extern Isa_desc *conv_isalist(void); 171extern const char *conv_lddstub(int); 172extern const char *conv_seg_flags(Half); 173extern int conv_sys_eclass(); 174extern Uts_desc *conv_uts(void); 175extern const char *conv_ver_flags(Half); 176 177/* 178 * Define all class specific routines. 179 */ 180#if defined(_ELF64) 181#define conv_bnd_obj conv64_bnd_obj 182#define conv_bnd_type conv64_bnd_type 183#define conv_cap_tag conv64_cap_tag 184#define conv_cap_val conv64_cap_val 185#define conv_cap_val_hw1 conv64_cap_val_hw1 186#define conv_cap_val_sf1 conv64_cap_val_sf1 187#define conv_dyn_feature1 conv64_dyn_feature1 188#define conv_dyn_flag1 conv64_dyn_flag1 189#define conv_dyn_flag conv64_dyn_flag 190#define conv_dyn_posflag1 conv64_dyn_posflag1 191#define conv_dyn_tag conv64_dyn_tag 192#define conv_ehdr_class conv64_ehdr_class 193#define conv_ehdr_data conv64_ehdr_data 194#define conv_ehdr_flags conv64_ehdr_flags 195#define conv_ehdr_mach conv64_ehdr_mach 196#define conv_ehdr_osabi conv64_ehdr_osabi 197#define conv_ehdr_type conv64_ehdr_type 198#define conv_ehdr_vers conv64_ehdr_vers 199#define conv_expn_field conv64_expn_field 200#define conv_invalid_val conv64_invalid_val 201#define conv_phdr_flags conv64_phdr_flags 202#define conv_phdr_type conv64_phdr_type 203#define conv_reject_desc conv64_reject_desc 204#define conv_reloc_type conv64_reloc_type 205#define conv_reloc_386_type conv64_reloc_386_type 206#define conv_reloc_amd64_type conv64_reloc_amd64_type 207#define conv_reloc_SPARC_type conv64_reloc_SPARC_type 208#define conv_sec_flags conv64_sec_flags 209#define conv_sec_linkinfo conv64_sec_linkinfo 210#define conv_sec_type conv64_sec_type 211#define conv_sym_info_bind conv64_sym_info_bind 212#define conv_sym_info_type conv64_sym_info_type 213#define conv_sym_shndx conv64_sym_shndx 214#define conv_sym_other conv64_sym_other 215#define conv_sym_value conv64_sym_value 216#define conv_sym_SPARC_value conv64_sym_SPARC_value 217#else 218#define conv_bnd_obj conv32_bnd_obj 219#define conv_bnd_type conv32_bnd_type 220#define conv_cap_tag conv32_cap_tag 221#define conv_cap_val conv32_cap_val 222#define conv_cap_val_hw1 conv32_cap_val_hw1 223#define conv_cap_val_sf1 conv32_cap_val_sf1 224#define conv_dyn_feature1 conv32_dyn_feature1 225#define conv_dyn_flag1 conv32_dyn_flag1 226#define conv_dyn_flag conv32_dyn_flag 227#define conv_dyn_posflag1 conv32_dyn_posflag1 228#define conv_dyn_tag conv32_dyn_tag 229#define conv_ehdr_class conv32_ehdr_class 230#define conv_ehdr_data conv32_ehdr_data 231#define conv_ehdr_flags conv32_ehdr_flags 232#define conv_ehdr_mach conv32_ehdr_mach 233#define conv_ehdr_osabi conv32_ehdr_osabi 234#define conv_ehdr_type conv32_ehdr_type 235#define conv_ehdr_vers conv32_ehdr_vers 236#define conv_expn_field conv32_expn_field 237#define conv_invalid_val conv32_invalid_val 238#define conv_phdr_flags conv32_phdr_flags 239#define conv_phdr_type conv32_phdr_type 240#define conv_reject_desc conv32_reject_desc 241#define conv_reloc_type conv32_reloc_type 242#define conv_reloc_386_type conv32_reloc_386_type 243#define conv_reloc_amd64_type conv32_reloc_amd64_type 244#define conv_reloc_SPARC_type conv32_reloc_SPARC_type 245#define conv_sec_flags conv32_sec_flags 246#define conv_sec_linkinfo conv32_sec_linkinfo 247#define conv_sec_type conv32_sec_type 248#define conv_sym_info_bind conv32_sym_info_bind 249#define conv_sym_info_type conv32_sym_info_type 250#define conv_sym_shndx conv32_sym_shndx 251#define conv_sym_other conv32_sym_other 252#define conv_sym_value conv32_sym_value 253#define conv_sym_SPARC_value conv32_sym_SPARC_value 254#endif 255 256extern const char *conv_bnd_obj(uint_t); 257extern const char *conv_bnd_type(uint_t); 258extern const char *conv_cap_tag(Xword); 259extern const char *conv_cap_val(Xword, Xword, Half); 260extern const char *conv_cap_val_hw1(Xword, Half); 261extern const char *conv_cap_val_sf1(Xword, Half); 262extern const char *conv_dyn_flag1(Xword); 263extern const char *conv_dyn_flag(Xword, int); 264extern const char *conv_dyn_posflag1(Xword, int); 265extern const char *conv_dyn_tag(Xword, Half, int); 266extern const char *conv_dyn_feature1(Xword, int); 267extern const char *conv_ehdr_class(uchar_t, int); 268extern const char *conv_ehdr_data(uchar_t, int); 269extern const char *conv_ehdr_flags(Half, Word); 270extern const char *conv_ehdr_mach(Half, int); 271extern const char *conv_ehdr_osabi(uchar_t, int); 272extern const char *conv_ehdr_type(Half, int); 273extern const char *conv_ehdr_vers(Word, int); 274extern int conv_expn_field(CONV_EXPN_FIELD_ARG *); 275extern const char *conv_invalid_val(char *, size_t, Xword, int); 276extern const char *conv_phdr_flags(Word); 277extern const char *conv_phdr_type(Half, Word); 278extern const char *conv_reject_desc(Rej_desc *); 279extern const char *conv_reloc_type(Half, Word, int); 280extern const char *conv_reloc_386_type(Word, int); 281extern const char *conv_reloc_amd64_type(Word, int); 282extern const char *conv_reloc_SPARC_type(Word, int); 283extern const char *conv_sec_flags(Xword); 284extern const char *conv_sec_linkinfo(Word, Xword, Conv_inv_buf_t); 285extern const char *conv_sec_type(Half, Word, int); 286extern const char *conv_sym_info_bind(uchar_t, int); 287extern const char *conv_sym_info_type(Half, uchar_t, int); 288extern const char *conv_sym_shndx(Half); 289extern const char *conv_sym_other(uchar_t); 290extern const char *conv_sym_value(Half, uchar_t, Addr); 291extern const char *conv_sym_SPARC_value(Addr, int); 292 293#ifdef __cplusplus 294} 295#endif 296 297#endif /* _CONV_H */ 298