@@ -117,14 +117,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
117
117
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
118
118
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
119
119
id if id == sys_getrandom => {
120
+ // Used by getrandom 0.1
120
121
// The first argument is the syscall id, so skip over it.
121
122
if args. len ( ) < 4 {
122
123
throw_ub_format ! (
123
124
"incorrect number of arguments for `getrandom` syscall: got {}, expected at least 4" ,
124
125
args. len( )
125
126
) ;
126
127
}
127
- getrandom ( this, & args[ 1 ] , & args[ 2 ] , & args[ 3 ] , dest) ?;
128
+
129
+ let ptr = this. read_pointer ( & args[ 1 ] ) ?;
130
+ let len = this. read_target_usize ( & args[ 2 ] ) ?;
131
+ // The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
132
+ // neither of which have any effect on our current PRNG.
133
+ // See <https://github.com/rust-lang/rust/pull/79196> for a discussion of argument sizes.
134
+ let _flags = this. read_scalar ( & args[ 3 ] ) ?. to_i32 ( ) ;
135
+
136
+ this. gen_random ( ptr, len) ?;
137
+ this. write_scalar ( Scalar :: from_target_usize ( len, this) , dest) ?;
128
138
}
129
139
// `futex` is used by some synchronization primitives.
130
140
id if id == sys_futex => {
@@ -196,24 +206,3 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
196
206
Ok ( EmulateItemResult :: NeedsJumping )
197
207
}
198
208
}
199
-
200
- // Shims the linux `getrandom` syscall.
201
- fn getrandom < ' tcx > (
202
- this : & mut MiriInterpCx < ' _ , ' tcx > ,
203
- ptr : & OpTy < ' tcx , Provenance > ,
204
- len : & OpTy < ' tcx , Provenance > ,
205
- flags : & OpTy < ' tcx , Provenance > ,
206
- dest : & MPlaceTy < ' tcx , Provenance > ,
207
- ) -> InterpResult < ' tcx > {
208
- let ptr = this. read_pointer ( ptr) ?;
209
- let len = this. read_target_usize ( len) ?;
210
-
211
- // The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
212
- // neither of which have any effect on our current PRNG.
213
- // See <https://github.com/rust-lang/rust/pull/79196> for a discussion of argument sizes.
214
- let _flags = this. read_scalar ( flags) ?. to_i32 ( ) ;
215
-
216
- this. gen_random ( ptr, len) ?;
217
- this. write_scalar ( Scalar :: from_target_usize ( len, this) , dest) ?;
218
- Ok ( ( ) )
219
- }
0 commit comments