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 |
11 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/platform_file.h" |
18 #include "base/process/launch.h" | 19 #include "base/process/launch.h" |
19 #include "base/process/process_iterator.h" | 20 #include "base/process/process_iterator.h" |
20 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
21 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_split.h" | 23 #include "base/strings/string_split.h" |
23 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
24 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
26 #include "base/threading/sequenced_worker_pool.h" | 27 #include "base/threading/sequenced_worker_pool.h" |
27 #include "base/win/windows_version.h" | 28 #include "base/win/windows_version.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 : socket_for_renderer(NACL_INVALID_HANDLE), | 251 : socket_for_renderer(NACL_INVALID_HANDLE), |
251 socket_for_sel_ldr(NACL_INVALID_HANDLE) { } | 252 socket_for_sel_ldr(NACL_INVALID_HANDLE) { } |
252 }; | 253 }; |
253 | 254 |
254 // ----------------------------------------------------------------------------- | 255 // ----------------------------------------------------------------------------- |
255 | 256 |
256 unsigned NaClProcessHost::keepalive_throttle_interval_milliseconds_ = | 257 unsigned NaClProcessHost::keepalive_throttle_interval_milliseconds_ = |
257 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds; | 258 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds; |
258 | 259 |
259 NaClProcessHost::NaClProcessHost(const GURL& manifest_url, | 260 NaClProcessHost::NaClProcessHost(const GURL& manifest_url, |
| 261 base::PlatformFile nexe_file, |
| 262 uint64_t nexe_token_lo, |
| 263 uint64_t nexe_token_hi, |
260 int render_view_id, | 264 int render_view_id, |
261 uint32 permission_bits, | 265 uint32 permission_bits, |
262 bool uses_irt, | 266 bool uses_irt, |
263 bool uses_nonsfi_mode, | 267 bool uses_nonsfi_mode, |
264 bool enable_dyncode_syscalls, | 268 bool enable_dyncode_syscalls, |
265 bool enable_exception_handling, | 269 bool enable_exception_handling, |
266 bool enable_crash_throttling, | 270 bool enable_crash_throttling, |
267 bool off_the_record, | 271 bool off_the_record, |
268 const base::FilePath& profile_directory) | 272 const base::FilePath& profile_directory) |
269 : manifest_url_(manifest_url), | 273 : manifest_url_(manifest_url), |
| 274 nexe_file_(nexe_file), |
| 275 nexe_token_lo_(nexe_token_lo), |
| 276 nexe_token_hi_(nexe_token_hi), |
270 permissions_(GetNaClPermissions(permission_bits)), | 277 permissions_(GetNaClPermissions(permission_bits)), |
271 #if defined(OS_WIN) | 278 #if defined(OS_WIN) |
272 process_launched_by_broker_(false), | 279 process_launched_by_broker_(false), |
273 #endif | 280 #endif |
274 reply_msg_(NULL), | 281 reply_msg_(NULL), |
275 #if defined(OS_WIN) | 282 #if defined(OS_WIN) |
276 debug_exception_handler_requested_(false), | 283 debug_exception_handler_requested_(false), |
277 #endif | 284 #endif |
278 internal_(new NaClInternal()), | 285 internal_(new NaClInternal()), |
279 weak_factory_(this), | 286 weak_factory_(this), |
(...skipping 13 matching lines...) Expand all Loading... |
293 // We aren't on the UI thread so getting the pref locale for language | 300 // We aren't on the UI thread so getting the pref locale for language |
294 // formatting isn't possible, so IDN will be lost, but this is probably OK | 301 // formatting isn't possible, so IDN will be lost, but this is probably OK |
295 // for this use case. | 302 // for this use case. |
296 process_->SetName(net::FormatUrl(manifest_url_, std::string())); | 303 process_->SetName(net::FormatUrl(manifest_url_, std::string())); |
297 | 304 |
298 enable_debug_stub_ = CommandLine::ForCurrentProcess()->HasSwitch( | 305 enable_debug_stub_ = CommandLine::ForCurrentProcess()->HasSwitch( |
299 switches::kEnableNaClDebug); | 306 switches::kEnableNaClDebug); |
300 } | 307 } |
301 | 308 |
302 NaClProcessHost::~NaClProcessHost() { | 309 NaClProcessHost::~NaClProcessHost() { |
| 310 if (nexe_file_ != base::kInvalidPlatformFileValue) |
| 311 base::ClosePlatformFile(nexe_file_); |
| 312 |
303 // Report exit status only if the process was successfully started. | 313 // Report exit status only if the process was successfully started. |
304 if (process_->GetData().handle != base::kNullProcessHandle) { | 314 if (process_->GetData().handle != base::kNullProcessHandle) { |
305 int exit_code = 0; | 315 int exit_code = 0; |
306 process_->GetTerminationStatus(false /* known_dead */, &exit_code); | 316 process_->GetTerminationStatus(false /* known_dead */, &exit_code); |
307 std::string message = | 317 std::string message = |
308 base::StringPrintf("NaCl process exited with status %i (0x%x)", | 318 base::StringPrintf("NaCl process exited with status %i (0x%x)", |
309 exit_code, exit_code); | 319 exit_code, exit_code); |
310 if (exit_code == 0) { | 320 if (exit_code == 0) { |
311 VLOG(1) << message; | 321 VLOG(1) << message; |
312 } else { | 322 } else { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 458 |
449 if (!nonsfi_mode_enabled) { | 459 if (!nonsfi_mode_enabled) { |
450 SendErrorToRenderer( | 460 SendErrorToRenderer( |
451 "NaCl non-SFI mode is not available for this platform" | 461 "NaCl non-SFI mode is not available for this platform" |
452 " and NaCl module."); | 462 " and NaCl module."); |
453 delete this; | 463 delete this; |
454 return; | 464 return; |
455 } | 465 } |
456 } | 466 } |
457 | 467 |
| 468 // TODO(hidehiko): We no longer use imc socket channel for non-SFI mode. |
| 469 // Do not create them. |
| 470 |
458 // Rather than creating a socket pair in the renderer, and passing | 471 // Rather than creating a socket pair in the renderer, and passing |
459 // one side through the browser to sel_ldr, socket pairs are created | 472 // one side through the browser to sel_ldr, socket pairs are created |
460 // in the browser and then passed to the renderer and sel_ldr. | 473 // in the browser and then passed to the renderer and sel_ldr. |
461 // | 474 // |
462 // This is mainly for the benefit of Windows, where sockets cannot | 475 // This is mainly for the benefit of Windows, where sockets cannot |
463 // be passed in messages, but are copied via DuplicateHandle(). | 476 // be passed in messages, but are copied via DuplicateHandle(). |
464 // This means the sandboxed renderer cannot send handles to the | 477 // This means the sandboxed renderer cannot send handles to the |
465 // browser process. | 478 // browser process. |
466 | 479 |
467 NaClHandle pair[2]; | 480 NaClHandle pair[2]; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 void NaClProcessHost::OnDebugStubPortSelected(uint16_t debug_stub_port) { | 825 void NaClProcessHost::OnDebugStubPortSelected(uint16_t debug_stub_port) { |
813 CHECK(!uses_nonsfi_mode_); | 826 CHECK(!uses_nonsfi_mode_); |
814 SetDebugStubPort(debug_stub_port); | 827 SetDebugStubPort(debug_stub_port); |
815 } | 828 } |
816 #endif | 829 #endif |
817 | 830 |
818 bool NaClProcessHost::StartNaClExecution() { | 831 bool NaClProcessHost::StartNaClExecution() { |
819 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | 832 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); |
820 | 833 |
821 NaClStartParams params; | 834 NaClStartParams params; |
| 835 |
822 // Enable PPAPI proxy channel creation only for renderer processes. | 836 // Enable PPAPI proxy channel creation only for renderer processes. |
823 params.enable_ipc_proxy = enable_ppapi_proxy(); | 837 params.enable_ipc_proxy = enable_ppapi_proxy(); |
824 if (!uses_nonsfi_mode_) { | 838 if (uses_nonsfi_mode_) { |
| 839 // Currently, non-SFI mode is supported only on Linux. |
| 840 #if defined(OS_LINUX) |
| 841 params.nexe_file = base::FileDescriptor(nexe_file_, true); |
| 842 params.nexe_token_lo = nexe_token_lo_; |
| 843 params.nexe_token_hi = nexe_token_hi_; |
| 844 #endif |
| 845 } else { |
825 params.validation_cache_enabled = nacl_browser->ValidationCacheIsEnabled(); | 846 params.validation_cache_enabled = nacl_browser->ValidationCacheIsEnabled(); |
826 params.validation_cache_key = nacl_browser->GetValidationCacheKey(); | 847 params.validation_cache_key = nacl_browser->GetValidationCacheKey(); |
827 params.version = NaClBrowser::GetDelegate()->GetVersionString(); | 848 params.version = NaClBrowser::GetDelegate()->GetVersionString(); |
828 params.enable_exception_handling = enable_exception_handling_; | 849 params.enable_exception_handling = enable_exception_handling_; |
829 params.enable_debug_stub = enable_debug_stub_ && | 850 params.enable_debug_stub = enable_debug_stub_ && |
830 NaClBrowser::GetDelegate()->URLMatchesDebugPatterns(manifest_url_); | 851 NaClBrowser::GetDelegate()->URLMatchesDebugPatterns(manifest_url_); |
831 params.uses_irt = uses_irt_; | 852 params.uses_irt = uses_irt_; |
832 params.enable_dyncode_syscalls = enable_dyncode_syscalls_; | 853 params.enable_dyncode_syscalls = enable_dyncode_syscalls_; |
833 } | 854 } |
834 | 855 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 net::SocketDescriptor server_bound_socket = GetDebugStubSocketHandle(); | 898 net::SocketDescriptor server_bound_socket = GetDebugStubSocketHandle(); |
878 if (server_bound_socket != net::kInvalidSocket) { | 899 if (server_bound_socket != net::kInvalidSocket) { |
879 params.debug_stub_server_bound_socket = | 900 params.debug_stub_server_bound_socket = |
880 FileDescriptor(server_bound_socket, true); | 901 FileDescriptor(server_bound_socket, true); |
881 } | 902 } |
882 } | 903 } |
883 #endif | 904 #endif |
884 | 905 |
885 process_->Send(new NaClProcessMsg_Start(params)); | 906 process_->Send(new NaClProcessMsg_Start(params)); |
886 | 907 |
| 908 if (uses_nonsfi_mode_) { |
| 909 // Moved the ownership of nexe_file to params. |
| 910 nexe_file_ = base::kInvalidPlatformFileValue; |
| 911 } |
887 internal_->socket_for_sel_ldr = NACL_INVALID_HANDLE; | 912 internal_->socket_for_sel_ldr = NACL_INVALID_HANDLE; |
888 return true; | 913 return true; |
889 } | 914 } |
890 | 915 |
891 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is | 916 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is |
892 // received. | 917 // received. |
893 void NaClProcessHost::OnPpapiChannelsCreated( | 918 void NaClProcessHost::OnPpapiChannelsCreated( |
894 const IPC::ChannelHandle& browser_channel_handle, | 919 const IPC::ChannelHandle& browser_channel_handle, |
895 const IPC::ChannelHandle& ppapi_renderer_channel_handle, | 920 const IPC::ChannelHandle& ppapi_renderer_channel_handle, |
896 const IPC::ChannelHandle& trusted_renderer_channel_handle, | 921 const IPC::ChannelHandle& trusted_renderer_channel_handle, |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 process_handle.Take(), info, | 1156 process_handle.Take(), info, |
1132 base::MessageLoopProxy::current(), | 1157 base::MessageLoopProxy::current(), |
1133 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1158 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
1134 weak_factory_.GetWeakPtr())); | 1159 weak_factory_.GetWeakPtr())); |
1135 return true; | 1160 return true; |
1136 } | 1161 } |
1137 } | 1162 } |
1138 #endif | 1163 #endif |
1139 | 1164 |
1140 } // namespace nacl | 1165 } // namespace nacl |
OLD | NEW |