Skip to content

Commit

Permalink
Auto merge of rust-lang#2460 - LegNeato:sysconf, r=RalfJung
Browse files Browse the repository at this point in the history
Add additional raw error mappings for the nightly `io_error_more` feature

Some crates are using nightly and failing when mapping these errors,
for example <https://miri.saethlin.dev/?crate=remove_dir_all&version=0.7.0>:

```
error: unsupported operation: io error NotADirectory cannot be translated into a raw os error
    --> /root/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/sys/unix/fs.rs:1203:19
```
  • Loading branch information
bors committed Aug 3, 2022
2 parents 730a799 + e1e1f42 commit 1a87926
Showing 1 changed file with 45 additions and 20 deletions.
65 changes: 45 additions & 20 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,51 @@ use crate::*;

impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}

const UNIX_IO_ERROR_TABLE: &[(std::io::ErrorKind, &str)] = {
// This mapping should match `decode_error_kind` in
// <https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/mod.rs>.
const UNIX_IO_ERROR_TABLE: &[(&str, std::io::ErrorKind)] = {
use std::io::ErrorKind::*;
&[
(ConnectionRefused, "ECONNREFUSED"),
(ConnectionReset, "ECONNRESET"),
(PermissionDenied, "EPERM"),
(BrokenPipe, "EPIPE"),
(NotConnected, "ENOTCONN"),
(ConnectionAborted, "ECONNABORTED"),
(AddrNotAvailable, "EADDRNOTAVAIL"),
(AddrInUse, "EADDRINUSE"),
(NotFound, "ENOENT"),
(Interrupted, "EINTR"),
(InvalidInput, "EINVAL"),
(InvalidFilename, "ENAMETOOLONG"),
(TimedOut, "ETIMEDOUT"),
(AlreadyExists, "EEXIST"),
(WouldBlock, "EWOULDBLOCK"),
(DirectoryNotEmpty, "ENOTEMPTY"),
(FilesystemLoop, "ELOOP"),
("E2BIG", ArgumentListTooLong),
("EADDRINUSE", AddrInUse),
("EADDRNOTAVAIL", AddrNotAvailable),
("EBUSY", ResourceBusy),
("ECONNABORTED", ConnectionAborted),
("ECONNREFUSED", ConnectionRefused),
("ECONNRESET", ConnectionReset),
("EDEADLK", Deadlock),
("EDQUOT", FilesystemQuotaExceeded),
("EEXIST", AlreadyExists),
("EFBIG", FileTooLarge),
("EHOSTUNREACH", HostUnreachable),
("EINTR", Interrupted),
("EINVAL", InvalidInput),
("EISDIR", IsADirectory),
("ELOOP", FilesystemLoop),
("ENOENT", NotFound),
("ENOMEM", OutOfMemory),
("ENOSPC", StorageFull),
("ENOSYS", Unsupported),
("EMLINK", TooManyLinks),
("ENAMETOOLONG", InvalidFilename),
("ENETDOWN", NetworkDown),
("ENETUNREACH", NetworkUnreachable),
("ENOTCONN", NotConnected),
("ENOTDIR", NotADirectory),
("ENOTEMPTY", DirectoryNotEmpty),
("EPIPE", BrokenPipe),
("EROFS", ReadOnlyFilesystem),
("ESPIPE", NotSeekable),
("ESTALE", StaleNetworkFileHandle),
("ETIMEDOUT", TimedOut),
("ETXTBSY", ExecutableFileBusy),
("EXDEV", CrossesDevices),
// The following have two valid options. We have both for the forwards mapping; only the
// first one will be used for the backwards mapping.
("EPERM", PermissionDenied),
("EACCES", PermissionDenied),
("EWOULDBLOCK", WouldBlock),
("EAGAIN", WouldBlock),
]
};

Expand Down Expand Up @@ -554,7 +579,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let this = self.eval_context_ref();
let target = &this.tcx.sess.target;
if target.families.iter().any(|f| f == "unix") {
for &(kind, name) in UNIX_IO_ERROR_TABLE {
for &(name, kind) in UNIX_IO_ERROR_TABLE {
if err_kind == kind {
return this.eval_libc(name);
}
Expand Down Expand Up @@ -592,7 +617,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let target = &this.tcx.sess.target;
if target.families.iter().any(|f| f == "unix") {
let errnum = errnum.to_i32()?;
for &(kind, name) in UNIX_IO_ERROR_TABLE {
for &(name, kind) in UNIX_IO_ERROR_TABLE {
if errnum == this.eval_libc_i32(name)? {
return Ok(kind);
}
Expand Down

0 comments on commit 1a87926

Please sign in to comment.