bpf_gen_internal.h 2.2 KB

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