162306a36Sopenharmony_ci#ifndef __BPF_EXPERIMENTAL__
262306a36Sopenharmony_ci#define __BPF_EXPERIMENTAL__
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#include <vmlinux.h>
562306a36Sopenharmony_ci#include <bpf/bpf_tracing.h>
662306a36Sopenharmony_ci#include <bpf/bpf_helpers.h>
762306a36Sopenharmony_ci#include <bpf/bpf_core_read.h>
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#define __contains(name, node) __attribute__((btf_decl_tag("contains:" #name ":" #node)))
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/* Description
1262306a36Sopenharmony_ci *	Allocates an object of the type represented by 'local_type_id' in
1362306a36Sopenharmony_ci *	program BTF. User may use the bpf_core_type_id_local macro to pass the
1462306a36Sopenharmony_ci *	type ID of a struct in program BTF.
1562306a36Sopenharmony_ci *
1662306a36Sopenharmony_ci *	The 'local_type_id' parameter must be a known constant.
1762306a36Sopenharmony_ci *	The 'meta' parameter is rewritten by the verifier, no need for BPF
1862306a36Sopenharmony_ci *	program to set it.
1962306a36Sopenharmony_ci * Returns
2062306a36Sopenharmony_ci *	A pointer to an object of the type corresponding to the passed in
2162306a36Sopenharmony_ci *	'local_type_id', or NULL on failure.
2262306a36Sopenharmony_ci */
2362306a36Sopenharmony_ciextern void *bpf_obj_new_impl(__u64 local_type_id, void *meta) __ksym;
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/* Convenience macro to wrap over bpf_obj_new_impl */
2662306a36Sopenharmony_ci#define bpf_obj_new(type) ((type *)bpf_obj_new_impl(bpf_core_type_id_local(type), NULL))
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/* Description
2962306a36Sopenharmony_ci *	Free an allocated object. All fields of the object that require
3062306a36Sopenharmony_ci *	destruction will be destructed before the storage is freed.
3162306a36Sopenharmony_ci *
3262306a36Sopenharmony_ci *	The 'meta' parameter is rewritten by the verifier, no need for BPF
3362306a36Sopenharmony_ci *	program to set it.
3462306a36Sopenharmony_ci * Returns
3562306a36Sopenharmony_ci *	Void.
3662306a36Sopenharmony_ci */
3762306a36Sopenharmony_ciextern void bpf_obj_drop_impl(void *kptr, void *meta) __ksym;
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/* Convenience macro to wrap over bpf_obj_drop_impl */
4062306a36Sopenharmony_ci#define bpf_obj_drop(kptr) bpf_obj_drop_impl(kptr, NULL)
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* Description
4362306a36Sopenharmony_ci *	Increment the refcount on a refcounted local kptr, turning the
4462306a36Sopenharmony_ci *	non-owning reference input into an owning reference in the process.
4562306a36Sopenharmony_ci *
4662306a36Sopenharmony_ci *	The 'meta' parameter is rewritten by the verifier, no need for BPF
4762306a36Sopenharmony_ci *	program to set it.
4862306a36Sopenharmony_ci * Returns
4962306a36Sopenharmony_ci *	An owning reference to the object pointed to by 'kptr'
5062306a36Sopenharmony_ci */
5162306a36Sopenharmony_ciextern void *bpf_refcount_acquire_impl(void *kptr, void *meta) __ksym;
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci/* Convenience macro to wrap over bpf_refcount_acquire_impl */
5462306a36Sopenharmony_ci#define bpf_refcount_acquire(kptr) bpf_refcount_acquire_impl(kptr, NULL)
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci/* Description
5762306a36Sopenharmony_ci *	Add a new entry to the beginning of the BPF linked list.
5862306a36Sopenharmony_ci *
5962306a36Sopenharmony_ci *	The 'meta' and 'off' parameters are rewritten by the verifier, no need
6062306a36Sopenharmony_ci *	for BPF programs to set them
6162306a36Sopenharmony_ci * Returns
6262306a36Sopenharmony_ci *	0 if the node was successfully added
6362306a36Sopenharmony_ci *	-EINVAL if the node wasn't added because it's already in a list
6462306a36Sopenharmony_ci */
6562306a36Sopenharmony_ciextern int bpf_list_push_front_impl(struct bpf_list_head *head,
6662306a36Sopenharmony_ci				    struct bpf_list_node *node,
6762306a36Sopenharmony_ci				    void *meta, __u64 off) __ksym;
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci/* Convenience macro to wrap over bpf_list_push_front_impl */
7062306a36Sopenharmony_ci#define bpf_list_push_front(head, node) bpf_list_push_front_impl(head, node, NULL, 0)
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* Description
7362306a36Sopenharmony_ci *	Add a new entry to the end of the BPF linked list.
7462306a36Sopenharmony_ci *
7562306a36Sopenharmony_ci *	The 'meta' and 'off' parameters are rewritten by the verifier, no need
7662306a36Sopenharmony_ci *	for BPF programs to set them
7762306a36Sopenharmony_ci * Returns
7862306a36Sopenharmony_ci *	0 if the node was successfully added
7962306a36Sopenharmony_ci *	-EINVAL if the node wasn't added because it's already in a list
8062306a36Sopenharmony_ci */
8162306a36Sopenharmony_ciextern int bpf_list_push_back_impl(struct bpf_list_head *head,
8262306a36Sopenharmony_ci				   struct bpf_list_node *node,
8362306a36Sopenharmony_ci				   void *meta, __u64 off) __ksym;
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/* Convenience macro to wrap over bpf_list_push_back_impl */
8662306a36Sopenharmony_ci#define bpf_list_push_back(head, node) bpf_list_push_back_impl(head, node, NULL, 0)
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/* Description
8962306a36Sopenharmony_ci *	Remove the entry at the beginning of the BPF linked list.
9062306a36Sopenharmony_ci * Returns
9162306a36Sopenharmony_ci *	Pointer to bpf_list_node of deleted entry, or NULL if list is empty.
9262306a36Sopenharmony_ci */
9362306a36Sopenharmony_ciextern struct bpf_list_node *bpf_list_pop_front(struct bpf_list_head *head) __ksym;
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci/* Description
9662306a36Sopenharmony_ci *	Remove the entry at the end of the BPF linked list.
9762306a36Sopenharmony_ci * Returns
9862306a36Sopenharmony_ci *	Pointer to bpf_list_node of deleted entry, or NULL if list is empty.
9962306a36Sopenharmony_ci */
10062306a36Sopenharmony_ciextern struct bpf_list_node *bpf_list_pop_back(struct bpf_list_head *head) __ksym;
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci/* Description
10362306a36Sopenharmony_ci *	Remove 'node' from rbtree with root 'root'
10462306a36Sopenharmony_ci * Returns
10562306a36Sopenharmony_ci * 	Pointer to the removed node, or NULL if 'root' didn't contain 'node'
10662306a36Sopenharmony_ci */
10762306a36Sopenharmony_ciextern struct bpf_rb_node *bpf_rbtree_remove(struct bpf_rb_root *root,
10862306a36Sopenharmony_ci					     struct bpf_rb_node *node) __ksym;
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci/* Description
11162306a36Sopenharmony_ci *	Add 'node' to rbtree with root 'root' using comparator 'less'
11262306a36Sopenharmony_ci *
11362306a36Sopenharmony_ci *	The 'meta' and 'off' parameters are rewritten by the verifier, no need
11462306a36Sopenharmony_ci *	for BPF programs to set them
11562306a36Sopenharmony_ci * Returns
11662306a36Sopenharmony_ci *	0 if the node was successfully added
11762306a36Sopenharmony_ci *	-EINVAL if the node wasn't added because it's already in a tree
11862306a36Sopenharmony_ci */
11962306a36Sopenharmony_ciextern int bpf_rbtree_add_impl(struct bpf_rb_root *root, struct bpf_rb_node *node,
12062306a36Sopenharmony_ci			       bool (less)(struct bpf_rb_node *a, const struct bpf_rb_node *b),
12162306a36Sopenharmony_ci			       void *meta, __u64 off) __ksym;
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci/* Convenience macro to wrap over bpf_rbtree_add_impl */
12462306a36Sopenharmony_ci#define bpf_rbtree_add(head, node, less) bpf_rbtree_add_impl(head, node, less, NULL, 0)
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci/* Description
12762306a36Sopenharmony_ci *	Return the first (leftmost) node in input tree
12862306a36Sopenharmony_ci * Returns
12962306a36Sopenharmony_ci *	Pointer to the node, which is _not_ removed from the tree. If the tree
13062306a36Sopenharmony_ci *	contains no nodes, returns NULL.
13162306a36Sopenharmony_ci */
13262306a36Sopenharmony_ciextern struct bpf_rb_node *bpf_rbtree_first(struct bpf_rb_root *root) __ksym;
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci#endif
135