Add function to error with enabled isolation

This commit is contained in:
Christian Poveda 2019-10-14 15:36:15 -05:00
parent 0d01c306fe
commit 78311a7132
4 changed files with 19 additions and 30 deletions

View File

@ -336,7 +336,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
)?;
offset += imm.layout.size;
}
Ok(())
}
/// Helper function used inside the shims of foreign functions to check that isolation is
/// disabled. It returns an error using the `name` of the foreign function if this is not the
/// case.
fn check_no_isolation(&mut self, name: &str) -> InterpResult<'tcx> {
if !self.eval_context_mut().machine.communicate {
throw_unsup_format!("`{}` not available when isolation is enabled. Pass the flag `-Zmiri-disable-isolation` to disable it.", name)
}
Ok(())
}
}

View File

@ -120,9 +120,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
) -> InterpResult<'tcx, Scalar<Tag>> {
let this = self.eval_context_mut();
if !this.machine.communicate {
throw_unsup_format!("`getcwd` not available when isolation is enabled")
}
this.check_no_isolation("getcwd")?;
let tcx = &{ this.tcx.tcx };
@ -158,9 +156,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn chdir(&mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !this.machine.communicate {
throw_unsup_format!("`chdir` not available when isolation is enabled")
}
this.check_no_isolation("chdir")?;
let path_bytes = this
.memory()

View File

@ -36,9 +36,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !this.machine.communicate {
throw_unsup_format!("`open` not available when isolation is enabled")
}
this.check_no_isolation("open")?;
let flag = this.read_scalar(flag_op)?.to_i32()?;
@ -91,9 +89,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !this.machine.communicate {
throw_unsup_format!("`fcntl` not available when isolation is enabled")
}
this.check_no_isolation("fcntl")?;
let fd = this.read_scalar(fd_op)?.to_i32()?;
let cmd = this.read_scalar(cmd_op)?.to_i32()?;
@ -126,9 +122,7 @@ 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();
if !this.machine.communicate {
throw_unsup_format!("`close` not available when isolation is enabled")
}
this.check_no_isolation("close")?;
let fd = this.read_scalar(fd_op)?.to_i32()?;
@ -145,9 +139,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
) -> InterpResult<'tcx, i64> {
let this = self.eval_context_mut();
if !this.machine.communicate {
throw_unsup_format!("`read` not available when isolation is enabled")
}
this.check_no_isolation("read")?;
let tcx = &{ this.tcx.tcx };
@ -182,9 +174,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
) -> InterpResult<'tcx, i64> {
let this = self.eval_context_mut();
if !this.machine.communicate {
throw_unsup_format!("`write` not available when isolation is enabled")
}
this.check_no_isolation("write")?;
let tcx = &{ this.tcx.tcx };
@ -210,9 +200,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();
if !this.machine.communicate {
throw_unsup_format!("`write` not available when isolation is enabled")
}
this.check_no_isolation("unlink")?;
let path_bytes = this
.memory()

View File

@ -41,9 +41,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !this.machine.communicate {
throw_unsup_format!("`clock_gettime` not available when isolation is enabled")
}
this.check_no_isolation("clock_gettime")?;
let clk_id = this.read_scalar(clk_id_op)?.to_i32()?;
if clk_id != this.eval_libc_i32("CLOCK_REALTIME")? {
@ -75,9 +73,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !this.machine.communicate {
throw_unsup_format!("`gettimeofday` not available when isolation is enabled")
}
this.check_no_isolation("gettimeofday")?;
// Using tz is obsolete and should always be null
let tz = this.read_scalar(tz_op)?.not_undef()?;
if !this.is_null(tz)? {