Wang Nan | 69d262a | 2015-10-14 12:41:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com> |
| 3 | * Copyright (C) 2015, Huawei Inc. |
| 4 | */ |
| 5 | #ifndef __BPF_LOADER_H |
| 6 | #define __BPF_LOADER_H |
| 7 | |
| 8 | #include <linux/compiler.h> |
| 9 | #include <linux/err.h> |
| 10 | #include <string.h> |
| 11 | #include "debug.h" |
| 12 | |
| 13 | struct bpf_object; |
Wang Nan | aa3abf3 | 2015-10-14 12:41:15 +0000 | [diff] [blame^] | 14 | #define PERF_BPF_PROBE_GROUP "perf_bpf_probe" |
Wang Nan | 69d262a | 2015-10-14 12:41:13 +0000 | [diff] [blame] | 15 | |
| 16 | #ifdef HAVE_LIBBPF_SUPPORT |
| 17 | struct bpf_object *bpf__prepare_load(const char *filename); |
| 18 | |
| 19 | void bpf__clear(void); |
Wang Nan | aa3abf3 | 2015-10-14 12:41:15 +0000 | [diff] [blame^] | 20 | |
| 21 | int bpf__probe(struct bpf_object *obj); |
| 22 | int bpf__unprobe(struct bpf_object *obj); |
| 23 | int bpf__strerror_probe(struct bpf_object *obj, int err, |
| 24 | char *buf, size_t size); |
| 25 | |
Wang Nan | 69d262a | 2015-10-14 12:41:13 +0000 | [diff] [blame] | 26 | #else |
| 27 | static inline struct bpf_object * |
| 28 | bpf__prepare_load(const char *filename __maybe_unused) |
| 29 | { |
| 30 | pr_debug("ERROR: eBPF object loading is disabled during compiling.\n"); |
| 31 | return ERR_PTR(-ENOTSUP); |
| 32 | } |
| 33 | |
| 34 | static inline void bpf__clear(void) { } |
Wang Nan | aa3abf3 | 2015-10-14 12:41:15 +0000 | [diff] [blame^] | 35 | |
| 36 | static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;} |
| 37 | static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;} |
| 38 | |
| 39 | static inline int |
| 40 | __bpf_strerror(char *buf, size_t size) |
| 41 | { |
| 42 | if (!size) |
| 43 | return 0; |
| 44 | strncpy(buf, |
| 45 | "ERROR: eBPF object loading is disabled during compiling.\n", |
| 46 | size); |
| 47 | buf[size - 1] = '\0'; |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static inline int |
| 52 | bpf__strerror_probe(struct bpf_object *obj __maybe_unused, |
| 53 | int err __maybe_unused, |
| 54 | char *buf, size_t size) |
| 55 | { |
| 56 | return __bpf_strerror(buf, size); |
| 57 | } |
Wang Nan | 69d262a | 2015-10-14 12:41:13 +0000 | [diff] [blame] | 58 | #endif |
| 59 | #endif |