Skip to content

Commit 3c17839

Browse files
committed
Add function to panic with enabled isolation
1 parent 2adc39f commit 3c17839

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

src/helpers.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
304304
fn eval_libc_i32(&mut self, name: &str) -> InterpResult<'tcx, i32> {
305305
self.eval_libc(name)?.to_i32()
306306
}
307+
308+
fn avoid_isolation(&mut self, name: &str) -> InterpResult<'tcx> {
309+
if !self.eval_context_mut().machine.communicate {
310+
throw_unsup_format!("`{}` not available when isolation is enabled", name)
311+
}
312+
Ok(())
313+
}
307314
}

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.avoid_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.avoid_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
@@ -36,9 +36,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3636
) -> InterpResult<'tcx, i32> {
3737
let this = self.eval_context_mut();
3838

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

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

@@ -91,9 +89,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9189
) -> InterpResult<'tcx, i32> {
9290
let this = self.eval_context_mut();
9391

94-
if !this.machine.communicate {
95-
throw_unsup_format!("`fcntl` not available when isolation is enabled")
96-
}
92+
this.avoid_isolation("fcntl")?;
9793

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

129-
if !this.machine.communicate {
130-
throw_unsup_format!("`close` not available when isolation is enabled")
131-
}
125+
this.avoid_isolation("close")?;
132126

133127
let fd = this.read_scalar(fd_op)?.to_i32()?;
134128

@@ -145,9 +139,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
145139
) -> InterpResult<'tcx, i64> {
146140
let this = self.eval_context_mut();
147141

148-
if !this.machine.communicate {
149-
throw_unsup_format!("`read` not available when isolation is enabled")
150-
}
142+
this.avoid_isolation("read")?;
151143

152144
let tcx = &{ this.tcx.tcx };
153145

@@ -182,9 +174,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
182174
) -> InterpResult<'tcx, i64> {
183175
let this = self.eval_context_mut();
184176

185-
if !this.machine.communicate {
186-
throw_unsup_format!("`write` not available when isolation is enabled")
187-
}
177+
this.avoid_isolation("write")?;
188178

189179
let tcx = &{ this.tcx.tcx };
190180

@@ -210,9 +200,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
210200
fn unlink( &mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
211201
let this = self.eval_context_mut();
212202

213-
if !this.machine.communicate {
214-
throw_unsup_format!("`write` not available when isolation is enabled")
215-
}
203+
this.avoid_isolation("unlink")?;
216204

217205
let path_bytes = this
218206
.memory()

0 commit comments

Comments
 (0)