On 2017-05-22 14:00 +0100, Jonathan Wakely wrote: > On 18/05/17 19:27 +0800, Xi Ruoyao wrote: > > This patch use ioctl to get entropy of std::random_device using > > /dev/random and /dev/urandom. > > This is a nice addition, thanks. > > N.B. I couldn't apply your patch, several lines had U+00A0 (i.e. > NO-BREAK SPACE) characters where normal spaces should be. I don't know > if this is something your mail client did, but maybe attaching the > patch as a multipart message rather than including it inline in the > body will prevent it in future.
Oh no... Seems my email client destroyed my patch. I'll attach the patch next time. Please wait for PATCH v2. > > diff --git a/libstdc++-v3/config/abi/pre/gnu.ver > > b/libstdc++-v3/config/abi/pre/gnu.ver > > index 3e6e70b..39ad330 100644 > > --- a/libstdc++-v3/config/abi/pre/gnu.ver > > +++ b/libstdc++-v3/config/abi/pre/gnu.ver > > @@ -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; > > The 3.4.23 version is now "closed" because it was used for the GCC 7.1 > release, and so we can't add new symbols to it. That means we need to > bump the library version and create a new GLIBCXX_3.4.24 version node. > The required steps are documented in doc/xml/manual/build_hacking.xml > (and done by the attached patch which I'm testing). I'll do it. Glad to add the first symbol in 3.4.24. > > @@ -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 > > Is RNDGETENTCNT guaranteed to be defined by all versions of > <linux/random.h>? > > Would it be better to check for it explicitly? i.e. > > #if defined _GLIBCXX_HAVE_SYS_IOCTL_H && defined RNDGETENTCNT It has been there since the git repo of Linux kernel was created. I have to check the ancient history of kernel code to know. > > It would also be nice to have a test for this functionality, but since > the available entropy might be zero sometimes we can't guarantee that > a test for a non-zero value will always pass. I've thought about it, but I couldn't find out how to do the test. -- Xi Ruoyao <r...@stu.xidian.edu.cn> School of Aerospace Science and Technology, Xidian University