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) { |
119 IPC::ChannelHandle client_handle; | |
120 IPC::Channel::GenerateMojoChannelHandlePair("nacl", handle, &client_handle); | |
120 scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter( | 121 scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter( |
121 *handle, task_runner.get(), resolve_file_token_cb, open_resource_cb)); | 122 client_handle, task_runner, resolve_file_token_cb, open_resource_cb)); |
122 ipc_adapter->ConnectChannel(); | 123 ipc_adapter->ConnectChannel(); |
123 #if defined(OS_POSIX) | |
124 handle->socket = | |
125 base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor()); | |
126 #endif | |
127 | 124 |
128 // Pass a NaClDesc to the untrusted side. This will hold a ref to the | 125 // Pass a NaClDesc to the untrusted side. This will hold a ref to the |
129 // NaClIPCAdapter. | 126 // NaClIPCAdapter. |
130 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); | 127 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); |
131 } | 128 } |
132 | 129 |
133 } // namespace | 130 } // namespace |
134 | 131 |
135 class BrowserValidationDBProxy : public NaClValidationDB { | 132 class BrowserValidationDBProxy : public NaClValidationDB { |
136 public: | 133 public: |
(...skipping 192 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 |
363 trusted_listener_ = | 357 IPC::ChannelHandle trusted_client; |
364 new NaClTrustedListener(IPC::Channel::GenerateVerifiedChannelID("nacl"), | 358 IPC::ChannelHandle trusted_server; |
365 io_thread_.task_runner().get(), &shutdown_event_); | 359 IPC::Channel::GenerateMojoChannelHandlePair("NaCl-trusted-listener", |
360 &trusted_client, &trusted_server); | |
361 trusted_listener_ = new NaClTrustedListener( | |
362 trusted_server, io_thread_.task_runner().get(), &shutdown_event_); | |
366 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( | 363 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( |
367 browser_handle, | 364 browser_handle, ppapi_renderer_handle, trusted_client, |
368 ppapi_renderer_handle, | |
369 trusted_listener_->TakeClientChannelHandle(), | |
Mark Seaborn
2016/10/13 21:27:51
You should be able to remove TakeClientChannelHand
Sam McNally
2016/10/14 02:35:03
Done.
| |
370 manifest_service_handle))) | 365 manifest_service_handle))) |
371 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; | 366 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; |
372 | 367 |
373 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); | 368 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); |
374 if (args == NULL) { | 369 if (args == NULL) { |
375 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; | 370 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; |
376 } | 371 } |
377 | 372 |
378 #if defined(OS_POSIX) | 373 #if defined(OS_POSIX) |
379 args->number_of_cores = number_of_cores_; | 374 args->number_of_cores = number_of_cores_; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 } | 469 } |
475 | 470 |
476 void NaClListener::OnFileTokenResolved( | 471 void NaClListener::OnFileTokenResolved( |
477 uint64_t token_lo, | 472 uint64_t token_lo, |
478 uint64_t token_hi, | 473 uint64_t token_hi, |
479 IPC::PlatformFileForTransit ipc_fd, | 474 IPC::PlatformFileForTransit ipc_fd, |
480 base::FilePath file_path) { | 475 base::FilePath file_path) { |
481 resolved_cb_.Run(ipc_fd, file_path); | 476 resolved_cb_.Run(ipc_fd, file_path); |
482 resolved_cb_.Reset(); | 477 resolved_cb_.Reset(); |
483 } | 478 } |
OLD | NEW |