1 --- src/3rdparty/chromium/base/rand_util_posix.cc.orig 2025-08-15 18:30:00 UTC 2 +++ src/3rdparty/chromium/base/rand_util_posix.cc 3 @@ -28,7 +28,7 @@ 4 #include "base/time/time.h" 5 #include "build/build_config.h" 6 7 -#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !BUILDFLAG(IS_NACL) 8 +#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_BSD) 9 #include "third_party/lss/linux_syscall_support.h" 10 #elif BUILDFLAG(IS_MAC) 11 // TODO(crbug.com/40641285): Waiting for this header to appear in the iOS SDK. 12 @@ -44,6 +44,7 @@ namespace { 13 14 namespace { 15 16 +#if !BUILDFLAG(IS_BSD) 17 #if BUILDFLAG(IS_AIX) 18 // AIX has no 64-bit support for O_CLOEXEC. 19 static constexpr int kOpenFlags = O_RDONLY; 20 @@ -68,10 +69,11 @@ class URandomFd { 21 private: 22 const int fd_; 23 }; 24 +#endif 25 26 #if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \ 27 BUILDFLAG(IS_ANDROID)) && \ 28 - !BUILDFLAG(IS_NACL) 29 + !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_BSD) 30 // TODO(pasko): Unify reading kernel version numbers in: 31 // mojo/core/channel_linux.cc 32 // chrome/browser/android/seccomp_support_detector.cc 33 @@ -156,6 +158,7 @@ void RandBytesInternal(span<uint8_t> output, bool avoi 34 namespace { 35 36 void RandBytesInternal(span<uint8_t> output, bool avoid_allocation) { 37 +#if !BUILDFLAG(IS_BSD) 38 #if !BUILDFLAG(IS_NACL) 39 // The BoringSSL experiment takes priority over everything else. 40 if (!avoid_allocation && internal::UseBoringSSLForRandBytes()) { 41 @@ -190,6 +193,9 @@ void RandBytesInternal(span<uint8_t> output, bool avoi 42 const int urandom_fd = GetUrandomFD(); 43 const bool success = ReadFromFD(urandom_fd, as_writable_chars(output)); 44 CHECK(success); 45 +#else 46 + arc4random_buf(output.data(), output.size()); 47 +#endif 48 } 49 50 } // namespace 51 @@ -209,9 +215,11 @@ void RandBytes(span<uint8_t> output) { 52 RandBytesInternal(output, /*avoid_allocation=*/false); 53 } 54 55 +#if !BUILDFLAG(IS_BSD) 56 int GetUrandomFD() { 57 static NoDestructor<URandomFd> urandom_fd; 58 return urandom_fd->fd(); 59 } 60 +#endif 61 62 } // namespace base 63