mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
Revert "Update fix_fall_back_to_rtlgenrandom_when_bcryptprimitives_dll_is.patch"
This reverts commit fb2ea1104f688fc17dd72ceb193986f9419cb7af.
This commit is contained in:
@@ -1,103 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: John Kleinschmidt <kleinschmidtorama@gmail.com>
|
||||
Date: Wed, 25 Mar 2026 15:24:27 -0400
|
||||
Subject: fix: fall back to RtlGenRandom when bcryptprimitives.dll is
|
||||
unavailable
|
||||
|
||||
When cross-compiling for Windows using Wine, bcryptprimitives.dll may not
|
||||
be available (e.g. Wine 6.0 does not implement it). This causes
|
||||
mksnapshot.exe to crash with a CHECK failure at rand_util_win.cc.
|
||||
|
||||
Fall back to RtlGenRandom (advapi32 SystemFunction036) which is available
|
||||
on Wine and all Windows versions. This only affects the code path when
|
||||
LoadLibraryW for bcryptprimitives.dll fails, so real Windows builds are
|
||||
unaffected.
|
||||
|
||||
diff --git a/base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/rand_util_win.cc b/base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/rand_util_win.cc
|
||||
index 1596bc2a31a29fd1fb08e8d6491253b04b1a5aaa..e37454348919f275a5f39cf3ac5d5e91af528be7 100644
|
||||
--- a/base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/rand_util_win.cc
|
||||
+++ b/base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/rand_util_win.cc
|
||||
@@ -24,16 +24,32 @@ namespace partition_alloc::internal::base {
|
||||
void RandBytes(void* output, size_t output_length) {
|
||||
// Import bcryptprimitives directly rather than cryptbase to avoid opening a
|
||||
// handle to \\Device\KsecDD in the renderer.
|
||||
+ // Falls back to advapi32!RtlGenRandom when bcryptprimitives.dll is unavailable
|
||||
+ // (e.g. when running under Wine during cross-compilation).
|
||||
// Note: we cannot use a magic static here as PA runs too early in process
|
||||
// startup, but this should be safe as the process will be single-threaded
|
||||
// when this first runs.
|
||||
static decltype(&ProcessPrng) process_prng_fn = nullptr;
|
||||
if (!process_prng_fn) {
|
||||
HMODULE hmod = LoadLibraryW(L"bcryptprimitives.dll");
|
||||
- PA_BASE_CHECK(hmod);
|
||||
- process_prng_fn = reinterpret_cast<decltype(&ProcessPrng)>(
|
||||
- GetProcAddress(hmod, "ProcessPrng"));
|
||||
- PA_BASE_CHECK(process_prng_fn);
|
||||
+ if (hmod) {
|
||||
+ process_prng_fn = reinterpret_cast<decltype(&ProcessPrng)>(
|
||||
+ GetProcAddress(hmod, "ProcessPrng"));
|
||||
+ }
|
||||
+ if (!process_prng_fn) {
|
||||
+ // Fallback: use RtlGenRandom from advapi32.dll (available on Wine and
|
||||
+ // older Windows).
|
||||
+ using RtlGenRandomFn = BOOLEAN(WINAPI*)(PVOID, ULONG);
|
||||
+ HMODULE advapi = LoadLibraryW(L"advapi32.dll");
|
||||
+ PA_BASE_CHECK(advapi);
|
||||
+ RtlGenRandomFn rtl_gen_random = reinterpret_cast<RtlGenRandomFn>(
|
||||
+ GetProcAddress(advapi, "SystemFunction036"));
|
||||
+ PA_BASE_CHECK(rtl_gen_random);
|
||||
+ static RtlGenRandomFn stored_fn = rtl_gen_random;
|
||||
+ process_prng_fn = [](PBYTE pbData, SIZE_T cbData) -> BOOL {
|
||||
+ return stored_fn(pbData, static_cast<ULONG>(cbData)) ? TRUE : FALSE;
|
||||
+ };
|
||||
+ }
|
||||
}
|
||||
BOOL success = process_prng_fn(static_cast<BYTE*>(output), output_length);
|
||||
// ProcessPrng is documented to always return TRUE.
|
||||
diff --git a/base/rand_util_win.cc b/base/rand_util_win.cc
|
||||
index c840303611d328c0dae30bdf5da42e6ccd787fea..e6423778e1b2a72b82e04d2dd3d15188b4fa3592 100644
|
||||
--- a/base/rand_util_win.cc
|
||||
+++ b/base/rand_util_win.cc
|
||||
@@ -52,14 +52,36 @@ namespace {
|
||||
|
||||
// Import bcryptprimitives!ProcessPrng rather than cryptbase!RtlGenRandom to
|
||||
// avoid opening a handle to \\Device\KsecDD in the renderer.
|
||||
+// Falls back to advapi32!RtlGenRandom when bcryptprimitives.dll is unavailable
|
||||
+// (e.g. when running under Wine during cross-compilation).
|
||||
decltype(&ProcessPrng) GetProcessPrng() {
|
||||
HMODULE hmod = LoadLibraryW(L"bcryptprimitives.dll");
|
||||
- CHECK(hmod);
|
||||
- decltype(&ProcessPrng) process_prng_fn =
|
||||
- reinterpret_cast<decltype(&ProcessPrng)>(
|
||||
- GetProcAddress(hmod, "ProcessPrng"));
|
||||
- CHECK(process_prng_fn);
|
||||
- return process_prng_fn;
|
||||
+ if (hmod) {
|
||||
+ decltype(&ProcessPrng) process_prng_fn =
|
||||
+ reinterpret_cast<decltype(&ProcessPrng)>(
|
||||
+ GetProcAddress(hmod, "ProcessPrng"));
|
||||
+ if (process_prng_fn) {
|
||||
+ return process_prng_fn;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // Fallback: use RtlGenRandom from advapi32.dll (available on Wine and
|
||||
+ // older Windows). RtlGenRandom has a different signature but we wrap it
|
||||
+ // to match ProcessPrng's BOOL(PBYTE, SIZE_T) contract.
|
||||
+ using RtlGenRandomFn = BOOLEAN(WINAPI*)(PVOID, ULONG);
|
||||
+ HMODULE advapi = LoadLibraryW(L"advapi32.dll");
|
||||
+ CHECK(advapi);
|
||||
+ RtlGenRandomFn rtl_gen_random = reinterpret_cast<RtlGenRandomFn>(
|
||||
+ GetProcAddress(advapi, "SystemFunction036"));
|
||||
+ CHECK(rtl_gen_random);
|
||||
+
|
||||
+ // Store in a static so the lambda-like wrapper can reference it.
|
||||
+ static RtlGenRandomFn stored_fn = rtl_gen_random;
|
||||
+ return [](PBYTE pbData, SIZE_T cbData) -> BOOL {
|
||||
+ // RtlGenRandom takes ULONG; cast is safe because callers never request
|
||||
+ // more than a few hundred bytes at a time.
|
||||
+ return stored_fn(pbData, static_cast<ULONG>(cbData)) ? TRUE : FALSE;
|
||||
+ };
|
||||
}
|
||||
|
||||
void RandBytesInternal(span<uint8_t> output, bool avoid_allocation) {
|
||||
Reference in New Issue
Block a user