| ... | ... | @@ -408,7 +408,12 @@ pub fn SetHandleInformation(h: HANDLE, mask: DWORD, flags: DWORD) SetHandleInfor |
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | | pub const RtlGenRandomError = error{Unexpected}; |
| 411 | pub const RtlGenRandomError = error{ |
| 412 | /// `RtlGenRandom` has been known to fail in situations where the system is under heavy load. |
| 413 | /// Unfortunately, it does not call `SetLastError`, so it is not possible to get more specific |
| 414 | /// error information; it could actually be due to an out-of-memory condition, for example. |
| 415 | SystemResources, |
| 416 | }; |
| 412 | 417 | |
| 413 | 418 | /// Call RtlGenRandom() instead of CryptGetRandom() on Windows |
| 414 | 419 | /// https://github.com/rust-lang-nursery/rand/issues/111 |
| ... | ... | @@ -422,7 +427,7 @@ pub fn RtlGenRandom(output: []u8) RtlGenRandomError!void { |
| 422 | 427 | const to_read: ULONG = @min(buff.len, max_read_size); |
| 423 | 428 | |
| 424 | 429 | if (advapi32.RtlGenRandom(buff.ptr, to_read) == 0) { |
| 425 | | return unexpectedError(GetLastError()); |
| 430 | return error.SystemResources; |
| 426 | 431 | } |
| 427 | 432 | |
| 428 | 433 | total_read += to_read; |