Skip to content

Question: Best way to share malloc/free in multiple modules? #579

@konsumer

Description

@konsumer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions