1*f7c14bbaSAndroid Build Coastguard Worker /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2*f7c14bbaSAndroid Build Coastguard Worker /* Copyright (c) 2018 Facebook */ 3*f7c14bbaSAndroid Build Coastguard Worker #ifndef _UAPI__LINUX_BTF_H__ 4*f7c14bbaSAndroid Build Coastguard Worker #define _UAPI__LINUX_BTF_H__ 5*f7c14bbaSAndroid Build Coastguard Worker 6*f7c14bbaSAndroid Build Coastguard Worker #include <linux/types.h> 7*f7c14bbaSAndroid Build Coastguard Worker 8*f7c14bbaSAndroid Build Coastguard Worker #define BTF_MAGIC 0xeB9F 9*f7c14bbaSAndroid Build Coastguard Worker #define BTF_VERSION 1 10*f7c14bbaSAndroid Build Coastguard Worker 11*f7c14bbaSAndroid Build Coastguard Worker struct btf_header { 12*f7c14bbaSAndroid Build Coastguard Worker __u16 magic; 13*f7c14bbaSAndroid Build Coastguard Worker __u8 version; 14*f7c14bbaSAndroid Build Coastguard Worker __u8 flags; 15*f7c14bbaSAndroid Build Coastguard Worker __u32 hdr_len; 16*f7c14bbaSAndroid Build Coastguard Worker 17*f7c14bbaSAndroid Build Coastguard Worker /* All offsets are in bytes relative to the end of this header */ 18*f7c14bbaSAndroid Build Coastguard Worker __u32 type_off; /* offset of type section */ 19*f7c14bbaSAndroid Build Coastguard Worker __u32 type_len; /* length of type section */ 20*f7c14bbaSAndroid Build Coastguard Worker __u32 str_off; /* offset of string section */ 21*f7c14bbaSAndroid Build Coastguard Worker __u32 str_len; /* length of string section */ 22*f7c14bbaSAndroid Build Coastguard Worker }; 23*f7c14bbaSAndroid Build Coastguard Worker 24*f7c14bbaSAndroid Build Coastguard Worker /* Max # of type identifier */ 25*f7c14bbaSAndroid Build Coastguard Worker #define BTF_MAX_TYPE 0x000fffff 26*f7c14bbaSAndroid Build Coastguard Worker /* Max offset into the string section */ 27*f7c14bbaSAndroid Build Coastguard Worker #define BTF_MAX_NAME_OFFSET 0x00ffffff 28*f7c14bbaSAndroid Build Coastguard Worker /* Max # of struct/union/enum members or func args */ 29*f7c14bbaSAndroid Build Coastguard Worker #define BTF_MAX_VLEN 0xffff 30*f7c14bbaSAndroid Build Coastguard Worker 31*f7c14bbaSAndroid Build Coastguard Worker struct btf_type { 32*f7c14bbaSAndroid Build Coastguard Worker __u32 name_off; 33*f7c14bbaSAndroid Build Coastguard Worker /* "info" bits arrangement 34*f7c14bbaSAndroid Build Coastguard Worker * bits 0-15: vlen (e.g. # of struct's members) 35*f7c14bbaSAndroid Build Coastguard Worker * bits 16-23: unused 36*f7c14bbaSAndroid Build Coastguard Worker * bits 24-28: kind (e.g. int, ptr, array...etc) 37*f7c14bbaSAndroid Build Coastguard Worker * bits 29-30: unused 38*f7c14bbaSAndroid Build Coastguard Worker * bit 31: kind_flag, currently used by 39*f7c14bbaSAndroid Build Coastguard Worker * struct, union, enum, fwd and enum64 40*f7c14bbaSAndroid Build Coastguard Worker */ 41*f7c14bbaSAndroid Build Coastguard Worker __u32 info; 42*f7c14bbaSAndroid Build Coastguard Worker /* "size" is used by INT, ENUM, STRUCT, UNION, DATASEC and ENUM64. 43*f7c14bbaSAndroid Build Coastguard Worker * "size" tells the size of the type it is describing. 44*f7c14bbaSAndroid Build Coastguard Worker * 45*f7c14bbaSAndroid Build Coastguard Worker * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT, 46*f7c14bbaSAndroid Build Coastguard Worker * FUNC, FUNC_PROTO, VAR, DECL_TAG and TYPE_TAG. 47*f7c14bbaSAndroid Build Coastguard Worker * "type" is a type_id referring to another type. 48*f7c14bbaSAndroid Build Coastguard Worker */ 49*f7c14bbaSAndroid Build Coastguard Worker union { 50*f7c14bbaSAndroid Build Coastguard Worker __u32 size; 51*f7c14bbaSAndroid Build Coastguard Worker __u32 type; 52*f7c14bbaSAndroid Build Coastguard Worker }; 53*f7c14bbaSAndroid Build Coastguard Worker }; 54*f7c14bbaSAndroid Build Coastguard Worker 55*f7c14bbaSAndroid Build Coastguard Worker #define BTF_INFO_KIND(info) (((info) >> 24) & 0x1f) 56*f7c14bbaSAndroid Build Coastguard Worker #define BTF_INFO_VLEN(info) ((info) & 0xffff) 57*f7c14bbaSAndroid Build Coastguard Worker #define BTF_INFO_KFLAG(info) ((info) >> 31) 58*f7c14bbaSAndroid Build Coastguard Worker 59*f7c14bbaSAndroid Build Coastguard Worker enum { 60*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_UNKN = 0, /* Unknown */ 61*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_INT = 1, /* Integer */ 62*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_PTR = 2, /* Pointer */ 63*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_ARRAY = 3, /* Array */ 64*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_STRUCT = 4, /* Struct */ 65*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_UNION = 5, /* Union */ 66*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_ENUM = 6, /* Enumeration up to 32-bit values */ 67*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_FWD = 7, /* Forward */ 68*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_TYPEDEF = 8, /* Typedef */ 69*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_VOLATILE = 9, /* Volatile */ 70*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_CONST = 10, /* Const */ 71*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_RESTRICT = 11, /* Restrict */ 72*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_FUNC = 12, /* Function */ 73*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_FUNC_PROTO = 13, /* Function Proto */ 74*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_VAR = 14, /* Variable */ 75*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_DATASEC = 15, /* Section */ 76*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_FLOAT = 16, /* Floating point */ 77*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_DECL_TAG = 17, /* Decl Tag */ 78*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_TYPE_TAG = 18, /* Type Tag */ 79*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_ENUM64 = 19, /* Enumeration up to 64-bit values */ 80*f7c14bbaSAndroid Build Coastguard Worker 81*f7c14bbaSAndroid Build Coastguard Worker NR_BTF_KINDS, 82*f7c14bbaSAndroid Build Coastguard Worker BTF_KIND_MAX = NR_BTF_KINDS - 1, 83*f7c14bbaSAndroid Build Coastguard Worker }; 84*f7c14bbaSAndroid Build Coastguard Worker 85*f7c14bbaSAndroid Build Coastguard Worker /* For some specific BTF_KIND, "struct btf_type" is immediately 86*f7c14bbaSAndroid Build Coastguard Worker * followed by extra data. 87*f7c14bbaSAndroid Build Coastguard Worker */ 88*f7c14bbaSAndroid Build Coastguard Worker 89*f7c14bbaSAndroid Build Coastguard Worker /* BTF_KIND_INT is followed by a u32 and the following 90*f7c14bbaSAndroid Build Coastguard Worker * is the 32 bits arrangement: 91*f7c14bbaSAndroid Build Coastguard Worker */ 92*f7c14bbaSAndroid Build Coastguard Worker #define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24) 93*f7c14bbaSAndroid Build Coastguard Worker #define BTF_INT_OFFSET(VAL) (((VAL) & 0x00ff0000) >> 16) 94*f7c14bbaSAndroid Build Coastguard Worker #define BTF_INT_BITS(VAL) ((VAL) & 0x000000ff) 95*f7c14bbaSAndroid Build Coastguard Worker 96*f7c14bbaSAndroid Build Coastguard Worker /* Attributes stored in the BTF_INT_ENCODING */ 97*f7c14bbaSAndroid Build Coastguard Worker #define BTF_INT_SIGNED (1 << 0) 98*f7c14bbaSAndroid Build Coastguard Worker #define BTF_INT_CHAR (1 << 1) 99*f7c14bbaSAndroid Build Coastguard Worker #define BTF_INT_BOOL (1 << 2) 100*f7c14bbaSAndroid Build Coastguard Worker 101*f7c14bbaSAndroid Build Coastguard Worker /* BTF_KIND_ENUM is followed by multiple "struct btf_enum". 102*f7c14bbaSAndroid Build Coastguard Worker * The exact number of btf_enum is stored in the vlen (of the 103*f7c14bbaSAndroid Build Coastguard Worker * info in "struct btf_type"). 104*f7c14bbaSAndroid Build Coastguard Worker */ 105*f7c14bbaSAndroid Build Coastguard Worker struct btf_enum { 106*f7c14bbaSAndroid Build Coastguard Worker __u32 name_off; 107*f7c14bbaSAndroid Build Coastguard Worker __s32 val; 108*f7c14bbaSAndroid Build Coastguard Worker }; 109*f7c14bbaSAndroid Build Coastguard Worker 110*f7c14bbaSAndroid Build Coastguard Worker /* BTF_KIND_ARRAY is followed by one "struct btf_array" */ 111*f7c14bbaSAndroid Build Coastguard Worker struct btf_array { 112*f7c14bbaSAndroid Build Coastguard Worker __u32 type; 113*f7c14bbaSAndroid Build Coastguard Worker __u32 index_type; 114*f7c14bbaSAndroid Build Coastguard Worker __u32 nelems; 115*f7c14bbaSAndroid Build Coastguard Worker }; 116*f7c14bbaSAndroid Build Coastguard Worker 117*f7c14bbaSAndroid Build Coastguard Worker /* BTF_KIND_STRUCT and BTF_KIND_UNION are followed 118*f7c14bbaSAndroid Build Coastguard Worker * by multiple "struct btf_member". The exact number 119*f7c14bbaSAndroid Build Coastguard Worker * of btf_member is stored in the vlen (of the info in 120*f7c14bbaSAndroid Build Coastguard Worker * "struct btf_type"). 121*f7c14bbaSAndroid Build Coastguard Worker */ 122*f7c14bbaSAndroid Build Coastguard Worker struct btf_member { 123*f7c14bbaSAndroid Build Coastguard Worker __u32 name_off; 124*f7c14bbaSAndroid Build Coastguard Worker __u32 type; 125*f7c14bbaSAndroid Build Coastguard Worker /* If the type info kind_flag is set, the btf_member offset 126*f7c14bbaSAndroid Build Coastguard Worker * contains both member bitfield size and bit offset. The 127*f7c14bbaSAndroid Build Coastguard Worker * bitfield size is set for bitfield members. If the type 128*f7c14bbaSAndroid Build Coastguard Worker * info kind_flag is not set, the offset contains only bit 129*f7c14bbaSAndroid Build Coastguard Worker * offset. 130*f7c14bbaSAndroid Build Coastguard Worker */ 131*f7c14bbaSAndroid Build Coastguard Worker __u32 offset; 132*f7c14bbaSAndroid Build Coastguard Worker }; 133*f7c14bbaSAndroid Build Coastguard Worker 134*f7c14bbaSAndroid Build Coastguard Worker /* If the struct/union type info kind_flag is set, the 135*f7c14bbaSAndroid Build Coastguard Worker * following two macros are used to access bitfield_size 136*f7c14bbaSAndroid Build Coastguard Worker * and bit_offset from btf_member.offset. 137*f7c14bbaSAndroid Build Coastguard Worker */ 138*f7c14bbaSAndroid Build Coastguard Worker #define BTF_MEMBER_BITFIELD_SIZE(val) ((val) >> 24) 139*f7c14bbaSAndroid Build Coastguard Worker #define BTF_MEMBER_BIT_OFFSET(val) ((val) & 0xffffff) 140*f7c14bbaSAndroid Build Coastguard Worker 141*f7c14bbaSAndroid Build Coastguard Worker /* BTF_KIND_FUNC_PROTO is followed by multiple "struct btf_param". 142*f7c14bbaSAndroid Build Coastguard Worker * The exact number of btf_param is stored in the vlen (of the 143*f7c14bbaSAndroid Build Coastguard Worker * info in "struct btf_type"). 144*f7c14bbaSAndroid Build Coastguard Worker */ 145*f7c14bbaSAndroid Build Coastguard Worker struct btf_param { 146*f7c14bbaSAndroid Build Coastguard Worker __u32 name_off; 147*f7c14bbaSAndroid Build Coastguard Worker __u32 type; 148*f7c14bbaSAndroid Build Coastguard Worker }; 149*f7c14bbaSAndroid Build Coastguard Worker 150*f7c14bbaSAndroid Build Coastguard Worker enum { 151*f7c14bbaSAndroid Build Coastguard Worker BTF_VAR_STATIC = 0, 152*f7c14bbaSAndroid Build Coastguard Worker BTF_VAR_GLOBAL_ALLOCATED = 1, 153*f7c14bbaSAndroid Build Coastguard Worker BTF_VAR_GLOBAL_EXTERN = 2, 154*f7c14bbaSAndroid Build Coastguard Worker }; 155*f7c14bbaSAndroid Build Coastguard Worker 156*f7c14bbaSAndroid Build Coastguard Worker enum btf_func_linkage { 157*f7c14bbaSAndroid Build Coastguard Worker BTF_FUNC_STATIC = 0, 158*f7c14bbaSAndroid Build Coastguard Worker BTF_FUNC_GLOBAL = 1, 159*f7c14bbaSAndroid Build Coastguard Worker BTF_FUNC_EXTERN = 2, 160*f7c14bbaSAndroid Build Coastguard Worker }; 161*f7c14bbaSAndroid Build Coastguard Worker 162*f7c14bbaSAndroid Build Coastguard Worker /* BTF_KIND_VAR is followed by a single "struct btf_var" to describe 163*f7c14bbaSAndroid Build Coastguard Worker * additional information related to the variable such as its linkage. 164*f7c14bbaSAndroid Build Coastguard Worker */ 165*f7c14bbaSAndroid Build Coastguard Worker struct btf_var { 166*f7c14bbaSAndroid Build Coastguard Worker __u32 linkage; 167*f7c14bbaSAndroid Build Coastguard Worker }; 168*f7c14bbaSAndroid Build Coastguard Worker 169*f7c14bbaSAndroid Build Coastguard Worker /* BTF_KIND_DATASEC is followed by multiple "struct btf_var_secinfo" 170*f7c14bbaSAndroid Build Coastguard Worker * to describe all BTF_KIND_VAR types it contains along with it's 171*f7c14bbaSAndroid Build Coastguard Worker * in-section offset as well as size. 172*f7c14bbaSAndroid Build Coastguard Worker */ 173*f7c14bbaSAndroid Build Coastguard Worker struct btf_var_secinfo { 174*f7c14bbaSAndroid Build Coastguard Worker __u32 type; 175*f7c14bbaSAndroid Build Coastguard Worker __u32 offset; 176*f7c14bbaSAndroid Build Coastguard Worker __u32 size; 177*f7c14bbaSAndroid Build Coastguard Worker }; 178*f7c14bbaSAndroid Build Coastguard Worker 179*f7c14bbaSAndroid Build Coastguard Worker /* BTF_KIND_DECL_TAG is followed by a single "struct btf_decl_tag" to describe 180*f7c14bbaSAndroid Build Coastguard Worker * additional information related to the tag applied location. 181*f7c14bbaSAndroid Build Coastguard Worker * If component_idx == -1, the tag is applied to a struct, union, 182*f7c14bbaSAndroid Build Coastguard Worker * variable or function. Otherwise, it is applied to a struct/union 183*f7c14bbaSAndroid Build Coastguard Worker * member or a func argument, and component_idx indicates which member 184*f7c14bbaSAndroid Build Coastguard Worker * or argument (0 ... vlen-1). 185*f7c14bbaSAndroid Build Coastguard Worker */ 186*f7c14bbaSAndroid Build Coastguard Worker struct btf_decl_tag { 187*f7c14bbaSAndroid Build Coastguard Worker __s32 component_idx; 188*f7c14bbaSAndroid Build Coastguard Worker }; 189*f7c14bbaSAndroid Build Coastguard Worker 190*f7c14bbaSAndroid Build Coastguard Worker /* BTF_KIND_ENUM64 is followed by multiple "struct btf_enum64". 191*f7c14bbaSAndroid Build Coastguard Worker * The exact number of btf_enum64 is stored in the vlen (of the 192*f7c14bbaSAndroid Build Coastguard Worker * info in "struct btf_type"). 193*f7c14bbaSAndroid Build Coastguard Worker */ 194*f7c14bbaSAndroid Build Coastguard Worker struct btf_enum64 { 195*f7c14bbaSAndroid Build Coastguard Worker __u32 name_off; 196*f7c14bbaSAndroid Build Coastguard Worker __u32 val_lo32; 197*f7c14bbaSAndroid Build Coastguard Worker __u32 val_hi32; 198*f7c14bbaSAndroid Build Coastguard Worker }; 199*f7c14bbaSAndroid Build Coastguard Worker 200*f7c14bbaSAndroid Build Coastguard Worker #endif /* _UAPI__LINUX_BTF_H__ */ 201