@@ -35,7 +35,7 @@ struct ErrnoProtect {
3535};
3636
3737// parameters for allocating per-thread random state
38- struct Params {
38+ struct RandomStateMMapParams {
3939 unsigned size_of_opaque_state;
4040 unsigned mmap_prot;
4141 unsigned mmap_flags;
@@ -143,11 +143,11 @@ class MMapContainer {
143143 }
144144};
145145
146- class StateFactory {
146+ class RandomStateFactory {
147147 RawMutex mutex{};
148148 MMapContainer allocations{};
149149 MMapContainer freelist{};
150- Params params{};
150+ RandomStateMMapParams params{};
151151 size_t states_per_page = 0 ;
152152 size_t pages_per_allocation = 0 ;
153153 size_t page_size = 0 ;
@@ -214,7 +214,7 @@ class StateFactory {
214214 return true ;
215215 }
216216
217- static StateFactory *instance ();
217+ static RandomStateFactory *instance ();
218218
219219 void *acquire () {
220220 cpp::lock_guard guard{mutex};
@@ -227,7 +227,7 @@ class StateFactory {
227227 // there should be no need to check this pushing
228228 freelist.push_unchecked (state);
229229 }
230- ~StateFactory () {
230+ ~RandomStateFactory () {
231231 for (auto *allocation : allocations)
232232 munmap (allocation, page_size * pages_per_allocation);
233233 }
@@ -253,28 +253,30 @@ class StateFactory {
253253
254254thread_local bool fork_inflight = false ;
255255thread_local void *tls_state = nullptr ;
256- alignas (StateFactory) static char factory_storage[sizeof (StateFactory)]{};
256+ alignas (RandomStateFactory) static char factory_storage[sizeof (
257+ RandomStateFactory)]{};
257258static CallOnceFlag factory_onceflag = callonce_impl::NOT_CALLED;
258259static bool factory_valid = false ;
259260
260- StateFactory * StateFactory ::instance () {
261+ RandomStateFactory * RandomStateFactory ::instance () {
261262 callonce (&factory_onceflag, []() {
262- auto *factory = new (factory_storage) StateFactory ();
263+ auto *factory = new (factory_storage) RandomStateFactory ();
263264 factory_valid = factory->prepare ();
264265 if (factory_valid)
265266 atexit ([]() {
266- auto factory = reinterpret_cast <StateFactory *>(factory_storage);
267- factory->~StateFactory ();
267+ auto factory = reinterpret_cast <RandomStateFactory *>(factory_storage);
268+ factory->~RandomStateFactory ();
268269 factory_valid = false ;
269270 });
270271 });
271- return factory_valid ? reinterpret_cast <StateFactory *>(factory_storage)
272+ return factory_valid ? reinterpret_cast <RandomStateFactory *>(factory_storage)
272273 : nullptr ;
273274}
274275
275- void StateFactory ::postfork_cleanup () {
276+ void RandomStateFactory ::postfork_cleanup () {
276277 if (factory_valid)
277- reinterpret_cast <StateFactory *>(factory_storage)->~StateFactory ();
278+ reinterpret_cast <RandomStateFactory *>(factory_storage)
279+ ->~RandomStateFactory ();
278280 factory_onceflag = callonce_impl::NOT_CALLED;
279281 factory_valid = false ;
280282}
@@ -287,17 +289,17 @@ void *acquire_tls() {
287289 return nullptr ;
288290 // first acquirement
289291 if (tls_state == nullptr ) {
290- tls_state = StateFactory ::acquire_global ();
292+ tls_state = RandomStateFactory ::acquire_global ();
291293 // if still fails, remember the failure
292294 if (tls_state == nullptr ) {
293295 tls_state = MAP_FAILED;
294296 return nullptr ;
295297 } else {
296298 // register the release callback.
297299 if (__cxa_thread_atexit_impl (
298- [](void *s) { StateFactory ::release_global (s); }, tls_state,
300+ [](void *s) { RandomStateFactory ::release_global (s); }, tls_state,
299301 __dso_handle)) {
300- StateFactory ::release_global (tls_state);
302+ RandomStateFactory ::release_global (tls_state);
301303 tls_state = MAP_FAILED;
302304 return nullptr ;
303305 }
@@ -329,7 +331,7 @@ void random_fill(void *buf, size_t size) {
329331 [state](void *buf, size_t size) {
330332 vdso::TypedSymbol<vdso::VDSOSym::GetRandom> vgetrandom;
331333 int res = vgetrandom (buf, size, 0 , state,
332- StateFactory ::size_of_opaque_state ());
334+ RandomStateFactory ::size_of_opaque_state ());
333335 if (res < 0 ) {
334336 libc_errno = -res;
335337 return -1 ;
@@ -350,7 +352,7 @@ void random_prefork() { fork_inflight = true; }
350352void random_postfork_parent () { fork_inflight = false ; }
351353void random_postfork_child () {
352354 tls_state = nullptr ;
353- StateFactory ::postfork_cleanup ();
355+ RandomStateFactory ::postfork_cleanup ();
354356 fork_inflight = false ;
355357}
356358
0 commit comments