uringmachine 0.16 → 0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.gitmodules +4 -0
  4. data/CHANGELOG.md +12 -0
  5. data/TODO.md +13 -4
  6. data/examples/bm_send.rb +86 -0
  7. data/examples/fiber_scheduler_demo.rb +71 -0
  8. data/ext/um/um.c +107 -36
  9. data/ext/um/um.h +7 -2
  10. data/ext/um/um_async_op.c +2 -1
  11. data/ext/um/um_class.c +23 -0
  12. data/ext/um/um_const.c +5 -2
  13. data/ext/um/um_stream.c +8 -8
  14. data/ext/um/um_stream_class.c +1 -1
  15. data/ext/um/um_sync.c +2 -2
  16. data/ext/um/um_utils.c +38 -15
  17. data/lib/uringmachine/fiber_scheduler.rb +104 -0
  18. data/lib/uringmachine/version.rb +1 -1
  19. data/test/test_stream.rb +3 -3
  20. data/test/test_um.rb +129 -0
  21. data/vendor/libressl/.github/scripts/changelog.sh +74 -0
  22. data/vendor/libressl/.github/workflows/android.yml +35 -0
  23. data/vendor/libressl/.github/workflows/cifuzz.yml +33 -0
  24. data/vendor/libressl/.github/workflows/cmake-config.yml +98 -0
  25. data/vendor/libressl/.github/workflows/coverity.yml +69 -0
  26. data/vendor/libressl/.github/workflows/emscripten.yml +71 -0
  27. data/vendor/libressl/.github/workflows/fedora-rawhide.yml +39 -0
  28. data/vendor/libressl/.github/workflows/freebsd.yml +71 -0
  29. data/vendor/libressl/.github/workflows/linux.yml +71 -0
  30. data/vendor/libressl/.github/workflows/macos.yml +37 -0
  31. data/vendor/libressl/.github/workflows/release.yml +81 -0
  32. data/vendor/libressl/.github/workflows/rust-openssl.yml +47 -0
  33. data/vendor/libressl/.github/workflows/solaris.yml +37 -0
  34. data/vendor/libressl/.github/workflows/windows.yml +70 -0
  35. data/vendor/libressl/.gitignore +333 -0
  36. data/vendor/libressl/CMakeLists.txt +581 -0
  37. data/vendor/libressl/COPYING +133 -0
  38. data/vendor/libressl/ChangeLog +3280 -0
  39. data/vendor/libressl/FindLibreSSL.cmake +232 -0
  40. data/vendor/libressl/LibreSSLConfig.cmake.in +36 -0
  41. data/vendor/libressl/Makefile.am +60 -0
  42. data/vendor/libressl/Makefile.am.common +20 -0
  43. data/vendor/libressl/OPENBSD_BRANCH +1 -0
  44. data/vendor/libressl/README.md +238 -0
  45. data/vendor/libressl/README.mingw.md +43 -0
  46. data/vendor/libressl/apps/CMakeLists.txt +18 -0
  47. data/vendor/libressl/apps/Makefile.am +5 -0
  48. data/vendor/libressl/apps/nc/CMakeLists.txt +67 -0
  49. data/vendor/libressl/apps/nc/Makefile.am +64 -0
  50. data/vendor/libressl/apps/nc/compat/accept4.c +17 -0
  51. data/vendor/libressl/apps/nc/compat/readpassphrase.c +205 -0
  52. data/vendor/libressl/apps/nc/compat/socket.c +29 -0
  53. data/vendor/libressl/apps/nc/compat/sys/socket.h +30 -0
  54. data/vendor/libressl/apps/ocspcheck/CMakeLists.txt +44 -0
  55. data/vendor/libressl/apps/ocspcheck/Makefile.am +45 -0
  56. data/vendor/libressl/apps/ocspcheck/compat/.gitignore +0 -0
  57. data/vendor/libressl/apps/openssl/CMakeLists.txt +97 -0
  58. data/vendor/libressl/apps/openssl/Makefile.am +108 -0
  59. data/vendor/libressl/apps/openssl/apps_win.c +138 -0
  60. data/vendor/libressl/apps/openssl/certhash_win.c +13 -0
  61. data/vendor/libressl/apps/openssl/compat/clock_gettime_osx.c +26 -0
  62. data/vendor/libressl/apps/openssl/compat/poll_win.c +329 -0
  63. data/vendor/libressl/appveyor.yml +53 -0
  64. data/vendor/libressl/autogen.sh +15 -0
  65. data/vendor/libressl/check-release.sh +86 -0
  66. data/vendor/libressl/cmake_export_symbol.cmake +71 -0
  67. data/vendor/libressl/cmake_uninstall.cmake.in +36 -0
  68. data/vendor/libressl/config +17 -0
  69. data/vendor/libressl/configure.ac +165 -0
  70. data/vendor/libressl/crypto/CMakeLists.txt +863 -0
  71. data/vendor/libressl/crypto/Makefile.am +962 -0
  72. data/vendor/libressl/crypto/Makefile.am.arc4random +46 -0
  73. data/vendor/libressl/crypto/Makefile.am.elf-mips +14 -0
  74. data/vendor/libressl/crypto/Makefile.am.elf-mips64 +14 -0
  75. data/vendor/libressl/crypto/Makefile.am.elf-x86_64 +35 -0
  76. data/vendor/libressl/crypto/Makefile.am.macosx-x86_64 +35 -0
  77. data/vendor/libressl/crypto/Makefile.am.masm-x86_64 +22 -0
  78. data/vendor/libressl/crypto/Makefile.am.mingw64-x86_64 +23 -0
  79. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_darwin.c +60 -0
  80. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_linux.c +62 -0
  81. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_none.c +26 -0
  82. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_windows.c +36 -0
  83. data/vendor/libressl/crypto/arch/loongarch64/crypto_arch.h +21 -0
  84. data/vendor/libressl/crypto/arch/mips/crypto_arch.h +21 -0
  85. data/vendor/libressl/crypto/bn/arch/loongarch64/bn_arch.h +23 -0
  86. data/vendor/libressl/crypto/bn/arch/mips/bn_arch.h +24 -0
  87. data/vendor/libressl/crypto/compat/.gitignore +31 -0
  88. data/vendor/libressl/crypto/compat/arc4random.h +41 -0
  89. data/vendor/libressl/crypto/compat/b_win.c +55 -0
  90. data/vendor/libressl/crypto/compat/bsd-asprintf.c +96 -0
  91. data/vendor/libressl/crypto/compat/crypto_lock_win.c +56 -0
  92. data/vendor/libressl/crypto/compat/explicit_bzero_win.c +13 -0
  93. data/vendor/libressl/crypto/compat/freezero.c +32 -0
  94. data/vendor/libressl/crypto/compat/getdelim.c +78 -0
  95. data/vendor/libressl/crypto/compat/getline.c +40 -0
  96. data/vendor/libressl/crypto/compat/getopt_long.c +528 -0
  97. data/vendor/libressl/crypto/compat/getpagesize.c +18 -0
  98. data/vendor/libressl/crypto/compat/getprogname_linux.c +23 -0
  99. data/vendor/libressl/crypto/compat/getprogname_unimpl.c +7 -0
  100. data/vendor/libressl/crypto/compat/getprogname_windows.c +13 -0
  101. data/vendor/libressl/crypto/compat/posix_win.c +296 -0
  102. data/vendor/libressl/crypto/compat/syslog_r.c +19 -0
  103. data/vendor/libressl/crypto/compat/ui_openssl_win.c +334 -0
  104. data/vendor/libressl/dist.sh +22 -0
  105. data/vendor/libressl/gen-coverage-report.sh +58 -0
  106. data/vendor/libressl/gen-openbsd-tags.sh +20 -0
  107. data/vendor/libressl/include/CMakeLists.txt +61 -0
  108. data/vendor/libressl/include/Makefile.am +79 -0
  109. data/vendor/libressl/include/arch/loongarch64/opensslconf.h +150 -0
  110. data/vendor/libressl/include/arch/mips/opensslconf.h +150 -0
  111. data/vendor/libressl/include/compat/arpa/inet.h +15 -0
  112. data/vendor/libressl/include/compat/arpa/nameser.h +25 -0
  113. data/vendor/libressl/include/compat/cet.h +19 -0
  114. data/vendor/libressl/include/compat/dirent.h +17 -0
  115. data/vendor/libressl/include/compat/dirent_msvc.h +611 -0
  116. data/vendor/libressl/include/compat/endian.h +161 -0
  117. data/vendor/libressl/include/compat/err.h +95 -0
  118. data/vendor/libressl/include/compat/fcntl.h +32 -0
  119. data/vendor/libressl/include/compat/getopt.h +50 -0
  120. data/vendor/libressl/include/compat/limits.h +25 -0
  121. data/vendor/libressl/include/compat/netdb.h +10 -0
  122. data/vendor/libressl/include/compat/netinet/in.h +19 -0
  123. data/vendor/libressl/include/compat/netinet/ip.h +49 -0
  124. data/vendor/libressl/include/compat/netinet/tcp.h +10 -0
  125. data/vendor/libressl/include/compat/poll.h +63 -0
  126. data/vendor/libressl/include/compat/pthread.h +122 -0
  127. data/vendor/libressl/include/compat/readpassphrase.h +44 -0
  128. data/vendor/libressl/include/compat/resolv.h +24 -0
  129. data/vendor/libressl/include/compat/stdint.h +31 -0
  130. data/vendor/libressl/include/compat/stdio.h +65 -0
  131. data/vendor/libressl/include/compat/stdlib.h +57 -0
  132. data/vendor/libressl/include/compat/string.h +98 -0
  133. data/vendor/libressl/include/compat/sys/_null.h +18 -0
  134. data/vendor/libressl/include/compat/sys/ioctl.h +11 -0
  135. data/vendor/libressl/include/compat/sys/mman.h +19 -0
  136. data/vendor/libressl/include/compat/sys/param.h +15 -0
  137. data/vendor/libressl/include/compat/sys/queue.h +536 -0
  138. data/vendor/libressl/include/compat/sys/select.h +10 -0
  139. data/vendor/libressl/include/compat/sys/socket.h +18 -0
  140. data/vendor/libressl/include/compat/sys/stat.h +129 -0
  141. data/vendor/libressl/include/compat/sys/time.h +37 -0
  142. data/vendor/libressl/include/compat/sys/tree.h +1006 -0
  143. data/vendor/libressl/include/compat/sys/types.h +69 -0
  144. data/vendor/libressl/include/compat/sys/uio.h +17 -0
  145. data/vendor/libressl/include/compat/syslog.h +38 -0
  146. data/vendor/libressl/include/compat/time.h +59 -0
  147. data/vendor/libressl/include/compat/unistd.h +83 -0
  148. data/vendor/libressl/include/compat/win32netcompat.h +57 -0
  149. data/vendor/libressl/include/openssl/Makefile.am.tpl +45 -0
  150. data/vendor/libressl/libcrypto.pc.in +28 -0
  151. data/vendor/libressl/libressl.pub +2 -0
  152. data/vendor/libressl/libssl.pc.in +28 -0
  153. data/vendor/libressl/libtls.pc.in +28 -0
  154. data/vendor/libressl/m4/ax_add_fortify_source.m4 +80 -0
  155. data/vendor/libressl/m4/ax_check_compile_flag.m4 +53 -0
  156. data/vendor/libressl/m4/check-hardening-options.m4 +110 -0
  157. data/vendor/libressl/m4/check-libc.m4 +189 -0
  158. data/vendor/libressl/m4/check-os-options.m4 +181 -0
  159. data/vendor/libressl/m4/disable-compiler-warnings.m4 +44 -0
  160. data/vendor/libressl/man/CMakeLists.txt +26 -0
  161. data/vendor/libressl/man/links +2780 -0
  162. data/vendor/libressl/man/update_links.sh +25 -0
  163. data/vendor/libressl/openssl.pc.in +11 -0
  164. data/vendor/libressl/patches/bn_shift.patch +34 -0
  165. data/vendor/libressl/patches/crypto_arch.h.patch +34 -0
  166. data/vendor/libressl/patches/crypto_namespace.h.patch +22 -0
  167. data/vendor/libressl/patches/netcat.c.patch +178 -0
  168. data/vendor/libressl/patches/openssl.c.patch +12 -0
  169. data/vendor/libressl/patches/opensslfeatures.h.patch +49 -0
  170. data/vendor/libressl/patches/patch-amd64-crypto-cpu-caps.c.patch +20 -0
  171. data/vendor/libressl/patches/patch-i386-crypto-cpu-caps.c.patch +20 -0
  172. data/vendor/libressl/patches/speed.c.patch +114 -0
  173. data/vendor/libressl/patches/ssl_namespace.h.patch +21 -0
  174. data/vendor/libressl/patches/tls.h.patch +16 -0
  175. data/vendor/libressl/patches/tls_config.c.patch +15 -0
  176. data/vendor/libressl/patches/win32_amd64_bn_arch.h.patch +28 -0
  177. data/vendor/libressl/patches/windows_headers.patch +80 -0
  178. data/vendor/libressl/scripts/config.guess +1774 -0
  179. data/vendor/libressl/scripts/config.sub +1907 -0
  180. data/vendor/libressl/scripts/i686-w64-mingw32.cmake +9 -0
  181. data/vendor/libressl/scripts/test +210 -0
  182. data/vendor/libressl/scripts/wrap-compiler-for-flag-check +31 -0
  183. data/vendor/libressl/scripts/x86_64-w64-mingw32.cmake +9 -0
  184. data/vendor/libressl/ssl/CMakeLists.txt +183 -0
  185. data/vendor/libressl/ssl/Makefile.am +187 -0
  186. data/vendor/libressl/tests/CMakeLists.txt +970 -0
  187. data/vendor/libressl/tests/Makefile.am +944 -0
  188. data/vendor/libressl/tests/aeadtest.sh +30 -0
  189. data/vendor/libressl/tests/arc4randomforktest.sh +21 -0
  190. data/vendor/libressl/tests/asn1time_small.test +10 -0
  191. data/vendor/libressl/tests/cmake/CMakeLists.txt +52 -0
  192. data/vendor/libressl/tests/cmake/crypto.c +7 -0
  193. data/vendor/libressl/tests/cmake/ssl.c +6 -0
  194. data/vendor/libressl/tests/cmake/tls.c +6 -0
  195. data/vendor/libressl/tests/compat/pipe2.c +186 -0
  196. data/vendor/libressl/tests/dtlstest.sh +28 -0
  197. data/vendor/libressl/tests/evptest.sh +22 -0
  198. data/vendor/libressl/tests/keypairtest.sh +27 -0
  199. data/vendor/libressl/tests/mlkem_tests.sh +39 -0
  200. data/vendor/libressl/tests/ocsptest.bat +25 -0
  201. data/vendor/libressl/tests/ocsptest.sh +23 -0
  202. data/vendor/libressl/tests/openssl.cnf +29 -0
  203. data/vendor/libressl/tests/optionstest.c +381 -0
  204. data/vendor/libressl/tests/pidwraptest.c +85 -0
  205. data/vendor/libressl/tests/pidwraptest.sh +26 -0
  206. data/vendor/libressl/tests/quictest.bat +27 -0
  207. data/vendor/libressl/tests/quictest.sh +30 -0
  208. data/vendor/libressl/tests/renegotiation_test.bat +27 -0
  209. data/vendor/libressl/tests/renegotiation_test.sh +30 -0
  210. data/vendor/libressl/tests/rfc5280time_small.test +10 -0
  211. data/vendor/libressl/tests/servertest.bat +27 -0
  212. data/vendor/libressl/tests/servertest.sh +30 -0
  213. data/vendor/libressl/tests/shutdowntest.bat +27 -0
  214. data/vendor/libressl/tests/shutdowntest.sh +30 -0
  215. data/vendor/libressl/tests/ssltest.bat +32 -0
  216. data/vendor/libressl/tests/ssltest.sh +48 -0
  217. data/vendor/libressl/tests/testdsa.bat +47 -0
  218. data/vendor/libressl/tests/testdsa.sh +57 -0
  219. data/vendor/libressl/tests/testenc.bat +85 -0
  220. data/vendor/libressl/tests/testenc.sh +93 -0
  221. data/vendor/libressl/tests/testrsa.bat +47 -0
  222. data/vendor/libressl/tests/testrsa.sh +57 -0
  223. data/vendor/libressl/tests/testssl.bat +171 -0
  224. data/vendor/libressl/tests/tlstest.bat +27 -0
  225. data/vendor/libressl/tests/tlstest.sh +28 -0
  226. data/vendor/libressl/tls/CMakeLists.txt +125 -0
  227. data/vendor/libressl/tls/Makefile.am +76 -0
  228. data/vendor/libressl/tls/compat/ftruncate.c +17 -0
  229. data/vendor/libressl/tls/compat/pread.c +29 -0
  230. data/vendor/libressl/tls/compat/pwrite.c +29 -0
  231. data/vendor/libressl/update.sh +460 -0
  232. data/vendor/liburing/.github/workflows/ci.yml +8 -0
  233. data/vendor/liburing/configure +23 -2
  234. data/vendor/liburing/examples/helpers.c +1 -1
  235. data/vendor/liburing/examples/helpers.h +1 -1
  236. data/vendor/liburing/examples/reg-wait.c +3 -3
  237. data/vendor/liburing/examples/zcrx.c +5 -5
  238. data/vendor/liburing/liburing.spec +1 -1
  239. data/vendor/liburing/src/include/liburing/io_uring.h +16 -0
  240. data/vendor/liburing/src/include/liburing.h +20 -4
  241. data/vendor/liburing/src/lib.h +2 -4
  242. data/vendor/liburing/src/liburing-ffi.map +7 -0
  243. data/vendor/liburing/src/liburing.map +7 -0
  244. data/vendor/liburing/src/register.c +5 -0
  245. data/vendor/liburing/src/sanitize.c +5 -4
  246. data/vendor/liburing/src/setup.c +43 -28
  247. data/vendor/liburing/test/Makefile +7 -0
  248. data/vendor/liburing/test/cmd-discard.c +2 -2
  249. data/vendor/liburing/test/evfd-short-read.c +84 -0
  250. data/vendor/liburing/test/fdinfo-sqpoll.c +117 -0
  251. data/vendor/liburing/test/fdinfo.c +1 -1
  252. data/vendor/liburing/test/fixed-buf-merge.c +2 -2
  253. data/vendor/liburing/test/futex-kill.c +135 -0
  254. data/vendor/liburing/test/helpers.c +1 -1
  255. data/vendor/liburing/test/helpers.h +1 -1
  256. data/vendor/liburing/test/init-mem.c +50 -12
  257. data/vendor/liburing/test/io_uring_passthrough.c +25 -6
  258. data/vendor/liburing/test/msg-ring.c +123 -9
  259. data/vendor/liburing/test/recv-bundle-short-ooo.c +16 -1
  260. data/vendor/liburing/test/recv-inc-ooo.c +411 -0
  261. data/vendor/liburing/test/recv-mshot-fair.c +513 -0
  262. data/vendor/liburing/test/reg-wait.c +14 -14
  263. data/vendor/liburing/test/send-zerocopy.c +4 -4
  264. data/vendor/liburing/test/timerfd-short-read.c +81 -0
  265. data/vendor/liburing/test/timestamp.c +382 -0
  266. data/vendor/liburing/test/zcrx.c +22 -22
  267. metadata +224 -2
data/ext/um/um_const.c CHANGED
@@ -12,7 +12,7 @@
12
12
  #include <netinet/udp.h>
13
13
  #include <netdb.h>
14
14
  #include <net/if.h>
15
-
15
+ #include <poll.h>
16
16
 
17
17
  #define DEF_CONST_INT(mod, v) rb_define_const(mod, #v, INT2NUM(v))
18
18
 
@@ -258,6 +258,10 @@ void um_define_net_constants(VALUE mod) {
258
258
 
259
259
  DEF_CONST_INT(mod, SOMAXCONN);
260
260
 
261
+ DEF_CONST_INT(mod, POLLIN);
262
+ DEF_CONST_INT(mod, POLLOUT);
263
+ DEF_CONST_INT(mod, POLLERR);
264
+
261
265
  DEF_CONST_INT(mod, EPERM);
262
266
  DEF_CONST_INT(mod, ENOENT);
263
267
  DEF_CONST_INT(mod, ESRCH);
@@ -387,5 +391,4 @@ void um_define_net_constants(VALUE mod) {
387
391
  DEF_CONST_INT(mod, EKEYREJECTED);
388
392
  DEF_CONST_INT(mod, EOWNERDEAD);
389
393
  DEF_CONST_INT(mod, ENOTRECOVERABLE);
390
-
391
394
  }
data/ext/um/um_stream.c CHANGED
@@ -26,7 +26,7 @@ int stream_read_more(struct um_stream *stream) {
26
26
  size_t capa = rb_str_capacity(stream->buffer);
27
27
  if (capa - stream->pos < maxlen)
28
28
  rb_str_modify_expand(stream->buffer, maxlen - (capa - stream->pos));
29
-
29
+
30
30
  rb_str_modify(stream->buffer);
31
31
  char *ptr = RSTRING_PTR(stream->buffer) + stream->pos;
32
32
  size_t ret = um_read_raw(stream->machine, stream->fd, ptr, maxlen);
@@ -94,7 +94,7 @@ VALUE stream_get_string(struct um_stream *stream, VALUE buf, ssize_t len) {
94
94
 
95
95
  abslen = stream->len - stream->pos;
96
96
  }
97
-
97
+
98
98
  char *start = RSTRING_PTR(stream->buffer) + stream->pos;
99
99
  stream->pos += abslen;
100
100
 
@@ -137,7 +137,7 @@ VALUE resp_get_string(struct um_stream *stream, ulong len, VALUE out_buffer) {
137
137
 
138
138
  while (stream->len - stream->pos < read_len)
139
139
  if (!stream_read_more(stream)) return Qnil;
140
-
140
+
141
141
  char *start = RSTRING_PTR(stream->buffer) + stream->pos;
142
142
  stream->pos += read_len;
143
143
 
@@ -198,7 +198,7 @@ static inline VALUE resp_decode_string_with_encoding(struct um_stream *stream, V
198
198
 
199
199
  static inline VALUE resp_decode_integer(char *ptr) {
200
200
  long value = strtol(ptr + 1, NULL, 10);
201
- return LONG2NUM(value);
201
+ return LONG2NUM(value);
202
202
  }
203
203
 
204
204
  static inline VALUE resp_decode_float(char *ptr) {
@@ -234,13 +234,13 @@ VALUE resp_decode(struct um_stream *stream, VALUE out_buffer) {
234
234
  ulong len = RSTRING_LEN(msg);
235
235
  ulong data_len;
236
236
  if (len == 0) return Qnil;
237
-
237
+
238
238
  switch (ptr[0]) {
239
239
  case '%': // hash
240
240
  case '|': // attributes hash
241
241
  data_len = resp_parse_length_field(ptr, len);
242
242
  return resp_decode_hash(stream, out_buffer, data_len);
243
-
243
+
244
244
  case '*': // array
245
245
  case '~': // set
246
246
  case '>': // pub/sub push
@@ -276,7 +276,7 @@ VALUE resp_decode(struct um_stream *stream, VALUE out_buffer) {
276
276
  default:
277
277
  rb_raise(rb_eRuntimeError, "Invalid character encountered");
278
278
  }
279
-
279
+
280
280
  RB_GC_GUARD(msg);
281
281
  }
282
282
 
@@ -284,7 +284,7 @@ void write_buffer_init(struct um_write_buffer *buf, VALUE str) {
284
284
  size_t capa = 1 << 12;
285
285
  size_t len = RSTRING_LEN(str);
286
286
  while (capa < len) capa += 1 << 12;
287
-
287
+
288
288
  rb_str_resize(str, capa);
289
289
  rb_str_set_len(str, len);
290
290
  buf->str = str;
@@ -88,7 +88,7 @@ void Init_Stream(void) {
88
88
  rb_define_alloc_func(cStream, Stream_allocate);
89
89
 
90
90
  rb_define_method(cStream, "initialize", Stream_initialize, 2);
91
-
91
+
92
92
  rb_define_method(cStream, "get_line", Stream_get_line, 2);
93
93
  rb_define_method(cStream, "get_string", Stream_get_string, 2);
94
94
 
data/ext/um/um_sync.c CHANGED
@@ -21,8 +21,8 @@ void um_futex_wait(struct um *machine, uint32_t *futex, uint32_t expect) {
21
21
  um_raise_on_error_result(op.result.res);
22
22
  }
23
23
 
24
+ RAISE_IF_EXCEPTION(ret);
24
25
  RB_GC_GUARD(ret);
25
- raise_if_exception(ret);
26
26
  }
27
27
 
28
28
  void um_futex_wake(struct um *machine, uint32_t *futex, uint32_t num_waiters) {
@@ -38,8 +38,8 @@ void um_futex_wake(struct um *machine, uint32_t *futex, uint32_t num_waiters) {
38
38
  VALUE ret = um_fiber_switch(machine);
39
39
  um_check_completion(machine, &op);
40
40
 
41
+ RAISE_IF_EXCEPTION(ret);
41
42
  RB_GC_GUARD(ret);
42
- raise_if_exception(ret);
43
43
  }
44
44
 
45
45
  void um_futex_wake_transient(struct um *machine, uint32_t *futex, uint32_t num_waiters) {
data/ext/um/um_utils.c CHANGED
@@ -65,11 +65,11 @@ int um_setup_buffer_ring(struct um *machine, unsigned size, unsigned count) {
65
65
  struct buf_ring_descriptor *desc = machine->buffer_rings + machine->buffer_ring_count;
66
66
  desc->buf_count = count;
67
67
  desc->buf_size = size;
68
-
69
68
  desc->br_size = sizeof(struct io_uring_buf) * desc->buf_count;
69
+ desc->buf_mask = io_uring_buf_ring_mask(desc->buf_count);
70
+
70
71
  void *mapped = mmap(
71
- NULL, desc->br_size, PROT_READ | PROT_WRITE,
72
- MAP_ANONYMOUS | MAP_PRIVATE, 0, 0
72
+ NULL, desc->br_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0
73
73
  );
74
74
  if (mapped == MAP_FAILED)
75
75
  rb_raise(rb_eRuntimeError, "Failed to allocate buffer ring");
@@ -82,21 +82,22 @@ int um_setup_buffer_ring(struct um *machine, unsigned size, unsigned count) {
82
82
  desc->br = io_uring_setup_buf_ring(&machine->ring, count, bg_id, 0, &ret);
83
83
  if (!desc->br) {
84
84
  munmap(desc->br, desc->br_size);
85
- rb_syserr_fail(ret, strerror(ret));
85
+ rb_syserr_fail(-ret, strerror(-ret));
86
86
  }
87
87
 
88
- if (posix_memalign(&desc->buf_base, 4096, desc->buf_count * desc->buf_size)) {
89
- io_uring_free_buf_ring(&machine->ring, desc->br, desc->buf_count, bg_id);
90
- rb_raise(rb_eRuntimeError, "Failed to allocate buffers");
88
+ if (size > 0) {
89
+ if (posix_memalign(&desc->buf_base, 4096, desc->buf_count * desc->buf_size)) {
90
+ io_uring_free_buf_ring(&machine->ring, desc->br, desc->buf_count, bg_id);
91
+ rb_raise(rb_eRuntimeError, "Failed to allocate buffers");
92
+ }
93
+
94
+ void *ptr = desc->buf_base;
95
+ for (unsigned i = 0; i < desc->buf_count; i++) {
96
+ io_uring_buf_ring_add(desc->br, ptr, desc->buf_size, i, desc->buf_mask, i);
97
+ ptr += desc->buf_size;
98
+ }
99
+ io_uring_buf_ring_advance(desc->br, desc->buf_count);
91
100
  }
92
-
93
- desc->buf_mask = io_uring_buf_ring_mask(desc->buf_count);
94
- void *ptr = desc->buf_base;
95
- for (unsigned i = 0; i < desc->buf_count; i++) {
96
- io_uring_buf_ring_add(desc->br, ptr, desc->buf_size, i, desc->buf_mask, i);
97
- ptr += desc->buf_size;
98
- }
99
- io_uring_buf_ring_advance(desc->br, desc->buf_count);
100
101
  machine->buffer_ring_count++;
101
102
  return bg_id;
102
103
  }
@@ -120,3 +121,25 @@ inline VALUE um_get_string_from_buffer_ring(struct um *machine, int bgid, __s32
120
121
  RB_GC_GUARD(buf);
121
122
  return buf;
122
123
  }
124
+
125
+ inline void um_add_strings_to_buffer_ring(struct um *machine, int bgid, VALUE strings) {
126
+ static ID ID_to_s = 0;
127
+
128
+ struct buf_ring_descriptor *desc = machine->buffer_rings + bgid;
129
+ ulong count = RARRAY_LEN(strings);
130
+ VALUE str = Qnil;
131
+ VALUE converted = Qnil;
132
+
133
+ for (ulong i = 0; i < count; i++) {
134
+ str = rb_ary_entry(strings, i);
135
+ if (TYPE(str) != T_STRING) {
136
+ if (!ID_to_s) ID_to_s = rb_intern("to_s");
137
+ if (NIL_P(converted)) converted = rb_ary_new();
138
+ str = rb_funcall(str, ID_to_s, 0);
139
+ rb_ary_push(converted, str);
140
+ }
141
+ io_uring_buf_ring_add(desc->br, RSTRING_PTR(str), RSTRING_LEN(str), i, desc->buf_mask, i);
142
+ }
143
+ RB_GC_GUARD(converted);
144
+ io_uring_buf_ring_advance(desc->br, count);
145
+ }
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UringMachine
4
+ class FiberScheduler
5
+ def initialize(machine)
6
+ @machine = machine
7
+ end
8
+
9
+ def p(o)
10
+ @machine.write(1, "#{o.inspect}\n")
11
+ rescue Errno::EINTR
12
+ retry
13
+ end
14
+
15
+ def join(*)
16
+ @machine.join(*)
17
+ end
18
+
19
+ def block(blocker, timeout)
20
+ p block: [blocker, timeout]
21
+
22
+ end
23
+
24
+ def unblock(blocker, fiber)
25
+ p unblock: [blocker, fiber]
26
+ end
27
+
28
+ def kernel_sleep(duration = nil)
29
+ # p sleep: [duration]
30
+ if duration
31
+ @machine.sleep(duration)
32
+ else
33
+ @machine.yield
34
+ end
35
+ end
36
+
37
+ def io_wait(io, events, timeout = nil)
38
+ timeout ||= io.timeout
39
+ p timeout: timeout
40
+ if timeout
41
+ p 1
42
+ @machine.timeout(timeout, Timeout::Error) {
43
+ p 2
44
+ @machine.poll(io.fileno, events).tap { p 3 }
45
+ }.tap { p 4 }
46
+ else
47
+ p 5
48
+ @machine.poll(io.fileno, events).tap { p 6 }
49
+
50
+ end
51
+ rescue => e
52
+ p e: e
53
+ raise
54
+ end
55
+
56
+ def fiber(&block)
57
+ f = @machine.spin(&block)
58
+ @machine.snooze
59
+ f
60
+ end
61
+
62
+ def io_write(io, buffer, length, offset)
63
+ p io_write: [io, buffer.get_string, length, offset]
64
+ @machine.write(io.fileno, buffer.get_string)
65
+ end
66
+
67
+ def io_read(io, buffer, length, offset)
68
+ # p io_read: [io, buffer, length, offset]
69
+ s = +''
70
+ length = buffer.size if length == 0
71
+ bytes = @machine.read(io.fileno, s, length)
72
+ buffer.set_string(s)
73
+ bytes
74
+ rescue SystemCallError => e
75
+ -e.errno
76
+ end
77
+
78
+ def io_pwrite(io, buffer, from, length, offset)
79
+ p io_pwrite: [io, buffer, from, length, offset]
80
+ end
81
+
82
+ def io_pread(io, buffer, from, length, offset)
83
+ p io_pread: [io, buffer, from, length, offset]
84
+ end
85
+
86
+ # def fiber(&block)
87
+ # fiber = Fiber.new(blocking: false, &block)
88
+ # unblock(nil, fiber)
89
+ # # fiber.resume
90
+ # return fiber
91
+ # end
92
+
93
+ # def kernel_sleep(duration = nil)
94
+ # block(:sleep, duration)
95
+ # end
96
+
97
+ # def process_wait(pid, flags)
98
+ # # This is a very simple way to implement a non-blocking wait:
99
+ # Thread.new do
100
+ # Process::Status.wait(pid, flags)
101
+ # end.value
102
+ # end
103
+ end
104
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UringMachine
4
- VERSION = '0.16'
4
+ VERSION = '0.19'
5
5
  end
data/test/test_stream.rb CHANGED
@@ -7,7 +7,7 @@ class StreamBaseTest < UMBaseTest
7
7
  super
8
8
  @rfd, @wfd = UM.pipe
9
9
  @stream = UM::Stream.new(@machine, @rfd)
10
- end
10
+ end
11
11
  end
12
12
 
13
13
  class StreamTest < StreamBaseTest
@@ -166,7 +166,7 @@ class StreamRespTest < StreamBaseTest
166
166
  end
167
167
 
168
168
  def test_resp_encode
169
- s = UM::Stream
169
+ s = UM::Stream
170
170
  assert_equal "_\r\n", s.resp_encode(+'', nil)
171
171
  assert_equal "#t\r\n", s.resp_encode(+'', true)
172
172
  assert_equal "#f\r\n", s.resp_encode(+'', false)
@@ -174,7 +174,7 @@ class StreamRespTest < StreamBaseTest
174
174
  assert_equal ",42.1\r\n", s.resp_encode(+'', 42.1)
175
175
  assert_equal "$6\r\nfoobar\r\n", s.resp_encode(+'', 'foobar')
176
176
  assert_equal "$10\r\nפובאר\r\n", s.resp_encode(+'', 'פובאר')
177
-
177
+
178
178
  assert_equal "*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n",
179
179
  s.resp_encode(+'', ['foo', 'bar'])
180
180
 
data/test/test_um.rb CHANGED
@@ -169,6 +169,17 @@ class ScheduleTest < UMBaseTest
169
169
  assert_equal 0, machine.pending_count
170
170
  end
171
171
 
172
+ def test_timeout_with_no_timeout
173
+ _r, w = UM.pipe
174
+ v = machine.timeout(0.1, TOError) { machine.write(w, 'foo') }
175
+
176
+ assert_equal 3, v
177
+
178
+ assert_equal 1, machine.pending_count
179
+ machine.sleep 0.01 # wait for cancelled CQE
180
+ assert_equal 0, machine.pending_count
181
+ end
182
+
172
183
  class TO2Error < RuntimeError; end
173
184
  class TO3Error < RuntimeError; end
174
185
 
@@ -565,6 +576,22 @@ class WriteAsyncTest < UMBaseTest
565
576
  assert_equal 'foo', r.readpartial(3)
566
577
  end
567
578
 
579
+ def test_write_async_dynamic_string
580
+ r, w = IO.pipe
581
+
582
+ assert_equal 0, machine.pending_count
583
+ str = "foo#{123}#{'bar' * 48}"
584
+ len = str.bytesize
585
+ machine.write_async(w.fileno, str)
586
+ str = nil
587
+ GC.start
588
+ assert_equal 1, machine.pending_count
589
+
590
+ machine.snooze
591
+ assert_equal 0, machine.pending_count
592
+ assert_equal "foo#{123}#{'bar' * 48}", r.readpartial(len)
593
+ end
594
+
568
595
  def test_write_async_bad_fd
569
596
  r, _w = IO.pipe
570
597
 
@@ -1283,6 +1310,37 @@ class PipeTest < UMBaseTest
1283
1310
  end
1284
1311
  end
1285
1312
 
1313
+ class PollTest < UMBaseTest
1314
+ def test_poll
1315
+ rfd, wfd = UM.pipe
1316
+
1317
+ events = []
1318
+ f1 = machine.spin do
1319
+ events << :pre
1320
+ events << machine.poll(rfd, UM::POLLIN)
1321
+ events << :post
1322
+ end
1323
+
1324
+ machine.snooze
1325
+ assert_equal [:pre], events
1326
+
1327
+ machine.write(wfd, 'foo')
1328
+ machine.snooze
1329
+ assert_equal [:pre, UM::POLLIN, :post], events
1330
+
1331
+ ret = machine.poll(wfd, UM::POLLOUT)
1332
+ assert_equal UM::POLLOUT, ret
1333
+
1334
+ machine.close(rfd)
1335
+ ret = machine.poll(wfd, UM::POLLOUT | UM::POLLERR)
1336
+ assert_equal UM::POLLOUT | UM::POLLERR, ret
1337
+ end
1338
+
1339
+ def test_poll_bad_fd
1340
+ assert_raises(Errno::EBADF) { machine.poll(9876, POLLIN) }
1341
+ end
1342
+ end
1343
+
1286
1344
  class WaitTest < UMBaseTest
1287
1345
  def test_waitpid
1288
1346
  skip if UM.kernel_version < 607
@@ -1380,6 +1438,17 @@ class StatxTest < UMBaseTest
1380
1438
  io.close
1381
1439
  end
1382
1440
 
1441
+ def test_statx_mask
1442
+ fd = @machine.open(__FILE__, UM::O_RDONLY)
1443
+ ustat = machine.statx(fd, nil, UM::AT_EMPTY_PATH, UM::STATX_MTIME | UM::STATX_SIZE)
1444
+ rstat = File.stat(__FILE__)
1445
+
1446
+ assert_equal rstat.size, ustat[:size]
1447
+ assert_equal rstat.mtime.to_i, ustat[:mtime].to_i
1448
+ ensure
1449
+ @machine.close_async(fd)
1450
+ end
1451
+
1383
1452
  def test_statx_bad_path
1384
1453
  assert_raises(Errno::ENOENT) { machine.statx(UM::AT_FDCWD, 'foobar', 0, UM::STATX_ALL) }
1385
1454
  end
@@ -1417,5 +1486,65 @@ class ForkTest < UMBaseTest
1417
1486
  ensure
1418
1487
  Process.wait(child_pid) rescue Errno::ECHILD
1419
1488
  end
1489
+ end
1490
+
1491
+ class SendBundleTest < UMBaseTest
1492
+ def setup
1493
+ super
1494
+ @client_fd, @server_fd = make_socket_pair
1495
+ end
1496
+
1497
+ def test_send_bundle_splat
1498
+ skip if UringMachine.kernel_version < 610
1499
+
1500
+ bgid = machine.setup_buffer_ring(0, 8)
1501
+ assert_equal 0, bgid
1502
+
1503
+ strs = ['foo', 'bar', 'bazzzzz']
1504
+ len = strs.inject(0) { |len, s| len + s.bytesize }
1505
+
1506
+ ret = machine.send_bundle(@client_fd, bgid, *strs)
1507
+ assert_equal len, ret
1508
+
1509
+ buf = +''
1510
+ ret = machine.recv(@server_fd, buf, 8192, 0)
1511
+ assert_equal len, ret
1512
+ assert_equal strs.join, buf
1513
+ end
1514
+
1515
+ def test_send_bundle_array
1516
+ skip if UringMachine.kernel_version < 610
1517
+
1518
+ bgid = machine.setup_buffer_ring(0, 8)
1519
+ assert_equal 0, bgid
1520
+
1521
+ strs = ['foo', 'bar', 'bazzzzz']
1522
+ len = strs.inject(0) { |len, s| len + s.bytesize }
1523
+
1524
+ ret = machine.send_bundle(@client_fd, bgid, strs)
1525
+ assert_equal len, ret
1526
+
1527
+ buf = +''
1528
+ ret = machine.recv(@server_fd, buf, 8192, 0)
1529
+ assert_equal len, ret
1530
+ assert_equal strs.join, buf
1531
+ end
1532
+
1533
+ def test_send_bundle_non_strings
1534
+ skip if UringMachine.kernel_version < 610
1535
+
1536
+ bgid = machine.setup_buffer_ring(0, 8)
1537
+ assert_equal 0, bgid
1420
1538
 
1539
+ strs = [42, 'bar', false]
1540
+ len = strs.inject(0) { |len, s| len + s.to_s.bytesize }
1541
+
1542
+ ret = machine.send_bundle(@client_fd, bgid, strs)
1543
+ assert_equal len, ret
1544
+
1545
+ buf = +''
1546
+ ret = machine.recv(@server_fd, buf, 8192, 0)
1547
+ assert_equal len, ret
1548
+ assert_equal strs.map(&:to_s).join, buf
1549
+ end
1421
1550
  end
@@ -0,0 +1,74 @@
1
+ #!/bin/sh
2
+ # Copyright (c) 2023 Joshua Sing <joshua@hypera.dev>
3
+ #
4
+ # Permission to use, copy, modify, and distribute this software for any
5
+ # purpose with or without fee is hereby granted, provided that the above
6
+ # copyright notice and this permission notice appear in all copies.
7
+ #
8
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+
16
+ #
17
+ # Usage: changelog.sh <version>
18
+ # Reads the changelog for the specified version from the changelog file.
19
+ # The output will be reformatted for use in GitHub releases.
20
+ #
21
+ # The changelog file defaults to "ChangeLog", but can be changed by setting
22
+ # the environment variable $CHANGELOG_FILE
23
+ #
24
+
25
+ set -e
26
+
27
+ # Check if the version argument is provided
28
+ if [ "$#" -ne 1 ]; then
29
+ echo "Usage: $0 <version>" 1>&2
30
+ exit 1
31
+ fi
32
+
33
+ version="${1#v}"
34
+ changelog_file="${CHANGELOG_FILE:-ChangeLog}"
35
+ found_version=false
36
+ changelog=""
37
+
38
+ # Check if the specified changelog file exists
39
+ if [ ! -f "$changelog_file" ]; then
40
+ echo "Error: Changelog file '$changelog_file' not found" 1>&2
41
+ exit 1
42
+ fi
43
+
44
+ # Read the changelog file line by line
45
+ while IFS= read -r line; do
46
+ # Check for the version line
47
+ if echo "$line" | grep -Eq "^${version} - "; then
48
+ found_version=true
49
+ continue
50
+ fi
51
+
52
+ # Continue reading the changelog until the next version or end of file,
53
+ # skipping empty lines
54
+ if $found_version; then
55
+ echo "$line" | grep -Eq "^\s*$" && continue
56
+ echo "$line" | grep -Eq "^[0-9]+\.[0-9]+\.[0-9]+ - " && break
57
+ changelog="${changelog}${line}\n"
58
+ fi
59
+ done < "$changelog_file"
60
+
61
+ # If the specified version was not found, print an error
62
+ if ! $found_version; then
63
+ echo "Error: Version $version was not found in changelog" 1>&2
64
+ exit 1
65
+ fi
66
+
67
+ # Tidy up the changelog for displaying on GitHub
68
+ changelog=$(echo "$changelog" | sed -e 's/^\t\*/###/' -e 's/^\t//')
69
+
70
+ # Print the changelog for the specified version
71
+ echo "$changelog"
72
+ echo
73
+ echo "Full changelog: https://github.com/libressl/portable/blob/master/ChangeLog"
74
+ exit 0
@@ -0,0 +1,35 @@
1
+ # GitHub Actions workflow to run tests on Android.
2
+ name: "Android"
3
+
4
+ on: [push, pull_request]
5
+
6
+ concurrency:
7
+ group: "${{ github.workflow }}-${{ github.event.number || github.ref }}"
8
+ cancel-in-progress: true
9
+
10
+ jobs:
11
+ test:
12
+ name: "Test ${{ matrix.name }}"
13
+ runs-on: ubuntu-24.04
14
+ permissions:
15
+ contents: read
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ include:
20
+ - name: "Android 8-9"
21
+ min-nal: 26
22
+ max-nal: 28
23
+ - name: "Android 10-11"
24
+ min-nal: 29
25
+ max-nal: 30
26
+ steps:
27
+ - name: "Checkout repository"
28
+ uses: actions/checkout@v4
29
+
30
+ - name: "Run CI script"
31
+ run: ./scripts/test
32
+ env:
33
+ ARCH: "android"
34
+ MIN_NAL: "${{ matrix.min-nal }}"
35
+ MAX_NAL: "${{ matrix.max-nal }}"
@@ -0,0 +1,33 @@
1
+ name: CIFuzz
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ concurrency:
7
+ group: "${{ github.workflow }}-${{ github.event.number || github.ref }}"
8
+ cancel-in-progress: true
9
+
10
+ jobs:
11
+ Fuzzing:
12
+ runs-on: ubuntu-24.04
13
+ steps:
14
+ - name: Build Fuzzers
15
+ id: build
16
+ uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
17
+ with:
18
+ oss-fuzz-project-name: 'libressl'
19
+ dry-run: false
20
+ language: c++
21
+ - name: Run Fuzzers
22
+ uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
23
+ with:
24
+ oss-fuzz-project-name: 'libressl'
25
+ fuzz-seconds: 300
26
+ dry-run: false
27
+ language: c++
28
+ - name: Upload Crash
29
+ uses: actions/upload-artifact@v4
30
+ if: failure() && steps.build.outcome == 'success'
31
+ with:
32
+ name: artifacts
33
+ path: ./out/artifacts