10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51618Srie * Common Development and Distribution License (the "License"). 61618Srie * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211618Srie 220Sstevel@tonic-gate /* 23*4031Srie * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * String conversion routines for program header attributes. 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate #include <string.h> 330Sstevel@tonic-gate #include <_conv.h> 340Sstevel@tonic-gate #include <phdr_msg.h> 350Sstevel@tonic-gate 36*4031Srie /* Instantiate a local copy of conv_map2str() from _conv.h */ 37*4031Srie DEFINE_conv_map2str 380Sstevel@tonic-gate 390Sstevel@tonic-gate const char * 40*4031Srie conv_phdr_type(Half mach, Word type, int fmt_flags) 410Sstevel@tonic-gate { 422850Srie static Conv_inv_buf_t string; 431618Srie static const Msg phdrs[] = { 44*4031Srie MSG_PT_NULL, MSG_PT_LOAD, 45*4031Srie MSG_PT_DYNAMIC, MSG_PT_INTERP, 46*4031Srie MSG_PT_NOTE, MSG_PT_SHLIB, 471618Srie MSG_PT_PHDR, MSG_PT_TLS 481618Srie }; 49*4031Srie static const Msg phdrs_alt[] = { 50*4031Srie MSG_PT_NULL_ALT, MSG_PT_LOAD_ALT, 51*4031Srie MSG_PT_DYNAMIC_ALT, MSG_PT_INTERP_ALT, 52*4031Srie MSG_PT_NOTE_ALT, MSG_PT_SHLIB_ALT, 53*4031Srie MSG_PT_PHDR_ALT, MSG_PT_TLS_ALT 54*4031Srie }; 55*4031Srie #if PT_NUM != (PT_TLS + 1) 56*4031Srie error "PT_NUM has grown. Update phdrs[]" 57*4031Srie #endif 58*4031Srie static const Msg uphdrs[] = { 59*4031Srie MSG_PT_SUNWBSS, MSG_PT_SUNWSTACK, 60*4031Srie MSG_PT_SUNWDTRACE, MSG_PT_SUNWCAP 61*4031Srie }; 62*4031Srie static const Msg uphdrs_alt[] = { 63*4031Srie MSG_PT_SUNWBSS_ALT, MSG_PT_SUNWSTACK_ALT, 64*4031Srie MSG_PT_SUNWDTRACE_ALT, MSG_PT_SUNWCAP_ALT 65*4031Srie }; 66*4031Srie #if PT_LOSUNW != PT_SUNWBSS 67*4031Srie #error "PT_LOSUNW has grown. Update uphdrs[]" 68*4031Srie #endif 690Sstevel@tonic-gate 70*4031Srie if (type < PT_NUM) { 71*4031Srie return (conv_map2str(string, sizeof (string), 72*4031Srie type, fmt_flags, ARRAY_NELTS(phdrs), 73*4031Srie phdrs, phdrs_alt, phdrs_alt)); 74*4031Srie } else if ((type >= PT_SUNWBSS) && (type <= PT_HISUNW)) { 75*4031Srie return (conv_map2str(string, sizeof (string), 76*4031Srie (type - PT_SUNWBSS), fmt_flags, ARRAY_NELTS(uphdrs), 77*4031Srie uphdrs, uphdrs_alt, uphdrs_alt)); 78*4031Srie } else if ((type == PT_SUNW_UNWIND) && (mach == EM_AMD64)) { 79*4031Srie return ((fmt_flags & CONV_FMTALTMASK) ? 80*4031Srie MSG_ORIG(MSG_PT_SUNW_UNWIND_ALT) : 81*4031Srie MSG_ORIG(MSG_PT_SUNW_UNWIND)); 82*4031Srie } else 831618Srie return (conv_invalid_val(string, CONV_INV_STRSIZE, type, 0)); 840Sstevel@tonic-gate } 850Sstevel@tonic-gate 862352Sab196087 #define PHDRSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 872352Sab196087 MSG_PF_X_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 882352Sab196087 MSG_PF_W_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 892352Sab196087 MSG_PF_R_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 902352Sab196087 MSG_PF_SUNW_FAILURE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 912352Sab196087 CONV_INV_STRSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 920Sstevel@tonic-gate 930Sstevel@tonic-gate const char * 941618Srie conv_phdr_flags(Word flags) 950Sstevel@tonic-gate { 962352Sab196087 static char string[PHDRSZ]; 971618Srie static Val_desc vda[] = { 981618Srie { PF_X, MSG_ORIG(MSG_PF_X) }, 991618Srie { PF_W, MSG_ORIG(MSG_PF_W) }, 1001618Srie { PF_R, MSG_ORIG(MSG_PF_R) }, 1011618Srie { PF_SUNW_FAILURE, MSG_ORIG(MSG_PF_SUNW_FAILURE) }, 1021618Srie { 0, 0 } 1031618Srie }; 1042352Sab196087 static CONV_EXPN_FIELD_ARG conv_arg = { string, sizeof (string), vda }; 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate if (flags == 0) 1070Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 1080Sstevel@tonic-gate 1092352Sab196087 conv_arg.oflags = conv_arg.rflags = flags; 1102352Sab196087 (void) conv_expn_field(&conv_arg); 1111618Srie 1121618Srie return ((const char *)string); 1130Sstevel@tonic-gate } 114