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 0x0000ffff
26 /* Max offset into the string section */
27 #define BTF_MAX_NAME_OFFSET 0x0000ffff
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 and UNION.
43 * "size" tells the size of the type it is describing.
45 * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
46 * FUNC and FUNC_PROTO.
47 * "type" is a type_id referring to another type.
55 #define BTF_INFO_KIND(info) (((info) >> 24) & 0x0f)
56 #define BTF_INFO_VLEN(info) ((info) & 0xffff)
57 #define BTF_INFO_KFLAG(info) ((info) >> 31)
59 #define BTF_KIND_UNKN 0 /* Unknown */
60 #define BTF_KIND_INT 1 /* Integer */
61 #define BTF_KIND_PTR 2 /* Pointer */
62 #define BTF_KIND_ARRAY 3 /* Array */
63 #define BTF_KIND_STRUCT 4 /* Struct */
64 #define BTF_KIND_UNION 5 /* Union */
65 #define BTF_KIND_ENUM 6 /* Enumeration */
66 #define BTF_KIND_FWD 7 /* Forward */
67 #define BTF_KIND_TYPEDEF 8 /* Typedef */
68 #define BTF_KIND_VOLATILE 9 /* Volatile */
69 #define BTF_KIND_CONST 10 /* Const */
70 #define BTF_KIND_RESTRICT 11 /* Restrict */
71 #define BTF_KIND_FUNC 12 /* Function */
72 #define BTF_KIND_FUNC_PROTO 13 /* Function Proto */
73 #define BTF_KIND_MAX 13
74 #define NR_BTF_KINDS 14
76 /* For some specific BTF_KIND, "struct btf_type" is immediately
77 * followed by extra data.
80 /* BTF_KIND_INT is followed by a u32 and the following
81 * is the 32 bits arrangement:
83 #define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24)
84 #define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16)
85 #define BTF_INT_BITS(VAL) ((VAL) & 0x000000ff)
87 /* Attributes stored in the BTF_INT_ENCODING */
88 #define BTF_INT_SIGNED (1 << 0)
89 #define BTF_INT_CHAR (1 << 1)
90 #define BTF_INT_BOOL (1 << 2)
92 /* BTF_KIND_ENUM is followed by multiple "struct btf_enum".
93 * The exact number of btf_enum is stored in the vlen (of the
94 * info in "struct btf_type").
101 /* BTF_KIND_ARRAY is followed by one "struct btf_array" */
108 /* BTF_KIND_STRUCT and BTF_KIND_UNION are followed
109 * by multiple "struct btf_member". The exact number
110 * of btf_member is stored in the vlen (of the info in
111 * "struct btf_type").
116 /* If the type info kind_flag is set, the btf_member offset
117 * contains both member bitfield size and bit offset. The
118 * bitfield size is set for bitfield members. If the type
119 * info kind_flag is not set, the offset contains only bit
125 /* If the struct/union type info kind_flag is set, the
126 * following two macros are used to access bitfield_size
127 * and bit_offset from btf_member.offset.
129 #define BTF_MEMBER_BITFIELD_SIZE(val) ((val) >> 24)
130 #define BTF_MEMBER_BIT_OFFSET(val) ((val) & 0xffffff)
132 /* BTF_KIND_FUNC_PROTO is followed by multiple "struct btf_param".
133 * The exact number of btf_param is stored in the vlen (of the
134 * info in "struct btf_type").
141 #endif /* _UAPI__LINUX_BTF_H__ */