Skip to content

Commit 91cf68f

Browse files
committed
Add lstat shim for macos
1 parent 329310f commit 91cf68f

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/shims/foreign_items.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
504504
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
505505
}
506506

507+
"lstat$INODE64" => {
508+
let result = this.lstat(args[0], args[1])?;
509+
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
510+
}
511+
507512
"clock_gettime" => {
508513
let result = this.clock_gettime(args[0], args[1])?;
509514
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;

src/shims/fs.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,29 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
312312
buf_op: OpTy<'tcx, Tag>,
313313
) -> InterpResult<'tcx, i32> {
314314
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();
315338

316339
if this.tcx.sess.target.target.target_os.to_lowercase() != "macos" {
317340
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
322345

323346
let buf = this.deref_operand(buf_op)?;
324347

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)? {
327349
Some(metadata) => metadata,
328350
None => return Ok(-1),
329351
};

0 commit comments

Comments
 (0)