Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update dependency #109

Merged
merged 6 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
]

[workspace.package]
version = "19.0.0"
version = "21.0.0"
authors = ["The Blockless Project Developers"]
edition = "2021"

Expand All @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions blockless/src/context.rs
Original file line number Diff line number Diff line change
@@ -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<wasi_common::WasiCtx>,

pub(crate) preview2_ctx: Option<Arc<Mutex<wasmtime_wasi::WasiP1Ctx>>>,
pub(crate) preview2_ctx: Option<Arc<Mutex<WasiP1Ctx>>>,

pub(crate) wasi_threads: Option<Arc<WasiThreadsCtx<BlocklessContext>>>,
}
Expand All @@ -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")
Expand Down
6 changes: 2 additions & 4 deletions bls-runtime/src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#[macro_export]
macro_rules! plog {
($level: expr, $($args:tt)+) => {{
crate::plog::plog($level, std::format_args!($($args)+))
}};
}

/// 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)+)
}};

() => {{
Expand All @@ -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)+)
Expand Down
1 change: 1 addition & 0 deletions bls-runtime/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod cli_clap;
mod config;
mod error;
#[macro_use]
mod macros;
mod plog;
mod v86;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-common/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
/// <https://github.com/bytecodealliance/wasmtime/issues/5643)>.
#[derive(Clone)]
pub struct WasiCtx(Arc<WasiCtxInner>);

Expand Down
13 changes: 10 additions & 3 deletions crates/wasi-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 14 additions & 8 deletions crates/wasi-common/src/snapshots/preview_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<wiggle::GuestSliceMut<u8>> = iovs
.into_iter()
.filter(|iov| iov.len() > 0)
.map(|iov| Ok(iov.as_slice_mut()?.unwrap()))
.take(1)
.collect::<Result<_, Error>>()?;

// Read directly into the Wasm memory.
Expand Down Expand Up @@ -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<wiggle::GuestSliceMut<u8>> = iovs
.into_iter()
.filter(|iov| iov.len() > 0)
.map(|iov| Ok(iov.as_slice_mut()?.unwrap()))
.take(1)
.collect::<Result<_, Error>>()?;

// Read directly into the Wasm memory.
Expand Down
Loading