@@ -851,8 +851,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
851
851
// Reject if isolation is enabled.
852
852
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
853
853
this. reject_in_isolation ( "`stat`" , reject_with) ?;
854
- // macos stat never sets "EPERM". Set error code "ENOENT".
855
- this. set_last_error_from_io_error ( ErrorKind :: NotFound ) ?;
854
+ let eacc = this . eval_libc ( "EACCES" ) ? ;
855
+ this. set_last_error ( eacc ) ?;
856
856
return Ok ( -1 ) ;
857
857
}
858
858
@@ -872,8 +872,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
872
872
// Reject if isolation is enabled.
873
873
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
874
874
this. reject_in_isolation ( "`lstat`" , reject_with) ?;
875
- // macos lstat never sets "EPERM". Set error code "ENOENT".
876
- this. set_last_error_from_io_error ( ErrorKind :: NotFound ) ?;
875
+ let eacc = this . eval_libc ( "EACCES" ) ? ;
876
+ this. set_last_error ( eacc ) ?;
877
877
return Ok ( -1 ) ;
878
878
}
879
879
@@ -917,14 +917,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
917
917
918
918
this. assert_target_os ( "linux" , "statx" ) ;
919
919
920
- // Reject if isolation is enabled.
921
- if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
922
- this. reject_in_isolation ( "`statx`" , reject_with) ?;
923
- // statx never sets "EPERM". Set error code "ENOENT".
924
- this. set_last_error_from_io_error ( ErrorKind :: NotFound ) ?;
925
- return Ok ( -1 ) ;
926
- }
927
-
928
920
let statxbuf_ptr = this. read_pointer ( statxbuf_op) ?;
929
921
let pathname_ptr = this. read_pointer ( pathname_op) ?;
930
922
@@ -973,6 +965,22 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
973
965
)
974
966
}
975
967
968
+ // Reject if isolation is enabled.
969
+ if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
970
+ this. reject_in_isolation ( "`statx`" , reject_with) ?;
971
+ let ecode = if path. is_absolute ( ) || dirfd == this. eval_libc_i32 ( "AT_FDCWD" ) ? {
972
+ // since `path` is provided, either absolute or
973
+ // relative to CWD, `EACCES` is the most relevant.
974
+ this. eval_libc ( "EACCES" ) ?
975
+ } else {
976
+ // `dirfd` is set to target file, and `path` is
977
+ // empty. `EACCES` would violate the spec.
978
+ this. eval_libc ( "EBADF" ) ?
979
+ } ;
980
+ this. set_last_error ( ecode) ?;
981
+ return Ok ( -1 ) ;
982
+ }
983
+
976
984
// the `_mask_op` paramter specifies the file information that the caller requested.
977
985
// However `statx` is allowed to return information that was not requested or to not
978
986
// return information that was requested. This `mask` represents the information we can
@@ -1167,8 +1175,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1167
1175
// Reject if isolation is enabled.
1168
1176
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1169
1177
this. reject_in_isolation ( "`opendir`" , reject_with) ?;
1170
- // opendir function never sets "EPERM". Set "ENOENT".
1171
- this. set_last_error_from_io_error ( ErrorKind :: NotFound ) ?;
1178
+ let eacc = this . eval_libc ( "EACCES" ) ? ;
1179
+ this. set_last_error ( eacc ) ?;
1172
1180
return Ok ( Scalar :: null_ptr ( this) ) ;
1173
1181
}
1174
1182
@@ -1422,8 +1430,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1422
1430
// Reject if isolation is enabled.
1423
1431
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1424
1432
this. reject_in_isolation ( "`ftruncate64`" , reject_with) ?;
1425
- this . set_last_error_from_io_error ( ErrorKind :: PermissionDenied ) ? ;
1426
- return Ok ( - 1 ) ;
1433
+ // Set error code as "EBADF" (bad fd)
1434
+ return this . handle_not_found ( ) ;
1427
1435
}
1428
1436
1429
1437
let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
@@ -1554,8 +1562,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1554
1562
// Reject if isolation is enabled.
1555
1563
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1556
1564
this. reject_in_isolation ( "`readlink`" , reject_with) ?;
1557
- // readlink never sets "EPERM". Set "ENOENT".
1558
- this. set_last_error_from_io_error ( ErrorKind :: NotFound ) ?;
1565
+ let eacc = this . eval_libc ( "EACCES" ) ? ;
1566
+ this. set_last_error ( eacc ) ?;
1559
1567
return Ok ( -1 ) ;
1560
1568
}
1561
1569
0 commit comments