add backtics back in isolation error message

This commit is contained in:
Ralf Jung 2020-10-03 15:20:16 +02:00
parent 044c9ca206
commit b350c80a31
7 changed files with 36 additions and 38 deletions

View File

@ -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()?)?;

View File

@ -90,7 +90,7 @@ impl FileDescriptor for io::Stdin {
fn read<'tcx>(&mut self, communicate_allowed: bool, bytes: &mut [u8]) -> InterpResult<'tcx, io::Result<usize>> {
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<Tag>> {
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()?;

View File

@ -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 {

View File

@ -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)?;

View File

@ -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,

View File

@ -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();

View File

@ -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(())
}