1 #ifndef __BPF_EXPERIMENTAL__
2 #define __BPF_EXPERIMENTAL__
5 #include <bpf/bpf_tracing.h>
6 #include <bpf/bpf_helpers.h>
7 #include <bpf/bpf_core_read.h>
9 #define __contains(name, node) __attribute__((btf_decl_tag("contains:" #name ":" #node)))
12 * Allocates an object of the type represented by 'local_type_id' in
13 * program BTF. User may use the bpf_core_type_id_local macro to pass the
14 * type ID of a struct in program BTF.
16 * The 'local_type_id' parameter must be a known constant.
17 * The 'meta' parameter is rewritten by the verifier, no need for BPF
20 * A pointer to an object of the type corresponding to the passed in
21 * 'local_type_id', or NULL on failure.
23 extern void *bpf_obj_new_impl(__u64 local_type_id, void *meta) __ksym;
25 /* Convenience macro to wrap over bpf_obj_new_impl */
26 #define bpf_obj_new(type) ((type *)bpf_obj_new_impl(bpf_core_type_id_local(type), NULL))
29 * Free an allocated object. All fields of the object that require
30 * destruction will be destructed before the storage is freed.
32 * The 'meta' parameter is rewritten by the verifier, no need for BPF
37 extern void bpf_obj_drop_impl(void *kptr, void *meta) __ksym;
39 /* Convenience macro to wrap over bpf_obj_drop_impl */
40 #define bpf_obj_drop(kptr) bpf_obj_drop_impl(kptr, NULL)
43 * Increment the refcount on a refcounted local kptr, turning the
44 * non-owning reference input into an owning reference in the process.
46 * The 'meta' parameter is rewritten by the verifier, no need for BPF
49 * An owning reference to the object pointed to by 'kptr'
51 extern void *bpf_refcount_acquire_impl(void *kptr, void *meta) __ksym;
53 /* Convenience macro to wrap over bpf_refcount_acquire_impl */
54 #define bpf_refcount_acquire(kptr) bpf_refcount_acquire_impl(kptr, NULL)
57 * Add a new entry to the beginning of the BPF linked list.
59 * The 'meta' and 'off' parameters are rewritten by the verifier, no need
60 * for BPF programs to set them
62 * 0 if the node was successfully added
63 * -EINVAL if the node wasn't added because it's already in a list
65 extern int bpf_list_push_front_impl(struct bpf_list_head *head,
66 struct bpf_list_node *node,
67 void *meta, __u64 off) __ksym;
69 /* Convenience macro to wrap over bpf_list_push_front_impl */
70 #define bpf_list_push_front(head, node) bpf_list_push_front_impl(head, node, NULL, 0)
73 * Add a new entry to the end of the BPF linked list.
75 * The 'meta' and 'off' parameters are rewritten by the verifier, no need
76 * for BPF programs to set them
78 * 0 if the node was successfully added
79 * -EINVAL if the node wasn't added because it's already in a list
81 extern int bpf_list_push_back_impl(struct bpf_list_head *head,
82 struct bpf_list_node *node,
83 void *meta, __u64 off) __ksym;
85 /* Convenience macro to wrap over bpf_list_push_back_impl */
86 #define bpf_list_push_back(head, node) bpf_list_push_back_impl(head, node, NULL, 0)
89 * Remove the entry at the beginning of the BPF linked list.
91 * Pointer to bpf_list_node of deleted entry, or NULL if list is empty.
93 extern struct bpf_list_node *bpf_list_pop_front(struct bpf_list_head *head) __ksym;
96 * Remove the entry at the end of the BPF linked list.
98 * Pointer to bpf_list_node of deleted entry, or NULL if list is empty.
100 extern struct bpf_list_node *bpf_list_pop_back(struct bpf_list_head *head) __ksym;
103 * Remove 'node' from rbtree with root 'root'
105 * Pointer to the removed node, or NULL if 'root' didn't contain 'node'
107 extern struct bpf_rb_node *bpf_rbtree_remove(struct bpf_rb_root *root,
108 struct bpf_rb_node *node) __ksym;
111 * Add 'node' to rbtree with root 'root' using comparator 'less'
113 * The 'meta' and 'off' parameters are rewritten by the verifier, no need
114 * for BPF programs to set them
116 * 0 if the node was successfully added
117 * -EINVAL if the node wasn't added because it's already in a tree
119 extern int bpf_rbtree_add_impl(struct bpf_rb_root *root, struct bpf_rb_node *node,
120 bool (less)(struct bpf_rb_node *a, const struct bpf_rb_node *b),
121 void *meta, __u64 off) __ksym;
123 /* Convenience macro to wrap over bpf_rbtree_add_impl */
124 #define bpf_rbtree_add(head, node, less) bpf_rbtree_add_impl(head, node, less, NULL, 0)
127 * Return the first (leftmost) node in input tree
129 * Pointer to the node, which is _not_ removed from the tree. If the tree
130 * contains no nodes, returns NULL.
132 extern struct bpf_rb_node *bpf_rbtree_first(struct bpf_rb_root *root) __ksym;