@@ -1963,6 +1963,9 @@ GLIBCXX_3.4.23 {
_ZNSt13__future_base13_State_baseV211_Make_ready6_M_setEv;
#endif
+ # std::random_device::_M_getentropy() const
+ _ZNKSt13random_device13_M_getentropyEv;
+
} GLIBCXX_3.4.22;
# Symbols in the support library (libsupc++) have their own tag.
@@ -237,7 +237,7 @@ AC_CHECK_HEADERS([endian.h execinfo.h float.h fp.h ieeefp.h inttypes.h \
locale.h machine/endian.h machine/param.h nan.h stdint.h stdlib.h string.h \
strings.h sys/ipc.h sys/isa_defs.h sys/machine.h sys/param.h \
sys/resource.h sys/sem.h sys/stat.h sys/time.h sys/types.h unistd.h \
-wchar.h wctype.h])
+wchar.h wctype.h linux/random.h])
# Only do link tests if native. Else, hardcode.
if $GLIBCXX_IS_NATIVE; then
@@ -1603,7 +1603,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
double
entropy() const noexcept
- { return 0.0; }
+ {
+#ifdef _GLIBCXX_USE_RANDOM_TR1
+ return this->_M_getentropy();
+#else
+ return 0.0;
+#endif
+ }
result_type
operator()()
@@ -1627,6 +1633,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
result_type _M_getval();
result_type _M_getval_pretr1();
+ double _M_getentropy() const noexcept;
union
{
@@ -38,6 +38,14 @@
# include <unistd.h>
#endif
+#ifdef _GLIBCXX_HAVE_SYS_IOCTL_H
+# include <sys/ioctl.h>
+#endif
+
+#ifdef _GLIBCXX_HAVE_LINUX_RANDOM_H
+# include <linux/random.h>
+#endif
+
namespace std _GLIBCXX_VISIBILITY(default)
{
namespace
@@ -161,6 +169,34 @@ namespace std _GLIBCXX_VISIBILITY(default)
return _M_mt();
}
+ double
+ random_device::_M_getentropy() const noexcept
+ {
+#if defined _GLIBCXX_HAVE_SYS_IOCTL_H && \
+ defined _GLIBCXX_HAVE_LINUX_RANDOM_H
+ if (!_M_file)
+ return 0.0;
+
+ int fd = fileno(static_cast<FILE *>(_M_file));
+ if (fd < 0)
+ return 0.0;
+
+ int ent;
+ if (ioctl(fd, RNDGETENTCNT, &ent) < 0)
+ return 0.0;
+
+ if (ent < 0)
+ return 0.0;
+
+ if (static_cast<unsigned>(ent) > sizeof(result_type) * 8)
+ return static_cast<double>(sizeof(result_type) * 8);
+
+ return static_cast<double>(ent);
+#else
+ return 0.0;
+#endif
+ }
+
template class mersenne_twister_engine<
uint_fast32_t,
32, 624, 397, 31,