From ea15647868f0c0779c106fc2219af1810cf12c16 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Sun, 28 Sep 2025 09:12:10 +0300 Subject: [PATCH] chore(lib/vm): update `corosensei` to `0.3.0` to support AddressSanitizer --- Cargo.lock | 4 ++-- lib/api/Cargo.toml | 3 +++ lib/vm/Cargo.toml | 3 ++- lib/vm/src/trap/traphandlers.rs | 30 ++++++++++++++++-------------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 41c2b3869b09..cd4dc73ec966 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -918,9 +918,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "corosensei" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d1ea1c2a2f898d2a6ff149587b8a04f41ee708d248c723f01ac2f0f01edc0b3" +checksum = "878ba85678ef5d34ffe1b5da981b0828232b4c7f2726b20984f59c7e79f6d514" dependencies = [ "autocfg", "cfg-if", diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index 9a192e1b120e..c4c25e5fbb7b 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -174,6 +174,9 @@ enable-serde = [ "wasmer-types/enable-serde", ] +# AddressSanitizer support +sanitizer = ["wasmer-vm/sanitizer"] + wasmer-artifact-load = ["wasmer-compiler/wasmer-artifact-load"] wasmer-artifact-create = ["wasmer-compiler/wasmer-artifact-create"] static-artifact-load = ["wasmer-compiler/static-artifact-load"] diff --git a/lib/vm/Cargo.toml b/lib/vm/Cargo.toml index 5452904dc84e..293f4536bdae 100644 --- a/lib/vm/Cargo.toml +++ b/lib/vm/Cargo.toml @@ -26,7 +26,7 @@ serde = { workspace = true, features = ["derive", "rc"], optional = true } enum-iterator.workspace = true scopeguard = "1.1.0" region.workspace = true -corosensei = { version = "0.2.2" } +corosensei = { version = "0.3.0" } fnv = "1.0.3" # - Optional shared dependencies. tracing = { workspace = true, optional = true } @@ -58,6 +58,7 @@ maintenance = { status = "actively-developed" } default = [] enable-serde = ["serde", "indexmap/serde", "wasmer-types/enable-serde"] artifact-size = ["dep:loupe", "wasmer-types/artifact-size"] +sanitizer = ["corosensei/sanitizer"] [package.metadata.docs.rs] rustc-args = ["--cfg", "docsrs"] diff --git a/lib/vm/src/trap/traphandlers.rs b/lib/vm/src/trap/traphandlers.rs index d177479be520..f3f7b9c99532 100644 --- a/lib/vm/src/trap/traphandlers.rs +++ b/lib/vm/src/trap/traphandlers.rs @@ -12,7 +12,7 @@ use backtrace::Backtrace; use core::ptr::{read, read_unaligned}; use corosensei::stack::DefaultStack; use corosensei::trap::{CoroutineTrapHandler, TrapHandlerRegs}; -use corosensei::{Coroutine, CoroutineResult, Yielder}; +use corosensei::{CoroutineResult, ScopedCoroutine, Yielder}; use scopeguard::defer; use std::any::Any; use std::cell::Cell; @@ -950,7 +950,7 @@ fn on_wasm_stack T + 'static, T: 'static>( let mut stack = scopeguard::guard(stack, |stack| STACK_POOL.push(stack)); // Create a coroutine with a new stack to run the function on. - let mut coro = Coroutine::with_stack(&mut *stack, move |yielder, ()| { + let coro = ScopedCoroutine::with_stack(&mut *stack, move |yielder, ()| { // Save the yielder to TLS so that it can be used later. YIELDER.with(|cell| cell.set(Some(yielder.into()))); @@ -962,20 +962,22 @@ fn on_wasm_stack T + 'static, T: 'static>( YIELDER.with(|cell| cell.set(None)); } - // Set up metadata for the trap handler for the duration of the coroutine - // execution. This is restored to its previous value afterwards. - TrapHandlerContext::install(trap_handler, coro.trap_handler(), || { - match coro.resume(()) { - CoroutineResult::Yield(trap) => { - // This came from unwind_with which requires that there be only - // Wasm code on the stack. - unsafe { - coro.force_reset(); + coro.scope(|mut coro_ref| { + // Set up metadata for the trap handler for the duration of the coroutine + // execution. This is restored to its previous value afterwards. + TrapHandlerContext::install(trap_handler, coro_ref.trap_handler(), || { + match coro_ref.resume(()) { + CoroutineResult::Yield(trap) => { + // This came from unwind_with which requires that there be only + // Wasm code on the stack. + unsafe { + coro_ref.force_reset(); + } + Err(trap) } - Err(trap) + CoroutineResult::Return(result) => result, } - CoroutineResult::Return(result) => result, - } + }) }) }