cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

uprobe_autoattach.c (1585B)


      1// SPDX-License-Identifier: GPL-2.0
      2/* Copyright (c) 2022, Oracle and/or its affiliates. */
      3
      4#include <test_progs.h>
      5#include "test_uprobe_autoattach.skel.h"
      6
      7/* uprobe attach point */
      8static noinline int autoattach_trigger_func(int arg)
      9{
     10	asm volatile ("");
     11	return arg + 1;
     12}
     13
     14void test_uprobe_autoattach(void)
     15{
     16	struct test_uprobe_autoattach *skel;
     17	int trigger_val = 100, trigger_ret;
     18	size_t malloc_sz = 1;
     19	char *mem;
     20
     21	skel = test_uprobe_autoattach__open_and_load();
     22	if (!ASSERT_OK_PTR(skel, "skel_open"))
     23		return;
     24
     25	if (!ASSERT_OK(test_uprobe_autoattach__attach(skel), "skel_attach"))
     26		goto cleanup;
     27
     28	skel->bss->test_pid = getpid();
     29
     30	/* trigger & validate uprobe & uretprobe */
     31	trigger_ret = autoattach_trigger_func(trigger_val);
     32
     33	skel->bss->test_pid = getpid();
     34
     35	/* trigger & validate shared library u[ret]probes attached by name */
     36	mem = malloc(malloc_sz);
     37
     38	ASSERT_EQ(skel->bss->uprobe_byname_parm1, trigger_val, "check_uprobe_byname_parm1");
     39	ASSERT_EQ(skel->bss->uprobe_byname_ran, 1, "check_uprobe_byname_ran");
     40	ASSERT_EQ(skel->bss->uretprobe_byname_rc, trigger_ret, "check_uretprobe_byname_rc");
     41	ASSERT_EQ(skel->bss->uretprobe_byname_ran, 2, "check_uretprobe_byname_ran");
     42	ASSERT_EQ(skel->bss->uprobe_byname2_parm1, malloc_sz, "check_uprobe_byname2_parm1");
     43	ASSERT_EQ(skel->bss->uprobe_byname2_ran, 3, "check_uprobe_byname2_ran");
     44	ASSERT_EQ(skel->bss->uretprobe_byname2_rc, mem, "check_uretprobe_byname2_rc");
     45	ASSERT_EQ(skel->bss->uretprobe_byname2_ran, 4, "check_uretprobe_byname2_ran");
     46
     47	free(mem);
     48cleanup:
     49	test_uprobe_autoattach__destroy(skel);
     50}