xref: /illumos-gate/usr/src/cmd/sgs/libconv/common/phdr.c (revision 5aefb6555731130ca4fd295960123d71f2d21fe8)
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 char		string[CONV_INV_STRSIZE];
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	MSG_GBL_OSQBRKT_SIZE + \
62 		MSG_PF_X_SIZE + \
63 		MSG_PF_W_SIZE + \
64 		MSG_PF_R_SIZE + \
65 		MSG_PF_SUNW_FAILURE_SIZE + \
66 		CONV_INV_STRSIZE + MSG_GBL_CSQBRKT_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 
80 	if (flags == 0)
81 		return (MSG_ORIG(MSG_GBL_ZERO));
82 
83 	(void) strlcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT), PHDRSZ);
84 	if (conv_expn_field(string, PHDRSZ, vda, flags, flags, 0, 0))
85 		(void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), PHDRSZ);
86 
87 	return ((const char *)string);
88 }
89