1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
/* $OpenBSD: ctf.h,v 1.5 2017/08/13 14:56:05 nayden Exp $ */
/*-
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2016 Martin Pieuchot <mpi@openbsd.org>
* Copyright (c) 2022 The FreeBSD Foundation
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _SYS_CTF_H_
#define _SYS_CTF_H_
#include <sys/_types.h>
/*
* CTF ``Compact ANSI-C Type Format'' ABI header file.
*
* See the ctf(5) manual page for a detailed description of the format.
*/
typedef struct ctf_preamble {
__uint16_t ctp_magic;
__uint8_t ctp_version;
__uint8_t ctp_flags;
} ctf_preamble_t;
typedef struct ctf_header {
struct ctf_preamble cth_preamble;
#define cth_magic cth_preamble.ctp_magic
#define cth_version cth_preamble.ctp_version
#define cth_flags cth_preamble.ctp_flags
__uint32_t cth_parlabel;
__uint32_t cth_parname;
__uint32_t cth_lbloff;
__uint32_t cth_objtoff;
__uint32_t cth_funcoff;
__uint32_t cth_typeoff;
__uint32_t cth_stroff;
__uint32_t cth_strlen;
} ctf_header_t;
#define CTF_F_COMPRESS (1 << 0) /* zlib compression */
typedef struct ctf_lblent {
__uint32_t ctl_label;
__uint32_t ctl_typeidx;
} ctf_lblent_t;
struct ctf_stype_v2 {
__uint32_t ctt_name;
__uint16_t ctt_info;
union {
__uint16_t _size;
__uint16_t _type;
} _u;
};
struct ctf_stype_v3 {
__uint32_t ctt_name;
__uint32_t ctt_info;
union {
__uint32_t _size;
__uint32_t _type;
} _u;
};
struct ctf_type_v2 {
__uint32_t ctt_name;
__uint16_t ctt_info;
union {
__uint16_t _size;
__uint16_t _type;
} _u;
__uint32_t ctt_lsizehi;
__uint32_t ctt_lsizelo;
};
struct ctf_type_v3 {
__uint32_t ctt_name;
__uint32_t ctt_info;
union {
__uint32_t _size;
__uint32_t _type;
} _u;
__uint32_t ctt_lsizehi;
__uint32_t ctt_lsizelo;
};
#define ctt_size _u._size
#define ctt_type _u._type
struct ctf_array_v2 {
__uint16_t cta_contents;
__uint16_t cta_index;
__uint32_t cta_nelems;
};
struct ctf_array_v3 {
__uint32_t cta_contents;
__uint32_t cta_index;
__uint32_t cta_nelems;
};
struct ctf_member_v2 {
__uint32_t ctm_name;
__uint16_t ctm_type;
__uint16_t ctm_offset;
};
struct ctf_member_v3 {
__uint32_t ctm_name;
__uint32_t ctm_type;
__uint32_t ctm_offset;
};
struct ctf_lmember_v2 {
__uint32_t ctlm_name;
__uint16_t ctlm_type;
__uint16_t ctlm_pad;
__uint32_t ctlm_offsethi;
__uint32_t ctlm_offsetlo;
};
struct ctf_lmember_v3 {
__uint32_t ctlm_name;
__uint32_t ctlm_type;
__uint32_t ctlm_offsethi;
__uint32_t ctlm_offsetlo;
};
#define CTF_V2_LSTRUCT_THRESH (1 << 13)
#define CTF_V3_LSTRUCT_THRESH (1 << 29)
typedef struct ctf_enum {
__uint32_t cte_name;
__int32_t cte_value;
} ctf_enum_t;
#define CTF_MAGIC 0xcff1
#define CTF_VERSION CTF_VERSION_3
#define CTF_VERSION_3 3
#define CTF_VERSION_2 2
#define CTF_VERSION_1 1
#define CTF_MAX_NAME 0x7fffffff
#define CTF_V2_MAX_VLEN 0x03ff
#define CTF_V2_MAX_SIZE 0xfffe
#define CTF_V2_LSIZE_SENT (CTF_V2_MAX_SIZE + 1) /* sentinel for cts vs ctt */
#define CTF_V3_MAX_VLEN 0x00ffffff
#define CTF_V3_MAX_SIZE 0xfffffffeu
#define CTF_V3_LSIZE_SENT (CTF_V3_MAX_SIZE + 1)
#define CTF_V2_PARENT_SHIFT 15
#define CTF_V2_MAX_TYPE 0xffff
#define CTF_V2_TYPE_ISPARENT(id) ((id) < 0x8000)
#define CTF_V2_TYPE_ISCHILD(id) ((id) > 0x7fff)
#define CTF_V2_TYPE_TO_INDEX(type) ((type) & 0x7fff)
#define CTF_V2_INDEX_TO_TYPE(type, ischild) \
(((type) & 0x7fff) | ((ischild) != 0 ? 0x8000 : 0))
#define CTF_V2_TYPE_INFO(kind, isroot, vlen) \
(((kind) << 11) | ((isroot) != 0 ? (1 << 10) : 0) | \
((vlen) & CTF_V2_MAX_VLEN))
#define CTF_V3_PARENT_SHIFT 31
#define CTF_V3_MAX_TYPE 0xfffffffeu
#define CTF_V3_TYPE_ISPARENT(id) ((__uint32_t)(id) < 0x80000000u)
#define CTF_V3_TYPE_ISCHILD(id) ((__uint32_t)(id) > 0x7fffffffu)
#define CTF_V3_TYPE_TO_INDEX(type) ((type) & 0x7fffffffu)
#define CTF_V3_INDEX_TO_TYPE(type, ischild) \
(((type) & 0x7fffffffu) | ((ischild) != 0 ? 0x80000000u : 0))
#define CTF_V3_TYPE_INFO(kind, isroot, vlen) \
(((kind) << 26) | ((isroot) != 0 ? (1 << 25) : 0) | \
((vlen) & CTF_V3_MAX_VLEN))
#define CTF_STRTAB_0 0
#define CTF_STRTAB_1 1
#define CTF_TYPE_NAME(t, o) (((t) << 31) | ((o) & ((1u << 31) - 1)))
/*
* Info macro.
*/
#define CTF_V2_INFO_VLEN(i) ((i) & CTF_V2_MAX_VLEN)
#define CTF_V2_INFO_ISROOT(i) (((i) & 0x0400) >> 10)
#define CTF_V2_INFO_KIND(i) (((i) & 0xf800) >> 11)
#define CTF_V3_INFO_VLEN(i) ((i) & CTF_V3_MAX_VLEN)
#define CTF_V3_INFO_ISROOT(i) (((i) & 0x02000000) >> 25)
#define CTF_V3_INFO_KIND(i) (((i) & 0xfc000000) >> 26)
#define CTF_K_UNKNOWN 0
#define CTF_K_INTEGER 1
#define CTF_K_FLOAT 2
#define CTF_K_POINTER 3
#define CTF_K_ARRAY 4
#define CTF_K_FUNCTION 5
#define CTF_K_STRUCT 6
#define CTF_K_UNION 7
#define CTF_K_ENUM 8
#define CTF_K_FORWARD 9
#define CTF_K_TYPEDEF 10
#define CTF_K_VOLATILE 11
#define CTF_K_CONST 12
#define CTF_K_RESTRICT 13
#define CTF_K_MAX 63
/*
* Integer/Float Encoding macro.
*/
#define _CTF_ENCODING(e) (((e) & 0xff000000) >> 24)
#define _CTF_OFFSET(e) (((e) & 0x00ff0000) >> 16)
#define _CTF_BITS(e) (((e) & 0x0000ffff))
#define _CTF_DATA(encoding, offset, bits) \
(((encoding) << 24) | ((offset) << 16) | (bits))
#define CTF_INT_ENCODING(e) _CTF_ENCODING(e)
#define CTF_INT_SIGNED (1 << 0)
#define CTF_INT_CHAR (1 << 1)
#define CTF_INT_BOOL (1 << 2)
#define CTF_INT_VARARGS (1 << 3)
#define CTF_INT_OFFSET(e) _CTF_OFFSET(e)
#define CTF_INT_BITS(e) _CTF_BITS(e)
#define CTF_INT_DATA(e, o, b) _CTF_DATA(e, o, b)
#define CTF_FP_ENCODING(e) _CTF_ENCODING(e)
#define CTF_FP_SINGLE 1
#define CTF_FP_DOUBLE 2
#define CTF_FP_CPLX 3
#define CTF_FP_DCPLX 4
#define CTF_FP_LDCPLX 5
#define CTF_FP_LDOUBLE 6
#define CTF_FP_INTRVL 7
#define CTF_FP_DINTRVL 8
#define CTF_FP_LDINTRVL 9
#define CTF_FP_IMAGRY 10
#define CTF_FP_DIMAGRY 11
#define CTF_FP_LDIMAGRY 12
#define CTF_FP_OFFSET(e) _CTF_OFFSET(e)
#define CTF_FP_BITS(e) _CTF_BITS(e)
#define CTF_FP_DATA(e, o, b) _CTF_DATA(e, o, b)
/*
* Name reference macro.
*/
#define CTF_NAME_STID(n) ((n) >> 31)
#define CTF_NAME_OFFSET(n) ((n) & CTF_MAX_NAME)
/*
* Type macro.
*/
#define CTF_SIZE_TO_LSIZE_HI(s) ((uint32_t)((uint64_t)(s) >> 32))
#define CTF_SIZE_TO_LSIZE_LO(s) ((uint32_t)(s))
#define CTF_TYPE_LSIZE(t) \
(((uint64_t)(t)->ctt_lsizehi) << 32 | (t)->ctt_lsizelo)
/*
* Member macro.
*/
#define CTF_LMEM_OFFSET(m) \
(((__uint64_t)(m)->ctlm_offsethi) << 32 | (m)->ctlm_offsetlo)
#define CTF_OFFSET_TO_LMEMHI(off) ((__uint32_t)((__uint64_t)(off) >> 32))
#define CTF_OFFSET_TO_LMEMLO(off) ((__uint32_t)(off))
/*
* Compatibility for pre-v3 code.
*/
typedef struct ctf_array_v2 ctf_array_t;
typedef struct ctf_member_v2 ctf_member_t;
typedef struct ctf_lmember_v2 ctf_lmember_t;
typedef struct ctf_type_v2 ctf_type_t;
typedef struct ctf_stype_v2 ctf_stype_t;
#define CTF_INFO_KIND CTF_V2_INFO_KIND
#define CTF_INFO_VLEN CTF_V2_INFO_VLEN
#define CTF_INFO_ISROOT CTF_V2_INFO_ISROOT
#define CTF_TYPE_INFO CTF_V2_TYPE_INFO
#define CTF_TYPE_ISPARENT CTF_V2_TYPE_ISPARENT
#define CTF_TYPE_ISCHILD CTF_V2_TYPE_ISCHILD
#define CTF_TYPE_TO_INDEX CTF_V2_TYPE_TO_INDEX
#define CTF_INDEX_TO_TYPE CTF_V2_INDEX_TO_TYPE
#define CTF_LSIZE_SENT CTF_V2_LSIZE_SENT
#define CTF_LSTRUCT_THRESH CTF_V2_LSTRUCT_THRESH
#define CTF_MAX_SIZE CTF_V2_MAX_SIZE
#define CTF_MAX_TYPE CTF_V2_MAX_TYPE
#define CTF_MAX_VLEN CTF_V2_MAX_VLEN
#endif /* _SYS_CTF_H_ */
|