@@ -293,22 +293,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
293293 // is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
294294 match this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ? {
295295 id if id == sys_getrandom => {
296- let ptr = this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
297- let len = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
298-
299- // The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
300- // neither of which have any effect on our current PRNG
301- let _flags = this. read_scalar ( args[ 3 ] ) ?. to_i32 ( ) ?;
302-
303- this. gen_random ( ptr, len as usize ) ?;
304- this. write_scalar ( Scalar :: from_uint ( len, dest. layout . size ) , dest) ?;
296+ // The first argument is the syscall id,
297+ // so skip over it.
298+ linux_getrandom ( this, & args[ 1 ..] , dest) ?;
305299 }
306300 id => {
307301 throw_unsup_format ! ( "miri does not support syscall ID {}" , id)
308302 }
309303 }
310304 }
311305
306+ "getrandom" => {
307+ linux_getrandom ( this, args, dest) ?;
308+ }
309+
312310 "dlsym" => {
313311 let _handle = this. read_scalar ( args[ 0 ] ) ?;
314312 let symbol = this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
@@ -969,3 +967,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
969967 return Ok ( None ) ;
970968 }
971969}
970+
971+ // Shims the linux 'getrandom()' syscall.
972+ fn linux_getrandom < ' tcx > (
973+ this : & mut MiriEvalContext < ' _ , ' tcx > ,
974+ args : & [ OpTy < ' tcx , Tag > ] ,
975+ dest : PlaceTy < ' tcx , Tag > ,
976+ ) -> InterpResult < ' tcx > {
977+ let ptr = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
978+ let len = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
979+
980+ // The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
981+ // neither of which have any effect on our current PRNG.
982+ let _flags = this. read_scalar ( args[ 2 ] ) ?. to_i32 ( ) ?;
983+
984+ this. gen_random ( ptr, len as usize ) ?;
985+ this. write_scalar ( Scalar :: from_uint ( len, dest. layout . size ) , dest) ?;
986+ Ok ( ( ) )
987+ }
0 commit comments