@@ -312,6 +312,29 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
312
312
buf_op : OpTy < ' tcx , Tag > ,
313
313
) -> InterpResult < ' tcx , i32 > {
314
314
let this = self . eval_context_mut ( ) ;
315
+ this. check_no_isolation ( "stat" ) ?;
316
+ // `stat` always follows symlinks.
317
+ this. stat_or_lstat ( true , path_op, buf_op)
318
+ }
319
+
320
+ // `lstat` is used to get symlink metadata.
321
+ fn lstat (
322
+ & mut self ,
323
+ path_op : OpTy < ' tcx , Tag > ,
324
+ buf_op : OpTy < ' tcx , Tag > ,
325
+ ) -> InterpResult < ' tcx , i32 > {
326
+ let this = self . eval_context_mut ( ) ;
327
+ this. check_no_isolation ( "lstat" ) ?;
328
+ this. stat_or_lstat ( false , path_op, buf_op)
329
+ }
330
+
331
+ fn stat_or_lstat (
332
+ & mut self ,
333
+ follow_symlink : bool ,
334
+ path_op : OpTy < ' tcx , Tag > ,
335
+ buf_op : OpTy < ' tcx , Tag > ,
336
+ ) -> InterpResult < ' tcx , i32 > {
337
+ let this = self . eval_context_mut ( ) ;
315
338
316
339
if this. tcx . sess . target . target . target_os . to_lowercase ( ) != "macos" {
317
340
throw_unsup_format ! ( "The `stat` shim is only available for `macos` targets." )
@@ -322,8 +345,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
322
345
323
346
let buf = this. deref_operand ( buf_op) ?;
324
347
325
- // `stat` always follows symlinks. `lstat` is used to get symlink metadata.
326
- let metadata = match FileMetadata :: new ( this, path, true ) ? {
348
+ let metadata = match FileMetadata :: new ( this, path, follow_symlink) ? {
327
349
Some ( metadata) => metadata,
328
350
None => return Ok ( -1 ) ,
329
351
} ;
0 commit comments