@@ -851,8 +851,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
851851 // Reject if isolation is enabled.
852852 if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
853853 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 ) ?;
856856 return Ok ( -1 ) ;
857857 }
858858
@@ -872,8 +872,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
872872 // Reject if isolation is enabled.
873873 if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
874874 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 ) ?;
877877 return Ok ( -1 ) ;
878878 }
879879
@@ -917,14 +917,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
917917
918918 this. assert_target_os ( "linux" , "statx" ) ;
919919
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-
928920 let statxbuf_ptr = this. read_pointer ( statxbuf_op) ?;
929921 let pathname_ptr = this. read_pointer ( pathname_op) ?;
930922
@@ -973,6 +965,22 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
973965 )
974966 }
975967
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+
976984 // the `_mask_op` paramter specifies the file information that the caller requested.
977985 // However `statx` is allowed to return information that was not requested or to not
978986 // 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
11671175 // Reject if isolation is enabled.
11681176 if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
11691177 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 ) ?;
11721180 return Ok ( Scalar :: null_ptr ( this) ) ;
11731181 }
11741182
@@ -1422,8 +1430,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
14221430 // Reject if isolation is enabled.
14231431 if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
14241432 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 ( ) ;
14271435 }
14281436
14291437 let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
@@ -1554,8 +1562,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
15541562 // Reject if isolation is enabled.
15551563 if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
15561564 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 ) ?;
15591567 return Ok ( -1 ) ;
15601568 }
15611569
0 commit comments