@@ -657,12 +657,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
657
657
}
658
658
659
659
// `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 ) ? {
661
661
Some ( metadata) => metadata,
662
- None => {
663
- this. write_int ( -1 , dest) ?;
664
- return Ok ( EmulateItemResult :: NeedsReturn ) ;
665
- }
662
+ None => return Ok ( EmulateItemResult :: NeedsReturn ) ,
666
663
} ;
667
664
let res = this. macos_stat_write_buf ( metadata, buf_op) ?;
668
665
this. write_int ( res, dest) ?;
@@ -691,12 +688,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
691
688
return this. set_libc_err_and_return_neg1 ( "EACCES" , dest) ;
692
689
}
693
690
694
- let metadata = match FileMetadata :: from_path ( this, & path, false ) ? {
691
+ let metadata = match FileMetadata :: from_path ( this, & path, false , dest ) ? {
695
692
Some ( metadata) => metadata,
696
- None => {
697
- this. write_int ( -1 , dest) ?;
698
- return Ok ( EmulateItemResult :: NeedsReturn ) ;
699
- }
693
+ None => return Ok ( EmulateItemResult :: NeedsReturn ) ,
700
694
} ;
701
695
let res = this. macos_stat_write_buf ( metadata, buf_op) ?;
702
696
this. write_int ( res, dest) ?;
@@ -724,12 +718,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
724
718
return this. set_fd_not_found_and_return_neg1 ( dest) ;
725
719
}
726
720
727
- let metadata = match FileMetadata :: from_fd ( this, fd) ? {
721
+ let metadata = match FileMetadata :: from_fd ( this, fd, dest ) ? {
728
722
Some ( metadata) => metadata,
729
- None => {
730
- this. write_int ( -1 , dest) ?;
731
- return Ok ( EmulateItemResult :: NeedsReturn ) ;
732
- }
723
+ None => return Ok ( EmulateItemResult :: NeedsReturn ) ,
733
724
} ;
734
725
let res = this. macos_stat_write_buf ( metadata, buf_op) ?;
735
726
this. write_int ( res, dest) ?;
@@ -814,16 +805,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
814
805
// If the path is empty, and the AT_EMPTY_PATH flag is set, we query the open file
815
806
// represented by dirfd, whether it's a directory or otherwise.
816
807
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 ) ?
818
809
} else {
819
- FileMetadata :: from_path ( this, & path, follow_symlink) ?
810
+ FileMetadata :: from_path ( this, & path, follow_symlink, dest ) ?
820
811
} ;
821
812
let metadata = match metadata {
822
813
Some ( metadata) => metadata,
823
- None => {
824
- this. write_int ( -1 , dest) ?;
825
- return Ok ( EmulateItemResult :: NeedsReturn ) ;
826
- }
814
+ None => return Ok ( EmulateItemResult :: NeedsReturn ) ,
827
815
} ;
828
816
829
817
// The `mode` field specifies the type of the file and the permissions over the file for
@@ -1712,19 +1700,22 @@ impl FileMetadata {
1712
1700
ecx : & mut MiriInterpCx < ' tcx > ,
1713
1701
path : & Path ,
1714
1702
follow_symlink : bool ,
1703
+ dest : & MPlaceTy < ' tcx > ,
1715
1704
) -> InterpResult < ' tcx , Option < FileMetadata > > {
1716
1705
let metadata =
1717
1706
if follow_symlink { std:: fs:: metadata ( path) } else { std:: fs:: symlink_metadata ( path) } ;
1718
1707
1719
- FileMetadata :: from_meta ( ecx, metadata)
1708
+ FileMetadata :: from_meta ( ecx, metadata, dest )
1720
1709
}
1721
1710
1722
1711
fn from_fd < ' tcx > (
1723
1712
ecx : & mut MiriInterpCx < ' tcx > ,
1724
1713
fd : i32 ,
1714
+ dest : & MPlaceTy < ' tcx > ,
1725
1715
) -> InterpResult < ' tcx , Option < FileMetadata > > {
1726
1716
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 ) ;
1728
1719
} ;
1729
1720
1730
1721
let file = & file_description
@@ -1738,17 +1729,18 @@ impl FileMetadata {
1738
1729
1739
1730
let metadata = file. metadata ( ) ;
1740
1731
drop ( file_description) ;
1741
- FileMetadata :: from_meta ( ecx, metadata)
1732
+ FileMetadata :: from_meta ( ecx, metadata, dest )
1742
1733
}
1743
1734
1744
1735
fn from_meta < ' tcx > (
1745
1736
ecx : & mut MiriInterpCx < ' tcx > ,
1746
1737
metadata : Result < std:: fs:: Metadata , std:: io:: Error > ,
1738
+ dest : & MPlaceTy < ' tcx > ,
1747
1739
) -> InterpResult < ' tcx , Option < FileMetadata > > {
1748
1740
let metadata = match metadata {
1749
1741
Ok ( metadata) => metadata,
1750
1742
Err ( e) => {
1751
- ecx. set_last_error_from_io_error ( e ) ?;
1743
+ ecx. set_io_err_and_return_neg1 ( e , dest ) ?;
1752
1744
return Ok ( None ) ;
1753
1745
}
1754
1746
} ;
0 commit comments