tools/lib/bpf/btf.h

Source file repositories/reference/linux-study-clean/tools/lib/bpf/btf.h

File Facts

System
Linux kernel
Corpus path
tools/lib/bpf/btf.h
Extension
.h
Size
23774 bytes
Lines
689
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct btf_new_opts {
	size_t sz;
	struct btf *base_btf;	/* optional base BTF */
	bool add_layout;	/* add BTF layout information */
	size_t:0;
};
#define btf_new_opts__last_field add_layout

/**
 * @brief **btf__new_empty_opts()** creates an unpopulated BTF object with
 * optional *base_btf* and BTF kind layout description if *add_layout*
 * is set
 * @return new BTF object instance which has to be eventually freed with
 * **btf__free()**
 *
 * On error, NULL is returned and the thread-local `errno` variable is
 * set to the error code.
 */
LIBBPF_API struct btf *btf__new_empty_opts(struct btf_new_opts *opts);

/**
 * @brief **btf__distill_base()** creates new versions of the split BTF
 * *src_btf* and its base BTF. The new base BTF will only contain the types
 * needed to improve robustness of the split BTF to small changes in base BTF.
 * When that split BTF is loaded against a (possibly changed) base, this
 * distilled base BTF will help update references to that (possibly changed)
 * base BTF.
 * @param src_btf source split BTF object
 * @param new_base_btf pointer to where the new base BTF object pointer will be stored
 * @param new_split_btf pointer to where the new split BTF object pointer will be stored
 * @return 0 on success; negative error code, otherwise
 *
 * Both the new split and its associated new base BTF must be freed by
 * the caller.
 *
 * If successful, 0 is returned and **new_base_btf** and **new_split_btf**
 * will point at new base/split BTF. Both the new split and its associated
 * new base BTF must be freed by the caller.
 *
 * A negative value is returned on error and the thread-local `errno` variable
 * is set to the error code as well.
 */
LIBBPF_API int btf__distill_base(const struct btf *src_btf, struct btf **new_base_btf,
				 struct btf **new_split_btf);

LIBBPF_API struct btf *btf__parse(const char *path, struct btf_ext **btf_ext);
LIBBPF_API struct btf *btf__parse_split(const char *path, struct btf *base_btf);
LIBBPF_API struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext);
LIBBPF_API struct btf *btf__parse_elf_split(const char *path, struct btf *base_btf);
LIBBPF_API struct btf *btf__parse_raw(const char *path);
LIBBPF_API struct btf *btf__parse_raw_split(const char *path, struct btf *base_btf);

LIBBPF_API struct btf *btf__load_vmlinux_btf(void);
LIBBPF_API struct btf *btf__load_module_btf(const char *module_name, struct btf *vmlinux_btf);

LIBBPF_API struct btf *btf__load_from_kernel_by_id(__u32 id);
LIBBPF_API struct btf *btf__load_from_kernel_by_id_split(__u32 id, struct btf *base_btf);

LIBBPF_API int btf__load_into_kernel(struct btf *btf);
LIBBPF_API __s32 btf__find_by_name(const struct btf *btf,
				   const char *type_name);
LIBBPF_API __s32 btf__find_by_name_kind(const struct btf *btf,
					const char *type_name, __u32 kind);
LIBBPF_API __u32 btf__type_cnt(const struct btf *btf);
LIBBPF_API const struct btf *btf__base_btf(const struct btf *btf);
LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
						  __u32 id);
LIBBPF_API size_t btf__pointer_size(const struct btf *btf);
LIBBPF_API int btf__set_pointer_size(struct btf *btf, size_t ptr_sz);
LIBBPF_API enum btf_endianness btf__endianness(const struct btf *btf);
LIBBPF_API int btf__set_endianness(struct btf *btf, enum btf_endianness endian);
LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id);
LIBBPF_API int btf__align_of(const struct btf *btf, __u32 id);
LIBBPF_API int btf__fd(const struct btf *btf);
LIBBPF_API void btf__set_fd(struct btf *btf, int fd);
LIBBPF_API const void *btf__raw_data(const struct btf *btf, __u32 *size);
LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset);

LIBBPF_API struct btf_ext *btf_ext__new(const __u8 *data, __u32 size);
LIBBPF_API void btf_ext__free(struct btf_ext *btf_ext);
LIBBPF_API const void *btf_ext__raw_data(const struct btf_ext *btf_ext, __u32 *size);
LIBBPF_API enum btf_endianness btf_ext__endianness(const struct btf_ext *btf_ext);
LIBBPF_API int btf_ext__set_endianness(struct btf_ext *btf_ext,
				       enum btf_endianness endian);

LIBBPF_API int btf__find_str(struct btf *btf, const char *s);
LIBBPF_API int btf__add_str(struct btf *btf, const char *s);
LIBBPF_API int btf__add_type(struct btf *btf, const struct btf *src_btf,

Annotation

Implementation Notes