WebAssembly / WebAssembly/wasi-libc
Question: Best way to share malloc/free in multiple modules?
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 1k
- Forks
- 251
- Avg merge
- 7h 15m
- Merged PRs (30d)
- 3
Description
I have an example project that allows me to load multiple modules and share malloc/free (by implementing it in the host and sharing memory and a few other globals.)
I would like to do similar, but be able to use all of wasi-libc, so I can write "mostly just libc" code that shares memory between multiple modules.
What is the best way to do this? I have tried these so far:
- import malloc/free and some memory things into every module. This currently works, but for the rest of libc, I'd need to wrap all the wasi stuff, duplicating the work here. I wrote a stub that implements some libc stuff, and imports wasi and malloc/free. I am not a very experienced C programmer, though, and the idea of maintaining my own libc seems a bit daunting. Is there a define or something that says "use all WASI preview2 imports, but import malloc/free instead of implement it" in wasi-libc? (maybe something with
MALLOC_IMPL?) - export wasi-libc's malloc/free & mem from 1 module, and share with others. I tried this, and could not really get it working. Each other module that uses wasi-libc also wants to implement it's own malloc/free and they do not load together. I may have set this up wrong, so if this is the right way to do it, help with building this would be appreciated
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked example project and its wasm/wasm_shared.h stub, then compare the two approaches described for sharing malloc/free across WASI modules. Determine whether wasi-libc supports this configuration or document the supported setup and its limitations; the issue has no named tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, wasm
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100