-
Notifications
You must be signed in to change notification settings - Fork 829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reentrant/cyclic calls from host functions? #1364
Comments
Not tested, but I would say yes :-). What's your usecase? |
Basically using WASM for scripting. For example lets say an event triggers a WASM function and in it you call SpawnCreature function from WASM that adds a new creature into the game world. Then inside that same call an event for the creature's AI initialisation would trigger a call from the native code back to WASM again. Once the whole call sequence created from events ends we return back to where the SpawnCreature function was called from. So event triggers a call from native to module and module calls a native function that then causes another event that triggers a call from native to module. And eventually the call stack unwinds back to the first call. |
I am asking because it is not obvious that it would be supported. |
Yes, this has been possible with Wasmer, but it's not very simple to do right now: you can't get an We should investigate improving the API here. We also support calling "function pointers" on the host when passed from the guest (this happens through the table) and we have an example of it somewhere but it's not well documented. I'll update this comment in a bit with the information! |
Ah, funny: I tried the same thing yesterday/today and gave up at some point. My flow was
In CosmWasm/cosmwasm#245 you find all the pointer magic, which basically is a raw way of creating a weak pointer stored in the This way, I can call |
While digging around the code for To summarize the above, from the context of a host function, an exported function pointer is available through: let module: &ModuleInner = unsafe { &*context.module };
let fn_ptr = module.runnable_module.get_func(&module.info, LocalFuncIndex::new(/* index */)); Given that these pointers are already available, Is it possible to also contain the rest of the metadata that would be required to create and invoke the functions themselves? Alternatively, would it be possible to just include a |
@Rochet2 with making |
The original question was answered. I am closing this in favor of #638 which seems to discuss the lack of API for calling functions from host functions. |
Summary
Does wasmer support cyclical/reentrant calls back to module from a host function?
Additional details
I could not find information about if this is supported.
For example a module calls a host function, which then calls a function from the same module.
The text was updated successfully, but these errors were encountered: