From b350c80a314b0b1a94fbfa2bb5d391df98388992 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 3 Oct 2020 15:20:16 +0200 Subject: [PATCH] add backtics back in isolation error message --- src/shims/env.rs | 8 ++--- src/shims/posix/fs.rs | 42 ++++++++++++------------- src/shims/posix/linux/sync.rs | 2 +- src/shims/posix/sync.rs | 2 +- src/shims/time.rs | 16 +++++----- tests/compile-fail/fs/isolated_file.rs | 2 +- tests/compile-fail/fs/isolated_stdin.rs | 2 +- 7 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/shims/env.rs b/src/shims/env.rs index d7474dbf87ef..42fd6e3dced8 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -293,7 +293,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let target_os = &this.tcx.sess.target.target.target_os; assert!(target_os == "linux" || target_os == "macos", "`getcwd` is only available for the UNIX target family"); - this.check_no_isolation("getcwd")?; + this.check_no_isolation("`getcwd`")?; let buf = this.read_scalar(buf_op)?.check_init()?; let size = this.read_scalar(size_op)?.to_machine_usize(&*this.tcx)?; @@ -320,7 +320,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("windows", "GetCurrentDirectoryW"); - this.check_no_isolation("GetCurrentDirectoryW")?; + this.check_no_isolation("`GetCurrentDirectoryW`")?; let size = u64::from(this.read_scalar(size_op)?.to_u32()?); let buf = this.read_scalar(buf_op)?.check_init()?; @@ -339,7 +339,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let target_os = &this.tcx.sess.target.target.target_os; assert!(target_os == "linux" || target_os == "macos", "`getcwd` is only available for the UNIX target family"); - this.check_no_isolation("chdir")?; + this.check_no_isolation("`chdir`")?; let path = this.read_path_from_c_str(this.read_scalar(path_op)?.check_init()?)?; @@ -360,7 +360,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("windows", "SetCurrentDirectoryW"); - this.check_no_isolation("SetCurrentDirectoryW")?; + this.check_no_isolation("`SetCurrentDirectoryW`")?; let path = this.read_path_from_wide_str(this.read_scalar(path_op)?.check_init()?)?; diff --git a/src/shims/posix/fs.rs b/src/shims/posix/fs.rs index c50b41b75ef9..88597b4a3981 100644 --- a/src/shims/posix/fs.rs +++ b/src/shims/posix/fs.rs @@ -90,7 +90,7 @@ impl FileDescriptor for io::Stdin { fn read<'tcx>(&mut self, communicate_allowed: bool, bytes: &mut [u8]) -> InterpResult<'tcx, io::Result> { if !communicate_allowed { // We want isolation mode to be deterministic, so we have to disallow all reads, even stdin. - helpers::isolation_error("read")?; + helpers::isolation_error("`read` from stdin")?; } Ok(Read::read(self, bytes)) } @@ -417,7 +417,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); - this.check_no_isolation("open")?; + this.check_no_isolation("`open`")?; let flag = this.read_scalar(flag_op)?.to_i32()?; @@ -510,7 +510,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); - this.check_no_isolation("fcntl")?; + this.check_no_isolation("`fcntl`")?; if args.len() < 2 { throw_ub_format!("incorrect number of arguments for fcntl: got {}, expected at least 2", args.len()); @@ -574,8 +574,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx fn close(&mut self, fd_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); - this.check_no_isolation("close")?; - let fd = this.read_scalar(fd_op)?.to_i32()?; if let Some(file_descriptor) = this.machine.file_handler.handles.remove(&fd) { @@ -709,7 +707,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx fn unlink(&mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); - this.check_no_isolation("unlink")?; + this.check_no_isolation("`unlink`")?; let path = this.read_path_from_c_str(this.read_scalar(path_op)?.check_init()?)?; @@ -739,7 +737,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); - this.check_no_isolation("symlink")?; + this.check_no_isolation("`symlink`")?; let target = this.read_path_from_c_str(this.read_scalar(target_op)?.check_init()?)?; let linkpath = this.read_path_from_c_str(this.read_scalar(linkpath_op)?.check_init()?)?; @@ -755,7 +753,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); this.assert_target_os("macos", "stat"); - this.check_no_isolation("stat")?; + this.check_no_isolation("`stat`")?; // `stat` always follows symlinks. this.macos_stat_or_lstat(true, path_op, buf_op) } @@ -768,7 +766,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); this.assert_target_os("macos", "lstat"); - this.check_no_isolation("lstat")?; + this.check_no_isolation("`lstat`")?; this.macos_stat_or_lstat(false, path_op, buf_op) } @@ -780,7 +778,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("macos", "fstat"); - this.check_no_isolation("fstat")?; + this.check_no_isolation("`fstat`")?; let fd = this.read_scalar(fd_op)?.to_i32()?; @@ -802,7 +800,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("linux", "statx"); - this.check_no_isolation("statx")?; + this.check_no_isolation("`statx`")?; let statxbuf_scalar = this.read_scalar(statxbuf_op)?.check_init()?; let pathname_scalar = this.read_scalar(pathname_op)?.check_init()?; @@ -961,7 +959,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); - this.check_no_isolation("rename")?; + this.check_no_isolation("`rename`")?; let oldpath_scalar = this.read_scalar(oldpath_op)?.check_init()?; let newpath_scalar = this.read_scalar(newpath_op)?.check_init()?; @@ -987,7 +985,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); - this.check_no_isolation("mkdir")?; + this.check_no_isolation("`mkdir`")?; #[cfg_attr(not(unix), allow(unused_variables))] let mode = if this.tcx.sess.target.target.target_os == "macos" { @@ -1020,7 +1018,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); - this.check_no_isolation("rmdir")?; + this.check_no_isolation("`rmdir`")?; let path = this.read_path_from_c_str(this.read_scalar(path_op)?.check_init()?)?; @@ -1032,7 +1030,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx fn opendir(&mut self, name_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - this.check_no_isolation("opendir")?; + this.check_no_isolation("`opendir`")?; let name = this.read_path_from_c_str(this.read_scalar(name_op)?.check_init()?)?; @@ -1063,7 +1061,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("linux", "readdir64_r"); - this.check_no_isolation("readdir64_r")?; + this.check_no_isolation("`readdir64_r`")?; let dirp = this.read_scalar(dirp_op)?.to_machine_usize(this)?; @@ -1150,7 +1148,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("macos", "readdir_r"); - this.check_no_isolation("readdir_r")?; + this.check_no_isolation("`readdir_r`")?; let dirp = this.read_scalar(dirp_op)?.to_machine_usize(this)?; @@ -1233,7 +1231,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx fn closedir(&mut self, dirp_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); - this.check_no_isolation("closedir")?; + this.check_no_isolation("`closedir`")?; let dirp = this.read_scalar(dirp_op)?.to_machine_usize(this)?; @@ -1252,7 +1250,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); - this.check_no_isolation("ftruncate64")?; + this.check_no_isolation("`ftruncate64`")?; let fd = this.read_scalar(fd_op)?.to_i32()?; let length = this.read_scalar(length_op)?.to_i64()?; @@ -1287,7 +1285,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); - this.check_no_isolation("fsync")?; + this.check_no_isolation("`fsync`")?; let fd = this.read_scalar(fd_op)?.to_i32()?; if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) { @@ -1303,7 +1301,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx fn fdatasync(&mut self, fd_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); - this.check_no_isolation("fdatasync")?; + this.check_no_isolation("`fdatasync`")?; let fd = this.read_scalar(fd_op)?.to_i32()?; if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) { @@ -1325,7 +1323,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); - this.check_no_isolation("sync_file_range")?; + this.check_no_isolation("`sync_file_range`")?; let fd = this.read_scalar(fd_op)?.to_i32()?; let offset = this.read_scalar(offset_op)?.to_i64()?; diff --git a/src/shims/posix/linux/sync.rs b/src/shims/posix/linux/sync.rs index d7ecb45279de..ef172fa2a671 100644 --- a/src/shims/posix/linux/sync.rs +++ b/src/shims/posix/linux/sync.rs @@ -55,6 +55,7 @@ pub fn futex<'tcx>( let timeout_time = if this.is_null(this.read_scalar(timeout)?.check_init()?)? { None } else { + this.check_no_isolation("`syscall(SYS_FUTEX, op=FUTEX_WAIT)` with timeout")?; let duration = match this.read_timespec(timeout)? { Some(duration) => duration, None => { @@ -64,7 +65,6 @@ pub fn futex<'tcx>( return Ok(()); } }; - this.check_no_isolation("FUTEX_WAIT with timeout")?; Some(if op & futex_realtime != 0 { Time::RealTime(SystemTime::now().checked_add(duration).unwrap()) } else { diff --git a/src/shims/posix/sync.rs b/src/shims/posix/sync.rs index 6918fb7fd7ec..a0b5db42ed06 100644 --- a/src/shims/posix/sync.rs +++ b/src/shims/posix/sync.rs @@ -690,7 +690,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); - this.check_no_isolation("pthread_cond_timedwait")?; + this.check_no_isolation("`pthread_cond_timedwait`")?; let id = cond_get_or_create_id(this, cond_op)?; let mutex_id = mutex_get_or_create_id(this, mutex_op)?; diff --git a/src/shims/time.rs b/src/shims/time.rs index 9d6d6ed38daa..806fa65d1564 100644 --- a/src/shims/time.rs +++ b/src/shims/time.rs @@ -22,7 +22,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("linux", "clock_gettime"); - this.check_no_isolation("clock_gettime")?; + this.check_no_isolation("`clock_gettime`")?; let clk_id = this.read_scalar(clk_id_op)?.to_i32()?; let tp = this.deref_operand(tp_op)?; @@ -60,7 +60,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("macos", "gettimeofday"); - this.check_no_isolation("gettimeofday")?; + this.check_no_isolation("`gettimeofday`")?; // Using tz is obsolete and should always be null let tz = this.read_scalar(tz_op)?.check_init()?; @@ -91,7 +91,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("windows", "GetSystemTimeAsFileTime"); - this.check_no_isolation("GetSystemTimeAsFileTime")?; + this.check_no_isolation("`GetSystemTimeAsFileTime`")?; let NANOS_PER_SEC = this.eval_windows_u64("time", "NANOS_PER_SEC")?; let INTERVALS_PER_SEC = this.eval_windows_u64("time", "INTERVALS_PER_SEC")?; @@ -119,7 +119,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("windows", "QueryPerformanceCounter"); - this.check_no_isolation("QueryPerformanceCounter")?; + this.check_no_isolation("`QueryPerformanceCounter`")?; // QueryPerformanceCounter uses a hardware counter as its basis. // Miri will emulate a counter with a resolution of 1 nanosecond. @@ -135,7 +135,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("windows", "QueryPerformanceFrequency"); - this.check_no_isolation("QueryPerformanceFrequency")?; + this.check_no_isolation("`QueryPerformanceFrequency`")?; // Retrieves the frequency of the hardware performance counter. // The frequency of the performance counter is fixed at system boot and @@ -150,7 +150,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_ref(); this.assert_target_os("macos", "mach_absolute_time"); - this.check_no_isolation("mach_absolute_time")?; + this.check_no_isolation("`mach_absolute_time`")?; // This returns a u64, with time units determined dynamically by `mach_timebase_info`. // We return plain nanoseconds. @@ -163,7 +163,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); this.assert_target_os("macos", "mach_timebase_info"); - this.check_no_isolation("mach_timebase_info")?; + this.check_no_isolation("`mach_timebase_info`")?; let info = this.deref_operand(info_op)?; @@ -188,7 +188,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let this = self.eval_context_mut(); - this.check_no_isolation("nanosleep")?; + this.check_no_isolation("`nanosleep`")?; let duration = match this.read_timespec(req_op)? { Some(duration) => duration, diff --git a/tests/compile-fail/fs/isolated_file.rs b/tests/compile-fail/fs/isolated_file.rs index 4c6adc8bf406..5b7270f18931 100644 --- a/tests/compile-fail/fs/isolated_file.rs +++ b/tests/compile-fail/fs/isolated_file.rs @@ -1,5 +1,5 @@ // ignore-windows: File handling is not implemented yet -// error-pattern: open not available when isolation is enabled +// error-pattern: `open` not available when isolation is enabled fn main() { let _file = std::fs::File::open("file.txt").unwrap(); diff --git a/tests/compile-fail/fs/isolated_stdin.rs b/tests/compile-fail/fs/isolated_stdin.rs index 19ce064089aa..4098a104761e 100644 --- a/tests/compile-fail/fs/isolated_stdin.rs +++ b/tests/compile-fail/fs/isolated_stdin.rs @@ -7,7 +7,7 @@ extern crate libc; fn main() -> std::io::Result<()> { let mut bytes = [0u8; 512]; unsafe { - libc::read(0, bytes.as_mut_ptr() as *mut libc::c_void, 512); //~ ERROR read not available when isolation is enabled + libc::read(0, bytes.as_mut_ptr() as *mut libc::c_void, 512); //~ ERROR `read` from stdin not available when isolation is enabled } Ok(()) }