Skip to content
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

Stability of wasm exports for allocation #2788

Closed
codefromthecrypt opened this issue Apr 20, 2022 · 2 comments
Closed

Stability of wasm exports for allocation #2788

codefromthecrypt opened this issue Apr 20, 2022 · 2 comments
Labels
docs Documentation needed wasm WebAssembly

Comments

@codefromthecrypt
Copy link
Contributor

There are wasm exports like "malloc" and "free" which make it seem like you can allocate outside code compiled by TinyGo and not collide with memory managed by code compiled by TinyGo. This seems like a dangerous practice, but also intentionally not using it is extremely complicated (ex tracking references and re-exporting your own functions as described in #2787)

It would help to get an answer on these special exports, what they are expected to do and if they are stable. If they are stable, simpler instructions can be made like https://wasmedge.org/book/en/embed/go/memory.html#pass-bytes-to-tinygo-functions

If they aren't stable, then solving #2787 will be more complicated.

By stable, I mean the signatures and exports not disappearing on future releases, and the behavior understood. Ex if you call malloc, you won't get collissions by code managed in Go, and that remains the case until "free" is called. Moreover, that you can pass ownership of memory to an external function and they can call "free" to clear it.

I still think #2787 will be nuanced after this, but a decision here will impact how complex that will be.

@aykevl
Copy link
Member

aykevl commented Aug 24, 2022

Yeah we should document it. The way WebAssembly works is certainly not well enough documented.

But to answer your question:

It would help to get an answer on these special exports, what they are expected to do and if they are stable.

To be honest, they were exported by accident. They are there so that wasm-libc works (it needs malloc), but by accident they also got exported out of the module. So I wouldn't count on them to remain available.

@codefromthecrypt
Copy link
Contributor Author

I will close this, though would warn against removing these exports as they are all over the ecosystem in many runtime examples. Provided they don't hurt I wouldn't eagerly remove them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation needed wasm WebAssembly
Projects
None yet
Development

No branches or pull requests

3 participants