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__PROGCONF_TERM
,/* Invalid program config term in config string */
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 */
27 __BPF_LOADER_ERRNO__END
,
31 #define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
33 typedef int (*bpf_prog_iter_callback_t
)(struct probe_trace_event
*tev
,
36 #ifdef HAVE_LIBBPF_SUPPORT
37 struct bpf_object
*bpf__prepare_load(const char *filename
, bool source
);
38 int bpf__strerror_prepare_load(const char *filename
, bool source
,
39 int err
, char *buf
, size_t size
);
41 struct bpf_object
*bpf__prepare_load_buffer(void *obj_buf
, size_t obj_buf_sz
,
44 void bpf__clear(void);
46 int bpf__probe(struct bpf_object
*obj
);
47 int bpf__unprobe(struct bpf_object
*obj
);
48 int bpf__strerror_probe(struct bpf_object
*obj
, int err
,
49 char *buf
, size_t size
);
51 int bpf__load(struct bpf_object
*obj
);
52 int bpf__strerror_load(struct bpf_object
*obj
, int err
,
53 char *buf
, size_t size
);
54 int bpf__foreach_tev(struct bpf_object
*obj
,
55 bpf_prog_iter_callback_t func
, void *arg
);
57 static inline struct bpf_object
*
58 bpf__prepare_load(const char *filename __maybe_unused
,
59 bool source __maybe_unused
)
61 pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
62 return ERR_PTR(-ENOTSUP
);
65 static inline struct bpf_object
*
66 bpf__prepare_load_buffer(void *obj_buf __maybe_unused
,
67 size_t obj_buf_sz __maybe_unused
)
69 return ERR_PTR(-ENOTSUP
);
72 static inline void bpf__clear(void) { }
74 static inline int bpf__probe(struct bpf_object
*obj __maybe_unused
) { return 0;}
75 static inline int bpf__unprobe(struct bpf_object
*obj __maybe_unused
) { return 0;}
76 static inline int bpf__load(struct bpf_object
*obj __maybe_unused
) { return 0; }
79 bpf__foreach_tev(struct bpf_object
*obj __maybe_unused
,
80 bpf_prog_iter_callback_t func __maybe_unused
,
81 void *arg __maybe_unused
)
87 __bpf_strerror(char *buf
, size_t size
)
92 "ERROR: eBPF object loading is disabled during compiling.\n",
99 int 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
)
104 return __bpf_strerror(buf
, size
);
108 bpf__strerror_probe(struct bpf_object
*obj __maybe_unused
,
109 int err __maybe_unused
,
110 char *buf
, size_t size
)
112 return __bpf_strerror(buf
, size
);
115 static inline int bpf__strerror_load(struct bpf_object
*obj __maybe_unused
,
116 int err __maybe_unused
,
117 char *buf
, size_t size
)
119 return __bpf_strerror(buf
, size
);