aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf/libbpf.c
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-11-26 02:03:27 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-11-29 10:10:19 -0500
commit5a6acad17d2e81765dd4c2fce7346a6f045eab25 (patch)
treec5ee94f9aec5b8ac2d1b09e7e1b8b28f927a1204 /tools/lib/bpf/libbpf.c
parent10931d2413478239bdceac5546cce85d7a497a4e (diff)
tools lib bpf: Retrive bpf_map through offset of bpf_map_def
Add a new API to libbpf, caller is able to get bpf_map through the offset of bpf_map_def to 'maps' section. The API will be used to help jitted perf hook code find fd of a map. Signed-off-by: Wang Nan <wangnan0@huawei.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Cc: He Kuang <hekuang@huawei.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Joe Stringer <joe@ovn.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/20161126070354.141764-4-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r--tools/lib/bpf/libbpf.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 866d5cdeffc7..2e974593f3e8 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1524,3 +1524,15 @@ bpf_object__find_map_by_name(struct bpf_object *obj, const char *name)
1524 } 1524 }
1525 return NULL; 1525 return NULL;
1526} 1526}
1527
1528struct bpf_map *
1529bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset)
1530{
1531 int i;
1532
1533 for (i = 0; i < obj->nr_maps; i++) {
1534 if (obj->maps[i].offset == offset)
1535 return &obj->maps[i];
1536 }
1537 return ERR_PTR(-ENOENT);
1538}