2 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
3 * Copyright (C) 2015, Huawei Inc.
8 #include <linux/compiler.h>
11 #include <bpf/libbpf.h>
12 #include "probe-event.h"
15 enum bpf_loader_errno {
16 __BPF_LOADER_ERRNO__START = __LIBBPF_ERRNO__START - 100,
17 /* Invalid config string */
18 BPF_LOADER_ERRNO__CONFIG = __BPF_LOADER_ERRNO__START,
19 BPF_LOADER_ERRNO__GROUP, /* Invalid group name */
20 BPF_LOADER_ERRNO__EVENTNAME, /* Event name is missing */
21 BPF_LOADER_ERRNO__INTERNAL, /* BPF loader internal error */
22 BPF_LOADER_ERRNO__COMPILE, /* Error when compiling BPF scriptlet */
23 __BPF_LOADER_ERRNO__END,
27 #define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
29 typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev,
32 #ifdef HAVE_LIBBPF_SUPPORT
33 struct bpf_object *bpf__prepare_load(const char *filename, bool source);
34 int bpf__strerror_prepare_load(const char *filename, bool source,
35 int err, char *buf, size_t size);
37 struct bpf_object *bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz,
40 void bpf__clear(void);
42 int bpf__probe(struct bpf_object *obj);
43 int bpf__unprobe(struct bpf_object *obj);
44 int bpf__strerror_probe(struct bpf_object *obj, int err,
45 char *buf, size_t size);
47 int bpf__load(struct bpf_object *obj);
48 int bpf__strerror_load(struct bpf_object *obj, int err,
49 char *buf, size_t size);
50 int bpf__foreach_tev(struct bpf_object *obj,
51 bpf_prog_iter_callback_t func, void *arg);
53 static inline struct bpf_object *
54 bpf__prepare_load(const char *filename __maybe_unused,
55 bool source __maybe_unused)
57 pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
58 return ERR_PTR(-ENOTSUP);
61 static inline struct bpf_object *
62 bpf__prepare_load_buffer(void *obj_buf __maybe_unused,
63 size_t obj_buf_sz __maybe_unused)
65 return ERR_PTR(-ENOTSUP);
68 static inline void bpf__clear(void) { }
70 static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
71 static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
72 static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
75 bpf__foreach_tev(struct bpf_object *obj __maybe_unused,
76 bpf_prog_iter_callback_t func __maybe_unused,
77 void *arg __maybe_unused)
83 __bpf_strerror(char *buf, size_t size)
88 "ERROR: eBPF object loading is disabled during compiling.\n",
95 int bpf__strerror_prepare_load(const char *filename __maybe_unused,
96 bool source __maybe_unused,
97 int err __maybe_unused,
98 char *buf, size_t size)
100 return __bpf_strerror(buf, size);
104 bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
105 int err __maybe_unused,
106 char *buf, size_t size)
108 return __bpf_strerror(buf, size);
111 static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused,
112 int err __maybe_unused,
113 char *buf, size_t size)
115 return __bpf_strerror(buf, size);