summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authoramistry <amistry@chromium.org>2016-03-21 11:32:47 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-21 18:33:59 +0000
commit6bebadddb399ad1c1f91592efed410040617e708 (patch)
tree1426cccc724ed9d24a312e17b8b3352d04aaa086 /mojo
parent4950587322e8c7d7fff97a65ed9be1bb5030a9cc (diff)
downloadchromium_src-6bebadddb399ad1c1f91592efed410040617e708.zip
chromium_src-6bebadddb399ad1c1f91592efed410040617e708.tar.gz
chromium_src-6bebadddb399ad1c1f91592efed410040617e708.tar.bz2
Add mach ports support to the Mojo shell.
BUG=582468 Review URL: https://codereview.chromium.org/1812523003 Cr-Commit-Position: refs/heads/master@{#382335}
Diffstat (limited to 'mojo')
-rw-r--r--mojo/mojo_shell.gyp6
-rw-r--r--mojo/shell/runner/host/BUILD.gn7
-rw-r--r--mojo/shell/runner/host/child_process.cc9
-rw-r--r--mojo/shell/runner/host/child_process_host.cc14
-rw-r--r--mojo/shell/runner/host/mach_broker.cc45
-rw-r--r--mojo/shell/runner/host/mach_broker.h54
-rw-r--r--mojo/shell/standalone/context.cc10
7 files changed, 144 insertions, 1 deletions
diff --git a/mojo/mojo_shell.gyp b/mojo/mojo_shell.gyp
index 0b95228..9f4c80b 100644
--- a/mojo/mojo_shell.gyp
+++ b/mojo/mojo_shell.gyp
@@ -141,6 +141,12 @@
'<(DEPTH)/sandbox/sandbox.gyp:seccomp_bpf_helpers',
],
}],
+ ['OS=="mac"', {
+ 'sources': [
+ 'shell/runner/host/mach_broker.cc',
+ 'shell/runner/host/mach_broker.h',
+ ],
+ }],
],
}],
}
diff --git a/mojo/shell/runner/host/BUILD.gn b/mojo/shell/runner/host/BUILD.gn
index 67066af..edcce93 100644
--- a/mojo/shell/runner/host/BUILD.gn
+++ b/mojo/shell/runner/host/BUILD.gn
@@ -99,6 +99,13 @@ source_set("lib") {
"//sandbox/linux:seccomp_bpf_helpers",
]
}
+
+ if (is_mac) {
+ sources += [
+ "mach_broker.cc",
+ "mach_broker.h",
+ ]
+ }
}
test("mojo_runner_host_unittests") {
diff --git a/mojo/shell/runner/host/child_process.cc b/mojo/shell/runner/host/child_process.cc
index 51915d7..260dc66 100644
--- a/mojo/shell/runner/host/child_process.cc
+++ b/mojo/shell/runner/host/child_process.cc
@@ -44,6 +44,10 @@
#include "mojo/shell/runner/host/linux_sandbox.h"
#endif
+#if defined(OS_MACOSX)
+#include "mojo/shell/runner/host/mach_broker.h"
+#endif
+
namespace mojo {
namespace shell {
@@ -103,6 +107,11 @@ int ChildProcessMain() {
if (app_library)
CallLibraryEarlyInitialization(app_library);
+#if defined(OS_MACOSX)
+ // Send our task port to the parent.
+ MachBroker::SendTaskPortToParent();
+#endif
+
#if !defined(OFFICIAL_BUILD)
// Initialize stack dumping just before initializing sandbox to make
// sure symbol names in all loaded libraries will be cached.
diff --git a/mojo/shell/runner/host/child_process_host.cc b/mojo/shell/runner/host/child_process_host.cc
index f887dbd..19a5161 100644
--- a/mojo/shell/runner/host/child_process_host.cc
+++ b/mojo/shell/runner/host/child_process_host.cc
@@ -16,6 +16,7 @@
#include "base/message_loop/message_loop.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
+#include "base/synchronization/lock.h"
#include "base/task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "mojo/edk/embedder/embedder.h"
@@ -33,6 +34,10 @@
#include "base/win/windows_version.h"
#endif
+#if defined(OS_MACOSX)
+#include "mojo/shell/runner/host/mach_broker.h"
+#endif
+
namespace mojo {
namespace shell {
@@ -179,7 +184,16 @@ void ChildProcessHost::DoLaunch(
}
} else
#endif
+ {
+#if defined(OS_MACOSX)
+ MachBroker* mach_broker = MachBroker::GetInstance();
+ base::AutoLock locker(mach_broker->GetLock());
+#endif
child_process_ = base::LaunchProcess(*child_command_line, options);
+#if defined(OS_MACOSX)
+ mach_broker->ExpectPid(child_process_.Handle());
+#endif
+ }
if (child_process_.IsValid()) {
if (mojo_ipc_channel_.get()) {
diff --git a/mojo/shell/runner/host/mach_broker.cc b/mojo/shell/runner/host/mach_broker.cc
new file mode 100644
index 0000000..8b99279
--- /dev/null
+++ b/mojo/shell/runner/host/mach_broker.cc
@@ -0,0 +1,45 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/shell/runner/host/mach_broker.h"
+
+#include "base/logging.h"
+#include "base/memory/singleton.h"
+
+namespace mojo {
+namespace shell {
+
+namespace {
+const char kBootstrapPortName[] = "mojo_shell";
+}
+
+// static
+void MachBroker::SendTaskPortToParent() {
+ bool result = base::MachPortBroker::ChildSendTaskPortToParent(
+ kBootstrapPortName);
+ DCHECK(result);
+}
+
+// static
+MachBroker* MachBroker::GetInstance() {
+ return base::Singleton<MachBroker>::get();
+}
+
+MachBroker::MachBroker() : broker_(kBootstrapPortName) {
+ bool result = broker_.Init();
+ DCHECK(result);
+}
+
+MachBroker::~MachBroker() {}
+
+void MachBroker::ExpectPid(base::ProcessHandle pid) {
+ broker_.AddPlaceholderForPid(pid);
+}
+
+void MachBroker::RemovePid(base::ProcessHandle pid) {
+ broker_.InvalidatePid(pid);
+}
+
+} // namespace shell
+} // namespace mojo
diff --git a/mojo/shell/runner/host/mach_broker.h b/mojo/shell/runner/host/mach_broker.h
new file mode 100644
index 0000000..19b4b8b
--- /dev/null
+++ b/mojo/shell/runner/host/mach_broker.h
@@ -0,0 +1,54 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SHELL_RUNNER_HOST_MACH_BROKER_H_
+#define MOJO_SHELL_RUNNER_HOST_MACH_BROKER_H_
+
+#include "base/mac/mach_port_broker.h"
+
+namespace base {
+template <typename T> struct DefaultSingletonTraits;
+}
+
+namespace mojo {
+namespace shell {
+
+// A global singleton |MachBroker| is used by the shell to provide access to
+// Mach task ports for shell out-of-process applications.
+class MachBroker {
+ public:
+ // Sends the task port of the current process to the parent over Mach IPC.
+ // For use in child processes.
+ static void SendTaskPortToParent();
+
+ // Returns the global |MachBroker|. For use in the shell.
+ static MachBroker* GetInstance();
+
+ // Registers |pid| with a MACH_PORT_NULL task port in the port provider. A
+ // child's pid must be registered before the broker will accept a task port
+ // from that child.
+ // Callers MUST acquire the lock given by GetLock() before calling this method
+ // (and release the lock afterwards).
+ void ExpectPid(base::ProcessHandle pid);
+
+ // Removes |pid| from the port provider.
+ // Callers MUST acquire the lock given by GetLock() before calling this method
+ // (and release the lock afterwards).
+ void RemovePid(base::ProcessHandle pid);
+
+ base::Lock& GetLock() { return broker_.GetLock(); }
+ base::PortProvider* port_provider() { return &broker_; }
+
+ private:
+ MachBroker();
+ ~MachBroker();
+ friend struct base::DefaultSingletonTraits<MachBroker>;
+
+ base::MachPortBroker broker_;
+};
+
+} // namespace shell
+} // namespace mojo
+
+#endif // MOJO_SHELL_RUNNER_HOST_MACH_BROKER_H_
diff --git a/mojo/shell/standalone/context.cc b/mojo/shell/standalone/context.cc
index 5b53879..e64ed82 100644
--- a/mojo/shell/standalone/context.cc
+++ b/mojo/shell/standalone/context.cc
@@ -43,6 +43,10 @@
#include "mojo/shell/switches.h"
#include "mojo/util/filename_util.h"
+#if defined(OS_MACOSX)
+#include "mojo/shell/runner/host/mach_broker.h"
+#endif
+
namespace mojo {
namespace shell {
namespace {
@@ -136,8 +140,12 @@ void Context::Init(scoped_ptr<InitParams> init_params) {
blocking_pool_ =
new base::SequencedWorkerPool(kMaxBlockingPoolThreads, "blocking_pool");
- if (!init_params || init_params->init_edk)
+ if (!init_params || init_params->init_edk) {
edk::InitIPCSupport(this, io_thread_->task_runner().get());
+#if defined(OS_MACOSX)
+ edk::SetMachPortProvider(MachBroker::GetInstance()->port_provider());
+#endif
+ }
scoped_ptr<NativeRunnerFactory> runner_factory;
if (command_line.HasSwitch(switches::kSingleProcess)) {