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.
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.
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).
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.
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?
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 awasmtime_func_t
which is sort of equivalent to a function pointer as it's passed towasmtime_func_call*
but you won't be able to acquire a literal native function pointer.
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.
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: Nov 22 2024 at 17:03 UTC