BUG=89462
Review URL: http://codereview.chromium.org/7395012
Patch from Chris Neckar <cdn@chromium.org>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8666
ce2b1a6d-e550-0410-aec6-
3dcde31c8c00
char** raw_data;
};
+
+/**
+ * EntropySource is used as a callback function when v8 needs a source
+ * of entropy.
+ */
+typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
+
/**
* Container class for static utility functions.
*/
static bool Initialize();
/**
+ * Allows the host application to provide a callback which can be used
+ * as a source of entropy for random number generators.
+ */
+ static void SetEntropySource(EntropySource source);
+
+ /**
* Adjusts the amount of registered external memory. Used to give
* V8 an indication of the amount of externally allocated memory
* that is kept alive by JavaScript objects. V8 uses this to decide
}
+void v8::V8::SetEntropySource(EntropySource source) {
+ i::V8::SetEntropySource(source);
+}
+
+
bool v8::V8::Dispose() {
i::Isolate* isolate = i::Isolate::Current();
if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(),
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();
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 != 0) {
+ 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();
}
}
}
+void V8::SetEntropySource(EntropySource source) {
+ entropy_source = source;
+}
+
+
// Used by JavaScript APIs
uint32_t V8::Random(Isolate* isolate) {
ASSERT(isolate == Isolate::Current());
static void FatalProcessOutOfMemory(const char* location,
bool take_snapshot = false);
+ // Allows an entropy source to be provided for use in random number
+ // generation.
+ static void SetEntropySource(EntropySource source);
// Random number generation support. Not cryptographically safe.
static uint32_t Random(Isolate* isolate);
// We use random numbers internally in memory allocation and in the