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>
7 * Copyright (c) 2022 The FreeBSD Foundation
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 #include <sys/_types.h>
28 * CTF ``Compact ANSI-C Type Format'' ABI header file.
30 * See the ctf(5) manual page for a detailed description of the format.
33 typedef struct ctf_preamble {
35 __uint8_t ctp_version;
39 typedef struct ctf_header {
40 struct ctf_preamble cth_preamble;
41 #define cth_magic cth_preamble.ctp_magic
42 #define cth_version cth_preamble.ctp_version
43 #define cth_flags cth_preamble.ctp_flags
44 __uint32_t cth_parlabel;
45 __uint32_t cth_parname;
46 __uint32_t cth_lbloff;
47 __uint32_t cth_objtoff;
48 __uint32_t cth_funcoff;
49 __uint32_t cth_typeoff;
50 __uint32_t cth_stroff;
51 __uint32_t cth_strlen;
54 #define CTF_F_COMPRESS (1 << 0) /* zlib compression */
56 typedef struct ctf_lblent {
58 __uint32_t ctl_typeidx;
86 __uint32_t ctt_lsizehi;
87 __uint32_t ctt_lsizelo;
97 __uint32_t ctt_lsizehi;
98 __uint32_t ctt_lsizelo;
101 #define ctt_size _u._size
102 #define ctt_type _u._type
104 struct ctf_array_v2 {
105 __uint16_t cta_contents;
106 __uint16_t cta_index;
107 __uint32_t cta_nelems;
110 struct ctf_array_v3 {
111 __uint32_t cta_contents;
112 __uint32_t cta_index;
113 __uint32_t cta_nelems;
116 struct ctf_member_v2 {
119 __uint16_t ctm_offset;
122 struct ctf_member_v3 {
125 __uint32_t ctm_offset;
128 struct ctf_lmember_v2 {
129 __uint32_t ctlm_name;
130 __uint16_t ctlm_type;
132 __uint32_t ctlm_offsethi;
133 __uint32_t ctlm_offsetlo;
136 struct ctf_lmember_v3 {
137 __uint32_t ctlm_name;
138 __uint32_t ctlm_type;
139 __uint32_t ctlm_offsethi;
140 __uint32_t ctlm_offsetlo;
143 #define CTF_V2_LSTRUCT_THRESH (1 << 13)
144 #define CTF_V3_LSTRUCT_THRESH (1 << 29)
146 typedef struct ctf_enum {
151 #define CTF_MAGIC 0xcff1
152 #define CTF_VERSION CTF_VERSION_3
153 #define CTF_VERSION_3 3
154 #define CTF_VERSION_2 2
155 #define CTF_VERSION_1 1
157 #define CTF_MAX_NAME 0x7fffffff
159 #define CTF_V2_MAX_VLEN 0x03ff
160 #define CTF_V2_MAX_SIZE 0xfffe
161 #define CTF_V2_LSIZE_SENT (CTF_V2_MAX_SIZE + 1) /* sentinel for cts vs ctt */
163 #define CTF_V3_MAX_VLEN 0x00ffffff
164 #define CTF_V3_MAX_SIZE 0xfffffffeu
165 #define CTF_V3_LSIZE_SENT (CTF_V3_MAX_SIZE + 1)
167 #define CTF_V2_PARENT_SHIFT 15
168 #define CTF_V2_MAX_TYPE 0xffff
169 #define CTF_V2_TYPE_ISPARENT(id) ((id) < 0x8000)
170 #define CTF_V2_TYPE_ISCHILD(id) ((id) > 0x7fff)
171 #define CTF_V2_TYPE_TO_INDEX(type) ((type) & 0x7fff)
172 #define CTF_V2_INDEX_TO_TYPE(type, ischild) \
173 (((type) & 0x7fff) | ((ischild) != 0 ? 0x8000 : 0))
174 #define CTF_V2_TYPE_INFO(kind, isroot, vlen) \
175 (((kind) << 11) | ((isroot) != 0 ? (1 << 10) : 0) | \
176 ((vlen) & CTF_V2_MAX_VLEN))
178 #define CTF_V3_PARENT_SHIFT 31
179 #define CTF_V3_MAX_TYPE 0xfffffffeu
180 #define CTF_V3_TYPE_ISPARENT(id) ((__uint32_t)(id) < 0x80000000u)
181 #define CTF_V3_TYPE_ISCHILD(id) ((__uint32_t)(id) > 0x7fffffffu)
182 #define CTF_V3_TYPE_TO_INDEX(type) ((type) & 0x7fffffffu)
183 #define CTF_V3_INDEX_TO_TYPE(type, ischild) \
184 (((type) & 0x7fffffffu) | ((ischild) != 0 ? 0x80000000u : 0))
185 #define CTF_V3_TYPE_INFO(kind, isroot, vlen) \
186 (((kind) << 26) | ((isroot) != 0 ? (1 << 25) : 0) | \
187 ((vlen) & CTF_V3_MAX_VLEN))
189 #define CTF_STRTAB_0 0
190 #define CTF_STRTAB_1 1
192 #define CTF_TYPE_NAME(t, o) (((t) << 31) | ((o) & ((1u << 31) - 1)))
197 #define CTF_V2_INFO_VLEN(i) ((i) & CTF_V2_MAX_VLEN)
198 #define CTF_V2_INFO_ISROOT(i) (((i) & 0x0400) >> 10)
199 #define CTF_V2_INFO_KIND(i) (((i) & 0xf800) >> 11)
201 #define CTF_V3_INFO_VLEN(i) ((i) & CTF_V3_MAX_VLEN)
202 #define CTF_V3_INFO_ISROOT(i) (((i) & 0x02000000) >> 25)
203 #define CTF_V3_INFO_KIND(i) (((i) & 0xfc000000) >> 26)
205 #define CTF_K_UNKNOWN 0
206 #define CTF_K_INTEGER 1
207 #define CTF_K_FLOAT 2
208 #define CTF_K_POINTER 3
209 #define CTF_K_ARRAY 4
210 #define CTF_K_FUNCTION 5
211 #define CTF_K_STRUCT 6
212 #define CTF_K_UNION 7
214 #define CTF_K_FORWARD 9
215 #define CTF_K_TYPEDEF 10
216 #define CTF_K_VOLATILE 11
217 #define CTF_K_CONST 12
218 #define CTF_K_RESTRICT 13
222 * Integer/Float Encoding macro.
224 #define _CTF_ENCODING(e) (((e) & 0xff000000) >> 24)
225 #define _CTF_OFFSET(e) (((e) & 0x00ff0000) >> 16)
226 #define _CTF_BITS(e) (((e) & 0x0000ffff))
227 #define _CTF_DATA(encoding, offset, bits) \
228 (((encoding) << 24) | ((offset) << 16) | (bits))
230 #define CTF_INT_ENCODING(e) _CTF_ENCODING(e)
231 #define CTF_INT_SIGNED (1 << 0)
232 #define CTF_INT_CHAR (1 << 1)
233 #define CTF_INT_BOOL (1 << 2)
234 #define CTF_INT_VARARGS (1 << 3)
235 #define CTF_INT_OFFSET(e) _CTF_OFFSET(e)
236 #define CTF_INT_BITS(e) _CTF_BITS(e)
237 #define CTF_INT_DATA(e, o, b) _CTF_DATA(e, o, b)
239 #define CTF_FP_ENCODING(e) _CTF_ENCODING(e)
240 #define CTF_FP_SINGLE 1
241 #define CTF_FP_DOUBLE 2
242 #define CTF_FP_CPLX 3
243 #define CTF_FP_DCPLX 4
244 #define CTF_FP_LDCPLX 5
245 #define CTF_FP_LDOUBLE 6
246 #define CTF_FP_INTRVL 7
247 #define CTF_FP_DINTRVL 8
248 #define CTF_FP_LDINTRVL 9
249 #define CTF_FP_IMAGRY 10
250 #define CTF_FP_DIMAGRY 11
251 #define CTF_FP_LDIMAGRY 12
252 #define CTF_FP_OFFSET(e) _CTF_OFFSET(e)
253 #define CTF_FP_BITS(e) _CTF_BITS(e)
254 #define CTF_FP_DATA(e, o, b) _CTF_DATA(e, o, b)
257 * Name reference macro.
259 #define CTF_NAME_STID(n) ((n) >> 31)
260 #define CTF_NAME_OFFSET(n) ((n) & CTF_MAX_NAME)
265 #define CTF_SIZE_TO_LSIZE_HI(s) ((uint32_t)((uint64_t)(s) >> 32))
266 #define CTF_SIZE_TO_LSIZE_LO(s) ((uint32_t)(s))
267 #define CTF_TYPE_LSIZE(t) \
268 (((uint64_t)(t)->ctt_lsizehi) << 32 | (t)->ctt_lsizelo)
273 #define CTF_LMEM_OFFSET(m) \
274 (((__uint64_t)(m)->ctlm_offsethi) << 32 | (m)->ctlm_offsetlo)
275 #define CTF_OFFSET_TO_LMEMHI(off) ((__uint32_t)((__uint64_t)(off) >> 32))
276 #define CTF_OFFSET_TO_LMEMLO(off) ((__uint32_t)(off))
279 * Compatibility for pre-v3 code.
281 typedef struct ctf_array_v2 ctf_array_t;
282 typedef struct ctf_member_v2 ctf_member_t;
283 typedef struct ctf_lmember_v2 ctf_lmember_t;
284 typedef struct ctf_type_v2 ctf_type_t;
285 typedef struct ctf_stype_v2 ctf_stype_t;
287 #define CTF_INFO_KIND CTF_V2_INFO_KIND
288 #define CTF_INFO_VLEN CTF_V2_INFO_VLEN
289 #define CTF_INFO_ISROOT CTF_V2_INFO_ISROOT
290 #define CTF_TYPE_INFO CTF_V2_TYPE_INFO
291 #define CTF_TYPE_ISPARENT CTF_V2_TYPE_ISPARENT
292 #define CTF_TYPE_ISCHILD CTF_V2_TYPE_ISCHILD
293 #define CTF_TYPE_TO_INDEX CTF_V2_TYPE_TO_INDEX
294 #define CTF_INDEX_TO_TYPE CTF_V2_INDEX_TO_TYPE
295 #define CTF_LSIZE_SENT CTF_V2_LSIZE_SENT
296 #define CTF_LSTRUCT_THRESH CTF_V2_LSTRUCT_THRESH
297 #define CTF_MAX_SIZE CTF_V2_MAX_SIZE
298 #define CTF_MAX_TYPE CTF_V2_MAX_TYPE
299 #define CTF_MAX_VLEN CTF_V2_MAX_VLEN
301 #endif /* _SYS_CTF_H_ */