1

I have a simple function compiled using the WASI SDK, intended to receive a function pointer to pass to another C library that is supposed to call it at a later time (and with an arbitrary signature):

__attribute__((export_name("add_func")))
void add_func(void* func) {
    // pass func to some other API expecting void*
}

The WASM module is loaded and executed through wasmtime-dotnet, where I want to dynamically create an arbitrary number of functions and pass them to add_func, in this manner:

Instance inst = ...;
var add_func = inst.GetAction<Function>("add_func");
add_func(Function.FromCallback(_store, (caller, arguments, results) => {
   ...
});

However, inst.GetAction<Function> returns null, and the only way to retrieve and call this function seems to be with an int parameter, like GetAction<int>.

How do I pass a function created in this way to WASM? I could not find any way to either change the signature of the function to allow funcref arguments, or to obtain the index of the created function (I reckon function pointers are indexes in WASM anyway).

IS4
  • 11,945
  • 2
  • 47
  • 86

0 Answers0