Wang Nan | 1b76c13 | 2015-07-01 02:13:51 +0000 | [diff] [blame] | 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 | |
Wang Nan | 1a5e3fb | 2015-07-01 02:13:53 +0000 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | |
Wang Nan | b3f59d6 | 2015-07-01 02:13:52 +0000 | [diff] [blame] | 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 | |
Wang Nan | 1a5e3fb | 2015-07-01 02:13:53 +0000 | [diff] [blame] | 25 | /* Hide internal to user */ |
| 26 | struct bpf_object; |
| 27 | |
| 28 | struct bpf_object *bpf_object__open(const char *path); |
Wang Nan | 6c95639 | 2015-07-01 02:13:54 +0000 | [diff] [blame] | 29 | struct bpf_object *bpf_object__open_buffer(void *obj_buf, |
| 30 | size_t obj_buf_sz); |
Wang Nan | 1a5e3fb | 2015-07-01 02:13:53 +0000 | [diff] [blame] | 31 | void bpf_object__close(struct bpf_object *object); |
| 32 | |
Wang Nan | 52d3352 | 2015-07-01 02:14:04 +0000 | [diff] [blame^] | 33 | /* Load/unload object into/from kernel */ |
| 34 | int bpf_object__load(struct bpf_object *obj); |
| 35 | int bpf_object__unload(struct bpf_object *obj); |
| 36 | |
Wang Nan | 3409091 | 2015-07-01 02:14:02 +0000 | [diff] [blame] | 37 | /* |
| 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 | */ |
| 43 | struct 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 Nan | 1b76c13 | 2015-07-01 02:13:51 +0000 | [diff] [blame] | 50 | #endif |