mirror of
https://github.com/netdata/libbpf.git
synced 2026-11-07 18:30:15 +08:00
Light skeleton doesn't create maps. The loader prog does at run time. Teach gen_loader to create a copy of .rodata map with offsets of functions for a prog, see create_func_ptr_map(). - Such maps are not maps of the object and are not in the loader ctx. Reserve slots in fd_array after the maps of the object for them and close their fds when the loader is done or fails. The progs hold them. Which progs have callx is not known when the loader is initialized, so reserve for every prog if .text has callx and for the progs that have callx otherwise. - Add bpf_gen__func_ptr_map_create() that emits map create, update, freeze and returns the index in fd_array for ld_imm64 BPF_PSEUDO_MAP_IDX_VALUE. - User space can set .rodata before loading the skeleton, see initial_value in bpf_map_desc. Copy it into the copy of the map as well and store the offsets of functions on top, since user space doesn't have them. - Light skeleton can be generated for a target of another endianness. Store the offsets in the byte order of the object. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20260924031042.1690890-15-alexei.starovoitov@gmail.com
89 lines
2.7 KiB
C
89 lines
2.7 KiB
C
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
|
|
/* Copyright (c) 2021 Facebook */
|
|
#ifndef __BPF_GEN_INTERNAL_H
|
|
#define __BPF_GEN_INTERNAL_H
|
|
|
|
#include "bpf.h"
|
|
#include "libbpf_internal.h"
|
|
|
|
struct ksym_relo_desc {
|
|
const char *name;
|
|
int kind;
|
|
int insn_idx;
|
|
bool is_weak;
|
|
bool is_typeless;
|
|
bool is_ld64;
|
|
};
|
|
|
|
struct ksym_desc {
|
|
const char *name;
|
|
int ref;
|
|
int kind;
|
|
union {
|
|
/* used for kfunc */
|
|
int off;
|
|
/* used for typeless ksym */
|
|
bool typeless;
|
|
};
|
|
int insn;
|
|
bool is_ld64;
|
|
};
|
|
|
|
struct bpf_gen {
|
|
struct gen_loader_opts *opts;
|
|
void *data_start;
|
|
void *data_cur;
|
|
void *insn_start;
|
|
void *insn_cur;
|
|
bool swapped_endian;
|
|
ssize_t cleanup_label;
|
|
__u32 nr_progs;
|
|
__u32 nr_maps;
|
|
int log_level;
|
|
int error;
|
|
struct ksym_relo_desc *relos;
|
|
int relo_cnt;
|
|
struct bpf_core_relo *core_relos;
|
|
int core_relo_cnt;
|
|
char attach_target[128];
|
|
int attach_kind;
|
|
struct ksym_desc *ksyms;
|
|
__u32 nr_ksyms;
|
|
int fd_array;
|
|
int nr_fd_array;
|
|
/*
|
|
* Maps with pointers to functions, that programs get their own copies
|
|
* of, take slots in fd_array after nr_obj_maps maps of the object.
|
|
*/
|
|
__u32 nr_obj_maps;
|
|
__u32 nr_func_ptr_maps;
|
|
__u32 max_func_ptr_maps;
|
|
};
|
|
|
|
void bpf_gen__init(struct bpf_gen *gen, int log_level, int nr_progs, int nr_maps,
|
|
int max_func_ptr_maps);
|
|
int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps);
|
|
void bpf_gen__free(struct bpf_gen *gen);
|
|
void bpf_gen__load_btf(struct bpf_gen *gen, const void *raw_data, __u32 raw_size);
|
|
void bpf_gen__map_create(struct bpf_gen *gen,
|
|
enum bpf_map_type map_type, const char *map_name,
|
|
__u32 key_size, __u32 value_size, __u32 max_entries,
|
|
struct bpf_map_create_opts *map_attr, int map_idx);
|
|
void bpf_gen__prog_load(struct bpf_gen *gen,
|
|
enum bpf_prog_type prog_type, const char *prog_name,
|
|
const char *license, struct bpf_insn *insns, size_t insn_cnt,
|
|
struct bpf_prog_load_opts *load_attr, int prog_idx);
|
|
void bpf_gen__map_update_elem(struct bpf_gen *gen, int map_idx, void *value, __u32 value_size,
|
|
__u64 flags);
|
|
void bpf_gen__map_freeze(struct bpf_gen *gen, int map_idx);
|
|
int bpf_gen__func_ptr_map_create(struct bpf_gen *gen, const char *map_name, int obj_map_idx,
|
|
void *value, __u32 value_size, const __u32 *ptr_offs,
|
|
const __u64 *ptr_vals, int ptr_cnt);
|
|
void bpf_gen__record_attach_target(struct bpf_gen *gen, const char *name, enum bpf_attach_type type);
|
|
void bpf_gen__record_extern(struct bpf_gen *gen, const char *name, bool is_weak,
|
|
bool is_typeless, bool is_ld64, int kind, int insn_idx);
|
|
void bpf_gen__record_relo_core(struct bpf_gen *gen, const struct bpf_core_relo *core_relo);
|
|
void bpf_gen__populate_outer_map(struct bpf_gen *gen, int outer_map_idx, int key, int inner_map_idx);
|
|
|
|
#endif
|