File: task_pt_regs.c

package info (click to toggle)
linux 6.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,488,076 kB
  • sloc: ansic: 23,401,844; asm: 266,744; sh: 108,976; makefile: 49,705; python: 36,927; perl: 36,810; cpp: 6,044; yacc: 4,904; lex: 2,722; awk: 1,440; ruby: 25; sed: 5
file content (50 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: GPL-2.0
#define _GNU_SOURCE
#include <test_progs.h>
#include "test_task_pt_regs.skel.h"

/* uprobe attach point */
static noinline void trigger_func(void)
{
	asm volatile ("");
}

void test_task_pt_regs(void)
{
	struct test_task_pt_regs *skel;
	struct bpf_link *uprobe_link;
	ssize_t uprobe_offset;
	bool match;

	uprobe_offset = get_uprobe_offset(&trigger_func);
	if (!ASSERT_GE(uprobe_offset, 0, "uprobe_offset"))
		return;

	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 */
	trigger_func();

	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);
}