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