@@ -265,47 +265,59 @@ impl FileDescription for FileHandle {
265265
266266impl < ' tcx > EvalContextExtPrivate < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
267267trait EvalContextExtPrivate < ' tcx > : crate :: MiriInterpCxExt < ' tcx > {
268- fn macos_stat_write_buf (
268+ fn macos_fbsd_solaris_write_buf (
269269 & mut self ,
270270 metadata : FileMetadata ,
271271 buf_op : & OpTy < ' tcx > ,
272272 ) -> InterpResult < ' tcx , i32 > {
273273 let this = self . eval_context_mut ( ) ;
274274
275- let mode: u16 = metadata. mode . to_u16 ( ) ?;
276-
277275 let ( access_sec, access_nsec) = metadata. accessed . unwrap_or ( ( 0 , 0 ) ) ;
278276 let ( created_sec, created_nsec) = metadata. created . unwrap_or ( ( 0 , 0 ) ) ;
279277 let ( modified_sec, modified_nsec) = metadata. modified . unwrap_or ( ( 0 , 0 ) ) ;
278+ let mode = metadata. mode . to_uint ( this. libc_ty_layout ( "mode_t" ) . size ) ?;
280279
281280 let buf = this. deref_pointer_as ( buf_op, this. libc_ty_layout ( "stat" ) ) ?;
282-
283281 this. write_int_fields_named (
284282 & [
285283 ( "st_dev" , 0 ) ,
286- ( "st_mode" , mode. into ( ) ) ,
284+ ( "st_mode" , mode. try_into ( ) . unwrap ( ) ) ,
287285 ( "st_nlink" , 0 ) ,
288286 ( "st_ino" , 0 ) ,
289287 ( "st_uid" , 0 ) ,
290288 ( "st_gid" , 0 ) ,
291289 ( "st_rdev" , 0 ) ,
292290 ( "st_atime" , access_sec. into ( ) ) ,
293- ( "st_atime_nsec" , access_nsec. into ( ) ) ,
294291 ( "st_mtime" , modified_sec. into ( ) ) ,
295- ( "st_mtime_nsec" , modified_nsec. into ( ) ) ,
296292 ( "st_ctime" , 0 ) ,
297- ( "st_ctime_nsec" , 0 ) ,
298- ( "st_birthtime" , created_sec. into ( ) ) ,
299- ( "st_birthtime_nsec" , created_nsec. into ( ) ) ,
300293 ( "st_size" , metadata. size . into ( ) ) ,
301294 ( "st_blocks" , 0 ) ,
302295 ( "st_blksize" , 0 ) ,
303- ( "st_flags" , 0 ) ,
304- ( "st_gen" , 0 ) ,
305296 ] ,
306297 & buf,
307298 ) ?;
308299
300+ if matches ! ( & * this. tcx. sess. target. os, "macos" | "freebsd" ) {
301+ this. write_int_fields_named (
302+ & [
303+ ( "st_atime_nsec" , access_nsec. into ( ) ) ,
304+ ( "st_mtime_nsec" , modified_nsec. into ( ) ) ,
305+ ( "st_ctime_nsec" , 0 ) ,
306+ ( "st_birthtime" , created_sec. into ( ) ) ,
307+ ( "st_birthtime_nsec" , created_nsec. into ( ) ) ,
308+ ( "st_flags" , 0 ) ,
309+ ( "st_gen" , 0 ) ,
310+ ] ,
311+ & buf,
312+ ) ?;
313+ }
314+
315+ if matches ! ( & * this. tcx. sess. target. os, "solaris" | "illumos" ) {
316+ // FIXME: write st_fstype field once libc is updated.
317+ // https://github.com/rust-lang/libc/pull/4145
318+ //this.write_int_fields_named(&[("st_fstype", 0)], &buf)?;
319+ }
320+
309321 interp_ok ( 0 )
310322 }
311323
@@ -648,15 +660,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
648660 interp_ok ( Scalar :: from_i32 ( this. try_unwrap_io_result ( result) ?) )
649661 }
650662
651- fn macos_fbsd_stat (
663+ fn macos_fbsd_solaris_stat (
652664 & mut self ,
653665 path_op : & OpTy < ' tcx > ,
654666 buf_op : & OpTy < ' tcx > ,
655667 ) -> InterpResult < ' tcx , Scalar > {
656668 let this = self . eval_context_mut ( ) ;
657669
658- if !matches ! ( & * this. tcx. sess. target. os, "macos" | "freebsd" ) {
659- panic ! ( "`macos_fbsd_stat ` should not be called on {}" , this. tcx. sess. target. os) ;
670+ if !matches ! ( & * this. tcx. sess. target. os, "macos" | "freebsd" | "solaris" | "illumos" ) {
671+ panic ! ( "`macos_fbsd_solaris_stat ` should not be called on {}" , this. tcx. sess. target. os) ;
660672 }
661673
662674 let path_scalar = this. read_pointer ( path_op) ?;
@@ -674,19 +686,22 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
674686 Err ( err) => return this. set_last_error_and_return_i32 ( err) ,
675687 } ;
676688
677- interp_ok ( Scalar :: from_i32 ( this. macos_stat_write_buf ( metadata, buf_op) ?) )
689+ interp_ok ( Scalar :: from_i32 ( this. macos_fbsd_solaris_write_buf ( metadata, buf_op) ?) )
678690 }
679691
680692 // `lstat` is used to get symlink metadata.
681- fn macos_fbsd_lstat (
693+ fn macos_fbsd_solaris_lstat (
682694 & mut self ,
683695 path_op : & OpTy < ' tcx > ,
684696 buf_op : & OpTy < ' tcx > ,
685697 ) -> InterpResult < ' tcx , Scalar > {
686698 let this = self . eval_context_mut ( ) ;
687699
688- if !matches ! ( & * this. tcx. sess. target. os, "macos" | "freebsd" ) {
689- panic ! ( "`macos_fbsd_lstat` should not be called on {}" , this. tcx. sess. target. os) ;
700+ if !matches ! ( & * this. tcx. sess. target. os, "macos" | "freebsd" | "solaris" | "illumos" ) {
701+ panic ! (
702+ "`macos_fbsd_solaris_lstat` should not be called on {}" ,
703+ this. tcx. sess. target. os
704+ ) ;
690705 }
691706
692707 let path_scalar = this. read_pointer ( path_op) ?;
@@ -703,18 +718,21 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
703718 Err ( err) => return this. set_last_error_and_return_i32 ( err) ,
704719 } ;
705720
706- interp_ok ( Scalar :: from_i32 ( this. macos_stat_write_buf ( metadata, buf_op) ?) )
721+ interp_ok ( Scalar :: from_i32 ( this. macos_fbsd_solaris_write_buf ( metadata, buf_op) ?) )
707722 }
708723
709- fn macos_fbsd_fstat (
724+ fn macos_fbsd_solaris_fstat (
710725 & mut self ,
711726 fd_op : & OpTy < ' tcx > ,
712727 buf_op : & OpTy < ' tcx > ,
713728 ) -> InterpResult < ' tcx , Scalar > {
714729 let this = self . eval_context_mut ( ) ;
715730
716- if !matches ! ( & * this. tcx. sess. target. os, "macos" | "freebsd" ) {
717- panic ! ( "`macos_fbsd_fstat` should not be called on {}" , this. tcx. sess. target. os) ;
731+ if !matches ! ( & * this. tcx. sess. target. os, "macos" | "freebsd" | "solaris" | "illumos" ) {
732+ panic ! (
733+ "`macos_fbsd_solaris_fstat` should not be called on {}" ,
734+ this. tcx. sess. target. os
735+ ) ;
718736 }
719737
720738 let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
@@ -730,7 +748,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
730748 Ok ( metadata) => metadata,
731749 Err ( err) => return this. set_last_error_and_return_i32 ( err) ,
732750 } ;
733- interp_ok ( Scalar :: from_i32 ( this. macos_stat_write_buf ( metadata, buf_op) ?) )
751+ interp_ok ( Scalar :: from_i32 ( this. macos_fbsd_solaris_write_buf ( metadata, buf_op) ?) )
734752 }
735753
736754 fn linux_statx (
0 commit comments