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
@@ -25,25 +25,26 @@ module Kobako
25
25
  attr_reader :options
26
26
 
27
27
  def_delegators :@options, :timeout, :setup_timeout, :memory_limit, :stdout_limit, :stderr_limit,
28
- :open_file_limit, :profile, :gvl
28
+ :open_file_limit, :open_connection_limit, :connection_limit, :profile, :gvl
29
29
 
30
30
  # Build a Sandbox on the Guest Binary at +wasm_path+, the one bundled
31
31
  # with the gem by default. The other keywords are the options
32
32
  # SandboxOptions describes.
33
33
  #
34
- # Raises ArgumentError for an invalid option, and SetupError when the
35
- # runtime cannot be built or provides less isolation than +profile+ asks
36
- # for.
34
+ # Raises TypeError for an option of another class, RangeError for a cap
35
+ # past what the host counts, ArgumentError for any other invalid option,
36
+ # and SetupError when the runtime cannot be built or provides less
37
+ # isolation than +profile+ asks for.
37
38
  def initialize(wasm_path: nil, **)
38
39
  @wasm_path = wasm_path || Kobako::Runtime.default_path
39
- @options = SandboxOptions.new(**)
40
+ @options = SandboxOptions.new(**Kobako::Runtime.default_options, **)
40
41
  @services = Kobako::Catalog::Services.new
41
42
  @snippets = Catalog::Snippets.new
42
43
  @flags = Catalog::Flags.new
43
44
  @extensions = Catalog::Extensions.new
44
45
  @grants = Catalog::Grants.new
45
46
  @sealed = false
46
- @runtime = build_runtime!
47
+ @runtime = build_runtime
47
48
  end
48
49
 
49
50
  # Make +object+ reachable from the guest as the constant at +path+, a
@@ -58,11 +59,12 @@ module Kobako
58
59
  # the constant, and Context#bind supplies the object for each invocation.
59
60
  # A call to one left unfilled fails as a ServiceError.
60
61
  #
61
- # Raises ArgumentError for a malformed path, a path under the reserved
62
- # +Kobako+ namespace, a path that collides with an existing binding, or a
63
- # call after the first invocation.
62
+ # Raises TypeError for a path that is no Symbol or String, ArgumentError
63
+ # for a malformed path, a path under the reserved
64
+ # +Kobako+ namespace, or a path that collides with an existing binding,
65
+ # and FrozenError for a call after the first invocation.
64
66
  def bind(path, object = Unresolved)
65
- refuse_once_invoked!("bind")
67
+ refuse_once_invoked("bind")
66
68
  @services.bind(path, object)
67
69
  self
68
70
  end
@@ -71,10 +73,11 @@ module Kobako
71
73
  # backend. Any object answering +name+, +source+, +backend+ and
72
74
  # +depends_on+ works; Extension is the bundled one. Returns +self+.
73
75
  #
74
- # Raises ArgumentError for a malformed Extension, a call after the first
75
- # invocation, or, at the first invocation, a missing dependency.
76
+ # Raises TypeError for an Extension of another shape, FrozenError for a
77
+ # call after the first invocation, and, at the first invocation,
78
+ # ArgumentError for a missing dependency.
76
79
  def install(*extensions)
77
- refuse_once_invoked!("install")
80
+ refuse_once_invoked("install")
78
81
 
79
82
  extensions.each { |extension| @extensions.install(extension, snippets: @snippets, services: @services) }
80
83
  self
@@ -85,22 +88,46 @@ module Kobako
85
88
  # +:read_write+; a write beneath a read-only mount fails as
86
89
  # <tt>Errno::EROFS</tt> in the guest. Returns +self+.
87
90
  #
88
- # A given block decides, in +access+'s place, each open and each change
89
- # that reaches the mount, asked at most once for each with the guest path
90
- # and +:read+ or +:read_write+. A falsy answer,
91
+ # A given block judges each open and each change +access+ allows, asked
92
+ # with the guest path and +:read+ or +:read_write+, and can only refuse
93
+ # more; an open that may create asks +:read_write+ first, then what it
94
+ # opens for. A falsy answer,
91
95
  # or a StandardError, fails that call as <tt>Errno::EACCES</tt> in the
92
96
  # guest and leaves the script running.
93
97
  #
98
+ # A path may sit beneath another mount, standing where Linux's +mount+
99
+ # would place it, and a run fails where Linux would refuse it.
100
+ #
94
101
  # Raises TypeError for a path that is no String or something other than
95
- # a Filesystem, and ArgumentError for a malformed, duplicate, or nested
96
- # path, an unknown access, or a call after the first invocation.
102
+ # a Filesystem, ArgumentError for a malformed or duplicate path or an
103
+ # unknown access, and FrozenError for a call after the first invocation.
97
104
  def mount(at, filesystem, access: :read, &policy)
98
- refuse_once_invoked!("mount")
99
- Runtime.validate_mount!(at, access, filesystem)
105
+ refuse_once_invoked("mount")
100
106
  @grants.register(Catalog::Mount.new(at: at, access: access, filesystem: filesystem, policy: policy))
101
107
  self
102
108
  end
103
109
 
110
+ # Give the guest the network entry +entry+ under +name+, any object
111
+ # answering any of +endpoints+, +credentials+, +resolve?+, +connect?+, and
112
+ # +request?+. A given block yields a Kobako::Network::Builder adding to
113
+ # +entry+, so the block's +self+ stays the caller's. Each entry's endpoints
114
+ # and credentials are read afresh for every invocation. Its +resolve?+ is
115
+ # handed each name the guest looks up, its +connect?+ each
116
+ # Kobako::Network::Connection, and its +request?+ each
117
+ # Kobako::Network::Request; any entry refusing refuses. Returns +self+.
118
+ #
119
+ # Raises TypeError for a name that is no Symbol or String, ArgumentError
120
+ # for an empty or duplicate name, an endpoint with an
121
+ # empty host, a port outside 1 to 65535, or an unknown protocol, and
122
+ # FrozenError for a call after the first invocation. An
123
+ # endpoint the ruleset refuses, such as a wildcard leading to +:private+,
124
+ # raises ArgumentError from the invocation that compiles it.
125
+ def network(name, entry = nil, &builder)
126
+ refuse_once_invoked("network")
127
+ @grants.register(Catalog::Network.new(name: name, entry: entry, &builder))
128
+ self
129
+ end
130
+
104
131
  # Register a snippet that every invocation runs, in the order registered,
105
132
  # before its own code. Returns +self+.
106
133
  #
@@ -110,11 +137,12 @@ module Kobako
110
137
  # Precompiled RITE bytecode, trusted as host code: the unmodified
111
138
  # compiler output of the mruby release the Guest Binary is built on.
112
139
  #
113
- # Raises ArgumentError for a malformed or duplicate snippet, or a call
114
- # after the first invocation. A snippet that fails to load fails every
140
+ # Raises TypeError for a snippet part of another class, ArgumentError for
141
+ # a malformed or duplicate snippet, and FrozenError for a call after the
142
+ # first invocation. A snippet that fails to load fails every
115
143
  # invocation with SandboxError, or BytecodeError for bytecode.
116
144
  def preload(code: nil, name: nil, binary: nil)
117
- refuse_once_invoked!("preload")
145
+ refuse_once_invoked("preload")
118
146
 
119
147
  @snippets.register(code: code, name: name, binary: binary)
120
148
  self
@@ -127,10 +155,10 @@ module Kobako
127
155
  # Mark a flag advisory only when a script cannot tell it was skipped.
128
156
  # Returns +self+.
129
157
  #
130
- # Raises ArgumentError for a malformed or duplicate flag, or a call after
131
- # the first invocation.
158
+ # Raises TypeError for a name or value of another class, ArgumentError for
159
+ # a duplicate flag, and FrozenError for a call after the first invocation.
132
160
  def flag(name, value = "", advisory: false)
133
- refuse_once_invoked!("flag")
161
+ refuse_once_invoked("flag")
134
162
 
135
163
  @flags.register(name, value, advisory: advisory)
136
164
  self
@@ -140,45 +168,39 @@ module Kobako
140
168
  # and +kwargs+, and return the Execution. A given block receives the
141
169
  # invocation's Context before the guest runs.
142
170
  #
143
- # Raises TypeError when +target+ is not a Symbol or String, and
144
- # ArgumentError when it is not a constant name or the arguments carry a
145
- # Handle or a non-Symbol keyword. A failed run raises as #eval does.
171
+ # Raises TypeError when +target+ is not a Symbol or String, a keyword is
172
+ # not a Symbol, or an argument holds a Hash key or a reflective object
173
+ # that cannot cross, and ArgumentError when +target+ is not a constant
174
+ # name, the arguments carry a Handle, or an argument nests past what the
175
+ # wire carries. A failed run raises as #eval does.
146
176
  def run(target, *args, **kwargs, &block)
147
177
  request = Transport::Run.new(entrypoint: target, args: args, kwargs: kwargs)
148
- Codec.within_value_budget(@options.value_budget) { new_invocation.run(request, &block) }
178
+ Codec.within_value_budget(@options.value_budget) { begin_invocation.run(request, &block) }
149
179
  end
150
180
 
151
181
  # Evaluate +code+, mruby source as a String, and return the Execution,
152
182
  # whose +value+ is the last expression. A given block receives the
153
183
  # invocation's Context before the guest runs.
154
184
  #
155
- # Raises TrapError when the engine stopped the guest, a deadline or
156
- # memory budget included; SandboxError when the guest failed, +code+ not
157
- # being a String or the Guest Binary not starting the run included; and
158
- # ServiceError when a Service call failed and the guest left it
185
+ # Raises TypeError when +code+ is no String, and ArgumentError when it is
186
+ # not UTF-8 text, before the guest runs; TrapError when the engine
187
+ # stopped the guest, a deadline or memory budget included; SandboxError
188
+ # when the guest failed, the Guest Binary not starting the run included;
189
+ # and ServiceError when a Service call failed and the guest left it
159
190
  # unrescued.
160
191
  def eval(code, &block)
161
- raise SandboxError, "code must be a String, got #{code.class}" unless code.is_a?(String)
192
+ raise TypeError, "code must be a String, got #{code.class}" unless code.is_a?(String)
162
193
 
163
- Codec.within_value_budget(@options.value_budget) { new_invocation.eval(code, &block) }
194
+ source = code.dup.force_encoding(Encoding::UTF_8)
195
+ raise ArgumentError, "code must be UTF-8 text" unless source.valid_encoding?
196
+
197
+ Codec.within_value_budget(@options.value_budget) { begin_invocation.eval(source, &block) }
164
198
  end
165
199
 
166
200
  private
167
201
 
168
- # A runtime whose declared posture falls below the request never runs
169
- # guest code.
170
- def build_runtime!
171
- runtime = Kobako::Runtime.from_path(@wasm_path, **@options.to_h)
172
- @options.enforce_floor!(runtime.profile)
173
- runtime
174
- end
175
-
176
- # Per-invocation state lives on the Context, so nothing an invocation
177
- # does is written back onto the shared config.
178
- def new_invocation
179
- begin_invocation!
180
- Context.new(runtime: @runtime, services: @services, extensions: @extensions, grants: @grants,
181
- preamble: preamble(@snippets.entries))
202
+ def build_runtime
203
+ Kobako::Runtime.from_path(@wasm_path, **@options.to_h)
182
204
  end
183
205
 
184
206
  # The one place the Preamble's parts are put together, for a compile
@@ -189,17 +211,52 @@ module Kobako
189
211
 
190
212
  # Registration closes at the first invocation, so every invocation ships
191
213
  # the same Services, snippets, flags, Extensions and mounts.
192
- def refuse_once_invoked!(verb)
193
- raise ArgumentError, "cannot #{verb} after first Sandbox invocation" if @sealed
214
+ def refuse_once_invoked(verb)
215
+ raise FrozenError, "cannot #{verb} #{@sealed}" if @sealed
216
+ end
217
+
218
+ # Close registration, saying why for the refusal that follows.
219
+ def seal(reason)
220
+ @sealed = reason
194
221
  end
195
222
 
196
223
  # Sealing before the dependency check keeps a Sandbox whose check failed
197
224
  # closed to further registration. The sealed snippets are compiled once,
198
- # before the first invocation replays them.
199
- def begin_invocation!
200
- @sealed = true
201
- @extensions.assert_dependencies!
225
+ # before the first invocation replays them. Per-invocation state lives on
226
+ # the Context it answers, so nothing an invocation does is written back
227
+ # onto the shared config.
228
+ def begin_invocation
229
+ warn_release_on_main_thread
230
+ seal("after first Sandbox invocation")
231
+ @extensions.assert_dependencies
202
232
  @snippets.compile { |entries| @runtime.compile(preamble(entries)) }
233
+ Context.new(runtime: @runtime, services: @services, extensions: @extensions, grants: @grants,
234
+ preamble: preamble(@snippets.entries))
235
+ end
236
+
237
+ # Ruby runs a signal's trap handler, and a Ractor's +require+, on the main
238
+ # Thread alone, and either raising as a run releasing the GVL takes it back
239
+ # after a Service call leaves the run where it cannot unwind. The first such
240
+ # run warns once.
241
+ def warn_release_on_main_thread
242
+ MainThreadRelease.warn_once if @options.gvl == :release && Thread.current == Thread.main
243
+ end
244
+
245
+ # The process's one warning that a run releasing the GVL ran on the main
246
+ # Thread.
247
+ module MainThreadRelease
248
+ MESSAGE = "Kobako::Sandbox with gvl: :release runs on the main Thread, where a trap handler " \
249
+ "that raises or exits, or another Ractor's require, can stop the run where it cannot " \
250
+ "unwind; run it on another Thread, or keep trap handlers to setting a flag"
251
+ @warned = false
252
+
253
+ def self.warn_once
254
+ return if @warned
255
+
256
+ @warned = true
257
+ warn(MESSAGE)
258
+ end
203
259
  end
260
+ private_constant :MainThreadRelease
204
261
  end
205
262
  end
@@ -4,123 +4,57 @@ require_relative "errors"
4
4
 
5
5
  module Kobako
6
6
  # The options a Sandbox was built with, read through Sandbox#options or
7
- # directly on the Sandbox, as in Sandbox#timeout. A cap left out takes its
8
- # default, and +nil+ switches it off.
7
+ # directly on the Sandbox, as in Sandbox#timeout. An option Sandbox.new
8
+ # leaves out takes the runtime's default, given below, and +nil+ switches a
9
+ # cap off.
9
10
  #
10
- # [+timeout+] Float seconds one invocation may run.
11
+ # [+timeout+] Float seconds one invocation may run; 60.
11
12
  # [+setup_timeout+] Float seconds the Guest Binary may take to be set up
12
- # the first time its path is loaded.
13
- # [+memory_limit+] Integer bytes one invocation may grow guest memory by.
13
+ # the first time its path is loaded; 10.
14
+ # [+memory_limit+] Integer bytes one invocation may grow guest memory by;
15
+ # 4 MiB.
14
16
  # [+stdout_limit+, +stderr_limit+]
15
- # Integer bytes kept from each output channel.
17
+ # Integer bytes kept from each output channel; 1 MiB.
16
18
  # [+open_file_limit+]
17
19
  # Integer descriptors one invocation may hold open, the
18
- # standard ones and each Mount's included.
19
- # [+profile+] The isolation the runtime must provide, one of PROFILES.
20
- # [+gvl+] How an invocation holds Ruby's GVL, one of GVL_MODES.
20
+ # standard ones and each outermost mount's included; 1024.
21
+ # [+open_connection_limit+]
22
+ # Integer connections one invocation holds open at once, each
23
+ # socket once it dials, HTTP request, and name lookup in
24
+ # flight one; 6.
25
+ # [+connection_limit+]
26
+ # Integer connections one invocation makes in all, each
27
+ # socket's dial and HTTP request one; 50.
28
+ # [+profile+] The isolation the runtime must provide at least:
29
+ # +:hermetic+, which denies the guest the clock and
30
+ # entropy, or the weaker +:permissive+, which leaves them
31
+ # live; +:hermetic+.
32
+ # [+gvl+] How an invocation holds Ruby's GVL: +:hold+ through
33
+ # the invocation, or +:release+ while the guest runs, so
34
+ # Sandboxes on different Threads run in parallel; +:hold+.
35
+ # [+network+] What the guest's network dials and looks names up
36
+ # through, beneath every rule its entries make: +nil+
37
+ # for the host's own, or a Kobako::Network::Mock a test
38
+ # writes; +nil+.
21
39
  #
22
- # Raises ArgumentError for a value outside these shapes, and SetupError
23
- # when the runtime provides less isolation than +profile+ asks for.
40
+ # Raises TypeError for a cap of another class, RangeError for one past
41
+ # what the host counts, and ArgumentError for another value outside these
42
+ # shapes. The runtime judges every cap, and +profile+, +gvl+, and
43
+ # +network+ as Sandbox.new builds it.
24
44
  class SandboxOptions < Data.define(:timeout, :setup_timeout, :memory_limit, :stdout_limit, :stderr_limit,
25
- :open_file_limit, :profile, :gvl)
26
- # The default +timeout+: 60 seconds.
27
- DEFAULT_TIMEOUT_SECONDS = 60.0
28
-
29
- # The default +setup_timeout+: 10 seconds.
30
- DEFAULT_SETUP_TIMEOUT_SECONDS = 10.0
31
-
32
- # The default +memory_limit+: 4 MiB of growth past the guest's starting
33
- # memory, sized for a guest whose every value takes 16 bytes.
34
- DEFAULT_MEMORY_LIMIT = 4 << 20
35
-
36
- # The default +stdout_limit+ and +stderr_limit+: 1 MiB each.
37
- DEFAULT_OUTPUT_LIMIT = 1 << 20
38
-
39
- # The default +open_file_limit+: 1024, the soft limit Linux gives a
40
- # process.
41
- DEFAULT_OPEN_FILE_LIMIT = 1024
42
-
43
- # The isolation profiles, weakest first. +:hermetic+ denies the guest the
44
- # clock and entropy; +:permissive+ leaves them live.
45
- PROFILES = %i[permissive hermetic].freeze
46
-
47
- # The default +profile+, the strictest.
48
- DEFAULT_PROFILE = :hermetic
49
-
50
- # +:hold+ keeps the GVL through the invocation; +:release+ drops it while
51
- # the guest runs, so Sandboxes on different Threads run in parallel.
52
- GVL_MODES = %i[hold release].freeze
53
-
54
- # The default +gvl+, +:hold+.
55
- DEFAULT_GVL = :hold
56
-
57
- def initialize(timeout: DEFAULT_TIMEOUT_SECONDS,
58
- setup_timeout: DEFAULT_SETUP_TIMEOUT_SECONDS,
59
- memory_limit: DEFAULT_MEMORY_LIMIT,
60
- stdout_limit: DEFAULT_OUTPUT_LIMIT,
61
- stderr_limit: DEFAULT_OUTPUT_LIMIT,
62
- open_file_limit: DEFAULT_OPEN_FILE_LIMIT,
63
- profile: DEFAULT_PROFILE,
64
- gvl: DEFAULT_GVL)
65
- timeout = normalize_timeout(timeout, "timeout")
66
- setup_timeout = normalize_timeout(setup_timeout, "setup_timeout")
67
- memory_limit = normalize_limit(memory_limit, "memory_limit")
68
- stdout_limit = normalize_limit(stdout_limit, "stdout_limit")
69
- stderr_limit = normalize_limit(stderr_limit, "stderr_limit")
70
- open_file_limit = normalize_limit(open_file_limit, "open_file_limit")
71
- profile = normalize_choice(profile, PROFILES, "profile")
72
- gvl = normalize_choice(gvl, GVL_MODES, "gvl")
73
- super
45
+ :open_file_limit, :open_connection_limit, :connection_limit, :profile, :gvl,
46
+ :network)
47
+ # Every option is required; Sandbox.new fills each one left out from
48
+ # the runtime's defaults.
49
+ def initialize(timeout:, setup_timeout:, memory_limit:, stdout_limit:, stderr_limit:, open_file_limit:,
50
+ open_connection_limit:, connection_limit:, profile:, gvl:, network:)
51
+ caps = Kobako::Runtime.normalize_caps({ timeout:, setup_timeout:, memory_limit:, stdout_limit:, stderr_limit:,
52
+ open_file_limit:, open_connection_limit:, connection_limit: })
53
+ super(**caps.merge(profile:, gvl:, network:))
74
54
  end
75
55
 
76
- # The least guest memory one value occupies, so a guest payload may hold
77
- # one value for each of these bytes of +memory_limit+
78
- # (docs/wire/payload-msgpack.md § Value Budget).
79
- VALUE_BYTES = 16
80
- private_constant :VALUE_BYTES
81
-
82
56
  def value_budget # :nodoc:
83
- memory_limit&./(VALUE_BYTES)
84
- end
85
-
86
- # Both fallbacks fail closed: an unknown declaration ranks below every
87
- # request, and an unknown request refuses every declaration.
88
- def enforce_floor!(declared) # :nodoc:
89
- return if (PROFILES.index(declared) || -1) >= (PROFILES.index(profile) || PROFILES.size)
90
-
91
- raise Kobako::SetupError, "runtime declares isolation profile #{declared.inspect}, " \
92
- "below the requested floor #{profile.inspect}"
93
- end
94
-
95
- private
96
-
97
- # A zero or negative timeout would either fire instantly or never, both
98
- # more surprising than an early ArgumentError.
99
- def normalize_timeout(timeout, name)
100
- return nil if timeout.nil?
101
- raise ArgumentError, "#{name} must be Numeric or nil, got #{timeout.class}" unless timeout.is_a?(Numeric)
102
-
103
- seconds = timeout.to_f
104
- raise ArgumentError, "#{name} must be > 0 (got #{timeout})" unless seconds.positive? && seconds.finite?
105
-
106
- seconds
107
- end
108
-
109
- def normalize_limit(limit, name)
110
- return nil if limit.nil?
111
- unless limit.is_a?(Integer) && limit.positive?
112
- raise ArgumentError, "#{name} must be a positive Integer or nil, got #{limit.inspect}"
113
- end
114
-
115
- limit
116
- end
117
-
118
- # Unlike the caps there is no +nil+ form: every choice, the weakest
119
- # included, is requested by name, as in +:permissive+.
120
- def normalize_choice(value, choices, name)
121
- return value if choices.include?(value)
122
-
123
- raise ArgumentError, "#{name} must be one of #{choices.map(&:inspect).join(", ")}, got #{value.inspect}"
57
+ Kobako::Runtime.value_budget_of(memory_limit)
124
58
  end
125
59
  end
126
60
  end
@@ -4,7 +4,7 @@ module Kobako
4
4
  module Snippet
5
5
  class Bytecode < Data.define(:body) # :nodoc:
6
6
  # Names the snippet form the guest replays this entry as. The wire's
7
- # discriminant byte is assigned by the core envelope, not here.
7
+ # discriminant byte is assigned by the Envelope, not here.
8
8
  KIND = :bytecode
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module Kobako
4
4
  module Snippet
5
5
  class Source < Data.define(:name, :body) # :nodoc:
6
6
  # Names the snippet form the guest replays this entry as. The wire's
7
- # discriminant byte is assigned by the core envelope, not here.
7
+ # discriminant byte is assigned by the Envelope, not here.
8
8
  KIND = :source
9
9
  end
10
10
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../codec"
4
+ require_relative "exposure"
5
+
6
+ module Kobako
7
+ module Transport
8
+ # The walk a #run argument takes on its way to the guest: a leaf with no
9
+ # wire form becomes a Capability Handle in the invocation's table, and
10
+ # the rest crosses as it stands. An argument the walk refuses is the
11
+ # Host App's mistake, raised as +Marshal.dump+ raises it: +TypeError+
12
+ # for what has no form to cross as, +ArgumentError+ past the depth.
13
+ module ArgumentWrap # :nodoc:
14
+ # Only Hash values are wrapped: a non-representable key raises rather
15
+ # than crossing as a token the guest→host restore walk could not
16
+ # round-trip.
17
+ def self.wrap(value, handles, depth = 0)
18
+ refuse_past_nesting(depth)
19
+ case value
20
+ when ::Array then value.map { |element| wrap(element, handles, depth + 1) }
21
+ when ::Hash then wrap_hash(value, handles, depth)
22
+ else
23
+ Codec::HandleWalk.representable?(value) ? value : wrap_leaf(value, handles)
24
+ end
25
+ end
26
+
27
+ class << self
28
+ private
29
+
30
+ # A reference cycle necessarily trips the nesting bound, so an
31
+ # argument fails as a clean +ArgumentError+ rather than an unbounded
32
+ # host recursion.
33
+ def refuse_past_nesting(depth)
34
+ return unless depth > Codec::MAX_NESTING_DEPTH
35
+
36
+ raise ArgumentError,
37
+ "a #run argument nests deeper than #{Codec::MAX_NESTING_DEPTH} levels within the Run payload " \
38
+ "and cannot cross the sandbox boundary (possible reference cycle)"
39
+ end
40
+
41
+ def wrap_leaf(value, handles)
42
+ refused = Exposure.refused_class_of(value)
43
+ raise TypeError, "a #{refused} cannot cross as a Capability Handle" if refused
44
+
45
+ handles.alloc(value)
46
+ end
47
+
48
+ # A stateful object may cross the boundary as a Hash value but not as
49
+ # a key — the one deliberate asymmetry with the guest→host restore
50
+ # walk, which resolves Handle keys the guest built.
51
+ def wrap_hash(hash, handles, depth)
52
+ hash.to_h do |key, val|
53
+ unless Codec::HandleWalk.representable?(key, depth + 1)
54
+ raise TypeError,
55
+ "a Hash passed to #run has a key that cannot cross the sandbox boundary " \
56
+ "(#{key.class}); only wire-representable values may be Hash keys"
57
+ end
58
+ [key, wrap(val, handles, depth + 1)]
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -28,7 +28,7 @@ module Kobako
28
28
  raised = @raised
29
29
  return if raised.nil? || !error.equal?(raised)
30
30
 
31
- "#{raised.klass}: #{raised.message}"
31
+ "#{raised.class_name}: #{raised.message}"
32
32
  end
33
33
  end
34
34
  end
@@ -60,17 +60,18 @@ module Kobako
60
60
  # stays uncaught and traps the invocation rather than being masked as a
61
61
  # rescuable fault.
62
62
  rescue StandardError => e
63
- [:fault, *caught_fault(e, failure)] # : [Symbol, String, String?]
64
- ensure
65
- yielder&.invalidate
63
+ [:fault, *fault_of(e, failure)] # : [Symbol, String, String?]
66
64
  end
67
65
 
68
66
  class << self
69
67
  private
70
68
 
69
+ # Routing reads only the target and the method, so a dispatch that
70
+ # cannot route answers before its arguments are read.
71
71
  def run(call, resolver, handles, yielder)
72
- arguments, carried_handle = decode_arguments(call.payload)
73
72
  exposure = resolve_target(call.target, resolver, handles)
73
+ reject_unreachable(exposure, call.method_name.to_sym)
74
+ arguments, carried_handle = decode_arguments(call.payload)
74
75
  args, kwargs = resolve_call_args(arguments, handles, carried_handle)
75
76
  invoke(exposure, call.method_name, args, kwargs, yielder)
76
77
  end
@@ -97,7 +98,7 @@ module Kobako
97
98
  # The guest's own block failing is not the Service's to report at
98
99
  # all, so the Yielder that raised it is asked first — it recognises
99
100
  # its own by identity and words the failure the guest's way.
100
- def caught_fault(error, failure)
101
+ def fault_of(error, failure)
101
102
  block_failure = failure.fault_text(error)
102
103
  return fault("block", block_failure) if block_failure
103
104
 
@@ -111,20 +112,19 @@ module Kobako
111
112
  # unsplatted for methods that take no keywords.
112
113
  def invoke(exposure, method, args, kwargs, yielder)
113
114
  name = method.to_sym
114
- reject_unreachable!(exposure, name)
115
115
  target = exposure.object
116
116
  block = yielder&.to_proc
117
117
  if kwargs.empty?
118
- target.public_send(name, *args, &block)
118
+ Reflection::PUBLIC_SEND.bind(target).call(name, *args, &block)
119
119
  else
120
- target.public_send(name, *args, **kwargs, &block)
120
+ Reflection::PUBLIC_SEND.bind(target).call(name, *args, **kwargs, &block)
121
121
  end
122
122
  end
123
123
 
124
124
  # Both the ambient-surface floor and the reference's Exposure answer
125
125
  # through Reflection, so a rejected name discloses nothing about
126
126
  # which of the two refused.
127
- def reject_unreachable!(exposure, name)
127
+ def reject_unreachable(exposure, name)
128
128
  reason = Reflection.refusal(exposure, name)
129
129
  raise UndefinedTargetError, reason if reason
130
130
  end
@@ -163,7 +163,7 @@ module Kobako
163
163
  # Service can change — so it is named here, where the direction is
164
164
  # known, instead of falling to the boundary's codec floor.
165
165
  def encode_ok(value, handles)
166
- Kobako::Codec::Nesting.assert_within_bound!(value)
166
+ Kobako::Codec::Nesting.assert_within_bound(value)
167
167
  Kobako::Codec::Encoder.encode(value)
168
168
  rescue Kobako::Codec::UnsupportedTypeError
169
169
  encode_ok(handles.alloc(value), handles)