btf.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
  2. /* Copyright (c) 2018 Facebook */
  3. /*! \file */
  4. #ifndef __LIBBPF_BTF_H
  5. #define __LIBBPF_BTF_H
  6. #include <stdarg.h>
  7. #include <stdbool.h>
  8. #include <linux/btf.h>
  9. #include <linux/types.h>
  10. #include "libbpf_common.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define BTF_ELF_SEC ".BTF"
  15. #define BTF_EXT_ELF_SEC ".BTF.ext"
  16. #define MAPS_ELF_SEC ".maps"
  17. struct btf;
  18. struct btf_ext;
  19. struct btf_type;
  20. struct bpf_object;
  21. enum btf_endianness {
  22. BTF_LITTLE_ENDIAN = 0,
  23. BTF_BIG_ENDIAN = 1,
  24. };
  25. /**
  26. * @brief **btf__free()** frees all data of a BTF object
  27. * @param btf BTF object to free
  28. */
  29. LIBBPF_API void btf__free(struct btf *btf);
  30. /**
  31. * @brief **btf__new()** creates a new instance of a BTF object from the raw
  32. * bytes of an ELF's BTF section
  33. * @param data raw bytes
  34. * @param size number of bytes passed in `data`
  35. * @return new BTF object instance which has to be eventually freed with
  36. * **btf__free()**
  37. *
  38. * On error, error-code-encoded-as-pointer is returned, not a NULL. To extract
  39. * error code from such a pointer `libbpf_get_error()` should be used. If
  40. * `libbpf_set_strict_mode(LIBBPF_STRICT_CLEAN_PTRS)` is enabled, NULL is
  41. * returned on error instead. In both cases thread-local `errno` variable is
  42. * always set to error code as well.
  43. */
  44. LIBBPF_API struct btf *btf__new(const void *data, __u32 size);
  45. /**
  46. * @brief **btf__new_split()** create a new instance of a BTF object from the
  47. * provided raw data bytes. It takes another BTF instance, **base_btf**, which
  48. * serves as a base BTF, which is extended by types in a newly created BTF
  49. * instance
  50. * @param data raw bytes
  51. * @param size length of raw bytes
  52. * @param base_btf the base BTF object
  53. * @return new BTF object instance which has to be eventually freed with
  54. * **btf__free()**
  55. *
  56. * If *base_btf* is NULL, `btf__new_split()` is equivalent to `btf__new()` and
  57. * creates non-split BTF.
  58. *
  59. * On error, error-code-encoded-as-pointer is returned, not a NULL. To extract
  60. * error code from such a pointer `libbpf_get_error()` should be used. If
  61. * `libbpf_set_strict_mode(LIBBPF_STRICT_CLEAN_PTRS)` is enabled, NULL is
  62. * returned on error instead. In both cases thread-local `errno` variable is
  63. * always set to error code as well.
  64. */
  65. LIBBPF_API struct btf *btf__new_split(const void *data, __u32 size, struct btf *base_btf);
  66. /**
  67. * @brief **btf__new_empty()** creates an empty BTF object. Use
  68. * `btf__add_*()` to populate such BTF object.
  69. * @return new BTF object instance which has to be eventually freed with
  70. * **btf__free()**
  71. *
  72. * On error, error-code-encoded-as-pointer is returned, not a NULL. To extract
  73. * error code from such a pointer `libbpf_get_error()` should be used. If
  74. * `libbpf_set_strict_mode(LIBBPF_STRICT_CLEAN_PTRS)` is enabled, NULL is
  75. * returned on error instead. In both cases thread-local `errno` variable is
  76. * always set to error code as well.
  77. */
  78. LIBBPF_API struct btf *btf__new_empty(void);
  79. /**
  80. * @brief **btf__new_empty_split()** creates an unpopulated BTF object from an
  81. * ELF BTF section except with a base BTF on top of which split BTF should be
  82. * based
  83. * @return new BTF object instance which has to be eventually freed with
  84. * **btf__free()**
  85. *
  86. * If *base_btf* is NULL, `btf__new_empty_split()` is equivalent to
  87. * `btf__new_empty()` and creates non-split BTF.
  88. *
  89. * On error, error-code-encoded-as-pointer is returned, not a NULL. To extract
  90. * error code from such a pointer `libbpf_get_error()` should be used. If
  91. * `libbpf_set_strict_mode(LIBBPF_STRICT_CLEAN_PTRS)` is enabled, NULL is
  92. * returned on error instead. In both cases thread-local `errno` variable is
  93. * always set to error code as well.
  94. */
  95. LIBBPF_API struct btf *btf__new_empty_split(struct btf *base_btf);
  96. LIBBPF_API struct btf *btf__parse(const char *path, struct btf_ext **btf_ext);
  97. LIBBPF_API struct btf *btf__parse_split(const char *path, struct btf *base_btf);
  98. LIBBPF_API struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext);
  99. LIBBPF_API struct btf *btf__parse_elf_split(const char *path, struct btf *base_btf);
  100. LIBBPF_API struct btf *btf__parse_raw(const char *path);
  101. LIBBPF_API struct btf *btf__parse_raw_split(const char *path, struct btf *base_btf);
  102. LIBBPF_API struct btf *btf__load_vmlinux_btf(void);
  103. LIBBPF_API struct btf *btf__load_module_btf(const char *module_name, struct btf *vmlinux_btf);
  104. LIBBPF_API struct btf *btf__load_from_kernel_by_id(__u32 id);
  105. LIBBPF_API struct btf *btf__load_from_kernel_by_id_split(__u32 id, struct btf *base_btf);
  106. LIBBPF_API int btf__load_into_kernel(struct btf *btf);
  107. LIBBPF_API __s32 btf__find_by_name(const struct btf *btf,
  108. const char *type_name);
  109. LIBBPF_API __s32 btf__find_by_name_kind(const struct btf *btf,
  110. const char *type_name, __u32 kind);
  111. LIBBPF_API __u32 btf__type_cnt(const struct btf *btf);
  112. LIBBPF_API const struct btf *btf__base_btf(const struct btf *btf);
  113. LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
  114. __u32 id);
  115. LIBBPF_API size_t btf__pointer_size(const struct btf *btf);
  116. LIBBPF_API int btf__set_pointer_size(struct btf *btf, size_t ptr_sz);
  117. LIBBPF_API enum btf_endianness btf__endianness(const struct btf *btf);
  118. LIBBPF_API int btf__set_endianness(struct btf *btf, enum btf_endianness endian);
  119. LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
  120. LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id);
  121. LIBBPF_API int btf__align_of(const struct btf *btf, __u32 id);
  122. LIBBPF_API int btf__fd(const struct btf *btf);
  123. LIBBPF_API void btf__set_fd(struct btf *btf, int fd);
  124. LIBBPF_API const void *btf__raw_data(const struct btf *btf, __u32 *size);
  125. LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
  126. LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset);
  127. LIBBPF_API struct btf_ext *btf_ext__new(const __u8 *data, __u32 size);
  128. LIBBPF_API void btf_ext__free(struct btf_ext *btf_ext);
  129. LIBBPF_API const void *btf_ext__raw_data(const struct btf_ext *btf_ext, __u32 *size);
  130. LIBBPF_API int btf__find_str(struct btf *btf, const char *s);
  131. LIBBPF_API int btf__add_str(struct btf *btf, const char *s);
  132. LIBBPF_API int btf__add_type(struct btf *btf, const struct btf *src_btf,
  133. const struct btf_type *src_type);
  134. /**
  135. * @brief **btf__add_btf()** appends all the BTF types from *src_btf* into *btf*
  136. * @param btf BTF object which all the BTF types and strings are added to
  137. * @param src_btf BTF object which all BTF types and referenced strings are copied from
  138. * @return BTF type ID of the first appended BTF type, or negative error code
  139. *
  140. * **btf__add_btf()** can be used to simply and efficiently append the entire
  141. * contents of one BTF object to another one. All the BTF type data is copied
  142. * over, all referenced type IDs are adjusted by adding a necessary ID offset.
  143. * Only strings referenced from BTF types are copied over and deduplicated, so
  144. * if there were some unused strings in *src_btf*, those won't be copied over,
  145. * which is consistent with the general string deduplication semantics of BTF
  146. * writing APIs.
  147. *
  148. * If any error is encountered during this process, the contents of *btf* is
  149. * left intact, which means that **btf__add_btf()** follows the transactional
  150. * semantics and the operation as a whole is all-or-nothing.
  151. *
  152. * *src_btf* has to be non-split BTF, as of now copying types from split BTF
  153. * is not supported and will result in -ENOTSUP error code returned.
  154. */
  155. LIBBPF_API int btf__add_btf(struct btf *btf, const struct btf *src_btf);
  156. LIBBPF_API int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding);
  157. LIBBPF_API int btf__add_float(struct btf *btf, const char *name, size_t byte_sz);
  158. LIBBPF_API int btf__add_ptr(struct btf *btf, int ref_type_id);
  159. LIBBPF_API int btf__add_array(struct btf *btf,
  160. int index_type_id, int elem_type_id, __u32 nr_elems);
  161. /* struct/union construction APIs */
  162. LIBBPF_API int btf__add_struct(struct btf *btf, const char *name, __u32 sz);
  163. LIBBPF_API int btf__add_union(struct btf *btf, const char *name, __u32 sz);
  164. LIBBPF_API int btf__add_field(struct btf *btf, const char *name, int field_type_id,
  165. __u32 bit_offset, __u32 bit_size);
  166. /* enum construction APIs */
  167. LIBBPF_API int btf__add_enum(struct btf *btf, const char *name, __u32 bytes_sz);
  168. LIBBPF_API int btf__add_enum_value(struct btf *btf, const char *name, __s64 value);
  169. LIBBPF_API int btf__add_enum64(struct btf *btf, const char *name, __u32 bytes_sz, bool is_signed);
  170. LIBBPF_API int btf__add_enum64_value(struct btf *btf, const char *name, __u64 value);
  171. enum btf_fwd_kind {
  172. BTF_FWD_STRUCT = 0,
  173. BTF_FWD_UNION = 1,
  174. BTF_FWD_ENUM = 2,
  175. };
  176. LIBBPF_API int btf__add_fwd(struct btf *btf, const char *name, enum btf_fwd_kind fwd_kind);
  177. LIBBPF_API int btf__add_typedef(struct btf *btf, const char *name, int ref_type_id);
  178. LIBBPF_API int btf__add_volatile(struct btf *btf, int ref_type_id);
  179. LIBBPF_API int btf__add_const(struct btf *btf, int ref_type_id);
  180. LIBBPF_API int btf__add_restrict(struct btf *btf, int ref_type_id);
  181. LIBBPF_API int btf__add_type_tag(struct btf *btf, const char *value, int ref_type_id);
  182. /* func and func_proto construction APIs */
  183. LIBBPF_API int btf__add_func(struct btf *btf, const char *name,
  184. enum btf_func_linkage linkage, int proto_type_id);
  185. LIBBPF_API int btf__add_func_proto(struct btf *btf, int ret_type_id);
  186. LIBBPF_API int btf__add_func_param(struct btf *btf, const char *name, int type_id);
  187. /* var & datasec construction APIs */
  188. LIBBPF_API int btf__add_var(struct btf *btf, const char *name, int linkage, int type_id);
  189. LIBBPF_API int btf__add_datasec(struct btf *btf, const char *name, __u32 byte_sz);
  190. LIBBPF_API int btf__add_datasec_var_info(struct btf *btf, int var_type_id,
  191. __u32 offset, __u32 byte_sz);
  192. /* tag construction API */
  193. LIBBPF_API int btf__add_decl_tag(struct btf *btf, const char *value, int ref_type_id,
  194. int component_idx);
  195. struct btf_dedup_opts {
  196. size_t sz;
  197. /* optional .BTF.ext info to dedup along the main BTF info */
  198. struct btf_ext *btf_ext;
  199. /* force hash collisions (used for testing) */
  200. bool force_collisions;
  201. size_t :0;
  202. };
  203. #define btf_dedup_opts__last_field force_collisions
  204. LIBBPF_API int btf__dedup(struct btf *btf, const struct btf_dedup_opts *opts);
  205. struct btf_dump;
  206. struct btf_dump_opts {
  207. size_t sz;
  208. };
  209. #define btf_dump_opts__last_field sz
  210. typedef void (*btf_dump_printf_fn_t)(void *ctx, const char *fmt, va_list args);
  211. LIBBPF_API struct btf_dump *btf_dump__new(const struct btf *btf,
  212. btf_dump_printf_fn_t printf_fn,
  213. void *ctx,
  214. const struct btf_dump_opts *opts);
  215. LIBBPF_API void btf_dump__free(struct btf_dump *d);
  216. LIBBPF_API int btf_dump__dump_type(struct btf_dump *d, __u32 id);
  217. struct btf_dump_emit_type_decl_opts {
  218. /* size of this struct, for forward/backward compatiblity */
  219. size_t sz;
  220. /* optional field name for type declaration, e.g.:
  221. * - struct my_struct <FNAME>
  222. * - void (*<FNAME>)(int)
  223. * - char (*<FNAME>)[123]
  224. */
  225. const char *field_name;
  226. /* extra indentation level (in number of tabs) to emit for multi-line
  227. * type declarations (e.g., anonymous struct); applies for lines
  228. * starting from the second one (first line is assumed to have
  229. * necessary indentation already
  230. */
  231. int indent_level;
  232. /* strip all the const/volatile/restrict mods */
  233. bool strip_mods;
  234. size_t :0;
  235. };
  236. #define btf_dump_emit_type_decl_opts__last_field strip_mods
  237. LIBBPF_API int
  238. btf_dump__emit_type_decl(struct btf_dump *d, __u32 id,
  239. const struct btf_dump_emit_type_decl_opts *opts);
  240. struct btf_dump_type_data_opts {
  241. /* size of this struct, for forward/backward compatibility */
  242. size_t sz;
  243. const char *indent_str;
  244. int indent_level;
  245. /* below match "show" flags for bpf_show_snprintf() */
  246. bool compact; /* no newlines/indentation */
  247. bool skip_names; /* skip member/type names */
  248. bool emit_zeroes; /* show 0-valued fields */
  249. size_t :0;
  250. };
  251. #define btf_dump_type_data_opts__last_field emit_zeroes
  252. LIBBPF_API int
  253. btf_dump__dump_type_data(struct btf_dump *d, __u32 id,
  254. const void *data, size_t data_sz,
  255. const struct btf_dump_type_data_opts *opts);
  256. /*
  257. * A set of helpers for easier BTF types handling.
  258. *
  259. * The inline functions below rely on constants from the kernel headers which
  260. * may not be available for applications including this header file. To avoid
  261. * compilation errors, we define all the constants here that were added after
  262. * the initial introduction of the BTF_KIND* constants.
  263. */
  264. #ifndef BTF_KIND_FUNC
  265. #define BTF_KIND_FUNC 12 /* Function */
  266. #define BTF_KIND_FUNC_PROTO 13 /* Function Proto */
  267. #endif
  268. #ifndef BTF_KIND_VAR
  269. #define BTF_KIND_VAR 14 /* Variable */
  270. #define BTF_KIND_DATASEC 15 /* Section */
  271. #endif
  272. #ifndef BTF_KIND_FLOAT
  273. #define BTF_KIND_FLOAT 16 /* Floating point */
  274. #endif
  275. /* The kernel header switched to enums, so the following were never #defined */
  276. #define BTF_KIND_DECL_TAG 17 /* Decl Tag */
  277. #define BTF_KIND_TYPE_TAG 18 /* Type Tag */
  278. #define BTF_KIND_ENUM64 19 /* Enum for up-to 64bit values */
  279. static inline __u16 btf_kind(const struct btf_type *t)
  280. {
  281. return BTF_INFO_KIND(t->info);
  282. }
  283. static inline __u16 btf_vlen(const struct btf_type *t)
  284. {
  285. return BTF_INFO_VLEN(t->info);
  286. }
  287. static inline bool btf_kflag(const struct btf_type *t)
  288. {
  289. return BTF_INFO_KFLAG(t->info);
  290. }
  291. static inline bool btf_is_void(const struct btf_type *t)
  292. {
  293. return btf_kind(t) == BTF_KIND_UNKN;
  294. }
  295. static inline bool btf_is_int(const struct btf_type *t)
  296. {
  297. return btf_kind(t) == BTF_KIND_INT;
  298. }
  299. static inline bool btf_is_ptr(const struct btf_type *t)
  300. {
  301. return btf_kind(t) == BTF_KIND_PTR;
  302. }
  303. static inline bool btf_is_array(const struct btf_type *t)
  304. {
  305. return btf_kind(t) == BTF_KIND_ARRAY;
  306. }
  307. static inline bool btf_is_struct(const struct btf_type *t)
  308. {
  309. return btf_kind(t) == BTF_KIND_STRUCT;
  310. }
  311. static inline bool btf_is_union(const struct btf_type *t)
  312. {
  313. return btf_kind(t) == BTF_KIND_UNION;
  314. }
  315. static inline bool btf_is_composite(const struct btf_type *t)
  316. {
  317. __u16 kind = btf_kind(t);
  318. return kind == BTF_KIND_STRUCT || kind == BTF_KIND_UNION;
  319. }
  320. static inline bool btf_is_enum(const struct btf_type *t)
  321. {
  322. return btf_kind(t) == BTF_KIND_ENUM;
  323. }
  324. static inline bool btf_is_enum64(const struct btf_type *t)
  325. {
  326. return btf_kind(t) == BTF_KIND_ENUM64;
  327. }
  328. static inline bool btf_is_fwd(const struct btf_type *t)
  329. {
  330. return btf_kind(t) == BTF_KIND_FWD;
  331. }
  332. static inline bool btf_is_typedef(const struct btf_type *t)
  333. {
  334. return btf_kind(t) == BTF_KIND_TYPEDEF;
  335. }
  336. static inline bool btf_is_volatile(const struct btf_type *t)
  337. {
  338. return btf_kind(t) == BTF_KIND_VOLATILE;
  339. }
  340. static inline bool btf_is_const(const struct btf_type *t)
  341. {
  342. return btf_kind(t) == BTF_KIND_CONST;
  343. }
  344. static inline bool btf_is_restrict(const struct btf_type *t)
  345. {
  346. return btf_kind(t) == BTF_KIND_RESTRICT;
  347. }
  348. static inline bool btf_is_mod(const struct btf_type *t)
  349. {
  350. __u16 kind = btf_kind(t);
  351. return kind == BTF_KIND_VOLATILE ||
  352. kind == BTF_KIND_CONST ||
  353. kind == BTF_KIND_RESTRICT ||
  354. kind == BTF_KIND_TYPE_TAG;
  355. }
  356. static inline bool btf_is_func(const struct btf_type *t)
  357. {
  358. return btf_kind(t) == BTF_KIND_FUNC;
  359. }
  360. static inline bool btf_is_func_proto(const struct btf_type *t)
  361. {
  362. return btf_kind(t) == BTF_KIND_FUNC_PROTO;
  363. }
  364. static inline bool btf_is_var(const struct btf_type *t)
  365. {
  366. return btf_kind(t) == BTF_KIND_VAR;
  367. }
  368. static inline bool btf_is_datasec(const struct btf_type *t)
  369. {
  370. return btf_kind(t) == BTF_KIND_DATASEC;
  371. }
  372. static inline bool btf_is_float(const struct btf_type *t)
  373. {
  374. return btf_kind(t) == BTF_KIND_FLOAT;
  375. }
  376. static inline bool btf_is_decl_tag(const struct btf_type *t)
  377. {
  378. return btf_kind(t) == BTF_KIND_DECL_TAG;
  379. }
  380. static inline bool btf_is_type_tag(const struct btf_type *t)
  381. {
  382. return btf_kind(t) == BTF_KIND_TYPE_TAG;
  383. }
  384. static inline bool btf_is_any_enum(const struct btf_type *t)
  385. {
  386. return btf_is_enum(t) || btf_is_enum64(t);
  387. }
  388. static inline bool btf_kind_core_compat(const struct btf_type *t1,
  389. const struct btf_type *t2)
  390. {
  391. return btf_kind(t1) == btf_kind(t2) ||
  392. (btf_is_any_enum(t1) && btf_is_any_enum(t2));
  393. }
  394. static inline __u8 btf_int_encoding(const struct btf_type *t)
  395. {
  396. return BTF_INT_ENCODING(*(__u32 *)(t + 1));
  397. }
  398. static inline __u8 btf_int_offset(const struct btf_type *t)
  399. {
  400. return BTF_INT_OFFSET(*(__u32 *)(t + 1));
  401. }
  402. static inline __u8 btf_int_bits(const struct btf_type *t)
  403. {
  404. return BTF_INT_BITS(*(__u32 *)(t + 1));
  405. }
  406. static inline struct btf_array *btf_array(const struct btf_type *t)
  407. {
  408. return (struct btf_array *)(t + 1);
  409. }
  410. static inline struct btf_enum *btf_enum(const struct btf_type *t)
  411. {
  412. return (struct btf_enum *)(t + 1);
  413. }
  414. struct btf_enum64;
  415. static inline struct btf_enum64 *btf_enum64(const struct btf_type *t)
  416. {
  417. return (struct btf_enum64 *)(t + 1);
  418. }
  419. static inline __u64 btf_enum64_value(const struct btf_enum64 *e)
  420. {
  421. /* struct btf_enum64 is introduced in Linux 6.0, which is very
  422. * bleeding-edge. Here we are avoiding relying on struct btf_enum64
  423. * definition coming from kernel UAPI headers to support wider range
  424. * of system-wide kernel headers.
  425. *
  426. * Given this header can be also included from C++ applications, that
  427. * further restricts C tricks we can use (like using compatible
  428. * anonymous struct). So just treat struct btf_enum64 as
  429. * a three-element array of u32 and access second (lo32) and third
  430. * (hi32) elements directly.
  431. *
  432. * For reference, here is a struct btf_enum64 definition:
  433. *
  434. * const struct btf_enum64 {
  435. * __u32 name_off;
  436. * __u32 val_lo32;
  437. * __u32 val_hi32;
  438. * };
  439. */
  440. const __u32 *e64 = (const __u32 *)e;
  441. return ((__u64)e64[2] << 32) | e64[1];
  442. }
  443. static inline struct btf_member *btf_members(const struct btf_type *t)
  444. {
  445. return (struct btf_member *)(t + 1);
  446. }
  447. /* Get bit offset of a member with specified index. */
  448. static inline __u32 btf_member_bit_offset(const struct btf_type *t,
  449. __u32 member_idx)
  450. {
  451. const struct btf_member *m = btf_members(t) + member_idx;
  452. bool kflag = btf_kflag(t);
  453. return kflag ? BTF_MEMBER_BIT_OFFSET(m->offset) : m->offset;
  454. }
  455. /*
  456. * Get bitfield size of a member, assuming t is BTF_KIND_STRUCT or
  457. * BTF_KIND_UNION. If member is not a bitfield, zero is returned.
  458. */
  459. static inline __u32 btf_member_bitfield_size(const struct btf_type *t,
  460. __u32 member_idx)
  461. {
  462. const struct btf_member *m = btf_members(t) + member_idx;
  463. bool kflag = btf_kflag(t);
  464. return kflag ? BTF_MEMBER_BITFIELD_SIZE(m->offset) : 0;
  465. }
  466. static inline struct btf_param *btf_params(const struct btf_type *t)
  467. {
  468. return (struct btf_param *)(t + 1);
  469. }
  470. static inline struct btf_var *btf_var(const struct btf_type *t)
  471. {
  472. return (struct btf_var *)(t + 1);
  473. }
  474. static inline struct btf_var_secinfo *
  475. btf_var_secinfos(const struct btf_type *t)
  476. {
  477. return (struct btf_var_secinfo *)(t + 1);
  478. }
  479. struct btf_decl_tag;
  480. static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t)
  481. {
  482. return (struct btf_decl_tag *)(t + 1);
  483. }
  484. #ifdef __cplusplus
  485. } /* extern "C" */
  486. #endif
  487. #endif /* __LIBBPF_BTF_H */