bpf tools: Open eBPF object file and do basic validation
authorWang Nan <wangnan0@huawei.com>
Wed, 1 Jul 2015 02:13:53 +0000 (02:13 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 7 Aug 2015 13:16:56 +0000 (10:16 -0300)
commit1a5e3fb1e9a4a3e3695cd57c33c169a90d16fd3b
treebbd48754a0885ae3a861f2374f9d8435fcd34520
parentb3f59d66e22b8be4ccae67c8eaffa2cbb9e54eb1
bpf tools: Open eBPF object file and do basic validation

This patch defines basic interface of libbpf. 'struct bpf_object' will
be the handler of each object file. Its internal structure is hide to
user. eBPF object files are compiled by LLVM as ELF format. In this
patch, libelf is used to open those files, read EHDR and do basic
validation according to e_type and e_machine.

All elf related staffs are grouped together and reside in efile field of
'struct bpf_object'. bpf_object__elf_finish() is introduced to clear it.

After all eBPF programs in an object file are loaded, related ELF
information is useless. Close the object file and free those memory.

The zfree() and zclose() functions are introduced to ensure setting NULL
pointers and negative file descriptors after resources are released.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1435716878-189507-6-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf.h
This page took 0.025491 seconds and 5 git commands to generate.