Skip to content

Commit 8d68956

Browse files
committed
Warn about dummy error produced in isolation mode
1 parent a7a6627 commit 8d68956

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/helpers.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
397397
Ok(())
398398
}
399399

400+
/// Helper function used inside the shims of foreign functions
401+
/// which produce a dummy error when isolation is enabled. It is
402+
/// used to print a warning informing this decision to the user.
403+
fn warn_foreign_in_isolation(&self, name: &str) {
404+
let this = self.eval_context_ref();
405+
this.tcx.sess.warn(&format!("`{}` in isolation mode produced a dummy error", name));
406+
}
407+
400408
/// Helper function used inside the shims of foreign functions to assert that the target OS
401409
/// is `target_os`. It panics showing a message with the `name` of the foreign function
402410
/// if this is not the case.

src/shims/env.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
337337
Err(e) => this.set_last_error_from_io_error(e)?,
338338
}
339339
} else {
340-
// Emulate an error in isolation mode
341-
let err = Error::new(ErrorKind::NotFound, "`getcwd` not available in isolation mode");
340+
// Return a dummy error in isolation mode, after printing a warning about it.
341+
this.warn_foreign_in_isolation("getcwd");
342+
let err = Error::new(ErrorKind::NotFound, "dummy error in isolation mode");
342343
this.set_last_error_from_io_error(err)?;
343344
}
344345
Ok(Scalar::null_ptr(&*this.tcx))
@@ -364,8 +365,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
364365
Err(e) => this.set_last_error_from_io_error(e)?,
365366
}
366367
} else {
367-
// Emulate an error in isolation mode
368-
let err = Error::new(ErrorKind::NotFound, "`GetCurrentDirectoryW` not available in isolation mode");
368+
// Return a dummy error in isolation mode, after printing a warning about it.
369+
this.warn_foreign_in_isolation("GetCurrentDirectoryW");
370+
let err = Error::new(ErrorKind::NotFound, "dummy error in isolation mode");
369371
this.set_last_error_from_io_error(err)?;
370372
}
371373
Ok(0)
@@ -390,9 +392,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
390392
}
391393
}
392394
} else {
393-
// Emulate an error in isolation mode
394-
let err = Error::new(ErrorKind::NotFound, "`chdir` not available in isolation mode");
395+
// Return a dummy error in isolation mode, after printing a warning about it.
396+
this.warn_foreign_in_isolation("chdir");
397+
let err = Error::new(ErrorKind::NotFound, "dummy error in isolation mode");
395398
this.set_last_error_from_io_error(err)?;
399+
396400
Ok(-1)
397401
}
398402
}
@@ -418,8 +422,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
418422
}
419423
}
420424
} else {
421-
// Emulate an error in isolation mode
422-
let err = Error::new(ErrorKind::NotFound, "`SetCurrentDirectoryW` not available in isolation mode");
425+
// Return a dummy error in isolation mode, after printing a warning about it.
426+
this.warn_foreign_in_isolation("SetCurrentDirectoryW");
427+
let err = Error::new(ErrorKind::NotFound, "dummy error in isolation mode");
423428
this.set_last_error_from_io_error(err)?;
424429
Ok(0)
425430
}

0 commit comments

Comments
 (0)