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

Sub-proposal: virtual mode #18

Open
bvisness opened this issue Aug 16, 2024 · 4 comments
Open

Sub-proposal: virtual mode #18

bvisness opened this issue Aug 16, 2024 · 4 comments

Comments

@bvisness
Copy link
Collaborator

This issue tracks discussion of the virtual mode sub-proposal. This proposal is one possible component of the eventual Memory Control MVP. Please make sure to read the full sub-proposal document.

@programmerjake
Copy link

- **macOS and Linux:** `mmap(MAP_FIXED, PROT_NONE)` on instantiation, `mmap(MAP_FIXED, <prot>)` on `memory.map`, `munmap()` on `memory.unmap`.

I don't think you can use munmap since iirc that would let the host put unrelated allocations in the memory range that was supposed to be reserved for the wasm instance.

@bvisness
Copy link
Collaborator Author

I think you're right, and the "unmap" operation should probably be implemented by another PROT_NONE instead. As far as I'm aware, this should free any physical resources and reduce commit.

@SingleAccretion
Copy link

SingleAccretion commented Sep 12, 2024

Why is it important for the failure mode of the instructions (primarily memory.map) to be "always trap"?

It limits the ability of the WASM application to handle error conditions like out of memory gracefully. Consider, for example, that malloc is supposed to return null if it fails to allocate. Or consider a linear memory GC that can initiate an aggressive older generation collection if it finds itself unable to allocate (commit) more memory (not a hypothetical scenario: I am writing this on a machine where a variant of this mechanism allows multiple IDE instances to be simultaneously opened and the system to still work well).

Edit: memory.grow also doesn't trap on an OOM condition, it returns -1.

@bvisness
Copy link
Collaborator Author

Yeah, that's also a good point. Returning -1 could probably work just fine for memory.map as well.

I'm not sure that the other operations need to return error codes, but if they can reasonably fail under normal conditions, perhaps they should. Off the top of my head, though, I'm not aware though of any failures cases that would arise from correct use of system memory APIs after the memory has already been mapped.

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

No branches or pull requests

3 participants