diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 80cfd9c119b3..110b0ce6b56d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -187,7 +187,7 @@ jobs: submodules: true - uses: ./.github/actions/install-rust with: - toolchain: nightly-2023-07-02 + toolchain: nightly-2023-10-10 # Build C API documentation - run: curl -L https://sourceforge.net/projects/doxygen/files/rel-1.9.3/doxygen-1.9.3.linux.bin.tar.gz/download | tar xzf - @@ -347,7 +347,7 @@ jobs: # flags to rustc. - uses: ./.github/actions/install-rust with: - toolchain: nightly-2023-07-02 + toolchain: nightly-2023-10-10 - run: cargo install cargo-fuzz --vers "^0.11" # Install the OCaml packages necessary for fuzz targets that use the # `wasm-spec-interpreter`. @@ -628,7 +628,7 @@ jobs: submodules: true - uses: ./.github/actions/install-rust with: - toolchain: nightly-2023-07-02 + toolchain: nightly-2023-10-10 - run: rustup component add rust-src miri - uses: actions/cache@v3 with: diff --git a/Cargo.toml b/Cargo.toml index 4b97cab4537f..d9653b4cdbbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -125,7 +125,7 @@ authors = ["The Wasmtime Project Developers"] edition = "2021" # Wasmtime's current policy is that this number can be no larger than the # current stable release of Rust minus 2. -rust-version = "1.70.0" +rust-version = "1.71.0" [workspace.dependencies] wasmtime-wmemcheck = { path = "crates/wmemcheck", version = "=15.0.0" } diff --git a/ci/build-test-matrix.js b/ci/build-test-matrix.js index 298203f5d4de..5fee846d6787 100644 --- a/ci/build-test-matrix.js +++ b/ci/build-test-matrix.js @@ -96,12 +96,6 @@ const array = [ "name": "Test Linux riscv64", "filter": "linux-riscv64", "isa": "riscv64", - // There appears to be a miscompile in Rust 1.72 for riscv64 where - // wasmtime-wasi tests are segfaulting in CI with the stack pointing in - // Tokio. Updating rustc seems to do the trick, so without doing a full - // rigorous investigation this uses beta for now but Rust 1.73 should be - // good to go for this. - "rust": "beta-2023-09-10", } ]; diff --git a/crates/runtime/src/instance/allocator/pooling/table_pool.rs b/crates/runtime/src/instance/allocator/pooling/table_pool.rs index 81938cb0491d..558cb548e966 100644 --- a/crates/runtime/src/instance/allocator/pooling/table_pool.rs +++ b/crates/runtime/src/instance/allocator/pooling/table_pool.rs @@ -3,9 +3,10 @@ use super::{ index_allocator::{SimpleIndexAllocator, SlotId}, round_up_to_pow2, TableAllocationIndex, }; -use crate::{InstanceAllocationRequest, Mmap, PoolingInstanceAllocatorConfig, Table}; +use crate::{InstanceAllocationRequest, Mmap, PoolingInstanceAllocatorConfig, SendSyncPtr, Table}; use anyhow::{anyhow, bail, Context, Result}; use std::mem; +use std::ptr::NonNull; use wasmtime_environ::{Module, TablePlan}; /// Represents a pool of WebAssembly tables. @@ -133,11 +134,14 @@ impl TablePool { self.table_elements * mem::size_of::<*mut u8>(), )?; - Table::new_static( - table_plan, - unsafe { std::slice::from_raw_parts_mut(base.cast(), self.table_elements) }, - unsafe { &mut *request.store.get().unwrap() }, - ) + let ptr = NonNull::new(std::ptr::slice_from_raw_parts_mut( + base.cast(), + self.table_elements, + )) + .unwrap(); + Table::new_static(table_plan, SendSyncPtr::new(ptr), unsafe { + &mut *request.store.get().unwrap() + }) })() { Ok(table) => Ok((allocation_index, table)), Err(e) => { diff --git a/crates/runtime/src/send_sync_ptr.rs b/crates/runtime/src/send_sync_ptr.rs index ce9d8b422ed5..5b6d05d4f4c0 100644 --- a/crates/runtime/src/send_sync_ptr.rs +++ b/crates/runtime/src/send_sync_ptr.rs @@ -39,6 +39,13 @@ impl SendSyncPtr { } } +impl SendSyncPtr<[T]> { + /// Returns the slice's length component of the pointer. + pub fn len(&self) -> usize { + self.0.len() + } +} + impl From for SendSyncPtr where U: Into>, diff --git a/crates/runtime/src/table.rs b/crates/runtime/src/table.rs index a978bc8924e5..2e5fcf3f4359 100644 --- a/crates/runtime/src/table.rs +++ b/crates/runtime/src/table.rs @@ -153,7 +153,7 @@ pub enum Table { Static { /// Where data for this table is stored. The length of this list is the /// maximum size of the table. - data: &'static mut [TableValue], + data: SendSyncPtr<[TableValue]>, /// The current size of the table. size: u32, /// The type of this table. @@ -200,7 +200,7 @@ impl Table { /// Create a new static (immovable) table instance for the specified table plan. pub fn new_static( plan: &TablePlan, - data: &'static mut [TableValue], + data: SendSyncPtr<[TableValue]>, store: &mut dyn Store, ) -> Result { Self::limit_new(plan, store)?; @@ -215,7 +215,10 @@ impl Table { ); } let data = match plan.table.maximum { - Some(max) if (max as usize) < data.len() => &mut data[..max as usize], + Some(max) if (max as usize) < data.len() => { + let ptr = data.as_non_null(); + SendSyncPtr::new(NonNull::slice_from_raw_parts(ptr.cast(), max as usize)) + } _ => data, }; @@ -383,9 +386,11 @@ impl Table { // First resize the storage and then fill with the init value match self { Table::Static { size, data, .. } => { - debug_assert!(data[*size as usize..new_size as usize] - .iter() - .all(|x| x.is_none())); + unsafe { + debug_assert!(data.as_ref()[*size as usize..new_size as usize] + .iter() + .all(|x| x.is_none())); + } *size = new_size; } Table::Dynamic { elements, .. } => { @@ -472,7 +477,7 @@ impl Table { pub fn vmtable(&mut self) -> VMTableDefinition { match self { Table::Static { data, size, .. } => VMTableDefinition { - base: data.as_mut_ptr().cast(), + base: data.as_ptr().cast(), current_elements: *size, }, Table::Dynamic { elements, .. } => VMTableDefinition { @@ -492,14 +497,14 @@ impl Table { fn elements(&self) -> &[TableValue] { match self { - Table::Static { data, size, .. } => &data[..*size as usize], + Table::Static { data, size, .. } => unsafe { &data.as_ref()[..*size as usize] }, Table::Dynamic { elements, .. } => &elements[..], } } fn elements_mut(&mut self) -> &mut [TableValue] { match self { - Table::Static { data, size, .. } => &mut data[..*size as usize], + Table::Static { data, size, .. } => unsafe { &mut data.as_mut()[..*size as usize] }, Table::Dynamic { elements, .. } => &mut elements[..], } } @@ -590,7 +595,7 @@ impl Drop for Table { impl Default for Table { fn default() -> Self { Table::Static { - data: &mut [], + data: SendSyncPtr::new(NonNull::from(&mut [])), size: 0, ty: TableElementType::Func, } diff --git a/crates/runtime/src/traphandlers/macos.rs b/crates/runtime/src/traphandlers/macos.rs index 493d4b5dbcaf..9cbe059bd9a2 100644 --- a/crates/runtime/src/traphandlers/macos.rs +++ b/crates/runtime/src/traphandlers/macos.rs @@ -167,6 +167,9 @@ static mut WASMTIME_PORT: mach_port_name_t = MACH_PORT_NULL; static mut CHILD_OF_FORKED_PROCESS: bool = false; pub unsafe fn platform_init() { + if cfg!(miri) { + return; + } // Mach ports do not currently work across forks, so configure Wasmtime to // panic in `lazy_per_thread_init` if the child attempts to invoke // WebAssembly. @@ -465,6 +468,9 @@ unsafe extern "C" fn unwind( /// exception handlers to get registered. #[cold] pub fn lazy_per_thread_init() { + if cfg!(miri) { + return; + } unsafe { assert!( !CHILD_OF_FORKED_PROCESS, diff --git a/crates/wasi-common/cap-std-sync/src/sched/windows.rs b/crates/wasi-common/cap-std-sync/src/sched/windows.rs index e3eeb930523e..d67d30d922d1 100644 --- a/crates/wasi-common/cap-std-sync/src/sched/windows.rs +++ b/crates/wasi-common/cap-std-sync/src/sched/windows.rs @@ -9,7 +9,6 @@ // taken the time to improve it. See bug #2880. use once_cell::sync::Lazy; -use std::ops::Deref; use std::sync::mpsc::{self, Receiver, RecvTimeoutError, Sender, TryRecvError}; use std::sync::Mutex; use std::thread; @@ -50,7 +49,7 @@ pub async fn poll_oneoff_<'a>( for s in poll.rw_subscriptions() { match s { Subscription::Read(r) => { - if file_is_stdin(r.file.deref()) { + if file_is_stdin(r.file) { stdin_read_subs.push(r); } else if r.file.pollable().is_some() { immediate_reads.push(r);