Page MenuHomeWildfire Games

Add a getrandom() codepath on Linux
Needs ReviewPublic

Authored by linkmauve on Oct 23 2020, 9:00 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

This syscall works even if /dev/urandom isn’t available, and doesn’t use
a file descriptor, so it should generally be preferred when available.

Ideally that’d be guarded by a libc function check instead of being set
only on Linux, but premake5 apparently doesn’t let me do that.

Test Plan

Check that e.g. userreport.id is still random on Linux.

Event Timeline

linkmauve created this revision.Oct 23 2020, 9:00 PM

Build failure - The Moirai have given mortals hearts that can endure.

builderr-debug-gcc6.txt
../../../source/lib/sysdep/os/unix/unix.cpp:42:24: fatal error: sys/random.h: No such file or directory
 #include <sys/random.h>
                        ^
compilation terminated.
make[1]: *** [obj/lowlevel_Debug/unix.o] Error 1
make: *** [lowlevel] Error 2

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/3323/display/redirect

Successful build - Chance fights ever on the side of the prudent.

builderr-release-macos.txt
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/liblowlevel.a(dbghelp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/liblowlevel.a(file_stats.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/liblowlevel.a(vfs_path.o) has no symbols

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/1671/display/redirect

linkmauve requested review of this revision.Oct 23 2020, 9:06 PM
vladislavbelov added inline comments.
source/lib/sysdep/os/unix/unix.cpp
332

getrandom() was introduced in version 3.17

We have about 0.4% of users with version less than 3.17, are we ready to drop them?

const ssize_t numread. Also I suppose we need to limit the count by IOSIZE_MAX somehow.

335

Is it possible to have numread == 0? Also what's going to happen in case we have EAGAIN?

vladislavbelov added inline comments.Mon, Oct 26, 9:19 PM
source/lib/sysdep/os/unix/unix.cpp
335

Or we have EINTR.

Does getrandom have some performance expectations? Is it similar to /dev/urandom?

Does getrandom have some performance expectations? Is it similar to /dev/urandom?

Without GRND_RANDOM set in its flags, it is equivalent to /dev/urandom, otherwise to /dev/random. Also note that on modern kernels, both nodes are equivalent and provide bytes fast.