tools/bpf/bpftool/cfg.c
Source file repositories/reference/linux-study-clean/tools/bpf/bpftool/cfg.c
File Facts
- System
- Linux kernel
- Corpus path
tools/bpf/bpftool/cfg.c- Extension
.c- Size
- 10394 bytes
- Lines
- 490
- 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
linux/list.hstdlib.hstring.hcfg.hmain.hxlated_dumper.h
Detected Declarations
struct cfgstruct func_nodestruct bb_nodestruct edge_nodefunction list_for_each_entryfunction list_for_each_entryfunction cfg_partition_funcsfunction is_jmp_insnfunction func_partition_bb_headfunction func_partition_bb_tailfunction func_add_special_bbfunction func_partition_bbfunction list_for_each_entryfunction func_add_bb_edgesfunction cfg_buildfunction list_for_each_entryfunction cfg_destroyfunction list_for_each_entry_safefunction list_for_each_entry_safefunction list_for_each_entry_safefunction list_for_each_entry_safefunction draw_bb_nodefunction draw_bb_succ_edgesfunction list_for_each_entryfunction func_output_bb_deffunction list_for_each_entryfunction func_output_edgesfunction list_for_each_entryfunction cfg_dumpfunction dump_xlated_cfg
Annotated Snippet
struct cfg {
struct list_head funcs;
int func_num;
};
struct func_node {
struct list_head l;
struct list_head bbs;
struct bpf_insn *start;
struct bpf_insn *end;
int idx;
int bb_num;
};
struct bb_node {
struct list_head l;
struct list_head e_prevs;
struct list_head e_succs;
struct bpf_insn *head;
struct bpf_insn *tail;
int idx;
};
#define EDGE_FLAG_EMPTY 0x0
#define EDGE_FLAG_FALLTHROUGH 0x1
#define EDGE_FLAG_JUMP 0x2
struct edge_node {
struct list_head l;
struct bb_node *src;
struct bb_node *dst;
int flags;
};
#define ENTRY_BLOCK_INDEX 0
#define EXIT_BLOCK_INDEX 1
#define NUM_FIXED_BLOCKS 2
#define func_prev(func) list_prev_entry(func, l)
#define func_next(func) list_next_entry(func, l)
#define bb_prev(bb) list_prev_entry(bb, l)
#define bb_next(bb) list_next_entry(bb, l)
#define entry_bb(func) func_first_bb(func)
#define exit_bb(func) func_last_bb(func)
#define cfg_first_func(cfg) \
list_first_entry(&cfg->funcs, struct func_node, l)
#define cfg_last_func(cfg) \
list_last_entry(&cfg->funcs, struct func_node, l)
#define func_first_bb(func) \
list_first_entry(&func->bbs, struct bb_node, l)
#define func_last_bb(func) \
list_last_entry(&func->bbs, struct bb_node, l)
static struct func_node *cfg_append_func(struct cfg *cfg, struct bpf_insn *insn)
{
struct func_node *new_func, *func;
list_for_each_entry(func, &cfg->funcs, l) {
if (func->start == insn)
return func;
else if (func->start > insn)
break;
}
func = func_prev(func);
new_func = calloc(1, sizeof(*new_func));
if (!new_func) {
p_err("OOM when allocating FUNC node");
return NULL;
}
new_func->start = insn;
new_func->idx = cfg->func_num;
list_add(&new_func->l, &func->l);
cfg->func_num++;
return new_func;
}
static struct bb_node *func_append_bb(struct func_node *func,
struct bpf_insn *insn)
{
struct bb_node *new_bb, *bb;
list_for_each_entry(bb, &func->bbs, l) {
if (bb->head == insn)
return bb;
else if (bb->head > insn)
break;
}
bb = bb_prev(bb);
new_bb = calloc(1, sizeof(*new_bb));
Annotation
- Immediate include surface: `linux/list.h`, `stdlib.h`, `string.h`, `cfg.h`, `main.h`, `xlated_dumper.h`.
- Detected declarations: `struct cfg`, `struct func_node`, `struct bb_node`, `struct edge_node`, `function list_for_each_entry`, `function list_for_each_entry`, `function cfg_partition_funcs`, `function is_jmp_insn`, `function func_partition_bb_head`, `function func_partition_bb_tail`.
- 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.