tools/testing/selftests/bpf/progs/bpf_gotox.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/bpf_gotox.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/bpf_gotox.c- Extension
.c- Size
- 7975 bytes
- Lines
- 480
- 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.hbpf/bpf_core_read.hbpf_misc.h
Detected Declarations
struct simple_ctxfunction adjust_insnsfunction one_switchfunction one_switch_non_zero_sec_offfunction simple_test_other_secfunction two_switchesfunction big_jump_tablefunction one_jump_two_mapsfunction one_map_two_jumpsfunction f0function __static_globalfunction use_static_global1function use_static_global2function use_static_global_other_secfunction __nonstatic_globalfunction use_nonstatic_global1function use_nonstatic_global2function use_nonstatic_global_other_secfunction load_with_nonzero_offset
Annotated Snippet
struct simple_ctx {
__u64 x;
};
#ifdef __BPF_FEATURE_GOTOX
__u64 some_var;
/*
* This function adds code which will be replaced by a different
* number of instructions by the verifier. This adds additional
* stress on testing the insn_array maps corresponding to indirect jumps.
*/
static __always_inline void adjust_insns(__u64 x)
{
some_var ^= x + bpf_jiffies64();
}
SEC("syscall")
int one_switch(struct simple_ctx *ctx)
{
switch (ctx->x) {
case 0:
adjust_insns(ctx->x + 1);
ret_user = 2;
break;
case 1:
adjust_insns(ctx->x + 7);
ret_user = 3;
break;
case 2:
adjust_insns(ctx->x + 9);
ret_user = 4;
break;
case 3:
adjust_insns(ctx->x + 11);
ret_user = 5;
break;
case 4:
adjust_insns(ctx->x + 17);
ret_user = 7;
break;
default:
adjust_insns(ctx->x + 177);
ret_user = 19;
break;
}
return 0;
}
SEC("syscall")
int one_switch_non_zero_sec_off(struct simple_ctx *ctx)
{
switch (ctx->x) {
case 0:
adjust_insns(ctx->x + 1);
ret_user = 2;
break;
case 1:
adjust_insns(ctx->x + 7);
ret_user = 3;
break;
case 2:
adjust_insns(ctx->x + 9);
ret_user = 4;
break;
case 3:
adjust_insns(ctx->x + 11);
ret_user = 5;
break;
case 4:
adjust_insns(ctx->x + 17);
ret_user = 7;
break;
default:
adjust_insns(ctx->x + 177);
ret_user = 19;
break;
}
return 0;
}
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
int simple_test_other_sec(struct pt_regs *ctx)
{
__u64 x = in_user;
if (bpf_get_current_pid_tgid() >> 32 != pid)
return 0;
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf/bpf_core_read.h`, `bpf_misc.h`.
- Detected declarations: `struct simple_ctx`, `function adjust_insns`, `function one_switch`, `function one_switch_non_zero_sec_off`, `function simple_test_other_sec`, `function two_switches`, `function big_jump_table`, `function one_jump_two_maps`, `function one_map_two_jumps`, `function f0`.
- 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.