libbpf_internal.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
  2. /*
  3. * Internal libbpf helpers.
  4. *
  5. * Copyright (c) 2019 Facebook
  6. */
  7. #ifndef __LIBBPF_LIBBPF_INTERNAL_H
  8. #define __LIBBPF_LIBBPF_INTERNAL_H
  9. #include <stdlib.h>
  10. #include <limits.h>
  11. #include <errno.h>
  12. #include <linux/err.h>
  13. #include <fcntl.h>
  14. #include <unistd.h>
  15. #include "relo_core.h"
  16. /* make sure libbpf doesn't use kernel-only integer typedefs */
  17. #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
  18. /* prevent accidental re-addition of reallocarray() */
  19. #pragma GCC poison reallocarray
  20. #include "libbpf.h"
  21. #include "btf.h"
  22. #ifndef EM_BPF
  23. #define EM_BPF 247
  24. #endif
  25. #ifndef R_BPF_64_64
  26. #define R_BPF_64_64 1
  27. #endif
  28. #ifndef R_BPF_64_ABS64
  29. #define R_BPF_64_ABS64 2
  30. #endif
  31. #ifndef R_BPF_64_ABS32
  32. #define R_BPF_64_ABS32 3
  33. #endif
  34. #ifndef R_BPF_64_32
  35. #define R_BPF_64_32 10
  36. #endif
  37. #ifndef SHT_LLVM_ADDRSIG
  38. #define SHT_LLVM_ADDRSIG 0x6FFF4C03
  39. #endif
  40. /* if libelf is old and doesn't support mmap(), fall back to read() */
  41. #ifndef ELF_C_READ_MMAP
  42. #define ELF_C_READ_MMAP ELF_C_READ
  43. #endif
  44. /* Older libelf all end up in this expression, for both 32 and 64 bit */
  45. #ifndef ELF64_ST_VISIBILITY
  46. #define ELF64_ST_VISIBILITY(o) ((o) & 0x03)
  47. #endif
  48. #define BTF_INFO_ENC(kind, kind_flag, vlen) \
  49. ((!!(kind_flag) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
  50. #define BTF_TYPE_ENC(name, info, size_or_type) (name), (info), (size_or_type)
  51. #define BTF_INT_ENC(encoding, bits_offset, nr_bits) \
  52. ((encoding) << 24 | (bits_offset) << 16 | (nr_bits))
  53. #define BTF_TYPE_INT_ENC(name, encoding, bits_offset, bits, sz) \
  54. BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), sz), \
  55. BTF_INT_ENC(encoding, bits_offset, bits)
  56. #define BTF_MEMBER_ENC(name, type, bits_offset) (name), (type), (bits_offset)
  57. #define BTF_PARAM_ENC(name, type) (name), (type)
  58. #define BTF_VAR_SECINFO_ENC(type, offset, size) (type), (offset), (size)
  59. #define BTF_TYPE_FLOAT_ENC(name, sz) \
  60. BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 0), sz)
  61. #define BTF_TYPE_DECL_TAG_ENC(value, type, component_idx) \
  62. BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), type), (component_idx)
  63. #define BTF_TYPE_TYPE_TAG_ENC(value, type) \
  64. BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TYPE_TAG, 0, 0), type)
  65. #ifndef likely
  66. #define likely(x) __builtin_expect(!!(x), 1)
  67. #endif
  68. #ifndef unlikely
  69. #define unlikely(x) __builtin_expect(!!(x), 0)
  70. #endif
  71. #ifndef min
  72. # define min(x, y) ((x) < (y) ? (x) : (y))
  73. #endif
  74. #ifndef max
  75. # define max(x, y) ((x) < (y) ? (y) : (x))
  76. #endif
  77. #ifndef offsetofend
  78. # define offsetofend(TYPE, FIELD) \
  79. (offsetof(TYPE, FIELD) + sizeof(((TYPE *)0)->FIELD))
  80. #endif
  81. #ifndef __alias
  82. #define __alias(symbol) __attribute__((alias(#symbol)))
  83. #endif
  84. /* Check whether a string `str` has prefix `pfx`, regardless if `pfx` is
  85. * a string literal known at compilation time or char * pointer known only at
  86. * runtime.
  87. */
  88. #define str_has_pfx(str, pfx) \
  89. (strncmp(str, pfx, __builtin_constant_p(pfx) ? sizeof(pfx) - 1 : strlen(pfx)) == 0)
  90. /* suffix check */
  91. static inline bool str_has_sfx(const char *str, const char *sfx)
  92. {
  93. size_t str_len = strlen(str);
  94. size_t sfx_len = strlen(sfx);
  95. if (sfx_len > str_len)
  96. return false;
  97. return strcmp(str + str_len - sfx_len, sfx) == 0;
  98. }
  99. /* Symbol versioning is different between static and shared library.
  100. * Properly versioned symbols are needed for shared library, but
  101. * only the symbol of the new version is needed for static library.
  102. * Starting with GNU C 10, use symver attribute instead of .symver assembler
  103. * directive, which works better with GCC LTO builds.
  104. */
  105. #if defined(SHARED) && defined(__GNUC__) && __GNUC__ >= 10
  106. #define DEFAULT_VERSION(internal_name, api_name, version) \
  107. __attribute__((symver(#api_name "@@" #version)))
  108. #define COMPAT_VERSION(internal_name, api_name, version) \
  109. __attribute__((symver(#api_name "@" #version)))
  110. #elif defined(SHARED)
  111. #define COMPAT_VERSION(internal_name, api_name, version) \
  112. asm(".symver " #internal_name "," #api_name "@" #version);
  113. #define DEFAULT_VERSION(internal_name, api_name, version) \
  114. asm(".symver " #internal_name "," #api_name "@@" #version);
  115. #else /* !SHARED */
  116. #define COMPAT_VERSION(internal_name, api_name, version)
  117. #define DEFAULT_VERSION(internal_name, api_name, version) \
  118. extern typeof(internal_name) api_name \
  119. __attribute__((alias(#internal_name)));
  120. #endif
  121. extern void libbpf_print(enum libbpf_print_level level,
  122. const char *format, ...)
  123. __attribute__((format(printf, 2, 3)));
  124. #define __pr(level, fmt, ...) \
  125. do { \
  126. libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \
  127. } while (0)
  128. #define pr_warn(fmt, ...) __pr(LIBBPF_WARN, fmt, ##__VA_ARGS__)
  129. #define pr_info(fmt, ...) __pr(LIBBPF_INFO, fmt, ##__VA_ARGS__)
  130. #define pr_debug(fmt, ...) __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__)
  131. #ifndef __has_builtin
  132. #define __has_builtin(x) 0
  133. #endif
  134. struct bpf_link {
  135. int (*detach)(struct bpf_link *link);
  136. void (*dealloc)(struct bpf_link *link);
  137. char *pin_path; /* NULL, if not pinned */
  138. int fd; /* hook FD, -1 if not applicable */
  139. bool disconnected;
  140. };
  141. /*
  142. * Re-implement glibc's reallocarray() for libbpf internal-only use.
  143. * reallocarray(), unfortunately, is not available in all versions of glibc,
  144. * so requires extra feature detection and using reallocarray() stub from
  145. * <tools/libc_compat.h> and COMPAT_NEED_REALLOCARRAY. All this complicates
  146. * build of libbpf unnecessarily and is just a maintenance burden. Instead,
  147. * it's trivial to implement libbpf-specific internal version and use it
  148. * throughout libbpf.
  149. */
  150. static inline void *libbpf_reallocarray(void *ptr, size_t nmemb, size_t size)
  151. {
  152. size_t total;
  153. #if __has_builtin(__builtin_mul_overflow)
  154. if (unlikely(__builtin_mul_overflow(nmemb, size, &total)))
  155. return NULL;
  156. #else
  157. if (size == 0 || nmemb > ULONG_MAX / size)
  158. return NULL;
  159. total = nmemb * size;
  160. #endif
  161. return realloc(ptr, total);
  162. }
  163. /* Copy up to sz - 1 bytes from zero-terminated src string and ensure that dst
  164. * is zero-terminated string no matter what (unless sz == 0, in which case
  165. * it's a no-op). It's conceptually close to FreeBSD's strlcpy(), but differs
  166. * in what is returned. Given this is internal helper, it's trivial to extend
  167. * this, when necessary. Use this instead of strncpy inside libbpf source code.
  168. */
  169. static inline void libbpf_strlcpy(char *dst, const char *src, size_t sz)
  170. {
  171. size_t i;
  172. if (sz == 0)
  173. return;
  174. sz--;
  175. for (i = 0; i < sz && src[i]; i++)
  176. dst[i] = src[i];
  177. dst[i] = '\0';
  178. }
  179. __u32 get_kernel_version(void);
  180. struct btf;
  181. struct btf_type;
  182. struct btf_type *btf_type_by_id(const struct btf *btf, __u32 type_id);
  183. const char *btf_kind_str(const struct btf_type *t);
  184. const struct btf_type *skip_mods_and_typedefs(const struct btf *btf, __u32 id, __u32 *res_id);
  185. static inline enum btf_func_linkage btf_func_linkage(const struct btf_type *t)
  186. {
  187. return (enum btf_func_linkage)(int)btf_vlen(t);
  188. }
  189. static inline __u32 btf_type_info(int kind, int vlen, int kflag)
  190. {
  191. return (kflag << 31) | (kind << 24) | vlen;
  192. }
  193. enum map_def_parts {
  194. MAP_DEF_MAP_TYPE = 0x001,
  195. MAP_DEF_KEY_TYPE = 0x002,
  196. MAP_DEF_KEY_SIZE = 0x004,
  197. MAP_DEF_VALUE_TYPE = 0x008,
  198. MAP_DEF_VALUE_SIZE = 0x010,
  199. MAP_DEF_MAX_ENTRIES = 0x020,
  200. MAP_DEF_MAP_FLAGS = 0x040,
  201. MAP_DEF_NUMA_NODE = 0x080,
  202. MAP_DEF_PINNING = 0x100,
  203. MAP_DEF_INNER_MAP = 0x200,
  204. MAP_DEF_MAP_EXTRA = 0x400,
  205. MAP_DEF_ALL = 0x7ff, /* combination of all above */
  206. };
  207. struct btf_map_def {
  208. enum map_def_parts parts;
  209. __u32 map_type;
  210. __u32 key_type_id;
  211. __u32 key_size;
  212. __u32 value_type_id;
  213. __u32 value_size;
  214. __u32 max_entries;
  215. __u32 map_flags;
  216. __u32 numa_node;
  217. __u32 pinning;
  218. __u64 map_extra;
  219. };
  220. int parse_btf_map_def(const char *map_name, struct btf *btf,
  221. const struct btf_type *def_t, bool strict,
  222. struct btf_map_def *map_def, struct btf_map_def *inner_def);
  223. void *libbpf_add_mem(void **data, size_t *cap_cnt, size_t elem_sz,
  224. size_t cur_cnt, size_t max_cnt, size_t add_cnt);
  225. int libbpf_ensure_mem(void **data, size_t *cap_cnt, size_t elem_sz, size_t need_cnt);
  226. static inline bool libbpf_is_mem_zeroed(const char *p, ssize_t len)
  227. {
  228. while (len > 0) {
  229. if (*p)
  230. return false;
  231. p++;
  232. len--;
  233. }
  234. return true;
  235. }
  236. static inline bool libbpf_validate_opts(const char *opts,
  237. size_t opts_sz, size_t user_sz,
  238. const char *type_name)
  239. {
  240. if (user_sz < sizeof(size_t)) {
  241. pr_warn("%s size (%zu) is too small\n", type_name, user_sz);
  242. return false;
  243. }
  244. if (!libbpf_is_mem_zeroed(opts + opts_sz, (ssize_t)user_sz - opts_sz)) {
  245. pr_warn("%s has non-zero extra bytes\n", type_name);
  246. return false;
  247. }
  248. return true;
  249. }
  250. #define OPTS_VALID(opts, type) \
  251. (!(opts) || libbpf_validate_opts((const char *)opts, \
  252. offsetofend(struct type, \
  253. type##__last_field), \
  254. (opts)->sz, #type))
  255. #define OPTS_HAS(opts, field) \
  256. ((opts) && opts->sz >= offsetofend(typeof(*(opts)), field))
  257. #define OPTS_GET(opts, field, fallback_value) \
  258. (OPTS_HAS(opts, field) ? (opts)->field : fallback_value)
  259. #define OPTS_SET(opts, field, value) \
  260. do { \
  261. if (OPTS_HAS(opts, field)) \
  262. (opts)->field = value; \
  263. } while (0)
  264. #define OPTS_ZEROED(opts, last_nonzero_field) \
  265. ({ \
  266. ssize_t __off = offsetofend(typeof(*(opts)), last_nonzero_field); \
  267. !(opts) || libbpf_is_mem_zeroed((const void *)opts + __off, \
  268. (opts)->sz - __off); \
  269. })
  270. enum kern_feature_id {
  271. /* v4.14: kernel support for program & map names. */
  272. FEAT_PROG_NAME,
  273. /* v5.2: kernel support for global data sections. */
  274. FEAT_GLOBAL_DATA,
  275. /* BTF support */
  276. FEAT_BTF,
  277. /* BTF_KIND_FUNC and BTF_KIND_FUNC_PROTO support */
  278. FEAT_BTF_FUNC,
  279. /* BTF_KIND_VAR and BTF_KIND_DATASEC support */
  280. FEAT_BTF_DATASEC,
  281. /* BTF_FUNC_GLOBAL is supported */
  282. FEAT_BTF_GLOBAL_FUNC,
  283. /* BPF_F_MMAPABLE is supported for arrays */
  284. FEAT_ARRAY_MMAP,
  285. /* kernel support for expected_attach_type in BPF_PROG_LOAD */
  286. FEAT_EXP_ATTACH_TYPE,
  287. /* bpf_probe_read_{kernel,user}[_str] helpers */
  288. FEAT_PROBE_READ_KERN,
  289. /* BPF_PROG_BIND_MAP is supported */
  290. FEAT_PROG_BIND_MAP,
  291. /* Kernel support for module BTFs */
  292. FEAT_MODULE_BTF,
  293. /* BTF_KIND_FLOAT support */
  294. FEAT_BTF_FLOAT,
  295. /* BPF perf link support */
  296. FEAT_PERF_LINK,
  297. /* BTF_KIND_DECL_TAG support */
  298. FEAT_BTF_DECL_TAG,
  299. /* BTF_KIND_TYPE_TAG support */
  300. FEAT_BTF_TYPE_TAG,
  301. /* memcg-based accounting for BPF maps and progs */
  302. FEAT_MEMCG_ACCOUNT,
  303. /* BPF cookie (bpf_get_attach_cookie() BPF helper) support */
  304. FEAT_BPF_COOKIE,
  305. /* BTF_KIND_ENUM64 support and BTF_KIND_ENUM kflag support */
  306. FEAT_BTF_ENUM64,
  307. /* Kernel uses syscall wrapper (CONFIG_ARCH_HAS_SYSCALL_WRAPPER) */
  308. FEAT_SYSCALL_WRAPPER,
  309. __FEAT_CNT,
  310. };
  311. int probe_memcg_account(void);
  312. bool kernel_supports(const struct bpf_object *obj, enum kern_feature_id feat_id);
  313. int bump_rlimit_memlock(void);
  314. int parse_cpu_mask_str(const char *s, bool **mask, int *mask_sz);
  315. int parse_cpu_mask_file(const char *fcpu, bool **mask, int *mask_sz);
  316. int libbpf__load_raw_btf(const char *raw_types, size_t types_len,
  317. const char *str_sec, size_t str_len);
  318. int btf_load_into_kernel(struct btf *btf, char *log_buf, size_t log_sz, __u32 log_level);
  319. struct btf *btf_get_from_fd(int btf_fd, struct btf *base_btf);
  320. void btf_get_kernel_prefix_kind(enum bpf_attach_type attach_type,
  321. const char **prefix, int *kind);
  322. struct btf_ext_info {
  323. /*
  324. * info points to the individual info section (e.g. func_info and
  325. * line_info) from the .BTF.ext. It does not include the __u32 rec_size.
  326. */
  327. void *info;
  328. __u32 rec_size;
  329. __u32 len;
  330. /* optional (maintained internally by libbpf) mapping between .BTF.ext
  331. * section and corresponding ELF section. This is used to join
  332. * information like CO-RE relocation records with corresponding BPF
  333. * programs defined in ELF sections
  334. */
  335. __u32 *sec_idxs;
  336. int sec_cnt;
  337. };
  338. #define for_each_btf_ext_sec(seg, sec) \
  339. for (sec = (seg)->info; \
  340. (void *)sec < (seg)->info + (seg)->len; \
  341. sec = (void *)sec + sizeof(struct btf_ext_info_sec) + \
  342. (seg)->rec_size * sec->num_info)
  343. #define for_each_btf_ext_rec(seg, sec, i, rec) \
  344. for (i = 0, rec = (void *)&(sec)->data; \
  345. i < (sec)->num_info; \
  346. i++, rec = (void *)rec + (seg)->rec_size)
  347. /*
  348. * The .BTF.ext ELF section layout defined as
  349. * struct btf_ext_header
  350. * func_info subsection
  351. *
  352. * The func_info subsection layout:
  353. * record size for struct bpf_func_info in the func_info subsection
  354. * struct btf_sec_func_info for section #1
  355. * a list of bpf_func_info records for section #1
  356. * where struct bpf_func_info mimics one in include/uapi/linux/bpf.h
  357. * but may not be identical
  358. * struct btf_sec_func_info for section #2
  359. * a list of bpf_func_info records for section #2
  360. * ......
  361. *
  362. * Note that the bpf_func_info record size in .BTF.ext may not
  363. * be the same as the one defined in include/uapi/linux/bpf.h.
  364. * The loader should ensure that record_size meets minimum
  365. * requirement and pass the record as is to the kernel. The
  366. * kernel will handle the func_info properly based on its contents.
  367. */
  368. struct btf_ext_header {
  369. __u16 magic;
  370. __u8 version;
  371. __u8 flags;
  372. __u32 hdr_len;
  373. /* All offsets are in bytes relative to the end of this header */
  374. __u32 func_info_off;
  375. __u32 func_info_len;
  376. __u32 line_info_off;
  377. __u32 line_info_len;
  378. /* optional part of .BTF.ext header */
  379. __u32 core_relo_off;
  380. __u32 core_relo_len;
  381. };
  382. struct btf_ext {
  383. union {
  384. struct btf_ext_header *hdr;
  385. void *data;
  386. };
  387. struct btf_ext_info func_info;
  388. struct btf_ext_info line_info;
  389. struct btf_ext_info core_relo_info;
  390. __u32 data_size;
  391. };
  392. struct btf_ext_info_sec {
  393. __u32 sec_name_off;
  394. __u32 num_info;
  395. /* Followed by num_info * record_size number of bytes */
  396. __u8 data[];
  397. };
  398. /* The minimum bpf_func_info checked by the loader */
  399. struct bpf_func_info_min {
  400. __u32 insn_off;
  401. __u32 type_id;
  402. };
  403. /* The minimum bpf_line_info checked by the loader */
  404. struct bpf_line_info_min {
  405. __u32 insn_off;
  406. __u32 file_name_off;
  407. __u32 line_off;
  408. __u32 line_col;
  409. };
  410. typedef int (*type_id_visit_fn)(__u32 *type_id, void *ctx);
  411. typedef int (*str_off_visit_fn)(__u32 *str_off, void *ctx);
  412. int btf_type_visit_type_ids(struct btf_type *t, type_id_visit_fn visit, void *ctx);
  413. int btf_type_visit_str_offs(struct btf_type *t, str_off_visit_fn visit, void *ctx);
  414. int btf_ext_visit_type_ids(struct btf_ext *btf_ext, type_id_visit_fn visit, void *ctx);
  415. int btf_ext_visit_str_offs(struct btf_ext *btf_ext, str_off_visit_fn visit, void *ctx);
  416. __s32 btf__find_by_name_kind_own(const struct btf *btf, const char *type_name,
  417. __u32 kind);
  418. typedef int (*kallsyms_cb_t)(unsigned long long sym_addr, char sym_type,
  419. const char *sym_name, void *ctx);
  420. int libbpf_kallsyms_parse(kallsyms_cb_t cb, void *arg);
  421. /* handle direct returned errors */
  422. static inline int libbpf_err(int ret)
  423. {
  424. if (ret < 0)
  425. errno = -ret;
  426. return ret;
  427. }
  428. /* handle errno-based (e.g., syscall or libc) errors according to libbpf's
  429. * strict mode settings
  430. */
  431. static inline int libbpf_err_errno(int ret)
  432. {
  433. /* errno is already assumed to be set on error */
  434. return ret < 0 ? -errno : ret;
  435. }
  436. /* handle error for pointer-returning APIs, err is assumed to be < 0 always */
  437. static inline void *libbpf_err_ptr(int err)
  438. {
  439. /* set errno on error, this doesn't break anything */
  440. errno = -err;
  441. return NULL;
  442. }
  443. /* handle pointer-returning APIs' error handling */
  444. static inline void *libbpf_ptr(void *ret)
  445. {
  446. /* set errno on error, this doesn't break anything */
  447. if (IS_ERR(ret))
  448. errno = -PTR_ERR(ret);
  449. return IS_ERR(ret) ? NULL : ret;
  450. }
  451. static inline bool str_is_empty(const char *s)
  452. {
  453. return !s || !s[0];
  454. }
  455. static inline bool is_ldimm64_insn(struct bpf_insn *insn)
  456. {
  457. return insn->code == (BPF_LD | BPF_IMM | BPF_DW);
  458. }
  459. /* if fd is stdin, stdout, or stderr, dup to a fd greater than 2
  460. * Takes ownership of the fd passed in, and closes it if calling
  461. * fcntl(fd, F_DUPFD_CLOEXEC, 3).
  462. */
  463. static inline int ensure_good_fd(int fd)
  464. {
  465. int old_fd = fd, saved_errno;
  466. if (fd < 0)
  467. return fd;
  468. if (fd < 3) {
  469. fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
  470. saved_errno = errno;
  471. close(old_fd);
  472. if (fd < 0) {
  473. pr_warn("failed to dup FD %d to FD > 2: %d\n", old_fd, -saved_errno);
  474. errno = saved_errno;
  475. }
  476. }
  477. return fd;
  478. }
  479. /* The following two functions are exposed to bpftool */
  480. int bpf_core_add_cands(struct bpf_core_cand *local_cand,
  481. size_t local_essent_len,
  482. const struct btf *targ_btf,
  483. const char *targ_btf_name,
  484. int targ_start_id,
  485. struct bpf_core_cand_list *cands);
  486. void bpf_core_free_cands(struct bpf_core_cand_list *cands);
  487. struct usdt_manager *usdt_manager_new(struct bpf_object *obj);
  488. void usdt_manager_free(struct usdt_manager *man);
  489. struct bpf_link * usdt_manager_attach_usdt(struct usdt_manager *man,
  490. const struct bpf_program *prog,
  491. pid_t pid, const char *path,
  492. const char *usdt_provider, const char *usdt_name,
  493. __u64 usdt_cookie);
  494. static inline bool is_pow_of_2(size_t x)
  495. {
  496. return x && (x & (x - 1)) == 0;
  497. }
  498. #define PROG_LOAD_ATTEMPTS 5
  499. int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size, int attempts);
  500. #endif /* __LIBBPF_LIBBPF_INTERNAL_H */