From 3418b40dac84d124db68a10fb0e17668139751e9 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 19 Feb 2020 17:28:48 -0500 Subject: [PATCH] remove syscall shim from macos and move getrandom to linux module --- src/shims/foreign_items/posix.rs | 18 ------------------ src/shims/foreign_items/posix/linux.rs | 22 ++++++++++++++++++++-- src/shims/foreign_items/posix/macos.rs | 18 ------------------ 3 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/shims/foreign_items/posix.rs b/src/shims/foreign_items/posix.rs index d82c7eddc7d..a391baa0b22 100644 --- a/src/shims/foreign_items/posix.rs +++ b/src/shims/foreign_items/posix.rs @@ -333,21 +333,3 @@ fn emulate_foreign_item_by_name( 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(()) -} diff --git a/src/shims/foreign_items/posix/linux.rs b/src/shims/foreign_items/posix/linux.rs index 1c03e3cb1cf..8635455b1d7 100644 --- a/src/shims/foreign_items/posix/linux.rs +++ b/src/shims/foreign_items/posix/linux.rs @@ -52,7 +52,7 @@ fn emulate_foreign_item_by_name( 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 @@ fn emulate_foreign_item_by_name( } "getrandom" => { - super::getrandom(this, args, dest)?; + getrandom(this, args, dest)?; } "sched_getaffinity" => { @@ -79,3 +79,21 @@ fn emulate_foreign_item_by_name( 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(()) +} diff --git a/src/shims/foreign_items/posix/macos.rs b/src/shims/foreign_items/posix/macos.rs index bf714626794..8cfe959c393 100644 --- a/src/shims/foreign_items/posix/macos.rs +++ b/src/shims/foreign_items/posix/macos.rs @@ -79,24 +79,6 @@ fn emulate_foreign_item_by_name( 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). - 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), }; -- 2.44.0