xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/phdr.c (revision 2352:9cdfed81bb1c)
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 /*
231618Srie  * Copyright 2006 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 
360Sstevel@tonic-gate static const Msg uphdrs[] = {
370Sstevel@tonic-gate 	MSG_PT_SUNWBSS,		MSG_PT_SUNWSTACK,	MSG_PT_SUNWDTRACE,
380Sstevel@tonic-gate 	MSG_PT_SUNWCAP
390Sstevel@tonic-gate };
400Sstevel@tonic-gate 
410Sstevel@tonic-gate const char *
421618Srie conv_phdr_type(Half mach, Word type)
430Sstevel@tonic-gate {
441618Srie 	static char		string[CONV_INV_STRSIZE];
451618Srie 	static const Msg	phdrs[] = {
461618Srie 		MSG_PT_NULL,		MSG_PT_LOAD,		MSG_PT_DYNAMIC,
471618Srie 		MSG_PT_INTERP,		MSG_PT_NOTE,		MSG_PT_SHLIB,
481618Srie 		MSG_PT_PHDR,		MSG_PT_TLS
491618Srie 	};
500Sstevel@tonic-gate 
511618Srie 	if (type < PT_NUM)
521618Srie 		return (MSG_ORIG(phdrs[type]));
531618Srie 	else if ((type >= PT_SUNWBSS) && (type <= PT_HISUNW))
541618Srie 		return (MSG_ORIG(uphdrs[type - PT_SUNWBSS]));
551618Srie 	else if ((type == PT_SUNW_UNWIND) && (mach == EM_AMD64))
560Sstevel@tonic-gate 		return (MSG_ORIG(MSG_PT_SUNW_UNWIND));
570Sstevel@tonic-gate 	else
581618Srie 		return (conv_invalid_val(string, CONV_INV_STRSIZE, type, 0));
590Sstevel@tonic-gate }
600Sstevel@tonic-gate 
61*2352Sab196087 #define	PHDRSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
62*2352Sab196087 		MSG_PF_X_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
63*2352Sab196087 		MSG_PF_W_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
64*2352Sab196087 		MSG_PF_R_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
65*2352Sab196087 		MSG_PF_SUNW_FAILURE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
66*2352Sab196087 		CONV_INV_STRSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
670Sstevel@tonic-gate 
680Sstevel@tonic-gate const char *
691618Srie conv_phdr_flags(Word flags)
700Sstevel@tonic-gate {
71*2352Sab196087 	static char string[PHDRSZ];
721618Srie 	static Val_desc vda[] = {
731618Srie 		{ PF_X,			MSG_ORIG(MSG_PF_X) },
741618Srie 		{ PF_W,			MSG_ORIG(MSG_PF_W) },
751618Srie 		{ PF_R,			MSG_ORIG(MSG_PF_R) },
761618Srie 		{ PF_SUNW_FAILURE,	MSG_ORIG(MSG_PF_SUNW_FAILURE) },
771618Srie 		{ 0,			0 }
781618Srie 	};
79*2352Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = { string, sizeof (string), vda };
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	if (flags == 0)
820Sstevel@tonic-gate 		return (MSG_ORIG(MSG_GBL_ZERO));
830Sstevel@tonic-gate 
84*2352Sab196087 	conv_arg.oflags = conv_arg.rflags = flags;
85*2352Sab196087 	(void) conv_expn_field(&conv_arg);
861618Srie 
871618Srie 	return ((const char *)string);
880Sstevel@tonic-gate }
89