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