struct pt_regs is not exported to userspace on all archs. arm64 and s390
export "user_pt_regs" instead, which causes build failure at the moment:
progs/test_task_pt_regs.c:8:16: error: variable has incomplete type 'struct pt_regs'
struct pt_regs current_regs = {};
Instead of using pt_regs from ptrace.h, use the larger kernel struct
from vmlinux.h directly. Since the test runner task_pt_regs.c does not
have access to the kernel struct definition, copy it into a char array.
Fixes: 576d47bb1a
("bpf: selftests: Add bpf_task_pt_regs() selftest")
Suggested-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Ilya Leoshkevich <iii@linux.ibm.com>
Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/bpf/20210906163635.302307-1-jean-philippe@linaro.org
46 lines
1.2 KiB
C
46 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#define _GNU_SOURCE
|
|
#include <test_progs.h>
|
|
#include "test_task_pt_regs.skel.h"
|
|
|
|
void test_task_pt_regs(void)
|
|
{
|
|
struct test_task_pt_regs *skel;
|
|
struct bpf_link *uprobe_link;
|
|
size_t uprobe_offset;
|
|
ssize_t base_addr;
|
|
bool match;
|
|
|
|
base_addr = get_base_addr();
|
|
if (!ASSERT_GT(base_addr, 0, "get_base_addr"))
|
|
return;
|
|
uprobe_offset = get_uprobe_offset(&get_base_addr, base_addr);
|
|
|
|
skel = test_task_pt_regs__open_and_load();
|
|
if (!ASSERT_OK_PTR(skel, "skel_open"))
|
|
return;
|
|
if (!ASSERT_OK_PTR(skel->bss, "check_bss"))
|
|
goto cleanup;
|
|
|
|
uprobe_link = bpf_program__attach_uprobe(skel->progs.handle_uprobe,
|
|
false /* retprobe */,
|
|
0 /* self pid */,
|
|
"/proc/self/exe",
|
|
uprobe_offset);
|
|
if (!ASSERT_OK_PTR(uprobe_link, "attach_uprobe"))
|
|
goto cleanup;
|
|
skel->links.handle_uprobe = uprobe_link;
|
|
|
|
/* trigger & validate uprobe */
|
|
get_base_addr();
|
|
|
|
if (!ASSERT_EQ(skel->bss->uprobe_res, 1, "check_uprobe_res"))
|
|
goto cleanup;
|
|
|
|
match = !memcmp(&skel->bss->current_regs, &skel->bss->ctx_regs,
|
|
sizeof(skel->bss->current_regs));
|
|
ASSERT_TRUE(match, "check_regs_match");
|
|
|
|
cleanup:
|
|
test_task_pt_regs__destroy(skel);
|
|
}
|