kobako 0.29.0 → 0.31.0

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 (291) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +552 -10
  4. data/Cargo.lock +595 -139
  5. data/README.md +126 -564
  6. data/ROADMAP.md +3 -2
  7. data/crates/kobako-runtime/CHANGELOG.md +488 -1
  8. data/crates/kobako-runtime/Cargo.toml +73 -15
  9. data/crates/kobako-runtime/README.md +11 -4
  10. data/crates/kobako-runtime/src/cred.rs +124 -0
  11. data/crates/kobako-runtime/src/dispatch.rs +5 -6
  12. data/crates/kobako-runtime/src/endpoint/buffer.rs +301 -0
  13. data/crates/kobako-runtime/src/endpoint/dispatch.rs +292 -0
  14. data/crates/kobako-runtime/src/endpoint/invoke.rs +181 -0
  15. data/crates/kobako-runtime/src/endpoint.rs +267 -0
  16. data/crates/kobako-runtime/src/errno.rs +391 -0
  17. data/crates/kobako-runtime/src/error.rs +31 -10
  18. data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
  19. data/crates/kobako-runtime/src/filesystem/bind/fid.rs +82 -0
  20. data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +274 -0
  21. data/crates/kobako-runtime/src/filesystem/bind/walk.rs +248 -0
  22. data/crates/kobako-runtime/src/filesystem/bind.rs +2857 -0
  23. data/crates/kobako-runtime/src/filesystem/overlay/file.rs +89 -0
  24. data/crates/kobako-runtime/src/filesystem/overlay/inode.rs +106 -0
  25. data/crates/kobako-runtime/src/filesystem/overlay/path.rs +263 -0
  26. data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +128 -0
  27. data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +238 -0
  28. data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +135 -0
  29. data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +54 -0
  30. data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +316 -739
  31. data/crates/kobako-runtime/src/filesystem/overlay.rs +2627 -1154
  32. data/crates/kobako-runtime/src/filesystem/pipe.rs +224 -0
  33. data/crates/kobako-runtime/src/filesystem/rdir.rs +84 -0
  34. data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
  35. data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +32 -0
  36. data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +107 -0
  37. data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +22 -0
  38. data/crates/kobako-runtime/src/filesystem/tmpfs.rs +1997 -0
  39. data/crates/kobako-runtime/src/filesystem/wrap.rs +208 -0
  40. data/crates/kobako-runtime/src/filesystem.rs +25 -388
  41. data/crates/kobako-runtime/src/fork.rs +96 -0
  42. data/crates/kobako-runtime/src/grant.rs +3 -0
  43. data/crates/kobako-runtime/src/hashtable.rs +46 -0
  44. data/crates/kobako-runtime/src/lib.rs +27 -11
  45. data/crates/kobako-runtime/src/limits.rs +195 -0
  46. data/crates/kobako-runtime/src/locking/seqlock.rs +66 -0
  47. data/crates/kobako-runtime/src/locking.rs +228 -0
  48. data/crates/kobako-runtime/src/memcg.rs +383 -0
  49. data/crates/kobako-runtime/src/mount.rs +86 -101
  50. data/crates/kobako-runtime/src/net/backends.rs +43 -0
  51. data/crates/kobako-runtime/src/net/connections.rs +179 -0
  52. data/crates/kobako-runtime/src/net/credential.rs +125 -0
  53. data/crates/kobako-runtime/src/net/egress.rs +160 -0
  54. data/crates/kobako-runtime/src/net/family.rs +181 -0
  55. data/crates/kobako-runtime/src/net/http.rs +2733 -0
  56. data/crates/kobako-runtime/src/net/lookup.rs +285 -0
  57. data/crates/kobako-runtime/src/net/mock.rs +251 -0
  58. data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
  59. data/crates/kobako-runtime/src/net/reactor.rs +531 -0
  60. data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
  61. data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
  62. data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
  63. data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
  64. data/crates/kobako-runtime/src/net/resolv.rs +227 -0
  65. data/crates/kobako-runtime/src/net/socket.rs +870 -0
  66. data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
  67. data/crates/kobako-runtime/src/net/tls.rs +58 -0
  68. data/crates/kobako-runtime/src/net/transport.rs +279 -0
  69. data/crates/kobako-runtime/src/net/udp.rs +1003 -0
  70. data/crates/kobako-runtime/src/net.rs +42 -0
  71. data/crates/kobako-runtime/src/network/builder.rs +177 -0
  72. data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
  73. data/crates/kobako-runtime/src/network.rs +551 -0
  74. data/crates/kobako-runtime/src/policy.rs +16 -0
  75. data/crates/kobako-runtime/src/profile.rs +37 -16
  76. data/crates/kobako-runtime/src/runtime.rs +3 -5
  77. data/crates/kobako-runtime/src/sched.rs +311 -0
  78. data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
  79. data/crates/kobako-runtime/src/security/hooks.rs +242 -0
  80. data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
  81. data/crates/kobako-runtime/src/security.rs +601 -0
  82. data/crates/kobako-runtime/src/snapshot.rs +121 -2
  83. data/crates/kobako-runtime/src/vfs/attr.rs +162 -0
  84. data/crates/kobako-runtime/src/vfs/dentry.rs +1466 -0
  85. data/crates/kobako-runtime/src/vfs/file.rs +1911 -0
  86. data/crates/kobako-runtime/src/vfs/inode.rs +425 -0
  87. data/crates/kobako-runtime/src/vfs/kern_path.rs +213 -0
  88. data/crates/kobako-runtime/src/vfs/mount.rs +60 -0
  89. data/crates/kobako-runtime/src/vfs/namei.rs +5837 -0
  90. data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
  91. data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
  92. data/crates/kobako-runtime/src/vfs/openat2.rs +116 -0
  93. data/crates/kobako-runtime/src/vfs/path.rs +64 -0
  94. data/crates/kobako-runtime/src/vfs/readdir.rs +163 -0
  95. data/crates/kobako-runtime/src/vfs/stat.rs +293 -0
  96. data/crates/kobako-runtime/src/vfs/super_block.rs +126 -0
  97. data/crates/kobako-runtime/src/vfs/utimes.rs +299 -0
  98. data/crates/kobako-runtime/src/vfs.rs +63 -0
  99. data/crates/kobako-runtime/src/wait.rs +356 -0
  100. data/crates/kobako-transport/CHANGELOG.md +39 -2
  101. data/crates/kobako-transport/Cargo.toml +3 -3
  102. data/crates/kobako-transport/README.md +8 -8
  103. data/crates/kobako-transport/src/abi.rs +78 -72
  104. data/crates/kobako-transport/src/envelope/bytes.rs +49 -30
  105. data/crates/kobako-transport/src/envelope/call.rs +37 -9
  106. data/crates/kobako-transport/src/envelope/compile_reply.rs +2 -2
  107. data/crates/kobako-transport/src/envelope/error_record.rs +24 -3
  108. data/crates/kobako-transport/src/envelope/fault.rs +2 -2
  109. data/crates/kobako-transport/src/envelope/name.rs +99 -0
  110. data/crates/kobako-transport/src/envelope/outcome.rs +11 -11
  111. data/crates/kobako-transport/src/envelope/preamble.rs +34 -31
  112. data/crates/kobako-transport/src/envelope/reply.rs +29 -29
  113. data/crates/kobako-transport/src/envelope/request.rs +2 -2
  114. data/crates/kobako-transport/src/envelope/run.rs +1 -1
  115. data/crates/kobako-transport/src/envelope/unsupported.rs +12 -12
  116. data/crates/kobako-transport/src/envelope.rs +15 -10
  117. data/crates/kobako-wasmtime/CHANGELOG.md +315 -8
  118. data/crates/kobako-wasmtime/Cargo.toml +35 -15
  119. data/crates/kobako-wasmtime/README.md +11 -6
  120. data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
  121. data/crates/kobako-wasmtime/build.rs +16 -0
  122. data/crates/kobako-wasmtime/src/abi.rs +19 -47
  123. data/crates/kobako-wasmtime/src/ambient.rs +33 -19
  124. data/crates/kobako-wasmtime/src/cache.rs +28 -20
  125. data/crates/kobako-wasmtime/src/config.rs +59 -60
  126. data/crates/kobako-wasmtime/src/driver.rs +63 -145
  127. data/crates/kobako-wasmtime/src/exports.rs +147 -32
  128. data/crates/kobako-wasmtime/src/guest.rs +44 -0
  129. data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
  130. data/crates/kobako-wasmtime/src/imports.rs +48 -18
  131. data/crates/kobako-wasmtime/src/instance_pre.rs +7 -7
  132. data/crates/kobako-wasmtime/src/invocation.rs +93 -51
  133. data/crates/kobako-wasmtime/src/lib.rs +6 -7
  134. data/crates/kobako-wasmtime/src/limiter.rs +52 -211
  135. data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
  136. data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +70 -57
  137. data/crates/kobako-wasmtime/src/preview1/differential.rs +137 -27
  138. data/crates/kobako-wasmtime/src/preview1/errno.rs +90 -233
  139. data/crates/kobako-wasmtime/src/preview1/fd.rs +1301 -522
  140. data/crates/kobako-wasmtime/src/preview1/memory.rs +126 -150
  141. data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +192 -0
  142. data/crates/kobako-wasmtime/src/preview1/mount_view.rs +1989 -708
  143. data/crates/kobako-wasmtime/src/preview1/path.rs +181 -365
  144. data/crates/kobako-wasmtime/src/preview1/poll.rs +345 -173
  145. data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -25
  146. data/crates/kobako-wasmtime/src/preview1/testsuite-expected.txt +6 -0
  147. data/crates/kobako-wasmtime/src/preview1/testsuite.rs +147 -0
  148. data/crates/kobako-wasmtime/src/preview1.rs +471 -416
  149. data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
  150. data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
  151. data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
  152. data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
  153. data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
  154. data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
  155. data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
  156. data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
  157. data/crates/kobako-wasmtime/src/preview2.rs +57 -0
  158. data/crates/kobako-wasmtime/src/trap.rs +31 -16
  159. data/crates/kobako-wasmtime/src/wasi.rs +238 -93
  160. data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
  161. data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
  162. data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
  163. data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
  164. data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
  165. data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
  166. data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
  167. data/crates/kobako-wasmtime/witx/typenames.witx +750 -0
  168. data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +441 -0
  169. data/data/kobako.wasm +0 -0
  170. data/ext/kobako/Cargo.toml +1 -1
  171. data/ext/kobako/src/{runtime/errors.rs → errors.rs} +35 -27
  172. data/ext/kobako/src/escape.rs +98 -0
  173. data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +36 -16
  174. data/ext/kobako/src/filesystem/ruby.rs +689 -0
  175. data/ext/kobako/src/filesystem.rs +217 -0
  176. data/ext/kobako/src/gvl.rs +306 -0
  177. data/ext/kobako/src/lib.rs +64 -3
  178. data/ext/kobako/src/network/mock.rs +187 -0
  179. data/ext/kobako/src/network.rs +591 -0
  180. data/ext/kobako/src/runtime/bridge.rs +31 -30
  181. data/ext/kobako/src/runtime/snapshot.rs +5 -5
  182. data/ext/kobako/src/runtime.rs +221 -138
  183. data/ext/kobako/src/wire.rs +42 -0
  184. data/lib/kobako/catalog/extensions.rb +19 -7
  185. data/lib/kobako/catalog/flags.rb +4 -6
  186. data/lib/kobako/catalog/grants.rb +5 -4
  187. data/lib/kobako/catalog/handles.rb +9 -31
  188. data/lib/kobako/catalog/mount.rb +12 -12
  189. data/lib/kobako/catalog/network.rb +35 -0
  190. data/lib/kobako/catalog/replacements.rb +28 -0
  191. data/lib/kobako/catalog/services.rb +7 -21
  192. data/lib/kobako/catalog/snippets.rb +10 -25
  193. data/lib/kobako/catalog.rb +4 -1
  194. data/lib/kobako/codec/{utils.rb → boundary.rb} +5 -3
  195. data/lib/kobako/codec/decoder.rb +12 -12
  196. data/lib/kobako/codec/ext_types.rb +5 -7
  197. data/lib/kobako/codec/handle_walk.rb +5 -47
  198. data/lib/kobako/codec/nesting.rb +7 -7
  199. data/lib/kobako/codec/value_budget.rb +134 -42
  200. data/lib/kobako/codec.rb +1 -1
  201. data/lib/kobako/context.rb +28 -15
  202. data/lib/kobako/errors.rb +15 -12
  203. data/lib/kobako/extension.rb +3 -2
  204. data/lib/kobako/filesystem.rb +53 -15
  205. data/lib/kobako/handle.rb +2 -2
  206. data/lib/kobako/names.rb +28 -0
  207. data/lib/kobako/network.rb +210 -0
  208. data/lib/kobako/outcome.rb +7 -7
  209. data/lib/kobako/payload/arguments.rb +2 -2
  210. data/lib/kobako/pool.rb +47 -25
  211. data/lib/kobako/runtime.rb +3 -2
  212. data/lib/kobako/sandbox.rb +113 -56
  213. data/lib/kobako/sandbox_options.rb +41 -107
  214. data/lib/kobako/snippet/bytecode.rb +1 -1
  215. data/lib/kobako/snippet/source.rb +1 -1
  216. data/lib/kobako/transport/argument_wrap.rb +64 -0
  217. data/lib/kobako/transport/block_failure.rb +1 -1
  218. data/lib/kobako/transport/dispatcher.rb +10 -10
  219. data/lib/kobako/transport/exposure.rb +28 -17
  220. data/lib/kobako/transport/reflection.rb +28 -11
  221. data/lib/kobako/transport/run.rb +13 -28
  222. data/lib/kobako/transport/yielder.rb +3 -10
  223. data/lib/kobako/transport.rb +1 -0
  224. data/lib/kobako/version.rb +1 -1
  225. data/lib/kobako.rb +38 -0
  226. data/release-please-config.json +16 -0
  227. data/sig/core/thread.rbs +6 -0
  228. data/sig/kobako/catalog/extensions.rbs +5 -3
  229. data/sig/kobako/catalog/grants.rbs +7 -4
  230. data/sig/kobako/catalog/handles.rbs +2 -4
  231. data/sig/kobako/catalog/mount.rbs +3 -5
  232. data/sig/kobako/catalog/network.rbs +20 -0
  233. data/sig/kobako/catalog/replacements.rbs +14 -0
  234. data/sig/kobako/catalog/services.rbs +1 -5
  235. data/sig/kobako/catalog/snippets.rbs +3 -5
  236. data/sig/kobako/catalog.rbs +1 -1
  237. data/sig/kobako/codec/boundary.rbs +9 -0
  238. data/sig/kobako/codec/decoder.rbs +1 -1
  239. data/sig/kobako/codec/handle_walk.rbs +0 -6
  240. data/sig/kobako/codec/nesting.rbs +2 -2
  241. data/sig/kobako/codec/value_budget.rbs +48 -5
  242. data/sig/kobako/codec.rbs +1 -2
  243. data/sig/kobako/context.rbs +4 -2
  244. data/sig/kobako/errors.rbs +4 -4
  245. data/sig/kobako/filesystem.rbs +38 -15
  246. data/sig/kobako/guest_yielder.rbs +1 -1
  247. data/sig/kobako/network.rbs +115 -0
  248. data/sig/kobako/outcome.rbs +1 -1
  249. data/sig/kobako/payload/arguments.rbs +1 -1
  250. data/sig/kobako/pool.rbs +8 -4
  251. data/sig/kobako/runtime.rbs +32 -3
  252. data/sig/kobako/sandbox.rbs +22 -7
  253. data/sig/kobako/sandbox_options.rbs +29 -38
  254. data/sig/kobako/transport/argument_wrap.rbs +15 -0
  255. data/sig/kobako/transport/dispatcher.rbs +2 -2
  256. data/sig/kobako/transport/error.rbs +1 -1
  257. data/sig/kobako/transport/exposure.rbs +3 -5
  258. data/sig/kobako/transport/reflection.rbs +12 -2
  259. data/sig/kobako/transport/run.rbs +3 -5
  260. data/sig/kobako/transport/yielder.rbs +0 -3
  261. data/sig/kobako/transport.rbs +2 -2
  262. data/sig/kobako.rbs +13 -0
  263. metadata +131 -34
  264. data/crates/kobako-runtime/src/filesystem/directory/spelling.rs +0 -194
  265. data/crates/kobako-runtime/src/filesystem/directory.rs +0 -1082
  266. data/crates/kobako-runtime/src/filesystem/memory.rs +0 -1100
  267. data/crates/kobako-runtime/src/filesystem/overlay/exclusive.rs +0 -88
  268. data/crates/kobako-runtime/src/filesystem/path.rs +0 -60
  269. data/crates/kobako-runtime/src/filesystem/temporary.rs +0 -167
  270. data/crates/kobako-wasmtime/src/capture.rs +0 -96
  271. data/crates/kobako-wasmtime/src/descriptors.rs +0 -167
  272. data/crates/kobako-wasmtime/src/dispatch.rs +0 -125
  273. data/crates/kobako-wasmtime/src/guest_mem.rs +0 -271
  274. data/crates/kobako-wasmtime/src/io.rs +0 -89
  275. data/crates/kobako-wasmtime/src/preview1/args.rs +0 -60
  276. data/crates/kobako-wasmtime/src/preview1/beneath.rs +0 -188
  277. data/crates/kobako-wasmtime/tests/compile_posture.rs +0 -43
  278. data/crates/kobako-wasmtime/tests/guest_file.rs +0 -1054
  279. data/crates/kobako-wasmtime/tests/preamble_flags.rs +0 -70
  280. data/crates/kobako-wasmtime/tests/snippet_compile.rs +0 -95
  281. data/crates/kobako-wasmtime/tests/support/mod.rs +0 -30
  282. data/crates/kobako-wasmtime/tests/unanswered_call.rs +0 -86
  283. data/crates/kobako-wasmtime/tests/unsupported_call.rs +0 -51
  284. data/ext/kobako/src/runtime/escape.rs +0 -53
  285. data/ext/kobako/src/runtime/filesystem/ruby.rs +0 -400
  286. data/ext/kobako/src/runtime/filesystem.rs +0 -236
  287. data/ext/kobako/src/runtime/gvl.rs +0 -112
  288. data/lib/kobako/constant_name.rb +0 -8
  289. data/sig/kobako/codec/utils.rbs +0 -9
  290. data/sig/kobako/constant_name.rbs +0 -3
  291. /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
@@ -0,0 +1,356 @@
1
+ //! Waiting for what another thread brings, as Linux's wait queues and
2
+ //! `do_poll` are: a producer wakes the queue its event stands on, and a
3
+ //! poller that registered on that queue looks again. A wait ends once its run
4
+ //! is to stop, as `do_poll`'s interruptible sleep ends on a pending signal; the
5
+ //! only signal a run receives is the one that stops it. It waits through the
6
+ //! registered Blocking, as a lock's slow path does.
7
+
8
+ use std::sync::{Arc, Condvar, Mutex, MutexGuard, PoisonError};
9
+ use std::task::Waker;
10
+ use std::time::Instant;
11
+
12
+ use crate::sched;
13
+ use crate::Errno;
14
+
15
+ /// Where the waiters for one event stand, as Linux's `wait_queue_head_t`.
16
+ #[derive(Default)]
17
+ pub struct WaitQueueHead {
18
+ waiters: Mutex<Vec<Arc<Waiter>>>,
19
+ /// The tasks waiting here, each woken once and then gone, as an entry
20
+ /// `init_waitqueue_func_entry` makes with `autoremove_wake_function`.
21
+ tasks: Mutex<Vec<Waker>>,
22
+ }
23
+
24
+ impl WaitQueueHead {
25
+ /// Wake every waiter standing here, as `wake_up` does once the event
26
+ /// arrived.
27
+ pub fn wake_up(&self) {
28
+ for waiter in self.waiters().iter() {
29
+ waiter.wake();
30
+ }
31
+ let tasks = std::mem::take(&mut *self.tasks.lock().unwrap_or_else(PoisonError::into_inner));
32
+ for task in tasks {
33
+ task.wake();
34
+ }
35
+ }
36
+
37
+ /// Have the task `waker` stands for woken by the next wake here, once, as
38
+ /// `add_wait_queue` adds an entry whose wake function is the task's; a
39
+ /// task already waiting is not added twice.
40
+ pub(crate) fn add(&self, waker: &Waker) {
41
+ let mut tasks = self.tasks.lock().unwrap_or_else(PoisonError::into_inner);
42
+ if !tasks.iter().any(|task| task.will_wake(waker)) {
43
+ tasks.push(waker.clone());
44
+ }
45
+ }
46
+
47
+ fn waiters(&self) -> MutexGuard<'_, Vec<Arc<Waiter>>> {
48
+ self.waiters.lock().unwrap_or_else(PoisonError::into_inner)
49
+ }
50
+ }
51
+
52
+ /// One sleeping poller, as a `poll_wqueues` entry: a wake that arrives
53
+ /// before it sleeps is kept, so none is lost.
54
+ #[derive(Default)]
55
+ pub(crate) struct Waiter {
56
+ woken: Mutex<bool>,
57
+ wake: Condvar,
58
+ }
59
+
60
+ impl Waiter {
61
+ pub(crate) fn wake(&self) {
62
+ *self.woken() = true;
63
+ self.wake.notify_all();
64
+ }
65
+
66
+ /// Sleep until woken or `until` passes.
67
+ fn sleep_until(&self, until: Option<Instant>) {
68
+ let mut woken = self.woken();
69
+ while !*woken {
70
+ woken = match until {
71
+ Some(at) => {
72
+ let left = at.saturating_duration_since(Instant::now());
73
+ if left.is_zero() {
74
+ break;
75
+ }
76
+ self.wake
77
+ .wait_timeout(woken, left)
78
+ .unwrap_or_else(PoisonError::into_inner)
79
+ .0
80
+ }
81
+ None => self
82
+ .wake
83
+ .wait(woken)
84
+ .unwrap_or_else(PoisonError::into_inner),
85
+ };
86
+ }
87
+ *woken = false;
88
+ }
89
+
90
+ fn woken(&self) -> MutexGuard<'_, bool> {
91
+ self.woken.lock().unwrap_or_else(PoisonError::into_inner)
92
+ }
93
+ }
94
+
95
+ /// The queues one poll registered on, as Linux's `poll_table`; dropping it
96
+ /// leaves each, as `poll_freewait` does.
97
+ pub struct PollTable {
98
+ waiter: Arc<Waiter>,
99
+ queues: Vec<Arc<WaitQueueHead>>,
100
+ }
101
+
102
+ impl Drop for PollTable {
103
+ fn drop(&mut self) {
104
+ for queue in &self.queues {
105
+ queue
106
+ .waiters()
107
+ .retain(|waiter| !Arc::ptr_eq(waiter, &self.waiter));
108
+ }
109
+ }
110
+ }
111
+
112
+ /// Have the poll `table` stands for woken by `queue`, as a file's `->poll`
113
+ /// calls `poll_wait`; a poll that will not sleep passes no table.
114
+ pub fn poll_wait(queue: &Arc<WaitQueueHead>, table: Option<&mut PollTable>) {
115
+ if let Some(table) = table {
116
+ queue.waiters().push(table.waiter.clone());
117
+ table.queues.push(queue.clone());
118
+ }
119
+ }
120
+
121
+ /// Ask `poll` until it finds something ready, `end` passes, or the run is to
122
+ /// stop, as Linux's `do_poll` asks each file again whenever a queue it
123
+ /// registered on wakes. `end` is read afresh each turn, so a wait whose
124
+ /// soonest due moves earlier, as an exchange's next timeout starting once the
125
+ /// last ends, sleeps only to the new one. The first ask registers through the
126
+ /// table it is handed; nothing ready by `end` answers `None`, and a run that is
127
+ /// to stop answers EINTR.
128
+ pub fn do_poll<T>(
129
+ end: impl Fn() -> Option<Instant>,
130
+ mut poll: impl FnMut(Option<&mut PollTable>) -> Option<T>,
131
+ ) -> Result<Option<T>, Errno> {
132
+ let mut table = PollTable {
133
+ waiter: Arc::default(),
134
+ queues: Vec::new(),
135
+ };
136
+ if let Some(ready) = poll(Some(&mut table)) {
137
+ return Ok(Some(ready));
138
+ }
139
+ let mut answer = Ok(None);
140
+ sched::sleep_on(&table.waiter, || {
141
+ sched::schedule(&mut || loop {
142
+ if sched::fatal_signal_pending() {
143
+ answer = Err(Errno::Interrupted);
144
+ return;
145
+ }
146
+ let end = end();
147
+ if end.is_some_and(|end| Instant::now() >= end) {
148
+ return;
149
+ }
150
+ let until = match (end, sched::deadline()) {
151
+ (Some(end), Some(deadline)) => Some(end.min(deadline)),
152
+ (end, deadline) => end.or(deadline),
153
+ };
154
+ table.waiter.sleep_until(until);
155
+ if let Some(ready) = poll(None) {
156
+ answer = Ok(Some(ready));
157
+ return;
158
+ }
159
+ })
160
+ });
161
+ answer
162
+ }
163
+
164
+ #[cfg(test)]
165
+ mod tests {
166
+ use std::sync::atomic::{AtomicBool, Ordering};
167
+ use std::thread;
168
+ use std::time::Duration;
169
+
170
+ use super::*;
171
+ use crate::sched::testing::{count_waits, join, within_max_wait};
172
+ use crate::sched::{run_task, Task};
173
+
174
+ /// An end `after` from now, the same each time it is read.
175
+ fn end_after(after: Duration) -> impl Fn() -> Option<Instant> {
176
+ let end = Instant::now() + after;
177
+ move || Some(end)
178
+ }
179
+
180
+ // @behavior RT-335
181
+ #[test]
182
+ fn a_poll_looks_again_once_the_queue_it_registered_on_wakes() {
183
+ let queue = Arc::new(WaitQueueHead::default());
184
+ let ready = Arc::new(AtomicBool::new(false));
185
+ let producer = {
186
+ let (queue, ready) = (queue.clone(), ready.clone());
187
+ thread::spawn(move || {
188
+ while queue.waiters().is_empty() {
189
+ thread::yield_now();
190
+ }
191
+ // The poller has asked once and gone to sleep by now, so only
192
+ // the wake makes it look again before its deadline.
193
+ thread::sleep(Duration::from_millis(50));
194
+ ready.store(true, Ordering::SeqCst);
195
+ queue.wake_up();
196
+ })
197
+ };
198
+ let started = Instant::now();
199
+ let answer = within_max_wait(|| {
200
+ do_poll(
201
+ || None,
202
+ |table| {
203
+ poll_wait(&queue, table);
204
+ ready.load(Ordering::SeqCst).then_some("ready")
205
+ },
206
+ )
207
+ });
208
+ let spent = started.elapsed();
209
+ join("the producer", producer);
210
+ assert!(
211
+ answer == Ok(Some("ready"))
212
+ && queue.waiters().is_empty()
213
+ && spent < Duration::from_secs(5),
214
+ "do_poll with no timeout over a queue another thread wakes once its event arrives \
215
+ must answer what the poll then finds at once, and leave the queue, got {answer:?} \
216
+ after {spent:?}"
217
+ );
218
+ }
219
+
220
+ /// A task's wake, counted.
221
+ #[derive(Default)]
222
+ struct CountsWakes(std::sync::atomic::AtomicUsize);
223
+
224
+ impl std::task::Wake for CountsWakes {
225
+ fn wake(self: Arc<Self>) {
226
+ self.0.fetch_add(1, Ordering::SeqCst);
227
+ }
228
+ }
229
+
230
+ #[test]
231
+ fn a_task_waiting_on_a_queue_is_woken_once_by_its_next_wake() {
232
+ let queue = WaitQueueHead::default();
233
+ let wakes = Arc::new(CountsWakes::default());
234
+ let waker = Waker::from(wakes.clone());
235
+ queue.add(&waker);
236
+ queue.add(&waker);
237
+ queue.wake_up();
238
+ queue.wake_up();
239
+ assert_eq!(
240
+ wakes.0.load(Ordering::SeqCst),
241
+ 1,
242
+ "a task added to a wait queue twice must be woken once by the next wake_up and not \
243
+ by a later one, as an autoremoving wait entry leaves once it wakes"
244
+ );
245
+ }
246
+
247
+ // @behavior RT-335
248
+ #[test]
249
+ fn a_poll_finding_nothing_answers_none_once_its_timeout_passes() {
250
+ let started = Instant::now();
251
+ let answer = do_poll(end_after(Duration::from_millis(20)), |_| None::<()>);
252
+ assert!(
253
+ answer == Ok(None) && started.elapsed() >= Duration::from_millis(20),
254
+ "do_poll with a 20 ms timeout over nothing ready must answer None once it passes, \
255
+ got {answer:?} after {:?}",
256
+ started.elapsed()
257
+ );
258
+ }
259
+
260
+ // @behavior RT-395
261
+ #[test]
262
+ fn a_poll_sleeps_only_to_its_end_once_a_wake_moves_it_earlier() {
263
+ let queue = Arc::new(WaitQueueHead::default());
264
+ let moved = Arc::new(Mutex::new(None::<Instant>));
265
+ let far = Instant::now() + Duration::from_secs(30);
266
+ let waker = {
267
+ let (queue, moved) = (queue.clone(), moved.clone());
268
+ thread::spawn(move || {
269
+ while queue.waiters().is_empty() {
270
+ thread::yield_now();
271
+ }
272
+ thread::sleep(Duration::from_millis(50));
273
+ *moved.lock().unwrap() = Some(Instant::now() + Duration::from_millis(20));
274
+ queue.wake_up();
275
+ })
276
+ };
277
+ let started = Instant::now();
278
+ let answer = within_max_wait(|| {
279
+ do_poll(
280
+ || Some(moved.lock().unwrap().unwrap_or(far)),
281
+ |table| {
282
+ poll_wait(&queue, table);
283
+ None::<()>
284
+ },
285
+ )
286
+ });
287
+ let spent = started.elapsed();
288
+ join("the waker", waker);
289
+ assert!(
290
+ answer == Ok(None) && spent < Duration::from_secs(5),
291
+ "do_poll over nothing ready, its 30 s end moved to 20 ms after a wake, must answer \
292
+ None once the moved end passes, got {answer:?} after {spent:?}"
293
+ );
294
+ }
295
+
296
+ // @behavior RT-267
297
+ #[test]
298
+ fn a_poll_ends_with_eintr_once_its_thread_is_interrupted() {
299
+ let (task, waiting) = (Arc::new(Mutex::new(None)), Arc::new(AtomicBool::new(false)));
300
+ let poller = {
301
+ let (task, waiting) = (task.clone(), waiting.clone());
302
+ thread::spawn(move || {
303
+ run_task(Some(Instant::now() + Duration::from_secs(10)), || {
304
+ *task.lock().unwrap() = Some(Task::current());
305
+ do_poll(
306
+ || None,
307
+ |_| {
308
+ waiting.store(true, Ordering::SeqCst);
309
+ None::<()>
310
+ },
311
+ )
312
+ })
313
+ })
314
+ };
315
+ crate::sched::testing::wait_until("the poll", || waiting.load(Ordering::SeqCst));
316
+ // The poller has asked once and gone to sleep by now, so only a wake
317
+ // from the interrupt ends it before its deadline.
318
+ thread::sleep(Duration::from_millis(50));
319
+ task.lock().unwrap().as_ref().unwrap().interrupt();
320
+ let started = Instant::now();
321
+ let answer = join("the interrupted poll", poller);
322
+ assert!(
323
+ answer == Err(Errno::Interrupted) && started.elapsed() < Duration::from_secs(1),
324
+ "do_poll with no timeout, its thread interrupted, must answer EINTR without waiting \
325
+ for its deadline, got {answer:?} after {:?}",
326
+ started.elapsed()
327
+ );
328
+ }
329
+
330
+ // @behavior RT-267
331
+ #[test]
332
+ fn a_poll_ends_with_eintr_once_its_deadline_passes() {
333
+ let answer = run_task(Some(Instant::now() + Duration::from_millis(20)), || {
334
+ do_poll(|| None, |_| None::<()>)
335
+ });
336
+ assert_eq!(
337
+ answer,
338
+ Err(Errno::Interrupted),
339
+ "do_poll with no timeout, past its run's deadline, must answer EINTR"
340
+ );
341
+ }
342
+
343
+ // @behavior RT-336
344
+ #[test]
345
+ fn a_poll_that_sleeps_waits_through_the_registered_blocking() {
346
+ let waits = count_waits();
347
+ let _ = do_poll(end_after(Duration::from_millis(1)), |_| None::<()>);
348
+ let _ = do_poll(end_after(Duration::from_secs(1)), |_| Some(()));
349
+ assert_eq!(
350
+ waits.load(Ordering::SeqCst),
351
+ 1,
352
+ "do_poll must sleep through the registered Blocking only when its first ask finds \
353
+ nothing ready"
354
+ );
355
+ }
356
+ }
@@ -1,12 +1,49 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.21.0](https://github.com/elct9620/kobako/compare/kobako-transport-v0.20.0...kobako-transport-v0.21.0) (2026-11-18)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * **transport:** kobako_transport::envelope::Reply is CallReply.
9
+ * **transport:** call Driver::from_file in place of Driver::new;
10
+ * **transport:** a Guest Binary built against ABI 5 is refused at construction. Rebuild it against kobako-core, whose export_guest! emits the new names. kobako-transport drops ABI_VERSION as a u32, FRAME_LEN_SIZE, MAX_FRAME_LEN, pack_ptr_len, and unpack_ptr_len, and names the ABI through ABI_VERSION ("0.6.0"), GUEST_INTERFACE, HOST_INTERFACE, DOWNCALL, UPCALL, and PREAMBLE. kobako-core drops alloc; answer returns the return area's address.
11
+ * **transport:** kobako_transport::abi::MAX_DISPATCH_PAYLOAD is renamed to MAX_MESSAGE_LEN; its value is unchanged.
12
+
13
+ ### Features
14
+
15
+ * **transport:** carry the Guest ABI in the Canonical ABI's core shape ([34b9560](https://github.com/elct9620/kobako/commit/34b956001a05e15fe29febd7098b2ceb054e1bab))
16
+ * **transport:** expose the Capability Handle id bound the Envelope holds ([8a48012](https://github.com/elct9620/kobako/commit/8a48012cbac62c6a4a67c0c47664ee03a8089605))
17
+ * **transport:** spell once the form of a name a guest interns ([95c10bc](https://github.com/elct9620/kobako/commit/95c10bcf7180fc0e5ef432a9935ce3f856c75c9f))
18
+ * **transport:** spell once the names a Panic carries that a Frontend reads ([d1fb291](https://github.com/elct9620/kobako/commit/d1fb291082abcc376fc17d2f53b2e7d69dbf5da2))
19
+ * **transport:** spell once the Service and entrypoint names a Panic carries ([fd09028](https://github.com/elct9620/kobako/commit/fd09028dee973397c66eb2029f7fd75bf6e7ee26))
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * **guest:** say a guest supports no block, as the glossary words an Unsupported ([3aa9a78](https://github.com/elct9620/kobako/commit/3aa9a7844780ba095fa2d197c3ab1a163a33dce6))
25
+ * **transport:** refuse a Call target past the wire's Handle id range ([8a9b169](https://github.com/elct9620/kobako/commit/8a9b1694f96dc0769fff3251a76c3e1cb52a4866))
26
+
27
+
28
+ ### Code Refactoring
29
+
30
+ * **transport:** load a Driver from its file, and read an origin as a lookup that may miss ([4ec8d79](https://github.com/elct9620/kobako/commit/4ec8d792ddf14bb21cfd36437b64b2389ee6df89))
31
+ * **transport:** name a Call's reply CallReply beside YieldReply and CompileReply ([f34063e](https://github.com/elct9620/kobako/commit/f34063ee94edb723800b4a0670cf912aa1a445e0))
32
+ * **transport:** name the message cap by what it bounds ([133e1c1](https://github.com/elct9620/kobako/commit/133e1c151506a1f41d5f2d17ac2678648c6ed262))
33
+
34
+ ## [0.20.0](https://github.com/elct9620/kobako/compare/kobako-transport-v0.19.0...kobako-transport-v0.20.0) (2026-11-07)
35
+
36
+
37
+ ### Bug Fixes
38
+
39
+ * **transport:** call the Envelope by its name when one fails to decode ([411c8d5](https://github.com/elct9620/kobako/commit/411c8d505e2d939b8014b5406b1a9625b865f02b))
40
+
3
41
  ## [0.19.0](https://github.com/elct9620/kobako/compare/kobako-transport-v0.18.0...kobako-transport-v0.19.0) (2026-10-26)
4
42
 
5
43
 
6
44
  ### ⚠ BREAKING CHANGES
7
45
 
8
- * in kobako-transport, YieldReply::Break carries no payload and Reply gains a Break arm, so a Guest Binary built against the earlier version 5 wire must be rebuilt.
9
- * the Guest ABI is version 5, so a Guest Binary built against version 4 is refused at Sandbox construction until rebuilt. The Yielder trait of kobako-runtime gains frame and takes the frame in yield_to_block; the Guest trait of kobako-core and the MrbGuest trait of kobako-mruby take the frame in yield_to_block; Downcall::Yield carries frame and args.
46
+ * the Guest ABI is version 5, so a Guest Binary built against version 4 is refused at Sandbox construction until rebuilt. In kobako-transport, Reply gains a Break arm and YieldReply::Break carries no payload. The Yielder trait of kobako-runtime gains frame and takes the frame in yield_to_block; the Guest trait of kobako-core and the MrbGuest trait of kobako-mruby take the frame in yield_to_block; Downcall::Yield carries frame and args.
10
47
 
11
48
  ### Features
12
49
 
@@ -1,6 +1,6 @@
1
1
  # kobako-transport — the fixed tier of the kobako wire.
2
2
  #
3
- # The core envelope: the outer frame every host↔guest message rides in,
3
+ # The Envelope: the outer frame every host↔guest message rides in,
4
4
  # carrying routing and outcome attribution and handing the payload
5
5
  # through untouched. A host, a payload codec, and a guest are chosen
6
6
  # independently only because this layer is the same in every assembly,
@@ -12,9 +12,9 @@
12
12
 
13
13
  [package]
14
14
  name = "kobako-transport"
15
- version = "0.19.0"
15
+ version = "0.21.0"
16
16
  edition = "2021"
17
- description = "The kobako core envelope — the fixed host↔guest wire frame every assembly shares."
17
+ description = "The kobako Envelope —the fixed host↔guest wire frame every assembly shares."
18
18
  license = "Apache-2.0"
19
19
  repository = "https://github.com/elct9620/kobako"
20
20
  readme = "README.md"
@@ -9,15 +9,14 @@ same in every assembly. This crate is both of them, and nothing else.
9
9
 
10
10
  | Module | What it fixes |
11
11
  |---|---|
12
- | `envelope` | the **core envelope**, the outer frame each message rides in |
12
+ | `envelope` | the **Envelope**, the outer frame each message rides in |
13
13
  | `abi` | the values both sides agree on before exchanging a byte |
14
14
 
15
15
  The envelope covers the downcall's and the upcall's requests under one
16
16
  tag registry. It also covers a dispatch round-trip, how an invocation
17
17
  ended, and what an invocation is handed, and re-exports every message
18
- type. The ABI values are the version, the packed `(ptr, len)` return
19
- layout, the length prefix the Preamble rides stdin behind, and the
20
- message size cap.
18
+ type. The ABI values are the version, the interface and function
19
+ names it carries, and the message size cap.
21
20
 
22
21
  ## Opaque Payload
23
22
 
@@ -28,7 +27,7 @@ so that payload reaches its reader as a view rather than a copy.
28
27
 
29
28
  ```text
30
29
  Call { method, payload }
31
- └── opaque here; read by whoever owns the schema
30
+ +-- opaque here; read by whoever owns the schema
32
31
  ```
33
32
 
34
33
  ## Dependency Position
@@ -37,8 +36,9 @@ This crate depends on no other, and every kobako tier depends on it —
37
36
  including any third-party engine, codec, or guest composing against them.
38
37
 
39
38
  ```text
40
- host kobako-runtime · kobako-wasmtime ──┐
41
- guest kobako-core · kobako-mruby ────────┴──> kobako-transport
39
+ host kobako-runtime, kobako-wasmtime --+
40
+ +--> kobako-transport
41
+ guest kobako-core, kobako-mruby --------+
42
42
  ```
43
43
 
44
44
  The golden vectors in this crate are derived from the kobako repository's
@@ -51,7 +51,7 @@ reaches the same types through `kobako-core`.
51
51
 
52
52
  ```toml
53
53
  [dependencies]
54
- kobako-transport = "0.19.0" # x-release-please-version
54
+ kobako-transport = "0.21.0" # x-release-please-version
55
55
  ```
56
56
 
57
57
  ## License
@@ -1,88 +1,94 @@
1
- //! The ABI's fixed values — the numbers and layouts a host and a guest
2
- //! must already agree on before either can read the other's bytes.
1
+ //! The ABI's fixed values — the names and limits a host and a guest must
2
+ //! already agree on before either can read the other's bytes.
3
3
  //!
4
4
  //! The symbols that carry the ABI are declared where they are
5
5
  //! implemented: the guest contract crate emits the exports, the driver
6
- //! resolves them and provides the import. What lives here is what both sides must spell the
7
- //! same way, and each value is spelled once.
6
+ //! resolves them and provides the imports. What lives here is what both
7
+ //! sides must spell the same way.
8
8
 
9
- /// The Guest ABI version. A host accepts a Guest Binary only when the
10
- /// version it reports equals this one, so a framing or symbol change is
11
- /// an increment rather than a negotiation. A new request tag needs
12
- /// neither, but a new answer arm is an increment.
13
- pub const ABI_VERSION: u32 = 5;
9
+ /// Spell an ABI name as a literal, for the attributes that accept no
10
+ /// constant: a guest's `export_name`, and its `wasm_import_module` through
11
+ /// `(host => $then)`, which hands the host interface to `$then!`.
12
+ ///
13
+ /// `wasm_import_module` takes no macro, so the host interface is spelled
14
+ /// once more there; a build whose spelling no longer matches
15
+ /// `HOST_INTERFACE` fails.
16
+ #[doc(hidden)]
17
+ #[macro_export]
18
+ macro_rules! abi_name {
19
+ (version) => {
20
+ "0.6.0"
21
+ };
22
+ (guest) => {
23
+ concat!("kobako:abi/guest@", $crate::abi_name!(version))
24
+ };
25
+ (host) => {
26
+ concat!("kobako:abi/host@", $crate::abi_name!(version))
27
+ };
28
+ (host => $then:ident) => {
29
+ $crate::abi_name!(@import $then "kobako:abi/host@0.6.0");
30
+ };
31
+ (@import $then:ident $module:literal) => {
32
+ $then!($module);
33
+ const _: () = assert!($crate::abi::is_host_interface($module));
34
+ };
35
+ (downcall) => {
36
+ "downcall"
37
+ };
38
+ (downcall_export) => {
39
+ concat!($crate::abi_name!(guest), "#", $crate::abi_name!(downcall))
40
+ };
41
+ (upcall) => {
42
+ "upcall"
43
+ };
44
+ (preamble) => {
45
+ "preamble"
46
+ };
47
+ }
14
48
 
15
- /// Width in bytes of the length prefix that frames a message on WASI
16
- /// stdin, such as the Preamble.
17
- pub const FRAME_LEN_SIZE: usize = 4;
49
+ /// The Guest ABI version, as the semver every ABI name carries. A host
50
+ /// accepts a Guest Binary only when its names carry this one, so a framing
51
+ /// or symbol change is an increment rather than a negotiation. A new request
52
+ /// tag needs neither, but a new answer arm is an increment.
53
+ pub const ABI_VERSION: &str = abi_name!(version);
18
54
 
19
- /// Single-dispatch size cap: 16 MiB in either direction, applied to the
20
- /// whole envelope rather than the payload alone. A larger transfer is a
21
- /// wire violation the receiving side refuses before allocating for it.
22
- pub const MAX_DISPATCH_PAYLOAD: usize = 16 * 1024 * 1024;
55
+ /// The interface a Guest Binary exports its downcall under.
56
+ pub const GUEST_INTERFACE: &str = abi_name!(guest);
23
57
 
24
- /// Allocation ceiling on a length-prefixed frame. A reader learns a frame's
25
- /// length before it can check anything else about it, so this bounds what a
26
- /// declared length may make it allocate. It sits above
27
- /// `MAX_DISPATCH_PAYLOAD` because it guards the read rather than enforcing
28
- /// the contract: the host enforces the 16 MiB cap before it sends a frame.
29
- pub const MAX_FRAME_LEN: usize = 64 * 1024 * 1024;
58
+ /// The interface a Guest Binary imports the upcall and the Preamble from.
59
+ pub const HOST_INTERFACE: &str = abi_name!(host);
30
60
 
31
- // The read guard must admit every frame the contract allows, so a refusal
32
- // names the cap rather than the allocation ceiling.
33
- const _: () = assert!(MAX_FRAME_LEN > MAX_DISPATCH_PAYLOAD);
61
+ /// The guest function a host calls with each request.
62
+ pub const DOWNCALL: &str = abi_name!(downcall);
34
63
 
35
- /// Pack `(ptr, len)` into the u64 the downcall and the upcall answer with: the high 32 bits carry the linear-memory pointer,
36
- /// the low 32 the byte length. A `len` of zero is the failure signal.
37
- ///
38
- /// ```text
39
- /// 63 32 31 0
40
- /// ┌──────────┬────────────┐
41
- /// │ ptr │ len │
42
- /// └──────────┴────────────┘
43
- /// ```
44
- #[inline]
45
- pub fn pack_ptr_len(ptr: u32, len: u32) -> u64 {
46
- ((ptr as u64) << 32) | (len as u64)
47
- }
64
+ /// The core export the downcall stands under: its interface, `#`, then the
65
+ /// function, as the Canonical ABI's legacy core naming spells it.
66
+ pub const DOWNCALL_EXPORT: &str = abi_name!(downcall_export);
48
67
 
49
- /// Read a packed u64 back into `(ptr, len)`.
50
- #[inline]
51
- pub fn unpack_ptr_len(packed: u64) -> (u32, u32) {
52
- ((packed >> 32) as u32, packed as u32)
53
- }
68
+ /// The host function a guest calls with each Call.
69
+ pub const UPCALL: &str = abi_name!(upcall);
54
70
 
55
- #[cfg(test)]
56
- mod tests {
57
- use super::*;
71
+ /// The host function a guest calls for the Preamble of its Invocation.
72
+ pub const PREAMBLE: &str = abi_name!(preamble);
58
73
 
59
- // @behavior WE-001
60
- #[test]
61
- fn the_layout_is_high_ptr_low_len() {
62
- let packed = pack_ptr_len(0xAABB_CCDD, 0x1122_3344);
63
- assert_eq!(
64
- packed, 0xAABB_CCDD_1122_3344,
65
- "the packed u64 must carry ptr in the high half and len in the low half"
66
- );
74
+ /// Whether `module` spells `HOST_INTERFACE`, readable in a const context.
75
+ #[doc(hidden)]
76
+ pub const fn is_host_interface(module: &str) -> bool {
77
+ let (module, host) = (module.as_bytes(), HOST_INTERFACE.as_bytes());
78
+ if module.len() != host.len() {
79
+ return false;
67
80
  }
68
-
69
- // @behavior WE-002
70
- #[test]
71
- fn every_pair_round_trips() {
72
- for &(ptr, len) in &[
73
- (0u32, 0u32),
74
- (0x1000, 1024),
75
- (0x0001_0000, 4),
76
- (0x7fff_ffff, 0xffff),
77
- (1, u32::MAX),
78
- (u32::MAX, 1),
79
- (u32::MAX, u32::MAX),
80
- ] {
81
- assert_eq!(
82
- unpack_ptr_len(pack_ptr_len(ptr, len)),
83
- (ptr, len),
84
- "a ({ptr:#x}, {len:#x}) pair must survive the pack the ABI returns"
85
- );
81
+ let mut i = 0;
82
+ while i < host.len() {
83
+ if module[i] != host[i] {
84
+ return false;
86
85
  }
86
+ i += 1;
87
87
  }
88
+ true
88
89
  }
90
+
91
+ /// The largest message either side sends: 16 MiB, the whole Envelope
92
+ /// rather than the payload alone. A larger one is a wire violation the
93
+ /// receiving side refuses before allocating for it.
94
+ pub const MAX_MESSAGE_LEN: usize = 16 * 1024 * 1024;