0001
0002
0003
0004 #include <linux/ptrace.h>
0005 #include <linux/bpf.h>
0006 #include <bpf/bpf_helpers.h>
0007 #include <bpf/bpf_tracing.h>
0008
0009 #define VAR_NUM 2
0010
0011 struct hmap_elem {
0012 struct bpf_spin_lock lock;
0013 int var[VAR_NUM];
0014 };
0015
0016 struct {
0017 __uint(type, BPF_MAP_TYPE_HASH);
0018 __uint(max_entries, 1);
0019 __type(key, __u32);
0020 __type(value, struct hmap_elem);
0021 } hash_map SEC(".maps");
0022
0023 SEC("freplace/handle_kprobe")
0024 int new_handle_kprobe(struct pt_regs *ctx)
0025 {
0026 struct hmap_elem zero = {}, *val;
0027 int key = 0;
0028
0029 val = bpf_map_lookup_elem(&hash_map, &key);
0030 if (!val)
0031 return 1;
0032
0033 bpf_spin_lock(&val->lock);
0034 val->var[0] = 99;
0035 bpf_spin_unlock(&val->lock);
0036
0037 return 0;
0038 }
0039
0040 char _license[] SEC("license") = "GPL";