From dc3cc7368b319a7fa96cdbe42f731e696a513b83 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 23 Jun 2021 21:48:51 +0200 Subject: [PATCH] Kernel: Don't use function-level static variables When building the kernel for x86_64 the compiler injects calls to __cxa_guard_acquire which depends on a bunch of pthread functions we don't have in the kernel. --- Kernel/Random.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Kernel/Random.cpp b/Kernel/Random.cpp index ca72e613bf..fed7a76261 100644 --- a/Kernel/Random.cpp +++ b/Kernel/Random.cpp @@ -17,6 +17,7 @@ namespace Kernel { static AK::Singleton s_the; +static Atomic s_next_random_value = 1; KernelRng& KernelRng::the() { @@ -88,7 +89,6 @@ size_t EntropySource::next_source { static_cast(EntropySource::Static::M static void do_get_fast_random_bytes(u8* buffer, size_t buffer_size) { - static Atomic next = 1; union { u8 bytes[4]; @@ -97,10 +97,10 @@ static void do_get_fast_random_bytes(u8* buffer, size_t buffer_size) size_t offset = 4; for (size_t i = 0; i < buffer_size; ++i) { if (offset >= 4) { - auto current_next = next.load(); + auto current_next = s_next_random_value.load(); for (;;) { auto new_next = current_next * 1103515245 + 12345; - if (next.compare_exchange_strong(current_next, new_next)) { + if (s_next_random_value.compare_exchange_strong(current_next, new_next)) { u.value = new_next; break; }