bpf-loader.h 2.2 KB
Newer Older
W
Wang Nan 已提交
1 2 3 4 5 6 7 8 9 10
/*
 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
 * Copyright (C) 2015, Huawei Inc.
 */
#ifndef __BPF_LOADER_H
#define __BPF_LOADER_H

#include <linux/compiler.h>
#include <linux/err.h>
#include <string.h>
11
#include "probe-event.h"
W
Wang Nan 已提交
12 13 14
#include "debug.h"

struct bpf_object;
15
#define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
W
Wang Nan 已提交
16

17 18 19
typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev,
					int fd, void *arg);

W
Wang Nan 已提交
20
#ifdef HAVE_LIBBPF_SUPPORT
21
struct bpf_object *bpf__prepare_load(const char *filename, bool source);
W
Wang Nan 已提交
22 23

void bpf__clear(void);
24 25 26 27 28 29

int bpf__probe(struct bpf_object *obj);
int bpf__unprobe(struct bpf_object *obj);
int bpf__strerror_probe(struct bpf_object *obj, int err,
			char *buf, size_t size);

30 31 32
int bpf__load(struct bpf_object *obj);
int bpf__strerror_load(struct bpf_object *obj, int err,
		       char *buf, size_t size);
33 34
int bpf__foreach_tev(struct bpf_object *obj,
		     bpf_prog_iter_callback_t func, void *arg);
W
Wang Nan 已提交
35 36
#else
static inline struct bpf_object *
37 38
bpf__prepare_load(const char *filename __maybe_unused,
		  bool source __maybe_unused)
W
Wang Nan 已提交
39 40 41 42 43 44
{
	pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
	return ERR_PTR(-ENOTSUP);
}

static inline void bpf__clear(void) { }
45 46 47

static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
48
static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
49

50 51 52 53 54 55 56 57
static inline int
bpf__foreach_tev(struct bpf_object *obj __maybe_unused,
		 bpf_prog_iter_callback_t func __maybe_unused,
		 void *arg __maybe_unused)
{
	return 0;
}

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
static inline int
__bpf_strerror(char *buf, size_t size)
{
	if (!size)
		return 0;
	strncpy(buf,
		"ERROR: eBPF object loading is disabled during compiling.\n",
		size);
	buf[size - 1] = '\0';
	return 0;
}

static inline int
bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
		    int err __maybe_unused,
		    char *buf, size_t size)
{
	return __bpf_strerror(buf, size);
}
77 78 79 80 81 82 83

static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused,
				     int err __maybe_unused,
				     char *buf, size_t size)
{
	return __bpf_strerror(buf, size);
}
W
Wang Nan 已提交
84 85
#endif
#endif