btf.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /* Copyright (c) 2018 Facebook */
  3. #ifndef _UAPI__LINUX_BTF_H__
  4. #define _UAPI__LINUX_BTF_H__
  5. #include <linux/types.h>
  6. #define BTF_MAGIC 0xeB9F
  7. #define BTF_VERSION 1
  8. struct btf_header {
  9. __u16 magic;
  10. __u8 version;
  11. __u8 flags;
  12. __u32 hdr_len;
  13. /* All offsets are in bytes relative to the end of this header */
  14. __u32 type_off; /* offset of type section */
  15. __u32 type_len; /* length of type section */
  16. __u32 str_off; /* offset of string section */
  17. __u32 str_len; /* length of string section */
  18. };
  19. /* Max # of type identifier */
  20. #define BTF_MAX_TYPE 0x000fffff
  21. /* Max offset into the string section */
  22. #define BTF_MAX_NAME_OFFSET 0x00ffffff
  23. /* Max # of struct/union/enum members or func args */
  24. #define BTF_MAX_VLEN 0xffff
  25. struct btf_type {
  26. __u32 name_off;
  27. /* "info" bits arrangement
  28. * bits 0-15: vlen (e.g. # of struct's members)
  29. * bits 16-23: unused
  30. * bits 24-27: kind (e.g. int, ptr, array...etc)
  31. * bits 28-31: unused
  32. */
  33. __u32 info;
  34. /* "size" is used by INT, ENUM, STRUCT and UNION.
  35. * "size" tells the size of the type it is describing.
  36. *
  37. * "type" is used by PTR, TYPEDEF, VOLATILE, CONST and RESTRICT.
  38. * "type" is a type_id referring to another type.
  39. */
  40. union {
  41. __u32 size;
  42. __u32 type;
  43. };
  44. };
  45. #define BTF_INFO_KIND(info) (((info) >> 24) & 0x0f)
  46. #define BTF_INFO_VLEN(info) ((info) & 0xffff)
  47. #define BTF_KIND_UNKN 0 /* Unknown */
  48. #define BTF_KIND_INT 1 /* Integer */
  49. #define BTF_KIND_PTR 2 /* Pointer */
  50. #define BTF_KIND_ARRAY 3 /* Array */
  51. #define BTF_KIND_STRUCT 4 /* Struct */
  52. #define BTF_KIND_UNION 5 /* Union */
  53. #define BTF_KIND_ENUM 6 /* Enumeration */
  54. #define BTF_KIND_FWD 7 /* Forward */
  55. #define BTF_KIND_TYPEDEF 8 /* Typedef */
  56. #define BTF_KIND_VOLATILE 9 /* Volatile */
  57. #define BTF_KIND_CONST 10 /* Const */
  58. #define BTF_KIND_RESTRICT 11 /* Restrict */
  59. #define BTF_KIND_MAX 11
  60. #define NR_BTF_KINDS 12
  61. /* For some specific BTF_KIND, "struct btf_type" is immediately
  62. * followed by extra data.
  63. */
  64. /* BTF_KIND_INT is followed by a u32 and the following
  65. * is the 32 bits arrangement:
  66. */
  67. #define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24)
  68. #define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16)
  69. #define BTF_INT_BITS(VAL) ((VAL) & 0x000000ff)
  70. /* Attributes stored in the BTF_INT_ENCODING */
  71. #define BTF_INT_SIGNED (1 << 0)
  72. #define BTF_INT_CHAR (1 << 1)
  73. #define BTF_INT_BOOL (1 << 2)
  74. /* BTF_KIND_ENUM is followed by multiple "struct btf_enum".
  75. * The exact number of btf_enum is stored in the vlen (of the
  76. * info in "struct btf_type").
  77. */
  78. struct btf_enum {
  79. __u32 name_off;
  80. __s32 val;
  81. };
  82. /* BTF_KIND_ARRAY is followed by one "struct btf_array" */
  83. struct btf_array {
  84. __u32 type;
  85. __u32 index_type;
  86. __u32 nelems;
  87. };
  88. /* BTF_KIND_STRUCT and BTF_KIND_UNION are followed
  89. * by multiple "struct btf_member". The exact number
  90. * of btf_member is stored in the vlen (of the info in
  91. * "struct btf_type").
  92. */
  93. struct btf_member {
  94. __u32 name_off;
  95. __u32 type;
  96. __u32 offset; /* offset in bits */
  97. };
  98. #endif /* _UAPI__LINUX_BTF_H__ */