Stream: general

Topic: Callbacks to the host VM


view this post on Zulip Alexandru Ene (Jun 30 2020 at 12:15):

Hello,

I was looking through the examples here: https://github.com/bytecodealliance/wasmtime/blob/main/examples/hello.c
I don't understand how the wasm program "knows" that the registered import is the one for the hello function.

Other VMs have to name the functions registered (e.g. wasm3 linker). But I find no such thing for wasmtime.

Does this mean that imports are matched in order with the imports provided to this method?:

  const wasm_extern_t *imports[] = { wasm_func_as_extern(hello) };
  error = wasmtime_instance_new(store, module, imports, 1, &instance, &trap);

This seems like a difficult way to manage an import table. Is there another way?

Standalone JIT-style runtime for WebAssembly, using Cranelift - bytecodealliance/wasmtime

view this post on Zulip Alex Crichton (Jun 30 2020 at 14:11):

@Alexandru Ene ah yeah so wasm_instance_new (and wasmtime_instance_new) require a 1:1 mapping from the module's imports to the list of imports provided (you can see some info on that at https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Instance.html#method.new)

view this post on Zulip Alex Crichton (Jun 30 2020 at 14:12):

for a more ergonomic or string-based API, though, I'd recommend using the wasmtime_linker_t type which allows you to specify imports by name and then instantiate a module via that name lookup

view this post on Zulip Alexandru Ene (Jun 30 2020 at 14:30):

Alex, you're absolutely right! Thanks for all the help btw, and sorry for all the newbish questions :D

view this post on Zulip Alex Crichton (Jun 30 2020 at 14:31):

No worries at all! This is also on us for not having a documented C API and a pretty limited number of examples :)

view this post on Zulip Till Schneidereit (Jun 30 2020 at 17:56):

@Alexandru Ene to add to what Alex said, the example you mentioned uses the official Wasm C-API so that determines how this works. Better documentation would help, of course! :slight_smile:

Wasm C API prototype. Contribute to WebAssembly/wasm-c-api development by creating an account on GitHub.

view this post on Zulip Alexandru Ene (Jun 30 2020 at 18:00):

Yup, I did spend some time even in the linker api as I even had a PR on it, but somehow missed that it is available for linking host functions :D .


Last updated: Nov 22 2024 at 17:03 UTC