Update WASI to cap-std 0.25 and windows-sys. (#4302)

This updates to rustix 0.35.6, and updates wasi-common to use cap-std 0.25 and
windows-sys (instead of winapi).

Changes include:

 - Better error code mappings on Windows.
 - Fixes undefined references to `utimensat` on Darwin.
 - Fixes undefined references to `preadv64` and `pwritev64` on Android.
 - Updates to io-lifetimes 0.7, which matches the io_safety API in Rust.
 - y2038 bug fixes for 32-bit platforms
This commit is contained in:
Dan Gohman
2022-06-23 10:47:15 -07:00
committed by GitHub
parent 445cc87a06
commit fa36e86f2c
27 changed files with 317 additions and 186 deletions

View File

@@ -112,67 +112,144 @@ impl TryFrom<std::io::Error> for types::Errno {
fn try_from(err: std::io::Error) -> Result<types::Errno, Error> {
#[cfg(unix)]
fn raw_error_code(err: &std::io::Error) -> Option<types::Errno> {
use rustix::io::Error;
match Error::from_io_error(err) {
Some(Error::AGAIN) => Some(types::Errno::Again),
Some(Error::PIPE) => Some(types::Errno::Pipe),
Some(Error::PERM) => Some(types::Errno::Perm),
Some(Error::NOENT) => Some(types::Errno::Noent),
Some(Error::NOMEM) => Some(types::Errno::Nomem),
Some(Error::TOOBIG) => Some(types::Errno::TooBig),
Some(Error::IO) => Some(types::Errno::Io),
Some(Error::BADF) => Some(types::Errno::Badf),
Some(Error::BUSY) => Some(types::Errno::Busy),
Some(Error::ACCESS) => Some(types::Errno::Acces),
Some(Error::FAULT) => Some(types::Errno::Fault),
Some(Error::NOTDIR) => Some(types::Errno::Notdir),
Some(Error::ISDIR) => Some(types::Errno::Isdir),
Some(Error::INVAL) => Some(types::Errno::Inval),
Some(Error::EXIST) => Some(types::Errno::Exist),
Some(Error::FBIG) => Some(types::Errno::Fbig),
Some(Error::NOSPC) => Some(types::Errno::Nospc),
Some(Error::SPIPE) => Some(types::Errno::Spipe),
Some(Error::MFILE) => Some(types::Errno::Mfile),
Some(Error::MLINK) => Some(types::Errno::Mlink),
Some(Error::NAMETOOLONG) => Some(types::Errno::Nametoolong),
Some(Error::NFILE) => Some(types::Errno::Nfile),
Some(Error::NOTEMPTY) => Some(types::Errno::Notempty),
Some(Error::LOOP) => Some(types::Errno::Loop),
Some(Error::OVERFLOW) => Some(types::Errno::Overflow),
Some(Error::ILSEQ) => Some(types::Errno::Ilseq),
Some(Error::NOTSUP) => Some(types::Errno::Notsup),
use rustix::io::Errno;
match Errno::from_io_error(err) {
Some(Errno::AGAIN) => Some(types::Errno::Again),
Some(Errno::PIPE) => Some(types::Errno::Pipe),
Some(Errno::PERM) => Some(types::Errno::Perm),
Some(Errno::NOENT) => Some(types::Errno::Noent),
Some(Errno::NOMEM) => Some(types::Errno::Nomem),
Some(Errno::TOOBIG) => Some(types::Errno::TooBig),
Some(Errno::IO) => Some(types::Errno::Io),
Some(Errno::BADF) => Some(types::Errno::Badf),
Some(Errno::BUSY) => Some(types::Errno::Busy),
Some(Errno::ACCESS) => Some(types::Errno::Acces),
Some(Errno::FAULT) => Some(types::Errno::Fault),
Some(Errno::NOTDIR) => Some(types::Errno::Notdir),
Some(Errno::ISDIR) => Some(types::Errno::Isdir),
Some(Errno::INVAL) => Some(types::Errno::Inval),
Some(Errno::EXIST) => Some(types::Errno::Exist),
Some(Errno::FBIG) => Some(types::Errno::Fbig),
Some(Errno::NOSPC) => Some(types::Errno::Nospc),
Some(Errno::SPIPE) => Some(types::Errno::Spipe),
Some(Errno::MFILE) => Some(types::Errno::Mfile),
Some(Errno::MLINK) => Some(types::Errno::Mlink),
Some(Errno::NAMETOOLONG) => Some(types::Errno::Nametoolong),
Some(Errno::NFILE) => Some(types::Errno::Nfile),
Some(Errno::NOTEMPTY) => Some(types::Errno::Notempty),
Some(Errno::LOOP) => Some(types::Errno::Loop),
Some(Errno::OVERFLOW) => Some(types::Errno::Overflow),
Some(Errno::ILSEQ) => Some(types::Errno::Ilseq),
Some(Errno::NOTSUP) => Some(types::Errno::Notsup),
Some(Errno::ADDRINUSE) => Some(types::Errno::Addrinuse),
Some(Errno::CANCELED) => Some(types::Errno::Canceled),
Some(Errno::ADDRNOTAVAIL) => Some(types::Errno::Addrnotavail),
Some(Errno::AFNOSUPPORT) => Some(types::Errno::Afnosupport),
Some(Errno::ALREADY) => Some(types::Errno::Already),
Some(Errno::CONNABORTED) => Some(types::Errno::Connaborted),
Some(Errno::CONNREFUSED) => Some(types::Errno::Connrefused),
Some(Errno::CONNRESET) => Some(types::Errno::Connreset),
Some(Errno::DESTADDRREQ) => Some(types::Errno::Destaddrreq),
Some(Errno::DQUOT) => Some(types::Errno::Dquot),
Some(Errno::HOSTUNREACH) => Some(types::Errno::Hostunreach),
Some(Errno::INPROGRESS) => Some(types::Errno::Inprogress),
Some(Errno::INTR) => Some(types::Errno::Intr),
Some(Errno::ISCONN) => Some(types::Errno::Isconn),
Some(Errno::MSGSIZE) => Some(types::Errno::Msgsize),
Some(Errno::NETDOWN) => Some(types::Errno::Netdown),
Some(Errno::NETRESET) => Some(types::Errno::Netreset),
Some(Errno::NETUNREACH) => Some(types::Errno::Netunreach),
Some(Errno::NOBUFS) => Some(types::Errno::Nobufs),
Some(Errno::NOPROTOOPT) => Some(types::Errno::Noprotoopt),
Some(Errno::NOTCONN) => Some(types::Errno::Notconn),
Some(Errno::NOTSOCK) => Some(types::Errno::Notsock),
Some(Errno::PROTONOSUPPORT) => Some(types::Errno::Protonosupport),
Some(Errno::PROTOTYPE) => Some(types::Errno::Prototype),
Some(Errno::STALE) => Some(types::Errno::Stale),
Some(Errno::TIMEDOUT) => Some(types::Errno::Timedout),
// On some platforms, these have the same value as other errno values.
#[allow(unreachable_patterns)]
Some(Errno::WOULDBLOCK) => Some(types::Errno::Again),
#[allow(unreachable_patterns)]
Some(Errno::OPNOTSUPP) => Some(types::Errno::Notsup),
_ => None,
}
}
#[cfg(windows)]
fn raw_error_code(err: &std::io::Error) -> Option<types::Errno> {
use winapi::shared::winerror;
use windows_sys::Win32::Foundation;
use windows_sys::Win32::Networking::WinSock;
match err.raw_os_error().map(|code| code as u32) {
Some(winerror::WSAEWOULDBLOCK) => Some(types::Errno::Again),
Some(winerror::ERROR_BAD_ENVIRONMENT) => Some(types::Errno::TooBig),
Some(winerror::ERROR_FILE_NOT_FOUND) => Some(types::Errno::Noent),
Some(winerror::ERROR_PATH_NOT_FOUND) => Some(types::Errno::Noent),
Some(winerror::ERROR_TOO_MANY_OPEN_FILES) => Some(types::Errno::Nfile),
Some(winerror::ERROR_ACCESS_DENIED) => Some(types::Errno::Acces),
Some(winerror::ERROR_SHARING_VIOLATION) => Some(types::Errno::Acces),
Some(winerror::ERROR_PRIVILEGE_NOT_HELD) => Some(types::Errno::Perm),
Some(winerror::ERROR_INVALID_HANDLE) => Some(types::Errno::Badf),
Some(winerror::ERROR_INVALID_NAME) => Some(types::Errno::Noent),
Some(winerror::ERROR_NOT_ENOUGH_MEMORY) => Some(types::Errno::Nomem),
Some(winerror::ERROR_OUTOFMEMORY) => Some(types::Errno::Nomem),
Some(winerror::ERROR_DIR_NOT_EMPTY) => Some(types::Errno::Notempty),
Some(winerror::ERROR_NOT_READY) => Some(types::Errno::Busy),
Some(winerror::ERROR_BUSY) => Some(types::Errno::Busy),
Some(winerror::ERROR_NOT_SUPPORTED) => Some(types::Errno::Notsup),
Some(winerror::ERROR_FILE_EXISTS) => Some(types::Errno::Exist),
Some(winerror::ERROR_BROKEN_PIPE) => Some(types::Errno::Pipe),
Some(winerror::ERROR_BUFFER_OVERFLOW) => Some(types::Errno::Nametoolong),
Some(winerror::ERROR_NOT_A_REPARSE_POINT) => Some(types::Errno::Inval),
Some(winerror::ERROR_NEGATIVE_SEEK) => Some(types::Errno::Inval),
Some(winerror::ERROR_DIRECTORY) => Some(types::Errno::Notdir),
Some(winerror::ERROR_ALREADY_EXISTS) => Some(types::Errno::Exist),
Some(winerror::ERROR_STOPPED_ON_SYMLINK) => Some(types::Errno::Loop),
Some(winerror::ERROR_DIRECTORY_NOT_SUPPORTED) => Some(types::Errno::Isdir),
Some(Foundation::ERROR_BAD_ENVIRONMENT) => return Some(types::Errno::TooBig),
Some(Foundation::ERROR_FILE_NOT_FOUND) => return Some(types::Errno::Noent),
Some(Foundation::ERROR_PATH_NOT_FOUND) => return Some(types::Errno::Noent),
Some(Foundation::ERROR_TOO_MANY_OPEN_FILES) => return Some(types::Errno::Nfile),
Some(Foundation::ERROR_ACCESS_DENIED) => return Some(types::Errno::Acces),
Some(Foundation::ERROR_SHARING_VIOLATION) => return Some(types::Errno::Acces),
Some(Foundation::ERROR_PRIVILEGE_NOT_HELD) => return Some(types::Errno::Perm),
Some(Foundation::ERROR_INVALID_HANDLE) => return Some(types::Errno::Badf),
Some(Foundation::ERROR_INVALID_NAME) => return Some(types::Errno::Noent),
Some(Foundation::ERROR_NOT_ENOUGH_MEMORY) => return Some(types::Errno::Nomem),
Some(Foundation::ERROR_OUTOFMEMORY) => return Some(types::Errno::Nomem),
Some(Foundation::ERROR_DIR_NOT_EMPTY) => return Some(types::Errno::Notempty),
Some(Foundation::ERROR_NOT_READY) => return Some(types::Errno::Busy),
Some(Foundation::ERROR_BUSY) => return Some(types::Errno::Busy),
Some(Foundation::ERROR_NOT_SUPPORTED) => return Some(types::Errno::Notsup),
Some(Foundation::ERROR_FILE_EXISTS) => return Some(types::Errno::Exist),
Some(Foundation::ERROR_BROKEN_PIPE) => return Some(types::Errno::Pipe),
Some(Foundation::ERROR_BUFFER_OVERFLOW) => return Some(types::Errno::Nametoolong),
Some(Foundation::ERROR_NOT_A_REPARSE_POINT) => return Some(types::Errno::Inval),
Some(Foundation::ERROR_NEGATIVE_SEEK) => return Some(types::Errno::Inval),
Some(Foundation::ERROR_DIRECTORY) => return Some(types::Errno::Notdir),
Some(Foundation::ERROR_ALREADY_EXISTS) => return Some(types::Errno::Exist),
Some(Foundation::ERROR_STOPPED_ON_SYMLINK) => return Some(types::Errno::Loop),
Some(Foundation::ERROR_DIRECTORY_NOT_SUPPORTED) => {
return Some(types::Errno::Isdir)
}
_ => {}
}
match err.raw_os_error() {
Some(WinSock::WSAEWOULDBLOCK) => Some(types::Errno::Again),
Some(WinSock::WSAECANCELLED) => Some(types::Errno::Canceled),
Some(WinSock::WSA_E_CANCELLED) => Some(types::Errno::Canceled),
Some(WinSock::WSAEBADF) => Some(types::Errno::Badf),
Some(WinSock::WSAEFAULT) => Some(types::Errno::Fault),
Some(WinSock::WSAEINVAL) => Some(types::Errno::Inval),
Some(WinSock::WSAEMFILE) => Some(types::Errno::Mfile),
Some(WinSock::WSAENAMETOOLONG) => Some(types::Errno::Nametoolong),
Some(WinSock::WSAENOTEMPTY) => Some(types::Errno::Notempty),
Some(WinSock::WSAELOOP) => Some(types::Errno::Loop),
Some(WinSock::WSAEOPNOTSUPP) => Some(types::Errno::Notsup),
Some(WinSock::WSAEADDRINUSE) => Some(types::Errno::Addrinuse),
Some(WinSock::WSAEACCES) => Some(types::Errno::Acces),
Some(WinSock::WSAEADDRNOTAVAIL) => Some(types::Errno::Addrnotavail),
Some(WinSock::WSAEAFNOSUPPORT) => Some(types::Errno::Afnosupport),
Some(WinSock::WSAEALREADY) => Some(types::Errno::Already),
Some(WinSock::WSAECONNABORTED) => Some(types::Errno::Connaborted),
Some(WinSock::WSAECONNREFUSED) => Some(types::Errno::Connrefused),
Some(WinSock::WSAECONNRESET) => Some(types::Errno::Connreset),
Some(WinSock::WSAEDESTADDRREQ) => Some(types::Errno::Destaddrreq),
Some(WinSock::WSAEDQUOT) => Some(types::Errno::Dquot),
Some(WinSock::WSAEHOSTUNREACH) => Some(types::Errno::Hostunreach),
Some(WinSock::WSAEINPROGRESS) => Some(types::Errno::Inprogress),
Some(WinSock::WSAEINTR) => Some(types::Errno::Intr),
Some(WinSock::WSAEISCONN) => Some(types::Errno::Isconn),
Some(WinSock::WSAEMSGSIZE) => Some(types::Errno::Msgsize),
Some(WinSock::WSAENETDOWN) => Some(types::Errno::Netdown),
Some(WinSock::WSAENETRESET) => Some(types::Errno::Netreset),
Some(WinSock::WSAENETUNREACH) => Some(types::Errno::Netunreach),
Some(WinSock::WSAENOBUFS) => Some(types::Errno::Nobufs),
Some(WinSock::WSAENOPROTOOPT) => Some(types::Errno::Noprotoopt),
Some(WinSock::WSAENOTCONN) => Some(types::Errno::Notconn),
Some(WinSock::WSAENOTSOCK) => Some(types::Errno::Notsock),
Some(WinSock::WSAEPROTONOSUPPORT) => Some(types::Errno::Protonosupport),
Some(WinSock::WSAEPROTOTYPE) => Some(types::Errno::Prototype),
Some(WinSock::WSAESTALE) => Some(types::Errno::Stale),
Some(WinSock::WSAETIMEDOUT) => Some(types::Errno::Timedout),
_ => None,
}
}