tools/bpf/bpftool/gen.c
Source file repositories/reference/linux-study-clean/tools/bpf/bpftool/gen.c
File Facts
- System
- Linux kernel
- Corpus path
tools/bpf/bpftool/gen.c- Extension
.c- Size
- 67138 bytes
- Lines
- 2698
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
ctype.herrno.hfcntl.hlibgen.hlinux/err.hstdbool.hstdio.hstring.hunistd.hbpf/bpf.hbpf/libbpf.hbpf/libbpf_internal.hsys/types.hsys/stat.hsys/mman.hbpf/btf.hjson_writer.hmain.hbpf/skel_internal.hstdlib.h
Detected Declarations
struct btfgen_infofunction sanitize_identifierfunction str_has_prefixfunction str_has_suffixfunction resolve_func_ptrfunction get_obj_namefunction get_header_guardfunction get_map_identfunction get_datasec_identfunction codegen_btf_dump_printffunction codegen_datasec_deffunction is_mmapable_mapfunction codegen_datasecsfunction bpf_object__for_each_mapfunction btf_is_ptr_to_func_protofunction codegen_subskel_datasecsfunction bpf_object__for_each_mapfunction codegenfunction print_hexfunction bpf_map_mmap_szfunction codegen_assertsfunction bpf_object__for_each_mapfunction codegen_attach_detachfunction bpf_object__for_each_programfunction bpf_object__for_each_programfunction bpf_object__for_each_programfunction codegen_destroyfunction bpf_object__for_each_programfunction bpf_object__for_each_mapfunction gen_tracefunction codegen_maps_skeletonfunction bpf_object__for_each_mapfunction codegen_progs_skeletonfunction walk_st_ops_shadow_varsfunction gen_st_ops_shadow_typefunction gen_st_ops_shadowfunction gen_st_ops_shadow_initfunction do_skeletonfunction bpf_object__for_each_mapfunction bpf_object__for_each_mapfunction bpf_object__for_each_programfunction bpf_object__for_each_programfunction bpf_object__for_each_mapfunction do_subskeletonfunction bpf_object__for_each_programfunction bpf_object__for_each_mapfunction bpf_object__for_each_programfunction do_object
Annotated Snippet
struct btfgen_info {
struct btf *src_btf;
struct btf *marked_btf; /* btf structure used to mark used types */
};
static size_t btfgen_hash_fn(long key, void *ctx)
{
return key;
}
static bool btfgen_equal_fn(long k1, long k2, void *ctx)
{
return k1 == k2;
}
static void btfgen_free_info(struct btfgen_info *info)
{
if (!info)
return;
btf__free(info->src_btf);
btf__free(info->marked_btf);
free(info);
}
static struct btfgen_info *
btfgen_new_info(const char *targ_btf_path)
{
struct btfgen_info *info;
int err;
info = calloc(1, sizeof(*info));
if (!info)
return NULL;
info->src_btf = btf__parse(targ_btf_path, NULL);
if (!info->src_btf) {
err = -errno;
p_err("failed parsing '%s' BTF file: %s", targ_btf_path, strerror(errno));
goto err_out;
}
info->marked_btf = btf__parse(targ_btf_path, NULL);
if (!info->marked_btf) {
err = -errno;
p_err("failed parsing '%s' BTF file: %s", targ_btf_path, strerror(errno));
goto err_out;
}
return info;
err_out:
btfgen_free_info(info);
errno = -err;
return NULL;
}
#define MARKED UINT32_MAX
static void btfgen_mark_member(struct btfgen_info *info, int type_id, int idx)
{
const struct btf_type *t = btf__type_by_id(info->marked_btf, type_id);
struct btf_member *m = btf_members(t) + idx;
m->name_off = MARKED;
}
static int
btfgen_mark_type(struct btfgen_info *info, unsigned int type_id, bool follow_pointers)
{
const struct btf_type *btf_type = btf__type_by_id(info->src_btf, type_id);
struct btf_type *cloned_type;
struct btf_param *param;
struct btf_array *array;
__u32 i;
int err;
if (type_id == 0)
return 0;
/* mark type on cloned BTF as used */
cloned_type = (struct btf_type *) btf__type_by_id(info->marked_btf, type_id);
cloned_type->name_off = MARKED;
/* recursively mark other types needed by it */
switch (btf_kind(btf_type)) {
case BTF_KIND_UNKN:
case BTF_KIND_INT:
case BTF_KIND_FLOAT:
Annotation
- Immediate include surface: `ctype.h`, `errno.h`, `fcntl.h`, `libgen.h`, `linux/err.h`, `stdbool.h`, `stdio.h`, `string.h`.
- Detected declarations: `struct btfgen_info`, `function sanitize_identifier`, `function str_has_prefix`, `function str_has_suffix`, `function resolve_func_ptr`, `function get_obj_name`, `function get_header_guard`, `function get_map_ident`, `function get_datasec_ident`, `function codegen_btf_dump_printf`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.