0001
0002
0003
0004 #include "vmlinux.h"
0005 #include <bpf/bpf_helpers.h>
0006 #include <bpf/bpf_tracing.h>
0007
0008
0009 typedef struct my_key { long x; } key_type;
0010 typedef struct my_value { long x; } value_type;
0011
0012 extern struct {
0013 __uint(max_entries, 16);
0014 __type(key, key_type);
0015 __type(value, value_type);
0016 __uint(type, BPF_MAP_TYPE_HASH);
0017 } map1 SEC(".maps");
0018
0019 struct {
0020 __uint(type, BPF_MAP_TYPE_ARRAY);
0021 __type(key, int);
0022 __type(value, int);
0023 __uint(max_entries, 8);
0024 } map2 SEC(".maps");
0025
0026
0027 struct {
0028 __uint(type, BPF_MAP_TYPE_ARRAY);
0029 __type(key, int);
0030 __type(value, int);
0031 __uint(max_entries, 16);
0032 } map_weak __weak SEC(".maps");
0033
0034 int output_first2;
0035 int output_second2;
0036 int output_weak2;
0037
0038 SEC("raw_tp/sys_enter")
0039 int BPF_PROG(handler_enter2)
0040 {
0041
0042 int key = 2, val = 2;
0043 key_type key_struct = { .x = 2 };
0044 value_type val_struct = { .x = 2000 };
0045
0046 bpf_map_update_elem(&map1, &key_struct, &val_struct, 0);
0047 bpf_map_update_elem(&map2, &key, &val, 0);
0048 bpf_map_update_elem(&map_weak, &key, &val, 0);
0049
0050 return 0;
0051 }
0052
0053 SEC("raw_tp/sys_exit")
0054 int BPF_PROG(handler_exit2)
0055 {
0056
0057 int key = 1, *val;
0058 key_type key_struct = { .x = 1 };
0059 value_type *value_struct;
0060
0061 value_struct = bpf_map_lookup_elem(&map1, &key_struct);
0062 if (value_struct)
0063 output_first2 = value_struct->x;
0064
0065 val = bpf_map_lookup_elem(&map2, &key);
0066 if (val)
0067 output_second2 = *val;
0068
0069 val = bpf_map_lookup_elem(&map_weak, &key);
0070 if (val)
0071 output_weak2 = *val;
0072
0073 return 0;
0074 }
0075
0076 char LICENSE[] SEC("license") = "GPL";