| Index: content/app/content_main_runner.cc
|
| diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc
|
| index 5d799dc812168423e5a3d6c61d192a9dbee2ab6a..82d7533fb705ffc3bd9e25b620e759c0d3d54f6a 100644
|
| --- a/content/app/content_main_runner.cc
|
| +++ b/content/app/content_main_runner.cc
|
| @@ -52,6 +52,7 @@
|
| #include "content/public/app/content_main_delegate.h"
|
| #include "content/public/common/content_client.h"
|
| #include "content/public/common/content_constants.h"
|
| +#include "content/public/common/content_descriptor_keys.h"
|
| #include "content/public/common/content_paths.h"
|
| #include "content/public/common/content_switches.h"
|
| #include "content/public/common/main_function_params.h"
|
| @@ -59,6 +60,7 @@
|
| #include "ipc/ipc_descriptors.h"
|
| #include "media/base/media.h"
|
| #include "ppapi/features/features.h"
|
| +#include "services/service_manager/public/cpp/shared_file_util.h"
|
| #include "ui/base/ui_base_paths.h"
|
| #include "ui/base/ui_base_switches.h"
|
|
|
| @@ -88,6 +90,7 @@
|
| #if defined(OS_POSIX)
|
| #include <signal.h>
|
|
|
| +#include "base/file_descriptor_store.h"
|
| #include "base/posix/global_descriptors.h"
|
| #include "content/public/common/content_descriptors.h"
|
|
|
| @@ -147,9 +150,9 @@ namespace {
|
|
|
| #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID)
|
| #if defined __LP64__
|
| -#define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64
|
| +#define kV8SnapshotDataDescriptor kV8Snapshot64DataDescriptor
|
| #else
|
| -#define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32
|
| +#define kV8SnapshotDataDescriptor kV8Snapshot32DataDescriptor
|
| #endif
|
| #endif
|
|
|
| @@ -194,35 +197,22 @@ void InitializeV8IfNeeded(
|
|
|
| #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
| #if defined(OS_POSIX) && !defined(OS_MACOSX)
|
| - base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance();
|
| -#if !defined(OS_ANDROID)
|
| - // kV8NativesDataDescriptor and kV8SnapshotDataDescriptor could be shared
|
| - // with child processes via file descriptors. On Android they are set in
|
| - // ChildProcessService::InternalInitChildProcess, otherwise set them here.
|
| - if (command_line.HasSwitch(switches::kV8NativesPassedByFD)) {
|
| - g_fds->Set(
|
| - kV8NativesDataDescriptor,
|
| - kV8NativesDataDescriptor + base::GlobalDescriptors::kBaseDescriptor);
|
| - }
|
| - if (command_line.HasSwitch(switches::kV8SnapshotPassedByFD)) {
|
| - g_fds->Set(
|
| - kV8SnapshotDataDescriptor,
|
| - kV8SnapshotDataDescriptor + base::GlobalDescriptors::kBaseDescriptor);
|
| - }
|
| -#endif // !OS_ANDROID
|
| - int v8_natives_fd = g_fds->MaybeGet(kV8NativesDataDescriptor);
|
| - int v8_snapshot_fd = g_fds->MaybeGet(kV8SnapshotDataDescriptor);
|
| - if (v8_snapshot_fd != -1) {
|
| - auto v8_snapshot_region = g_fds->GetRegion(kV8SnapshotDataDescriptor);
|
| - gin::V8Initializer::LoadV8SnapshotFromFD(
|
| - v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size);
|
| + base::FileDescriptorStore& file_descriptor_store =
|
| + base::FileDescriptorStore::GetInstance();
|
| + base::MemoryMappedFile::Region region;
|
| + base::ScopedFD v8_snapshot_fd =
|
| + file_descriptor_store.MaybeTakeFD(kV8SnapshotDataDescriptor, ®ion);
|
| + if (v8_snapshot_fd.is_valid()) {
|
| + gin::V8Initializer::LoadV8SnapshotFromFD(v8_snapshot_fd.get(),
|
| + region.offset, region.size);
|
| } else {
|
| gin::V8Initializer::LoadV8Snapshot();
|
| }
|
| - if (v8_natives_fd != -1) {
|
| - auto v8_natives_region = g_fds->GetRegion(kV8NativesDataDescriptor);
|
| - gin::V8Initializer::LoadV8NativesFromFD(
|
| - v8_natives_fd, v8_natives_region.offset, v8_natives_region.size);
|
| + base::ScopedFD v8_natives_fd =
|
| + file_descriptor_store.MaybeTakeFD(kV8NativesDataDescriptor, ®ion);
|
| + if (v8_natives_fd.is_valid()) {
|
| + gin::V8Initializer::LoadV8NativesFromFD(v8_natives_fd.get(),
|
| + region.offset, region.size);
|
| } else {
|
| gin::V8Initializer::LoadV8Natives();
|
| }
|
| @@ -275,6 +265,27 @@ void SetupSignalHandlers() {
|
| CHECK_NE(SIG_ERR, signal(SIGPIPE, SIG_IGN));
|
| }
|
|
|
| +void PopulateFDsFromCommandLine() {
|
| + const std::string& shared_file_param =
|
| + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
|
| + switches::kSharedFiles);
|
| + if (shared_file_param.empty())
|
| + return;
|
| +
|
| + base::Optional<std::map<int, std::string>> shared_file_descriptors =
|
| + service_manager::ParseSharedFileSwitchValue(shared_file_param);
|
| + if (!shared_file_descriptors)
|
| + return;
|
| +
|
| + for (const auto& descriptor : *shared_file_descriptors) {
|
| + base::MemoryMappedFile::Region region;
|
| + const std::string& key = descriptor.second;
|
| + base::ScopedFD fd = base::GlobalDescriptors::GetInstance()->TakeFD(
|
| + descriptor.first, ®ion);
|
| + base::FileDescriptorStore::GetInstance().Set(key, std::move(fd), region);
|
| + }
|
| +}
|
| +
|
| #endif // OS_POSIX
|
|
|
| void CommonSubprocessInit() {
|
| @@ -597,8 +608,8 @@ class ContentMainRunnerImpl : public ContentMainRunner {
|
| InitializeMac();
|
| #endif
|
|
|
| - // On Android, the command line is initialized when library is loaded and
|
| - // we have already started our TRACE_EVENT0.
|
| +// On Android, the command line is initialized and the FDs set when the
|
| +// library is loaded and we have already started our TRACE_EVENT0.
|
| #if !defined(OS_ANDROID)
|
| // argc/argv are ignored on Windows and Android; see command_line.h for
|
| // details.
|
| @@ -612,6 +623,10 @@ class ContentMainRunnerImpl : public ContentMainRunner {
|
|
|
| base::CommandLine::Init(argc, argv);
|
|
|
| +#if defined(OS_POSIX)
|
| + PopulateFDsFromCommandLine();
|
| +#endif
|
| +
|
| base::EnableTerminationOnHeapCorruption();
|
|
|
| // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed.
|
|
|