Dynamic callbacks from guest module. #2628
Unanswered
make-things-better
asked this question in
Q&A
Replies: 1 comment
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
I want to call "host" function from "guest" using function pointer without having to include any host function in "import" object, which means that host function targets are chosen at runtime.
Question: Are there any ways to do it using Wasmer? If not, do you think it is a legitimate use case and have plans for supporting it later on?
(I have talked to @MarkMcCaskey in the Wasmer slack channel about this issue and am just making it more public here for easier tracking later on.)
Additional details
Note: The Wasmer version used in the examples below is "1.0.0-alpha3".
Considering different machine model between host and guest: LP64 vs. LP32 and type check before indirect call in guest module, the only way I could come up with to dynamically call host functions is through manipulating the function pointer table of the guest module. Here is the code I have made for it.
One problem I encountered is that there was nothing I could do to insert a new element in the table other than replacing an existing element in the table because I couldn't resize the table. I couldn't modify maximum size of the guest table at runtime and thus failed to call
Table::grow()
. To work around this, I made a new Table with bigger size and overwrite the table into the Wasm instance, but it didn't work as expected emittingTrap(TableAccessOutOfBounds)
. Here is the code.Since the above code also didn't work, this time I wanted the guest wasm module to have bigger table size from the start rather than resizing it. For this, I searched for some clang compile options like
--table-size-maximum=??
but there weren't such options. Besides, I searched for some APIs in Wasmer to make the table size bigger before or after the guest module is instantiated, and failed.Similar issue
#1302
Beta Was this translation helpful? Give feedback.
All reactions