Skip to content

Commit 20e31db

Browse files
committed
fix newer getrandom on Windows
1 parent 0f7c015 commit 20e31db

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/shims/windows/foreign_items.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,30 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
282282

283283
// Miscellaneous
284284
"SystemFunction036" => {
285+
// This is really 'RtlGenRandom'.
285286
check_abi(abi, Abi::System { unwind: false })?;
286-
// The actual name of 'RtlGenRandom'
287287
let &[ref ptr, ref len] = check_arg_count(args)?;
288288
let ptr = this.read_scalar(ptr)?.check_init()?;
289289
let len = this.read_scalar(len)?.to_u32()?;
290290
this.gen_random(ptr, len.into())?;
291291
this.write_scalar(Scalar::from_bool(true), dest)?;
292292
}
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+
}
293309
"GetConsoleScreenBufferInfo" => {
294310
check_abi(abi, Abi::System { unwind: false })?;
295311
// `term` needs this, so we fake it.

0 commit comments

Comments
 (0)