| 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/v8_initializer.h" | 5 #include "gin/v8_initializer.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 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/memory/scoped_ptr.h" |
| 12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 13 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "crypto/sha2.h" | 18 #include "crypto/sha2.h" |
| 18 | 19 |
| 19 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 20 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 20 #if defined(OS_MACOSX) | 21 #if defined(OS_MACOSX) |
| 21 #include "base/mac/foundation_util.h" | 22 #include "base/mac/foundation_util.h" |
| 22 #endif // OS_MACOSX | 23 #endif // OS_MACOSX |
| 23 #include "base/path_service.h" | 24 #include "base/path_service.h" |
| 24 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 25 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 25 | 26 |
| 26 namespace gin { | 27 namespace gin { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 31 // None of these globals are ever freed nor closed. |
| 30 base::MemoryMappedFile* g_mapped_natives = nullptr; | 32 base::MemoryMappedFile* g_mapped_natives = nullptr; |
| 31 base::MemoryMappedFile* g_mapped_snapshot = nullptr; | 33 base::MemoryMappedFile* g_mapped_snapshot = nullptr; |
| 32 | 34 |
| 33 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 35 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 36 |
| 37 const base::PlatformFile kInvalidPlatformFile = |
| 38 #if defined(OS_WIN) |
| 39 INVALID_HANDLE_VALUE; |
| 40 #else |
| 41 -1; |
| 42 #endif |
| 43 |
| 44 // File handles intentionally never closed. Not using File here because its |
| 45 // Windows implementation guards against two instances owning the same |
| 46 // PlatformFile (which we allow since we know it is never freed). |
| 47 base::PlatformFile g_natives_pf = kInvalidPlatformFile; |
| 48 base::PlatformFile g_snapshot_pf = kInvalidPlatformFile; |
| 49 base::MemoryMappedFile::Region g_natives_region; |
| 50 base::MemoryMappedFile::Region g_snapshot_region; |
| 51 |
| 34 #if !defined(OS_MACOSX) | 52 #if !defined(OS_MACOSX) |
| 35 const int kV8SnapshotBasePathKey = | 53 const int kV8SnapshotBasePathKey = |
| 36 #if defined(OS_ANDROID) | 54 #if defined(OS_ANDROID) |
| 37 base::DIR_ANDROID_APP_DATA; | 55 base::DIR_ANDROID_APP_DATA; |
| 38 #elif defined(OS_POSIX) | 56 #elif defined(OS_POSIX) |
| 39 base::DIR_EXE; | 57 base::DIR_EXE; |
| 40 #elif defined(OS_WIN) | 58 #elif defined(OS_WIN) |
| 41 base::DIR_MODULE; | 59 base::DIR_MODULE; |
| 42 #endif // OS_ANDROID | 60 #endif // OS_ANDROID |
| 43 #endif // !OS_MACOSX | 61 #endif // !OS_MACOSX |
| (...skipping 14 matching lines...) Expand all Loading... |
| 58 | 76 |
| 59 *path_out = data_path.AppendASCII(file_name); | 77 *path_out = data_path.AppendASCII(file_name); |
| 60 #else // !defined(OS_MACOSX) | 78 #else // !defined(OS_MACOSX) |
| 61 base::ScopedCFTypeRef<CFStringRef> natives_file_name( | 79 base::ScopedCFTypeRef<CFStringRef> natives_file_name( |
| 62 base::SysUTF8ToCFStringRef(file_name)); | 80 base::SysUTF8ToCFStringRef(file_name)); |
| 63 *path_out = base::mac::PathForFrameworkBundleResource(natives_file_name); | 81 *path_out = base::mac::PathForFrameworkBundleResource(natives_file_name); |
| 64 #endif // !defined(OS_MACOSX) | 82 #endif // !defined(OS_MACOSX) |
| 65 DCHECK(!path_out->empty()); | 83 DCHECK(!path_out->empty()); |
| 66 } | 84 } |
| 67 | 85 |
| 68 static bool MapV8File(base::File file, | 86 static bool MapV8File(base::PlatformFile platform_file, |
| 69 base::MemoryMappedFile::Region region, | 87 base::MemoryMappedFile::Region region, |
| 70 base::MemoryMappedFile** mmapped_file_out) { | 88 base::MemoryMappedFile** mmapped_file_out) { |
| 71 DCHECK(*mmapped_file_out == NULL); | 89 DCHECK(*mmapped_file_out == NULL); |
| 72 base::MemoryMappedFile* mmapped_file = *mmapped_file_out = | 90 scoped_ptr<base::MemoryMappedFile> mmapped_file(new base::MemoryMappedFile()); |
| 73 new base::MemoryMappedFile; | 91 if (mmapped_file->Initialize(base::File(platform_file), region)) { |
| 74 if (!mmapped_file->Initialize(file.Pass(), region)) { | 92 *mmapped_file_out = mmapped_file.release(); |
| 75 delete mmapped_file; | 93 return true; |
| 76 *mmapped_file_out = NULL; | |
| 77 return false; | |
| 78 } | 94 } |
| 79 | 95 return false; |
| 80 return true; | |
| 81 } | 96 } |
| 82 | 97 |
| 83 static bool OpenV8File(const base::FilePath& path, | 98 base::PlatformFile OpenV8File(const char* file_name, |
| 84 int flags, | 99 base::MemoryMappedFile::Region* region_out) { |
| 85 base::File& file) { | |
| 86 // Re-try logic here is motivated by http://crbug.com/479537 | 100 // Re-try logic here is motivated by http://crbug.com/479537 |
| 87 // for A/V on Windows (https://support.microsoft.com/en-us/kb/316609). | 101 // for A/V on Windows (https://support.microsoft.com/en-us/kb/316609). |
| 88 | 102 |
| 89 // These match tools/metrics/histograms.xml | 103 // These match tools/metrics/histograms.xml |
| 90 enum OpenV8FileResult { | 104 enum OpenV8FileResult { |
| 91 OPENED = 0, | 105 OPENED = 0, |
| 92 OPENED_RETRY, | 106 OPENED_RETRY, |
| 93 FAILED_IN_USE, | 107 FAILED_IN_USE, |
| 94 FAILED_OTHER, | 108 FAILED_OTHER, |
| 95 MAX_VALUE | 109 MAX_VALUE |
| 96 }; | 110 }; |
| 97 | 111 |
| 112 base::FilePath path; |
| 113 GetV8FilePath(file_name, &path); |
| 114 |
| 98 OpenV8FileResult result = OpenV8FileResult::FAILED_IN_USE; | 115 OpenV8FileResult result = OpenV8FileResult::FAILED_IN_USE; |
| 116 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
| 117 base::File file; |
| 99 for (int attempt = 0; attempt < kMaxOpenAttempts; attempt++) { | 118 for (int attempt = 0; attempt < kMaxOpenAttempts; attempt++) { |
| 100 file.Initialize(path, flags); | 119 file.Initialize(path, flags); |
| 101 if (file.IsValid()) { | 120 if (file.IsValid()) { |
| 121 *region_out = base::MemoryMappedFile::Region::kWholeFile; |
| 102 if (attempt == 0) { | 122 if (attempt == 0) { |
| 103 result = OpenV8FileResult::OPENED; | 123 result = OpenV8FileResult::OPENED; |
| 104 break; | 124 break; |
| 105 } else { | 125 } else { |
| 106 result = OpenV8FileResult::OPENED_RETRY; | 126 result = OpenV8FileResult::OPENED_RETRY; |
| 107 break; | 127 break; |
| 108 } | 128 } |
| 109 } else if (file.error_details() != base::File::FILE_ERROR_IN_USE) { | 129 } else if (file.error_details() != base::File::FILE_ERROR_IN_USE) { |
| 110 result = OpenV8FileResult::FAILED_OTHER; | 130 result = OpenV8FileResult::FAILED_OTHER; |
| 111 break; | 131 break; |
| 112 } else if (kMaxOpenAttempts - 1 != attempt) { | 132 } else if (kMaxOpenAttempts - 1 != attempt) { |
| 113 base::PlatformThread::Sleep( | 133 base::PlatformThread::Sleep( |
| 114 base::TimeDelta::FromMilliseconds(kOpenRetryDelayMillis)); | 134 base::TimeDelta::FromMilliseconds(kOpenRetryDelayMillis)); |
| 115 } | 135 } |
| 116 } | 136 } |
| 117 | 137 |
| 118 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.OpenV8File.Result", | 138 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.OpenV8File.Result", |
| 119 result, | 139 result, |
| 120 OpenV8FileResult::MAX_VALUE); | 140 OpenV8FileResult::MAX_VALUE); |
| 141 return file.TakePlatformFile(); |
| 142 } |
| 121 | 143 |
| 122 return result == OpenV8FileResult::OPENED | 144 void OpenNativesFileIfNecessary() { |
| 123 || result == OpenV8FileResult::OPENED_RETRY; | 145 if (g_natives_pf == kInvalidPlatformFile) { |
| 146 g_natives_pf = OpenV8File(kNativesFileName, &g_natives_region); |
| 147 } |
| 148 } |
| 149 |
| 150 void OpenSnapshotFileIfNecessary() { |
| 151 if (g_snapshot_pf == kInvalidPlatformFile) { |
| 152 g_snapshot_pf = OpenV8File(kSnapshotFileName, &g_snapshot_region); |
| 153 } |
| 124 } | 154 } |
| 125 | 155 |
| 126 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 156 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
| 127 bool VerifyV8StartupFile(base::MemoryMappedFile** file, | 157 bool VerifyV8StartupFile(base::MemoryMappedFile** file, |
| 128 const unsigned char* fingerprint) { | 158 const unsigned char* fingerprint) { |
| 129 unsigned char output[crypto::kSHA256Length]; | 159 unsigned char output[crypto::kSHA256Length]; |
| 130 crypto::SHA256HashString( | 160 crypto::SHA256HashString( |
| 131 base::StringPiece(reinterpret_cast<const char*>((*file)->data()), | 161 base::StringPiece(reinterpret_cast<const char*>((*file)->data()), |
| 132 (*file)->length()), | 162 (*file)->length()), |
| 133 output, sizeof(output)); | 163 output, sizeof(output)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 156 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA | 186 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA |
| 157 | 187 |
| 158 enum LoadV8FileResult { | 188 enum LoadV8FileResult { |
| 159 V8_LOAD_SUCCESS = 0, | 189 V8_LOAD_SUCCESS = 0, |
| 160 V8_LOAD_FAILED_OPEN, | 190 V8_LOAD_FAILED_OPEN, |
| 161 V8_LOAD_FAILED_MAP, | 191 V8_LOAD_FAILED_MAP, |
| 162 V8_LOAD_FAILED_VERIFY, | 192 V8_LOAD_FAILED_VERIFY, |
| 163 V8_LOAD_MAX_VALUE | 193 V8_LOAD_MAX_VALUE |
| 164 }; | 194 }; |
| 165 | 195 |
| 166 static LoadV8FileResult OpenMapVerify( | 196 static LoadV8FileResult MapVerify(base::PlatformFile platform_file, |
| 167 const char* file_name, | 197 const base::MemoryMappedFile::Region& region, |
| 168 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 198 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
| 169 const unsigned char* fingerprint, | 199 const unsigned char* fingerprint, |
| 170 #endif | 200 #endif |
| 171 base::MemoryMappedFile** mmapped_file_out) { | 201 base::MemoryMappedFile** mmapped_file_out) { |
| 172 base::FilePath path; | 202 if (platform_file == kInvalidPlatformFile) |
| 173 GetV8FilePath(file_name, &path); | |
| 174 | |
| 175 base::File file; | |
| 176 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | |
| 177 | |
| 178 if (!OpenV8File(path, flags, file)) | |
| 179 return V8_LOAD_FAILED_OPEN; | 203 return V8_LOAD_FAILED_OPEN; |
| 180 if (!MapV8File(file.Pass(), base::MemoryMappedFile::Region::kWholeFile, | 204 if (!MapV8File(platform_file, region, mmapped_file_out)) |
| 181 mmapped_file_out)) | |
| 182 return V8_LOAD_FAILED_MAP; | 205 return V8_LOAD_FAILED_MAP; |
| 183 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 206 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
| 184 if (!VerifyV8StartupFile(mmapped_file_out, fingerprint)) | 207 if (!VerifyV8StartupFile(mmapped_file_out, fingerprint)) |
| 185 return V8_LOAD_FAILED_VERIFY; | 208 return V8_LOAD_FAILED_VERIFY; |
| 186 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA | 209 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA |
| 187 return V8_LOAD_SUCCESS; | 210 return V8_LOAD_SUCCESS; |
| 188 } | 211 } |
| 189 | 212 |
| 190 // static | 213 // static |
| 191 void V8Initializer::LoadV8Snapshot() { | 214 void V8Initializer::LoadV8Snapshot() { |
| 192 if (g_mapped_snapshot) | 215 if (g_mapped_snapshot) |
| 193 return; | 216 return; |
| 194 | 217 |
| 195 LoadV8FileResult result = OpenMapVerify(kSnapshotFileName, | 218 OpenSnapshotFileIfNecessary(); |
| 219 LoadV8FileResult result = MapVerify(g_snapshot_pf, g_snapshot_region, |
| 196 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 220 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
| 197 g_snapshot_fingerprint, | 221 g_snapshot_fingerprint, |
| 198 #endif | 222 #endif |
| 199 &g_mapped_snapshot); | 223 &g_mapped_snapshot); |
| 224 // V8 can't start up without the source of the natives, but it can |
| 225 // start up (slower) without the snapshot. |
| 200 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result, | 226 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result, |
| 201 V8_LOAD_MAX_VALUE); | 227 V8_LOAD_MAX_VALUE); |
| 202 } | 228 } |
| 203 | 229 |
| 204 void V8Initializer::LoadV8Natives() { | 230 void V8Initializer::LoadV8Natives() { |
| 205 if (g_mapped_natives) | 231 if (g_mapped_natives) |
| 206 return; | 232 return; |
| 207 | 233 |
| 208 LoadV8FileResult result = OpenMapVerify(kNativesFileName, | 234 OpenNativesFileIfNecessary(); |
| 235 LoadV8FileResult result = MapVerify(g_natives_pf, g_natives_region, |
| 209 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 236 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
| 210 g_natives_fingerprint, | 237 g_natives_fingerprint, |
| 211 #endif | 238 #endif |
| 212 &g_mapped_natives); | 239 &g_mapped_natives); |
| 213 if (result != V8_LOAD_SUCCESS) { | 240 if (result != V8_LOAD_SUCCESS) { |
| 214 LOG(FATAL) << "Couldn't mmap v8 natives data file, status code is " | 241 LOG(FATAL) << "Couldn't mmap v8 natives data file, status code is " |
| 215 << static_cast<int>(result); | 242 << static_cast<int>(result); |
| 216 } | 243 } |
| 217 } | 244 } |
| 218 | 245 |
| 219 // static | 246 // static |
| 220 void V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile snapshot_pf, | 247 void V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile snapshot_pf, |
| 221 int64 snapshot_offset, | 248 int64 snapshot_offset, |
| 222 int64 snapshot_size) { | 249 int64 snapshot_size) { |
| 223 if (g_mapped_snapshot) | 250 if (g_mapped_snapshot) |
| 224 return; | 251 return; |
| 225 | 252 |
| 226 if (snapshot_pf == reinterpret_cast<base::PlatformFile>(-1)) | 253 if (snapshot_pf == kInvalidPlatformFile) |
| 227 return; | 254 return; |
| 228 | 255 |
| 229 base::MemoryMappedFile::Region snapshot_region = | 256 base::MemoryMappedFile::Region snapshot_region = |
| 230 base::MemoryMappedFile::Region::kWholeFile; | 257 base::MemoryMappedFile::Region::kWholeFile; |
| 231 if (snapshot_size != 0 || snapshot_offset != 0) { | 258 if (snapshot_size != 0 || snapshot_offset != 0) { |
| 232 snapshot_region = | 259 snapshot_region.offset = snapshot_offset; |
| 233 base::MemoryMappedFile::Region(snapshot_offset, snapshot_size); | 260 snapshot_region.size = snapshot_size; |
| 234 } | 261 } |
| 235 | 262 |
| 236 LoadV8FileResult result = V8_LOAD_SUCCESS; | 263 LoadV8FileResult result = V8_LOAD_SUCCESS; |
| 237 if (!MapV8File(base::File(snapshot_pf), snapshot_region, &g_mapped_snapshot)) | 264 if (!MapV8File(snapshot_pf, snapshot_region, &g_mapped_snapshot)) |
| 238 result = V8_LOAD_FAILED_MAP; | 265 result = V8_LOAD_FAILED_MAP; |
| 239 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 266 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
| 240 if (!VerifyV8StartupFile(&g_mapped_snapshot, g_snapshot_fingerprint)) | 267 if (!VerifyV8StartupFile(&g_mapped_snapshot, g_snapshot_fingerprint)) |
| 241 result = V8_LOAD_FAILED_VERIFY; | 268 result = V8_LOAD_FAILED_VERIFY; |
| 242 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA | 269 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA |
| 243 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result, | 270 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result, |
| 244 V8_LOAD_MAX_VALUE); | 271 V8_LOAD_MAX_VALUE); |
| 245 } | 272 } |
| 246 | 273 |
| 247 // static | 274 // static |
| 248 void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf, | 275 void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf, |
| 249 int64 natives_offset, | 276 int64 natives_offset, |
| 250 int64 natives_size) { | 277 int64 natives_size) { |
| 251 if (g_mapped_natives) | 278 if (g_mapped_natives) |
| 252 return; | 279 return; |
| 253 | 280 |
| 254 CHECK_NE(natives_pf, reinterpret_cast<base::PlatformFile>(-1)); | 281 CHECK_NE(natives_pf, kInvalidPlatformFile); |
| 255 | 282 |
| 256 base::MemoryMappedFile::Region natives_region = | 283 base::MemoryMappedFile::Region natives_region = |
| 257 base::MemoryMappedFile::Region::kWholeFile; | 284 base::MemoryMappedFile::Region::kWholeFile; |
| 258 if (natives_size != 0 || natives_offset != 0) { | 285 if (natives_size != 0 || natives_offset != 0) { |
| 259 natives_region = | 286 natives_region.offset = natives_offset; |
| 260 base::MemoryMappedFile::Region(natives_offset, natives_size); | 287 natives_region.size = natives_size; |
| 261 } | 288 } |
| 262 | 289 |
| 263 if (!MapV8File(base::File(natives_pf), natives_region, &g_mapped_natives)) { | 290 if (!MapV8File(natives_pf, natives_region, &g_mapped_natives)) { |
| 264 LOG(FATAL) << "Couldn't mmap v8 natives data file"; | 291 LOG(FATAL) << "Couldn't mmap v8 natives data file"; |
| 265 } | 292 } |
| 266 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 293 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
| 267 if (!VerifyV8StartupFile(&g_mapped_natives, g_natives_fingerprint)) { | 294 if (!VerifyV8StartupFile(&g_mapped_natives, g_natives_fingerprint)) { |
| 268 LOG(FATAL) << "Couldn't verify contents of v8 natives data file"; | 295 LOG(FATAL) << "Couldn't verify contents of v8 natives data file"; |
| 269 } | 296 } |
| 270 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA | 297 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA |
| 271 } | 298 } |
| 272 | 299 |
| 273 // static | 300 // static |
| 274 bool V8Initializer::OpenV8FilesForChildProcesses( | 301 base::PlatformFile V8Initializer::GetOpenNativesFileForChildProcesses( |
| 275 base::PlatformFile* natives_fd_out, | 302 base::MemoryMappedFile::Region* region_out) { |
| 276 base::PlatformFile* snapshot_fd_out) { | 303 OpenNativesFileIfNecessary(); |
| 277 base::FilePath natives_data_path; | 304 *region_out = g_natives_region; |
| 278 base::FilePath snapshot_data_path; | 305 return g_natives_pf; |
| 279 GetV8FilePath(kNativesFileName, &natives_data_path); | |
| 280 GetV8FilePath(kSnapshotFileName, &snapshot_data_path); | |
| 281 | |
| 282 base::File natives_data_file; | |
| 283 base::File snapshot_data_file; | |
| 284 int file_flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | |
| 285 | |
| 286 bool natives_success = | |
| 287 OpenV8File(natives_data_path, file_flags, natives_data_file); | |
| 288 if (natives_success) { | |
| 289 *natives_fd_out = natives_data_file.TakePlatformFile(); | |
| 290 } | |
| 291 bool snapshot_success = | |
| 292 OpenV8File(snapshot_data_path, file_flags, snapshot_data_file); | |
| 293 if (snapshot_success) { | |
| 294 *snapshot_fd_out = snapshot_data_file.TakePlatformFile(); | |
| 295 } | |
| 296 // We can start up without the snapshot file, but not without the natives. | |
| 297 return natives_success; | |
| 298 } | 306 } |
| 299 | 307 |
| 300 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 308 // static |
| 309 base::PlatformFile V8Initializer::GetOpenSnapshotFileForChildProcesses( |
| 310 base::MemoryMappedFile::Region* region_out) { |
| 311 OpenSnapshotFileIfNecessary(); |
| 312 *region_out = g_snapshot_region; |
| 313 return g_snapshot_pf; |
| 314 } |
| 315 #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 301 | 316 |
| 302 // static | 317 // static |
| 303 void V8Initializer::Initialize(gin::IsolateHolder::ScriptMode mode) { | 318 void V8Initializer::Initialize(gin::IsolateHolder::ScriptMode mode) { |
| 304 static bool v8_is_initialized = false; | 319 static bool v8_is_initialized = false; |
| 305 if (v8_is_initialized) | 320 if (v8_is_initialized) |
| 306 return; | 321 return; |
| 307 | 322 |
| 308 v8::V8::InitializePlatform(V8Platform::Get()); | 323 v8::V8::InitializePlatform(V8Platform::Get()); |
| 309 | 324 |
| 310 if (gin::IsolateHolder::kStrictMode == mode) { | 325 if (gin::IsolateHolder::kStrictMode == mode) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 *snapshot_data_out = | 363 *snapshot_data_out = |
| 349 reinterpret_cast<const char*>(g_mapped_snapshot->data()); | 364 reinterpret_cast<const char*>(g_mapped_snapshot->data()); |
| 350 *snapshot_size_out = static_cast<int>(g_mapped_snapshot->length()); | 365 *snapshot_size_out = static_cast<int>(g_mapped_snapshot->length()); |
| 351 } else { | 366 } else { |
| 352 *snapshot_data_out = NULL; | 367 *snapshot_data_out = NULL; |
| 353 *snapshot_size_out = 0; | 368 *snapshot_size_out = 0; |
| 354 } | 369 } |
| 355 } | 370 } |
| 356 | 371 |
| 357 } // namespace gin | 372 } // namespace gin |
| OLD | NEW |