summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/tracing_struct.c
blob: c435a3a8328ab1580c63967a7f0ab779aa7ca4d4 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */

#include <vmlinux.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>

struct bpf_testmod_struct_arg_1 {
	int a;
};
struct bpf_testmod_struct_arg_2 {
	long a;
	long b;
};

struct bpf_testmod_struct_arg_3 {
	int a;
	int b[];
};

long t1_a_a, t1_a_b, t1_b, t1_c, t1_ret, t1_nregs;
__u64 t1_reg0, t1_reg1, t1_reg2, t1_reg3;
long t2_a, t2_b_a, t2_b_b, t2_c, t2_ret;
long t3_a, t3_b, t3_c_a, t3_c_b, t3_ret;
long t4_a_a, t4_b, t4_c, t4_d, t4_e_a, t4_e_b, t4_ret;
long t5_ret;
int t6;

SEC("fentry/bpf_testmod_test_struct_arg_1")
int BPF_PROG2(test_struct_arg_1, struct bpf_testmod_struct_arg_2, a, int, b, int, c)
{
	t1_a_a = a.a;
	t1_a_b = a.b;
	t1_b = b;
	t1_c = c;
	return 0;
}

SEC("fexit/bpf_testmod_test_struct_arg_1")
int BPF_PROG2(test_struct_arg_2, struct bpf_testmod_struct_arg_2, a, int, b, int, c, int, ret)
{
	t1_nregs =  bpf_get_func_arg_cnt(ctx);
	/* a.a */
	bpf_get_func_arg(ctx, 0, &t1_reg0);
	/* a.b */
	bpf_get_func_arg(ctx, 1, &t1_reg1);
	/* b */
	bpf_get_func_arg(ctx, 2, &t1_reg2);
	t1_reg2 = (int)t1_reg2;
	/* c */
	bpf_get_func_arg(ctx, 3, &t1_reg3);
	t1_reg3 = (int)t1_reg3;

	t1_ret = ret;
	return 0;
}

SEC("fentry/bpf_testmod_test_struct_arg_2")
int BPF_PROG2(test_struct_arg_3, int, a, struct bpf_testmod_struct_arg_2, b, int, c)
{
	t2_a = a;
	t2_b_a = b.a;
	t2_b_b = b.b;
	t2_c = c;
	return 0;
}

SEC("fexit/bpf_testmod_test_struct_arg_2")
int BPF_PROG2(test_struct_arg_4, int, a, struct bpf_testmod_struct_arg_2, b, int, c, int, ret)
{
	t2_ret = ret;
	return 0;
}

SEC("fentry/bpf_testmod_test_struct_arg_3")
int BPF_PROG2(test_struct_arg_5, int, a, int, b, struct bpf_testmod_struct_arg_2, c)
{
	t3_a = a;
	t3_b = b;
	t3_c_a = c.a;
	t3_c_b = c.b;
	return 0;
}

SEC("fexit/bpf_testmod_test_struct_arg_3")
int BPF_PROG2(test_struct_arg_6, int, a, int, b, struct bpf_testmod_struct_arg_2, c, int, ret)
{
	t3_ret = ret;
	return 0;
}

SEC("fentry/bpf_testmod_test_struct_arg_4")
int BPF_PROG2(test_struct_arg_7, struct bpf_testmod_struct_arg_1, a, int, b,
	     int, c, int, d, struct bpf_testmod_struct_arg_2, e)
{
	t4_a_a = a.a;
	t4_b = b;
	t4_c = c;
	t4_d = d;
	t4_e_a = e.a;
	t4_e_b = e.b;
	return 0;
}

SEC("fexit/bpf_testmod_test_struct_arg_4")
int BPF_PROG2(test_struct_arg_8, struct bpf_testmod_struct_arg_1, a, int, b,
	     int, c, int, d, struct bpf_testmod_struct_arg_2, e, int, ret)
{
	t4_ret = ret;
	return 0;
}

SEC("fentry/bpf_testmod_test_struct_arg_5")
int BPF_PROG2(test_struct_arg_9)
{
	return 0;
}

SEC("fexit/bpf_testmod_test_struct_arg_5")
int BPF_PROG2(test_struct_arg_10, int, ret)
{
	t5_ret = ret;
	return 0;
}

SEC("fentry/bpf_testmod_test_struct_arg_6")
int BPF_PROG2(test_struct_arg_11, struct bpf_testmod_struct_arg_3 *, a)
{
	t6 = a->b[0];
	return 0;
}

char _license[] SEC("license") = "GPL";