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