btf.h (9fb424c4c29df0d7f39b686d4037cbc7e06ed7b5) | btf.h (aaf6886d9b53d34f0a3d2f577ddc1224026d12ab) |
---|---|
1/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2/* Copyright (c) 2018 Facebook */ 3/*! \file */ 4 5#ifndef __LIBBPF_BTF_H 6#define __LIBBPF_BTF_H 7 8#include <stdarg.h> --- 106 unchanged lines hidden (view full) --- 115LIBBPF_API struct btf *btf__parse_raw_split(const char *path, struct btf *base_btf); 116 117LIBBPF_API struct btf *btf__load_vmlinux_btf(void); 118LIBBPF_API struct btf *btf__load_module_btf(const char *module_name, struct btf *vmlinux_btf); 119LIBBPF_API struct btf *libbpf_find_kernel_btf(void); 120 121LIBBPF_API struct btf *btf__load_from_kernel_by_id(__u32 id); 122LIBBPF_API struct btf *btf__load_from_kernel_by_id_split(__u32 id, struct btf *base_btf); | 1/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2/* Copyright (c) 2018 Facebook */ 3/*! \file */ 4 5#ifndef __LIBBPF_BTF_H 6#define __LIBBPF_BTF_H 7 8#include <stdarg.h> --- 106 unchanged lines hidden (view full) --- 115LIBBPF_API struct btf *btf__parse_raw_split(const char *path, struct btf *base_btf); 116 117LIBBPF_API struct btf *btf__load_vmlinux_btf(void); 118LIBBPF_API struct btf *btf__load_module_btf(const char *module_name, struct btf *vmlinux_btf); 119LIBBPF_API struct btf *libbpf_find_kernel_btf(void); 120 121LIBBPF_API struct btf *btf__load_from_kernel_by_id(__u32 id); 122LIBBPF_API struct btf *btf__load_from_kernel_by_id_split(__u32 id, struct btf *base_btf); |
123LIBBPF_DEPRECATED_SINCE(0, 6, "use btf__load_from_kernel_by_id instead") 124LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf); | |
125 | 123 |
126LIBBPF_DEPRECATED_SINCE(0, 6, "intended for internal libbpf use only") 127LIBBPF_API int btf__finalize_data(struct bpf_object *obj, struct btf *btf); 128LIBBPF_DEPRECATED_SINCE(0, 6, "use btf__load_into_kernel instead") 129LIBBPF_API int btf__load(struct btf *btf); | |
130LIBBPF_API int btf__load_into_kernel(struct btf *btf); 131LIBBPF_API __s32 btf__find_by_name(const struct btf *btf, 132 const char *type_name); 133LIBBPF_API __s32 btf__find_by_name_kind(const struct btf *btf, 134 const char *type_name, __u32 kind); | 124LIBBPF_API int btf__load_into_kernel(struct btf *btf); 125LIBBPF_API __s32 btf__find_by_name(const struct btf *btf, 126 const char *type_name); 127LIBBPF_API __s32 btf__find_by_name_kind(const struct btf *btf, 128 const char *type_name, __u32 kind); |
135LIBBPF_DEPRECATED_SINCE(0, 7, "use btf__type_cnt() instead; note that btf__get_nr_types() == btf__type_cnt() - 1") 136LIBBPF_API __u32 btf__get_nr_types(const struct btf *btf); | |
137LIBBPF_API __u32 btf__type_cnt(const struct btf *btf); 138LIBBPF_API const struct btf *btf__base_btf(const struct btf *btf); 139LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf, 140 __u32 id); 141LIBBPF_API size_t btf__pointer_size(const struct btf *btf); 142LIBBPF_API int btf__set_pointer_size(struct btf *btf, size_t ptr_sz); 143LIBBPF_API enum btf_endianness btf__endianness(const struct btf *btf); 144LIBBPF_API int btf__set_endianness(struct btf *btf, enum btf_endianness endian); 145LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id); 146LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id); 147LIBBPF_API int btf__align_of(const struct btf *btf, __u32 id); 148LIBBPF_API int btf__fd(const struct btf *btf); 149LIBBPF_API void btf__set_fd(struct btf *btf, int fd); 150LIBBPF_API const void *btf__raw_data(const struct btf *btf, __u32 *size); 151LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset); 152LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset); | 129LIBBPF_API __u32 btf__type_cnt(const struct btf *btf); 130LIBBPF_API const struct btf *btf__base_btf(const struct btf *btf); 131LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf, 132 __u32 id); 133LIBBPF_API size_t btf__pointer_size(const struct btf *btf); 134LIBBPF_API int btf__set_pointer_size(struct btf *btf, size_t ptr_sz); 135LIBBPF_API enum btf_endianness btf__endianness(const struct btf *btf); 136LIBBPF_API int btf__set_endianness(struct btf *btf, enum btf_endianness endian); 137LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id); 138LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id); 139LIBBPF_API int btf__align_of(const struct btf *btf, __u32 id); 140LIBBPF_API int btf__fd(const struct btf *btf); 141LIBBPF_API void btf__set_fd(struct btf *btf, int fd); 142LIBBPF_API const void *btf__raw_data(const struct btf *btf, __u32 *size); 143LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset); 144LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset); |
153LIBBPF_DEPRECATED_SINCE(0, 7, "this API is not necessary when BTF-defined maps are used") 154LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, 155 __u32 expected_key_size, 156 __u32 expected_value_size, 157 __u32 *key_type_id, __u32 *value_type_id); | |
158 159LIBBPF_API struct btf_ext *btf_ext__new(const __u8 *data, __u32 size); 160LIBBPF_API void btf_ext__free(struct btf_ext *btf_ext); 161LIBBPF_API const void *btf_ext__raw_data(const struct btf_ext *btf_ext, __u32 *size); | 145 146LIBBPF_API struct btf_ext *btf_ext__new(const __u8 *data, __u32 size); 147LIBBPF_API void btf_ext__free(struct btf_ext *btf_ext); 148LIBBPF_API const void *btf_ext__raw_data(const struct btf_ext *btf_ext, __u32 *size); |
162LIBBPF_API LIBBPF_DEPRECATED("btf_ext__reloc_func_info was never meant as a public API and has wrong assumptions embedded in it; it will be removed in the future libbpf versions") 163int btf_ext__reloc_func_info(const struct btf *btf, 164 const struct btf_ext *btf_ext, 165 const char *sec_name, __u32 insns_cnt, 166 void **func_info, __u32 *cnt); 167LIBBPF_API LIBBPF_DEPRECATED("btf_ext__reloc_line_info was never meant as a public API and has wrong assumptions embedded in it; it will be removed in the future libbpf versions") 168int btf_ext__reloc_line_info(const struct btf *btf, 169 const struct btf_ext *btf_ext, 170 const char *sec_name, __u32 insns_cnt, 171 void **line_info, __u32 *cnt); 172LIBBPF_API LIBBPF_DEPRECATED("btf_ext__reloc_func_info is deprecated; write custom func_info parsing to fetch rec_size") 173__u32 btf_ext__func_info_rec_size(const struct btf_ext *btf_ext); 174LIBBPF_API LIBBPF_DEPRECATED("btf_ext__reloc_line_info is deprecated; write custom line_info parsing to fetch rec_size") 175__u32 btf_ext__line_info_rec_size(const struct btf_ext *btf_ext); | |
176 177LIBBPF_API int btf__find_str(struct btf *btf, const char *s); 178LIBBPF_API int btf__add_str(struct btf *btf, const char *s); 179LIBBPF_API int btf__add_type(struct btf *btf, const struct btf *src_btf, 180 const struct btf_type *src_type); 181/** 182 * @brief **btf__add_btf()** appends all the BTF types from *src_btf* into *btf* 183 * @param btf BTF object which all the BTF types and strings are added to --- 70 unchanged lines hidden (view full) --- 254 /* force hash collisions (used for testing) */ 255 bool force_collisions; 256 size_t :0; 257}; 258#define btf_dedup_opts__last_field force_collisions 259 260LIBBPF_API int btf__dedup(struct btf *btf, const struct btf_dedup_opts *opts); 261 | 149 150LIBBPF_API int btf__find_str(struct btf *btf, const char *s); 151LIBBPF_API int btf__add_str(struct btf *btf, const char *s); 152LIBBPF_API int btf__add_type(struct btf *btf, const struct btf *src_btf, 153 const struct btf_type *src_type); 154/** 155 * @brief **btf__add_btf()** appends all the BTF types from *src_btf* into *btf* 156 * @param btf BTF object which all the BTF types and strings are added to --- 70 unchanged lines hidden (view full) --- 227 /* force hash collisions (used for testing) */ 228 bool force_collisions; 229 size_t :0; 230}; 231#define btf_dedup_opts__last_field force_collisions 232 233LIBBPF_API int btf__dedup(struct btf *btf, const struct btf_dedup_opts *opts); 234 |
262LIBBPF_API int btf__dedup_v0_6_0(struct btf *btf, const struct btf_dedup_opts *opts); 263 264LIBBPF_DEPRECATED_SINCE(0, 7, "use btf__dedup() instead") 265LIBBPF_API int btf__dedup_deprecated(struct btf *btf, struct btf_ext *btf_ext, const void *opts); 266#define btf__dedup(...) ___libbpf_overload(___btf_dedup, __VA_ARGS__) 267#define ___btf_dedup3(btf, btf_ext, opts) btf__dedup_deprecated(btf, btf_ext, opts) 268#define ___btf_dedup2(btf, opts) btf__dedup(btf, opts) 269 | |
270struct btf_dump; 271 272struct btf_dump_opts { | 235struct btf_dump; 236 237struct btf_dump_opts { |
273 union { 274 size_t sz; 275 void *ctx; /* DEPRECATED: will be gone in v1.0 */ 276 }; | 238 size_t sz; |
277}; | 239}; |
240#define btf_dump_opts__last_field sz |
|
278 279typedef void (*btf_dump_printf_fn_t)(void *ctx, const char *fmt, va_list args); 280 281LIBBPF_API struct btf_dump *btf_dump__new(const struct btf *btf, 282 btf_dump_printf_fn_t printf_fn, 283 void *ctx, 284 const struct btf_dump_opts *opts); 285 | 241 242typedef void (*btf_dump_printf_fn_t)(void *ctx, const char *fmt, va_list args); 243 244LIBBPF_API struct btf_dump *btf_dump__new(const struct btf *btf, 245 btf_dump_printf_fn_t printf_fn, 246 void *ctx, 247 const struct btf_dump_opts *opts); 248 |
286LIBBPF_API struct btf_dump *btf_dump__new_v0_6_0(const struct btf *btf, 287 btf_dump_printf_fn_t printf_fn, 288 void *ctx, 289 const struct btf_dump_opts *opts); 290 291LIBBPF_API struct btf_dump *btf_dump__new_deprecated(const struct btf *btf, 292 const struct btf_ext *btf_ext, 293 const struct btf_dump_opts *opts, 294 btf_dump_printf_fn_t printf_fn); 295 296/* Choose either btf_dump__new() or btf_dump__new_deprecated() based on the 297 * type of 4th argument. If it's btf_dump's print callback, use deprecated 298 * API; otherwise, choose the new btf_dump__new(). ___libbpf_override() 299 * doesn't work here because both variants have 4 input arguments. 300 * 301 * (void *) casts are necessary to avoid compilation warnings about type 302 * mismatches, because even though __builtin_choose_expr() only ever evaluates 303 * one side the other side still has to satisfy type constraints (this is 304 * compiler implementation limitation which might be lifted eventually, 305 * according to the documentation). So passing struct btf_ext in place of 306 * btf_dump_printf_fn_t would be generating compilation warning. Casting to 307 * void * avoids this issue. 308 * 309 * Also, two type compatibility checks for a function and function pointer are 310 * required because passing function reference into btf_dump__new() as 311 * btf_dump__new(..., my_callback, ...) and as btf_dump__new(..., 312 * &my_callback, ...) (not explicit ampersand in the latter case) actually 313 * differs as far as __builtin_types_compatible_p() is concerned. Thus two 314 * checks are combined to detect callback argument. 315 * 316 * The rest works just like in case of ___libbpf_override() usage with symbol 317 * versioning. 318 * 319 * C++ compilers don't support __builtin_types_compatible_p(), so at least 320 * don't screw up compilation for them and let C++ users pick btf_dump__new 321 * vs btf_dump__new_deprecated explicitly. 322 */ 323#ifndef __cplusplus 324#define btf_dump__new(a1, a2, a3, a4) __builtin_choose_expr( \ 325 __builtin_types_compatible_p(typeof(a4), btf_dump_printf_fn_t) || \ 326 __builtin_types_compatible_p(typeof(a4), void(void *, const char *, va_list)), \ 327 btf_dump__new_deprecated((void *)a1, (void *)a2, (void *)a3, (void *)a4), \ 328 btf_dump__new((void *)a1, (void *)a2, (void *)a3, (void *)a4)) 329#endif 330 | |
331LIBBPF_API void btf_dump__free(struct btf_dump *d); 332 333LIBBPF_API int btf_dump__dump_type(struct btf_dump *d, __u32 id); 334 335struct btf_dump_emit_type_decl_opts { 336 /* size of this struct, for forward/backward compatiblity */ 337 size_t sz; 338 /* optional field name for type declaration, e.g.: --- 297 unchanged lines hidden --- | 249LIBBPF_API void btf_dump__free(struct btf_dump *d); 250 251LIBBPF_API int btf_dump__dump_type(struct btf_dump *d, __u32 id); 252 253struct btf_dump_emit_type_decl_opts { 254 /* size of this struct, for forward/backward compatiblity */ 255 size_t sz; 256 /* optional field name for type declaration, e.g.: --- 297 unchanged lines hidden --- |