Lines Matching +full:libbpf +full:- +full:tools
1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
4 * Internal libbpf helpers.
21 /* make sure libbpf doesn't use kernel-only integer typedefs */
24 /* prevent accidental re-addition of reallocarray() */
27 #include "libbpf.h"
93 (offsetof(TYPE, FIELD) + sizeof(((TYPE *)0)->FIELD))
104 (strncmp(str, pfx, __builtin_constant_p(pfx) ? sizeof(pfx) - 1 : strlen(pfx)) == 0)
141 libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \
152 * Re-implement glibc's reallocarray() for libbpf internal-only use.
155 * <tools/libc_compat.h> and COMPAT_NEED_REALLOCARRAY. All this complicates
156 * build of libbpf unnecessarily and is just a maintenance burden. Instead,
157 * it's trivial to implement libbpf-specific internal version and use it
158 * throughout libbpf.
175 /* Copy up to sz - 1 bytes from zero-terminated src string and ensure that dst
176 * is zero-terminated string no matter what (unless sz == 0, in which case
177 * it's a no-op). It's conceptually close to FreeBSD's strlcpy(), but differs
179 * this, when necessary. Use this instead of strncpy inside libbpf source code.
188 sz--; in libbpf_strlcpy()
257 len--; in libbpf_is_mem_zeroed()
270 if (!libbpf_is_mem_zeroed(opts + opts_sz, (ssize_t)user_sz - opts_sz)) { in libbpf_validate_opts()
271 pr_warn("%s has non-zero extra bytes\n", type_name); in libbpf_validate_opts()
281 (opts)->sz, #type))
283 ((opts) && opts->sz >= offsetofend(typeof(*(opts)), field))
285 (OPTS_HAS(opts, field) ? (opts)->field : fallback_value)
289 (opts)->field = value; \
296 (opts)->sz - __off); \
330 /* memcg-based accounting for BPF maps and progs */
360 for (sec = (seg)->info; \
361 (void *)sec < (seg)->info + (seg)->len; \
363 (seg)->rec_size * sec->num_info)
366 for (i = 0, rec = (void *)&(sec)->data; \
367 i < (sec)->num_info; \
368 i++, rec = (void *)rec + (seg)->rec_size)
456 errno = -ret; in libbpf_err()
460 /* handle errno-based (e.g., syscall or libc) errors according to libbpf's
467 return ret < 0 ? -errno : ret; in libbpf_err_errno()
469 /* legacy: on error return -1 directly and don't touch errno */ in libbpf_err_errno()
473 /* handle error for pointer-returning APIs, err is assumed to be < 0 always */
477 errno = -err; in libbpf_err_ptr()
486 /* handle pointer-returning APIs' error handling */
491 errno = -PTR_ERR(ret); in libbpf_ptr()
496 /* legacy: pass-through original pointer */ in libbpf_ptr()
507 return insn->code == (BPF_LD | BPF_IMM | BPF_DW); in is_ldimm64_insn()
525 pr_warn("failed to dup FD %d to FD > 2: %d\n", old_fd, -saved_errno); in ensure_good_fd()