remove syscall shim from macos and move getrandom to linux module
This commit is contained in:
parent
b213f88b58
commit
3418b40dac
3 changed files with 20 additions and 38 deletions
|
|
@ -333,21 +333,3 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
Ok(true)
|
||||
}
|
||||
}
|
||||
|
||||
// Shims the posix 'getrandom()' syscall.
|
||||
fn getrandom<'tcx>(
|
||||
this: &mut MiriEvalContext<'_, 'tcx>,
|
||||
args: &[OpTy<'tcx, Tag>],
|
||||
dest: PlaceTy<'tcx, Tag>,
|
||||
) -> InterpResult<'tcx> {
|
||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
|
||||
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
|
||||
// neither of which have any effect on our current PRNG.
|
||||
let _flags = this.read_scalar(args[2])?.to_i32()?;
|
||||
|
||||
this.gen_random(ptr, len as usize)?;
|
||||
this.write_scalar(Scalar::from_uint(len, dest.layout.size), dest)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
id if id == sys_getrandom => {
|
||||
// The first argument is the syscall id,
|
||||
// so skip over it.
|
||||
super::getrandom(this, &args[1..], dest)?;
|
||||
getrandom(this, &args[1..], dest)?;
|
||||
}
|
||||
id if id == sys_statx => {
|
||||
// The first argument is the syscall id,
|
||||
|
|
@ -65,7 +65,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
}
|
||||
|
||||
"getrandom" => {
|
||||
super::getrandom(this, args, dest)?;
|
||||
getrandom(this, args, dest)?;
|
||||
}
|
||||
|
||||
"sched_getaffinity" => {
|
||||
|
|
@ -79,3 +79,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
Ok(true)
|
||||
}
|
||||
}
|
||||
|
||||
// Shims the posix 'getrandom()' syscall.
|
||||
fn getrandom<'tcx>(
|
||||
this: &mut MiriEvalContext<'_, 'tcx>,
|
||||
args: &[OpTy<'tcx, Tag>],
|
||||
dest: PlaceTy<'tcx, Tag>,
|
||||
) -> InterpResult<'tcx> {
|
||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
|
||||
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
|
||||
// neither of which have any effect on our current PRNG.
|
||||
let _flags = this.read_scalar(args[2])?.to_i32()?;
|
||||
|
||||
this.gen_random(ptr, len as usize)?;
|
||||
this.write_scalar(Scalar::from_uint(len, dest.layout.size), dest)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,24 +79,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
this.write_null(dest)?;
|
||||
}
|
||||
|
||||
"syscall" => {
|
||||
let sys_getrandom = this
|
||||
.eval_path_scalar(&["libc", "SYS_getrandom"])?
|
||||
.expect("Failed to get libc::SYS_getrandom")
|
||||
.to_machine_usize(this)?;
|
||||
|
||||
match this.read_scalar(args[0])?.to_machine_usize(this)? {
|
||||
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
|
||||
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
|
||||
id if id == sys_getrandom => {
|
||||
// The first argument is the syscall id,
|
||||
// so skip over it.
|
||||
super::getrandom(this, &args[1..], dest)?;
|
||||
}
|
||||
id => throw_unsup_format!("miri does not support syscall ID {}", id),
|
||||
}
|
||||
}
|
||||
|
||||
_ => throw_unsup_format!("can't call foreign function: {}", link_name),
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue