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

Add beginnings of a Resources and Handles design document. #319

Closed

Conversation

monoclex
Copy link

@monoclex monoclex commented Sep 6, 2020

File Descriptors seem like they will be a very ubiquitous concept in WASI, thus guiding users to understand them would be extremely helpful. As the implementation is still not fully fleshed out and very much a draft, this document is to remain very incomplete but ideally would have examples and links to other documents so developers can figure out how to use these APIs. This is to resolve another part of #316

@monoclex monoclex changed the title Add initial File Descriptors document. Add beginnings of a File Descriptors design document. Sep 6, 2020
design/file-descriptors.md Outdated Show resolved Hide resolved
design/file-descriptors.md Outdated Show resolved Hide resolved
```

# Files
Files can be opened and closed with the method [`path_open`](https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs.md#-path_openfd-fd-dirflags-lookupflags-path-string-oflags-oflags-fs_rights_base-rights-fs_rights_inherting-rights-fdflags-fdflags---errno-fd), and simply drop the returned `fd` to close it. These commands will fail if the WASM environment did not give the program permission to execute these.
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be too specific for a design document as it refers to a specific snapshot and will easily get out of sync.

Copy link
Author

Choose a reason for hiding this comment

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

Would modifying the URL to a less precise URL fix this? If not, does the document have a better fit elsewhere?

Copy link
Member

Choose a reason for hiding this comment

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

How about documenting them in the witx files, which are the sources from which the docs.md files are generated?

Copy link
Author

Choose a reason for hiding this comment

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

Where are the witx files? Sorry if this is obvious and I'm just missing it.

Copy link
Member

Choose a reason for hiding this comment

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

Currently they live here: https://github.com/WebAssembly/WASI/tree/master/phases/ephemeral/witx

We'll likely be reorganizing things as WASI modularization moves forward, but this is where they are for now.

Copy link
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

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

I apologize for being slow here! This is a great topic to start documenting, as I agree, file descriptors are one of the most important concepts we have. This document looks like a good start -- I expect a lot of things will evolve over time, but it's useful to start somewhere! -- I just have a few review comments below:

design/file-descriptors.md Outdated Show resolved Hide resolved
design/file-descriptors.md Outdated Show resolved Hide resolved
design/file-descriptors.md Outdated Show resolved Hide resolved
@sunfishcode
Copy link
Member

This looks like it's in good shape. I see it's still marked as a "Draft"; is there more to be done here?

@monoclex
Copy link
Author

monoclex commented Oct 15, 2020

Ah yeah, I was going to move the documentation for specific code related to files to the WITX documentation, then link to it in the Files header. Haven't gotten around to that yet, my bad - I'll try get it done relatively soon.

Base automatically changed from master to main January 19, 2021 23:08
@monoclex monoclex force-pushed the file-descriptors-information branch from 8878a93 to 7a71315 Compare May 11, 2021 05:58
@monoclex
Copy link
Author

Apologies for it having been a while since I've worked on this (so much for "relatively soon", eh?). I recall last stating that I needed to do this,

Ah yeah, I was going to move the documentation for specific code related to files to the WITX documentation, then link to it in the Files header. Haven't gotten around to that yet, my bad - I'll try get it done relatively soon.

but can't quite seem to remember what that would entail (I'm unsure what I would link to in the Files section, where in the witx folder I would link to that section, and what code I would move over). Moreover, I assume there might be significant changes since I've last worked on this, so perhaps it'd be best to get another look at it.

@programmerjake

This comment has been minimized.

@sunfishcode
Copy link
Member

Thanks for picking this up again! Since this PR was started, a few developments have changed the landscape somewhat:

A major development since this PR was started has been the development of handles as an explicit feature of the interface-types proposal. The canonical ABI PR includes an ABI which can represent handles as i32 indices within modules, and includes resource lifetimes and closing handles. I expect we'll want to rebase WASI's concept of file descriptors on this new handle mechanism. That will let WASI focus on API functionality, and leave low-level resource management to lower levels of the stack that all APIs can use.

And, WASI is moving toward modularization. path_open is now defined in the wasi-filesystem proposal. I think that's the best place for documenting how to open and close files now.

Stdout, stdin, stderr are interesting. These won't be needed in all use cases, so I expect WASI will move toward a model where those will be defined by libc and tooling rather than by WASI itself. That said, we'll likely need to continue to support "commands" in their current form, which expect 0, 1, and 2 to be prepopulated. This isn't all figured out yet, but I'm starting to think of wasi-classic-command as the place where we'll collect documentation for how these kinds of commands work.

Does that make sense?

@monoclex
Copy link
Author

Thanks for the information! I read more into what you mentioned, by reading the Handle and Resources presentation, the Scoping and Layering presentation, and through the canonical ABI proposal that was linked.

I decided to make this PR more geared towards resources and handles, as that seems like the replacement for file descriptors, and tried to write documentation for them based on my current understanding. I ended up dropping the mention to the console, but I should probably put that back in there if the commands proposal makes use of resources and handles.

@monoclex monoclex changed the title Add beginnings of a File Descriptors design document. Add beginnings of a Resources and Handles design document. May 13, 2021
@sunfishcode
Copy link
Member

As another update here, interface types has now evolved into a component model, which is now defining the concepts of handles, resources, and commands. Going forward, the component model will be the best place for documentation about what handles and resources are and how they work, with the WASI repo here focusing more on just the APIs that are built on top of them.

@sunfishcode
Copy link
Member

As I mentioned above, resources and handles are now defined by the component model.

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.

5 participants