Index: src/v8.cc |
=================================================================== |
--- src/v8.cc (revision 8657) |
+++ src/v8.cc (working copy) |
@@ -50,7 +50,10 @@ |
bool V8::has_fatal_error_ = false; |
bool V8::use_crankshaft_ = true; |
+static Mutex* entropy_mutex = OS::CreateMutex(); |
+static EntropySource entropy_source; |
+ |
bool V8::Initialize(Deserializer* des) { |
InitializeOncePerProcess(); |
@@ -102,8 +105,14 @@ |
static void seed_random(uint32_t* state) { |
for (int i = 0; i < 2; ++i) { |
- state[i] = FLAG_random_seed; |
- while (state[i] == 0) { |
+ if (FLAG_random_seed != NULL) |
Mads Ager (chromium)
2011/07/17 09:11:39
Please consistently use braces around the body. Al
|
+ state[i] = FLAG_random_seed; |
+ else if (entropy_source != NULL) { |
+ uint32_t val; |
+ ScopedLock lock(entropy_mutex); |
+ entropy_source(reinterpret_cast<unsigned char*>(&val), sizeof(uint32_t)); |
+ state[i] = val; |
+ } else { |
state[i] = random(); |
} |
} |
@@ -124,6 +133,11 @@ |
} |
+void V8::SetEntropySource(EntropySource source) { |
+ entropy_source = source; |
+} |
+ |
+ |
// Used by JavaScript APIs |
uint32_t V8::Random(Isolate* isolate) { |
ASSERT(isolate == Isolate::Current()); |