linux/tools/testing/selftests/bpf/progs/test_task_pt_regs.c
Jean-Philippe Brucker 3a029e1f3d selftests/bpf: Fix build of task_pt_regs test for arm64
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: 576d47bb1a92 ("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
2021-09-07 17:23:19 +02:00

37 lines
841 B
C

// SPDX-License-Identifier: GPL-2.0
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#define PT_REGS_SIZE sizeof(struct pt_regs)
/*
* The kernel struct pt_regs isn't exported in its entirety to userspace.
* Pass it as an array to task_pt_regs.c
*/
char current_regs[PT_REGS_SIZE] = {};
char ctx_regs[PT_REGS_SIZE] = {};
int uprobe_res = 0;
SEC("uprobe/trigger_func")
int handle_uprobe(struct pt_regs *ctx)
{
struct task_struct *current;
struct pt_regs *regs;
current = bpf_get_current_task_btf();
regs = (struct pt_regs *) bpf_task_pt_regs(current);
if (bpf_probe_read_kernel(current_regs, PT_REGS_SIZE, regs))
return 0;
if (bpf_probe_read_kernel(ctx_regs, PT_REGS_SIZE, ctx))
return 0;
/* Prove that uprobe was run */
uprobe_res = 1;
return 0;
}
char _license[] SEC("license") = "GPL";