Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
0002 /* Copyright (c) 2021 Facebook */
0003 #ifndef __BPF_GEN_INTERNAL_H
0004 #define __BPF_GEN_INTERNAL_H
0005 
0006 #include "bpf.h"
0007 
0008 struct ksym_relo_desc {
0009     const char *name;
0010     int kind;
0011     int insn_idx;
0012     bool is_weak;
0013     bool is_typeless;
0014 };
0015 
0016 struct ksym_desc {
0017     const char *name;
0018     int ref;
0019     int kind;
0020     union {
0021         /* used for kfunc */
0022         int off;
0023         /* used for typeless ksym */
0024         bool typeless;
0025     };
0026     int insn;
0027 };
0028 
0029 struct bpf_gen {
0030     struct gen_loader_opts *opts;
0031     void *data_start;
0032     void *data_cur;
0033     void *insn_start;
0034     void *insn_cur;
0035     ssize_t cleanup_label;
0036     __u32 nr_progs;
0037     __u32 nr_maps;
0038     int log_level;
0039     int error;
0040     struct ksym_relo_desc *relos;
0041     int relo_cnt;
0042     struct bpf_core_relo *core_relos;
0043     int core_relo_cnt;
0044     char attach_target[128];
0045     int attach_kind;
0046     struct ksym_desc *ksyms;
0047     __u32 nr_ksyms;
0048     int fd_array;
0049     int nr_fd_array;
0050 };
0051 
0052 void bpf_gen__init(struct bpf_gen *gen, int log_level, int nr_progs, int nr_maps);
0053 int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps);
0054 void bpf_gen__free(struct bpf_gen *gen);
0055 void bpf_gen__load_btf(struct bpf_gen *gen, const void *raw_data, __u32 raw_size);
0056 void bpf_gen__map_create(struct bpf_gen *gen,
0057              enum bpf_map_type map_type, const char *map_name,
0058              __u32 key_size, __u32 value_size, __u32 max_entries,
0059              struct bpf_map_create_opts *map_attr, int map_idx);
0060 void bpf_gen__prog_load(struct bpf_gen *gen,
0061             enum bpf_prog_type prog_type, const char *prog_name,
0062             const char *license, struct bpf_insn *insns, size_t insn_cnt,
0063             struct bpf_prog_load_opts *load_attr, int prog_idx);
0064 void bpf_gen__map_update_elem(struct bpf_gen *gen, int map_idx, void *value, __u32 value_size);
0065 void bpf_gen__map_freeze(struct bpf_gen *gen, int map_idx);
0066 void bpf_gen__record_attach_target(struct bpf_gen *gen, const char *name, enum bpf_attach_type type);
0067 void bpf_gen__record_extern(struct bpf_gen *gen, const char *name, bool is_weak,
0068                 bool is_typeless, int kind, int insn_idx);
0069 void bpf_gen__record_relo_core(struct bpf_gen *gen, const struct bpf_core_relo *core_relo);
0070 void bpf_gen__populate_outer_map(struct bpf_gen *gen, int outer_map_idx, int key, int inner_map_idx);
0071 
0072 #endif