tools/testing/selftests/bpf/progs/test_helper_restricted.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/test_helper_restricted.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/test_helper_restricted.c- Extension
.c- Size
- 1820 bytes
- Lines
- 124
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
time.hlinux/bpf.hbpf/bpf_helpers.h
Detected Declarations
struct timerstruct lockfunction timer_cbfunction timer_workfunction spin_lock_workfunction raw_tp_timerfunction tp_timerfunction kprobe_timerfunction perf_event_timerfunction raw_tp_spin_lockfunction tp_spin_lockfunction kprobe_spin_lockfunction perf_event_spin_lock
Annotated Snippet
struct timer {
struct bpf_timer t;
};
struct lock {
struct bpf_spin_lock l;
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, __u32);
__type(value, struct timer);
} timers SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, __u32);
__type(value, struct lock);
} locks SEC(".maps");
static int timer_cb(void *map, int *key, struct timer *timer)
{
return 0;
}
static void timer_work(void)
{
struct timer *timer;
const int key = 0;
timer = bpf_map_lookup_elem(&timers, &key);
if (timer) {
bpf_timer_init(&timer->t, &timers, CLOCK_MONOTONIC);
bpf_timer_set_callback(&timer->t, timer_cb);
bpf_timer_start(&timer->t, 10E9, 0);
bpf_timer_cancel(&timer->t);
}
}
static void spin_lock_work(void)
{
const int key = 0;
struct lock *lock;
lock = bpf_map_lookup_elem(&locks, &key);
if (lock) {
bpf_spin_lock(&lock->l);
bpf_spin_unlock(&lock->l);
}
}
SEC("?raw_tp/sys_enter")
int raw_tp_timer(void *ctx)
{
timer_work();
return 0;
}
SEC("?tp/syscalls/sys_enter_nanosleep")
int tp_timer(void *ctx)
{
timer_work();
return 0;
}
SEC("?kprobe")
int kprobe_timer(void *ctx)
{
timer_work();
return 0;
}
SEC("?perf_event")
int perf_event_timer(void *ctx)
{
timer_work();
return 0;
}
SEC("?raw_tp/sys_enter")
int raw_tp_spin_lock(void *ctx)
{
spin_lock_work();
Annotation
- Immediate include surface: `time.h`, `linux/bpf.h`, `bpf/bpf_helpers.h`.
- Detected declarations: `struct timer`, `struct lock`, `function timer_cb`, `function timer_work`, `function spin_lock_work`, `function raw_tp_timer`, `function tp_timer`, `function kprobe_timer`, `function perf_event_timer`, `function raw_tp_spin_lock`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.