1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /* Copyright (c) 2018 Facebook */
3 #ifndef _UAPI__LINUX_BTF_H__
4 #define _UAPI__LINUX_BTF_H__
6 #include <linux/types.h>
8 #define BTF_MAGIC 0xeB9F
17 /* All offsets are in bytes relative to the end of this header */
18 __u32 type_off; /* offset of type section */
19 __u32 type_len; /* length of type section */
20 __u32 str_off; /* offset of string section */
21 __u32 str_len; /* length of string section */
24 /* Max # of type identifier */
25 #define BTF_MAX_TYPE 0x000fffff
26 /* Max offset into the string section */
27 #define BTF_MAX_NAME_OFFSET 0x00ffffff
28 /* Max # of struct/union/enum members or func args */
29 #define BTF_MAX_VLEN 0xffff
33 /* "info" bits arrangement
34 * bits 0-15: vlen (e.g. # of struct's members)
36 * bits 24-27: kind (e.g. int, ptr, array...etc)
38 * bit 31: kind_flag, currently used by
39 * struct, union and fwd
42 /* "size" is used by INT, ENUM, STRUCT, UNION and DATASEC.
43 * "size" tells the size of the type it is describing.
45 * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
46 * FUNC, FUNC_PROTO, VAR and DECL_TAG.
47 * "type" is a type_id referring to another type.
55 #define BTF_INFO_KIND(info) (((info) >> 24) & 0x1f)
56 #define BTF_INFO_VLEN(info) ((info) & 0xffff)
57 #define BTF_INFO_KFLAG(info) ((info) >> 31)
60 BTF_KIND_UNKN = 0, /* Unknown */
61 BTF_KIND_INT = 1, /* Integer */
62 BTF_KIND_PTR = 2, /* Pointer */
63 BTF_KIND_ARRAY = 3, /* Array */
64 BTF_KIND_STRUCT = 4, /* Struct */
65 BTF_KIND_UNION = 5, /* Union */
66 BTF_KIND_ENUM = 6, /* Enumeration */
67 BTF_KIND_FWD = 7, /* Forward */
68 BTF_KIND_TYPEDEF = 8, /* Typedef */
69 BTF_KIND_VOLATILE = 9, /* Volatile */
70 BTF_KIND_CONST = 10, /* Const */
71 BTF_KIND_RESTRICT = 11, /* Restrict */
72 BTF_KIND_FUNC = 12, /* Function */
73 BTF_KIND_FUNC_PROTO = 13, /* Function Proto */
74 BTF_KIND_VAR = 14, /* Variable */
75 BTF_KIND_DATASEC = 15, /* Section */
76 BTF_KIND_FLOAT = 16, /* Floating point */
77 BTF_KIND_DECL_TAG = 17, /* Decl Tag */
80 BTF_KIND_MAX = NR_BTF_KINDS - 1,
83 /* For some specific BTF_KIND, "struct btf_type" is immediately
84 * followed by extra data.
87 /* BTF_KIND_INT is followed by a u32 and the following
88 * is the 32 bits arrangement:
90 #define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24)
91 #define BTF_INT_OFFSET(VAL) (((VAL) & 0x00ff0000) >> 16)
92 #define BTF_INT_BITS(VAL) ((VAL) & 0x000000ff)
94 /* Attributes stored in the BTF_INT_ENCODING */
95 #define BTF_INT_SIGNED (1 << 0)
96 #define BTF_INT_CHAR (1 << 1)
97 #define BTF_INT_BOOL (1 << 2)
99 /* BTF_KIND_ENUM is followed by multiple "struct btf_enum".
100 * The exact number of btf_enum is stored in the vlen (of the
101 * info in "struct btf_type").
108 /* BTF_KIND_ARRAY is followed by one "struct btf_array" */
115 /* BTF_KIND_STRUCT and BTF_KIND_UNION are followed
116 * by multiple "struct btf_member". The exact number
117 * of btf_member is stored in the vlen (of the info in
118 * "struct btf_type").
123 /* If the type info kind_flag is set, the btf_member offset
124 * contains both member bitfield size and bit offset. The
125 * bitfield size is set for bitfield members. If the type
126 * info kind_flag is not set, the offset contains only bit
132 /* If the struct/union type info kind_flag is set, the
133 * following two macros are used to access bitfield_size
134 * and bit_offset from btf_member.offset.
136 #define BTF_MEMBER_BITFIELD_SIZE(val) ((val) >> 24)
137 #define BTF_MEMBER_BIT_OFFSET(val) ((val) & 0xffffff)
139 /* BTF_KIND_FUNC_PROTO is followed by multiple "struct btf_param".
140 * The exact number of btf_param is stored in the vlen (of the
141 * info in "struct btf_type").
150 BTF_VAR_GLOBAL_ALLOCATED = 1,
151 BTF_VAR_GLOBAL_EXTERN = 2,
154 enum btf_func_linkage {
160 /* BTF_KIND_VAR is followed by a single "struct btf_var" to describe
161 * additional information related to the variable such as its linkage.
167 /* BTF_KIND_DATASEC is followed by multiple "struct btf_var_secinfo"
168 * to describe all BTF_KIND_VAR types it contains along with it's
169 * in-section offset as well as size.
171 struct btf_var_secinfo {
177 /* BTF_KIND_DECL_TAG is followed by a single "struct btf_decl_tag" to describe
178 * additional information related to the tag applied location.
179 * If component_idx == -1, the tag is applied to a struct, union,
180 * variable or function. Otherwise, it is applied to a struct/union
181 * member or a func argument, and component_idx indicates which member
182 * or argument (0 ... vlen-1).
184 struct btf_decl_tag {
188 #endif /* _UAPI__LINUX_BTF_H__ */