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