| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/nacl_process_host.h" | 5 #include "components/nacl/browser/nacl_process_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 SendErrorToRenderer("NaClSocketPair() failed"); | 467 SendErrorToRenderer("NaClSocketPair() failed"); |
| 468 delete this; | 468 delete this; |
| 469 return; | 469 return; |
| 470 } | 470 } |
| 471 internal_->socket_for_renderer = pair[0]; | 471 internal_->socket_for_renderer = pair[0]; |
| 472 internal_->socket_for_sel_ldr = pair[1]; | 472 internal_->socket_for_sel_ldr = pair[1]; |
| 473 SetCloseOnExec(pair[0]); | 473 SetCloseOnExec(pair[0]); |
| 474 SetCloseOnExec(pair[1]); | 474 SetCloseOnExec(pair[1]); |
| 475 } | 475 } |
| 476 | 476 |
| 477 // Create a shared memory region that the renderer and plugin share for |
| 478 // reporting crash information. |
| 479 crash_info_shmem_.CreateAnonymous(kNaClCrashInfoShmemSize); |
| 480 |
| 477 // Launch the process | 481 // Launch the process |
| 478 if (!LaunchSelLdr()) { | 482 if (!LaunchSelLdr()) { |
| 479 delete this; | 483 delete this; |
| 480 } | 484 } |
| 481 } | 485 } |
| 482 | 486 |
| 483 void NaClProcessHost::OnChannelConnected(int32 peer_pid) { | 487 void NaClProcessHost::OnChannelConnected(int32 peer_pid) { |
| 484 if (!CommandLine::ForCurrentProcess()->GetSwitchValuePath( | 488 if (!CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
| 485 switches::kNaClGdb).empty()) { | 489 switches::kNaClGdb).empty()) { |
| 486 LaunchNaClGdb(); | 490 LaunchNaClGdb(); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 #else | 733 #else |
| 730 // No need to dup the imc_handle - we don't pass it anywhere else so | 734 // No need to dup the imc_handle - we don't pass it anywhere else so |
| 731 // it cannot be closed. | 735 // it cannot be closed. |
| 732 FileDescriptor imc_handle; | 736 FileDescriptor imc_handle; |
| 733 imc_handle.fd = internal_->socket_for_renderer; | 737 imc_handle.fd = internal_->socket_for_renderer; |
| 734 imc_handle.auto_close = true; | 738 imc_handle.auto_close = true; |
| 735 imc_handle_for_renderer = imc_handle; | 739 imc_handle_for_renderer = imc_handle; |
| 736 #endif | 740 #endif |
| 737 | 741 |
| 738 const ChildProcessData& data = process_->GetData(); | 742 const ChildProcessData& data = process_->GetData(); |
| 743 base::SharedMemoryHandle crash_info_shmem_renderer_handle; |
| 744 if (!crash_info_shmem_.ShareToProcess(nacl_host_message_filter_->PeerHandle(), |
| 745 &crash_info_shmem_renderer_handle)) { |
| 746 SendErrorToRenderer("ShareToProcess() failed"); |
| 747 return false; |
| 748 } |
| 749 |
| 739 SendMessageToRenderer( | 750 SendMessageToRenderer( |
| 740 NaClLaunchResult(imc_handle_for_renderer, | 751 NaClLaunchResult(imc_handle_for_renderer, |
| 741 ppapi_channel_handle, | 752 ppapi_channel_handle, |
| 742 trusted_channel_handle, | 753 trusted_channel_handle, |
| 743 manifest_service_channel_handle, | 754 manifest_service_channel_handle, |
| 744 base::GetProcId(data.handle), | 755 base::GetProcId(data.handle), |
| 745 data.id), | 756 data.id, |
| 757 crash_info_shmem_renderer_handle), |
| 746 std::string() /* error_message */); | 758 std::string() /* error_message */); |
| 747 internal_->socket_for_renderer = NACL_INVALID_HANDLE; | 759 internal_->socket_for_renderer = NACL_INVALID_HANDLE; |
| 760 |
| 761 // Now that the crash information shmem handles have been shared with the |
| 762 // plugin and the renderer, the browser can close its handle. |
| 763 crash_info_shmem_.Close(); |
| 748 return true; | 764 return true; |
| 749 } | 765 } |
| 750 | 766 |
| 751 void NaClProcessHost::SendErrorToRenderer(const std::string& error_message) { | 767 void NaClProcessHost::SendErrorToRenderer(const std::string& error_message) { |
| 752 LOG(ERROR) << "NaCl process launch failed: " << error_message; | 768 LOG(ERROR) << "NaCl process launch failed: " << error_message; |
| 753 SendMessageToRenderer(NaClLaunchResult(), error_message); | 769 SendMessageToRenderer(NaClLaunchResult(), error_message); |
| 754 } | 770 } |
| 755 | 771 |
| 756 void NaClProcessHost::SendMessageToRenderer( | 772 void NaClProcessHost::SendMessageToRenderer( |
| 757 const NaClLaunchResult& result, | 773 const NaClLaunchResult& result, |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 } | 908 } |
| 893 #endif | 909 #endif |
| 894 } | 910 } |
| 895 | 911 |
| 896 if (!uses_nonsfi_mode_) { | 912 if (!uses_nonsfi_mode_) { |
| 897 internal_->socket_for_sel_ldr = NACL_INVALID_HANDLE; | 913 internal_->socket_for_sel_ldr = NACL_INVALID_HANDLE; |
| 898 } | 914 } |
| 899 | 915 |
| 900 params.nexe_file = IPC::TakeFileHandleForProcess(nexe_file_.Pass(), | 916 params.nexe_file = IPC::TakeFileHandleForProcess(nexe_file_.Pass(), |
| 901 process_->GetData().handle); | 917 process_->GetData().handle); |
| 918 if (!crash_info_shmem_.ShareToProcess(process_->GetData().handle, |
| 919 ¶ms.crash_info_shmem_handle)) { |
| 920 DLOG(ERROR) << "Failed to ShareToProcess() a shared memory buffer"; |
| 921 return false; |
| 922 } |
| 902 | 923 |
| 903 process_->Send(new NaClProcessMsg_Start(params)); | 924 process_->Send(new NaClProcessMsg_Start(params)); |
| 904 return true; | 925 return true; |
| 905 } | 926 } |
| 906 | 927 |
| 907 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is | 928 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is |
| 908 // received. | 929 // received. |
| 909 void NaClProcessHost::OnPpapiChannelsCreated( | 930 void NaClProcessHost::OnPpapiChannelsCreated( |
| 910 const IPC::ChannelHandle& browser_channel_handle, | 931 const IPC::ChannelHandle& browser_channel_handle, |
| 911 const IPC::ChannelHandle& ppapi_renderer_channel_handle, | 932 const IPC::ChannelHandle& ppapi_renderer_channel_handle, |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 process_handle.Take(), info, | 1168 process_handle.Take(), info, |
| 1148 base::MessageLoopProxy::current(), | 1169 base::MessageLoopProxy::current(), |
| 1149 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1170 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
| 1150 weak_factory_.GetWeakPtr())); | 1171 weak_factory_.GetWeakPtr())); |
| 1151 return true; | 1172 return true; |
| 1152 } | 1173 } |
| 1153 } | 1174 } |
| 1154 #endif | 1175 #endif |
| 1155 | 1176 |
| 1156 } // namespace nacl | 1177 } // namespace nacl |
| OLD | NEW |