bpf_gen_internal.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include "bpf.h"
  6. struct ksym_relo_desc {
  7. const char *name;
  8. int kind;
  9. int insn_idx;
  10. bool is_weak;
  11. bool is_typeless;
  12. };
  13. struct ksym_desc {
  14. const char *name;
  15. int ref;
  16. int kind;
  17. union {
  18. /* used for kfunc */
  19. int off;
  20. /* used for typeless ksym */
  21. bool typeless;
  22. };
  23. int insn;
  24. };
  25. struct bpf_gen {
  26. struct gen_loader_opts *opts;
  27. void *data_start;
  28. void *data_cur;
  29. void *insn_start;
  30. void *insn_cur;
  31. ssize_t cleanup_label;
  32. __u32 nr_progs;
  33. __u32 nr_maps;
  34. int log_level;
  35. int error;
  36. struct ksym_relo_desc *relos;
  37. int relo_cnt;
  38. struct bpf_core_relo *core_relos;
  39. int core_relo_cnt;
  40. char attach_target[128];
  41. int attach_kind;
  42. struct ksym_desc *ksyms;
  43. __u32 nr_ksyms;
  44. int fd_array;
  45. int nr_fd_array;
  46. };
  47. void bpf_gen__init(struct bpf_gen *gen, int log_level, int nr_progs, int nr_maps);
  48. int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps);
  49. void bpf_gen__free(struct bpf_gen *gen);
  50. void bpf_gen__load_btf(struct bpf_gen *gen, const void *raw_data, __u32 raw_size);
  51. void bpf_gen__map_create(struct bpf_gen *gen,
  52. enum bpf_map_type map_type, const char *map_name,
  53. __u32 key_size, __u32 value_size, __u32 max_entries,
  54. struct bpf_map_create_opts *map_attr, int map_idx);
  55. void bpf_gen__prog_load(struct bpf_gen *gen,
  56. enum bpf_prog_type prog_type, const char *prog_name,
  57. const char *license, struct bpf_insn *insns, size_t insn_cnt,
  58. struct bpf_prog_load_opts *load_attr, int prog_idx);
  59. void bpf_gen__map_update_elem(struct bpf_gen *gen, int map_idx, void *value, __u32 value_size);
  60. void bpf_gen__map_freeze(struct bpf_gen *gen, int map_idx);
  61. void bpf_gen__record_attach_target(struct bpf_gen *gen, const char *name, enum bpf_attach_type type);
  62. void bpf_gen__record_extern(struct bpf_gen *gen, const char *name, bool is_weak,
  63. bool is_typeless, int kind, int insn_idx);
  64. void bpf_gen__record_relo_core(struct bpf_gen *gen, const struct bpf_core_relo *core_relo);
  65. void bpf_gen__populate_outer_map(struct bpf_gen *gen, int outer_map_idx, int key, int inner_map_idx);
  66. #endif