1 /* $OpenBSD: ctf.h,v 1.5 2017/08/13 14:56:05 nayden Exp $ */
4 * SPDX-License-Identifier: ISC
6 * Copyright (c) 2016 Martin Pieuchot <mpi@openbsd.org>
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include <sys/_types.h>
27 * CTF ``Compact ANSI-C Type Format'' ABI header file.
29 * See the ctf(5) manual page for a detailed description of the format.
32 typedef struct ctf_preamble {
34 __uint8_t ctp_version;
38 typedef struct ctf_header {
39 struct ctf_preamble cth_preamble;
40 #define cth_magic cth_preamble.ctp_magic
41 #define cth_version cth_preamble.ctp_version
42 #define cth_flags cth_preamble.ctp_flags
43 __uint32_t cth_parlabel;
44 __uint32_t cth_parname;
45 __uint32_t cth_lbloff;
46 __uint32_t cth_objtoff;
47 __uint32_t cth_funcoff;
48 __uint32_t cth_typeoff;
49 __uint32_t cth_stroff;
50 __uint32_t cth_strlen;
53 #define CTF_F_COMPRESS (1 << 0) /* zlib compression */
55 typedef struct ctf_lblent {
57 __uint32_t ctl_typeidx;
60 typedef struct ctf_stype {
69 typedef struct ctf_type {
76 __uint32_t ctt_lsizehi;
77 __uint32_t ctt_lsizelo;
80 #define ctt_size _u._size
81 #define ctt_type _u._type
83 typedef struct ctf_array {
84 __uint16_t cta_contents;
86 __uint32_t cta_nelems;
89 typedef struct ctf_member {
92 __uint16_t ctm_offset;
95 typedef struct ctf_lmember {
99 __uint32_t ctlm_offsethi;
100 __uint32_t ctlm_offsetlo;
103 #define CTF_LSTRUCT_THRESH 8192
105 typedef struct ctf_enum {
110 #define CTF_MAGIC 0xcff1
111 #define CTF_VERSION CTF_VERSION_2
112 #define CTF_VERSION_2 2
113 #define CTF_VERSION_1 1
115 #define CTF_MAX_NAME 0x7fffffff
116 #define CTF_MAX_VLEN 0x03ff
117 #define CTF_MAX_SIZE 0xfffe
118 #define CTF_LSIZE_SENT (CTF_MAX_SIZE + 1) /* sentinel for cts vs ctt */
120 #define CTF_PARENT_SHIFT 15
121 #define CTF_MAX_TYPE 0xffff
122 #define CTF_TYPE_ISPARENT(id) ((id) < 0x8000)
123 #define CTF_TYPE_ISCHILD(id) ((id) > 0x7fff)
124 #define CTF_TYPE_TO_INDEX(t) ((t) & 0x7fff)
125 #define CTF_INDEX_TO_TYPE(t, c) (((t) & 0x7fff) | ((c) != 0 ? 0x8000 : 0))
127 #define CTF_TYPE_INFO(k, r, l) \
128 ((k) << 11) | ((r) != 0 ? (1 << 10) : 0) | ((l) & ((1 << 10) - 1))
130 #define CTF_STRTAB_0 0
131 #define CTF_STRTAB_1 1
133 #define CTF_TYPE_NAME(t, o) (((t) << 31) | ((o) & ((1u << 31) - 1)))
138 #define CTF_INFO_VLEN(i) (((i) & CTF_MAX_VLEN))
139 #define CTF_INFO_ISROOT(i) (((i) & 0x0400) >> 10)
140 #define CTF_INFO_KIND(i) (((i) & 0xf800) >> 11)
141 #define CTF_K_UNKNOWN 0
142 #define CTF_K_INTEGER 1
143 #define CTF_K_FLOAT 2
144 #define CTF_K_POINTER 3
145 #define CTF_K_ARRAY 4
146 #define CTF_K_FUNCTION 5
147 #define CTF_K_STRUCT 6
148 #define CTF_K_UNION 7
150 #define CTF_K_FORWARD 9
151 #define CTF_K_TYPEDEF 10
152 #define CTF_K_VOLATILE 11
153 #define CTF_K_CONST 12
154 #define CTF_K_RESTRICT 13
158 * Integer/Float Encoding macro.
160 #define _CTF_ENCODING(e) (((e) & 0xff000000) >> 24)
161 #define _CTF_OFFSET(e) (((e) & 0x00ff0000) >> 16)
162 #define _CTF_BITS(e) (((e) & 0x0000ffff))
163 #define _CTF_DATA(encoding, offset, bits) \
164 (((encoding) << 24) | ((offset) << 16) | (bits))
166 #define CTF_INT_ENCODING(e) _CTF_ENCODING(e)
167 #define CTF_INT_SIGNED (1 << 0)
168 #define CTF_INT_CHAR (1 << 1)
169 #define CTF_INT_BOOL (1 << 2)
170 #define CTF_INT_VARARGS (1 << 3)
171 #define CTF_INT_OFFSET(e) _CTF_OFFSET(e)
172 #define CTF_INT_BITS(e) _CTF_BITS(e)
173 #define CTF_INT_DATA(e, o, b) _CTF_DATA(e, o, b)
175 #define CTF_FP_ENCODING(e) _CTF_ENCODING(e)
176 #define CTF_FP_SINGLE 1
177 #define CTF_FP_DOUBLE 2
178 #define CTF_FP_CPLX 3
179 #define CTF_FP_DCPLX 4
180 #define CTF_FP_LDCPLX 5
181 #define CTF_FP_LDOUBLE 6
182 #define CTF_FP_INTRVL 7
183 #define CTF_FP_DINTRVL 8
184 #define CTF_FP_LDINTRVL 9
185 #define CTF_FP_IMAGRY 10
186 #define CTF_FP_DIMAGRY 11
187 #define CTF_FP_LDIMAGRY 12
188 #define CTF_FP_OFFSET(e) _CTF_OFFSET(e)
189 #define CTF_FP_BITS(e) _CTF_BITS(e)
190 #define CTF_FP_DATA(e, o, b) _CTF_DATA(e, o, b)
193 * Name reference macro.
195 #define CTF_NAME_STID(n) ((n) >> 31)
196 #define CTF_NAME_OFFSET(n) ((n) & CTF_MAX_NAME)
201 #define CTF_SIZE_TO_LSIZE_HI(s) ((uint32_t)((uint64_t)(s) >> 32))
202 #define CTF_SIZE_TO_LSIZE_LO(s) ((uint32_t)(s))
203 #define CTF_TYPE_LSIZE(t) \
204 (((uint64_t)(t)->ctt_lsizehi) << 32 | (t)->ctt_lsizelo)
209 #define CTF_LMEM_OFFSET(m) \
210 (((__uint64_t)(m)->ctlm_offsethi) << 32 | (m)->ctlm_offsetlo)
211 #define CTF_OFFSET_TO_LMEMHI(off) ((__uint32_t)((__uint64_t)(off) >> 32))
212 #define CTF_OFFSET_TO_LMEMLO(off) ((__uint32_t)(off))
214 #endif /* _SYS_CTF_H_ */