polyphony 0.98 → 0.99

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/examples/io/https_server_sni_2.rb +14 -8
  4. data/ext/polyphony/extconf.rb +6 -5
  5. data/ext/polyphony/libev.h +0 -2
  6. data/lib/polyphony/core/sync.rb +53 -0
  7. data/lib/polyphony/extensions/io.rb +37 -14
  8. data/lib/polyphony/extensions/openssl.rb +1 -1
  9. data/lib/polyphony/version.rb +1 -1
  10. data/test/test_io.rb +6 -7
  11. data/test/test_socket.rb +61 -0
  12. data/test/test_sync.rb +42 -1
  13. data/vendor/liburing/.github/workflows/build.yml +7 -16
  14. data/vendor/liburing/.gitignore +5 -0
  15. data/vendor/liburing/CHANGELOG +23 -1
  16. data/vendor/liburing/Makefile +4 -3
  17. data/vendor/liburing/Makefile.common +1 -0
  18. data/vendor/liburing/README +48 -0
  19. data/vendor/liburing/configure +76 -6
  20. data/vendor/liburing/debian/changelog +11 -0
  21. data/vendor/liburing/debian/control +7 -16
  22. data/vendor/liburing/debian/liburing-dev.manpages +3 -6
  23. data/vendor/liburing/debian/liburing2.install +1 -0
  24. data/vendor/liburing/debian/liburing2.symbols +56 -0
  25. data/vendor/liburing/debian/rules +15 -68
  26. data/vendor/liburing/examples/Makefile +4 -0
  27. data/vendor/liburing/examples/io_uring-close-test.c +123 -0
  28. data/vendor/liburing/examples/io_uring-udp.c +1 -1
  29. data/vendor/liburing/examples/send-zerocopy.c +315 -56
  30. data/vendor/liburing/examples/ucontext-cp.c +2 -17
  31. data/vendor/liburing/liburing-ffi.pc.in +12 -0
  32. data/vendor/liburing/liburing.pc.in +1 -1
  33. data/vendor/liburing/liburing.spec +1 -1
  34. data/vendor/liburing/make-debs.sh +3 -3
  35. data/vendor/liburing/man/IO_URING_CHECK_VERSION.3 +1 -0
  36. data/vendor/liburing/man/IO_URING_VERSION_MAJOR.3 +1 -0
  37. data/vendor/liburing/man/IO_URING_VERSION_MINOR.3 +1 -0
  38. data/vendor/liburing/man/io_uring_buf_ring_add.3 +6 -6
  39. data/vendor/liburing/man/io_uring_check_version.3 +72 -0
  40. data/vendor/liburing/man/io_uring_close_ring_fd.3 +43 -0
  41. data/vendor/liburing/man/io_uring_major_version.3 +1 -0
  42. data/vendor/liburing/man/io_uring_minor_version.3 +1 -0
  43. data/vendor/liburing/man/io_uring_prep_accept.3 +1 -1
  44. data/vendor/liburing/man/io_uring_prep_fgetxattr.3 +1 -0
  45. data/vendor/liburing/man/io_uring_prep_fsetxattr.3 +1 -0
  46. data/vendor/liburing/man/io_uring_prep_getxattr.3 +61 -0
  47. data/vendor/liburing/man/io_uring_prep_link_timeout.3 +94 -0
  48. data/vendor/liburing/man/io_uring_prep_msg_ring.3 +22 -2
  49. data/vendor/liburing/man/io_uring_prep_msg_ring_cqe_flags.3 +1 -0
  50. data/vendor/liburing/man/io_uring_prep_poll_add.3 +1 -1
  51. data/vendor/liburing/man/io_uring_prep_provide_buffers.3 +18 -9
  52. data/vendor/liburing/man/io_uring_prep_readv.3 +3 -3
  53. data/vendor/liburing/man/io_uring_prep_readv2.3 +3 -3
  54. data/vendor/liburing/man/io_uring_prep_recv.3 +5 -5
  55. data/vendor/liburing/man/io_uring_prep_recvmsg.3 +4 -4
  56. data/vendor/liburing/man/io_uring_prep_send.3 +9 -0
  57. data/vendor/liburing/man/io_uring_prep_send_set_addr.3 +38 -0
  58. data/vendor/liburing/man/io_uring_prep_send_zc.3 +39 -7
  59. data/vendor/liburing/man/io_uring_prep_send_zc_fixed.3 +1 -0
  60. data/vendor/liburing/man/io_uring_prep_sendmsg.3 +20 -0
  61. data/vendor/liburing/man/io_uring_prep_sendmsg_zc.3 +1 -0
  62. data/vendor/liburing/man/io_uring_prep_setxattr.3 +64 -0
  63. data/vendor/liburing/man/io_uring_prep_splice.3 +40 -0
  64. data/vendor/liburing/man/io_uring_prep_writev.3 +2 -2
  65. data/vendor/liburing/man/io_uring_prep_writev2.3 +2 -2
  66. data/vendor/liburing/man/io_uring_recvmsg_out.3 +13 -9
  67. data/vendor/liburing/man/io_uring_register.2 +15 -9
  68. data/vendor/liburing/man/io_uring_register_buf_ring.3 +4 -4
  69. data/vendor/liburing/man/io_uring_register_buffers.3 +49 -6
  70. data/vendor/liburing/man/io_uring_register_buffers_sparse.3 +1 -0
  71. data/vendor/liburing/man/io_uring_register_buffers_tags.3 +1 -0
  72. data/vendor/liburing/man/io_uring_register_buffers_update_tag.3 +1 -0
  73. data/vendor/liburing/man/io_uring_register_files.3 +60 -5
  74. data/vendor/liburing/man/io_uring_register_files_tags.3 +1 -0
  75. data/vendor/liburing/man/io_uring_register_files_update.3 +1 -0
  76. data/vendor/liburing/man/io_uring_register_files_update_tag.3 +1 -0
  77. data/vendor/liburing/man/io_uring_setup.2 +31 -2
  78. data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +1 -1
  79. data/vendor/liburing/src/Makefile +25 -3
  80. data/vendor/liburing/src/ffi.c +15 -0
  81. data/vendor/liburing/src/include/liburing/io_uring.h +30 -7
  82. data/vendor/liburing/src/include/liburing.h +190 -148
  83. data/vendor/liburing/src/int_flags.h +1 -0
  84. data/vendor/liburing/src/lib.h +5 -16
  85. data/vendor/liburing/src/liburing-ffi.map +172 -0
  86. data/vendor/liburing/src/liburing.map +11 -0
  87. data/vendor/liburing/src/nolibc.c +9 -2
  88. data/vendor/liburing/src/queue.c +2 -2
  89. data/vendor/liburing/src/register.c +66 -96
  90. data/vendor/liburing/src/setup.c +5 -4
  91. data/vendor/liburing/src/version.c +21 -0
  92. data/vendor/liburing/test/232c93d07b74.c +3 -3
  93. data/vendor/liburing/test/35fa71a030ca.c +3 -3
  94. data/vendor/liburing/test/500f9fbadef8.c +2 -0
  95. data/vendor/liburing/test/917257daa0fe.c +1 -1
  96. data/vendor/liburing/test/Makefile +27 -7
  97. data/vendor/liburing/test/a0908ae19763.c +2 -2
  98. data/vendor/liburing/test/a4c0b3decb33.c +2 -2
  99. data/vendor/liburing/test/accept-link.c +4 -4
  100. data/vendor/liburing/test/accept-reuse.c +5 -7
  101. data/vendor/liburing/test/accept.c +34 -31
  102. data/vendor/liburing/test/b19062a56726.c +1 -1
  103. data/vendor/liburing/test/buf-ring.c +58 -4
  104. data/vendor/liburing/test/ce593a6c480a.c +2 -2
  105. data/vendor/liburing/test/close-opath.c +2 -1
  106. data/vendor/liburing/test/connect.c +8 -0
  107. data/vendor/liburing/test/cq-overflow.c +14 -8
  108. data/vendor/liburing/test/d4ae271dfaae.c +1 -1
  109. data/vendor/liburing/test/defer-taskrun.c +64 -9
  110. data/vendor/liburing/test/defer.c +1 -1
  111. data/vendor/liburing/test/double-poll-crash.c +3 -3
  112. data/vendor/liburing/test/eeed8b54e0df.c +8 -3
  113. data/vendor/liburing/test/eploop.c +74 -0
  114. data/vendor/liburing/test/eventfd-ring.c +1 -1
  115. data/vendor/liburing/test/eventfd.c +1 -1
  116. data/vendor/liburing/test/evloop.c +73 -0
  117. data/vendor/liburing/test/exit-no-cleanup.c +1 -1
  118. data/vendor/liburing/test/fadvise.c +1 -1
  119. data/vendor/liburing/test/fc2a85cb02ef.c +3 -3
  120. data/vendor/liburing/test/fd-pass.c +35 -16
  121. data/vendor/liburing/test/file-register.c +61 -0
  122. data/vendor/liburing/test/file-verify.c +2 -2
  123. data/vendor/liburing/test/files-exit-hang-timeout.c +2 -2
  124. data/vendor/liburing/test/fixed-link.c +1 -1
  125. data/vendor/liburing/test/fsnotify.c +118 -0
  126. data/vendor/liburing/test/hardlink.c +1 -1
  127. data/vendor/liburing/test/helpers.c +54 -2
  128. data/vendor/liburing/test/helpers.h +4 -0
  129. data/vendor/liburing/test/io-cancel.c +3 -1
  130. data/vendor/liburing/test/io_uring_passthrough.c +39 -8
  131. data/vendor/liburing/test/io_uring_setup.c +3 -80
  132. data/vendor/liburing/test/iopoll-overflow.c +118 -0
  133. data/vendor/liburing/test/iopoll.c +90 -4
  134. data/vendor/liburing/test/lfs-openat-write.c +7 -9
  135. data/vendor/liburing/test/lfs-openat.c +6 -8
  136. data/vendor/liburing/test/link_drain.c +31 -5
  137. data/vendor/liburing/test/madvise.c +1 -1
  138. data/vendor/liburing/test/msg-ring-flags.c +192 -0
  139. data/vendor/liburing/test/msg-ring-overflow.c +159 -0
  140. data/vendor/liburing/test/msg-ring.c +173 -13
  141. data/vendor/liburing/test/multicqes_drain.c +22 -19
  142. data/vendor/liburing/test/nvme.h +4 -3
  143. data/vendor/liburing/test/pipe-bug.c +95 -0
  144. data/vendor/liburing/test/poll-link.c +3 -3
  145. data/vendor/liburing/test/poll-many.c +41 -19
  146. data/vendor/liburing/test/poll-mshot-overflow.c +105 -2
  147. data/vendor/liburing/test/poll-race-mshot.c +292 -0
  148. data/vendor/liburing/test/poll-race.c +105 -0
  149. data/vendor/liburing/test/poll.c +244 -26
  150. data/vendor/liburing/test/pollfree.c +5 -5
  151. data/vendor/liburing/test/read-before-exit.c +20 -3
  152. data/vendor/liburing/test/read-write.c +2 -0
  153. data/vendor/liburing/test/recv-multishot.c +96 -3
  154. data/vendor/liburing/test/reg-reg-ring.c +90 -0
  155. data/vendor/liburing/test/rename.c +1 -1
  156. data/vendor/liburing/test/ring-leak.c +0 -1
  157. data/vendor/liburing/test/ring-leak2.c +1 -1
  158. data/vendor/liburing/test/ringbuf-read.c +10 -6
  159. data/vendor/liburing/test/send-zerocopy.c +273 -103
  160. data/vendor/liburing/test/send_recv.c +7 -4
  161. data/vendor/liburing/test/sendmsg_fs_cve.c +2 -2
  162. data/vendor/liburing/test/single-issuer.c +7 -9
  163. data/vendor/liburing/test/skip-cqe.c +3 -4
  164. data/vendor/liburing/test/socket.c +0 -1
  165. data/vendor/liburing/test/sq-poll-dup.c +10 -3
  166. data/vendor/liburing/test/sq-poll-kthread.c +1 -1
  167. data/vendor/liburing/test/sq-poll-share.c +3 -2
  168. data/vendor/liburing/test/sqpoll-cancel-hang.c +17 -6
  169. data/vendor/liburing/test/sqpoll-disable-exit.c +4 -4
  170. data/vendor/liburing/test/symlink.c +2 -1
  171. data/vendor/liburing/test/test.h +2 -1
  172. data/vendor/liburing/test/timeout-new.c +11 -7
  173. data/vendor/liburing/test/timeout.c +1 -2
  174. data/vendor/liburing/test/unlink.c +1 -1
  175. data/vendor/liburing/test/version.c +25 -0
  176. data/vendor/liburing/test/wakeup-hang.c +1 -1
  177. data/vendor/liburing/test/xattr.c +8 -4
  178. metadata +42 -6
  179. data/vendor/liburing/debian/compat +0 -1
  180. data/vendor/liburing/debian/liburing1-udeb.install +0 -1
  181. data/vendor/liburing/debian/liburing1.install +0 -1
  182. data/vendor/liburing/debian/liburing1.symbols +0 -32
@@ -4,6 +4,7 @@
4
4
 
5
5
  enum {
6
6
  INT_FLAG_REG_RING = 1,
7
+ INT_FLAG_REG_REG_RING = 2,
7
8
  };
8
9
 
9
10
  #endif
@@ -37,25 +37,14 @@
37
37
  #define __hot __attribute__((__hot__))
38
38
  #define __cold __attribute__((__cold__))
39
39
 
40
+ #ifdef CONFIG_NOLIBC
41
+ void *__uring_memset(void *s, int c, size_t n);
40
42
  void *__uring_malloc(size_t len);
41
43
  void __uring_free(void *p);
42
44
 
43
- static inline void *uring_malloc(size_t len)
44
- {
45
- #ifdef CONFIG_NOLIBC
46
- return __uring_malloc(len);
47
- #else
48
- return malloc(len);
49
- #endif
50
- }
51
-
52
- static inline void uring_free(void *ptr)
53
- {
54
- #ifdef CONFIG_NOLIBC
55
- __uring_free(ptr);
56
- #else
57
- free(ptr);
45
+ #define malloc(LEN) __uring_malloc(LEN)
46
+ #define free(PTR) __uring_free(PTR)
47
+ #define memset(PTR, C, LEN) __uring_memset(PTR, C, LEN)
58
48
  #endif
59
- }
60
49
 
61
50
  #endif /* #ifndef LIBURING_LIB_H */
@@ -0,0 +1,172 @@
1
+ LIBURING_2.4 {
2
+ global:
3
+ io_uring_get_probe;
4
+ io_uring_get_probe_ring;
5
+ io_uring_free_probe;
6
+ io_uring_get_sqe;
7
+ io_uring_peek_batch_cqe;
8
+ io_uring_queue_exit;
9
+ io_uring_queue_init;
10
+ io_uring_queue_init_params;
11
+ io_uring_queue_mmap;
12
+ io_uring_register_buffers;
13
+ io_uring_register_eventfd;
14
+ io_uring_register_eventfd_async;
15
+ io_uring_register_files;
16
+ io_uring_register_files_update;
17
+ io_uring_register_personality;
18
+ io_uring_register_probe;
19
+ io_uring_ring_dontfork;
20
+ io_uring_submit;
21
+ io_uring_submit_and_wait;
22
+ io_uring_unregister_buffers;
23
+ io_uring_unregister_eventfd;
24
+ io_uring_unregister_files;
25
+ io_uring_unregister_personality;
26
+ io_uring_wait_cqe_timeout;
27
+ io_uring_wait_cqes;
28
+
29
+ __io_uring_get_cqe;
30
+ __io_uring_sqring_wait;
31
+
32
+ io_uring_mlock_size_params;
33
+ io_uring_mlock_size;
34
+ io_uring_register_buffers_tags;
35
+ io_uring_register_buffers_update_tag;
36
+ io_uring_register_files_tags;
37
+ io_uring_register_files_update_tag;
38
+ io_uring_register_iowq_aff;
39
+ io_uring_unregister_iowq_aff;
40
+ io_uring_register_iowq_max_workers;
41
+
42
+ io_uring_submit_and_wait_timeout;
43
+ io_uring_register_ring_fd;
44
+ io_uring_unregister_ring_fd;
45
+ io_uring_register_files_sparse;
46
+ io_uring_register_buffers_sparse;
47
+ io_uring_register_buf_ring;
48
+ io_uring_unregister_buf_ring;
49
+ io_uring_close_ring_fd;
50
+
51
+ io_uring_register_sync_cancel;
52
+ io_uring_register_file_alloc_range;
53
+ io_uring_enter;
54
+ io_uring_enter2;
55
+ io_uring_setup;
56
+ io_uring_register;
57
+ io_uring_get_events;
58
+ io_uring_submit_and_get_events;
59
+
60
+ io_uring_major_version;
61
+ io_uring_minor_version;
62
+ io_uring_check_version;
63
+
64
+ io_uring_peek_cqe;
65
+ io_uring_prep_timeout_update;
66
+ io_uring_buf_ring_init;
67
+ io_uring_prep_mkdirat;
68
+ io_uring_prep_recv_multishot;
69
+ io_uring_cq_advance;
70
+ io_uring_prep_multishot_accept;
71
+ io_uring_prep_fallocate;
72
+ io_uring_prep_link_timeout;
73
+ io_uring_prep_fsync;
74
+ io_uring_prep_openat_direct;
75
+ io_uring_prep_multishot_accept_direct;
76
+ io_uring_opcode_supported;
77
+ io_uring_prep_madvise;
78
+ io_uring_prep_send_set_addr;
79
+ io_uring_recvmsg_payload_length;
80
+ io_uring_prep_readv2;
81
+ io_uring_prep_msg_ring;
82
+ io_uring_prep_rename;
83
+ io_uring_prep_fadvise;
84
+ io_uring_prep_send_zc;
85
+ io_uring_buf_ring_advance;
86
+ io_uring_cqe_get_data;
87
+ io_uring_prep_symlinkat;
88
+ io_uring_prep_writev;
89
+ io_uring_cq_eventfd_toggle;
90
+ io_uring_prep_provide_buffers;
91
+ io_uring_cq_has_overflow;
92
+ io_uring_prep_cancel_fd;
93
+ io_uring_prep_socket;
94
+ io_uring_prep_close_direct;
95
+ io_uring_recvmsg_name;
96
+ io_uring_prep_timeout_remove;
97
+ io_uring_sqring_wait;
98
+ io_uring_cq_eventfd_enabled;
99
+ io_uring_prep_remove_buffers;
100
+ io_uring_prep_tee;
101
+ io_uring_prep_accept_direct;
102
+ io_uring_prep_nop;
103
+ io_uring_prep_getxattr;
104
+ io_uring_prep_link;
105
+ io_uring_prep_cancel;
106
+ io_uring_prep_readv;
107
+ io_uring_prep_connect;
108
+ io_uring_cq_ready;
109
+ io_uring_enable_rings;
110
+ io_uring_prep_shutdown;
111
+ io_uring_prep_openat;
112
+ io_uring_sq_space_left;
113
+ io_uring_recvmsg_payload;
114
+ io_uring_prep_send;
115
+ io_uring_buf_ring_add;
116
+ io_uring_prep_send_zc_fixed;
117
+ io_uring_prep_epoll_ctl;
118
+ io_uring_recvmsg_cmsg_firsthdr;
119
+ io_uring_prep_socket_direct;
120
+ io_uring_buf_ring_cq_advance;
121
+ io_uring_prep_mkdir;
122
+ io_uring_wait_cqe_nr;
123
+ io_uring_prep_unlink;
124
+ io_uring_prep_writev2;
125
+ io_uring_prep_openat2_direct;
126
+ io_uring_sqe_set_flags;
127
+ io_uring_sqe_set_data;
128
+ io_uring_prep_accept;
129
+ io_uring_prep_poll_update;
130
+ io_uring_prep_splice;
131
+ io_uring_prep_poll_multishot;
132
+ io_uring_prep_symlink;
133
+ io_uring_sqe_set_data64;
134
+ io_uring_prep_cancel64;
135
+ io_uring_prep_fsetxattr;
136
+ io_uring_prep_recvmsg_multishot;
137
+ io_uring_cqe_seen;
138
+ io_uring_prep_sendmsg_zc;
139
+ io_uring_prep_read;
140
+ io_uring_prep_statx;
141
+ io_uring_prep_sendmsg;
142
+ io_uring_prep_unlinkat;
143
+ io_uring_prep_setxattr;
144
+ io_uring_cqe_get_data64;
145
+ io_uring_prep_renameat;
146
+ io_uring_prep_poll_remove;
147
+ io_uring_prep_close;
148
+ io_uring_sq_ready;
149
+ io_uring_prep_files_update;
150
+ io_uring_wait_cqe;
151
+ io_uring_prep_fgetxattr;
152
+ io_uring_prep_socket_direct_alloc;
153
+ io_uring_prep_sync_file_range;
154
+ io_uring_prep_read_fixed;
155
+ io_uring_prep_openat2;
156
+ io_uring_prep_recvmsg;
157
+ io_uring_recvmsg_cmsg_nexthdr;
158
+ io_uring_recvmsg_validate;
159
+ io_uring_prep_rw;
160
+ io_uring_prep_timeout;
161
+ io_uring_prep_linkat;
162
+ io_uring_prep_write_fixed;
163
+ io_uring_prep_poll_add;
164
+ io_uring_buf_ring_mask;
165
+ io_uring_register_restrictions;
166
+ io_uring_prep_write;
167
+ io_uring_prep_recv;
168
+ io_uring_prep_msg_ring_cqe_flags;
169
+ io_uring_prep_msg_ring_fd;
170
+ local:
171
+ *;
172
+ };
@@ -67,3 +67,14 @@ LIBURING_2.3 {
67
67
  io_uring_get_events;
68
68
  io_uring_submit_and_get_events;
69
69
  } LIBURING_2.2;
70
+
71
+ LIBURING_2.4 {
72
+ global:
73
+ io_uring_major_version;
74
+ io_uring_minor_version;
75
+ io_uring_check_version;
76
+
77
+ io_uring_close_ring_fd;
78
+ io_uring_enable_rings;
79
+ io_uring_register_restrictions;
80
+ } LIBURING_2.3;
@@ -7,14 +7,21 @@
7
7
  #include "lib.h"
8
8
  #include "syscall.h"
9
9
 
10
- void *memset(void *s, int c, size_t n)
10
+ void *__uring_memset(void *s, int c, size_t n)
11
11
  {
12
12
  size_t i;
13
13
  unsigned char *p = s;
14
14
 
15
- for (i = 0; i < n; i++)
15
+ for (i = 0; i < n; i++) {
16
16
  p[i] = (unsigned char) c;
17
17
 
18
+ /*
19
+ * An empty inline ASM to avoid auto-vectorization
20
+ * because it's too bloated for liburing.
21
+ */
22
+ __asm__ volatile ("");
23
+ }
24
+
18
25
  return s;
19
26
  }
20
27
 
@@ -81,7 +81,7 @@ static int _io_uring_get_cqe(struct io_uring *ring,
81
81
  }
82
82
  if (!cqe && !data->wait_nr && !data->submit) {
83
83
  /*
84
- * If we already looped once, we already entererd
84
+ * If we already looped once, we already entered
85
85
  * the kernel. Since there's nothing to submit or
86
86
  * wait for, don't keep retrying.
87
87
  */
@@ -201,7 +201,7 @@ again:
201
201
  * Sync internal state with kernel ring state on the SQ side. Returns the
202
202
  * number of pending items in the SQ ring, for the shared ring.
203
203
  */
204
- unsigned __io_uring_flush_sq(struct io_uring *ring)
204
+ static unsigned __io_uring_flush_sq(struct io_uring *ring)
205
205
  {
206
206
  struct io_uring_sq *sq = &ring->sq;
207
207
  unsigned tail = sq->sqe_tail;
@@ -8,6 +8,16 @@
8
8
  #include "liburing/compat.h"
9
9
  #include "liburing/io_uring.h"
10
10
 
11
+ static inline int do_register(struct io_uring *ring, unsigned int opcode,
12
+ const void *arg, unsigned int nr_args)
13
+ {
14
+ if (ring->int_flags & INT_FLAG_REG_REG_RING) {
15
+ opcode |= IORING_REGISTER_USE_REGISTERED_RING;
16
+ return __sys_io_uring_register(ring->enter_ring_fd, opcode, arg, nr_args);
17
+ }
18
+ return __sys_io_uring_register(ring->ring_fd, opcode, arg, nr_args);
19
+ }
20
+
11
21
  int io_uring_register_buffers_update_tag(struct io_uring *ring, unsigned off,
12
22
  const struct iovec *iovecs,
13
23
  const __u64 *tags,
@@ -20,8 +30,7 @@ int io_uring_register_buffers_update_tag(struct io_uring *ring, unsigned off,
20
30
  .nr = nr,
21
31
  };
22
32
 
23
- return __sys_io_uring_register(ring->ring_fd,IORING_REGISTER_BUFFERS_UPDATE, &up,
24
- sizeof(up));
33
+ return do_register(ring, IORING_REGISTER_BUFFERS_UPDATE, &up, sizeof(up));
25
34
  }
26
35
 
27
36
  int io_uring_register_buffers_tags(struct io_uring *ring,
@@ -35,9 +44,7 @@ int io_uring_register_buffers_tags(struct io_uring *ring,
35
44
  .tags = (unsigned long)tags,
36
45
  };
37
46
 
38
- return __sys_io_uring_register(ring->ring_fd,
39
- IORING_REGISTER_BUFFERS2, &reg,
40
- sizeof(reg));
47
+ return do_register(ring, IORING_REGISTER_BUFFERS2, &reg, sizeof(reg));
41
48
  }
42
49
 
43
50
  int io_uring_register_buffers_sparse(struct io_uring *ring, unsigned nr)
@@ -47,27 +54,18 @@ int io_uring_register_buffers_sparse(struct io_uring *ring, unsigned nr)
47
54
  .nr = nr,
48
55
  };
49
56
 
50
- return __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_BUFFERS2,
51
- &reg, sizeof(reg));
57
+ return do_register(ring, IORING_REGISTER_BUFFERS2, &reg, sizeof(reg));
52
58
  }
53
59
 
54
60
  int io_uring_register_buffers(struct io_uring *ring, const struct iovec *iovecs,
55
61
  unsigned nr_iovecs)
56
62
  {
57
- int ret;
58
-
59
- ret = __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_BUFFERS,
60
- iovecs, nr_iovecs);
61
- return (ret < 0) ? ret : 0;
63
+ return do_register(ring, IORING_REGISTER_BUFFERS, iovecs, nr_iovecs);
62
64
  }
63
65
 
64
66
  int io_uring_unregister_buffers(struct io_uring *ring)
65
67
  {
66
- int ret;
67
-
68
- ret = __sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_BUFFERS,
69
- NULL, 0);
70
- return (ret < 0) ? ret : 0;
68
+ return do_register(ring, IORING_UNREGISTER_BUFFERS, NULL, 0);
71
69
  }
72
70
 
73
71
  int io_uring_register_files_update_tag(struct io_uring *ring, unsigned off,
@@ -81,9 +79,7 @@ int io_uring_register_files_update_tag(struct io_uring *ring, unsigned off,
81
79
  .nr = nr_files,
82
80
  };
83
81
 
84
- return __sys_io_uring_register(ring->ring_fd,
85
- IORING_REGISTER_FILES_UPDATE2, &up,
86
- sizeof(up));
82
+ return do_register(ring, IORING_REGISTER_FILES_UPDATE2, &up, sizeof(up));
87
83
  }
88
84
 
89
85
  /*
@@ -101,9 +97,7 @@ int io_uring_register_files_update(struct io_uring *ring, unsigned off,
101
97
  .fds = (unsigned long) files,
102
98
  };
103
99
 
104
- return __sys_io_uring_register(ring->ring_fd,
105
- IORING_REGISTER_FILES_UPDATE, &up,
106
- nr_files);
100
+ return do_register(ring, IORING_REGISTER_FILES_UPDATE, &up, nr_files);
107
101
  }
108
102
 
109
103
  static int increase_rlimit_nofile(unsigned nr)
@@ -132,9 +126,7 @@ int io_uring_register_files_sparse(struct io_uring *ring, unsigned nr)
132
126
  int ret, did_increase = 0;
133
127
 
134
128
  do {
135
- ret = __sys_io_uring_register(ring->ring_fd,
136
- IORING_REGISTER_FILES2, &reg,
137
- sizeof(reg));
129
+ ret = do_register(ring, IORING_REGISTER_FILES2, &reg, sizeof(reg));
138
130
  if (ret >= 0)
139
131
  break;
140
132
  if (ret == -EMFILE && !did_increase) {
@@ -159,9 +151,7 @@ int io_uring_register_files_tags(struct io_uring *ring, const int *files,
159
151
  int ret, did_increase = 0;
160
152
 
161
153
  do {
162
- ret = __sys_io_uring_register(ring->ring_fd,
163
- IORING_REGISTER_FILES2, &reg,
164
- sizeof(reg));
154
+ ret = do_register(ring, IORING_REGISTER_FILES2, &reg, sizeof(reg));
165
155
  if (ret >= 0)
166
156
  break;
167
157
  if (ret == -EMFILE && !did_increase) {
@@ -181,9 +171,7 @@ int io_uring_register_files(struct io_uring *ring, const int *files,
181
171
  int ret, did_increase = 0;
182
172
 
183
173
  do {
184
- ret = __sys_io_uring_register(ring->ring_fd,
185
- IORING_REGISTER_FILES, files,
186
- nr_files);
174
+ ret = do_register(ring, IORING_REGISTER_FILES, files, nr_files);
187
175
  if (ret >= 0)
188
176
  break;
189
177
  if (ret == -EMFILE && !did_increase) {
@@ -199,79 +187,50 @@ int io_uring_register_files(struct io_uring *ring, const int *files,
199
187
 
200
188
  int io_uring_unregister_files(struct io_uring *ring)
201
189
  {
202
- int ret;
203
-
204
- ret = __sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_FILES,
205
- NULL, 0);
206
- return (ret < 0) ? ret : 0;
190
+ return do_register(ring, IORING_UNREGISTER_FILES, NULL, 0);
207
191
  }
208
192
 
209
193
  int io_uring_register_eventfd(struct io_uring *ring, int event_fd)
210
194
  {
211
- int ret;
212
-
213
- ret = __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_EVENTFD,
214
- &event_fd, 1);
215
- return (ret < 0) ? ret : 0;
195
+ return do_register(ring, IORING_REGISTER_EVENTFD, &event_fd, 1);
216
196
  }
217
197
 
218
198
  int io_uring_unregister_eventfd(struct io_uring *ring)
219
199
  {
220
- int ret;
221
-
222
- ret = __sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_EVENTFD,
223
- NULL, 0);
224
- return (ret < 0) ? ret : 0;
200
+ return do_register(ring, IORING_UNREGISTER_EVENTFD, NULL, 0);
225
201
  }
226
202
 
227
203
  int io_uring_register_eventfd_async(struct io_uring *ring, int event_fd)
228
204
  {
229
- int ret;
230
-
231
- ret = __sys_io_uring_register(ring->ring_fd,
232
- IORING_REGISTER_EVENTFD_ASYNC, &event_fd,
233
- 1);
234
- return (ret < 0) ? ret : 0;
205
+ return do_register(ring, IORING_REGISTER_EVENTFD_ASYNC, &event_fd, 1);
235
206
  }
236
207
 
237
208
  int io_uring_register_probe(struct io_uring *ring, struct io_uring_probe *p,
238
209
  unsigned int nr_ops)
239
210
  {
240
- int ret;
241
-
242
- ret = __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_PROBE, p,
243
- nr_ops);
244
- return (ret < 0) ? ret : 0;
211
+ return do_register(ring, IORING_REGISTER_PROBE, p, nr_ops);
245
212
  }
246
213
 
247
214
  int io_uring_register_personality(struct io_uring *ring)
248
215
  {
249
- return __sys_io_uring_register(ring->ring_fd,
250
- IORING_REGISTER_PERSONALITY, NULL, 0);
216
+ return do_register(ring, IORING_REGISTER_PERSONALITY, NULL, 0);
251
217
  }
252
218
 
253
219
  int io_uring_unregister_personality(struct io_uring *ring, int id)
254
220
  {
255
- return __sys_io_uring_register(ring->ring_fd,
256
- IORING_UNREGISTER_PERSONALITY, NULL, id);
221
+ return do_register(ring, IORING_UNREGISTER_PERSONALITY, NULL, id);
257
222
  }
258
223
 
259
224
  int io_uring_register_restrictions(struct io_uring *ring,
260
225
  struct io_uring_restriction *res,
261
226
  unsigned int nr_res)
262
227
  {
263
- int ret;
264
-
265
- ret = __sys_io_uring_register(ring->ring_fd,
266
- IORING_REGISTER_RESTRICTIONS, res,
267
- nr_res);
268
- return (ret < 0) ? ret : 0;
228
+ return do_register(ring, IORING_REGISTER_RESTRICTIONS, res, nr_res);
269
229
  }
270
230
 
271
231
  int io_uring_enable_rings(struct io_uring *ring)
272
232
  {
273
- return __sys_io_uring_register(ring->ring_fd,
274
- IORING_REGISTER_ENABLE_RINGS, NULL, 0);
233
+ return do_register(ring, IORING_REGISTER_ENABLE_RINGS, NULL, 0);
275
234
  }
276
235
 
277
236
  int io_uring_register_iowq_aff(struct io_uring *ring, size_t cpusz,
@@ -280,21 +239,17 @@ int io_uring_register_iowq_aff(struct io_uring *ring, size_t cpusz,
280
239
  if (cpusz >= (1U << 31))
281
240
  return -EINVAL;
282
241
 
283
- return __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_IOWQ_AFF,
284
- mask, (int) cpusz);
242
+ return do_register(ring, IORING_REGISTER_IOWQ_AFF, mask, (int) cpusz);
285
243
  }
286
244
 
287
245
  int io_uring_unregister_iowq_aff(struct io_uring *ring)
288
246
  {
289
- return __sys_io_uring_register(ring->ring_fd,
290
- IORING_UNREGISTER_IOWQ_AFF, NULL, 0);
247
+ return do_register(ring, IORING_UNREGISTER_IOWQ_AFF, NULL, 0);
291
248
  }
292
249
 
293
250
  int io_uring_register_iowq_max_workers(struct io_uring *ring, unsigned int *val)
294
251
  {
295
- return __sys_io_uring_register(ring->ring_fd,
296
- IORING_REGISTER_IOWQ_MAX_WORKERS, val,
297
- 2);
252
+ return do_register(ring, IORING_REGISTER_IOWQ_MAX_WORKERS, val, 2);
298
253
  }
299
254
 
300
255
  int io_uring_register_ring_fd(struct io_uring *ring)
@@ -305,11 +260,16 @@ int io_uring_register_ring_fd(struct io_uring *ring)
305
260
  };
306
261
  int ret;
307
262
 
308
- ret = __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_RING_FDS,
309
- &up, 1);
263
+ if (ring->int_flags & INT_FLAG_REG_RING)
264
+ return -EEXIST;
265
+
266
+ ret = do_register(ring, IORING_REGISTER_RING_FDS, &up, 1);
310
267
  if (ret == 1) {
311
268
  ring->enter_ring_fd = up.offset;
312
269
  ring->int_flags |= INT_FLAG_REG_RING;
270
+ if (ring->features & IORING_FEAT_REG_REG_RING) {
271
+ ring->int_flags |= INT_FLAG_REG_REG_RING;
272
+ }
313
273
  }
314
274
  return ret;
315
275
  }
@@ -322,48 +282,58 @@ int io_uring_unregister_ring_fd(struct io_uring *ring)
322
282
  };
323
283
  int ret;
324
284
 
325
- ret = __sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_RING_FDS,
326
- &up, 1);
285
+ if (!(ring->int_flags & INT_FLAG_REG_RING))
286
+ return -EINVAL;
287
+
288
+ ret = do_register(ring, IORING_UNREGISTER_RING_FDS, &up, 1);
327
289
  if (ret == 1) {
328
290
  ring->enter_ring_fd = ring->ring_fd;
329
- ring->int_flags &= ~INT_FLAG_REG_RING;
291
+ ring->int_flags &= ~(INT_FLAG_REG_RING | INT_FLAG_REG_REG_RING);
330
292
  }
331
293
  return ret;
332
294
  }
333
295
 
296
+ int io_uring_close_ring_fd(struct io_uring *ring)
297
+ {
298
+ if (!(ring->features & IORING_FEAT_REG_REG_RING))
299
+ return -EOPNOTSUPP;
300
+ if (!(ring->int_flags & INT_FLAG_REG_RING))
301
+ return -EINVAL;
302
+ if (ring->ring_fd == -1)
303
+ return -EBADF;
304
+
305
+ __sys_close(ring->ring_fd);
306
+ ring->ring_fd = -1;
307
+ return 1;
308
+ }
309
+
334
310
  int io_uring_register_buf_ring(struct io_uring *ring,
335
311
  struct io_uring_buf_reg *reg,
336
312
  unsigned int __maybe_unused flags)
337
313
  {
338
- return __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_PBUF_RING,
339
- reg, 1);
314
+ return do_register(ring, IORING_REGISTER_PBUF_RING, reg, 1);
340
315
  }
341
316
 
342
317
  int io_uring_unregister_buf_ring(struct io_uring *ring, int bgid)
343
318
  {
344
319
  struct io_uring_buf_reg reg = { .bgid = bgid };
345
320
 
346
- return __sys_io_uring_register(ring->ring_fd,
347
- IORING_UNREGISTER_PBUF_RING, &reg, 1);
321
+ return do_register(ring, IORING_UNREGISTER_PBUF_RING, &reg, 1);
348
322
  }
349
323
 
350
324
  int io_uring_register_sync_cancel(struct io_uring *ring,
351
325
  struct io_uring_sync_cancel_reg *reg)
352
326
  {
353
- return __sys_io_uring_register(ring->ring_fd,
354
- IORING_REGISTER_SYNC_CANCEL, reg, 1);
327
+ return do_register(ring, IORING_REGISTER_SYNC_CANCEL, reg, 1);
355
328
  }
356
329
 
357
330
  int io_uring_register_file_alloc_range(struct io_uring *ring,
358
331
  unsigned off, unsigned len)
359
332
  {
360
- struct io_uring_file_index_range range;
361
-
362
- memset(&range, 0, sizeof(range));
363
- range.off = off;
364
- range.len = len;
333
+ struct io_uring_file_index_range range = {
334
+ .off = off,
335
+ .len = len
336
+ };
365
337
 
366
- return __sys_io_uring_register(ring->ring_fd,
367
- IORING_REGISTER_FILE_ALLOC_RANGE, &range,
368
- 0);
338
+ return do_register(ring, IORING_REGISTER_FILE_ALLOC_RANGE, &range, 0);
369
339
  }
@@ -205,7 +205,8 @@ __cold void io_uring_queue_exit(struct io_uring *ring)
205
205
  */
206
206
  if (ring->int_flags & INT_FLAG_REG_RING)
207
207
  io_uring_unregister_ring_fd(ring);
208
- __sys_close(ring->ring_fd);
208
+ if (ring->ring_fd != -1)
209
+ __sys_close(ring->ring_fd);
209
210
  }
210
211
 
211
212
  __cold struct io_uring_probe *io_uring_get_probe_ring(struct io_uring *ring)
@@ -215,7 +216,7 @@ __cold struct io_uring_probe *io_uring_get_probe_ring(struct io_uring *ring)
215
216
  int r;
216
217
 
217
218
  len = sizeof(*probe) + 256 * sizeof(struct io_uring_probe_op);
218
- probe = uring_malloc(len);
219
+ probe = malloc(len);
219
220
  if (!probe)
220
221
  return NULL;
221
222
  memset(probe, 0, len);
@@ -224,7 +225,7 @@ __cold struct io_uring_probe *io_uring_get_probe_ring(struct io_uring *ring)
224
225
  if (r >= 0)
225
226
  return probe;
226
227
 
227
- uring_free(probe);
228
+ free(probe);
228
229
  return NULL;
229
230
  }
230
231
 
@@ -245,7 +246,7 @@ __cold struct io_uring_probe *io_uring_get_probe(void)
245
246
 
246
247
  __cold void io_uring_free_probe(struct io_uring_probe *probe)
247
248
  {
248
- uring_free(probe);
249
+ free(probe);
249
250
  }
250
251
 
251
252
  static inline int __fls(unsigned long x)
@@ -0,0 +1,21 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+
3
+ #include "liburing.h"
4
+ #include "liburing/io_uring_version.h"
5
+
6
+ int io_uring_major_version(void)
7
+ {
8
+ return IO_URING_VERSION_MAJOR;
9
+ }
10
+
11
+ int io_uring_minor_version(void)
12
+ {
13
+ return IO_URING_VERSION_MINOR;
14
+ }
15
+
16
+ bool io_uring_check_version(int major, int minor)
17
+ {
18
+ return major > io_uring_major_version() ||
19
+ (major == io_uring_major_version() &&
20
+ minor >= io_uring_minor_version());
21
+ }
@@ -33,9 +33,9 @@ struct params {
33
33
  __be16 bind_port;
34
34
  };
35
35
 
36
- pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
37
- pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
38
- int rcv_ready = 0;
36
+ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
37
+ static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
38
+ static int rcv_ready = 0;
39
39
 
40
40
  static void set_rcv_ready(void)
41
41
  {
@@ -176,7 +176,7 @@ static void kill_and_wait(int pid, int* status)
176
176
  }
177
177
 
178
178
  #define SYZ_HAVE_SETUP_TEST 1
179
- static void setup_test()
179
+ static void setup_test(void)
180
180
  {
181
181
  prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
182
182
  setpgrp();
@@ -262,7 +262,7 @@ static void loop(void)
262
262
  }
263
263
  }
264
264
 
265
- uint64_t r[1] = {0xffffffffffffffff};
265
+ static uint64_t r[1] = {0xffffffffffffffff};
266
266
 
267
267
  void execute_call(int call)
268
268
  {
@@ -320,7 +320,7 @@ int main(int argc, char *argv[])
320
320
  if (argc > 1)
321
321
  return T_EXIT_SKIP;
322
322
  signal(SIGINT, sig_int);
323
- mmap((void *) 0x20000000, 0x1000000, 3, 0x32, -1, 0);
323
+ mmap((void *) 0x20000000, 0x1000000, 3, MAP_ANON|MAP_PRIVATE, -1, 0);
324
324
  signal(SIGALRM, sig_int);
325
325
  alarm(5);
326
326