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