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

Allow non-global WASI contexts. #331

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

FGasper
Copy link
Contributor

@FGasper FGasper commented Apr 20, 2022

This allows embedding applications to create multiple WASI instances
within the same process. It preserves the existing singleton
implementations while allowing the newer path.

The new interfaces are prototyped in m3_api_wasi.h.

This allows embedding applications to create multiple WASI instances
within the same process. It preserves the existing singleton
implementations while allowing the newer path.

The new interfaces are prototyped in m3_api_wasi.h.
@sascha1337
Copy link

this looks rocksolid, @vshymanskyy hope you okay - seems like there's no maintenance on this repo anymore, at all - how to progress on this one ? LGTM x)

@vshymanskyy
Copy link
Member

@sascha1337 sorry, I've been busy lately. But I do see wasm3 needs some attention! I'll try to allocate some time during the following weeks!

@sascha1337
Copy link

Was it in any way related to something new, tech-wise? If so, let us know what you have been cooking - but if in case it was due to the geopolitic sadness and family, ( I saw the tweet. Heartbreaking), may god bless you and all related, no problem at all, that things go first. 🙌🏻

@vshymanskyy
Copy link
Member

Yes I was working on a new thing a bit:
https://github.com/vshymanskyy/muon
But mostly earning money. We need them 😁

@sascha1337
Copy link

sascha1337 commented Aug 28, 2022 via email

@FGasper
Copy link
Contributor Author

FGasper commented Aug 29, 2022

@vshymanskyy Conflicts resolved. Thanks!

@vshymanskyy
Copy link
Member

vshymanskyy commented Aug 31, 2022

@FGasper adding WASI-specific functionality to the Module API is not ideal: in fact WASI should be completely separated from the wasm3 engine, but this wasn't done yet.
I think maybe we should switch to using m3_LinkRawFunctionEx for all uvwasi bindings and pass uvwasi instance via the userdata? This would also play nicely with metawasi (which can be left unchanged in this case). WDYT?

@FGasper
Copy link
Contributor Author

FGasper commented Sep 1, 2022

adding WASI-specific functionality to the Module API is not ideal: in fact WASI should be completely separated from the wasm3 engine, but this wasn't done yet. I think maybe we should switch to using m3_LinkRawFunctionEx for all uvwasi bindings and pass uvwasi instance via the userdata? This would also play nicely with metawasi (which can be left unchanged in this case). WDYT?

@vshymanskyy: m3_LinkWASI seems already to be WASI-specific functionality in the Module API, though I get the desire to avoid furthering that design, and at the least it’s not “teaching” the module internals about WASI.

If I understand correctly, you envision a WASI object—assumedly this could be uvwasi, wasm3’s own WASI, or something else—that fulfills the m3_module’s needed imports, without the m3_module knowing or caring that the imports are WASI.

So something like (pseudocode):

wasi_context = m3_AllocStruct(m3_wasi_context_t);
m3_LinkCustomWASI(module, wasi_context);

That’s probably a cleaner design in terms of looser coupling. Applications would just need to take care to free the WASI and m3_module together. It also seems like a more significant API design change, though maybe not by much?

@FGasper
Copy link
Contributor Author

FGasper commented Sep 1, 2022

Actually, I think it’s not that different … it would just mean removing this PR’s struct M3Module.wasi, and adjusting code accordingly. m3_GetModuleWasiContext would go away, and I’d probably rename m3_LinkModuleWASI to m3_LinkCustomWASI. Applications would just have to ensure that that “custom” WASI-context gets freed along with the M3Module.

How does that strike you, @vshymanskyy?

@vshymanskyy
Copy link
Member

Yes I like it. We can also use explicit m3_LinkUvWASI / m3_LinkMetaWASI / m3_LinkSimpleWASI (and maybe even split the header in future). Only UvWASI can have multiple instances at the moment.

@FGasper
Copy link
Contributor Author

FGasper commented Sep 2, 2022

Only UvWASI can have multiple instances at the moment.

Why is that? I see that only UvWASI can accept configuration options, but can’t there be multiple simple-WASI instances that all just access the same host OS resources?

@FGasper
Copy link
Contributor Author

FGasper commented Sep 2, 2022

We can also use explicit m3_LinkUvWASI / m3_LinkMetaWASI / m3_LinkSimpleWASI (and maybe even split the header in future).

From what I can tell, the WASI implementation is determined when wasm3 is built. Are you thinking that, for example, a UvWASI-built wasm3 would expose both m3_LinkUvWASI() and m3_LinkSimpleWASI()?

@vshymanskyy
Copy link
Member

No, I don't think this has any practical use, i just want to eliminate confusion when switching between implementations.
Esp. as those methods will have different signatures (or expect a different version of m3_wasi_context_t)

@FGasper
Copy link
Contributor Author

FGasper commented Sep 2, 2022

I’ve pushed an update that reworks the branch a bit. I’ve not actually tested it, though I’m curious of your thoughts: 1ae165d

i just want to eliminate confusion when switching between implementations.

As best I can tell, the caller won’t care about the version of m3_wasi_context_t, and making the WASI API differ depending on the WASI implementation would make it harder to swap out the WASI implementation.

For example, in my Perl binding, right now I use UvWASI on platforms that I’ve seen support it, and simple WASI elsewhere. It’s nice that the WASI interaction code is the same regardless of the WASI implementation.

@FGasper FGasper changed the title Allow storing WASI context in module structs. Allow non-global WASI contexts. Sep 2, 2022
@vshymanskyy
Copy link
Member

@FGasper sorry for the huge delay. I decided to perform a maintenance release of wasm3, so I hope to review and merge PRs like this finally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants