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 27 /* 28 * String conversion routines for syminfo attributes. 29 */ 30 #include <stdio.h> 31 #include <_machelf.h> 32 #include "_conv.h" 33 #include "syminfo_msg.h" 34 35 36 37 static const Val_desc * 38 conv_syminfo_flags_strings(Conv_fmt_flags_t fmt_flags) 39 { 40 #define FLAGSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 41 MSG_SYMINFO_FLG_DIRECT_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 42 MSG_SYMINFO_FLG_FILTER_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 43 MSG_SYMINFO_FLG_COPY_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 44 MSG_SYMINFO_FLG_LAZYLOAD_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 45 MSG_SYMINFO_FLG_DIRECTBIND_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 46 MSG_SYMINFO_FLG_NOEXTDIRECT_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 47 MSG_SYMINFO_FLG_AUXILIARY_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 48 MSG_SYMINFO_FLG_INTERPOSE_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 49 CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 50 51 /* 52 * Ensure that Conv_syminfo_flags_buf_t is large enough: 53 * 54 * FLAGSZ is the real minimum size of the buffer required by 55 * conv_syminfo_flags(). However, Conv_syminfo_flags_buf_t uses 56 * CONV_SYMINFO_FLAGS_BUFSIZE to set the buffer size. We do things 57 * this way because the definition of FLAGSZ uses information that 58 * is not available in the environment of other programs that include 59 * the conv.h header file. 60 */ 61 #if (CONV_SYMINFO_FLAGS_BUFSIZE != FLAGSZ) && !defined(__lint) 62 #define REPORT_BUFSIZE FLAGSZ 63 #include "report_bufsize.h" 64 #error "CONV_SYMINFO_FLAGS_BUFSIZE does not match FLAGSZ" 65 #endif 66 67 static const Val_desc vda_cf[] = { 68 { SYMINFO_FLG_DIRECT, MSG_SYMINFO_FLG_DIRECT_CF }, 69 { SYMINFO_FLG_FILTER, MSG_SYMINFO_FLG_FILTER_CF }, 70 { SYMINFO_FLG_COPY, MSG_SYMINFO_FLG_COPY_CF }, 71 { SYMINFO_FLG_LAZYLOAD, MSG_SYMINFO_FLG_LAZYLOAD_CF }, 72 { SYMINFO_FLG_DIRECTBIND, MSG_SYMINFO_FLG_DIRECTBIND_CF }, 73 { SYMINFO_FLG_NOEXTDIRECT, MSG_SYMINFO_FLG_NOEXTDIRECT_CF }, 74 { SYMINFO_FLG_AUXILIARY, MSG_SYMINFO_FLG_AUXILIARY_CF }, 75 { SYMINFO_FLG_INTERPOSE, MSG_SYMINFO_FLG_INTERPOSE_CF }, 76 { SYMINFO_FLG_CAP, MSG_SYMINFO_FLG_CAP_CF }, 77 { 0 } 78 }; 79 static const Val_desc vda_cfnp[] = { 80 { SYMINFO_FLG_DIRECT, MSG_SYMINFO_FLG_DIRECT_CFNP }, 81 { SYMINFO_FLG_FILTER, MSG_SYMINFO_FLG_FILTER_CFNP }, 82 { SYMINFO_FLG_COPY, MSG_SYMINFO_FLG_COPY_CFNP }, 83 { SYMINFO_FLG_LAZYLOAD, MSG_SYMINFO_FLG_LAZYLOAD_CFNP }, 84 { SYMINFO_FLG_DIRECTBIND, MSG_SYMINFO_FLG_DIRECTBIND_CFNP }, 85 { SYMINFO_FLG_NOEXTDIRECT, MSG_SYMINFO_FLG_NOEXTDIRECT_CFNP }, 86 { SYMINFO_FLG_AUXILIARY, MSG_SYMINFO_FLG_AUXILIARY_CFNP }, 87 { SYMINFO_FLG_INTERPOSE, MSG_SYMINFO_FLG_INTERPOSE_CFNP }, 88 { SYMINFO_FLG_CAP, MSG_SYMINFO_FLG_CAP_CFNP }, 89 { 0 } 90 }; 91 static const Val_desc vda_nf[] = { 92 { SYMINFO_FLG_DIRECT, MSG_SYMINFO_FLG_DIRECT_NF }, 93 { SYMINFO_FLG_FILTER, MSG_SYMINFO_FLG_FILTER_NF }, 94 { SYMINFO_FLG_COPY, MSG_SYMINFO_FLG_COPY_NF }, 95 { SYMINFO_FLG_LAZYLOAD, MSG_SYMINFO_FLG_LAZYLOAD_NF }, 96 { SYMINFO_FLG_DIRECTBIND, MSG_SYMINFO_FLG_DIRECTBIND_NF }, 97 { SYMINFO_FLG_NOEXTDIRECT, MSG_SYMINFO_FLG_NOEXTDIRECT_NF }, 98 { SYMINFO_FLG_AUXILIARY, MSG_SYMINFO_FLG_AUXILIARY_NF }, 99 { SYMINFO_FLG_INTERPOSE, MSG_SYMINFO_FLG_INTERPOSE_NF }, 100 { SYMINFO_FLG_CAP, MSG_SYMINFO_FLG_CAP_NF }, 101 { 0 } 102 }; 103 104 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 105 case CONV_FMT_ALT_CF: 106 return (vda_cf); 107 case CONV_FMT_ALT_NF: 108 return (vda_nf); 109 } 110 111 return (vda_cfnp); 112 } 113 114 115 const char * 116 conv_syminfo_flags(Half flags, Conv_fmt_flags_t fmt_flags, 117 Conv_syminfo_flags_buf_t *syminfo_flags_buf) 118 { 119 static CONV_EXPN_FIELD_ARG conv_arg = { 120 NULL, sizeof (syminfo_flags_buf->buf) }; 121 122 if (flags == 0) 123 return (MSG_ORIG(MSG_GBL_ZERO)); 124 125 conv_arg.buf = syminfo_flags_buf->buf; 126 conv_arg.oflags = conv_arg.rflags = flags; 127 conv_arg.prefix = conv_arg.suffix = NULL; 128 (void) conv_expn_field(&conv_arg, 129 conv_syminfo_flags_strings(fmt_flags), fmt_flags); 130 131 return ((const char *)syminfo_flags_buf->buf); 132 } 133 134 conv_iter_ret_t 135 conv_iter_syminfo_flags(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 136 void *uvalue) 137 { 138 return (conv_iter_vd(conv_syminfo_flags_strings(fmt_flags), 139 func, uvalue)); 140 } 141 142 143 static const conv_ds_t ** 144 conv_syminfo_boundto_strings(Conv_fmt_flags_t fmt_flags) 145 { 146 static const Msg boundto_cf[] = { 147 MSG_SYMINFO_BT_EXTERN_CF, MSG_SYMINFO_BT_NONE_CF, 148 MSG_SYMINFO_BT_PARENT_CF, MSG_SYMINFO_BT_SELF_CF 149 }; 150 static const Msg boundto_cfnp[] = { 151 MSG_SYMINFO_BT_EXTERN_CFNP, MSG_SYMINFO_BT_NONE_CFNP, 152 MSG_SYMINFO_BT_PARENT_CFNP, MSG_SYMINFO_BT_SELF_CFNP 153 }; 154 static const Msg boundto_nf[] = { 155 MSG_SYMINFO_BT_EXTERN_NF, MSG_SYMINFO_BT_NONE_NF, 156 MSG_SYMINFO_BT_PARENT_NF, MSG_SYMINFO_BT_SELF_NF 157 }; 158 static const conv_ds_msg_t ds_boundto_cf = { 159 CONV_DS_MSG_INIT(SYMINFO_BT_EXTERN, boundto_cf) }; 160 static const conv_ds_msg_t ds_boundto_cfnp = { 161 CONV_DS_MSG_INIT(SYMINFO_BT_EXTERN, boundto_cfnp) }; 162 static const conv_ds_msg_t ds_boundto_nf = { 163 CONV_DS_MSG_INIT(SYMINFO_BT_EXTERN, boundto_nf) }; 164 165 /* Build NULL terminated return arrays for each string style */ 166 static const const conv_ds_t *ds_cf[] = { 167 CONV_DS_ADDR(ds_boundto_cf), NULL }; 168 static const const conv_ds_t *ds_cfnp[] = { 169 CONV_DS_ADDR(ds_boundto_cfnp), NULL }; 170 static const const conv_ds_t *ds_nf[] = { 171 CONV_DS_ADDR(ds_boundto_nf), NULL }; 172 173 /* Select the strings to use */ 174 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 175 case CONV_FMT_ALT_CF: 176 return (ds_cf); 177 case CONV_FMT_ALT_NF: 178 return (ds_nf); 179 } 180 181 return (ds_cfnp); 182 } 183 184 const char * 185 conv_syminfo_boundto(Half value, Conv_fmt_flags_t fmt_flags, 186 Conv_inv_buf_t *inv_buf) 187 { 188 return (conv_map_ds(ELFOSABI_NONE, EM_NONE, value, 189 conv_syminfo_boundto_strings(fmt_flags), fmt_flags, inv_buf)); 190 } 191 192 conv_iter_ret_t 193 conv_iter_syminfo_boundto(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 194 void *uvalue) 195 { 196 return (conv_iter_ds(ELFOSABI_NONE, EM_NONE, 197 conv_syminfo_boundto_strings(fmt_flags), func, uvalue)); 198 } 199