@@ -63,6 +63,105 @@ impl FileHandler {
63
63
}
64
64
}
65
65
66
+ impl < ' mir , ' tcx > EvalContextExtPrivate < ' mir , ' tcx > for crate :: MiriEvalContext < ' mir , ' tcx > { }
67
+ trait EvalContextExtPrivate < ' mir , ' tcx : ' mir > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
68
+ /// Emulate `stat` or `lstat` on the `macos` platform. This function is not intended to be
69
+ /// called directly from `emulate_foreign_item_by_name`, so it does not check if isolation is
70
+ /// disabled or if the target platform is the correct one. Please use `macos_stat` or
71
+ /// `macos_lstat` instead.
72
+ fn macos_stat_or_lstat (
73
+ & mut self ,
74
+ follow_symlink : bool ,
75
+ path_op : OpTy < ' tcx , Tag > ,
76
+ buf_op : OpTy < ' tcx , Tag > ,
77
+ ) -> InterpResult < ' tcx , i32 > {
78
+ let this = self . eval_context_mut ( ) ;
79
+
80
+ let path_scalar = this. read_scalar ( path_op) ?. not_undef ( ) ?;
81
+ let path: PathBuf = this. read_os_str_from_c_str ( path_scalar) ?. into ( ) ;
82
+
83
+ let metadata = match FileMetadata :: from_path ( this, path, follow_symlink) ? {
84
+ Some ( metadata) => metadata,
85
+ None => return Ok ( -1 ) ,
86
+ } ;
87
+ this. macos_stat_write_buf ( metadata, buf_op)
88
+ }
89
+
90
+ fn macos_stat_write_buf (
91
+ & mut self ,
92
+ metadata : FileMetadata ,
93
+ buf_op : OpTy < ' tcx , Tag > ,
94
+ ) -> InterpResult < ' tcx , i32 > {
95
+ let this = self . eval_context_mut ( ) ;
96
+
97
+ let mode: u16 = metadata. mode . to_u16 ( ) ?;
98
+
99
+ let ( access_sec, access_nsec) = metadata. accessed . unwrap_or ( ( 0 , 0 ) ) ;
100
+ let ( created_sec, created_nsec) = metadata. created . unwrap_or ( ( 0 , 0 ) ) ;
101
+ let ( modified_sec, modified_nsec) = metadata. modified . unwrap_or ( ( 0 , 0 ) ) ;
102
+
103
+ let dev_t_layout = this. libc_ty_layout ( "dev_t" ) ?;
104
+ let mode_t_layout = this. libc_ty_layout ( "mode_t" ) ?;
105
+ let nlink_t_layout = this. libc_ty_layout ( "nlink_t" ) ?;
106
+ let ino_t_layout = this. libc_ty_layout ( "ino_t" ) ?;
107
+ let uid_t_layout = this. libc_ty_layout ( "uid_t" ) ?;
108
+ let gid_t_layout = this. libc_ty_layout ( "gid_t" ) ?;
109
+ let time_t_layout = this. libc_ty_layout ( "time_t" ) ?;
110
+ let long_layout = this. libc_ty_layout ( "c_long" ) ?;
111
+ let off_t_layout = this. libc_ty_layout ( "off_t" ) ?;
112
+ let blkcnt_t_layout = this. libc_ty_layout ( "blkcnt_t" ) ?;
113
+ let blksize_t_layout = this. libc_ty_layout ( "blksize_t" ) ?;
114
+ let uint32_t_layout = this. libc_ty_layout ( "uint32_t" ) ?;
115
+
116
+ // We need to add 32 bits of padding after `st_rdev` if we are on a 64-bit platform.
117
+ let pad_layout = if this. tcx . sess . target . ptr_width == 64 {
118
+ uint32_t_layout
119
+ } else {
120
+ this. layout_of ( this. tcx . mk_unit ( ) ) ?
121
+ } ;
122
+
123
+ let imms = [
124
+ immty_from_uint_checked ( 0u128 , dev_t_layout) ?, // st_dev
125
+ immty_from_uint_checked ( mode, mode_t_layout) ?, // st_mode
126
+ immty_from_uint_checked ( 0u128 , nlink_t_layout) ?, // st_nlink
127
+ immty_from_uint_checked ( 0u128 , ino_t_layout) ?, // st_ino
128
+ immty_from_uint_checked ( 0u128 , uid_t_layout) ?, // st_uid
129
+ immty_from_uint_checked ( 0u128 , gid_t_layout) ?, // st_gid
130
+ immty_from_uint_checked ( 0u128 , dev_t_layout) ?, // st_rdev
131
+ immty_from_uint_checked ( 0u128 , pad_layout) ?, // padding for 64-bit targets
132
+ immty_from_uint_checked ( access_sec, time_t_layout) ?, // st_atime
133
+ immty_from_uint_checked ( access_nsec, long_layout) ?, // st_atime_nsec
134
+ immty_from_uint_checked ( modified_sec, time_t_layout) ?, // st_mtime
135
+ immty_from_uint_checked ( modified_nsec, long_layout) ?, // st_mtime_nsec
136
+ immty_from_uint_checked ( 0u128 , time_t_layout) ?, // st_ctime
137
+ immty_from_uint_checked ( 0u128 , long_layout) ?, // st_ctime_nsec
138
+ immty_from_uint_checked ( created_sec, time_t_layout) ?, // st_birthtime
139
+ immty_from_uint_checked ( created_nsec, long_layout) ?, // st_birthtime_nsec
140
+ immty_from_uint_checked ( metadata. size , off_t_layout) ?, // st_size
141
+ immty_from_uint_checked ( 0u128 , blkcnt_t_layout) ?, // st_blocks
142
+ immty_from_uint_checked ( 0u128 , blksize_t_layout) ?, // st_blksize
143
+ immty_from_uint_checked ( 0u128 , uint32_t_layout) ?, // st_flags
144
+ immty_from_uint_checked ( 0u128 , uint32_t_layout) ?, // st_gen
145
+ ] ;
146
+
147
+ let buf = this. deref_operand ( buf_op) ?;
148
+ this. write_packed_immediates ( buf, & imms) ?;
149
+
150
+ Ok ( 0 )
151
+ }
152
+
153
+ /// Function used when a handle is not found inside `FileHandler`. It returns `Ok(-1)`and sets
154
+ /// the last OS error to `libc::EBADF` (invalid file descriptor). This function uses
155
+ /// `T: From<i32>` instead of `i32` directly because some fs functions return different integer
156
+ /// types (like `read`, that returns an `i64`).
157
+ fn handle_not_found < T : From < i32 > > ( & mut self ) -> InterpResult < ' tcx , T > {
158
+ let this = self . eval_context_mut ( ) ;
159
+ let ebadf = this. eval_libc ( "EBADF" ) ?;
160
+ this. set_last_error ( ebadf) ?;
161
+ Ok ( ( -1 ) . into ( ) )
162
+ }
163
+ }
164
+
66
165
impl < ' mir , ' tcx > EvalContextExt < ' mir , ' tcx > for crate :: MiriEvalContext < ' mir , ' tcx > { }
67
166
pub trait EvalContextExt < ' mir , ' tcx : ' mir > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
68
167
fn open (
@@ -432,29 +531,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
432
531
Some ( metadata) => metadata,
433
532
None => return Ok ( -1 ) ,
434
533
} ;
435
- macos_stat_write_buf ( this, metadata, buf_op)
436
- }
437
-
438
- /// Emulate `stat` or `lstat` on the `macos` platform. This function is not intended to be
439
- /// called directly from `emulate_foreign_item_by_name`, so it does not check if isolation is
440
- /// disabled or if the target platform is the correct one. Please use `macos_stat` or
441
- /// `macos_lstat` instead.
442
- fn macos_stat_or_lstat (
443
- & mut self ,
444
- follow_symlink : bool ,
445
- path_op : OpTy < ' tcx , Tag > ,
446
- buf_op : OpTy < ' tcx , Tag > ,
447
- ) -> InterpResult < ' tcx , i32 > {
448
- let this = self . eval_context_mut ( ) ;
449
-
450
- let path_scalar = this. read_scalar ( path_op) ?. not_undef ( ) ?;
451
- let path: PathBuf = this. read_os_str_from_c_str ( path_scalar) ?. into ( ) ;
452
-
453
- let metadata = match FileMetadata :: from_path ( this, path, follow_symlink) ? {
454
- Some ( metadata) => metadata,
455
- None => return Ok ( -1 ) ,
456
- } ;
457
- macos_stat_write_buf ( this, metadata, buf_op)
534
+ this. macos_stat_write_buf ( metadata, buf_op)
458
535
}
459
536
460
537
fn linux_statx (
@@ -620,17 +697,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
620
697
Ok ( 0 )
621
698
}
622
699
623
- /// Function used when a handle is not found inside `FileHandler`. It returns `Ok(-1)`and sets
624
- /// the last OS error to `libc::EBADF` (invalid file descriptor). This function uses
625
- /// `T: From<i32>` instead of `i32` directly because some fs functions return different integer
626
- /// types (like `read`, that returns an `i64`).
627
- fn handle_not_found < T : From < i32 > > ( & mut self ) -> InterpResult < ' tcx , T > {
628
- let this = self . eval_context_mut ( ) ;
629
- let ebadf = this. eval_libc ( "EBADF" ) ?;
630
- this. set_last_error ( ebadf) ?;
631
- Ok ( ( -1 ) . into ( ) )
632
- }
633
-
634
700
fn rename (
635
701
& mut self ,
636
702
oldpath_op : OpTy < ' tcx , Tag > ,
@@ -743,64 +809,3 @@ impl FileMetadata {
743
809
Ok ( Some ( FileMetadata { mode, size, created, accessed, modified } ) )
744
810
}
745
811
}
746
-
747
- fn macos_stat_write_buf < ' tcx , ' mir > (
748
- ecx : & mut MiriEvalContext < ' mir , ' tcx > ,
749
- metadata : FileMetadata ,
750
- buf_op : OpTy < ' tcx , Tag > ,
751
- ) -> InterpResult < ' tcx , i32 > {
752
- let mode: u16 = metadata. mode . to_u16 ( ) ?;
753
-
754
- let ( access_sec, access_nsec) = metadata. accessed . unwrap_or ( ( 0 , 0 ) ) ;
755
- let ( created_sec, created_nsec) = metadata. created . unwrap_or ( ( 0 , 0 ) ) ;
756
- let ( modified_sec, modified_nsec) = metadata. modified . unwrap_or ( ( 0 , 0 ) ) ;
757
-
758
- let dev_t_layout = ecx. libc_ty_layout ( "dev_t" ) ?;
759
- let mode_t_layout = ecx. libc_ty_layout ( "mode_t" ) ?;
760
- let nlink_t_layout = ecx. libc_ty_layout ( "nlink_t" ) ?;
761
- let ino_t_layout = ecx. libc_ty_layout ( "ino_t" ) ?;
762
- let uid_t_layout = ecx. libc_ty_layout ( "uid_t" ) ?;
763
- let gid_t_layout = ecx. libc_ty_layout ( "gid_t" ) ?;
764
- let time_t_layout = ecx. libc_ty_layout ( "time_t" ) ?;
765
- let long_layout = ecx. libc_ty_layout ( "c_long" ) ?;
766
- let off_t_layout = ecx. libc_ty_layout ( "off_t" ) ?;
767
- let blkcnt_t_layout = ecx. libc_ty_layout ( "blkcnt_t" ) ?;
768
- let blksize_t_layout = ecx. libc_ty_layout ( "blksize_t" ) ?;
769
- let uint32_t_layout = ecx. libc_ty_layout ( "uint32_t" ) ?;
770
-
771
- // We need to add 32 bits of padding after `st_rdev` if we are on a 64-bit platform.
772
- let pad_layout = if ecx. tcx . sess . target . ptr_width == 64 {
773
- uint32_t_layout
774
- } else {
775
- ecx. layout_of ( ecx. tcx . mk_unit ( ) ) ?
776
- } ;
777
-
778
- let imms = [
779
- immty_from_uint_checked ( 0u128 , dev_t_layout) ?, // st_dev
780
- immty_from_uint_checked ( mode, mode_t_layout) ?, // st_mode
781
- immty_from_uint_checked ( 0u128 , nlink_t_layout) ?, // st_nlink
782
- immty_from_uint_checked ( 0u128 , ino_t_layout) ?, // st_ino
783
- immty_from_uint_checked ( 0u128 , uid_t_layout) ?, // st_uid
784
- immty_from_uint_checked ( 0u128 , gid_t_layout) ?, // st_gid
785
- immty_from_uint_checked ( 0u128 , dev_t_layout) ?, // st_rdev
786
- immty_from_uint_checked ( 0u128 , pad_layout) ?, // padding for 64-bit targets
787
- immty_from_uint_checked ( access_sec, time_t_layout) ?, // st_atime
788
- immty_from_uint_checked ( access_nsec, long_layout) ?, // st_atime_nsec
789
- immty_from_uint_checked ( modified_sec, time_t_layout) ?, // st_mtime
790
- immty_from_uint_checked ( modified_nsec, long_layout) ?, // st_mtime_nsec
791
- immty_from_uint_checked ( 0u128 , time_t_layout) ?, // st_ctime
792
- immty_from_uint_checked ( 0u128 , long_layout) ?, // st_ctime_nsec
793
- immty_from_uint_checked ( created_sec, time_t_layout) ?, // st_birthtime
794
- immty_from_uint_checked ( created_nsec, long_layout) ?, // st_birthtime_nsec
795
- immty_from_uint_checked ( metadata. size , off_t_layout) ?, // st_size
796
- immty_from_uint_checked ( 0u128 , blkcnt_t_layout) ?, // st_blocks
797
- immty_from_uint_checked ( 0u128 , blksize_t_layout) ?, // st_blksize
798
- immty_from_uint_checked ( 0u128 , uint32_t_layout) ?, // st_flags
799
- immty_from_uint_checked ( 0u128 , uint32_t_layout) ?, // st_gen
800
- ] ;
801
-
802
- let buf = ecx. deref_operand ( buf_op) ?;
803
- ecx. write_packed_immediates ( buf, & imms) ?;
804
-
805
- Ok ( 0 )
806
- }
0 commit comments