Auto merge of #996 - christianpoveda:unsup-wo-isolation, r=RalfJung

Add function to error with enabled isolation

Fixes https://github.com/rust-lang/miri/issues/986
r? @RalfJung
This commit is contained in:
bors 2019-10-16 08:17:57 +00:00
commit 358cfd290c
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

@ -35,9 +35,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()?;
@ -120,9 +118,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()?;
@ -142,9 +138,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()?;
@ -161,9 +155,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 };
@ -198,9 +190,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 };
@ -226,9 +216,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)? {