Skip to content

Commit 358cfd2

Browse files
committed
Auto merge of #996 - christianpoveda:unsup-wo-isolation, r=RalfJung
Add function to error with enabled isolation Fixes #986 r? @RalfJung
2 parents 49cab51 + 78311a7 commit 358cfd2

File tree

4 files changed

+19
-30
lines changed

4 files changed

+19
-30
lines changed

src/helpers.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
336336
)?;
337337
offset += imm.layout.size;
338338
}
339+
Ok(())
340+
}
339341

342+
/// Helper function used inside the shims of foreign functions to check that isolation is
343+
/// disabled. It returns an error using the `name` of the foreign function if this is not the
344+
/// case.
345+
fn check_no_isolation(&mut self, name: &str) -> InterpResult<'tcx> {
346+
if !self.eval_context_mut().machine.communicate {
347+
throw_unsup_format!("`{}` not available when isolation is enabled. Pass the flag `-Zmiri-disable-isolation` to disable it.", name)
348+
}
340349
Ok(())
341350
}
342351
}

src/shims/env.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
120120
) -> InterpResult<'tcx, Scalar<Tag>> {
121121
let this = self.eval_context_mut();
122122

123-
if !this.machine.communicate {
124-
throw_unsup_format!("`getcwd` not available when isolation is enabled")
125-
}
123+
this.check_no_isolation("getcwd")?;
126124

127125
let tcx = &{ this.tcx.tcx };
128126

@@ -158,9 +156,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
158156
fn chdir(&mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
159157
let this = self.eval_context_mut();
160158

161-
if !this.machine.communicate {
162-
throw_unsup_format!("`chdir` not available when isolation is enabled")
163-
}
159+
this.check_no_isolation("chdir")?;
164160

165161
let path_bytes = this
166162
.memory()

src/shims/fs.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3535
) -> InterpResult<'tcx, i32> {
3636
let this = self.eval_context_mut();
3737

38-
if !this.machine.communicate {
39-
throw_unsup_format!("`open` not available when isolation is enabled")
40-
}
38+
this.check_no_isolation("open")?;
4139

4240
let flag = this.read_scalar(flag_op)?.to_i32()?;
4341

@@ -120,9 +118,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
120118
) -> InterpResult<'tcx, i32> {
121119
let this = self.eval_context_mut();
122120

123-
if !this.machine.communicate {
124-
throw_unsup_format!("`fcntl` not available when isolation is enabled")
125-
}
121+
this.check_no_isolation("fcntl")?;
126122

127123
let fd = this.read_scalar(fd_op)?.to_i32()?;
128124
let cmd = this.read_scalar(cmd_op)?.to_i32()?;
@@ -142,9 +138,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
142138
fn close(&mut self, fd_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
143139
let this = self.eval_context_mut();
144140

145-
if !this.machine.communicate {
146-
throw_unsup_format!("`close` not available when isolation is enabled")
147-
}
141+
this.check_no_isolation("close")?;
148142

149143
let fd = this.read_scalar(fd_op)?.to_i32()?;
150144

@@ -161,9 +155,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
161155
) -> InterpResult<'tcx, i64> {
162156
let this = self.eval_context_mut();
163157

164-
if !this.machine.communicate {
165-
throw_unsup_format!("`read` not available when isolation is enabled")
166-
}
158+
this.check_no_isolation("read")?;
167159

168160
let tcx = &{ this.tcx.tcx };
169161

@@ -198,9 +190,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
198190
) -> InterpResult<'tcx, i64> {
199191
let this = self.eval_context_mut();
200192

201-
if !this.machine.communicate {
202-
throw_unsup_format!("`write` not available when isolation is enabled")
203-
}
193+
this.check_no_isolation("write")?;
204194

205195
let tcx = &{ this.tcx.tcx };
206196

@@ -226,9 +216,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
226216
fn unlink( &mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
227217
let this = self.eval_context_mut();
228218

229-
if !this.machine.communicate {
230-
throw_unsup_format!("`write` not available when isolation is enabled")
231-
}
219+
this.check_no_isolation("unlink")?;
232220

233221
let path_bytes = this
234222
.memory()

src/shims/time.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4141
) -> InterpResult<'tcx, i32> {
4242
let this = self.eval_context_mut();
4343

44-
if !this.machine.communicate {
45-
throw_unsup_format!("`clock_gettime` not available when isolation is enabled")
46-
}
44+
this.check_no_isolation("clock_gettime")?;
4745

4846
let clk_id = this.read_scalar(clk_id_op)?.to_i32()?;
4947
if clk_id != this.eval_libc_i32("CLOCK_REALTIME")? {
@@ -75,9 +73,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7573
) -> InterpResult<'tcx, i32> {
7674
let this = self.eval_context_mut();
7775

78-
if !this.machine.communicate {
79-
throw_unsup_format!("`gettimeofday` not available when isolation is enabled")
80-
}
76+
this.check_no_isolation("gettimeofday")?;
8177
// Using tz is obsolete and should always be null
8278
let tz = this.read_scalar(tz_op)?.not_undef()?;
8379
if !this.is_null(tz)? {

0 commit comments

Comments
 (0)