blob: b091ceb19c48a661736df2d0a47371fc302c46c5 [file] [log] [blame]
Wang Nan69d262a2015-10-14 12:41:13 +00001/*
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
13struct bpf_object;
Wang Nanaa3abf32015-10-14 12:41:15 +000014#define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
Wang Nan69d262a2015-10-14 12:41:13 +000015
16#ifdef HAVE_LIBBPF_SUPPORT
17struct bpf_object *bpf__prepare_load(const char *filename);
18
19void bpf__clear(void);
Wang Nanaa3abf32015-10-14 12:41:15 +000020
21int bpf__probe(struct bpf_object *obj);
22int bpf__unprobe(struct bpf_object *obj);
23int bpf__strerror_probe(struct bpf_object *obj, int err,
24 char *buf, size_t size);
25
Wang Nan1e5e3ee2015-10-14 12:41:16 +000026int bpf__load(struct bpf_object *obj);
27int bpf__strerror_load(struct bpf_object *obj, int err,
28 char *buf, size_t size);
Wang Nan69d262a2015-10-14 12:41:13 +000029#else
30static inline struct bpf_object *
31bpf__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
37static inline void bpf__clear(void) { }
Wang Nanaa3abf32015-10-14 12:41:15 +000038
39static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
40static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
Wang Nan1e5e3ee2015-10-14 12:41:16 +000041static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
Wang Nanaa3abf32015-10-14 12:41:15 +000042
43static 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
55static inline int
56bpf__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}
Wang Nan1e5e3ee2015-10-14 12:41:16 +000062
63static 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}
Wang Nan69d262a2015-10-14 12:41:13 +000069#endif
70#endif