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

Update to wasi 0.11 #253

Merged
merged 3 commits into from
Apr 15, 2022
Merged

Update to wasi 0.11 #253

merged 3 commits into from
Apr 15, 2022

Conversation

Thomasdezeeuw
Copy link
Contributor

The main breaking change between v0.10 and v0.11 is that Error is
removed in favour of Errno. Unfortunately we can't create an Errno from
outside the wasi create so we're loosing some debug information for
errors.

I've opened an issue to add back such a constructor, see
bytecodealliance/wasi-rs#64.

@newpavlov
Copy link
Member

Personally, I would prefer for wasi developers to fix the Error issue first before moving from v0.10.

@josephlr
Copy link
Member

While I'd also prefer the wasi types to have the error information, it looks like wasi's libc provides strerror_r which contains the errno information. So we might be able to get the debug info just from the call to libc, and handle things on wasi like we do on unix.

This also seems to be what the standard library does.

Cargo.toml Outdated Show resolved Hide resolved
src/error.rs Outdated Show resolved Hide resolved
The main breaking change between v0.10 and v0.11 is that Error is
removed in favour of Errno. Unfortunately we can't create an Errno from
outside the wasi create so we're loosing some debug information for
errors.

I've opened an issue to add back such a constructor, see
<bytecodealliance/wasi-rs#64>.
Since wasi v0.11 doesn't (yet) provided a way to create Errno, see
<bytecodealliance/wasi-rs#64>.
@Thomasdezeeuw
Copy link
Contributor Author

I've changed over to use libc::stderrorand needed to force push to resolve the merge conflict.

@@ -9,15 +9,11 @@
//! Implementation for WASI
use crate::Error;
use core::num::NonZeroU32;
use wasi::random_get;
use wasi::wasi_snapshot_preview1::random_get;
Copy link
Member

Choose a reason for hiding this comment

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

Why not just use wasi::random_get?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the new Errno from wasi, which replaced Error, can actually hold 0. Errno::as_raw returns u16, which may be zero, thus invalidating the previous code calling NonZeroU32::new_unchecked. However handling zero ourselves ensures we can call NonZeroU32::new_unchecked again.

Copy link
Member

Choose a reason for hiding this comment

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

But it won't actually be zero if the function returns Err, so it seems fine.

Copy link
Member

@newpavlov newpavlov Mar 26, 2022

Choose a reason for hiding this comment

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

It would mean that soundness of our code relies on an implementation detail of wasi. I am not sure we can rely on it, even though it's a very reasonable assumption.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would mean that soundness of our code relies on an implementation detail of wasi. I am not sure we can rely on it, even though it's a very reasonable assumption.

This is the exact reason I decided to switch.

@newpavlov
Copy link
Member

Adding libc simply for error messages is not great... Especially considering that random_get errors are extremely unlikely and there are no random_get-specific error codes.

@josephlr
Copy link
Member

Adding libc simply for error messages is not great... Especially considering that random_get errors are extremely unlikely and there are no random_get-specific error codes.

So do you think we should just not have error messages for wasi errors then? I would be fine with that.

@newpavlov
Copy link
Member

Yes, before the wasi crate improves handling of errors, I think it's fine to simply do not have any error messages for WASI.

@Thomasdezeeuw
Copy link
Contributor Author

So I should drop the libc dependency and remove the error message?

@josephlr
Copy link
Member

josephlr commented Mar 29, 2022

That sounds great!

This does mean that we won't get an error message for the error type.
@Thomasdezeeuw
Copy link
Contributor Author

@josephlr done.

@Thomasdezeeuw
Copy link
Contributor Author

Any update on this?

@josephlr josephlr merged commit 2d65a40 into rust-random:master Apr 15, 2022
@Thomasdezeeuw Thomasdezeeuw deleted the wasi-v0.11 branch April 15, 2022 15:30
josephlr added a commit that referenced this pull request Oct 23, 2022
This change ensures that we only compile our WASI implementation for
32-bit targets. The interaction between the WASI proposal and the
memory64 proposal is not yet clear, [wasmtime does not yet support](
bytecodealliance/wasmtime#3594 (comment))
using WASI with memory64, and many of the interfaces use 32-bit values
for pointers.

This change also reduces the use of `unsafe` from the wasi
implementation. As noted in #253, changes to `Errno` mean that we can't
get the error message from the raw error code, but we can avoid using
unsafe when converting this code to a NonZeroU32. This handling also
makes WASI behave more like our other targets, which also manually check
that errno is non-zero.

Signed-off-by: Joe Richey <joerichey@google.com>
josephlr added a commit that referenced this pull request Oct 23, 2022
* Cleanup wasm32-wasi target

This change ensures that we only compile our WASI implementation for
32-bit targets. The interaction between the WASI proposal and the
memory64 proposal is not yet clear, [wasmtime does not yet support](
bytecodealliance/wasmtime#3594 (comment))
using WASI with memory64, and many of the interfaces use 32-bit values
for pointers.

This change also reduces the use of `unsafe` from the wasi
implementation. As noted in #253, changes to `Errno` mean that we can't
get the error message from the raw error code, but we can avoid using
unsafe when converting this code to a NonZeroU32. This handling also
makes WASI behave more like our other targets, which also manually check
that errno is non-zero.

Signed-off-by: Joe Richey <joerichey@google.com>

* Disable default features for WASI crate

Similar to this crate, the `wasi` crate just uses a `std` feature to
implement `std::error::Errno`, which we don't use.

Signed-off-by: Joe Richey <joerichey@google.com>

Signed-off-by: Joe Richey <joerichey@google.com>
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.

3 participants