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 | ||
1e5e3ee8 WN |
26 | int bpf__load(struct bpf_object *obj); |
27 | int bpf__strerror_load(struct bpf_object *obj, int err, | |
28 | char *buf, size_t size); | |
69d262a9 WN |
29 | #else |
30 | static inline struct bpf_object * | |
31 | bpf__prepare_load(const char *filename __maybe_unused) | |
32 | { | |
33 | pr_debug("ERROR: eBPF object loading is disabled during compiling.\n"); | |
34 | return ERR_PTR(-ENOTSUP); | |
35 | } | |
36 | ||
37 | static inline void bpf__clear(void) { } | |
aa3abf30 WN |
38 | |
39 | static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;} | |
40 | static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;} | |
1e5e3ee8 | 41 | static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; } |
aa3abf30 WN |
42 | |
43 | static inline int | |
44 | __bpf_strerror(char *buf, size_t size) | |
45 | { | |
46 | if (!size) | |
47 | return 0; | |
48 | strncpy(buf, | |
49 | "ERROR: eBPF object loading is disabled during compiling.\n", | |
50 | size); | |
51 | buf[size - 1] = '\0'; | |
52 | return 0; | |
53 | } | |
54 | ||
55 | static inline int | |
56 | bpf__strerror_probe(struct bpf_object *obj __maybe_unused, | |
57 | int err __maybe_unused, | |
58 | char *buf, size_t size) | |
59 | { | |
60 | return __bpf_strerror(buf, size); | |
61 | } | |
1e5e3ee8 WN |
62 | |
63 | static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused, | |
64 | int err __maybe_unused, | |
65 | char *buf, size_t size) | |
66 | { | |
67 | return __bpf_strerror(buf, size); | |
68 | } | |
69d262a9 WN |
69 | #endif |
70 | #endif |