Stream: wasmtime

Topic: ✔ `CallThreadState::pop` regression ?


view this post on Zulip Antoine Lavandier (Aug 26 2026 at 13:04):

Hi,

I have some code that I used for benchmarks that I first made for wasmtime version 42.0.1, the same code when used with wasmtime version 48.0.1 panics.

Panic Message:

panicked at /home/tribe11200675/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wasmtime-48.0.1/src/runtime/vm/traphandlers.rs:627:13:
assertion failed: core::ptr::eq(head, self)

Code (Removed boilerplate)

#![no_std]

fn main() {
       let mut config = Config::default();
        config.max_wasm_stack(4096);

        config.target("pulley32").unwrap();

        config.wasm_custom_page_sizes(true);

        config.table_lazy_init(false);
        config.memory_reservation(0);
        config.memory_init_cow(false);
        config.memory_may_move(false);

        // Options that can be changed without changing the payload
        config.memory_reservation_for_growth(0);

        config.memory_init_cow(false);

        let engine = Engine::new(&config).unwrap();

        let mut store = Store::new(&engine, (Instant::now(), Instant::now()));

        let module = unsafe { Module::deserialize_raw(&engine, wasm.as_slice().into()).unwrap() };

        let mut linker = Linker::new(&engine);

       let instance = linker.instantiate(&mut store, &module).unwrap();

       let correct = instance.get_typed_func::<(), u32>(&mut store, "__original_main").unwrap()
                .call(&mut store, ()).unwrap();
}

// Same as https://github.com/bytecodealliance/wasmtime/blob/main/examples/min-platform/embedding/wasmtime-platform.c
// I have no idea whether this is safe or not.
static mut TLS_PTR: *mut u8 = core::ptr::null_mut();

#[allow(unsafe_code)]
#[unsafe(no_mangle)]
extern "C" fn wasmtime_tls_get() -> *mut u8 {
    #[allow(unsafe_code)]
    unsafe { TLS_PTR }
}

#[allow(unsafe_code)]
#[unsafe(no_mangle)]
extern "C" fn wasmtime_tls_set(ptr: *mut u8) {
    #[allow(unsafe_code)]
    unsafe { TLS_PTR = ptr };
}

What's the new correct way of doing the TLS thing ?

view this post on Zulip Antoine Lavandier (Aug 26 2026 at 13:08):

Ok I see that this was changed in https://github.com/bytecodealliance/wasmtime/pull/13533

view this post on Zulip Antoine Lavandier (Aug 26 2026 at 13:15):

Ok, changing the tls code to the following worked

    static mut TLS_STORAGE: [*mut u8; 2] = [core::ptr::null_mut(); 2];

    #[allow(unsafe_code)]
    #[unsafe(no_mangle)]
    extern "C" fn wasmtime_tls_get(slot: usize) -> *mut u8 {
        #[allow(unsafe_code)]
        unsafe { TLS_STORAGE[slot] }
    }

    #[allow(unsafe_code)]
    #[unsafe(no_mangle)]
    extern "C" fn wasmtime_tls_set(slot: usize, ptr: *mut u8) {
        #[allow(unsafe_code)]
        unsafe { TLS_STORAGE[slot] = ptr };
    }

view this post on Zulip Notification Bot (Aug 26 2026 at 13:15):

Antoine Lavandier has marked this topic as resolved.


Last updated: Aug 30 2026 at 09:07 UTC