Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /* Copyright (c) 2018 Facebook */
0003 #ifndef _UAPI__LINUX_BTF_H__
0004 #define _UAPI__LINUX_BTF_H__
0005 
0006 #include <linux/types.h>
0007 
0008 #define BTF_MAGIC   0xeB9F
0009 #define BTF_VERSION 1
0010 
0011 struct btf_header {
0012     __u16   magic;
0013     __u8    version;
0014     __u8    flags;
0015     __u32   hdr_len;
0016 
0017     /* All offsets are in bytes relative to the end of this header */
0018     __u32   type_off;   /* offset of type section   */
0019     __u32   type_len;   /* length of type section   */
0020     __u32   str_off;    /* offset of string section */
0021     __u32   str_len;    /* length of string section */
0022 };
0023 
0024 /* Max # of type identifier */
0025 #define BTF_MAX_TYPE    0x000fffff
0026 /* Max offset into the string section */
0027 #define BTF_MAX_NAME_OFFSET 0x00ffffff
0028 /* Max # of struct/union/enum members or func args */
0029 #define BTF_MAX_VLEN    0xffff
0030 
0031 struct btf_type {
0032     __u32 name_off;
0033     /* "info" bits arrangement
0034      * bits  0-15: vlen (e.g. # of struct's members)
0035      * bits 16-23: unused
0036      * bits 24-28: kind (e.g. int, ptr, array...etc)
0037      * bits 29-30: unused
0038      * bit     31: kind_flag, currently used by
0039      *             struct, union, enum, fwd and enum64
0040      */
0041     __u32 info;
0042     /* "size" is used by INT, ENUM, STRUCT, UNION, DATASEC and ENUM64.
0043      * "size" tells the size of the type it is describing.
0044      *
0045      * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
0046      * FUNC, FUNC_PROTO, VAR, DECL_TAG and TYPE_TAG.
0047      * "type" is a type_id referring to another type.
0048      */
0049     union {
0050         __u32 size;
0051         __u32 type;
0052     };
0053 };
0054 
0055 #define BTF_INFO_KIND(info) (((info) >> 24) & 0x1f)
0056 #define BTF_INFO_VLEN(info) ((info) & 0xffff)
0057 #define BTF_INFO_KFLAG(info)    ((info) >> 31)
0058 
0059 enum {
0060     BTF_KIND_UNKN       = 0,    /* Unknown  */
0061     BTF_KIND_INT        = 1,    /* Integer  */
0062     BTF_KIND_PTR        = 2,    /* Pointer  */
0063     BTF_KIND_ARRAY      = 3,    /* Array    */
0064     BTF_KIND_STRUCT     = 4,    /* Struct   */
0065     BTF_KIND_UNION      = 5,    /* Union    */
0066     BTF_KIND_ENUM       = 6,    /* Enumeration up to 32-bit values */
0067     BTF_KIND_FWD        = 7,    /* Forward  */
0068     BTF_KIND_TYPEDEF    = 8,    /* Typedef  */
0069     BTF_KIND_VOLATILE   = 9,    /* Volatile */
0070     BTF_KIND_CONST      = 10,   /* Const    */
0071     BTF_KIND_RESTRICT   = 11,   /* Restrict */
0072     BTF_KIND_FUNC       = 12,   /* Function */
0073     BTF_KIND_FUNC_PROTO = 13,   /* Function Proto   */
0074     BTF_KIND_VAR        = 14,   /* Variable */
0075     BTF_KIND_DATASEC    = 15,   /* Section  */
0076     BTF_KIND_FLOAT      = 16,   /* Floating point   */
0077     BTF_KIND_DECL_TAG   = 17,   /* Decl Tag */
0078     BTF_KIND_TYPE_TAG   = 18,   /* Type Tag */
0079     BTF_KIND_ENUM64     = 19,   /* Enumeration up to 64-bit values */
0080 
0081     NR_BTF_KINDS,
0082     BTF_KIND_MAX        = NR_BTF_KINDS - 1,
0083 };
0084 
0085 /* For some specific BTF_KIND, "struct btf_type" is immediately
0086  * followed by extra data.
0087  */
0088 
0089 /* BTF_KIND_INT is followed by a u32 and the following
0090  * is the 32 bits arrangement:
0091  */
0092 #define BTF_INT_ENCODING(VAL)   (((VAL) & 0x0f000000) >> 24)
0093 #define BTF_INT_OFFSET(VAL) (((VAL) & 0x00ff0000) >> 16)
0094 #define BTF_INT_BITS(VAL)   ((VAL)  & 0x000000ff)
0095 
0096 /* Attributes stored in the BTF_INT_ENCODING */
0097 #define BTF_INT_SIGNED  (1 << 0)
0098 #define BTF_INT_CHAR    (1 << 1)
0099 #define BTF_INT_BOOL    (1 << 2)
0100 
0101 /* BTF_KIND_ENUM is followed by multiple "struct btf_enum".
0102  * The exact number of btf_enum is stored in the vlen (of the
0103  * info in "struct btf_type").
0104  */
0105 struct btf_enum {
0106     __u32   name_off;
0107     __s32   val;
0108 };
0109 
0110 /* BTF_KIND_ARRAY is followed by one "struct btf_array" */
0111 struct btf_array {
0112     __u32   type;
0113     __u32   index_type;
0114     __u32   nelems;
0115 };
0116 
0117 /* BTF_KIND_STRUCT and BTF_KIND_UNION are followed
0118  * by multiple "struct btf_member".  The exact number
0119  * of btf_member is stored in the vlen (of the info in
0120  * "struct btf_type").
0121  */
0122 struct btf_member {
0123     __u32   name_off;
0124     __u32   type;
0125     /* If the type info kind_flag is set, the btf_member offset
0126      * contains both member bitfield size and bit offset. The
0127      * bitfield size is set for bitfield members. If the type
0128      * info kind_flag is not set, the offset contains only bit
0129      * offset.
0130      */
0131     __u32   offset;
0132 };
0133 
0134 /* If the struct/union type info kind_flag is set, the
0135  * following two macros are used to access bitfield_size
0136  * and bit_offset from btf_member.offset.
0137  */
0138 #define BTF_MEMBER_BITFIELD_SIZE(val)   ((val) >> 24)
0139 #define BTF_MEMBER_BIT_OFFSET(val)  ((val) & 0xffffff)
0140 
0141 /* BTF_KIND_FUNC_PROTO is followed by multiple "struct btf_param".
0142  * The exact number of btf_param is stored in the vlen (of the
0143  * info in "struct btf_type").
0144  */
0145 struct btf_param {
0146     __u32   name_off;
0147     __u32   type;
0148 };
0149 
0150 enum {
0151     BTF_VAR_STATIC = 0,
0152     BTF_VAR_GLOBAL_ALLOCATED = 1,
0153     BTF_VAR_GLOBAL_EXTERN = 2,
0154 };
0155 
0156 enum btf_func_linkage {
0157     BTF_FUNC_STATIC = 0,
0158     BTF_FUNC_GLOBAL = 1,
0159     BTF_FUNC_EXTERN = 2,
0160 };
0161 
0162 /* BTF_KIND_VAR is followed by a single "struct btf_var" to describe
0163  * additional information related to the variable such as its linkage.
0164  */
0165 struct btf_var {
0166     __u32   linkage;
0167 };
0168 
0169 /* BTF_KIND_DATASEC is followed by multiple "struct btf_var_secinfo"
0170  * to describe all BTF_KIND_VAR types it contains along with it's
0171  * in-section offset as well as size.
0172  */
0173 struct btf_var_secinfo {
0174     __u32   type;
0175     __u32   offset;
0176     __u32   size;
0177 };
0178 
0179 /* BTF_KIND_DECL_TAG is followed by a single "struct btf_decl_tag" to describe
0180  * additional information related to the tag applied location.
0181  * If component_idx == -1, the tag is applied to a struct, union,
0182  * variable or function. Otherwise, it is applied to a struct/union
0183  * member or a func argument, and component_idx indicates which member
0184  * or argument (0 ... vlen-1).
0185  */
0186 struct btf_decl_tag {
0187        __s32   component_idx;
0188 };
0189 
0190 /* BTF_KIND_ENUM64 is followed by multiple "struct btf_enum64".
0191  * The exact number of btf_enum64 is stored in the vlen (of the
0192  * info in "struct btf_type").
0193  */
0194 struct btf_enum64 {
0195     __u32   name_off;
0196     __u32   val_lo32;
0197     __u32   val_hi32;
0198 };
0199 
0200 #endif /* _UAPI__LINUX_BTF_H__ */