@@ -657,7 +657,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
657
657
& mut self ,
658
658
path_op : & OpTy < ' tcx > ,
659
659
buf_op : & OpTy < ' tcx > ,
660
- ) -> InterpResult < ' tcx , Scalar > {
660
+ dest : & MPlaceTy < ' tcx > ,
661
+ ) -> InterpResult < ' tcx > {
661
662
let this = self . eval_context_mut ( ) ;
662
663
663
664
if !matches ! ( & * this. tcx. sess. target. os, "macos" | "freebsd" ) {
@@ -670,26 +671,25 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
670
671
// Reject if isolation is enabled.
671
672
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
672
673
this. reject_in_isolation ( "`stat`" , reject_with) ?;
673
- let eacc = this. eval_libc ( "EACCES" ) ;
674
- this. set_last_error ( eacc) ?;
675
- return Ok ( Scalar :: from_i32 ( -1 ) ) ;
674
+ return this. set_libc_err_and_return_neg1 ( "EACCES" , dest) ;
676
675
}
677
676
678
677
// `stat` always follows symlinks.
679
678
let metadata = match FileMetadata :: from_path ( this, & path, true ) ? {
680
679
Some ( metadata) => metadata,
681
- None => return Ok ( Scalar :: from_i32 ( - 1 ) ) , // `FileMetadata` has set errno
680
+ None => return this . write_int ( - 1 , dest ) , // `FileMetadata` has set errno
682
681
} ;
683
-
684
- Ok ( Scalar :: from_i32 ( this. macos_stat_write_buf ( metadata , buf_op ) ? ) )
682
+ let res = this . macos_stat_write_buf ( metadata , buf_op ) ? ;
683
+ this. write_int ( res , dest )
685
684
}
686
685
687
686
// `lstat` is used to get symlink metadata.
688
687
fn macos_fbsd_lstat (
689
688
& mut self ,
690
689
path_op : & OpTy < ' tcx > ,
691
690
buf_op : & OpTy < ' tcx > ,
692
- ) -> InterpResult < ' tcx , Scalar > {
691
+ dest : & MPlaceTy < ' tcx > ,
692
+ ) -> InterpResult < ' tcx > {
693
693
let this = self . eval_context_mut ( ) ;
694
694
695
695
if !matches ! ( & * this. tcx. sess. target. os, "macos" | "freebsd" ) {
@@ -702,24 +702,23 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
702
702
// Reject if isolation is enabled.
703
703
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
704
704
this. reject_in_isolation ( "`lstat`" , reject_with) ?;
705
- let eacc = this. eval_libc ( "EACCES" ) ;
706
- this. set_last_error ( eacc) ?;
707
- return Ok ( Scalar :: from_i32 ( -1 ) ) ;
705
+ return this. set_libc_err_and_return_neg1 ( "EACCES" , dest) ;
708
706
}
709
707
710
708
let metadata = match FileMetadata :: from_path ( this, & path, false ) ? {
711
709
Some ( metadata) => metadata,
712
- None => return Ok ( Scalar :: from_i32 ( - 1 ) ) , // `FileMetadata` has set errno
710
+ None => return this . write_int ( - 1 , dest ) , // `FileMetadata` has set errno
713
711
} ;
714
-
715
- Ok ( Scalar :: from_i32 ( this. macos_stat_write_buf ( metadata , buf_op ) ? ) )
712
+ let res = this . macos_stat_write_buf ( metadata , buf_op ) ? ;
713
+ this. write_int ( res , dest )
716
714
}
717
715
718
716
fn macos_fbsd_fstat (
719
717
& mut self ,
720
718
fd_op : & OpTy < ' tcx > ,
721
719
buf_op : & OpTy < ' tcx > ,
722
- ) -> InterpResult < ' tcx , Scalar > {
720
+ dest : & MPlaceTy < ' tcx > ,
721
+ ) -> InterpResult < ' tcx > {
723
722
let this = self . eval_context_mut ( ) ;
724
723
725
724
if !matches ! ( & * this. tcx. sess. target. os, "macos" | "freebsd" ) {
@@ -731,15 +730,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
731
730
// Reject if isolation is enabled.
732
731
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
733
732
this. reject_in_isolation ( "`fstat`" , reject_with) ?;
734
- // Set error code as "EBADF" (bad fd)
735
- return Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ?) ) ;
733
+ return this. set_libc_err_and_return_neg1 ( "EBADF" , dest) ;
736
734
}
737
735
738
736
let metadata = match FileMetadata :: from_fd_num ( this, fd) ? {
739
737
Some ( metadata) => metadata,
740
- None => return Ok ( Scalar :: from_i32 ( - 1 ) ) ,
738
+ None => return this . write_int ( - 1 , dest ) , // `FileMetadata` has set errno
741
739
} ;
742
- Ok ( Scalar :: from_i32 ( this. macos_stat_write_buf ( metadata, buf_op) ?) )
740
+ let res = this. macos_stat_write_buf ( metadata, buf_op) ?;
741
+ this. write_int ( res, dest)
743
742
}
744
743
745
744
fn linux_statx (
@@ -1138,7 +1137,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1138
1137
dirp_op : & OpTy < ' tcx > ,
1139
1138
entry_op : & OpTy < ' tcx > ,
1140
1139
result_op : & OpTy < ' tcx > ,
1141
- ) -> InterpResult < ' tcx , Scalar > {
1140
+ dest : & MPlaceTy < ' tcx > ,
1141
+ ) -> InterpResult < ' tcx > {
1142
1142
let this = self . eval_context_mut ( ) ;
1143
1143
1144
1144
if !matches ! ( & * this. tcx. sess. target. os, "macos" | "freebsd" ) {
@@ -1150,14 +1150,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1150
1150
// Reject if isolation is enabled.
1151
1151
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1152
1152
this. reject_in_isolation ( "`readdir_r`" , reject_with) ?;
1153
- // Set error code as "EBADF" (bad fd)
1154
- return Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ? ) ) ;
1153
+ // return positive error number on error
1154
+ return this . write_scalar ( this. eval_libc ( "EBADF" ) , dest ) ;
1155
1155
}
1156
1156
1157
1157
let open_dir = this. machine . dirs . streams . get_mut ( & dirp) . ok_or_else ( || {
1158
1158
err_unsup_format ! ( "the DIR pointer passed to readdir_r did not come from opendir" )
1159
1159
} ) ?;
1160
- Ok ( Scalar :: from_i32 ( match open_dir. read_dir . next ( ) {
1160
+ match open_dir. read_dir . next ( ) {
1161
1161
Some ( Ok ( dir_entry) ) => {
1162
1162
// Write into entry, write pointer to result, return 0 on success.
1163
1163
// The name is written with write_os_str_to_c_str, while the rest of the
@@ -1234,26 +1234,27 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1234
1234
1235
1235
let result_place = this. deref_pointer ( result_op) ?;
1236
1236
this. write_scalar ( this. read_scalar ( entry_op) ?, & result_place) ?;
1237
-
1238
- 0
1237
+ this. write_null ( dest) ?;
1239
1238
}
1240
1239
None => {
1241
1240
// end of stream: return 0, assign *result=NULL
1242
1241
this. write_null ( & this. deref_pointer ( result_op) ?) ?;
1243
- 0
1242
+ this . write_null ( dest ) ? ;
1244
1243
}
1245
1244
Some ( Err ( e) ) =>
1246
1245
match e. raw_os_error ( ) {
1247
1246
// return positive error number on error
1248
- Some ( error) => error,
1247
+ Some ( error) => this . write_int ( error, dest ) ? ,
1249
1248
None => {
1250
1249
throw_unsup_format ! (
1251
1250
"the error {} couldn't be converted to a return value" ,
1252
1251
e
1253
1252
)
1254
1253
}
1255
1254
} ,
1256
- } ) )
1255
+ }
1256
+
1257
+ Ok ( ( ) )
1257
1258
}
1258
1259
1259
1260
fn closedir ( & mut self , dirp_op : & OpTy < ' tcx > ) -> InterpResult < ' tcx , Scalar > {
0 commit comments