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 #include "libbpf.h" 13 14 #define BTF_INFO_ENC(kind, kind_flag, vlen) \ 15 ((!!(kind_flag) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN)) 16 #define BTF_TYPE_ENC(name, info, size_or_type) (name), (info), (size_or_type) 17 #define BTF_INT_ENC(encoding, bits_offset, nr_bits) \ 18 ((encoding) << 24 | (bits_offset) << 16 | (nr_bits)) 19 #define BTF_TYPE_INT_ENC(name, encoding, bits_offset, bits, sz) \ 20 BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), sz), \ 21 BTF_INT_ENC(encoding, bits_offset, bits) 22 #define BTF_MEMBER_ENC(name, type, bits_offset) (name), (type), (bits_offset) 23 #define BTF_PARAM_ENC(name, type) (name), (type) 24 #define BTF_VAR_SECINFO_ENC(type, offset, size) (type), (offset), (size) 25 26 #ifndef min 27 # define min(x, y) ((x) < (y) ? (x) : (y)) 28 #endif 29 #ifndef max 30 # define max(x, y) ((x) < (y) ? (y) : (x)) 31 #endif 32 33 extern void libbpf_print(enum libbpf_print_level level, 34 const char *format, ...) 35 __attribute__((format(printf, 2, 3))); 36 37 #define __pr(level, fmt, ...) \ 38 do { \ 39 libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \ 40 } while (0) 41 42 #define pr_warning(fmt, ...) __pr(LIBBPF_WARN, fmt, ##__VA_ARGS__) 43 #define pr_info(fmt, ...) __pr(LIBBPF_INFO, fmt, ##__VA_ARGS__) 44 #define pr_debug(fmt, ...) __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__) 45 46 int libbpf__load_raw_btf(const char *raw_types, size_t types_len, 47 const char *str_sec, size_t str_len); 48 49 #endif /* __LIBBPF_LIBBPF_INTERNAL_H */ 50