kobako 0.29.0-aarch64-linux → 0.31.0-aarch64-linux

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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +552 -10
  4. data/README.md +126 -564
  5. data/ROADMAP.md +3 -2
  6. data/crates/kobako-runtime/CHANGELOG.md +488 -1
  7. data/crates/kobako-runtime/README.md +11 -4
  8. data/crates/kobako-transport/CHANGELOG.md +39 -2
  9. data/crates/kobako-transport/README.md +8 -8
  10. data/crates/kobako-wasmtime/CHANGELOG.md +315 -8
  11. data/crates/kobako-wasmtime/README.md +11 -6
  12. data/crates/kobako-wasmtime/src/preview1/testsuite-expected.txt +6 -0
  13. data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
  14. data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
  15. data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
  16. data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
  17. data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
  18. data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
  19. data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
  20. data/crates/kobako-wasmtime/witx/typenames.witx +750 -0
  21. data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +441 -0
  22. data/data/kobako.wasm +0 -0
  23. data/lib/kobako/3.3/kobako.so +0 -0
  24. data/lib/kobako/3.4/kobako.so +0 -0
  25. data/lib/kobako/4.0/kobako.so +0 -0
  26. data/lib/kobako/catalog/extensions.rb +19 -7
  27. data/lib/kobako/catalog/flags.rb +4 -6
  28. data/lib/kobako/catalog/grants.rb +5 -4
  29. data/lib/kobako/catalog/handles.rb +9 -31
  30. data/lib/kobako/catalog/mount.rb +12 -12
  31. data/lib/kobako/catalog/network.rb +35 -0
  32. data/lib/kobako/catalog/replacements.rb +28 -0
  33. data/lib/kobako/catalog/services.rb +7 -21
  34. data/lib/kobako/catalog/snippets.rb +10 -25
  35. data/lib/kobako/catalog.rb +4 -1
  36. data/lib/kobako/codec/{utils.rb → boundary.rb} +5 -3
  37. data/lib/kobako/codec/decoder.rb +12 -12
  38. data/lib/kobako/codec/ext_types.rb +5 -7
  39. data/lib/kobako/codec/handle_walk.rb +5 -47
  40. data/lib/kobako/codec/nesting.rb +7 -7
  41. data/lib/kobako/codec/value_budget.rb +134 -42
  42. data/lib/kobako/codec.rb +1 -1
  43. data/lib/kobako/context.rb +28 -15
  44. data/lib/kobako/errors.rb +15 -12
  45. data/lib/kobako/extension.rb +3 -2
  46. data/lib/kobako/filesystem.rb +53 -15
  47. data/lib/kobako/handle.rb +2 -2
  48. data/lib/kobako/names.rb +28 -0
  49. data/lib/kobako/network.rb +210 -0
  50. data/lib/kobako/outcome.rb +7 -7
  51. data/lib/kobako/payload/arguments.rb +2 -2
  52. data/lib/kobako/pool.rb +47 -25
  53. data/lib/kobako/runtime.rb +3 -2
  54. data/lib/kobako/sandbox.rb +113 -56
  55. data/lib/kobako/sandbox_options.rb +41 -107
  56. data/lib/kobako/snippet/bytecode.rb +1 -1
  57. data/lib/kobako/snippet/source.rb +1 -1
  58. data/lib/kobako/transport/argument_wrap.rb +64 -0
  59. data/lib/kobako/transport/block_failure.rb +1 -1
  60. data/lib/kobako/transport/dispatcher.rb +10 -10
  61. data/lib/kobako/transport/exposure.rb +28 -17
  62. data/lib/kobako/transport/reflection.rb +28 -11
  63. data/lib/kobako/transport/run.rb +13 -28
  64. data/lib/kobako/transport/yielder.rb +3 -10
  65. data/lib/kobako/transport.rb +1 -0
  66. data/lib/kobako/version.rb +1 -1
  67. data/lib/kobako.rb +38 -0
  68. data/release-please-config.json +16 -0
  69. data/sig/core/thread.rbs +6 -0
  70. data/sig/kobako/catalog/extensions.rbs +5 -3
  71. data/sig/kobako/catalog/grants.rbs +7 -4
  72. data/sig/kobako/catalog/handles.rbs +2 -4
  73. data/sig/kobako/catalog/mount.rbs +3 -5
  74. data/sig/kobako/catalog/network.rbs +20 -0
  75. data/sig/kobako/catalog/replacements.rbs +14 -0
  76. data/sig/kobako/catalog/services.rbs +1 -5
  77. data/sig/kobako/catalog/snippets.rbs +3 -5
  78. data/sig/kobako/catalog.rbs +1 -1
  79. data/sig/kobako/codec/boundary.rbs +9 -0
  80. data/sig/kobako/codec/decoder.rbs +1 -1
  81. data/sig/kobako/codec/handle_walk.rbs +0 -6
  82. data/sig/kobako/codec/nesting.rbs +2 -2
  83. data/sig/kobako/codec/value_budget.rbs +48 -5
  84. data/sig/kobako/codec.rbs +1 -2
  85. data/sig/kobako/context.rbs +4 -2
  86. data/sig/kobako/errors.rbs +4 -4
  87. data/sig/kobako/filesystem.rbs +38 -15
  88. data/sig/kobako/guest_yielder.rbs +1 -1
  89. data/sig/kobako/network.rbs +115 -0
  90. data/sig/kobako/outcome.rbs +1 -1
  91. data/sig/kobako/payload/arguments.rbs +1 -1
  92. data/sig/kobako/pool.rbs +8 -4
  93. data/sig/kobako/runtime.rbs +32 -3
  94. data/sig/kobako/sandbox.rbs +22 -7
  95. data/sig/kobako/sandbox_options.rbs +29 -38
  96. data/sig/kobako/transport/argument_wrap.rbs +15 -0
  97. data/sig/kobako/transport/dispatcher.rbs +2 -2
  98. data/sig/kobako/transport/error.rbs +1 -1
  99. data/sig/kobako/transport/exposure.rbs +3 -5
  100. data/sig/kobako/transport/reflection.rbs +12 -2
  101. data/sig/kobako/transport/run.rbs +3 -5
  102. data/sig/kobako/transport/yielder.rbs +0 -3
  103. data/sig/kobako/transport.rbs +2 -2
  104. data/sig/kobako.rbs +13 -0
  105. metadata +26 -8
  106. data/lib/kobako/constant_name.rb +0 -8
  107. data/sig/kobako/codec/utils.rbs +0 -9
  108. data/sig/kobako/constant_name.rbs +0 -3
@@ -0,0 +1,441 @@
1
+ ;; WASI Preview. This is an evolution of the API that WASI initially
2
+ ;; launched with.
3
+ ;;
4
+ ;; Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi).
5
+ ;;
6
+ ;; This is a `witx` file. See [here](https://github.com/WebAssembly/WASI/blob/main/legacy/tools/witx-docs.md)
7
+ ;; for an explanation of what that means.
8
+
9
+ (use "typenames.witx")
10
+
11
+ (module $wasi_snapshot_preview1
12
+ ;;; Linear memory to be accessed by WASI functions that need it.
13
+ (import "memory" (memory))
14
+
15
+
16
+
17
+
18
+ ;;; Provide file advisory information on a file descriptor.
19
+ ;;; Note: This is similar to `posix_fadvise` in POSIX.
20
+ (@interface func (export "fd_advise")
21
+ (param $fd $fd)
22
+ ;;; The offset within the file to which the advisory applies.
23
+ (param $offset $filesize)
24
+ ;;; The length of the region to which the advisory applies.
25
+ (param $len $filesize)
26
+ ;;; The advice.
27
+ (param $advice $advice)
28
+ (result $error (expected (error $errno)))
29
+ )
30
+
31
+ ;;; Force the allocation of space in a file.
32
+ ;;; Note: This is similar to `posix_fallocate` in POSIX.
33
+ (@interface func (export "fd_allocate")
34
+ (param $fd $fd)
35
+ ;;; The offset at which to start the allocation.
36
+ (param $offset $filesize)
37
+ ;;; The length of the area that is allocated.
38
+ (param $len $filesize)
39
+ (result $error (expected (error $errno)))
40
+ )
41
+
42
+ ;;; Close a file descriptor.
43
+ ;;; Note: This is similar to `close` in POSIX.
44
+ (@interface func (export "fd_close")
45
+ (param $fd $fd)
46
+ (result $error (expected (error $errno)))
47
+ )
48
+
49
+ ;;; Synchronize the data of a file to disk.
50
+ ;;; Note: This is similar to `fdatasync` in POSIX.
51
+ (@interface func (export "fd_datasync")
52
+ (param $fd $fd)
53
+ (result $error (expected (error $errno)))
54
+ )
55
+
56
+ ;;; Get the attributes of a file descriptor.
57
+ ;;; Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
58
+ (@interface func (export "fd_fdstat_get")
59
+ (param $fd $fd)
60
+ ;;; The buffer where the file descriptor's attributes are stored.
61
+ (result $error (expected $fdstat (error $errno)))
62
+ )
63
+
64
+ ;;; Adjust the flags associated with a file descriptor.
65
+ ;;; Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
66
+ (@interface func (export "fd_fdstat_set_flags")
67
+ (param $fd $fd)
68
+ ;;; The desired values of the file descriptor flags.
69
+ (param $flags $fdflags)
70
+ (result $error (expected (error $errno)))
71
+ )
72
+
73
+ ;;; Adjust the rights associated with a file descriptor.
74
+ ;;; This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights
75
+ (@interface func (export "fd_fdstat_set_rights")
76
+ (param $fd $fd)
77
+ ;;; The desired rights of the file descriptor.
78
+ (param $fs_rights_base $rights)
79
+ (param $fs_rights_inheriting $rights)
80
+ (result $error (expected (error $errno)))
81
+ )
82
+
83
+ ;;; Return the attributes of an open file.
84
+ (@interface func (export "fd_filestat_get")
85
+ (param $fd $fd)
86
+ ;;; The buffer where the file's attributes are stored.
87
+ (result $error (expected $filestat (error $errno)))
88
+ )
89
+
90
+ ;;; Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
91
+ ;;; Note: This is similar to `ftruncate` in POSIX.
92
+ (@interface func (export "fd_filestat_set_size")
93
+ (param $fd $fd)
94
+ ;;; The desired file size.
95
+ (param $size $filesize)
96
+ (result $error (expected (error $errno)))
97
+ )
98
+
99
+ ;;; Adjust the timestamps of an open file or directory.
100
+ ;;; Note: This is similar to `futimens` in POSIX.
101
+ (@interface func (export "fd_filestat_set_times")
102
+ (param $fd $fd)
103
+ ;;; The desired values of the data access timestamp.
104
+ (param $atim $timestamp)
105
+ ;;; The desired values of the data modification timestamp.
106
+ (param $mtim $timestamp)
107
+ ;;; A bitmask indicating which timestamps to adjust.
108
+ (param $fst_flags $fstflags)
109
+ (result $error (expected (error $errno)))
110
+ )
111
+
112
+ ;;; Read from a file descriptor, without using and updating the file descriptor's offset.
113
+ ;;; Note: This is similar to `preadv` in POSIX.
114
+ (@interface func (export "fd_pread")
115
+ (param $fd $fd)
116
+ ;;; List of scatter/gather vectors in which to store data.
117
+ (param $iovs $iovec_array)
118
+ ;;; The offset within the file at which to read.
119
+ (param $offset $filesize)
120
+ ;;; The number of bytes read.
121
+ (result $error (expected $size (error $errno)))
122
+ )
123
+
124
+ ;;; Return a description of the given preopened file descriptor.
125
+ (@interface func (export "fd_prestat_get")
126
+ (param $fd $fd)
127
+ ;;; The buffer where the description is stored.
128
+ (result $error (expected $prestat (error $errno)))
129
+ )
130
+
131
+ ;;; Return a description of the given preopened file descriptor.
132
+ (@interface func (export "fd_prestat_dir_name")
133
+ (param $fd $fd)
134
+ ;;; A buffer into which to write the preopened directory name.
135
+ (param $path (@witx pointer u8))
136
+ (param $path_len $size)
137
+ (result $error (expected (error $errno)))
138
+ )
139
+
140
+ ;;; Write to a file descriptor, without using and updating the file descriptor's offset.
141
+ ;;; Note: This is similar to `pwritev` in POSIX.
142
+ (@interface func (export "fd_pwrite")
143
+ (param $fd $fd)
144
+ ;;; List of scatter/gather vectors from which to retrieve data.
145
+ (param $iovs $ciovec_array)
146
+ ;;; The offset within the file at which to write.
147
+ (param $offset $filesize)
148
+ ;;; The number of bytes written.
149
+ (result $error (expected $size (error $errno)))
150
+ )
151
+
152
+ ;;; Read from a file descriptor.
153
+ ;;; Note: This is similar to `readv` in POSIX.
154
+ (@interface func (export "fd_read")
155
+ (param $fd $fd)
156
+ ;;; List of scatter/gather vectors to which to store data.
157
+ (param $iovs $iovec_array)
158
+ ;;; The number of bytes read.
159
+ (result $error (expected $size (error $errno)))
160
+ )
161
+
162
+ ;;; Read directory entries from a directory.
163
+ ;;; When successful, the contents of the output buffer consist of a sequence of
164
+ ;;; directory entries. Each directory entry consists of a `dirent` object,
165
+ ;;; followed by `dirent::d_namlen` bytes holding the name of the directory
166
+ ;;; entry.
167
+ ;;
168
+ ;;; This function fills the output buffer as much as possible, potentially
169
+ ;;; truncating the last directory entry. This allows the caller to grow its
170
+ ;;; read buffer size in case it's too small to fit a single large directory
171
+ ;;; entry, or skip the oversized directory entry.
172
+ (@interface func (export "fd_readdir")
173
+ (param $fd $fd)
174
+ ;;; The buffer where directory entries are stored
175
+ (param $buf (@witx pointer u8))
176
+ (param $buf_len $size)
177
+ ;;; The location within the directory to start reading
178
+ (param $cookie $dircookie)
179
+ ;;; The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached.
180
+ (result $error (expected $size (error $errno)))
181
+ )
182
+
183
+ ;;; Atomically replace a file descriptor by renumbering another file descriptor.
184
+ ;;
185
+ ;;; Due to the strong focus on thread safety, this environment does not provide
186
+ ;;; a mechanism to duplicate or renumber a file descriptor to an arbitrary
187
+ ;;; number, like `dup2()`. This would be prone to race conditions, as an actual
188
+ ;;; file descriptor with the same number could be allocated by a different
189
+ ;;; thread at the same time.
190
+ ;;
191
+ ;;; This function provides a way to atomically renumber file descriptors, which
192
+ ;;; would disappear if `dup2()` were to be removed entirely.
193
+ (@interface func (export "fd_renumber")
194
+ (param $fd $fd)
195
+ ;;; The file descriptor to overwrite.
196
+ (param $to $fd)
197
+ (result $error (expected (error $errno)))
198
+ )
199
+
200
+ ;;; Move the offset of a file descriptor.
201
+ ;;; Note: This is similar to `lseek` in POSIX.
202
+ (@interface func (export "fd_seek")
203
+ (param $fd $fd)
204
+ ;;; The number of bytes to move.
205
+ (param $offset $filedelta)
206
+ ;;; The base from which the offset is relative.
207
+ (param $whence $whence)
208
+ ;;; The new offset of the file descriptor, relative to the start of the file.
209
+ (result $error (expected $filesize (error $errno)))
210
+ )
211
+
212
+ ;;; Synchronize the data and metadata of a file to disk.
213
+ ;;; Note: This is similar to `fsync` in POSIX.
214
+ (@interface func (export "fd_sync")
215
+ (param $fd $fd)
216
+ (result $error (expected (error $errno)))
217
+ )
218
+
219
+ ;;; Return the current offset of a file descriptor.
220
+ ;;; Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
221
+ (@interface func (export "fd_tell")
222
+ (param $fd $fd)
223
+ ;;; The current offset of the file descriptor, relative to the start of the file.
224
+ (result $error (expected $filesize (error $errno)))
225
+ )
226
+
227
+ ;;; Write to a file descriptor.
228
+ ;;; Note: This is similar to `writev` in POSIX.
229
+ (@interface func (export "fd_write")
230
+ (param $fd $fd)
231
+ ;;; List of scatter/gather vectors from which to retrieve data.
232
+ (param $iovs $ciovec_array)
233
+ (result $error (expected $size (error $errno)))
234
+ )
235
+
236
+ ;;; Create a directory.
237
+ ;;; Note: This is similar to `mkdirat` in POSIX.
238
+ (@interface func (export "path_create_directory")
239
+ (param $fd $fd)
240
+ ;;; The path at which to create the directory.
241
+ (param $path string)
242
+ (result $error (expected (error $errno)))
243
+ )
244
+
245
+ ;;; Return the attributes of a file or directory.
246
+ ;;; Note: This is similar to `stat` in POSIX.
247
+ (@interface func (export "path_filestat_get")
248
+ (param $fd $fd)
249
+ ;;; Flags determining the method of how the path is resolved.
250
+ (param $flags $lookupflags)
251
+ ;;; The path of the file or directory to inspect.
252
+ (param $path string)
253
+ ;;; The buffer where the file's attributes are stored.
254
+ (result $error (expected $filestat (error $errno)))
255
+ )
256
+
257
+ ;;; Adjust the timestamps of a file or directory.
258
+ ;;; Note: This is similar to `utimensat` in POSIX.
259
+ (@interface func (export "path_filestat_set_times")
260
+ (param $fd $fd)
261
+ ;;; Flags determining the method of how the path is resolved.
262
+ (param $flags $lookupflags)
263
+ ;;; The path of the file or directory to operate on.
264
+ (param $path string)
265
+ ;;; The desired values of the data access timestamp.
266
+ (param $atim $timestamp)
267
+ ;;; The desired values of the data modification timestamp.
268
+ (param $mtim $timestamp)
269
+ ;;; A bitmask indicating which timestamps to adjust.
270
+ (param $fst_flags $fstflags)
271
+ (result $error (expected (error $errno)))
272
+ )
273
+
274
+ ;;; Create a hard link.
275
+ ;;; Note: This is similar to `linkat` in POSIX.
276
+ (@interface func (export "path_link")
277
+ (param $old_fd $fd)
278
+ ;;; Flags determining the method of how the path is resolved.
279
+ (param $old_flags $lookupflags)
280
+ ;;; The source path from which to link.
281
+ (param $old_path string)
282
+ ;;; The working directory at which the resolution of the new path starts.
283
+ (param $new_fd $fd)
284
+ ;;; The destination path at which to create the hard link.
285
+ (param $new_path string)
286
+ (result $error (expected (error $errno)))
287
+ )
288
+
289
+ ;;; Open a file or directory.
290
+ ;;
291
+ ;;; The returned file descriptor is not guaranteed to be the lowest-numbered
292
+ ;;; file descriptor not currently open; it is randomized to prevent
293
+ ;;; applications from depending on making assumptions about indexes, since this
294
+ ;;; is error-prone in multi-threaded contexts. The returned file descriptor is
295
+ ;;; guaranteed to be less than 2**31.
296
+ ;;
297
+ ;;; Note: This is similar to `openat` in POSIX.
298
+ (@interface func (export "path_open")
299
+ (param $fd $fd)
300
+ ;;; Flags determining the method of how the path is resolved.
301
+ (param $dirflags $lookupflags)
302
+ ;;; The relative path of the file or directory to open, relative to the
303
+ ;;; `path_open::fd` directory.
304
+ (param $path string)
305
+ ;;; The method by which to open the file.
306
+ (param $oflags $oflags)
307
+ ;;; The initial rights of the newly created file descriptor. The
308
+ ;;; implementation is allowed to return a file descriptor with fewer rights
309
+ ;;; than specified, if and only if those rights do not apply to the type of
310
+ ;;; file being opened.
311
+ ;;
312
+ ;;; The *base* rights are rights that will apply to operations using the file
313
+ ;;; descriptor itself, while the *inheriting* rights are rights that apply to
314
+ ;;; file descriptors derived from it.
315
+ (param $fs_rights_base $rights)
316
+ (param $fs_rights_inheriting $rights)
317
+ (param $fdflags $fdflags)
318
+ ;;; The file descriptor of the file that has been opened.
319
+ (result $error (expected $fd (error $errno)))
320
+ )
321
+
322
+ ;;; Read the contents of a symbolic link.
323
+ ;;; Note: This is similar to `readlinkat` in POSIX.
324
+ (@interface func (export "path_readlink")
325
+ (param $fd $fd)
326
+ ;;; The path of the symbolic link from which to read.
327
+ (param $path string)
328
+ ;;; The buffer to which to write the contents of the symbolic link.
329
+ (param $buf (@witx pointer u8))
330
+ (param $buf_len $size)
331
+ ;;; The number of bytes placed in the buffer.
332
+ (result $error (expected $size (error $errno)))
333
+ )
334
+
335
+ ;;; Remove a directory.
336
+ ;;; Return `errno::notempty` if the directory is not empty.
337
+ ;;; Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
338
+ (@interface func (export "path_remove_directory")
339
+ (param $fd $fd)
340
+ ;;; The path to a directory to remove.
341
+ (param $path string)
342
+ (result $error (expected (error $errno)))
343
+ )
344
+
345
+ ;;; Rename a file or directory.
346
+ ;;; Note: This is similar to `renameat` in POSIX.
347
+ (@interface func (export "path_rename")
348
+ (param $fd $fd)
349
+ ;;; The source path of the file or directory to rename.
350
+ (param $old_path string)
351
+ ;;; The working directory at which the resolution of the new path starts.
352
+ (param $new_fd $fd)
353
+ ;;; The destination path to which to rename the file or directory.
354
+ (param $new_path string)
355
+ (result $error (expected (error $errno)))
356
+ )
357
+
358
+ ;;; Create a symbolic link.
359
+ ;;; Note: This is similar to `symlinkat` in POSIX.
360
+ (@interface func (export "path_symlink")
361
+ ;;; The contents of the symbolic link.
362
+ (param $old_path string)
363
+ (param $fd $fd)
364
+ ;;; The destination path at which to create the symbolic link.
365
+ (param $new_path string)
366
+ (result $error (expected (error $errno)))
367
+ )
368
+
369
+
370
+ ;;; Unlink a file.
371
+ ;;; Return `errno::isdir` if the path refers to a directory.
372
+ ;;; Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
373
+ (@interface func (export "path_unlink_file")
374
+ (param $fd $fd)
375
+ ;;; The path to a file to unlink.
376
+ (param $path string)
377
+ (result $error (expected (error $errno)))
378
+ )
379
+
380
+ ;;; Concurrently poll for the occurrence of a set of events.
381
+ (@interface func (export "poll_oneoff")
382
+ ;;; The events to which to subscribe.
383
+ (param $in (@witx const_pointer $subscription))
384
+ ;;; The events that have occurred.
385
+ (param $out (@witx pointer $event))
386
+ ;;; Both the number of subscriptions and events.
387
+ (param $nsubscriptions $size)
388
+ ;;; The number of events stored.
389
+ (result $error (expected $size (error $errno)))
390
+ )
391
+
392
+
393
+
394
+
395
+
396
+ ;;; Accept a new incoming connection.
397
+ ;;; Note: This is similar to `accept` in POSIX.
398
+ (@interface func (export "sock_accept")
399
+ ;;; The listening socket.
400
+ (param $fd $fd)
401
+ ;;; The desired values of the file descriptor flags.
402
+ (param $flags $fdflags)
403
+ ;;; New socket connection
404
+ (result $error (expected $fd (error $errno)))
405
+ )
406
+
407
+ ;;; Receive a message from a socket.
408
+ ;;; Note: This is similar to `recv` in POSIX, though it also supports reading
409
+ ;;; the data into multiple buffers in the manner of `readv`.
410
+ (@interface func (export "sock_recv")
411
+ (param $fd $fd)
412
+ ;;; List of scatter/gather vectors to which to store data.
413
+ (param $ri_data $iovec_array)
414
+ ;;; Message flags.
415
+ (param $ri_flags $riflags)
416
+ ;;; Number of bytes stored in ri_data and message flags.
417
+ (result $error (expected (tuple $size $roflags) (error $errno)))
418
+ )
419
+
420
+ ;;; Send a message on a socket.
421
+ ;;; Note: This is similar to `send` in POSIX, though it also supports writing
422
+ ;;; the data from multiple buffers in the manner of `writev`.
423
+ (@interface func (export "sock_send")
424
+ (param $fd $fd)
425
+ ;;; List of scatter/gather vectors to which to retrieve data
426
+ (param $si_data $ciovec_array)
427
+ ;;; Message flags.
428
+ (param $si_flags $siflags)
429
+ ;;; Number of bytes transmitted.
430
+ (result $error (expected $size (error $errno)))
431
+ )
432
+
433
+ ;;; Shut down socket send and receive channels.
434
+ ;;; Note: This is similar to `shutdown` in POSIX.
435
+ (@interface func (export "sock_shutdown")
436
+ (param $fd $fd)
437
+ ;;; Which channels on the socket to shut down.
438
+ (param $how $sdflags)
439
+ (result $error (expected (error $errno)))
440
+ )
441
+ )
data/data/kobako.wasm CHANGED
Binary file
Binary file
Binary file
Binary file
@@ -16,10 +16,10 @@ module Kobako
16
16
  # The Extension readers are duck-typed, so a malformed +name+ or
17
17
  # +backend.path+ surfaces through the registry it routes to.
18
18
  def install(extension, snippets:, services:)
19
- validate!(extension)
19
+ validate(extension)
20
20
  snippets.register(code: extension.source, name: extension.name)
21
21
  backend = extension.backend
22
- services.bind(backend.path, install_object(backend)) if backend
22
+ services.bind(backend.path, object_of(backend)) if backend
23
23
  @entries << extension
24
24
  self
25
25
  end
@@ -27,7 +27,7 @@ module Kobako
27
27
  # The asserted flag flips only on success, so a check that failed
28
28
  # re-runs on the next invocation rather than silently passing a broken
29
29
  # Sandbox.
30
- def assert_dependencies!
30
+ def assert_dependencies
31
31
  return self if @asserted
32
32
 
33
33
  extension, dependency = unmet_dependency
@@ -52,7 +52,7 @@ module Kobako
52
52
 
53
53
  private
54
54
 
55
- def install_object(backend) = backend.object.nil? ? Kobako::Unresolved : backend.object
55
+ def object_of(backend) = backend.object.nil? ? Kobako::Unresolved : backend.object
56
56
 
57
57
  def resolve_backend(extension, resolved, by_provider)
58
58
  backend = extension.backend
@@ -64,15 +64,27 @@ module Kobako
64
64
  resolved[backend.path.to_s] = by_provider.fetch(provider) { by_provider[provider] = provider.call }
65
65
  end
66
66
 
67
- def validate!(extension)
67
+ def validate(extension)
68
68
  source = extension.source
69
- raise ArgumentError, "Extension #source must be a String, got #{source.class}" unless source.is_a?(String)
69
+ raise TypeError, "Extension #source must be a String, got #{source.class}" unless source.is_a?(String)
70
70
 
71
+ validate_dependencies(extension.depends_on)
71
72
  backend = extension.backend
72
73
  return if backend.nil?
73
74
  return if backend.respond_to?(:path) && backend.respond_to?(:object) && backend.respond_to?(:provider)
74
75
 
75
- raise ArgumentError, "Extension #backend must expose #path, #object, and #provider"
76
+ raise TypeError, "Extension #backend must expose #path, #object, and #provider"
77
+ end
78
+
79
+ # Each dependency names an Extension as its +name+ does.
80
+ def validate_dependencies(dependencies)
81
+ return if dependencies.nil?
82
+ unless dependencies.is_a?(Array)
83
+ raise TypeError,
84
+ "Extension #depends_on must be an Array, got #{dependencies.class}"
85
+ end
86
+
87
+ dependencies.each { |dependency| Kobako.to_name(dependency, "Extension #depends_on entry") }
76
88
  end
77
89
 
78
90
  def unmet_dependency
@@ -13,15 +13,13 @@ module Kobako
13
13
  end
14
14
 
15
15
  def register(name, value, advisory:)
16
- unless name.is_a?(Symbol) || name.is_a?(String)
17
- raise ArgumentError, "flag name must be a Symbol or String, got #{name.class}"
18
- end
19
- raise ArgumentError, "flag value must be a String, got #{value.class}" unless value.is_a?(String)
16
+ name = Kobako.to_name(name, "flag name")
17
+ raise TypeError, "flag value must be a String, got #{value.class}" unless value.is_a?(String)
20
18
 
21
- key = Catalog.to_utf8!(name.to_s, "flag name")
19
+ key = Catalog.to_utf8(name, "flag name")
22
20
  raise ArgumentError, "flag #{key.inspect} already set" if @entries.key?(key)
23
21
 
24
- @entries[key] = [Catalog.to_utf8!(value, "flag value"), !advisory]
22
+ @entries[key] = [Catalog.to_utf8(value, "flag value"), !advisory]
25
23
  nil
26
24
  end
27
25
  end
@@ -4,7 +4,7 @@ module Kobako
4
4
  module Catalog
5
5
  class Grants # :nodoc:
6
6
  def initialize
7
- @entries = {} # : Hash[String, Mount]
7
+ @entries = {} # : Hash[key, Mount | Network]
8
8
  end
9
9
 
10
10
  # Each Grant decides what it cannot stand beside.
@@ -20,10 +20,11 @@ module Kobako
20
20
  @entries.key?(grant.key)
21
21
  end
22
22
 
23
- # Each Grant as the native side reads it, an override standing in for
24
- # the Grant it shares a key with.
23
+ # The Mounts, then the network entries, each as the native side reads
24
+ # it, an override standing in for the Grant it shares a key with.
25
25
  def entries(overrides = {})
26
- @entries.merge(overrides).values.map(&:to_native)
26
+ grants = @entries.merge(overrides).values
27
+ [grants.grep(Mount).map(&:to_native), grants.grep(Network).map(&:to_native)]
27
28
  end
28
29
  end
29
30
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "delegate"
4
-
5
3
  require_relative "../handle"
6
4
  require_relative "../transport/exposure"
7
5
 
@@ -21,10 +19,13 @@ module Kobako
21
19
 
22
20
  # The entry records the object's Exposure as it stands at mint, so a
23
21
  # call made through this Handle is authorized against the reference
24
- # the guest was given.
22
+ # the guest was given. The mint point asks the refusal itself, so it
23
+ # holds on every path a Handle is issued.
25
24
  def alloc(object)
26
- reject_unwrappable!(object)
27
- ensure_capacity!
25
+ refused = Kobako::Transport::Exposure.refused_class_of(object)
26
+ raise SandboxError, "a #{refused} cannot cross as a Capability Handle" if refused
27
+
28
+ ensure_capacity
28
29
  id = @next_id
29
30
  @entries[id] = Kobako::Transport::Exposure.of(object, @surfaces)
30
31
  @next_id = id + 1
@@ -36,7 +37,7 @@ module Kobako
36
37
  end
37
38
 
38
39
  def exposure(id)
39
- require_bound!(id)
40
+ require_bound(id)
40
41
  @entries[id]
41
42
  end
42
43
 
@@ -48,30 +49,7 @@ module Kobako
48
49
 
49
50
  private
50
51
 
51
- # Refuse to mint a Capability Handle for an object whose reachable
52
- # surface is not Service behaviour: a +Binding+ / +Method+ /
53
- # +UnboundMethod+ hands the guest a callable proxy onto host
54
- # reflection (a returned +Binding+ reaches +Binding#eval+); a +Class+
55
- # or +Module+ hands over its class-level API (+File.popen+ / +read+,
56
- # +Kernel.system+), which the owner-based dispatch floor cannot see
57
- # because a singleton-class owner matches no core-module list; a
58
- # +Delegator+ (+SimpleDelegator+, +DelegateClass+, +WeakRef+,
59
- # +Tempfile+) is a transparent forwarder whose public +method_missing+
60
- # binds and calls the private method the guest names (+Kernel#system+),
61
- # a surface the floor reads as ordinary Service behaviour. Raising here
62
- # keeps the rule at the single mint point, so it holds on both the
63
- # Service-return and the +#run+ host→guest auto-wrap paths.
64
- def reject_unwrappable!(object)
65
- case object
66
- when Binding, Method, UnboundMethod, Module, Delegator
67
- # Delegator < BasicObject exposes no static +#class+, so name the
68
- # rejected object's class through Object's own.
69
- kind = Object.instance_method(:class).bind_call(object)
70
- raise SandboxError, "a #{kind} cannot cross as a Capability Handle"
71
- end
72
- end
73
-
74
- def ensure_capacity!
52
+ def ensure_capacity
75
53
  cap = Kobako::Handle::MAX_ID
76
54
  return unless @next_id > cap
77
55
 
@@ -80,7 +58,7 @@ module Kobako
80
58
  "in a single invocation (limit #{cap})"
81
59
  end
82
60
 
83
- def require_bound!(id)
61
+ def require_bound(id)
84
62
  return if @entries.key?(id)
85
63
 
86
64
  raise SandboxError, "unknown Handle id: #{id.inspect}"
@@ -3,25 +3,25 @@
3
3
  module Kobako
4
4
  module Catalog
5
5
  class Mount < Data.define(:at, :access, :filesystem, :policy) # :nodoc:
6
- # The path a Context replaces this Mount at.
7
- def key = at
6
+ # The Mount at +at+, refused by the rules an invocation builds it with,
7
+ # so a mistake raises where it was written.
8
+ def initialize(at:, access:, filesystem:, policy:)
9
+ Kobako::Filesystem.validate_mount(at, access, filesystem)
10
+ super
11
+ end
12
+
13
+ # The kind and path a Context replaces this Mount at, so a Grant of
14
+ # another kind never meets it.
15
+ def key = [:mount, at]
8
16
 
9
17
  # Why +other+ cannot be mounted beside this Mount, or +nil+: a path
10
- # means one Mount, and never sits inside another.
18
+ # means one Mount, as Docker refuses a duplicate mount point.
11
19
  def conflict(other)
12
- return "path #{at.inspect} is already mounted" if other.at == at
13
-
14
- "path #{at.inspect} nests with the mounted path #{other.at.inspect}" if nested?(other.at)
20
+ "path #{at.inspect} is already mounted" if other.key == key
15
21
  end
16
22
 
17
23
  # The Mount as the native side reads it.
18
24
  def to_native = [at, access, filesystem, policy]
19
-
20
- private
21
-
22
- def nested?(other)
23
- [at, other].include?("/") || at.start_with?("#{other}/") || other.start_with?("#{at}/")
24
- end
25
25
  end
26
26
  end
27
27
  end