1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018 Facebook */
7 #include <linux/types.h>
8 #include <uapi/linux/btf.h>
15 extern const struct file_operations btf_fops;
17 void btf_put(struct btf *btf);
18 int btf_new_fd(const union bpf_attr *attr);
19 struct btf *btf_get_by_fd(int fd);
20 int btf_get_info_by_fd(const struct btf *btf,
21 const union bpf_attr *attr,
22 union bpf_attr __user *uattr);
23 /* Figure out the size of a type_id. If type_id is a modifier
24 * (e.g. const), it will be resolved to find out the type with size.
27 * In describing "const void *", type_id is "const" and "const"
28 * refers to "void *". The return type will be "void *".
30 * If type_id is a simple "int", then return type will be "int".
32 * @btf: struct btf object
33 * @type_id: Find out the size of type_id. The type_id of the return
34 * type is set to *type_id.
35 * @ret_size: It can be NULL. If not NULL, the size of the return
36 * type is set to *ret_size.
37 * Return: The btf_type (resolved to another type with size info if needed).
38 * NULL is returned if type_id itself does not have size info
39 * (e.g. void) or it cannot be resolved to another type that
41 * *type_id and *ret_size will not be changed in the
44 const struct btf_type *btf_type_id_size(const struct btf *btf,
47 void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj,
49 int btf_get_fd_by_id(u32 id);
50 u32 btf_id(const struct btf *btf);
51 bool btf_member_is_reg_int(const struct btf *btf, const struct btf_type *s,
52 const struct btf_member *m,
53 u32 expected_offset, u32 expected_size);
54 int btf_find_spin_lock(const struct btf *btf, const struct btf_type *t);
55 bool btf_type_is_void(const struct btf_type *t);
57 static inline bool btf_type_is_ptr(const struct btf_type *t)
59 return BTF_INFO_KIND(t->info) == BTF_KIND_PTR;
62 static inline bool btf_type_is_int(const struct btf_type *t)
64 return BTF_INFO_KIND(t->info) == BTF_KIND_INT;
67 static inline bool btf_type_is_enum(const struct btf_type *t)
69 return BTF_INFO_KIND(t->info) == BTF_KIND_ENUM;
72 static inline bool btf_type_is_typedef(const struct btf_type *t)
74 return BTF_INFO_KIND(t->info) == BTF_KIND_TYPEDEF;
77 static inline bool btf_type_is_func(const struct btf_type *t)
79 return BTF_INFO_KIND(t->info) == BTF_KIND_FUNC;
82 static inline bool btf_type_is_func_proto(const struct btf_type *t)
84 return BTF_INFO_KIND(t->info) == BTF_KIND_FUNC_PROTO;
87 #ifdef CONFIG_BPF_SYSCALL
88 const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id);
89 const char *btf_name_by_offset(const struct btf *btf, u32 offset);
90 struct btf *btf_parse_vmlinux(void);
91 struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog);
93 static inline const struct btf_type *btf_type_by_id(const struct btf *btf,
98 static inline const char *btf_name_by_offset(const struct btf *btf,