16#if QT_CONFIG(getauxval)
20#if QT_CONFIG(getentropy) && __has_include(<sys/random.h>)
21# include <sys/random.h>
22#elif !QT_CONFIG(getentropy) && (!defined(Q_OS_BSD4) || defined(__GLIBC__)) && !defined(Q_OS_WIN)
29# include <private/qcore_unix_p.h>
38DECLSPEC_IMPORT BOOLEAN WINAPI
SystemFunction036(PVOID RandomBuffer, ULONG RandomBufferLength);
47#define Q_ASSERT(cond) assert(cond)
48#define Q_ASSERT_X(cond, x, msg) assert(cond && msg)
49#if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
61#if defined(QT_BUILD_INTERNAL)
67#if QT_CONFIG(getentropy)
86#elif defined(Q_OS_UNIX)
111 return opened_fdp1 - 1;
118 static void closeDevice()
120 int fd =
self().fdp1.loadRelaxed() - 1;
129 int fd = openDevice();
134 return qMax<qsizetype>(
n, 0);
137#elif defined(Q_OS_WIN)
154 static_assert(
sizeof(T) >=
sizeof(
quint32));
155 if (
sizeof(T) ==
sizeof(
quint32)) {
160 std::generate(
begin,
end, [
this]() {
181#elif QT_CONFIG(getentropy)
188#elif defined(Q_OS_BSD4) && !defined(__GLIBC__)
232 *
end++ = foldPointer(
quintptr(
reinterpret_cast<void*
>(strerror)));
234#ifndef QT_BOOTSTRAPPED
242#if QT_CONFIG(getauxval)
247 ulong auxvSeed = getauxval(AT_RANDOM);
249 memcpy(
end,
reinterpret_cast<void *
>(auxvSeed), 16);
263# ifdef AT_SYSINFO_EHDR
265 ulong sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
267 *
end++ = foldPointer(sysinfo_ehdr);
274 std::seed_seq
sseq(scratch,
end);
338#if !defined(Q_OS_INTEGRITY)
375 new (&rng->storage.engine()) RandomEngine(
self()->
sys);
1115constexpr QRandomGenerator::Storage::Storage()
1144 SystemAndGlobalGenerators::PRNGLocker locker(self);
1175 storage.engine() =
other.storage.engine();
1182 qFatal(
"Attempted to overwrite a QRandomGenerator to system() or global().");
1186 storage.engine() =
other.storage.engine();
1195 Q_ASSERT(
this != SystemAndGlobalGenerators::globalNoInit());
1207 new (&storage.engine()) RandomEngine(
s);
1216 storage.engine().discard(
z);
1221 if (rng1.type != rng2.type)
1229 return rng1.storage.engine() == rng2.storage.engine();
1254 SystemAndGlobalGenerators::PRNGLocker
lock(
this);
1255 std::generate(
begin,
end, [
this]() {
return storage.engine()(); });
1265template <
typename Generator,
typename FillBufferType,
typename T>
1268 if constexpr (std::is_member_function_pointer_v<FillBufferType>) {
1270 return (Generator::self().*
f)(
v,
sizeof(*
v));
1273 return f(
v,
sizeof(*
v));
1289#if QT_CONFIG(getauxval) && defined(AT_RANDOM)
1290 auto at_random_ptr =
reinterpret_cast<size_t *
>(getauxval(AT_RANDOM));
1292 return qFromUnaligned<QRandomGenerator::InitialRandomData>(at_random_ptr);
1297 QRandomGenerator::InitialRandomData
v;
1298 for (
int attempts = 16; attempts; --attempts) {
1300 auto fillBuffer = &Generator::fillBuffer;
1301 if (callFillBuffer<Generator>(fillBuffer, &
v) !=
sizeof(
v))
1309 memcpy(
v.data,
data,
sizeof(
v.data));
bool testAndSetOrdered(T expectedValue, T newValue) noexcept
T loadAcquire() const noexcept
static QDeadlineTimer current(Qt::TimerType timerType=Qt::CoarseTimer) noexcept
Returns a QDeadlineTimer that is expired but is guaranteed to contain the current time.
qint64 deadline() const noexcept Q_DECL_PURE_FUNCTION
Returns the absolute time point for the deadline stored in QDeadlineTimer object, calculated in milli...
void unlock() noexcept
Unlocks the mutex.
void lock() noexcept
Locks the mutex.
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()
\inmodule QtCore \reentrant
friend class QRandomGenerator64
static Q_DECL_CONST_FUNCTION QRandomGenerator * system()
\threadsafe
Q_CORE_EXPORT QRandomGenerator & operator=(const QRandomGenerator &other)
Q_CORE_EXPORT void discard(unsigned long long z)
Discards the next z entries from the sequence.
QRandomGenerator(quint32 seedValue=1)
Initializes this QRandomGenerator object with the value seedValue as the seed.
quint32 generate()
Generates a 32-bit random quantity and returns it.
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
\threadsafe
Combined button and popup list for selecting options.
#define Q_BASIC_ATOMIC_INITIALIZER(a)
static int qt_safe_open(const char *pathname, int flags, mode_t mode=0777)
static qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
static int qt_safe_close(int fd)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static ControlElement< T > * ptr(QWidget *widget)
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
static qsizetype callFillBuffer(FillBufferType f, T *v)
static Q_NEVER_INLINE void fallback_fill(quint32 *ptr, qsizetype left) noexcept
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
static void fallback_update_seed(unsigned value)
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
DECLSPEC_IMPORT BOOLEAN WINAPI SystemFunction036(PVOID RandomBuffer, ULONG RandomBufferLength)
QRandomGenerator::InitialRandomData qt_initial_random_value() noexcept
static const struct @7 qt_randomdevice_control
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
unsigned long long quint64
ReturnedValue read(const char *data)
std::seed_seq sseq(seedBuffer, seedBuffer+len)
[3]
QRandomGenerator generator(sseq)
PRNGLocker(const QRandomGenerator *that)
struct QRandomGenerator::SystemAndGlobalGenerators::@19 global_
constexpr SystemAndGlobalGenerators()
static QRandomGenerator64 * system()
static void securelySeed(QRandomGenerator *rng)
QBasicMutex globalPRNGMutex
static SystemAndGlobalGenerators * self()
static QRandomGenerator64 * globalNoInit()
struct QRandomGenerator::SystemAndGlobalGenerators::ShortenedSystem system_
void generate(quint32 *begin, quint32 *end) noexcept(FillBufferNoexcept)
static SystemGenerator & self()
void generate(T *begin, T *end)