xref: /illumos-gate/usr/src/cmd/sgs/include/conv.h (revision 915894ef19890baaed00080f85f6b69e225cda98)
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 (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
27  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
28  * Copyright (c) 2018, Joyent, Inc.
29  * Copyright 2016 RackTop Systems.
30  * Copyright 2020 Oxide Computer Company
31  */
32 
33 #ifndef	_CONV_H
34 #define	_CONV_H
35 
36 /*
37  * Global include file for conversion library.
38  */
39 
40 #include <stdlib.h>
41 #include <libelf.h>
42 #include <dlfcn.h>
43 #include <libld.h>
44 #include <sgs.h>
45 #include <sgsmsg.h>
46 #include <sys/secflags.h>
47 
48 #ifdef	__cplusplus
49 extern "C" {
50 #endif
51 
52 /*
53  * Configuration features available - maintained here (instead of debug.h)
54  * to save libconv from having to include debug.h which results in numerous
55  * "declared but not used or defined" lint errors.
56  */
57 #define	CONF_EDLIBPATH	0x000100	/* ELF default library path */
58 #define	CONF_ESLIBPATH	0x000200	/* ELF secure library path */
59 #define	CONF_ADLIBPATH	0x000400	/* AOUT default library path */
60 #define	CONF_ASLIBPATH	0x000800	/* AOUT secure library path */
61 #define	CONF_DIRCFG	0x001000	/* directory configuration available */
62 #define	CONF_OBJALT	0x002000	/* object alternatives available */
63 #define	CONF_MEMRESV	0x004000	/* memory reservation required */
64 #define	CONF_ENVS	0x008000	/* environment variables available */
65 #define	CONF_FLTR	0x010000	/* filter information available */
66 #define	CONF_FEATMSK	0xffff00
67 
68 
69 /*
70  * Valid flags for conv_strproc_extract_value().
71  */
72 #define	CONV_SPEXV_F_NOTRIM	0x0001	/* Do not trim whitespace around '=' */
73 #define	CONV_SPEXV_F_UCASE	0x0002	/* Convert value to uppercase */
74 #define	CONV_SPEXV_F_NULLOK	0x0004	 /* Empty ("") value is OK */
75 
76 /*
77  * Buffer types:
78  *
79  * Many of the routines in this module require the user to supply a
80  * buffer into which the desired strings may be written. These are
81  * all arrays of characters, and might be defined as simple arrays
82  * of char. The problem with that approach is that when such an array
83  * is passed to a function, the C language considers it to have the
84  * type (char *), without any regard to its length. Not all of our
85  * buffers have the same length, and we want to ensure that the compiler
86  * will refuse to compile code that passes the wrong type of buffer to
87  * a given routine. The solution is to define the buffers as unions
88  * that contain the needed array, and then to pass the given union
89  * by address. The compiler will catch attempts to pass the wrong type
90  * of pointer, and the size of a structure/union is implicit in its type.
91  *
92  * A nice side effect of this approach is that we can use a union with
93  * multiple buffers to handle the cases where a given routine needs
94  * more than one type of buffer. The end result is a single buffer large
95  * enough to handle any of the subcases, but no larger.
96  */
97 
98 /*
99  * Size of buffer used by conv_invalid_val():
100  *
101  * Various values that can't be matched to a symbolic definition are converted
102  * to a numeric string.
103  *
104  * The buffer size reflects the maximum number of digits needed to
105  * display an integer as text, plus a trailing null, and with room for
106  * a leading "0x" if hexidecimal display is selected.
107  *
108  * The 32-bit version of this requires 12 characters, and the 64-bit version
109  * needs 22. By using the larger value for both, we can have a single
110  * definition, which is necessary for code that is ELFCLASS independent. A
111  * nice side benefit is that it lets us dispense with a large number of 32/64
112  * buffer size definitions that build off CONV_INV_BUFSIZE, and the macros
113  * that would then be needed.
114  */
115 #define	CONV_INV_BUFSIZE		22
116 typedef union {
117 	char				buf[CONV_INV_BUFSIZE];
118 } Conv_inv_buf_t;
119 
120 /* conv_ehdr_flags() */
121 #define	CONV_EHDR_FLAGS_BUFSIZE		91
122 typedef union {
123 	Conv_inv_buf_t			inv_buf;
124 	char				buf[CONV_EHDR_FLAGS_BUFSIZE];
125 } Conv_ehdr_flags_buf_t;
126 
127 /* conv_reject_desc() */
128 typedef union {
129 	Conv_inv_buf_t			inv_buf;
130 	Conv_ehdr_flags_buf_t		flags_buf;
131 } Conv_reject_desc_buf_t;
132 
133 /*
134  * conv_la_bind()
135  */
136 #define	CONV_LA_BIND_BUFSIZE		56
137 typedef union {
138 	Conv_inv_buf_t			inv_buf;
139 	char				buf[CONV_LA_BIND_BUFSIZE];
140 } Conv_la_bind_buf_t;
141 
142 /*
143  * conv_la_search()
144  */
145 #define	CONV_LA_SEARCH_BUFSIZE		111
146 typedef union {
147 	Conv_inv_buf_t			inv_buf;
148 	char				buf[CONV_LA_SEARCH_BUFSIZE];
149 } Conv_la_search_buf_t;
150 
151 /*
152  * conv_la_symbind()
153  */
154 #define	CONV_LA_SYMBIND_BUFSIZE		113
155 typedef union {
156 	Conv_inv_buf_t			inv_buf;
157 	char				buf[CONV_LA_SYMBIND_BUFSIZE];
158 } Conv_la_symbind_buf_t;
159 
160 /*
161  * conv_cap_val_hw/sf()
162  *
163  * These sizes are based on the maximum number of capabilities that exist.
164  * See common/elfcap.
165  */
166 #define	CONV_CAP_VAL_HW1_BUFSIZE	195
167 typedef union {
168 	Conv_inv_buf_t			inv_buf;
169 	char				buf[CONV_CAP_VAL_HW1_BUFSIZE];
170 } Conv_cap_val_hw1_buf_t;
171 
172 #define	CONV_CAP_VAL_HW2_BUFSIZE	350
173 typedef union {
174 	Conv_inv_buf_t			inv_buf;
175 	char				buf[CONV_CAP_VAL_HW2_BUFSIZE];
176 } Conv_cap_val_hw2_buf_t;
177 
178 #define	CONV_CAP_VAL_SF1_BUFSIZE	45
179 typedef union {
180 	Conv_inv_buf_t			inv_buf;
181 	char				buf[CONV_CAP_VAL_SF1_BUFSIZE];
182 } Conv_cap_val_sf1_buf_t;
183 
184 /* conv_cap_val_buf() */
185 typedef union {
186 	Conv_inv_buf_t			inv_buf;
187 	Conv_cap_val_hw1_buf_t		cap_val_hw1_buf;
188 	Conv_cap_val_sf1_buf_t		cap_val_sf1_buf;
189 	Conv_cap_val_hw2_buf_t		cap_val_hw2_buf;
190 } Conv_cap_val_buf_t;
191 
192 /* conv_config_feat() */
193 #define	CONV_CONFIG_FEAT_BUFSIZE	204
194 typedef union {
195 	Conv_inv_buf_t			inv_buf;
196 	char				buf[CONV_CONFIG_FEAT_BUFSIZE];
197 } Conv_config_feat_buf_t;
198 
199 /* conv_config_obj() */
200 #define	CONV_CONFIG_OBJ_BUFSIZE		164
201 typedef union {
202 	Conv_inv_buf_t			inv_buf;
203 	char				buf[CONV_CONFIG_OBJ_BUFSIZE];
204 } Conv_config_obj_buf_t;
205 
206 /* conv_dl_mode() */
207 #define	CONV_DL_MODE_BUFSIZE		132
208 typedef union {
209 	Conv_inv_buf_t			inv_buf;
210 	char				buf[CONV_DL_MODE_BUFSIZE];
211 } Conv_dl_mode_buf_t;
212 
213 /* conv_dl_flag() */
214 #define	CONV_DL_FLAG_BUFSIZE		185
215 typedef union {
216 	Conv_inv_buf_t			inv_buf;
217 	char				buf[CONV_DL_FLAG_BUFSIZE];
218 } Conv_dl_flag_buf_t;
219 
220 /* conv_grphdl_flags() */
221 #define	CONV_GRPHDL_FLAGS_BUFSIZE	78
222 typedef union {
223 	Conv_inv_buf_t			inv_buf;
224 	char				buf[CONV_GRPHDL_FLAGS_BUFSIZE];
225 } Conv_grphdl_flags_buf_t;
226 
227 /* conv_grpdesc_flags() */
228 #define	CONV_GRPDESC_FLAGS_BUFSIZE	91
229 typedef union {
230 	Conv_inv_buf_t			inv_buf;
231 	char				buf[CONV_GRPDESC_FLAGS_BUFSIZE];
232 } Conv_grpdesc_flags_buf_t;
233 
234 /* conv_seg_flags() */
235 #define	CONV_SEG_FLAGS_BUFSIZE		241
236 typedef union {
237 	Conv_inv_buf_t			inv_buf;
238 	char				buf[CONV_SEG_FLAGS_BUFSIZE];
239 } Conv_seg_flags_buf_t;
240 
241 /* conv_dyn_posflag1() */
242 #define	CONV_DYN_POSFLAG1_BUFSIZE	72
243 typedef union {
244 	Conv_inv_buf_t			inv_buf;
245 	char				buf[CONV_DYN_POSFLAG1_BUFSIZE];
246 } Conv_dyn_posflag1_buf_t;
247 
248 /* conv_dyn_flag() */
249 #define	CONV_DYN_FLAG_BUFSIZE		85
250 typedef union {
251 	Conv_inv_buf_t			inv_buf;
252 	char				buf[CONV_DYN_FLAG_BUFSIZE];
253 } Conv_dyn_flag_buf_t;
254 
255 /* conv_dyn_flag1() */
256 #define	CONV_DYN_FLAG1_BUFSIZE		361
257 typedef union {
258 	Conv_inv_buf_t			inv_buf;
259 	char				buf[CONV_DYN_FLAG1_BUFSIZE];
260 } Conv_dyn_flag1_buf_t;
261 
262 /* conv_dyn_feature1() */
263 #define	CONV_DYN_FEATURE1_BUFSIZE	54
264 typedef union {
265 	Conv_inv_buf_t			inv_buf;
266 	char				buf[CONV_DYN_FEATURE1_BUFSIZE];
267 } Conv_dyn_feature1_buf_t;
268 
269 /* conv_bnd_type() */
270 #define	CONV_BND_TYPE_BUFSIZE		51
271 typedef union {
272 	Conv_inv_buf_t			inv_buf;
273 	char				buf[CONV_BND_TYPE_BUFSIZE];
274 } Conv_bnd_type_buf_t;
275 
276 /* conv_bnd_obj() */
277 #define	CONV_BND_OBJ_BUFSIZE		60
278 typedef union {
279 	Conv_inv_buf_t			inv_buf;
280 	char				buf[CONV_BND_OBJ_BUFSIZE];
281 } Conv_bnd_obj_buf_t;
282 
283 /* conv_phdr_flags() */
284 #define	CONV_PHDR_FLAGS_BUFSIZE		88
285 typedef union {
286 	Conv_inv_buf_t			inv_buf;
287 	char				buf[CONV_PHDR_FLAGS_BUFSIZE];
288 } Conv_phdr_flags_buf_t;
289 
290 /* conv_sec_flags() */
291 #define	CONV_SEC_FLAGS_BUFSIZE		190
292 typedef union {
293 	Conv_inv_buf_t			inv_buf;
294 	char				buf[CONV_SEC_FLAGS_BUFSIZE];
295 } Conv_sec_flags_buf_t;
296 
297 /* conv_dwarf_ehe() */
298 #define	CONV_DWARF_EHE_BUFSIZE		43
299 typedef union {
300 	Conv_inv_buf_t			inv_buf;
301 	char				buf[CONV_DWARF_EHE_BUFSIZE];
302 } Conv_dwarf_ehe_buf_t;
303 
304 /* conv_syminfo_flags() */
305 #define	CONV_SYMINFO_FLAGS_BUFSIZE	230
306 typedef union {
307 	Conv_inv_buf_t			inv_buf;
308 	char				buf[CONV_SYMINFO_FLAGS_BUFSIZE];
309 } Conv_syminfo_flags_buf_t;
310 
311 /* conv_cnote_pr_flags() */
312 #define	CONV_CNOTE_PR_FLAGS_BUFSIZE	254
313 typedef union {
314 	Conv_inv_buf_t			inv_buf;
315 	char				buf[CONV_CNOTE_PR_FLAGS_BUFSIZE];
316 } Conv_cnote_pr_flags_buf_t;
317 
318 /* conv_cnote_old_pr_flags() */
319 #define	CONV_CNOTE_OLD_PR_FLAGS_BUFSIZE	174
320 typedef union {
321 	Conv_inv_buf_t			inv_buf;
322 	char				buf[CONV_CNOTE_OLD_PR_FLAGS_BUFSIZE];
323 } Conv_cnote_old_pr_flags_buf_t;
324 
325 /* conv_cnote_proc_flag() */
326 #define	CONV_CNOTE_PROC_FLAG_BUFSIZE	39
327 typedef union {
328 	Conv_inv_buf_t			inv_buf;
329 	char				buf[CONV_CNOTE_PROC_FLAG_BUFSIZE];
330 } Conv_cnote_proc_flag_buf_t;
331 
332 /* conv_prsecflags() */
333 #define	CONV_PRSECFLAGS_BUFSIZE		57
334 typedef union {
335 	Conv_inv_buf_t			inv_buf;
336 	char				buf[CONV_PRSECFLAGS_BUFSIZE];
337 } Conv_secflags_buf_t;
338 
339 /* conv_prupanic() */
340 #define	CONV_PRUPANIC_BUFSIZE		56
341 typedef union {
342 	Conv_inv_buf_t			inv_buf;
343 	char				buf[CONV_PRUPANIC_BUFSIZE];
344 } Conv_upanic_buf_t;
345 
346 /* conv_cnote_sigset() */
347 #define	CONV_CNOTE_SIGSET_BUFSIZE	639
348 typedef union {
349 	Conv_inv_buf_t			inv_buf;
350 	char				buf[CONV_CNOTE_SIGSET_BUFSIZE];
351 } Conv_cnote_sigset_buf_t;
352 
353 /* conv_cnote_fltset() */
354 #define	CONV_CNOTE_FLTSET_BUFSIZE	511
355 typedef union {
356 	Conv_inv_buf_t			inv_buf;
357 	char				buf[CONV_CNOTE_FLTSET_BUFSIZE];
358 } Conv_cnote_fltset_buf_t;
359 
360 /* conv_cnote_sysset() */
361 #define	CONV_CNOTE_SYSSET_BUFSIZE	3227
362 typedef union {
363 	Conv_inv_buf_t			inv_buf;
364 	char				buf[CONV_CNOTE_SYSSET_BUFSIZE];
365 } Conv_cnote_sysset_buf_t;
366 
367 /* conv_cnote_sa_flags() */
368 #define	CONV_CNOTE_SA_FLAGS_BUFSIZE	109
369 typedef union {
370 	Conv_inv_buf_t			inv_buf;
371 	char				buf[CONV_CNOTE_SA_FLAGS_BUFSIZE];
372 } Conv_cnote_sa_flags_buf_t;
373 
374 /* conv_cnote_ss_flags() */
375 #define	CONV_CNOTE_SS_FLAGS_BUFSIZE	48
376 typedef union {
377 	Conv_inv_buf_t			inv_buf;
378 	char				buf[CONV_CNOTE_SS_FLAGS_BUFSIZE];
379 } Conv_cnote_ss_flags_buf_t;
380 
381 /* conv_cnote_cc_content() */
382 #define	CONV_CNOTE_CC_CONTENT_BUFSIZE	97
383 typedef union {
384 	Conv_inv_buf_t			inv_buf;
385 	char				buf[CONV_CNOTE_CC_CONTENT_BUFSIZE];
386 } Conv_cnote_cc_content_buf_t;
387 
388 /* conv_cnote_auxv_af() */
389 #define	CONV_CNOTE_AUXV_AF_BUFSIZE	73
390 typedef union {
391 	Conv_inv_buf_t			inv_buf;
392 	char				buf[CONV_CNOTE_AUXV_AF_BUFSIZE];
393 } Conv_cnote_auxv_af_buf_t;
394 
395 /* conv_ver_flags() */
396 #define	CONV_VER_FLAGS_BUFSIZE		41
397 typedef union {
398 	Conv_inv_buf_t			inv_buf;
399 	char				buf[CONV_VER_FLAGS_BUFSIZE];
400 } Conv_ver_flags_buf_t;
401 
402 /* conv_ent_flags() */
403 #define	CONV_ENT_FLAGS_BUFSIZE		69
404 typedef union {
405 	Conv_inv_buf_t			inv_buf;
406 	char				buf[CONV_ENT_FLAGS_BUFSIZE];
407 } Conv_ent_flags_buf_t;
408 
409 /* conv_ent_files_flags() */
410 #define	CONV_ENT_FILES_FLAGS_BUFSIZE	89
411 typedef union {
412 	Conv_inv_buf_t			inv_buf;
413 	char				buf[CONV_ENT_FILES_FLAGS_BUFSIZE];
414 } Conv_ent_files_flags_buf_t;
415 
416 /*
417  * conv_time()
418  *
419  * This size is based on the maximum "hour.min.sec.fraction: " time that
420  * would be expected of ld().
421  */
422 #define	CONV_TIME_BUFSIZE		18
423 typedef union {
424 	char				buf[CONV_TIME_BUFSIZE];
425 } Conv_time_buf_t;
426 
427 /*
428  * Many conversion routines accept a fmt_flags argument of this type
429  * to allow the caller to modify the output. There are two parts to
430  * this value:
431  *
432  *	(1) Format requests (decimal vs hex, etc...)
433  *	(2) The low order bits specified by CONV_MASK_FMT_ALT
434  *		and retrieved by CONV_TYPE_FMT_ALT are integer
435  *		values that specify that an alternate set of
436  *		strings should be used.
437  *
438  * The fmt_flags value is designed such that a caller can always
439  * supply a 0 in order to receive default behavior.
440  */
441 typedef int Conv_fmt_flags_t;
442 
443 /*
444  * Type used to represent ELF constants within libconv. This relies on
445  * the fact that there are no ELF constants that need more than 32-bits,
446  * nor are there any signed values.
447  */
448 typedef uint32_t Conv_elfvalue_t;
449 
450 /*
451  * Most conversion routines are able to provide strings in one of
452  * several alternative styles. The bottom 8 bits of Conv_fmt_flags_t
453  * are used to specify which strings should be used for a given call
454  * to a conversion routine:
455  *
456  *   DEFAULT
457  *	The default string style used by a given conversion routine is
458  *	an independent choice made by that routine. Different routines
459  *	make different choices, based largely on historical usage and
460  *	the perceived common case. It may be an alias for one of the
461  *	specific styles listed below, or it may be unique.
462  *
463  *   DUMP
464  *	Style of strings used by dump(1).
465  *
466  *   FILE
467  *	Style of strings used by file(1).
468  *
469  *   CRLE
470  *	Style of strings used by crle(1).
471  *
472  *   CF
473  *	Canonical Form: The string is exactly the same as the name
474  *	of the #define macro that defines it in the public header files.
475  *	(e.g. STB_LOCAL, not LOCL, LOCAL, LOC, or any other variation).
476  *
477  *   CFNP
478  *	No Prefix Canonical Form: The same strings supplied by CF,
479  *	but without their standard prefix. (e.g. LOCAL, instead of STT_LOCAL).
480  *
481  *   NF
482  *	Natural Form: The form of the strings that might typically be entered
483  *	via a keyboard by an interactive user. These are usually the strings
484  *	from CFNP, converted to lowercase, although in some cases they may
485  *	take some other "natural" form. In command completion applications,
486  *	lowercase strings appear less formal, and are easier on the eye.
487  *
488  * Every routine is required to have a default style. The others are optional,
489  * and may not be provided if not needed. If a given conversion routine does
490  * not support alternative strings for a given CONV_FMT_ALT type, it silently
491  * ignores the request and supplies the default set. This means that a utility
492  * like dump(1) is free to specify a style like DUMP to every conversion
493  * routine. It will receive its special strings if there are any, and
494  * the defaults otherwise.
495  */
496 #define	CONV_MASK_FMT_ALT		0xff
497 #define	CONV_TYPE_FMT_ALT(fmt_flags)	(fmt_flags & CONV_MASK_FMT_ALT)
498 
499 #define	CONV_FMT_ALT_DEFAULT	0	/* "Standard" strings */
500 #define	CONV_FMT_ALT_DUMP	1	/* dump(1) */
501 #define	CONV_FMT_ALT_FILE	2	/* file(1) */
502 #define	CONV_FMT_ALT_CRLE	3	/* crle(1) */
503 #define	CONV_FMT_ALT_CF		4	/* Canonical Form */
504 #define	CONV_FMT_ALT_CFNP	5	/* No Prefix Canonical Form */
505 #define	CONV_FMT_ALT_NF		6	/* Natural Form */
506 
507 /*
508  * Flags that alter standard formatting for conversion routines.
509  * These bits start after the range occupied by CONV_MASK_FMT_ALT.
510  */
511 #define	CONV_FMT_DECIMAL	0x0100	/* conv_invalid_val() should print */
512 					/*    integer print as decimal */
513 					/*    (default is hex) */
514 #define	CONV_FMT_SPACE		0x0200	/* conv_invalid_val() should append */
515 					/*    a space after the number.  */
516 #define	CONV_FMT_NOBKT		0x0400	/* conv_expn_field() should omit */
517 					/*    prefix and suffix strings */
518 
519 /*
520  * A Val_desc structure is used to associate an ELF constant and
521  * the message code (Msg) for the string that corresponds to it.
522  *
523  * Val_desc2 adds v_osabi and v_mach fields to Val_desc, which allows
524  * for non-generic mappings that apply only to a specific OSABI/machine.
525  * Setting v_osabi to 0 (ELFOSABI_NONE) specifies that any OSABI matches.
526  * Similarly, setting v_mach to 0 (EM_MACH) matches any machine. Hence,
527  * setting v_osabi and v_mach to 0 in a Val_desc2 results in a generic item,
528  * and is equivalent to simply using a Val_desc.
529  *
530  * These structs are used in two different contexts:
531  *
532  * 1)	To expand bit-field data items, using conv_expn_field() to
533  *	process a NULL terminated array of Val_desc, or conv_expn_field2()
534  *	to process a null terminated array of Val_desc2.
535  *
536  * 2)	To represent sparse ranges of non-bitfield values, referenced via
537  *	conv_ds_vd_t or conv_ds_vd2_t descriptors, as described below.
538  */
539 typedef struct {
540 	Conv_elfvalue_t	v_val;		/* expansion value */
541 	Msg		v_msg;		/* associated message string code */
542 } Val_desc;
543 typedef struct {
544 	Conv_elfvalue_t	v_val;		/* expansion value */
545 	uchar_t		v_osabi;	/* OSABI to which entry applies */
546 	Half		v_mach;		/* Machine to which entry applies */
547 	Msg		v_msg;		/* associated message string code */
548 } Val_desc2;
549 
550 /*
551  * The conv_ds_XXX_t structs are used to pull together the information used
552  * to map non-bitfield values to strings. They are a variant family, sharing
553  * the same initial fields, with a generic "header" definition that can be
554  * used to read those common fields and determine which subcase is being
555  * seen. We do this instead of using a single struct containing a type code
556  * and a union in order to allow for static compile-time initialization.
557  *
558  * conv_ds_t is the base type, containing the initial fields common to all
559  * the variants. Variables of type conv_ds_t are never instantiated. This
560  * type exists only to provide a common pointer type that can reference
561  * any of the variants safely. In C++, it would be a virtual base class.
562  * The fields common to all the variants are:
563  *
564  *	ds_type: Identifies the variant
565  *	ds_baseval/ds_topval: The lower and upper bound of the range
566  *		of values represented by this conv_ds_XXX_t descriptor.
567  *
568  * There are three different variants:
569  *    conv_ds_msg_t (ds_type == CONV_DS_MSGARR)
570  *	This structure references an array of message codes corresponding
571  *	to consecutive ELF values. The first item in the array is the Msg
572  *	code for the value given by ds_baseval. Consecutive strings follow
573  *	in consecutive order. The final item corresponds to the value given
574  *	by ds_topval. Zero (0) Msg values can be used to represent missing
575  *	values. Entries with a 0 are quietly ignored.
576  *
577  *    conv_ds_vd_t (ds_type == CONV_DS_VD)
578  *	This structure employs a NULL terminated array of Val_desc structs.
579  *	Each Val_desc supplies a mapping from a value in the range
580  *	(ds_baseval <= value <= ds_topval). The values described need not
581  *	be consecutive, and can be sparse. ds_baseval does not need to
582  *	correspond to the first item, and ds_topval need not correspond to
583  *	the final item.
584  *
585  *    conv_ds_vd2_t (ds_type == CONV_DS_VD2)
586  *	This structure employs a NULL terminated array of Val_desc2 structs,
587  *	rather than Val_desc, adding the ability to specify OSABI and machine
588  *	as part of the value/string mapping. It is otherwise the same thing
589  *	as CONV_DS_VD.
590  */
591 typedef enum {
592 	CONV_DS_MSGARR = 0,		/* Array of Msg */
593 	CONV_DS_VD = 1,			/* Null terminated array of Val_desc */
594 	CONV_DS_VD2 = 2,		/* Null terminated array of Val_desc2 */
595 } conv_ds_type_t;
596 
597 #define	CONV_DS_COMMON_FIELDS \
598 	conv_ds_type_t	ds_type;	/* Type of data structure used */ \
599 	uint32_t	ds_baseval;	/* Value of first item */	\
600 	uint32_t	ds_topval	/* Value of last item */
601 
602 typedef struct {		/* Virtual base type --- do not instantiate */
603 	CONV_DS_COMMON_FIELDS;
604 } conv_ds_t;
605 typedef struct {
606 	CONV_DS_COMMON_FIELDS;
607 	const Msg		*ds_msg;
608 } conv_ds_msg_t;
609 typedef struct {
610 	CONV_DS_COMMON_FIELDS;
611 	const Val_desc		*ds_vd;
612 } conv_ds_vd_t;
613 typedef struct {
614 	CONV_DS_COMMON_FIELDS;
615 	const Val_desc2		*ds_vd2;
616 } conv_ds_vd2_t;
617 
618 /*
619  * The initialization of conv_ds_msg_t can be completely derived from
620  * its base value and the array of Msg codes. CONV_DS_MSG_INIT() is used
621  * to do that.
622  */
623 #define	CONV_DS_MSG_INIT(_baseval, _arr) \
624 	CONV_DS_MSGARR, _baseval, \
625 	_baseval + (sizeof (_arr) / sizeof (_arr[0])) - 1, _arr
626 
627 /*
628  * Null terminated arrays of pointers to conv_ds_XXX_t structs are processed
629  * by conv_map_ds() to convert ELF constants to their symbolic names, and by
630  * conv_iter_ds() to iterate over all the available value/name combinations.
631  *
632  * These pointers are formed by casting the address of the specific
633  * variant types (described above) to generic base type pointer.
634  * CONV_DS_ADDR() is a convenience macro to take the address of
635  * one of these variants and turn it into a generic pointer.
636  */
637 #define	CONV_DS_ADDR(_item) ((conv_ds_t *)&(_item))
638 
639 /*
640  * Type used by libconv to represent osabi values passed to iteration
641  * functions. The type in the ELF header is uchar_t. However, every possible
642  * value 0-255 has a valid meaning, leaving us no extra value to assign
643  * to mean "ALL". Using Half for osabi leaves us the top byte to use for
644  * out of bound values.
645  *
646  * Non-iteration functions, and any code that does not need to use
647  * CONV_OSABI_ALL, should use uchar_t for osabi.
648  */
649 typedef Half conv_iter_osabi_t;
650 
651 /*
652  * Many of the iteration functions accept an osabi or mach argument,
653  * used to specify the type of object being processed. The following
654  * values can be used to specify a wildcard that matches any item. Their
655  * values are carefully chosen to ensure that they cannot be interpreted
656  * as an otherwise valid osabi or machine.
657  */
658 #define	CONV_OSABI_ALL	1024	/* Larger than can be represented by uchar_t */
659 #define	CONV_MACH_ALL	EM_NUM	/* Never a valid machine type */
660 
661 /*
662  * We compare Val_Desc2 descriptors with a specified osabi and machine
663  * to determine whether to use it or not. This macro encapsulates that logic.
664  *
665  * We consider an osabi to match when any of the following things hold:
666  *
667  * -	The descriptor osabi is ELFOSABI_NONE.
668  * -	The supplied osabi and the descriptor osabi match
669  * -	The supplied osabi is ELFOSABI_NONE, and the descriptor osabi is
670  *	ELFOSABI_SOLARIS. Many operating systems, Solaris included,
671  *	produce or have produced ELFOSABI_NONE native objects, if only
672  *	because OSABI ranges are not an original ELF feature. We
673  *	give our own objects the home field advantage.
674  * -	Iteration Only: An osabi value of CONV_OSABI_ALL is specified.
675  *
676  * We consider a machine to match when any of the following things hold:
677  *
678  * -	The descriptor mach is EM_NONE.
679  * -	The supplied mach and the descriptor mach match
680  * -	Iteration Only: A mach value of CONV_MACH_ALL is specified.
681  *
682  * The special extra _ALL case for iteration is handled by defining a separate
683  * macro with the extra CONV_xxx_ALL tests.
684  */
685 #define	CONV_VD2_SKIP_OSABI(_osabi, _vdp) \
686 	((_vdp->v_osabi != ELFOSABI_NONE) && (_vdp->v_osabi != osabi) && \
687 	((_osabi != ELFOSABI_NONE) || (_vdp->v_osabi != ELFOSABI_SOLARIS)))
688 
689 #define	CONV_VD2_SKIP_MACH(_mach, _vdp) \
690 	((_vdp->v_mach != EM_NONE) && (_vdp->v_mach != _mach))
691 
692 #define	CONV_VD2_SKIP(_osabi, _mach, _vdp) \
693 	(CONV_VD2_SKIP_OSABI(_osabi, _vdp) || CONV_VD2_SKIP_MACH(_mach, _vdp))
694 
695 #define	CONV_ITER_VD2_SKIP(_osabi, _mach, _vdp)			      \
696 	((CONV_VD2_SKIP_OSABI(_osabi, _vdp) && (_osabi != CONV_OSABI_ALL)) || \
697 	(CONV_VD2_SKIP_MACH(_mach, _vdp) && (_mach != CONV_MACH_ALL)))
698 
699 
700 /*
701  * Possible return values from iteration functions.
702  */
703 typedef enum {
704 	CONV_ITER_DONE,		/* Stop: No more iterations are desired */
705 	CONV_ITER_CONT		/* Continue with following iterations */
706 } conv_iter_ret_t;
707 
708 /*
709  * Prototype for caller supplied callback function to iteration functions.
710  */
711 typedef conv_iter_ret_t (* conv_iter_cb_t)(const char *str,
712     Conv_elfvalue_t value, void *uvalue);
713 
714 /*
715  * User value block employed by conv_iter_strtol()
716  */
717 typedef struct {
718 	const char	*csl_str;	/* String to search for */
719 	size_t		csl_strlen;	/* # chars in csl_str to examine */
720 	int		csl_found;	/* Init to 0, set to 1 if item found */
721 	Conv_elfvalue_t	csl_value;	/* If csl_found, resulting value */
722 } conv_strtol_uvalue_t;
723 
724 /*
725  * conv_expn_field() is willing to supply default strings for the
726  * prefix, separator, and suffix arguments, if they are passed as NULL.
727  * The caller needs to know how much room to allow for these items.
728  * These values supply those sizes.
729  */
730 #define	CONV_EXPN_FIELD_DEF_PREFIX_SIZE	2	/* Default is "[ " */
731 #define	CONV_EXPN_FIELD_DEF_SEP_SIZE	1	/* Default is " " */
732 #define	CONV_EXPN_FIELD_DEF_SUFFIX_SIZE	2	/* Default is " ]" */
733 
734 /*
735  * conv_expn_field() requires a large number of inputs, many of which
736  * can be NULL to accept default behavior. An argument of the following
737  * type is used to supply them.
738  */
739 typedef struct {
740 	char *buf;		/* Buffer to receive generated string */
741 	size_t bufsize;		/* sizeof(buf) */
742 	const char **lead_str;	/* NULL, or array of pointers to strings to */
743 				/*	be output at the head of the list. */
744 				/*	Last entry must be NULL. */
745 	Xword oflags;		/* Bits for which output strings are desired */
746 	Xword rflags;		/* Bits for which a numeric value should be */
747 				/*	output if vdp does not provide str. */
748 				/*	Must be a proper subset of oflags */
749 	const char *prefix;	/* NULL, or string to prefix output with */
750 				/*	If NULL, "[ " is used. */
751 	const char *sep;	/* NULL, or string to separate output items */
752 				/*	with. If NULL, " " is used. */
753 	const char *suffix;	/* NULL, or string to suffix output with */
754 				/*	If NULL, " ]" is used. */
755 } CONV_EXPN_FIELD_ARG;
756 
757 /*
758  * Callback function for conv_str_to_c_literal(). A user supplied function
759  * of this type is called by conv_str_to_c_literal() in order to dispatch
760  * the translated output characters.
761  *
762  *	buf - Pointer to output text
763  *	n - # of characters to output
764  *	uvalue - User value argument to conv_str_to_c_literal(),
765  *		passed through without interpretation.
766  */
767 typedef	void		Conv_str_to_c_literal_func_t(const void *ptr,
768 			    size_t size, void *uvalue);
769 
770 /*
771  * Generic miscellaneous interfaces
772  */
773 extern	uchar_t		conv_check_native(char **, char **);
774 extern	const char	*conv_lddstub(int);
775 extern	int		conv_strproc_isspace(int);
776 extern	char		*conv_strproc_trim(char *);
777 extern	Boolean		conv_strproc_extract_value(char *, size_t, int,
778 			    const char **);
779 extern	int		conv_sys_eclass(void);
780 extern	int		conv_translate_c_esc(char **);
781 
782 /*
783  * Generic core formatting and iteration functionality
784  */
785 extern	conv_iter_ret_t	_conv_iter_ds(conv_iter_osabi_t, Half,
786 			    const conv_ds_t **, conv_iter_cb_t, void *,
787 			    const char *);
788 extern	conv_iter_ret_t	_conv_iter_ds_msg(const conv_ds_msg_t *,
789 			    conv_iter_cb_t, void *, const char *);
790 extern	conv_iter_ret_t	_conv_iter_vd(const Val_desc *, conv_iter_cb_t,
791 			    void *, const char *);
792 extern	conv_iter_ret_t	_conv_iter_vd2(conv_iter_osabi_t, Half,
793 			    const Val_desc2 *, conv_iter_cb_t, void *,
794 			    const char *);
795 extern	int		conv_iter_strtol_init(const char *,
796 			    conv_strtol_uvalue_t *);
797 extern	conv_iter_ret_t	conv_iter_strtol(const char *, Conv_elfvalue_t, void *);
798 extern	const char	*_conv_map_ds(uchar_t, Half, Conv_elfvalue_t,
799 			    const conv_ds_t **, Conv_fmt_flags_t,
800 			    Conv_inv_buf_t *, const char *);
801 
802 
803 /*
804  * Generic formatting interfaces.
805  */
806 extern	const char	*conv_bnd_obj(uint_t, Conv_bnd_obj_buf_t *);
807 extern	const char	*conv_bnd_type(uint_t, Conv_bnd_type_buf_t *);
808 extern	const char	*conv_config_feat(int, Conv_config_feat_buf_t *);
809 extern	const char	*conv_config_obj(ushort_t, Conv_config_obj_buf_t *);
810 extern	const char	*conv_config_upm(const char *, const char *,
811 			    const char *, size_t);
812 extern	const char	*conv_cnote_auxv_af(Word, Conv_fmt_flags_t,
813 			    Conv_cnote_auxv_af_buf_t *);
814 extern	const char	*conv_cnote_auxv_type(Word, Conv_fmt_flags_t,
815 			    Conv_inv_buf_t *);
816 extern	const char	*conv_cnote_cc_content(Lword, Conv_fmt_flags_t,
817 			    Conv_cnote_cc_content_buf_t *);
818 extern	const char	*conv_cnote_errno(int, Conv_fmt_flags_t,
819 			    Conv_inv_buf_t *);
820 extern	const char	*conv_cnote_fault(Word, Conv_fmt_flags_t,
821 			    Conv_inv_buf_t *);
822 extern	const char	*conv_cnote_fltset(uint32_t *, int,
823 			    Conv_fmt_flags_t, Conv_cnote_fltset_buf_t *);
824 extern	const char	*conv_cnote_old_pr_flags(int, Conv_fmt_flags_t,
825 			    Conv_cnote_old_pr_flags_buf_t *);
826 extern	const char	*conv_cnote_pr_dmodel(Word, Conv_fmt_flags_t,
827 			    Conv_inv_buf_t *);
828 extern	const char	*conv_cnote_pr_flags(int, Conv_fmt_flags_t,
829 			    Conv_cnote_pr_flags_buf_t *);
830 extern	const char	*conv_cnote_proc_flag(int, Conv_fmt_flags_t,
831 			    Conv_cnote_proc_flag_buf_t *);
832 extern	const char	*conv_cnote_pr_regname(Half, int, Conv_fmt_flags_t,
833 			    Conv_inv_buf_t *inv_buf);
834 extern	const char	*conv_cnote_pr_stype(Word, Conv_fmt_flags_t,
835 			    Conv_inv_buf_t *);
836 extern	const char	*conv_cnote_pr_what(short, short, Conv_fmt_flags_t,
837 			    Conv_inv_buf_t *);
838 extern	const char	*conv_cnote_pr_why(short, Conv_fmt_flags_t,
839 			    Conv_inv_buf_t *);
840 extern	const char	*conv_cnote_priv(int, Conv_fmt_flags_t,
841 			    Conv_inv_buf_t *);
842 extern	const char	*conv_prsecflags(secflagset_t, Conv_fmt_flags_t,
843 			    Conv_secflags_buf_t *);
844 extern	const char	*conv_prupanic(uint32_t, Conv_fmt_flags_t,
845 			    Conv_upanic_buf_t *);
846 extern	const char	*conv_cnote_psetid(int, Conv_fmt_flags_t,
847 			    Conv_inv_buf_t *);
848 extern	const char	*conv_cnote_sa_flags(int, Conv_fmt_flags_t,
849 			    Conv_cnote_sa_flags_buf_t *);
850 extern	const char	*conv_cnote_signal(Word, Conv_fmt_flags_t,
851 			    Conv_inv_buf_t *);
852 extern	const char	*conv_cnote_si_code(Half, int, int, Conv_fmt_flags_t,
853 			    Conv_inv_buf_t *);
854 extern	const char	*conv_cnote_sigset(uint32_t *, int,
855 			    Conv_fmt_flags_t, Conv_cnote_sigset_buf_t *);
856 extern	const char	*conv_cnote_ss_flags(int, Conv_fmt_flags_t,
857 			    Conv_cnote_ss_flags_buf_t *);
858 extern	const char	*conv_cnote_syscall(Word, Conv_fmt_flags_t,
859 			    Conv_inv_buf_t *);
860 extern	const char	*conv_cnote_sysset(uint32_t *, int,
861 			    Conv_fmt_flags_t, Conv_cnote_sysset_buf_t *);
862 extern	const char	*conv_cnote_fileflags(uint32_t, Conv_fmt_flags_t,
863 			    char *, size_t);
864 extern	const char	*conv_cnote_filemode(uint32_t, Conv_fmt_flags_t,
865 			    char *, size_t);
866 extern	const char	*conv_cnote_type(Word, Conv_fmt_flags_t,
867 			    Conv_inv_buf_t *);
868 extern	const char	*conv_def_tag(Symref, Conv_inv_buf_t *);
869 extern	const char	*conv_demangle_name(const char *);
870 extern	const char	*conv_dl_flag(int, Conv_fmt_flags_t,
871 			    Conv_dl_flag_buf_t *);
872 extern	const char	*conv_dl_info(int);
873 extern	const char	*conv_dl_mode(int, int, Conv_dl_mode_buf_t *);
874 extern	const char	*conv_dwarf_cfa(uchar_t, Conv_fmt_flags_t,
875 			    Conv_inv_buf_t *);
876 extern	const char	*conv_dwarf_ehe(uint_t, Conv_dwarf_ehe_buf_t *);
877 extern	const char	*conv_dwarf_regname(Half, Word, Conv_fmt_flags_t,
878 			    int *, Conv_inv_buf_t *);
879 extern	const char	*conv_ehdr_abivers(uchar_t, Word, Conv_fmt_flags_t,
880 			    Conv_inv_buf_t *);
881 extern	const char	*conv_ehdr_class(uchar_t, Conv_fmt_flags_t,
882 			    Conv_inv_buf_t *);
883 extern	const char	*conv_ehdr_data(uchar_t, Conv_fmt_flags_t,
884 			    Conv_inv_buf_t *);
885 extern	const char	*conv_ehdr_flags(Half, Word, Conv_fmt_flags_t,
886 			    Conv_ehdr_flags_buf_t *);
887 extern	const char	*conv_ehdr_mach(Half, Conv_fmt_flags_t,
888 			    Conv_inv_buf_t *);
889 extern	const char	*conv_ehdr_osabi(uchar_t, Conv_fmt_flags_t,
890 			    Conv_inv_buf_t *);
891 extern	const char	*conv_ehdr_type(uchar_t, Half, Conv_fmt_flags_t,
892 			    Conv_inv_buf_t *);
893 extern	const char	*conv_ehdr_vers(Word, Conv_fmt_flags_t,
894 			    Conv_inv_buf_t *);
895 extern	const char	*conv_elfdata_type(Elf_Type, Conv_inv_buf_t *);
896 extern	const char	*conv_ent_flags(ec_flags_t, Conv_ent_flags_buf_t *);
897 extern	const char	*conv_ent_files_flags(Word,  Conv_fmt_flags_t fmt_flags,
898 			    Conv_ent_files_flags_buf_t *);
899 extern	const char	*conv_la_activity(uint_t, Conv_fmt_flags_t,
900 			    Conv_inv_buf_t *);
901 extern	const char	*conv_la_bind(uint_t, Conv_la_bind_buf_t *);
902 extern	const char	*conv_la_search(uint_t, Conv_la_search_buf_t *);
903 extern	const char	*conv_la_symbind(uint_t, Conv_la_symbind_buf_t *);
904 extern	const char	*conv_grphdl_flags(uint_t, Conv_grphdl_flags_buf_t *);
905 extern	const char	*conv_grpdesc_flags(uint_t, Conv_grpdesc_flags_buf_t *);
906 extern	Isa_desc	*conv_isalist(void);
907 extern	const char	*conv_mapfile_version(Word, Conv_fmt_flags_t,
908 			    Conv_inv_buf_t *);
909 extern	const char	*conv_phdr_flags(uchar_t, Word, Conv_fmt_flags_t,
910 			    Conv_phdr_flags_buf_t *);
911 extern	const char	*conv_phdr_type(uchar_t, Half, Word, Conv_fmt_flags_t,
912 			    Conv_inv_buf_t *);
913 extern	const char	*conv_reject_desc(Rej_desc *, Conv_reject_desc_buf_t *,
914 			    Half mach);
915 extern	const char	*conv_reloc_type(Half, Word, Conv_fmt_flags_t,
916 			    Conv_inv_buf_t *);
917 extern	const char	*conv_reloc_type_static(Half, Word, Conv_fmt_flags_t);
918 extern	const char	*conv_reloc_386_type(Word, Conv_fmt_flags_t,
919 			    Conv_inv_buf_t *);
920 extern	const char	*conv_reloc_amd64_type(Word, Conv_fmt_flags_t,
921 			    Conv_inv_buf_t *);
922 extern	const char	*conv_reloc_SPARC_type(Word, Conv_fmt_flags_t,
923 			    Conv_inv_buf_t *);
924 extern	const char	*conv_sec_type(uchar_t, Half, Word, Conv_fmt_flags_t,
925 			    Conv_inv_buf_t *);
926 extern	const char	*conv_seg_flags(sg_flags_t, Conv_seg_flags_buf_t *);
927 extern	void		conv_str_to_c_literal(const char *buf, size_t n,
928 			    Conv_str_to_c_literal_func_t *cb_func,
929 			    void *uvalue);
930 extern	const char	*conv_sym_info_bind(uchar_t, Conv_fmt_flags_t,
931 			    Conv_inv_buf_t *);
932 extern	const char	*conv_sym_info_type(Half, uchar_t, Conv_fmt_flags_t,
933 			    Conv_inv_buf_t *);
934 extern	const char	*conv_sym_shndx(uchar_t, Half, Half, Conv_fmt_flags_t,
935 			    Conv_inv_buf_t *);
936 extern	const char	*conv_sym_other(uchar_t, Conv_inv_buf_t *);
937 extern	const char	*conv_sym_other_vis(uchar_t, Conv_fmt_flags_t,
938 			    Conv_inv_buf_t *);
939 extern	const char	*conv_syminfo_boundto(Half, Conv_fmt_flags_t,
940 			    Conv_inv_buf_t *);
941 extern	const char	*conv_syminfo_flags(Half, Conv_fmt_flags_t,
942 			    Conv_syminfo_flags_buf_t *);
943 extern	const char	*conv_time(struct timeval *, struct timeval *,
944 			    Conv_time_buf_t *);
945 extern	Uts_desc	*conv_uts(void);
946 extern	const char	*conv_ver_flags(Half, Conv_fmt_flags_t,
947 			    Conv_ver_flags_buf_t *);
948 extern	const char	*conv_ver_index(Versym, int, Conv_inv_buf_t *);
949 
950 
951 /*
952  * Generic iteration interfaces.
953  */
954 extern	conv_iter_ret_t	conv_iter_cap_tags(Conv_fmt_flags_t, conv_iter_cb_t,
955 			    void *);
956 extern	conv_iter_ret_t	conv_iter_cap_val_hw1(Half, Conv_fmt_flags_t,
957 			    conv_iter_cb_t, void *);
958 extern	conv_iter_ret_t	conv_iter_cap_val_hw2(Half, Conv_fmt_flags_t,
959 			    conv_iter_cb_t, void *);
960 extern	conv_iter_ret_t	conv_iter_cap_val_sf1(Conv_fmt_flags_t, conv_iter_cb_t,
961 			    void *);
962 
963 extern	conv_iter_ret_t	conv_iter_dyn_feature1(Conv_fmt_flags_t, conv_iter_cb_t,
964 			    void *);
965 extern	conv_iter_ret_t	conv_iter_dyn_flag(Conv_fmt_flags_t, conv_iter_cb_t,
966 			    void *);
967 extern	conv_iter_ret_t	conv_iter_dyn_flag1(Conv_fmt_flags_t, conv_iter_cb_t,
968 			    void *);
969 extern	conv_iter_ret_t	conv_iter_dyn_posflag1(Conv_fmt_flags_t, conv_iter_cb_t,
970 			    void *);
971 extern	conv_iter_ret_t	conv_iter_dyn_tag(conv_iter_osabi_t, Half,
972 			    Conv_fmt_flags_t, conv_iter_cb_t, void *);
973 
974 extern	conv_iter_ret_t	conv_iter_ehdr_abivers(conv_iter_osabi_t,
975 			    Conv_fmt_flags_t, conv_iter_cb_t, void *);
976 extern	conv_iter_ret_t	conv_iter_ehdr_class(Conv_fmt_flags_t, conv_iter_cb_t,
977 			    void *);
978 extern	conv_iter_ret_t	conv_iter_ehdr_data(Conv_fmt_flags_t, conv_iter_cb_t,
979 			    void *);
980 extern	conv_iter_ret_t	conv_iter_ehdr_eident(Conv_fmt_flags_t, conv_iter_cb_t,
981 			    void *);
982 extern	conv_iter_ret_t	conv_iter_ehdr_flags(Half, Conv_fmt_flags_t,
983 			    conv_iter_cb_t, void *);
984 extern	conv_iter_ret_t	conv_iter_ehdr_mach(Conv_fmt_flags_t, conv_iter_cb_t,
985 			    void *);
986 extern	conv_iter_ret_t	conv_iter_ehdr_osabi(Conv_fmt_flags_t, conv_iter_cb_t,
987 			    void *);
988 extern	conv_iter_ret_t	conv_iter_ehdr_type(conv_iter_osabi_t, Conv_fmt_flags_t,
989 			    conv_iter_cb_t, void *);
990 extern	conv_iter_ret_t	conv_iter_ehdr_vers(Conv_fmt_flags_t, conv_iter_cb_t,
991 			    void *);
992 
993 extern	conv_iter_ret_t	conv_iter_phdr_flags(conv_iter_osabi_t,
994 			    Conv_fmt_flags_t, conv_iter_cb_t, void *);
995 extern	conv_iter_ret_t	conv_iter_phdr_type(conv_iter_osabi_t, Conv_fmt_flags_t,
996 			    conv_iter_cb_t, void *);
997 
998 extern	conv_iter_ret_t	conv_iter_sec_flags(conv_iter_osabi_t, Half,
999 			    Conv_fmt_flags_t, conv_iter_cb_t, void *);
1000 extern	conv_iter_ret_t	conv_iter_sec_symtab(conv_iter_osabi_t,
1001 			    Conv_fmt_flags_t, conv_iter_cb_t, void *);
1002 extern	conv_iter_ret_t	conv_iter_sec_type(conv_iter_osabi_t, Half,
1003 			    Conv_fmt_flags_t, conv_iter_cb_t, void *);
1004 
1005 extern	conv_iter_ret_t	conv_iter_sym_info_bind(Conv_fmt_flags_t,
1006 			    conv_iter_cb_t, void *);
1007 extern	conv_iter_ret_t	conv_iter_sym_other_vis(Conv_fmt_flags_t,
1008 			    conv_iter_cb_t, void *);
1009 extern	conv_iter_ret_t	conv_iter_sym_shndx(conv_iter_osabi_t, Half,
1010 			    Conv_fmt_flags_t, conv_iter_cb_t, void *);
1011 extern	conv_iter_ret_t	conv_iter_sym_info_type(Half, Conv_fmt_flags_t,
1012 			    conv_iter_cb_t, void *);
1013 
1014 extern	conv_iter_ret_t	conv_iter_syminfo_boundto(Conv_fmt_flags_t,
1015 			    conv_iter_cb_t, void *);
1016 extern	conv_iter_ret_t	conv_iter_syminfo_flags(Conv_fmt_flags_t,
1017 			    conv_iter_cb_t, void *);
1018 
1019 /*
1020  * Define all class specific routines.
1021  */
1022 #if	defined(_ELF64)
1023 #define	conv_cap_tag		conv64_cap_tag
1024 #define	conv_cap_val		conv64_cap_val
1025 #define	conv_cap_val_hw1	conv64_cap_val_hw1
1026 #define	conv_cap_val_hw2	conv64_cap_val_hw2
1027 #define	conv_cap_val_sf1	conv64_cap_val_sf1
1028 #define	conv_dyn_feature1	conv64_dyn_feature1
1029 #define	conv_dyn_flag1		conv64_dyn_flag1
1030 #define	conv_dyn_flag		conv64_dyn_flag
1031 #define	conv_dyn_posflag1	conv64_dyn_posflag1
1032 #define	conv_dyn_tag		conv64_dyn_tag
1033 #define	_conv_expn_field	_conv64_expn_field
1034 #define	_conv_expn_field2	_conv64_expn_field2
1035 #define	conv_invalid_val	conv64_invalid_val
1036 #define	conv_sec_flags		conv64_sec_flags
1037 #define	conv_sec_linkinfo	conv64_sec_linkinfo
1038 #define	conv_sym_value		conv64_sym_value
1039 #define	conv_sym_SPARC_value	conv64_sym_SPARC_value
1040 #else
1041 #define	conv_cap_tag		conv32_cap_tag
1042 #define	conv_cap_val		conv32_cap_val
1043 #define	conv_cap_val_hw1	conv32_cap_val_hw1
1044 #define	conv_cap_val_hw2	conv32_cap_val_hw2
1045 #define	conv_cap_val_sf1	conv32_cap_val_sf1
1046 #define	conv_dyn_feature1	conv32_dyn_feature1
1047 #define	conv_dyn_flag1		conv32_dyn_flag1
1048 #define	conv_dyn_flag		conv32_dyn_flag
1049 #define	conv_dyn_posflag1	conv32_dyn_posflag1
1050 #define	conv_dyn_tag		conv32_dyn_tag
1051 #define	_conv_expn_field	_conv32_expn_field
1052 #define	_conv_expn_field2	_conv32_expn_field2
1053 #define	conv_invalid_val	conv32_invalid_val
1054 #define	conv_sec_flags		conv32_sec_flags
1055 #define	conv_sec_linkinfo	conv32_sec_linkinfo
1056 #define	conv_sym_value		conv32_sym_value
1057 #define	conv_sym_SPARC_value	conv32_sym_SPARC_value
1058 #endif
1059 
1060 /*
1061  * ELFCLASS-specific core formatting functionality
1062  */
1063 extern	int		_conv_expn_field(CONV_EXPN_FIELD_ARG *,
1064 			    const Val_desc *, Conv_fmt_flags_t, const char *);
1065 extern	int		_conv_expn_field2(CONV_EXPN_FIELD_ARG *, uchar_t,
1066 			    Half, const Val_desc2 *, Conv_fmt_flags_t,
1067 			    const char *);
1068 extern	const char	*conv_invalid_val(Conv_inv_buf_t *, Xword,
1069 			    Conv_fmt_flags_t);
1070 
1071 /*
1072  * ELFCLASS-specific formatting interfaces.
1073  */
1074 extern	const char	*conv_cap_tag(Xword, Conv_fmt_flags_t,
1075 			    Conv_inv_buf_t *);
1076 extern	const char	*conv_cap_val(Xword, Xword, Half, Conv_fmt_flags_t,
1077 			    Conv_cap_val_buf_t *);
1078 extern	const char	*conv_cap_val_hw1(Xword, Half, Conv_fmt_flags_t,
1079 			    Conv_cap_val_hw1_buf_t *);
1080 extern	const char	*conv_cap_val_hw2(Xword, Half, Conv_fmt_flags_t,
1081 			    Conv_cap_val_hw2_buf_t *);
1082 extern	const char	*conv_cap_val_sf1(Xword, Half, Conv_fmt_flags_t,
1083 			    Conv_cap_val_sf1_buf_t *);
1084 extern	const char	*conv_dyn_flag1(Xword, Conv_fmt_flags_t,
1085 			    Conv_dyn_flag1_buf_t *);
1086 extern	const char	*conv_dyn_flag(Xword, Conv_fmt_flags_t,
1087 			    Conv_dyn_flag_buf_t *);
1088 extern	const char	*conv_dyn_posflag1(Xword, Conv_fmt_flags_t,
1089 			    Conv_dyn_posflag1_buf_t *);
1090 extern	const char	*conv_dyn_tag(Xword, uchar_t, Half, Conv_fmt_flags_t,
1091 			    Conv_inv_buf_t *);
1092 extern	const char	*conv_dyn_feature1(Xword, Conv_fmt_flags_t,
1093 			    Conv_dyn_feature1_buf_t *);
1094 extern	const char	*conv_sec_flags(uchar_t osabi, Half mach, Xword,
1095 			    Conv_fmt_flags_t, Conv_sec_flags_buf_t *);
1096 extern	const char	*conv_sec_linkinfo(Word, Xword, Conv_inv_buf_t *);
1097 extern	const char	*conv_sym_value(Half, uchar_t, Addr, Conv_inv_buf_t *);
1098 extern	const char	*conv_sym_SPARC_value(Addr, Conv_fmt_flags_t,
1099 			    Conv_inv_buf_t *);
1100 
1101 /*
1102  * Define macros for _conv_XXX() routines that accept local_sgs_msg as the
1103  * final argument. The macros hide that argument from the caller's view and
1104  * supply the SGS message array for the file from which the macro is used
1105  * in its place. This trick is used to allow these functions to access the
1106  * message strings from any source file they are called from.
1107  */
1108 #define	conv_expn_field(_arg, _vdp, _fmt_flags) \
1109     _conv_expn_field(_arg, _vdp, _fmt_flags, MSG_SGS_LOCAL_ARRAY)
1110 
1111 #define	conv_expn_field2(_arg, _osabi, _mach, _vdp, _fmt_flags) \
1112     _conv_expn_field2(_arg, _osabi, _mach, _vdp, _fmt_flags, \
1113     MSG_SGS_LOCAL_ARRAY)
1114 
1115 #define	conv_iter_ds(_osabi, _mach, _dsp, _func, _uvalue) \
1116     _conv_iter_ds(_osabi, _mach, _dsp, _func, _uvalue, MSG_SGS_LOCAL_ARRAY)
1117 
1118 #define	conv_iter_vd(_vdp, _func, _uvalue)	\
1119     _conv_iter_vd(_vdp, _func, _uvalue, MSG_SGS_LOCAL_ARRAY)
1120 
1121 #define	conv_iter_vd2(_osabi, _mach, _vdp, _func, _uvalue)		\
1122     _conv_iter_vd2(_osabi, _mach, _vdp, _func, _uvalue, MSG_SGS_LOCAL_ARRAY)
1123 
1124 #define	conv_map_ds(_osabi, _mach, _value, _dsp, _fmt_flags, _inv_buf) \
1125     _conv_map_ds(_osabi, _mach, _value, _dsp, _fmt_flags, _inv_buf, \
1126     MSG_SGS_LOCAL_ARRAY)
1127 
1128 
1129 #ifdef	__cplusplus
1130 }
1131 #endif
1132 
1133 #endif /* _CONV_H */
1134