xref: /openbmc/linux/tools/lib/bpf/libbpf_internal.h (revision 4b4f3acc)
1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
2 
3 /*
4  * Internal libbpf helpers.
5  *
6  * Copyright (c) 2019 Facebook
7  */
8 
9 #ifndef __LIBBPF_LIBBPF_INTERNAL_H
10 #define __LIBBPF_LIBBPF_INTERNAL_H
11 
12 #define BTF_INFO_ENC(kind, kind_flag, vlen) \
13 	((!!(kind_flag) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
14 #define BTF_TYPE_ENC(name, info, size_or_type) (name), (info), (size_or_type)
15 #define BTF_INT_ENC(encoding, bits_offset, nr_bits) \
16 	((encoding) << 24 | (bits_offset) << 16 | (nr_bits))
17 #define BTF_TYPE_INT_ENC(name, encoding, bits_offset, bits, sz) \
18 	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), sz), \
19 	BTF_INT_ENC(encoding, bits_offset, bits)
20 #define BTF_MEMBER_ENC(name, type, bits_offset) (name), (type), (bits_offset)
21 #define BTF_PARAM_ENC(name, type) (name), (type)
22 #define BTF_VAR_SECINFO_ENC(type, offset, size) (type), (offset), (size)
23 
24 extern void libbpf_print(enum libbpf_print_level level,
25 			 const char *format, ...)
26 	__attribute__((format(printf, 2, 3)));
27 
28 #define __pr(level, fmt, ...)	\
29 do {				\
30 	libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__);	\
31 } while (0)
32 
33 #define pr_warning(fmt, ...)	__pr(LIBBPF_WARN, fmt, ##__VA_ARGS__)
34 #define pr_info(fmt, ...)	__pr(LIBBPF_INFO, fmt, ##__VA_ARGS__)
35 #define pr_debug(fmt, ...)	__pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__)
36 
37 int libbpf__load_raw_btf(const char *raw_types, size_t types_len,
38 			 const char *str_sec, size_t str_len);
39 
40 #endif /* __LIBBPF_LIBBPF_INTERNAL_H */
41