diff --git a/Cargo.toml b/Cargo.toml index ddd3923..edff375 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ members = [ ] [workspace.package] -version = "19.0.0" +version = "21.0.0" authors = ["The Blockless Project Developers"] edition = "2021" @@ -21,13 +21,13 @@ wasi-common = {path = "crates/wasi-common"} [workspace.dependencies] tempfile = "3.1.0" libc = "0.2.60" -wasmtime = "19.0.0" -wasmtime-wasi = "19.0.0" -wiggle-generate = "19.0.0" -wasmtime-wasi-threads = "19.0.0" -wasi-common = { path = "crates/wasi-common", version="19.0.0" } +wasmtime = "21.0.0" +wasmtime-wasi = "21.0.0" +wiggle-generate = "21.0.0" +wasmtime-wasi-threads = "21.0.0" +wasi-common = { path = "crates/wasi-common", version="21.0.0" } # witx dependency by wiggle -wiggle = "19.0.0" +wiggle = "21.0.0" witx = "0.9.1" anyhow = "1.0.22" diff --git a/blockless/src/context.rs b/blockless/src/context.rs index f394c7d..e4442aa 100644 --- a/blockless/src/context.rs +++ b/blockless/src/context.rs @@ -1,12 +1,13 @@ use std::sync::{Arc, Mutex}; +use wasmtime_wasi::preview1::WasiP1Ctx; use wasmtime_wasi_threads::WasiThreadsCtx; #[derive(Clone)] pub(crate) struct BlocklessContext { pub(crate) preview1_ctx: Option, - pub(crate) preview2_ctx: Option>>, + pub(crate) preview2_ctx: Option>>, pub(crate) wasi_threads: Option>>, } @@ -22,7 +23,7 @@ impl Default for BlocklessContext { } impl BlocklessContext { - pub(crate) fn preview2_ctx(&mut self) -> &mut wasmtime_wasi::WasiP1Ctx { + pub(crate) fn preview2_ctx(&mut self) -> &mut WasiP1Ctx { let ctx = self.preview2_ctx.as_mut().unwrap(); Arc::get_mut(ctx) .expect("wasmtime_wasi was not compatiable threads") diff --git a/bls-runtime/src/macros.rs b/bls-runtime/src/macros.rs index 06c22a9..1015619 100644 --- a/bls-runtime/src/macros.rs +++ b/bls-runtime/src/macros.rs @@ -1,4 +1,3 @@ -#[macro_export] macro_rules! plog { ($level: expr, $($args:tt)+) => {{ crate::plog::plog($level, std::format_args!($($args)+)) @@ -6,10 +5,9 @@ macro_rules! plog { } /// export the perror macro for log the error -#[macro_export] macro_rules! perror { ($($args:tt)+) => {{ - crate::plog!(log::Level::Error, $($args)+) + plog!(log::Level::Error, $($args)+) }}; () => {{ @@ -19,7 +17,7 @@ macro_rules! perror { } /// export the pinfo macro for log the info -#[macro_export] +#[allow(unused_macros)] macro_rules! pinfo { ($($args:tt)+) => {{ crate::plog!(log::Level::Info, $($args)+) diff --git a/bls-runtime/src/main.rs b/bls-runtime/src/main.rs index 9ada853..e6da38c 100644 --- a/bls-runtime/src/main.rs +++ b/bls-runtime/src/main.rs @@ -1,6 +1,7 @@ mod cli_clap; mod config; mod error; +#[macro_use] mod macros; mod plog; mod v86; diff --git a/crates/wasi-common/src/ctx.rs b/crates/wasi-common/src/ctx.rs index 9cf2232..29caad9 100644 --- a/crates/wasi-common/src/ctx.rs +++ b/crates/wasi-common/src/ctx.rs @@ -15,7 +15,7 @@ use std::sync::{Arc, Mutex}; /// the file descriptor table. This wrapper is only necessary due to the /// signature of `fd_fdstat_set_flags`; if that changes, there are a variety of /// improvements that can be made (TODO: -/// https://github.com/bytecodealliance/wasmtime/issues/5643). +/// . #[derive(Clone)] pub struct WasiCtx(Arc); diff --git a/crates/wasi-common/src/lib.rs b/crates/wasi-common/src/lib.rs index c790f48..dff9a6e 100644 --- a/crates/wasi-common/src/lib.rs +++ b/crates/wasi-common/src/lib.rs @@ -68,6 +68,7 @@ //! interface to plug in its own implementations of each of these resources. #![warn(clippy::cast_sign_loss)] +#![cfg_attr(docsrs, feature(doc_cfg))] pub mod clocks; mod ctx; @@ -79,15 +80,14 @@ pub mod random; pub mod sched; pub mod snapshots; mod string_array; +#[cfg_attr(docsrs, doc(cfg(feature = "sync")))] #[cfg(feature = "sync")] pub mod sync; pub mod table; +#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))] #[cfg(feature = "tokio")] pub mod tokio; -pub mod blockless; -pub use blockless::*; - pub use cap_rand::RngCore; pub use clocks::{SystemTimeSpec, WasiClocks, WasiMonotonicClock, WasiSystemClock}; pub use ctx::WasiCtx; @@ -98,6 +98,12 @@ pub use sched::{Poll, WasiSched}; pub use string_array::{StringArray, StringArrayError}; pub use table::Table; +mod blockless; +pub use blockless::{ + BlocklessConfig, BlocklessConfigVersion, BlocklessModule, DriverConfig, LoggerLevel, + ModuleType, Permission, Stderr, Stdout, +}; + // The only difference between these definitions for sync vs async is whether // the wasmtime::Funcs generated are async (& therefore need an async Store and an executor to run) // or whether they have an internal "dummy executor" that expects the implementation of all @@ -153,6 +159,7 @@ macro_rules! define_wasi { /// Note: this function is designed for usage where it is acceptable for /// Wasmtime failures to terminate the parent process, such as in the Wasmtime /// CLI; this would not be suitable for use in multi-tenant embeddings. +#[cfg_attr(docsrs, doc(cfg(feature = "exit")))] #[cfg(feature = "exit")] pub fn maybe_exit_on_error(e: anyhow::Error) -> anyhow::Error { use std::process; diff --git a/crates/wasi-common/src/snapshots/preview_1.rs b/crates/wasi-common/src/snapshots/preview_1.rs index 329e5ab..a583126 100644 --- a/crates/wasi-common/src/snapshots/preview_1.rs +++ b/crates/wasi-common/src/snapshots/preview_1.rs @@ -340,13 +340,17 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx { return Ok(0); } } else { - // Convert all of the unsafe guest slices to safe ones--this uses - // Wiggle's internal borrow checker to ensure no overlaps. We assume - // here that, because the memory is not shared, there are no other - // threads to access it while it is written to. + // Convert the first unsafe guest slice into a safe one--Wiggle + // can only track mutable borrows for an entire region, and converting + // all guest pointers to slices would cause a runtime borrow-checking + // error. As read is allowed to return less than the requested amount, + // it's valid (though not as efficient) for us to only perform the + // read of the first buffer. let mut guest_slices: Vec> = iovs .into_iter() + .filter(|iov| iov.len() > 0) .map(|iov| Ok(iov.as_slice_mut()?.unwrap())) + .take(1) .collect::>()?; // Read directly into the Wasm memory. @@ -417,13 +421,15 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx { return Ok(0); } } else { - // Convert all of the unsafe guest slices to safe ones--this uses - // Wiggle's internal borrow checker to ensure no overlaps. We assume - // here that, because the memory is not shared, there are no other - // threads to access it while it is written to. + // Convert unsafe guest slices to safe ones -- this uses Wiggle's + // internal borrow checker to ensure no overlaps. Note that borrow + // checking is coarse at this time so at most one non-empty slice is + // chosen. let mut guest_slices: Vec> = iovs .into_iter() + .filter(|iov| iov.len() > 0) .map(|iov| Ok(iov.as_slice_mut()?.unwrap())) + .take(1) .collect::>()?; // Read directly into the Wasm memory.