tools/testing/selftests/bpf/progs/linked_maps1.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/linked_maps1.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/linked_maps1.c- Extension
.c- Size
- 1851 bytes
- Lines
- 83
- 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
vmlinux.hbpf/bpf_helpers.hbpf/bpf_tracing.h
Detected Declarations
struct my_keystruct my_valuefunction BPF_PROGfunction BPF_PROG
Annotated Snippet
struct my_key { long x; };
struct my_value { long x; };
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, struct my_key);
__type(value, struct my_value);
__uint(max_entries, 16);
} map1 SEC(".maps");
/* Matches map2 definition in linked_maps2.c. Order of the attributes doesn't
* matter.
*/
typedef struct {
__uint(max_entries, 8);
__type(key, int);
__type(value, int);
__uint(type, BPF_MAP_TYPE_ARRAY);
} map2_t;
extern map2_t map2 SEC(".maps");
/* This should be the winning map definition, but we have no way of verifying,
* so we just make sure that it links and works without errors
*/
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__type(key, int);
__type(value, int);
__uint(max_entries, 16);
} map_weak __weak SEC(".maps");
int output_first1;
int output_second1;
int output_weak1;
SEC("raw_tp/sys_enter")
int BPF_PROG(handler_enter1)
{
/* update values with key = 1 */
int key = 1, val = 1;
struct my_key key_struct = { .x = 1 };
struct my_value val_struct = { .x = 1000 };
bpf_map_update_elem(&map1, &key_struct, &val_struct, 0);
bpf_map_update_elem(&map2, &key, &val, 0);
bpf_map_update_elem(&map_weak, &key, &val, 0);
return 0;
}
SEC("raw_tp/sys_exit")
int BPF_PROG(handler_exit1)
{
/* lookup values with key = 2, set in another file */
int key = 2, *val;
struct my_key key_struct = { .x = 2 };
struct my_value *value_struct;
value_struct = bpf_map_lookup_elem(&map1, &key_struct);
if (value_struct)
output_first1 = value_struct->x;
val = bpf_map_lookup_elem(&map2, &key);
if (val)
output_second1 = *val;
val = bpf_map_lookup_elem(&map_weak, &key);
if (val)
output_weak1 = *val;
return 0;
}
char LICENSE[] SEC("license") = "GPL";
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`.
- Detected declarations: `struct my_key`, `struct my_value`, `function BPF_PROG`, `function BPF_PROG`.
- 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.