OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/run_loop.h" | |
6 #include "components/nacl/loader/nacl_listener.h" | 5 #include "components/nacl/loader/nacl_listener.h" |
7 | 6 |
8 #include <errno.h> | 7 #include <errno.h> |
9 #include <fcntl.h> | 8 #include <fcntl.h> |
10 #include <stdlib.h> | 9 #include <stdlib.h> |
11 #include <string.h> | 10 #include <string.h> |
12 | 11 |
13 #include <memory> | 12 #include <memory> |
| 13 #include <utility> |
14 | 14 |
15 #if defined(OS_POSIX) | 15 #if defined(OS_POSIX) |
16 #include <unistd.h> | 16 #include <unistd.h> |
17 #endif | 17 #endif |
18 | 18 |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/memory/ptr_util.h" |
21 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
22 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
23 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
24 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
25 #include "build/build_config.h" | 26 #include "build/build_config.h" |
26 #include "components/nacl/common/nacl_messages.h" | 27 #include "components/nacl/common/nacl_messages.h" |
27 #include "components/nacl/common/nacl_renderer_messages.h" | 28 #include "components/nacl/common/nacl_renderer_messages.h" |
28 #include "components/nacl/common/nacl_switches.h" | 29 #include "components/nacl/common/nacl_switches.h" |
29 #include "components/nacl/loader/nacl_ipc_adapter.h" | 30 #include "components/nacl/loader/nacl_ipc_adapter.h" |
30 #include "components/nacl/loader/nacl_validation_db.h" | 31 #include "components/nacl/loader/nacl_validation_db.h" |
31 #include "components/nacl/loader/nacl_validation_query.h" | 32 #include "components/nacl/loader/nacl_validation_query.h" |
| 33 #include "content/public/common/mojo_channel_switches.h" |
32 #include "ipc/attachment_broker_unprivileged.h" | 34 #include "ipc/attachment_broker_unprivileged.h" |
33 #include "ipc/ipc_channel_handle.h" | 35 #include "ipc/ipc_channel_handle.h" |
34 #include "ipc/ipc_switches.h" | 36 #include "ipc/ipc_switches.h" |
35 #include "ipc/ipc_sync_channel.h" | 37 #include "ipc/ipc_sync_channel.h" |
36 #include "ipc/ipc_sync_message_filter.h" | 38 #include "ipc/ipc_sync_message_filter.h" |
| 39 #include "mojo/edk/embedder/embedder.h" |
| 40 #include "mojo/edk/embedder/scoped_ipc_support.h" |
37 #include "native_client/src/public/chrome_main.h" | 41 #include "native_client/src/public/chrome_main.h" |
38 #include "native_client/src/public/nacl_app.h" | 42 #include "native_client/src/public/nacl_app.h" |
39 #include "native_client/src/public/nacl_desc.h" | 43 #include "native_client/src/public/nacl_desc.h" |
40 | 44 |
41 #if defined(OS_POSIX) | 45 #if defined(OS_POSIX) |
42 #include "base/file_descriptor_posix.h" | 46 #include "base/file_descriptor_posix.h" |
| 47 #include "base/posix/global_descriptors.h" |
| 48 #include "content/public/common/content_descriptors.h" |
43 #endif | 49 #endif |
44 | 50 |
45 #if defined(OS_LINUX) | 51 #if defined(OS_LINUX) |
46 #include "content/public/common/child_process_sandbox_support_linux.h" | 52 #include "content/public/common/child_process_sandbox_support_linux.h" |
47 #endif | 53 #endif |
48 | 54 |
49 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
50 #include <io.h> | 56 #include <io.h> |
51 | 57 |
52 #include "content/public/common/sandbox_init.h" | 58 #include "content/public/common/sandbox_init.h" |
| 59 #include "mojo/edk/embedder/platform_channel_pair.h" |
53 #endif | 60 #endif |
54 | 61 |
55 namespace { | 62 namespace { |
56 | 63 |
57 NaClListener* g_listener; | 64 NaClListener* g_listener; |
58 | 65 |
59 void FatalLogHandler(const char* data, size_t bytes) { | 66 void FatalLogHandler(const char* data, size_t bytes) { |
60 // We use uint32_t rather than size_t for the case when the browser and NaCl | 67 // We use uint32_t rather than size_t for the case when the browser and NaCl |
61 // processes are a mix of 32-bit and 64-bit processes. | 68 // processes are a mix of 32-bit and 64-bit processes. |
62 uint32_t copy_bytes = std::min<uint32_t>(static_cast<uint32_t>(bytes), | 69 uint32_t copy_bytes = std::min<uint32_t>(static_cast<uint32_t>(bytes), |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 #endif | 173 #endif |
167 #if defined(OS_POSIX) | 174 #if defined(OS_POSIX) |
168 number_of_cores_(-1), // unknown/error | 175 number_of_cores_(-1), // unknown/error |
169 #endif | 176 #endif |
170 is_started_(false) { | 177 is_started_(false) { |
171 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); | 178 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); |
172 io_thread_.StartWithOptions( | 179 io_thread_.StartWithOptions( |
173 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 180 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
174 DCHECK(g_listener == NULL); | 181 DCHECK(g_listener == NULL); |
175 g_listener = this; | 182 g_listener = this; |
| 183 |
| 184 mojo_ipc_support_ = |
| 185 base::MakeUnique<mojo::edk::ScopedIPCSupport>(io_thread_.task_runner()); |
| 186 #if defined(OS_WIN) |
| 187 mojo::edk::ScopedPlatformHandle platform_channel( |
| 188 mojo::edk::PlatformChannelPair::PassClientHandleFromParentProcess( |
| 189 *base::CommandLine::ForCurrentProcess())); |
| 190 #else |
| 191 mojo::edk::ScopedPlatformHandle platform_channel( |
| 192 mojo::edk::PlatformHandle( |
| 193 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel))); |
| 194 #endif |
| 195 DCHECK(platform_channel.is_valid()); |
| 196 mojo::edk::SetParentPipeHandle(std::move(platform_channel)); |
176 } | 197 } |
177 | 198 |
178 NaClListener::~NaClListener() { | 199 NaClListener::~NaClListener() { |
179 NOTREACHED(); | 200 NOTREACHED(); |
180 shutdown_event_.Signal(); | 201 shutdown_event_.Signal(); |
181 g_listener = NULL; | 202 g_listener = NULL; |
182 } | 203 } |
183 | 204 |
184 bool NaClListener::Send(IPC::Message* msg) { | 205 bool NaClListener::Send(IPC::Message* msg) { |
185 DCHECK(!!main_task_runner_); | 206 DCHECK(!!main_task_runner_); |
(...skipping 28 matching lines...) Expand all Loading... |
214 IPC::PlatformFileForTransit ipc_fd, | 235 IPC::PlatformFileForTransit ipc_fd, |
215 base::FilePath file_path) { | 236 base::FilePath file_path) { |
216 CHECK(g_listener); | 237 CHECK(g_listener); |
217 g_listener->OnFileTokenResolved(token_lo, token_hi, ipc_fd, file_path); | 238 g_listener->OnFileTokenResolved(token_lo, token_hi, ipc_fd, file_path); |
218 } | 239 } |
219 private: | 240 private: |
220 ~FileTokenMessageFilter() override {} | 241 ~FileTokenMessageFilter() override {} |
221 }; | 242 }; |
222 | 243 |
223 void NaClListener::Listen() { | 244 void NaClListener::Listen() { |
224 std::string channel_name = | 245 mojo::ScopedMessagePipeHandle handle( |
225 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 246 mojo::edk::CreateChildMessagePipe( |
226 switches::kProcessChannelID); | 247 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 248 switches::kMojoChannelToken))); |
| 249 DCHECK(handle.is_valid()); |
| 250 IPC::ChannelHandle channel_handle(handle.release()); |
| 251 |
227 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(), | 252 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(), |
228 &shutdown_event_); | 253 &shutdown_event_); |
229 filter_ = channel_->CreateSyncMessageFilter(); | 254 filter_ = channel_->CreateSyncMessageFilter(); |
230 channel_->AddFilter(new FileTokenMessageFilter()); | 255 channel_->AddFilter(new FileTokenMessageFilter()); |
231 IPC::AttachmentBroker* global = IPC::AttachmentBroker::GetGlobal(); | 256 IPC::AttachmentBroker* global = IPC::AttachmentBroker::GetGlobal(); |
232 if (global && !global->IsPrivilegedBroker()) | 257 if (global && !global->IsPrivilegedBroker()) |
233 global->RegisterBrokerCommunicationChannel(channel_.get()); | 258 global->RegisterBrokerCommunicationChannel(channel_.get()); |
234 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true); | 259 channel_->Init(channel_handle, IPC::Channel::MODE_CLIENT, true); |
235 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 260 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
236 base::RunLoop().Run(); | 261 base::RunLoop().Run(); |
237 } | 262 } |
238 | 263 |
239 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { | 264 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { |
240 bool handled = true; | 265 bool handled = true; |
241 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) | 266 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) |
242 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource, | 267 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource, |
243 OnAddPrefetchedResource) | 268 OnAddPrefetchedResource) |
244 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) | 269 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 } | 475 } |
451 | 476 |
452 void NaClListener::OnFileTokenResolved( | 477 void NaClListener::OnFileTokenResolved( |
453 uint64_t token_lo, | 478 uint64_t token_lo, |
454 uint64_t token_hi, | 479 uint64_t token_hi, |
455 IPC::PlatformFileForTransit ipc_fd, | 480 IPC::PlatformFileForTransit ipc_fd, |
456 base::FilePath file_path) { | 481 base::FilePath file_path) { |
457 resolved_cb_.Run(ipc_fd, file_path); | 482 resolved_cb_.Run(ipc_fd, file_path); |
458 resolved_cb_.Reset(); | 483 resolved_cb_.Reset(); |
459 } | 484 } |
OLD | NEW |