Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Unified Diff: runtime/bin/crypto_linux.cc

Issue 209333014: Speed up GetRandomBytes by only entering signal-blocking scope once. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/crypto_linux.cc
diff --git a/runtime/bin/crypto_linux.cc b/runtime/bin/crypto_linux.cc
index 643af6cf5014c70dedc4006f9489d2944227b45c..cf3062d0318a1aa1072f605769e4ce1e8e04276b 100644
--- a/runtime/bin/crypto_linux.cc
+++ b/runtime/bin/crypto_linux.cc
@@ -17,11 +17,24 @@ namespace dart {
namespace bin {
bool Crypto::GetRandomBytes(intptr_t count, uint8_t* buffer) {
- intptr_t fd = TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY));
+ ThreadSignalBlocker signal_blocker(SIGPROF);
+ intptr_t fd = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(
+ open("/dev/urandom", O_RDONLY));
if (fd < 0) return false;
- intptr_t bytes_read = FDUtils::ReadFromBlocking(fd, buffer, count);
- VOID_TEMP_FAILURE_RETRY(close(fd));
- return bytes_read == count;
+ intptr_t bytes_read = 0;
+ do {
+ int res = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(
+ read(fd, buffer + bytes_read, count - bytes_read));
+ if (res < 0) {
+ int err = errno;
+ VOID_TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(close(fd));
+ errno = err;
+ return false;
+ }
+ bytes_read += res;
+ } while (bytes_read < count);
+ VOID_TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(close(fd));
+ return true;
}
} // namespace bin

Powered by Google App Engine
This is Rietveld 408576698