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> |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "ipc/ipc_channel_handle.h" | 35 #include "ipc/ipc_channel_handle.h" |
36 #include "ipc/ipc_sync_channel.h" | 36 #include "ipc/ipc_sync_channel.h" |
37 #include "ipc/ipc_sync_message_filter.h" | 37 #include "ipc/ipc_sync_message_filter.h" |
38 #include "mojo/edk/embedder/embedder.h" | 38 #include "mojo/edk/embedder/embedder.h" |
39 #include "mojo/edk/embedder/scoped_ipc_support.h" | 39 #include "mojo/edk/embedder/scoped_ipc_support.h" |
40 #include "native_client/src/public/chrome_main.h" | 40 #include "native_client/src/public/chrome_main.h" |
41 #include "native_client/src/public/nacl_app.h" | 41 #include "native_client/src/public/nacl_app.h" |
42 #include "native_client/src/public/nacl_desc.h" | 42 #include "native_client/src/public/nacl_desc.h" |
43 | 43 |
44 #if defined(OS_POSIX) | 44 #if defined(OS_POSIX) |
45 #include "base/file_descriptor_posix.h" | |
46 #include "base/posix/global_descriptors.h" | 45 #include "base/posix/global_descriptors.h" |
47 #include "content/public/common/content_descriptors.h" | 46 #include "content/public/common/content_descriptors.h" |
48 #endif | 47 #endif |
49 | 48 |
50 #if defined(OS_LINUX) | 49 #if defined(OS_LINUX) |
51 #include "content/public/common/child_process_sandbox_support_linux.h" | 50 #include "content/public/common/child_process_sandbox_support_linux.h" |
52 #endif | 51 #endif |
53 | 52 |
54 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
55 #include <io.h> | 54 #include <io.h> |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // the given task runner runs. | 109 // the given task runner runs. |
111 // Also, creates and sets the corresponding NaClDesc to the given nap with | 110 // Also, creates and sets the corresponding NaClDesc to the given nap with |
112 // the FD #. | 111 // the FD #. |
113 void SetUpIPCAdapter( | 112 void SetUpIPCAdapter( |
114 IPC::ChannelHandle* handle, | 113 IPC::ChannelHandle* handle, |
115 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 114 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
116 struct NaClApp* nap, | 115 struct NaClApp* nap, |
117 int nacl_fd, | 116 int nacl_fd, |
118 NaClIPCAdapter::ResolveFileTokenCallback resolve_file_token_cb, | 117 NaClIPCAdapter::ResolveFileTokenCallback resolve_file_token_cb, |
119 NaClIPCAdapter::OpenResourceCallback open_resource_cb) { | 118 NaClIPCAdapter::OpenResourceCallback open_resource_cb) { |
120 scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter( | 119 mojo::MessagePipe pipe; |
121 *handle, task_runner.get(), resolve_file_token_cb, open_resource_cb)); | 120 scoped_refptr<NaClIPCAdapter> ipc_adapter( |
| 121 new NaClIPCAdapter(pipe.handle0.release(), task_runner, |
| 122 resolve_file_token_cb, open_resource_cb)); |
122 ipc_adapter->ConnectChannel(); | 123 ipc_adapter->ConnectChannel(); |
123 #if defined(OS_POSIX) | 124 *handle = pipe.handle1.release(); |
124 handle->socket = | |
125 base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor()); | |
126 #endif | |
127 | 125 |
128 // Pass a NaClDesc to the untrusted side. This will hold a ref to the | 126 // Pass a NaClDesc to the untrusted side. This will hold a ref to the |
129 // NaClIPCAdapter. | 127 // NaClIPCAdapter. |
130 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); | 128 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); |
131 } | 129 } |
132 | 130 |
133 } // namespace | 131 } // namespace |
134 | 132 |
135 class BrowserValidationDBProxy : public NaClValidationDB { | 133 class BrowserValidationDBProxy : public NaClValidationDB { |
136 public: | 134 public: |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 private: | 237 private: |
240 ~FileTokenMessageFilter() override {} | 238 ~FileTokenMessageFilter() override {} |
241 }; | 239 }; |
242 | 240 |
243 void NaClListener::Listen() { | 241 void NaClListener::Listen() { |
244 mojo::ScopedMessagePipeHandle handle( | 242 mojo::ScopedMessagePipeHandle handle( |
245 mojo::edk::CreateChildMessagePipe( | 243 mojo::edk::CreateChildMessagePipe( |
246 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 244 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
247 switches::kMojoChannelToken))); | 245 switches::kMojoChannelToken))); |
248 DCHECK(handle.is_valid()); | 246 DCHECK(handle.is_valid()); |
249 IPC::ChannelHandle channel_handle(handle.release()); | |
250 | 247 |
251 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(), | 248 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(), |
252 &shutdown_event_); | 249 &shutdown_event_); |
253 filter_ = channel_->CreateSyncMessageFilter(); | 250 filter_ = channel_->CreateSyncMessageFilter(); |
254 channel_->AddFilter(new FileTokenMessageFilter()); | 251 channel_->AddFilter(new FileTokenMessageFilter()); |
255 IPC::AttachmentBroker* global = IPC::AttachmentBroker::GetGlobal(); | 252 IPC::AttachmentBroker* global = IPC::AttachmentBroker::GetGlobal(); |
256 if (global && !global->IsPrivilegedBroker()) | 253 if (global && !global->IsPrivilegedBroker()) |
257 global->RegisterBrokerCommunicationChannel(channel_.get()); | 254 global->RegisterBrokerCommunicationChannel(channel_.get()); |
258 channel_->Init(channel_handle, IPC::Channel::MODE_CLIENT, true); | 255 channel_->Init(handle.release(), IPC::Channel::MODE_CLIENT, true); |
259 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 256 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
260 base::RunLoop().Run(); | 257 base::RunLoop().Run(); |
261 } | 258 } |
262 | 259 |
263 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { | 260 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { |
264 bool handled = true; | 261 bool handled = true; |
265 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) | 262 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) |
266 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource, | 263 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource, |
267 OnAddPrefetchedResource) | 264 OnAddPrefetchedResource) |
268 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) | 265 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 crash_info_shmem_.reset(new base::SharedMemory( | 326 crash_info_shmem_.reset(new base::SharedMemory( |
330 params.crash_info_shmem_handle, false /* not readonly */)); | 327 params.crash_info_shmem_handle, false /* not readonly */)); |
331 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); | 328 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); |
332 NaClSetFatalErrorCallback(&FatalLogHandler); | 329 NaClSetFatalErrorCallback(&FatalLogHandler); |
333 | 330 |
334 nap = NaClAppCreate(); | 331 nap = NaClAppCreate(); |
335 if (nap == NULL) { | 332 if (nap == NULL) { |
336 LOG(FATAL) << "NaClAppCreate() failed"; | 333 LOG(FATAL) << "NaClAppCreate() failed"; |
337 } | 334 } |
338 | 335 |
339 IPC::ChannelHandle browser_handle = | 336 IPC::ChannelHandle browser_handle; |
340 IPC::Channel::GenerateVerifiedChannelID("nacl"); | 337 IPC::ChannelHandle ppapi_renderer_handle; |
341 IPC::ChannelHandle ppapi_renderer_handle = | 338 IPC::ChannelHandle manifest_service_handle; |
342 IPC::Channel::GenerateVerifiedChannelID("nacl"); | |
343 IPC::ChannelHandle manifest_service_handle = | |
344 IPC::Channel::GenerateVerifiedChannelID("nacl"); | |
345 | 339 |
346 // Create the PPAPI IPC channels between the NaCl IRT and the host | 340 // Create the PPAPI IPC channels between the NaCl IRT and the host |
347 // (browser/renderer) processes. The IRT uses these channels to | 341 // (browser/renderer) processes. The IRT uses these channels to |
348 // communicate with the host and to initialize the IPC dispatchers. | 342 // communicate with the host and to initialize the IPC dispatchers. |
349 SetUpIPCAdapter(&browser_handle, io_thread_.task_runner(), nap, | 343 SetUpIPCAdapter(&browser_handle, io_thread_.task_runner(), nap, |
350 NACL_CHROME_DESC_BASE, | 344 NACL_CHROME_DESC_BASE, |
351 NaClIPCAdapter::ResolveFileTokenCallback(), | 345 NaClIPCAdapter::ResolveFileTokenCallback(), |
352 NaClIPCAdapter::OpenResourceCallback()); | 346 NaClIPCAdapter::OpenResourceCallback()); |
353 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap, | 347 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap, |
354 NACL_CHROME_DESC_BASE + 1, | 348 NACL_CHROME_DESC_BASE + 1, |
355 NaClIPCAdapter::ResolveFileTokenCallback(), | 349 NaClIPCAdapter::ResolveFileTokenCallback(), |
356 NaClIPCAdapter::OpenResourceCallback()); | 350 NaClIPCAdapter::OpenResourceCallback()); |
357 SetUpIPCAdapter( | 351 SetUpIPCAdapter( |
358 &manifest_service_handle, io_thread_.task_runner(), nap, | 352 &manifest_service_handle, io_thread_.task_runner(), nap, |
359 NACL_CHROME_DESC_BASE + 2, | 353 NACL_CHROME_DESC_BASE + 2, |
360 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)), | 354 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)), |
361 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this))); | 355 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this))); |
362 | 356 |
| 357 mojo::MessagePipe trusted_pipe; |
363 trusted_listener_ = | 358 trusted_listener_ = |
364 new NaClTrustedListener(IPC::Channel::GenerateVerifiedChannelID("nacl"), | 359 new NaClTrustedListener(trusted_pipe.handle0.release(), |
365 io_thread_.task_runner().get(), &shutdown_event_); | 360 io_thread_.task_runner().get(), &shutdown_event_); |
366 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( | 361 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( |
367 browser_handle, | 362 browser_handle, ppapi_renderer_handle, trusted_pipe.handle1.release(), |
368 ppapi_renderer_handle, | |
369 trusted_listener_->TakeClientChannelHandle(), | |
370 manifest_service_handle))) | 363 manifest_service_handle))) |
371 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; | 364 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; |
372 | 365 |
373 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); | 366 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); |
374 if (args == NULL) { | 367 if (args == NULL) { |
375 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; | 368 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; |
376 } | 369 } |
377 | 370 |
378 #if defined(OS_POSIX) | 371 #if defined(OS_POSIX) |
379 args->number_of_cores = number_of_cores_; | 372 args->number_of_cores = number_of_cores_; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 467 } |
475 | 468 |
476 void NaClListener::OnFileTokenResolved( | 469 void NaClListener::OnFileTokenResolved( |
477 uint64_t token_lo, | 470 uint64_t token_lo, |
478 uint64_t token_hi, | 471 uint64_t token_hi, |
479 IPC::PlatformFileForTransit ipc_fd, | 472 IPC::PlatformFileForTransit ipc_fd, |
480 base::FilePath file_path) { | 473 base::FilePath file_path) { |
481 resolved_cb_.Run(ipc_fd, file_path); | 474 resolved_cb_.Run(ipc_fd, file_path); |
482 resolved_cb_.Reset(); | 475 resolved_cb_.Reset(); |
483 } | 476 } |
OLD | NEW |