Skip to content

Commit aa31003

Browse files
committed
Auto merge of #3326 - rust-lang:rustup-2024-02-26, r=RalfJung
Automatic Rustup also fixes #3308
2 parents bffd41b + 4541dcd commit aa31003

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-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

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ extern "system" {
2222
#[link_name = "SystemFunction036"]
2323
fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: u32) -> BOOLEAN;
2424
}
25+
#[cfg(target_arch = "x86")]
26+
#[link(name = "bcryptprimitives", kind = "raw-dylib", import_name_type = "undecorated")]
27+
extern "system" {
28+
pub fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL;
29+
}
30+
#[cfg(not(target_arch = "x86"))]
31+
#[link(name = "bcryptprimitives", kind = "raw-dylib")]
32+
extern "system" {
33+
pub fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL;
34+
}
2535

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

0 commit comments

Comments
 (0)