Browse Source

Merge #10614: random: fix crash on some 64bit platforms

9af207c81 random: fix crash on some 64bit platforms (Cory Fields)

Tree-SHA512: c9516b69bec224c7e650dfc7c50f04cdd93a1006d515699bc64a311a03662d4ad33a834861194a1649ed212b37fb50aadfb004954cdf8b9bc1dc82f3ea962897
0.15
Pieter Wuille 8 years ago
parent
commit
cafe24f039
No known key found for this signature in database
GPG Key ID: A636E97631F767E0
  1. 10
      src/random.cpp

10
src/random.cpp

@ -72,10 +72,16 @@ static bool rdrand_supported = false;
static constexpr uint32_t CPUID_F1_ECX_RDRAND = 0x40000000; static constexpr uint32_t CPUID_F1_ECX_RDRAND = 0x40000000;
static void RDRandInit() static void RDRandInit()
{ {
//! When calling cpuid function #1, ecx register will have this set if RDRAND is available. uint32_t eax, ecx, edx;
#if defined(__i386__) && ( defined(__PIC__) || defined(__PIE__))
// Avoid clobbering ebx, as that is used for PIC on x86. // Avoid clobbering ebx, as that is used for PIC on x86.
uint32_t eax, tmp, ecx, edx; uint32_t tmp;
__asm__ ("mov %%ebx, %1; cpuid; mov %1, %%ebx": "=a"(eax), "=g"(tmp), "=c"(ecx), "=d"(edx) : "a"(1)); __asm__ ("mov %%ebx, %1; cpuid; mov %1, %%ebx": "=a"(eax), "=g"(tmp), "=c"(ecx), "=d"(edx) : "a"(1));
#else
uint32_t ebx;
__asm__ ("cpuid": "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(1));
#endif
//! When calling cpuid function #1, ecx register will have this set if RDRAND is available.
if (ecx & CPUID_F1_ECX_RDRAND) { if (ecx & CPUID_F1_ECX_RDRAND) {
LogPrintf("Using RdRand as entropy source\n"); LogPrintf("Using RdRand as entropy source\n");
rdrand_supported = true; rdrand_supported = true;

Loading…
Cancel
Save