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 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 /* 30 * String conversion routines for program header attributes. 31 */ 32 #include <string.h> 33 #include <_conv.h> 34 #include <phdr_msg.h> 35 36 /* Instantiate a local copy of conv_map2str() from _conv.h */ 37 DEFINE_conv_map2str 38 39 const char * 40 conv_phdr_type(Half mach, Word type, int fmt_flags) 41 { 42 static Conv_inv_buf_t string; 43 static const Msg phdrs[] = { 44 MSG_PT_NULL, MSG_PT_LOAD, 45 MSG_PT_DYNAMIC, MSG_PT_INTERP, 46 MSG_PT_NOTE, MSG_PT_SHLIB, 47 MSG_PT_PHDR, MSG_PT_TLS 48 }; 49 static const Msg phdrs_alt[] = { 50 MSG_PT_NULL_ALT, MSG_PT_LOAD_ALT, 51 MSG_PT_DYNAMIC_ALT, MSG_PT_INTERP_ALT, 52 MSG_PT_NOTE_ALT, MSG_PT_SHLIB_ALT, 53 MSG_PT_PHDR_ALT, MSG_PT_TLS_ALT 54 }; 55 #if PT_NUM != (PT_TLS + 1) 56 error "PT_NUM has grown. Update phdrs[]" 57 #endif 58 static const Msg uphdrs[] = { 59 MSG_PT_SUNWBSS, MSG_PT_SUNWSTACK, 60 MSG_PT_SUNWDTRACE, MSG_PT_SUNWCAP 61 }; 62 static const Msg uphdrs_alt[] = { 63 MSG_PT_SUNWBSS_ALT, MSG_PT_SUNWSTACK_ALT, 64 MSG_PT_SUNWDTRACE_ALT, MSG_PT_SUNWCAP_ALT 65 }; 66 #if PT_LOSUNW != PT_SUNWBSS 67 #error "PT_LOSUNW has grown. Update uphdrs[]" 68 #endif 69 70 if (type < PT_NUM) { 71 return (conv_map2str(string, sizeof (string), 72 type, fmt_flags, ARRAY_NELTS(phdrs), 73 phdrs, phdrs_alt, phdrs_alt)); 74 } else if ((type >= PT_SUNWBSS) && (type <= PT_HISUNW)) { 75 return (conv_map2str(string, sizeof (string), 76 (type - PT_SUNWBSS), fmt_flags, ARRAY_NELTS(uphdrs), 77 uphdrs, uphdrs_alt, uphdrs_alt)); 78 } else if ((type == PT_SUNW_UNWIND) && (mach == EM_AMD64)) { 79 return ((fmt_flags & CONV_FMTALTMASK) ? 80 MSG_ORIG(MSG_PT_SUNW_UNWIND_ALT) : 81 MSG_ORIG(MSG_PT_SUNW_UNWIND)); 82 } else 83 return (conv_invalid_val(string, CONV_INV_STRSIZE, type, 0)); 84 } 85 86 #define PHDRSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 87 MSG_PF_X_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 88 MSG_PF_W_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 89 MSG_PF_R_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 90 MSG_PF_SUNW_FAILURE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 91 CONV_INV_STRSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 92 93 const char * 94 conv_phdr_flags(Word flags) 95 { 96 static char string[PHDRSZ]; 97 static Val_desc vda[] = { 98 { PF_X, MSG_ORIG(MSG_PF_X) }, 99 { PF_W, MSG_ORIG(MSG_PF_W) }, 100 { PF_R, MSG_ORIG(MSG_PF_R) }, 101 { PF_SUNW_FAILURE, MSG_ORIG(MSG_PF_SUNW_FAILURE) }, 102 { 0, 0 } 103 }; 104 static CONV_EXPN_FIELD_ARG conv_arg = { string, sizeof (string), vda }; 105 106 if (flags == 0) 107 return (MSG_ORIG(MSG_GBL_ZERO)); 108 109 conv_arg.oflags = conv_arg.rflags = flags; 110 (void) conv_expn_field(&conv_arg); 111 112 return ((const char *)string); 113 } 114