Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (c) 2021 Hengqi Chen */
0003 
0004 #include "vmlinux.h"
0005 #include <bpf/bpf_helpers.h>
0006 #include <bpf/bpf_tracing.h>
0007 
0008 const volatile pid_t my_pid = 0;
0009 int value = 0;
0010 
0011 SEC("raw_tp/sys_enter")
0012 int tailcall_1(void *ctx)
0013 {
0014     value = 42;
0015     return 0;
0016 }
0017 
0018 struct {
0019     __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
0020     __uint(max_entries, 2);
0021     __uint(key_size, sizeof(__u32));
0022     __array(values, int (void *));
0023 } prog_array_init SEC(".maps") = {
0024     .values = {
0025         [1] = (void *)&tailcall_1,
0026     },
0027 };
0028 
0029 SEC("raw_tp/sys_enter")
0030 int entry(void *ctx)
0031 {
0032     pid_t pid = bpf_get_current_pid_tgid() >> 32;
0033 
0034     if (pid != my_pid)
0035         return 0;
0036 
0037     bpf_tail_call(ctx, &prog_array_init, 1);
0038     return 0;
0039 }