phdr.c revision 8521e5e6630b57b9883c3979cd5589e53f09e044
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/*
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * CDDL HEADER START
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * The contents of this file are subject to the terms of the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Common Development and Distribution License (the "License").
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * You may not use this file except in compliance with the License.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * or http://www.opensolaris.org/os/licensing.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * See the License for the specific language governing permissions
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * and limitations under the License.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * When distributing Covered Code, include this CDDL HEADER in each
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * If applicable, add the following below this CDDL HEADER, with the
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk * fields enclosed by brackets "[]" replaced with your own identifying
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk * information: Portions Copyright [yyyy] [name of copyright owner]
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk *
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk * CDDL HEADER END
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk/*
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Use is subject to license terms.
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#pragma ident "%Z%%M% %I% %E% SMI"
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/*
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * String conversion routines for program header attributes.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#include <string.h>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#include <_conv.h>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#include <phdr_msg.h>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/* Instantiate a local copy of conv_map2str() from _conv.h */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkDEFINE_conv_map2str
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkconst char *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkconv_phdr_type(Half mach, Word type, int fmt_flags)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk{
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk static Conv_inv_buf_t string;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk static const Msg phdrs[] = {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PT_NULL, MSG_PT_LOAD,
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk MSG_PT_DYNAMIC, MSG_PT_INTERP,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PT_NOTE, MSG_PT_SHLIB,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PT_PHDR, MSG_PT_TLS
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk };
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk static const Msg phdrs_alt[] = {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PT_NULL_ALT, MSG_PT_LOAD_ALT,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PT_DYNAMIC_ALT, MSG_PT_INTERP_ALT,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PT_NOTE_ALT, MSG_PT_SHLIB_ALT,
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk MSG_PT_PHDR_ALT, MSG_PT_TLS_ALT
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk };
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#if PT_NUM != (PT_TLS + 1)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkerror "PT_NUM has grown. Update phdrs[]"
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk#endif
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk static const Msg uphdrs[] = {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PT_SUNWBSS, MSG_PT_SUNWSTACK,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PT_SUNWDTRACE, MSG_PT_SUNWCAP
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk };
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk static const Msg uphdrs_alt[] = {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PT_SUNWBSS_ALT, MSG_PT_SUNWSTACK_ALT,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PT_SUNWDTRACE_ALT, MSG_PT_SUNWCAP_ALT
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk };
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#if PT_LOSUNW != PT_SUNWBSS
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#error "PT_LOSUNW has grown. Update uphdrs[]"
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#endif
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (type < PT_NUM) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return (conv_map2str(string, sizeof (string),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk type, fmt_flags, ARRAY_NELTS(phdrs),
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk phdrs, phdrs_alt, phdrs_alt));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else if ((type >= PT_SUNWBSS) && (type <= PT_HISUNW)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return (conv_map2str(string, sizeof (string),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (type - PT_SUNWBSS), fmt_flags, ARRAY_NELTS(uphdrs),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk uphdrs, uphdrs_alt, uphdrs_alt));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else if ((type == PT_SUNW_UNWIND) && (mach == EM_AMD64)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return ((fmt_flags & CONV_FMTALTMASK) ?
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_ORIG(MSG_PT_SUNW_UNWIND_ALT) :
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_ORIG(MSG_PT_SUNW_UNWIND));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return (conv_invalid_val(string, CONV_INV_STRSIZE, type, 0));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk}
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#define PHDRSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PF_X_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PF_W_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PF_R_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MSG_PF_SUNW_FAILURE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk CONV_INV_STRSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkconst char *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkconv_phdr_flags(Word flags)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk{
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk static char string[PHDRSZ];
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk static Val_desc vda[] = {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk { PF_X, MSG_ORIG(MSG_PF_X) },
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk { PF_W, MSG_ORIG(MSG_PF_W) },
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk { PF_R, MSG_ORIG(MSG_PF_R) },
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk { PF_SUNW_FAILURE, MSG_ORIG(MSG_PF_SUNW_FAILURE) },
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk { 0, 0 }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk };
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk static CONV_EXPN_FIELD_ARG conv_arg = { string, sizeof (string), vda };
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (flags == 0)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return (MSG_ORIG(MSG_GBL_ZERO));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk conv_arg.oflags = conv_arg.rflags = flags;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (void) conv_expn_field(&conv_arg);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return ((const char *)string);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk}
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk