Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ dependencies = [
"std_detect",
"unwind",
"vex-sdk",
"wasi 0.11.1+wasi-snapshot-preview1",
"wasi 0.14.4+wasi-0.2.4",
"wasip1",
"wasip2",
"windows-link 0.0.0",
]

Expand Down Expand Up @@ -407,20 +407,20 @@ dependencies = [
]

[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
name = "wasip1"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
checksum = "b5e26842486624357dbeb8f0381cf1fb42f022291fd787d4a816768fec8cc760"
dependencies = [
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
]

[[package]]
name = "wasi"
version = "0.14.4+wasi-0.2.4"
name = "wasip2"
version = "1.0.2+wasi-0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88a5f4a424faf49c3c2c344f166f0662341d470ea185e939657aaff130f0ec4a"
checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5"
dependencies = [
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
Expand Down Expand Up @@ -513,9 +513,9 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"

[[package]]
name = "wit-bindgen"
version = "0.45.1"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c573471f125075647d03df72e026074b7203790d41351cd6edc96f46bcccd36"
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
dependencies = [
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
Expand Down
10 changes: 5 additions & 5 deletions library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ hermit-abi = { version = "0.5.0", features = [
], public = true }

[target.'cfg(all(target_os = "wasi", target_env = "p1"))'.dependencies]
wasi = { version = "0.11.0", features = [
wasip1 = { version = "1.0.0", features = [
'rustc-dep-of-std',
], default-features = false }

[target.'cfg(all(target_os = "wasi", target_env = "p2"))'.dependencies]
wasip2 = { version = '0.14.4', features = [
wasip2 = { version = '1.0.2', features = [
'rustc-dep-of-std',
], default-features = false, package = 'wasi' }
], default-features = false }

[target.'cfg(all(target_os = "wasi", target_env = "p3"))'.dependencies]
wasip2 = { version = '0.14.4', features = [
wasip2 = { version = '1.0.2', features = [
'rustc-dep-of-std',
], default-features = false, package = 'wasi' }
], default-features = false }

[target.'cfg(target_os = "uefi")'.dependencies]
r-efi = { version = "5.2.0", features = ['rustc-dep-of-std'] }
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::ops::Index;
/// reasonable best-effort is made to generate this seed from a high quality,
/// secure source of randomness provided by the host without blocking the
/// program. Because of this, the randomness of the seed depends on the output
/// quality of the system's random number coroutine when the seed is created.
/// quality of the system's random number generator when the seed is created.
/// In particular, seeds generated when the system's entropy pool is abnormally
/// low such as during system boot may be of a lower quality.
///
Expand Down
8 changes: 4 additions & 4 deletions library/std/src/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ impl TcpStream {
/// to be retried, an error with kind [`io::ErrorKind::WouldBlock`] is
/// returned.
///
/// On Unix platforms, calling this method corresponds to calling `fcntl`
/// `FIONBIO`. On Windows calling this method corresponds to calling
/// On most Unix platforms, calling this method corresponds to calling `ioctl`
/// `FIONBIO`. On Windows, calling this method corresponds to calling
/// `ioctlsocket` `FIONBIO`.
///
/// # Examples
Expand Down Expand Up @@ -988,8 +988,8 @@ impl TcpListener {
/// IO operation could not be completed and needs to be retried, an error
/// with kind [`io::ErrorKind::WouldBlock`] is returned.
///
/// On Unix platforms, calling this method corresponds to calling `fcntl`
/// `FIONBIO`. On Windows calling this method corresponds to calling
/// On most Unix platforms, calling this method corresponds to calling `ioctl`
/// `FIONBIO`. On Windows, calling this method corresponds to calling
/// `ioctlsocket` `FIONBIO`.
///
/// # Examples
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ impl UdpSocket {
/// and needs to be retried, an error with kind
/// [`io::ErrorKind::WouldBlock`] is returned.
///
/// On Unix platforms, calling this method corresponds to calling `fcntl`
/// `FIONBIO`. On Windows calling this method corresponds to calling
/// On most Unix platforms, calling this method corresponds to calling `ioctl`
/// `FIONBIO`. On Windows, calling this method corresponds to calling
/// `ioctlsocket` `FIONBIO`.
///
/// # Examples
Expand Down
48 changes: 27 additions & 21 deletions library/std/src/os/wasi/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,26 +246,28 @@ impl FileExt for File {

#[cfg(target_env = "p1")]
fn fdstat_set_flags(&self, flags: u16) -> io::Result<()> {
unsafe { wasi::fd_fdstat_set_flags(self.as_raw_fd() as wasi::Fd, flags).map_err(err2io) }
unsafe {
wasip1::fd_fdstat_set_flags(self.as_raw_fd() as wasip1::Fd, flags).map_err(err2io)
}
}

#[cfg(target_env = "p1")]
fn fdstat_set_rights(&self, rights: u64, inheriting: u64) -> io::Result<()> {
unsafe {
wasi::fd_fdstat_set_rights(self.as_raw_fd() as wasi::Fd, rights, inheriting)
wasip1::fd_fdstat_set_rights(self.as_raw_fd() as wasip1::Fd, rights, inheriting)
.map_err(err2io)
}
}

#[cfg(target_env = "p1")]
fn advise(&self, offset: u64, len: u64, advice: u8) -> io::Result<()> {
let advice = match advice {
a if a == wasi::ADVICE_NORMAL.raw() => wasi::ADVICE_NORMAL,
a if a == wasi::ADVICE_SEQUENTIAL.raw() => wasi::ADVICE_SEQUENTIAL,
a if a == wasi::ADVICE_RANDOM.raw() => wasi::ADVICE_RANDOM,
a if a == wasi::ADVICE_WILLNEED.raw() => wasi::ADVICE_WILLNEED,
a if a == wasi::ADVICE_DONTNEED.raw() => wasi::ADVICE_DONTNEED,
a if a == wasi::ADVICE_NOREUSE.raw() => wasi::ADVICE_NOREUSE,
a if a == wasip1::ADVICE_NORMAL.raw() => wasip1::ADVICE_NORMAL,
a if a == wasip1::ADVICE_SEQUENTIAL.raw() => wasip1::ADVICE_SEQUENTIAL,
a if a == wasip1::ADVICE_RANDOM.raw() => wasip1::ADVICE_RANDOM,
a if a == wasip1::ADVICE_WILLNEED.raw() => wasip1::ADVICE_WILLNEED,
a if a == wasip1::ADVICE_DONTNEED.raw() => wasip1::ADVICE_DONTNEED,
a if a == wasip1::ADVICE_NOREUSE.raw() => wasip1::ADVICE_NOREUSE,
_ => {
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
Expand All @@ -275,31 +277,35 @@ impl FileExt for File {
};

unsafe {
wasi::fd_advise(self.as_raw_fd() as wasi::Fd, offset, len, advice).map_err(err2io)
wasip1::fd_advise(self.as_raw_fd() as wasip1::Fd, offset, len, advice).map_err(err2io)
}
}

#[cfg(target_env = "p1")]
fn allocate(&self, offset: u64, len: u64) -> io::Result<()> {
unsafe { wasi::fd_allocate(self.as_raw_fd() as wasi::Fd, offset, len).map_err(err2io) }
unsafe { wasip1::fd_allocate(self.as_raw_fd() as wasip1::Fd, offset, len).map_err(err2io) }
}

#[cfg(target_env = "p1")]
fn create_directory<P: AsRef<Path>>(&self, dir: P) -> io::Result<()> {
let path = osstr2str(dir.as_ref().as_ref())?;
unsafe { wasi::path_create_directory(self.as_raw_fd() as wasi::Fd, path).map_err(err2io) }
unsafe {
wasip1::path_create_directory(self.as_raw_fd() as wasip1::Fd, path).map_err(err2io)
}
}

#[cfg(target_env = "p1")]
fn remove_file<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
let path = osstr2str(path.as_ref().as_ref())?;
unsafe { wasi::path_unlink_file(self.as_raw_fd() as wasi::Fd, path).map_err(err2io) }
unsafe { wasip1::path_unlink_file(self.as_raw_fd() as wasip1::Fd, path).map_err(err2io) }
}

#[cfg(target_env = "p1")]
fn remove_directory<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
let path = osstr2str(path.as_ref().as_ref())?;
unsafe { wasi::path_remove_directory(self.as_raw_fd() as wasi::Fd, path).map_err(err2io) }
unsafe {
wasip1::path_remove_directory(self.as_raw_fd() as wasip1::Fd, path).map_err(err2io)
}
}
}

Expand Down Expand Up @@ -388,11 +394,11 @@ pub fn link<P: AsRef<Path>, U: AsRef<Path>>(
new_path: U,
) -> io::Result<()> {
unsafe {
wasi::path_link(
old_fd.as_raw_fd() as wasi::Fd,
wasip1::path_link(
old_fd.as_raw_fd() as wasip1::Fd,
old_flags,
osstr2str(old_path.as_ref().as_ref())?,
new_fd.as_raw_fd() as wasi::Fd,
new_fd.as_raw_fd() as wasip1::Fd,
osstr2str(new_path.as_ref().as_ref())?,
)
.map_err(err2io)
Expand All @@ -411,10 +417,10 @@ pub fn rename<P: AsRef<Path>, U: AsRef<Path>>(
new_path: U,
) -> io::Result<()> {
unsafe {
wasi::path_rename(
old_fd.as_raw_fd() as wasi::Fd,
wasip1::path_rename(
old_fd.as_raw_fd() as wasip1::Fd,
osstr2str(old_path.as_ref().as_ref())?,
new_fd.as_raw_fd() as wasi::Fd,
new_fd.as_raw_fd() as wasip1::Fd,
osstr2str(new_path.as_ref().as_ref())?,
)
.map_err(err2io)
Expand All @@ -432,9 +438,9 @@ pub fn symlink<P: AsRef<Path>, U: AsRef<Path>>(
new_path: U,
) -> io::Result<()> {
unsafe {
wasi::path_symlink(
wasip1::path_symlink(
osstr2str(old_path.as_ref().as_ref())?,
fd.as_raw_fd() as wasi::Fd,
fd.as_raw_fd() as wasip1::Fd,
osstr2str(new_path.as_ref().as_ref())?,
)
.map_err(err2io)
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/wasi/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ pub trait TcpListenerExt {

impl TcpListenerExt for net::TcpListener {
fn sock_accept(&self, flags: u16) -> io::Result<u32> {
unsafe { wasi::sock_accept(self.as_raw_fd() as wasi::Fd, flags).map_err(err2io) }
unsafe { wasip1::sock_accept(self.as_raw_fd() as wasip1::Fd, flags).map_err(err2io) }
}
}
3 changes: 3 additions & 0 deletions library/std/src/sys/alloc/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ unsafe fn allocate(layout: Layout, zeroed: bool) -> *mut u8 {
process_heap_alloc(MaybeUninit::uninit(), flags, layout.size()) as *mut u8
} else {
// Allocate extra padding in order to be able to satisfy the alignment.
// This addition does not overflow due to `Layout` type invariants,
// `size()` is at most `isize::MAX` while
// `align()` is at most `1 << (bits in usize - 2)` if `size()` is non-zero.
let total = layout.align() + layout.size();

let ptr = process_heap_alloc(MaybeUninit::uninit(), flags, total) as *mut u8;
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/args/wasip1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ pub fn args() -> Args {

fn maybe_args() -> Option<Vec<OsString>> {
unsafe {
let (argc, buf_size) = wasi::args_sizes_get().ok()?;
let (argc, buf_size) = wasip1::args_sizes_get().ok()?;
let mut argv = Vec::with_capacity(argc);
let mut buf = Vec::with_capacity(buf_size);
wasi::args_get(argv.as_mut_ptr(), buf.as_mut_ptr()).ok()?;
wasip1::args_get(argv.as_mut_ptr(), buf.as_mut_ptr()).ok()?;
argv.set_len(argc);
let mut ret = Vec::with_capacity(argc);
for ptr in argv {
Expand Down
5 changes: 5 additions & 0 deletions library/std/src/sys/fs/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,11 @@ mod uefi_fs {
path: crate::path::PathBuf,
}

// SAFETY: UEFI has no regular threads, and as per <https://github.com/rust-lang/rust/issues/133604>
// std does not support being invoked from "irregular threads" such as interrupt handlers or other
// CPU cores that run outside the scope of UEFI.
unsafe impl Send for File {}

impl File {
pub(crate) fn from_path(path: &Path, open_mode: u64, attr: u64) -> io::Result<Self> {
let absolute = crate::path::absolute(path)?;
Expand Down
28 changes: 15 additions & 13 deletions library/std/src/sys/net/connection/wasip1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ impl TcpStream {

pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
let wasi_how = match how {
Shutdown::Read => wasi::SDFLAGS_RD,
Shutdown::Write => wasi::SDFLAGS_WR,
Shutdown::Both => wasi::SDFLAGS_RD | wasi::SDFLAGS_WR,
Shutdown::Read => wasip1::SDFLAGS_RD,
Shutdown::Write => wasip1::SDFLAGS_WR,
Shutdown::Both => wasip1::SDFLAGS_RD | wasip1::SDFLAGS_WR,
};

unsafe { wasi::sock_shutdown(self.socket().as_raw_fd() as _, wasi_how).map_err(err2io) }
unsafe { wasip1::sock_shutdown(self.socket().as_raw_fd() as _, wasi_how).map_err(err2io) }
}

pub fn duplicate(&self) -> io::Result<TcpStream> {
Expand Down Expand Up @@ -167,19 +167,20 @@ impl TcpStream {

pub fn set_nonblocking(&self, state: bool) -> io::Result<()> {
let fdstat = unsafe {
wasi::fd_fdstat_get(self.socket().as_inner().as_raw_fd() as wasi::Fd).map_err(err2io)?
wasip1::fd_fdstat_get(self.socket().as_inner().as_raw_fd() as wasip1::Fd)
.map_err(err2io)?
};

let mut flags = fdstat.fs_flags;

if state {
flags |= wasi::FDFLAGS_NONBLOCK;
flags |= wasip1::FDFLAGS_NONBLOCK;
} else {
flags &= !wasi::FDFLAGS_NONBLOCK;
flags &= !wasip1::FDFLAGS_NONBLOCK;
}

unsafe {
wasi::fd_fdstat_set_flags(self.socket().as_inner().as_raw_fd() as wasi::Fd, flags)
wasip1::fd_fdstat_set_flags(self.socket().as_inner().as_raw_fd() as wasip1::Fd, flags)
.map_err(err2io)
}
}
Expand Down Expand Up @@ -221,7 +222,7 @@ impl TcpListener {

pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
let fd = unsafe {
wasi::sock_accept(self.as_inner().as_inner().as_raw_fd() as _, 0).map_err(err2io)?
wasip1::sock_accept(self.as_inner().as_inner().as_raw_fd() as _, 0).map_err(err2io)?
};

Ok((
Expand Down Expand Up @@ -258,19 +259,20 @@ impl TcpListener {

pub fn set_nonblocking(&self, state: bool) -> io::Result<()> {
let fdstat = unsafe {
wasi::fd_fdstat_get(self.socket().as_inner().as_raw_fd() as wasi::Fd).map_err(err2io)?
wasip1::fd_fdstat_get(self.socket().as_inner().as_raw_fd() as wasip1::Fd)
.map_err(err2io)?
};

let mut flags = fdstat.fs_flags;

if state {
flags |= wasi::FDFLAGS_NONBLOCK;
flags |= wasip1::FDFLAGS_NONBLOCK;
} else {
flags &= !wasi::FDFLAGS_NONBLOCK;
flags &= !wasip1::FDFLAGS_NONBLOCK;
}

unsafe {
wasi::fd_fdstat_set_flags(self.socket().as_inner().as_raw_fd() as wasi::Fd, flags)
wasip1::fd_fdstat_set_flags(self.socket().as_inner().as_raw_fd() as wasip1::Fd, flags)
.map_err(err2io)
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn abort_internal() -> ! {

#[inline]
#[cfg(target_env = "p1")]
pub(crate) fn err2io(err: wasi::Errno) -> crate::io::Error {
pub(crate) fn err2io(err: wasip1::Errno) -> crate::io::Error {
crate::io::Error::from_raw_os_error(err.raw().into())
}

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/random/wasip1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub fn fill_bytes(bytes: &mut [u8]) {
unsafe {
wasi::random_get(bytes.as_mut_ptr(), bytes.len()).expect("failed to generate random data")
wasip1::random_get(bytes.as_mut_ptr(), bytes.len()).expect("failed to generate random data")
}
}
8 changes: 3 additions & 5 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ const PERMITTED_STDLIB_DEPENDENCIES: &[&str] = &[
"shlex",
"unwinding",
"vex-sdk",
"wasi",
"wasip1",
"wasip2",
"windows-link",
"windows-sys",
"windows-targets",
Expand Down Expand Up @@ -881,10 +882,7 @@ fn check_runtime_no_duplicate_dependencies(metadata: &Metadata, check: &mut Runn
continue;
}

// Skip the `wasi` crate here which the standard library explicitly
// depends on two version of (one for the `wasm32-wasip1` target and
// another for the `wasm32-wasip2` target).
if pkg.name.to_string() != "wasi" && !seen_pkgs.insert(&*pkg.name) {
if !seen_pkgs.insert(&*pkg.name) {
check.error(format!(
"duplicate package `{}` is not allowed for the standard library",
pkg.name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/45425>
//@ check-pass
#![allow(dead_code)]
use std::ops::Add;
Expand Down
Loading
Loading