Comments (6)
You are too nice! The current solution is stop-gap and not ideal. We could come up with clever and equally elegant solution that handles all the edge cases.
Another idea we had was to make the code less verbose with macros and other code gen. It would still be static, but it would be a lot nicer to look at.
If you think doing a dynfunc is best, we would be happy to work with you on it! PRs welcome!
from wasmer.
Thanks for the quick response!
macros and other code gen
I'm always a fan of static dispatch when possible. What were you thinking here? I see three obvious options:
- Create a bunch of boxed closures when the module is loaded but before cranelifting. This would still require a dynamic type to store the closure cache.
- Use a proc macro to generate the power set of
{v, i, d, j}^7
, but this would make extra work for the compiler and then someone withinvoke_iiiiiiii
would just come along and ruin everything - Parse the module, cargo compile a dylib containing the invokes, load it in wasmer and create
ImportedFunc
s. This option is probably the cleanest and most static if one ignores its patent absurdity :)
DynCall seems the most straightforward, but it'll take a bit of hacking to get the types and ownership ironed out.
from wasmer.
That is a pretty good analysis! 😍
I was originally thinking of something along-the-lines of #2. Yes, it would hurt compile times, but I think the solution would have terse code, and we wouldn't have to introduce many new concepts into the code base.
Introducing a dynamic call would be cool, but it may introduce some complexity. We are currently working on a few other backends (including LLVM!) and this may slow progress there.
If you could imagine a clever way of doing dyncall, I am all hears 👂
In the mean time, I am going to think about it for a bit. Will get back to you 🔙 👌. It seems like this problem is important to you so, we should get it figured out!
from wasmer.
The way that this works in the wace interpreter is that import is basically a direct dlopen/dlsym. In other words, this works without any knowledge about fputs
in wace:
(import "env" "fputs" (func $lib_fputs (param i32 i32) (result i32)))
wace is even able to handle function pointer based callbacks (needed for SDL for example) by doing mprotect on the table data and then trapping on reads of the table and translating the offsets back into actual function pointers. And for 32-bit x86 it even supports calling functions that use 16bit and 8bit parameters but this is relying on the little endian nature of x86 and the way parameters are passed/padded on the stack so it wouldn't necessarily be portable.
One major caveat however is that this requires that the wace executable to be compiled as a 32-bit program.
Might or might not be relevant but I thought I would mention that this is already being done in a different context :-)
from wasmer.
This is now solved in the refactor. Will close this issue once it lands in master
.
from wasmer.
Thanks to the refactor, now all functions (host and wasm) can be called dynamically (via Function::call
).
Closing the issue
from wasmer.
Related Issues (20)
- CLI: "container unpack" command does not correctly unpack atoms HOT 1
- Mobile compatible wasmer engine HOT 4
- example wasm.hh Code running error HOT 1
- Upgrade to tlsv2 HOT 2
- Fuzz tests are broken HOT 1
- WASI Preview 2 Support HOT 3
- Fetching logs for an app fails HOT 2
- Broken on nightly because of ahash 0.7 (aka "update hashbrown") HOT 4
- PHP execution breaks after consecutive requests HOT 2
- Fix failure when fetching logs for an app HOT 2
- Make wordpress (in PHP) run end to end in Wasmer/WASIX HOT 2
- Potential Bug: Use-of-Uninitialized-Value HOT 1
- Possible race condition on `virtual-fs` HOT 1
- CI: Run tests with nightly rustc HOT 1
- Build PHP locally HOT 2
- Add README for wasi-fyi tests HOT 1
- CLI: "wasmer deploy" auto package version bump does not work if package version is out of date HOT 1
- Deprecation of `cfg_attr(..., crate_type = "...")` HOT 2
- (WASI) Wrong file offset after file write in append mode HOT 1
- fs::readdir performance in wasi is not great HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasmer.