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 #include <utility> | 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/memory/ptr_util.h" |
22 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
23 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
24 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
25 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
26 #include "build/build_config.h" | 26 #include "build/build_config.h" |
27 #include "components/nacl/common/nacl.mojom.h" | |
28 #include "components/nacl/common/nacl_messages.h" | 27 #include "components/nacl/common/nacl_messages.h" |
| 28 #include "components/nacl/common/nacl_renderer_messages.h" |
29 #include "components/nacl/common/nacl_switches.h" | 29 #include "components/nacl/common/nacl_switches.h" |
30 #include "components/nacl/loader/nacl_ipc_adapter.h" | 30 #include "components/nacl/loader/nacl_ipc_adapter.h" |
31 #include "components/nacl/loader/nacl_validation_db.h" | 31 #include "components/nacl/loader/nacl_validation_db.h" |
32 #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" | 33 #include "content/public/common/mojo_channel_switches.h" |
34 #include "ipc/ipc_channel_handle.h" | 34 #include "ipc/ipc_channel_handle.h" |
35 #include "ipc/ipc_sync_channel.h" | 35 #include "ipc/ipc_sync_channel.h" |
36 #include "ipc/ipc_sync_message_filter.h" | 36 #include "ipc/ipc_sync_message_filter.h" |
37 #include "mojo/edk/embedder/embedder.h" | 37 #include "mojo/edk/embedder/embedder.h" |
38 #include "mojo/edk/embedder/scoped_ipc_support.h" | 38 #include "mojo/edk/embedder/scoped_ipc_support.h" |
(...skipping 30 matching lines...) Expand all Loading... |
69 // We copy the length of the crash data to the start of the shared memory | 69 // We copy the length of the crash data to the start of the shared memory |
70 // segment so we know how much to copy. | 70 // segment so we know how much to copy. |
71 memcpy(g_listener->crash_info_shmem_memory(), ©_bytes, sizeof(uint32_t)); | 71 memcpy(g_listener->crash_info_shmem_memory(), ©_bytes, sizeof(uint32_t)); |
72 | 72 |
73 memcpy((char*)g_listener->crash_info_shmem_memory() + sizeof(uint32_t), | 73 memcpy((char*)g_listener->crash_info_shmem_memory() + sizeof(uint32_t), |
74 data, | 74 data, |
75 copy_bytes); | 75 copy_bytes); |
76 } | 76 } |
77 | 77 |
78 void LoadStatusCallback(int load_status) { | 78 void LoadStatusCallback(int load_status) { |
79 g_listener->trusted_listener()->renderer_host()->ReportLoadStatus( | 79 g_listener->trusted_listener()->Send( |
80 static_cast<NaClErrorCode>(load_status)); | 80 new NaClRendererMsg_ReportLoadStatus( |
| 81 static_cast<NaClErrorCode>(load_status))); |
81 } | 82 } |
82 | 83 |
83 #if defined(OS_LINUX) | 84 #if defined(OS_LINUX) |
84 | 85 |
85 int CreateMemoryObject(size_t size, int executable) { | 86 int CreateMemoryObject(size_t size, int executable) { |
86 return content::MakeSharedMemorySegmentViaIPC(size, executable); | 87 return content::MakeSharedMemorySegmentViaIPC(size, executable); |
87 } | 88 } |
88 | 89 |
89 #elif defined(OS_WIN) | 90 #elif defined(OS_WIN) |
90 int AttachDebugExceptionHandler(const void* info, size_t info_size) { | 91 int AttachDebugExceptionHandler(const void* info, size_t info_size) { |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap, | 342 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap, |
342 NACL_CHROME_DESC_BASE + 1, | 343 NACL_CHROME_DESC_BASE + 1, |
343 NaClIPCAdapter::ResolveFileTokenCallback(), | 344 NaClIPCAdapter::ResolveFileTokenCallback(), |
344 NaClIPCAdapter::OpenResourceCallback()); | 345 NaClIPCAdapter::OpenResourceCallback()); |
345 SetUpIPCAdapter( | 346 SetUpIPCAdapter( |
346 &manifest_service_handle, io_thread_.task_runner(), nap, | 347 &manifest_service_handle, io_thread_.task_runner(), nap, |
347 NACL_CHROME_DESC_BASE + 2, | 348 NACL_CHROME_DESC_BASE + 2, |
348 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)), | 349 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)), |
349 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this))); | 350 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this))); |
350 | 351 |
351 nacl::mojom::NaClRendererHostPtr renderer_host; | 352 mojo::MessagePipe trusted_pipe; |
| 353 trusted_listener_ = |
| 354 new NaClTrustedListener(trusted_pipe.handle0.release(), |
| 355 io_thread_.task_runner().get(), &shutdown_event_); |
352 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( | 356 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( |
353 browser_handle, ppapi_renderer_handle, | 357 browser_handle, ppapi_renderer_handle, trusted_pipe.handle1.release(), |
354 GetProxy(&renderer_host).PassMessagePipe().release(), | |
355 manifest_service_handle))) | 358 manifest_service_handle))) |
356 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; | 359 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; |
357 | 360 |
358 trusted_listener_ = base::MakeUnique<NaClTrustedListener>( | |
359 std::move(renderer_host), io_thread_.task_runner().get()); | |
360 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); | 361 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); |
361 if (args == NULL) { | 362 if (args == NULL) { |
362 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; | 363 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; |
363 } | 364 } |
364 | 365 |
365 #if defined(OS_POSIX) | 366 #if defined(OS_POSIX) |
366 args->number_of_cores = number_of_cores_; | 367 args->number_of_cores = number_of_cores_; |
367 #endif | 368 #endif |
368 | 369 |
369 #if defined(OS_LINUX) | 370 #if defined(OS_LINUX) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 params.nexe_file); | 439 params.nexe_file); |
439 std::string file_path_str = params.nexe_file_path_metadata.AsUTF8Unsafe(); | 440 std::string file_path_str = params.nexe_file_path_metadata.AsUTF8Unsafe(); |
440 args->nexe_desc = NaClDescCreateWithFilePathMetadata(nexe_file, | 441 args->nexe_desc = NaClDescCreateWithFilePathMetadata(nexe_file, |
441 file_path_str.c_str()); | 442 file_path_str.c_str()); |
442 | 443 |
443 int exit_status; | 444 int exit_status; |
444 if (!NaClChromeMainStart(nap, args, &exit_status)) | 445 if (!NaClChromeMainStart(nap, args, &exit_status)) |
445 NaClExit(1); | 446 NaClExit(1); |
446 | 447 |
447 // Report the plugin's exit status if the application started successfully. | 448 // Report the plugin's exit status if the application started successfully. |
448 trusted_listener_->renderer_host()->ReportExitStatus(exit_status); | 449 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status)); |
449 NaClExit(exit_status); | 450 NaClExit(exit_status); |
450 } | 451 } |
451 | 452 |
452 void NaClListener::ResolveFileToken( | 453 void NaClListener::ResolveFileToken( |
453 uint64_t token_lo, | 454 uint64_t token_lo, |
454 uint64_t token_hi, | 455 uint64_t token_hi, |
455 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) { | 456 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) { |
456 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) { | 457 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) { |
457 cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); | 458 cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); |
458 return; | 459 return; |
459 } | 460 } |
460 resolved_cb_ = cb; | 461 resolved_cb_ = cb; |
461 } | 462 } |
462 | 463 |
463 void NaClListener::OnFileTokenResolved( | 464 void NaClListener::OnFileTokenResolved( |
464 uint64_t token_lo, | 465 uint64_t token_lo, |
465 uint64_t token_hi, | 466 uint64_t token_hi, |
466 IPC::PlatformFileForTransit ipc_fd, | 467 IPC::PlatformFileForTransit ipc_fd, |
467 base::FilePath file_path) { | 468 base::FilePath file_path) { |
468 resolved_cb_.Run(ipc_fd, file_path); | 469 resolved_cb_.Run(ipc_fd, file_path); |
469 resolved_cb_.Reset(); | 470 resolved_cb_.Reset(); |
470 } | 471 } |
OLD | NEW |