xref: /illumos-gate/usr/src/common/ctf/ctf_impl.h (revision a676209d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22e4586ebfSmws 
237c478bd9Sstevel@tonic-gate /*
24e4586ebfSmws  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
270a47c91cSRobert Mustacchi /*
28fe2dc8bdSJohn Levon  * Copyright 2020 Joyent, Inc.
29*a676209dSAndy Fiddaman  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
300a47c91cSRobert Mustacchi  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifndef	_CTF_IMPL_H
337c478bd9Sstevel@tonic-gate #define	_CTF_IMPL_H
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <sys/errno.h>
377c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
387c478bd9Sstevel@tonic-gate #include <sys/ctf_api.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifdef _KERNEL
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <sys/systm.h>
437c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
447c478bd9Sstevel@tonic-gate #include <sys/varargs.h>
45bc1f688bSRobert Mustacchi #include <sys/ddi.h>
46bc1f688bSRobert Mustacchi #include <sys/sunddi.h>
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #define	isspace(c) \
497c478bd9Sstevel@tonic-gate 	((c) == ' ' || (c) == '\t' || (c) == '\n' || \
507c478bd9Sstevel@tonic-gate 	(c) == '\r' || (c) == '\f' || (c) == '\v')
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #define	MAP_FAILED	((void *)-1)
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #else	/* _KERNEL */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #include <strings.h>
577c478bd9Sstevel@tonic-gate #include <stdlib.h>
587c478bd9Sstevel@tonic-gate #include <stdarg.h>
597c478bd9Sstevel@tonic-gate #include <stdio.h>
607c478bd9Sstevel@tonic-gate #include <limits.h>
617c478bd9Sstevel@tonic-gate #include <ctype.h>
62bc1f688bSRobert Mustacchi #include <stddef.h>
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
677c478bd9Sstevel@tonic-gate extern "C" {
687c478bd9Sstevel@tonic-gate #endif
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate typedef struct ctf_helem {
717c478bd9Sstevel@tonic-gate 	uint_t h_name;		/* reference to name in string table */
727c478bd9Sstevel@tonic-gate 	ushort_t h_type;	/* corresponding type ID number */
737c478bd9Sstevel@tonic-gate 	ushort_t h_next;	/* index of next element in hash chain */
747c478bd9Sstevel@tonic-gate } ctf_helem_t;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate typedef struct ctf_hash {
777c478bd9Sstevel@tonic-gate 	ushort_t *h_buckets;	/* hash bucket array (chain indices) */
787c478bd9Sstevel@tonic-gate 	ctf_helem_t *h_chains;	/* hash chains buffer */
797c478bd9Sstevel@tonic-gate 	ushort_t h_nbuckets;	/* number of elements in bucket array */
807c478bd9Sstevel@tonic-gate 	ushort_t h_nelems;	/* number of elements in hash table */
817c478bd9Sstevel@tonic-gate 	uint_t h_free;		/* index of next free hash element */
827c478bd9Sstevel@tonic-gate } ctf_hash_t;
837c478bd9Sstevel@tonic-gate 
84bc1f688bSRobert Mustacchi struct ctf_idhash_iter {
85bc1f688bSRobert Mustacchi 	int cii_id;	/* Current iteration id */
86bc1f688bSRobert Mustacchi };
87bc1f688bSRobert Mustacchi 
887c478bd9Sstevel@tonic-gate typedef struct ctf_strs {
897c478bd9Sstevel@tonic-gate 	const char *cts_strs;	/* base address of string table */
907c478bd9Sstevel@tonic-gate 	size_t cts_len;		/* size of string table in bytes */
917c478bd9Sstevel@tonic-gate } ctf_strs_t;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate typedef struct ctf_dmodel {
947c478bd9Sstevel@tonic-gate 	const char *ctd_name;	/* data model name */
957c478bd9Sstevel@tonic-gate 	int ctd_code;		/* data model code */
967c478bd9Sstevel@tonic-gate 	size_t ctd_pointer;	/* size of void * in bytes */
977c478bd9Sstevel@tonic-gate 	size_t ctd_char;	/* size of char in bytes */
987c478bd9Sstevel@tonic-gate 	size_t ctd_short;	/* size of short in bytes */
997c478bd9Sstevel@tonic-gate 	size_t ctd_int;		/* size of int in bytes */
1007c478bd9Sstevel@tonic-gate 	size_t ctd_long;	/* size of long in bytes */
1017c478bd9Sstevel@tonic-gate } ctf_dmodel_t;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate typedef struct ctf_lookup {
1047c478bd9Sstevel@tonic-gate 	const char *ctl_prefix;	/* string prefix for this lookup */
1057c478bd9Sstevel@tonic-gate 	size_t ctl_len;		/* length of prefix string in bytes */
1067c478bd9Sstevel@tonic-gate 	ctf_hash_t *ctl_hash;	/* pointer to hash table for lookup */
1077c478bd9Sstevel@tonic-gate } ctf_lookup_t;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate typedef struct ctf_fileops {
1107c478bd9Sstevel@tonic-gate 	ushort_t (*ctfo_get_kind)(ushort_t);
1117c478bd9Sstevel@tonic-gate 	ushort_t (*ctfo_get_root)(ushort_t);
1127c478bd9Sstevel@tonic-gate 	ushort_t (*ctfo_get_vlen)(ushort_t);
1137c478bd9Sstevel@tonic-gate } ctf_fileops_t;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate typedef struct ctf_list {
1167c478bd9Sstevel@tonic-gate 	struct ctf_list *l_prev; /* previous pointer or tail pointer */
1177c478bd9Sstevel@tonic-gate 	struct ctf_list *l_next; /* next pointer or head pointer */
1187c478bd9Sstevel@tonic-gate } ctf_list_t;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate typedef enum {
1217c478bd9Sstevel@tonic-gate 	CTF_PREC_BASE,
1227c478bd9Sstevel@tonic-gate 	CTF_PREC_POINTER,
1237c478bd9Sstevel@tonic-gate 	CTF_PREC_ARRAY,
1247c478bd9Sstevel@tonic-gate 	CTF_PREC_FUNCTION,
1257c478bd9Sstevel@tonic-gate 	CTF_PREC_MAX
1267c478bd9Sstevel@tonic-gate } ctf_decl_prec_t;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate typedef struct ctf_decl_node {
1297c478bd9Sstevel@tonic-gate 	ctf_list_t cd_list;			/* linked list pointers */
1307c478bd9Sstevel@tonic-gate 	ctf_id_t cd_type;			/* type identifier */
1317c478bd9Sstevel@tonic-gate 	uint_t cd_kind;				/* type kind */
1327c478bd9Sstevel@tonic-gate 	uint_t cd_n;				/* type dimension if array */
1337c478bd9Sstevel@tonic-gate } ctf_decl_node_t;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate typedef struct ctf_decl {
1367c478bd9Sstevel@tonic-gate 	ctf_list_t cd_nodes[CTF_PREC_MAX];	/* declaration node stacks */
1377c478bd9Sstevel@tonic-gate 	int cd_order[CTF_PREC_MAX];		/* storage order of decls */
1387c478bd9Sstevel@tonic-gate 	ctf_decl_prec_t cd_qualp;		/* qualifier precision */
1397c478bd9Sstevel@tonic-gate 	ctf_decl_prec_t cd_ordp;		/* ordered precision */
1407c478bd9Sstevel@tonic-gate 	char *cd_buf;				/* buffer for output */
1417c478bd9Sstevel@tonic-gate 	char *cd_ptr;				/* buffer location */
1427c478bd9Sstevel@tonic-gate 	char *cd_end;				/* buffer limit */
1437c478bd9Sstevel@tonic-gate 	size_t cd_len;				/* buffer space required */
1447c478bd9Sstevel@tonic-gate 	int cd_err;				/* saved error value */
1457c478bd9Sstevel@tonic-gate } ctf_decl_t;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate typedef struct ctf_dmdef {
1487c478bd9Sstevel@tonic-gate 	ctf_list_t dmd_list;	/* list forward/back pointers */
1497c478bd9Sstevel@tonic-gate 	char *dmd_name;		/* name of this member */
1507c478bd9Sstevel@tonic-gate 	ctf_id_t dmd_type;	/* type of this member (for sou) */
1517c478bd9Sstevel@tonic-gate 	ulong_t dmd_offset;	/* offset of this member in bits (for sou) */
1527c478bd9Sstevel@tonic-gate 	int dmd_value;		/* value of this member (for enum) */
1537c478bd9Sstevel@tonic-gate } ctf_dmdef_t;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate typedef struct ctf_dtdef {
1567c478bd9Sstevel@tonic-gate 	ctf_list_t dtd_list;	/* list forward/back pointers */
157e4586ebfSmws 	struct ctf_dtdef *dtd_hash; /* hash chain pointer for ctf_dthash */
1587c478bd9Sstevel@tonic-gate 	char *dtd_name;		/* name associated with definition (if any) */
1597c478bd9Sstevel@tonic-gate 	ctf_id_t dtd_type;	/* type identifier for this definition */
1607c478bd9Sstevel@tonic-gate 	ctf_type_t dtd_data;	/* type node (see <sys/ctf.h>) */
1610a47c91cSRobert Mustacchi 	int dtd_ref;		/* recfount for dyanmic types */
1627c478bd9Sstevel@tonic-gate 	union {
1637c478bd9Sstevel@tonic-gate 		ctf_list_t dtu_members;	/* struct, union, or enum */
1647c478bd9Sstevel@tonic-gate 		ctf_arinfo_t dtu_arr;	/* array */
1657c478bd9Sstevel@tonic-gate 		ctf_encoding_t dtu_enc;	/* integer or float */
1667c478bd9Sstevel@tonic-gate 		ctf_id_t *dtu_argv;	/* function */
1677c478bd9Sstevel@tonic-gate 	} dtd_u;
1687c478bd9Sstevel@tonic-gate } ctf_dtdef_t;
1697c478bd9Sstevel@tonic-gate 
170bc1f688bSRobert Mustacchi typedef struct ctf_dsdef {
171bc1f688bSRobert Mustacchi 	ctf_list_t dsd_list;	/* list forward/back pointers */
172bc1f688bSRobert Mustacchi 	ulong_t dsd_symidx;	/* symbol id */
173bc1f688bSRobert Mustacchi 	ctf_id_t dsd_tid;	/* type for obj, 0 if function */
174bc1f688bSRobert Mustacchi 	uint_t dsd_nargs;
175bc1f688bSRobert Mustacchi 	ctf_id_t *dsd_argc;	/* function argv */
176bc1f688bSRobert Mustacchi } ctf_dsdef_t;
177bc1f688bSRobert Mustacchi 
178bc1f688bSRobert Mustacchi typedef struct ctf_dldef {
179bc1f688bSRobert Mustacchi 	ctf_list_t dld_list;	/* list forward/back pointers */
180bc1f688bSRobert Mustacchi 	char *dld_name;		/* name of the label */
181bc1f688bSRobert Mustacchi 	ctf_id_t dld_type;	/* type ID associated with the label */
182bc1f688bSRobert Mustacchi } ctf_dldef_t;
183bc1f688bSRobert Mustacchi 
1847c478bd9Sstevel@tonic-gate typedef struct ctf_bundle {
1857c478bd9Sstevel@tonic-gate 	ctf_file_t *ctb_file;	/* CTF container handle */
1867c478bd9Sstevel@tonic-gate 	ctf_id_t ctb_type;	/* CTF type identifier */
1877c478bd9Sstevel@tonic-gate 	ctf_dtdef_t *ctb_dtd;	/* CTF dynamic type definition (if any) */
1887c478bd9Sstevel@tonic-gate } ctf_bundle_t;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate  * The ctf_file is the structure used to represent a CTF container to library
1927c478bd9Sstevel@tonic-gate  * clients, who see it only as an opaque pointer.  Modifications can therefore
1937c478bd9Sstevel@tonic-gate  * be made freely to this structure without regard to client versioning.  The
1947c478bd9Sstevel@tonic-gate  * ctf_file_t typedef appears in <sys/ctf_api.h> and declares a forward tag.
1957c478bd9Sstevel@tonic-gate  *
1967c478bd9Sstevel@tonic-gate  * NOTE: ctf_update() requires that everything inside of ctf_file either be an
1977c478bd9Sstevel@tonic-gate  * immediate value, a pointer to dynamically allocated data *outside* of the
1987c478bd9Sstevel@tonic-gate  * ctf_file itself, or a pointer to statically allocated data.  If you add a
1997c478bd9Sstevel@tonic-gate  * pointer to ctf_file that points to something within the ctf_file itself,
2007c478bd9Sstevel@tonic-gate  * you must make corresponding changes to ctf_update().
2017c478bd9Sstevel@tonic-gate  */
2027c478bd9Sstevel@tonic-gate struct ctf_file {
2037c478bd9Sstevel@tonic-gate 	const ctf_fileops_t *ctf_fileops; /* version-specific file operations */
2047c478bd9Sstevel@tonic-gate 	ctf_sect_t ctf_data;	/* CTF data from object file */
2057c478bd9Sstevel@tonic-gate 	ctf_sect_t ctf_symtab;	/* symbol table from object file */
2067c478bd9Sstevel@tonic-gate 	ctf_sect_t ctf_strtab;	/* string table from object file */
2077c478bd9Sstevel@tonic-gate 	ctf_hash_t ctf_structs;	/* hash table of struct types */
2087c478bd9Sstevel@tonic-gate 	ctf_hash_t ctf_unions;	/* hash table of union types */
2097c478bd9Sstevel@tonic-gate 	ctf_hash_t ctf_enums;	/* hash table of enum types */
2107c478bd9Sstevel@tonic-gate 	ctf_hash_t ctf_names;	/* hash table of remaining type names */
2117c478bd9Sstevel@tonic-gate 	ctf_lookup_t ctf_lookups[5];	/* pointers to hashes for name lookup */
2127c478bd9Sstevel@tonic-gate 	ctf_strs_t ctf_str[2];	/* array of string table base and bounds */
2137c478bd9Sstevel@tonic-gate 	const uchar_t *ctf_base; /* base of CTF header + uncompressed buffer */
2147c478bd9Sstevel@tonic-gate 	const uchar_t *ctf_buf;	/* uncompressed CTF data buffer */
2157c478bd9Sstevel@tonic-gate 	size_t ctf_size;	/* size of CTF header + uncompressed data */
2167c478bd9Sstevel@tonic-gate 	uint_t *ctf_sxlate;	/* translation table for symtab entries */
2177c478bd9Sstevel@tonic-gate 	ulong_t ctf_nsyms;	/* number of entries in symtab xlate table */
2187c478bd9Sstevel@tonic-gate 	uint_t *ctf_txlate;	/* translation table for type IDs */
2197c478bd9Sstevel@tonic-gate 	ushort_t *ctf_ptrtab;	/* translation table for pointer-to lookups */
2207c478bd9Sstevel@tonic-gate 	ulong_t ctf_typemax;	/* maximum valid type ID number */
2217c478bd9Sstevel@tonic-gate 	const ctf_dmodel_t *ctf_dmodel;	/* data model pointer (see above) */
2227c478bd9Sstevel@tonic-gate 	struct ctf_file *ctf_parent;	/* parent CTF container (if any) */
2237c478bd9Sstevel@tonic-gate 	const char *ctf_parlabel;	/* label in parent container (if any) */
2247c478bd9Sstevel@tonic-gate 	const char *ctf_parname;	/* basename of parent (if any) */
2257c478bd9Sstevel@tonic-gate 	uint_t ctf_refcnt;	/* reference count (for parent links) */
2267c478bd9Sstevel@tonic-gate 	uint_t ctf_flags;	/* libctf flags (see below) */
2277c478bd9Sstevel@tonic-gate 	int ctf_errno;		/* error code for most recent error */
2287c478bd9Sstevel@tonic-gate 	int ctf_version;	/* CTF data version */
229e4586ebfSmws 	ctf_dtdef_t **ctf_dthash; /* hash of dynamic type definitions */
230e4586ebfSmws 	ulong_t ctf_dthashlen;	/* size of dynamic type hash bucket array */
2317c478bd9Sstevel@tonic-gate 	ctf_list_t ctf_dtdefs;	/* list of dynamic type definitions */
2327c478bd9Sstevel@tonic-gate 	size_t ctf_dtstrlen;	/* total length of dynamic type strings */
2337c478bd9Sstevel@tonic-gate 	ulong_t ctf_dtnextid;	/* next dynamic type id to assign */
2347c478bd9Sstevel@tonic-gate 	ulong_t ctf_dtoldid;	/* oldest id that has been committed */
2357c478bd9Sstevel@tonic-gate 	void *ctf_specific;	/* data for ctf_get/setspecific */
236bc1f688bSRobert Mustacchi 	ctf_list_t ctf_dsdefs;	/* list of dynamic obj/func definitions */
237bc1f688bSRobert Mustacchi 	ctf_list_t ctf_dldefs;	/* list of dynamic labels */
238bc1f688bSRobert Mustacchi 	uint_t ctf_hflags;	/* original flags on the header */
2397c478bd9Sstevel@tonic-gate };
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate #define	LCTF_INDEX_TO_TYPEPTR(fp, i) \
2427c478bd9Sstevel@tonic-gate 	((ctf_type_t *)((uintptr_t)(fp)->ctf_buf + (fp)->ctf_txlate[(i)]))
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate #define	LCTF_INFO_KIND(fp, info)	((fp)->ctf_fileops->ctfo_get_kind(info))
2457c478bd9Sstevel@tonic-gate #define	LCTF_INFO_ROOT(fp, info)	((fp)->ctf_fileops->ctfo_get_root(info))
2467c478bd9Sstevel@tonic-gate #define	LCTF_INFO_VLEN(fp, info)	((fp)->ctf_fileops->ctfo_get_vlen(info))
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate #define	LCTF_MMAP	0x0001	/* libctf should munmap buffers on close */
2497c478bd9Sstevel@tonic-gate #define	LCTF_CHILD	0x0002	/* CTF container is a child */
2507c478bd9Sstevel@tonic-gate #define	LCTF_RDWR	0x0004	/* CTF container is writable */
2517c478bd9Sstevel@tonic-gate #define	LCTF_DIRTY	0x0008	/* CTF container has been modified */
252*a676209dSAndy Fiddaman /*
253*a676209dSAndy Fiddaman  * The storage for this CTF container was allocated via ctf_data_alloc()
254*a676209dSAndy Fiddaman  * and libctf should free it with ctf_data_free() on close.
255*a676209dSAndy Fiddaman  */
256*a676209dSAndy Fiddaman #define	LCTF_FREE	0x0010
2577c478bd9Sstevel@tonic-gate 
258bc1f688bSRobert Mustacchi #define	CTF_ELF_SCN_NAME	".SUNW_ctf"
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate extern ssize_t ctf_get_ctt_size(const ctf_file_t *, const ctf_type_t *,
2617c478bd9Sstevel@tonic-gate     ssize_t *, ssize_t *);
2627c478bd9Sstevel@tonic-gate 
263fe2dc8bdSJohn Levon extern void ctf_set_ctt_size(ctf_type_t *, ssize_t);
264fe2dc8bdSJohn Levon 
2657c478bd9Sstevel@tonic-gate extern const ctf_type_t *ctf_lookup_by_id(ctf_file_t **, ctf_id_t);
2667c478bd9Sstevel@tonic-gate 
267bc1f688bSRobert Mustacchi extern ctf_file_t *ctf_fdcreate_int(int, int *, ctf_sect_t *);
268bc1f688bSRobert Mustacchi 
2697c478bd9Sstevel@tonic-gate extern int ctf_hash_create(ctf_hash_t *, ulong_t);
2707c478bd9Sstevel@tonic-gate extern int ctf_hash_insert(ctf_hash_t *, ctf_file_t *, ushort_t, uint_t);
271e4586ebfSmws extern int ctf_hash_define(ctf_hash_t *, ctf_file_t *, ushort_t, uint_t);
2727c478bd9Sstevel@tonic-gate extern ctf_helem_t *ctf_hash_lookup(ctf_hash_t *, ctf_file_t *,
2737c478bd9Sstevel@tonic-gate     const char *, size_t);
2747c478bd9Sstevel@tonic-gate extern uint_t ctf_hash_size(const ctf_hash_t *);
2757c478bd9Sstevel@tonic-gate extern void ctf_hash_destroy(ctf_hash_t *);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate #define	ctf_list_prev(elem)	((void *)(((ctf_list_t *)(elem))->l_prev))
2787c478bd9Sstevel@tonic-gate #define	ctf_list_next(elem)	((void *)(((ctf_list_t *)(elem))->l_next))
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate extern void ctf_list_append(ctf_list_t *, void *);
2817c478bd9Sstevel@tonic-gate extern void ctf_list_prepend(ctf_list_t *, void *);
282bc1f688bSRobert Mustacchi extern void ctf_list_insert_before(ctf_list_t *, void *, void *);
2837c478bd9Sstevel@tonic-gate extern void ctf_list_delete(ctf_list_t *, void *);
2847c478bd9Sstevel@tonic-gate 
285e4586ebfSmws extern void ctf_dtd_insert(ctf_file_t *, ctf_dtdef_t *);
286e4586ebfSmws extern void ctf_dtd_delete(ctf_file_t *, ctf_dtdef_t *);
287e4586ebfSmws extern ctf_dtdef_t *ctf_dtd_lookup(ctf_file_t *, ctf_id_t);
288e4586ebfSmws 
289bc1f688bSRobert Mustacchi extern void ctf_dsd_delete(ctf_file_t *, ctf_dsdef_t *);
290bc1f688bSRobert Mustacchi extern void ctf_dld_delete(ctf_file_t *, ctf_dldef_t *);
291bc1f688bSRobert Mustacchi 
2927c478bd9Sstevel@tonic-gate extern void ctf_decl_init(ctf_decl_t *, char *, size_t);
2937c478bd9Sstevel@tonic-gate extern void ctf_decl_fini(ctf_decl_t *);
2947c478bd9Sstevel@tonic-gate extern void ctf_decl_push(ctf_decl_t *, ctf_file_t *, ctf_id_t);
2957c478bd9Sstevel@tonic-gate extern void ctf_decl_sprintf(ctf_decl_t *, const char *, ...);
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate extern const char *ctf_strraw(ctf_file_t *, uint_t);
2987c478bd9Sstevel@tonic-gate extern const char *ctf_strptr(ctf_file_t *, uint_t);
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate extern ctf_file_t *ctf_set_open_errno(int *, int);
3017c478bd9Sstevel@tonic-gate extern long ctf_set_errno(ctf_file_t *, int);
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate extern const void *ctf_sect_mmap(ctf_sect_t *, int);
3047c478bd9Sstevel@tonic-gate extern void ctf_sect_munmap(const ctf_sect_t *);
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate extern void *ctf_data_alloc(size_t);
3077c478bd9Sstevel@tonic-gate extern void ctf_data_free(void *, size_t);
3087c478bd9Sstevel@tonic-gate extern void ctf_data_protect(void *, size_t);
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate extern void *ctf_alloc(size_t);
3117c478bd9Sstevel@tonic-gate extern void ctf_free(void *, size_t);
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate extern char *ctf_strdup(const char *);
3147c478bd9Sstevel@tonic-gate extern const char *ctf_strerror(int);
3157c478bd9Sstevel@tonic-gate extern void ctf_dprintf(const char *, ...);
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate extern void *ctf_zopen(int *);
3187c478bd9Sstevel@tonic-gate 
319bc1f688bSRobert Mustacchi extern ctf_id_t ctf_add_encoded(ctf_file_t *, uint_t, const char *,
320bc1f688bSRobert Mustacchi     const ctf_encoding_t *, uint_t);
321bc1f688bSRobert Mustacchi extern ctf_id_t ctf_add_reftype(ctf_file_t *, uint_t, const char *, ctf_id_t,
322bc1f688bSRobert Mustacchi     uint_t);
323bc1f688bSRobert Mustacchi extern boolean_t ctf_sym_valid(uintptr_t, int, uint16_t, uint64_t,
324bc1f688bSRobert Mustacchi     uint32_t);
325bc1f688bSRobert Mustacchi 
3266ef284f1SJohn Levon extern const ctf_type_t *ctf_dyn_lookup_by_id(ctf_file_t *, ctf_id_t);
3276ef284f1SJohn Levon extern int ctf_dyn_array_info(ctf_file_t *, ctf_id_t, ctf_arinfo_t *);
3286ef284f1SJohn Levon 
3297c478bd9Sstevel@tonic-gate extern const char _CTF_SECTION[];	/* name of CTF ELF section */
3307c478bd9Sstevel@tonic-gate extern const char _CTF_NULLSTR[];	/* empty string */
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate extern int _libctf_version;		/* library client version */
3337c478bd9Sstevel@tonic-gate extern int _libctf_debug;		/* debugging messages enabled */
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate #endif
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate #endif	/* _CTF_IMPL_H */
340