Skip to content

Commit 24854b4

Browse files
committed
Covert gRandomGenerator into a unique_ptr. Having a static object of type LLRandFlagFib2281 needs a lot of space in the TLB, which is usually fine. Unless libcef gets loaded...
CEF is compiled with static TLS/TLS model initial-exec and then having gRandomGenerator allocation so much space in the TLB will exhaust the available space and CEF cannot be loaded.
1 parent 34e48e6 commit 24854b4

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

indra/llcommon/llrand.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,26 @@
5858
* to restore uniform distribution.
5959
*/
6060

61-
// gRandomGenerator is a stateful static object, which is therefore not
61+
// pRandomGenerator is a stateful static object, which is therefore not
6262
// inherently thread-safe.
63-
static thread_local LLRandLagFib2281 gRandomGenerator(LLUUID::getRandomSeed());
63+
//We use a pointer to not construct a huge object in the TLS space, sadly this is necessary
64+
// due to libcef.so on Linux being compiled with TLS model initial-exec (resulting in
65+
// FLAG STATIC_TLS, see readelf libcef.so). CEFs own TLS objects + LLRandLagFib2281 then will exhaust the
66+
// available TLS space, causing media failure.
67+
68+
static thread_local std::unique_ptr< LLRandLagFib2281 > pRandomGenerator = nullptr;
69+
70+
namespace {
71+
F64 ll_internal_get_rand()
72+
{
73+
if( !pRandomGenerator )
74+
{
75+
pRandomGenerator.reset(new LLRandLagFib2281(LLUUID::getRandomSeed( ) ));
76+
}
77+
78+
return(*pRandomGenerator)();
79+
}
80+
}
6481

6582
// no default implementation, only specific F64 and F32 specializations
6683
template <typename REAL>
@@ -73,7 +90,7 @@ inline F64 ll_internal_random<F64>()
7390
// CPUs (or at least multi-threaded processes) seem to
7491
// occasionally give an obviously incorrect random number -- like
7592
// 5^15 or something. Sooooo, clamp it as described above.
76-
F64 rv{ gRandomGenerator() };
93+
F64 rv{ ll_internal_get_rand() };
7794
if(!((rv >= 0.0) && (rv < 1.0))) return fmod(rv, 1.0);
7895
return rv;
7996
}
@@ -85,7 +102,7 @@ inline F32 ll_internal_random<F32>()
85102
// Per Monty, it's important to clamp using the correct fmodf() rather
86103
// than expanding to F64 for fmod() and then truncating back to F32. Prior
87104
// to this change, we were getting sporadic ll_frand() == 1.0 results.
88-
F32 rv{ narrow<F64>(gRandomGenerator()) };
105+
F32 rv{ narrow<F64>(ll_internal_get_rand()) };
89106
if(!((rv >= 0.0f) && (rv < 1.0f))) return fmodf(rv, 1.0f);
90107
return rv;
91108
}

0 commit comments

Comments
 (0)