0001
0002
0003
0004 #include "vmlinux.h"
0005 #include <bpf/bpf_helpers.h>
0006 #include <bpf/bpf_tracing.h>
0007
0008 char _license[] SEC("license") = "GPL";
0009
0010 struct {
0011 __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
0012 __uint(map_flags, BPF_F_NO_PREALLOC);
0013 __type(key, int);
0014 __type(value, long);
0015 } map_a SEC(".maps");
0016
0017 struct {
0018 __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
0019 __uint(map_flags, BPF_F_NO_PREALLOC);
0020 __type(key, int);
0021 __type(value, long);
0022 } map_b SEC(".maps");
0023
0024 SEC("fentry/bpf_local_storage_lookup")
0025 int BPF_PROG(on_lookup)
0026 {
0027 struct task_struct *task = bpf_get_current_task_btf();
0028
0029 bpf_task_storage_delete(&map_a, task);
0030 bpf_task_storage_delete(&map_b, task);
0031 return 0;
0032 }
0033
0034 SEC("fentry/bpf_local_storage_update")
0035 int BPF_PROG(on_update)
0036 {
0037 struct task_struct *task = bpf_get_current_task_btf();
0038 long *ptr;
0039
0040 ptr = bpf_task_storage_get(&map_a, task, 0,
0041 BPF_LOCAL_STORAGE_GET_F_CREATE);
0042 if (ptr)
0043 *ptr += 1;
0044
0045 ptr = bpf_task_storage_get(&map_b, task, 0,
0046 BPF_LOCAL_STORAGE_GET_F_CREATE);
0047 if (ptr)
0048 *ptr += 1;
0049
0050 return 0;
0051 }
0052
0053 SEC("tp_btf/sys_enter")
0054 int BPF_PROG(on_enter, struct pt_regs *regs, long id)
0055 {
0056 struct task_struct *task;
0057 long *ptr;
0058
0059 task = bpf_get_current_task_btf();
0060 ptr = bpf_task_storage_get(&map_a, task, 0,
0061 BPF_LOCAL_STORAGE_GET_F_CREATE);
0062 if (ptr)
0063 *ptr = 200;
0064
0065 ptr = bpf_task_storage_get(&map_b, task, 0,
0066 BPF_LOCAL_STORAGE_GET_F_CREATE);
0067 if (ptr)
0068 *ptr = 100;
0069 return 0;
0070 }