perf tools: Fix assertion failure on dynamic entry
[linux-2.6-block.git] / tools / perf / util / bpf-loader.h
CommitLineData
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>
d3e0ce39 11#include <bpf/libbpf.h>
4edf30e3 12#include "probe-event.h"
69d262a9
WN
13#include "debug.h"
14
d3e0ce39
WN
15enum 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 */
0bb93490 23 BPF_LOADER_ERRNO__PROGCONF_TERM,/* Invalid program config term in config string */
bfc077b4
HK
24 BPF_LOADER_ERRNO__PROLOGUE, /* Failed to generate prologue */
25 BPF_LOADER_ERRNO__PROLOGUE2BIG, /* Prologue too big for program */
26 BPF_LOADER_ERRNO__PROLOGUEOOB, /* Offset out of bound for prologue */
d3e0ce39
WN
27 __BPF_LOADER_ERRNO__END,
28};
29
69d262a9 30struct bpf_object;
aa3abf30 31#define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
69d262a9 32
4edf30e3
WN
33typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev,
34 int fd, void *arg);
35
69d262a9 36#ifdef HAVE_LIBBPF_SUPPORT
d509db04 37struct bpf_object *bpf__prepare_load(const char *filename, bool source);
d3e0ce39
WN
38int bpf__strerror_prepare_load(const char *filename, bool source,
39 int err, char *buf, size_t size);
69d262a9 40
ba1fae43
WN
41struct bpf_object *bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz,
42 const char *name);
43
69d262a9 44void bpf__clear(void);
aa3abf30
WN
45
46int bpf__probe(struct bpf_object *obj);
47int bpf__unprobe(struct bpf_object *obj);
48int bpf__strerror_probe(struct bpf_object *obj, int err,
49 char *buf, size_t size);
50
1e5e3ee8
WN
51int bpf__load(struct bpf_object *obj);
52int bpf__strerror_load(struct bpf_object *obj, int err,
53 char *buf, size_t size);
4edf30e3
WN
54int bpf__foreach_tev(struct bpf_object *obj,
55 bpf_prog_iter_callback_t func, void *arg);
69d262a9
WN
56#else
57static inline struct bpf_object *
d509db04
WN
58bpf__prepare_load(const char *filename __maybe_unused,
59 bool source __maybe_unused)
69d262a9
WN
60{
61 pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
62 return ERR_PTR(-ENOTSUP);
63}
64
ba1fae43
WN
65static inline struct bpf_object *
66bpf__prepare_load_buffer(void *obj_buf __maybe_unused,
67 size_t obj_buf_sz __maybe_unused)
68{
69 return ERR_PTR(-ENOTSUP);
70}
71
69d262a9 72static inline void bpf__clear(void) { }
aa3abf30
WN
73
74static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
75static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
1e5e3ee8 76static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
aa3abf30 77
4edf30e3
WN
78static inline int
79bpf__foreach_tev(struct bpf_object *obj __maybe_unused,
80 bpf_prog_iter_callback_t func __maybe_unused,
81 void *arg __maybe_unused)
82{
83 return 0;
84}
85
aa3abf30
WN
86static inline int
87__bpf_strerror(char *buf, size_t size)
88{
89 if (!size)
90 return 0;
91 strncpy(buf,
92 "ERROR: eBPF object loading is disabled during compiling.\n",
93 size);
94 buf[size - 1] = '\0';
95 return 0;
96}
97
d3e0ce39
WN
98static inline
99int bpf__strerror_prepare_load(const char *filename __maybe_unused,
100 bool source __maybe_unused,
101 int err __maybe_unused,
102 char *buf, size_t size)
103{
104 return __bpf_strerror(buf, size);
105}
106
aa3abf30
WN
107static inline int
108bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
109 int err __maybe_unused,
110 char *buf, size_t size)
111{
112 return __bpf_strerror(buf, size);
113}
1e5e3ee8
WN
114
115static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused,
116 int err __maybe_unused,
117 char *buf, size_t size)
118{
119 return __bpf_strerror(buf, size);
120}
69d262a9
WN
121#endif
122#endif