test_btf.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2019 Facebook */
  3. #ifndef _TEST_BTF_H
  4. #define _TEST_BTF_H
  5. #define BTF_END_RAW 0xdeadbeef
  6. #define BTF_INFO_ENC(kind, kind_flag, vlen) \
  7. ((!!(kind_flag) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
  8. #define BTF_TYPE_ENC(name, info, size_or_type) \
  9. (name), (info), (size_or_type)
  10. #define BTF_INT_ENC(encoding, bits_offset, nr_bits) \
  11. ((encoding) << 24 | (bits_offset) << 16 | (nr_bits))
  12. #define BTF_TYPE_INT_ENC(name, encoding, bits_offset, bits, sz) \
  13. BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), sz), \
  14. BTF_INT_ENC(encoding, bits_offset, bits)
  15. #define BTF_FWD_ENC(name, kind_flag) \
  16. BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FWD, kind_flag, 0), 0)
  17. #define BTF_ARRAY_ENC(type, index_type, nr_elems) \
  18. (type), (index_type), (nr_elems)
  19. #define BTF_TYPE_ARRAY_ENC(type, index_type, nr_elems) \
  20. BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY, 0, 0), 0), \
  21. BTF_ARRAY_ENC(type, index_type, nr_elems)
  22. #define BTF_STRUCT_ENC(name, nr_elems, sz) \
  23. BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, nr_elems), sz)
  24. #define BTF_UNION_ENC(name, nr_elems, sz) \
  25. BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_UNION, 0, nr_elems), sz)
  26. #define BTF_VAR_ENC(name, type, linkage) \
  27. BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), type), (linkage)
  28. #define BTF_VAR_SECINFO_ENC(type, offset, size) \
  29. (type), (offset), (size)
  30. #define BTF_MEMBER_ENC(name, type, bits_offset) \
  31. (name), (type), (bits_offset)
  32. #define BTF_ENUM_ENC(name, val) (name), (val)
  33. #define BTF_ENUM64_ENC(name, val_lo32, val_hi32) (name), (val_lo32), (val_hi32)
  34. #define BTF_MEMBER_OFFSET(bitfield_size, bits_offset) \
  35. ((bitfield_size) << 24 | (bits_offset))
  36. #define BTF_TYPEDEF_ENC(name, type) \
  37. BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), type)
  38. #define BTF_PTR_ENC(type) \
  39. BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), type)
  40. #define BTF_CONST_ENC(type) \
  41. BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), type)
  42. #define BTF_VOLATILE_ENC(type) \
  43. BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE, 0, 0), type)
  44. #define BTF_RESTRICT_ENC(type) \
  45. BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_RESTRICT, 0, 0), type)
  46. #define BTF_FUNC_PROTO_ENC(ret_type, nargs) \
  47. BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 0, nargs), ret_type)
  48. #define BTF_FUNC_PROTO_ARG_ENC(name, type) \
  49. (name), (type)
  50. #define BTF_FUNC_ENC(name, func_proto) \
  51. BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FUNC, 0, 0), func_proto)
  52. #define BTF_TYPE_FLOAT_ENC(name, sz) \
  53. BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 0), sz)
  54. #define BTF_DECL_TAG_ENC(value, type, component_idx) \
  55. BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), type), (component_idx)
  56. #define BTF_TYPE_TAG_ENC(value, type) \
  57. BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TYPE_TAG, 0, 0), type)
  58. #endif /* _TEST_BTF_H */