Skip to content

Commit 3418b40

Browse files
committed
remove syscall shim from macos and move getrandom to linux module
1 parent b213f88 commit 3418b40

File tree

3 files changed

+20
-38
lines changed

3 files changed

+20
-38
lines changed

src/shims/foreign_items/posix.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -333,21 +333,3 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
333333
Ok(true)
334334
}
335335
}
336-
337-
// Shims the posix 'getrandom()' syscall.
338-
fn getrandom<'tcx>(
339-
this: &mut MiriEvalContext<'_, 'tcx>,
340-
args: &[OpTy<'tcx, Tag>],
341-
dest: PlaceTy<'tcx, Tag>,
342-
) -> InterpResult<'tcx> {
343-
let ptr = this.read_scalar(args[0])?.not_undef()?;
344-
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
345-
346-
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
347-
// neither of which have any effect on our current PRNG.
348-
let _flags = this.read_scalar(args[2])?.to_i32()?;
349-
350-
this.gen_random(ptr, len as usize)?;
351-
this.write_scalar(Scalar::from_uint(len, dest.layout.size), dest)?;
352-
Ok(())
353-
}

src/shims/foreign_items/posix/linux.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5252
id if id == sys_getrandom => {
5353
// The first argument is the syscall id,
5454
// so skip over it.
55-
super::getrandom(this, &args[1..], dest)?;
55+
getrandom(this, &args[1..], dest)?;
5656
}
5757
id if id == sys_statx => {
5858
// The first argument is the syscall id,
@@ -65,7 +65,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6565
}
6666

6767
"getrandom" => {
68-
super::getrandom(this, args, dest)?;
68+
getrandom(this, args, dest)?;
6969
}
7070

7171
"sched_getaffinity" => {
@@ -79,3 +79,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7979
Ok(true)
8080
}
8181
}
82+
83+
// Shims the posix 'getrandom()' syscall.
84+
fn getrandom<'tcx>(
85+
this: &mut MiriEvalContext<'_, 'tcx>,
86+
args: &[OpTy<'tcx, Tag>],
87+
dest: PlaceTy<'tcx, Tag>,
88+
) -> InterpResult<'tcx> {
89+
let ptr = this.read_scalar(args[0])?.not_undef()?;
90+
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
91+
92+
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
93+
// neither of which have any effect on our current PRNG.
94+
let _flags = this.read_scalar(args[2])?.to_i32()?;
95+
96+
this.gen_random(ptr, len as usize)?;
97+
this.write_scalar(Scalar::from_uint(len, dest.layout.size), dest)?;
98+
Ok(())
99+
}

src/shims/foreign_items/posix/macos.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7979
this.write_null(dest)?;
8080
}
8181

82-
"syscall" => {
83-
let sys_getrandom = this
84-
.eval_path_scalar(&["libc", "SYS_getrandom"])?
85-
.expect("Failed to get libc::SYS_getrandom")
86-
.to_machine_usize(this)?;
87-
88-
match this.read_scalar(args[0])?.to_machine_usize(this)? {
89-
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
90-
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
91-
id if id == sys_getrandom => {
92-
// The first argument is the syscall id,
93-
// so skip over it.
94-
super::getrandom(this, &args[1..], dest)?;
95-
}
96-
id => throw_unsup_format!("miri does not support syscall ID {}", id),
97-
}
98-
}
99-
10082
_ => throw_unsup_format!("can't call foreign function: {}", link_name),
10183
};
10284

0 commit comments

Comments
 (0)