Skip to content

Commit cafe24f

Browse files
committed
Merge #10614: random: fix crash on some 64bit platforms
9af207c random: fix crash on some 64bit platforms (Cory Fields) Tree-SHA512: c9516b69bec224c7e650dfc7c50f04cdd93a1006d515699bc64a311a03662d4ad33a834861194a1649ed212b37fb50aadfb004954cdf8b9bc1dc82f3ea962897
2 parents de8db47 + 9af207c commit cafe24f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/random.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,16 @@ static bool rdrand_supported = false;
7272
static constexpr uint32_t CPUID_F1_ECX_RDRAND = 0x40000000;
7373
static void RDRandInit()
7474
{
75-
//! When calling cpuid function #1, ecx register will have this set if RDRAND is available.
75+
uint32_t eax, ecx, edx;
76+
#if defined(__i386__) && ( defined(__PIC__) || defined(__PIE__))
7677
// Avoid clobbering ebx, as that is used for PIC on x86.
77-
uint32_t eax, tmp, ecx, edx;
78+
uint32_t tmp;
7879
__asm__ ("mov %%ebx, %1; cpuid; mov %1, %%ebx": "=a"(eax), "=g"(tmp), "=c"(ecx), "=d"(edx) : "a"(1));
80+
#else
81+
uint32_t ebx;
82+
__asm__ ("cpuid": "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(1));
83+
#endif
84+
//! When calling cpuid function #1, ecx register will have this set if RDRAND is available.
7985
if (ecx & CPUID_F1_ECX_RDRAND) {
8086
LogPrintf("Using RdRand as entropy source\n");
8187
rdrand_supported = true;

0 commit comments

Comments
 (0)