Skip to content

KFunc bpf_obj_new_impl

v6.2

Allocates an object.

Definition

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 rewritten by the verifier, no need for BPF program to set it.

Returns

A pointer to an object of the type corresponding to the passed in local_type_id, or NULL on failure.

void *bpf_obj_new_impl(u64 local_type_id__k, void *meta__ign)

Note

This kfunc returns a pointer to a refcounted object. The verifier will then ensure that the pointer to the object is eventually released using a release kfunc, or transferred to a map using a referenced kptr (by invoking bpf_kptr_xchg). If not, the verifier fails the loading of the BPF program until no lingering references remain in all possible explored states of the program.

Note

The pointer returned by the kfunc may be NULL. Hence, it forces the user to do a NULL check on the pointer returned from the kfunc before making use of it (dereferencing or passing to another helper).

Usage

Docs could be improved

This part of the docs is incomplete, contributions are very welcome

Program types

The following program types can make use of this kfunc:

Example

Docs could be improved

This part of the docs is incomplete, contributions are very welcome