xref: /illumos-gate/usr/src/common/elfcap/elfcap.h (revision 56726c7e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
599f63845Sab  * Common Development and Distribution License (the "License").
699f63845Sab  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21bebb829dSRod Evans 
227c478bd9Sstevel@tonic-gate /*
237af88ac7SKuriakose Kuruvilla  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24e4f6ce70SRobert Mustacchi  * Copyright 2019, Joyent, Inc.
25*56726c7eSRobert Mustacchi  * Copyright 2022 Oxide Computer Company
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef _ELFCAP_DOT_H
297c478bd9Sstevel@tonic-gate #define	_ELFCAP_DOT_H
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
3769112eddSAli Bahrami /*
3869112eddSAli Bahrami  * Type used to represent capability bitmasks. This 32-bit type cannot be
3969112eddSAli Bahrami  * widened without breaking the ability to use them in ELFCLASS32 objects.
4069112eddSAli Bahrami  */
4169112eddSAli Bahrami typedef uint32_t elfcap_mask_t;
4269112eddSAli Bahrami 
437c478bd9Sstevel@tonic-gate /*
4499f63845Sab  * The elfcap code handles mappings to and from several string styles.
4599f63845Sab  * The caller uses elfcap_style_t to specify the style to use.
4669112eddSAli Bahrami  *
4769112eddSAli Bahrami  * The bottom 16 bits are used to represent styles, and the upper 16
4869112eddSAli Bahrami  * bits are used for flags to modify default behavior.
4999f63845Sab  */
5069112eddSAli Bahrami #define	ELFCAP_STYLE_MASK(_style) (_style & 0xff)
5169112eddSAli Bahrami 
5299f63845Sab typedef enum {
5399f63845Sab 	ELFCAP_STYLE_FULL =	1,	/* Full formal name (e.g. AV_386_SSE) */
54cff040f3SRobert Mustacchi 	ELFCAP_STYLE_UC =	2,	/* Informal upper case (e.g. SSE) */
55cff040f3SRobert Mustacchi 	ELFCAP_STYLE_LC =	3,	/* Informal lower case (e.g. sse) */
5669112eddSAli Bahrami 
5769112eddSAli Bahrami 	ELFCAP_STYLE_F_ICMP =	0x0100	 /* Use case insensitive strcmp */
5899f63845Sab } elfcap_style_t;
5999f63845Sab 
6099f63845Sab /*
6199f63845Sab  * String descriptor: Contains the string and strlen(string). elfcap can
6299f63845Sab  * be used in contexts (ld.so.1) where we do not want to make calls to
6399f63845Sab  * string processing functions, so the length is calculated at compile time.
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate typedef	struct {
6699f63845Sab 	const char	*s_str;
6799f63845Sab 	size_t		s_len;
6899f63845Sab } elfcap_str_t;
6999f63845Sab 
7099f63845Sab /*
7199f63845Sab  * Capabilities descriptor: This maps the integer bit value
7299f63845Sab  * (c_val) to/from the various strings that represent it.
7399f63845Sab  *
7499f63845Sab  * c_val is normally expected to be a non-zero power of 2
7599f63845Sab  * value (i.e. a single set bit). The value 0 is special, and
7699f63845Sab  * used to represent a "reserved" placeholder in an array of
7799f63845Sab  * capabilities. These reserved values have NULL string pointers,
7899f63845Sab  * and are intended to be ignored by the processing code.
7999f63845Sab  */
8099f63845Sab typedef	struct {
8169112eddSAli Bahrami 	elfcap_mask_t	c_val;		/* Bit value */
8299f63845Sab 	elfcap_str_t	c_full;		/* ELFCAP_STYLE_FULL */
8399f63845Sab 	elfcap_str_t	c_uc;		/* ELFCAP_STYLE_UC */
8499f63845Sab 	elfcap_str_t	c_lc;		/* ELFCAP_STYLE_LC */
8599f63845Sab } elfcap_desc_t;
8699f63845Sab 
8799f63845Sab /*
8899f63845Sab  * Valid format values: The various formats in which a generated
8999f63845Sab  * string representing bitmap values can be displayed.
9099f63845Sab  *
9199f63845Sab  * This must be kept in sync with the format[] array in elfcap.c.
9299f63845Sab  */
9399f63845Sab typedef enum {
9499f63845Sab 	ELFCAP_FMT_SNGSPACE =		0,
9599f63845Sab 	ELFCAP_FMT_DBLSPACE =		1,
9699f63845Sab 	ELFCAP_FMT_PIPSPACE =		2
9799f63845Sab } elfcap_fmt_t;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /*
10099f63845Sab  * Error codes:
1017c478bd9Sstevel@tonic-gate  */
10299f63845Sab typedef enum {
10399f63845Sab 	ELFCAP_ERR_NONE =		0,	/* no error */
10499f63845Sab 	ELFCAP_ERR_BUFOVFL =		1,	/* buffer overfow */
10599f63845Sab 	ELFCAP_ERR_INVFMT =		2,	/* invalid format */
10699f63845Sab 	ELFCAP_ERR_UNKTAG =		3,	/* unknown capabilities tag */
10799f63845Sab 	ELFCAP_ERR_UNKMACH =		4,	/* unknown machine type */
10899f63845Sab 	ELFCAP_ERR_INVSTYLE =		5	/* unknown style */
10999f63845Sab } elfcap_err_t;
11099f63845Sab 
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /*
11399f63845Sab  * # of each type of capability known to the system. These values
1144a8d0ea7SAli Bahrami  * must be kept in sync with the arrays found in elfcap.c.
1157c478bd9Sstevel@tonic-gate  */
116bebb829dSRod Evans #define	ELFCAP_NUM_SF1			3
1171ba081eeSToomas Soome #define	ELFCAP_NUM_HW1_SPARC		30
118faa20166SBryan Cantrill #define	ELFCAP_NUM_HW1_386		32
119*56726c7eSRobert Mustacchi #define	ELFCAP_NUM_HW2_386		32
120*56726c7eSRobert Mustacchi #define	ELFCAP_NUM_HW3_386		2
12199f63845Sab 
122*56726c7eSRobert Mustacchi /*
123*56726c7eSRobert Mustacchi  * String buffer lengths that should be sufficient for elfcap values today. This
124*56726c7eSRobert Mustacchi  * is used because this is compiled into programs. Do not assume it won't change
125*56726c7eSRobert Mustacchi  * or make it part of an ABI. This uses the worst case values as calculated by
126*56726c7eSRobert Mustacchi  * the elfcap_chk program that is run in sgs and checked as part of the build.
127*56726c7eSRobert Mustacchi  */
128*56726c7eSRobert Mustacchi #define	ELFCAP_SF1_BUFSIZE	73
129*56726c7eSRobert Mustacchi #define	ELFCAP_HW1_BUFSIZE	528
130*56726c7eSRobert Mustacchi #define	ELFCAP_HW2_BUFSIZE	632
131*56726c7eSRobert Mustacchi #define	ELFCAP_HW3_BUFSIZE	66
1327c478bd9Sstevel@tonic-gate 
13399f63845Sab /*
13499f63845Sab  * Given a capability section tag and value, call the proper underlying
13599f63845Sab  * "to str" function to generate the string description.
13699f63845Sab  */
13799f63845Sab extern elfcap_err_t elfcap_tag_to_str(elfcap_style_t, uint64_t,
13869112eddSAli Bahrami     elfcap_mask_t, char *, size_t, elfcap_fmt_t, ushort_t);
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /*
14199f63845Sab  * The functions that convert from a specific capability value to
14299f63845Sab  * a string representation all use the same common prototype.
1437c478bd9Sstevel@tonic-gate  */
14469112eddSAli Bahrami typedef elfcap_err_t elfcap_to_str_func_t(elfcap_style_t, elfcap_mask_t, char *,
14599f63845Sab     size_t, elfcap_fmt_t, ushort_t);
1467c478bd9Sstevel@tonic-gate 
14799f63845Sab extern elfcap_to_str_func_t elfcap_hw1_to_str;
14869112eddSAli Bahrami extern elfcap_to_str_func_t elfcap_hw2_to_str;
149*56726c7eSRobert Mustacchi extern elfcap_to_str_func_t elfcap_hw3_to_str;
15099f63845Sab extern elfcap_to_str_func_t elfcap_sf1_to_str;
1517c478bd9Sstevel@tonic-gate 
15299f63845Sab /*
15399f63845Sab  * The reverse mapping: Given a string representation, turn it back into
15499f63845Sab  * integer form.
15599f63845Sab  */
15669112eddSAli Bahrami typedef elfcap_mask_t elfcap_from_str_func_t(elfcap_style_t,
15799f63845Sab     const char *, ushort_t mach);
15899f63845Sab 
15969112eddSAli Bahrami /*
16069112eddSAli Bahrami  * Given a capability section tag and string, call the proper underlying
16169112eddSAli Bahrami  * "from str" function to generate the numeric value.
16269112eddSAli Bahrami  */
16369112eddSAli Bahrami extern elfcap_mask_t elfcap_tag_from_str(elfcap_style_t, uint64_t,
16469112eddSAli Bahrami     const char *, ushort_t);
16569112eddSAli Bahrami 
16699f63845Sab extern elfcap_from_str_func_t elfcap_hw1_from_str;
16769112eddSAli Bahrami extern elfcap_from_str_func_t elfcap_hw2_from_str;
16899f63845Sab extern elfcap_from_str_func_t elfcap_sf1_from_str;
169*56726c7eSRobert Mustacchi extern elfcap_from_str_func_t elfcap_hw3_from_str;
17099f63845Sab 
17199f63845Sab /*
17299f63845Sab  * These functions give access to the individual descriptor arrays.
17399f63845Sab  * The caller is allowed to copy and use the string pointers contained
17499f63845Sab  * in the descriptors, but must not alter them. Functions are used instead
17599f63845Sab  * of making the arrays directly visible to preclude copy relocations in
17699f63845Sab  * non-pic code.
17799f63845Sab  */
178*56726c7eSRobert Mustacchi extern const elfcap_str_t *elfcap_getdesc_formats(void);
17999f63845Sab extern const elfcap_desc_t *elfcap_getdesc_hw1_sparc(void);
18099f63845Sab extern const elfcap_desc_t *elfcap_getdesc_hw1_386(void);
181*56726c7eSRobert Mustacchi extern const elfcap_desc_t *elfcap_getdesc_hw2_386(void);
182*56726c7eSRobert Mustacchi extern const elfcap_desc_t *elfcap_getdesc_hw3_386(void);
18399f63845Sab extern const elfcap_desc_t *elfcap_getdesc_sf1(void);
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate #endif
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #endif /* _ELFCAP_DOT_H */
190