xref: /illumos-gate/usr/src/uts/common/sys/ctf.h (revision bc1f688b)
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  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*bc1f688bSRobert Mustacchi  *
26*bc1f688bSRobert Mustacchi  * Copyright 2018 Joyent, Inc.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_CTF_H
307c478bd9Sstevel@tonic-gate #define	_CTF_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
357c478bd9Sstevel@tonic-gate extern "C" {
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * CTF - Compact ANSI-C Type Format
407c478bd9Sstevel@tonic-gate  *
417c478bd9Sstevel@tonic-gate  * This file format can be used to compactly represent the information needed
427c478bd9Sstevel@tonic-gate  * by a debugger to interpret the ANSI-C types used by a given program.
437c478bd9Sstevel@tonic-gate  * Traditionally, this kind of information is generated by the compiler when
447c478bd9Sstevel@tonic-gate  * invoked with the -g flag and is stored in "stabs" strings or in the more
457c478bd9Sstevel@tonic-gate  * modern DWARF format.  CTF provides a representation of only the information
467c478bd9Sstevel@tonic-gate  * that is relevant to debugging a complex, optimized C program such as the
477c478bd9Sstevel@tonic-gate  * operating system kernel in a form that is significantly more compact than
487c478bd9Sstevel@tonic-gate  * the equivalent stabs or DWARF representation.  The format is data-model
497c478bd9Sstevel@tonic-gate  * independent, so consumers do not need different code depending on whether
507c478bd9Sstevel@tonic-gate  * they are 32-bit or 64-bit programs.  CTF assumes that a standard ELF symbol
517c478bd9Sstevel@tonic-gate  * table is available for use in the debugger, and uses the structure and data
527c478bd9Sstevel@tonic-gate  * of the symbol table to avoid storing redundant information.  The CTF data
537c478bd9Sstevel@tonic-gate  * may be compressed on disk or in memory, indicated by a bit in the header.
547c478bd9Sstevel@tonic-gate  * CTF may be interpreted in a raw disk file, or it may be stored in an ELF
557c478bd9Sstevel@tonic-gate  * section, typically named .SUNW_ctf.  Data structures are aligned so that
567c478bd9Sstevel@tonic-gate  * a raw CTF file or CTF ELF section may be manipulated using mmap(2).
577c478bd9Sstevel@tonic-gate  *
587c478bd9Sstevel@tonic-gate  * The CTF file or section itself has the following structure:
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  * +--------+--------+---------+----------+-------+--------+
617c478bd9Sstevel@tonic-gate  * |  file  |  type  |  data   | function | data  | string |
627c478bd9Sstevel@tonic-gate  * | header | labels | objects |   info   | types | table  |
637c478bd9Sstevel@tonic-gate  * +--------+--------+---------+----------+-------+--------+
647c478bd9Sstevel@tonic-gate  *
657c478bd9Sstevel@tonic-gate  * The file header stores a magic number and version information, encoding
667c478bd9Sstevel@tonic-gate  * flags, and the byte offset of each of the sections relative to the end of the
677c478bd9Sstevel@tonic-gate  * header itself.  If the CTF data has been uniquified against another set of
687c478bd9Sstevel@tonic-gate  * CTF data, a reference to that data also appears in the the header.  This
697c478bd9Sstevel@tonic-gate  * reference is the name of the label corresponding to the types uniquified
707c478bd9Sstevel@tonic-gate  * against.
717c478bd9Sstevel@tonic-gate  *
727c478bd9Sstevel@tonic-gate  * Following the header is a list of labels, used to group the types included in
737c478bd9Sstevel@tonic-gate  * the data types section.  Each label is accompanied by a type ID i.  A given
747c478bd9Sstevel@tonic-gate  * label refers to the group of types whose IDs are in the range [0, i].
757c478bd9Sstevel@tonic-gate  *
767c478bd9Sstevel@tonic-gate  * Data object and function records are stored in the same order as they appear
777c478bd9Sstevel@tonic-gate  * in the corresponding symbol table, except that symbols marked SHN_UNDEF are
787c478bd9Sstevel@tonic-gate  * not stored and symbols that have no type data are padded out with zeroes.
797c478bd9Sstevel@tonic-gate  * For each data object, the type ID (a small integer) is recorded.  For each
807c478bd9Sstevel@tonic-gate  * function, the type ID of the return type and argument types is recorded.
817c478bd9Sstevel@tonic-gate  *
827c478bd9Sstevel@tonic-gate  * The data types section is a list of variable size records that represent each
837c478bd9Sstevel@tonic-gate  * type, in order by their ID.  The types themselves form a directed graph,
847c478bd9Sstevel@tonic-gate  * where each node may contain one or more outgoing edges to other type nodes,
857c478bd9Sstevel@tonic-gate  * denoted by their ID.
867c478bd9Sstevel@tonic-gate  *
877c478bd9Sstevel@tonic-gate  * Strings are recorded as a string table ID (0 or 1) and a byte offset into the
887c478bd9Sstevel@tonic-gate  * string table.  String table 0 is the internal CTF string table.  String table
897c478bd9Sstevel@tonic-gate  * 1 is the external string table, which is the string table associated with the
907c478bd9Sstevel@tonic-gate  * ELF symbol table for this object.  CTF does not record any strings that are
917c478bd9Sstevel@tonic-gate  * already in the symbol table, and the CTF string table does not contain any
927c478bd9Sstevel@tonic-gate  * duplicated strings.
937c478bd9Sstevel@tonic-gate  *
947c478bd9Sstevel@tonic-gate  * If the CTF data has been merged with another parent CTF object, some outgoing
957c478bd9Sstevel@tonic-gate  * edges may refer to type nodes that exist in another CTF object.  The debugger
967c478bd9Sstevel@tonic-gate  * and libctf library are responsible for connecting the appropriate objects
977c478bd9Sstevel@tonic-gate  * together so that the full set of types can be explored and manipulated.
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #define	CTF_MAX_TYPE	0xffff	/* max type identifier value */
1017c478bd9Sstevel@tonic-gate #define	CTF_MAX_NAME 0x7fffffff	/* max offset into a string table */
1027c478bd9Sstevel@tonic-gate #define	CTF_MAX_VLEN	0x3ff	/* max struct, union, enum members or args */
1037c478bd9Sstevel@tonic-gate #define	CTF_MAX_INTOFF	0xff	/* max offset of intrinsic value in bits */
1047c478bd9Sstevel@tonic-gate #define	CTF_MAX_INTBITS	0xffff	/* max size of an intrinsic in bits */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /* See ctf_type_t */
1077c478bd9Sstevel@tonic-gate #define	CTF_MAX_SIZE	0xfffe	/* max size of a type in bytes */
1087c478bd9Sstevel@tonic-gate #define	CTF_LSIZE_SENT	0xffff	/* sentinel for ctt_size */
1097c478bd9Sstevel@tonic-gate #define	CTF_MAX_LSIZE	UINT64_MAX
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate typedef struct ctf_preamble {
1127c478bd9Sstevel@tonic-gate 	ushort_t ctp_magic;	/* magic number (CTF_MAGIC) */
1137c478bd9Sstevel@tonic-gate 	uchar_t ctp_version;	/* data format version number (CTF_VERSION) */
1147c478bd9Sstevel@tonic-gate 	uchar_t ctp_flags;	/* flags (see below) */
1157c478bd9Sstevel@tonic-gate } ctf_preamble_t;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate typedef struct ctf_header {
1187c478bd9Sstevel@tonic-gate 	ctf_preamble_t cth_preamble;
1197c478bd9Sstevel@tonic-gate 	uint_t cth_parlabel;	/* ref to name of parent lbl uniq'd against */
1207c478bd9Sstevel@tonic-gate 	uint_t cth_parname;	/* ref to basename of parent */
1217c478bd9Sstevel@tonic-gate 	uint_t cth_lbloff;	/* offset of label section */
1227c478bd9Sstevel@tonic-gate 	uint_t cth_objtoff;	/* offset of object section */
1237c478bd9Sstevel@tonic-gate 	uint_t cth_funcoff;	/* offset of function section */
1247c478bd9Sstevel@tonic-gate 	uint_t cth_typeoff;	/* offset of type section */
1257c478bd9Sstevel@tonic-gate 	uint_t cth_stroff;	/* offset of string section */
1267c478bd9Sstevel@tonic-gate 	uint_t cth_strlen;	/* length of string section in bytes */
1277c478bd9Sstevel@tonic-gate } ctf_header_t;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate #define	cth_magic   cth_preamble.ctp_magic
1307c478bd9Sstevel@tonic-gate #define	cth_version cth_preamble.ctp_version
1317c478bd9Sstevel@tonic-gate #define	cth_flags   cth_preamble.ctp_flags
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #ifdef CTF_OLD_VERSIONS
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate typedef struct ctf_header_v1 {
1367c478bd9Sstevel@tonic-gate 	ctf_preamble_t cth_preamble;
1377c478bd9Sstevel@tonic-gate 	uint_t cth_objtoff;
1387c478bd9Sstevel@tonic-gate 	uint_t cth_funcoff;
1397c478bd9Sstevel@tonic-gate 	uint_t cth_typeoff;
1407c478bd9Sstevel@tonic-gate 	uint_t cth_stroff;
1417c478bd9Sstevel@tonic-gate 	uint_t cth_strlen;
1427c478bd9Sstevel@tonic-gate } ctf_header_v1_t;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #endif /* CTF_OLD_VERSIONS */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #define	CTF_MAGIC	0xcff1	/* magic number identifying header */
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /* data format version number */
1497c478bd9Sstevel@tonic-gate #define	CTF_VERSION_1	1
1507c478bd9Sstevel@tonic-gate #define	CTF_VERSION_2	2
1517c478bd9Sstevel@tonic-gate #define	CTF_VERSION	CTF_VERSION_2	/* current version */
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #define	CTF_F_COMPRESS	0x1	/* data buffer is compressed */
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate typedef struct ctf_lblent {
1567c478bd9Sstevel@tonic-gate 	uint_t ctl_label;	/* ref to name of label */
1577c478bd9Sstevel@tonic-gate 	uint_t ctl_typeidx;	/* last type associated with this label */
1587c478bd9Sstevel@tonic-gate } ctf_lblent_t;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate typedef struct ctf_stype {
1617c478bd9Sstevel@tonic-gate 	uint_t ctt_name;	/* reference to name in string table */
1627c478bd9Sstevel@tonic-gate 	ushort_t ctt_info;	/* encoded kind, variant length (see below) */
1637c478bd9Sstevel@tonic-gate 	union {
1647c478bd9Sstevel@tonic-gate 		ushort_t _size;	/* size of entire type in bytes */
1657c478bd9Sstevel@tonic-gate 		ushort_t _type;	/* reference to another type */
1667c478bd9Sstevel@tonic-gate 	} _u;
1677c478bd9Sstevel@tonic-gate } ctf_stype_t;
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * type sizes, measured in bytes, come in two flavors.  99% of them fit within
1717c478bd9Sstevel@tonic-gate  * (USHRT_MAX - 1), and thus can be stored in the ctt_size member of a
1727c478bd9Sstevel@tonic-gate  * ctf_stype_t.  The maximum value for these sizes is CTF_MAX_SIZE.  The sizes
1737c478bd9Sstevel@tonic-gate  * larger than CTF_MAX_SIZE must be stored in the ctt_lsize member of a
1747c478bd9Sstevel@tonic-gate  * ctf_type_t.  Use of this member is indicated by the presence of
1757c478bd9Sstevel@tonic-gate  * CTF_LSIZE_SENT in ctt_size.
1767c478bd9Sstevel@tonic-gate  */
1777c478bd9Sstevel@tonic-gate typedef struct ctf_type {
1787c478bd9Sstevel@tonic-gate 	uint_t ctt_name;	/* reference to name in string table */
1797c478bd9Sstevel@tonic-gate 	ushort_t ctt_info;	/* encoded kind, variant length (see below) */
1807c478bd9Sstevel@tonic-gate 	union {
1817c478bd9Sstevel@tonic-gate 		ushort_t _size;	/* always CTF_LSIZE_SENT */
1827c478bd9Sstevel@tonic-gate 		ushort_t _type; /* do not use */
1837c478bd9Sstevel@tonic-gate 	} _u;
1847c478bd9Sstevel@tonic-gate 	uint_t ctt_lsizehi;	/* high 32 bits of type size in bytes */
1857c478bd9Sstevel@tonic-gate 	uint_t ctt_lsizelo;	/* low 32 bits of type size in bytes */
1867c478bd9Sstevel@tonic-gate } ctf_type_t;
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate #define	ctt_size _u._size	/* for fundamental types that have a size */
1897c478bd9Sstevel@tonic-gate #define	ctt_type _u._type	/* for types that reference another type */
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  * The following macros compose and decompose values for ctt_info and
1937c478bd9Sstevel@tonic-gate  * ctt_name, as well as other structures that contain name references.
1947c478bd9Sstevel@tonic-gate  *
1957c478bd9Sstevel@tonic-gate  *             ------------------------
1967c478bd9Sstevel@tonic-gate  * ctt_info:   | kind | isroot | vlen |
1977c478bd9Sstevel@tonic-gate  *             ------------------------
1987c478bd9Sstevel@tonic-gate  *             15   11    10    9     0
1997c478bd9Sstevel@tonic-gate  *
2007c478bd9Sstevel@tonic-gate  * kind = CTF_INFO_KIND(c.ctt_info);     <-- CTF_K_* value (see below)
2017c478bd9Sstevel@tonic-gate  * vlen = CTF_INFO_VLEN(c.ctt_info);     <-- length of variable data list
2027c478bd9Sstevel@tonic-gate  *
2037c478bd9Sstevel@tonic-gate  * stid = CTF_NAME_STID(c.ctt_name);     <-- string table id number (0 or 1)
2047c478bd9Sstevel@tonic-gate  * offset = CTF_NAME_OFFSET(c.ctt_name); <-- string table byte offset
2057c478bd9Sstevel@tonic-gate  *
2067c478bd9Sstevel@tonic-gate  * c.ctt_info = CTF_TYPE_INFO(kind, vlen);
2077c478bd9Sstevel@tonic-gate  * c.ctt_name = CTF_TYPE_NAME(stid, offset);
2087c478bd9Sstevel@tonic-gate  */
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate #define	CTF_INFO_KIND(info)	(((info) & 0xf800) >> 11)
2117c478bd9Sstevel@tonic-gate #define	CTF_INFO_ISROOT(info)	(((info) & 0x0400) >> 10)
2127c478bd9Sstevel@tonic-gate #define	CTF_INFO_VLEN(info)	(((info) & CTF_MAX_VLEN))
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate #define	CTF_NAME_STID(name)	((name) >> 31)
2157c478bd9Sstevel@tonic-gate #define	CTF_NAME_OFFSET(name)	((name) & 0x7fffffff)
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate #define	CTF_TYPE_INFO(kind, isroot, vlen) \
2187c478bd9Sstevel@tonic-gate 	(((kind) << 11) | (((isroot) ? 1 : 0) << 10) | ((vlen) & CTF_MAX_VLEN))
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate #define	CTF_TYPE_NAME(stid, offset) \
2217c478bd9Sstevel@tonic-gate 	(((stid) << 31) | ((offset) & 0x7fffffff))
2227c478bd9Sstevel@tonic-gate 
223*bc1f688bSRobert Mustacchi #define	CTF_CHILD_START		(0x8000)
224*bc1f688bSRobert Mustacchi #define	CTF_TYPE_ISPARENT(id)	((id) < CTF_CHILD_START)
225*bc1f688bSRobert Mustacchi #define	CTF_TYPE_ISCHILD(id)	((id) >= CTF_CHILD_START)
2267c478bd9Sstevel@tonic-gate 
227*bc1f688bSRobert Mustacchi #define	CTF_TYPE_TO_INDEX(id)		((id) & (CTF_CHILD_START - 1))
228*bc1f688bSRobert Mustacchi #define	CTF_INDEX_TO_TYPE(id, child) \
229*bc1f688bSRobert Mustacchi 	((child) ? ((id) | CTF_CHILD_START) : (id))
2307c478bd9Sstevel@tonic-gate #define	CTF_PARENT_SHIFT	15
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate #define	CTF_STRTAB_0	0	/* symbolic define for string table id 0 */
2337c478bd9Sstevel@tonic-gate #define	CTF_STRTAB_1	1	/* symbolic define for string table id 1 */
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate #define	CTF_TYPE_LSIZE(cttp) \
2367c478bd9Sstevel@tonic-gate 	(((uint64_t)(cttp)->ctt_lsizehi) << 32 | (cttp)->ctt_lsizelo)
2377c478bd9Sstevel@tonic-gate #define	CTF_SIZE_TO_LSIZE_HI(size)	((uint32_t)((uint64_t)(size) >> 32))
2387c478bd9Sstevel@tonic-gate #define	CTF_SIZE_TO_LSIZE_LO(size)	((uint32_t)(size))
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate #ifdef CTF_OLD_VERSIONS
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate #define	CTF_INFO_KIND_V1(info)		(((info) & 0xf000) >> 12)
2437c478bd9Sstevel@tonic-gate #define	CTF_INFO_ISROOT_V1(info)	(((info) & 0x0800) >> 11)
2447c478bd9Sstevel@tonic-gate #define	CTF_INFO_VLEN_V1(info)		(((info) & 0x07ff))
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate #define	CTF_TYPE_INFO_V1(kind, isroot, vlen) \
2477c478bd9Sstevel@tonic-gate 	(((kind) << 12) | (((isroot) ? 1 : 0) << 11) | ((vlen) & 0x07ff))
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate #endif /* CTF_OLD_VERSIONS */
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate  * Values for CTF_TYPE_KIND().  If the kind has an associated data list,
2537c478bd9Sstevel@tonic-gate  * CTF_INFO_VLEN() will extract the number of elements in the list, and
2547c478bd9Sstevel@tonic-gate  * the type of each element is shown in the comments below.
2557c478bd9Sstevel@tonic-gate  */
2567c478bd9Sstevel@tonic-gate #define	CTF_K_UNKNOWN	0	/* unknown type (used for padding) */
2577c478bd9Sstevel@tonic-gate #define	CTF_K_INTEGER	1	/* variant data is CTF_INT_DATA() (see below) */
2587c478bd9Sstevel@tonic-gate #define	CTF_K_FLOAT	2	/* variant data is CTF_FP_DATA() (see below) */
2597c478bd9Sstevel@tonic-gate #define	CTF_K_POINTER	3	/* ctt_type is referenced type */
2607c478bd9Sstevel@tonic-gate #define	CTF_K_ARRAY	4	/* variant data is single ctf_array_t */
2617c478bd9Sstevel@tonic-gate #define	CTF_K_FUNCTION	5	/* ctt_type is return type, variant data is */
2627c478bd9Sstevel@tonic-gate 				/* list of argument types (ushort_t's) */
2637c478bd9Sstevel@tonic-gate #define	CTF_K_STRUCT	6	/* variant data is list of ctf_member_t's */
2647c478bd9Sstevel@tonic-gate #define	CTF_K_UNION	7	/* variant data is list of ctf_member_t's */
2657c478bd9Sstevel@tonic-gate #define	CTF_K_ENUM	8	/* variant data is list of ctf_enum_t's */
2667c478bd9Sstevel@tonic-gate #define	CTF_K_FORWARD	9	/* no additional data; ctt_name is tag */
2677c478bd9Sstevel@tonic-gate #define	CTF_K_TYPEDEF	10	/* ctt_type is referenced type */
2687c478bd9Sstevel@tonic-gate #define	CTF_K_VOLATILE	11	/* ctt_type is base type */
2697c478bd9Sstevel@tonic-gate #define	CTF_K_CONST	12	/* ctt_type is base type */
2707c478bd9Sstevel@tonic-gate #define	CTF_K_RESTRICT	13	/* ctt_type is base type */
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate #define	CTF_K_MAX	31	/* Maximum possible CTF_K_* value */
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate /*
2757c478bd9Sstevel@tonic-gate  * Values for ctt_type when kind is CTF_K_INTEGER.  The flags, offset in bits,
2767c478bd9Sstevel@tonic-gate  * and size in bits are encoded as a single word using the following macros.
2777c478bd9Sstevel@tonic-gate  */
2787c478bd9Sstevel@tonic-gate #define	CTF_INT_ENCODING(data)	(((data) & 0xff000000) >> 24)
2797c478bd9Sstevel@tonic-gate #define	CTF_INT_OFFSET(data)	(((data) & 0x00ff0000) >> 16)
2807c478bd9Sstevel@tonic-gate #define	CTF_INT_BITS(data)	(((data) & 0x0000ffff))
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate #define	CTF_INT_DATA(encoding, offset, bits) \
2837c478bd9Sstevel@tonic-gate 	(((encoding) << 24) | ((offset) << 16) | (bits))
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate #define	CTF_INT_SIGNED	0x01	/* integer is signed (otherwise unsigned) */
2867c478bd9Sstevel@tonic-gate #define	CTF_INT_CHAR	0x02	/* character display format */
2877c478bd9Sstevel@tonic-gate #define	CTF_INT_BOOL	0x04	/* boolean display format */
2887c478bd9Sstevel@tonic-gate #define	CTF_INT_VARARGS	0x08	/* varargs display format */
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate /*
2917c478bd9Sstevel@tonic-gate  * Values for ctt_type when kind is CTF_K_FLOAT.  The encoding, offset in bits,
2927c478bd9Sstevel@tonic-gate  * and size in bits are encoded as a single word using the following macros.
2937c478bd9Sstevel@tonic-gate  */
2947c478bd9Sstevel@tonic-gate #define	CTF_FP_ENCODING(data)	(((data) & 0xff000000) >> 24)
2957c478bd9Sstevel@tonic-gate #define	CTF_FP_OFFSET(data)	(((data) & 0x00ff0000) >> 16)
2967c478bd9Sstevel@tonic-gate #define	CTF_FP_BITS(data)	(((data) & 0x0000ffff))
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate #define	CTF_FP_DATA(encoding, offset, bits) \
2997c478bd9Sstevel@tonic-gate 	(((encoding) << 24) | ((offset) << 16) | (bits))
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate #define	CTF_FP_SINGLE	1	/* IEEE 32-bit float encoding */
3027c478bd9Sstevel@tonic-gate #define	CTF_FP_DOUBLE	2	/* IEEE 64-bit float encoding */
3037c478bd9Sstevel@tonic-gate #define	CTF_FP_CPLX	3	/* Complex encoding */
3047c478bd9Sstevel@tonic-gate #define	CTF_FP_DCPLX	4	/* Double complex encoding */
3057c478bd9Sstevel@tonic-gate #define	CTF_FP_LDCPLX	5	/* Long double complex encoding */
3067c478bd9Sstevel@tonic-gate #define	CTF_FP_LDOUBLE	6	/* Long double encoding */
3077c478bd9Sstevel@tonic-gate #define	CTF_FP_INTRVL	7	/* Interval (2x32-bit) encoding */
3087c478bd9Sstevel@tonic-gate #define	CTF_FP_DINTRVL	8	/* Double interval (2x64-bit) encoding */
3097c478bd9Sstevel@tonic-gate #define	CTF_FP_LDINTRVL	9	/* Long double interval (2x128-bit) encoding */
3107c478bd9Sstevel@tonic-gate #define	CTF_FP_IMAGRY	10	/* Imaginary (32-bit) encoding */
3117c478bd9Sstevel@tonic-gate #define	CTF_FP_DIMAGRY	11	/* Long imaginary (64-bit) encoding */
3127c478bd9Sstevel@tonic-gate #define	CTF_FP_LDIMAGRY	12	/* Long double imaginary (128-bit) encoding */
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate #define	CTF_FP_MAX	12	/* Maximum possible CTF_FP_* value */
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate typedef struct ctf_array {
3177c478bd9Sstevel@tonic-gate 	ushort_t cta_contents;	/* reference to type of array contents */
3187c478bd9Sstevel@tonic-gate 	ushort_t cta_index;	/* reference to type of array index */
3197c478bd9Sstevel@tonic-gate 	uint_t cta_nelems;	/* number of elements */
3207c478bd9Sstevel@tonic-gate } ctf_array_t;
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate /*
3237c478bd9Sstevel@tonic-gate  * Most structure members have bit offsets that can be expressed using a
3247c478bd9Sstevel@tonic-gate  * short.  Some don't.  ctf_member_t is used for structs which cannot
3257c478bd9Sstevel@tonic-gate  * contain any of these large offsets, whereas ctf_lmember_t is used in the
3267c478bd9Sstevel@tonic-gate  * latter case.  If ctt_size for a given struct is >= 8192 bytes, all members
3277c478bd9Sstevel@tonic-gate  * will be stored as type ctf_lmember_t.
3287c478bd9Sstevel@tonic-gate  */
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate #define	CTF_LSTRUCT_THRESH	8192
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate typedef struct ctf_member {
3337c478bd9Sstevel@tonic-gate 	uint_t ctm_name;	/* reference to name in string table */
3347c478bd9Sstevel@tonic-gate 	ushort_t ctm_type;	/* reference to type of member */
3357c478bd9Sstevel@tonic-gate 	ushort_t ctm_offset;	/* offset of this member in bits */
3367c478bd9Sstevel@tonic-gate } ctf_member_t;
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate typedef struct ctf_lmember {
3397c478bd9Sstevel@tonic-gate 	uint_t ctlm_name;	/* reference to name in string table */
3407c478bd9Sstevel@tonic-gate 	ushort_t ctlm_type;	/* reference to type of member */
3417c478bd9Sstevel@tonic-gate 	ushort_t ctlm_pad;	/* padding */
3427c478bd9Sstevel@tonic-gate 	uint_t ctlm_offsethi;	/* high 32 bits of member offset in bits */
3437c478bd9Sstevel@tonic-gate 	uint_t ctlm_offsetlo;	/* low 32 bits of member offset in bits */
3447c478bd9Sstevel@tonic-gate } ctf_lmember_t;
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate #define	CTF_LMEM_OFFSET(ctlmp) \
3477c478bd9Sstevel@tonic-gate 	(((uint64_t)(ctlmp)->ctlm_offsethi) << 32 | (ctlmp)->ctlm_offsetlo)
3487c478bd9Sstevel@tonic-gate #define	CTF_OFFSET_TO_LMEMHI(offset)	((uint32_t)((uint64_t)(offset) >> 32))
3497c478bd9Sstevel@tonic-gate #define	CTF_OFFSET_TO_LMEMLO(offset)	((uint32_t)(offset))
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate typedef struct ctf_enum {
3527c478bd9Sstevel@tonic-gate 	uint_t cte_name;	/* reference to name in string table */
3537c478bd9Sstevel@tonic-gate 	int cte_value;		/* value associated with this name */
3547c478bd9Sstevel@tonic-gate } ctf_enum_t;
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate #endif
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate #endif	/* _CTF_H */
361