diff options
Diffstat (limited to 'compiler-rt/lib/scudo/standalone/linux.cpp')
-rw-r--r-- | compiler-rt/lib/scudo/standalone/linux.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler-rt/lib/scudo/standalone/linux.cpp b/compiler-rt/lib/scudo/standalone/linux.cpp index 6cc8e0c..57171ed 100644 --- a/compiler-rt/lib/scudo/standalone/linux.cpp +++ b/compiler-rt/lib/scudo/standalone/linux.cpp @@ -192,6 +192,12 @@ bool getRandom(void *Buffer, uptr Length, UNUSED bool Blocking) { syscall(SYS_getrandom, Buffer, Length, Blocking ? 0 : GRND_NONBLOCK); if (ReadBytes == static_cast<ssize_t>(Length)) return true; + // If this system call is not implemented in the kernel, then we will try + // and use /dev/urandom. Otherwise, if the syscall fails, return false + // assuming that trying to read /dev/urandom will cause a delay waiting for + // the random data to be usable. + if (errno != ENOSYS) + return false; #endif // defined(SYS_getrandom) // Up to 256 bytes, a read off /dev/urandom will not be interrupted. // Blocking is moot here, O_NONBLOCK has no effect when opening /dev/urandom. |