xref: /titanic_44/usr/src/cmd/sgs/libconv/common/phdr.c (revision 18c2aff776a775d34a4c9893a4c72e0434d68e36)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * String conversion routines for program header attributes.
31  */
32 #include	<string.h>
33 #include	<_conv.h>
34 #include	<phdr_msg.h>
35 
36 static const Msg uphdrs[] = {
37 	MSG_PT_SUNWBSS,		MSG_PT_SUNWSTACK,	MSG_PT_SUNWDTRACE,
38 	MSG_PT_SUNWCAP
39 };
40 
41 const char *
42 conv_phdr_type(Half mach, Word type)
43 {
44 	static Conv_inv_buf_t	string;
45 	static const Msg	phdrs[] = {
46 		MSG_PT_NULL,		MSG_PT_LOAD,		MSG_PT_DYNAMIC,
47 		MSG_PT_INTERP,		MSG_PT_NOTE,		MSG_PT_SHLIB,
48 		MSG_PT_PHDR,		MSG_PT_TLS
49 	};
50 
51 	if (type < PT_NUM)
52 		return (MSG_ORIG(phdrs[type]));
53 	else if ((type >= PT_SUNWBSS) && (type <= PT_HISUNW))
54 		return (MSG_ORIG(uphdrs[type - PT_SUNWBSS]));
55 	else if ((type == PT_SUNW_UNWIND) && (mach == EM_AMD64))
56 		return (MSG_ORIG(MSG_PT_SUNW_UNWIND));
57 	else
58 		return (conv_invalid_val(string, CONV_INV_STRSIZE, type, 0));
59 }
60 
61 #define	PHDRSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
62 		MSG_PF_X_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
63 		MSG_PF_W_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
64 		MSG_PF_R_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
65 		MSG_PF_SUNW_FAILURE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
66 		CONV_INV_STRSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
67 
68 const char *
69 conv_phdr_flags(Word flags)
70 {
71 	static char string[PHDRSZ];
72 	static Val_desc vda[] = {
73 		{ PF_X,			MSG_ORIG(MSG_PF_X) },
74 		{ PF_W,			MSG_ORIG(MSG_PF_W) },
75 		{ PF_R,			MSG_ORIG(MSG_PF_R) },
76 		{ PF_SUNW_FAILURE,	MSG_ORIG(MSG_PF_SUNW_FAILURE) },
77 		{ 0,			0 }
78 	};
79 	static CONV_EXPN_FIELD_ARG conv_arg = { string, sizeof (string), vda };
80 
81 	if (flags == 0)
82 		return (MSG_ORIG(MSG_GBL_ZERO));
83 
84 	conv_arg.oflags = conv_arg.rflags = flags;
85 	(void) conv_expn_field(&conv_arg);
86 
87 	return ((const char *)string);
88 }
89