Skip to content
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
3 changes: 2 additions & 1 deletion lib/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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"]
30 changes: 16 additions & 14 deletions lib/vm/src/trap/traphandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -950,7 +950,7 @@ fn on_wasm_stack<F: FnOnce() -> 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())));

Expand All @@ -962,20 +962,22 @@ fn on_wasm_stack<F: FnOnce() -> 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,
}
})
})
}

Expand Down
Loading