mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Introduce bpf_obj_drop, which is the kfunc used to free allocated objects (allocated using bpf_obj_new). Pairing with bpf_obj_new, it implicitly destructs the fields part of object automatically without user intervention. Just like the previous patch, btf_struct_meta that is needed to free up the special fields is passed as a hidden argument to the kfunc. For the user, a convenience macro hides over the kernel side kfunc which is named bpf_obj_drop_impl. Continuing the previous example: void prog(void) { struct foo *f; f = bpf_obj_new(typeof(*f)); if (!f) return; bpf_obj_drop(f); } Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20221118015614.2013203-15-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
38 lines
1.2 KiB
C
38 lines
1.2 KiB
C
#ifndef __BPF_EXPERIMENTAL__
|
|
#define __BPF_EXPERIMENTAL__
|
|
|
|
#include <vmlinux.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_core_read.h>
|
|
|
|
/* Description
|
|
* Allocates an object of the type represented by 'local_type_id' in
|
|
* program BTF. User may use the bpf_core_type_id_local macro to pass the
|
|
* type ID of a struct in program BTF.
|
|
*
|
|
* The 'local_type_id' parameter must be a known constant.
|
|
* The 'meta' parameter is a hidden argument that is ignored.
|
|
* Returns
|
|
* A pointer to an object of the type corresponding to the passed in
|
|
* 'local_type_id', or NULL on failure.
|
|
*/
|
|
extern void *bpf_obj_new_impl(__u64 local_type_id, void *meta) __ksym;
|
|
|
|
/* Convenience macro to wrap over bpf_obj_new_impl */
|
|
#define bpf_obj_new(type) ((type *)bpf_obj_new_impl(bpf_core_type_id_local(type), NULL))
|
|
|
|
/* Description
|
|
* Free an allocated object. All fields of the object that require
|
|
* destruction will be destructed before the storage is freed.
|
|
*
|
|
* The 'meta' parameter is a hidden argument that is ignored.
|
|
* Returns
|
|
* Void.
|
|
*/
|
|
extern void bpf_obj_drop_impl(void *kptr, void *meta) __ksym;
|
|
|
|
/* Convenience macro to wrap over bpf_obj_drop_impl */
|
|
#define bpf_obj_drop(kptr) bpf_obj_drop_impl(kptr, NULL)
|
|
|
|
#endif
|