]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/ctf.h
ctf: Import ctf.h from OpenBSD
[FreeBSD/FreeBSD.git] / sys / sys / ctf.h
1 /*      $OpenBSD: ctf.h,v 1.5 2017/08/13 14:56:05 nayden Exp $  */
2
3 /*-
4  * SPDX-License-Identifier: ISC
5  *
6  * Copyright (c) 2016 Martin Pieuchot <mpi@openbsd.org>
7  *
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.
11  *
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.
19  */
20
21 #ifndef _SYS_CTF_H_
22 #define _SYS_CTF_H_
23
24 #include <sys/_types.h>
25
26 /*
27  * CTF ``Compact ANSI-C Type Format'' ABI header file.
28  *
29  * See the ctf(5) manual page for a detailed description of the format.
30  */
31
32 typedef struct ctf_preamble {
33         __uint16_t              ctp_magic;
34         __uint8_t               ctp_version;
35         __uint8_t               ctp_flags;
36 } ctf_preamble_t;
37
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;
51 } ctf_header_t;
52
53 #define CTF_F_COMPRESS          (1 << 0)        /* zlib compression */
54
55 typedef struct ctf_lblent {
56         __uint32_t              ctl_label;
57         __uint32_t              ctl_typeidx;
58 } ctf_lblent_t;
59
60 typedef struct ctf_stype {
61         __uint32_t              ctt_name;
62         __uint16_t              ctt_info;
63         union {
64                 __uint16_t _size;
65                 __uint16_t _type;
66         } _u;
67 } ctf_stype_t;
68
69 typedef struct ctf_type {
70         __uint32_t              ctt_name;
71         __uint16_t              ctt_info;
72         union {
73                 __uint16_t _size;
74                 __uint16_t _type;
75         } _u;
76         __uint32_t              ctt_lsizehi;
77         __uint32_t              ctt_lsizelo;
78 } ctf_type_t;
79
80 #define ctt_size _u._size
81 #define ctt_type _u._type
82
83 typedef struct ctf_array {
84         __uint16_t              cta_contents;
85         __uint16_t              cta_index;
86         __uint32_t              cta_nelems;
87 } ctf_array_t;
88
89 typedef struct ctf_member {
90         __uint32_t              ctm_name;
91         __uint16_t              ctm_type;
92         __uint16_t              ctm_offset;
93 } ctf_member_t;
94
95 typedef struct ctf_lmember {
96         __uint32_t              ctlm_name;
97         __uint16_t              ctlm_type;
98         __uint16_t              ctlm_pad;
99         __uint32_t              ctlm_offsethi;
100         __uint32_t              ctlm_offsetlo;
101 } ctf_lmember_t;
102
103 #define CTF_LSTRUCT_THRESH      8192
104
105 typedef struct ctf_enum {
106         __uint32_t              cte_name;
107         __int32_t               cte_value;
108 } ctf_enum_t;
109
110 #define CTF_MAGIC               0xcff1
111 #define CTF_VERSION             CTF_VERSION_2
112 #define CTF_VERSION_2           2
113 #define CTF_VERSION_1           1
114
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 */
119
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))
126
127 #define CTF_TYPE_INFO(k, r, l)  \
128         ((k) << 11) | ((r) != 0 ? (1 << 10) : 0) | ((l) & ((1 << 10) - 1))
129
130 #define CTF_STRTAB_0            0
131 #define CTF_STRTAB_1            1
132
133 #define CTF_TYPE_NAME(t, o)     (((t) << 31) | ((o) & ((1u << 31) - 1)))
134
135 /*
136  * Info macro.
137  */
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
149 #define  CTF_K_ENUM             8
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
155 #define  CTF_K_MAX              31
156
157 /*
158  * Integer/Float Encoding macro.
159  */
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))
165
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)
174
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)
191
192 /*
193  * Name reference macro.
194  */
195 #define CTF_NAME_STID(n)        ((n) >> 31)
196 #define CTF_NAME_OFFSET(n)      ((n) & CTF_MAX_NAME)
197
198 /*
199  * Type macro.
200  */
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)
205
206 /*
207  * Member macro.
208  */
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))
213
214 #endif /* _SYS_CTF_H_ */