MPK: Segfault running an `Engine` on a preexisting thread
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
Two reproducers are given in the issue: one segfaults when a Store (with memory_protection_keys(Enabled::Yes) and linear_memory_keep_resident) is dropped on a different thread than where it ran, the other when an Engine's memory is read from a preexisting thread. Start by reproducing both under a debugger to see where the fault happens, then trace wasmtime's MPK/PKRU handling in the pooling allocator — where per-thread key state is registered, saved/restored across threads, and cleaned up on thread exit and Store drop. Done means both snippets run to completion without a segfault, ideally with a regression test.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
This input:
use std::sync::mpsc;
use wasmtime::*;
const WAT: &str = r#"(module
(memory (export "m") 1)
(data (i32.const 0) "hello")
(func (export "f") (i32.store (i32.const 100) (i32.const 1))))"#;
fn engine() -> Result<Engine> {
let mut pool = PoolingAllocationConfig::default();
pool.memory_protection_keys(Enabled::Yes);
pool.total_memories(32);
pool.linear_memory_keep_resident(65536);
let mut config = Config::new();
config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
Engine::new(&config)
}
fn main() -> Result<()> {
let (tx, rx) = mpsc::channel::<Store<()>>();
let pre = std::thread::spawn(move || {
let store = rx.recv().unwrap();
eprintln!("dropping store on other thread...");
drop(store);
eprintln!("dropped");
});
let engine = engine()?;
let module = Module::new(&engine, WAT)?;
let mut store = Store::new(&engine, ());
let instance = Instance::new(&mut store, &module, &[])?;
instance
.get_typed_func::<(), ()>(&mut store, "f")?
.call(&mut store, ())?;
tx.send(store).unwrap();
pre.join().unwrap();
Ok(())
}
fails with:
$ cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/mpk-thread`
dropping store on other thread...
zsh: segmentation fault (core dumped) cargo run
and this input:
use std::sync::mpsc;
use wasmtime::*;
const WAT: &str = r#"(module
(memory (export "m") 1)
(data (i32.const 0) "hello")
(func (export "f") (i32.store (i32.const 100) (i32.const 1))))"#;
fn engine() -> Result<Engine> {
let mut pool = PoolingAllocationConfig::default();
pool.memory_protection_keys(Enabled::Yes);
pool.total_memories(32);
pool.linear_memory_keep_resident(65536);
let mut config = Config::new();
config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
Engine::new(&config)
}
fn main() -> Result<()> {
let (tx, rx) = mpsc::channel::<Engine>();
let worker = std::thread::spawn(move || -> Result<()> {
let engine = rx.recv().unwrap();
let module = Module::new(&engine, WAT)?;
let mut store = Store::new(&engine, ());
let instance = Instance::new(&mut store, &module, &[])?;
let mem = instance.get_memory(&mut store, "m").unwrap();
eprintln!("reading memory from pre-existing thread...");
eprintln!("data = {:?}", &mem.data(&store)[..5]);
Ok(())
});
tx.send(engine()?).unwrap();
worker.join().unwrap()?;
Ok(())
}
fails with:
$ cargo run
Compiling mpk-thread v0.1.0 (/home/alex/code/wasmtime2/reports/001-mpk-pkru-preexisting-thread-segv)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.39s
Running `target/debug/mpk-thread`
reading memory from pre-existing thread...
data = [zsh: segmentation fault (core dumped) cargo run
- Lenguaje dominante
- Rust
- Estrellas
- 18.9k
- Forks
- 2k
- Merge medio
- 1 d 6 h
- PR fusionados (30 d)
- 238
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de bytecodealliance/wasmtime
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
bytecodealliance/wasmtime#15536 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
bytecodealliance/wasmtime#15455 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
wasi-preview1-component-adapter: fd_write does not invalidate cached InputStream, causing stale readsPosiblemente ocupada @dpfens la tomó hace 13 días. Abiertowasi
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
bytecodealliance/wasmtime#15296 ·
Los mantenedores suelen responder en 1 día
-
bug wasm-proposal:exceptions wasmtime:debugging
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
bytecodealliance/wasmtime#14102 ·
Los mantenedores suelen responder en 1 día
-
wasm-proposal:gc
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
bytecodealliance/wasmtime#13808 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de bytecodealliance/wasmtime
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
area: plugins bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
clipy-recorder/clipy#1039 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
valkey-io/valkey-glide#7975 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
gofractally/psibase#2379 ·
Los mantenedores suelen responder en 3 días
-
Qwen stream parser: a chunk with "error": null is treated as a stream errorPosiblemente ocupada @Beehtrix la tomó hoy. Abiertoarea:models bug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
brekkylab/ailoy#681 · 1 comentario ·
Los mantenedores suelen responder en 2 días