Commit | Line | Data |
---|---|---|
69d262a9 WN |
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; | |
aa3abf30 | 14 | #define PERF_BPF_PROBE_GROUP "perf_bpf_probe" |
69d262a9 WN |
15 | |
16 | #ifdef HAVE_LIBBPF_SUPPORT | |
17 | struct bpf_object *bpf__prepare_load(const char *filename); | |
18 | ||
19 | void bpf__clear(void); | |
aa3abf30 WN |
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 | ||
69d262a9 WN |
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) { } | |
aa3abf30 WN |
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 | } | |
69d262a9 WN |
58 | #endif |
59 | #endif |