1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2021 Hengqi Chen */
3 
4 #include "vmlinux.h"
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_tracing.h>
7 
8 const volatile pid_t my_pid = 0;
9 int value = 0;
10 
11 SEC("raw_tp/sys_enter")
tailcall_1(void * ctx)12 int tailcall_1(void *ctx)
13 {
14 	value = 42;
15 	return 0;
16 }
17 
18 struct {
19 	__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
20 	__uint(max_entries, 2);
21 	__uint(key_size, sizeof(__u32));
22 	__array(values, int (void *));
23 } prog_array_init SEC(".maps") = {
24 	.values = {
25 		[1] = (void *)&tailcall_1,
26 	},
27 };
28 
29 SEC("raw_tp/sys_enter")
entry(void * ctx)30 int entry(void *ctx)
31 {
32 	pid_t pid = bpf_get_current_pid_tgid() >> 32;
33 
34 	if (pid != my_pid)
35 		return 0;
36 
37 	bpf_tail_call(ctx, &prog_array_init, 1);
38 	return 0;
39 }
40