Skip to content

isolated operations return EPERM; tweak isolation hint #1829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ pub fn report_error<'tcx, 'mir>(
#[rustfmt::skip]
let helps = match info {
UnsupportedInIsolation(_) =>
vec![(None, format!("pass the flag `-Zmiri-disable-isolation` to disable isolation; or pass `-Zmiri-isolation-error=warn to configure Miri to return an error code from isolated operations and continue with a warning"))],
vec![
(None, format!("pass the flag `-Zmiri-disable-isolation` to disable isolation;")),
(None, format!("or pass `-Zmiri-isolation-error=warn to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning")),
],
ExperimentalUb { url, .. } =>
vec![
(None, format!("this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental")),
Expand Down
5 changes: 3 additions & 2 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
WouldBlock => "EWOULDBLOCK",
_ => {
throw_unsup_format!(
"io error {:?} cannot be transformed into a raw os error",
"io error {:?} cannot be translated into a raw os error",
err_kind
)
}
Expand All @@ -496,8 +496,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
"c",
match err_kind {
NotFound => "ERROR_FILE_NOT_FOUND",
PermissionDenied => "ERROR_ACCESS_DENIED",
_ => throw_unsup_format!(
"io error {:?} cannot be transformed into a raw os error",
"io error {:?} cannot be translated into a raw os error",
err_kind
),
},
Expand Down
8 changes: 4 additions & 4 deletions src/shims/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx

if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
this.reject_in_isolation("getcwd", reject_with)?;
this.set_last_error_from_io_error(ErrorKind::NotFound)?;
this.set_last_error_from_io_error(ErrorKind::PermissionDenied)?;
return Ok(Scalar::null_ptr(&*this.tcx));
}

Expand Down Expand Up @@ -356,7 +356,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx

if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
this.reject_in_isolation("GetCurrentDirectoryW", reject_with)?;
this.set_last_error_from_io_error(ErrorKind::NotFound)?;
this.set_last_error_from_io_error(ErrorKind::PermissionDenied)?;
return Ok(0);
}

Expand All @@ -382,7 +382,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx

if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
this.reject_in_isolation("chdir", reject_with)?;
this.set_last_error_from_io_error(ErrorKind::NotFound)?;
this.set_last_error_from_io_error(ErrorKind::PermissionDenied)?;

return Ok(-1);
}
Expand Down Expand Up @@ -410,7 +410,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx

if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
this.reject_in_isolation("SetCurrentDirectoryW", reject_with)?;
this.set_last_error_from_io_error(ErrorKind::NotFound)?;
this.set_last_error_from_io_error(ErrorKind::PermissionDenied)?;

return Ok(0);
}
Expand Down
13 changes: 7 additions & 6 deletions tests/run-pass/current_dir_with_isolation.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// compile-flags: -Zmiri-isolation-error=warn-nobacktrace
// normalize-stderr-test "(getcwd|GetCurrentDirectoryW)" -> "$$GET"
// normalize-stderr-test "(chdir|SetCurrentDirectoryW)" -> "$$SET"
// normalize-stderr-test "(getcwd|GetCurrentDirectoryW)" -> "$$GETCWD"
// normalize-stderr-test "(chdir|SetCurrentDirectoryW)" -> "$$SETCWD"

use std::env;
use std::io::ErrorKind;

fn main() {
// Test that current dir operations return a proper error instead
// of stopping the machine in isolation mode
assert_eq!(env::current_dir().unwrap_err().kind(), ErrorKind::NotFound);
assert_eq!(env::current_dir().unwrap_err().kind(), ErrorKind::PermissionDenied);
for _i in 0..3 {
assert_eq!(env::current_dir().unwrap_err().kind(), ErrorKind::NotFound);
// Ensure we get no repeated warnings when doing this multiple times.
assert_eq!(env::current_dir().unwrap_err().kind(), ErrorKind::PermissionDenied);
}

assert_eq!(env::set_current_dir("..").unwrap_err().kind(), ErrorKind::NotFound);
assert_eq!(env::set_current_dir("..").unwrap_err().kind(), ErrorKind::PermissionDenied);
for _i in 0..3 {
assert_eq!(env::set_current_dir("..").unwrap_err().kind(), ErrorKind::NotFound);
assert_eq!(env::set_current_dir("..").unwrap_err().kind(), ErrorKind::PermissionDenied);
}
}
4 changes: 2 additions & 2 deletions tests/run-pass/current_dir_with_isolation.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning: `$GET` was made to return an error due to isolation
warning: `$GETCWD` was made to return an error due to isolation

warning: `$SET` was made to return an error due to isolation
warning: `$SETCWD` was made to return an error due to isolation