@@ -4,8 +4,7 @@ use rustc_target::spec::abi::Abi;
44use self :: shims:: unix:: linux:: epoll:: EvalContextExt as _;
55use self :: shims:: unix:: linux:: eventfd:: EvalContextExt as _;
66use self :: shims:: unix:: linux:: mem:: EvalContextExt as _;
7- use self :: shims:: unix:: linux:: sync:: futex;
8- use crate :: helpers:: check_min_arg_count;
7+ use self :: shims:: unix:: linux:: syscall:: syscall;
98use crate :: machine:: { SIGRTMAX , SIGRTMIN } ;
109use crate :: shims:: unix:: * ;
1110use crate :: * ;
@@ -117,53 +116,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
117116
118117 // Dynamically invoked syscalls
119118 "syscall" => {
120- // We do not use `check_shim` here because `syscall` is variadic. The argument
121- // count is checked bellow.
122- this. check_abi_and_shim_symbol_clash ( abi, Abi :: C { unwind : false } , link_name) ?;
123- // The syscall variadic function is legal to call with more arguments than needed,
124- // extra arguments are simply ignored. The important check is that when we use an
125- // argument, we have to also check all arguments *before* it to ensure that they
126- // have the right type.
127-
128- let sys_getrandom = this. eval_libc ( "SYS_getrandom" ) . to_target_usize ( this) ?;
129- let sys_futex = this. eval_libc ( "SYS_futex" ) . to_target_usize ( this) ?;
130- let sys_eventfd2 = this. eval_libc ( "SYS_eventfd2" ) . to_target_usize ( this) ?;
131-
132- let [ op] = check_min_arg_count ( "syscall" , args) ?;
133- match this. read_target_usize ( op) ? {
134- // `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
135- // is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
136- num if num == sys_getrandom => {
137- // Used by getrandom 0.1
138- // The first argument is the syscall id, so skip over it.
139- let [ _, ptr, len, flags] =
140- check_min_arg_count ( "syscall(SYS_getrandom, ...)" , args) ?;
141-
142- let ptr = this. read_pointer ( ptr) ?;
143- let len = this. read_target_usize ( len) ?;
144- // The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
145- // neither of which have any effect on our current PRNG.
146- // See <https://github.com/rust-lang/rust/pull/79196> for a discussion of argument sizes.
147- let _flags = this. read_scalar ( flags) ?. to_i32 ( ) ?;
148-
149- this. gen_random ( ptr, len) ?;
150- this. write_scalar ( Scalar :: from_target_usize ( len, this) , dest) ?;
151- }
152- // `futex` is used by some synchronization primitives.
153- num if num == sys_futex => {
154- futex ( this, args, dest) ?;
155- }
156- num if num == sys_eventfd2 => {
157- let [ _, initval, flags] =
158- check_min_arg_count ( "syscall(SYS_evetfd2, ...)" , args) ?;
159-
160- let result = this. eventfd ( initval, flags) ?;
161- this. write_int ( result. to_i32 ( ) ?, dest) ?;
162- }
163- num => {
164- throw_unsup_format ! ( "syscall: unsupported syscall number {num}" ) ;
165- }
166- }
119+ syscall ( this, link_name, abi, args, dest) ?;
167120 }
168121
169122 // Miscellaneous
0 commit comments