xref: /illumos-gate/usr/src/cmd/sgs/include/conv.h (revision 24da5b34)
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) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #ifndef	_CONV_H
31 #define	_CONV_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 /*
36  * Global include file for conversion library.
37  */
38 
39 #include <stdlib.h>
40 #include <libelf.h>
41 #include <dlfcn.h>
42 #include <libld.h>
43 #include <sgs.h>
44 #include <machdep.h>
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 /*
51  * Configuration features available - maintained here (instead of debug.h)
52  * to save libconv from having to include debug.h which results in numerous
53  * "declared but not used or defined" lint errors.
54  */
55 #define	CONF_EDLIBPATH	0x000100	/* ELF default library path */
56 #define	CONF_ESLIBPATH	0x000200	/* ELF secure library path */
57 #define	CONF_ADLIBPATH	0x000400	/* AOUT default library path */
58 #define	CONF_ASLIBPATH	0x000800	/* AOUT secure library path */
59 #define	CONF_DIRCFG	0x001000	/* directory configuration available */
60 #define	CONF_OBJALT	0x002000	/* object alternatives available */
61 #define	CONF_MEMRESV	0x004000	/* memory reservation required */
62 #define	CONF_ENVS	0x008000	/* environment variables available */
63 #define	CONF_FLTR	0x010000	/* filter information available */
64 #define	CONF_FEATMSK	0xffff00
65 
66 /*
67  * Various values that can't be matched to a symbolic definition are converted
68  * to a numeric string.  Each function that may require this fallback maintains
69  * its own static string buffer, as many conversion routines may be called for
70  * one final diagnostic.  See conv_invalid_val().
71  *
72  * The string size reflects the largest possible decimal number plus a trailing
73  * null.  Typically however, values are hex with a leading "0x".
74  */
75 #if	defined(_ELF64)
76 #define	CONV_INV_STRSIZE	22
77 #else
78 #define	CONV_INV_STRSIZE	12
79 #endif
80 
81 /*
82  * Some libconv routines require the caller to supply the buffer used by
83  * conv_invalid_val().
84  */
85 typedef char Conv_inv_buf_t[CONV_INV_STRSIZE];
86 
87 /*
88  * Flags that alter standard formatting for conversion routines.
89  */
90 #define	CONV_FMT_DECIMAL	0x01	/* conv_invalid_val() should print */
91 					/*    integer print as decimal */
92 					/*    (default is hex) */
93 #define	CONV_FMT_SPACE		0x02	/* conv_invalid_val() should append */
94 					/*    a space after the number.  */
95 #define	CONV_FMT_ALTDUMP	0x04	/* Output strings using the versions */
96 					/*    used by the dump program. */
97 #define	CONV_FMT_ALTFILE	0x08	/* Output strings in the form used */
98 					/*    by the file(1) command */
99 #define	CONV_FMT_ALTCRLE	0x10	/* Output strings in the form used */
100 					/*    by the crle(1) command */
101 
102 /*
103  * Mask of CONV_FMT bits that reflect a desire to use alternate strings.
104  */
105 #define	CONV_FMTALTMASK	(CONV_FMT_ALTDUMP | CONV_FMT_ALTFILE)
106 
107 /*
108  * The expansion of bit-field data items is driven from a value descriptor and
109  * the conv_expn_field() routine.
110  */
111 typedef struct {
112 	Xword		v_val;		/* expansion value */
113 	const char	*v_msg;		/* associated message string */
114 } Val_desc;
115 
116 /*
117  * conv_expn_field() is willing to supply default strings for the
118  * prefix, separator, and suffix arguments, if they are passed as NULL.
119  * The caller needs to know how much room to allow for these items.
120  * These values supply those sizes.
121  */
122 #define	CONV_EXPN_FIELD_DEF_PREFIX_SIZE	2	/* Default is "[ " */
123 #define	CONV_EXPN_FIELD_DEF_SEP_SIZE	1	/* Default is " " */
124 #define	CONV_EXPN_FIELD_DEF_SUFFIX_SIZE	2	/* Default is " ]" */
125 
126 /*
127  * conv_expn_field() requires a large number of inputs, many of which
128  * can be NULL to accept default behavior. An argument of the following
129  * type is used to supply them.
130  */
131 typedef struct {
132 	char *buf;		/* Buffer to receive generated string */
133 	size_t bufsize;		/* sizeof(buf) */
134 	const Val_desc *vdp;	/* Array of value descriptors, giving the */
135 				/*	possible bit values, and their */
136 				/*	corresponding strings. Note that the */
137 				/*	final element must contain only NULL */
138 				/*	values. This terminates the list. */
139 	const char **lead_str;	/* NULL, or array of pointers to strings to */
140 				/*	be output at the head of the list. */
141 				/*	Last entry must be NULL. */
142 	Xword oflags;		/* Bits for which output strings are desired */
143 	Xword rflags;		/* Bits for which a numeric value should be */
144 				/*	output if vdp does not provide str. */
145 				/*	Must be a proper subset of oflags */
146 	const char *prefix;	/* NULL, or string to prefix output with */
147 				/*	If NULL, "[ " is used. */
148 	const char *sep;	/* NULL, or string to separate output items */
149 				/*	with. If NULL, " " is used. */
150 	const char *suffix;	/* NULL, or string to suffix output with */
151 				/*	If NULL, " ]" is used. */
152 } CONV_EXPN_FIELD_ARG;
153 
154 /*
155  * Define all generic interfaces.
156  */
157 extern	uchar_t		conv_check_native(char **, char **);
158 extern	const char	*conv_config_feat(int);
159 extern	const char	*conv_config_obj(ushort_t);
160 extern	const char	*conv_config_upm(const char *, const char *,
161 			    const char *, size_t);
162 extern	const char	*conv_def_tag(Symref);
163 extern	const char	*conv_demangle_name(const char *);
164 extern	const char	*conv_dl_flag(int, int);
165 extern	const char	*conv_dl_mode(int, int);
166 extern	const char	*conv_dwarf_ehe(uint_t);
167 extern	const char	*conv_elfdata_type(Elf_Type);
168 extern	const char	*conv_grphdl_flags(uint_t);
169 extern	const char	*conv_grpdesc_flags(uint_t);
170 extern	Isa_desc	*conv_isalist(void);
171 extern	const char	*conv_lddstub(int);
172 extern	const char	*conv_seg_flags(Half);
173 extern	int		conv_sys_eclass();
174 extern	Uts_desc	*conv_uts(void);
175 extern	const char	*conv_ver_flags(Half);
176 extern	const char	*conv_ver_index(Versym);
177 
178 /*
179  * Define all class specific routines.
180  */
181 #if	defined(_ELF64)
182 #define	conv_bnd_obj		conv64_bnd_obj
183 #define	conv_bnd_type		conv64_bnd_type
184 #define	conv_cap_tag		conv64_cap_tag
185 #define	conv_cap_val		conv64_cap_val
186 #define	conv_cap_val_hw1	conv64_cap_val_hw1
187 #define	conv_cap_val_sf1	conv64_cap_val_sf1
188 #define	conv_dyn_feature1	conv64_dyn_feature1
189 #define	conv_dyn_flag1		conv64_dyn_flag1
190 #define	conv_dyn_flag		conv64_dyn_flag
191 #define	conv_dyn_posflag1	conv64_dyn_posflag1
192 #define	conv_dyn_tag		conv64_dyn_tag
193 #define	conv_ehdr_class		conv64_ehdr_class
194 #define	conv_ehdr_data		conv64_ehdr_data
195 #define	conv_ehdr_flags		conv64_ehdr_flags
196 #define	conv_ehdr_mach		conv64_ehdr_mach
197 #define	conv_ehdr_osabi		conv64_ehdr_osabi
198 #define	conv_ehdr_type		conv64_ehdr_type
199 #define	conv_ehdr_vers		conv64_ehdr_vers
200 #define	conv_expn_field		conv64_expn_field
201 #define	conv_invalid_val	conv64_invalid_val
202 #define	conv_phdr_flags		conv64_phdr_flags
203 #define	conv_phdr_type		conv64_phdr_type
204 #define	conv_reject_desc	conv64_reject_desc
205 #define	conv_reloc_type		conv64_reloc_type
206 #define	conv_reloc_386_type	conv64_reloc_386_type
207 #define	conv_reloc_amd64_type	conv64_reloc_amd64_type
208 #define	conv_reloc_SPARC_type	conv64_reloc_SPARC_type
209 #define	conv_sec_flags		conv64_sec_flags
210 #define	conv_sec_linkinfo	conv64_sec_linkinfo
211 #define	conv_sec_type		conv64_sec_type
212 #define	conv_sym_info_bind	conv64_sym_info_bind
213 #define	conv_sym_info_type	conv64_sym_info_type
214 #define	conv_sym_shndx		conv64_sym_shndx
215 #define	conv_sym_other		conv64_sym_other
216 #define	conv_sym_value		conv64_sym_value
217 #define	conv_sym_SPARC_value	conv64_sym_SPARC_value
218 #else
219 #define	conv_bnd_obj		conv32_bnd_obj
220 #define	conv_bnd_type		conv32_bnd_type
221 #define	conv_cap_tag		conv32_cap_tag
222 #define	conv_cap_val		conv32_cap_val
223 #define	conv_cap_val_hw1	conv32_cap_val_hw1
224 #define	conv_cap_val_sf1	conv32_cap_val_sf1
225 #define	conv_dyn_feature1	conv32_dyn_feature1
226 #define	conv_dyn_flag1		conv32_dyn_flag1
227 #define	conv_dyn_flag		conv32_dyn_flag
228 #define	conv_dyn_posflag1	conv32_dyn_posflag1
229 #define	conv_dyn_tag		conv32_dyn_tag
230 #define	conv_ehdr_class		conv32_ehdr_class
231 #define	conv_ehdr_data		conv32_ehdr_data
232 #define	conv_ehdr_flags		conv32_ehdr_flags
233 #define	conv_ehdr_mach		conv32_ehdr_mach
234 #define	conv_ehdr_osabi		conv32_ehdr_osabi
235 #define	conv_ehdr_type		conv32_ehdr_type
236 #define	conv_ehdr_vers		conv32_ehdr_vers
237 #define	conv_expn_field		conv32_expn_field
238 #define	conv_invalid_val	conv32_invalid_val
239 #define	conv_phdr_flags		conv32_phdr_flags
240 #define	conv_phdr_type		conv32_phdr_type
241 #define	conv_reject_desc	conv32_reject_desc
242 #define	conv_reloc_type		conv32_reloc_type
243 #define	conv_reloc_386_type	conv32_reloc_386_type
244 #define	conv_reloc_amd64_type	conv32_reloc_amd64_type
245 #define	conv_reloc_SPARC_type	conv32_reloc_SPARC_type
246 #define	conv_sec_flags		conv32_sec_flags
247 #define	conv_sec_linkinfo	conv32_sec_linkinfo
248 #define	conv_sec_type		conv32_sec_type
249 #define	conv_sym_info_bind	conv32_sym_info_bind
250 #define	conv_sym_info_type	conv32_sym_info_type
251 #define	conv_sym_shndx		conv32_sym_shndx
252 #define	conv_sym_other		conv32_sym_other
253 #define	conv_sym_value		conv32_sym_value
254 #define	conv_sym_SPARC_value	conv32_sym_SPARC_value
255 #endif
256 
257 extern	const char	*conv_bnd_obj(uint_t);
258 extern	const char	*conv_bnd_type(uint_t);
259 extern	const char	*conv_cap_tag(Xword);
260 extern	const char	*conv_cap_val(Xword, Xword, Half);
261 extern	const char	*conv_cap_val_hw1(Xword, Half);
262 extern	const char	*conv_cap_val_sf1(Xword, Half);
263 extern	const char	*conv_dyn_flag1(Xword);
264 extern	const char	*conv_dyn_flag(Xword, int);
265 extern	const char	*conv_dyn_posflag1(Xword, int);
266 extern	const char	*conv_dyn_tag(Xword, Half, int);
267 extern	const char	*conv_dyn_feature1(Xword, int);
268 extern	const char	*conv_ehdr_class(uchar_t, int);
269 extern	const char	*conv_ehdr_data(uchar_t, int);
270 extern	const char	*conv_ehdr_flags(Half, Word);
271 extern	const char	*conv_ehdr_mach(Half, int);
272 extern	const char	*conv_ehdr_osabi(uchar_t, int);
273 extern	const char	*conv_ehdr_type(Half, int);
274 extern	const char	*conv_ehdr_vers(Word, int);
275 extern	int		conv_expn_field(CONV_EXPN_FIELD_ARG *);
276 extern	const char	*conv_invalid_val(char *, size_t, Xword, int);
277 extern	const char	*conv_phdr_flags(Word);
278 extern	const char	*conv_phdr_type(Half, Word, int);
279 extern	const char	*conv_reject_desc(Rej_desc *);
280 extern	const char	*conv_reloc_type(Half, Word, int);
281 extern	const char	*conv_reloc_386_type(Word, int);
282 extern	const char	*conv_reloc_amd64_type(Word, int);
283 extern	const char	*conv_reloc_SPARC_type(Word, int);
284 extern	const char	*conv_sec_flags(Xword);
285 extern	const char	*conv_sec_linkinfo(Word, Xword, Conv_inv_buf_t);
286 extern	const char	*conv_sec_type(Half, Word, int);
287 extern	const char	*conv_sym_info_bind(uchar_t, int);
288 extern	const char	*conv_sym_info_type(Half, uchar_t, int);
289 extern	const char	*conv_sym_shndx(Half);
290 extern	const char	*conv_sym_other(uchar_t);
291 extern	const char	*conv_sym_value(Half, uchar_t, Addr);
292 extern	const char	*conv_sym_SPARC_value(Addr, int);
293 
294 #ifdef	__cplusplus
295 }
296 #endif
297 
298 #endif /* _CONV_H */
299