libbpf: Add getter for program size
This adds a new getter for the BPF program size (in bytes). This is useful for a caller that is trying to predict how much memory will be locked by loading a BPF object into the kernel. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Acked-by: David S. Miller <davem@davemloft.net> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/157333185272.88376.10996937115395724683.stgit@toke.dk
This commit is contained in:
committed by
Alexei Starovoitov
parent
473f4e133a
commit
1a734efe06
@@ -4782,6 +4782,11 @@ int bpf_program__fd(const struct bpf_program *prog)
|
||||
return bpf_program__nth_fd(prog, 0);
|
||||
}
|
||||
|
||||
size_t bpf_program__size(const struct bpf_program *prog)
|
||||
{
|
||||
return prog->insns_cnt * sizeof(struct bpf_insn);
|
||||
}
|
||||
|
||||
int bpf_program__set_prep(struct bpf_program *prog, int nr_instances,
|
||||
bpf_program_prep_t prep)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user