2 * Common eBPF ELF object loading operations.
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.
13 #include <linux/err.h>
16 __LIBBPF_ERRNO__START
= 4000,
18 /* Something wrong in libelf */
19 LIBBPF_ERRNO__LIBELF
= __LIBBPF_ERRNO__START
,
20 LIBBPF_ERRNO__FORMAT
, /* BPF object format invalid */
21 LIBBPF_ERRNO__KVERSION
, /* Incorrect or no 'version' section */
22 LIBBPF_ERRNO__ENDIAN
, /* Endian missmatch */
23 LIBBPF_ERRNO__INTERNAL
, /* Internal error in libbpf */
24 LIBBPF_ERRNO__RELOC
, /* Relocation failed */
25 LIBBPF_ERRNO__LOAD
, /* Load program failure for unknown reason */
26 LIBBPF_ERRNO__VERIFY
, /* Kernel verifier blocks program loading */
27 LIBBPF_ERRNO__PROG2BIG
, /* Program too big */
28 LIBBPF_ERRNO__KVER
, /* Incorrect kernel version */
32 int libbpf_strerror(int err
, char *buf
, size_t size
);
35 * In include/linux/compiler-gcc.h, __printf is defined. However
36 * it should be better if libbpf.h doesn't depend on Linux header file.
37 * So instead of __printf, here we use gcc attribute directly.
39 typedef int (*libbpf_print_fn_t
)(const char *, ...)
40 __attribute__((format(printf
, 1, 2)));
42 void libbpf_set_print(libbpf_print_fn_t warn
,
43 libbpf_print_fn_t info
,
44 libbpf_print_fn_t debug
);
46 /* Hide internal to user */
49 struct bpf_object
*bpf_object__open(const char *path
);
50 struct bpf_object
*bpf_object__open_buffer(void *obj_buf
,
53 void bpf_object__close(struct bpf_object
*object
);
55 /* Load/unload object into/from kernel */
56 int bpf_object__load(struct bpf_object
*obj
);
57 int bpf_object__unload(struct bpf_object
*obj
);
58 const char *bpf_object__get_name(struct bpf_object
*obj
);
59 unsigned int bpf_object__get_kversion(struct bpf_object
*obj
);
61 struct bpf_object
*bpf_object__next(struct bpf_object
*prev
);
62 #define bpf_object__for_each_safe(pos, tmp) \
63 for ((pos) = bpf_object__next(NULL), \
64 (tmp) = bpf_object__next(pos); \
66 (pos) = (tmp), (tmp) = bpf_object__next(tmp))
68 /* Accessors of bpf_program. */
70 struct bpf_program
*bpf_program__next(struct bpf_program
*prog
,
71 struct bpf_object
*obj
);
73 #define bpf_object__for_each_program(pos, obj) \
74 for ((pos) = bpf_program__next(NULL, (obj)); \
76 (pos) = bpf_program__next((pos), (obj)))
78 typedef void (*bpf_program_clear_priv_t
)(struct bpf_program
*,
81 int bpf_program__set_private(struct bpf_program
*prog
, void *priv
,
82 bpf_program_clear_priv_t clear_priv
);
84 int bpf_program__get_private(struct bpf_program
*prog
,
87 const char *bpf_program__title(struct bpf_program
*prog
, bool needs_copy
);
89 int bpf_program__fd(struct bpf_program
*prog
);
92 * We don't need __attribute__((packed)) now since it is
93 * unnecessary for 'bpf_map_def' because they are all aligned.
94 * In addition, using it will trigger -Wpacked warning message,
95 * and will be treated as an error due to -Werror.
99 unsigned int key_size
;
100 unsigned int value_size
;
101 unsigned int max_entries
;