]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - include/linux/btf.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018 Facebook */
7 #include <linux/types.h>
8 #include <uapi/linux/btf.h>
10 #define BTF_TYPE_EMIT(type) ((void)(type *)0)
17 extern const struct file_operations btf_fops
;
19 void btf_put(struct btf
*btf
);
20 int btf_new_fd(const union bpf_attr
*attr
);
21 struct btf
*btf_get_by_fd(int fd
);
22 int btf_get_info_by_fd(const struct btf
*btf
,
23 const union bpf_attr
*attr
,
24 union bpf_attr __user
*uattr
);
25 /* Figure out the size of a type_id. If type_id is a modifier
26 * (e.g. const), it will be resolved to find out the type with size.
29 * In describing "const void *", type_id is "const" and "const"
30 * refers to "void *". The return type will be "void *".
32 * If type_id is a simple "int", then return type will be "int".
34 * @btf: struct btf object
35 * @type_id: Find out the size of type_id. The type_id of the return
36 * type is set to *type_id.
37 * @ret_size: It can be NULL. If not NULL, the size of the return
38 * type is set to *ret_size.
39 * Return: The btf_type (resolved to another type with size info if needed).
40 * NULL is returned if type_id itself does not have size info
41 * (e.g. void) or it cannot be resolved to another type that
43 * *type_id and *ret_size will not be changed in the
46 const struct btf_type
*btf_type_id_size(const struct btf
*btf
,
49 void btf_type_seq_show(const struct btf
*btf
, u32 type_id
, void *obj
,
51 int btf_get_fd_by_id(u32 id
);
52 u32
btf_id(const struct btf
*btf
);
53 bool btf_member_is_reg_int(const struct btf
*btf
, const struct btf_type
*s
,
54 const struct btf_member
*m
,
55 u32 expected_offset
, u32 expected_size
);
56 int btf_find_spin_lock(const struct btf
*btf
, const struct btf_type
*t
);
57 bool btf_type_is_void(const struct btf_type
*t
);
58 s32
btf_find_by_name_kind(const struct btf
*btf
, const char *name
, u8 kind
);
59 const struct btf_type
*btf_type_skip_modifiers(const struct btf
*btf
,
61 const struct btf_type
*btf_type_resolve_ptr(const struct btf
*btf
,
63 const struct btf_type
*btf_type_resolve_func_ptr(const struct btf
*btf
,
65 const struct btf_type
*
66 btf_resolve_size(const struct btf
*btf
, const struct btf_type
*type
,
67 u32
*type_size
, const struct btf_type
**elem_type
,
70 #define for_each_member(i, struct_type, member) \
71 for (i = 0, member = btf_type_member(struct_type); \
72 i < btf_type_vlen(struct_type); \
75 static inline bool btf_type_is_ptr(const struct btf_type
*t
)
77 return BTF_INFO_KIND(t
->info
) == BTF_KIND_PTR
;
80 static inline bool btf_type_is_int(const struct btf_type
*t
)
82 return BTF_INFO_KIND(t
->info
) == BTF_KIND_INT
;
85 static inline bool btf_type_is_small_int(const struct btf_type
*t
)
87 return btf_type_is_int(t
) && t
->size
<= sizeof(u64
);
90 static inline bool btf_type_is_enum(const struct btf_type
*t
)
92 return BTF_INFO_KIND(t
->info
) == BTF_KIND_ENUM
;
95 static inline bool btf_type_is_typedef(const struct btf_type
*t
)
97 return BTF_INFO_KIND(t
->info
) == BTF_KIND_TYPEDEF
;
100 static inline bool btf_type_is_func(const struct btf_type
*t
)
102 return BTF_INFO_KIND(t
->info
) == BTF_KIND_FUNC
;
105 static inline bool btf_type_is_func_proto(const struct btf_type
*t
)
107 return BTF_INFO_KIND(t
->info
) == BTF_KIND_FUNC_PROTO
;
110 static inline u16
btf_type_vlen(const struct btf_type
*t
)
112 return BTF_INFO_VLEN(t
->info
);
115 static inline u16
btf_func_linkage(const struct btf_type
*t
)
117 return BTF_INFO_VLEN(t
->info
);
120 static inline bool btf_type_kflag(const struct btf_type
*t
)
122 return BTF_INFO_KFLAG(t
->info
);
125 static inline u32
btf_member_bit_offset(const struct btf_type
*struct_type
,
126 const struct btf_member
*member
)
128 return btf_type_kflag(struct_type
) ? BTF_MEMBER_BIT_OFFSET(member
->offset
)
132 static inline u32
btf_member_bitfield_size(const struct btf_type
*struct_type
,
133 const struct btf_member
*member
)
135 return btf_type_kflag(struct_type
) ? BTF_MEMBER_BITFIELD_SIZE(member
->offset
)
139 static inline const struct btf_member
*btf_type_member(const struct btf_type
*t
)
141 return (const struct btf_member
*)(t
+ 1);
144 #ifdef CONFIG_BPF_SYSCALL
145 const struct btf_type
*btf_type_by_id(const struct btf
*btf
, u32 type_id
);
146 const char *btf_name_by_offset(const struct btf
*btf
, u32 offset
);
147 struct btf
*btf_parse_vmlinux(void);
148 struct btf
*bpf_prog_get_target_btf(const struct bpf_prog
*prog
);
150 static inline const struct btf_type
*btf_type_by_id(const struct btf
*btf
,
155 static inline const char *btf_name_by_offset(const struct btf
*btf
,