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