@@ -657,12 +657,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
657657 }
658658
659659 // `stat` always follows symlinks.
660- let metadata = match FileMetadata :: from_path ( this, & path, true ) ? {
660+ let metadata = match FileMetadata :: from_path ( this, & path, true , dest ) ? {
661661 Some ( metadata) => metadata,
662- None => {
663- this. write_int ( -1 , dest) ?;
664- return Ok ( EmulateItemResult :: NeedsReturn ) ;
665- }
662+ None => return Ok ( EmulateItemResult :: NeedsReturn ) ,
666663 } ;
667664 let res = this. macos_stat_write_buf ( metadata, buf_op) ?;
668665 this. write_int ( res, dest) ?;
@@ -691,12 +688,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
691688 return this. set_libc_err_and_return_neg1 ( "EACCES" , dest) ;
692689 }
693690
694- let metadata = match FileMetadata :: from_path ( this, & path, false ) ? {
691+ let metadata = match FileMetadata :: from_path ( this, & path, false , dest ) ? {
695692 Some ( metadata) => metadata,
696- None => {
697- this. write_int ( -1 , dest) ?;
698- return Ok ( EmulateItemResult :: NeedsReturn ) ;
699- }
693+ None => return Ok ( EmulateItemResult :: NeedsReturn ) ,
700694 } ;
701695 let res = this. macos_stat_write_buf ( metadata, buf_op) ?;
702696 this. write_int ( res, dest) ?;
@@ -724,12 +718,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
724718 return this. set_fd_not_found_and_return_neg1 ( dest) ;
725719 }
726720
727- let metadata = match FileMetadata :: from_fd ( this, fd) ? {
721+ let metadata = match FileMetadata :: from_fd ( this, fd, dest ) ? {
728722 Some ( metadata) => metadata,
729- None => {
730- this. write_int ( -1 , dest) ?;
731- return Ok ( EmulateItemResult :: NeedsReturn ) ;
732- }
723+ None => return Ok ( EmulateItemResult :: NeedsReturn ) ,
733724 } ;
734725 let res = this. macos_stat_write_buf ( metadata, buf_op) ?;
735726 this. write_int ( res, dest) ?;
@@ -814,16 +805,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
814805 // If the path is empty, and the AT_EMPTY_PATH flag is set, we query the open file
815806 // represented by dirfd, whether it's a directory or otherwise.
816807 let metadata = if path. as_os_str ( ) . is_empty ( ) && empty_path_flag {
817- FileMetadata :: from_fd ( this, dirfd) ?
808+ FileMetadata :: from_fd ( this, dirfd, dest ) ?
818809 } else {
819- FileMetadata :: from_path ( this, & path, follow_symlink) ?
810+ FileMetadata :: from_path ( this, & path, follow_symlink, dest ) ?
820811 } ;
821812 let metadata = match metadata {
822813 Some ( metadata) => metadata,
823- None => {
824- this. write_int ( -1 , dest) ?;
825- return Ok ( EmulateItemResult :: NeedsReturn ) ;
826- }
814+ None => return Ok ( EmulateItemResult :: NeedsReturn ) ,
827815 } ;
828816
829817 // The `mode` field specifies the type of the file and the permissions over the file for
@@ -1712,19 +1700,22 @@ impl FileMetadata {
17121700 ecx : & mut MiriInterpCx < ' tcx > ,
17131701 path : & Path ,
17141702 follow_symlink : bool ,
1703+ dest : & MPlaceTy < ' tcx > ,
17151704 ) -> InterpResult < ' tcx , Option < FileMetadata > > {
17161705 let metadata =
17171706 if follow_symlink { std:: fs:: metadata ( path) } else { std:: fs:: symlink_metadata ( path) } ;
17181707
1719- FileMetadata :: from_meta ( ecx, metadata)
1708+ FileMetadata :: from_meta ( ecx, metadata, dest )
17201709 }
17211710
17221711 fn from_fd < ' tcx > (
17231712 ecx : & mut MiriInterpCx < ' tcx > ,
17241713 fd : i32 ,
1714+ dest : & MPlaceTy < ' tcx > ,
17251715 ) -> InterpResult < ' tcx , Option < FileMetadata > > {
17261716 let Some ( file_description) = ecx. machine . fds . get ( fd) else {
1727- return ecx. fd_not_found ( ) . map ( |_: i32 | None ) ;
1717+ ecx. set_fd_not_found_and_return_neg1 ( dest) ?;
1718+ return Ok ( None ) ;
17281719 } ;
17291720
17301721 let file = & file_description
@@ -1738,17 +1729,18 @@ impl FileMetadata {
17381729
17391730 let metadata = file. metadata ( ) ;
17401731 drop ( file_description) ;
1741- FileMetadata :: from_meta ( ecx, metadata)
1732+ FileMetadata :: from_meta ( ecx, metadata, dest )
17421733 }
17431734
17441735 fn from_meta < ' tcx > (
17451736 ecx : & mut MiriInterpCx < ' tcx > ,
17461737 metadata : Result < std:: fs:: Metadata , std:: io:: Error > ,
1738+ dest : & MPlaceTy < ' tcx > ,
17471739 ) -> InterpResult < ' tcx , Option < FileMetadata > > {
17481740 let metadata = match metadata {
17491741 Ok ( metadata) => metadata,
17501742 Err ( e) => {
1751- ecx. set_last_error_from_io_error ( e ) ?;
1743+ ecx. set_io_err_and_return_neg1 ( e , dest ) ?;
17521744 return Ok ( None ) ;
17531745 }
17541746 } ;
0 commit comments