Skip to content

add virtualization doc#69

Closed
wanderer wants to merge 2 commits into
WebAssembly:masterfrom
wanderer:virtualization
Closed

add virtualization doc#69
wanderer wants to merge 2 commits into
WebAssembly:masterfrom
wanderer:virtualization

Conversation

@wanderer
Copy link
Copy Markdown

This PR attempts to sketch out what the overloaded term "virtualization" mean, why we might want it and how it might be accomplished.

Comment thread docs/virtualization.md Outdated
)
```

### inheritance
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the reason to use inheritance over composition here because of other OOP types defined in the IDL?

Being able to arbitrarily combine interfaces without the restrictions of a hierarchy is something I'm interested in if this grows beyond WASI

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh i really messed this up. I copied the wrong file here!!! :S please move to #64

@sunfishcode
Copy link
Copy Markdown
Member

This document introduces the concepts of "static" and "dynamic" virtualization, however it appears to only discuss "dynamic" virtualization, with techniques to essentially create vtable-like objects which would expose the API functions.

This paper describes a path which enables virtualizating static APIs dynamically by making modules first-class objects. From what I understand, this would seem to fit wasm fairly well, as it would allow us to continue to use static bindings for many cases, but still virtualize APIs. I'd be interested in what you think of this approach.

@lukewagner
Copy link
Copy Markdown
Member

Agreed with @sunfishcode. I've also discussed the rough idea with @erights and it seemed like it would indeed be possible to base an ocap-style runtime-polymorphic system on top of a lower-level, more-static virtualization mechanism like what's in the paper Dan linked to. I think it would end up being expressed as a "layered on top of core wasm" spec, just like, and quite complementary to, Interface Types.

Unfortunately, we don't yet have even an explainer-level writeup of how the idea in the paper maps concretely down to wasm. Personally, I'm interested to help write an initial sketch so that we can get a Stage 0 proposal repo to discuss more, but I need to make some more progress on getting Interface Types written up before starting. I'd also be happy to collaborate with anyone who wants to start sooner.

Copy link
Copy Markdown

@Chatina73 Chatina73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove changes

Comment thread docs/virtualization.md
@@ -0,0 +1,62 @@
# Virtualization

Virtualization in the context of WASI interfaces is the ability for a Webassembly module to implement a given interface and consumer module to be able to use that implement transparently.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Virtualization in the context of WASI interfaces is the ability for a Webassembly module to implement a given interface and consumer module to be able to use that implement transparently.
Virtualization in the context of WASI interfaces is the ability for a Webassembly module to implement a given interface and for a consumer module to be able to use its implementation transparently.

Comment thread docs/virtualization.md

Virtualization in the context of WASI interfaces is the ability for a Webassembly module to implement a given interface and consumer module to be able to use that implement transparently.

Furthermore there are two classes of virtualization; static and dynamic. Static virtualization is done before the initialization of a Wasm store and dynamic at runtime.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Furthermore there are two classes of virtualization; static and dynamic. Static virtualization is done before the initialization of a Wasm store and dynamic at runtime.
Furthermore there are two classes of virtualization: static and dynamic. Static virtualization is done before the initialization of a Wasm store and dynamic is performed at runtime.

Comment thread docs/virtualization.md

## Usecase

Roughly taken from [here](https://pdfs.semanticscholar.org/4cce/9abb177cc58c199e13b82d498f37010c2bfc.pdf). Lets say a user wants to encrypt a text file they are editing. One way this could be accomplished is by having composable services. An encryption module could export the interface for a directory that would encrypt any file written to it. Lets consider how this could be done with in the framework of WASI. At runtime the encryption module would given a root directory file descriptor in which it would write encrypted text to, it would also would return a wrapped file descriptor of a directory that would be given to the text editor to write in. This means any WASI `fd` related calls that the text editor makes would handled by the encryption module which would then interact base system. Lets look next at a WASI program might accomplish virtualizing the file descriptor interface.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Roughly taken from [here](https://pdfs.semanticscholar.org/4cce/9abb177cc58c199e13b82d498f37010c2bfc.pdf). Lets say a user wants to encrypt a text file they are editing. One way this could be accomplished is by having composable services. An encryption module could export the interface for a directory that would encrypt any file written to it. Lets consider how this could be done with in the framework of WASI. At runtime the encryption module would given a root directory file descriptor in which it would write encrypted text to, it would also would return a wrapped file descriptor of a directory that would be given to the text editor to write in. This means any WASI `fd` related calls that the text editor makes would handled by the encryption module which would then interact base system. Lets look next at a WASI program might accomplish virtualizing the file descriptor interface.
Roughly taken from [here](https://pdfs.semanticscholar.org/4cce/9abb177cc58c199e13b82d498f37010c2bfc.pdf). Let's say a user wants to encrypt a text file they are editing. One way this could be accomplished is by having composable services. An encryption module could export the interface for a directory that would encrypt any file written to it. Let's consider how this could be done with in the framework of WASI. At runtime the encryption module would given a root directory file descriptor in which it would write encrypted text to, it would also would return a wrapped file descriptor of a directory that would be given to the text editor to write in. This means any WASI `fd`-related calls that the text editor makes would handled by the encryption module which would then interact with the base system. Let's look next at how a WASI program might accomplish virtualizing the file descriptor interface.

Comment thread docs/virtualization.md

### Dynamic Dispatching - Without GC

Assuming the function reference proposal, another way to implement dynamic dispatching currently would be to create a primitive polyfill for structs. An `fd` would then be represented as a stuct who's fields contained all the associated functions
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Assuming the function reference proposal, another way to implement dynamic dispatching currently would be to create a primitive polyfill for structs. An `fd` would then be represented as a stuct who's fields contained all the associated functions
Assuming the function reference proposal, another way to implement dynamic dispatching currently would be to create a primitive polyfill for structs. An `fd` would then be represented as a struct whose fields contain all the associated functions.

sunfishcode added a commit to sunfishcode/WASI that referenced this pull request Jan 6, 2020
This spells out WASI's design principles around capabilities,
relationship to POSIX, and other topics.

This also includes a section on virtualization, which takes some ideas
from WebAssembly#69, but modifies it to focus on using interface types and the
linking proposal to implement virtualization.
sunfishcode added a commit to sunfishcode/WASI that referenced this pull request Feb 7, 2020
This spells out WASI's design principles around capabilities,
relationship to POSIX, and other topics.

This also includes a section on virtualization, which takes some ideas
from WebAssembly#69, but modifies it to focus on using interface types and the
linking proposal to implement virtualization.
sunfishcode added a commit that referenced this pull request Feb 19, 2020
* Add a WASI design principles document.

This spells out WASI's design principles around capabilities,
relationship to POSIX, and other topics.

This also includes a section on virtualization, which takes some ideas
from #69, but modifies it to focus on using interface types and the
linking proposal to implement virtualization.

* Fix the links to the type imports proposal.

* Fix "wowever" typo.

* Elaborate on what WASI does instead of shared filesystem views.

* Linkify "weak imports".

* Rename WASI-design-principles.md to DesignPrinciples.md

* Wrap lines to 72 columns.

* Remove a redundant "always".

* Say "interposition" instead of "virtualization".

* Add some text to clarify that shared-nothing linking will require porting.

* Reword the paragraph explaining how forgeable indices doesn't mean forgeable capabilities.

* Update docs/DesignPrinciples.md

Fix spelling of "trade-off"

Co-Authored-By: Ben B. <benne@klimlive.de>

Co-authored-by: Ben B. <benne@klimlive.de>
@sunfishcode
Copy link
Copy Markdown
Member

Virtualization in WASI is now described in the Design Principles document which has now landed, in the section on interposition (meaning "virtualization" in the sense used here), which lays out a vision. In short, the "verbs" are imported functions, and the "nouns" are handle values. This describes the "more static" version described by Luke above.

If there are any questions or concerns about this approach, or anything that's unclear, feel free to file issues or bring them to the WASI Subgroup meetings.

yoshuawuyts pushed a commit to yoshuawuyts/WASI that referenced this pull request Nov 25, 2025
yoshuawuyts pushed a commit to yoshuawuyts/WASI that referenced this pull request Nov 25, 2025
* Add a WASI design principles document.

This spells out WASI's design principles around capabilities,
relationship to POSIX, and other topics.

This also includes a section on virtualization, which takes some ideas
from WebAssembly#69, but modifies it to focus on using interface types and the
linking proposal to implement virtualization.

* Fix the links to the type imports proposal.

* Fix "wowever" typo.

* Elaborate on what WASI does instead of shared filesystem views.

* Linkify "weak imports".

* Rename WASI-design-principles.md to DesignPrinciples.md

* Wrap lines to 72 columns.

* Remove a redundant "always".

* Say "interposition" instead of "virtualization".

* Add some text to clarify that shared-nothing linking will require porting.

* Reword the paragraph explaining how forgeable indices doesn't mean forgeable capabilities.

* Update docs/DesignPrinciples.md

Fix spelling of "trade-off"

Co-Authored-By: Ben B. <benne@klimlive.de>

Co-authored-by: Ben B. <benne@klimlive.de>
yoshuawuyts added a commit to yoshuawuyts/WASI that referenced this pull request Nov 25, 2025
yoshuawuyts pushed a commit to yoshuawuyts/WASI that referenced this pull request Nov 25, 2025
* Add a WASI design principles document.

This spells out WASI's design principles around capabilities,
relationship to POSIX, and other topics.

This also includes a section on virtualization, which takes some ideas
from WebAssembly#69, but modifies it to focus on using interface types and the
linking proposal to implement virtualization.

* Fix the links to the type imports proposal.

* Fix "wowever" typo.

* Elaborate on what WASI does instead of shared filesystem views.

* Linkify "weak imports".

* Rename WASI-design-principles.md to DesignPrinciples.md

* Wrap lines to 72 columns.

* Remove a redundant "always".

* Say "interposition" instead of "virtualization".

* Add some text to clarify that shared-nothing linking will require porting.

* Reword the paragraph explaining how forgeable indices doesn't mean forgeable capabilities.

* Update docs/DesignPrinciples.md

Fix spelling of "trade-off"

Co-Authored-By: Ben B. <benne@klimlive.de>

Co-authored-by: Ben B. <benne@klimlive.de>
yoshuawuyts pushed a commit to yoshuawuyts/WASI that referenced this pull request Nov 25, 2025
* Add advisory file locking support.

Add functions which correspond to `flock` in Unix. This is not a POSIX
interface, but it's sufficiently portable, there's a way to implement it
on Windows, and it doesn't have problematic process-associated locks.

Instead of having a single `flock` function that gets passed and enum,
this has separate functions for shared vs. exclusive, and locking vs.
non-locking. That's something we can revisit if needed, but it keeps the
API simpler for now.

* Document what happens if a lock is already held.

* Add notes about interactions between WASI locks and non-WASI locks.

Also mention that exclusive locks may require write mode on file
descriptors, as described in the [Linux `flock` man page].

[Linux `flock` man page]: https://man7.org/linux/man-pages/man2/flock.2.html

* Add a comment that not all filesystems support locking.

* Update wasi-filesystem.abi.md.
yoshuawuyts pushed a commit to yoshuawuyts/WASI that referenced this pull request Nov 25, 2025
* Make the `fields.delete` method fallible
* Make setters fallible
* Regenerate proxy.md
yoshuawuyts pushed a commit to yoshuawuyts/WASI that referenced this pull request Nov 25, 2025
* Add a WASI design principles document.

This spells out WASI's design principles around capabilities,
relationship to POSIX, and other topics.

This also includes a section on virtualization, which takes some ideas
from WebAssembly#69, but modifies it to focus on using interface types and the
linking proposal to implement virtualization.

* Fix the links to the type imports proposal.

* Fix "wowever" typo.

* Elaborate on what WASI does instead of shared filesystem views.

* Linkify "weak imports".

* Rename WASI-design-principles.md to DesignPrinciples.md

* Wrap lines to 72 columns.

* Remove a redundant "always".

* Say "interposition" instead of "virtualization".

* Add some text to clarify that shared-nothing linking will require porting.

* Reword the paragraph explaining how forgeable indices doesn't mean forgeable capabilities.

* Update docs/DesignPrinciples.md

Fix spelling of "trade-off"

Co-Authored-By: Ben B. <benne@klimlive.de>

Co-authored-by: Ben B. <benne@klimlive.de>
yoshuawuyts added a commit to yoshuawuyts/WASI that referenced this pull request Nov 25, 2025
…it-0.3.0-rc-2025-09-16-1

Revert "Update 0.3.0 WIT definitions to 0.3.0-rc-2025-09-16-1"
yoshuawuyts pushed a commit to yoshuawuyts/WASI that referenced this pull request Nov 25, 2025
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

Successfully merging this pull request may close these issues.

6 participants