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 (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 24 */ 25 26 #ifndef _ELFCAP_DOT_H 27 #define _ELFCAP_DOT_H 28 29 #include <sys/types.h> 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /* 36 * Type used to represent capability bitmasks. This 32-bit type cannot be 37 * widened without breaking the ability to use them in ELFCLASS32 objects. 38 */ 39 typedef uint32_t elfcap_mask_t; 40 41 /* 42 * The elfcap code handles mappings to and from several string styles. 43 * The caller uses elfcap_style_t to specify the style to use. 44 * 45 * The bottom 16 bits are used to represent styles, and the upper 16 46 * bits are used for flags to modify default behavior. 47 */ 48 #define ELFCAP_STYLE_MASK(_style) (_style & 0xff) 49 50 typedef enum { 51 ELFCAP_STYLE_FULL = 1, /* Full formal name (e.g. AV_386_SSE) */ 52 ELFCAP_STYLE_UC = 2, /* Informal upper case (e.g. SSE) */ 53 ELFCAP_STYLE_LC = 3, /* Informal lower case (e.g. sse) */ 54 55 ELFCAP_STYLE_F_ICMP = 0x0100 /* Use case insensitive strcmp */ 56 } elfcap_style_t; 57 58 /* 59 * String descriptor: Contains the string and strlen(string). elfcap can 60 * be used in contexts (ld.so.1) where we do not want to make calls to 61 * string processing functions, so the length is calculated at compile time. 62 */ 63 typedef struct { 64 const char *s_str; 65 size_t s_len; 66 } elfcap_str_t; 67 68 /* 69 * Capabilities descriptor: This maps the integer bit value 70 * (c_val) to/from the various strings that represent it. 71 * 72 * c_val is normally expected to be a non-zero power of 2 73 * value (i.e. a single set bit). The value 0 is special, and 74 * used to represent a "reserved" placeholder in an array of 75 * capabilities. These reserved values have NULL string pointers, 76 * and are intended to be ignored by the processing code. 77 */ 78 typedef struct { 79 elfcap_mask_t c_val; /* Bit value */ 80 elfcap_str_t c_full; /* ELFCAP_STYLE_FULL */ 81 elfcap_str_t c_uc; /* ELFCAP_STYLE_UC */ 82 elfcap_str_t c_lc; /* ELFCAP_STYLE_LC */ 83 } elfcap_desc_t; 84 85 /* 86 * Valid format values: The various formats in which a generated 87 * string representing bitmap values can be displayed. 88 * 89 * This must be kept in sync with the format[] array in elfcap.c. 90 */ 91 typedef enum { 92 ELFCAP_FMT_SNGSPACE = 0, 93 ELFCAP_FMT_DBLSPACE = 1, 94 ELFCAP_FMT_PIPSPACE = 2 95 } elfcap_fmt_t; 96 97 /* 98 * Error codes: 99 */ 100 typedef enum { 101 ELFCAP_ERR_NONE = 0, /* no error */ 102 ELFCAP_ERR_BUFOVFL = 1, /* buffer overfow */ 103 ELFCAP_ERR_INVFMT = 2, /* invalid format */ 104 ELFCAP_ERR_UNKTAG = 3, /* unknown capabilities tag */ 105 ELFCAP_ERR_UNKMACH = 4, /* unknown machine type */ 106 ELFCAP_ERR_INVSTYLE = 5 /* unknown style */ 107 } elfcap_err_t; 108 109 110 /* 111 * # of each type of capability known to the system. These values 112 * must be kept in sync with the arrays found in elfcap.c. 113 */ 114 #define ELFCAP_NUM_SF1 3 115 #define ELFCAP_NUM_HW1_SPARC 17 116 #define ELFCAP_NUM_HW1_386 30 117 118 119 /* 120 * Given a capability section tag and value, call the proper underlying 121 * "to str" function to generate the string description. 122 */ 123 extern elfcap_err_t elfcap_tag_to_str(elfcap_style_t, uint64_t, 124 elfcap_mask_t, char *, size_t, elfcap_fmt_t, ushort_t); 125 126 /* 127 * The functions that convert from a specific capability value to 128 * a string representation all use the same common prototype. 129 */ 130 typedef elfcap_err_t elfcap_to_str_func_t(elfcap_style_t, elfcap_mask_t, char *, 131 size_t, elfcap_fmt_t, ushort_t); 132 133 extern elfcap_to_str_func_t elfcap_hw1_to_str; 134 extern elfcap_to_str_func_t elfcap_hw2_to_str; 135 extern elfcap_to_str_func_t elfcap_sf1_to_str; 136 137 /* 138 * The reverse mapping: Given a string representation, turn it back into 139 * integer form. 140 */ 141 typedef elfcap_mask_t elfcap_from_str_func_t(elfcap_style_t, 142 const char *, ushort_t mach); 143 144 /* 145 * Given a capability section tag and string, call the proper underlying 146 * "from str" function to generate the numeric value. 147 */ 148 extern elfcap_mask_t elfcap_tag_from_str(elfcap_style_t, uint64_t, 149 const char *, ushort_t); 150 151 extern elfcap_from_str_func_t elfcap_hw1_from_str; 152 extern elfcap_from_str_func_t elfcap_hw2_from_str; 153 extern elfcap_from_str_func_t elfcap_sf1_from_str; 154 155 /* 156 * These functions give access to the individual descriptor arrays. 157 * The caller is allowed to copy and use the string pointers contained 158 * in the descriptors, but must not alter them. Functions are used instead 159 * of making the arrays directly visible to preclude copy relocations in 160 * non-pic code. 161 */ 162 extern const elfcap_desc_t *elfcap_getdesc_hw1_sparc(void); 163 extern const elfcap_desc_t *elfcap_getdesc_hw1_386(void); 164 extern const elfcap_desc_t *elfcap_getdesc_sf1(void); 165 166 #ifdef __cplusplus 167 } 168 #endif 169 170 #endif /* _ELFCAP_DOT_H */ 171