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" | 5 #include "base/run_loop.h" |
6 #include "components/nacl/loader/nacl_listener.h" | 6 #include "components/nacl/loader/nacl_listener.h" |
7 | 7 |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "ipc/ipc_switches.h" | 35 #include "ipc/ipc_switches.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) { |
| 119 IPC::ChannelHandle client_handle; |
| 120 IPC::Channel::GenerateMojoChannelHandlePair( |
| 121 "nacl", handle, &client_handle); |
120 scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter( | 122 scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter( |
121 *handle, task_runner.get(), resolve_file_token_cb, open_resource_cb)); | 123 *handle, task_runner.get(), resolve_file_token_cb, open_resource_cb)); |
122 ipc_adapter->ConnectChannel(); | 124 ipc_adapter->ConnectChannel(); |
123 #if defined(OS_POSIX) | 125 *handle = client_handle; |
124 handle->socket = | |
125 base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor()); | |
126 #endif | |
127 | 126 |
128 // Pass a NaClDesc to the untrusted side. This will hold a ref to the | 127 // Pass a NaClDesc to the untrusted side. This will hold a ref to the |
129 // NaClIPCAdapter. | 128 // NaClIPCAdapter. |
130 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); | 129 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); |
131 } | 130 } |
132 | 131 |
133 } // namespace | 132 } // namespace |
134 | 133 |
135 class BrowserValidationDBProxy : public NaClValidationDB { | 134 class BrowserValidationDBProxy : public NaClValidationDB { |
136 public: | 135 public: |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 crash_info_shmem_.reset(new base::SharedMemory( | 328 crash_info_shmem_.reset(new base::SharedMemory( |
330 params.crash_info_shmem_handle, false /* not readonly */)); | 329 params.crash_info_shmem_handle, false /* not readonly */)); |
331 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); | 330 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); |
332 NaClSetFatalErrorCallback(&FatalLogHandler); | 331 NaClSetFatalErrorCallback(&FatalLogHandler); |
333 | 332 |
334 nap = NaClAppCreate(); | 333 nap = NaClAppCreate(); |
335 if (nap == NULL) { | 334 if (nap == NULL) { |
336 LOG(FATAL) << "NaClAppCreate() failed"; | 335 LOG(FATAL) << "NaClAppCreate() failed"; |
337 } | 336 } |
338 | 337 |
339 IPC::ChannelHandle browser_handle = | 338 IPC::ChannelHandle browser_handle; |
340 IPC::Channel::GenerateVerifiedChannelID("nacl"); | 339 IPC::ChannelHandle ppapi_renderer_handle; |
341 IPC::ChannelHandle ppapi_renderer_handle = | 340 IPC::ChannelHandle manifest_service_handle; |
342 IPC::Channel::GenerateVerifiedChannelID("nacl"); | |
343 IPC::ChannelHandle manifest_service_handle = | |
344 IPC::Channel::GenerateVerifiedChannelID("nacl"); | |
345 | 341 |
346 // Create the PPAPI IPC channels between the NaCl IRT and the host | 342 // Create the PPAPI IPC channels between the NaCl IRT and the host |
347 // (browser/renderer) processes. The IRT uses these channels to | 343 // (browser/renderer) processes. The IRT uses these channels to |
348 // communicate with the host and to initialize the IPC dispatchers. | 344 // communicate with the host and to initialize the IPC dispatchers. |
349 SetUpIPCAdapter(&browser_handle, io_thread_.task_runner(), nap, | 345 SetUpIPCAdapter(&browser_handle, io_thread_.task_runner(), nap, |
350 NACL_CHROME_DESC_BASE, | 346 NACL_CHROME_DESC_BASE, |
351 NaClIPCAdapter::ResolveFileTokenCallback(), | 347 NaClIPCAdapter::ResolveFileTokenCallback(), |
352 NaClIPCAdapter::OpenResourceCallback()); | 348 NaClIPCAdapter::OpenResourceCallback()); |
353 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap, | 349 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap, |
354 NACL_CHROME_DESC_BASE + 1, | 350 NACL_CHROME_DESC_BASE + 1, |
355 NaClIPCAdapter::ResolveFileTokenCallback(), | 351 NaClIPCAdapter::ResolveFileTokenCallback(), |
356 NaClIPCAdapter::OpenResourceCallback()); | 352 NaClIPCAdapter::OpenResourceCallback()); |
357 SetUpIPCAdapter( | 353 SetUpIPCAdapter( |
358 &manifest_service_handle, io_thread_.task_runner(), nap, | 354 &manifest_service_handle, io_thread_.task_runner(), nap, |
359 NACL_CHROME_DESC_BASE + 2, | 355 NACL_CHROME_DESC_BASE + 2, |
360 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)), | 356 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)), |
361 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this))); | 357 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this))); |
362 | 358 |
| 359 IPC::ChannelHandle trusted_client; |
| 360 IPC::ChannelHandle trusted_server; |
| 361 IPC::Channel::GenerateMojoChannelHandlePair("NaCl-trusted-listener", |
| 362 &trusted_client, &trusted_server); |
363 trusted_listener_ = | 363 trusted_listener_ = |
364 new NaClTrustedListener(IPC::Channel::GenerateVerifiedChannelID("nacl"), | 364 new NaClTrustedListener(trusted_server, |
365 io_thread_.task_runner().get(), &shutdown_event_); | 365 io_thread_.task_runner().get(), &shutdown_event_); |
366 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( | 366 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( |
367 browser_handle, | 367 browser_handle, |
368 ppapi_renderer_handle, | 368 ppapi_renderer_handle, |
369 trusted_listener_->TakeClientChannelHandle(), | 369 trusted_client, |
370 manifest_service_handle))) | 370 manifest_service_handle))) |
371 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; | 371 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; |
372 | 372 |
373 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); | 373 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); |
374 if (args == NULL) { | 374 if (args == NULL) { |
375 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; | 375 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; |
376 } | 376 } |
377 | 377 |
378 #if defined(OS_POSIX) | 378 #if defined(OS_POSIX) |
379 args->number_of_cores = number_of_cores_; | 379 args->number_of_cores = number_of_cores_; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 474 } |
475 | 475 |
476 void NaClListener::OnFileTokenResolved( | 476 void NaClListener::OnFileTokenResolved( |
477 uint64_t token_lo, | 477 uint64_t token_lo, |
478 uint64_t token_hi, | 478 uint64_t token_hi, |
479 IPC::PlatformFileForTransit ipc_fd, | 479 IPC::PlatformFileForTransit ipc_fd, |
480 base::FilePath file_path) { | 480 base::FilePath file_path) { |
481 resolved_cb_.Run(ipc_fd, file_path); | 481 resolved_cb_.Run(ipc_fd, file_path); |
482 resolved_cb_.Reset(); | 482 resolved_cb_.Reset(); |
483 } | 483 } |
OLD | NEW |