Skip to content

Commit a38f02c

Browse files
committed
isolated operations return EPERM; tweak isolation hint
1 parent 31c1afa commit a38f02c

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

src/diagnostics.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ pub fn report_error<'tcx, 'mir>(
8484
#[rustfmt::skip]
8585
let helps = match info {
8686
UnsupportedInIsolation(_) =>
87-
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"))],
87+
vec![
88+
(None, format!("pass the flag `-Zmiri-disable-isolation` to disable isolation;")),
89+
(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")),
90+
],
8891
ExperimentalUb { url, .. } =>
8992
vec![
9093
(None, format!("this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental")),

src/helpers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
485485
WouldBlock => "EWOULDBLOCK",
486486
_ => {
487487
throw_unsup_format!(
488-
"io error {:?} cannot be transformed into a raw os error",
488+
"io error {:?} cannot be translated into a raw os error",
489489
err_kind
490490
)
491491
}
@@ -496,8 +496,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
496496
"c",
497497
match err_kind {
498498
NotFound => "ERROR_FILE_NOT_FOUND",
499+
PermissionDenied => "ERROR_ACCESS_DENIED",
499500
_ => throw_unsup_format!(
500-
"io error {:?} cannot be transformed into a raw os error",
501+
"io error {:?} cannot be translated into a raw os error",
501502
err_kind
502503
),
503504
},

src/shims/env.rs

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

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

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

357357
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
358358
this.reject_in_isolation("GetCurrentDirectoryW", reject_with)?;
359-
this.set_last_error_from_io_error(ErrorKind::NotFound)?;
359+
this.set_last_error_from_io_error(ErrorKind::PermissionDenied)?;
360360
return Ok(0);
361361
}
362362

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

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

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

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

415415
return Ok(0);
416416
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
// compile-flags: -Zmiri-isolation-error=warn-nobacktrace
2-
// normalize-stderr-test "(getcwd|GetCurrentDirectoryW)" -> "$$GET"
3-
// normalize-stderr-test "(chdir|SetCurrentDirectoryW)" -> "$$SET"
2+
// normalize-stderr-test "(getcwd|GetCurrentDirectoryW)" -> "$$GETCWD"
3+
// normalize-stderr-test "(chdir|SetCurrentDirectoryW)" -> "$$SETCWD"
44

55
use std::env;
66
use std::io::ErrorKind;
77

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

16-
assert_eq!(env::set_current_dir("..").unwrap_err().kind(), ErrorKind::NotFound);
17+
assert_eq!(env::set_current_dir("..").unwrap_err().kind(), ErrorKind::PermissionDenied);
1718
for _i in 0..3 {
18-
assert_eq!(env::set_current_dir("..").unwrap_err().kind(), ErrorKind::NotFound);
19+
assert_eq!(env::set_current_dir("..").unwrap_err().kind(), ErrorKind::PermissionDenied);
1920
}
2021
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: `$GET` was made to return an error due to isolation
1+
warning: `$GETCWD` was made to return an error due to isolation
22

3-
warning: `$SET` was made to return an error due to isolation
3+
warning: `$SETCWD` was made to return an error due to isolation
44

0 commit comments

Comments
 (0)