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.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +552 -10
- data/Cargo.lock +595 -139
- data/README.md +126 -564
- data/ROADMAP.md +3 -2
- data/crates/kobako-runtime/CHANGELOG.md +488 -1
- data/crates/kobako-runtime/Cargo.toml +73 -15
- data/crates/kobako-runtime/README.md +11 -4
- data/crates/kobako-runtime/src/cred.rs +124 -0
- data/crates/kobako-runtime/src/dispatch.rs +5 -6
- data/crates/kobako-runtime/src/endpoint/buffer.rs +301 -0
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +292 -0
- data/crates/kobako-runtime/src/endpoint/invoke.rs +181 -0
- data/crates/kobako-runtime/src/endpoint.rs +267 -0
- data/crates/kobako-runtime/src/errno.rs +391 -0
- data/crates/kobako-runtime/src/error.rs +31 -10
- data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
- data/crates/kobako-runtime/src/filesystem/bind/fid.rs +82 -0
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +274 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +248 -0
- data/crates/kobako-runtime/src/filesystem/bind.rs +2857 -0
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +89 -0
- data/crates/kobako-runtime/src/filesystem/overlay/inode.rs +106 -0
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +263 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +128 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +238 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +135 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +54 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +316 -739
- data/crates/kobako-runtime/src/filesystem/overlay.rs +2627 -1154
- data/crates/kobako-runtime/src/filesystem/pipe.rs +224 -0
- data/crates/kobako-runtime/src/filesystem/rdir.rs +84 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +107 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +22 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +1997 -0
- data/crates/kobako-runtime/src/filesystem/wrap.rs +208 -0
- data/crates/kobako-runtime/src/filesystem.rs +25 -388
- data/crates/kobako-runtime/src/fork.rs +96 -0
- data/crates/kobako-runtime/src/grant.rs +3 -0
- data/crates/kobako-runtime/src/hashtable.rs +46 -0
- data/crates/kobako-runtime/src/lib.rs +27 -11
- data/crates/kobako-runtime/src/limits.rs +195 -0
- data/crates/kobako-runtime/src/locking/seqlock.rs +66 -0
- data/crates/kobako-runtime/src/locking.rs +228 -0
- data/crates/kobako-runtime/src/memcg.rs +383 -0
- data/crates/kobako-runtime/src/mount.rs +86 -101
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +179 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +160 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +2733 -0
- data/crates/kobako-runtime/src/net/lookup.rs +285 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
- data/crates/kobako-runtime/src/net/reactor.rs +531 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
- data/crates/kobako-runtime/src/net/resolv.rs +227 -0
- data/crates/kobako-runtime/src/net/socket.rs +870 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
- data/crates/kobako-runtime/src/net/tls.rs +58 -0
- data/crates/kobako-runtime/src/net/transport.rs +279 -0
- data/crates/kobako-runtime/src/net/udp.rs +1003 -0
- data/crates/kobako-runtime/src/net.rs +42 -0
- data/crates/kobako-runtime/src/network/builder.rs +177 -0
- data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
- data/crates/kobako-runtime/src/network.rs +551 -0
- data/crates/kobako-runtime/src/policy.rs +16 -0
- data/crates/kobako-runtime/src/profile.rs +37 -16
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +311 -0
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/security/hooks.rs +242 -0
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +601 -0
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +162 -0
- data/crates/kobako-runtime/src/vfs/dentry.rs +1466 -0
- data/crates/kobako-runtime/src/vfs/file.rs +1911 -0
- data/crates/kobako-runtime/src/vfs/inode.rs +425 -0
- data/crates/kobako-runtime/src/vfs/kern_path.rs +213 -0
- data/crates/kobako-runtime/src/vfs/mount.rs +60 -0
- data/crates/kobako-runtime/src/vfs/namei.rs +5837 -0
- data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
- data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
- data/crates/kobako-runtime/src/vfs/openat2.rs +116 -0
- data/crates/kobako-runtime/src/vfs/path.rs +64 -0
- data/crates/kobako-runtime/src/vfs/readdir.rs +163 -0
- data/crates/kobako-runtime/src/vfs/stat.rs +293 -0
- data/crates/kobako-runtime/src/vfs/super_block.rs +126 -0
- data/crates/kobako-runtime/src/vfs/utimes.rs +299 -0
- data/crates/kobako-runtime/src/vfs.rs +63 -0
- data/crates/kobako-runtime/src/wait.rs +356 -0
- data/crates/kobako-transport/CHANGELOG.md +39 -2
- data/crates/kobako-transport/Cargo.toml +3 -3
- data/crates/kobako-transport/README.md +8 -8
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +49 -30
- data/crates/kobako-transport/src/envelope/call.rs +37 -9
- data/crates/kobako-transport/src/envelope/compile_reply.rs +2 -2
- data/crates/kobako-transport/src/envelope/error_record.rs +24 -3
- data/crates/kobako-transport/src/envelope/fault.rs +2 -2
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +11 -11
- data/crates/kobako-transport/src/envelope/preamble.rs +34 -31
- data/crates/kobako-transport/src/envelope/reply.rs +29 -29
- data/crates/kobako-transport/src/envelope/request.rs +2 -2
- data/crates/kobako-transport/src/envelope/run.rs +1 -1
- data/crates/kobako-transport/src/envelope/unsupported.rs +12 -12
- data/crates/kobako-transport/src/envelope.rs +15 -10
- data/crates/kobako-wasmtime/CHANGELOG.md +315 -8
- data/crates/kobako-wasmtime/Cargo.toml +35 -15
- data/crates/kobako-wasmtime/README.md +11 -6
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +19 -47
- data/crates/kobako-wasmtime/src/ambient.rs +33 -19
- data/crates/kobako-wasmtime/src/cache.rs +28 -20
- data/crates/kobako-wasmtime/src/config.rs +59 -60
- data/crates/kobako-wasmtime/src/driver.rs +63 -145
- data/crates/kobako-wasmtime/src/exports.rs +147 -32
- data/crates/kobako-wasmtime/src/guest.rs +44 -0
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +48 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +7 -7
- data/crates/kobako-wasmtime/src/invocation.rs +93 -51
- data/crates/kobako-wasmtime/src/lib.rs +6 -7
- data/crates/kobako-wasmtime/src/limiter.rs +52 -211
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +70 -57
- data/crates/kobako-wasmtime/src/preview1/differential.rs +137 -27
- data/crates/kobako-wasmtime/src/preview1/errno.rs +90 -233
- data/crates/kobako-wasmtime/src/preview1/fd.rs +1301 -522
- data/crates/kobako-wasmtime/src/preview1/memory.rs +126 -150
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +192 -0
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +1989 -708
- data/crates/kobako-wasmtime/src/preview1/path.rs +181 -365
- data/crates/kobako-wasmtime/src/preview1/poll.rs +345 -173
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -25
- data/crates/kobako-wasmtime/src/preview1/testsuite-expected.txt +6 -0
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +147 -0
- data/crates/kobako-wasmtime/src/preview1.rs +471 -416
- data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
- data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
- data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +31 -16
- data/crates/kobako-wasmtime/src/wasi.rs +238 -93
- data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
- data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
- data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
- data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
- data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
- data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
- data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
- data/crates/kobako-wasmtime/witx/typenames.witx +750 -0
- data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +441 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +1 -1
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +35 -27
- data/ext/kobako/src/escape.rs +98 -0
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +36 -16
- data/ext/kobako/src/filesystem/ruby.rs +689 -0
- data/ext/kobako/src/filesystem.rs +217 -0
- data/ext/kobako/src/gvl.rs +306 -0
- data/ext/kobako/src/lib.rs +64 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +591 -0
- data/ext/kobako/src/runtime/bridge.rs +31 -30
- data/ext/kobako/src/runtime/snapshot.rs +5 -5
- data/ext/kobako/src/runtime.rs +221 -138
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +19 -7
- data/lib/kobako/catalog/flags.rb +4 -6
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +9 -31
- data/lib/kobako/catalog/mount.rb +12 -12
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +7 -21
- data/lib/kobako/catalog/snippets.rb +10 -25
- data/lib/kobako/catalog.rb +4 -1
- data/lib/kobako/codec/{utils.rb → boundary.rb} +5 -3
- data/lib/kobako/codec/decoder.rb +12 -12
- data/lib/kobako/codec/ext_types.rb +5 -7
- data/lib/kobako/codec/handle_walk.rb +5 -47
- data/lib/kobako/codec/nesting.rb +7 -7
- data/lib/kobako/codec/value_budget.rb +134 -42
- data/lib/kobako/codec.rb +1 -1
- data/lib/kobako/context.rb +28 -15
- data/lib/kobako/errors.rb +15 -12
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +53 -15
- data/lib/kobako/handle.rb +2 -2
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/payload/arguments.rb +2 -2
- data/lib/kobako/pool.rb +47 -25
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +113 -56
- data/lib/kobako/sandbox_options.rb +41 -107
- data/lib/kobako/snippet/bytecode.rb +1 -1
- data/lib/kobako/snippet/source.rb +1 -1
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +10 -10
- data/lib/kobako/transport/exposure.rb +28 -17
- data/lib/kobako/transport/reflection.rb +28 -11
- data/lib/kobako/transport/run.rb +13 -28
- data/lib/kobako/transport/yielder.rb +3 -10
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +38 -0
- data/release-please-config.json +16 -0
- data/sig/core/thread.rbs +6 -0
- data/sig/kobako/catalog/extensions.rbs +5 -3
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +2 -4
- data/sig/kobako/catalog/mount.rbs +3 -5
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +1 -5
- data/sig/kobako/catalog/snippets.rbs +3 -5
- data/sig/kobako/catalog.rbs +1 -1
- data/sig/kobako/codec/boundary.rbs +9 -0
- data/sig/kobako/codec/decoder.rbs +1 -1
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/nesting.rbs +2 -2
- data/sig/kobako/codec/value_budget.rbs +48 -5
- data/sig/kobako/codec.rbs +1 -2
- data/sig/kobako/context.rbs +4 -2
- data/sig/kobako/errors.rbs +4 -4
- data/sig/kobako/filesystem.rbs +38 -15
- data/sig/kobako/guest_yielder.rbs +1 -1
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/payload/arguments.rbs +1 -1
- data/sig/kobako/pool.rbs +8 -4
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +22 -7
- data/sig/kobako/sandbox_options.rbs +29 -38
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/dispatcher.rbs +2 -2
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +3 -5
- data/sig/kobako/transport/reflection.rbs +12 -2
- data/sig/kobako/transport/run.rbs +3 -5
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +2 -2
- data/sig/kobako.rbs +13 -0
- metadata +131 -34
- data/crates/kobako-runtime/src/filesystem/directory/spelling.rs +0 -194
- data/crates/kobako-runtime/src/filesystem/directory.rs +0 -1082
- data/crates/kobako-runtime/src/filesystem/memory.rs +0 -1100
- data/crates/kobako-runtime/src/filesystem/overlay/exclusive.rs +0 -88
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -60
- data/crates/kobako-runtime/src/filesystem/temporary.rs +0 -167
- data/crates/kobako-wasmtime/src/capture.rs +0 -96
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -167
- data/crates/kobako-wasmtime/src/dispatch.rs +0 -125
- data/crates/kobako-wasmtime/src/guest_mem.rs +0 -271
- data/crates/kobako-wasmtime/src/io.rs +0 -89
- data/crates/kobako-wasmtime/src/preview1/args.rs +0 -60
- data/crates/kobako-wasmtime/src/preview1/beneath.rs +0 -188
- data/crates/kobako-wasmtime/tests/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/guest_file.rs +0 -1054
- data/crates/kobako-wasmtime/tests/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/escape.rs +0 -53
- data/ext/kobako/src/runtime/filesystem/ruby.rs +0 -400
- data/ext/kobako/src/runtime/filesystem.rs +0 -236
- data/ext/kobako/src/runtime/gvl.rs +0 -112
- data/lib/kobako/constant_name.rb +0 -8
- data/sig/kobako/codec/utils.rbs +0 -9
- data/sig/kobako/constant_name.rbs +0 -3
- /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
|
@@ -1,198 +1,186 @@
|
|
|
1
1
|
//! `poll_oneoff`, the guest's wait: for a clock, or for a descriptor to be
|
|
2
2
|
//! ready.
|
|
3
3
|
//!
|
|
4
|
-
//!
|
|
5
|
-
//!
|
|
6
|
-
//!
|
|
7
|
-
//!
|
|
8
|
-
//!
|
|
4
|
+
//! Each subscription becomes the pollable preview2 waits on, and preview2's
|
|
5
|
+
//! poll answers which are ready, as wasmtime-wasi's preview1 builds its
|
|
6
|
+
//! `poll_oneoff` on preview2's pollables. Every descriptor preview1 holds is
|
|
7
|
+
//! a file, ready at once. A clock is due as the profile has it: at once on
|
|
8
|
+
//! the hermetic profile's frozen clocks, and in host time on the permissive
|
|
9
|
+
//! profile, never past the invocation's deadline. What only preview1 has
|
|
10
|
+
//! stays here: which descriptor answers what, and EINTR for a wait the
|
|
11
|
+
//! frontend interrupts.
|
|
9
12
|
|
|
10
|
-
use std::thread;
|
|
11
13
|
use std::time::{Duration, Instant};
|
|
12
14
|
|
|
13
|
-
use
|
|
15
|
+
use kobako_runtime::vfs::PollMask;
|
|
16
|
+
use wiggle::GuestPtr;
|
|
17
|
+
|
|
18
|
+
use super::errno::{Answer, Errno};
|
|
19
|
+
use super::fd::get_file;
|
|
14
20
|
use super::memory::GuestMemory;
|
|
15
|
-
use
|
|
21
|
+
use super::types::{self, Clockid, Eventrwflags, Eventtype, Subclockflags, SubscriptionU};
|
|
16
22
|
use crate::invocation::Invocation;
|
|
17
|
-
use crate::
|
|
18
|
-
|
|
19
|
-
const SUBSCRIPTION_SIZE: u32 = 48;
|
|
20
|
-
const EVENT_SIZE: u32 = 32;
|
|
21
|
-
|
|
22
|
-
const TAG_CLOCK: u8 = 0;
|
|
23
|
-
const TAG_FD_READ: u8 = 1;
|
|
24
|
-
const TAG_FD_WRITE: u8 = 2;
|
|
25
|
-
|
|
26
|
-
const CLOCK_REALTIME: u32 = 0;
|
|
27
|
-
const CLOCK_MONOTONIC: u32 = 1;
|
|
28
|
-
/// The highest `clockid` variant.
|
|
29
|
-
const CLOCK_MAX: u32 = 3;
|
|
30
|
-
const SUBCLOCKFLAGS_ABSTIME: u16 = 1;
|
|
23
|
+
use crate::preview2::Pollable;
|
|
24
|
+
use crate::trap::Interrupted;
|
|
31
25
|
|
|
32
|
-
/// One subscription as the guest wrote it.
|
|
26
|
+
/// One subscription as the guest wrote it, and the error its event reports.
|
|
33
27
|
struct Subscription {
|
|
34
28
|
userdata: u64,
|
|
35
29
|
kind: Kind,
|
|
30
|
+
error: Errno,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
impl Subscription {
|
|
34
|
+
/// The pollable preview2 waits on for this subscription, a clock due
|
|
35
|
+
/// `started` plus what it has left.
|
|
36
|
+
fn to_pollable(&self, started: Instant) -> Pollable {
|
|
37
|
+
match self.kind {
|
|
38
|
+
Kind::Clock(left) => Pollable::Clock {
|
|
39
|
+
at: started + Duration::from_nanos(left),
|
|
40
|
+
},
|
|
41
|
+
Kind::FdRead | Kind::FdWrite => Pollable::Ready,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
enum Kind {
|
|
39
47
|
/// A clock, as the nanoseconds left before it fires.
|
|
40
48
|
Clock(u64),
|
|
41
|
-
|
|
42
|
-
/// its position.
|
|
43
|
-
FdRead {
|
|
44
|
-
hangup: bool,
|
|
45
|
-
},
|
|
49
|
+
FdRead,
|
|
46
50
|
FdWrite,
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
const EVENTRWFLAGS_HANGUP: u16 = 1;
|
|
50
|
-
|
|
51
53
|
pub(crate) fn poll_oneoff(
|
|
52
54
|
invocation: &Invocation,
|
|
53
|
-
mem: &mut GuestMemory,
|
|
54
|
-
subs:
|
|
55
|
-
events:
|
|
55
|
+
mem: &mut GuestMemory<'_, '_>,
|
|
56
|
+
subs: GuestPtr<types::Subscription>,
|
|
57
|
+
events: GuestPtr<types::Event>,
|
|
56
58
|
count: u32,
|
|
57
|
-
|
|
58
|
-
) -> Answer {
|
|
59
|
+
) -> Answer<types::Size> {
|
|
59
60
|
if count == 0 {
|
|
60
61
|
return Err(Errno::Inval.into());
|
|
61
62
|
}
|
|
62
|
-
mem.
|
|
63
|
-
mem.
|
|
64
|
-
let subscriptions =
|
|
65
|
-
.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
63
|
+
mem.consume_array::<types::Subscription>(count)?;
|
|
64
|
+
mem.consume_array::<types::Event>(count)?;
|
|
65
|
+
let subscriptions = subs
|
|
66
|
+
.as_array(count)
|
|
67
|
+
.iter()
|
|
68
|
+
.map(|sub| read_subscription(invocation, mem, sub?))
|
|
69
69
|
.collect::<Answer<Vec<_>>>()?;
|
|
70
70
|
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
0
|
|
71
|
+
let started = Instant::now();
|
|
72
|
+
let pollables = subscriptions
|
|
73
|
+
.iter()
|
|
74
|
+
.map(|sub| sub.to_pollable(started))
|
|
75
|
+
.collect();
|
|
76
|
+
let ready = match invocation.poll_ready(pollables) {
|
|
77
|
+
Ok(ready) => ready,
|
|
78
|
+
Err(err) if err.is::<Interrupted>() => return Err(Errno::Intr.into()),
|
|
79
|
+
Err(err) => return Err(types::Error::trap(err)),
|
|
81
80
|
};
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
let
|
|
86
|
-
Kind::Clock(
|
|
87
|
-
Kind::FdRead
|
|
82
|
+
for (written, index) in ready.iter().enumerate() {
|
|
83
|
+
let sub = &subscriptions[*index as usize];
|
|
84
|
+
let nbytes = match sub.kind {
|
|
85
|
+
Kind::Clock(_) => 0,
|
|
86
|
+
Kind::FdRead | Kind::FdWrite => u64::from(sub.error == Errno::Success),
|
|
88
87
|
};
|
|
89
|
-
|
|
90
|
-
let event = GuestMemory::element(events, written, EVENT_SIZE)?;
|
|
91
|
-
write_event(mem, event, sub, nbytes)?;
|
|
92
|
-
written += 1;
|
|
93
|
-
}
|
|
88
|
+
mem.write(events.add(written as u32)?, to_event(sub, nbytes))?;
|
|
94
89
|
}
|
|
95
|
-
|
|
90
|
+
Ok(ready.len() as u32)
|
|
96
91
|
}
|
|
97
92
|
|
|
98
|
-
fn read_subscription(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
},
|
|
115
|
-
_ => return Err(Errno::Inval.into()),
|
|
93
|
+
fn read_subscription(
|
|
94
|
+
invocation: &Invocation,
|
|
95
|
+
mem: &GuestMemory<'_, '_>,
|
|
96
|
+
sub: GuestPtr<types::Subscription>,
|
|
97
|
+
) -> Answer<Subscription> {
|
|
98
|
+
let sub = mem.read(sub)?;
|
|
99
|
+
let (kind, subscribed) = match sub.u {
|
|
100
|
+
SubscriptionU::Clock(clock) => {
|
|
101
|
+
return Ok(Subscription {
|
|
102
|
+
userdata: sub.userdata,
|
|
103
|
+
kind: read_clock(invocation, &clock)?,
|
|
104
|
+
error: Errno::Success,
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
SubscriptionU::FdRead(subscribed) => (Kind::FdRead, subscribed),
|
|
108
|
+
SubscriptionU::FdWrite(subscribed) => (Kind::FdWrite, subscribed),
|
|
116
109
|
};
|
|
117
|
-
|
|
110
|
+
let mask = match kind {
|
|
111
|
+
Kind::FdRead => PollMask::IN,
|
|
112
|
+
_ => PollMask::OUT,
|
|
113
|
+
};
|
|
114
|
+
Ok(Subscription {
|
|
115
|
+
userdata: sub.userdata,
|
|
116
|
+
kind,
|
|
117
|
+
error: poll_descriptor(invocation, subscribed, mask)?,
|
|
118
|
+
})
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
/// The error a subscription's event reports for what its descriptor would
|
|
122
|
+
/// find ready. A number no descriptor holds, or one standing only for its
|
|
123
|
+
/// path, is reported in its event, as Linux's `do_pollfd` marks it
|
|
124
|
+
/// `POLLNVAL` when `fdget` refuses it and the wait goes on. A pipe's end is
|
|
125
|
+
/// never ready for what the other end does, and nothing here would wake a
|
|
126
|
+
/// wait on it, so that is `BADF` rather than a wait that never ends.
|
|
127
|
+
fn poll_descriptor(
|
|
128
|
+
invocation: &Invocation,
|
|
129
|
+
subscribed: types::SubscriptionFdReadwrite,
|
|
130
|
+
event: PollMask,
|
|
131
|
+
) -> Answer<Errno> {
|
|
132
|
+
let Ok(file) = get_file(invocation.wasi(), subscribed.file_descriptor.into()) else {
|
|
133
|
+
return Ok(Errno::Badf);
|
|
134
|
+
};
|
|
135
|
+
match file.poll(None).contains(event) {
|
|
136
|
+
true => Ok(Errno::Success),
|
|
137
|
+
false => Err(Errno::Badf.into()),
|
|
138
|
+
}
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
/// A clock, read against the guest's own clocks. Only the realtime and
|
|
134
142
|
/// monotonic clocks can be waited on, alone or among other
|
|
135
143
|
/// subscriptions, as in wasmtime-wasi.
|
|
136
|
-
fn read_clock(invocation: &Invocation,
|
|
137
|
-
let
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if id > CLOCK_MAX || flags & !SUBCLOCKFLAGS_ABSTIME != 0 {
|
|
141
|
-
return Err(Errno::Inval.into());
|
|
142
|
-
}
|
|
143
|
-
let absolute = flags & SUBCLOCKFLAGS_ABSTIME != 0;
|
|
144
|
+
fn read_clock(invocation: &Invocation, clock: &types::SubscriptionClock) -> Answer<Kind> {
|
|
145
|
+
let absolute = clock
|
|
146
|
+
.flags
|
|
147
|
+
.contains(Subclockflags::SUBSCRIPTION_CLOCK_ABSTIME);
|
|
144
148
|
let clocks = invocation.wasi().clocks();
|
|
145
|
-
let now = match (id, absolute) {
|
|
146
|
-
(
|
|
147
|
-
(
|
|
148
|
-
(
|
|
149
|
+
let now = match (clock.id, absolute) {
|
|
150
|
+
(Clockid::Realtime | Clockid::Monotonic, false) => 0,
|
|
151
|
+
(Clockid::Monotonic, true) => clocks.monotonic_now(),
|
|
152
|
+
(Clockid::Realtime, true) => clocks.wall_now(),
|
|
149
153
|
_ => return Err(Errno::Inval.into()),
|
|
150
154
|
};
|
|
151
|
-
Ok(Kind::Clock(timeout.saturating_sub(now)))
|
|
155
|
+
Ok(Kind::Clock(clock.timeout.saturating_sub(now)))
|
|
152
156
|
}
|
|
153
157
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
158
|
+
fn to_event(sub: &Subscription, nbytes: u64) -> types::Event {
|
|
159
|
+
types::Event {
|
|
160
|
+
userdata: sub.userdata,
|
|
161
|
+
error: sub.error,
|
|
162
|
+
type_: match sub.kind {
|
|
163
|
+
Kind::Clock(_) => Eventtype::Clock,
|
|
164
|
+
Kind::FdRead => Eventtype::FdRead,
|
|
165
|
+
Kind::FdWrite => Eventtype::FdWrite,
|
|
166
|
+
},
|
|
167
|
+
fd_readwrite: types::EventFdReadwrite {
|
|
168
|
+
nbytes,
|
|
169
|
+
flags: Eventrwflags::empty(),
|
|
170
|
+
},
|
|
168
171
|
}
|
|
169
|
-
thread::sleep(wanted);
|
|
170
|
-
Ok(())
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
fn write_event(mem: &mut GuestMemory, event: u32, sub: &Subscription, nbytes: u64) -> Answer {
|
|
174
|
-
let (kind, flags) = match sub.kind {
|
|
175
|
-
Kind::Clock(_) => (TAG_CLOCK, 0),
|
|
176
|
-
Kind::FdRead { hangup } => (TAG_FD_READ, if hangup { EVENTRWFLAGS_HANGUP } else { 0 }),
|
|
177
|
-
Kind::FdWrite => (TAG_FD_WRITE, 0),
|
|
178
|
-
};
|
|
179
|
-
mem.write_u64(event, sub.userdata)?;
|
|
180
|
-
mem.write_u16(GuestMemory::field(event, 8)?, 0)?;
|
|
181
|
-
mem.write_u8(GuestMemory::field(event, 10)?, kind)?;
|
|
182
|
-
mem.write_u64(GuestMemory::field(event, 16)?, nbytes)?;
|
|
183
|
-
mem.write_u16(GuestMemory::field(event, 24)?, flags)
|
|
184
172
|
}
|
|
185
173
|
|
|
186
174
|
#[cfg(test)]
|
|
187
175
|
mod tests {
|
|
188
|
-
//! Witness that a guest's clock wait passes on its
|
|
176
|
+
//! Witness that a guest's clock wait passes on its profile's clocks:
|
|
189
177
|
//! at once on the frozen ones, and on the live ones no further than
|
|
190
178
|
//! the deadline.
|
|
191
179
|
use std::time::{Duration, Instant};
|
|
192
180
|
|
|
193
181
|
use wasmtime::{Module, Store};
|
|
194
182
|
|
|
195
|
-
use crate::cache::
|
|
183
|
+
use crate::cache::load_engine;
|
|
196
184
|
use crate::config::Config;
|
|
197
185
|
use crate::imports;
|
|
198
186
|
use crate::invocation::Invocation;
|
|
@@ -200,39 +188,71 @@ mod tests {
|
|
|
200
188
|
use crate::wasi::Wasi;
|
|
201
189
|
use kobako_runtime::error::Trap;
|
|
202
190
|
use kobako_runtime::profile::Profile;
|
|
191
|
+
use kobako_runtime::sched::{run_task, Task};
|
|
203
192
|
|
|
204
|
-
/// One
|
|
205
|
-
///
|
|
193
|
+
/// One clock subscription at 0, its event written at 64 and the event
|
|
194
|
+
/// count at 96: a relative monotonic one of ten seconds, or an absolute
|
|
195
|
+
/// realtime one a fifth of a second past the realtime clock it reads.
|
|
206
196
|
const WAIT_WAT: &str = r#"
|
|
207
197
|
(module
|
|
208
198
|
(import "wasi_snapshot_preview1" "poll_oneoff"
|
|
209
199
|
(func $poll (param i32 i32 i32 i32) (result i32)))
|
|
200
|
+
(import "wasi_snapshot_preview1" "clock_time_get"
|
|
201
|
+
(func $clock (param i32 i64 i32) (result i32)))
|
|
210
202
|
(memory (export "memory") 1)
|
|
211
203
|
(func (export "wait_ten_seconds") (result i32)
|
|
212
204
|
(i32.store8 (i32.const 8) (i32.const 0))
|
|
213
205
|
(i32.store (i32.const 16) (i32.const 1))
|
|
214
206
|
(i64.store (i32.const 24) (i64.const 10000000000))
|
|
215
|
-
(call $poll (i32.const 0) (i32.const 64) (i32.const 1) (i32.const 96)))
|
|
207
|
+
(call $poll (i32.const 0) (i32.const 64) (i32.const 1) (i32.const 96)))
|
|
208
|
+
(func (export "wait_the_largest_duration") (result i32)
|
|
209
|
+
(i32.store8 (i32.const 8) (i32.const 0))
|
|
210
|
+
(i32.store (i32.const 16) (i32.const 1))
|
|
211
|
+
(i64.store (i32.const 24) (i64.const -1))
|
|
212
|
+
(call $poll (i32.const 0) (i32.const 64) (i32.const 1) (i32.const 96)))
|
|
213
|
+
(func (export "wait_until_a_fifth_past_now") (result i32)
|
|
214
|
+
(drop (call $clock (i32.const 0) (i64.const 1) (i32.const 128)))
|
|
215
|
+
(i32.store8 (i32.const 8) (i32.const 0))
|
|
216
|
+
(i32.store (i32.const 16) (i32.const 0))
|
|
217
|
+
(i64.store (i32.const 24)
|
|
218
|
+
(i64.add (i64.load (i32.const 128)) (i64.const 200000000)))
|
|
219
|
+
(i32.store16 (i32.const 40) (i32.const 1))
|
|
220
|
+
(call $poll (i32.const 0) (i32.const 64) (i32.const 1) (i32.const 96)))
|
|
221
|
+
(func (export "poll_count") (param $count i32) (result i32)
|
|
222
|
+
(call $poll (i32.const 0) (i32.const 0) (local.get $count) (i32.const 96)))
|
|
223
|
+
(func (export "events_of_two_clocks") (result i32)
|
|
224
|
+
(i32.store8 (i32.const 8) (i32.const 0))
|
|
225
|
+
(i32.store (i32.const 16) (i32.const 1))
|
|
226
|
+
(i64.store (i32.const 24) (i64.const 1000000000))
|
|
227
|
+
(i32.store8 (i32.const 56) (i32.const 0))
|
|
228
|
+
(i32.store (i32.const 64) (i32.const 1))
|
|
229
|
+
(i64.store (i32.const 72) (i64.const 2000000000))
|
|
230
|
+
(drop (call $poll (i32.const 0) (i32.const 160) (i32.const 2) (i32.const 240)))
|
|
231
|
+
(i32.load (i32.const 240))))
|
|
216
232
|
"#;
|
|
217
233
|
|
|
218
|
-
/// Run the ten-second wait at `profile` under `deadline`,
|
|
219
|
-
///
|
|
234
|
+
/// Run the ten-second wait at `profile` under `deadline`, handing the
|
|
235
|
+
/// running thread's Task to `interrupted` first, answering how it ended
|
|
236
|
+
/// and how long the host spent on it.
|
|
220
237
|
fn wait_ten_seconds(
|
|
221
238
|
profile: Profile,
|
|
222
239
|
deadline: Option<Duration>,
|
|
240
|
+
interrupted: Option<fn(Task)>,
|
|
223
241
|
) -> (wasmtime::Result<i32>, Duration) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
let
|
|
235
|
-
let
|
|
242
|
+
call_wait("wait_ten_seconds", profile, deadline, interrupted)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/// Run the wait `export` as `wait_ten_seconds` runs its own.
|
|
246
|
+
fn call_wait(
|
|
247
|
+
export: &str,
|
|
248
|
+
profile: Profile,
|
|
249
|
+
deadline: Option<Duration>,
|
|
250
|
+
interrupted: Option<fn(Task)>,
|
|
251
|
+
) -> (wasmtime::Result<i32>, Duration) {
|
|
252
|
+
let engine = load_engine().expect("shared engine must be constructible");
|
|
253
|
+
let config = Config::for_profile(profile);
|
|
254
|
+
let wasi = Wasi::for_invocation(&config, &[]).expect("WASI context must build");
|
|
255
|
+
let mut store = Store::new(engine, Invocation::new(wasi));
|
|
236
256
|
store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
|
|
237
257
|
let linker = imports::linker().expect("host imports must link");
|
|
238
258
|
let module = Module::new(engine, WAIT_WAT).expect("wait module must compile");
|
|
@@ -240,20 +260,103 @@ mod tests {
|
|
|
240
260
|
.instantiate(&mut store, &module)
|
|
241
261
|
.expect("wait module must instantiate");
|
|
242
262
|
let wait = instance
|
|
243
|
-
.get_typed_func::<(), i32>(&mut store,
|
|
263
|
+
.get_typed_func::<(), i32>(&mut store, export)
|
|
244
264
|
.expect("wait export must resolve");
|
|
245
265
|
let started = Instant::now();
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
266
|
+
let deadline = deadline.map(|left| started + left);
|
|
267
|
+
store.data_mut().set_deadline(deadline);
|
|
268
|
+
let ended = run_task(deadline, || {
|
|
269
|
+
if let Some(interrupted) = interrupted {
|
|
270
|
+
interrupted(Task::current());
|
|
271
|
+
}
|
|
272
|
+
wait.call(&mut store, ())
|
|
273
|
+
});
|
|
250
274
|
(ended, started.elapsed())
|
|
251
275
|
}
|
|
252
276
|
|
|
277
|
+
// @behavior RT-337
|
|
278
|
+
#[test]
|
|
279
|
+
fn an_interrupted_wait_answers_eintr_at_once() {
|
|
280
|
+
let (ended, spent) = wait_ten_seconds(
|
|
281
|
+
Profile::Permissive,
|
|
282
|
+
Some(Duration::from_secs(20)),
|
|
283
|
+
Some(|task: Task| {
|
|
284
|
+
std::thread::spawn(move || {
|
|
285
|
+
std::thread::sleep(Duration::from_millis(50));
|
|
286
|
+
task.interrupt();
|
|
287
|
+
});
|
|
288
|
+
}),
|
|
289
|
+
);
|
|
290
|
+
assert!(
|
|
291
|
+
ended.as_ref().ok() == Some(&ERRNO_INTR) && spent < Duration::from_secs(5),
|
|
292
|
+
"a ten-second clock wait through a permissive guest's poll_oneoff, its thread \
|
|
293
|
+
interrupted, must answer EINTR at once, got {:?} after {spent:?}",
|
|
294
|
+
ended.map_err(|trap| trap.to_string())
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const ERRNO_INTR: i32 = 27;
|
|
299
|
+
|
|
300
|
+
/// Poll `count` subscriptions at 0 in a fresh instance whose one page
|
|
301
|
+
/// holds few of them, answering the errno or the trap.
|
|
302
|
+
fn poll_count(count: i32) -> wasmtime::Result<i32> {
|
|
303
|
+
let engine = load_engine().expect("shared engine must be constructible");
|
|
304
|
+
let config = Config::for_profile(Profile::Hermetic);
|
|
305
|
+
let wasi = Wasi::for_invocation(&config, &[]).expect("WASI context must build");
|
|
306
|
+
let mut store = Store::new(engine, Invocation::new(wasi));
|
|
307
|
+
store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
|
|
308
|
+
let linker = imports::linker().expect("host imports must link");
|
|
309
|
+
let module = Module::new(engine, WAIT_WAT).expect("wait module must compile");
|
|
310
|
+
let instance = linker
|
|
311
|
+
.instantiate(&mut store, &module)
|
|
312
|
+
.expect("wait module must instantiate");
|
|
313
|
+
instance
|
|
314
|
+
.get_typed_func::<i32, i32>(&mut store, "poll_count")
|
|
315
|
+
.expect("poll export must resolve")
|
|
316
|
+
.call(&mut store, count)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// The memory holds neither array, so a count the fuel admits fails only
|
|
320
|
+
// once the host reads past the page, and one past it before.
|
|
321
|
+
// @behavior RT-399
|
|
322
|
+
#[test]
|
|
323
|
+
fn a_poll_spends_its_fuel_as_the_host_holds_each_subscription() {
|
|
324
|
+
// 128 MiB of fuel over the 32-byte subscription and 32-byte event
|
|
325
|
+
// the host holds for each.
|
|
326
|
+
let admitted = 2_097_152;
|
|
327
|
+
let within = poll_count(admitted).ok();
|
|
328
|
+
let past = poll_count(admitted + 1).ok();
|
|
329
|
+
assert!(
|
|
330
|
+
within != Some(ERRNO_NOMEM) && past == Some(ERRNO_NOMEM),
|
|
331
|
+
"poll_oneoff must spend its hostcall fuel by the host's size of each subscription \
|
|
332
|
+
and event, as wasmtime-wasi does, answering NOMEM only past 2097152 of them, got \
|
|
333
|
+
{within:?} and {past:?}"
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const ERRNO_NOMEM: i32 = 48;
|
|
338
|
+
|
|
339
|
+
// @behavior RT-382
|
|
340
|
+
#[test]
|
|
341
|
+
fn a_wait_on_the_largest_duration_lasts_until_the_deadline() {
|
|
342
|
+
let (ended, spent) = call_wait(
|
|
343
|
+
"wait_the_largest_duration",
|
|
344
|
+
Profile::Permissive,
|
|
345
|
+
Some(Duration::from_millis(100)),
|
|
346
|
+
None,
|
|
347
|
+
);
|
|
348
|
+
assert!(
|
|
349
|
+
ended.is_err() && spent >= Duration::from_millis(100),
|
|
350
|
+
"a poll_oneoff on a clock of the largest duration through a permissive guest must \
|
|
351
|
+
wait until the deadline ends it; got {:?} after {spent:?}",
|
|
352
|
+
ended.map_err(|trap| trap.to_string())
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
253
356
|
// @behavior RT-073
|
|
254
357
|
#[test]
|
|
255
358
|
fn a_hermetic_wait_ends_without_the_host_waiting() {
|
|
256
|
-
let (ended, spent) = wait_ten_seconds(Profile::Hermetic, None);
|
|
359
|
+
let (ended, spent) = wait_ten_seconds(Profile::Hermetic, None, None);
|
|
257
360
|
assert_eq!(
|
|
258
361
|
ended.ok(),
|
|
259
362
|
Some(0),
|
|
@@ -277,18 +380,10 @@ mod tests {
|
|
|
277
380
|
(i32.store (i32.const 16) (local.get $id))
|
|
278
381
|
(call $poll (i32.const 0) (i32.const 64) (i32.const 1) (i32.const 96))))
|
|
279
382
|
"#;
|
|
280
|
-
let engine =
|
|
281
|
-
let config = Config
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
memory_limit: None,
|
|
285
|
-
stdout_limit: None,
|
|
286
|
-
stderr_limit: None,
|
|
287
|
-
open_file_limit: None,
|
|
288
|
-
profile: Profile::Hermetic,
|
|
289
|
-
};
|
|
290
|
-
let wasi = Wasi::for_invocation(&config, &[], &[]).expect("WASI context must build");
|
|
291
|
-
let mut store = Store::new(engine, Invocation::new(None, wasi));
|
|
383
|
+
let engine = load_engine().expect("shared engine must be constructible");
|
|
384
|
+
let config = Config::for_profile(Profile::Hermetic);
|
|
385
|
+
let wasi = Wasi::for_invocation(&config, &[]).expect("WASI context must build");
|
|
386
|
+
let mut store = Store::new(engine, Invocation::new(wasi));
|
|
292
387
|
store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
|
|
293
388
|
let linker = imports::linker().expect("host imports must link");
|
|
294
389
|
let module = Module::new(engine, WAIT_ON_WAT).expect("wait module must compile");
|
|
@@ -314,10 +409,87 @@ mod tests {
|
|
|
314
409
|
|
|
315
410
|
const ERRNO_INVAL: i32 = 28;
|
|
316
411
|
|
|
412
|
+
/// What a lone wait on standard output answers for event `tag`, 1 to read
|
|
413
|
+
/// and 2 to write.
|
|
414
|
+
fn wait_on_stdout(tag: i32) -> i32 {
|
|
415
|
+
const WAIT_ON_FD_WAT: &str = r#"
|
|
416
|
+
(module
|
|
417
|
+
(import "wasi_snapshot_preview1" "poll_oneoff"
|
|
418
|
+
(func $poll (param i32 i32 i32 i32) (result i32)))
|
|
419
|
+
(memory (export "memory") 1)
|
|
420
|
+
(func (export "wait_on") (param $tag i32) (result i32)
|
|
421
|
+
(i32.store8 (i32.const 8) (local.get $tag))
|
|
422
|
+
(i32.store (i32.const 16) (i32.const 1))
|
|
423
|
+
(call $poll (i32.const 0) (i32.const 64) (i32.const 1) (i32.const 96))))
|
|
424
|
+
"#;
|
|
425
|
+
let engine = load_engine().expect("shared engine must be constructible");
|
|
426
|
+
let config = Config::for_profile(Profile::Hermetic);
|
|
427
|
+
let wasi = Wasi::for_invocation(&config, &[]).expect("WASI context must build");
|
|
428
|
+
let mut store = Store::new(engine, Invocation::new(wasi));
|
|
429
|
+
store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
|
|
430
|
+
let linker = imports::linker().expect("host imports must link");
|
|
431
|
+
let module = Module::new(engine, WAIT_ON_FD_WAT).expect("wait module must compile");
|
|
432
|
+
linker
|
|
433
|
+
.instantiate(&mut store, &module)
|
|
434
|
+
.expect("wait module must instantiate")
|
|
435
|
+
.get_typed_func::<i32, i32>(&mut store, "wait_on")
|
|
436
|
+
.expect("wait export must resolve")
|
|
437
|
+
.call(&mut store, tag)
|
|
438
|
+
.expect("the wait must not trap")
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const ERRNO_BADF: i32 = 8;
|
|
442
|
+
|
|
443
|
+
// Nothing ever makes standard output ready to read, so without the refusal
|
|
444
|
+
// the wait would only end with the invocation.
|
|
445
|
+
// @behavior RT-285
|
|
446
|
+
#[test]
|
|
447
|
+
fn a_wait_on_what_a_descriptor_never_does_answers_ebadf() {
|
|
448
|
+
assert_eq!(
|
|
449
|
+
[1, 2].map(wait_on_stdout),
|
|
450
|
+
[ERRNO_BADF, 0],
|
|
451
|
+
"poll_oneoff on standard output must answer EBADF waiting to read and be ready to \
|
|
452
|
+
write"
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// @behavior RT-371
|
|
457
|
+
#[test]
|
|
458
|
+
fn a_hermetic_wait_on_two_clocks_fires_both_at_once() {
|
|
459
|
+
let (ended, spent) = call_wait(
|
|
460
|
+
"events_of_two_clocks",
|
|
461
|
+
Profile::Hermetic,
|
|
462
|
+
Some(Duration::from_secs(20)),
|
|
463
|
+
None,
|
|
464
|
+
);
|
|
465
|
+
assert!(
|
|
466
|
+
matches!(ended, Ok(2)) && spent < Duration::from_secs(1),
|
|
467
|
+
"a hermetic poll_oneoff on a one- and a two-second clock must report both events at \
|
|
468
|
+
once, not {ended:?} after {spent:?}"
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// @behavior RT-370
|
|
473
|
+
#[test]
|
|
474
|
+
fn a_wait_until_a_wall_time_reads_the_clock_the_guest_reads() {
|
|
475
|
+
let (ended, spent) = call_wait(
|
|
476
|
+
"wait_until_a_fifth_past_now",
|
|
477
|
+
Profile::Permissive,
|
|
478
|
+
Some(Duration::from_secs(5)),
|
|
479
|
+
None,
|
|
480
|
+
);
|
|
481
|
+
assert!(
|
|
482
|
+
matches!(ended, Ok(0)) && spent >= Duration::from_millis(150),
|
|
483
|
+
"an absolute realtime wait a fifth of a second past clock_time_get's realtime must \
|
|
484
|
+
end about then, not as {ended:?} after {spent:?}"
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
|
|
317
488
|
// @behavior RT-074
|
|
318
489
|
#[test]
|
|
319
490
|
fn a_permissive_wait_ends_at_the_deadline_as_a_timeout() {
|
|
320
|
-
let (ended, spent) =
|
|
491
|
+
let (ended, spent) =
|
|
492
|
+
wait_ten_seconds(Profile::Permissive, Some(Duration::from_millis(50)), None);
|
|
321
493
|
let trap = ended.expect_err("a wait past the deadline must not return to the guest");
|
|
322
494
|
assert!(
|
|
323
495
|
matches!(to_trap(trap), Trap::Timeout(_)),
|