-
Notifications
You must be signed in to change notification settings - Fork 701
Description
Forked from the discussion on dynamically linked data segments (#302):
I think what @jfbastien said is about as good as you can do within the current memory model, but to me it seems inevitable that wasm must abandon the idea that a module has absolute control over its address space. I think a model closer to OS processes can be efficiently polyfilled and will more easily accommodate dynamic linking.
Some things we can take from OSes:
- Processes as isolated address spaces.
- Modules don't get their own address space, or any isolation from other modules running in the same process, or from the OS.
- The OS manages the address space of the process, and the module must go through it for page-level allocations.
Some things we shouldn't take from OSes:
- The idea of modules being loaded at static addresses.
- You only have control over the direct dependencies of your module, making it easy to get conflicts in indirect dependencies. I think that can be solved by a process-wide dictionary from semantic names (e.g. libc v34) to URIs, but I don't want to derail this thread with that half-baked idea.
If we applied these ideas to WebAssembly:
- We can define a wasm process with an address space isolated from other processes. Make minimal guarantees about the address space: maybe just a minimum size and a protected first page.
- Define a platform API for allocating virtual address space and committing physical pages to it. mmap(pointer?,I64) -> pointer and munmap(pointer,I64) -> bool are all that's really needed.
- The platform loader needs to cooperate with the map/unmap API to reserve address space for module data segments.
This could all be implemented efficiently in the polyfill as a page allocator for the asm.js linear memory. The polyfill could also require the application to provide an initial size for linear memory, a hint that would no longer be necessary for the wasm module itself.
I expect native implementations would reserve a fixed range of addresses for a wasm process, and generate memory access code using an immutable base and bounds check. However you do it, supporting a true 64-bit address space would likely require a separate OS process for each wasm process, which has its own implications for things like APIs to talk to the browser.
Thoughts?