Browse Source

Plumb coredump feature to `wasmtime-runtime` (#8252)

* Plumb coredump feature to `wasmtime-runtime`

The `wasmtime` crate already has a `coredump` feature but whether or not
it's enabled the `wasmtime-runtime` crate still captures a core dump.
Use this flag in the `wasmtime` crate to plumb support to
`wasmtime-runtime` to skip capture if it's not enabled.

* Fix a typo
pull/8256/head
Alex Crichton 7 months ago
committed by GitHub
parent
commit
c6bec9c1e9
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      crates/runtime/Cargo.toml
  2. 21
      crates/runtime/src/traphandlers.rs
  3. 16
      crates/runtime/src/traphandlers/coredump_disabled.rs
  4. 18
      crates/runtime/src/traphandlers/coredump_enabled.rs
  5. 2
      crates/wasmtime/Cargo.toml

7
crates/runtime/Cargo.toml

@ -29,7 +29,7 @@ anyhow = { workspace = true }
paste = "1.0.3"
encoding_rs = { version = "0.8.31", optional = true }
sptr = "0.3.2"
wasm-encoder = { workspace = true }
wasm-encoder = { workspace = true, optional = true }
[target.'cfg(target_os = "linux")'.dependencies]
memfd = "0.6.2"
@ -65,9 +65,10 @@ cc = "1.0"
wasmtime-versioned-export-macros = { workspace = true }
[features]
async = ["wasmtime-fiber"]
async = ["dep:wasmtime-fiber"]
pooling-allocator = []
component-model = ["wasmtime-environ/component-model", "dep:encoding_rs"]
wmemcheck = ['dep:wasmtime-wmemcheck']
debug-builtins = ['wasmtime-jit-debug']
debug-builtins = ['dep:wasmtime-jit-debug']
gc = ["wasmtime-environ/gc"]
coredump = ["dep:wasm-encoder"]

21
crates/runtime/src/traphandlers.rs

@ -2,6 +2,12 @@
//! signalhandling mechanisms.
mod backtrace;
#[cfg(feature = "coredump")]
#[path = "traphandlers/coredump_enabled.rs"]
mod coredump;
#[cfg(not(feature = "coredump"))]
#[path = "traphandlers/coredump_disabled.rs"]
mod coredump;
use crate::sys::traphandlers;
@ -277,6 +283,7 @@ mod call_thread_state {
pub(super) jmp_buf: Cell<*const u8>,
pub(super) signal_handler: Option<*const SignalHandler<'static>>,
pub(super) capture_backtrace: bool,
#[cfg(feature = "coredump")]
pub(super) capture_coredump: bool,
pub(crate) limits: *const VMRuntimeLimits,
@ -314,11 +321,14 @@ mod call_thread_state {
capture_coredump: bool,
limits: *const VMRuntimeLimits,
) -> CallThreadState {
let _ = capture_coredump;
CallThreadState {
unwind: UnsafeCell::new(MaybeUninit::uninit()),
jmp_buf: Cell::new(ptr::null()),
signal_handler,
capture_backtrace,
#[cfg(feature = "coredump")]
capture_coredump,
limits,
prev: Cell::new(ptr::null()),
@ -500,17 +510,6 @@ impl CallThreadState {
Some(unsafe { Backtrace::new_with_trap_state(limits, self, trap_pc_and_fp) })
}
fn capture_coredump(
&self,
limits: *const VMRuntimeLimits,
trap_pc_and_fp: Option<(usize, usize)>,
) -> Option<CoreDumpStack> {
if !self.capture_coredump {
return None;
}
Some(CoreDumpStack::new(&self, limits, trap_pc_and_fp))
}
pub(crate) fn iter<'a>(&'a self) -> impl Iterator<Item = &Self> + 'a {
let mut state = Some(self);
std::iter::from_fn(move || {

16
crates/runtime/src/traphandlers/coredump_disabled.rs

@ -0,0 +1,16 @@
use crate::traphandlers::CallThreadState;
use crate::VMRuntimeLimits;
/// A WebAssembly Coredump
#[derive(Debug)]
pub enum CoreDumpStack {}
impl CallThreadState {
pub(super) fn capture_coredump(
&self,
_limits: *const VMRuntimeLimits,
_trap_pc_and_fp: Option<(usize, usize)>,
) -> Option<CoreDumpStack> {
None
}
}

18
crates/runtime/src/traphandlers/coredump.rs → crates/runtime/src/traphandlers/coredump_enabled.rs

@ -20,19 +20,21 @@ pub struct CoreDumpStack {
pub operand_stack: Vec<Vec<CoreDumpValue>>,
}
impl CoreDumpStack {
/// Capture a core dump of the current wasm state
pub fn new(
cts: &CallThreadState,
impl CallThreadState {
pub(super) fn capture_coredump(
&self,
limits: *const VMRuntimeLimits,
trap_pc_and_fp: Option<(usize, usize)>,
) -> Self {
let bt = unsafe { Backtrace::new_with_trap_state(limits, cts, trap_pc_and_fp) };
) -> Option<CoreDumpStack> {
if !self.capture_coredump {
return None;
}
let bt = unsafe { Backtrace::new_with_trap_state(limits, self, trap_pc_and_fp) };
Self {
Some(CoreDumpStack {
bt,
locals: vec![],
operand_stack: vec![],
}
})
}
}

2
crates/wasmtime/Cargo.toml

@ -167,7 +167,7 @@ wmemcheck = ["wasmtime-runtime?/wmemcheck", "wasmtime-cranelift?/wmemcheck"]
demangle = ["wasmtime-environ/demangle"]
# Enable support for generating core dumps on traps.
coredump = ["dep:wasm-encoder", "runtime"]
coredump = ["dep:wasm-encoder", "runtime", "wasmtime-runtime/coredump"]
# Export some symbols from the final binary to assist in debugging
# Cranelift-generated code with native debuggers like GDB and LLDB.

Loading…
Cancel
Save