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" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 int natives_fd = -1, | 48 int natives_fd = -1, |
49 int snapshot_fd = -1, | 49 int snapshot_fd = -1, |
50 base::MemoryMappedFile::Region natives_region = | 50 base::MemoryMappedFile::Region natives_region = |
51 base::MemoryMappedFile::Region::kWholeFile, | 51 base::MemoryMappedFile::Region::kWholeFile, |
52 base::MemoryMappedFile::Region snapshot_region = | 52 base::MemoryMappedFile::Region snapshot_region = |
53 base::MemoryMappedFile::Region::kWholeFile) { | 53 base::MemoryMappedFile::Region::kWholeFile) { |
54 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | 54 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
55 | 55 |
56 g_mapped_natives = new base::MemoryMappedFile; | 56 g_mapped_natives = new base::MemoryMappedFile; |
57 if (!g_mapped_natives->IsValid()) { | 57 if (!g_mapped_natives->IsValid()) { |
| 58 #if !defined(OS_WIN) |
58 if (natives_fd == -1 | 59 if (natives_fd == -1 |
59 ? !g_mapped_natives->Initialize(base::File(*natives_path, flags), | 60 ? !g_mapped_natives->Initialize(base::File(*natives_path, flags), |
60 natives_region) | 61 natives_region) |
61 : !g_mapped_natives->Initialize(base::File(natives_fd), | 62 : !g_mapped_natives->Initialize(base::File(natives_fd), |
62 natives_region)) { | 63 natives_region)) { |
| 64 #else |
| 65 if (!g_mapped_natives->Initialize(base::File(*natives_path, flags), |
| 66 natives_region)) { |
| 67 #endif // !OS_WIN |
63 delete g_mapped_natives; | 68 delete g_mapped_natives; |
64 g_mapped_natives = NULL; | 69 g_mapped_natives = NULL; |
65 LOG(FATAL) << "Couldn't mmap v8 natives data file"; | 70 LOG(FATAL) << "Couldn't mmap v8 natives data file"; |
66 return false; | 71 return false; |
67 } | 72 } |
68 } | 73 } |
69 | 74 |
70 g_mapped_snapshot = new base::MemoryMappedFile; | 75 g_mapped_snapshot = new base::MemoryMappedFile; |
71 if (!g_mapped_snapshot->IsValid()) { | 76 if (!g_mapped_snapshot->IsValid()) { |
| 77 #if !defined(OS_WIN) |
72 if (snapshot_fd == -1 | 78 if (snapshot_fd == -1 |
73 ? !g_mapped_snapshot->Initialize(base::File(*snapshot_path, flags), | 79 ? !g_mapped_snapshot->Initialize(base::File(*snapshot_path, flags), |
74 snapshot_region) | 80 snapshot_region) |
75 : !g_mapped_snapshot->Initialize(base::File(snapshot_fd), | 81 : !g_mapped_snapshot->Initialize(base::File(snapshot_fd), |
76 snapshot_region)) { | 82 snapshot_region)) { |
| 83 #else |
| 84 if (!g_mapped_snapshot->Initialize(base::File(*snapshot_path, flags), |
| 85 snapshot_region)) { |
| 86 #endif // !OS_WIN |
77 delete g_mapped_snapshot; | 87 delete g_mapped_snapshot; |
78 g_mapped_snapshot = NULL; | 88 g_mapped_snapshot = NULL; |
79 LOG(ERROR) << "Couldn't mmap v8 snapshot data file"; | 89 LOG(ERROR) << "Couldn't mmap v8 snapshot data file"; |
80 return false; | 90 return false; |
81 } | 91 } |
82 } | 92 } |
83 | 93 |
84 return true; | 94 return true; |
85 } | 95 } |
86 | 96 |
87 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 97 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
88 bool VerifyV8SnapshotFile(base::MemoryMappedFile* snapshot_file, | 98 bool VerifyV8SnapshotFile(base::MemoryMappedFile* snapshot_file, |
89 const unsigned char* fingerprint) { | 99 const unsigned char* fingerprint) { |
90 unsigned char output[crypto::kSHA256Length]; | 100 unsigned char output[crypto::kSHA256Length]; |
91 crypto::SHA256HashString( | 101 crypto::SHA256HashString( |
92 base::StringPiece(reinterpret_cast<const char*>(snapshot_file->data()), | 102 base::StringPiece(reinterpret_cast<const char*>(snapshot_file->data()), |
93 snapshot_file->length()), | 103 snapshot_file->length()), |
94 output, sizeof(output)); | 104 output, sizeof(output)); |
95 return !memcmp(fingerprint, output, sizeof(output)); | 105 return !memcmp(fingerprint, output, sizeof(output)); |
96 } | 106 } |
97 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA | 107 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA |
98 | 108 |
99 #if !defined(OS_MACOSX) | 109 #if !defined(OS_MACOSX) |
100 const int v8_snapshot_dir = | 110 const int v8_snapshot_dir = |
101 #if defined(OS_ANDROID) | 111 #if defined(OS_ANDROID) |
102 base::DIR_ANDROID_APP_DATA; | 112 base::DIR_ANDROID_APP_DATA; |
103 #elif defined(OS_POSIX) | 113 #elif defined(OS_POSIX) |
104 base::DIR_EXE; | 114 base::DIR_EXE; |
| 115 #elif defined(OS_WIN) |
| 116 base::DIR_MODULE; |
105 #endif // OS_ANDROID | 117 #endif // OS_ANDROID |
106 #endif // !OS_MACOSX | 118 #endif // !OS_MACOSX |
107 | 119 |
108 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 120 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
109 | 121 |
110 } // namespace | 122 } // namespace |
111 | 123 |
112 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 124 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
113 | 125 |
114 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 126 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 base::MessageLoop::current()->AddTaskObserver(task_observer_.get()); | 291 base::MessageLoop::current()->AddTaskObserver(task_observer_.get()); |
280 } | 292 } |
281 | 293 |
282 void IsolateHolder::RemoveRunMicrotasksObserver() { | 294 void IsolateHolder::RemoveRunMicrotasksObserver() { |
283 DCHECK(task_observer_.get()); | 295 DCHECK(task_observer_.get()); |
284 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); | 296 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); |
285 task_observer_.reset(); | 297 task_observer_.reset(); |
286 } | 298 } |
287 | 299 |
288 } // namespace gin | 300 } // namespace gin |
OLD | NEW |