mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-15 22:41:38 +00:00
Change the values of fields, including scalar types and function pointers, and check if the struct_ops map works as expected. The test changes the field "test_2" of "testmod_1" from the pointer to test_2() to pointer to test_3() and the field "data" to 13. The function test_2() and test_3() both compute a new value for "test_2_result", but in different way. By checking the value of "test_2_result", it ensures the struct_ops map works as expected with changes through shadow types. Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20240229064523.2091270-6-thinker.li@gmail.com
38 lines
689 B
C
38 lines
689 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
|
|
#include <vmlinux.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
#include "../bpf_testmod/bpf_testmod.h"
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
int test_2_result = 0;
|
|
|
|
SEC("struct_ops/test_1")
|
|
int BPF_PROG(test_1)
|
|
{
|
|
return 0xdeadbeef;
|
|
}
|
|
|
|
SEC("struct_ops/test_2")
|
|
void BPF_PROG(test_2, int a, int b)
|
|
{
|
|
test_2_result = a + b;
|
|
}
|
|
|
|
SEC("struct_ops/test_3")
|
|
int BPF_PROG(test_3, int a, int b)
|
|
{
|
|
test_2_result = a + b + 3;
|
|
return a + b + 3;
|
|
}
|
|
|
|
SEC(".struct_ops.link")
|
|
struct bpf_testmod_ops testmod_1 = {
|
|
.test_1 = (void *)test_1,
|
|
.test_2 = (void *)test_2,
|
|
.data = 0x1,
|
|
};
|
|
|