perf bpf: Mute libbpf when '-v' not set
[deliverable/linux.git] / tools / lib / bpf / libbpf.h
CommitLineData
1b76c13e
WN
1/*
2 * Common eBPF ELF object loading operations.
3 *
4 * Copyright (C) 2013-2015 Alexei Starovoitov <ast@kernel.org>
5 * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com>
6 * Copyright (C) 2015 Huawei Inc.
7 */
8#ifndef __BPF_LIBBPF_H
9#define __BPF_LIBBPF_H
10
1a5e3fb1 11#include <stdio.h>
aa9b1ac3 12#include <stdbool.h>
1a5e3fb1 13
b3f59d66
WN
14/*
15 * In include/linux/compiler-gcc.h, __printf is defined. However
16 * it should be better if libbpf.h doesn't depend on Linux header file.
17 * So instead of __printf, here we use gcc attribute directly.
18 */
19typedef int (*libbpf_print_fn_t)(const char *, ...)
20 __attribute__((format(printf, 1, 2)));
21
22void libbpf_set_print(libbpf_print_fn_t warn,
23 libbpf_print_fn_t info,
24 libbpf_print_fn_t debug);
25
1a5e3fb1
WN
26/* Hide internal to user */
27struct bpf_object;
28
29struct bpf_object *bpf_object__open(const char *path);
6c956392 30struct bpf_object *bpf_object__open_buffer(void *obj_buf,
acf860ae
WN
31 size_t obj_buf_sz,
32 const char *name);
1a5e3fb1
WN
33void bpf_object__close(struct bpf_object *object);
34
52d3352e
WN
35/* Load/unload object into/from kernel */
36int bpf_object__load(struct bpf_object *obj);
37int bpf_object__unload(struct bpf_object *obj);
acf860ae 38const char *bpf_object__get_name(struct bpf_object *obj);
52d3352e 39
9a208eff
WN
40struct bpf_object *bpf_object__next(struct bpf_object *prev);
41#define bpf_object__for_each_safe(pos, tmp) \
42 for ((pos) = bpf_object__next(NULL), \
43 (tmp) = bpf_object__next(pos); \
44 (pos) != NULL; \
45 (pos) = (tmp), (tmp) = bpf_object__next(tmp))
46
aa9b1ac3
WN
47/* Accessors of bpf_program. */
48struct bpf_program;
49struct bpf_program *bpf_program__next(struct bpf_program *prog,
50 struct bpf_object *obj);
51
52#define bpf_object__for_each_program(pos, obj) \
53 for ((pos) = bpf_program__next(NULL, (obj)); \
54 (pos) != NULL; \
55 (pos) = bpf_program__next((pos), (obj)))
56
57typedef void (*bpf_program_clear_priv_t)(struct bpf_program *,
58 void *);
59
60int bpf_program__set_private(struct bpf_program *prog, void *priv,
61 bpf_program_clear_priv_t clear_priv);
62
63int bpf_program__get_private(struct bpf_program *prog,
64 void **ppriv);
65
66const char *bpf_program__title(struct bpf_program *prog, bool dup);
67
68int bpf_program__fd(struct bpf_program *prog);
69
34090915
WN
70/*
71 * We don't need __attribute__((packed)) now since it is
72 * unnecessary for 'bpf_map_def' because they are all aligned.
73 * In addition, using it will trigger -Wpacked warning message,
74 * and will be treated as an error due to -Werror.
75 */
76struct bpf_map_def {
77 unsigned int type;
78 unsigned int key_size;
79 unsigned int value_size;
80 unsigned int max_entries;
81};
82
1b76c13e 83#endif
This page took 0.030914 seconds and 5 git commands to generate.