From 5af27e4617590d82572e41867aac1a1cc8e41809 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 1 Aug 2024 11:29:40 +0200 Subject: [PATCH] flock: a bit of cleanup --- src/tools/miri/src/shims/unix/fd.rs | 14 +++++++------- src/tools/miri/src/shims/unix/fs.rs | 4 ++-- .../miri/tests/pass-dep/libc/libc-fs-flock.rs | 1 - 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/tools/miri/src/shims/unix/fd.rs b/src/tools/miri/src/shims/unix/fd.rs index 464b4638c63..1b25ef05769 100644 --- a/src/tools/miri/src/shims/unix/fd.rs +++ b/src/tools/miri/src/shims/unix/fd.rs @@ -12,6 +12,13 @@ use crate::shims::unix::*; use crate::*; +#[derive(Debug, Clone, Copy, Eq, PartialEq)] +pub(crate) enum FlockOp { + SharedLock { nonblocking: bool }, + ExclusiveLock { nonblocking: bool }, + Unlock, +} + /// Represents an open file descriptor. pub trait FileDescription: std::fmt::Debug + Any { fn name(&self) -> &'static str; @@ -567,10 +574,3 @@ fn write( Ok(Scalar::from_target_isize(this.try_unwrap_io_result(result)?, this)) } } - -#[derive(Debug, Clone, Copy, Eq, PartialEq)] -pub(crate) enum FlockOp { - SharedLock { nonblocking: bool }, - ExclusiveLock { nonblocking: bool }, - Unlock, -} diff --git a/src/tools/miri/src/shims/unix/fs.rs b/src/tools/miri/src/shims/unix/fs.rs index 5606e3d85b7..ebe928018b0 100644 --- a/src/tools/miri/src/shims/unix/fs.rs +++ b/src/tools/miri/src/shims/unix/fs.rs @@ -198,8 +198,8 @@ fn flock<'tcx>( let code: u32 = err.raw_os_error().unwrap().try_into().unwrap(); if matches!(code, ERROR_IO_PENDING | ERROR_LOCK_VIOLATION) { if lock_nb { - // Replace error with a custom WouldBlock error, which later will be - // mapped in the `helpers` module + // The io error mapping does not know about these error codes, + // so we translate it to `WouldBlock` manually. let desc = format!("LockFileEx wouldblock error: {err}"); err = io::Error::new(io::ErrorKind::WouldBlock, desc); } else { diff --git a/src/tools/miri/tests/pass-dep/libc/libc-fs-flock.rs b/src/tools/miri/tests/pass-dep/libc/libc-fs-flock.rs index c1b3b8f575c..3f7f9b18be9 100644 --- a/src/tools/miri/tests/pass-dep/libc/libc-fs-flock.rs +++ b/src/tools/miri/tests/pass-dep/libc/libc-fs-flock.rs @@ -1,4 +1,3 @@ -// Flock tests are separate since they don't in general work on a Windows host. //@ignore-target-windows: File handling is not implemented yet //@compile-flags: -Zmiri-disable-isolation