| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/shell/runner/host/child_process.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <utility> | |
| 10 | |
| 11 #include "base/base_switches.h" | |
| 12 #include "base/bind.h" | |
| 13 #include "base/callback_helpers.h" | |
| 14 #include "base/command_line.h" | |
| 15 #include "base/debug/stack_trace.h" | |
| 16 #include "base/files/file_path.h" | |
| 17 #include "base/i18n/icu_util.h" | |
| 18 #include "base/location.h" | |
| 19 #include "base/logging.h" | |
| 20 #include "base/macros.h" | |
| 21 #include "base/memory/ref_counted.h" | |
| 22 #include "base/memory/scoped_ptr.h" | |
| 23 #include "base/message_loop/message_loop.h" | |
| 24 #include "base/single_thread_task_runner.h" | |
| 25 #include "base/synchronization/waitable_event.h" | |
| 26 #include "base/thread_task_runner_handle.h" | |
| 27 #include "base/threading/thread.h" | |
| 28 #include "base/threading/thread_checker.h" | |
| 29 #include "mojo/edk/embedder/embedder.h" | |
| 30 #include "mojo/edk/embedder/platform_channel_pair.h" | |
| 31 #include "mojo/edk/embedder/process_delegate.h" | |
| 32 #include "mojo/edk/embedder/scoped_platform_handle.h" | |
| 33 #include "mojo/message_pump/message_pump_mojo.h" | |
| 34 #include "mojo/public/cpp/bindings/binding.h" | |
| 35 #include "mojo/public/cpp/system/core.h" | |
| 36 #include "mojo/shell/runner/common/switches.h" | |
| 37 #include "mojo/shell/runner/host/child_process_base.h" | |
| 38 #include "mojo/shell/runner/host/native_application_support.h" | |
| 39 #include "mojo/shell/runner/init.h" | |
| 40 | |
| 41 #if defined(OS_LINUX) && !defined(OS_ANDROID) | |
| 42 #include "base/rand_util.h" | |
| 43 #include "base/sys_info.h" | |
| 44 #include "mojo/shell/runner/host/linux_sandbox.h" | |
| 45 #endif | |
| 46 | |
| 47 #if defined(OS_MACOSX) | |
| 48 #include "mojo/shell/runner/host/mach_broker.h" | |
| 49 #endif | |
| 50 | |
| 51 namespace mojo { | |
| 52 namespace shell { | |
| 53 | |
| 54 namespace { | |
| 55 | |
| 56 #if defined(OS_LINUX) && !defined(OS_ANDROID) | |
| 57 scoped_ptr<mojo::shell::LinuxSandbox> InitializeSandbox() { | |
| 58 using sandbox::syscall_broker::BrokerFilePermission; | |
| 59 // Warm parts of base in the copy of base in the mojo runner. | |
| 60 base::RandUint64(); | |
| 61 base::SysInfo::AmountOfPhysicalMemory(); | |
| 62 base::SysInfo::MaxSharedMemorySize(); | |
| 63 base::SysInfo::NumberOfProcessors(); | |
| 64 | |
| 65 // TODO(erg,jln): Allowing access to all of /dev/shm/ makes it easy to | |
| 66 // spy on other shared memory using processes. This is a temporary hack | |
| 67 // so that we have some sandbox until we have proper shared memory | |
| 68 // support integrated into mojo. | |
| 69 std::vector<BrokerFilePermission> permissions; | |
| 70 permissions.push_back( | |
| 71 BrokerFilePermission::ReadWriteCreateUnlinkRecursive("/dev/shm/")); | |
| 72 scoped_ptr<mojo::shell::LinuxSandbox> sandbox( | |
| 73 new mojo::shell::LinuxSandbox(permissions)); | |
| 74 sandbox->Warmup(); | |
| 75 sandbox->EngageNamespaceSandbox(); | |
| 76 sandbox->EngageSeccompSandbox(); | |
| 77 sandbox->Seal(); | |
| 78 return sandbox; | |
| 79 } | |
| 80 #endif | |
| 81 | |
| 82 void RunNativeLibrary( | |
| 83 base::NativeLibrary app_library, | |
| 84 InterfaceRequest<mojom::ShellClient> shell_client_request) { | |
| 85 if (!RunNativeApplication(app_library, std::move(shell_client_request))) { | |
| 86 LOG(ERROR) << "Failure to RunNativeApplication()"; | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 } // namespace | |
| 91 | |
| 92 int ChildProcessMain() { | |
| 93 DVLOG(2) << "ChildProcessMain()"; | |
| 94 const base::CommandLine& command_line = | |
| 95 *base::CommandLine::ForCurrentProcess(); | |
| 96 | |
| 97 #if defined(OS_LINUX) && !defined(OS_ANDROID) | |
| 98 scoped_ptr<mojo::shell::LinuxSandbox> sandbox; | |
| 99 #endif | |
| 100 base::NativeLibrary app_library = 0; | |
| 101 // Load the application library before we engage the sandbox. | |
| 102 base::FilePath app_library_path = | |
| 103 command_line.GetSwitchValuePath(switches::kChildProcess); | |
| 104 if (!app_library_path.empty()) | |
| 105 app_library = mojo::shell::LoadNativeApplication(app_library_path); | |
| 106 base::i18n::InitializeICU(); | |
| 107 if (app_library) | |
| 108 CallLibraryEarlyInitialization(app_library); | |
| 109 | |
| 110 #if defined(OS_MACOSX) | |
| 111 // Send our task port to the parent. | |
| 112 MachBroker::SendTaskPortToParent(); | |
| 113 #endif | |
| 114 | |
| 115 #if !defined(OFFICIAL_BUILD) | |
| 116 // Initialize stack dumping just before initializing sandbox to make | |
| 117 // sure symbol names in all loaded libraries will be cached. | |
| 118 base::debug::EnableInProcessStackDumping(); | |
| 119 #endif | |
| 120 #if defined(OS_LINUX) && !defined(OS_ANDROID) | |
| 121 if (command_line.HasSwitch(switches::kEnableSandbox)) | |
| 122 sandbox = InitializeSandbox(); | |
| 123 #endif | |
| 124 | |
| 125 ChildProcessMain(base::Bind(&RunNativeLibrary, app_library)); | |
| 126 | |
| 127 return 0; | |
| 128 } | |
| 129 | |
| 130 } // namespace shell | |
| 131 } // namespace mojo | |
| OLD | NEW |