phdr.c revision 4734:a4708faa3e85
1148834Sstefanf/* 21573Srgrimes * CDDL HEADER START 351794Smarcel * 41573Srgrimes * The contents of this file are subject to the terms of the 51573Srgrimes * Common Development and Distribution License (the "License"). 6195767Skensmith * You may not use this file except in compliance with the License. 7119071Sobrien * 81573Srgrimes * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9209136Sjilles * or http://www.opensolaris.org/os/licensing. 10209136Sjilles * See the License for the specific language governing permissions 1126926Smsmith * and limitations under the License. 121573Srgrimes * 1394278Sru * When distributing Covered Code, include this CDDL HEADER in each 1494278Sru * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153527Sache * If applicable, add the following below this CDDL HEADER, with the 1674870Sru * fields enclosed by brackets "[]" replaced with your own identifying 1726926Smsmith * information: Portions Copyright [yyyy] [name of copyright owner] 1884335Sobrien * 1984335Sobrien * CDDL HEADER END 2084335Sobrien */ 2184335Sobrien 2284335Sobrien/* 2384335Sobrien * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24148834Sstefanf * Use is subject to license terms. 25148834Sstefanf */ 26148834Sstefanf 2726926Smsmith#pragma ident "%Z%%M% %I% %E% SMI" 281573Srgrimes 291573Srgrimes/* 301573Srgrimes * String conversion routines for program header attributes. 311573Srgrimes */ 3226926Smsmith#include <string.h> 3384335Sobrien#include <_conv.h> 3426926Smsmith#include <phdr_msg.h> 3584335Sobrien 3684335Sobrien/* Instantiate a local copy of conv_map2str() from _conv.h */ 37148834SstefanfDEFINE_conv_map2str 381573Srgrimes 39201381Sedconst char * 40201381Sedconv_phdr_type(Half mach, Word type, int fmt_flags, Conv_inv_buf_t *inv_buf) 4184335Sobrien{ 4284335Sobrien static const Msg phdrs[] = { 431573Srgrimes MSG_PT_NULL, MSG_PT_LOAD, 4484335Sobrien MSG_PT_DYNAMIC, MSG_PT_INTERP, 4584335Sobrien MSG_PT_NOTE, MSG_PT_SHLIB, 4684335Sobrien MSG_PT_PHDR, MSG_PT_TLS 4784335Sobrien }; 481573Srgrimes static const Msg phdrs_alt[] = { 491573Srgrimes MSG_PT_NULL_ALT, MSG_PT_LOAD_ALT, 501573Srgrimes MSG_PT_DYNAMIC_ALT, MSG_PT_INTERP_ALT, 511573Srgrimes MSG_PT_NOTE_ALT, MSG_PT_SHLIB_ALT, 521573Srgrimes MSG_PT_PHDR_ALT, MSG_PT_TLS_ALT 531573Srgrimes }; 541573Srgrimes#if PT_NUM != (PT_TLS + 1) 558870Srgrimeserror "PT_NUM has grown. Update phdrs[]" 561573Srgrimes#endif 571573Srgrimes static const Msg uphdrs[] = { 581573Srgrimes MSG_PT_SUNWBSS, MSG_PT_SUNWSTACK, 591573Srgrimes MSG_PT_SUNWDTRACE, MSG_PT_SUNWCAP 601573Srgrimes }; 6184260Sobrien static const Msg uphdrs_alt[] = { 6284260Sobrien MSG_PT_SUNWBSS_ALT, MSG_PT_SUNWSTACK_ALT, 631573Srgrimes MSG_PT_SUNWDTRACE_ALT, MSG_PT_SUNWCAP_ALT 6484260Sobrien }; 6584260Sobrien#if PT_LOSUNW != PT_SUNWBSS 6684260Sobrien#error "PT_LOSUNW has grown. Update uphdrs[]" 671573Srgrimes#endif 6884335Sobrien 6984260Sobrien if (type < PT_NUM) { 7084335Sobrien return (conv_map2str(inv_buf, type, fmt_flags, 7117929Speter ARRAY_NELTS(phdrs), phdrs, phdrs_alt, phdrs_alt)); 721573Srgrimes } else if ((type >= PT_SUNWBSS) && (type <= PT_HISUNW)) { 731573Srgrimes return (conv_map2str(inv_buf, (type - PT_SUNWBSS), fmt_flags, 74 ARRAY_NELTS(uphdrs), uphdrs, uphdrs_alt, uphdrs_alt)); 75 } else if ((type == PT_SUNW_UNWIND) && (mach == EM_AMD64)) { 76 return ((fmt_flags & CONV_FMTALTMASK) ? 77 MSG_ORIG(MSG_PT_SUNW_UNWIND_ALT) : 78 MSG_ORIG(MSG_PT_SUNW_UNWIND)); 79 } else 80 return (conv_invalid_val(inv_buf, type, 0)); 81} 82 83#define PHDRSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 84 MSG_PF_X_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 85 MSG_PF_W_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 86 MSG_PF_R_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 87 MSG_PF_SUNW_FAILURE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 88 CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 89 90/* 91 * Ensure that Conv_phdr_flags_buf_t is large enough: 92 * 93 * PHDRSZ is the real minimum size of the buffer required by conv_phdr_flags(). 94 * However, Conv_phdr_flags_buf_t uses CONV_PHDR_FLAGS_BUFSIZE to set the 95 * buffer size. We do things this way because the definition of PHDRSZ uses 96 * information that is not available in the environment of other programs 97 * that include the conv.h header file. 98 */ 99#if CONV_PHDR_FLAGS_BUFSIZE < PHDRSZ 100#error "CONV_PHDR_FLAGS_BUFSIZE is not large enough" 101#endif 102 103const char * 104conv_phdr_flags(Word flags, Conv_phdr_flags_buf_t *phdr_flags_buf) 105{ 106 static Val_desc vda[] = { 107 { PF_X, MSG_ORIG(MSG_PF_X) }, 108 { PF_W, MSG_ORIG(MSG_PF_W) }, 109 { PF_R, MSG_ORIG(MSG_PF_R) }, 110 { PF_SUNW_FAILURE, MSG_ORIG(MSG_PF_SUNW_FAILURE) }, 111 { 0, 0 } 112 }; 113 static CONV_EXPN_FIELD_ARG conv_arg = { 114 NULL, sizeof (phdr_flags_buf->buf), vda }; 115 116 if (flags == 0) 117 return (MSG_ORIG(MSG_GBL_ZERO)); 118 119 conv_arg.buf = phdr_flags_buf->buf; 120 conv_arg.oflags = conv_arg.rflags = flags; 121 (void) conv_expn_field(&conv_arg); 122 123 return ((const char *)phdr_flags_buf->buf); 124} 125