@@ -282,14 +282,30 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
282
282
283
283
// Miscellaneous
284
284
"SystemFunction036" => {
285
+ // This is really 'RtlGenRandom'.
285
286
check_abi ( abi, Abi :: System { unwind : false } ) ?;
286
- // The actual name of 'RtlGenRandom'
287
287
let & [ ref ptr, ref len] = check_arg_count ( args) ?;
288
288
let ptr = this. read_scalar ( ptr) ?. check_init ( ) ?;
289
289
let len = this. read_scalar ( len) ?. to_u32 ( ) ?;
290
290
this. gen_random ( ptr, len. into ( ) ) ?;
291
291
this. write_scalar ( Scalar :: from_bool ( true ) , dest) ?;
292
292
}
293
+ "BCryptGenRandom" => {
294
+ check_abi ( abi, Abi :: System { unwind : false } ) ?;
295
+ let & [ ref algorithm, ref ptr, ref len, ref flags] = check_arg_count ( args) ?;
296
+ let algorithm = this. read_scalar ( algorithm) ?;
297
+ let ptr = this. read_scalar ( ptr) ?. check_init ( ) ?;
298
+ let len = this. read_scalar ( len) ?. to_u32 ( ) ?;
299
+ let flags = this. read_scalar ( flags) ?. to_u32 ( ) ?;
300
+ if flags != 2 { // BCRYPT_USE_SYSTEM_PREFERRED_RNG
301
+ throw_unsup_format ! ( "BCryptGenRandom is supported only with the BCRYPT_USE_SYSTEM_PREFERRED_RNG flag" ) ;
302
+ }
303
+ if algorithm. to_machine_usize ( this) ? != 0 {
304
+ throw_unsup_format ! ( "BCryptGenRandom algorithm must be NULL when the flag is BCRYPT_USE_SYSTEM_PREFERRED_RNG" ) ;
305
+ }
306
+ this. gen_random ( ptr, len. into ( ) ) ?;
307
+ this. write_null ( dest) ?; // STATUS_SUCCESS
308
+ }
293
309
"GetConsoleScreenBufferInfo" => {
294
310
check_abi ( abi, Abi :: System { unwind : false } ) ?;
295
311
// `term` needs this, so we fake it.
0 commit comments