Skip to content

Libbpf userspace function bpf_btf_get_fd_by_id_opts

1.1.0

Low level wrapper around the BPF_BTF_GET_FD_BY_ID syscall command.

Definition

int bpf_btf_get_fd_by_id_opts(__u32 id, const struct bpf_get_fd_by_id_opts *opts);

Parameters

  • id: BTF object ID
  • opts: options for configuring the file descriptor retrieval

Return

>0, a file descriptor for the BTF object; negative error code, otherwise

struct bpf_get_fd_by_id_opts

struct bpf_get_fd_by_id_opts {
    size_t sz; /* size of this struct for forward/backward compatibility */
    __u32 open_flags; /* permissions requested for the operation on fd */
    size_t :0;
};

open_flags

1.1.0

Usage

This function returns the file descriptor of the BTF object with the given id. This causes the current process to hold a reference to the BTF object, preventing the kernel from unloading it. The file descriptor should be closed with close when it is no longer needed.

Example

Docs could be improved

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