| 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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL); | 487 return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL); |
| 488 } | 488 } |
| 489 | 489 |
| 490 bool NaClProcessHost::LaunchSelLdr() { | 490 bool NaClProcessHost::LaunchSelLdr() { |
| 491 std::string channel_id = process_->GetHost()->CreateChannel(); | 491 std::string channel_id = process_->GetHost()->CreateChannel(); |
| 492 if (channel_id.empty()) { | 492 if (channel_id.empty()) { |
| 493 SendErrorToRenderer("CreateChannel() failed"); | 493 SendErrorToRenderer("CreateChannel() failed"); |
| 494 return false; | 494 return false; |
| 495 } | 495 } |
| 496 | 496 |
| 497 CommandLine::StringType nacl_loader_prefix; | |
| 498 #if defined(OS_POSIX) | |
| 499 nacl_loader_prefix = CommandLine::ForCurrentProcess()->GetSwitchValueNative( | |
| 500 switches::kNaClLoaderCmdPrefix); | |
| 501 #endif // defined(OS_POSIX) | |
| 502 | |
| 503 // Build command line for nacl. | 497 // Build command line for nacl. |
| 504 | 498 |
| 505 #if defined(OS_MACOSX) | 499 #if defined(OS_MACOSX) |
| 506 // The Native Client process needs to be able to allocate a 1GB contiguous | 500 // The Native Client process needs to be able to allocate a 1GB contiguous |
| 507 // region to use as the client environment's virtual address space. ASLR | 501 // region to use as the client environment's virtual address space. ASLR |
| 508 // (PIE) interferes with this by making it possible that no gap large enough | 502 // (PIE) interferes with this by making it possible that no gap large enough |
| 509 // to accomodate this request will exist in the child process' address | 503 // to accomodate this request will exist in the child process' address |
| 510 // space. Disable PIE for NaCl processes. See http://crbug.com/90221 and | 504 // space. Disable PIE for NaCl processes. See http://crbug.com/90221 and |
| 511 // http://code.google.com/p/nativeclient/issues/detail?id=2043. | 505 // http://code.google.com/p/nativeclient/issues/detail?id=2043. |
| 512 int flags = ChildProcessHost::CHILD_NO_PIE; | 506 int flags = ChildProcessHost::CHILD_NO_PIE; |
| 513 #elif defined(OS_LINUX) | 507 #elif defined(OS_LINUX) |
| 514 int flags = nacl_loader_prefix.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : | 508 int flags = ChildProcessHost::CHILD_ALLOW_SELF; |
| 515 ChildProcessHost::CHILD_NORMAL; | |
| 516 #else | 509 #else |
| 517 int flags = ChildProcessHost::CHILD_NORMAL; | 510 int flags = ChildProcessHost::CHILD_NORMAL; |
| 518 #endif | 511 #endif |
| 519 | 512 |
| 520 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); | 513 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); |
| 521 if (exe_path.empty()) | 514 if (exe_path.empty()) |
| 522 return false; | 515 return false; |
| 523 | 516 |
| 524 #if defined(OS_WIN) | 517 #if defined(OS_WIN) |
| 525 // On Windows 64-bit NaCl loader is called nacl64.exe instead of chrome.exe | 518 // On Windows 64-bit NaCl loader is called nacl64.exe instead of chrome.exe |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 | 553 |
| 561 scoped_ptr<CommandLine> cmd_line(new CommandLine(exe_path)); | 554 scoped_ptr<CommandLine> cmd_line(new CommandLine(exe_path)); |
| 562 CopyNaClCommandLineArguments(cmd_line.get()); | 555 CopyNaClCommandLineArguments(cmd_line.get()); |
| 563 | 556 |
| 564 cmd_line->AppendSwitchASCII(switches::kProcessType, | 557 cmd_line->AppendSwitchASCII(switches::kProcessType, |
| 565 switches::kNaClLoaderProcess); | 558 switches::kNaClLoaderProcess); |
| 566 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 559 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
| 567 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) | 560 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) |
| 568 cmd_line->AppendSwitch(switches::kNoErrorDialogs); | 561 cmd_line->AppendSwitch(switches::kNoErrorDialogs); |
| 569 | 562 |
| 570 if (!nacl_loader_prefix.empty()) | |
| 571 cmd_line->PrependWrapper(nacl_loader_prefix); | |
| 572 | |
| 573 // On Windows we might need to start the broker process to launch a new loader | 563 // On Windows we might need to start the broker process to launch a new loader |
| 574 #if defined(OS_WIN) | 564 #if defined(OS_WIN) |
| 575 if (RunningOnWOW64()) { | 565 if (RunningOnWOW64()) { |
| 576 if (!NaClBrokerService::GetInstance()->LaunchLoader( | 566 if (!NaClBrokerService::GetInstance()->LaunchLoader( |
| 577 weak_factory_.GetWeakPtr(), channel_id)) { | 567 weak_factory_.GetWeakPtr(), channel_id)) { |
| 578 SendErrorToRenderer("broker service did not launch process"); | 568 SendErrorToRenderer("broker service did not launch process"); |
| 579 return false; | 569 return false; |
| 580 } | 570 } |
| 581 } else { | 571 } else { |
| 582 process_->Launch(new NaClSandboxedProcessLauncherDelegate, | 572 process_->Launch(new NaClSandboxedProcessLauncherDelegate, |
| 583 false, | 573 false, |
| 584 cmd_line.release()); | 574 cmd_line.release()); |
| 585 } | 575 } |
| 586 #elif defined(OS_POSIX) | 576 #elif defined(OS_POSIX) |
| 587 process_->Launch(nacl_loader_prefix.empty(), // use_zygote | 577 process_->Launch(true, // use_zygote |
| 588 base::EnvironmentMap(), | 578 base::EnvironmentMap(), |
| 589 cmd_line.release()); | 579 cmd_line.release()); |
| 590 #endif | 580 #endif |
| 591 | 581 |
| 592 return true; | 582 return true; |
| 593 } | 583 } |
| 594 | 584 |
| 595 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { | 585 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { |
| 596 bool handled = true; | 586 bool handled = true; |
| 597 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) | 587 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 process_handle.Take(), info, | 1036 process_handle.Take(), info, |
| 1047 base::MessageLoopProxy::current(), | 1037 base::MessageLoopProxy::current(), |
| 1048 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1038 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
| 1049 weak_factory_.GetWeakPtr())); | 1039 weak_factory_.GetWeakPtr())); |
| 1050 return true; | 1040 return true; |
| 1051 } | 1041 } |
| 1052 } | 1042 } |
| 1053 #endif | 1043 #endif |
| 1054 | 1044 |
| 1055 } // namespace nacl | 1045 } // namespace nacl |
| OLD | NEW |