summaryrefslogtreecommitdiffstats
path: root/gin
diff options
context:
space:
mode:
authortobiasjs <tobiasjs@chromium.org>2016-02-10 03:54:12 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-10 11:56:11 +0000
commitb2001627a9e1dcf3df5218424a55e32143b957b1 (patch)
treee840c76250adc68abc7b79b82959881cfbdaaf4d /gin
parent5c19be8c985db1f4c158ca854252b2dd41b64f3c (diff)
downloadchromium_src-b2001627a9e1dcf3df5218424a55e32143b957b1.zip
chromium_src-b2001627a9e1dcf3df5218424a55e32143b957b1.tar.gz
chromium_src-b2001627a9e1dcf3df5218424a55e32143b957b1.tar.bz2
Pass both 32 and 64 bit snapshot and natives fds to child processes.
Child processes are in the best position to determine which files to use, therefore it is simplest just to provide both 32 and 64 bit versions from the parent. BUG=581409,455699 Committed: https://crrev.com/c560d75783aca05249092dd11503b53f7b631be1 Cr-Commit-Position: refs/heads/master@{#374371} Review URL: https://codereview.chromium.org/1665513002 Cr-Commit-Position: refs/heads/master@{#374643}
Diffstat (limited to 'gin')
-rw-r--r--gin/v8_initializer.cc128
-rw-r--r--gin/v8_initializer.h13
2 files changed, 104 insertions, 37 deletions
diff --git a/gin/v8_initializer.cc b/gin/v8_initializer.cc
index cfb3630..bb31951 100644
--- a/gin/v8_initializer.cc
+++ b/gin/v8_initializer.cc
@@ -11,6 +11,7 @@
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/memory_mapped_file.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
@@ -50,19 +51,34 @@ const base::PlatformFile kInvalidPlatformFile =
// File handles intentionally never closed. Not using File here because its
// Windows implementation guards against two instances owning the same
// PlatformFile (which we allow since we know it is never freed).
-base::PlatformFile g_natives_pf = kInvalidPlatformFile;
-base::PlatformFile g_snapshot_pf = kInvalidPlatformFile;
-base::MemoryMappedFile::Region g_natives_region;
-base::MemoryMappedFile::Region g_snapshot_region;
+typedef std::map<const char*,
+ std::pair<base::PlatformFile, base::MemoryMappedFile::Region>>
+ OpenedFileMap;
+static base::LazyInstance<OpenedFileMap>::Leaky g_opened_files =
+ LAZY_INSTANCE_INITIALIZER;
+
+OpenedFileMap::mapped_type& GetOpenedFile(const char* file) {
+ OpenedFileMap& opened_files(g_opened_files.Get());
+ if (opened_files.find(file) == opened_files.end()) {
+ opened_files[file] =
+ std::make_pair(kInvalidPlatformFile, base::MemoryMappedFile::Region());
+ }
+ return opened_files[file];
+}
#if defined(OS_ANDROID)
-#ifdef __LP64__
-const char kNativesFileName[] = "natives_blob_64.bin";
-const char kSnapshotFileName[] = "snapshot_blob_64.bin";
+const char kNativesFileName64[] = "natives_blob_64.bin";
+const char kSnapshotFileName64[] = "snapshot_blob_64.bin";
+const char kNativesFileName32[] = "natives_blob_32.bin";
+const char kSnapshotFileName32[] = "snapshot_blob_32.bin";
+
+#if defined(__LP64__)
+#define kNativesFileName kNativesFileName64
+#define kSnapshotFileName kSnapshotFileName64
#else
-const char kNativesFileName[] = "natives_blob_32.bin";
-const char kSnapshotFileName[] = "snapshot_blob_32.bin";
-#endif // __LP64__
+#define kNativesFileName kNativesFileName32
+#define kSnapshotFileName kSnapshotFileName32
+#endif
#else // defined(OS_ANDROID)
const char kNativesFileName[] = "natives_blob.bin";
@@ -170,16 +186,13 @@ base::PlatformFile OpenV8File(const char* file_name,
return file.TakePlatformFile();
}
-void OpenNativesFileIfNecessary() {
- if (g_natives_pf == kInvalidPlatformFile) {
- g_natives_pf = OpenV8File(kNativesFileName, &g_natives_region);
- }
-}
-
-void OpenSnapshotFileIfNecessary() {
- if (g_snapshot_pf == kInvalidPlatformFile) {
- g_snapshot_pf = OpenV8File(kSnapshotFileName, &g_snapshot_region);
+static const OpenedFileMap::mapped_type OpenFileIfNecessary(
+ const char* file_name) {
+ OpenedFileMap::mapped_type& opened = GetOpenedFile(file_name);
+ if (opened.first == kInvalidPlatformFile) {
+ opened.first = OpenV8File(file_name, &opened.second);
}
+ return opened;
}
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
@@ -236,15 +249,14 @@ enum LoadV8FileResult {
V8_LOAD_MAX_VALUE
};
-static LoadV8FileResult MapVerify(base::PlatformFile platform_file,
- const base::MemoryMappedFile::Region& region,
+static LoadV8FileResult MapVerify(const OpenedFileMap::mapped_type& file_region,
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
const unsigned char* fingerprint,
#endif
base::MemoryMappedFile** mmapped_file_out) {
- if (platform_file == kInvalidPlatformFile)
+ if (file_region.first == kInvalidPlatformFile)
return V8_LOAD_FAILED_OPEN;
- if (!MapV8File(platform_file, region, mmapped_file_out))
+ if (!MapV8File(file_region.first, file_region.second, mmapped_file_out))
return V8_LOAD_FAILED_MAP;
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
if (!VerifyV8StartupFile(mmapped_file_out, fingerprint))
@@ -258,8 +270,8 @@ void V8Initializer::LoadV8Snapshot() {
if (g_mapped_snapshot)
return;
- OpenSnapshotFileIfNecessary();
- LoadV8FileResult result = MapVerify(g_snapshot_pf, g_snapshot_region,
+ OpenFileIfNecessary(kSnapshotFileName);
+ LoadV8FileResult result = MapVerify(GetOpenedFile(kSnapshotFileName),
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
g_snapshot_fingerprint,
#endif
@@ -274,8 +286,8 @@ void V8Initializer::LoadV8Natives() {
if (g_mapped_natives)
return;
- OpenNativesFileIfNecessary();
- LoadV8FileResult result = MapVerify(g_natives_pf, g_natives_region,
+ OpenFileIfNecessary(kNativesFileName);
+ LoadV8FileResult result = MapVerify(GetOpenedFile(kNativesFileName),
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
g_natives_fingerprint,
#endif
@@ -311,8 +323,8 @@ void V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile snapshot_pf,
result = V8_LOAD_FAILED_VERIFY;
#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA
if (result == V8_LOAD_SUCCESS) {
- g_snapshot_pf = snapshot_pf;
- g_snapshot_region = snapshot_region;
+ g_opened_files.Get()[kSnapshotFileName] =
+ std::make_pair(snapshot_pf, snapshot_region);
}
UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result,
V8_LOAD_MAX_VALUE);
@@ -342,25 +354,51 @@ void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf,
LOG(FATAL) << "Couldn't verify contents of v8 natives data file";
}
#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA
- g_natives_pf = natives_pf;
- g_natives_region = natives_region;
+ g_opened_files.Get()[kNativesFileName] =
+ std::make_pair(natives_pf, natives_region);
}
// static
base::PlatformFile V8Initializer::GetOpenNativesFileForChildProcesses(
base::MemoryMappedFile::Region* region_out) {
- OpenNativesFileIfNecessary();
- *region_out = g_natives_region;
- return g_natives_pf;
+ const OpenedFileMap::mapped_type& opened =
+ OpenFileIfNecessary(kNativesFileName);
+ *region_out = opened.second;
+ return opened.first;
}
// static
base::PlatformFile V8Initializer::GetOpenSnapshotFileForChildProcesses(
base::MemoryMappedFile::Region* region_out) {
- OpenSnapshotFileIfNecessary();
- *region_out = g_snapshot_region;
- return g_snapshot_pf;
+ const OpenedFileMap::mapped_type& opened =
+ OpenFileIfNecessary(kSnapshotFileName);
+ *region_out = opened.second;
+ return opened.first;
+}
+
+#if defined(OS_ANDROID)
+// static
+base::PlatformFile V8Initializer::GetOpenNativesFileForChildProcesses(
+ base::MemoryMappedFile::Region* region_out,
+ bool abi_32_bit) {
+ const char* natives_file =
+ abi_32_bit ? kNativesFileName32 : kNativesFileName64;
+ const OpenedFileMap::mapped_type& opened = OpenFileIfNecessary(natives_file);
+ *region_out = opened.second;
+ return opened.first;
+}
+
+// static
+base::PlatformFile V8Initializer::GetOpenSnapshotFileForChildProcesses(
+ base::MemoryMappedFile::Region* region_out,
+ bool abi_32_bit) {
+ const char* snapshot_file =
+ abi_32_bit ? kSnapshotFileName32 : kSnapshotFileName64;
+ const OpenedFileMap::mapped_type& opened = OpenFileIfNecessary(snapshot_file);
+ *region_out = opened.second;
+ return opened.first;
}
+#endif // defined(OS_ANDROID)
#endif // defined(V8_USE_EXTERNAL_STARTUP_DATA)
// static
@@ -423,4 +461,20 @@ void V8Initializer::GetV8ExternalSnapshotData(const char** natives_data_out,
}
}
+#if defined(OS_ANDROID)
+// static
+base::FilePath V8Initializer::GetNativesFilePath(bool abi_32_bit) {
+ base::FilePath path;
+ GetV8FilePath(abi_32_bit ? kNativesFileName32 : kNativesFileName64, &path);
+ return path;
+}
+
+// static
+base::FilePath V8Initializer::GetSnapshotFilePath(bool abi_32_bit) {
+ base::FilePath path;
+ GetV8FilePath(abi_32_bit ? kSnapshotFileName32 : kSnapshotFileName64, &path);
+ return path;
+}
+#endif // defined(OS_ANDROID)
+
} // namespace gin
diff --git a/gin/v8_initializer.h b/gin/v8_initializer.h
index dcb5329..4c03480 100644
--- a/gin/v8_initializer.h
+++ b/gin/v8_initializer.h
@@ -65,6 +65,19 @@ class GIN_EXPORT V8Initializer {
// Will return -1 if the file does not exist.
static base::PlatformFile GetOpenSnapshotFileForChildProcesses(
base::MemoryMappedFile::Region* region_out);
+
+#if defined(OS_ANDROID)
+ static base::PlatformFile GetOpenNativesFileForChildProcesses(
+ base::MemoryMappedFile::Region* region_out,
+ bool abi_32_bit);
+ static base::PlatformFile GetOpenSnapshotFileForChildProcesses(
+ base::MemoryMappedFile::Region* region_out,
+ bool abi_32_bit);
+
+ static base::FilePath GetNativesFilePath(bool abi_32_bit);
+ static base::FilePath GetSnapshotFilePath(bool abi_32_bit);
+#endif
+
#endif // V8_USE_EXTERNAL_STARTUP_DATA
};