/linux/tools/testing/selftests/bpf/prog_tests/ |
H A D | linked_list.c | 249 static struct btf *init_btf(void) in init_btf() 252 struct btf *btf; in init_btf() local 254 btf = btf__new_empty(); in init_btf() 255 if (!ASSERT_OK_PTR(btf, "btf__new_empty")) in init_btf() 257 id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED); in init_btf() 260 lid = btf__add_struct(btf, "bpf_spin_lock", 4); in init_btf() 263 hid = btf__add_struct(btf, "bpf_list_head", 16); in init_btf() 266 nid = btf__add_struct(btf, "bpf_list_node", 24); in init_btf() 269 return btf; in init_btf() 271 btf__free(btf); in init_btf() [all …]
|
H A D | btf_dump.c | 26 static int btf_dump_all_types(const struct btf *btf, void *ctx) in btf_dump_all_types() argument 28 size_t type_cnt = btf__type_cnt(btf); in btf_dump_all_types() 32 d = btf_dump__new(btf, btf_dump_printf, ctx, NULL); in btf_dump_all_types() 51 struct btf *btf = NULL; in test_btf_dump_case() local 57 btf = btf__parse_elf(test_file, NULL); in test_btf_dump_case() 58 if (!ASSERT_OK_PTR(btf, "btf_parse_elf")) { in test_btf_dump_case() 59 err = -PTR_ERR(btf); in test_btf_dump_case() 60 btf = NULL; in test_btf_dump_case() 70 btf__set_pointer_size(btf, 8); in test_btf_dump_case() 72 CHECK(btf__pointer_size(btf) != 8, "ptr_sz", "exp %d, got %zu\n", in test_btf_dump_case() [all …]
|
H A D | btf_write.c | 7 static void gen_btf(struct btf *btf) in gen_btf() argument 17 str_off = btf__find_str(btf, "int"); in gen_btf() 20 str_off = btf__add_str(btf, "int"); in gen_btf() 23 str_off = btf__find_str(btf, "int"); in gen_btf() 27 id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED); in gen_btf() 30 t = btf__type_by_id(btf, 1); in gen_btf() 33 ASSERT_STREQ(btf__str_by_offset(btf, t->name_off), "int", "int_name"); in gen_btf() 38 ASSERT_STREQ(btf_type_raw_dump(btf, 1), in gen_btf() 42 id = btf__add_int(btf, "bad sz int", 7, 0); in gen_btf() 45 id = btf__add_int(btf, "bad enc int", 4, 123); in gen_btf() [all …]
|
H A D | btf_field_iter.c | 43 struct btf *btf = NULL; in test_btf_field_iter() local 46 btf = btf__new_empty(); in test_btf_field_iter() 47 if (!ASSERT_OK_PTR(btf, "empty_btf")) in test_btf_field_iter() 50 btf__add_int(btf, "int", 4, BTF_INT_SIGNED); /* [1] int */ in test_btf_field_iter() 51 btf__add_int(btf, "int64", 8, BTF_INT_SIGNED); /* [2] int64 */ in test_btf_field_iter() 52 btf__add_ptr(btf, 1); /* [3] int * */ in test_btf_field_iter() 53 btf__add_array(btf, 1, 2, 3); /* [4] int64[3] */ in test_btf_field_iter() 54 btf__add_struct(btf, "s1", 12); /* [5] struct s1 { */ in test_btf_field_iter() 55 btf__add_field(btf, "f1", 3, 0, 0); /* int *f1; */ in test_btf_field_iter() 56 btf__add_field(btf, "f2", 1, 0, 0); /* int f2; */ in test_btf_field_iter() [all …]
|
H A D | libbpf_str.c | 23 struct btf *btf; in test_libbpf_bpf_attach_type_str() local 28 btf = btf__parse("/sys/kernel/btf/vmlinux", NULL); in test_libbpf_bpf_attach_type_str() 29 if (!ASSERT_OK_PTR(btf, "btf_parse")) in test_libbpf_bpf_attach_type_str() 33 id = btf__find_by_name_kind(btf, "bpf_attach_type", BTF_KIND_ENUM); in test_libbpf_bpf_attach_type_str() 36 t = btf__type_by_id(btf, id); in test_libbpf_bpf_attach_type_str() 48 attach_type_name = btf__str_by_offset(btf, e->name_off); in test_libbpf_bpf_attach_type_str() 59 btf__free(btf); in test_libbpf_bpf_attach_type_str() 68 struct btf *btf; in test_libbpf_bpf_link_type_str() local 73 btf = btf__parse("/sys/kernel/btf/vmlinux", NULL); in test_libbpf_bpf_link_type_str() 74 if (!ASSERT_OK_PTR(btf, "btf_parse")) in test_libbpf_bpf_link_type_str() [all …]
|
H A D | libbpf_probes.c | 9 struct btf *btf; in test_libbpf_probe_prog_types() local 14 btf = btf__parse("/sys/kernel/btf/vmlinux", NULL); in test_libbpf_probe_prog_types() 15 if (!ASSERT_OK_PTR(btf, "btf_parse")) in test_libbpf_probe_prog_types() 19 id = btf__find_by_name_kind(btf, "bpf_prog_type", BTF_KIND_ENUM); in test_libbpf_probe_prog_types() 22 t = btf__type_by_id(btf, id); in test_libbpf_probe_prog_types() 27 const char *prog_type_name = btf__str_by_offset(btf, e->name_off); in test_libbpf_probe_prog_types() 44 btf__free(btf); in test_libbpf_probe_prog_types() 49 struct btf *btf; in test_libbpf_probe_map_types() local 54 btf = btf__parse("/sys/kernel/btf/vmlinux", NULL); in test_libbpf_probe_map_types() 55 if (!ASSERT_OK_PTR(btf, "btf_parse")) in test_libbpf_probe_map_types() [all …]
|
H A D | test_global_funcs.c | 26 static void check_ctx_arg_type(const struct btf *btf, const struct btf_param *p) in check_ctx_arg_type() argument 31 t = btf__type_by_id(btf, p->type); in check_ctx_arg_type() 35 s = btf_type_raw_dump(btf, t->type); in check_ctx_arg_type() 47 struct btf *btf = NULL; in subtest_ctx_arg_rewrite() local 50 struct btf *kern_btf = NULL; in subtest_ctx_arg_rewrite() 87 btf = btf__load_from_kernel_by_id(info.btf_id); in subtest_ctx_arg_rewrite() 88 if (!ASSERT_OK_PTR(btf, "obj_kern_btf")) in subtest_ctx_arg_rewrite() 99 fn_t = btf__type_by_id(btf, rec->type_id); in subtest_ctx_arg_rewrite() 104 proto_t = btf__type_by_id(btf, fn_t->type); in subtest_ctx_arg_rewrite() 108 name = btf__name_by_offset(btf, fn_t->name_off); in subtest_ctx_arg_rewrite() [all …]
|
H A D | btf_endian.c | 18 struct btf *btf = NULL, *swap_btf = NULL; in test_btf_endian() local 26 btf = btf__parse_elf("btf_dump_test_case_syntax.bpf.o", NULL); in test_btf_endian() 27 if (!ASSERT_OK_PTR(btf, "parse_native_btf")) in test_btf_endian() 30 ASSERT_EQ(btf__endianness(btf), endian, "endian"); in test_btf_endian() 31 btf__set_endianness(btf, swap_endian); in test_btf_endian() 32 ASSERT_EQ(btf__endianness(btf), swap_endian, "endian"); in test_btf_endian() 35 raw_data = btf__raw_data(btf, &raw_sz); in test_btf_endian() 45 ASSERT_EQ(btf__type_cnt(swap_btf), btf__type_cnt(btf), "nr_types"); in test_btf_endian() 71 var_id = btf__add_var(btf, "some_var", BTF_VAR_GLOBAL_ALLOCATED, 1); in test_btf_endian() 77 btf__set_endianness(btf, swap_endian); in test_btf_endian() [all …]
|
H A D | core_autosize.c | 60 struct btf *btf = NULL; in test_core_autosize() local 66 btf = btf__new_empty(); in test_core_autosize() 67 if (!ASSERT_OK_PTR(btf, "empty_btf")) in test_core_autosize() 85 btf__set_pointer_size(btf, 4); in test_core_autosize() 87 char_id = btf__add_int(btf, "unsigned char", 1, 0); in test_core_autosize() 89 short_id = btf__add_int(btf, "unsigned short", 2, 0); in test_core_autosize() 92 int_id = btf__add_int(btf, "long unsigned int", 4, 0); in test_core_autosize() 94 long_long_id = btf__add_int(btf, "unsigned long long", 8, 0); in test_core_autosize() 96 void_ptr_id = btf__add_ptr(btf, 0); in test_core_autosize() 99 id = btf__add_struct(btf, "test_struct", 20 /* bytes */); in test_core_autosize() [all …]
|
H A D | btf_dedup_split.c | 9 struct btf *btf1, *btf2; in test_split_simple() 127 struct btf *btf1, *btf2; in test_split_fwd_resolve() 225 struct btf *btf1, *btf2; in test_split_struct_duped() 332 static void btf_add_dup_struct_in_cu(struct btf *btf, int start_id) in btf_add_dup_struct_in_cu() argument 335 btf__set_pointer_size(btf, 8); /* enforce 64-bit arch */ in btf_add_dup_struct_in_cu() 337 btf__add_int(btf, "int", 4, BTF_INT_SIGNED); /* [1] int */ in btf_add_dup_struct_in_cu() 339 btf__add_struct(btf, "s", 8); /* [2] struct s { */ in btf_add_dup_struct_in_cu() 340 btf__add_field(btf, "a", ID(3), 0, 0); /* struct anon a; */ in btf_add_dup_struct_in_cu() 341 btf__add_field(btf, "b", ID(4), 0, 0); /* struct anon b; */ in btf_add_dup_struct_in_cu() 344 btf__add_struct(btf, "(anon)", 8); /* [3] struct anon { */ in btf_add_dup_struct_in_cu() [all …]
|
H A D | resolve_btfids.c | 66 __resolve_symbol(struct btf *btf, int type_id) in BTF_ID() 72 type = btf__type_by_id(btf, type_id); in BTF_ID() 85 str = btf__name_by_offset(btf, type->name_off); in BTF_ID() 100 struct btf *btf; in resolve_symbols() local 104 btf = btf__parse_elf("btf_data.bpf.o", NULL); in resolve_symbols() 105 if (CHECK(libbpf_get_error(btf), "resolve", in resolve_symbols() 109 nr = btf__type_cnt(btf); in resolve_symbols() 112 if (__resolve_symbol(btf, type_id)) in resolve_symbols() 116 btf__free(btf); in resolve_symbols()
|
H A D | ctx_rewrite.c | 252 static int find_field_offset_aux(struct btf *btf, int btf_id, char *field_name, int off) in find_field_offset_aux() argument 254 const struct btf_type *type = btf__type_by_id(btf, btf_id); in find_field_offset_aux() 273 const char *mname = btf__name_by_offset(btf, m->name_off); in find_field_offset_aux() 276 int msize = find_field_offset_aux(btf, m->type, field_name, in find_field_offset_aux() 291 static int find_field_offset(struct btf *btf, char *pattern, regmatch_t *matches) in find_field_offset() argument 313 btf_id = btf__find_by_name(btf, type_str); in find_field_offset() 319 field_offset = find_field_offset_aux(btf, btf_id, field_str, 0); in find_field_offset() 490 static bool match_pattern(struct btf *btf, char *pattern, char *text, char *reg_map[][2]) in match_pattern() argument 561 field_offset = find_field_offset(btf, pattern, matches); in match_pattern() 587 field_offset = find_field_offset(btf, pattern, matches); in match_pattern() [all …]
|
/linux/tools/lib/bpf/ |
H A D | btf.h | 24 struct btf; 39 LIBBPF_API void btf__free(struct btf *btf); 55 LIBBPF_API struct btf *btf__new(const void *data, __u32 size); 77 LIBBPF_API struct btf *btf__new_split(const void *data, __u32 size, struct btf *base_btf); 91 LIBBPF_API struct btf *btf__new_empty(void); 109 LIBBPF_API struct btf *btf__new_empty_split(struct btf *base_btf); 129 LIBBPF_API int btf__distill_base(const struct btf *src_btf, struct btf **new_base_btf, 130 struct btf **new_split_btf); 132 LIBBPF_API struct btf *btf__parse(const char *path, struct btf_ext **btf_ext); 133 LIBBPF_API struct btf *btf__parse_split(const char *path, struct btf *base_btf); [all …]
|
H A D | btf.c | 32 struct btf { struct 98 struct btf *base_btf; argument 196 static void *btf_add_type_offs_mem(struct btf *btf, size_t add_cnt) in btf_add_type_offs_mem() argument 198 return libbpf_add_mem((void **)&btf->type_offs, &btf->type_offs_cap, sizeof(__u32), in btf_add_type_offs_mem() 199 btf->nr_types, BTF_MAX_NR_TYPES, add_cnt); in btf_add_type_offs_mem() 202 static int btf_add_type_idx_entry(struct btf *btf, __u32 type_off) in btf_add_type_idx_entry() argument 206 p = btf_add_type_offs_mem(btf, 1); in btf_add_type_idx_entry() 224 static int btf_parse_hdr(struct btf *btf) in btf_parse_hdr() argument 226 struct btf_header *hdr = btf->hdr; in btf_parse_hdr() 229 if (btf->raw_size < sizeof(struct btf_header)) { in btf_parse_hdr() [all …]
|
H A D | relo_core.h | 10 const struct btf *btf; member 30 const struct btf *btf; member 71 int __bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id, 72 const struct btf *targ_btf, __u32 targ_id, int level); 73 int bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id, 74 const struct btf *targ_btf, __u32 targ_id); 75 int __bpf_core_types_match(const struct btf *local_btf, __u32 local_id, const struct btf *targ_btf, 77 int bpf_core_types_match(const struct btf *local_btf, __u32 local_id, const struct btf *targ_btf, 84 const struct btf *local_btf, 93 int bpf_core_parse_spec(const char *prog_name, const struct btf *btf,
|
/linux/include/linux/ |
H A D | btf.h | 108 struct btf; 141 const char *btf_get_name(const struct btf *btf); 142 void btf_get(struct btf *btf); 143 void btf_put(struct btf *btf); 144 const struct btf_header *btf_header(const struct btf *btf); 146 struct btf *btf_get_by_fd(int fd); 147 int btf_get_info_by_fd(const struct btf *btf, 171 const struct btf_type *btf_type_id_size(const struct btf *btf, 192 void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj, 194 int btf_type_seq_show_flags(const struct btf *btf, u32 type_id, void *obj, [all …]
|
/linux/kernel/bpf/ |
H A D | btf.c | 252 struct btf { struct 272 struct btf *base_btf; argument 313 struct btf *btf; member 419 const struct btf *btf; member 458 void (*show)(const struct btf *btf, const struct btf_type *t, 534 bool btf_is_vmlinux(const struct btf *btf) in btf_is_vmlinux() argument 536 return btf->kernel_btf && !btf->base_btf; in btf_is_vmlinux() 539 u32 btf_nr_types(const struct btf *btf) in btf_nr_types() argument 543 while (btf) { in btf_nr_types() 544 total += btf->nr_types; in btf_nr_types() [all …]
|
H A D | bpf_struct_ops.c | 43 struct btf *btf; member 87 extern struct btf *btf_vmlinux; 89 static bool is_valid_value_type(struct btf *btf, s32 value_id, in is_valid_value_type() argument 97 vt = btf_type_by_id(btf, value_id); in is_valid_value_type() 104 mt = btf_type_by_id(btf, member->type); in is_valid_value_type() 113 mt = btf_type_by_id(btf, member->type); in is_valid_value_type() 116 value_name, btf_name_by_offset(btf, type->name_off)); in is_valid_value_type() 159 find_stub_func_proto(const struct btf *btf, const char *st_op_name, in find_stub_func_proto() argument 173 btf_id = btf_find_by_name_kind(btf, stub_func_name, BTF_KIND_FUNC); in find_stub_func_proto() 176 func_type = btf_type_by_id(btf, btf_id); in find_stub_func_proto() [all …]
|
/linux/tools/bpf/bpftool/ |
H A D | btf_dumper.c | 27 static int btf_dump_func(const struct btf *btf, char *func_sig, 40 struct btf *prog_btf = NULL; in dump_prog_id_as_func_ptr() 47 func_sig_len = btf_dump_func(d->btf, prog_str, func_proto, NULL, 0, in dump_prog_id_as_func_ptr() 118 ptr_type_id = btf__resolve_type(d->btf, t->type); in btf_dumper_ptr() 121 ptr_type = btf__type_by_id(d->btf, ptr_type_id); in btf_dumper_ptr() 140 actual_type_id = btf__resolve_type(d->btf, type_id); in btf_dumper_modifier() 175 btf__name_by_offset(d->btf, in btf_dumper_enum() 201 btf__name_by_offset(d->btf, in btf_dumper_enum64() 211 static bool is_str_array(const struct btf *btf, const struct btf_array *arr, in is_str_array() argument 220 elem_type = btf__type_by_id(btf, arr->type); in is_str_array() [all …]
|
H A D | btf.c | 105 static const char *btf_str(const struct btf *btf, __u32 off) in btf_str() argument 109 return btf__name_by_offset(btf, off) ? : "(invalid)"; in btf_str() 117 static int dump_btf_type(const struct btf *btf, __u32 id, in dump_btf_type() argument 127 jsonw_string_field(w, "name", btf_str(btf, t->name_off)); in dump_btf_type() 130 btf_str(btf, t->name_off)); in dump_btf_type() 191 const char *name = btf_str(btf, m->name_off); in dump_btf_type() 240 const char *name = btf_str(btf, v->name_off); in dump_btf_type() 278 const char *name = btf_str(btf, v->name_off); in dump_btf_type() 337 const char *name = btf_str(btf, p->name_off); in dump_btf_type() 391 if (v->type < btf__type_cnt(btf)) { in dump_btf_type() [all …]
|
H A D | gen.c | 59 resolve_func_ptr(const struct btf *btf, __u32 id, __u32 *res_id) in resolve_func_ptr() argument 63 t = skip_mods_and_typedefs(btf, id, NULL); in resolve_func_ptr() 67 t = skip_mods_and_typedefs(btf, t->type, res_id); in resolve_func_ptr() 148 struct btf *btf, in codegen_datasec_def() argument 153 const char *sec_name = btf__name_by_offset(btf, sec->name_off); in codegen_datasec_def() 167 const struct btf_type *var = btf__type_by_id(btf, sec_var->type); in codegen_datasec_def() 168 const char *var_name = btf__name_by_offset(btf, var->name_off); in codegen_datasec_def() 187 align = btf__align_of(btf, var->type); in codegen_datasec_def() 235 static const struct btf_type *find_type_for_map(struct btf *btf, const char *map_ident) in find_type_for_map() argument 237 int n = btf__type_cnt(btf), i; in find_type_for_map() [all …]
|
H A D | main.h | 85 extern struct btf *base_btf; 112 struct btf; 179 const struct btf *btf, 188 const struct btf *btf, in disasm_print_insn() argument 210 const struct btf *btf; member 225 void btf_dumper_type_only(const struct btf *btf, __u32 func_type_id, 228 void btf_dump_linfo_plain(const struct btf *btf, 231 void btf_dump_linfo_json(const struct btf *btf, 233 void btf_dump_linfo_dotlabel(const struct btf *btf,
|
/linux/tools/testing/selftests/bpf/ |
H A D | btf_helpers.h | 9 int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id); 10 const char *btf_type_raw_dump(const struct btf *btf, int type_id); 11 int btf_validate_raw(struct btf *btf, int nr_types, const char *exp_types[]); 13 #define VALIDATE_RAW_BTF(btf, raw_types...) \ argument 14 btf_validate_raw(btf, \ 18 const char *btf_type_c_dump(const struct btf *btf);
|
H A D | btf_helpers.c | 81 static const char *btf_str(const struct btf *btf, __u32 off) in btf_str() argument 85 return btf__str_by_offset(btf, off) ?: "(invalid)"; in btf_str() 88 int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id) in fprintf_btf_type_raw() argument 94 t = btf__type_by_id(btf, id); in fprintf_btf_type_raw() 101 fprintf(out, "[%u] %s '%s'", id, btf_kind_str(kind), btf_str(btf, t->name_off)); in fprintf_btf_type_raw() 135 btf_str(btf, m->name_off), m->type, bit_off); in fprintf_btf_type_raw() 150 btf_str(btf, v->name_off), v->val); in fprintf_btf_type_raw() 164 btf_str(btf, v->name_off), in fprintf_btf_type_raw() 181 btf_str(btf, p->name_off), p->type); in fprintf_btf_type_raw() 216 const char *btf_type_raw_dump(const struct btf *btf, int type_id) in btf_type_raw_dump() argument [all …]
|
/linux/kernel/bpf/preload/iterators/ |
H A D | iterators.bpf.c | 34 struct btf { struct 46 struct btf *btf; member 59 static const char *get_name(struct btf *btf, long btf_id, const char *fallback) in get_name() argument 65 if (!btf) in get_name() 67 str = btf->strings; in get_name() 68 types = btf->types; in get_name() 71 if (name_off >= btf->hdr.str_len) in get_name() 114 get_name(aux->btf, aux->func_info[0].type_id, aux->name), in dump_bpf_prog()
|