OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gin/public/isolate_holder.h" | 5 #include "gin/public/isolate_holder.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/files/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
15 #include "crypto/sha2.h" | |
15 #include "gin/array_buffer.h" | 16 #include "gin/array_buffer.h" |
16 #include "gin/debug_impl.h" | 17 #include "gin/debug_impl.h" |
17 #include "gin/function_template.h" | 18 #include "gin/function_template.h" |
18 #include "gin/per_isolate_data.h" | 19 #include "gin/per_isolate_data.h" |
19 #include "gin/public/v8_platform.h" | 20 #include "gin/public/v8_platform.h" |
20 #include "gin/run_microtasks_observer.h" | 21 #include "gin/run_microtasks_observer.h" |
21 | 22 |
22 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 23 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
23 #ifdef OS_MACOSX | 24 #ifdef OS_MACOSX |
24 #include "base/mac/foundation_util.h" | 25 #include "base/mac/foundation_util.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 delete g_mapped_snapshot; | 66 delete g_mapped_snapshot; |
66 g_mapped_snapshot = NULL; | 67 g_mapped_snapshot = NULL; |
67 LOG(ERROR) << "Couldn't mmap v8 snapshot data file"; | 68 LOG(ERROR) << "Couldn't mmap v8 snapshot data file"; |
68 return false; | 69 return false; |
69 } | 70 } |
70 } | 71 } |
71 | 72 |
72 return true; | 73 return true; |
73 } | 74 } |
74 | 75 |
76 bool VerifyV8SnapshotFile(base::MemoryMappedFile* snapshot_file, | |
jochen (gone - plz use gerrit)
2015/01/08 15:11:53
#if defined(OS_WIN)
rmcilroy
2015/01/08 16:29:21
Done.
| |
77 const unsigned char* fingerprint) { | |
78 unsigned char output[crypto::kSHA256Length]; | |
79 crypto::SHA256HashString( | |
80 base::StringPiece(reinterpret_cast<const char*>(snapshot_file->data()), | |
81 snapshot_file->length()), | |
82 output, sizeof(output)); | |
83 return !memcmp(fingerprint, output, sizeof(output)); | |
84 } | |
85 | |
75 #if !defined(OS_MACOSX) | 86 #if !defined(OS_MACOSX) |
76 const int v8_snapshot_dir = | 87 const int v8_snapshot_dir = |
77 #if defined(OS_ANDROID) | 88 #if defined(OS_ANDROID) |
78 base::DIR_ANDROID_APP_DATA; | 89 base::DIR_ANDROID_APP_DATA; |
79 #elif defined(OS_POSIX) | 90 #elif defined(OS_POSIX) |
80 base::DIR_EXE; | 91 base::DIR_EXE; |
81 #endif // defined(OS_ANDROID) | 92 #endif // defined(OS_ANDROID) |
82 #endif // !defined(OS_MACOSX) | 93 #endif // !defined(OS_MACOSX) |
83 | 94 |
84 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 95 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
85 | 96 |
86 } // namespace | 97 } // namespace |
87 | 98 |
88 | 99 |
89 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 100 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
101 | |
102 // Declared in gen/gin/v8_snapshot_fingerprint.cc | |
103 extern const unsigned char g_natives_fingerprint[]; | |
104 extern const unsigned char g_snapshot_fingerprint[]; | |
105 | |
90 // static | 106 // static |
91 bool IsolateHolder::LoadV8Snapshot() { | 107 bool IsolateHolder::LoadV8Snapshot() { |
92 if (g_mapped_natives && g_mapped_snapshot) | 108 if (g_mapped_natives && g_mapped_snapshot) |
93 return true; | 109 return true; |
94 | 110 |
95 #if !defined(OS_MACOSX) | 111 #if !defined(OS_MACOSX) |
96 base::FilePath data_path; | 112 base::FilePath data_path; |
97 PathService::Get(v8_snapshot_dir, &data_path); | 113 PathService::Get(v8_snapshot_dir, &data_path); |
98 DCHECK(!data_path.empty()); | 114 DCHECK(!data_path.empty()); |
99 | 115 |
(...skipping 11 matching lines...) Expand all Loading... | |
111 return MapV8Files(&natives_path, &snapshot_path); | 127 return MapV8Files(&natives_path, &snapshot_path); |
112 } | 128 } |
113 | 129 |
114 //static | 130 //static |
115 bool IsolateHolder::LoadV8SnapshotFD(int natives_fd, int snapshot_fd) { | 131 bool IsolateHolder::LoadV8SnapshotFD(int natives_fd, int snapshot_fd) { |
116 if (g_mapped_natives && g_mapped_snapshot) | 132 if (g_mapped_natives && g_mapped_snapshot) |
117 return true; | 133 return true; |
118 | 134 |
119 return MapV8Files(NULL, NULL, natives_fd, snapshot_fd); | 135 return MapV8Files(NULL, NULL, natives_fd, snapshot_fd); |
120 } | 136 } |
137 | |
138 // static | |
139 bool IsolateHolder::LoadAndVerifyV8Snapshot() { | |
jochen (gone - plz use gerrit)
2015/01/08 15:11:53
#if OS_WIN
rmcilroy
2015/01/08 16:29:21
Done (and also ifdeffed out LoadV8Snapshot on Wind
| |
140 if (!LoadV8Snapshot()) | |
141 return false; | |
142 return VerifyV8SnapshotFile(g_mapped_natives, g_natives_fingerprint) && | |
143 VerifyV8SnapshotFile(g_mapped_snapshot, g_snapshot_fingerprint); | |
144 } | |
145 | |
121 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 146 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
122 | 147 |
123 //static | 148 //static |
124 void IsolateHolder::GetV8ExternalSnapshotData(const char** natives_data_out, | 149 void IsolateHolder::GetV8ExternalSnapshotData(const char** natives_data_out, |
125 int* natives_size_out, | 150 int* natives_size_out, |
126 const char** snapshot_data_out, | 151 const char** snapshot_data_out, |
127 int* snapshot_size_out) { | 152 int* snapshot_size_out) { |
128 if (!g_mapped_natives || !g_mapped_snapshot) { | 153 if (!g_mapped_natives || !g_mapped_snapshot) { |
129 *natives_data_out = *snapshot_data_out = NULL; | 154 *natives_data_out = *snapshot_data_out = NULL; |
130 *natives_size_out = *snapshot_size_out = 0; | 155 *natives_size_out = *snapshot_size_out = 0; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 base::MessageLoop::current()->AddTaskObserver(task_observer_.get()); | 239 base::MessageLoop::current()->AddTaskObserver(task_observer_.get()); |
215 } | 240 } |
216 | 241 |
217 void IsolateHolder::RemoveRunMicrotasksObserver() { | 242 void IsolateHolder::RemoveRunMicrotasksObserver() { |
218 DCHECK(task_observer_.get()); | 243 DCHECK(task_observer_.get()); |
219 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); | 244 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); |
220 task_observer_.reset(); | 245 task_observer_.reset(); |
221 } | 246 } |
222 | 247 |
223 } // namespace gin | 248 } // namespace gin |
OLD | NEW |