1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 /* Copyright (c) 2021 Facebook */ 3 #ifndef __BPF_GEN_INTERNAL_H 4 #define __BPF_GEN_INTERNAL_H 5 6 #include "bpf.h" 7 #include "libbpf_internal.h" 8 9 struct ksym_relo_desc { 10 const char *name; 11 int kind; 12 int insn_idx; 13 bool is_weak; 14 bool is_typeless; 15 bool is_ld64; 16 }; 17 18 struct ksym_desc { 19 const char *name; 20 int ref; 21 int kind; 22 union { 23 /* used for kfunc */ 24 int off; 25 /* used for typeless ksym */ 26 bool typeless; 27 }; 28 int insn; 29 bool is_ld64; 30 }; 31 32 struct bpf_gen { 33 struct gen_loader_opts *opts; 34 void *data_start; 35 void *data_cur; 36 void *insn_start; 37 void *insn_cur; 38 bool swapped_endian; 39 ssize_t cleanup_label; 40 __u32 nr_progs; 41 __u32 nr_maps; 42 int log_level; 43 int error; 44 struct ksym_relo_desc *relos; 45 int relo_cnt; 46 struct bpf_core_relo *core_relos; 47 int core_relo_cnt; 48 char attach_target[128]; 49 int attach_kind; 50 struct ksym_desc *ksyms; 51 __u32 nr_ksyms; 52 int fd_array; 53 int nr_fd_array; 54 int hash_insn_offset[SHA256_DWORD_SIZE]; 55 }; 56 57 void bpf_gen__init(struct bpf_gen *gen, int log_level, int nr_progs, int nr_maps); 58 int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps); 59 void bpf_gen__free(struct bpf_gen *gen); 60 void bpf_gen__load_btf(struct bpf_gen *gen, const void *raw_data, __u32 raw_size); 61 void bpf_gen__map_create(struct bpf_gen *gen, 62 enum bpf_map_type map_type, const char *map_name, 63 __u32 key_size, __u32 value_size, __u32 max_entries, 64 struct bpf_map_create_opts *map_attr, int map_idx); 65 void bpf_gen__prog_load(struct bpf_gen *gen, 66 enum bpf_prog_type prog_type, const char *prog_name, 67 const char *license, struct bpf_insn *insns, size_t insn_cnt, 68 struct bpf_prog_load_opts *load_attr, int prog_idx); 69 void bpf_gen__map_update_elem(struct bpf_gen *gen, int map_idx, void *value, __u32 value_size); 70 void bpf_gen__map_freeze(struct bpf_gen *gen, int map_idx); 71 void bpf_gen__record_attach_target(struct bpf_gen *gen, const char *name, enum bpf_attach_type type); 72 void bpf_gen__record_extern(struct bpf_gen *gen, const char *name, bool is_weak, 73 bool is_typeless, bool is_ld64, int kind, int insn_idx); 74 void bpf_gen__record_relo_core(struct bpf_gen *gen, const struct bpf_core_relo *core_relo); 75 void bpf_gen__populate_outer_map(struct bpf_gen *gen, int outer_map_idx, int key, int inner_map_idx); 76 77 #endif 78