Skip to content

Commit

Permalink
feat(wasi): Add CapabilityThreading with max thread count
Browse files Browse the repository at this point in the history
Extends the wasi Capabilities type with a setting for threading that
configures the maximum thread count.
  • Loading branch information
theduke committed Mar 8, 2023
1 parent 6b8c4b2 commit 041c211
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/wasi/src/runners/wcgi/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl Handler {
.capabilities(Capabilities {
insecure_allow_all: true,
http_client: HttpClientCapabilityV1::new_allow_all(),
threading: Default::default(),
})
.runtime(Arc::new(rt))
.sandbox_fs(self.fs()?)
Expand Down
7 changes: 5 additions & 2 deletions lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use wasmer_vfs::{ArcFile, FsError, TmpFileSystem, VirtualFile};
use crate::{
bin_factory::{BinFactory, ModuleCache},
fs::{WasiFs, WasiFsRoot, WasiInodes},
os::task::control_plane::{ControlPlaneError, WasiControlPlane},
os::task::control_plane::{ControlPlaneConfig, ControlPlaneError, WasiControlPlane},
state::WasiState,
syscalls::types::{__WASI_STDERR_FILENO, __WASI_STDIN_FILENO, __WASI_STDOUT_FILENO},
Capabilities, PluggableRuntimeImplementation, WasiEnv, WasiFunctionEnv, WasiRuntime,
Expand Down Expand Up @@ -684,7 +684,10 @@ impl WasiEnvBuilder {

let capabilities = self.capabilites;

let control_plane = WasiControlPlane::default();
let plane_config = ControlPlaneConfig {
max_task_count: capabilities.threading.max_threads,
};
let control_plane = WasiControlPlane::new(plane_config);

let init = WasiEnvInit {
state,
Expand Down
12 changes: 12 additions & 0 deletions lib/wasi/src/state/capabilities.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use crate::http::HttpClientCapabilityV1;

/// Defines capabilities for a Wasi environment.
#[derive(Clone, Debug)]
pub struct Capabilities {
pub insecure_allow_all: bool,
pub http_client: HttpClientCapabilityV1,
pub threading: CapabilityThreadingV1,
}

impl Capabilities {
pub fn new() -> Self {
Self {
insecure_allow_all: false,
http_client: Default::default(),
threading: Default::default(),
}
}
}
Expand All @@ -20,3 +23,12 @@ impl Default for Capabilities {
Self::new()
}
}

/// Defines threading related permissions.
#[derive(Debug, Default, Clone)]
pub struct CapabilityThreadingV1 {
/// Maximum number of threads that can be spawned.
///
/// [`None`] means no limit.
pub max_threads: Option<usize>,
}

0 comments on commit 041c211

Please sign in to comment.