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 WASI platform support #144

Merged
merged 1 commit into from
May 23, 2020
Merged

Add WASI platform support #144

merged 1 commit into from
May 23, 2020

Conversation

whitequark
Copy link
Contributor

@whitequark whitequark commented May 23, 2020

WASI is a POSIX-like platform that has a few important differences:

  • There is no concept of a mutable current directory. However, WASI host environment can provide a directory called . in the filesystem namespace that fulfills a similar role.
  • There is no concept of a file mode, and no chmod call.
  • There is no concept of a filesystem, and no statfs call.
  • There is no readdir_r call because there are no threads.

src/operations.cpp Outdated Show resolved Hide resolved
@@ -1564,7 +1566,9 @@ void create_symlink(const path& to, const path& from, error_code* ec)
BOOST_FILESYSTEM_DECL
path current_path(error_code* ec)
{
# ifdef BOOST_POSIX_API
# if defined(__wasm)
return ".";
Copy link
Member

Choose a reason for hiding this comment

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

This is not right, current_path must return an absolute path (see C++20 [fs.op.current.path]). For example, copy implementation relies on that, and probably not only that.

If the platform does not support current_path, it should fail with BOOST_ERROR_NOT_SUPPORTED (ENOSYS), but then I'm not sure how useful the rest of the library would be as it is used in implementation of quite a few operations.

Copy link
Member

Choose a reason for hiding this comment

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

As an alternative, you could assume that the current path is always the root directory. I'm not sure how valid is that in WASI (i.e. is equivalent(".", "/") == true).

Copy link
Member

Choose a reason for hiding this comment

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

Also, see if there is a way to obtain path from a file descriptor or from the result of stat on WASI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood. I'll check whether this assumption holds (the precise WASI semantics around . are not entirely clear to me) and see what can be done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, see if there is a way to obtain path from a file descriptor or from the result of stat on WASI.

That's what the fd_prestat_dir_name syscall is for.

Copy link
Member

Choose a reason for hiding this comment

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

Can you use it to obtain the full path to '.'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the platform does not support current_path, it should fail with BOOST_ERROR_NOT_SUPPORTED (ENOSYS), but then I'm not sure how useful the rest of the library would be as it is used in implementation of quite a few operations.

I've changed the code to do that. It turns out that the application I'm porting is only using boost::filesystem::path, so it's still useful for that. Failing with BOOST_ERROR_NOT_SUPPORTED seems to be a safe choice that can be always revisited later, perhaps with input from WASI folks.

Copy link
Contributor Author

@whitequark whitequark May 23, 2020

Choose a reason for hiding this comment

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

Can you use it to obtain the full path to '.'?

No. There is no concept of an "absolute path" in WASI, since it eliminates ambient authority and uses capabilities for everything; the /<something> directory, . directory, and .. directory behave effectively like separate mounts, akin to the way . and .. work on FAT, if you've seen that. There might not be any other name by which the application can access ..

WASI is really designed to use exclusively openat, and it only provides open as a shim over openat to aid in porting applications. That's why the behavior is so strange.

src/operations.cpp Outdated Show resolved Hide resolved
src/operations.cpp Outdated Show resolved Hide resolved
WASI is a POSIX-like platform that has a few important differences:
  * There is no concept of a mutable current directory.
  * There is no concept of a file mode, and no `chmod` call.
  * There is no concept of a filesystem, and no `statfs` call.
  * There is no `readdir_r` call because there are no threads.
@Lastique Lastique merged commit b6c3a70 into boostorg:develop May 23, 2020
@Lastique
Copy link
Member

Thanks.

@whitequark whitequark deleted the wasi branch May 23, 2020 14:18
@whitequark
Copy link
Contributor Author

Thanks for the quick review!

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.

None yet

4 participants