xref: /illumos-gate/usr/src/cmd/sgs/libconv/common/phdr.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 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	<sys/elf_amd64.h>
34 #include	<_conv.h>
35 #include	<phdr_msg.h>
36 
37 static const Msg phdrs[] = {
38 	MSG_PT_NULL,		MSG_PT_LOAD,		MSG_PT_DYNAMIC,
39 	MSG_PT_INTERP,		MSG_PT_NOTE,		MSG_PT_SHLIB,
40 	MSG_PT_PHDR,		MSG_PT_TLS
41 };
42 
43 static const Msg uphdrs[] = {
44 	MSG_PT_SUNWBSS,		MSG_PT_SUNWSTACK,	MSG_PT_SUNWDTRACE,
45 	MSG_PT_SUNWCAP
46 };
47 
48 const char *
49 /* ARGSUSED 1 */
50 conv_phdrtyp_str(ushort_t mach, uint_t phdr)
51 {
52 	static char	string[STRSIZE] = { '\0' };
53 
54 	if (phdr < PT_NUM)
55 		return (MSG_ORIG(phdrs[phdr]));
56 	else if ((phdr >= PT_SUNWBSS) && (phdr <= PT_HISUNW))
57 		return (MSG_ORIG(uphdrs[phdr - PT_SUNWBSS]));
58 	else if ((phdr == PT_SUNW_UNWIND) && (mach == EM_AMD64))
59 		return (MSG_ORIG(MSG_PT_SUNW_UNWIND));
60 	else
61 		return (conv_invalid_str(string, STRSIZE, phdr, 0));
62 }
63 
64 #define	PHDRSZ	MSG_GBL_OSQBRKT_SIZE + \
65 		MSG_PF_X_SIZE + \
66 		MSG_PF_W_SIZE + \
67 		MSG_PF_R_SIZE + \
68 		MSG_GBL_CSQBRKT_SIZE
69 
70 const char *
71 conv_phdrflg_str(uint_t flags)
72 {
73 	static	char	string[PHDRSZ] = { '\0' };
74 
75 	if (flags == 0)
76 		return (MSG_ORIG(MSG_GBL_ZERO));
77 	else {
78 		(void) strcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT));
79 		if (flags & PF_X)
80 			(void) strcat(string, MSG_ORIG(MSG_PF_X));
81 		if (flags & PF_W)
82 			(void) strcat(string, MSG_ORIG(MSG_PF_W));
83 		if (flags & PF_R)
84 			(void) strcat(string, MSG_ORIG(MSG_PF_R));
85 		if (flags & PF_SUNW_FAILURE)
86 			(void) strcat(string, MSG_ORIG(MSG_PF_SUNW_FAILURE));
87 		(void) strcat(string, MSG_ORIG(MSG_GBL_CSQBRKT));
88 
89 		return ((const char *)string);
90 	}
91 }
92