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.

Dependency Surface

Detected Declarations

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

Implementation Notes