| #include <linux/bpf.h> |
| #include <stdbool.h> |
| #include <stdint.h> |
| |
| /* place things in different elf sections */ |
| #define SEC(NAME) __attribute__((section(NAME), used)) |
| |
| /* helper functions */ |
| static void* (*bpf_map_lookup_elem)(void* map, void* key) = (void*) BPF_FUNC_map_lookup_elem; |
| static int (*bpf_map_update_elem)(void* map, void* key, void* value, |
| unsigned long long flags) = (void*) BPF_FUNC_map_update_elem; |
| static int (*bpf_map_delete_elem)(void* map, void* key) = (void*) BPF_FUNC_map_delete_elem; |
| static int (*bpf_probe_read)(void* dst, int size, void* unsafe_ptr) = (void*) BPF_FUNC_probe_read; |
| static unsigned long long (*bpf_ktime_get_ns)(void) = (void*) BPF_FUNC_ktime_get_ns; |
| static int (*bpf_trace_printk)(const char* fmt, int fmt_size, ...) = (void*) BPF_FUNC_trace_printk; |
| static unsigned long long (*bpf_get_current_pid_tgid)(void) = (void*) BPF_FUNC_get_current_pid_tgid; |
| static unsigned long long (*bpf_get_current_uid_gid)(void) = (void*) BPF_FUNC_get_current_uid_gid; |
| static unsigned long long (*bpf_get_smp_processor_id)(void) = (void*) BPF_FUNC_get_smp_processor_id; |
| |
| /* loader usage */ |
| struct bpf_map_def { |
| unsigned int type; |
| unsigned int key_size; |
| unsigned int value_size; |
| unsigned int max_entries; |
| unsigned int map_flags; |
| unsigned int pad1; |
| unsigned int pad2; |
| }; |