blob: 3e6960075835ceeb1313ff03ec3ef72f83af56a6 [file] [log] [blame]
Wang Nan1b76c132015-07-01 02:13:51 +00001/*
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
Wang Nan1a5e3fb2015-07-01 02:13:53 +000011#include <stdio.h>
12
Wang Nanb3f59d62015-07-01 02:13:52 +000013/*
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 */
18typedef int (*libbpf_print_fn_t)(const char *, ...)
19 __attribute__((format(printf, 1, 2)));
20
21void libbpf_set_print(libbpf_print_fn_t warn,
22 libbpf_print_fn_t info,
23 libbpf_print_fn_t debug);
24
Wang Nan1a5e3fb2015-07-01 02:13:53 +000025/* Hide internal to user */
26struct bpf_object;
27
28struct bpf_object *bpf_object__open(const char *path);
Wang Nan6c956392015-07-01 02:13:54 +000029struct bpf_object *bpf_object__open_buffer(void *obj_buf,
30 size_t obj_buf_sz);
Wang Nan1a5e3fb2015-07-01 02:13:53 +000031void bpf_object__close(struct bpf_object *object);
32
Wang Nan52d33522015-07-01 02:14:04 +000033/* Load/unload object into/from kernel */
34int bpf_object__load(struct bpf_object *obj);
35int bpf_object__unload(struct bpf_object *obj);
36
Wang Nan34090912015-07-01 02:14:02 +000037/*
38 * We don't need __attribute__((packed)) now since it is
39 * unnecessary for 'bpf_map_def' because they are all aligned.
40 * In addition, using it will trigger -Wpacked warning message,
41 * and will be treated as an error due to -Werror.
42 */
43struct bpf_map_def {
44 unsigned int type;
45 unsigned int key_size;
46 unsigned int value_size;
47 unsigned int max_entries;
48};
49
Wang Nan1b76c132015-07-01 02:13:51 +000050#endif