40 lines · c
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 8const volatile pid_t my_pid = 0;9int value = 0;10 11SEC("raw_tp/sys_enter")12int tailcall_1(void *ctx)13{14 value = 42;15 return 0;16}17 18struct {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 29SEC("raw_tp/sys_enter")30int 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