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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. uint32_t attach_btf_id;
  111. uint32_t attach_prog_fd;
  112. };
  113. # define BPF_PROG_LOAD_struct_size \
  114. offsetofend(struct BPF_PROG_LOAD_struct, attach_prog_fd)
  115. # define expected_BPF_PROG_LOAD_struct_size 116
  116. struct BPF_OBJ_PIN_struct {
  117. uint64_t ATTRIBUTE_ALIGNED(8) pathname;
  118. uint32_t bpf_fd;
  119. uint32_t file_flags;
  120. };
  121. # define BPF_OBJ_PIN_struct_size \
  122. sizeof(struct BPF_OBJ_PIN_struct)
  123. # define expected_BPF_OBJ_PIN_struct_size 16
  124. # define BPF_OBJ_GET_struct BPF_OBJ_PIN_struct
  125. # define BPF_OBJ_GET_struct_size BPF_OBJ_PIN_struct_size
  126. struct BPF_PROG_ATTACH_struct {
  127. uint32_t target_fd;
  128. uint32_t attach_bpf_fd;
  129. uint32_t attach_type;
  130. uint32_t attach_flags;
  131. };
  132. # define BPF_PROG_ATTACH_struct_size \
  133. sizeof(struct BPF_PROG_ATTACH_struct)
  134. # define expected_BPF_PROG_ATTACH_struct_size 16
  135. struct BPF_PROG_DETACH_struct {
  136. uint32_t target_fd;
  137. uint32_t dummy;
  138. uint32_t attach_type;
  139. };
  140. # define BPF_PROG_DETACH_struct_size \
  141. sizeof(struct BPF_PROG_DETACH_struct)
  142. # define expected_BPF_PROG_DETACH_struct_size 12
  143. struct BPF_PROG_TEST_RUN_struct /* test */ {
  144. uint32_t prog_fd;
  145. uint32_t retval;
  146. uint32_t data_size_in;
  147. uint32_t data_size_out;
  148. uint64_t ATTRIBUTE_ALIGNED(8) data_in;
  149. uint64_t ATTRIBUTE_ALIGNED(8) data_out;
  150. uint32_t repeat;
  151. uint32_t duration;
  152. uint32_t ctx_size_in;
  153. uint32_t ctx_size_out;
  154. uint64_t ATTRIBUTE_ALIGNED(8) ctx_in;
  155. uint64_t ATTRIBUTE_ALIGNED(8) ctx_out;
  156. };
  157. # define BPF_PROG_TEST_RUN_struct_size \
  158. sizeof(struct BPF_PROG_TEST_RUN_struct)
  159. # define expected_BPF_PROG_TEST_RUN_struct_size 64
  160. struct BPF_PROG_GET_NEXT_ID_struct {
  161. uint32_t start_id;
  162. uint32_t next_id;
  163. uint32_t open_flags;
  164. };
  165. # define BPF_PROG_GET_NEXT_ID_struct_size \
  166. sizeof(struct BPF_PROG_GET_NEXT_ID_struct)
  167. # define expected_BPF_PROG_GET_NEXT_ID_struct_size 12
  168. # define BPF_MAP_GET_NEXT_ID_struct BPF_PROG_GET_NEXT_ID_struct
  169. # define BPF_MAP_GET_NEXT_ID_struct_size BPF_PROG_GET_NEXT_ID_struct_size
  170. # define BPF_BTF_GET_NEXT_ID_struct BPF_PROG_GET_NEXT_ID_struct
  171. # define BPF_BTF_GET_NEXT_ID_struct_size BPF_PROG_GET_NEXT_ID_struct_size
  172. struct BPF_PROG_GET_FD_BY_ID_struct {
  173. uint32_t prog_id;
  174. uint32_t next_id;
  175. uint32_t open_flags;
  176. };
  177. # define BPF_PROG_GET_FD_BY_ID_struct_size \
  178. sizeof(struct BPF_PROG_GET_FD_BY_ID_struct)
  179. # define expected_BPF_PROG_GET_FD_BY_ID_struct_size 12
  180. struct BPF_MAP_GET_FD_BY_ID_struct {
  181. uint32_t map_id;
  182. uint32_t next_id;
  183. uint32_t open_flags;
  184. };
  185. # define BPF_MAP_GET_FD_BY_ID_struct_size \
  186. sizeof(struct BPF_MAP_GET_FD_BY_ID_struct)
  187. # define expected_BPF_MAP_GET_FD_BY_ID_struct_size 12
  188. struct BPF_OBJ_GET_INFO_BY_FD_struct /* info */ {
  189. uint32_t bpf_fd;
  190. uint32_t info_len;
  191. uint64_t ATTRIBUTE_ALIGNED(8) info;
  192. };
  193. # define BPF_OBJ_GET_INFO_BY_FD_struct_size \
  194. sizeof(struct BPF_OBJ_GET_INFO_BY_FD_struct)
  195. # define expected_BPF_OBJ_GET_INFO_BY_FD_struct_size 16
  196. struct BPF_PROG_QUERY_struct /* query */ {
  197. uint32_t target_fd;
  198. uint32_t attach_type;
  199. uint32_t query_flags;
  200. uint32_t attach_flags;
  201. uint64_t ATTRIBUTE_ALIGNED(8) prog_ids;
  202. uint32_t prog_cnt;
  203. };
  204. # define BPF_PROG_QUERY_struct_size \
  205. offsetofend(struct BPF_PROG_QUERY_struct, prog_cnt)
  206. # define expected_BPF_PROG_QUERY_struct_size 28
  207. struct BPF_RAW_TRACEPOINT_OPEN_struct /* raw_tracepoint */ {
  208. uint64_t ATTRIBUTE_ALIGNED(8) name;
  209. uint32_t prog_fd;
  210. };
  211. # define BPF_RAW_TRACEPOINT_OPEN_struct_size \
  212. offsetofend(struct BPF_RAW_TRACEPOINT_OPEN_struct, prog_fd)
  213. # define expected_BPF_RAW_TRACEPOINT_OPEN_struct_size 12
  214. struct BPF_BTF_LOAD_struct {
  215. uint64_t ATTRIBUTE_ALIGNED(8) btf;
  216. uint64_t ATTRIBUTE_ALIGNED(8) btf_log_buf;
  217. uint32_t btf_size;
  218. uint32_t btf_log_size;
  219. uint32_t btf_log_level;
  220. };
  221. # define BPF_BTF_LOAD_struct_size \
  222. offsetofend(struct BPF_BTF_LOAD_struct, btf_log_level)
  223. # define expected_BPF_BTF_LOAD_struct_size 28
  224. struct BPF_BTF_GET_FD_BY_ID_struct {
  225. uint32_t btf_id;
  226. };
  227. # define BPF_BTF_GET_FD_BY_ID_struct_size \
  228. sizeof(struct BPF_BTF_GET_FD_BY_ID_struct)
  229. # define expected_BPF_BTF_GET_FD_BY_ID_struct_size 4
  230. struct BPF_TASK_FD_QUERY_struct /* task_fd_query */ {
  231. uint32_t pid;
  232. uint32_t fd;
  233. uint32_t flags;
  234. uint32_t buf_len;
  235. uint64_t ATTRIBUTE_ALIGNED(8) buf;
  236. uint32_t prog_id;
  237. uint32_t fd_type;
  238. uint64_t ATTRIBUTE_ALIGNED(8) probe_offset;
  239. uint64_t ATTRIBUTE_ALIGNED(8) probe_addr;
  240. };
  241. # define BPF_TASK_FD_QUERY_struct_size \
  242. sizeof(struct BPF_TASK_FD_QUERY_struct)
  243. # define expected_BPF_TASK_FD_QUERY_struct_size 48
  244. struct bpf_map_info_struct {
  245. uint32_t type;
  246. uint32_t id;
  247. uint32_t key_size;
  248. uint32_t value_size;
  249. uint32_t max_entries;
  250. uint32_t map_flags;
  251. char name[BPF_OBJ_NAME_LEN];
  252. uint32_t ifindex;
  253. /*
  254. * The kernel UAPI is broken by Linux commit
  255. * v4.16-rc1~123^2~109^2~5^2~4 .
  256. */
  257. uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
  258. uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
  259. uint32_t btf_id;
  260. uint32_t btf_key_type_id;
  261. uint32_t btf_value_type_id;
  262. };
  263. # define bpf_map_info_struct_size \
  264. offsetofend(struct bpf_map_info_struct, btf_value_type_id)
  265. # define expected_bpf_map_info_struct_size 76
  266. struct bpf_prog_info_struct {
  267. uint32_t type;
  268. uint32_t id;
  269. uint8_t tag[BPF_TAG_SIZE];
  270. uint32_t jited_prog_len;
  271. uint32_t xlated_prog_len;
  272. uint64_t ATTRIBUTE_ALIGNED(8) jited_prog_insns;
  273. uint64_t ATTRIBUTE_ALIGNED(8) xlated_prog_insns;
  274. uint64_t ATTRIBUTE_ALIGNED(8) load_time;
  275. uint32_t created_by_uid;
  276. uint32_t nr_map_ids;
  277. uint64_t ATTRIBUTE_ALIGNED(8) map_ids;
  278. char name[BPF_OBJ_NAME_LEN];
  279. uint32_t ifindex;
  280. uint32_t gpl_compatible:1;
  281. /*
  282. * The kernel UAPI is broken by Linux commit
  283. * v4.16-rc1~123^2~227^2~5^2~2 .
  284. */
  285. uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
  286. uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
  287. uint32_t nr_jited_ksyms;
  288. uint32_t nr_jited_func_lens;
  289. uint64_t ATTRIBUTE_ALIGNED(8) jited_ksyms;
  290. uint64_t ATTRIBUTE_ALIGNED(8) jited_func_lens;
  291. uint32_t btf_id;
  292. uint32_t func_info_rec_size;
  293. uint64_t ATTRIBUTE_ALIGNED(8) func_info;
  294. uint32_t nr_func_info;
  295. uint32_t nr_line_info;
  296. uint64_t ATTRIBUTE_ALIGNED(8) line_info;
  297. uint64_t ATTRIBUTE_ALIGNED(8) jited_line_info;
  298. uint32_t nr_jited_line_info;
  299. uint32_t line_info_rec_size;
  300. uint32_t jited_line_info_rec_size;
  301. uint32_t nr_prog_tags;
  302. uint64_t ATTRIBUTE_ALIGNED(8) prog_tags;
  303. uint64_t ATTRIBUTE_ALIGNED(8) run_time_ns;
  304. uint64_t ATTRIBUTE_ALIGNED(8) run_cnt;
  305. };
  306. # define bpf_prog_info_struct_size \
  307. sizeof(struct bpf_prog_info_struct)
  308. # define expected_bpf_prog_info_struct_size 208
  309. #endif /* !STRACE_BPF_ATTR_H */