Stream: git-wasmtime

Topic: wasmtime / issue #8744 [question] Is it possible to obtai...


view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2024 at 06:48):

vlhomutov opened issue #8744:

WASM function pointers are just indexes in indirect function table.
We can build binary with this table enabled, and we can even access this table
using wasmtime C API.

What we see there is:

0 type1

1 type2
.....

We can also browse exports and we see there exported function names.

We can use the wasmtime API to get named export and call it normally (using API)

The problem is that looking at function table there is no way to determine which function has which name,
and thus it is not clear what index do I need for some named function.

The use case is very simple:
having a function name (provided by user), pass a pointer to it to another function in wasm module.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2024 at 07:38):

bjorn3 commented on issue #8744:

Not every exported function is guaranteed to be present in the table used for indirect calls. In fact you will likely only find the functions that the wasm module itself turns into function pointers.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2024 at 11:48):

vlhomutov commented on issue #8744:

ok, since we have a way to call function from wasmtime, is it somehow possible to pass some information into wasm to call the function there? I mean, extract some address of function from found extern? (yes, extern is just index inside engine/store, but somewhere inside there should be information about function real addres).

view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2024 at 14:37):

alexcrichton commented on issue #8744:

If the goal is to translate any name into a function pointer that needs to be done in the guest itself. As a host you can lookup exports by name but that doesn't include all functions. You can also lookup functions by their index in a table but as @bjorn3 not all tables are guaranteed to be in the function. There's currently no way for the host to invoke arbitrary functions in the guest, it's only those that are exported or a table.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2024 at 16:00):

vlhomutov commented on issue #8744:

Of course, we are talking about explicitly exported functions.
I have a function on a target that accepts function pointer and want to call it from host.
(and pass the function I found by name on the host)
The problem is that I cannot get pointer to function (usable for wasm function) on the host.

If the goal is to translate any name into a function pointer that needs to be done in the guest itself.
Is this possible in the guest at all? Any hints are welcome. Does wasm provides some metadata inside the guest by standard means?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2024 at 21:10):

alexcrichton commented on issue #8744:

Is your goal to get a literal native function pointer? If that's the case that's not possible. You can only invoke WebAssembly through the wasmtime_func_call* APIs. You can acquire a wasmtime_func_t which is sort of equivalent to a function pointer as it's passed to wasmtime_func_call* but you won't be able to acquire a literal native function pointer.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 17 2024 at 20:13):

alexcrichton closed issue #8744:

WASM function pointers are just indexes in indirect function table.
We can build binary with this table enabled, and we can even access this table
using wasmtime C API.

What we see there is:

0 type1

1 type2
.....

We can also browse exports and we see there exported function names.

We can use the wasmtime API to get named export and call it normally (using API)

The problem is that looking at function table there is no way to determine which function has which name,
and thus it is not clear what index do I need for some named function.

The use case is very simple:
having a function name (provided by user), pass a pointer to it to another function in wasm module.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 17 2024 at 20:13):

alexcrichton commented on issue #8744:

I believe the question here has been answered so I'm going to close this, but if there's any follow-ups or else feel free to comment and/or open a new issue.


Last updated: Oct 23 2024 at 20:03 UTC