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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. };
  56. # define BPF_MAP_LOOKUP_ELEM_struct_size \
  57. sizeof(struct BPF_MAP_LOOKUP_ELEM_struct)
  58. # define expected_BPF_MAP_LOOKUP_ELEM_struct_size 24
  59. struct BPF_MAP_UPDATE_ELEM_struct {
  60. uint32_t map_fd;
  61. uint64_t ATTRIBUTE_ALIGNED(8) key;
  62. uint64_t ATTRIBUTE_ALIGNED(8) value;
  63. uint64_t ATTRIBUTE_ALIGNED(8) flags;
  64. };
  65. # define BPF_MAP_UPDATE_ELEM_struct_size \
  66. sizeof(struct BPF_MAP_UPDATE_ELEM_struct)
  67. # define expected_BPF_MAP_UPDATE_ELEM_struct_size 32
  68. struct BPF_MAP_DELETE_ELEM_struct {
  69. uint32_t map_fd;
  70. uint64_t ATTRIBUTE_ALIGNED(8) key;
  71. };
  72. # define BPF_MAP_DELETE_ELEM_struct_size \
  73. sizeof(struct BPF_MAP_DELETE_ELEM_struct)
  74. # define expected_BPF_MAP_DELETE_ELEM_struct_size 16
  75. struct BPF_MAP_GET_NEXT_KEY_struct {
  76. uint32_t map_fd;
  77. uint64_t ATTRIBUTE_ALIGNED(8) key;
  78. uint64_t ATTRIBUTE_ALIGNED(8) next_key;
  79. };
  80. # define BPF_MAP_GET_NEXT_KEY_struct_size \
  81. sizeof(struct BPF_MAP_GET_NEXT_KEY_struct)
  82. # define expected_BPF_MAP_GET_NEXT_KEY_struct_size 24
  83. struct BPF_MAP_FREEZE_struct {
  84. uint32_t map_fd;
  85. };
  86. # define BPF_MAP_FREEZE_struct_size \
  87. sizeof(struct BPF_MAP_FREEZE_struct)
  88. # define expected_BPF_MAP_FREEZE_struct_size 4
  89. struct BPF_PROG_LOAD_struct {
  90. uint32_t prog_type;
  91. uint32_t insn_cnt;
  92. uint64_t ATTRIBUTE_ALIGNED(8) insns;
  93. uint64_t ATTRIBUTE_ALIGNED(8) license;
  94. uint32_t log_level;
  95. uint32_t log_size;
  96. uint64_t ATTRIBUTE_ALIGNED(8) log_buf;
  97. uint32_t kern_version;
  98. uint32_t prog_flags;
  99. char prog_name[BPF_OBJ_NAME_LEN];
  100. uint32_t prog_ifindex;
  101. uint32_t expected_attach_type;
  102. uint32_t prog_btf_fd;
  103. uint32_t func_info_rec_size;
  104. uint64_t ATTRIBUTE_ALIGNED(8) func_info;
  105. uint32_t func_info_cnt;
  106. uint32_t line_info_rec_size;
  107. uint64_t ATTRIBUTE_ALIGNED(8) line_info;
  108. uint32_t line_info_cnt;
  109. };
  110. # define BPF_PROG_LOAD_struct_size \
  111. offsetofend(struct BPF_PROG_LOAD_struct, line_info_cnt)
  112. # define expected_BPF_PROG_LOAD_struct_size 108
  113. struct BPF_OBJ_PIN_struct {
  114. uint64_t ATTRIBUTE_ALIGNED(8) pathname;
  115. uint32_t bpf_fd;
  116. uint32_t file_flags;
  117. };
  118. # define BPF_OBJ_PIN_struct_size \
  119. sizeof(struct BPF_OBJ_PIN_struct)
  120. # define expected_BPF_OBJ_PIN_struct_size 16
  121. # define BPF_OBJ_GET_struct BPF_OBJ_PIN_struct
  122. # define BPF_OBJ_GET_struct_size BPF_OBJ_PIN_struct_size
  123. struct BPF_PROG_ATTACH_struct {
  124. uint32_t target_fd;
  125. uint32_t attach_bpf_fd;
  126. uint32_t attach_type;
  127. uint32_t attach_flags;
  128. };
  129. # define BPF_PROG_ATTACH_struct_size \
  130. sizeof(struct BPF_PROG_ATTACH_struct)
  131. # define expected_BPF_PROG_ATTACH_struct_size 16
  132. struct BPF_PROG_DETACH_struct {
  133. uint32_t target_fd;
  134. uint32_t dummy;
  135. uint32_t attach_type;
  136. };
  137. # define BPF_PROG_DETACH_struct_size \
  138. sizeof(struct BPF_PROG_DETACH_struct)
  139. # define expected_BPF_PROG_DETACH_struct_size 12
  140. struct BPF_PROG_TEST_RUN_struct /* test */ {
  141. uint32_t prog_fd;
  142. uint32_t retval;
  143. uint32_t data_size_in;
  144. uint32_t data_size_out;
  145. uint64_t ATTRIBUTE_ALIGNED(8) data_in;
  146. uint64_t ATTRIBUTE_ALIGNED(8) data_out;
  147. uint32_t repeat;
  148. uint32_t duration;
  149. uint32_t ctx_size_in;
  150. uint32_t ctx_size_out;
  151. uint64_t ATTRIBUTE_ALIGNED(8) ctx_in;
  152. uint64_t ATTRIBUTE_ALIGNED(8) ctx_out;
  153. };
  154. # define BPF_PROG_TEST_RUN_struct_size \
  155. sizeof(struct BPF_PROG_TEST_RUN_struct)
  156. # define expected_BPF_PROG_TEST_RUN_struct_size 64
  157. struct BPF_PROG_GET_NEXT_ID_struct {
  158. uint32_t start_id;
  159. uint32_t next_id;
  160. uint32_t open_flags;
  161. };
  162. # define BPF_PROG_GET_NEXT_ID_struct_size \
  163. sizeof(struct BPF_PROG_GET_NEXT_ID_struct)
  164. # define expected_BPF_PROG_GET_NEXT_ID_struct_size 12
  165. # define BPF_MAP_GET_NEXT_ID_struct BPF_PROG_GET_NEXT_ID_struct
  166. # define BPF_MAP_GET_NEXT_ID_struct_size BPF_PROG_GET_NEXT_ID_struct_size
  167. struct BPF_PROG_GET_FD_BY_ID_struct {
  168. uint32_t prog_id;
  169. uint32_t next_id;
  170. uint32_t open_flags;
  171. };
  172. # define BPF_PROG_GET_FD_BY_ID_struct_size \
  173. sizeof(struct BPF_PROG_GET_FD_BY_ID_struct)
  174. # define expected_BPF_PROG_GET_FD_BY_ID_struct_size 12
  175. struct BPF_MAP_GET_FD_BY_ID_struct {
  176. uint32_t map_id;
  177. uint32_t next_id;
  178. uint32_t open_flags;
  179. };
  180. # define BPF_MAP_GET_FD_BY_ID_struct_size \
  181. sizeof(struct BPF_MAP_GET_FD_BY_ID_struct)
  182. # define expected_BPF_MAP_GET_FD_BY_ID_struct_size 12
  183. struct BPF_OBJ_GET_INFO_BY_FD_struct /* info */ {
  184. uint32_t bpf_fd;
  185. uint32_t info_len;
  186. uint64_t ATTRIBUTE_ALIGNED(8) info;
  187. };
  188. # define BPF_OBJ_GET_INFO_BY_FD_struct_size \
  189. sizeof(struct BPF_OBJ_GET_INFO_BY_FD_struct)
  190. # define expected_BPF_OBJ_GET_INFO_BY_FD_struct_size 16
  191. struct BPF_PROG_QUERY_struct /* query */ {
  192. uint32_t target_fd;
  193. uint32_t attach_type;
  194. uint32_t query_flags;
  195. uint32_t attach_flags;
  196. uint64_t ATTRIBUTE_ALIGNED(8) prog_ids;
  197. uint32_t prog_cnt;
  198. };
  199. # define BPF_PROG_QUERY_struct_size \
  200. offsetofend(struct BPF_PROG_QUERY_struct, prog_cnt)
  201. # define expected_BPF_PROG_QUERY_struct_size 28
  202. struct BPF_RAW_TRACEPOINT_OPEN_struct /* raw_tracepoint */ {
  203. uint64_t ATTRIBUTE_ALIGNED(8) name;
  204. uint32_t prog_fd;
  205. };
  206. # define BPF_RAW_TRACEPOINT_OPEN_struct_size \
  207. offsetofend(struct BPF_RAW_TRACEPOINT_OPEN_struct, prog_fd)
  208. # define expected_BPF_RAW_TRACEPOINT_OPEN_struct_size 12
  209. struct BPF_BTF_LOAD_struct {
  210. uint64_t ATTRIBUTE_ALIGNED(8) btf;
  211. uint64_t ATTRIBUTE_ALIGNED(8) btf_log_buf;
  212. uint32_t btf_size;
  213. uint32_t btf_log_size;
  214. uint32_t btf_log_level;
  215. };
  216. # define BPF_BTF_LOAD_struct_size \
  217. offsetofend(struct BPF_BTF_LOAD_struct, btf_log_level)
  218. # define expected_BPF_BTF_LOAD_struct_size 28
  219. struct BPF_BTF_GET_FD_BY_ID_struct {
  220. uint32_t btf_id;
  221. };
  222. # define BPF_BTF_GET_FD_BY_ID_struct_size \
  223. sizeof(struct BPF_BTF_GET_FD_BY_ID_struct)
  224. # define expected_BPF_BTF_GET_FD_BY_ID_struct_size 4
  225. struct BPF_TASK_FD_QUERY_struct /* task_fd_query */ {
  226. uint32_t pid;
  227. uint32_t fd;
  228. uint32_t flags;
  229. uint32_t buf_len;
  230. uint64_t ATTRIBUTE_ALIGNED(8) buf;
  231. uint32_t prog_id;
  232. uint32_t fd_type;
  233. uint64_t ATTRIBUTE_ALIGNED(8) probe_offset;
  234. uint64_t ATTRIBUTE_ALIGNED(8) probe_addr;
  235. };
  236. # define BPF_TASK_FD_QUERY_struct_size \
  237. sizeof(struct BPF_TASK_FD_QUERY_struct)
  238. # define expected_BPF_TASK_FD_QUERY_struct_size 48
  239. struct bpf_map_info_struct {
  240. uint32_t type;
  241. uint32_t id;
  242. uint32_t key_size;
  243. uint32_t value_size;
  244. uint32_t max_entries;
  245. uint32_t map_flags;
  246. char name[BPF_OBJ_NAME_LEN];
  247. uint32_t ifindex;
  248. /*
  249. * The kernel UAPI is broken by Linux commit
  250. * v4.16-rc1~123^2~109^2~5^2~4 .
  251. */
  252. uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
  253. uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
  254. uint32_t btf_id;
  255. uint32_t btf_key_type_id;
  256. uint32_t btf_value_type_id;
  257. };
  258. # define bpf_map_info_struct_size \
  259. offsetofend(struct bpf_map_info_struct, btf_value_type_id)
  260. # define expected_bpf_map_info_struct_size 76
  261. struct bpf_prog_info_struct {
  262. uint32_t type;
  263. uint32_t id;
  264. uint8_t tag[BPF_TAG_SIZE];
  265. uint32_t jited_prog_len;
  266. uint32_t xlated_prog_len;
  267. uint64_t ATTRIBUTE_ALIGNED(8) jited_prog_insns;
  268. uint64_t ATTRIBUTE_ALIGNED(8) xlated_prog_insns;
  269. uint64_t ATTRIBUTE_ALIGNED(8) load_time;
  270. uint32_t created_by_uid;
  271. uint32_t nr_map_ids;
  272. uint64_t ATTRIBUTE_ALIGNED(8) map_ids;
  273. char name[BPF_OBJ_NAME_LEN];
  274. uint32_t ifindex;
  275. uint32_t gpl_compatible:1;
  276. /*
  277. * The kernel UAPI is broken by Linux commit
  278. * v4.16-rc1~123^2~227^2~5^2~2 .
  279. */
  280. uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
  281. uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
  282. uint32_t nr_jited_ksyms;
  283. uint32_t nr_jited_func_lens;
  284. uint64_t ATTRIBUTE_ALIGNED(8) jited_ksyms;
  285. uint64_t ATTRIBUTE_ALIGNED(8) jited_func_lens;
  286. uint32_t btf_id;
  287. uint32_t func_info_rec_size;
  288. uint64_t ATTRIBUTE_ALIGNED(8) func_info;
  289. uint32_t nr_func_info;
  290. uint32_t nr_line_info;
  291. uint64_t ATTRIBUTE_ALIGNED(8) line_info;
  292. uint64_t ATTRIBUTE_ALIGNED(8) jited_line_info;
  293. uint32_t nr_jited_line_info;
  294. uint32_t line_info_rec_size;
  295. uint32_t jited_line_info_rec_size;
  296. uint32_t nr_prog_tags;
  297. uint64_t ATTRIBUTE_ALIGNED(8) prog_tags;
  298. uint64_t ATTRIBUTE_ALIGNED(8) run_time_ns;
  299. uint64_t ATTRIBUTE_ALIGNED(8) run_cnt;
  300. };
  301. # define bpf_prog_info_struct_size \
  302. sizeof(struct bpf_prog_info_struct)
  303. # define expected_bpf_prog_info_struct_size 208
  304. #endif /* !STRACE_BPF_ATTR_H */