53 #if QT_CONFIG(getauxval)
54 # include <sys/auxv.h>
57 #if QT_CONFIG(getentropy) && __has_include(<sys/random.h>)
58 # include <sys/random.h>
59 #elif !QT_CONFIG(getentropy) && (!defined(Q_OS_BSD4) || defined(__GLIBC__)) && !defined(Q_OS_WIN)
66 # include <private/qcore_unix_p.h>
75 DECLSPEC_IMPORT BOOLEAN WINAPI
SystemFunction036(PVOID RandomBuffer, ULONG RandomBufferLength);
84 #define Q_ASSERT(cond) assert(cond)
85 #define Q_ASSERT_X(cond, x, msg) assert(cond && msg)
86 #if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
98 #if defined(QT_BUILD_INTERNAL)
104 #if QT_CONFIG(getentropy)
109 while (
count - read > 256) {
111 int ret = getentropy(
reinterpret_cast<uchar *
>(
buffer) + read, 256);
123 #elif defined(Q_OS_UNIX)
133 fd = qt_safe_open(
"/dev/urandom", O_RDONLY);
135 fd = qt_safe_open(
"/dev/random", O_RDONLY | O_NONBLOCK);
148 return opened_fdp1 - 1;
155 static void closeDevice()
166 int fd = openDevice();
171 return qMax<qsizetype>(
n, 0);
174 #elif defined(Q_OS_WIN)
191 static_assert(
sizeof(
T) >=
sizeof(
quint32));
206 #if defined(Q_OS_WIN)
207 static void fallback_update_seed(
unsigned) {}
218 #elif QT_CONFIG(getentropy)
219 static void fallback_update_seed(
unsigned) {}
225 #elif defined(Q_OS_BSD4) && !defined(__GLIBC__)
226 static void fallback_update_seed(
unsigned) {}
230 arc4random_buf(ptr,
left *
sizeof(*ptr));
234 static void fallback_update_seed(
unsigned value)
239 seed.fetchAndXorRelaxed(
value);
269 *
end++ = foldPointer(
quintptr(
reinterpret_cast<void*
>(strerror)));
271 #ifndef QT_BOOTSTRAPPED
279 #if QT_CONFIG(getauxval)
284 ulong auxvSeed = getauxval(AT_RANDOM);
286 memcpy(
end,
reinterpret_cast<void *
>(auxvSeed), 16);
300 # ifdef AT_SYSINFO_EHDR
302 ulong sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
304 *
end++ = foldPointer(sysinfo_ehdr);
311 std::seed_seq
sseq(scratch,
end);
315 fallback_update_seed(*ptr);
341 fallback_update_seed(*
buffer);
375 #if !defined(Q_OS_INTEGRITY)
412 new (&
rng->storage.engine()) RandomEngine(
self()->sys);
1152 constexpr QRandomGenerator::Storage::Storage()
1181 SystemAndGlobalGenerators::PRNGLocker locker(
self);
1212 storage.engine() =
other.storage.engine();
1219 qFatal(
"Attempted to overwrite a QRandomGenerator to system() or global().");
1223 storage.engine() =
other.storage.engine();
1232 Q_ASSERT(
this != SystemAndGlobalGenerators::globalNoInit());
1244 new (&storage.engine()) RandomEngine(
s);
1253 storage.engine().discard(
z);
1258 if (rng1.type != rng2.type)
1266 return rng1.storage.engine() == rng2.storage.engine();
1291 SystemAndGlobalGenerators::PRNGLocker
lock(
this);
1302 template <
typename Generator,
typename FillBufferType,
typename T>
1303 static qsizetype callFillBuffer(FillBufferType
f,
T *
v)
1305 if constexpr (std::is_member_function_pointer_v<FillBufferType>) {
1310 return f(
v,
sizeof(*
v));
1326 #if QT_CONFIG(getauxval) && defined(AT_RANDOM)
1327 auto at_random_ptr =
reinterpret_cast<size_t *
>(getauxval(AT_RANDOM));
1329 return qFromUnaligned<QRandomGenerator::InitialRandomData>(at_random_ptr);
1334 QRandomGenerator::InitialRandomData
v;
1335 for (
int attempts = 16; attempts; --attempts) {
1337 auto fillBuffer = &Generator::fillBuffer;
1338 if (callFillBuffer<Generator>(fillBuffer, &
v) !=
sizeof(
v))
1346 memcpy(
v.data,
data,
sizeof(
v.data));
bool testAndSetOrdered(T expectedValue, T newValue) noexcept
T loadAcquire() const noexcept
T loadRelaxed() const noexcept
static QDeadlineTimer current(Qt::TimerType timerType=Qt::CoarseTimer) noexcept
qint64 deadline() const noexcept Q_DECL_PURE_FUNCTION
template< typename Enum > bool operator==(Enum lhs, QFlags< Enum > rhs)
The QMutex class provides access serialization between threads.
The QRandomGenerator64 class allows one to obtain 64-bit random values from a high-quality,...
static Q_CORE_EXPORT QRandomGenerator64 securelySeeded()
static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64 * global()
static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64 * system()
The QRandomGenerator class allows one to obtain random values from a high-quality Random Number Gener...
friend class QRandomGenerator64
static Q_DECL_CONST_FUNCTION QRandomGenerator * system()
Q_CORE_EXPORT QRandomGenerator & operator=(const QRandomGenerator &other)
Q_CORE_EXPORT void discard(unsigned long long z)
QRandomGenerator(quint32 seedValue=1)
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
auto generate(StringRef generatorName, SourceLineInfo const &lineInfo, L const &generatorExpression) -> decltype(std::declval< decltype(generatorExpression())>().get())
#define Q_BASIC_ATOMIC_INITIALIZER(a)
EGLOutputLayerEXT EGLint EGLAttrib value
QT_BEGIN_INCLUDE_NAMESPACE typedef unsigned char uchar
unsigned long long quint64
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
DECLSPEC_IMPORT BOOLEAN WINAPI SystemFunction036(PVOID RandomBuffer, ULONG RandomBufferLength)
QRandomGenerator::InitialRandomData qt_initial_random_value() noexcept
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
std::seed_seq sseq(seedBuffer, seedBuffer+len)
[3]
QRandomGenerator generator(sseq)
PRNGLocker(const QRandomGenerator *that)
static QRandomGenerator64 * system()
struct QRandomGenerator::SystemAndGlobalGenerators::@314 global_
static SystemAndGlobalGenerators * self()
constexpr SystemAndGlobalGenerators()
static QRandomGenerator64 * globalNoInit()
static void securelySeed(QRandomGenerator *rng)
QBasicMutex globalPRNGMutex
struct QRandomGenerator::SystemAndGlobalGenerators::ShortenedSystem system_
void generate(quint32 *begin, quint32 *end) noexcept(FillBufferNoexcept)
static SystemGenerator & self()
void generate(T *begin, T *end)
QThreadStorage< int * > dummy[8]