From 928ce402a41c291e6f746cac903a4a44702c4689 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 2 Apr 2021 01:18:32 -0700 Subject: QHash & QRandomGenerator: cooperate to provide a simpler initial seed Instead of initializing the whole QRandomGenerator::system(), which in turn gets to checking CPUID and whether the HWRNG works, trust the operating system functions for an initial value. On Linux, we'll use 4 or 8 of the 16 bytes of random data that the kernel populates for us on AT_RANDOM. This should make Qt applications not stall on an early system launch without an RNG daemon, if compiled without getentropy() support. And avoids silly mistakes causing recursion, like QTBUG-78007 found. Additionally, qt_random_initial_value() will most likely not throw either. It's marked noexcept, even though SystemGenerator::fillBuffer could throw on Linux, if the current thread is canceled, but Linux also has AT_RANDOM. That leaves the other Unix systems without getentropy() (read: macOS, since the BSDs have getentropy()). Fixes: QTBUG-69555 Change-Id: Id2983978ad544ff79911fffd1671fca1a9f9044d Reviewed-by: Lars Knoll --- src/corelib/global/qrandom.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/corelib/global/qrandom.h') diff --git a/src/corelib/global/qrandom.h b/src/corelib/global/qrandom.h index d6b8bd742e..c59ae4d42d 100644 --- a/src/corelib/global/qrandom.h +++ b/src/corelib/global/qrandom.h @@ -217,6 +217,7 @@ protected: private: Q_CORE_EXPORT quint64 _fillRange(void *buffer, qptrdiff count); + friend quintptr qt_initial_random_value() noexcept; friend class QRandomGenerator64; struct SystemGenerator; struct SystemAndGlobalGenerators; -- cgit v1.2.3