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