2018-10-06 06:40:00 +07:00
|
|
|
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
|
2018-04-19 05:56:05 +07:00
|
|
|
/* Copyright (c) 2018 Facebook */
|
|
|
|
|
2018-10-04 05:26:42 +07:00
|
|
|
#ifndef __LIBBPF_BTF_H
|
|
|
|
#define __LIBBPF_BTF_H
|
2018-04-19 05:56:05 +07:00
|
|
|
|
2018-07-24 22:40:21 +07:00
|
|
|
#include <linux/types.h>
|
2018-04-19 05:56:05 +07:00
|
|
|
|
2018-11-22 00:29:44 +07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-10-16 12:50:34 +07:00
|
|
|
#ifndef LIBBPF_API
|
|
|
|
#define LIBBPF_API __attribute__((visibility("default")))
|
|
|
|
#endif
|
|
|
|
|
2018-04-19 05:56:05 +07:00
|
|
|
#define BTF_ELF_SEC ".BTF"
|
2018-11-20 06:29:16 +07:00
|
|
|
#define BTF_EXT_ELF_SEC ".BTF.ext"
|
2018-04-19 05:56:05 +07:00
|
|
|
|
|
|
|
struct btf;
|
2018-11-20 06:29:16 +07:00
|
|
|
struct btf_ext;
|
2018-07-24 22:40:22 +07:00
|
|
|
struct btf_type;
|
2018-04-19 05:56:05 +07:00
|
|
|
|
2018-11-20 06:29:16 +07:00
|
|
|
/*
|
|
|
|
* The .BTF.ext ELF section layout defined as
|
|
|
|
* struct btf_ext_header
|
|
|
|
* func_info subsection
|
|
|
|
*
|
|
|
|
* The func_info subsection layout:
|
|
|
|
* record size for struct bpf_func_info in the func_info subsection
|
|
|
|
* struct btf_sec_func_info for section #1
|
|
|
|
* a list of bpf_func_info records for section #1
|
|
|
|
* where struct bpf_func_info mimics one in include/uapi/linux/bpf.h
|
|
|
|
* but may not be identical
|
|
|
|
* struct btf_sec_func_info for section #2
|
|
|
|
* a list of bpf_func_info records for section #2
|
|
|
|
* ......
|
|
|
|
*
|
|
|
|
* Note that the bpf_func_info record size in .BTF.ext may not
|
|
|
|
* be the same as the one defined in include/uapi/linux/bpf.h.
|
|
|
|
* The loader should ensure that record_size meets minimum
|
|
|
|
* requirement and pass the record as is to the kernel. The
|
|
|
|
* kernel will handle the func_info properly based on its contents.
|
|
|
|
*/
|
|
|
|
struct btf_ext_header {
|
|
|
|
__u16 magic;
|
|
|
|
__u8 version;
|
|
|
|
__u8 flags;
|
|
|
|
__u32 hdr_len;
|
|
|
|
|
|
|
|
/* All offsets are in bytes relative to the end of this header */
|
|
|
|
__u32 func_info_off;
|
|
|
|
__u32 func_info_len;
|
2018-12-08 07:42:31 +07:00
|
|
|
__u32 line_info_off;
|
|
|
|
__u32 line_info_len;
|
2018-11-20 06:29:16 +07:00
|
|
|
};
|
|
|
|
|
2018-10-16 12:50:34 +07:00
|
|
|
LIBBPF_API void btf__free(struct btf *btf);
|
2019-02-02 07:14:14 +07:00
|
|
|
LIBBPF_API struct btf *btf__new(__u8 *data, __u32 size);
|
2019-02-09 02:19:36 +07:00
|
|
|
LIBBPF_API int btf__load(struct btf *btf);
|
2018-10-16 12:50:34 +07:00
|
|
|
LIBBPF_API __s32 btf__find_by_name(const struct btf *btf,
|
|
|
|
const char *type_name);
|
2019-02-05 08:29:46 +07:00
|
|
|
LIBBPF_API __u32 btf__get_nr_types(const struct btf *btf);
|
2018-10-16 12:50:34 +07:00
|
|
|
LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
|
|
|
|
__u32 id);
|
|
|
|
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__fd(const struct btf *btf);
|
2019-02-09 02:19:37 +07:00
|
|
|
LIBBPF_API const void *btf__get_raw_data(const struct btf *btf, __u32 *size);
|
2019-02-05 08:29:46 +07:00
|
|
|
LIBBPF_API void btf__get_strings(const struct btf *btf, const char **strings,
|
|
|
|
__u32 *str_len);
|
2018-10-16 12:50:34 +07:00
|
|
|
LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
|
2018-11-24 07:44:32 +07:00
|
|
|
LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf);
|
2019-02-06 02:48:22 +07:00
|
|
|
LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
|
2019-02-05 02:00:58 +07:00
|
|
|
__u32 expected_key_size,
|
|
|
|
__u32 expected_value_size,
|
|
|
|
__u32 *key_type_id, __u32 *value_type_id);
|
2018-04-19 05:56:05 +07:00
|
|
|
|
2019-02-05 02:00:57 +07:00
|
|
|
LIBBPF_API struct btf_ext *btf_ext__new(__u8 *data, __u32 size);
|
|
|
|
LIBBPF_API void btf_ext__free(struct btf_ext *btf_ext);
|
2019-02-09 02:19:38 +07:00
|
|
|
LIBBPF_API const void *btf_ext__get_raw_data(const struct btf_ext* btf_ext,
|
|
|
|
__u32 *size);
|
2019-02-05 02:00:57 +07:00
|
|
|
LIBBPF_API int btf_ext__reloc_func_info(const struct btf *btf,
|
|
|
|
const struct btf_ext *btf_ext,
|
|
|
|
const char *sec_name, __u32 insns_cnt,
|
|
|
|
void **func_info, __u32 *cnt);
|
|
|
|
LIBBPF_API int btf_ext__reloc_line_info(const struct btf *btf,
|
|
|
|
const struct btf_ext *btf_ext,
|
|
|
|
const char *sec_name, __u32 insns_cnt,
|
|
|
|
void **line_info, __u32 *cnt);
|
|
|
|
LIBBPF_API __u32 btf_ext__func_info_rec_size(const struct btf_ext *btf_ext);
|
|
|
|
LIBBPF_API __u32 btf_ext__line_info_rec_size(const struct btf_ext *btf_ext);
|
2018-11-20 06:29:16 +07:00
|
|
|
|
2019-02-05 08:29:45 +07:00
|
|
|
struct btf_dedup_opts {
|
|
|
|
bool dont_resolve_fwds;
|
|
|
|
};
|
|
|
|
|
|
|
|
LIBBPF_API int btf__dedup(struct btf *btf, struct btf_ext *btf_ext,
|
|
|
|
const struct btf_dedup_opts *opts);
|
|
|
|
|
2018-11-22 00:29:44 +07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
2018-10-04 05:26:42 +07:00
|
|
|
#endif /* __LIBBPF_BTF_H */
|