Add lstat shim for macos

This commit is contained in:
Christian Poveda 2020-01-07 11:29:25 -05:00
parent 329310fbd6
commit 91cf68fac5
No known key found for this signature in database
GPG Key ID: 27525EF5E7420A50
2 changed files with 29 additions and 2 deletions

View File

@ -504,6 +504,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
}
"lstat$INODE64" => {
let result = this.lstat(args[0], args[1])?;
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
}
"clock_gettime" => {
let result = this.clock_gettime(args[0], args[1])?;
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;

View File

@ -312,6 +312,29 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
buf_op: OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.check_no_isolation("stat")?;
// `stat` always follows symlinks.
this.stat_or_lstat(true, path_op, buf_op)
}
// `lstat` is used to get symlink metadata.
fn lstat(
&mut self,
path_op: OpTy<'tcx, Tag>,
buf_op: OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.check_no_isolation("lstat")?;
this.stat_or_lstat(false, path_op, buf_op)
}
fn stat_or_lstat(
&mut self,
follow_symlink: bool,
path_op: OpTy<'tcx, Tag>,
buf_op: OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if this.tcx.sess.target.target.target_os.to_lowercase() != "macos" {
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
let buf = this.deref_operand(buf_op)?;
// `stat` always follows symlinks. `lstat` is used to get symlink metadata.
let metadata = match FileMetadata::new(this, path, true)? {
let metadata = match FileMetadata::new(this, path, follow_symlink)? {
Some(metadata) => metadata,
None => return Ok(-1),
};