Blame include/uapi/linux/btf.h

Packit Service 3880ab
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
Packit Service 3880ab
/* Copyright (c) 2018 Facebook */
Packit Service 3880ab
#ifndef __LINUX_BTF_H__
Packit Service 3880ab
#define __LINUX_BTF_H__
Packit Service 3880ab
Packit Service 3880ab
#include <linux/types.h>
Packit Service 3880ab
Packit Service 3880ab
#define BTF_MAGIC	0xeB9F
Packit Service 3880ab
#define BTF_VERSION	1
Packit Service 3880ab
Packit Service 3880ab
struct btf_header {
Packit Service 3880ab
	__u16	magic;
Packit Service 3880ab
	__u8	version;
Packit Service 3880ab
	__u8	flags;
Packit Service 3880ab
	__u32	hdr_len;
Packit Service 3880ab
Packit Service 3880ab
	/* All offsets are in bytes relative to the end of this header */
Packit Service 3880ab
	__u32	type_off;	/* offset of type section	*/
Packit Service 3880ab
	__u32	type_len;	/* length of type section	*/
Packit Service 3880ab
	__u32	str_off;	/* offset of string section	*/
Packit Service 3880ab
	__u32	str_len;	/* length of string section	*/
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
/* Max # of type identifier */
Packit Service 3880ab
#define BTF_MAX_TYPE	0x000fffff
Packit Service 3880ab
/* Max offset into the string section */
Packit Service 3880ab
#define BTF_MAX_NAME_OFFSET	0x00ffffff
Packit Service 3880ab
/* Max # of struct/union/enum members or func args */
Packit Service 3880ab
#define BTF_MAX_VLEN	0xffff
Packit Service 3880ab
Packit Service 3880ab
struct btf_type {
Packit Service 3880ab
	__u32 name_off;
Packit Service 3880ab
	/* "info" bits arrangement
Packit Service 3880ab
	 * bits  0-15: vlen (e.g. # of struct's members)
Packit Service 3880ab
	 * bits 16-23: unused
Packit Service 3880ab
	 * bits 24-27: kind (e.g. int, ptr, array...etc)
Packit Service 3880ab
	 * bits 28-30: unused
Packit Service 3880ab
	 * bit     31: kind_flag, currently used by
Packit Service 3880ab
	 *             struct, union and fwd
Packit Service 3880ab
	 */
Packit Service 3880ab
	__u32 info;
Packit Service 3880ab
	/* "size" is used by INT, ENUM, STRUCT, UNION and DATASEC.
Packit Service 3880ab
	 * "size" tells the size of the type it is describing.
Packit Service 3880ab
	 *
Packit Service 3880ab
	 * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
Packit Service 3880ab
	 * FUNC, FUNC_PROTO and VAR.
Packit Service 3880ab
	 * "type" is a type_id referring to another type.
Packit Service 3880ab
	 */
Packit Service 3880ab
	union {
Packit Service 3880ab
		__u32 size;
Packit Service 3880ab
		__u32 type;
Packit Service 3880ab
	};
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
#define BTF_INFO_KIND(info)	(((info) >> 24) & 0x0f)
Packit Service 3880ab
#define BTF_INFO_VLEN(info)	((info) & 0xffff)
Packit Service 3880ab
#define BTF_INFO_KFLAG(info)	((info) >> 31)
Packit Service 3880ab
Packit Service 3880ab
#define BTF_KIND_UNKN		0	/* Unknown	*/
Packit Service 3880ab
#define BTF_KIND_INT		1	/* Integer	*/
Packit Service 3880ab
#define BTF_KIND_PTR		2	/* Pointer	*/
Packit Service 3880ab
#define BTF_KIND_ARRAY		3	/* Array	*/
Packit Service 3880ab
#define BTF_KIND_STRUCT		4	/* Struct	*/
Packit Service 3880ab
#define BTF_KIND_UNION		5	/* Union	*/
Packit Service 3880ab
#define BTF_KIND_ENUM		6	/* Enumeration	*/
Packit Service 3880ab
#define BTF_KIND_FWD		7	/* Forward	*/
Packit Service 3880ab
#define BTF_KIND_TYPEDEF	8	/* Typedef	*/
Packit Service 3880ab
#define BTF_KIND_VOLATILE	9	/* Volatile	*/
Packit Service 3880ab
#define BTF_KIND_CONST		10	/* Const	*/
Packit Service 3880ab
#define BTF_KIND_RESTRICT	11	/* Restrict	*/
Packit Service 3880ab
#define BTF_KIND_FUNC		12	/* Function	*/
Packit Service 3880ab
#define BTF_KIND_FUNC_PROTO	13	/* Function Proto	*/
Packit Service 3880ab
#define BTF_KIND_VAR		14	/* Variable	*/
Packit Service 3880ab
#define BTF_KIND_DATASEC	15	/* Section	*/
Packit Service 3880ab
#define BTF_KIND_MAX		BTF_KIND_DATASEC
Packit Service 3880ab
#define NR_BTF_KINDS		(BTF_KIND_MAX + 1)
Packit Service 3880ab
Packit Service 3880ab
/* For some specific BTF_KIND, "struct btf_type" is immediately
Packit Service 3880ab
 * followed by extra data.
Packit Service 3880ab
 */
Packit Service 3880ab
Packit Service 3880ab
/* BTF_KIND_INT is followed by a u32 and the following
Packit Service 3880ab
 * is the 32 bits arrangement:
Packit Service 3880ab
 */
Packit Service 3880ab
#define BTF_INT_ENCODING(VAL)	(((VAL) & 0x0f000000) >> 24)
Packit Service 3880ab
#define BTF_INT_OFFSET(VAL)	(((VAL) & 0x00ff0000) >> 16)
Packit Service 3880ab
#define BTF_INT_BITS(VAL)	((VAL)  & 0x000000ff)
Packit Service 3880ab
Packit Service 3880ab
/* Attributes stored in the BTF_INT_ENCODING */
Packit Service 3880ab
#define BTF_INT_SIGNED	(1 << 0)
Packit Service 3880ab
#define BTF_INT_CHAR	(1 << 1)
Packit Service 3880ab
#define BTF_INT_BOOL	(1 << 2)
Packit Service 3880ab
Packit Service 3880ab
/* BTF_KIND_ENUM is followed by multiple "struct btf_enum".
Packit Service 3880ab
 * The exact number of btf_enum is stored in the vlen (of the
Packit Service 3880ab
 * info in "struct btf_type").
Packit Service 3880ab
 */
Packit Service 3880ab
struct btf_enum {
Packit Service 3880ab
	__u32	name_off;
Packit Service 3880ab
	__s32	val;
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
/* BTF_KIND_ARRAY is followed by one "struct btf_array" */
Packit Service 3880ab
struct btf_array {
Packit Service 3880ab
	__u32	type;
Packit Service 3880ab
	__u32	index_type;
Packit Service 3880ab
	__u32	nelems;
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
/* BTF_KIND_STRUCT and BTF_KIND_UNION are followed
Packit Service 3880ab
 * by multiple "struct btf_member".  The exact number
Packit Service 3880ab
 * of btf_member is stored in the vlen (of the info in
Packit Service 3880ab
 * "struct btf_type").
Packit Service 3880ab
 */
Packit Service 3880ab
struct btf_member {
Packit Service 3880ab
	__u32	name_off;
Packit Service 3880ab
	__u32	type;
Packit Service 3880ab
	/* If the type info kind_flag is set, the btf_member offset
Packit Service 3880ab
	 * contains both member bitfield size and bit offset. The
Packit Service 3880ab
	 * bitfield size is set for bitfield members. If the type
Packit Service 3880ab
	 * info kind_flag is not set, the offset contains only bit
Packit Service 3880ab
	 * offset.
Packit Service 3880ab
	 */
Packit Service 3880ab
	__u32	offset;
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
/* If the struct/union type info kind_flag is set, the
Packit Service 3880ab
 * following two macros are used to access bitfield_size
Packit Service 3880ab
 * and bit_offset from btf_member.offset.
Packit Service 3880ab
 */
Packit Service 3880ab
#define BTF_MEMBER_BITFIELD_SIZE(val)	((val) >> 24)
Packit Service 3880ab
#define BTF_MEMBER_BIT_OFFSET(val)	((val) & 0xffffff)
Packit Service 3880ab
Packit Service 3880ab
/* BTF_KIND_FUNC_PROTO is followed by multiple "struct btf_param".
Packit Service 3880ab
 * The exact number of btf_param is stored in the vlen (of the
Packit Service 3880ab
 * info in "struct btf_type").
Packit Service 3880ab
 */
Packit Service 3880ab
struct btf_param {
Packit Service 3880ab
	__u32	name_off;
Packit Service 3880ab
	__u32	type;
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
enum {
Packit Service 3880ab
	BTF_VAR_STATIC = 0,
Packit Service 3880ab
	BTF_VAR_GLOBAL_ALLOCATED = 1,
Packit Service 3880ab
	BTF_VAR_GLOBAL_EXTERN = 2,
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
enum btf_func_linkage {
Packit Service 3880ab
	BTF_FUNC_STATIC = 0,
Packit Service 3880ab
	BTF_FUNC_GLOBAL = 1,
Packit Service 3880ab
	BTF_FUNC_EXTERN = 2,
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
/* BTF_KIND_VAR is followed by a single "struct btf_var" to describe
Packit Service 3880ab
 * additional information related to the variable such as its linkage.
Packit Service 3880ab
 */
Packit Service 3880ab
struct btf_var {
Packit Service 3880ab
	__u32	linkage;
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
/* BTF_KIND_DATASEC is followed by multiple "struct btf_var_secinfo"
Packit Service 3880ab
 * to describe all BTF_KIND_VAR types it contains along with it's
Packit Service 3880ab
 * in-section offset as well as size.
Packit Service 3880ab
 */
Packit Service 3880ab
struct btf_var_secinfo {
Packit Service 3880ab
	__u32	type;
Packit Service 3880ab
	__u32	offset;
Packit Service 3880ab
	__u32	size;
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
#endif /* __LINUX_BTF_H__ */