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 9.4KB

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