Skip to content

Commit

Permalink
move reject with isolation for fcntl under F_FULLFSYNC
Browse files Browse the repository at this point in the history
  • Loading branch information
DebugSteven committed Mar 20, 2023
1 parent 8a36889 commit 0e2e617
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/tools/miri/src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,13 +628,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let fd = this.read_scalar(&args[0])?.to_i32()?;
let cmd = this.read_scalar(&args[1])?.to_i32()?;

// Reject if isolation is enabled.
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
this.reject_in_isolation("`fcntl`", reject_with)?;
this.set_last_error_from_io_error(ErrorKind::PermissionDenied)?;
return Ok(-1);
}

// We only support getting the flags for a descriptor.
if cmd == this.eval_libc_i32("F_GETFD") {
// Currently this is the only flag that `F_GETFD` returns. It is OK to just return the
Expand Down Expand Up @@ -677,6 +670,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
None => this.handle_not_found(),
}
} else if this.tcx.sess.target.os == "macos" && cmd == this.eval_libc_i32("F_FULLFSYNC") {
// Reject if isolation is enabled.
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
this.reject_in_isolation("`fcntl`", reject_with)?;
this.set_last_error_from_io_error(ErrorKind::PermissionDenied)?;
return Ok(-1);
}

if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) {
// FIXME: Support fullfsync for all FDs
let FileHandle { file, writable } =
Expand Down
12 changes: 12 additions & 0 deletions src/tools/miri/tests/pass-dep/shims/fcntl_f-fullfsync_apple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@only-target-apple: F_FULLFSYNC only on apple systems
//@compile-flags: -Zmiri-isolation-error=warn-nobacktrace

use std::io::Error;

fn main() {
// test `fcntl(F_FULLFSYNC)`
unsafe {
assert_eq!(libc::fcntl(1, libc::F_FULLFSYNC, 0), -1);
assert_eq!(Error::last_os_error().raw_os_error(), Some(libc::EPERM));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
warning: `fcntl` was made to return an error due to isolation

5 changes: 2 additions & 3 deletions src/tools/miri/tests/pass-dep/shims/libc-fs-with-isolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ use std::fs;
use std::io::{Error, ErrorKind};

fn main() {
// test `fcntl`
// test `fcntl(F_DUPFD): should work even with isolation.`
unsafe {
assert_eq!(libc::fcntl(1, libc::F_DUPFD, 0), -1);
assert_eq!(Error::last_os_error().raw_os_error(), Some(libc::EPERM));
assert!(libc::fcntl(1, libc::F_DUPFD, 0) >= 0);
}

// test `readlink`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
warning: `fcntl` was made to return an error due to isolation

warning: `readlink` was made to return an error due to isolation

warning: `$STAT` was made to return an error due to isolation
Expand Down
6 changes: 2 additions & 4 deletions src/tools/miri/tests/pass-dep/tokio/sleep.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@compile-flags: -Zmiri-disable-isolation -Zmiri-permissive-provenance -Zmiri-backtrace=full
//@compile-flags: -Zmiri-permissive-provenance -Zmiri-backtrace=full
//@only-target-x86_64-unknown-linux: support for tokio only on linux and x86

use tokio::time::{sleep, Duration, Instant};
Expand All @@ -7,8 +7,6 @@ use tokio::time::{sleep, Duration, Instant};
async fn main() {
let start = Instant::now();
sleep(Duration::from_secs(1)).await;
// It takes 96 millisecond to sleep for 1 millisecond
// It takes 1025 millisecond to sleep for 1 second
let time_elapsed = &start.elapsed().as_millis();
assert!(time_elapsed > &1000, "{}", time_elapsed);
assert!((1000..1100).contains(time_elapsed), "{}", time_elapsed);
}
2 changes: 1 addition & 1 deletion src/tools/miri/tests/pass-dep/tokio/tokio_mvp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Need to disable preemption to stay on the supported MVP codepath in mio.
//@compile-flags: -Zmiri-disable-isolation -Zmiri-permissive-provenance
//@compile-flags: -Zmiri-permissive-provenance
//@only-target-x86_64-unknown-linux: support for tokio exists only on linux and x86

#[tokio::main]
Expand Down

0 comments on commit 0e2e617

Please sign in to comment.