xref: /onnv-gate/usr/src/common/elfcap/elfcap.h (revision 13134:8315ff49e22e)
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
55565Sab196087  * Common Development and Distribution License (the "License").
65565Sab196087  * 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  */
217833SRod.Evans@Sun.COM 
220Sstevel@tonic-gate /*
23*13134Skuriakose.kuruvilla@oracle.com  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _ELFCAP_DOT_H
270Sstevel@tonic-gate #define	_ELFCAP_DOT_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #ifdef	__cplusplus
320Sstevel@tonic-gate extern "C" {
330Sstevel@tonic-gate #endif
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /*
3611734SAli.Bahrami@Sun.COM  * Type used to represent capability bitmasks. This 32-bit type cannot be
3711734SAli.Bahrami@Sun.COM  * widened without breaking the ability to use them in ELFCLASS32 objects.
3811734SAli.Bahrami@Sun.COM  */
3911734SAli.Bahrami@Sun.COM typedef uint32_t elfcap_mask_t;
4011734SAli.Bahrami@Sun.COM 
4111734SAli.Bahrami@Sun.COM /*
425565Sab196087  * The elfcap code handles mappings to and from several string styles.
435565Sab196087  * The caller uses elfcap_style_t to specify the style to use.
4411734SAli.Bahrami@Sun.COM  *
4511734SAli.Bahrami@Sun.COM  * The bottom 16 bits are used to represent styles, and the upper 16
4611734SAli.Bahrami@Sun.COM  * bits are used for flags to modify default behavior.
475565Sab196087  */
4811734SAli.Bahrami@Sun.COM #define	ELFCAP_STYLE_MASK(_style) (_style & 0xff)
4911734SAli.Bahrami@Sun.COM 
505565Sab196087 typedef enum {
515565Sab196087 	ELFCAP_STYLE_FULL =	1,	/* Full formal name (e.g. AV_386_SSE) */
525565Sab196087 	ELFCAP_STYLE_UC = 	2,	/* Informal upper case (e.g. SSE) */
5311734SAli.Bahrami@Sun.COM 	ELFCAP_STYLE_LC = 	3,	/* Informal lower case (e.g. sse) */
5411734SAli.Bahrami@Sun.COM 
5511734SAli.Bahrami@Sun.COM 	ELFCAP_STYLE_F_ICMP =	0x0100	 /* Use case insensitive strcmp */
565565Sab196087 } elfcap_style_t;
575565Sab196087 
585565Sab196087 /*
595565Sab196087  * String descriptor: Contains the string and strlen(string). elfcap can
605565Sab196087  * be used in contexts (ld.so.1) where we do not want to make calls to
615565Sab196087  * string processing functions, so the length is calculated at compile time.
620Sstevel@tonic-gate  */
630Sstevel@tonic-gate typedef	struct {
645565Sab196087 	const char	*s_str;
655565Sab196087 	size_t		s_len;
665565Sab196087 } elfcap_str_t;
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*
695565Sab196087  * Capabilities descriptor: This maps the integer bit value
705565Sab196087  * (c_val) to/from the various strings that represent it.
715565Sab196087  *
725565Sab196087  * c_val is normally expected to be a non-zero power of 2
735565Sab196087  * value (i.e. a single set bit). The value 0 is special, and
745565Sab196087  * used to represent a "reserved" placeholder in an array of
755565Sab196087  * capabilities. These reserved values have NULL string pointers,
765565Sab196087  * and are intended to be ignored by the processing code.
770Sstevel@tonic-gate  */
785565Sab196087 typedef	struct {
7911734SAli.Bahrami@Sun.COM 	elfcap_mask_t	c_val;		/* Bit value */
805565Sab196087 	elfcap_str_t	c_full;		/* ELFCAP_STYLE_FULL */
815565Sab196087 	elfcap_str_t	c_uc;		/* ELFCAP_STYLE_UC */
825565Sab196087 	elfcap_str_t	c_lc;		/* ELFCAP_STYLE_LC */
835565Sab196087 } elfcap_desc_t;
845565Sab196087 
855565Sab196087 /*
865565Sab196087  * Valid format values: The various formats in which a generated
875565Sab196087  * string representing bitmap values can be displayed.
885565Sab196087  *
895565Sab196087  * This must be kept in sync with the format[] array in elfcap.c.
905565Sab196087  */
915565Sab196087 typedef enum {
925565Sab196087 	ELFCAP_FMT_SNGSPACE =		0,
935565Sab196087 	ELFCAP_FMT_DBLSPACE =		1,
945565Sab196087 	ELFCAP_FMT_PIPSPACE =		2
955565Sab196087 } elfcap_fmt_t;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate /*
985565Sab196087  * Error codes:
990Sstevel@tonic-gate  */
1005565Sab196087 typedef enum {
1015565Sab196087 	ELFCAP_ERR_NONE =		0,	/* no error */
1025565Sab196087 	ELFCAP_ERR_BUFOVFL =		1,	/* buffer overfow */
1035565Sab196087 	ELFCAP_ERR_INVFMT =		2,	/* invalid format */
1045565Sab196087 	ELFCAP_ERR_UNKTAG =		3,	/* unknown capabilities tag */
1055565Sab196087 	ELFCAP_ERR_UNKMACH =		4,	/* unknown machine type */
1065565Sab196087 	ELFCAP_ERR_INVSTYLE =		5	/* unknown style */
1075565Sab196087 } elfcap_err_t;
1085565Sab196087 
1090Sstevel@tonic-gate 
1105565Sab196087 /*
1115565Sab196087  * # of each type of capability known to the system. These values
1129878SAli.Bahrami@Sun.COM  * must be kept in sync with the arrays found in elfcap.c.
1135565Sab196087  */
1147833SRod.Evans@Sun.COM #define	ELFCAP_NUM_SF1			3
1159202SJason.Beloro@Sun.COM #define	ELFCAP_NUM_HW1_SPARC		17
116*13134Skuriakose.kuruvilla@oracle.com #define	ELFCAP_NUM_HW1_386		30
1175565Sab196087 
1185565Sab196087 
1195565Sab196087 /*
1205565Sab196087  * Given a capability section tag and value, call the proper underlying
1215565Sab196087  * "to str" function to generate the string description.
1225565Sab196087  */
1235565Sab196087 extern elfcap_err_t elfcap_tag_to_str(elfcap_style_t, uint64_t,
12411734SAli.Bahrami@Sun.COM     elfcap_mask_t, char *, size_t, elfcap_fmt_t, ushort_t);
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /*
1275565Sab196087  * The functions that convert from a specific capability value to
1285565Sab196087  * a string representation all use the same common prototype.
1290Sstevel@tonic-gate  */
13011734SAli.Bahrami@Sun.COM typedef elfcap_err_t elfcap_to_str_func_t(elfcap_style_t, elfcap_mask_t, char *,
1315565Sab196087     size_t, elfcap_fmt_t, ushort_t);
1325565Sab196087 
1335565Sab196087 extern elfcap_to_str_func_t elfcap_hw1_to_str;
13411734SAli.Bahrami@Sun.COM extern elfcap_to_str_func_t elfcap_hw2_to_str;
1355565Sab196087 extern elfcap_to_str_func_t elfcap_sf1_to_str;
1360Sstevel@tonic-gate 
1375565Sab196087 /*
1385565Sab196087  * The reverse mapping: Given a string representation, turn it back into
1395565Sab196087  * integer form.
1405565Sab196087  */
14111734SAli.Bahrami@Sun.COM typedef elfcap_mask_t elfcap_from_str_func_t(elfcap_style_t,
1425565Sab196087     const char *, ushort_t mach);
1430Sstevel@tonic-gate 
14411734SAli.Bahrami@Sun.COM /*
14511734SAli.Bahrami@Sun.COM  * Given a capability section tag and string, call the proper underlying
14611734SAli.Bahrami@Sun.COM  * "from str" function to generate the numeric value.
14711734SAli.Bahrami@Sun.COM  */
14811734SAli.Bahrami@Sun.COM extern elfcap_mask_t elfcap_tag_from_str(elfcap_style_t, uint64_t,
14911734SAli.Bahrami@Sun.COM     const char *, ushort_t);
15011734SAli.Bahrami@Sun.COM 
1515565Sab196087 extern elfcap_from_str_func_t elfcap_hw1_from_str;
15211734SAli.Bahrami@Sun.COM extern elfcap_from_str_func_t elfcap_hw2_from_str;
1535565Sab196087 extern elfcap_from_str_func_t elfcap_sf1_from_str;
1545565Sab196087 
1555565Sab196087 /*
1565565Sab196087  * These functions give access to the individual descriptor arrays.
1575565Sab196087  * The caller is allowed to copy and use the string pointers contained
1585565Sab196087  * in the descriptors, but must not alter them. Functions are used instead
1595565Sab196087  * of making the arrays directly visible to preclude copy relocations in
1605565Sab196087  * non-pic code.
1615565Sab196087  */
1625565Sab196087 extern const elfcap_desc_t *elfcap_getdesc_hw1_sparc(void);
1635565Sab196087 extern const elfcap_desc_t *elfcap_getdesc_hw1_386(void);
1645565Sab196087 extern const elfcap_desc_t *elfcap_getdesc_sf1(void);
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate #ifdef	__cplusplus
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate #endif
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate #endif /* _ELFCAP_DOT_H */
171