Index: gin/isolate_holder.cc |
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc |
index 2b6d64b35c042b2e183e6cc0c963c2f2ab96d392..149bc10eb86b0eb43add0098ce904d614388fc41 100644 |
--- a/gin/isolate_holder.cc |
+++ b/gin/isolate_holder.cc |
@@ -12,6 +12,7 @@ |
#include "base/message_loop/message_loop.h" |
#include "base/rand_util.h" |
#include "base/sys_info.h" |
+#include "crypto/sha2.h" |
#include "gin/array_buffer.h" |
#include "gin/debug_impl.h" |
#include "gin/function_template.h" |
@@ -19,12 +20,12 @@ |
#include "gin/public/v8_platform.h" |
#include "gin/run_microtasks_observer.h" |
-#ifdef V8_USE_EXTERNAL_STARTUP_DATA |
-#ifdef OS_MACOSX |
+#if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
+#if defined(OS_MACOSX) |
#include "base/mac/foundation_util.h" |
-#endif // OS_MACOSX |
+#endif // defined(OS_MACOSX) |
#include "base/path_service.h" |
-#endif // V8_USE_EXTERNAL_STARTUP_DATA |
+#endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) |
namespace gin { |
@@ -40,7 +41,7 @@ bool GenerateEntropy(unsigned char* buffer, size_t amount) { |
base::MemoryMappedFile* g_mapped_natives = NULL; |
base::MemoryMappedFile* g_mapped_snapshot = NULL; |
-#ifdef V8_USE_EXTERNAL_STARTUP_DATA |
+#if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
bool MapV8Files(base::FilePath* natives_path, base::FilePath* snapshot_path, |
int natives_fd = -1, int snapshot_fd = -1) { |
int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
@@ -72,6 +73,18 @@ bool MapV8Files(base::FilePath* natives_path, base::FilePath* snapshot_path, |
return true; |
} |
+#if defined(OS_WIN) |
grt (UTC plus 2)
2015/01/08 17:46:35
i can imagine other platforms eventually wanting t
rmcilroy
2015/01/08 18:54:14
Done.
|
+bool VerifyV8SnapshotFile(base::MemoryMappedFile* snapshot_file, |
+ const unsigned char* fingerprint) { |
+ unsigned char output[crypto::kSHA256Length]; |
+ crypto::SHA256HashString( |
+ base::StringPiece(reinterpret_cast<const char*>(snapshot_file->data()), |
+ snapshot_file->length()), |
+ output, sizeof(output)); |
+ return !memcmp(fingerprint, output, sizeof(output)); |
+} |
+#endif // defined(OS_WIN) |
+ |
#if !defined(OS_MACOSX) |
const int v8_snapshot_dir = |
#if defined(OS_ANDROID) |
@@ -85,10 +98,16 @@ const int v8_snapshot_dir = |
} // namespace |
+#if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
+ |
+#if defined(OS_WIN) |
+// Declared in gen/gin/v8_snapshot_fingerprint.cc |
grt (UTC plus 2)
2015/01/08 17:46:35
ping: Declared -> Defined
rmcilroy
2015/01/08 18:54:14
Oops, sorry missed this. Done.
|
+extern const unsigned char g_natives_fingerprint[]; |
+extern const unsigned char g_snapshot_fingerprint[]; |
+#endif // defined(OS_WIN) |
-#ifdef V8_USE_EXTERNAL_STARTUP_DATA |
// static |
-bool IsolateHolder::LoadV8Snapshot() { |
+bool IsolateHolder::LoadV8SnapshotCommon() { |
if (g_mapped_natives && g_mapped_snapshot) |
return true; |
@@ -118,7 +137,23 @@ bool IsolateHolder::LoadV8SnapshotFD(int natives_fd, int snapshot_fd) { |
return MapV8Files(NULL, NULL, natives_fd, snapshot_fd); |
} |
-#endif // V8_USE_EXTERNAL_STARTUP_DATA |
+ |
+#if defined(OS_WIN) |
+// static |
+bool IsolateHolder::LoadAndVerifyV8Snapshot() { |
+ if (!LoadV8SnapshotCommon()) |
+ return false; |
+ return VerifyV8SnapshotFile(g_mapped_natives, g_natives_fingerprint) && |
+ VerifyV8SnapshotFile(g_mapped_snapshot, g_snapshot_fingerprint); |
+} |
+#else |
+// static |
+bool IsolateHolder::LoadV8Snapshot() { |
+ return LoadV8SnapshotCommon(); |
+} |
+#endif // defined(OS_WIN) |
+ |
+#endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) |
//static |
void IsolateHolder::GetV8ExternalSnapshotData(const char** natives_data_out, |
@@ -193,7 +228,7 @@ void IsolateHolder::Initialize(ScriptMode mode, |
v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1); |
} |
v8::V8::SetEntropySource(&GenerateEntropy); |
-#ifdef V8_USE_EXTERNAL_STARTUP_DATA |
+#if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
v8::StartupData natives; |
natives.data = reinterpret_cast<const char*>(g_mapped_natives->data()); |
natives.raw_size = static_cast<int>(g_mapped_natives->length()); |
@@ -203,7 +238,7 @@ void IsolateHolder::Initialize(ScriptMode mode, |
snapshot.data = reinterpret_cast<const char*>(g_mapped_snapshot->data()); |
snapshot.raw_size = static_cast<int>(g_mapped_snapshot->length()); |
v8::V8::SetSnapshotDataBlob(&snapshot); |
-#endif // V8_USE_EXTERNAL_STARTUP_DATA |
+#endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) |
v8::V8::Initialize(); |
v8_is_initialized = true; |
} |