Skip to content

Commit f057771

Browse files
committed
Delete redundant communicate flag from miri config and machine
Added a new function `communicate()` on machine and replaced the uses of flag with the new function.
1 parent 75cf599 commit f057771

File tree

6 files changed

+19
-23
lines changed

6 files changed

+19
-23
lines changed

src/bin/miri.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ fn main() {
228228
miri_config.check_alignment = miri::AlignmentCheck::Symbolic;
229229
}
230230
"-Zmiri-disable-isolation" => {
231-
miri_config.communicate = true;
232231
miri_config.isolated_op = miri::IsolatedOp::Allow;
233232
}
234233
"-Zmiri-ignore-leaks" => {

src/eval.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub enum AlignmentCheck {
2222
Int,
2323
}
2424

25-
#[derive(Copy, Clone, Debug)]
25+
#[derive(Copy, Clone, Debug, PartialEq)]
2626
pub enum RejectOpWith {
2727
/// Do not print warning about rejected isolated op
2828
NoWarning,
@@ -34,7 +34,7 @@ pub enum RejectOpWith {
3434
WarningWithoutBacktrace,
3535
}
3636

37-
#[derive(Copy, Clone, Debug)]
37+
#[derive(Copy, Clone, Debug, PartialEq)]
3838
pub enum IsolatedOp {
3939
/// Reject op requiring communication with the host. Usually, miri
4040
/// returns an error code for such op, and prints a warning
@@ -54,8 +54,6 @@ pub struct MiriConfig {
5454
pub stacked_borrows: bool,
5555
/// Controls alignment checking.
5656
pub check_alignment: AlignmentCheck,
57-
/// Determines if communication with the host environment is enabled.
58-
pub communicate: bool,
5957
/// Action for an op requiring communication with the host.
6058
pub isolated_op: IsolatedOp,
6159
/// Determines if memory leaks should be ignored.
@@ -87,7 +85,6 @@ impl Default for MiriConfig {
8785
validate: true,
8886
stacked_borrows: true,
8987
check_alignment: AlignmentCheck::Int,
90-
communicate: false,
9188
isolated_op: IsolatedOp::Reject(RejectOpWith::WarningWithoutBacktrace),
9289
ignore_leaks: false,
9390
excluded_env_vars: vec![],
@@ -252,7 +249,7 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) ->
252249
}
253250
SchedulingAction::ExecuteTimeoutCallback => {
254251
assert!(
255-
ecx.machine.communicate,
252+
ecx.machine.communicate(),
256253
"scheduler callbacks require disabled isolation, but the code \
257254
that created the callback did not check it"
258255
);

src/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
140140

141141
let mut data = vec![0; usize::try_from(len).unwrap()];
142142

143-
if this.machine.communicate {
143+
if this.machine.communicate() {
144144
// Fill the buffer using the host's rng.
145145
getrandom::getrandom(&mut data)
146146
.map_err(|err| err_unsup_format!("host getrandom failed: {}", err))?;
@@ -391,7 +391,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
391391
/// disabled. It returns an error using the `name` of the foreign function if this is not the
392392
/// case.
393393
fn check_no_isolation(&self, name: &str) -> InterpResult<'tcx> {
394-
if !self.eval_context_ref().machine.communicate {
394+
if !self.eval_context_ref().machine.communicate() {
395395
isolation_error(name)?;
396396
}
397397
Ok(())

src/machine.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,6 @@ pub struct Evaluator<'mir, 'tcx> {
249249
/// TLS state.
250250
pub(crate) tls: TlsData<'tcx>,
251251

252-
/// If enabled, the `env_vars` field is populated with the host env vars during initialization
253-
/// and random number generation is delegated to the host.
254-
pub(crate) communicate: bool,
255-
256252
/// What should Miri do when an op requires communicating with the host,
257253
/// such as accessing host env vars, random number generation, and
258254
/// file system access.
@@ -289,7 +285,6 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
289285
argv: None,
290286
cmd_line: None,
291287
tls: TlsData::default(),
292-
communicate: config.communicate,
293288
isolated_op: config.isolated_op,
294289
validate: config.validate,
295290
file_handler: Default::default(),
@@ -300,6 +295,10 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
300295
static_roots: Vec::new(),
301296
}
302297
}
298+
299+
pub(crate) fn communicate(&self) -> bool {
300+
self.isolated_op == IsolatedOp::Allow
301+
}
303302
}
304303

305304
/// A rustc InterpCx for Miri.

src/shims/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'tcx> EnvVars<'tcx> {
4646
excluded_env_vars.push("TERM".to_owned());
4747
}
4848

49-
if ecx.machine.communicate {
49+
if ecx.machine.communicate() {
5050
for (name, value) in env::vars() {
5151
if !excluded_env_vars.contains(&name) {
5252
let var_ptr = match target_os {

src/shims/posix/fs.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
662662
let fd = this.read_scalar(fd_op)?.to_i32()?;
663663

664664
if let Some(file_descriptor) = this.machine.file_handler.handles.remove(&fd) {
665-
let result = file_descriptor.close(this.machine.communicate)?;
665+
let result = file_descriptor.close(this.machine.communicate())?;
666666
this.try_unwrap_io_result(result)
667667
} else {
668668
this.handle_not_found()
@@ -687,6 +687,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
687687
// We cap the number of read bytes to the largest value that we are able to fit in both the
688688
// host's and target's `isize`. This saves us from having to handle overflows later.
689689
let count = count.min(this.machine_isize_max() as u64).min(isize::MAX as u64);
690+
let communicate = this.machine.communicate();
690691

691692
if let Some(file_descriptor) = this.machine.file_handler.handles.get_mut(&fd) {
692693
trace!("read: FD mapped to {:?}", file_descriptor);
@@ -696,9 +697,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
696697
let mut bytes = vec![0; count as usize];
697698
// `File::read` never returns a value larger than `count`,
698699
// so this cannot fail.
699-
let result = file_descriptor
700-
.read(this.machine.communicate, &mut bytes)?
701-
.map(|c| i64::try_from(c).unwrap());
700+
let result =
701+
file_descriptor.read(communicate, &mut bytes)?.map(|c| i64::try_from(c).unwrap());
702702

703703
match result {
704704
Ok(read_bytes) => {
@@ -733,12 +733,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
733733
// We cap the number of written bytes to the largest value that we are able to fit in both the
734734
// host's and target's `isize`. This saves us from having to handle overflows later.
735735
let count = count.min(this.machine_isize_max() as u64).min(isize::MAX as u64);
736+
let communicate = this.machine.communicate();
736737

737738
if let Some(file_descriptor) = this.machine.file_handler.handles.get_mut(&fd) {
738739
let bytes = this.memory.read_bytes(buf, Size::from_bytes(count))?;
739-
let result = file_descriptor
740-
.write(this.machine.communicate, &bytes)?
741-
.map(|c| i64::try_from(c).unwrap());
740+
let result =
741+
file_descriptor.write(communicate, &bytes)?.map(|c| i64::try_from(c).unwrap());
742742
this.try_unwrap_io_result(result)
743743
} else {
744744
this.handle_not_found()
@@ -771,9 +771,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
771771
return Ok(-1);
772772
};
773773

774+
let communicate = this.machine.communicate();
774775
if let Some(file_descriptor) = this.machine.file_handler.handles.get_mut(&fd) {
775776
let result = file_descriptor
776-
.seek(this.machine.communicate, seek_from)?
777+
.seek(communicate, seek_from)?
777778
.map(|offset| i64::try_from(offset).unwrap());
778779
this.try_unwrap_io_result(result)
779780
} else {

0 commit comments

Comments
 (0)