]> asedeno.scripts.mit.edu Git - linux.git/blob - include/linux/btf.h
kernel.h: update comment about simple_strto<foo>() functions
[linux.git] / include / linux / btf.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018 Facebook */
3
4 #ifndef _LINUX_BTF_H
5 #define _LINUX_BTF_H 1
6
7 #include <linux/types.h>
8 #include <uapi/linux/btf.h>
9
10 struct btf;
11 struct btf_member;
12 struct btf_type;
13 union bpf_attr;
14
15 extern const struct file_operations btf_fops;
16
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.
25  *
26  * For example:
27  * In describing "const void *",  type_id is "const" and "const"
28  * refers to "void *".  The return type will be "void *".
29  *
30  * If type_id is a simple "int", then return type will be "int".
31  *
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
40  *         has size info.
41  *         *type_id and *ret_size will not be changed in the
42  *         NULL return case.
43  */
44 const struct btf_type *btf_type_id_size(const struct btf *btf,
45                                         u32 *type_id,
46                                         u32 *ret_size);
47 void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj,
48                        struct seq_file *m);
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);
56
57 static inline bool btf_type_is_ptr(const struct btf_type *t)
58 {
59         return BTF_INFO_KIND(t->info) == BTF_KIND_PTR;
60 }
61
62 static inline bool btf_type_is_int(const struct btf_type *t)
63 {
64         return BTF_INFO_KIND(t->info) == BTF_KIND_INT;
65 }
66
67 static inline bool btf_type_is_enum(const struct btf_type *t)
68 {
69         return BTF_INFO_KIND(t->info) == BTF_KIND_ENUM;
70 }
71
72 static inline bool btf_type_is_typedef(const struct btf_type *t)
73 {
74         return BTF_INFO_KIND(t->info) == BTF_KIND_TYPEDEF;
75 }
76
77 static inline bool btf_type_is_func(const struct btf_type *t)
78 {
79         return BTF_INFO_KIND(t->info) == BTF_KIND_FUNC;
80 }
81
82 static inline bool btf_type_is_func_proto(const struct btf_type *t)
83 {
84         return BTF_INFO_KIND(t->info) == BTF_KIND_FUNC_PROTO;
85 }
86
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);
92 #else
93 static inline const struct btf_type *btf_type_by_id(const struct btf *btf,
94                                                     u32 type_id)
95 {
96         return NULL;
97 }
98 static inline const char *btf_name_by_offset(const struct btf *btf,
99                                              u32 offset)
100 {
101         return NULL;
102 }
103 #endif
104
105 #endif