tools/testing/selftests/bpf/progs/stack_arg.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/stack_arg.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/stack_arg.c- Extension
.c- Size
- 6083 bytes
- Lines
- 274
- 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.hstdbool.hbpf/bpf_helpers.hbpf_kfuncs.h
Detected Declarations
struct timer_elemstruct test_datafunction static_func_many_argsfunction global_calls_many_argsfunction test_global_many_argsfunction func_with_ptr_stack_argfunction global_ptr_stack_argfunction test_bpf2bpf_ptr_stack_argfunction func_with_mix_stack_argsfunction global_mix_stack_argsfunction test_bpf2bpf_mix_stack_argsfunction func_inner_ptrfunction func_outer_ptrfunction global_nesting_ptrfunction test_bpf2bpf_nesting_stack_argfunction func_with_dynptrfunction global_dynptr_stack_argfunction test_bpf2bpf_dynptr_stack_argfunction foo1function foo2function foo2function test_two_calleesfunction timer_cb_many_argsfunction test_async_cb_many_argsfunction test_global_many_argsfunction test_bpf2bpf_ptr_stack_argfunction test_bpf2bpf_mix_stack_argsfunction test_bpf2bpf_nesting_stack_argfunction test_bpf2bpf_dynptr_stack_argfunction test_two_calleesfunction test_async_cb_many_args
Annotated Snippet
struct timer_elem {
struct bpf_timer timer;
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, struct timer_elem);
} timer_map SEC(".maps");
int timer_result;
#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && \
defined(__BPF_FEATURE_STACK_ARGUMENT)
const volatile bool has_stack_arg = true;
__noinline static int static_func_many_args(int a, int b, int c, int d,
int e, int f, int g, int h,
int i, int j)
{
return a + b + c + d + e + f + g + h + i + j;
}
__noinline int global_calls_many_args(int a, int b, int c)
{
return static_func_many_args(a, b, c, a + 3, a + 4, a + 5, a + 6,
a + 7, a + 8, a + 9);
}
SEC("tc")
int test_global_many_args(void)
{
return global_calls_many_args(1, 2, 3);
}
struct test_data {
long x;
long y;
};
/* 1+2+3+4+5+6+7+8+9+10+20 = 75 */
__noinline static long func_with_ptr_stack_arg(long a, long b, long c, long d,
long e, long f, long g, long h,
long i, struct test_data *p)
{
return a + b + c + d + e + f + g + h + i + p->x + p->y;
}
__noinline long global_ptr_stack_arg(long a, long b, long c, long d, long e)
{
struct test_data data = { .x = 10, .y = 20 };
return func_with_ptr_stack_arg(a, b, c, d, e, a + 5, a + 6, a + 7,
a + 8, &data);
}
SEC("tc")
int test_bpf2bpf_ptr_stack_arg(void)
{
return global_ptr_stack_arg(1, 2, 3, 4, 5);
}
/* 1+2+3+4+5+6+7+10+8+20 = 66 */
__noinline static long func_with_mix_stack_args(long a, long b, long c, long d,
long e, long f, long g,
struct test_data *p,
long h, struct test_data *q)
{
return a + b + c + d + e + f + g + p->x + h + q->y;
}
__noinline long global_mix_stack_args(long a, long b, long c, long d, long e)
{
struct test_data p = { .x = 10 };
struct test_data q = { .y = 20 };
return func_with_mix_stack_args(a, b, c, d, e, e + 1, e + 2, &p,
e + 3, &q);
}
SEC("tc")
int test_bpf2bpf_mix_stack_args(void)
{
return global_mix_stack_args(1, 2, 3, 4, 5);
}
/*
* Nesting test: func_outer calls func_inner, both with struct pointer
Annotation
- Immediate include surface: `vmlinux.h`, `stdbool.h`, `bpf/bpf_helpers.h`, `bpf_kfuncs.h`.
- Detected declarations: `struct timer_elem`, `struct test_data`, `function static_func_many_args`, `function global_calls_many_args`, `function test_global_many_args`, `function func_with_ptr_stack_arg`, `function global_ptr_stack_arg`, `function test_bpf2bpf_ptr_stack_arg`, `function func_with_mix_stack_args`, `function global_mix_stack_args`.
- 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.