blob: 6f0c13a1fb3ce509685549d9a610cb95eed61b4a [file] [log] [blame]
Wang Nan1b76c132015-07-01 02:13:51 +00001/*
2 * Common eBPF ELF object loading operations.
3 *
4 * Copyright (C) 2013-2015 Alexei Starovoitov <ast@kernel.org>
5 * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com>
6 * Copyright (C) 2015 Huawei Inc.
7 */
8
9#include <stdlib.h>
Wang Nanb3f59d62015-07-01 02:13:52 +000010#include <stdio.h>
11#include <stdarg.h>
12#include <string.h>
Wang Nan1b76c132015-07-01 02:13:51 +000013#include <unistd.h>
14#include <asm/unistd.h>
15#include <linux/bpf.h>
16
17#include "libbpf.h"
Wang Nanb3f59d62015-07-01 02:13:52 +000018
19#define __printf(a, b) __attribute__((format(printf, a, b)))
20
21__printf(1, 2)
22static int __base_pr(const char *format, ...)
23{
24 va_list args;
25 int err;
26
27 va_start(args, format);
28 err = vfprintf(stderr, format, args);
29 va_end(args);
30 return err;
31}
32
33static __printf(1, 2) libbpf_print_fn_t __pr_warning = __base_pr;
34static __printf(1, 2) libbpf_print_fn_t __pr_info = __base_pr;
35static __printf(1, 2) libbpf_print_fn_t __pr_debug;
36
37#define __pr(func, fmt, ...) \
38do { \
39 if ((func)) \
40 (func)("libbpf: " fmt, ##__VA_ARGS__); \
41} while (0)
42
43#define pr_warning(fmt, ...) __pr(__pr_warning, fmt, ##__VA_ARGS__)
44#define pr_info(fmt, ...) __pr(__pr_info, fmt, ##__VA_ARGS__)
45#define pr_debug(fmt, ...) __pr(__pr_debug, fmt, ##__VA_ARGS__)
46
47void libbpf_set_print(libbpf_print_fn_t warn,
48 libbpf_print_fn_t info,
49 libbpf_print_fn_t debug)
50{
51 __pr_warning = warn;
52 __pr_info = info;
53 __pr_debug = debug;
54}