bpf tools: Add bpf.c/h for common bpf operations
[deliverable/linux.git] / tools / lib / bpf / libbpf.h
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
11 #include <stdio.h>
12
13 /*
14 * In include/linux/compiler-gcc.h, __printf is defined. However
15 * it should be better if libbpf.h doesn't depend on Linux header file.
16 * So instead of __printf, here we use gcc attribute directly.
17 */
18 typedef int (*libbpf_print_fn_t)(const char *, ...)
19 __attribute__((format(printf, 1, 2)));
20
21 void libbpf_set_print(libbpf_print_fn_t warn,
22 libbpf_print_fn_t info,
23 libbpf_print_fn_t debug);
24
25 /* Hide internal to user */
26 struct bpf_object;
27
28 struct bpf_object *bpf_object__open(const char *path);
29 struct bpf_object *bpf_object__open_buffer(void *obj_buf,
30 size_t obj_buf_sz);
31 void bpf_object__close(struct bpf_object *object);
32
33 /*
34 * We don't need __attribute__((packed)) now since it is
35 * unnecessary for 'bpf_map_def' because they are all aligned.
36 * In addition, using it will trigger -Wpacked warning message,
37 * and will be treated as an error due to -Werror.
38 */
39 struct bpf_map_def {
40 unsigned int type;
41 unsigned int key_size;
42 unsigned int value_size;
43 unsigned int max_entries;
44 };
45
46 #endif
This page took 0.049412 seconds and 6 git commands to generate.