0001
0002 #define _GNU_SOURCE
0003 #include <test_progs.h>
0004 #include "test_task_pt_regs.skel.h"
0005
0006
0007 static void trigger_func(void)
0008 {
0009 asm volatile ("");
0010 }
0011
0012 void test_task_pt_regs(void)
0013 {
0014 struct test_task_pt_regs *skel;
0015 struct bpf_link *uprobe_link;
0016 ssize_t uprobe_offset;
0017 bool match;
0018
0019 uprobe_offset = get_uprobe_offset(&trigger_func);
0020 if (!ASSERT_GE(uprobe_offset, 0, "uprobe_offset"))
0021 return;
0022
0023 skel = test_task_pt_regs__open_and_load();
0024 if (!ASSERT_OK_PTR(skel, "skel_open"))
0025 return;
0026 if (!ASSERT_OK_PTR(skel->bss, "check_bss"))
0027 goto cleanup;
0028
0029 uprobe_link = bpf_program__attach_uprobe(skel->progs.handle_uprobe,
0030 false ,
0031 0 ,
0032 "/proc/self/exe",
0033 uprobe_offset);
0034 if (!ASSERT_OK_PTR(uprobe_link, "attach_uprobe"))
0035 goto cleanup;
0036 skel->links.handle_uprobe = uprobe_link;
0037
0038
0039 trigger_func();
0040
0041 if (!ASSERT_EQ(skel->bss->uprobe_res, 1, "check_uprobe_res"))
0042 goto cleanup;
0043
0044 match = !memcmp(&skel->bss->current_regs, &skel->bss->ctx_regs,
0045 sizeof(skel->bss->current_regs));
0046 ASSERT_TRUE(match, "check_regs_match");
0047
0048 cleanup:
0049 test_task_pt_regs__destroy(skel);
0050 }