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*9085SAli.Bahrami@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* 280Sstevel@tonic-gate * String conversion routines for program header attributes. 290Sstevel@tonic-gate */ 300Sstevel@tonic-gate #include <string.h> 310Sstevel@tonic-gate #include <_conv.h> 320Sstevel@tonic-gate #include <phdr_msg.h> 330Sstevel@tonic-gate 344031Srie /* Instantiate a local copy of conv_map2str() from _conv.h */ 354031Srie DEFINE_conv_map2str 360Sstevel@tonic-gate 37*9085SAli.Bahrami@Sun.COM /*ARGSUSED*/ 380Sstevel@tonic-gate const char * 395088Sab196087 conv_phdr_type(Half mach, Word type, Conv_fmt_flags_t fmt_flags, 405088Sab196087 Conv_inv_buf_t *inv_buf) 410Sstevel@tonic-gate { 421618Srie static const Msg phdrs[] = { 434031Srie MSG_PT_NULL, MSG_PT_LOAD, 444031Srie MSG_PT_DYNAMIC, MSG_PT_INTERP, 454031Srie MSG_PT_NOTE, MSG_PT_SHLIB, 461618Srie MSG_PT_PHDR, MSG_PT_TLS 471618Srie }; 484031Srie static const Msg phdrs_alt[] = { 494031Srie MSG_PT_NULL_ALT, MSG_PT_LOAD_ALT, 504031Srie MSG_PT_DYNAMIC_ALT, MSG_PT_INTERP_ALT, 514031Srie MSG_PT_NOTE_ALT, MSG_PT_SHLIB_ALT, 524031Srie MSG_PT_PHDR_ALT, MSG_PT_TLS_ALT 534031Srie }; 544031Srie #if PT_NUM != (PT_TLS + 1) 554031Srie error "PT_NUM has grown. Update phdrs[]" 564031Srie #endif 574031Srie static const Msg uphdrs[] = { 584031Srie MSG_PT_SUNWBSS, MSG_PT_SUNWSTACK, 594031Srie MSG_PT_SUNWDTRACE, MSG_PT_SUNWCAP 604031Srie }; 614031Srie static const Msg uphdrs_alt[] = { 624031Srie MSG_PT_SUNWBSS_ALT, MSG_PT_SUNWSTACK_ALT, 634031Srie MSG_PT_SUNWDTRACE_ALT, MSG_PT_SUNWCAP_ALT 644031Srie }; 654031Srie #if PT_LOSUNW != PT_SUNWBSS 664031Srie #error "PT_LOSUNW has grown. Update uphdrs[]" 674031Srie #endif 680Sstevel@tonic-gate 694031Srie if (type < PT_NUM) { 705088Sab196087 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 715088Sab196087 case CONV_FMT_ALT_DUMP: 725088Sab196087 case CONV_FMT_ALT_FILE: 735088Sab196087 return (conv_map2str(inv_buf, type, fmt_flags, 745088Sab196087 ARRAY_NELTS(phdrs_alt), phdrs_alt)); 755088Sab196087 default: 765088Sab196087 return (conv_map2str(inv_buf, type, fmt_flags, 775088Sab196087 ARRAY_NELTS(phdrs), phdrs)); 785088Sab196087 } 794031Srie } else if ((type >= PT_SUNWBSS) && (type <= PT_HISUNW)) { 805088Sab196087 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 815088Sab196087 case CONV_FMT_ALT_DUMP: 825088Sab196087 case CONV_FMT_ALT_FILE: 835088Sab196087 return (conv_map2str(inv_buf, (type - PT_SUNWBSS), 845088Sab196087 fmt_flags, ARRAY_NELTS(uphdrs_alt), uphdrs_alt)); 855088Sab196087 default: 865088Sab196087 return (conv_map2str(inv_buf, (type - PT_SUNWBSS), 875088Sab196087 fmt_flags, ARRAY_NELTS(uphdrs), uphdrs)); 885088Sab196087 } 89*9085SAli.Bahrami@Sun.COM } else if (type == PT_SUNW_UNWIND) { 905088Sab196087 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 915088Sab196087 case CONV_FMT_ALT_DUMP: 925088Sab196087 case CONV_FMT_ALT_FILE: 935088Sab196087 return (MSG_ORIG(MSG_PT_SUNW_UNWIND_ALT)); 945088Sab196087 default: 955088Sab196087 return (MSG_ORIG(MSG_PT_SUNW_UNWIND)); 965088Sab196087 } 97*9085SAli.Bahrami@Sun.COM } else if (type == PT_SUNW_EH_FRAME) { 98*9085SAli.Bahrami@Sun.COM switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 99*9085SAli.Bahrami@Sun.COM case CONV_FMT_ALT_DUMP: 100*9085SAli.Bahrami@Sun.COM case CONV_FMT_ALT_FILE: 101*9085SAli.Bahrami@Sun.COM return (MSG_ORIG(MSG_PT_SUNW_EH_FRAME_ALT)); 102*9085SAli.Bahrami@Sun.COM default: 103*9085SAli.Bahrami@Sun.COM return (MSG_ORIG(MSG_PT_SUNW_EH_FRAME)); 104*9085SAli.Bahrami@Sun.COM } 1054031Srie } else 1064734Sab196087 return (conv_invalid_val(inv_buf, type, 0)); 1070Sstevel@tonic-gate } 1080Sstevel@tonic-gate 1092352Sab196087 #define PHDRSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 1102352Sab196087 MSG_PF_X_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1112352Sab196087 MSG_PF_W_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1122352Sab196087 MSG_PF_R_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1132352Sab196087 MSG_PF_SUNW_FAILURE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1144734Sab196087 CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 1154734Sab196087 1164734Sab196087 /* 1174734Sab196087 * Ensure that Conv_phdr_flags_buf_t is large enough: 1184734Sab196087 * 1194734Sab196087 * PHDRSZ is the real minimum size of the buffer required by conv_phdr_flags(). 1204734Sab196087 * However, Conv_phdr_flags_buf_t uses CONV_PHDR_FLAGS_BUFSIZE to set the 1214734Sab196087 * buffer size. We do things this way because the definition of PHDRSZ uses 1224734Sab196087 * information that is not available in the environment of other programs 1234734Sab196087 * that include the conv.h header file. 1244734Sab196087 */ 1255152Sab196087 #if (CONV_PHDR_FLAGS_BUFSIZE != PHDRSZ) && !defined(__lint) 1265152Sab196087 #define REPORT_BUFSIZE PHDRSZ 1275152Sab196087 #include "report_bufsize.h" 1285152Sab196087 #error "CONV_PHDR_FLAGS_BUFSIZE does not match PHDRSZ" 1294734Sab196087 #endif 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate const char * 1325088Sab196087 conv_phdr_flags(Word flags, Conv_fmt_flags_t fmt_flags, 1335088Sab196087 Conv_phdr_flags_buf_t *phdr_flags_buf) 1340Sstevel@tonic-gate { 1351618Srie static Val_desc vda[] = { 1361618Srie { PF_X, MSG_ORIG(MSG_PF_X) }, 1371618Srie { PF_W, MSG_ORIG(MSG_PF_W) }, 1381618Srie { PF_R, MSG_ORIG(MSG_PF_R) }, 1391618Srie { PF_SUNW_FAILURE, MSG_ORIG(MSG_PF_SUNW_FAILURE) }, 1401618Srie { 0, 0 } 1411618Srie }; 1424734Sab196087 static CONV_EXPN_FIELD_ARG conv_arg = { 1434734Sab196087 NULL, sizeof (phdr_flags_buf->buf), vda }; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate if (flags == 0) 1460Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 1470Sstevel@tonic-gate 1484734Sab196087 conv_arg.buf = phdr_flags_buf->buf; 1492352Sab196087 conv_arg.oflags = conv_arg.rflags = flags; 1505088Sab196087 (void) conv_expn_field(&conv_arg, fmt_flags); 1511618Srie 1524734Sab196087 return ((const char *)phdr_flags_buf->buf); 1530Sstevel@tonic-gate } 154