@@ -118,7 +118,7 @@ impl UnixFileDescription for FileHandle {
118118
119119impl < ' tcx > EvalContextExtPrivate < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
120120trait EvalContextExtPrivate < ' tcx > : crate :: MiriInterpCxExt < ' tcx > {
121- fn macos_fbsd_solarish_write_stat_buf (
121+ fn write_stat_buf (
122122 & mut self ,
123123 metadata : FileMetadata ,
124124 buf_op : & OpTy < ' tcx > ,
@@ -130,7 +130,11 @@ trait EvalContextExtPrivate<'tcx>: crate::MiriInterpCxExt<'tcx> {
130130 let ( modified_sec, modified_nsec) = metadata. modified . unwrap_or ( ( 0 , 0 ) ) ;
131131 let mode = metadata. mode . to_uint ( this. libc_ty_layout ( "mode_t" ) . size ) ?;
132132
133- let buf = this. deref_pointer_as ( buf_op, this. libc_ty_layout ( "stat" ) ) ?;
133+ // We do *not* use `deref_pointer_as` here since determining the right pointee type
134+ // is highly non-trivial: it depends on which exact alias of the function was invoked
135+ // (e.g. `fstat` vs `fstat64`), and then on FreeBSD it also depends on the ABI level
136+ // which can be different between the libc used by std and the libc used by everyone else.
137+ let buf = this. deref_pointer ( buf_op) ?;
134138 this. write_int_fields_named (
135139 & [
136140 ( "st_dev" , metadata. dev . into ( ) ) ,
@@ -141,8 +145,11 @@ trait EvalContextExtPrivate<'tcx>: crate::MiriInterpCxExt<'tcx> {
141145 ( "st_gid" , metadata. gid . into ( ) ) ,
142146 ( "st_rdev" , 0 ) ,
143147 ( "st_atime" , access_sec. into ( ) ) ,
148+ ( "st_atime_nsec" , access_nsec. into ( ) ) ,
144149 ( "st_mtime" , modified_sec. into ( ) ) ,
150+ ( "st_mtime_nsec" , modified_nsec. into ( ) ) ,
145151 ( "st_ctime" , 0 ) ,
152+ ( "st_ctime_nsec" , 0 ) ,
146153 ( "st_size" , metadata. size . into ( ) ) ,
147154 ( "st_blocks" , 0 ) ,
148155 ( "st_blksize" , 0 ) ,
@@ -153,9 +160,6 @@ trait EvalContextExtPrivate<'tcx>: crate::MiriInterpCxExt<'tcx> {
153160 if matches ! ( & this. tcx. sess. target. os, Os :: MacOs | Os :: FreeBsd ) {
154161 this. write_int_fields_named (
155162 & [
156- ( "st_atime_nsec" , access_nsec. into ( ) ) ,
157- ( "st_mtime_nsec" , modified_nsec. into ( ) ) ,
158- ( "st_ctime_nsec" , 0 ) ,
159163 ( "st_birthtime" , created_sec. into ( ) ) ,
160164 ( "st_birthtime_nsec" , created_nsec. into ( ) ) ,
161165 ( "st_flags" , 0 ) ,
@@ -550,7 +554,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
550554 Err ( err) => return this. set_last_error_and_return_i32 ( err) ,
551555 } ;
552556
553- interp_ok ( Scalar :: from_i32 ( this. macos_fbsd_solarish_write_stat_buf ( metadata, buf_op) ?) )
557+ interp_ok ( Scalar :: from_i32 ( this. write_stat_buf ( metadata, buf_op) ?) )
554558 }
555559
556560 // `lstat` is used to get symlink metadata.
@@ -583,22 +587,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
583587 Err ( err) => return this. set_last_error_and_return_i32 ( err) ,
584588 } ;
585589
586- interp_ok ( Scalar :: from_i32 ( this. macos_fbsd_solarish_write_stat_buf ( metadata, buf_op) ?) )
590+ interp_ok ( Scalar :: from_i32 ( this. write_stat_buf ( metadata, buf_op) ?) )
587591 }
588592
589- fn macos_fbsd_solarish_fstat (
590- & mut self ,
591- fd_op : & OpTy < ' tcx > ,
592- buf_op : & OpTy < ' tcx > ,
593- ) -> InterpResult < ' tcx , Scalar > {
593+ fn fstat ( & mut self , fd_op : & OpTy < ' tcx > , buf_op : & OpTy < ' tcx > ) -> InterpResult < ' tcx , Scalar > {
594594 let this = self . eval_context_mut ( ) ;
595595
596- if !matches ! ( & this. tcx. sess. target. os, Os :: MacOs | Os :: FreeBsd | Os :: Solaris | Os :: Illumos )
597- {
598- panic ! (
599- "`macos_fbsd_solaris_fstat` should not be called on {}" ,
600- this. tcx. sess. target. os
601- ) ;
596+ if !matches ! (
597+ & this. tcx. sess. target. os,
598+ Os :: MacOs | Os :: FreeBsd | Os :: Solaris | Os :: Illumos | Os :: Linux
599+ ) {
600+ panic ! ( "`fstat` should not be called on {}" , this. tcx. sess. target. os) ;
602601 }
603602
604603 let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
@@ -614,7 +613,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
614613 Ok ( metadata) => metadata,
615614 Err ( err) => return this. set_last_error_and_return_i32 ( err) ,
616615 } ;
617- interp_ok ( Scalar :: from_i32 ( this. macos_fbsd_solarish_write_stat_buf ( metadata, buf_op) ?) )
616+ interp_ok ( Scalar :: from_i32 ( this. write_stat_buf ( metadata, buf_op) ?) )
618617 }
619618
620619 fn linux_statx (
0 commit comments