-
Notifications
You must be signed in to change notification settings - Fork 240
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
add virtualization doc #69
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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. | ||||||
|
||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
## 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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
## Virtualization with GC | ||||||
|
||||||
The one possibility would be to use an object oriented approach. This is relies on the [function references](https://github.com/WebAssembly/function-references/blob/master/proposals/function-references/Overview.md) and [GC](https://github.com/WebAssembly/gc/blob/master/proposals/gc/Overview.md) proposals. | ||||||
|
||||||
We might have the following type definition for a `fd` and its related functions. | ||||||
``` | ||||||
(type $open_func (func (param i32) (param i32) ... )) | ||||||
(type $close_func) | ||||||
... | ||||||
|
||||||
(type $fd (struct | ||||||
(field $open (ref $open_func)) | ||||||
(field $close (ref $close_func)) | ||||||
)) | ||||||
|
||||||
``` | ||||||
|
||||||
`func.bind` from function references proposals would be used by the programs implementing the interface to create proxy functions. | ||||||
|
||||||
``` | ||||||
(func $fd-open-proxy (param $_fd (ref $fd)) (param i32) (param i32) ... ) | ||||||
(local $open_ref (ref $open_func)) | ||||||
... | ||||||
(call_ref | ||||||
... ;; other params | ||||||
(get_field $open_func $open (get_local $_fd) | ||||||
) | ||||||
|
||||||
) | ||||||
|
||||||
(func mk-fd-open-proxy (param (ref $fd) (result (ref $open_func))) | ||||||
(func.bind $open_func (local.get 0) (func.ref $fd-open-proxy)) | ||||||
) | ||||||
``` | ||||||
|
||||||
In this scenario no functions are imported, only types. While this is one possible future we don't currently have this functionality. While it maybe be possible to polyfill things like `func.bind` using tables, other things such as full GC would more complicated and may create overhead. | ||||||
|
||||||
### 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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
``` | ||||||
struct.create(fields: u32) -> anyRef | ||||||
``` | ||||||
|
||||||
``` | ||||||
struct.set(index: i32, func: funcRef) | ||||||
``` | ||||||
|
||||||
``` | ||||||
struct.get(stuct_ref: anyRef, index: u32) -> funcRef | ||||||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.