kobako 0.30.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 +335 -0
- data/Cargo.lock +469 -11
- data/README.md +43 -3
- data/ROADMAP.md +1 -1
- data/crates/kobako-runtime/CHANGELOG.md +219 -0
- data/crates/kobako-runtime/Cargo.toml +51 -3
- data/crates/kobako-runtime/README.md +7 -4
- data/crates/kobako-runtime/src/cred.rs +124 -0
- data/crates/kobako-runtime/src/dispatch.rs +4 -5
- data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
- data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
- data/crates/kobako-runtime/src/endpoint.rs +137 -36
- 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/lookup.rs +52 -14
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +19 -20
- data/crates/kobako-runtime/src/filesystem/bind.rs +437 -245
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +9 -16
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +121 -37
- data/crates/kobako-runtime/src/filesystem/overlay.rs +302 -343
- data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
- data/crates/kobako-runtime/src/filesystem/rdir.rs +15 -32
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +172 -160
- data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
- data/crates/kobako-runtime/src/filesystem.rs +6 -3
- 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 +4 -2
- data/crates/kobako-runtime/src/lib.rs +18 -7
- data/crates/kobako-runtime/src/limits.rs +195 -0
- data/crates/kobako-runtime/src/locking.rs +10 -0
- data/crates/kobako-runtime/src/memcg.rs +383 -0
- data/crates/kobako-runtime/src/mount.rs +67 -9
- 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 +29 -144
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +130 -29
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +101 -196
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
- data/crates/kobako-runtime/src/vfs/dentry.rs +143 -89
- data/crates/kobako-runtime/src/vfs/file.rs +199 -203
- data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
- data/crates/kobako-runtime/src/vfs/kern_path.rs +38 -42
- data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
- data/crates/kobako-runtime/src/vfs/namei.rs +829 -700
- 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 +3 -3
- data/crates/kobako-runtime/src/vfs/path.rs +6 -6
- data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
- data/crates/kobako-runtime/src/vfs/stat.rs +159 -23
- data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
- data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
- data/crates/kobako-runtime/src/vfs.rs +9 -6
- data/crates/kobako-runtime/src/wait.rs +356 -0
- data/crates/kobako-transport/CHANGELOG.md +31 -0
- data/crates/kobako-transport/Cargo.toml +1 -1
- data/crates/kobako-transport/README.md +3 -4
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
- data/crates/kobako-transport/src/envelope/call.rs +32 -4
- data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
- data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
- data/crates/kobako-transport/src/envelope/reply.rs +27 -27
- data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
- data/crates/kobako-transport/src/envelope.rs +13 -8
- data/crates/kobako-wasmtime/CHANGELOG.md +161 -0
- data/crates/kobako-wasmtime/Cargo.toml +26 -7
- data/crates/kobako-wasmtime/README.md +3 -2
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +17 -37
- data/crates/kobako-wasmtime/src/ambient.rs +33 -18
- data/crates/kobako-wasmtime/src/cache.rs +23 -15
- data/crates/kobako-wasmtime/src/config.rs +52 -68
- data/crates/kobako-wasmtime/src/driver.rs +48 -63
- data/crates/kobako-wasmtime/src/exports.rs +143 -17
- data/crates/kobako-wasmtime/src/guest.rs +12 -6
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +42 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
- data/crates/kobako-wasmtime/src/invocation.rs +74 -12
- data/crates/kobako-wasmtime/src/lib.rs +5 -3
- data/crates/kobako-wasmtime/src/limiter.rs +70 -5
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
- data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
- data/crates/kobako-wasmtime/src/preview1/fd.rs +327 -296
- data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +231 -217
- data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
- data/crates/kobako-wasmtime/src/preview1/poll.rs +244 -120
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1.rs +46 -42
- 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 +24 -9
- data/crates/kobako-wasmtime/src/wasi.rs +210 -81
- 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/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +1 -1
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
- data/ext/kobako/src/{runtime/escape.rs → escape.rs} +42 -11
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +30 -26
- data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +149 -168
- data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +24 -15
- 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 +30 -29
- data/ext/kobako/src/runtime/snapshot.rs +4 -4
- data/ext/kobako/src/runtime.rs +221 -143
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +14 -2
- data/lib/kobako/catalog/flags.rb +3 -5
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +5 -27
- data/lib/kobako/catalog/mount.rb +11 -3
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +5 -19
- data/lib/kobako/catalog/snippets.rb +3 -18
- data/lib/kobako/catalog.rb +3 -0
- data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
- data/lib/kobako/codec/decoder.rb +4 -4
- data/lib/kobako/codec/ext_types.rb +3 -3
- data/lib/kobako/codec/handle_walk.rb +3 -43
- data/lib/kobako/codec/value_budget.rb +132 -40
- data/lib/kobako/codec.rb +1 -1
- data/lib/kobako/context.rb +24 -11
- data/lib/kobako/errors.rb +15 -12
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +9 -2
- 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/pool.rb +45 -23
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +92 -35
- data/lib/kobako/sandbox_options.rb +41 -106
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +6 -6
- data/lib/kobako/transport/exposure.rb +26 -15
- data/lib/kobako/transport/reflection.rb +21 -4
- data/lib/kobako/transport/run.rb +8 -23
- data/lib/kobako/transport/yielder.rb +2 -9
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +6 -2
- data/release-please-config.json +15 -0
- data/sig/core/thread.rbs +6 -0
- data/sig/kobako/catalog/extensions.rbs +2 -0
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +0 -2
- data/sig/kobako/catalog/mount.rbs +3 -1
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +0 -4
- data/sig/kobako/catalog/snippets.rbs +0 -2
- data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/value_budget.rbs +47 -4
- data/sig/kobako/context.rbs +3 -1
- data/sig/kobako/errors.rbs +4 -4
- data/sig/kobako/filesystem.rbs +21 -3
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/pool.rbs +7 -3
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +19 -2
- data/sig/kobako/sandbox_options.rbs +29 -38
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +2 -4
- data/sig/kobako/transport/reflection.rbs +10 -0
- data/sig/kobako/transport/run.rbs +0 -2
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +1 -1
- data/sig/kobako.rbs +13 -0
- metadata +84 -35
- data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
- data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
- data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
- data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
- data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
- data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
- data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
- data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
- data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
- data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
- data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
- data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
- data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/gvl.rs +0 -147
- data/lib/kobako/constant_name.rb +0 -8
- data/sig/kobako/constant_name.rbs +0 -3
- /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
|
@@ -11,8 +11,8 @@ use std::any::Any;
|
|
|
11
11
|
use std::sync::Arc;
|
|
12
12
|
|
|
13
13
|
use super::{
|
|
14
|
-
DentryOperations, FileOperations, FileSystemType, Filesystem,
|
|
15
|
-
|
|
14
|
+
DentryOperations, Errno, FileOperations, FileSystemType, Filesystem, Iattr, InodeOperations,
|
|
15
|
+
Kstat, Lookup, Mask, OpenHow, RenameFlag,
|
|
16
16
|
};
|
|
17
17
|
use crate::vfs::{Dentry, Inode};
|
|
18
18
|
|
|
@@ -23,7 +23,7 @@ pub(crate) trait Hook: Send + Sync + 'static {
|
|
|
23
23
|
inner: &dyn InodeOperations,
|
|
24
24
|
dentry: &Dentry,
|
|
25
25
|
mask: Mask,
|
|
26
|
-
) -> Result<(),
|
|
26
|
+
) -> Result<(), Errno> {
|
|
27
27
|
inner.permission(dentry, mask)
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -32,23 +32,15 @@ pub(crate) trait Hook: Send + Sync + 'static {
|
|
|
32
32
|
ops: &dyn DentryOperations,
|
|
33
33
|
dir: &dyn InodeOperations,
|
|
34
34
|
dentry: &Dentry,
|
|
35
|
-
) -> Result<bool,
|
|
35
|
+
) -> Result<bool, Errno> {
|
|
36
36
|
ops.revalidate(dir, dentry)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
fn getattr(
|
|
40
|
-
&self,
|
|
41
|
-
inner: &dyn InodeOperations,
|
|
42
|
-
dentry: &Dentry,
|
|
43
|
-
) -> Result<Kstat, FilesystemError> {
|
|
39
|
+
fn getattr(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
44
40
|
inner.getattr(dentry)
|
|
45
41
|
}
|
|
46
42
|
|
|
47
|
-
fn lookup(
|
|
48
|
-
&self,
|
|
49
|
-
inner: &dyn InodeOperations,
|
|
50
|
-
dentry: &Dentry,
|
|
51
|
-
) -> Result<Lookup, FilesystemError> {
|
|
43
|
+
fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
52
44
|
inner.lookup(dentry)
|
|
53
45
|
}
|
|
54
46
|
|
|
@@ -57,31 +49,31 @@ pub(crate) trait Hook: Send + Sync + 'static {
|
|
|
57
49
|
inner: &dyn InodeOperations,
|
|
58
50
|
dentry: &Dentry,
|
|
59
51
|
how: &OpenHow,
|
|
60
|
-
) -> Result<Box<dyn FileOperations>,
|
|
52
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
61
53
|
inner.open(dentry, how)
|
|
62
54
|
}
|
|
63
55
|
|
|
64
|
-
fn mkdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(),
|
|
56
|
+
fn mkdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
|
|
65
57
|
inner.mkdir(dentry)
|
|
66
58
|
}
|
|
67
59
|
|
|
68
|
-
fn rmdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(),
|
|
60
|
+
fn rmdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
|
|
69
61
|
inner.rmdir(dentry)
|
|
70
62
|
}
|
|
71
63
|
|
|
72
|
-
fn unlink(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(),
|
|
64
|
+
fn unlink(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
|
|
73
65
|
inner.unlink(dentry)
|
|
74
66
|
}
|
|
75
67
|
|
|
76
68
|
fn rename(
|
|
77
69
|
&self,
|
|
78
70
|
inner: &dyn InodeOperations,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
) -> Result<(),
|
|
84
|
-
inner.rename(
|
|
71
|
+
old: &Dentry,
|
|
72
|
+
new_dir: &dyn InodeOperations,
|
|
73
|
+
new: &Dentry,
|
|
74
|
+
flags: Option<RenameFlag>,
|
|
75
|
+
) -> Result<(), Errno> {
|
|
76
|
+
inner.rename(old, new_dir, new, flags)
|
|
85
77
|
}
|
|
86
78
|
}
|
|
87
79
|
|
|
@@ -98,7 +90,7 @@ impl<H: Hook> Wrap<H> {
|
|
|
98
90
|
}
|
|
99
91
|
|
|
100
92
|
impl<H: Hook> FileSystemType for Wrap<H> {
|
|
101
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
93
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
102
94
|
self.fs.clone().fill_super(sb)?;
|
|
103
95
|
if let Some(ops) = sb.d_op().cloned() {
|
|
104
96
|
sb.set_default_d_op(Arc::new(WrapDentry {
|
|
@@ -151,11 +143,7 @@ struct WrapDentry<H> {
|
|
|
151
143
|
}
|
|
152
144
|
|
|
153
145
|
impl<H: Hook> DentryOperations for WrapDentry<H> {
|
|
154
|
-
fn revalidate(
|
|
155
|
-
&self,
|
|
156
|
-
dir: &dyn InodeOperations,
|
|
157
|
-
dentry: &Dentry,
|
|
158
|
-
) -> Result<bool, FilesystemError> {
|
|
146
|
+
fn revalidate(&self, dir: &dyn InodeOperations, dentry: &Dentry) -> Result<bool, Errno> {
|
|
159
147
|
let dir = (dir as &dyn Any)
|
|
160
148
|
.downcast_ref::<WrapInode<H>>()
|
|
161
149
|
.map_or(dir, |wrap| wrap.inner.as_ref());
|
|
@@ -164,61 +152,57 @@ impl<H: Hook> DentryOperations for WrapDentry<H> {
|
|
|
164
152
|
}
|
|
165
153
|
|
|
166
154
|
impl<H: Hook> InodeOperations for WrapInode<H> {
|
|
167
|
-
fn permission(&self, dentry: &Dentry, mask: Mask) -> Result<(),
|
|
155
|
+
fn permission(&self, dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
|
|
168
156
|
self.hook.permission(self.inner.as_ref(), dentry, mask)
|
|
169
157
|
}
|
|
170
158
|
|
|
171
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
159
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
172
160
|
self.hook.getattr(self.inner.as_ref(), dentry)
|
|
173
161
|
}
|
|
174
162
|
|
|
175
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
163
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
176
164
|
Ok(self.wrap(self.hook.lookup(self.inner.as_ref(), dentry)?))
|
|
177
165
|
}
|
|
178
166
|
|
|
179
|
-
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(),
|
|
167
|
+
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
|
|
180
168
|
self.inner.setattr(dentry, attr)
|
|
181
169
|
}
|
|
182
170
|
|
|
183
|
-
fn get_link(&self, dentry: &Dentry) -> Result<String,
|
|
171
|
+
fn get_link(&self, dentry: &Dentry) -> Result<String, Errno> {
|
|
184
172
|
self.inner.get_link(dentry)
|
|
185
173
|
}
|
|
186
174
|
|
|
187
|
-
fn open(
|
|
188
|
-
&self,
|
|
189
|
-
dentry: &Dentry,
|
|
190
|
-
how: &OpenHow,
|
|
191
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
175
|
+
fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
192
176
|
self.hook.open(self.inner.as_ref(), dentry, how)
|
|
193
177
|
}
|
|
194
178
|
|
|
195
|
-
fn create(&self, dentry: &Dentry) -> Result<(),
|
|
179
|
+
fn create(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
196
180
|
self.inner.create(dentry)
|
|
197
181
|
}
|
|
198
182
|
|
|
199
|
-
fn mkdir(&self, dentry: &Dentry) -> Result<(),
|
|
183
|
+
fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
200
184
|
self.hook.mkdir(self.inner.as_ref(), dentry)
|
|
201
185
|
}
|
|
202
186
|
|
|
203
|
-
fn rmdir(&self, dentry: &Dentry) -> Result<(),
|
|
187
|
+
fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
204
188
|
self.hook.rmdir(self.inner.as_ref(), dentry)
|
|
205
189
|
}
|
|
206
190
|
|
|
207
|
-
fn unlink(&self, dentry: &Dentry) -> Result<(),
|
|
191
|
+
fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
208
192
|
self.hook.unlink(self.inner.as_ref(), dentry)
|
|
209
193
|
}
|
|
210
194
|
|
|
211
195
|
fn rename(
|
|
212
196
|
&self,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
) -> Result<(),
|
|
218
|
-
let target = (
|
|
197
|
+
old: &Dentry,
|
|
198
|
+
new_dir: &dyn InodeOperations,
|
|
199
|
+
new: &Dentry,
|
|
200
|
+
flags: Option<RenameFlag>,
|
|
201
|
+
) -> Result<(), Errno> {
|
|
202
|
+
let target = (new_dir as &dyn Any)
|
|
219
203
|
.downcast_ref::<Self>()
|
|
220
|
-
.ok_or(
|
|
204
|
+
.ok_or(Errno::CrossesDevices)?;
|
|
221
205
|
self.hook
|
|
222
|
-
.rename(self.inner.as_ref(),
|
|
206
|
+
.rename(self.inner.as_ref(), old, target.inner.as_ref(), new, flags)
|
|
223
207
|
}
|
|
224
208
|
}
|
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
//! A third party implements the same tables to bring its own, so they are
|
|
5
5
|
//! named here too; the VFS, which calls them, owns them.
|
|
6
6
|
|
|
7
|
+
mod anon_inodes;
|
|
7
8
|
mod bind;
|
|
8
9
|
mod overlay;
|
|
9
|
-
mod path;
|
|
10
10
|
mod pipe;
|
|
11
11
|
mod rdir;
|
|
12
12
|
mod tmpfs;
|
|
13
13
|
#[cfg(test)]
|
|
14
14
|
pub(crate) mod wrap;
|
|
15
15
|
|
|
16
|
+
pub(crate) use anon_inodes::anon_inode_getfile;
|
|
16
17
|
pub use bind::Bind;
|
|
17
18
|
pub use overlay::Overlay;
|
|
18
19
|
pub use pipe::{create_pipe_files, PipeInodeInfo};
|
|
@@ -20,7 +21,9 @@ pub use rdir::Rdir;
|
|
|
20
21
|
pub use tmpfs::{SeedError, Tmpfs};
|
|
21
22
|
|
|
22
23
|
pub use crate::vfs::{
|
|
23
|
-
Dentry, DentryOperations, DirContext, DirEntry, FMode, FileOperations,
|
|
24
|
-
|
|
24
|
+
get_anon_bdev, Dentry, DentryOperations, DirContext, DirEntry, FMode, FileOperations,
|
|
25
|
+
FileSystemType, FileType, Finish, Iattr, Inode, InodeOperations, Kiocb, Kstat, Lookup, Mask,
|
|
25
26
|
OpenHow, PollMask, RenameFlag, SetTime, SuperBlock as Filesystem, Whence,
|
|
26
27
|
};
|
|
28
|
+
|
|
29
|
+
use crate::Errno;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
//! What a forked child keeps of its parent, as Linux's `kernel/fork.c` copies
|
|
2
|
+
//! the memory but only the thread that called `fork`. A value made for the
|
|
3
|
+
//! process — a count of what its own threads hold, or a thread it started — is
|
|
4
|
+
//! the parent's alone, so the child starts from none.
|
|
5
|
+
|
|
6
|
+
use std::sync::{Mutex, PoisonError};
|
|
7
|
+
|
|
8
|
+
/// The process a value was made in, as Linux's `struct pid` names a task: a
|
|
9
|
+
/// forked child inherits the value, but not having made it.
|
|
10
|
+
#[derive(Clone, Copy, PartialEq, Eq)]
|
|
11
|
+
pub(crate) struct Pid(u32);
|
|
12
|
+
|
|
13
|
+
impl Pid {
|
|
14
|
+
/// This process.
|
|
15
|
+
pub(crate) fn current() -> Self {
|
|
16
|
+
Self(std::process::id())
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// Whether this process is the one named.
|
|
20
|
+
pub(crate) fn is_current(self) -> bool {
|
|
21
|
+
self == Self::current()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// Another process than this one, as a forked child sees its parent.
|
|
25
|
+
#[cfg(test)]
|
|
26
|
+
pub(crate) fn parent() -> Self {
|
|
27
|
+
Self(std::process::id().wrapping_add(1))
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// A value of the process that made it, as `thread_local!` keeps one per
|
|
32
|
+
/// thread: a forked child, which inherits the memory but none of the parent's
|
|
33
|
+
/// other threads, sees none until it makes its own.
|
|
34
|
+
pub struct ProcessLocal<T> {
|
|
35
|
+
slot: Mutex<(Option<Pid>, Option<T>)>,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
impl<T> ProcessLocal<T> {
|
|
39
|
+
/// None made yet.
|
|
40
|
+
pub const fn new() -> Self {
|
|
41
|
+
Self {
|
|
42
|
+
slot: Mutex::new((None, None)),
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Run `f` on what this process holds, emptied first when another process
|
|
47
|
+
/// made it.
|
|
48
|
+
pub fn with<R>(&self, f: impl FnOnce(&mut Option<T>) -> R) -> R {
|
|
49
|
+
let mut slot = self.slot.lock().unwrap_or_else(PoisonError::into_inner);
|
|
50
|
+
if !slot.0.is_some_and(Pid::is_current) {
|
|
51
|
+
*slot = (Some(Pid::current()), None);
|
|
52
|
+
}
|
|
53
|
+
f(&mut slot.1)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// Stand in for a fork: what is held now was made by another process.
|
|
57
|
+
#[cfg(test)]
|
|
58
|
+
pub(crate) fn inherit(&self) {
|
|
59
|
+
let mut slot = self.slot.lock().unwrap_or_else(PoisonError::into_inner);
|
|
60
|
+
slot.0 = Some(Pid::parent());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
impl<T> Default for ProcessLocal<T> {
|
|
65
|
+
fn default() -> Self {
|
|
66
|
+
Self::new()
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#[cfg(test)]
|
|
71
|
+
mod tests {
|
|
72
|
+
use super::*;
|
|
73
|
+
|
|
74
|
+
#[test]
|
|
75
|
+
fn a_value_made_in_another_process_is_not_handed_out() {
|
|
76
|
+
let local = ProcessLocal::new();
|
|
77
|
+
local.with(|held| *held = Some(1));
|
|
78
|
+
local.inherit();
|
|
79
|
+
assert_eq!(
|
|
80
|
+
local.with(|held| *held),
|
|
81
|
+
None,
|
|
82
|
+
"a ProcessLocal must hand a forked child none of what its parent made"
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#[test]
|
|
87
|
+
fn a_value_made_in_this_process_is_kept() {
|
|
88
|
+
let local = ProcessLocal::new();
|
|
89
|
+
local.with(|held| *held = Some(1));
|
|
90
|
+
assert_eq!(
|
|
91
|
+
local.with(|held| *held),
|
|
92
|
+
Some(1),
|
|
93
|
+
"a ProcessLocal must keep what this process made"
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//! afresh; the guest reaches it through its system interface.
|
|
4
4
|
|
|
5
5
|
use crate::mount::Mount;
|
|
6
|
+
use crate::network::Network;
|
|
6
7
|
|
|
7
8
|
/// One resource handed over for an Invocation. Each kind carries what it
|
|
8
9
|
/// is and decides its own access.
|
|
@@ -10,6 +11,7 @@ use crate::mount::Mount;
|
|
|
10
11
|
#[non_exhaustive]
|
|
11
12
|
pub enum Grant {
|
|
12
13
|
Mount(Mount),
|
|
14
|
+
Network(Network),
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/// The kinds of Grant a runtime may support.
|
|
@@ -17,4 +19,5 @@ pub enum Grant {
|
|
|
17
19
|
#[non_exhaustive]
|
|
18
20
|
pub enum GrantKind {
|
|
19
21
|
Mount,
|
|
22
|
+
Network,
|
|
20
23
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
//! A table of objects held elsewhere, by key, as Linux's `
|
|
2
|
-
//!
|
|
1
|
+
//! A table of objects held elsewhere, by key, as Linux's `dentry_hashtable`
|
|
2
|
+
//! and `inode_hashtable` find the dentries and inodes in use. It holds each
|
|
3
|
+
//! weakly, so one nothing else holds drops out, where Linux's stays until the
|
|
4
|
+
//! shrinker prunes it.
|
|
3
5
|
|
|
4
6
|
use std::collections::HashMap;
|
|
5
7
|
use std::hash::Hash;
|
|
@@ -3,29 +3,38 @@
|
|
|
3
3
|
//! The surface where a wasm engine implementation and a host frontend
|
|
4
4
|
//! meet: the `Runtime` trait, the isolation `Profile` a runtime
|
|
5
5
|
//! declares, the Grants it presents to the guest and the Filesystem a
|
|
6
|
-
//! Mount places, the
|
|
7
|
-
//!
|
|
6
|
+
//! Mount places, the socket layer a network Grant opens and the HTTP
|
|
7
|
+
//! egress proxy above it, the neutral per-invocation value types, and the
|
|
8
|
+
//! dispatch / yield re-entry traits a frontend supplies. The messages these carry
|
|
8
9
|
//! are `kobako-transport`'s, which this crate takes as given.
|
|
9
10
|
//! Nothing here depends on an engine or a frontend type — each engine
|
|
10
11
|
//! hides its own machinery behind `Runtime`, and each frontend maps
|
|
11
|
-
//! these shapes onto its own host-language surface at its boundary
|
|
12
|
-
//!
|
|
13
|
-
//! so the engine stays swappable.
|
|
12
|
+
//! these shapes onto its own host-language surface at its boundary, so
|
|
13
|
+
//! the engine stays swappable.
|
|
14
14
|
|
|
15
|
+
pub mod cred;
|
|
15
16
|
pub mod dispatch;
|
|
16
17
|
pub mod endpoint;
|
|
18
|
+
mod errno;
|
|
17
19
|
pub mod error;
|
|
18
20
|
pub mod filesystem;
|
|
21
|
+
pub mod fork;
|
|
19
22
|
pub mod grant;
|
|
20
23
|
mod hashtable;
|
|
24
|
+
pub mod limits;
|
|
21
25
|
mod locking;
|
|
26
|
+
pub mod memcg;
|
|
22
27
|
pub mod mount;
|
|
28
|
+
pub mod net;
|
|
29
|
+
pub mod network;
|
|
30
|
+
pub mod policy;
|
|
23
31
|
pub mod profile;
|
|
24
32
|
pub mod runtime;
|
|
25
33
|
pub mod sched;
|
|
26
34
|
pub mod security;
|
|
27
35
|
pub mod snapshot;
|
|
28
36
|
pub mod vfs;
|
|
37
|
+
pub mod wait;
|
|
29
38
|
pub mod yielder;
|
|
30
39
|
|
|
31
40
|
// Every name an engine implementation writes into its own signatures, at
|
|
@@ -33,10 +42,12 @@ pub mod yielder;
|
|
|
33
42
|
// a reader of `kobako_runtime::Runtime` was missing.
|
|
34
43
|
pub use dispatch::DispatchHandler;
|
|
35
44
|
pub use endpoint::{Calls, GuestInstance};
|
|
45
|
+
pub use errno::Errno;
|
|
36
46
|
pub use error::{InvokeError, SetupError, Trap};
|
|
37
|
-
pub use filesystem::{Bind, DirEntry, FileType,
|
|
47
|
+
pub use filesystem::{Bind, DirEntry, FileType, Kstat, Overlay, SeedError, Tmpfs};
|
|
38
48
|
pub use grant::{Grant, GrantKind};
|
|
39
|
-
pub use mount::{Access, Mount, MountPathError,
|
|
49
|
+
pub use mount::{Access, Mount, MountPathError, MountRequest};
|
|
50
|
+
pub use policy::Policy;
|
|
40
51
|
pub use profile::Profile;
|
|
41
52
|
pub use runtime::{Entry, Runtime};
|
|
42
53
|
pub use sched::Blocking;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
//! The caps a Sandbox starts under when its Host App names none, as Linux's
|
|
2
|
+
//! `INIT_RLIMITS` sets what the first task starts with. Each cap is kept by
|
|
3
|
+
//! this crate, so every frontend and every Wasm Driver reads its default here.
|
|
4
|
+
|
|
5
|
+
use std::time::Duration;
|
|
6
|
+
|
|
7
|
+
/// The caps of one Sandbox. `None` on any field disables that cap.
|
|
8
|
+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
9
|
+
#[non_exhaustive]
|
|
10
|
+
pub struct Limits {
|
|
11
|
+
/// Wall-clock cap for one guest `#eval` / `#run`; the invocation traps
|
|
12
|
+
/// once it passes.
|
|
13
|
+
pub timeout: Option<Duration>,
|
|
14
|
+
/// Wall-clock cap for setting the Guest Binary up the first time its
|
|
15
|
+
/// path is loaded; past it, construction fails.
|
|
16
|
+
pub setup_timeout: Option<Duration>,
|
|
17
|
+
/// Guest linear-memory cap, in bytes, charged to what one invocation
|
|
18
|
+
/// grows beyond the image it starts from.
|
|
19
|
+
pub memory_limit: Option<usize>,
|
|
20
|
+
/// Byte cap for guest stdout capture; output past it is dropped and
|
|
21
|
+
/// the capture marked truncated.
|
|
22
|
+
pub stdout_limit: Option<usize>,
|
|
23
|
+
/// Byte cap for guest stderr capture, the same as `stdout_limit`.
|
|
24
|
+
pub stderr_limit: Option<usize>,
|
|
25
|
+
/// Descriptors one invocation may hold open, the standard ones and each
|
|
26
|
+
/// outermost Mount's preopen included; an open past it answers `MFILE`.
|
|
27
|
+
/// Only the guest's descriptors count, as `RLIMIT_NOFILE` counts a
|
|
28
|
+
/// process's: the host descriptors a Filesystem holds behind one are
|
|
29
|
+
/// its own, up to two for a file and one for each Layer holding a
|
|
30
|
+
/// directory, Directory Layers alone holding any.
|
|
31
|
+
pub open_file_limit: Option<usize>,
|
|
32
|
+
/// Connections one invocation holds open at once, each socket, HTTP request,
|
|
33
|
+
/// and name lookup in flight one; one past it answers `EAGAIN`.
|
|
34
|
+
pub open_connection_limit: Option<usize>,
|
|
35
|
+
/// Connections one invocation makes in all, each socket and HTTP request
|
|
36
|
+
/// one, as a budget of subrequests is counted; one past it answers
|
|
37
|
+
/// `EAGAIN`.
|
|
38
|
+
pub connection_limit: Option<usize>,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
impl Default for Limits {
|
|
42
|
+
/// A 60-second deadline, 10 seconds to set the Guest Binary up, 4 MiB of
|
|
43
|
+
/// memory growth, sized for a guest whose every value takes 16 bytes,
|
|
44
|
+
/// 1 MiB for each output channel, 1024 open files, the soft limit Linux
|
|
45
|
+
/// gives a process (`INR_OPEN_CUR`), and 6 open connections and 50 in
|
|
46
|
+
/// all, as a Cloudflare Worker may hold 6 waiting and make 50
|
|
47
|
+
/// subrequests on its free plan.
|
|
48
|
+
fn default() -> Self {
|
|
49
|
+
Limits {
|
|
50
|
+
timeout: Some(Duration::from_secs(60)),
|
|
51
|
+
setup_timeout: Some(Duration::from_secs(10)),
|
|
52
|
+
memory_limit: Some(4 << 20),
|
|
53
|
+
stdout_limit: Some(1 << 20),
|
|
54
|
+
stderr_limit: Some(1 << 20),
|
|
55
|
+
open_file_limit: Some(1024),
|
|
56
|
+
open_connection_limit: Some(6),
|
|
57
|
+
connection_limit: Some(50),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// The least guest memory one value occupies, so a guest payload may hold one
|
|
63
|
+
/// value for each of these bytes of the memory cap.
|
|
64
|
+
const VALUE_BYTES: usize = 16;
|
|
65
|
+
|
|
66
|
+
impl Limits {
|
|
67
|
+
/// The most values a guest payload may make the host build, one for each
|
|
68
|
+
/// `VALUE_BYTES` of `memory_limit`; none where memory is not capped.
|
|
69
|
+
pub fn value_budget(&self) -> Option<usize> {
|
|
70
|
+
self.memory_limit.map(|limit| limit / VALUE_BYTES)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// Each cap, named by the option a Host App sets it with, so every
|
|
74
|
+
/// frontend reads and writes the caps from this one list.
|
|
75
|
+
pub fn caps_mut(&mut self) -> [(&'static str, Cap<'_>); 8] {
|
|
76
|
+
[
|
|
77
|
+
("timeout", Cap::Deadline(&mut self.timeout)),
|
|
78
|
+
("setup_timeout", Cap::Deadline(&mut self.setup_timeout)),
|
|
79
|
+
("memory_limit", Cap::Count(&mut self.memory_limit)),
|
|
80
|
+
("stdout_limit", Cap::Count(&mut self.stdout_limit)),
|
|
81
|
+
("stderr_limit", Cap::Count(&mut self.stderr_limit)),
|
|
82
|
+
("open_file_limit", Cap::Count(&mut self.open_file_limit)),
|
|
83
|
+
(
|
|
84
|
+
"open_connection_limit",
|
|
85
|
+
Cap::Count(&mut self.open_connection_limit),
|
|
86
|
+
),
|
|
87
|
+
("connection_limit", Cap::Count(&mut self.connection_limit)),
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// Refuse a cap of zero, which would end every run at once rather than
|
|
92
|
+
/// bound it, as `setrlimit` takes no limit below what a task needs to
|
|
93
|
+
/// start; `None` is how a Host App asks for no cap.
|
|
94
|
+
pub fn check(&self) -> Result<(), ZeroCap> {
|
|
95
|
+
let mut limits = *self;
|
|
96
|
+
let zero = limits.caps_mut().into_iter().find_map(|(name, cap)| {
|
|
97
|
+
let is_zero = match cap {
|
|
98
|
+
Cap::Deadline(deadline) => *deadline == Some(Duration::ZERO),
|
|
99
|
+
Cap::Count(count) => *count == Some(0),
|
|
100
|
+
};
|
|
101
|
+
is_zero.then_some(name)
|
|
102
|
+
});
|
|
103
|
+
match zero {
|
|
104
|
+
Some(name) => Err(ZeroCap(name)),
|
|
105
|
+
None => Ok(()),
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// One cap of a `Limits`, by the kind of value it holds.
|
|
111
|
+
pub enum Cap<'a> {
|
|
112
|
+
/// A wall-clock deadline.
|
|
113
|
+
Deadline(&'a mut Option<Duration>),
|
|
114
|
+
/// A count of bytes, files, or connections.
|
|
115
|
+
Count(&'a mut Option<usize>),
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// A cap given as zero, named by its option.
|
|
119
|
+
#[derive(Debug, PartialEq, Eq)]
|
|
120
|
+
pub struct ZeroCap(&'static str);
|
|
121
|
+
|
|
122
|
+
impl std::fmt::Display for ZeroCap {
|
|
123
|
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
124
|
+
write!(f, "{} must be > 0, or none for no cap", self.0)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
impl std::error::Error for ZeroCap {}
|
|
129
|
+
|
|
130
|
+
#[cfg(test)]
|
|
131
|
+
mod tests {
|
|
132
|
+
use std::time::Duration;
|
|
133
|
+
|
|
134
|
+
use super::Limits;
|
|
135
|
+
|
|
136
|
+
#[test]
|
|
137
|
+
fn a_sandbox_starts_under_the_caps_every_frontend_promises() {
|
|
138
|
+
assert_eq!(
|
|
139
|
+
Limits::default(),
|
|
140
|
+
Limits {
|
|
141
|
+
timeout: Some(Duration::from_secs(60)),
|
|
142
|
+
setup_timeout: Some(Duration::from_secs(10)),
|
|
143
|
+
memory_limit: Some(4 * 1024 * 1024),
|
|
144
|
+
stdout_limit: Some(1024 * 1024),
|
|
145
|
+
stderr_limit: Some(1024 * 1024),
|
|
146
|
+
open_file_limit: Some(1024),
|
|
147
|
+
open_connection_limit: Some(6),
|
|
148
|
+
connection_limit: Some(50),
|
|
149
|
+
},
|
|
150
|
+
"a Sandbox given no caps must start under a 60 s deadline, 10 s of setup, 4 MiB of \
|
|
151
|
+
memory, 1 MiB per output channel, 1024 open files, and 6 open connections of 50"
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
#[test]
|
|
156
|
+
fn a_payload_holds_one_value_for_each_sixteen_bytes_of_memory() {
|
|
157
|
+
let uncapped = Limits {
|
|
158
|
+
memory_limit: None,
|
|
159
|
+
..Limits::default()
|
|
160
|
+
};
|
|
161
|
+
assert_eq!(
|
|
162
|
+
(Limits::default().value_budget(), uncapped.value_budget()),
|
|
163
|
+
(Some(4 * 1024 * 1024 / 16), None),
|
|
164
|
+
"Limits::value_budget must allow one value for each 16 bytes of memory_limit, and \
|
|
165
|
+
none to count where memory is not capped"
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// @behavior RT-058
|
|
170
|
+
#[test]
|
|
171
|
+
fn a_cap_of_zero_is_refused() {
|
|
172
|
+
let limits = Limits {
|
|
173
|
+
connection_limit: Some(0),
|
|
174
|
+
..Limits::default()
|
|
175
|
+
};
|
|
176
|
+
let deadline = Limits {
|
|
177
|
+
timeout: Some(Duration::ZERO),
|
|
178
|
+
..Limits::default()
|
|
179
|
+
};
|
|
180
|
+
assert_eq!(
|
|
181
|
+
(
|
|
182
|
+
limits.check().map_err(|e| e.to_string()),
|
|
183
|
+
deadline.check().map_err(|e| e.to_string()),
|
|
184
|
+
Limits::default().check().is_ok(),
|
|
185
|
+
),
|
|
186
|
+
(
|
|
187
|
+
Err("connection_limit must be > 0, or none for no cap".to_string()),
|
|
188
|
+
Err("timeout must be > 0, or none for no cap".to_string()),
|
|
189
|
+
true,
|
|
190
|
+
),
|
|
191
|
+
"a connection_limit or timeout of zero through Limits::check must be refused by name, \
|
|
192
|
+
and the default caps allowed"
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -9,6 +9,7 @@ use std::sync::{Arc, Condvar, Mutex, MutexGuard, PoisonError};
|
|
|
9
9
|
use std::thread::ThreadId;
|
|
10
10
|
|
|
11
11
|
use crate::sched;
|
|
12
|
+
use crate::Errno;
|
|
12
13
|
|
|
13
14
|
/// Why a hold was not taken.
|
|
14
15
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
@@ -22,6 +23,15 @@ pub(crate) enum DownError {
|
|
|
22
23
|
Interrupted,
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
impl From<DownError> for Errno {
|
|
27
|
+
fn from(error: DownError) -> Self {
|
|
28
|
+
match error {
|
|
29
|
+
DownError::Deadlock => Self::Deadlock,
|
|
30
|
+
DownError::Interrupted => Self::Interrupted,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
25
35
|
/// Held shared by any number of threads or exclusive by one. A thread
|
|
26
36
|
/// asking again for a hold it could only get once it let go of its own is
|
|
27
37
|
/// refused as a Deadlock; a thread already holding it shared may hold it
|