Skip to content

Commit 456c69e

Browse files
committedFeb 26, 2024·
Auto merge of #3326 - rust-lang:rustup-2024-02-26, r=RalfJung
Automatic Rustup also fixes #3308
2 parents bffd41b + aeab7ae commit 456c69e

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
 

‎rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a2f3c0cf880ad819c4eab2b320525b6a31ac6513
1+
0250ef2571185b05701ed9d74fc904c17508a397

‎src/shims/windows/foreign_items.rs

+8
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
427427
this.gen_random(ptr, len.into())?;
428428
this.write_scalar(Scalar::from_bool(true), dest)?;
429429
}
430+
"ProcessPrng" => {
431+
let [ptr, len] =
432+
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
433+
let ptr = this.read_pointer(ptr)?;
434+
let len = this.read_target_usize(len)?;
435+
this.gen_random(ptr, len)?;
436+
this.write_scalar(Scalar::from_i32(1), dest)?;
437+
}
430438
"BCryptGenRandom" => {
431439
let [algorithm, ptr, len, flags] =
432440
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;

‎tests/pass/shims/windows-rand.rs

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use core::ptr::null_mut;
66
// Windows API definitions.
77
type NTSTATUS = i32;
88
type BOOLEAN = u8;
9+
type BOOL = i32; // yes, seriously, BOOL and BOOLEAN are very different...
910
const BCRYPT_USE_SYSTEM_PREFERRED_RNG: u32 = 0x00000002;
1011
const BCRYPT_RNG_ALG_HANDLE: *mut c_void = 0x81 as *mut c_void;
1112
#[link(name = "bcrypt")]
@@ -22,6 +23,16 @@ extern "system" {
2223
#[link_name = "SystemFunction036"]
2324
fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: u32) -> BOOLEAN;
2425
}
26+
#[cfg(target_arch = "x86")]
27+
#[link(name = "bcryptprimitives", kind = "raw-dylib", import_name_type = "undecorated")]
28+
extern "system" {
29+
pub fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL;
30+
}
31+
#[cfg(not(target_arch = "x86"))]
32+
#[link(name = "bcryptprimitives", kind = "raw-dylib")]
33+
extern "system" {
34+
pub fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL;
35+
}
2536

2637
fn main() {
2738
let mut key = [0u8; 24];
@@ -38,4 +49,10 @@ fn main() {
3849
let ret = unsafe { RtlGenRandom(key.as_mut_ptr(), len) };
3950
// RtlGenRandom returns a BOOLEAN where 0 indicates an error
4051
assert_ne!(ret, 0);
52+
53+
let len = key.len();
54+
let ret = unsafe { ProcessPrng(key.as_mut_ptr(), len) };
55+
// ProcessPrng is documented as always returning `TRUE`.
56+
// https://learn.microsoft.com/en-us/windows/win32/seccng/processprng#return-value
57+
assert_eq!(ret, 1);
4158
}

0 commit comments

Comments
 (0)
Please sign in to comment.