Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bpf_attr.h 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@altlinux.org>
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: LGPL-2.1-or-later
  6. */
  7. #ifndef STRACE_BPF_ATTR_H
  8. # define STRACE_BPF_ATTR_H
  9. /*
  10. * The policy is that all fields of type uint64_t in this header file
  11. * must have ATTRIBUTE_ALIGNED(8).
  12. *
  13. * This should not cause any contradictions with <linux/bpf.h>
  14. * unless the latter is buggy.
  15. *
  16. * By word "buggy" I mean containing such changes as Linux kernel commit
  17. * v4.16-rc1~123^2~109^2~5^2~4.
  18. */
  19. # ifndef BPF_OBJ_NAME_LEN
  20. # define BPF_OBJ_NAME_LEN 16U
  21. # else
  22. # if BPF_OBJ_NAME_LEN != 16U
  23. # error "Unexpected value of BPF_OBJ_NAME_LEN"
  24. # endif
  25. # endif
  26. # ifndef BPF_TAG_SIZE
  27. # define BPF_TAG_SIZE 8
  28. # else
  29. # if BPF_TAG_SIZE != 8
  30. # error "Unexpected value of BPF_TAG_SIZE"
  31. # endif
  32. # endif
  33. struct BPF_MAP_CREATE_struct {
  34. uint32_t map_type;
  35. uint32_t key_size;
  36. uint32_t value_size;
  37. uint32_t max_entries;
  38. uint32_t map_flags;
  39. uint32_t inner_map_fd;
  40. uint32_t numa_node;
  41. char map_name[BPF_OBJ_NAME_LEN];
  42. uint32_t map_ifindex;
  43. uint32_t btf_fd;
  44. uint32_t btf_key_type_id;
  45. uint32_t btf_value_type_id;
  46. };
  47. # define BPF_MAP_CREATE_struct_size \
  48. sizeof(struct BPF_MAP_CREATE_struct)
  49. # define expected_BPF_MAP_CREATE_struct_size 60
  50. struct BPF_MAP_LOOKUP_ELEM_struct {
  51. uint32_t map_fd;
  52. uint64_t ATTRIBUTE_ALIGNED(8) key;
  53. uint64_t ATTRIBUTE_ALIGNED(8) value;
  54. };
  55. # define BPF_MAP_LOOKUP_ELEM_struct_size \
  56. sizeof(struct BPF_MAP_LOOKUP_ELEM_struct)
  57. # define expected_BPF_MAP_LOOKUP_ELEM_struct_size 24
  58. struct BPF_MAP_UPDATE_ELEM_struct {
  59. uint32_t map_fd;
  60. uint64_t ATTRIBUTE_ALIGNED(8) key;
  61. uint64_t ATTRIBUTE_ALIGNED(8) value;
  62. uint64_t ATTRIBUTE_ALIGNED(8) flags;
  63. };
  64. # define BPF_MAP_UPDATE_ELEM_struct_size \
  65. sizeof(struct BPF_MAP_UPDATE_ELEM_struct)
  66. # define expected_BPF_MAP_UPDATE_ELEM_struct_size 32
  67. struct BPF_MAP_DELETE_ELEM_struct {
  68. uint32_t map_fd;
  69. uint64_t ATTRIBUTE_ALIGNED(8) key;
  70. };
  71. # define BPF_MAP_DELETE_ELEM_struct_size \
  72. sizeof(struct BPF_MAP_DELETE_ELEM_struct)
  73. # define expected_BPF_MAP_DELETE_ELEM_struct_size 16
  74. struct BPF_MAP_GET_NEXT_KEY_struct {
  75. uint32_t map_fd;
  76. uint64_t ATTRIBUTE_ALIGNED(8) key;
  77. uint64_t ATTRIBUTE_ALIGNED(8) next_key;
  78. };
  79. # define BPF_MAP_GET_NEXT_KEY_struct_size \
  80. sizeof(struct BPF_MAP_GET_NEXT_KEY_struct)
  81. # define expected_BPF_MAP_GET_NEXT_KEY_struct_size 24
  82. struct BPF_PROG_LOAD_struct {
  83. uint32_t prog_type;
  84. uint32_t insn_cnt;
  85. uint64_t ATTRIBUTE_ALIGNED(8) insns;
  86. uint64_t ATTRIBUTE_ALIGNED(8) license;
  87. uint32_t log_level;
  88. uint32_t log_size;
  89. uint64_t ATTRIBUTE_ALIGNED(8) log_buf;
  90. uint32_t kern_version;
  91. uint32_t prog_flags;
  92. char prog_name[BPF_OBJ_NAME_LEN];
  93. uint32_t prog_ifindex;
  94. uint32_t expected_attach_type;
  95. uint32_t prog_btf_fd;
  96. uint32_t func_info_rec_size;
  97. uint64_t ATTRIBUTE_ALIGNED(8) func_info;
  98. uint32_t func_info_cnt;
  99. uint32_t line_info_rec_size;
  100. uint64_t ATTRIBUTE_ALIGNED(8) line_info;
  101. uint32_t line_info_cnt;
  102. };
  103. # define BPF_PROG_LOAD_struct_size \
  104. offsetofend(struct BPF_PROG_LOAD_struct, line_info_cnt)
  105. # define expected_BPF_PROG_LOAD_struct_size 108
  106. struct BPF_OBJ_PIN_struct {
  107. uint64_t ATTRIBUTE_ALIGNED(8) pathname;
  108. uint32_t bpf_fd;
  109. uint32_t file_flags;
  110. };
  111. # define BPF_OBJ_PIN_struct_size \
  112. sizeof(struct BPF_OBJ_PIN_struct)
  113. # define expected_BPF_OBJ_PIN_struct_size 16
  114. # define BPF_OBJ_GET_struct BPF_OBJ_PIN_struct
  115. # define BPF_OBJ_GET_struct_size BPF_OBJ_PIN_struct_size
  116. struct BPF_PROG_ATTACH_struct {
  117. uint32_t target_fd;
  118. uint32_t attach_bpf_fd;
  119. uint32_t attach_type;
  120. uint32_t attach_flags;
  121. };
  122. # define BPF_PROG_ATTACH_struct_size \
  123. sizeof(struct BPF_PROG_ATTACH_struct)
  124. # define expected_BPF_PROG_ATTACH_struct_size 16
  125. struct BPF_PROG_DETACH_struct {
  126. uint32_t target_fd;
  127. uint32_t dummy;
  128. uint32_t attach_type;
  129. };
  130. # define BPF_PROG_DETACH_struct_size \
  131. sizeof(struct BPF_PROG_DETACH_struct)
  132. # define expected_BPF_PROG_DETACH_struct_size 12
  133. struct BPF_PROG_TEST_RUN_struct /* test */ {
  134. uint32_t prog_fd;
  135. uint32_t retval;
  136. uint32_t data_size_in;
  137. uint32_t data_size_out;
  138. uint64_t ATTRIBUTE_ALIGNED(8) data_in;
  139. uint64_t ATTRIBUTE_ALIGNED(8) data_out;
  140. uint32_t repeat;
  141. uint32_t duration;
  142. };
  143. # define BPF_PROG_TEST_RUN_struct_size \
  144. sizeof(struct BPF_PROG_TEST_RUN_struct)
  145. # define expected_BPF_PROG_TEST_RUN_struct_size 40
  146. struct BPF_PROG_GET_NEXT_ID_struct {
  147. uint32_t start_id;
  148. uint32_t next_id;
  149. uint32_t open_flags;
  150. };
  151. # define BPF_PROG_GET_NEXT_ID_struct_size \
  152. sizeof(struct BPF_PROG_GET_NEXT_ID_struct)
  153. # define expected_BPF_PROG_GET_NEXT_ID_struct_size 12
  154. # define BPF_MAP_GET_NEXT_ID_struct BPF_PROG_GET_NEXT_ID_struct
  155. # define BPF_MAP_GET_NEXT_ID_struct_size BPF_PROG_GET_NEXT_ID_struct_size
  156. struct BPF_PROG_GET_FD_BY_ID_struct {
  157. uint32_t prog_id;
  158. uint32_t next_id;
  159. uint32_t open_flags;
  160. };
  161. # define BPF_PROG_GET_FD_BY_ID_struct_size \
  162. sizeof(struct BPF_PROG_GET_FD_BY_ID_struct)
  163. # define expected_BPF_PROG_GET_FD_BY_ID_struct_size 12
  164. struct BPF_MAP_GET_FD_BY_ID_struct {
  165. uint32_t map_id;
  166. uint32_t next_id;
  167. uint32_t open_flags;
  168. };
  169. # define BPF_MAP_GET_FD_BY_ID_struct_size \
  170. sizeof(struct BPF_MAP_GET_FD_BY_ID_struct)
  171. # define expected_BPF_MAP_GET_FD_BY_ID_struct_size 12
  172. struct BPF_OBJ_GET_INFO_BY_FD_struct /* info */ {
  173. uint32_t bpf_fd;
  174. uint32_t info_len;
  175. uint64_t ATTRIBUTE_ALIGNED(8) info;
  176. };
  177. # define BPF_OBJ_GET_INFO_BY_FD_struct_size \
  178. sizeof(struct BPF_OBJ_GET_INFO_BY_FD_struct)
  179. # define expected_BPF_OBJ_GET_INFO_BY_FD_struct_size 16
  180. struct BPF_PROG_QUERY_struct /* query */ {
  181. uint32_t target_fd;
  182. uint32_t attach_type;
  183. uint32_t query_flags;
  184. uint32_t attach_flags;
  185. uint64_t ATTRIBUTE_ALIGNED(8) prog_ids;
  186. uint32_t prog_cnt;
  187. };
  188. # define BPF_PROG_QUERY_struct_size \
  189. offsetofend(struct BPF_PROG_QUERY_struct, prog_cnt)
  190. # define expected_BPF_PROG_QUERY_struct_size 28
  191. struct BPF_RAW_TRACEPOINT_OPEN_struct /* raw_tracepoint */ {
  192. uint64_t ATTRIBUTE_ALIGNED(8) name;
  193. uint32_t prog_fd;
  194. };
  195. # define BPF_RAW_TRACEPOINT_OPEN_struct_size \
  196. offsetofend(struct BPF_RAW_TRACEPOINT_OPEN_struct, prog_fd)
  197. # define expected_BPF_RAW_TRACEPOINT_OPEN_struct_size 12
  198. struct BPF_BTF_LOAD_struct {
  199. uint64_t ATTRIBUTE_ALIGNED(8) btf;
  200. uint64_t ATTRIBUTE_ALIGNED(8) btf_log_buf;
  201. uint32_t btf_size;
  202. uint32_t btf_log_size;
  203. uint32_t btf_log_level;
  204. };
  205. # define BPF_BTF_LOAD_struct_size \
  206. offsetofend(struct BPF_BTF_LOAD_struct, btf_log_level)
  207. # define expected_BPF_BTF_LOAD_struct_size 28
  208. struct BPF_BTF_GET_FD_BY_ID_struct {
  209. uint32_t btf_id;
  210. };
  211. # define BPF_BTF_GET_FD_BY_ID_struct_size \
  212. sizeof(struct BPF_BTF_GET_FD_BY_ID_struct)
  213. # define expected_BPF_BTF_GET_FD_BY_ID_struct_size 4
  214. struct BPF_TASK_FD_QUERY_struct /* task_fd_query */ {
  215. uint32_t pid;
  216. uint32_t fd;
  217. uint32_t flags;
  218. uint32_t buf_len;
  219. uint64_t ATTRIBUTE_ALIGNED(8) buf;
  220. uint32_t prog_id;
  221. uint32_t fd_type;
  222. uint64_t ATTRIBUTE_ALIGNED(8) probe_offset;
  223. uint64_t ATTRIBUTE_ALIGNED(8) probe_addr;
  224. };
  225. # define BPF_TASK_FD_QUERY_struct_size \
  226. sizeof(struct BPF_TASK_FD_QUERY_struct)
  227. # define expected_BPF_TASK_FD_QUERY_struct_size 48
  228. struct bpf_map_info_struct {
  229. uint32_t type;
  230. uint32_t id;
  231. uint32_t key_size;
  232. uint32_t value_size;
  233. uint32_t max_entries;
  234. uint32_t map_flags;
  235. char name[BPF_OBJ_NAME_LEN];
  236. uint32_t ifindex;
  237. /*
  238. * The kernel UAPI is broken by Linux commit
  239. * v4.16-rc1~123^2~109^2~5^2~4 .
  240. */
  241. uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
  242. uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
  243. uint32_t btf_id;
  244. uint32_t btf_key_type_id;
  245. uint32_t btf_value_type_id;
  246. };
  247. # define bpf_map_info_struct_size \
  248. offsetofend(struct bpf_map_info_struct, btf_value_type_id)
  249. # define expected_bpf_map_info_struct_size 76
  250. struct bpf_prog_info_struct {
  251. uint32_t type;
  252. uint32_t id;
  253. uint8_t tag[BPF_TAG_SIZE];
  254. uint32_t jited_prog_len;
  255. uint32_t xlated_prog_len;
  256. uint64_t ATTRIBUTE_ALIGNED(8) jited_prog_insns;
  257. uint64_t ATTRIBUTE_ALIGNED(8) xlated_prog_insns;
  258. uint64_t ATTRIBUTE_ALIGNED(8) load_time;
  259. uint32_t created_by_uid;
  260. uint32_t nr_map_ids;
  261. uint64_t ATTRIBUTE_ALIGNED(8) map_ids;
  262. char name[BPF_OBJ_NAME_LEN];
  263. uint32_t ifindex;
  264. uint32_t gpl_compatible:1;
  265. /*
  266. * The kernel UAPI is broken by Linux commit
  267. * v4.16-rc1~123^2~227^2~5^2~2 .
  268. */
  269. uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
  270. uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
  271. uint32_t nr_jited_ksyms;
  272. uint32_t nr_jited_func_lens;
  273. uint64_t ATTRIBUTE_ALIGNED(8) jited_ksyms;
  274. uint64_t ATTRIBUTE_ALIGNED(8) jited_func_lens;
  275. uint32_t btf_id;
  276. uint32_t func_info_rec_size;
  277. uint64_t ATTRIBUTE_ALIGNED(8) func_info;
  278. uint32_t nr_func_info;
  279. uint32_t nr_line_info;
  280. uint64_t ATTRIBUTE_ALIGNED(8) line_info;
  281. uint64_t ATTRIBUTE_ALIGNED(8) jited_line_info;
  282. uint32_t nr_jited_line_info;
  283. uint32_t line_info_rec_size;
  284. uint32_t jited_line_info_rec_size;
  285. uint32_t nr_prog_tags;
  286. uint64_t ATTRIBUTE_ALIGNED(8) prog_tags;
  287. };
  288. # define bpf_prog_info_struct_size \
  289. sizeof(struct bpf_prog_info_struct)
  290. # define expected_bpf_prog_info_struct_size 192
  291. #endif /* !STRACE_BPF_ATTR_H */