kobako 0.30.0 → 0.32.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 (288) hide show
  1. checksums.yaml +4 -4
  2. data/.githooks/linux-tests.sh +29 -0
  3. data/.release-please-manifest.json +1 -1
  4. data/CHANGELOG.md +460 -0
  5. data/Cargo.lock +868 -447
  6. data/README.md +43 -4
  7. data/ROADMAP.md +1 -2
  8. data/crates/kobako-runtime/CHANGELOG.md +309 -0
  9. data/crates/kobako-runtime/Cargo.toml +58 -11
  10. data/crates/kobako-runtime/README.md +7 -4
  11. data/crates/kobako-runtime/src/cred.rs +136 -0
  12. data/crates/kobako-runtime/src/dispatch.rs +4 -5
  13. data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
  14. data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
  15. data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
  16. data/crates/kobako-runtime/src/endpoint.rs +137 -36
  17. data/crates/kobako-runtime/src/errno.rs +391 -0
  18. data/crates/kobako-runtime/src/error.rs +31 -10
  19. data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
  20. data/crates/kobako-runtime/src/filesystem/bind/fid.rs +300 -22
  21. data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +101 -29
  22. data/crates/kobako-runtime/src/filesystem/bind/unicode.rs +109 -0
  23. data/crates/kobako-runtime/src/filesystem/bind/walk.rs +52 -34
  24. data/crates/kobako-runtime/src/filesystem/bind.rs +812 -447
  25. data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
  26. data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
  27. data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +11 -16
  28. data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
  29. data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
  30. data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
  31. data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +120 -37
  32. data/crates/kobako-runtime/src/filesystem/overlay.rs +578 -388
  33. data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
  34. data/crates/kobako-runtime/src/filesystem/rdir.rs +14 -50
  35. data/crates/kobako-runtime/src/filesystem/testing.rs +31 -0
  36. data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
  37. data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
  38. data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
  39. data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
  40. data/crates/kobako-runtime/src/filesystem/tmpfs.rs +219 -173
  41. data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
  42. data/crates/kobako-runtime/src/filesystem.rs +8 -3
  43. data/crates/kobako-runtime/src/fork.rs +319 -0
  44. data/crates/kobako-runtime/src/grant.rs +3 -0
  45. data/crates/kobako-runtime/src/hashtable.rs +4 -2
  46. data/crates/kobako-runtime/src/lib.rs +18 -7
  47. data/crates/kobako-runtime/src/limits.rs +171 -0
  48. data/crates/kobako-runtime/src/locking/seqlock.rs +29 -3
  49. data/crates/kobako-runtime/src/locking.rs +518 -113
  50. data/crates/kobako-runtime/src/memcg.rs +306 -0
  51. data/crates/kobako-runtime/src/mount.rs +37 -9
  52. data/crates/kobako-runtime/src/net/backends.rs +43 -0
  53. data/crates/kobako-runtime/src/net/connections.rs +219 -0
  54. data/crates/kobako-runtime/src/net/credential.rs +125 -0
  55. data/crates/kobako-runtime/src/net/egress.rs +180 -0
  56. data/crates/kobako-runtime/src/net/family.rs +181 -0
  57. data/crates/kobako-runtime/src/net/http.rs +3165 -0
  58. data/crates/kobako-runtime/src/net/lookup.rs +385 -0
  59. data/crates/kobako-runtime/src/net/mock.rs +251 -0
  60. data/crates/kobako-runtime/src/net/namespace.rs +1368 -0
  61. data/crates/kobako-runtime/src/net/reactor.rs +626 -0
  62. data/crates/kobako-runtime/src/net/resolv/darwin.rs +280 -0
  63. data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +519 -0
  64. data/crates/kobako-runtime/src/net/resolv/stub.rs +542 -0
  65. data/crates/kobako-runtime/src/net/resolv/windows.rs +218 -0
  66. data/crates/kobako-runtime/src/net/resolv.rs +251 -0
  67. data/crates/kobako-runtime/src/net/skbuff.rs +109 -0
  68. data/crates/kobako-runtime/src/net/socket.rs +869 -0
  69. data/crates/kobako-runtime/src/net/task.rs +223 -0
  70. data/crates/kobako-runtime/src/net/tcp.rs +1840 -0
  71. data/crates/kobako-runtime/src/net/tls.rs +120 -0
  72. data/crates/kobako-runtime/src/net/transport.rs +304 -0
  73. data/crates/kobako-runtime/src/net/udp.rs +1105 -0
  74. data/crates/kobako-runtime/src/net.rs +45 -0
  75. data/crates/kobako-runtime/src/network/builder.rs +177 -0
  76. data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
  77. data/crates/kobako-runtime/src/network.rs +551 -0
  78. data/crates/kobako-runtime/src/policy.rs +16 -0
  79. data/crates/kobako-runtime/src/profile.rs +29 -144
  80. data/crates/kobako-runtime/src/runtime.rs +3 -5
  81. data/crates/kobako-runtime/src/sched.rs +338 -51
  82. data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
  83. data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
  84. data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
  85. data/crates/kobako-runtime/src/security.rs +125 -209
  86. data/crates/kobako-runtime/src/snapshot.rs +121 -2
  87. data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
  88. data/crates/kobako-runtime/src/vfs/dentry.rs +210 -117
  89. data/crates/kobako-runtime/src/vfs/file.rs +243 -248
  90. data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
  91. data/crates/kobako-runtime/src/vfs/kern_path.rs +62 -53
  92. data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
  93. data/crates/kobako-runtime/src/vfs/namei.rs +1162 -818
  94. data/crates/kobako-runtime/src/vfs/namespace.rs +245 -0
  95. data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
  96. data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
  97. data/crates/kobako-runtime/src/vfs/path.rs +6 -6
  98. data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
  99. data/crates/kobako-runtime/src/vfs/stat.rs +248 -23
  100. data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
  101. data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
  102. data/crates/kobako-runtime/src/vfs.rs +10 -6
  103. data/crates/kobako-runtime/src/wait.rs +381 -0
  104. data/crates/kobako-transport/CHANGELOG.md +38 -0
  105. data/crates/kobako-transport/Cargo.toml +1 -1
  106. data/crates/kobako-transport/README.md +3 -4
  107. data/crates/kobako-transport/src/abi.rs +78 -72
  108. data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
  109. data/crates/kobako-transport/src/envelope/call.rs +32 -4
  110. data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
  111. data/crates/kobako-transport/src/envelope/name.rs +99 -0
  112. data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
  113. data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
  114. data/crates/kobako-transport/src/envelope/reply.rs +27 -27
  115. data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
  116. data/crates/kobako-transport/src/envelope.rs +13 -8
  117. data/crates/kobako-wasmtime/CHANGELOG.md +208 -0
  118. data/crates/kobako-wasmtime/Cargo.toml +47 -7
  119. data/crates/kobako-wasmtime/README.md +4 -3
  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 +18 -37
  123. data/crates/kobako-wasmtime/src/ambient.rs +43 -19
  124. data/crates/kobako-wasmtime/src/cache/unix.rs +95 -0
  125. data/crates/kobako-wasmtime/src/cache/windows.rs +359 -0
  126. data/crates/kobako-wasmtime/src/cache.rs +106 -113
  127. data/crates/kobako-wasmtime/src/config.rs +52 -68
  128. data/crates/kobako-wasmtime/src/driver.rs +80 -82
  129. data/crates/kobako-wasmtime/src/exports.rs +143 -17
  130. data/crates/kobako-wasmtime/src/guest.rs +12 -6
  131. data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
  132. data/crates/kobako-wasmtime/src/imports.rs +42 -18
  133. data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
  134. data/crates/kobako-wasmtime/src/invocation.rs +91 -15
  135. data/crates/kobako-wasmtime/src/lib.rs +7 -3
  136. data/crates/kobako-wasmtime/src/limiter.rs +130 -12
  137. data/crates/kobako-wasmtime/src/preview1/descriptors.rs +305 -0
  138. data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +9 -20
  139. data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
  140. data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
  141. data/crates/kobako-wasmtime/src/preview1/fd.rs +347 -312
  142. data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
  143. data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
  144. data/crates/kobako-wasmtime/src/preview1/mount_view.rs +335 -388
  145. data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
  146. data/crates/kobako-wasmtime/src/preview1/poll.rs +255 -125
  147. data/crates/kobako-wasmtime/src/preview1/random.rs +125 -0
  148. data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
  149. data/crates/kobako-wasmtime/src/preview1/testing.rs +31 -0
  150. data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
  151. data/crates/kobako-wasmtime/src/preview1.rs +131 -51
  152. data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
  153. data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
  154. data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
  155. data/crates/kobako-wasmtime/src/preview2/host.rs +4319 -0
  156. data/crates/kobako-wasmtime/src/preview2/http.rs +1587 -0
  157. data/crates/kobako-wasmtime/src/preview2/io.rs +328 -0
  158. data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
  159. data/crates/kobako-wasmtime/src/preview2/table.rs +257 -0
  160. data/crates/kobako-wasmtime/src/preview2.rs +57 -0
  161. data/crates/kobako-wasmtime/src/trap.rs +88 -28
  162. data/crates/kobako-wasmtime/src/waits.rs +59 -0
  163. data/crates/kobako-wasmtime/src/wasi.rs +291 -81
  164. data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
  165. data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
  166. data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
  167. data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
  168. data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
  169. data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
  170. data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
  171. data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +13 -0
  172. data/data/kobako.wasm +0 -0
  173. data/ext/kobako/Cargo.toml +6 -2
  174. data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
  175. data/ext/kobako/src/escape.rs +404 -0
  176. data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +34 -32
  177. data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +158 -170
  178. data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +71 -23
  179. data/ext/kobako/src/fork.rs +72 -0
  180. data/ext/kobako/src/gvl.rs +729 -0
  181. data/ext/kobako/src/handoff.rs +490 -0
  182. data/ext/kobako/src/lib.rs +74 -3
  183. data/ext/kobako/src/network/mock.rs +187 -0
  184. data/ext/kobako/src/network.rs +593 -0
  185. data/ext/kobako/src/pinned_value.rs +44 -0
  186. data/ext/kobako/src/runtime/bridge.rs +58 -50
  187. data/ext/kobako/src/runtime/snapshot.rs +4 -4
  188. data/ext/kobako/src/runtime.rs +272 -163
  189. data/ext/kobako/src/wire.rs +42 -0
  190. data/lib/kobako/catalog/extensions.rb +14 -2
  191. data/lib/kobako/catalog/flags.rb +3 -5
  192. data/lib/kobako/catalog/grants.rb +5 -4
  193. data/lib/kobako/catalog/handles.rb +14 -32
  194. data/lib/kobako/catalog/mount.rb +11 -3
  195. data/lib/kobako/catalog/network.rb +35 -0
  196. data/lib/kobako/catalog/replacements.rb +28 -0
  197. data/lib/kobako/catalog/services.rb +5 -19
  198. data/lib/kobako/catalog/snippets.rb +3 -18
  199. data/lib/kobako/catalog.rb +3 -0
  200. data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
  201. data/lib/kobako/codec/decoder.rb +5 -5
  202. data/lib/kobako/codec/ext_types.rb +3 -3
  203. data/lib/kobako/codec/handle_walk.rb +3 -43
  204. data/lib/kobako/codec/state.rb +2 -18
  205. data/lib/kobako/codec/value_budget.rb +133 -41
  206. data/lib/kobako/codec.rb +6 -7
  207. data/lib/kobako/context.rb +24 -11
  208. data/lib/kobako/errors.rb +18 -18
  209. data/lib/kobako/extension.rb +3 -2
  210. data/lib/kobako/filesystem.rb +10 -3
  211. data/lib/kobako/fork.rb +42 -0
  212. data/lib/kobako/handle.rb +2 -3
  213. data/lib/kobako/names.rb +28 -0
  214. data/lib/kobako/network.rb +210 -0
  215. data/lib/kobako/outcome.rb +7 -7
  216. data/lib/kobako/runtime.rb +3 -2
  217. data/lib/kobako/sandbox.rb +73 -35
  218. data/lib/kobako/sandbox_options.rb +42 -109
  219. data/lib/kobako/transport/argument_wrap.rb +64 -0
  220. data/lib/kobako/transport/block_failure.rb +1 -1
  221. data/lib/kobako/transport/dispatcher.rb +6 -6
  222. data/lib/kobako/transport/exposure.rb +26 -15
  223. data/lib/kobako/transport/reflection.rb +21 -4
  224. data/lib/kobako/transport/run.rb +8 -23
  225. data/lib/kobako/transport/yielder.rb +2 -9
  226. data/lib/kobako/transport.rb +1 -0
  227. data/lib/kobako/usage.rb +4 -2
  228. data/lib/kobako/version.rb +1 -1
  229. data/lib/kobako.rb +8 -4
  230. data/release-please-config.json +15 -0
  231. data/sig/kobako/catalog/extensions.rbs +2 -0
  232. data/sig/kobako/catalog/grants.rbs +7 -4
  233. data/sig/kobako/catalog/handles.rbs +2 -2
  234. data/sig/kobako/catalog/mount.rbs +3 -1
  235. data/sig/kobako/catalog/network.rbs +20 -0
  236. data/sig/kobako/catalog/replacements.rbs +14 -0
  237. data/sig/kobako/catalog/services.rbs +0 -4
  238. data/sig/kobako/catalog/snippets.rbs +0 -2
  239. data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
  240. data/sig/kobako/codec/handle_walk.rbs +0 -6
  241. data/sig/kobako/codec/state.rbs +0 -4
  242. data/sig/kobako/codec/value_budget.rbs +48 -5
  243. data/sig/kobako/codec.rbs +2 -2
  244. data/sig/kobako/context.rbs +3 -1
  245. data/sig/kobako/errors.rbs +4 -7
  246. data/sig/kobako/filesystem.rbs +21 -3
  247. data/sig/kobako/fork.rbs +17 -0
  248. data/sig/kobako/network.rbs +115 -0
  249. data/sig/kobako/outcome.rbs +1 -1
  250. data/sig/kobako/runtime.rbs +32 -3
  251. data/sig/kobako/sandbox.rbs +10 -2
  252. data/sig/kobako/sandbox_options.rbs +29 -40
  253. data/sig/kobako/transport/argument_wrap.rbs +15 -0
  254. data/sig/kobako/transport/error.rbs +1 -1
  255. data/sig/kobako/transport/exposure.rbs +2 -4
  256. data/sig/kobako/transport/reflection.rbs +10 -0
  257. data/sig/kobako/transport/run.rbs +0 -2
  258. data/sig/kobako/transport/yielder.rbs +0 -3
  259. data/sig/kobako/transport.rbs +1 -1
  260. data/sig/kobako.rbs +13 -0
  261. metadata +97 -37
  262. data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
  263. data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
  264. data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
  265. data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
  266. data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
  267. data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
  268. data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
  269. data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
  270. data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
  271. data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
  272. data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
  273. data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
  274. data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
  275. data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
  276. data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
  277. data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
  278. data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
  279. data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
  280. data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
  281. data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
  282. data/ext/kobako/src/runtime/escape.rs +0 -67
  283. data/ext/kobako/src/runtime/gvl.rs +0 -147
  284. data/ext/kobako/src/runtime/pinned_value.rs +0 -31
  285. data/lib/kobako/constant_name.rb +0 -8
  286. data/lib/kobako/pool.rb +0 -140
  287. data/sig/kobako/constant_name.rbs +0 -3
  288. data/sig/kobako/pool.rbs +0 -42
@@ -3,12 +3,14 @@
3
3
  //!
4
4
  //! Owned as the data of each per-invocation `wasmtime::Store`
5
5
  //! and threaded through every host import —
6
- //! the `__kobako_upcall` dispatcher reads the bound dispatch handler,
6
+ //! the `upcall` dispatcher reads the bound dispatch handler, the `preamble`
7
+ //! import the Invocation's Preamble,
7
8
  //! and the WASI imports read the invocation's `Wasi` context, which the
8
9
  //! Store is created with.
9
10
  //!
10
11
  //! The slot also carries the per-invocation wall-clock deadline and the
11
- //! memory cap `MemoryLimiter`, both read from the wasmtime
12
+ //! `MemoryLimiter` charging the guest's growth to the memory budget its
13
+ //! Cred carries, both read from the wasmtime
12
14
  //! `epoch_deadline_callback` / `ResourceLimiter` callbacks installed in
13
15
  //! `Driver::new_store`.
14
16
 
@@ -16,7 +18,10 @@ use std::sync::Arc;
16
18
  use std::time::{Duration, Instant};
17
19
 
18
20
  use kobako_runtime::dispatch::DispatchHandler;
19
- use kobako_runtime::endpoint::{Calls, MemoryCap, ABANDONED};
21
+ use kobako_runtime::endpoint::{Calls, ABANDONED};
22
+ use kobako_runtime::profile::Profile;
23
+
24
+ use wasmtime::{Engine, Store};
20
25
 
21
26
  use crate::exports::Exports;
22
27
  use crate::limiter::MemoryLimiter;
@@ -39,20 +44,48 @@ pub(crate) struct Invocation {
39
44
  wall_time: Duration,
40
45
  exports: Option<Exports>,
41
46
  hostcall_fuel: usize,
47
+ preamble: Arc<[u8]>,
42
48
  }
43
49
 
44
50
  impl Invocation {
45
- pub(crate) fn new(memory_limit: Option<usize>, wasi: Wasi) -> Self {
51
+ /// The guest's growth is charged to the budget `wasi`'s Cred carries, which
52
+ /// counts it against the run's `memory_limit`.
53
+ pub(crate) fn new(wasi: Wasi) -> Self {
54
+ let limiter = MemoryLimiter::new(wasi.cred().memory_budget().clone());
46
55
  Self {
47
56
  wasi,
48
57
  calls: Calls::default(),
49
58
  deadline: None,
50
- limiter: MemoryLimiter(MemoryCap::new(memory_limit)),
59
+ limiter,
51
60
  wall_entry: None,
52
61
  wall_time: Duration::ZERO,
53
62
  exports: None,
54
63
  hostcall_fuel: 0,
64
+ preamble: Arc::from([]),
65
+ }
66
+ }
67
+
68
+ /// The Store the invocation's guest runs in. Each host call may have the
69
+ /// host copy at most the run's `memory_limit` out of the guest, or
70
+ /// wasmtime's default with no limit, as a one-call lift is overhead the
71
+ /// limit sizes.
72
+ pub(crate) fn into_store(self, engine: &Engine) -> wasmtime::Result<Store<Self>> {
73
+ let fuel = self.limiter.budget().limit();
74
+ let mut store = Store::try_new(engine, self)?;
75
+ if let Some(fuel) = fuel {
76
+ store.set_hostcall_fuel(fuel);
55
77
  }
78
+ Ok(store)
79
+ }
80
+
81
+ /// The Preamble bytes the `preamble` import hands the guest; empty until
82
+ /// an entry sets them.
83
+ pub(crate) fn preamble(&self) -> Arc<[u8]> {
84
+ Arc::clone(&self.preamble)
85
+ }
86
+
87
+ pub(crate) fn set_preamble(&mut self, preamble: Vec<u8>) {
88
+ self.preamble = Arc::from(preamble);
56
89
  }
57
90
 
58
91
  /// How much of the guest's memory the call under way may have the host
@@ -107,25 +140,29 @@ impl Invocation {
107
140
  self.deadline
108
141
  }
109
142
 
143
+ pub(crate) fn profile(&self) -> Profile {
144
+ self.wasi.profile()
145
+ }
146
+
110
147
  pub(crate) fn limiter_mut(&mut self) -> &mut MemoryLimiter {
111
148
  &mut self.limiter
112
149
  }
113
150
 
114
- /// Only the `memory.grow` delta past `baseline` is charged, so the
115
- /// image's initial allocation and the high-water mark of earlier
116
- /// invocations do not consume the budget.
117
- pub(crate) fn arm_memory_cap(&mut self, baseline: usize) {
118
- self.limiter.0.activate(baseline);
151
+ /// Growth past the `declared` bytes the Guest Binary's memories and
152
+ /// tables start with is charged from now on.
153
+ pub(crate) fn arm_memory_budget(&mut self, declared: usize) {
154
+ self.limiter.budget().arm(declared);
119
155
  }
120
156
 
121
157
  /// Disarmed once the export returns, so post-run host bookkeeping such
122
158
  /// as reading the answer back is not charged to the script.
123
- pub(crate) fn disarm_memory_cap(&mut self) {
124
- self.limiter.0.deactivate();
159
+ pub(crate) fn disarm_memory_budget(&mut self) {
160
+ self.limiter.budget().disarm();
125
161
  }
126
162
 
127
- /// Stamped right before the guest export call, so the bracket matches
128
- /// the `timeout` accounting and excludes post-run host bookkeeping.
163
+ /// Stamped as the Store opens, so instantiating the guest and writing its
164
+ /// request count as the `timeout` counts them, and post-run host
165
+ /// bookkeeping stays out.
129
166
  pub(crate) fn start_wall_clock(&mut self) {
130
167
  self.wall_entry = Some(Instant::now());
131
168
  }
@@ -141,6 +178,45 @@ impl Invocation {
141
178
  }
142
179
 
143
180
  pub(crate) fn memory_peak(&self) -> usize {
144
- self.limiter.0.peak()
181
+ self.limiter.budget().peak()
182
+ }
183
+ }
184
+
185
+ #[cfg(test)]
186
+ impl Invocation {
187
+ /// An invocation under `config` whose one network entry holds
188
+ /// `endpoints`.
189
+ pub(crate) fn with_network(
190
+ config: &crate::config::Config,
191
+ endpoints: impl IntoIterator<Item = kobako_runtime::network::Endpoint>,
192
+ ) -> Self {
193
+ use kobako_runtime::grant::Grant;
194
+ use kobako_runtime::network::{Builder, Network};
195
+
196
+ let mut entry = Builder::default();
197
+ for endpoint in endpoints {
198
+ entry.endpoint(endpoint);
199
+ }
200
+ let grant = Grant::Network(Network::new("local", Arc::new(entry)).unwrap());
201
+ let wasi = Wasi::for_invocation(config, &[grant]).expect("WASI context must build");
202
+ Self::new(wasi)
203
+ }
204
+
205
+ /// A hermetic invocation whose one network entry holds `endpoints`, or
206
+ /// with no network for `None`, under the hermetic config `adjust` moves.
207
+ pub(crate) fn hermetic(
208
+ endpoints: Option<Vec<kobako_runtime::network::Endpoint>>,
209
+ adjust: impl FnOnce(&mut crate::config::Config),
210
+ ) -> Self {
211
+ let mut config =
212
+ crate::config::Config::for_profile(kobako_runtime::profile::Profile::Hermetic);
213
+ adjust(&mut config);
214
+ match endpoints {
215
+ Some(endpoints) => Self::with_network(&config, endpoints),
216
+ None => {
217
+ let wasi = Wasi::for_invocation(&config, &[]).expect("WASI context must build");
218
+ Self::new(wasi)
219
+ }
220
+ }
145
221
  }
146
222
  }
@@ -5,8 +5,8 @@
5
5
  //! every invocation instantiates a fresh instance from a pre-linked
6
6
  //! template and discards the whole Store afterwards — the
7
7
  //! per-invocation instance discipline. Everything engine-bound
8
- //! lives behind the contract surface, so a frontend shell (the Ruby
9
- //! ext's `Kobako::Runtime`) sees no wasmtime type.
8
+ //! lives behind the contract surface, so a frontend sees no wasmtime
9
+ //! type.
10
10
  //!
11
11
  //! Each module holds one responsibility and opens with its own doc.
12
12
 
@@ -14,16 +14,20 @@ mod abi;
14
14
  mod ambient;
15
15
  mod cache;
16
16
  mod config;
17
- mod descriptors;
18
17
  mod driver;
19
18
  mod exports;
20
19
  mod guest;
20
+ #[cfg(test)]
21
+ mod guest_binary;
21
22
  mod imports;
22
23
  mod instance_pre;
23
24
  mod invocation;
24
25
  mod limiter;
25
26
  mod preview1;
27
+ mod preview2;
26
28
  mod trap;
29
+ #[cfg(test)]
30
+ mod waits;
27
31
  mod wasi;
28
32
 
29
33
  pub use config::Config;
@@ -1,29 +1,147 @@
1
- //! Hands wasmtime's growth hook to the runtime's per-invocation memory cap.
1
+ //! Hands wasmtime's growth hook to the runtime's per-invocation memory budget.
2
2
 
3
- use kobako_runtime::endpoint::MemoryCap;
4
- use wasmtime::ResourceLimiter;
3
+ use std::sync::Arc;
5
4
 
6
- /// wasmtime asks this as `memory.grow` runs; an `Err` becomes the trap
7
- /// surfaced to the host as a guest invocation failure.
8
- pub(crate) struct MemoryLimiter(pub(crate) MemoryCap);
5
+ use kobako_runtime::memcg::{GrowthCharge, MemoryBudget, MemoryLimitExceeded};
6
+ use wasmtime::{Module, ResourceLimiter};
7
+
8
+ /// What one wasm page of a memory takes; the Engine enables no custom page
9
+ /// size.
10
+ const PAGE: usize = 64 * 1024;
11
+
12
+ /// What one table entry takes, a pointer in wasmtime.
13
+ const TABLE_ENTRY: usize = size_of::<usize>();
14
+
15
+ /// The bytes the memories and tables `module` defines start with, which
16
+ /// wasmtime reports as their count and the largest initial size, so a module
17
+ /// whose sizes differ is granted the largest for each.
18
+ pub(crate) fn declared(module: &Module) -> usize {
19
+ let required = module.resources_required();
20
+ let memory = to_usize(required.max_initial_memory_size).saturating_mul(PAGE);
21
+ let table = to_usize(required.max_initial_table_size).saturating_mul(TABLE_ENTRY);
22
+ (required.num_memories as usize)
23
+ .saturating_mul(memory)
24
+ .saturating_add((required.num_tables as usize).saturating_mul(table))
25
+ }
26
+
27
+ fn to_usize(size: Option<u64>) -> usize {
28
+ size.map_or(0, |size| usize::try_from(size).unwrap_or(usize::MAX))
29
+ }
30
+
31
+ /// wasmtime asks this as a memory, a table, or the GC heap is created or
32
+ /// grows; a growth past the budget fails and is kept as the refusal that a
33
+ /// run failing after it is attributed to. A growth it allowed may still
34
+ /// fail, past the memory's maximum or for want of host memory, and its
35
+ /// charge is then given back.
36
+ pub(crate) struct MemoryLimiter {
37
+ budget: Arc<MemoryBudget>,
38
+ pending: Option<GrowthCharge>,
39
+ refused: Option<MemoryLimitExceeded>,
40
+ }
41
+
42
+ impl MemoryLimiter {
43
+ pub(crate) fn new(budget: Arc<MemoryBudget>) -> Self {
44
+ Self {
45
+ budget,
46
+ pending: None,
47
+ refused: None,
48
+ }
49
+ }
50
+
51
+ /// The budget it charges.
52
+ pub(crate) fn budget(&self) -> &MemoryBudget {
53
+ &self.budget
54
+ }
55
+
56
+ /// The last growth the budget refused. The guest only sees the growth
57
+ /// fail, so this is what tells a run that then fails apart as the
58
+ /// budget's.
59
+ pub(crate) fn refused(&self) -> Option<&MemoryLimitExceeded> {
60
+ self.refused.as_ref()
61
+ }
62
+
63
+ /// A growth the budget refuses fails, as `memory.grow` answers -1, rather
64
+ /// than ending the run, so the guest can collect what it no longer holds
65
+ /// and try again, as mruby does once its allocator answers none.
66
+ fn charge(&mut self, bytes: usize) -> wasmtime::Result<bool> {
67
+ match self.budget.charge_growth(bytes) {
68
+ Ok(charge) => {
69
+ self.pending = Some(charge);
70
+ Ok(true)
71
+ }
72
+ Err(refusal) => {
73
+ self.refused = Some(refusal);
74
+ Ok(false)
75
+ }
76
+ }
77
+ }
78
+
79
+ fn give_back(&mut self) {
80
+ if let Some(charge) = self.pending.take() {
81
+ self.budget.cancel_growth(charge);
82
+ }
83
+ }
84
+ }
9
85
 
10
86
  impl ResourceLimiter for MemoryLimiter {
11
87
  fn memory_growing(
12
88
  &mut self,
13
- _current: usize,
89
+ current: usize,
14
90
  desired: usize,
15
91
  _maximum: Option<usize>,
16
92
  ) -> wasmtime::Result<bool> {
17
- self.0.charge(desired).map_err(wasmtime::Error::new)?;
18
- Ok(true)
93
+ self.charge(desired.saturating_sub(current))
94
+ }
95
+
96
+ fn memory_grow_failed(&mut self, _error: wasmtime::Error) -> wasmtime::Result<()> {
97
+ self.give_back();
98
+ Ok(())
19
99
  }
20
100
 
21
101
  fn table_growing(
22
102
  &mut self,
23
- _current: usize,
24
- _desired: usize,
103
+ current: usize,
104
+ desired: usize,
25
105
  _maximum: Option<usize>,
26
106
  ) -> wasmtime::Result<bool> {
27
- Ok(true)
107
+ self.charge(desired.saturating_sub(current).saturating_mul(TABLE_ENTRY))
108
+ }
109
+
110
+ fn table_grow_failed(&mut self, _error: wasmtime::Error) -> wasmtime::Result<()> {
111
+ self.give_back();
112
+ Ok(())
113
+ }
114
+ }
115
+
116
+ #[cfg(test)]
117
+ mod tests {
118
+ use wasmtime::{Memory, MemoryType, Store};
119
+
120
+ use super::*;
121
+
122
+ const PAGE: usize = 64 * 1024;
123
+
124
+ // wasmtime asks the limiter before it checks the memory's own maximum, so
125
+ // only a growth it fails after the budget allowed it shows the charge
126
+ // given back.
127
+ // @behavior S-211
128
+ #[test]
129
+ fn a_growth_the_engine_fails_to_make_costs_the_budget_nothing() {
130
+ let budget = MemoryBudget::new(Some(3 * PAGE));
131
+ budget.arm(PAGE);
132
+ let engine = crate::cache::load_engine().expect("the shared Engine must be built");
133
+ let mut store = Store::new(engine, MemoryLimiter::new(budget.clone()));
134
+ store.limiter(|limiter| limiter);
135
+ let memory = Memory::new(&mut store, MemoryType::new(1, Some(2)))
136
+ .expect("a memory of one page within its maximum must be made");
137
+ let failed = memory.grow(&mut store, 2).is_err();
138
+ let peak = budget.peak();
139
+ let regrown = budget.charge_growth(2 * PAGE).is_ok();
140
+ assert_eq!(
141
+ (failed, peak, regrown),
142
+ (true, 2 * PAGE, true),
143
+ "a growth past a memory's maximum that the budget allowed must fail, give the \
144
+ budget back for the next growth, and stay in the peak reported"
145
+ );
28
146
  }
29
147
  }
@@ -0,0 +1,305 @@
1
+ //! The guest's descriptor table: what each preview1 file descriptor
2
+ //! stands for within one invocation.
3
+ //!
4
+ //! kobako answers every preview1 call that reads this table, so the guest
5
+ //! sees one table and no call falls through to a second one that
6
+ //! disagrees. Numbering follows Linux's `alloc_fd`: the lowest number the
7
+ //! table does not hold is taken. Each number stands over a handle in
8
+ //! preview2's resource table, which holds the file and counts it, as
9
+ //! wasmtime-wasi's preview1 numbers apart from the `ResourceTable` it shares
10
+ //! with preview2. The standard streams stand over preview2 streams, as
11
+ //! `wasi:cli` hands them out, each over its end of a pipe and lent to its
12
+ //! descriptor, so the guest drops none while the descriptor stands.
13
+
14
+ use std::collections::BTreeMap;
15
+ use std::ops::{Deref, DerefMut};
16
+ use std::sync::{Arc, MutexGuard};
17
+
18
+ use kobako_runtime::cred::Cred;
19
+ use kobako_runtime::vfs::File;
20
+ use kobako_runtime::Errno;
21
+
22
+ pub(crate) use crate::preview2::bindings::wasi_filesystem_types_0_2_12::Descriptor as FileHandle;
23
+ use crate::preview2::bindings::wasi_io_streams_0_2_12::{
24
+ InputStream as InputHandle, OutputStream as OutputHandle,
25
+ };
26
+ use crate::preview2::io::{InputStream, OutputStream, Stream};
27
+ use crate::preview2::table::Handle;
28
+ use crate::preview2::Table;
29
+
30
+ /// The preview2 resource one descriptor stands over, by its handle.
31
+ #[derive(Clone, Copy)]
32
+ pub(crate) enum Resource {
33
+ File(FileHandle),
34
+ /// stdin, read as `wasi:cli`'s `get-stdin` hands it.
35
+ Input(InputHandle),
36
+ /// stdout or stderr, written as `wasi:cli`'s `get-stdout` hands it.
37
+ Output(OutputHandle),
38
+ }
39
+
40
+ impl Resource {
41
+ /// The stream a standard stream's descriptor stands over, if it is one.
42
+ fn stream(self, table: &Table) -> Option<&Stream> {
43
+ match self {
44
+ Resource::File(_) => None,
45
+ Resource::Input(handle) => table.get(handle).ok().map(|input| &input.stream),
46
+ Resource::Output(handle) => table.get(handle).ok().map(|output| &output.stream),
47
+ }
48
+ }
49
+ }
50
+
51
+ /// What one descriptor stands for, as Linux's fd table holds a `struct file`.
52
+ pub(crate) struct Descriptor {
53
+ pub(crate) resource: Resource,
54
+ /// The guest path a preopen names; the guest's root has one, `/`.
55
+ pub(crate) preopen_path: Option<String>,
56
+ }
57
+
58
+ impl Descriptor {
59
+ /// The descriptor of the file under `file`, naming no preopen.
60
+ pub(crate) fn for_file(file: FileHandle) -> Self {
61
+ Self {
62
+ resource: Resource::File(file),
63
+ preopen_path: None,
64
+ }
65
+ }
66
+
67
+ fn for_stream(resource: Resource) -> Self {
68
+ Self {
69
+ resource,
70
+ preopen_path: None,
71
+ }
72
+ }
73
+ }
74
+
75
+ pub(crate) struct Descriptors {
76
+ used: BTreeMap<u32, Descriptor>,
77
+ /// No number below this is free, as Linux's `next_fd` hints `alloc_fd`.
78
+ next_fd: u32,
79
+ }
80
+
81
+ impl Descriptors {
82
+ /// The table every invocation starts from: stdin, then the two
83
+ /// Channels, then the guest's root as the one preopen `/`, at descriptor
84
+ /// 3, where `guest` holds one. Each counts against the open files in
85
+ /// `table`, as a process's `RLIMIT_NOFILE` counts every one it holds. The
86
+ /// root opens as `opener`, the Cred the Driver prepared, the topmost mount
87
+ /// stacked on it for `guest`, as Linux's `topmost_overmount` answers.
88
+ pub(crate) fn new(
89
+ stdin: File,
90
+ stdout: File,
91
+ stderr: File,
92
+ table: &mut Table,
93
+ (opener, guest): (&Arc<Cred>, &Arc<Cred>),
94
+ ) -> Result<Self, Errno> {
95
+ let mut used = BTreeMap::new();
96
+ let input = InputStream::new(Stream::from(stdin));
97
+ let input = lend_inherited(table, input)?;
98
+ used.insert(0, Descriptor::for_stream(Resource::Input(input)));
99
+ for (fd, file) in [(1, stdout), (2, stderr)] {
100
+ let output = lend_inherited(table, OutputStream::new(Stream::from(file)))?;
101
+ used.insert(fd, Descriptor::for_stream(Resource::Output(output)));
102
+ }
103
+ if let Some(root) = guest.root() {
104
+ let root = File::root(&guest.topmost_overmount(&root), opener)?;
105
+ used.insert(
106
+ 3,
107
+ Descriptor {
108
+ resource: Resource::File(install_inherited(table, root)?),
109
+ preopen_path: Some("/".to_string()),
110
+ },
111
+ );
112
+ }
113
+ Ok(Self {
114
+ next_fd: used.len() as u32,
115
+ used,
116
+ })
117
+ }
118
+
119
+ pub(crate) fn get(&self, fd: u32) -> Option<&Descriptor> {
120
+ self.used.get(&fd)
121
+ }
122
+
123
+ /// Take `fd` out of the table, freeing its number for reuse.
124
+ pub(crate) fn remove(&mut self, fd: u32) -> Option<Descriptor> {
125
+ let descriptor = self.used.remove(&fd)?;
126
+ self.next_fd = self.next_fd.min(fd);
127
+ Some(descriptor)
128
+ }
129
+
130
+ /// Place `descriptor` at `fd`, a number the caller has just freed or
131
+ /// `lowest_unused` found, as Linux's `fd_install` does.
132
+ pub(crate) fn place(&mut self, fd: u32, descriptor: Descriptor) {
133
+ self.used.insert(fd, descriptor);
134
+ if fd == self.next_fd {
135
+ self.next_fd = self.lowest_unused().unwrap_or(u32::MAX);
136
+ }
137
+ }
138
+
139
+ /// The number the next descriptor takes, the lowest one the table does
140
+ /// not hold, as Linux's `get_unused_fd_flags` finds it.
141
+ pub(crate) fn lowest_unused(&self) -> Option<u32> {
142
+ (self.next_fd..=u32::MAX).find(|fd| !self.used.contains_key(fd))
143
+ }
144
+
145
+ /// The file `fd` stands for, one that stands only for its path included:
146
+ /// the one `table` holds, or the pipe's end a standard stream stands
147
+ /// over, which answers each call as Linux's pipe does.
148
+ pub(crate) fn file<'a>(&self, fd: u32, table: &'a Table) -> Option<FileRef<'a>> {
149
+ let resource = self.get(fd)?.resource;
150
+ Some(match resource {
151
+ Resource::File(handle) => FileRef::Table(table.get(handle).ok()?),
152
+ stream => FileRef::Stream(stream.stream(table)?.lock()),
153
+ })
154
+ }
155
+
156
+ /// The file `fd` stands for, to change.
157
+ pub(crate) fn file_mut<'a>(&self, fd: u32, table: &'a mut Table) -> Option<FileRefMut<'a>> {
158
+ let resource = self.get(fd)?.resource;
159
+ Some(match resource {
160
+ Resource::File(handle) => FileRefMut::Table(table.get_mut(handle).ok()?),
161
+ stream => FileRefMut::Stream(stream.stream(table)?.lock()),
162
+ })
163
+ }
164
+
165
+ /// Take `fd` out of the table, and what it stood over out of `table`:
166
+ /// the file to close, or none for a standard stream, whose lend ends
167
+ /// while preview2's handle keeps the stream.
168
+ pub(crate) fn take(&mut self, fd: u32, table: &mut Table) -> Option<Option<File>> {
169
+ Some(match self.remove(fd)?.resource {
170
+ Resource::File(handle) => table.delete(handle).ok(),
171
+ Resource::Input(handle) => {
172
+ table.end_lend(handle);
173
+ None
174
+ }
175
+ Resource::Output(handle) => {
176
+ table.end_lend(handle);
177
+ None
178
+ }
179
+ })
180
+ }
181
+
182
+ /// Open `file` under the lowest free descriptor; `None` when the
183
+ /// Invocation holds as many files as it may.
184
+ #[cfg(test)]
185
+ pub(crate) fn push_file(&mut self, file: File, table: &mut Table) -> Option<u32> {
186
+ let room = table.reserve_file().ok()?;
187
+ let fd = self.lowest_unused()?;
188
+ let handle = table.install(room, file);
189
+ self.place(fd, Descriptor::for_file(handle));
190
+ Some(fd)
191
+ }
192
+ }
193
+
194
+ /// The handle `resource`, opened before the guest runs, takes in `table`;
195
+ /// refused past the open file limit.
196
+ fn install_inherited<H: Handle>(table: &mut Table, resource: H::Host) -> Result<H, Errno> {
197
+ let room = table.reserve_file()?;
198
+ Ok(table.install(room, resource))
199
+ }
200
+
201
+ /// The handle a standard stream takes in `table`, lent to the descriptor
202
+ /// standing over it.
203
+ fn lend_inherited<H: Handle>(table: &mut Table, stream: H::Host) -> Result<H, Errno> {
204
+ let handle = install_inherited(table, stream)?;
205
+ table.lend(handle);
206
+ Ok(handle)
207
+ }
208
+
209
+ /// A file a descriptor stands for, as `Descriptors::file` finds it.
210
+ pub(crate) enum FileRef<'a> {
211
+ Table(&'a File),
212
+ /// The pipe's end behind a standard stream, which its stream shares.
213
+ Stream(MutexGuard<'a, File>),
214
+ }
215
+
216
+ impl Deref for FileRef<'_> {
217
+ type Target = File;
218
+
219
+ fn deref(&self) -> &File {
220
+ match self {
221
+ FileRef::Table(file) => file,
222
+ FileRef::Stream(file) => file,
223
+ }
224
+ }
225
+ }
226
+
227
+ /// A file a descriptor stands for, to change, as `Descriptors::file_mut`
228
+ /// finds it.
229
+ pub(crate) enum FileRefMut<'a> {
230
+ Table(&'a mut File),
231
+ Stream(MutexGuard<'a, File>),
232
+ }
233
+
234
+ impl Deref for FileRefMut<'_> {
235
+ type Target = File;
236
+
237
+ fn deref(&self) -> &File {
238
+ match self {
239
+ FileRefMut::Table(file) => file,
240
+ FileRefMut::Stream(file) => file,
241
+ }
242
+ }
243
+ }
244
+
245
+ impl DerefMut for FileRefMut<'_> {
246
+ fn deref_mut(&mut self) -> &mut File {
247
+ match self {
248
+ FileRefMut::Table(file) => file,
249
+ FileRefMut::Stream(file) => file,
250
+ }
251
+ }
252
+ }
253
+
254
+ #[cfg(test)]
255
+ mod tests {
256
+ use super::*;
257
+ use kobako_runtime::filesystem::{create_pipe_files, PipeInodeInfo};
258
+ use kobako_runtime::security::prepare_creds;
259
+ use kobako_runtime::vfs::OpenFiles;
260
+
261
+ fn pipe_end() -> File {
262
+ create_pipe_files(&PipeInodeInfo::new(1), &prepare_creds(&[], None)).1
263
+ }
264
+
265
+ // @behavior RT-189
266
+ #[test]
267
+ fn a_new_descriptor_takes_the_lowest_closed_number() {
268
+ let mut table = Table::new(OpenFiles::new(None));
269
+ let mut descriptors = Descriptors::new(
270
+ pipe_end(),
271
+ pipe_end(),
272
+ pipe_end(),
273
+ &mut table,
274
+ (&prepare_creds(&[], None), &prepare_creds(&[], None)),
275
+ )
276
+ .unwrap_or_else(|_| panic!("a table holding no Mount must make"));
277
+ let mut open = |descriptors: &mut Descriptors| {
278
+ let fd = descriptors
279
+ .lowest_unused()
280
+ .expect("a table with no limit numbers every descriptor");
281
+ let file =
282
+ install_inherited(&mut table, pipe_end()).expect("a table with no limit takes it");
283
+ descriptors.place(fd, Descriptor::for_file(file));
284
+ fd
285
+ };
286
+ let numbers = [
287
+ open(&mut descriptors),
288
+ open(&mut descriptors),
289
+ open(&mut descriptors),
290
+ ];
291
+ assert_eq!(numbers, [3, 4, 5], "descriptors must number from 3");
292
+ descriptors.remove(3);
293
+ descriptors.remove(4);
294
+ assert_eq!(
295
+ (
296
+ open(&mut descriptors),
297
+ open(&mut descriptors),
298
+ open(&mut descriptors),
299
+ ),
300
+ (3, 4, 6),
301
+ "path_open's descriptors must take the lowest closed number first, as Linux's alloc_fd \
302
+ does, and then the one past the highest"
303
+ );
304
+ }
305
+ }