diff --git a/src/helpers.rs b/src/helpers.rs index acc2367afa2..8523af84d06 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -23,26 +23,51 @@ 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 +// . +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), ] }; @@ -554,7 +579,7 @@ fn io_error_to_errnum( 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); } @@ -592,7 +617,7 @@ fn errnum_to_io_error( 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); }