169b693f0SMartin KaFai Lau /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 269b693f0SMartin KaFai Lau /* Copyright (c) 2018 Facebook */ 369b693f0SMartin KaFai Lau #ifndef _UAPI__LINUX_BTF_H__ 469b693f0SMartin KaFai Lau #define _UAPI__LINUX_BTF_H__ 569b693f0SMartin KaFai Lau 669b693f0SMartin KaFai Lau #include <linux/types.h> 769b693f0SMartin KaFai Lau 869b693f0SMartin KaFai Lau #define BTF_MAGIC 0xeB9F 969b693f0SMartin KaFai Lau #define BTF_VERSION 1 1069b693f0SMartin KaFai Lau 1169b693f0SMartin KaFai Lau struct btf_header { 1269b693f0SMartin KaFai Lau __u16 magic; 1369b693f0SMartin KaFai Lau __u8 version; 1469b693f0SMartin KaFai Lau __u8 flags; 15f80442a4SMartin KaFai Lau __u32 hdr_len; 1669b693f0SMartin KaFai Lau 1769b693f0SMartin KaFai Lau /* All offsets are in bytes relative to the end of this header */ 1869b693f0SMartin KaFai Lau __u32 type_off; /* offset of type section */ 19f80442a4SMartin KaFai Lau __u32 type_len; /* length of type section */ 2069b693f0SMartin KaFai Lau __u32 str_off; /* offset of string section */ 2169b693f0SMartin KaFai Lau __u32 str_len; /* length of string section */ 2269b693f0SMartin KaFai Lau }; 2369b693f0SMartin KaFai Lau 2469b693f0SMartin KaFai Lau /* Max # of type identifier */ 25a0791f0dSAlexei Starovoitov #define BTF_MAX_TYPE 0x000fffff 2669b693f0SMartin KaFai Lau /* Max offset into the string section */ 27a0791f0dSAlexei Starovoitov #define BTF_MAX_NAME_OFFSET 0x00ffffff 2869b693f0SMartin KaFai Lau /* Max # of struct/union/enum members or func args */ 2969b693f0SMartin KaFai Lau #define BTF_MAX_VLEN 0xffff 3069b693f0SMartin KaFai Lau 3169b693f0SMartin KaFai Lau struct btf_type { 32fbcf93ebSMartin KaFai Lau __u32 name_off; 3369b693f0SMartin KaFai Lau /* "info" bits arrangement 3469b693f0SMartin KaFai Lau * bits 0-15: vlen (e.g. # of struct's members) 3569b693f0SMartin KaFai Lau * bits 16-23: unused 3666df0fdbSHaiyue Wang * bits 24-28: kind (e.g. int, ptr, array...etc) 3766df0fdbSHaiyue Wang * bits 29-30: unused 389d5f9f70SYonghong Song * bit 31: kind_flag, currently used by 39*6089fb32SYonghong Song * struct, union, enum, fwd and enum64 4069b693f0SMartin KaFai Lau */ 4169b693f0SMartin KaFai Lau __u32 info; 42*6089fb32SYonghong Song /* "size" is used by INT, ENUM, STRUCT, UNION, DATASEC and ENUM64. 4369b693f0SMartin KaFai Lau * "size" tells the size of the type it is describing. 4469b693f0SMartin KaFai Lau * 452667a262SMartin KaFai Lau * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT, 468c42d2faSYonghong Song * FUNC, FUNC_PROTO, VAR, DECL_TAG and TYPE_TAG. 4769b693f0SMartin KaFai Lau * "type" is a type_id referring to another type. 4869b693f0SMartin KaFai Lau */ 4969b693f0SMartin KaFai Lau union { 5069b693f0SMartin KaFai Lau __u32 size; 5169b693f0SMartin KaFai Lau __u32 type; 5269b693f0SMartin KaFai Lau }; 5369b693f0SMartin KaFai Lau }; 5469b693f0SMartin KaFai Lau 558fd88691SIlya Leoshkevich #define BTF_INFO_KIND(info) (((info) >> 24) & 0x1f) 5669b693f0SMartin KaFai Lau #define BTF_INFO_VLEN(info) ((info) & 0xffff) 579d5f9f70SYonghong Song #define BTF_INFO_KFLAG(info) ((info) >> 31) 5869b693f0SMartin KaFai Lau 5941ced4cdSYonghong Song enum { 6041ced4cdSYonghong Song BTF_KIND_UNKN = 0, /* Unknown */ 6141ced4cdSYonghong Song BTF_KIND_INT = 1, /* Integer */ 6241ced4cdSYonghong Song BTF_KIND_PTR = 2, /* Pointer */ 6341ced4cdSYonghong Song BTF_KIND_ARRAY = 3, /* Array */ 6441ced4cdSYonghong Song BTF_KIND_STRUCT = 4, /* Struct */ 6541ced4cdSYonghong Song BTF_KIND_UNION = 5, /* Union */ 66*6089fb32SYonghong Song BTF_KIND_ENUM = 6, /* Enumeration up to 32-bit values */ 6741ced4cdSYonghong Song BTF_KIND_FWD = 7, /* Forward */ 6841ced4cdSYonghong Song BTF_KIND_TYPEDEF = 8, /* Typedef */ 6941ced4cdSYonghong Song BTF_KIND_VOLATILE = 9, /* Volatile */ 7041ced4cdSYonghong Song BTF_KIND_CONST = 10, /* Const */ 7141ced4cdSYonghong Song BTF_KIND_RESTRICT = 11, /* Restrict */ 7241ced4cdSYonghong Song BTF_KIND_FUNC = 12, /* Function */ 7341ced4cdSYonghong Song BTF_KIND_FUNC_PROTO = 13, /* Function Proto */ 7441ced4cdSYonghong Song BTF_KIND_VAR = 14, /* Variable */ 7541ced4cdSYonghong Song BTF_KIND_DATASEC = 15, /* Section */ 7641ced4cdSYonghong Song BTF_KIND_FLOAT = 16, /* Floating point */ 77223f903eSYonghong Song BTF_KIND_DECL_TAG = 17, /* Decl Tag */ 788c42d2faSYonghong Song BTF_KIND_TYPE_TAG = 18, /* Type Tag */ 79*6089fb32SYonghong Song BTF_KIND_ENUM64 = 19, /* Enumeration up to 64-bit values */ 8041ced4cdSYonghong Song 8141ced4cdSYonghong Song NR_BTF_KINDS, 8241ced4cdSYonghong Song BTF_KIND_MAX = NR_BTF_KINDS - 1, 8341ced4cdSYonghong Song }; 8469b693f0SMartin KaFai Lau 8569b693f0SMartin KaFai Lau /* For some specific BTF_KIND, "struct btf_type" is immediately 8669b693f0SMartin KaFai Lau * followed by extra data. 8769b693f0SMartin KaFai Lau */ 8869b693f0SMartin KaFai Lau 8969b693f0SMartin KaFai Lau /* BTF_KIND_INT is followed by a u32 and the following 9069b693f0SMartin KaFai Lau * is the 32 bits arrangement: 9169b693f0SMartin KaFai Lau */ 92aea2f7b8SMartin KaFai Lau #define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24) 93948dc8c9SGary Lin #define BTF_INT_OFFSET(VAL) (((VAL) & 0x00ff0000) >> 16) 9436fc3c8cSMartin KaFai Lau #define BTF_INT_BITS(VAL) ((VAL) & 0x000000ff) 9569b693f0SMartin KaFai Lau 9669b693f0SMartin KaFai Lau /* Attributes stored in the BTF_INT_ENCODING */ 97aea2f7b8SMartin KaFai Lau #define BTF_INT_SIGNED (1 << 0) 98aea2f7b8SMartin KaFai Lau #define BTF_INT_CHAR (1 << 1) 99aea2f7b8SMartin KaFai Lau #define BTF_INT_BOOL (1 << 2) 10069b693f0SMartin KaFai Lau 10169b693f0SMartin KaFai Lau /* BTF_KIND_ENUM is followed by multiple "struct btf_enum". 10269b693f0SMartin KaFai Lau * The exact number of btf_enum is stored in the vlen (of the 10369b693f0SMartin KaFai Lau * info in "struct btf_type"). 10469b693f0SMartin KaFai Lau */ 10569b693f0SMartin KaFai Lau struct btf_enum { 106fbcf93ebSMartin KaFai Lau __u32 name_off; 10769b693f0SMartin KaFai Lau __s32 val; 10869b693f0SMartin KaFai Lau }; 10969b693f0SMartin KaFai Lau 11069b693f0SMartin KaFai Lau /* BTF_KIND_ARRAY is followed by one "struct btf_array" */ 11169b693f0SMartin KaFai Lau struct btf_array { 11269b693f0SMartin KaFai Lau __u32 type; 11369b693f0SMartin KaFai Lau __u32 index_type; 11469b693f0SMartin KaFai Lau __u32 nelems; 11569b693f0SMartin KaFai Lau }; 11669b693f0SMartin KaFai Lau 11769b693f0SMartin KaFai Lau /* BTF_KIND_STRUCT and BTF_KIND_UNION are followed 11869b693f0SMartin KaFai Lau * by multiple "struct btf_member". The exact number 11969b693f0SMartin KaFai Lau * of btf_member is stored in the vlen (of the info in 12069b693f0SMartin KaFai Lau * "struct btf_type"). 12169b693f0SMartin KaFai Lau */ 12269b693f0SMartin KaFai Lau struct btf_member { 123fbcf93ebSMartin KaFai Lau __u32 name_off; 12469b693f0SMartin KaFai Lau __u32 type; 1259d5f9f70SYonghong Song /* If the type info kind_flag is set, the btf_member offset 1269d5f9f70SYonghong Song * contains both member bitfield size and bit offset. The 1279d5f9f70SYonghong Song * bitfield size is set for bitfield members. If the type 1289d5f9f70SYonghong Song * info kind_flag is not set, the offset contains only bit 1299d5f9f70SYonghong Song * offset. 1309d5f9f70SYonghong Song */ 1319d5f9f70SYonghong Song __u32 offset; 13269b693f0SMartin KaFai Lau }; 13369b693f0SMartin KaFai Lau 1349d5f9f70SYonghong Song /* If the struct/union type info kind_flag is set, the 1359d5f9f70SYonghong Song * following two macros are used to access bitfield_size 1369d5f9f70SYonghong Song * and bit_offset from btf_member.offset. 1379d5f9f70SYonghong Song */ 1389d5f9f70SYonghong Song #define BTF_MEMBER_BITFIELD_SIZE(val) ((val) >> 24) 1399d5f9f70SYonghong Song #define BTF_MEMBER_BIT_OFFSET(val) ((val) & 0xffffff) 1409d5f9f70SYonghong Song 1412667a262SMartin KaFai Lau /* BTF_KIND_FUNC_PROTO is followed by multiple "struct btf_param". 1422667a262SMartin KaFai Lau * The exact number of btf_param is stored in the vlen (of the 1432667a262SMartin KaFai Lau * info in "struct btf_type"). 1442667a262SMartin KaFai Lau */ 1452667a262SMartin KaFai Lau struct btf_param { 1462667a262SMartin KaFai Lau __u32 name_off; 1472667a262SMartin KaFai Lau __u32 type; 1482667a262SMartin KaFai Lau }; 1492667a262SMartin KaFai Lau 150f063c889SDaniel Borkmann enum { 151f063c889SDaniel Borkmann BTF_VAR_STATIC = 0, 152166750bcSAndrii Nakryiko BTF_VAR_GLOBAL_ALLOCATED = 1, 153166750bcSAndrii Nakryiko BTF_VAR_GLOBAL_EXTERN = 2, 154f063c889SDaniel Borkmann }; 155f063c889SDaniel Borkmann 15651c39bb1SAlexei Starovoitov enum btf_func_linkage { 15751c39bb1SAlexei Starovoitov BTF_FUNC_STATIC = 0, 15851c39bb1SAlexei Starovoitov BTF_FUNC_GLOBAL = 1, 15951c39bb1SAlexei Starovoitov BTF_FUNC_EXTERN = 2, 16051c39bb1SAlexei Starovoitov }; 16151c39bb1SAlexei Starovoitov 162f063c889SDaniel Borkmann /* BTF_KIND_VAR is followed by a single "struct btf_var" to describe 163f063c889SDaniel Borkmann * additional information related to the variable such as its linkage. 164f063c889SDaniel Borkmann */ 165f063c889SDaniel Borkmann struct btf_var { 166f063c889SDaniel Borkmann __u32 linkage; 167f063c889SDaniel Borkmann }; 168f063c889SDaniel Borkmann 169f063c889SDaniel Borkmann /* BTF_KIND_DATASEC is followed by multiple "struct btf_var_secinfo" 170f063c889SDaniel Borkmann * to describe all BTF_KIND_VAR types it contains along with it's 171f063c889SDaniel Borkmann * in-section offset as well as size. 172f063c889SDaniel Borkmann */ 173f063c889SDaniel Borkmann struct btf_var_secinfo { 174f063c889SDaniel Borkmann __u32 type; 175f063c889SDaniel Borkmann __u32 offset; 176f063c889SDaniel Borkmann __u32 size; 177f063c889SDaniel Borkmann }; 178f063c889SDaniel Borkmann 179223f903eSYonghong Song /* BTF_KIND_DECL_TAG is followed by a single "struct btf_decl_tag" to describe 180b5ea834dSYonghong Song * additional information related to the tag applied location. 181b5ea834dSYonghong Song * If component_idx == -1, the tag is applied to a struct, union, 182b5ea834dSYonghong Song * variable or function. Otherwise, it is applied to a struct/union 183b5ea834dSYonghong Song * member or a func argument, and component_idx indicates which member 184b5ea834dSYonghong Song * or argument (0 ... vlen-1). 185b5ea834dSYonghong Song */ 186223f903eSYonghong Song struct btf_decl_tag { 187b5ea834dSYonghong Song __s32 component_idx; 188b5ea834dSYonghong Song }; 189b5ea834dSYonghong Song 190*6089fb32SYonghong Song /* BTF_KIND_ENUM64 is followed by multiple "struct btf_enum64". 191*6089fb32SYonghong Song * The exact number of btf_enum64 is stored in the vlen (of the 192*6089fb32SYonghong Song * info in "struct btf_type"). 193*6089fb32SYonghong Song */ 194*6089fb32SYonghong Song struct btf_enum64 { 195*6089fb32SYonghong Song __u32 name_off; 196*6089fb32SYonghong Song __u32 val_lo32; 197*6089fb32SYonghong Song __u32 val_hi32; 198*6089fb32SYonghong Song }; 199*6089fb32SYonghong Song 20069b693f0SMartin KaFai Lau #endif /* _UAPI__LINUX_BTF_H__ */ 201