Stream: wasmtime

Topic: linker.get_default not retaining memory


view this post on Zulip squirl (Mar 11 2023 at 10:22):

It seems like there's two different ways to add a module to a linker and get the _start symbol in it:

// Using module + get_default
linker.module(&mut store, "", &module)?;
let func = linker.get_default(&mut store, "")?.typed::<(), ()>(&store);

// Using instantiate + get_typed_func
let instance = linker.instantiate(&mut store, &module)?;
let func = instance.get_typed_func::<(), ()>(&mut store, "_start")?;

However, the first option resets the module's memory before every func.call() (meaning all globals are reset to their initial values each time), whereas the second doesn't. What's the difference between these and how can I change this behaviour for each of them?

view this post on Zulip bjorn3 (Mar 11 2023 at 20:20):

In wasi you are only allowed to call _start once.

view this post on Zulip Pat Hickey (Mar 12 2023 at 18:28):

Wasi programs that export a _start are so-called “commands” - they can be instantiated and run once, and should not run multiple times. This restriction exists to get things working with libc. the linker get_default knows about this pattern and enforces it for you, but the instantiate & func call does not.

view this post on Zulip Pat Hickey (Mar 12 2023 at 18:31):

if you want to use wasi in a program that has multiple export funcs called on the same instantance, you want to compile the wasi program differently - use the -mexec-model=reactor cflag in wasi-sdk, or crate type cdylib on a rust program


Last updated: Oct 23 2024 at 20:03 UTC